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
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * 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  */
2177c67f2fSkcpoon 
227c478bd9Sstevel@tonic-gate /*
235dd46ab5SKacheong Poon  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
2610ef8623SJohn Levon /*
2710ef8623SJohn Levon  * Copyright (c) 2018, Joyent, Inc.
28*78a2e113SAndy Fiddaman  * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
2910ef8623SJohn Levon  */
3010ef8623SJohn Levon 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/stream.h>
337c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
347c478bd9Sstevel@tonic-gate #define	_SUN_TPI_VERSION 2
357c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
367c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
377c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
3845916cd2Sjpk #include <sys/tsol/tndb.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <netinet/in.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <inet/common.h>
437c478bd9Sstevel@tonic-gate #include <inet/ip.h>
447c478bd9Sstevel@tonic-gate #include <inet/mib2.h>
457c478bd9Sstevel@tonic-gate #include <inet/snmpcom.h>
467c478bd9Sstevel@tonic-gate #include <inet/kstatcom.h>
477c478bd9Sstevel@tonic-gate #include <inet/ipclassifier.h>
487c478bd9Sstevel@tonic-gate #include "sctp_impl.h"
497c478bd9Sstevel@tonic-gate #include "sctp_addr.h"
507c478bd9Sstevel@tonic-gate 
515dd46ab5SKacheong Poon static void sctp_clr_kstats2(sctp_kstat_t *);
525dd46ab5SKacheong Poon static void sctp_add_kstats2(sctp_kstat_counter_t *, sctp_kstat_t *);
535dd46ab5SKacheong Poon static int sctp_snmp_state(sctp_t *);
545dd46ab5SKacheong Poon static void sctp_sum_mib(sctp_stack_t *, mib2_sctp_t *);
555dd46ab5SKacheong Poon static void sctp_add_mib(mib2_sctp_t *, mib2_sctp_t *);
5677c67f2fSkcpoon 
577c478bd9Sstevel@tonic-gate static int
sctp_kstat_update(kstat_t * kp,int rw)587c478bd9Sstevel@tonic-gate sctp_kstat_update(kstat_t *kp, int rw)
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate 	sctp_named_kstat_t	*sctpkp;
617c478bd9Sstevel@tonic-gate 	sctp_t			*sctp, *sctp_prev;
62f4b3ec61Sdh 	zoneid_t	myzoneid;
63f4b3ec61Sdh 	netstackid_t	stackid = (netstackid_t)(uintptr_t)kp->ks_private;
64f4b3ec61Sdh 	netstack_t	*ns;
65f4b3ec61Sdh 	sctp_stack_t	*sctps;
665dd46ab5SKacheong Poon 	mib2_sctp_t	sctp_mib;
677c478bd9Sstevel@tonic-gate 
6810ef8623SJohn Levon 	if (kp->ks_data == NULL)
697c478bd9Sstevel@tonic-gate 		return (EIO);
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	if (rw == KSTAT_WRITE)
727c478bd9Sstevel@tonic-gate 		return (EACCES);
737c478bd9Sstevel@tonic-gate 
74f4b3ec61Sdh 	ns = netstack_find_by_stackid(stackid);
75f4b3ec61Sdh 	if (ns == NULL)
76f4b3ec61Sdh 		return (-1);
77f4b3ec61Sdh 	sctps = ns->netstack_sctp;
78f4b3ec61Sdh 	if (sctps == NULL) {
79f4b3ec61Sdh 		netstack_rele(ns);
80f4b3ec61Sdh 		return (-1);
81f4b3ec61Sdh 	}
825dd46ab5SKacheong Poon 
835dd46ab5SKacheong Poon 	/*
845dd46ab5SKacheong Poon 	 * For all exclusive netstacks, the zone ID is always GLOBAL_ZONEID.
855dd46ab5SKacheong Poon 	 */
865dd46ab5SKacheong Poon 	if (stackid != GLOBAL_NETSTACKID)
875dd46ab5SKacheong Poon 		myzoneid = GLOBAL_ZONEID;
885dd46ab5SKacheong Poon 	else
895dd46ab5SKacheong Poon 		myzoneid = curproc->p_zone->zone_id;
905dd46ab5SKacheong Poon 
915dd46ab5SKacheong Poon 	bzero(&sctp_mib, sizeof (sctp_mib));
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	/*
947c478bd9Sstevel@tonic-gate 	 * Get the number of current associations and gather their
957c478bd9Sstevel@tonic-gate 	 * individual set of statistics.
967c478bd9Sstevel@tonic-gate 	 */
977c478bd9Sstevel@tonic-gate 	sctp_prev = NULL;
98f4b3ec61Sdh 	mutex_enter(&sctps->sctps_g_lock);
99bd670b35SErik Nordmark 	sctp = list_head(&sctps->sctps_g_list);
1007c478bd9Sstevel@tonic-gate 	while (sctp != NULL) {
1017c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp->sctp_reflock);
1027c478bd9Sstevel@tonic-gate 		if (sctp->sctp_condemned) {
1037c478bd9Sstevel@tonic-gate 			mutex_exit(&sctp->sctp_reflock);
104f4b3ec61Sdh 			sctp = list_next(&sctps->sctps_g_list, sctp);
1057c478bd9Sstevel@tonic-gate 			continue;
1067c478bd9Sstevel@tonic-gate 		}
1077c478bd9Sstevel@tonic-gate 		sctp->sctp_refcnt++;
1087c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp->sctp_reflock);
109f4b3ec61Sdh 		mutex_exit(&sctps->sctps_g_lock);
1107c478bd9Sstevel@tonic-gate 		if (sctp_prev != NULL)
1117c478bd9Sstevel@tonic-gate 			SCTP_REFRELE(sctp_prev);
112f4b3ec61Sdh 		if (sctp->sctp_connp->conn_zoneid != myzoneid)
1137c478bd9Sstevel@tonic-gate 			goto next_sctp;
1147c478bd9Sstevel@tonic-gate 		if (sctp->sctp_state == SCTPS_ESTABLISHED ||
1157c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_PENDING ||
1167c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_RECEIVED) {
1175dd46ab5SKacheong Poon 			/*
1185dd46ab5SKacheong Poon 			 * Just bump the local sctp_mib.  The number of
1195dd46ab5SKacheong Poon 			 * existing associations is not kept in kernel.
1205dd46ab5SKacheong Poon 			 */
1215dd46ab5SKacheong Poon 			BUMP_MIB(&sctp_mib, sctpCurrEstab);
1227c478bd9Sstevel@tonic-gate 		}
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 		if (sctp->sctp_opkts) {
1255dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpOutSCTPPkts,
1267c478bd9Sstevel@tonic-gate 			    sctp->sctp_opkts);
1277c478bd9Sstevel@tonic-gate 			sctp->sctp_opkts = 0;
1287c478bd9Sstevel@tonic-gate 		}
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 		if (sctp->sctp_obchunks) {
1315dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpOutCtrlChunks,
1327c478bd9Sstevel@tonic-gate 			    sctp->sctp_obchunks);
13335e12f9cSGeorge Shepherd 			UPDATE_LOCAL(sctp->sctp_cum_obchunks,
13435e12f9cSGeorge Shepherd 			    sctp->sctp_obchunks);
1357c478bd9Sstevel@tonic-gate 			sctp->sctp_obchunks = 0;
1367c478bd9Sstevel@tonic-gate 		}
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 		if (sctp->sctp_odchunks) {
1395dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpOutOrderChunks,
1407c478bd9Sstevel@tonic-gate 			    sctp->sctp_odchunks);
14135e12f9cSGeorge Shepherd 			UPDATE_LOCAL(sctp->sctp_cum_odchunks,
14235e12f9cSGeorge Shepherd 			    sctp->sctp_odchunks);
1437c478bd9Sstevel@tonic-gate 			sctp->sctp_odchunks = 0;
1447c478bd9Sstevel@tonic-gate 		}
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 		if (sctp->sctp_oudchunks) {
1475dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpOutUnorderChunks,
1487c478bd9Sstevel@tonic-gate 			    sctp->sctp_oudchunks);
14935e12f9cSGeorge Shepherd 			UPDATE_LOCAL(sctp->sctp_cum_oudchunks,
15035e12f9cSGeorge Shepherd 			    sctp->sctp_oudchunks);
1517c478bd9Sstevel@tonic-gate 			sctp->sctp_oudchunks = 0;
1527c478bd9Sstevel@tonic-gate 		}
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 		if (sctp->sctp_rxtchunks) {
1555dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpRetransChunks,
1567c478bd9Sstevel@tonic-gate 			    sctp->sctp_rxtchunks);
15735e12f9cSGeorge Shepherd 			UPDATE_LOCAL(sctp->sctp_cum_rxtchunks,
15835e12f9cSGeorge Shepherd 			    sctp->sctp_rxtchunks);
1597c478bd9Sstevel@tonic-gate 			sctp->sctp_rxtchunks = 0;
1607c478bd9Sstevel@tonic-gate 		}
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 		if (sctp->sctp_ipkts) {
1635dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpInSCTPPkts,
164f4b3ec61Sdh 			    sctp->sctp_ipkts);
1657c478bd9Sstevel@tonic-gate 			sctp->sctp_ipkts = 0;
1667c478bd9Sstevel@tonic-gate 		}
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 		if (sctp->sctp_ibchunks) {
1695dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpInCtrlChunks,
1707c478bd9Sstevel@tonic-gate 			    sctp->sctp_ibchunks);
17135e12f9cSGeorge Shepherd 			UPDATE_LOCAL(sctp->sctp_cum_ibchunks,
17235e12f9cSGeorge Shepherd 			    sctp->sctp_ibchunks);
1737c478bd9Sstevel@tonic-gate 			sctp->sctp_ibchunks = 0;
1747c478bd9Sstevel@tonic-gate 		}
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 		if (sctp->sctp_idchunks) {
1775dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpInOrderChunks,
1787c478bd9Sstevel@tonic-gate 			    sctp->sctp_idchunks);
17935e12f9cSGeorge Shepherd 			UPDATE_LOCAL(sctp->sctp_cum_idchunks,
18035e12f9cSGeorge Shepherd 			    sctp->sctp_idchunks);
1817c478bd9Sstevel@tonic-gate 			sctp->sctp_idchunks = 0;
1827c478bd9Sstevel@tonic-gate 		}
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 		if (sctp->sctp_iudchunks) {
1855dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpInUnorderChunks,
1867c478bd9Sstevel@tonic-gate 			    sctp->sctp_iudchunks);
18735e12f9cSGeorge Shepherd 			UPDATE_LOCAL(sctp->sctp_cum_iudchunks,
18835e12f9cSGeorge Shepherd 			    sctp->sctp_iudchunks);
1897c478bd9Sstevel@tonic-gate 			sctp->sctp_iudchunks = 0;
1907c478bd9Sstevel@tonic-gate 		}
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 		if (sctp->sctp_fragdmsgs) {
1935dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpFragUsrMsgs,
1947c478bd9Sstevel@tonic-gate 			    sctp->sctp_fragdmsgs);
1957c478bd9Sstevel@tonic-gate 			sctp->sctp_fragdmsgs = 0;
1967c478bd9Sstevel@tonic-gate 		}
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 		if (sctp->sctp_reassmsgs) {
1995dd46ab5SKacheong Poon 			SCTPS_UPDATE_MIB(sctps, sctpReasmUsrMsgs,
2007c478bd9Sstevel@tonic-gate 			    sctp->sctp_reassmsgs);
2017c478bd9Sstevel@tonic-gate 			sctp->sctp_reassmsgs = 0;
2027c478bd9Sstevel@tonic-gate 		}
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate next_sctp:
2057c478bd9Sstevel@tonic-gate 		sctp_prev = sctp;
206f4b3ec61Sdh 		mutex_enter(&sctps->sctps_g_lock);
207f4b3ec61Sdh 		sctp = list_next(&sctps->sctps_g_list, sctp);
2087c478bd9Sstevel@tonic-gate 	}
209f4b3ec61Sdh 	mutex_exit(&sctps->sctps_g_lock);
2107c478bd9Sstevel@tonic-gate 	if (sctp_prev != NULL)
2117c478bd9Sstevel@tonic-gate 		SCTP_REFRELE(sctp_prev);
2127c478bd9Sstevel@tonic-gate 
2135dd46ab5SKacheong Poon 	sctp_sum_mib(sctps, &sctp_mib);
2145dd46ab5SKacheong Poon 
2157c478bd9Sstevel@tonic-gate 	/* Copy data from the SCTP MIB */
2167c478bd9Sstevel@tonic-gate 	sctpkp = (sctp_named_kstat_t *)kp->ks_data;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	/* These are from global ndd params. */
219f4b3ec61Sdh 	sctpkp->sctpRtoMin.value.ui32 = sctps->sctps_rto_ming;
220f4b3ec61Sdh 	sctpkp->sctpRtoMax.value.ui32 = sctps->sctps_rto_maxg;
221f4b3ec61Sdh 	sctpkp->sctpRtoInitial.value.ui32 = sctps->sctps_rto_initialg;
222f4b3ec61Sdh 	sctpkp->sctpValCookieLife.value.ui32 = sctps->sctps_cookie_life;
223f4b3ec61Sdh 	sctpkp->sctpMaxInitRetr.value.ui32 = sctps->sctps_max_init_retr;
224f4b3ec61Sdh 
2255dd46ab5SKacheong Poon 	/* Copy data from the local sctp_mib to the provided kstat. */
2265dd46ab5SKacheong Poon 	sctpkp->sctpCurrEstab.value.i32 = sctp_mib.sctpCurrEstab;
2275dd46ab5SKacheong Poon 	sctpkp->sctpActiveEstab.value.i32 = sctp_mib.sctpActiveEstab;
2285dd46ab5SKacheong Poon 	sctpkp->sctpPassiveEstab.value.i32 = sctp_mib.sctpPassiveEstab;
2295dd46ab5SKacheong Poon 	sctpkp->sctpAborted.value.i32 = sctp_mib.sctpAborted;
2305dd46ab5SKacheong Poon 	sctpkp->sctpShutdowns.value.i32 = sctp_mib.sctpShutdowns;
2315dd46ab5SKacheong Poon 	sctpkp->sctpOutOfBlue.value.i32 = sctp_mib.sctpOutOfBlue;
2325dd46ab5SKacheong Poon 	sctpkp->sctpChecksumError.value.i32 = sctp_mib.sctpChecksumError;
2335dd46ab5SKacheong Poon 	sctpkp->sctpOutCtrlChunks.value.i64 = sctp_mib.sctpOutCtrlChunks;
2345dd46ab5SKacheong Poon 	sctpkp->sctpOutOrderChunks.value.i64 = sctp_mib.sctpOutOrderChunks;
2355dd46ab5SKacheong Poon 	sctpkp->sctpOutUnorderChunks.value.i64 = sctp_mib.sctpOutUnorderChunks;
2365dd46ab5SKacheong Poon 	sctpkp->sctpRetransChunks.value.i64 = sctp_mib.sctpRetransChunks;
2375dd46ab5SKacheong Poon 	sctpkp->sctpOutAck.value.i32 = sctp_mib.sctpOutAck;
2385dd46ab5SKacheong Poon 	sctpkp->sctpOutAckDelayed.value.i32 = sctp_mib.sctpOutAckDelayed;
2395dd46ab5SKacheong Poon 	sctpkp->sctpOutWinUpdate.value.i32 = sctp_mib.sctpOutWinUpdate;
2405dd46ab5SKacheong Poon 	sctpkp->sctpOutFastRetrans.value.i32 = sctp_mib.sctpOutFastRetrans;
2415dd46ab5SKacheong Poon 	sctpkp->sctpOutWinProbe.value.i32 = sctp_mib.sctpOutWinProbe;
2425dd46ab5SKacheong Poon 	sctpkp->sctpInCtrlChunks.value.i64 = sctp_mib.sctpInCtrlChunks;
2435dd46ab5SKacheong Poon 	sctpkp->sctpInOrderChunks.value.i64 = sctp_mib.sctpInOrderChunks;
2445dd46ab5SKacheong Poon 	sctpkp->sctpInUnorderChunks.value.i64 = sctp_mib.sctpInUnorderChunks;
2455dd46ab5SKacheong Poon 	sctpkp->sctpInAck.value.i32 = sctp_mib.sctpInAck;
2465dd46ab5SKacheong Poon 	sctpkp->sctpInDupAck.value.i32 = sctp_mib.sctpInDupAck;
2475dd46ab5SKacheong Poon 	sctpkp->sctpInAckUnsent.value.i32 = sctp_mib.sctpInAckUnsent;
2485dd46ab5SKacheong Poon 	sctpkp->sctpFragUsrMsgs.value.i64 = sctp_mib.sctpFragUsrMsgs;
2495dd46ab5SKacheong Poon 	sctpkp->sctpReasmUsrMsgs.value.i64 = sctp_mib.sctpReasmUsrMsgs;
2505dd46ab5SKacheong Poon 	sctpkp->sctpOutSCTPPkts.value.i64 = sctp_mib.sctpOutSCTPPkts;
2515dd46ab5SKacheong Poon 	sctpkp->sctpInSCTPPkts.value.i64 = sctp_mib.sctpInSCTPPkts;
2525dd46ab5SKacheong Poon 	sctpkp->sctpInInvalidCookie.value.i32 = sctp_mib.sctpInInvalidCookie;
2535dd46ab5SKacheong Poon 	sctpkp->sctpTimRetrans.value.i32 = sctp_mib.sctpTimRetrans;
2545dd46ab5SKacheong Poon 	sctpkp->sctpTimRetransDrop.value.i32 = sctp_mib.sctpTimRetransDrop;
2557c478bd9Sstevel@tonic-gate 	sctpkp->sctpTimHeartBeatProbe.value.i32 =
2565dd46ab5SKacheong Poon 	    sctp_mib.sctpTimHeartBeatProbe;
2575dd46ab5SKacheong Poon 	sctpkp->sctpTimHeartBeatDrop.value.i32 = sctp_mib.sctpTimHeartBeatDrop;
2585dd46ab5SKacheong Poon 	sctpkp->sctpListenDrop.value.i32 = sctp_mib.sctpListenDrop;
2595dd46ab5SKacheong Poon 	sctpkp->sctpInClosed.value.i32 = sctp_mib.sctpInClosed;
2607c478bd9Sstevel@tonic-gate 
261f4b3ec61Sdh 	netstack_rele(ns);
2627c478bd9Sstevel@tonic-gate 	return (0);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate 
265f4b3ec61Sdh void *
sctp_kstat_init(netstackid_t stackid)266f4b3ec61Sdh sctp_kstat_init(netstackid_t stackid)
2677c478bd9Sstevel@tonic-gate {
268f4b3ec61Sdh 	kstat_t	*ksp;
269f4b3ec61Sdh 
2707c478bd9Sstevel@tonic-gate 	sctp_named_kstat_t template = {
2717c478bd9Sstevel@tonic-gate 		{ "sctpRtoAlgorithm",		KSTAT_DATA_INT32, 0 },
2727c478bd9Sstevel@tonic-gate 		{ "sctpRtoMin",			KSTAT_DATA_UINT32, 0 },
2737c478bd9Sstevel@tonic-gate 		{ "sctpRtoMax",			KSTAT_DATA_UINT32, 0 },
2747c478bd9Sstevel@tonic-gate 		{ "sctpRtoInitial",		KSTAT_DATA_UINT32, 0 },
2757c478bd9Sstevel@tonic-gate 		{ "sctpMaxAssocs",		KSTAT_DATA_INT32, 0 },
2767c478bd9Sstevel@tonic-gate 		{ "sctpValCookieLife",		KSTAT_DATA_UINT32, 0 },
2777c478bd9Sstevel@tonic-gate 		{ "sctpMaxInitRetr",		KSTAT_DATA_UINT32, 0 },
2787c478bd9Sstevel@tonic-gate 		{ "sctpCurrEstab",		KSTAT_DATA_INT32, 0 },
2797c478bd9Sstevel@tonic-gate 		{ "sctpActiveEstab",		KSTAT_DATA_INT32, 0 },
2807c478bd9Sstevel@tonic-gate 		{ "sctpPassiveEstab",		KSTAT_DATA_INT32, 0 },
2817c478bd9Sstevel@tonic-gate 		{ "sctpAborted",		KSTAT_DATA_INT32, 0 },
2827c478bd9Sstevel@tonic-gate 		{ "sctpShutdowns",		KSTAT_DATA_INT32, 0 },
2837c478bd9Sstevel@tonic-gate 		{ "sctpOutOfBlue",		KSTAT_DATA_INT32, 0 },
2847c478bd9Sstevel@tonic-gate 		{ "sctpChecksumError",		KSTAT_DATA_INT32, 0 },
2857c478bd9Sstevel@tonic-gate 		{ "sctpOutCtrlChunks",		KSTAT_DATA_INT64, 0 },
2867c478bd9Sstevel@tonic-gate 		{ "sctpOutOrderChunks",		KSTAT_DATA_INT64, 0 },
2877c478bd9Sstevel@tonic-gate 		{ "sctpOutUnorderChunks",	KSTAT_DATA_INT64, 0 },
2887c478bd9Sstevel@tonic-gate 		{ "sctpRetransChunks",		KSTAT_DATA_INT64, 0 },
2897c478bd9Sstevel@tonic-gate 		{ "sctpOutAck",			KSTAT_DATA_INT32, 0 },
2907c478bd9Sstevel@tonic-gate 		{ "sctpOutAckDelayed",		KSTAT_DATA_INT32, 0 },
2917c478bd9Sstevel@tonic-gate 		{ "sctpOutWinUpdate",		KSTAT_DATA_INT32, 0 },
2927c478bd9Sstevel@tonic-gate 		{ "sctpOutFastRetrans",		KSTAT_DATA_INT32, 0 },
2937c478bd9Sstevel@tonic-gate 		{ "sctpOutWinProbe",		KSTAT_DATA_INT32, 0 },
2947c478bd9Sstevel@tonic-gate 		{ "sctpInCtrlChunks",		KSTAT_DATA_INT64, 0 },
2957c478bd9Sstevel@tonic-gate 		{ "sctpInOrderChunks",		KSTAT_DATA_INT64, 0 },
2967c478bd9Sstevel@tonic-gate 		{ "sctpInUnorderChunks",	KSTAT_DATA_INT64, 0 },
2977c478bd9Sstevel@tonic-gate 		{ "sctpInAck",			KSTAT_DATA_INT32, 0 },
2987c478bd9Sstevel@tonic-gate 		{ "sctpInDupAck",		KSTAT_DATA_INT32, 0 },
2997c478bd9Sstevel@tonic-gate 		{ "sctpInAckUnsent",		KSTAT_DATA_INT32, 0 },
3007c478bd9Sstevel@tonic-gate 		{ "sctpFragUsrMsgs",		KSTAT_DATA_INT64, 0 },
3017c478bd9Sstevel@tonic-gate 		{ "sctpReasmUsrMsgs",		KSTAT_DATA_INT64, 0 },
3027c478bd9Sstevel@tonic-gate 		{ "sctpOutSCTPPkts",		KSTAT_DATA_INT64, 0 },
3037c478bd9Sstevel@tonic-gate 		{ "sctpInSCTPPkts",		KSTAT_DATA_INT64, 0 },
3047c478bd9Sstevel@tonic-gate 		{ "sctpInInvalidCookie",	KSTAT_DATA_INT32, 0 },
3057c478bd9Sstevel@tonic-gate 		{ "sctpTimRetrans",		KSTAT_DATA_INT32, 0 },
3067c478bd9Sstevel@tonic-gate 		{ "sctpTimRetransDrop",		KSTAT_DATA_INT32, 0 },
3077c478bd9Sstevel@tonic-gate 		{ "sctpTimHearBeatProbe",	KSTAT_DATA_INT32, 0 },
3087c478bd9Sstevel@tonic-gate 		{ "sctpTimHearBeatDrop",	KSTAT_DATA_INT32, 0 },
3097c478bd9Sstevel@tonic-gate 		{ "sctpListenDrop",		KSTAT_DATA_INT32, 0 },
3107c478bd9Sstevel@tonic-gate 		{ "sctpInClosed",		KSTAT_DATA_INT32, 0 }
3117c478bd9Sstevel@tonic-gate 	};
3127c478bd9Sstevel@tonic-gate 
313f4b3ec61Sdh 	ksp = kstat_create_netstack(SCTP_MOD_NAME, 0, "sctp", "mib2",
314f4b3ec61Sdh 	    KSTAT_TYPE_NAMED, NUM_OF_FIELDS(sctp_named_kstat_t), 0, stackid);
3157c478bd9Sstevel@tonic-gate 
3165dd46ab5SKacheong Poon 	if (ksp == NULL)
317f4b3ec61Sdh 		return (NULL);
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	/* These won't change. */
3207c478bd9Sstevel@tonic-gate 	template.sctpRtoAlgorithm.value.i32 = MIB2_SCTP_RTOALGO_VANJ;
3217c478bd9Sstevel@tonic-gate 	template.sctpMaxAssocs.value.i32 = -1;
3227c478bd9Sstevel@tonic-gate 
323f4b3ec61Sdh 	bcopy(&template, ksp->ks_data, sizeof (template));
324f4b3ec61Sdh 	ksp->ks_update = sctp_kstat_update;
325f4b3ec61Sdh 	ksp->ks_private = (void *)(uintptr_t)stackid;
326f4b3ec61Sdh 
327f4b3ec61Sdh 	kstat_install(ksp);
328f4b3ec61Sdh 	return (ksp);
329f4b3ec61Sdh }
330f4b3ec61Sdh 
3315dd46ab5SKacheong Poon /*
3325dd46ab5SKacheong Poon  * To set all sctp_stat_t counters to 0.
3335dd46ab5SKacheong Poon  */
3345dd46ab5SKacheong Poon static void
sctp_clr_kstats2(sctp_kstat_t * stats)3355dd46ab5SKacheong Poon sctp_clr_kstats2(sctp_kstat_t *stats)
3365dd46ab5SKacheong Poon {
3375dd46ab5SKacheong Poon 	stats->sctp_add_faddr.value.ui64 = 0;
3385dd46ab5SKacheong Poon 	stats->sctp_add_timer.value.ui64 = 0;
3395dd46ab5SKacheong Poon 	stats->sctp_conn_create.value.ui64 = 0;
3405dd46ab5SKacheong Poon 	stats->sctp_find_next_tq.value.ui64 = 0;
3415dd46ab5SKacheong Poon 	stats->sctp_fr_add_hdr.value.ui64 = 0;
3425dd46ab5SKacheong Poon 	stats->sctp_fr_not_found.value.ui64 = 0;
3435dd46ab5SKacheong Poon 	stats->sctp_output_failed.value.ui64 = 0;
3445dd46ab5SKacheong Poon 	stats->sctp_rexmit_failed.value.ui64 = 0;
3455dd46ab5SKacheong Poon 	stats->sctp_send_init_failed.value.ui64 = 0;
3465dd46ab5SKacheong Poon 	stats->sctp_send_cookie_failed.value.ui64 = 0;
3475dd46ab5SKacheong Poon 	stats->sctp_send_cookie_ack_failed.value.ui64 = 0;
3485dd46ab5SKacheong Poon 	stats->sctp_send_err_failed.value.ui64 = 0;
3495dd46ab5SKacheong Poon 	stats->sctp_send_sack_failed.value.ui64 = 0;
3505dd46ab5SKacheong Poon 	stats->sctp_send_shutdown_failed.value.ui64 = 0;
3515dd46ab5SKacheong Poon 	stats->sctp_send_shutdown_ack_failed.value.ui64 = 0;
3525dd46ab5SKacheong Poon 	stats->sctp_send_shutdown_comp_failed.value.ui64 = 0;
3535dd46ab5SKacheong Poon 	stats->sctp_send_user_abort_failed.value.ui64 = 0;
3545dd46ab5SKacheong Poon 	stats->sctp_send_asconf_failed.value.ui64 = 0;
3555dd46ab5SKacheong Poon 	stats->sctp_send_asconf_ack_failed.value.ui64 = 0;
3565dd46ab5SKacheong Poon 	stats->sctp_send_ftsn_failed.value.ui64 = 0;
3575dd46ab5SKacheong Poon 	stats->sctp_send_hb_failed.value.ui64 = 0;
3585dd46ab5SKacheong Poon 	stats->sctp_return_hb_failed.value.ui64 = 0;
3595dd46ab5SKacheong Poon 	stats->sctp_ss_rexmit_failed.value.ui64 = 0;
3605dd46ab5SKacheong Poon 	stats->sctp_cl_connect.value.ui64 = 0;
3615dd46ab5SKacheong Poon 	stats->sctp_cl_assoc_change.value.ui64 = 0;
3625dd46ab5SKacheong Poon 	stats->sctp_cl_check_addrs.value.ui64 = 0;
3635dd46ab5SKacheong Poon 	stats->sctp_reclaim_cnt.value.ui64 = 0;
3645dd46ab5SKacheong Poon 	stats->sctp_listen_cnt_drop.value.ui64 = 0;
3655dd46ab5SKacheong Poon }
3665dd46ab5SKacheong Poon 
3675dd46ab5SKacheong Poon /*
3685dd46ab5SKacheong Poon  * To add counters from the per CPU sctp_kstat_counter_t to the stack
3695dd46ab5SKacheong Poon  * sctp_kstat_t.
3705dd46ab5SKacheong Poon  */
3715dd46ab5SKacheong Poon static void
sctp_add_kstats2(sctp_kstat_counter_t * from,sctp_kstat_t * to)3725dd46ab5SKacheong Poon sctp_add_kstats2(sctp_kstat_counter_t *from, sctp_kstat_t *to)
3735dd46ab5SKacheong Poon {
3745dd46ab5SKacheong Poon 	to->sctp_add_faddr.value.ui64 += from->sctp_add_faddr;
3755dd46ab5SKacheong Poon 	to->sctp_add_timer.value.ui64 += from->sctp_add_timer;
3765dd46ab5SKacheong Poon 	to->sctp_conn_create.value.ui64 += from->sctp_conn_create;
3775dd46ab5SKacheong Poon 	to->sctp_find_next_tq.value.ui64 += from->sctp_find_next_tq;
3785dd46ab5SKacheong Poon 	to->sctp_fr_add_hdr.value.ui64 += from->sctp_fr_add_hdr;
3795dd46ab5SKacheong Poon 	to->sctp_fr_not_found.value.ui64 += from->sctp_fr_not_found;
3805dd46ab5SKacheong Poon 	to->sctp_output_failed.value.ui64 += from->sctp_output_failed;
3815dd46ab5SKacheong Poon 	to->sctp_rexmit_failed.value.ui64 += from->sctp_rexmit_failed;
3825dd46ab5SKacheong Poon 	to->sctp_send_init_failed.value.ui64 += from->sctp_send_init_failed;
3835dd46ab5SKacheong Poon 	to->sctp_send_cookie_failed.value.ui64 += from->sctp_send_cookie_failed;
3845dd46ab5SKacheong Poon 	to->sctp_send_cookie_ack_failed.value.ui64 +=
3855dd46ab5SKacheong Poon 	    from->sctp_send_cookie_ack_failed;
3865dd46ab5SKacheong Poon 	to->sctp_send_err_failed.value.ui64 += from->sctp_send_err_failed;
3875dd46ab5SKacheong Poon 	to->sctp_send_sack_failed.value.ui64 += from->sctp_send_sack_failed;
3885dd46ab5SKacheong Poon 	to->sctp_send_shutdown_failed.value.ui64 +=
3895dd46ab5SKacheong Poon 	    from->sctp_send_shutdown_failed;
3905dd46ab5SKacheong Poon 	to->sctp_send_shutdown_ack_failed.value.ui64 +=
3915dd46ab5SKacheong Poon 	    from->sctp_send_shutdown_ack_failed;
3925dd46ab5SKacheong Poon 	to->sctp_send_shutdown_comp_failed.value.ui64 +=
3935dd46ab5SKacheong Poon 	    from->sctp_send_shutdown_comp_failed;
3945dd46ab5SKacheong Poon 	to->sctp_send_user_abort_failed.value.ui64 +=
3955dd46ab5SKacheong Poon 	    from->sctp_send_user_abort_failed;
3965dd46ab5SKacheong Poon 	to->sctp_send_asconf_failed.value.ui64 += from->sctp_send_asconf_failed;
3975dd46ab5SKacheong Poon 	to->sctp_send_asconf_ack_failed.value.ui64 +=
3985dd46ab5SKacheong Poon 	    from->sctp_send_asconf_ack_failed;
3995dd46ab5SKacheong Poon 	to->sctp_send_ftsn_failed.value.ui64 += from->sctp_send_ftsn_failed;
4005dd46ab5SKacheong Poon 	to->sctp_send_hb_failed.value.ui64 += from->sctp_send_hb_failed;
4015dd46ab5SKacheong Poon 	to->sctp_return_hb_failed.value.ui64 += from->sctp_return_hb_failed;
4025dd46ab5SKacheong Poon 	to->sctp_ss_rexmit_failed.value.ui64 += from->sctp_ss_rexmit_failed;
4035dd46ab5SKacheong Poon 	to->sctp_cl_connect.value.ui64 += from->sctp_cl_connect;
4045dd46ab5SKacheong Poon 	to->sctp_cl_assoc_change.value.ui64 += from->sctp_cl_assoc_change;
4055dd46ab5SKacheong Poon 	to->sctp_cl_check_addrs.value.ui64 += from->sctp_cl_check_addrs;
4065dd46ab5SKacheong Poon }
4075dd46ab5SKacheong Poon 
4085dd46ab5SKacheong Poon /*
4095dd46ab5SKacheong Poon  * Sum up all per CPU tcp_stat_t kstat counters.
4105dd46ab5SKacheong Poon  */
4115dd46ab5SKacheong Poon static int
sctp_kstat2_update(kstat_t * kp,int rw)4125dd46ab5SKacheong Poon sctp_kstat2_update(kstat_t *kp, int rw)
4135dd46ab5SKacheong Poon {
4145dd46ab5SKacheong Poon 	netstackid_t	stackid = (netstackid_t)(uintptr_t)kp->ks_private;
4155dd46ab5SKacheong Poon 	netstack_t	*ns;
4165dd46ab5SKacheong Poon 	sctp_stack_t	*sctps;
4175dd46ab5SKacheong Poon 	sctp_kstat_t	*stats;
4185dd46ab5SKacheong Poon 	int		i;
4195dd46ab5SKacheong Poon 	int		cnt;
4205dd46ab5SKacheong Poon 
4215dd46ab5SKacheong Poon 	if (rw == KSTAT_WRITE)
4225dd46ab5SKacheong Poon 		return (EACCES);
4235dd46ab5SKacheong Poon 
4245dd46ab5SKacheong Poon 	ns = netstack_find_by_stackid(stackid);
4255dd46ab5SKacheong Poon 	if (ns == NULL)
4265dd46ab5SKacheong Poon 		return (-1);
4275dd46ab5SKacheong Poon 	sctps = ns->netstack_sctp;
4285dd46ab5SKacheong Poon 	if (sctps == NULL) {
4295dd46ab5SKacheong Poon 		netstack_rele(ns);
4305dd46ab5SKacheong Poon 		return (-1);
4315dd46ab5SKacheong Poon 	}
4325dd46ab5SKacheong Poon 
4335dd46ab5SKacheong Poon 	stats = (sctp_kstat_t *)kp->ks_data;
4345dd46ab5SKacheong Poon 	sctp_clr_kstats2(stats);
4355dd46ab5SKacheong Poon 
4365dd46ab5SKacheong Poon 	/*
4375dd46ab5SKacheong Poon 	 * sctps_sc_cnt may change in the middle of the loop.  It is better
4385dd46ab5SKacheong Poon 	 * to get its value first.
4395dd46ab5SKacheong Poon 	 */
4405dd46ab5SKacheong Poon 	cnt = sctps->sctps_sc_cnt;
4415dd46ab5SKacheong Poon 	for (i = 0; i < cnt; i++)
4425dd46ab5SKacheong Poon 		sctp_add_kstats2(&sctps->sctps_sc[i]->sctp_sc_stats, stats);
4435dd46ab5SKacheong Poon 
4445dd46ab5SKacheong Poon 	netstack_rele(ns);
4455dd46ab5SKacheong Poon 	return (0);
4465dd46ab5SKacheong Poon }
4475dd46ab5SKacheong Poon 
448f4b3ec61Sdh /*
449f4b3ec61Sdh  * The following kstats are for debugging purposes.  They keep
450f4b3ec61Sdh  * track of problems which should not happen normally.  But in
451f4b3ec61Sdh  * those cases which they do happen, these kstats would be handy
452f4b3ec61Sdh  * for engineers to diagnose the problems.  They are not intended
453f4b3ec61Sdh  * to be consumed by customers.
454f4b3ec61Sdh  */
455f4b3ec61Sdh void *
sctp_kstat2_init(netstackid_t stackid)4565dd46ab5SKacheong Poon sctp_kstat2_init(netstackid_t stackid)
457f4b3ec61Sdh {
458f4b3ec61Sdh 	kstat_t *ksp;
459f4b3ec61Sdh 
460f4b3ec61Sdh 	sctp_kstat_t template = {
461f4b3ec61Sdh 		{ "sctp_add_faddr",			KSTAT_DATA_UINT64 },
462f4b3ec61Sdh 		{ "sctp_add_timer",			KSTAT_DATA_UINT64 },
463f4b3ec61Sdh 		{ "sctp_conn_create",			KSTAT_DATA_UINT64 },
464f4b3ec61Sdh 		{ "sctp_find_next_tq",			KSTAT_DATA_UINT64 },
465f4b3ec61Sdh 		{ "sctp_fr_add_hdr",			KSTAT_DATA_UINT64 },
466f4b3ec61Sdh 		{ "sctp_fr_not_found",			KSTAT_DATA_UINT64 },
467f4b3ec61Sdh 		{ "sctp_output_failed",			KSTAT_DATA_UINT64 },
468f4b3ec61Sdh 		{ "sctp_rexmit_failed",			KSTAT_DATA_UINT64 },
469f4b3ec61Sdh 		{ "sctp_send_init_failed",		KSTAT_DATA_UINT64 },
470f4b3ec61Sdh 		{ "sctp_send_cookie_failed",		KSTAT_DATA_UINT64 },
471f4b3ec61Sdh 		{ "sctp_send_cookie_ack_failed",	KSTAT_DATA_UINT64 },
472f4b3ec61Sdh 		{ "sctp_send_err_failed",		KSTAT_DATA_UINT64 },
473f4b3ec61Sdh 		{ "sctp_send_sack_failed",		KSTAT_DATA_UINT64 },
474f4b3ec61Sdh 		{ "sctp_send_shutdown_failed",		KSTAT_DATA_UINT64 },
475f4b3ec61Sdh 		{ "sctp_send_shutdown_ack_failed",	KSTAT_DATA_UINT64 },
476f4b3ec61Sdh 		{ "sctp_send_shutdown_comp_failed",	KSTAT_DATA_UINT64 },
477f4b3ec61Sdh 		{ "sctp_send_user_abort_failed",	KSTAT_DATA_UINT64 },
478f4b3ec61Sdh 		{ "sctp_send_asconf_failed",		KSTAT_DATA_UINT64 },
479f4b3ec61Sdh 		{ "sctp_send_asconf_ack_failed",	KSTAT_DATA_UINT64 },
480f4b3ec61Sdh 		{ "sctp_send_ftsn_failed",		KSTAT_DATA_UINT64 },
481f4b3ec61Sdh 		{ "sctp_send_hb_failed",		KSTAT_DATA_UINT64 },
482f4b3ec61Sdh 		{ "sctp_return_hb_failed",		KSTAT_DATA_UINT64 },
483f4b3ec61Sdh 		{ "sctp_ss_rexmit_failed",		KSTAT_DATA_UINT64 },
484f4b3ec61Sdh 		{ "sctp_cl_connect",			KSTAT_DATA_UINT64 },
485f4b3ec61Sdh 		{ "sctp_cl_assoc_change",		KSTAT_DATA_UINT64 },
486f4b3ec61Sdh 		{ "sctp_cl_check_addrs",		KSTAT_DATA_UINT64 },
4875dd46ab5SKacheong Poon 		{ "sctp_reclaim_drop",			KSTAT_DATA_UINT64 },
4885dd46ab5SKacheong Poon 		{ "sctp_listen_cnt_drop",		KSTAT_DATA_UINT64 },
489f4b3ec61Sdh 	};
490f4b3ec61Sdh 
491f4b3ec61Sdh 	ksp = kstat_create_netstack(SCTP_MOD_NAME, 0, "sctpstat", "net",
4925dd46ab5SKacheong Poon 	    KSTAT_TYPE_NAMED, NUM_OF_FIELDS(template), 0, stackid);
4937c478bd9Sstevel@tonic-gate 
494f4b3ec61Sdh 	if (ksp == NULL)
495f4b3ec61Sdh 		return (NULL);
4967c478bd9Sstevel@tonic-gate 
4975dd46ab5SKacheong Poon 	bcopy(&template, ksp->ks_data, sizeof (template));
498f4b3ec61Sdh 	ksp->ks_private = (void *)(uintptr_t)stackid;
4995dd46ab5SKacheong Poon 	ksp->ks_update = sctp_kstat2_update;
50077c67f2fSkcpoon 
501f4b3ec61Sdh 	kstat_install(ksp);
502f4b3ec61Sdh 	return (ksp);
5037c478bd9Sstevel@tonic-gate }
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate void
sctp_kstat_fini(netstackid_t stackid,kstat_t * ksp)506f4b3ec61Sdh sctp_kstat_fini(netstackid_t stackid, kstat_t *ksp)
5077c478bd9Sstevel@tonic-gate {
508f4b3ec61Sdh 	if (ksp != NULL) {
509f4b3ec61Sdh 		ASSERT(stackid == (netstackid_t)(uintptr_t)ksp->ks_private);
510f4b3ec61Sdh 		kstat_delete_netstack(ksp, stackid);
5117c478bd9Sstevel@tonic-gate 	}
512f4b3ec61Sdh }
513f4b3ec61Sdh 
514f4b3ec61Sdh void
sctp_kstat2_fini(netstackid_t stackid,kstat_t * ksp)515f4b3ec61Sdh sctp_kstat2_fini(netstackid_t stackid, kstat_t *ksp)
516f4b3ec61Sdh {
517f4b3ec61Sdh 	if (ksp != NULL) {
518f4b3ec61Sdh 		ASSERT(stackid == (netstackid_t)(uintptr_t)ksp->ks_private);
519f4b3ec61Sdh 		kstat_delete_netstack(ksp, stackid);
52077c67f2fSkcpoon 	}
5217c478bd9Sstevel@tonic-gate }
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate /*
5247c478bd9Sstevel@tonic-gate  * Return SNMP global stats in buffer in mpdata.
5257c478bd9Sstevel@tonic-gate  * Return associatiation table in mp_conn_data,
5267c478bd9Sstevel@tonic-gate  * local address table in mp_local_data, and
5277c478bd9Sstevel@tonic-gate  * remote address table in mp_rem_data.
5287c478bd9Sstevel@tonic-gate  */
5297c478bd9Sstevel@tonic-gate mblk_t *
sctp_snmp_get_mib2(queue_t * q,mblk_t * mpctl,sctp_stack_t * sctps)530f4b3ec61Sdh sctp_snmp_get_mib2(queue_t *q, mblk_t *mpctl, sctp_stack_t *sctps)
5317c478bd9Sstevel@tonic-gate {
5327c478bd9Sstevel@tonic-gate 	mblk_t			*mpdata, *mp_ret;
5337c478bd9Sstevel@tonic-gate 	mblk_t			*mp_conn_ctl = NULL;
5347c478bd9Sstevel@tonic-gate 	mblk_t			*mp_conn_data;
5357c478bd9Sstevel@tonic-gate 	mblk_t			*mp_conn_tail = NULL;
5367c478bd9Sstevel@tonic-gate 	mblk_t			*mp_local_ctl = NULL;
5377c478bd9Sstevel@tonic-gate 	mblk_t			*mp_local_data;
5387c478bd9Sstevel@tonic-gate 	mblk_t			*mp_local_tail = NULL;
5397c478bd9Sstevel@tonic-gate 	mblk_t			*mp_rem_ctl = NULL;
5407c478bd9Sstevel@tonic-gate 	mblk_t			*mp_rem_data;
5417c478bd9Sstevel@tonic-gate 	mblk_t			*mp_rem_tail = NULL;
54245916cd2Sjpk 	mblk_t			*mp_attr_ctl = NULL;
54345916cd2Sjpk 	mblk_t			*mp_attr_data;
54445916cd2Sjpk 	mblk_t			*mp_attr_tail = NULL;
545*78a2e113SAndy Fiddaman 	mblk_t			*mp_info_ctl = NULL;
546*78a2e113SAndy Fiddaman 	mblk_t			*mp_info_data;
547*78a2e113SAndy Fiddaman 	mblk_t			*mp_info_tail = NULL;
5487c478bd9Sstevel@tonic-gate 	struct opthdr		*optp;
5497c478bd9Sstevel@tonic-gate 	sctp_t			*sctp, *sctp_prev = NULL;
5507c478bd9Sstevel@tonic-gate 	sctp_faddr_t		*fp;
5517c478bd9Sstevel@tonic-gate 	mib2_sctpConnEntry_t	sce;
5527c478bd9Sstevel@tonic-gate 	mib2_sctpConnLocalEntry_t	scle;
5537c478bd9Sstevel@tonic-gate 	mib2_sctpConnRemoteEntry_t	scre;
55445916cd2Sjpk 	mib2_transportMLPEntry_t	mlp;
555*78a2e113SAndy Fiddaman 	mib2_socketInfoEntry_t		*sie, psie;
5567c478bd9Sstevel@tonic-gate 	int			i;
5577c478bd9Sstevel@tonic-gate 	int			l;
5587c478bd9Sstevel@tonic-gate 	int			scanned = 0;
5597c478bd9Sstevel@tonic-gate 	zoneid_t		zoneid = Q_TO_CONN(q)->conn_zoneid;
56045916cd2Sjpk 	conn_t			*connp;
56145916cd2Sjpk 	boolean_t		needattr;
56245916cd2Sjpk 	int			idx;
5635dd46ab5SKacheong Poon 	mib2_sctp_t		sctp_mib;
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	/*
5667c478bd9Sstevel@tonic-gate 	 * Make copies of the original message.
5677c478bd9Sstevel@tonic-gate 	 * mpctl will hold SCTP counters,
5687c478bd9Sstevel@tonic-gate 	 * mp_conn_ctl will hold list of connections.
5697c478bd9Sstevel@tonic-gate 	 */
5707c478bd9Sstevel@tonic-gate 	mp_ret = copymsg(mpctl);
5717c478bd9Sstevel@tonic-gate 	mp_conn_ctl = copymsg(mpctl);
5727c478bd9Sstevel@tonic-gate 	mp_local_ctl = copymsg(mpctl);
5737c478bd9Sstevel@tonic-gate 	mp_rem_ctl = copymsg(mpctl);
57445916cd2Sjpk 	mp_attr_ctl = copymsg(mpctl);
575*78a2e113SAndy Fiddaman 	mp_info_ctl = copymsg(mpctl);
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	mpdata = mpctl->b_cont;
5787c478bd9Sstevel@tonic-gate 
57945916cd2Sjpk 	if (mp_conn_ctl == NULL || mp_local_ctl == NULL ||
580*78a2e113SAndy Fiddaman 	    mp_rem_ctl == NULL || mp_attr_ctl == NULL || mp_info_ctl == NULL ||
581*78a2e113SAndy Fiddaman 	    mpdata == NULL) {
582*78a2e113SAndy Fiddaman 		freemsg(mp_info_ctl);
58345916cd2Sjpk 		freemsg(mp_attr_ctl);
5847c478bd9Sstevel@tonic-gate 		freemsg(mp_rem_ctl);
5857c478bd9Sstevel@tonic-gate 		freemsg(mp_local_ctl);
5867c478bd9Sstevel@tonic-gate 		freemsg(mp_conn_ctl);
5877c478bd9Sstevel@tonic-gate 		freemsg(mp_ret);
5887c478bd9Sstevel@tonic-gate 		freemsg(mpctl);
5897c478bd9Sstevel@tonic-gate 		return (NULL);
5907c478bd9Sstevel@tonic-gate 	}
5917c478bd9Sstevel@tonic-gate 	mp_conn_data = mp_conn_ctl->b_cont;
5927c478bd9Sstevel@tonic-gate 	mp_local_data = mp_local_ctl->b_cont;
5937c478bd9Sstevel@tonic-gate 	mp_rem_data = mp_rem_ctl->b_cont;
59445916cd2Sjpk 	mp_attr_data = mp_attr_ctl->b_cont;
595*78a2e113SAndy Fiddaman 	mp_info_data = mp_info_ctl->b_cont;
5967c478bd9Sstevel@tonic-gate 
5975dd46ab5SKacheong Poon 	bzero(&sctp_mib, sizeof (sctp_mib));
5985dd46ab5SKacheong Poon 
599*78a2e113SAndy Fiddaman 	/* hostname address parameters are not supported in illumos */
6007c478bd9Sstevel@tonic-gate 	sce.sctpAssocRemHostName.o_length = 0;
6017c478bd9Sstevel@tonic-gate 	sce.sctpAssocRemHostName.o_bytes[0] = 0;
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate 	/* build table of connections -- need count in fixed part */
6047c478bd9Sstevel@tonic-gate 
60545916cd2Sjpk 	idx = 0;
606f4b3ec61Sdh 	mutex_enter(&sctps->sctps_g_lock);
607bd670b35SErik Nordmark 	sctp = list_head(&sctps->sctps_g_list);
6087c478bd9Sstevel@tonic-gate 	while (sctp != NULL) {
6097c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp->sctp_reflock);
6107c478bd9Sstevel@tonic-gate 		if (sctp->sctp_condemned) {
6117c478bd9Sstevel@tonic-gate 			mutex_exit(&sctp->sctp_reflock);
612f4b3ec61Sdh 			sctp = list_next(&sctps->sctps_g_list, sctp);
6137c478bd9Sstevel@tonic-gate 			continue;
6147c478bd9Sstevel@tonic-gate 		}
6157c478bd9Sstevel@tonic-gate 		sctp->sctp_refcnt++;
6167c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp->sctp_reflock);
617f4b3ec61Sdh 		mutex_exit(&sctps->sctps_g_lock);
6187c478bd9Sstevel@tonic-gate 		if (sctp_prev != NULL)
6197c478bd9Sstevel@tonic-gate 			SCTP_REFRELE(sctp_prev);
6207c478bd9Sstevel@tonic-gate 		if (sctp->sctp_connp->conn_zoneid != zoneid)
6217c478bd9Sstevel@tonic-gate 			goto next_sctp;
6227c478bd9Sstevel@tonic-gate 		if (sctp->sctp_state == SCTPS_ESTABLISHED ||
6237c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_PENDING ||
6247c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_RECEIVED) {
6255dd46ab5SKacheong Poon 			/*
6265dd46ab5SKacheong Poon 			 * Just bump the local sctp_mib.  The number of
6275dd46ab5SKacheong Poon 			 * existing associations is not kept in kernel.
6285dd46ab5SKacheong Poon 			 */
6295dd46ab5SKacheong Poon 			BUMP_MIB(&sctp_mib, sctpCurrEstab);
6307c478bd9Sstevel@tonic-gate 		}
6315dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpOutSCTPPkts, sctp->sctp_opkts);
6327c478bd9Sstevel@tonic-gate 		sctp->sctp_opkts = 0;
6335dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpOutCtrlChunks, sctp->sctp_obchunks);
63435e12f9cSGeorge Shepherd 		UPDATE_LOCAL(sctp->sctp_cum_obchunks,
63535e12f9cSGeorge Shepherd 		    sctp->sctp_obchunks);
6367c478bd9Sstevel@tonic-gate 		sctp->sctp_obchunks = 0;
6375dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpOutOrderChunks,
6385dd46ab5SKacheong Poon 		    sctp->sctp_odchunks);
63935e12f9cSGeorge Shepherd 		UPDATE_LOCAL(sctp->sctp_cum_odchunks,
64035e12f9cSGeorge Shepherd 		    sctp->sctp_odchunks);
6417c478bd9Sstevel@tonic-gate 		sctp->sctp_odchunks = 0;
6425dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpOutUnorderChunks,
6437c478bd9Sstevel@tonic-gate 		    sctp->sctp_oudchunks);
64435e12f9cSGeorge Shepherd 		UPDATE_LOCAL(sctp->sctp_cum_oudchunks,
64535e12f9cSGeorge Shepherd 		    sctp->sctp_oudchunks);
6467c478bd9Sstevel@tonic-gate 		sctp->sctp_oudchunks = 0;
6475dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpRetransChunks,
6485dd46ab5SKacheong Poon 		    sctp->sctp_rxtchunks);
64935e12f9cSGeorge Shepherd 		UPDATE_LOCAL(sctp->sctp_cum_rxtchunks,
65035e12f9cSGeorge Shepherd 		    sctp->sctp_rxtchunks);
6517c478bd9Sstevel@tonic-gate 		sctp->sctp_rxtchunks = 0;
6525dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpInSCTPPkts, sctp->sctp_ipkts);
6537c478bd9Sstevel@tonic-gate 		sctp->sctp_ipkts = 0;
6545dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpInCtrlChunks, sctp->sctp_ibchunks);
65535e12f9cSGeorge Shepherd 		UPDATE_LOCAL(sctp->sctp_cum_ibchunks,
65635e12f9cSGeorge Shepherd 		    sctp->sctp_ibchunks);
6577c478bd9Sstevel@tonic-gate 		sctp->sctp_ibchunks = 0;
6585dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpInOrderChunks, sctp->sctp_idchunks);
65935e12f9cSGeorge Shepherd 		UPDATE_LOCAL(sctp->sctp_cum_idchunks,
66035e12f9cSGeorge Shepherd 		    sctp->sctp_idchunks);
6617c478bd9Sstevel@tonic-gate 		sctp->sctp_idchunks = 0;
6625dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpInUnorderChunks,
6637c478bd9Sstevel@tonic-gate 		    sctp->sctp_iudchunks);
66435e12f9cSGeorge Shepherd 		UPDATE_LOCAL(sctp->sctp_cum_iudchunks,
66535e12f9cSGeorge Shepherd 		    sctp->sctp_iudchunks);
6667c478bd9Sstevel@tonic-gate 		sctp->sctp_iudchunks = 0;
6675dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpFragUsrMsgs, sctp->sctp_fragdmsgs);
6687c478bd9Sstevel@tonic-gate 		sctp->sctp_fragdmsgs = 0;
6695dd46ab5SKacheong Poon 		SCTPS_UPDATE_MIB(sctps, sctpReasmUsrMsgs, sctp->sctp_reassmsgs);
6707c478bd9Sstevel@tonic-gate 		sctp->sctp_reassmsgs = 0;
6717c478bd9Sstevel@tonic-gate