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 /*
23fd7b5aedSGeorge Shepherd  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_INET_SCTP_SCTP_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_INET_SCTP_SCTP_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
307c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
317c478bd9Sstevel@tonic-gate #include <sys/list.h>
327c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
3345916cd2Sjpk #include <sys/zone.h>
345dd46ab5SKacheong Poon #include <sys/cpuvar.h>
355dd46ab5SKacheong Poon #include <sys/clock_impl.h>
365dd46ab5SKacheong Poon 
377c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
387c478bd9Sstevel@tonic-gate #include <inet/optcom.h>
396e91bba0SGirish Moodalbail #include <inet/tunables.h>
407c478bd9Sstevel@tonic-gate #include <netinet/sctp.h>
417c478bd9Sstevel@tonic-gate #include <inet/sctp_itf.h>
42f4b3ec61Sdh #include "sctp_stack.h"
43f4b3ec61Sdh 
44f4b3ec61Sdh #ifdef	__cplusplus
45f4b3ec61Sdh extern "C" {
46f4b3ec61Sdh #endif
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /* Streams device identifying info and version */
497c478bd9Sstevel@tonic-gate #define	SCTP_DEV_IDINFO	"SCTP Streams device 1.0"
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	SSN_GT(a, b)	((int16_t)((a)-(b)) > 0)
527c478bd9Sstevel@tonic-gate #define	SSN_GE(a, b)	((int16_t)((a)-(b)) >= 0)
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /* Default buffer size and flow control wake up threshold. */
557c478bd9Sstevel@tonic-gate #define	SCTP_XMIT_LOWATER	8192
567c478bd9Sstevel@tonic-gate #define	SCTP_XMIT_HIWATER	102400
577c478bd9Sstevel@tonic-gate #define	SCTP_RECV_LOWATER	8192
587c478bd9Sstevel@tonic-gate #define	SCTP_RECV_HIWATER	102400
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* SCTP Timer control structure */
617c478bd9Sstevel@tonic-gate typedef struct sctpt_s {
627c478bd9Sstevel@tonic-gate 	pfv_t	sctpt_pfv;	/* The routine we are to call */
637c478bd9Sstevel@tonic-gate 	struct sctp_s *sctpt_sctp;	/* The parameter we are to pass in */
647c478bd9Sstevel@tonic-gate 	struct sctp_faddr_s *sctpt_faddr;
657c478bd9Sstevel@tonic-gate } sctpt_t;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * Maximum number of duplicate TSNs we can report. This is currently
697c478bd9Sstevel@tonic-gate  * static, and governs the size of the mblk used to hold the duplicate
707c478bd9Sstevel@tonic-gate  * reports. The use of duplcate TSN reports is currently experimental,
717c478bd9Sstevel@tonic-gate  * so for now a static limit should suffice.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate #define	SCTP_DUP_MBLK_SZ	64
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #define	SCTP_IS_ADDR_UNSPEC(isv4, addr)		\
767c478bd9Sstevel@tonic-gate 	((isv4) ? IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) :	\
777c478bd9Sstevel@tonic-gate 	IN6_IS_ADDR_UNSPECIFIED(&(addr)))
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
806e91bba0SGirish Moodalbail  * SCTP properties/tunables
817c478bd9Sstevel@tonic-gate  */
826e91bba0SGirish Moodalbail #define	sctps_max_init_retr		sctps_propinfo_tbl[0].prop_cur_uval
836e91bba0SGirish Moodalbail #define	sctps_max_init_retr_high	sctps_propinfo_tbl[0].prop_max_uval
846e91bba0SGirish Moodalbail #define	sctps_max_init_retr_low		sctps_propinfo_tbl[0].prop_min_uval
856e91bba0SGirish Moodalbail #define	sctps_pa_max_retr		sctps_propinfo_tbl[1].prop_cur_uval
866e91bba0SGirish Moodalbail #define	sctps_pa_max_retr_high		sctps_propinfo_tbl[1].prop_max_uval
876e91bba0SGirish Moodalbail #define	sctps_pa_max_retr_low		sctps_propinfo_tbl[1].prop_min_uval
886e91bba0SGirish Moodalbail #define	sctps_pp_max_retr		sctps_propinfo_tbl[2].prop_cur_uval
896e91bba0SGirish Moodalbail #define	sctps_pp_max_retr_high		sctps_propinfo_tbl[2].prop_max_uval
906e91bba0SGirish Moodalbail #define	sctps_pp_max_retr_low		sctps_propinfo_tbl[2].prop_min_uval
916e91bba0SGirish Moodalbail #define	sctps_cwnd_max_			sctps_propinfo_tbl[3].prop_cur_uval
926e91bba0SGirish Moodalbail #define	sctps_smallest_nonpriv_port	sctps_propinfo_tbl[4].prop_cur_uval
936e91bba0SGirish Moodalbail #define	sctps_ipv4_ttl			sctps_propinfo_tbl[5].prop_cur_uval
946e91bba0SGirish Moodalbail #define	sctps_heartbeat_interval	sctps_propinfo_tbl[6].prop_cur_uval
956e91bba0SGirish Moodalbail #define	sctps_heartbeat_interval_high	sctps_propinfo_tbl[6].prop_max_uval
966e91bba0SGirish Moodalbail #define	sctps_heartbeat_interval_low	sctps_propinfo_tbl[6].prop_min_uval
976e91bba0SGirish Moodalbail #define	sctps_initial_mtu		sctps_propinfo_tbl[7].prop_cur_uval
986e91bba0SGirish Moodalbail #define	sctps_mtu_probe_interval	sctps_propinfo_tbl[8].prop_cur_uval
996e91bba0SGirish Moodalbail #define	sctps_new_secret_interval	sctps_propinfo_tbl[9].prop_cur_uval
1006e91bba0SGirish Moodalbail #define	sctps_deferred_ack_interval	sctps_propinfo_tbl[10].prop_cur_uval
1016e91bba0SGirish Moodalbail #define	sctps_snd_lowat_fraction	sctps_propinfo_tbl[11].prop_cur_uval
1026e91bba0SGirish Moodalbail #define	sctps_ignore_path_mtu		sctps_propinfo_tbl[12].prop_cur_bval
1036e91bba0SGirish Moodalbail #define	sctps_initial_ssthresh		sctps_propinfo_tbl[13].prop_cur_uval
1046e91bba0SGirish Moodalbail #define	sctps_smallest_anon_port	sctps_propinfo_tbl[14].prop_cur_uval
1056e91bba0SGirish Moodalbail #define	sctps_largest_anon_port		sctps_propinfo_tbl[15].prop_cur_uval
1066e91bba0SGirish Moodalbail #define	sctps_xmit_hiwat		sctps_propinfo_tbl[16].prop_cur_uval
1076e91bba0SGirish Moodalbail #define	sctps_xmit_lowat		sctps_propinfo_tbl[17].prop_cur_uval
1086e91bba0SGirish Moodalbail #define	sctps_recv_hiwat		sctps_propinfo_tbl[18].prop_cur_uval
1096e91bba0SGirish Moodalbail #define	sctps_max_buf			sctps_propinfo_tbl[19].prop_cur_uval
1106e91bba0SGirish Moodalbail #define	sctps_rtt_updates		sctps_propinfo_tbl[20].prop_cur_uval
1116e91bba0SGirish Moodalbail #define	sctps_ipv6_hoplimit		sctps_propinfo_tbl[21].prop_cur_uval
1126e91bba0SGirish Moodalbail #define	sctps_rto_ming			sctps_propinfo_tbl[22].prop_cur_uval
1136e91bba0SGirish Moodalbail #define	sctps_rto_ming_high		sctps_propinfo_tbl[22].prop_max_uval
1146e91bba0SGirish Moodalbail #define	sctps_rto_ming_low		sctps_propinfo_tbl[22].prop_min_uval
1156e91bba0SGirish Moodalbail #define	sctps_rto_maxg			sctps_propinfo_tbl[23].prop_cur_uval
1166e91bba0SGirish Moodalbail #define	sctps_rto_maxg_high		sctps_propinfo_tbl[23].prop_max_uval
1176e91bba0SGirish Moodalbail #define	sctps_rto_maxg_low		sctps_propinfo_tbl[23].prop_min_uval
1186e91bba0SGirish Moodalbail #define	sctps_rto_initialg		sctps_propinfo_tbl[24].prop_cur_uval
1196e91bba0SGirish Moodalbail #define	sctps_rto_initialg_high		sctps_propinfo_tbl[24].prop_max_uval
1206e91bba0SGirish Moodalbail #define	sctps_rto_initialg_low		sctps_propinfo_tbl[24].prop_min_uval
1216e91bba0SGirish Moodalbail #define	sctps_cookie_life		sctps_propinfo_tbl[25].prop_cur_uval
1226e91bba0SGirish Moodalbail #define	sctps_cookie_life_high		sctps_propinfo_tbl[25].prop_max_uval
1236e91bba0SGirish Moodalbail #define	sctps_cookie_life_low		sctps_propinfo_tbl[25].prop_min_uval
1246e91bba0SGirish Moodalbail #define	sctps_max_in_streams		sctps_propinfo_tbl[26].prop_cur_uval
1256e91bba0SGirish Moodalbail #define	sctps_max_in_streams_high	sctps_propinfo_tbl[26].prop_max_uval
1266e91bba0SGirish Moodalbail #define	sctps_max_in_streams_low	sctps_propinfo_tbl[26].prop_min_uval
1276e91bba0SGirish Moodalbail #define	sctps_initial_out_streams	sctps_propinfo_tbl[27].prop_cur_uval
1286e91bba0SGirish Moodalbail #define	sctps_initial_out_streams_high	sctps_propinfo_tbl[27].prop_max_uval
1296e91bba0SGirish Moodalbail #define	sctps_initial_out_streams_low	sctps_propinfo_tbl[27].prop_min_uval
1306e91bba0SGirish Moodalbail #define	sctps_shutack_wait_bound	sctps_propinfo_tbl[28].prop_cur_uval
1316e91bba0SGirish Moodalbail #define	sctps_maxburst			sctps_propinfo_tbl[29].prop_cur_uval
1326e91bba0SGirish Moodalbail #define	sctps_addip_enabled		sctps_propinfo_tbl[30].prop_cur_bval
1336e91bba0SGirish Moodalbail #define	sctps_recv_hiwat_minmss		sctps_propinfo_tbl[31].prop_cur_uval
1346e91bba0SGirish Moodalbail #define	sctps_slow_start_initial	sctps_propinfo_tbl[32].prop_cur_uval
1356e91bba0SGirish Moodalbail #define	sctps_slow_start_after_idle	sctps_propinfo_tbl[33].prop_cur_uval
1366e91bba0SGirish Moodalbail #define	sctps_prsctp_enabled		sctps_propinfo_tbl[34].prop_cur_bval
1376e91bba0SGirish Moodalbail #define	sctps_fast_rxt_thresh		sctps_propinfo_tbl[35].prop_cur_uval
1386e91bba0SGirish Moodalbail #define	sctps_deferred_acks_max		sctps_propinfo_tbl[36].prop_cur_uval
1396e91bba0SGirish Moodalbail #define	sctps_wroff_xtra		sctps_propinfo_tbl[37].prop_cur_uval
1407c478bd9Sstevel@tonic-gate 
14177c67f2fSkcpoon /*
14277c67f2fSkcpoon  * Retransmission timer start and stop macro for a given faddr.
14377c67f2fSkcpoon  */
14477c67f2fSkcpoon #define	SCTP_FADDR_TIMER_RESTART(sctp, fp, intvl)			\
14577c67f2fSkcpoon {									\
14677c67f2fSkcpoon 	dprint(3, ("faddr_timer_restart: fp=%p %x:%x:%x:%x %d\n",	\
1476be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	    (void *)(fp), SCTP_PRINTADDR((fp)->sf_faddr), (int)(intvl))); \
1486be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	sctp_timer((sctp), (fp)->sf_timer_mp, (intvl));			\
1496be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	(fp)->sf_timer_running = 1;					\
15077c67f2fSkcpoon }
15177c67f2fSkcpoon 
15277c67f2fSkcpoon #define	SCTP_FADDR_TIMER_STOP(fp)			\
1536be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	ASSERT((fp)->sf_timer_mp != NULL);		\
1546be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	if ((fp)->sf_timer_running) {			\
1556be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 		sctp_timer_stop((fp)->sf_timer_mp);	\
1566be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 		(fp)->sf_timer_running = 0;		\
15777c67f2fSkcpoon 	}
15877c67f2fSkcpoon 
1599f13099eSGeorge Shepherd /* For per endpoint association statistics */
1609f13099eSGeorge Shepherd #define	SCTP_MAX_RTO(sctp, fp) {			\
1619f13099eSGeorge Shepherd 	/*						\
1629f13099eSGeorge Shepherd 	 * Record the maximum observed RTO,		\
1639f13099eSGeorge Shepherd 	 * sctp_maxrto is zeroed elsewhere		\
1649f13099eSGeorge Shepherd 	 * at the end of each stats request.		\
1659f13099eSGeorge Shepherd 	 */						\
1669f13099eSGeorge Shepherd 	(sctp)->sctp_maxrto =				\
1676be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	    MAX((sctp)->sctp_maxrto, (fp)->sf_rto);	\
1689f13099eSGeorge Shepherd 	DTRACE_PROBE2(sctp__maxrto, sctp_t *,		\
1699f13099eSGeorge Shepherd 	    sctp, struct sctp_faddr_s, fp);		\
1709f13099eSGeorge Shepherd }
1719f13099eSGeorge Shepherd 
172fd7b5aedSGeorge Shepherd #define	SCTP_CALC_RXT(sctp, fp, max)	\
173fd7b5aedSGeorge Shepherd {					\
1746be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	if (((fp)->sf_rto <<= 1) > (max))	\
1756be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 		(fp)->sf_rto = (max);	\
176fd7b5aedSGeorge Shepherd 	SCTP_MAX_RTO(sctp, fp);		\
17777c67f2fSkcpoon }
17877c67f2fSkcpoon 
17977c67f2fSkcpoon 
1807c478bd9Sstevel@tonic-gate #define	SCTP_MAX_COMBINED_HEADER_LENGTH	(60 + 12) /* Maxed out ip + sctp */
1817c478bd9Sstevel@tonic-gate #define	SCTP_MAX_IP_OPTIONS_LENGTH	(60 - IP_SIMPLE_HDR_LENGTH)
1827c478bd9Sstevel@tonic-gate #define	SCTP_MAX_HDR_LENGTH		60
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate #define	SCTP_SECRET_LEN	16
1857c478bd9Sstevel@tonic-gate 
18692baa190SGeorge Shepherd #define	SCTP_REFHOLD(sctp) {				\
1877c478bd9Sstevel@tonic-gate 	mutex_enter(&(sctp)->sctp_reflock);		\
18892baa190SGeorge Shepherd 	(sctp)->sctp_refcnt++;				\
18992baa190SGeorge Shepherd 	DTRACE_PROBE1(sctp_refhold, sctp_t, sctp);	\
1907c478bd9Sstevel@tonic-gate 	ASSERT((sctp)->sctp_refcnt != 0);		\
19192baa190SGeorge Shepherd 	mutex_exit(&(sctp)->sctp_reflock);		\
19292baa190SGeorge Shepherd }
19392baa190SGeorge Shepherd 
19492baa190SGeorge Shepherd #define	SCTP_REFRELE(sctp) {					\
19592baa190SGeorge Shepherd 	mutex_enter(&(sctp)->sctp_reflock);			\
19692baa190SGeorge Shepherd 	ASSERT((sctp)->sctp_refcnt != 0);			\
19792baa190SGeorge Shepherd 	if (--(sctp)->sctp_refcnt == 0) {			\
19892baa190SGeorge Shepherd 		DTRACE_PROBE1(sctp_refrele, sctp_t, sctp);	\
19992baa190SGeorge Shepherd 		mutex_exit(&(sctp)->sctp_reflock);		\
20092baa190SGeorge Shepherd 		CONN_DEC_REF((sctp)->sctp_connp);		\
20192baa190SGeorge Shepherd 	} else {						\
20292baa190SGeorge Shepherd 		DTRACE_PROBE1(sctp_refrele, sctp_t, sctp);	\
20392baa190SGeorge Shepherd 		mutex_exit(&(sctp)->sctp_reflock);		\
20492baa190SGeorge Shepherd 	}							\
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate #define	SCTP_PRINTADDR(a)	(a).s6_addr32[0], (a).s6_addr32[1],\
2087c478bd9Sstevel@tonic-gate 				(a).s6_addr32[2], (a).s6_addr32[3]
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate #define	CONN2SCTP(conn)	((sctp_t *)(&((conn_t *)conn)[1]))
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate  * Outbound data, flags and macros for per-message, per-chunk info
2147c478bd9Sstevel@tonic-gate  */
2157c478bd9Sstevel@tonic-gate typedef struct {
2167c478bd9Sstevel@tonic-gate 	int64_t		smh_ttl;		/* Time to Live */
2177c478bd9Sstevel@tonic-gate 	int64_t		smh_tob;		/* Time of Birth */
2187c478bd9Sstevel@tonic-gate 	uint32_t	smh_context;
2197c478bd9Sstevel@tonic-gate 	uint16_t	smh_sid;
2207c478bd9Sstevel@tonic-gate 	uint16_t	smh_ssn;
2217c478bd9Sstevel@tonic-gate 	uint32_t	smh_ppid;
2227c478bd9Sstevel@tonic-gate 	uint16_t	smh_flags;
2237c478bd9Sstevel@tonic-gate 	uint32_t	smh_msglen;
2247c478bd9Sstevel@tonic-gate } sctp_msg_hdr_t;
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_FLAG_SENT		0x01
2277c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_FLAG_REXMIT		0x02
2287c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_FLAG_ACKED		0x04
2297c478bd9Sstevel@tonic-gate #define	SCTP_MSG_FLAG_CHUNKED		0x08
2307c478bd9Sstevel@tonic-gate #define	SCTP_MSG_FLAG_ABANDONED		0x10
2317c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_FLAG_ABANDONED	0x20
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_CLEAR_FLAGS(mp) ((mp)->b_flag = 0)
2347c478bd9Sstevel@tonic-gate /*
2357c478bd9Sstevel@tonic-gate  * If we are transmitting the chunk for the first time we assign the TSN and
2367c478bd9Sstevel@tonic-gate  * SSN here. The reason we assign the SSN here (as opposed to doing it in
2377c478bd9Sstevel@tonic-gate  * sctp_chunkify()) is that the chunk may expire, if PRSCTP is enabled, before
2387c478bd9Sstevel@tonic-gate  * we get a chance to send it out. If we assign the SSN in sctp_chunkify()
2397c478bd9Sstevel@tonic-gate  * and this happens, then we need to send a Forward TSN to the peer, which
2407c478bd9Sstevel@tonic-gate  * will be expecting this SSN, assuming ordered. If we assign it here we
2417c478bd9Sstevel@tonic-gate  * can just take out the chunk from the transmit list without having to
2427c478bd9Sstevel@tonic-gate  * send a Forward TSN chunk. While assigning the SSN we use (meta)->b_cont
2437c478bd9Sstevel@tonic-gate  * to determine if it needs a new SSN (i.e. the next SSN for the stream),
2447c478bd9Sstevel@tonic-gate  * since (meta)->b_cont signifies the first chunk of a message (if the message
2457c478bd9Sstevel@tonic-gate  * is unordered, then the SSN is 0).
2467c478bd9Sstevel@tonic-gate  *
2477c478bd9Sstevel@tonic-gate  */
2487c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_SENT(sctp, mp, sdc, fp, chunkdata, meta) {		\
2497c478bd9Sstevel@tonic-gate 	if (!SCTP_CHUNK_ISSENT(mp)) {					\
2507c478bd9Sstevel@tonic-gate 		sctp_msg_hdr_t	*mhdr = (sctp_msg_hdr_t *)(meta)->b_rptr; \
2517c478bd9Sstevel@tonic-gate 		ASSERT(!SCTP_CHUNK_ABANDONED(mp));			\
2527c478bd9Sstevel@tonic-gate 		(mp)->b_flag = SCTP_CHUNK_FLAG_SENT;			\
2537c478bd9Sstevel@tonic-gate 		(sdc)->sdh_tsn = htonl((sctp)->sctp_ltsn++);		\
2547c478bd9Sstevel@tonic-gate 		if ((mhdr)->smh_flags & MSG_UNORDERED) {		\
2557c478bd9Sstevel@tonic-gate 			(sdc)->sdh_ssn = 0;				\
2567c478bd9Sstevel@tonic-gate 			SCTP_DATA_SET_UBIT(sdc);			\
2577c478bd9Sstevel@tonic-gate 			BUMP_LOCAL((sctp)->sctp_oudchunks);		\
2587c478bd9Sstevel@tonic-gate 		} else {						\
2597c478bd9Sstevel@tonic-gate 			BUMP_LOCAL((sctp)->sctp_odchunks);		\
2607c478bd9Sstevel@tonic-gate 			if ((mp) == (meta)->b_cont) {			\
2617c478bd9Sstevel@tonic-gate 				mhdr->smh_ssn = htons(			\
2627c478bd9Sstevel@tonic-gate 				    (sctp)->sctp_ostrcntrs[mhdr->smh_sid]++); \
2637c478bd9Sstevel@tonic-gate 			}						\
2647c478bd9Sstevel@tonic-gate 			(sdc)->sdh_ssn = mhdr->smh_ssn;			\
2657c478bd9Sstevel@tonic-gate 		}							\
266c3c17166SGeorge Shepherd 		DTRACE_PROBE3(sctp__chunk__sent1, sctp_t *, sctp,	\
267c3c17166SGeorge Shepherd 		    mblk_t *, mp, mblk_t *, meta);			\
2687c478bd9Sstevel@tonic-gate 		(sctp)->sctp_unacked += (chunkdata);			\
2697c478bd9Sstevel@tonic-gate 		(sctp)->sctp_unsent -= (chunkdata);			\
2707c478bd9Sstevel@tonic-gate 		(sctp)->sctp_frwnd -= (chunkdata);			\
2717c478bd9Sstevel@tonic-gate 	} else {							\
2727c478bd9Sstevel@tonic-gate 		if (SCTP_CHUNK_ISACKED(mp)) {				\
2737c478bd9Sstevel@tonic-gate 			(sctp)->sctp_unacked += (chunkdata);		\
2747c478bd9Sstevel@tonic-gate 		} else {						\
2756be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 			ASSERT(SCTP_CHUNK_DEST(mp)->sf_suna >= ((chunkdata) + \
2767c478bd9Sstevel@tonic-gate 							sizeof (*sdc))); \
2776be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 			SCTP_CHUNK_DEST(mp)->sf_suna -= ((chunkdata) + 	\
2787c478bd9Sstevel@tonic-gate 					sizeof (*sdc));			\
2797c478bd9Sstevel@tonic-gate 		}							\
280c3c17166SGeorge Shepherd 		DTRACE_PROBE3(sctp__chunk__sent2, sctp_t *, sctp,	\
281c3c17166SGeorge Shepherd 		    mblk_t *, mp, mblk_t *, meta);			\
2827c478bd9Sstevel@tonic-gate 		(mp)->b_flag &= ~(SCTP_CHUNK_FLAG_REXMIT |		\
2837c478bd9Sstevel@tonic-gate 			SCTP_CHUNK_FLAG_ACKED);				\
2847c478bd9Sstevel@tonic-gate 		SCTP_CHUNK_SET_SACKCNT(mp, 0);				\
2857c478bd9Sstevel@tonic-gate 		BUMP_LOCAL(sctp->sctp_rxtchunks);			\
2867c478bd9Sstevel@tonic-gate 		BUMP_LOCAL((sctp)->sctp_T3expire);			\
2876be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 		BUMP_LOCAL((fp)->sf_T3expire);				\
2887c478bd9Sstevel@tonic-gate 	}								\
2897c478bd9Sstevel@tonic-gate 	SCTP_SET_CHUNK_DEST(mp, fp);					\
2906be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	(fp)->sf_suna += ((chunkdata) + sizeof (*sdc));			\
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_ISSENT(mp)	((mp)->b_flag & SCTP_CHUNK_FLAG_SENT)
2947c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_CANSEND(mp)	\
2957c478bd9Sstevel@tonic-gate 	(!(SCTP_CHUNK_ABANDONED(mp)) &&	\
2967c478bd9Sstevel@tonic-gate 	(((mp)->b_flag & (SCTP_CHUNK_FLAG_REXMIT|SCTP_CHUNK_FLAG_SENT)) != \
2977c478bd9Sstevel@tonic-gate 	SCTP_CHUNK_FLAG_SENT))
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_DEST(mp)		((sctp_faddr_t *)(mp)->b_queue)
3007c478bd9Sstevel@tonic-gate #define	SCTP_SET_CHUNK_DEST(mp, fp)	((mp)->b_queue = (queue_t *)fp)
3017c478bd9Sstevel@tonic-gate 
302c3c17166SGeorge Shepherd #define	SCTP_CHUNK_REXMIT(sctp, mp) {					\
303c3c17166SGeorge Shepherd 	DTRACE_PROBE2(sctp__chunk__rexmit, sctp_t *, sctp, mblk_t *,	\
304c3c17166SGeorge Shepherd 	    mp);							\
305c3c17166SGeorge Shepherd 	(mp)->b_flag |= SCTP_CHUNK_FLAG_REXMIT; 			\
306c3c17166SGeorge Shepherd }
3077c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_CLEAR_REXMIT(mp) ((mp)->b_flag &= ~SCTP_CHUNK_FLAG_REXMIT)
3087c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_WANT_REXMIT(mp) ((mp)->b_flag & SCTP_CHUNK_FLAG_REXMIT)
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_ACKED(mp) \
3117c478bd9Sstevel@tonic-gate 	((mp)->b_flag = (SCTP_CHUNK_FLAG_SENT|SCTP_CHUNK_FLAG_ACKED))
3127c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_ISACKED(mp)	((mp)->b_flag & SCTP_CHUNK_FLAG_ACKED)
313c3c17166SGeorge Shepherd #define	SCTP_CHUNK_CLEAR_ACKED(sctp, mp) {				\
314c3c17166SGeorge Shepherd 	DTRACE_PROBE2(sctp__chunk__clracked, sctp_t *, sctp, mblk_t *,	\
315c3c17166SGeorge Shepherd 	    mp);							\
316c3c17166SGeorge Shepherd 	(mp)->b_flag &= ~SCTP_CHUNK_FLAG_ACKED;				\
317c3c17166SGeorge Shepherd }
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_SACKCNT(mp)	((intptr_t)((mp)->b_prev))
3207c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_SET_SACKCNT(mp, val) ((mp)->b_prev = \
3217c478bd9Sstevel@tonic-gate 					(mblk_t *)(uintptr_t)(val))
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate #define	SCTP_MSG_SET_CHUNKED(mp)	((mp)->b_flag |= SCTP_MSG_FLAG_CHUNKED)
3247c478bd9Sstevel@tonic-gate #define	SCTP_MSG_CLEAR_CHUNKED(mp)((mp)->b_flag &= ~SCTP_MSG_FLAG_CHUNKED)
3257c478bd9Sstevel@tonic-gate #define	SCTP_IS_MSG_CHUNKED(mp)	((mp)->b_flag & SCTP_MSG_FLAG_CHUNKED)
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate /* For PR-SCTP */
3287c478bd9Sstevel@tonic-gate #define	SCTP_ABANDON_CHUNK(mp)	((mp)->b_flag |= SCTP_CHUNK_FLAG_ABANDONED)
3297c478bd9Sstevel@tonic-gate #define	SCTP_CHUNK_ABANDONED(mp) \
3307c478bd9Sstevel@tonic-gate 	((mp)->b_flag & SCTP_CHUNK_FLAG_ABANDONED)
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate #define	SCTP_MSG_SET_ABANDONED(mp)	\
3337c478bd9Sstevel@tonic-gate 	((mp)->b_flag |= SCTP_MSG_FLAG_ABANDONED)
3347c478bd9Sstevel@tonic-gate #define	SCTP_MSG_CLEAR_ABANDONED(mp)((mp)->b_flag &= ~SCTP_MSG_FLAG_ABANDONED)
3357c478bd9Sstevel@tonic-gate #define	SCTP_IS_MSG_ABANDONED(mp)	((mp)->b_flag & SCTP_MSG_FLAG_ABANDONED)
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate  * Check if a message has expired.  A message is expired if
3397c478bd9Sstevel@tonic-gate  *	1. It has a non-zero time to live value and has not been sent before
3407c478bd9Sstevel@tonic-gate  *	that time expires.
3417c478bd9Sstevel@tonic-gate  *	2. It is sent using PRSCTP and it has not been SACK'ed before
3427c478bd9Sstevel@tonic-gate  *	its lifetime expires.
3437c478bd9Sstevel@tonic-gate  */
3447c478bd9Sstevel@tonic-gate #define	SCTP_MSG_TO_BE_ABANDONED(meta, mhdr, sctp)			     \
3457c478bd9Sstevel@tonic-gate 	(((!SCTP_CHUNK_ISSENT((meta)->b_cont) && (mhdr)->smh_ttl > 0) ||     \
3467c478bd9Sstevel@tonic-gate 	((sctp)->sctp_prsctp_aware && ((mhdr)->smh_flags & MSG_PR_SCTP))) && \
347d3d50737SRafael Vanoni 	((ddi_get_lbolt64() - (mhdr)->smh_tob) > (mhdr)->smh_ttl))
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate /* SCTP association hash function. */
350f4b3ec61Sdh #define	SCTP_CONN_HASH(sctps, ports)			\
351f4b3ec61Sdh 	((((ports) ^ ((ports) >> 16)) * 31) & 		\
352f4b3ec61Sdh 	    ((sctps)->sctps_conn_hash_size - 1))
3537c478bd9Sstevel@tonic-gate 
3545dd46ab5SKacheong Poon /*
3555dd46ab5SKacheong Poon  * Linked list struct to store SCTP listener association limit configuration
3565dd46ab5SKacheong Poon  * per IP stack.  The list is stored at sctps_listener_conf in sctp_stack_t.
3575dd46ab5SKacheong Poon  *
3585dd46ab5SKacheong Poon  * sl_port: the listener port of this limit configuration
3595dd46ab5SKacheong Poon  * sl_ratio: the maximum amount of memory consumed by all concurrent SCTP
3605dd46ab5SKacheong Poon  *           connections created by a listener does not exceed 1/tl_ratio
3615dd46ab5SKacheong Poon  *           of the total system memory.  Note that this is only an
3625dd46ab5SKacheong Poon  *           approximation.
3635dd46ab5SKacheong Poon  * sl_link: linked list struct
3645dd46ab5SKacheong Poon  */
3655dd46ab5SKacheong Poon typedef struct sctp_listener_s {
3665dd46ab5SKacheong Poon 	in_port_t	sl_port;
3675dd46ab5SKacheong Poon 	uint32_t	sl_ratio;
3685dd46ab5SKacheong Poon 	list_node_t	sl_link;
3695dd46ab5SKacheong Poon } sctp_listener_t;
3705dd46ab5SKacheong Poon 
3715dd46ab5SKacheong Poon /*
3725dd46ab5SKacheong Poon  * If there is a limit set on the number of association allowed per each
3735dd46ab5SKacheong Poon  * listener, the following struct is used to store that counter.  It keeps
3745dd46ab5SKacheong Poon  * the number of SCTP association created by a listener.  Note that this needs
3755dd46ab5SKacheong Poon  * to be separated from the listener since the listener can go away before
3765dd46ab5SKacheong Poon  * all the associations are gone.
3775dd46ab5SKacheong Poon  *
3785dd46ab5SKacheong Poon  * When the struct is allocated, slc_cnt is set to 1.  When a new association
3795dd46ab5SKacheong Poon  * is created by the listener, slc_cnt is incremented by 1.  When an
3805dd46ab5SKacheong Poon  * association created by the listener goes away, slc_count is decremented by
3815dd46ab5SKacheong Poon  * 1.  When the listener itself goes away, slc_cnt is decremented  by one.
3825dd46ab5SKacheong Poon  * The last association (or the listener) which decrements slc_cnt to zero
3835dd46ab5SKacheong Poon  * frees the struct.
3845dd46ab5SKacheong Poon  *
3855dd46ab5SKacheong Poon  * slc_max is the maximum number of concurrent associations created from a
3865dd46ab5SKacheong Poon  * listener.  It is calculated when the sctp_listen_cnt_t is allocated.
3875dd46ab5SKacheong Poon  *
3885dd46ab5SKacheong Poon  * slc_report_time stores the time when cmn_err() is called to report that the
3895dd46ab5SKacheong Poon  * max has been exceeeded.  Report is done at most once every
3905dd46ab5SKacheong Poon  * SCTP_SLC_REPORT_INTERVAL mins for a listener.
3915dd46ab5SKacheong Poon  *
3925dd46ab5SKacheong Poon  * slc_drop stores the number of connection attempt dropped because the
3935dd46ab5SKacheong Poon  * limit has reached.
3945dd46ab5SKacheong Poon  */
3955dd46ab5SKacheong Poon typedef struct sctp_listen_cnt_s {
3965dd46ab5SKacheong Poon 	uint32_t	slc_max;
3975dd46ab5SKacheong Poon 	uint32_t	slc_cnt;
3985dd46ab5SKacheong Poon 	int64_t		slc_report_time;
3995dd46ab5SKacheong Poon 	uint32_t	slc_drop;
4005dd46ab5SKacheong Poon } sctp_listen_cnt_t;
4015dd46ab5SKacheong Poon 
4025dd46ab5SKacheong Poon #define	SCTP_SLC_REPORT_INTERVAL	(30 * MINUTES)
4035dd46ab5SKacheong Poon 
4045dd46ab5SKacheong Poon #define	SCTP_DECR_LISTEN_CNT(sctp)					\
4055dd46ab5SKacheong Poon {									\
4065dd46ab5SKacheong Poon 	ASSERT((sctp)->sctp_listen_cnt->slc_cnt > 0);			\
407*1a5e258fSJosef 'Jeff' Sipek 	if (atomic_dec_32_nv(&(sctp)->sctp_listen_cnt->slc_cnt) == 0) \
4085dd46ab5SKacheong Poon 		kmem_free((sctp)->sctp_listen_cnt, sizeof (sctp_listen_cnt_t));\
4095dd46ab5SKacheong Poon 	(sctp)->sctp_listen_cnt = NULL;					\
4105dd46ab5SKacheong Poon }
4115dd46ab5SKacheong Poon 
4125dd46ab5SKacheong Poon /* Increment and decrement the number of associations in sctp_stack_t. */
4135dd46ab5SKacheong Poon #define	SCTPS_ASSOC_INC(sctps)						\
4145dd46ab5SKacheong Poon 	atomic_inc_64(							\
4155dd46ab5SKacheong Poon 	    (uint64_t *)&(sctps)->sctps_sc[CPU->cpu_seqid]->sctp_sc_assoc_cnt)
4165dd46ab5SKacheong Poon 
4175dd46ab5SKacheong Poon #define	SCTPS_ASSOC_DEC(sctps)						\
4185dd46ab5SKacheong Poon 	atomic_dec_64(							\
4195dd46ab5SKacheong Poon 	    (uint64_t *)&(sctps)->sctps_sc[CPU->cpu_seqid]->sctp_sc_assoc_cnt)
4205dd46ab5SKacheong Poon 
4215dd46ab5SKacheong Poon #define	SCTP_ASSOC_EST(sctps, sctp)					\
4225dd46ab5SKacheong Poon {									\
4235dd46ab5SKacheong Poon 	(sctp)->sctp_state = SCTPS_ESTABLISHED;				\
4245dd46ab5SKacheong Poon 	(sctp)->sctp_assoc_start_time = (uint32_t)LBOLT_FASTPATH64;	\
4255dd46ab5SKacheong Poon 	SCTPS_ASSOC_INC(sctps);						\
4265dd46ab5SKacheong Poon }
4275dd46ab5SKacheong Poon 
4287c478bd9Sstevel@tonic-gate /*
4297c478bd9Sstevel@tonic-gate  * Bind hash array size and hash function.  The size must be a power
4307c478bd9Sstevel@tonic-gate  * of 2 and lport must be in host byte order.
4317c478bd9Sstevel@tonic-gate  */
4327c478bd9Sstevel@tonic-gate #define	SCTP_BIND_FANOUT_SIZE	2048
4337c478bd9Sstevel@tonic-gate #define	SCTP_BIND_HASH(lport)	(((lport) * 31) & (SCTP_BIND_FANOUT_SIZE - 1))
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate /* options that SCTP negotiates during association establishment */
4367c478bd9Sstevel@tonic-gate #define	SCTP_PRSCTP_OPTION	0x01
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate  * Listener hash array size and hash function.  The size must be a power
4407c478bd9Sstevel@tonic-gate  * of 2 and lport must be in host byte order.
4417c478bd9Sstevel@tonic-gate  */
4427c478bd9Sstevel@tonic-gate #define	SCTP_LISTEN_FANOUT_SIZE	512
4437c478bd9Sstevel@tonic-gate #define	SCTP_LISTEN_HASH(lport) (((lport) * 31) & (SCTP_LISTEN_FANOUT_SIZE - 1))
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate typedef struct sctp_tf_s {
4467c478bd9Sstevel@tonic-gate 	struct sctp_s	*tf_sctp;
4477c478bd9Sstevel@tonic-gate 	kmutex_t	tf_lock;
4487c478bd9Sstevel@tonic-gate } sctp_tf_t;
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate /* Round up the value to the nearest mss. */
4517c478bd9Sstevel@tonic-gate #define	MSS_ROUNDUP(value, mss)		((((value) - 1) / (mss) + 1) * (mss))
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate extern sin_t	sctp_sin_null;	/* Zero address for quick clears */
4547c478bd9Sstevel@tonic-gate extern sin6_t	sctp_sin6_null;	/* Zero address for quick clears */
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate #define	SCTP_IS_DETACHED(sctp)		((sctp)->sctp_detached)
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate /* Data structure used to track received TSNs */
4597c478bd9Sstevel@tonic-gate typedef struct sctp_set_s {
4607c478bd9Sstevel@tonic-gate 	struct sctp_set_s *next;
4617c478bd9Sstevel@tonic-gate 	struct sctp_set_s *prev;
4627c478bd9Sstevel@tonic-gate 	uint32_t begin;
4637c478bd9Sstevel@tonic-gate 	uint32_t end;
4647c478bd9Sstevel@tonic-gate } sctp_set_t;
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate /* Data structure used to track TSNs for PR-SCTP */
4677c478bd9Sstevel@tonic-gate typedef struct sctp_ftsn_set_s {
4687c478bd9Sstevel@tonic-gate 	struct sctp_ftsn_set_s *next;
4697c478bd9Sstevel@tonic-gate 	ftsn_entry_t	ftsn_entries;
4707c478bd9Sstevel@tonic-gate } sctp_ftsn_set_t;
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate /* Data structure used to track incoming SCTP streams */
4737c478bd9Sstevel@tonic-gate typedef struct sctp_instr_s {
4747c478bd9Sstevel@tonic-gate 	mblk_t		*istr_msgs;
4757c478bd9Sstevel@tonic-gate 	int		istr_nmsgs;
4767c478bd9Sstevel@tonic-gate 	uint16_t	nextseq;
4777c478bd9Sstevel@tonic-gate 	struct sctp_s	*sctp;
4787c478bd9Sstevel@tonic-gate 	mblk_t		*istr_reass;
4797c478bd9Sstevel@tonic-gate } sctp_instr_t;
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate /* Reassembly data structure (per-stream) */
4827c478bd9Sstevel@tonic-gate typedef struct sctp_reass_s {
4836be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint16_t	sr_ssn;
4846be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint16_t	sr_needed;
4856be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint16_t	sr_got;
4866be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint16_t	sr_msglen;	/* len of consecutive fragments */
4877d546a59Svi 					/* from the begining (B-bit) */
4886be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	mblk_t		*sr_tail;
4896be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	boolean_t	sr_hasBchunk;	/* If the fragment list begins with */
4907d546a59Svi 					/* a B-bit set chunk */
4916be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sr_nexttsn;	/* TSN of the next fragment we */
4927d546a59Svi 					/* are expecting */
4936be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	boolean_t	sr_partial_delivered;
4947c478bd9Sstevel@tonic-gate } sctp_reass_t;
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate /* debugging */
4977c478bd9Sstevel@tonic-gate #undef	dprint
49845916cd2Sjpk #ifdef DEBUG
4997c478bd9Sstevel@tonic-gate extern int sctpdebug;
5007c478bd9Sstevel@tonic-gate #define	dprint(level, args)	{ if (sctpdebug > (level)) printf args; }
50145916cd2Sjpk #else
5027c478bd9Sstevel@tonic-gate #define	dprint(level, args) {}
50345916cd2Sjpk #endif
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate /* Peer address tracking */
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate /*
5097c478bd9Sstevel@tonic-gate  * States for peer addresses
5107c478bd9Sstevel@tonic-gate  *
5117c478bd9Sstevel@tonic-gate  * SCTP_FADDRS_UNCONFIRMED: we have not communicated with this peer address
5127c478bd9Sstevel@tonic-gate  *     before, mark it as unconfirmed so that we will not send data to it.
5137c478bd9Sstevel@tonic-gate  *     All addresses initially are in unconfirmed state and required
5147c478bd9Sstevel@tonic-gate  *     validation.  SCTP sends a heartbeat to each of them and when it gets
5157c478bd9Sstevel@tonic-gate  *     back a heartbeat ACK, the address will be marked as alive.  This
5167c478bd9Sstevel@tonic-gate  *     validation fixes a security issue with multihoming.  If an attacker
5177c478bd9Sstevel@tonic-gate  *     establishes an association with us and tells us that it has addresses
5187c478bd9Sstevel@tonic-gate  *     belonging to another host A, this will prevent A from communicating
5197c478bd9Sstevel@tonic-gate  *     with us.  This is fixed by peer address validation.  In the above case,
5207c478bd9Sstevel@tonic-gate  *     A will respond with an abort.
5217c478bd9Sstevel@tonic-gate  *
5227c478bd9Sstevel@tonic-gate  * SCTP_FADDRS_ALIVE: this peer address is alive and we can communicate with
5237c478bd9Sstevel@tonic-gate  *     it with no problem.
5247c478bd9Sstevel@tonic-gate  *
5257c478bd9Sstevel@tonic-gate  * SCTP_FADDRS_DOWN: we have exceeded the retransmission limit to this
5267c478bd9Sstevel@tonic-gate  *     peer address.  Once an address is marked down, we will only send
5277c478bd9Sstevel@tonic-gate  *     a heartbeat to it every hb_interval in case it becomes alive now.
5287c478bd9Sstevel@tonic-gate  *
5297c478bd9Sstevel@tonic-gate  * SCTP_FADDRS_UNREACH: there is no suitable source address to send to
5307c478bd9Sstevel@tonic-gate  *     this peer address.  For example, the peer address is v6 but we only
5317c478bd9Sstevel@tonic-gate  *     have v4 addresses.  It is marked unreachable until there is an
5327c478bd9Sstevel@tonic-gate  *     address configuration change.  At that time, mark these addresses
5337c478bd9Sstevel@tonic-gate  *     as unconfirmed and try again to see if those unreachable addresses
5347c478bd9Sstevel@tonic-gate  *     are OK as we may have more source addresses.
5357c478bd9Sstevel@tonic-gate  */
5367c478bd9Sstevel@tonic-gate typedef enum {
5377c478bd9Sstevel@tonic-gate 	SCTP_FADDRS_UNREACH,
5387c478bd9Sstevel@tonic-gate 	SCTP_FADDRS_DOWN,
5397c478bd9Sstevel@tonic-gate 	SCTP_FADDRS_ALIVE,
5407c478bd9Sstevel@tonic-gate 	SCTP_FADDRS_UNCONFIRMED
5417c478bd9Sstevel@tonic-gate } faddr_state_t;
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate typedef struct sctp_faddr_s {
5446be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	struct sctp_faddr_s *sf_next;
5456be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	faddr_state_t	sf_state;
5466be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 
5476be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	in6_addr_t	sf_faddr;
5486be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	in6_addr_t	sf_saddr;
5496be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 
5506be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	int64_t		sf_hb_expiry;	/* time to retransmit heartbeat */
5516be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_hb_interval;	/* the heartbeat interval */
5526be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 
5536be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	int		sf_rto;		/* RTO in tick */
5546be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	int		sf_srtt;	/* Smoothed RTT in tick */
5556be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	int		sf_rttvar;	/* RTT variance in tick */
5566be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_rtt_updates;
5576be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	int		sf_strikes;
5586be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	int		sf_max_retr;
5596be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_pmss;
5606be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_cwnd;
5616be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_ssthresh;
5626be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_suna;	/* sent - unack'ed */
5636be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_pba;		/* partial bytes acked */
5646be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_acked;
5656be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	int64_t		sf_lastactive;
5666be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	mblk_t		*sf_timer_mp;	/* retransmission timer control */
5677c478bd9Sstevel@tonic-gate 	uint32_t
5686be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 			sf_hb_pending : 1,
5696be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 			sf_timer_running : 1,
5706be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 			sf_df : 1,
5716be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 			sf_pmtu_discovered : 1,
5727c478bd9Sstevel@tonic-gate 
5736be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 			sf_rc_timer_running : 1,
5746be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 			sf_isv4 : 1,
5756be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 			sf_hb_enabled : 1;
5767c478bd9Sstevel@tonic-gate 
5776be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	mblk_t		*sf_rc_timer_mp; /* reliable control chunk timer */
5786be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	ip_xmit_attr_t	*sf_ixa;	/* Transmit attributes */
5796be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_T3expire;	/* # of times T3 timer expired */
5807c478bd9Sstevel@tonic-gate 
5816be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint64_t	sf_hb_secret;	/* per addr "secret" in heartbeat */
5826be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	uint32_t	sf_rxt_unacked;	/* # unack'ed retransmitted bytes */
5837c478bd9Sstevel@tonic-gate } sctp_faddr_t;
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate /* Flags to indicate supported address type in the PARM_SUP_ADDRS. */
5867c478bd9Sstevel@tonic-gate #define	PARM_SUPP_V6	0x1
5877c478bd9Sstevel@tonic-gate #define	PARM_SUPP_V4	0x2
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate /*
5907c478bd9Sstevel@tonic-gate  * Set heartbeat interval plus jitter.  The jitter is supposed to be random,
5917c478bd9Sstevel@tonic-gate  * up to +/- 50% of the RTO.  We use gethrtime() here for  performance reason
5927c478bd9Sstevel@tonic-gate  * as the jitter does not really need to be "very" random.
5937c478bd9Sstevel@tonic-gate  */
5947c478bd9Sstevel@tonic-gate #define	SET_HB_INTVL(fp)					\
5956be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	((fp)->sf_hb_interval + (fp)->sf_rto + ((fp)->sf_rto >> 1) -	\
5966be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	(uint_t)gethrtime() % (fp)->sf_rto)
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate #define	SCTP_IPIF_HASH	16
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate typedef	struct	sctp_ipif_hash_s {
60192baa190SGeorge Shepherd 	list_t		sctp_ipif_list;
60292baa190SGeorge Shepherd 	int		ipif_count;
60392baa190SGeorge Shepherd 	krwlock_t	ipif_hash_lock;
6047c478bd9Sstevel@tonic-gate } sctp_ipif_hash_t;
6057c478bd9Sstevel@tonic-gate 
60612f47623Skcpoon 
60712f47623Skcpoon /*
60812f47623Skcpoon  * Initialize cwnd according to RFC 3390.  def_max_init_cwnd is
60912f47623Skcpoon  * either sctp_slow_start_initial or sctp_slow_start_after idle
61012f47623Skcpoon  * depending on the caller.
61112f47623Skcpoon  */
61212f47623Skcpoon #define	SET_CWND(fp, mss, def_max_init_cwnd)				\
61312f47623Skcpoon {									\
6146be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	(fp)->sf_cwnd = MIN(def_max_init_cwnd * (mss),			\
61512f47623Skcpoon 	    MIN(4 * (mss), MAX(2 * (mss), 4380 / (mss) * (mss))));	\
61612f47623Skcpoon }
61712f47623Skcpoon 
61812f47623Skcpoon 
6197c478bd9Sstevel@tonic-gate struct sctp_s;
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate /*
6227c478bd9Sstevel@tonic-gate  * Control structure for each open SCTP stream,
6237c478bd9Sstevel@tonic-gate  * defined only within the kernel or for a kmem user.
6247c478bd9Sstevel@tonic-gate  * NOTE: sctp_reinit_values MUST have a line for each field in this structure!
6257c478bd9Sstevel@tonic-gate  */
6267c478bd9Sstevel@tonic-gate #if (defined(_KERNEL) || defined(_KMEMUSER))
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate typedef struct sctp_s {
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 	/*
6317c478bd9Sstevel@tonic-gate 	 * The following is shared with (and duplicated) in IP, so if you
6327c478bd9Sstevel@tonic-gate 	 * make changes, make sure you also change things in ip_sctp.c.
6337c478bd9Sstevel@tonic-gate 	 */
6347c478bd9Sstevel@tonic-gate 	struct sctp_s	*sctp_conn_hash_next;
6357c478bd9Sstevel@tonic-gate 	struct sctp_s	*sctp_conn_hash_prev;
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate 	struct sctp_s	*sctp_listen_hash_next;
6387c478bd9Sstevel@tonic-gate 	struct sctp_s	*sctp_listen_hash_prev;
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 	sctp_tf_t	*sctp_listen_tfp;	/* Ptr to tf */
6417c478bd9Sstevel@tonic-gate 	sctp_tf_t	*sctp_conn_tfp;		/* Ptr to tf */
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 	/* Global list of sctp */
6447c478bd9Sstevel@tonic-gate 	list_node_t	sctp_list;
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 	sctp_faddr_t		*sctp_faddrs;
6471d8c4025Svi 	int			sctp_nfaddrs;
6487c478bd9Sstevel@tonic-gate 	sctp_ipif_hash_t	sctp_saddrs[SCTP_IPIF_HASH];
6497c478bd9Sstevel@tonic-gate 	int			sctp_nsaddrs;
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	kmutex_t	sctp_lock;
6527c478bd9Sstevel@tonic-gate 	kcondvar_t	sctp_cv;
6537c478bd9Sstevel@tonic-gate 	boolean_t	sctp_running;
6547c478bd9Sstevel@tonic-gate 
6550f1702c5SYu Xiangning #define	sctp_ulpd	sctp_connp->conn_upper_handle
6560f1702c5SYu Xiangning #define	sctp_upcalls	sctp_connp->conn_upcalls
6577c478bd9Sstevel@tonic-gate 
6580f1702c5SYu Xiangning #define	sctp_ulp_newconn	sctp_upcalls->su_newconn
6590f1702c5SYu Xiangning #define	sctp_ulp_connected	sctp_upcalls->su_connected
6600f1702c5SYu Xiangning #define	sctp_ulp_disconnected	sctp_upcalls->su_disconnected
6610f1702c5SYu Xiangning #define	sctp_ulp_opctl		sctp_upcalls->su_opctl
6620f1702c5SYu Xiangning #define	sctp_ulp_recv		sctp_upcalls->su_recv
663a215d4ebSKacheong Poon #define	sctp_ulp_txq_full	sctp_upcalls->su_txq_full
6640f1702c5SYu Xiangning #define	sctp_ulp_prop		sctp_upcalls->su_set_proto_props
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 	int32_t		sctp_state;
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 	conn_t		*sctp_connp;		/* conn_t stuff */
669f4b3ec61Sdh 	sctp_stack_t	*sctp_sctps;
670f4b3ec61Sdh 
6717c478bd9Sstevel@tonic-gate 	/* Peer address tracking */
6727c478bd9Sstevel@tonic-gate 	sctp_faddr_t	*sctp_lastfaddr;	/* last faddr in list */
6737c478bd9Sstevel@tonic-gate 	sctp_faddr_t	*sctp_primary;		/* primary faddr */
6747c478bd9Sstevel@tonic-gate 	sctp_faddr_t	*sctp_current;		/* current faddr */
6757c478bd9Sstevel@tonic-gate 	sctp_faddr_t	*sctp_lastdata;		/* last data seen from this */
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate 	/* Outbound data tracking */
6787c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_xmit_head;
6797c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_xmit_tail;
6807c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_xmit_unsent;
6817c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_xmit_unsent_tail;
6827c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_xmit_unacked;
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 	int32_t		sctp_unacked;		/* # of unacked bytes */
6857c478bd9Sstevel@tonic-gate 	int32_t		sctp_unsent;		/* # of unsent bytes in hand */
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate 	uint32_t	sctp_ltsn;		/* Local instance TSN */
6887c478bd9Sstevel@tonic-gate 	uint32_t	sctp_lastack_rxd;	/* Last rx'd cumtsn */
6897c478bd9Sstevel@tonic-gate 	uint32_t	sctp_recovery_tsn;	/* Exit from fast recovery */
6907c478bd9Sstevel@tonic-gate 	uint32_t	sctp_adv_pap;		/* Adv. Peer Ack Point */
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	uint16_t	sctp_num_ostr;
6937c478bd9Sstevel@tonic-gate 	uint16_t	*sctp_ostrcntrs;
6947c478bd9Sstevel@tonic-gate 
695121e5416Skcpoon 	mblk_t		*sctp_pad_mp;		/* pad unaligned data chunks */
696121e5416Skcpoon 
6977c478bd9Sstevel@tonic-gate 	/* sendmsg() default parameters */
6987c478bd9Sstevel@tonic-gate 	uint16_t	sctp_def_stream;	/* default stream id */
6997c478bd9Sstevel@tonic-gate 	uint16_t	sctp_def_flags;		/* default xmit flags */
7007c478bd9Sstevel@tonic-gate 	uint32_t	sctp_def_ppid;		/* default payload id */
7017c478bd9Sstevel@tonic-gate 	uint32_t	sctp_def_context;	/* default context */
7027c478bd9Sstevel@tonic-gate 	uint32_t	sctp_def_timetolive;	/* default msg TTL */
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate 	/* Inbound data tracking */
7057c478bd9Sstevel@tonic-gate 	sctp_set_t	*sctp_sack_info;	/* Sack tracking */
7067c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_ack_mp;		/* Delayed ACK timer block */
7077c478bd9Sstevel@tonic-gate 	sctp_instr_t	*sctp_instr;		/* Instream trackers */
7087c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_uo_frags;		/* Un-ordered msg. fragments */
7097c478bd9Sstevel@tonic-gate 	uint32_t	sctp_ftsn;		/* Peer's TSN */
7107c478bd9Sstevel@tonic-gate 	uint32_t	sctp_lastacked;		/* last cumtsn SACKd */
7117c478bd9Sstevel@tonic-gate 	uint16_t	sctp_num_istr;		/* No. of instreams */
7127c478bd9Sstevel@tonic-gate 	int32_t		sctp_istr_nmsgs;	/* No. of chunks in instreams */
7137c478bd9Sstevel@tonic-gate 	int32_t		sctp_sack_gaps;		/* No. of received gaps */
7147c478bd9Sstevel@tonic-gate 	int32_t		sctp_sack_toggle;	/* SACK every other pkt */
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 	/* RTT calculation */
7177c478bd9Sstevel@tonic-gate 	uint32_t	sctp_rtt_tsn;
7187c478bd9Sstevel@tonic-gate 	int64_t		sctp_out_time;
7197c478bd9Sstevel@tonic-gate 
72035e12f9cSGeorge Shepherd 	/* Stats can be reset by snmp users kstat, netstat and snmp agents */
7217c478bd9Sstevel@tonic-gate 	uint64_t	sctp_opkts;		/* sent pkts */
7227c478bd9Sstevel@tonic-gate 	uint64_t	sctp_obchunks;		/* sent control chunks */
7237c478bd9Sstevel@tonic-gate 	uint64_t	sctp_odchunks;		/* sent ordered data chunks */
7247c478bd9Sstevel@tonic-gate 	uint64_t	sctp_oudchunks;		/* sent unord data chunks */
7257c478bd9Sstevel@tonic-gate 	uint64_t	sctp_rxtchunks;		/* retransmitted chunks */
7267c478bd9Sstevel@tonic-gate 	uint64_t	sctp_ipkts;		/* recv pkts */
7277c478bd9Sstevel@tonic-gate 	uint64_t	sctp_ibchunks;		/* recv control chunks */
7287c478bd9Sstevel@tonic-gate 	uint64_t	sctp_idchunks;		/* recv ordered data chunks */
7297c478bd9Sstevel@tonic-gate 	uint64_t	sctp_iudchunks;		/* recv unord data chunks */
7307c478bd9Sstevel@tonic-gate 	uint64_t	sctp_fragdmsgs;
7317c478bd9Sstevel@tonic-gate 	uint64_t	sctp_reassmsgs;
7327c478bd9Sstevel@tonic-gate 	uint32_t	sctp_T1expire;		/* # of times T1timer expired */
7337c478bd9Sstevel@tonic-gate 	uint32_t	sctp_T2expire;		/* # of times T2timer expired */
7347c478bd9Sstevel@tonic-gate 	uint32_t	sctp_T3expire;		/* # of times T3timer expired */
7357c478bd9Sstevel@tonic-gate 	uint32_t	sctp_assoc_start_time;	/* time when assoc was est. */
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 	uint32_t	sctp_frwnd;		/* Peer RWND */
7387c478bd9Sstevel@tonic-gate 	uint32_t	sctp_cwnd_max;
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 	/* Inbound flow control */
7417c478bd9Sstevel@tonic-gate 	int32_t		sctp_rwnd;		/* Current receive window */
742a215d4ebSKacheong Poon 	int32_t		sctp_arwnd;		/* Last advertised window */
7437c478bd9Sstevel@tonic-gate 	int32_t		sctp_rxqueued;		/* No. of bytes in RX q's */
744a215d4ebSKacheong Poon 	int32_t		sctp_ulp_rxqueued;	/* Data in ULP */
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate 	/* Pre-initialized composite headers */
747bd670b35SErik Nordmark 	uchar_t		*sctp_iphc;	/* v4 sctp/ip hdr template buffer */
748bd670b35SErik Nordmark 	uchar_t		*sctp_iphc6;	/* v6 sctp/ip hdr template buffer */
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 	int32_t		sctp_iphc_len;	/* actual allocated v4 buffer size */
7517c478bd9Sstevel@tonic-gate 	int32_t		sctp_iphc6_len;	/* actual allocated v6 buffer size */
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate 	int32_t		sctp_hdr_len;	/* len of combined SCTP/IP v4 hdr */
7547c478bd9Sstevel@tonic-gate 	int32_t		sctp_hdr6_len;	/* len of combined SCTP/IP v6 hdr */
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate 	ipha_t		*sctp_ipha;	/* IPv4 header in the buffer */
7577c478bd9Sstevel@tonic-gate 	ip6_t		*sctp_ip6h;	/* IPv6 header in the buffer */
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate 	int32_t		sctp_ip_hdr_len; /* Byte len of our current v4 hdr */
7607c478bd9Sstevel@tonic-gate 	int32_t		sctp_ip_hdr6_len; /* Byte len of our current v6 hdr */
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 	sctp_hdr_t	*sctp_sctph;	/* sctp header in combined v4 hdr */
7637c478bd9Sstevel@tonic-gate 	sctp_hdr_t	*sctp_sctph6;	/* sctp header in combined v6 hdr */
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 	uint32_t	sctp_lvtag;	/* local SCTP instance verf tag */
7667c478bd9Sstevel@tonic-gate 	uint32_t	sctp_fvtag;	/* Peer's SCTP verf tag */
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 	/* Path MTU Discovery */
7697c478bd9Sstevel@tonic-gate 	int64_t		sctp_last_mtu_probe;
7707c478bd9Sstevel@tonic-gate 	clock_t		sctp_mtu_probe_intvl;
7717c478bd9Sstevel@tonic-gate 	uint32_t	sctp_mss;	/* Max send size (not TCP MSS!) */
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate 	/* structs sctp_bits, sctp_events are for clearing all bits at once */
7747c478bd9Sstevel@tonic-gate 	struct {
7757c478bd9Sstevel@tonic-gate 		uint32_t
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 		sctp_understands_asconf : 1, /* Peer handles ASCONF chunks */
7787c478bd9Sstevel@tonic-gate 		sctp_cchunk_pend : 1,	/* Control chunk in flight. */
7797c478bd9Sstevel@tonic-gate 		sctp_lingering : 1,	/* Lingering in close */
7807c478bd9Sstevel@tonic-gate 		sctp_loopback: 1,	/* src and dst are the same machine */
7817c478bd9Sstevel@tonic-gate 
782bd670b35SErik Nordmark 		sctp_force_sack : 1,
7837c478bd9Sstevel@tonic-gate 		sctp_ack_timer_running: 1,	/* Delayed ACK timer running */
7847c478bd9Sstevel@tonic-gate 		sctp_hwcksum : 1,	/* The NIC is capable of hwcksum */
7857c478bd9Sstevel@tonic-gate 		sctp_understands_addip : 1,
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate 		sctp_bound_to_all : 1,
7887c478bd9Sstevel@tonic-gate 		sctp_cansleep : 1,	/* itf routines can sleep */
7897c478bd9Sstevel@tonic-gate 		sctp_detached : 1,	/* If we're detached from a stream */
790558fbd03Skcpoon 		sctp_send_adaptation : 1,	/* send adaptation layer ind */
7917c478bd9Sstevel@tonic-gate 
792558fbd03Skcpoon 		sctp_recv_adaptation : 1,	/* recv adaptation layer ind */
7937c478bd9Sstevel@tonic-gate 		sctp_ndelay : 1,	/* turn off Nagle */
7947c478bd9Sstevel@tonic-gate 		sctp_condemned : 1,	/* this sctp is about to disappear */
7957c478bd9Sstevel@tonic-gate 		sctp_chk_fast_rexmit : 1, /* check for fast rexmit message */
796f551bb10Svi 
797f551bb10Svi 		sctp_prsctp_aware : 1,	/* is peer PR-SCTP aware? */
79845916cd2Sjpk 		sctp_linklocal : 1,	/* is linklocal assoc. */
79977c67f2fSkcpoon 		sctp_rexmitting : 1,	/* SCTP is retransmitting */
800769b977dSvi 		sctp_zero_win_probe : 1,	/* doing zero win probe */
80177c67f2fSkcpoon 
8020f1702c5SYu Xiangning 		sctp_txq_full : 1,	/* the tx queue is full */
803c31292eeSkcpoon 		sctp_ulp_discon_done : 1,	/* ulp_disconnecting done */
804a215d4ebSKacheong Poon 		sctp_flowctrld : 1,	/* upper layer flow controlled */
805a215d4ebSKacheong Poon 		sctp_dummy : 5;
8067c478bd9Sstevel@tonic-gate 	} sctp_bits;
8077c478bd9Sstevel@tonic-gate 	struct {
8087c478bd9Sstevel@tonic-gate 		uint32_t
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate 		sctp_recvsndrcvinfo : 1,
8117c478bd9Sstevel@tonic-gate 		sctp_recvassocevnt : 1,
8127c478bd9Sstevel@tonic-gate 		sctp_recvpathevnt : 1,
8137c478bd9Sstevel@tonic-gate 		sctp_recvsendfailevnt : 1,
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate 		sctp_recvpeererr : 1,
8167c478bd9Sstevel@tonic-gate 		sctp_recvshutdownevnt : 1,
8177c478bd9Sstevel@tonic-gate 		sctp_recvpdevnt : 1,
8187c478bd9Sstevel@tonic-gate 		sctp_recvalevnt : 1;
8197c478bd9Sstevel@tonic-gate 	} sctp_events;
8207c478bd9Sstevel@tonic-gate #define	sctp_priv_stream sctp_bits.sctp_priv_stream
8217c478bd9Sstevel@tonic-gate #define	sctp_understands_asconf sctp_bits.sctp_understands_asconf
8227c478bd9Sstevel@tonic-gate #define	sctp_cchunk_pend sctp_bits.sctp_cchunk_pend
8237c478bd9Sstevel@tonic-gate #define	sctp_lingering sctp_bits.sctp_lingering
8247c478bd9Sstevel@tonic-gate #define	sctp_loopback sctp_bits.sctp_loopback
8257c478bd9Sstevel@tonic-gate #define	sctp_force_sack sctp_bits.sctp_force_sack
8267c478bd9Sstevel@tonic-gate #define	sctp_ack_timer_running sctp_bits.sctp_ack_timer_running
8277c478bd9Sstevel@tonic-gate #define	sctp_hwcksum sctp_bits.sctp_hwcksum
8287c478bd9Sstevel@tonic-gate #define	sctp_understands_addip sctp_bits.sctp_understands_addip
8297c478bd9Sstevel@tonic-gate #define	sctp_bound_to_all sctp_bits.sctp_bound_to_all
8307c478bd9Sstevel@tonic-gate #define	sctp_cansleep sctp_bits.sctp_cansleep
8317c478bd9Sstevel@tonic-gate #define	sctp_detached sctp_bits.sctp_detached
832558fbd03Skcpoon #define	sctp_send_adaptation sctp_bits.sctp_send_adaptation
833558fbd03Skcpoon #define	sctp_recv_adaptation sctp_bits.sctp_recv_adaptation
8347c478bd9Sstevel@tonic-gate #define	sctp_ndelay sctp_bits.sctp_ndelay
8357c478bd9Sstevel@tonic-gate #define	sctp_condemned sctp_bits.sctp_condemned
8367c478bd9Sstevel@tonic-gate #define	sctp_chk_fast_rexmit sctp_bits.sctp_chk_fast_rexmit
8377c478bd9Sstevel@tonic-gate #define	sctp_prsctp_aware sctp_bits.sctp_prsctp_aware
838f551bb10Svi #define	sctp_linklocal sctp_bits.sctp_linklocal
83977c67f2fSkcpoon #define	sctp_rexmitting sctp_bits.sctp_rexmitting
840769b977dSvi #define	sctp_zero_win_probe sctp_bits.sctp_zero_win_probe
8410f1702c5SYu Xiangning #define	sctp_txq_full sctp_bits.sctp_txq_full
842c31292eeSkcpoon #define	sctp_ulp_discon_done sctp_bits.sctp_ulp_discon_done
843a215d4ebSKacheong Poon #define	sctp_flowctrld sctp_bits.sctp_flowctrld
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate #define	sctp_recvsndrcvinfo sctp_events.sctp_recvsndrcvinfo
8467c478bd9Sstevel@tonic-gate #define	sctp_recvassocevnt sctp_events.sctp_recvassocevnt
8477c478bd9Sstevel@tonic-gate #define	sctp_recvpathevnt sctp_events.sctp_recvpathevnt
8487c478bd9Sstevel@tonic-gate #define	sctp_recvsendfailevnt sctp_events.sctp_recvsendfailevnt
8497c478bd9Sstevel@tonic-gate #define	sctp_recvpeererr sctp_events.sctp_recvpeererr
8507c478bd9Sstevel@tonic-gate #define	sctp_recvshutdownevnt sctp_events.sctp_recvshutdownevnt
8517c478bd9Sstevel@tonic-gate #define	sctp_recvpdevnt sctp_events.sctp_recvpdevnt
8527c478bd9Sstevel@tonic-gate #define	sctp_recvalevnt sctp_events.sctp_recvalevnt
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate 	/* Retransmit info */
8557c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_cookie_mp; /* cookie chunk, if rxt needed */
8567c478bd9Sstevel@tonic-gate 	int32_t		sctp_strikes;	/* Total number of assoc strikes */
8577c478bd9Sstevel@tonic-gate 	int32_t		sctp_max_init_rxt;
8587c478bd9Sstevel@tonic-gate 	int32_t		sctp_pa_max_rxt; /* Max per-assoc retransmit cnt */
8597c478bd9Sstevel@tonic-gate 	int32_t		sctp_pp_max_rxt; /* Max per-path retransmit cnt */
8607c478bd9Sstevel@tonic-gate 	uint32_t	sctp_rto_max;
861fd7b5aedSGeorge Shepherd 	uint32_t	sctp_rto_max_init;
8627c478bd9Sstevel@tonic-gate 	uint32_t	sctp_rto_min;
8637c478bd9Sstevel@tonic-gate 	uint32_t	sctp_rto_initial;
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate 	int64_t		sctp_last_secret_update;
8667c478bd9Sstevel@tonic-gate 	uint8_t		sctp_secret[SCTP_SECRET_LEN]; /* for cookie auth */
8677c478bd9Sstevel@tonic-gate 	uint8_t		sctp_old_secret[SCTP_SECRET_LEN];
86812f47623Skcpoon 	uint32_t	sctp_cookie_lifetime;	/* cookie lifetime in tick */
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 	/* Bind hash tables */
8717c478bd9Sstevel@tonic-gate 	kmutex_t	*sctp_bind_lockp;	/* Ptr to tf_lock */
8727c478bd9Sstevel@tonic-gate 	struct sctp_s	*sctp_bind_hash;
8737c478bd9Sstevel@tonic-gate 	struct sctp_s **sctp_ptpbhn;
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 	/* Shutdown / cleanup */
8767c478bd9Sstevel@tonic-gate 	sctp_faddr_t	*sctp_shutdown_faddr;	/* rotate faddr during shutd */
8777c478bd9Sstevel@tonic-gate 	int32_t		sctp_client_errno;	/* How the client screwed up */
8787c478bd9Sstevel@tonic-gate 	kmutex_t	sctp_reflock;	/* Protects sctp_refcnt & timer mp */
8797c478bd9Sstevel@tonic-gate 	ushort_t	sctp_refcnt;	/* No. of pending upstream msg */
8807c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_timer_mp;	/* List of fired timers. */
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_heartbeat_mp; /* Timer block for heartbeats */
8837c478bd9Sstevel@tonic-gate 	uint32_t	sctp_hb_interval; /* Default hb_interval */
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate 	int32_t		sctp_autoclose;	/* Auto disconnect in ticks */
8867c478bd9Sstevel@tonic-gate 	int64_t		sctp_active;	/* Last time data/sack on this conn */
887558fbd03Skcpoon 	uint32_t	sctp_tx_adaptation_code; /* TX adaptation code */
888558fbd03Skcpoon 	uint32_t	sctp_rx_adaptation_code; /* RX adaptation code */
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 	/* Reliable control chunks */
8917c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_cxmit_list; /* Xmit list for control chunks */
8927c478bd9Sstevel@tonic-gate 	uint32_t	sctp_lcsn;	/* Our serial number */
8937c478bd9Sstevel@tonic-gate 	uint32_t	sctp_fcsn;	/* Peer serial number */
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 	/* Per association receive queue */
8967c478bd9Sstevel@tonic-gate 	kmutex_t	sctp_recvq_lock;
8977c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_recvq;
8987c478bd9Sstevel@tonic-gate 	mblk_t		*sctp_recvq_tail;
8997c478bd9Sstevel@tonic-gate 	taskq_t		*sctp_recvq_tq;
9007c478bd9Sstevel@tonic-gate 
9017c478bd9Sstevel@tonic-gate 	/* IPv6 ancillary data */
9027c478bd9Sstevel@tonic-gate 	uint_t		sctp_recvifindex;	/* last rcvd IPV6_RCVPKTINFO */
9037c478bd9Sstevel@tonic-gate 	uint_t		sctp_recvhops;		/*  " IPV6_RECVHOPLIMIT */
904bd670b35SErik Nordmark 	uint_t		sctp_recvtclass;	/*  " IPV6_RECVTCLASS */
9057c478bd9Sstevel@tonic-gate 	ip6_hbh_t	*sctp_hopopts;		/*  " IPV6_RECVHOPOPTS */
9067c478bd9Sstevel@tonic-gate 	ip6_dest_t	*sctp_dstopts;		/*  " IPV6_RECVDSTOPTS */
907bd670b35SErik Nordmark 	ip6_dest_t	*sctp_rthdrdstopts;	/*  " IPV6_RECVRTHDRDSTOPTS */
9087c478bd9Sstevel@tonic-gate 	ip6_rthdr_t	*sctp_rthdr;		/*  " IPV6_RECVRTHDR */
9097c478bd9Sstevel@tonic-gate 	uint_t		sctp_hopoptslen;
9107c478bd9Sstevel@tonic-gate 	uint_t		sctp_dstoptslen;
911bd670b35SErik Nordmark 	uint_t		sctp_rthdrdstoptslen;
9127c478bd9Sstevel@tonic-gate 	uint_t		sctp_rthdrlen;
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 	/* Stats */
9157c478bd9Sstevel@tonic-gate 	uint64_t	sctp_msgcount;
9167c478bd9Sstevel@tonic-gate 	uint64_t	sctp_prsctpdrop;
91745916cd2Sjpk 
91845916cd2Sjpk 	uint_t		sctp_v4label_len;	/* length of cached v4 label */
91945916cd2Sjpk 	uint_t		sctp_v6label_len;	/* length of cached v6 label */
92077c67f2fSkcpoon 	uint32_t	sctp_rxt_nxttsn;	/* Next TSN to be rexmitted */
92177c67f2fSkcpoon 	uint32_t	sctp_rxt_maxtsn;	/* Max TSN sent at time out */
9227d546a59Svi 
9237d546a59Svi 	int		sctp_pd_point;		/* Partial delivery point */
9247f093707Skcpoon 	mblk_t		*sctp_err_chunks;	/* Error chunks */
9257f093707Skcpoon 	uint32_t	sctp_err_len;		/* Total error chunks length */
926de8c4a14SErik Nordmark 
9279f13099eSGeorge Shepherd 	/* additional source data for per endpoint association statistics */
9289f13099eSGeorge Shepherd 	uint64_t	sctp_outseqtsns;	/* TSN rx > expected TSN */
9299f13099eSGeorge Shepherd 	uint64_t	sctp_osacks;		/* total sacks sent */
9309f13099eSGeorge Shepherd 	uint64_t	sctp_isacks;		/* total sacks received */
9319f13099eSGeorge Shepherd 	uint64_t	sctp_idupchunks;	/* rx dups, ord or unord */
9329f13099eSGeorge Shepherd 	uint64_t	sctp_gapcnt;		/* total gap acks rx */
93335e12f9cSGeorge Shepherd 	/*
93435e12f9cSGeorge Shepherd 	 * Add the current data from the counters which are reset by snmp
93535e12f9cSGeorge Shepherd 	 * to these cumulative counters to use in per endpoint statistics.
93635e12f9cSGeorge Shepherd 	 */
93735e12f9cSGeorge Shepherd 	uint64_t	sctp_cum_obchunks;	/* sent control chunks */
93835e12f9cSGeorge Shepherd 	uint64_t	sctp_cum_odchunks;	/* sent ordered data chunks */
93935e12f9cSGeorge Shepherd 	uint64_t	sctp_cum_oudchunks;	/* sent unord data chunks */
94035e12f9cSGeorge Shepherd 	uint64_t	sctp_cum_rxtchunks;	/* retransmitted chunks */
94135e12f9cSGeorge Shepherd 	uint64_t	sctp_cum_ibchunks;	/* recv control chunks */
94235e12f9cSGeorge Shepherd 	uint64_t	sctp_cum_idchunks;	/* recv ordered data chunks */
94335e12f9cSGeorge Shepherd 	uint64_t	sctp_cum_iudchunks;	/* recv unord data chunks */
9449f13099eSGeorge Shepherd 
9459f13099eSGeorge Shepherd 	/*
9469f13099eSGeorge Shepherd 	 * When non-zero, this is the maximum observed RTO since assoc stats
9479f13099eSGeorge Shepherd 	 * were last requested. When zero, no RTO update has occurred since
9489f13099eSGeorge Shepherd 	 * the previous user request for stats on this endpoint.
9499f13099eSGeorge Shepherd 	 */
9509f13099eSGeorge Shepherd 	int	sctp_maxrto;
9519f13099eSGeorge Shepherd 	/*
9529f13099eSGeorge Shepherd 	 * The stored value of sctp_maxrto passed to user during the previous
9539f13099eSGeorge Shepherd 	 * user request for stats on this endpoint.
9549f13099eSGeorge Shepherd 	 */
9559f13099eSGeorge Shepherd 	int	sctp_prev_maxrto;
9565dd46ab5SKacheong Poon 
9575dd46ab5SKacheong Poon 	/* For association counting. */
9585dd46ab5SKacheong Poon 	sctp_listen_cnt_t	*sctp_listen_cnt;
9597c478bd9Sstevel@tonic-gate } sctp_t;
9607c478bd9Sstevel@tonic-gate 
9610f1702c5SYu Xiangning #define	SCTP_TXQ_LEN(sctp)	((sctp)->sctp_unsent + (sctp)->sctp_unacked)
9620f1702c5SYu Xiangning #define	SCTP_TXQ_UPDATE(sctp)					\
9630f1702c5SYu Xiangning 	if ((sctp)->sctp_txq_full && SCTP_TXQ_LEN(sctp) <=	\
964bd670b35SErik Nordmark 	    (sctp)->sctp_connp->conn_sndlowat) {		\
9650f1702c5SYu Xiangning 		(sctp)->sctp_txq_full = 0;			\
966a215d4ebSKacheong Poon 		(sctp)->sctp_ulp_txq_full((sctp)->sctp_ulpd,	\
9670f1702c5SYu Xiangning 		    B_FALSE);					\
9680f1702c5SYu Xiangning 	}
9690f1702c5SYu Xiangning 
9707c478bd9Sstevel@tonic-gate #endif	/* (defined(_KERNEL) || defined(_KMEMUSER)) */
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate extern void	sctp_ack_timer(sctp_t *);
973558fbd03Skcpoon extern size_t	sctp_adaptation_code_param(sctp_t *, uchar_t *);
974558fbd03Skcpoon extern void	sctp_adaptation_event(sctp_t *);
9757f093707Skcpoon extern void	sctp_add_err(sctp_t *, uint16_t, void *, size_t,
9767f093707Skcpoon 		    sctp_faddr_t *);
97777c67f2fSkcpoon extern int	sctp_add_faddr(sctp_t *, in6_addr_t *, int, boolean_t);
9787c478bd9Sstevel@tonic-gate extern boolean_t sctp_add_ftsn_set(sctp_ftsn_set_t **, sctp_faddr_t *, mblk_t *,
9797c478bd9Sstevel@tonic-gate 		    uint_t *, uint32_t *);
980bd670b35SErik Nordmark extern void	sctp_add_recvq(sctp_t *, mblk_t *, boolean_t,
981bd670b35SErik Nordmark 		    ip_recv_attr_t *);
982c513743fSGeorge Shepherd extern void	sctp_add_unrec_parm(sctp_parm_hdr_t *, mblk_t **, boolean_t);
98312f47623Skcpoon extern size_t	sctp_addr_params(sctp_t *, int, uchar_t *, boolean_t);
984df19b344Svi extern mblk_t	*sctp_add_proto_hdr(sctp_t *, sctp_faddr_t *, mblk_t *, int,
985df19b344Svi 		    int *);
9867c478bd9Sstevel@tonic-gate extern void	sctp_addr_req(sctp_t *, mblk_t *);
9877c478bd9Sstevel@tonic-gate extern sctp_t	*sctp_addrlist2sctp(mblk_t *, sctp_hdr_t *, sctp_chunk_hdr_t *,
988e35d2278Svi 		    zoneid_t, sctp_stack_t *);
9897c478bd9Sstevel@tonic-gate extern void	sctp_check_adv_ack_pt(sctp_t *, mblk_t *, mblk_t *);
9907c478bd9Sstevel@tonic-gate extern void	sctp_assoc_event(sctp_t *, uint16_t, uint16_t,
9917c478bd9Sstevel@tonic-gate 		    sctp_chunk_hdr_t *);
9927c478bd9Sstevel@tonic-gate 
9937c478bd9Sstevel@tonic-gate extern void	sctp_bind_hash_insert(sctp_tf_t *, sctp_t *, int);
9947c478bd9Sstevel@tonic-gate extern void	sctp_bind_hash_remove(sctp_t *);
99545916cd2Sjpk extern int	sctp_bindi(sctp_t *, in_port_t, boolean_t, int, in_port_t *);
9961d8c4025Svi extern int	sctp_bind_add(sctp_t *, const void *, uint32_t, boolean_t,
9971d8c4025Svi 		    in_port_t);
9987c478bd9Sstevel@tonic-gate extern int	sctp_bind_del(sctp_t *, const void *, uint32_t, boolean_t);
999bd670b35SErik Nordmark extern int	sctp_build_hdrs(sctp_t *, int);
10007c478bd9Sstevel@tonic-gate 
10017c478bd9Sstevel@tonic-gate extern int	sctp_check_abandoned_msg(sctp_t *, mblk_t *);
10027c478bd9Sstevel@tonic-gate extern void	sctp_clean_death(sctp_t *, int);
10037c478bd9Sstevel@tonic-gate extern void	sctp_close_eager(sctp_t *);
10047c478bd9Sstevel@tonic-gate extern int	sctp_compare_faddrsets(sctp_faddr_t *, sctp_faddr_t *);
10057c478bd9Sstevel@tonic-gate extern void	sctp_congest_reset(sctp_t *);
10067c478bd9Sstevel@tonic-gate extern void	sctp_conn_hash_insert(sctp_tf_t *, sctp_t *, int);
10077c478bd9Sstevel@tonic-gate extern void	sctp_conn_hash_remove(sctp_t *);
1008121e5416Skcpoon extern void	sctp_conn_init(conn_t *);
1009a5407c02SAnil udupa extern sctp_t	*sctp_conn_match(in6_addr_t **, uint32_t, in6_addr_t *,
1010a5407c02SAnil udupa 		    uint32_t, zoneid_t, iaflags_t, sctp_stack_t *);
10115dd46ab5SKacheong Poon extern void	sctp_conn_reclaim(void *);
10127c478bd9Sstevel@tonic-gate extern sctp_t	*sctp_conn_request(sctp_t *, mblk_t *, uint_t, uint_t,
1013bd670b35SErik Nordmark 		    sctp_init_chunk_t *, ip_recv_attr_t *);
10147c478bd9Sstevel@tonic-gate extern uint32_t	sctp_cumack(sctp_t *, uint32_t, mblk_t **);
10157c478bd9Sstevel@tonic-gate extern sctp_t	*sctp_create_eager(sctp_t *);
10167c478bd9Sstevel@tonic-gate 
10177c478bd9Sstevel@tonic-gate extern void	sctp_dispatch_rput(queue_t *, sctp_t *, sctp_hdr_t *, mblk_t *,
10187c478bd9Sstevel@tonic-gate 		    uint_t, uint_t, in6_addr_t);
10197c478bd9Sstevel@tonic-gate extern char	*sctp_display(sctp_t *, char *);
1020f4b3ec61Sdh extern void	sctp_display_all(sctp_stack_t *);
10217c478bd9Sstevel@tonic-gate 
10228dfac042SAnil udupa extern void	sctp_error_event(sctp_t *, sctp_chunk_hdr_t *, boolean_t);
10237c478bd9Sstevel@tonic-gate 
10247c478bd9Sstevel@tonic-gate extern void	sctp_faddr_alive(sctp_t *, sctp_faddr_t *);
10257c478bd9Sstevel@tonic-gate extern int	sctp_faddr_dead(sctp_t *, sctp_faddr_t *, int);
102645916cd2Sjpk extern void	sctp_faddr_fini(void);
102745916cd2Sjpk extern void	sctp_faddr_init(void);
10287c478bd9Sstevel@tonic-gate extern void	sctp_fast_rexmit(sctp_t *);
10297c478bd9Sstevel@tonic-gate extern void	sctp_fill_sack(sctp_t *, unsigned char *, int);
10305dd46ab5SKacheong Poon extern uint32_t sctp_find_listener_conf(sctp_stack_t *, in_port_t);
10317c478bd9Sstevel@tonic-gate extern void	sctp_free_faddr_timers(sctp_t *);
10327c478bd9Sstevel@tonic-gate extern void	sctp_free_ftsn_set(sctp_ftsn_set_t *);
10337c478bd9Sstevel@tonic-gate extern void	sctp_free_msg(mblk_t *);
10347c478bd9Sstevel@tonic-gate extern void	sctp_free_reass(sctp_instr_t *);
10357c478bd9Sstevel@tonic-gate extern void	sctp_free_set(sctp_set_t *);
10367c478bd9Sstevel@tonic-gate extern void	sctp_ftsn_sets_fini(void);
10377c478bd9Sstevel@tonic-gate extern void	sctp_ftsn_sets_init(void);
10387c478bd9Sstevel@tonic-gate 
10391d8c4025Svi extern int	sctp_get_addrlist(sctp_t *, const void *, uint32_t *,
10401d8c4025Svi 		    uchar_t **, int *, size_t *);
10417c478bd9Sstevel@tonic-gate extern int	sctp_get_addrparams(sctp_t *, sctp_t *, mblk_t *,
10427c478bd9Sstevel@tonic-gate 		    sctp_chunk_hdr_t *, uint_t *);
1043bd670b35SErik Nordmark extern void	sctp_get_dest(sctp_t *, sctp_faddr_t *);
10441d8c4025Svi extern void	sctp_get_faddr_list(sctp_t *, uchar_t *, size_t);
10457c478bd9Sstevel@tonic-gate extern mblk_t	*sctp_get_first_sent(sctp_t *);
10467c478bd9Sstevel@tonic-gate extern mblk_t	*sctp_get_msg_to_send(sctp_t *, mblk_t **, mblk_t *, int  *,
10477c478bd9Sstevel@tonic-gate 		    int32_t, uint32_t, sctp_faddr_t *);
10481d8c4025Svi extern void	sctp_get_saddr_list(sctp_t *, uchar_t *, size_t);
10497c478bd9Sstevel@tonic-gate 
10507c478bd9Sstevel@tonic-gate extern int	sctp_handle_error(sctp_t *, sctp_hdr_t *, sctp_chunk_hdr_t *,
1051bd670b35SErik Nordmark 		    mblk_t *, ip_recv_attr_t *);
1052f4b3ec61Sdh extern void	sctp_hash_destroy(sctp_stack_t *);
1053f4b3ec61Sdh extern void	sctp_hash_init(sctp_stack_t *);
10547c478bd9Sstevel@tonic-gate extern void	sctp_heartbeat_timer(sctp_t *);
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate extern void	sctp_icmp_error(sctp_t *, mblk_t *);
1057f4b3ec61Sdh extern void	sctp_inc_taskq(sctp_stack_t *);
10587c478bd9Sstevel@tonic-gate extern void	sctp_info_req(sctp_t *, mblk_t *);
1059bd670b35SErik Nordmark extern mblk_t	*sctp_init_mp(sctp_t *, sctp_faddr_t *);
10607c478bd9Sstevel@tonic-gate extern boolean_t sctp_initialize_params(sctp_t *, sctp_init_chunk_t *,
10617c478bd9Sstevel@tonic-gate 		    sctp_init_chunk_t *);
10627c478bd9Sstevel@tonic-gate extern uint32_t	sctp_init2vtag(sctp_chunk_hdr_t *);
10637c478bd9Sstevel@tonic-gate extern void	sctp_intf_event(sctp_t *, in6_addr_t, int, int);
1064bd670b35SErik Nordmark extern void	sctp_input_data(sctp_t *, mblk_t *, ip_recv_attr_t *);
10657c478bd9Sstevel@tonic-gate extern void	sctp_instream_cleanup(sctp_t *, boolean_t);
10665dd46ab5SKacheong Poon extern boolean_t sctp_is_a_faddr_clean(sctp_t *);
10677c478bd9Sstevel@tonic-gate 
1068f4b3ec61Sdh extern void	*sctp_kstat_init(netstackid_t);
1069f4b3ec61Sdh extern void	sctp_kstat_fini(netstackid_t, kstat_t *);
10705dd46ab5SKacheong Poon extern void	*sctp_kstat2_init(netstackid_t);
1071f4b3ec61Sdh extern void	sctp_kstat2_fini(netstackid_t, kstat_t *);
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate extern ssize_t	sctp_link_abort(mblk_t *, uint16_t, char *, size_t, int,
10747c478bd9Sstevel@tonic-gate 		    boolean_t);
10757c478bd9Sstevel@tonic-gate extern void	sctp_listen_hash_insert(sctp_tf_t *, sctp_t *);
10767c478bd9Sstevel@tonic-gate extern void	sctp_listen_hash_remove(sctp_t *);
10775dd46ab5SKacheong Poon extern void	sctp_listener_conf_cleanup(sctp_stack_t *);
10787c478bd9Sstevel@tonic-gate extern sctp_t	*sctp_lookup(sctp_t *, in6_addr_t *, sctp_tf_t *, uint32_t *,
10797c478bd9Sstevel@tonic-gate 		    int);
10807c478bd9Sstevel@tonic-gate extern sctp_faddr_t *sctp_lookup_faddr(sctp_t *, in6_addr_t *);
10817c478bd9Sstevel@tonic-gate 
10827c478bd9Sstevel@tonic-gate extern mblk_t	*sctp_make_err(sctp_t *, uint16_t, void *, size_t);
10837c478bd9Sstevel@tonic-gate extern mblk_t	*sctp_make_ftsn_chunk(sctp_t *, sctp_faddr_t *,
10847c478bd9Sstevel@tonic-gate 		    sctp_ftsn_set_t *, uint_t, uint32_t);
10857c478bd9Sstevel@tonic-gate extern void	sctp_make_ftsns(sctp_t *, mblk_t *, mblk_t *, mblk_t **,
10867c478bd9Sstevel@tonic-gate 		    sctp_faddr_t *, uint32_t *);
10877c478bd9Sstevel@tonic-gate extern mblk_t	*sctp_make_mp(sctp_t *, sctp_faddr_t *, int);
10887c478bd9Sstevel@tonic-gate extern mblk_t	*sctp_make_sack(sctp_t *, sctp_faddr_t *, mblk_t *);
10897c478bd9Sstevel@tonic-gate extern void	sctp_maxpsz_set(sctp_t *);
10907c478bd9Sstevel@tonic-gate extern void	sctp_move_faddr_timers(queue_t *, sctp_t *);
10917c478bd9Sstevel@tonic-gate 
10927c478bd9Sstevel@tonic-gate extern sctp_parm_hdr_t *sctp_next_parm(sctp_parm_hdr_t *, ssize_t *);
10937c478bd9Sstevel@tonic-gate 
1094bd670b35SErik Nordmark extern void	sctp_ootb_shutdown_ack(mblk_t *, uint_t, ip_recv_attr_t *,
1095bd670b35SErik Nordmark 		    ip_stack_t *);
10967c478bd9Sstevel@tonic-gate extern size_t	sctp_options_param(const sctp_t *, void *, int);
10977c478bd9Sstevel@tonic-gate extern size_t	sctp_options_param_len(const sctp_t *, int);
109812f47623Skcpoon extern void	sctp_output(sctp_t *, uint_t);
10997c478bd9Sstevel@tonic-gate 
11007c478bd9Sstevel@tonic-gate extern void	sctp_partial_delivery_event(sctp_t *);
11017c478bd9Sstevel@tonic-gate extern int	sctp_process_cookie(sctp_t *, sctp_chunk_hdr_t *, mblk_t *,
1102bd670b35SErik Nordmark 		    sctp_init_chunk_t **, sctp_hdr_t *, int *, in6_addr_t *,
1103bd670b35SErik Nordmark 		    ip_recv_attr_t *);
11047f093707Skcpoon extern void	sctp_process_err(sctp_t *);
11057c478bd9Sstevel@tonic-gate extern void	sctp_process_heartbeat(sctp_t *, sctp_chunk_hdr_t *);
11067c478bd9Sstevel@tonic-gate extern void	sctp_process_timer(sctp_t *);
11077c478bd9Sstevel@tonic-gate 
11087c478bd9Sstevel@tonic-gate extern void	sctp_redo_faddr_srcs(sctp_t *);
11097c478bd9Sstevel@tonic-gate extern void	sctp_regift_xmitlist(sctp_t *);
11107c478bd9Sstevel@tonic-gate extern void	sctp_return_heartbeat(sctp_t *, sctp_chunk_hdr_t *, mblk_t *);
11117c478bd9Sstevel@tonic-gate extern void	sctp_rexmit(sctp_t *, sctp_faddr_t *);
1112769b977dSvi extern mblk_t	*sctp_rexmit_packet(sctp_t *, mblk_t **, mblk_t **,
1113769b977dSvi 		    sctp_faddr_t *, uint_t *);
11147c478bd9Sstevel@tonic-gate extern void	sctp_rexmit_timer(sctp_t *, sctp_faddr_t *);
11157c478bd9Sstevel@tonic-gate extern sctp_faddr_t *sctp_rotate_faddr(sctp_t *, sctp_faddr_t *);
11167c478bd9Sstevel@tonic-gate 
11177f093707Skcpoon extern boolean_t sctp_sack(sctp_t *, mblk_t *);
11187c478bd9Sstevel@tonic-gate extern int	sctp_secure_restart_check(mblk_t *, sctp_chunk_hdr_t *,
1119bd670b35SErik Nordmark 		    uint32_t, int, sctp_stack_t *, ip_recv_attr_t *);
11207c478bd9Sstevel@tonic-gate extern void	sctp_send_abort(sctp_t *, uint32_t, uint16_t, char *, size_t,
1121bd670b35SErik Nordmark 		    mblk_t *, int, boolean_t, ip_recv_attr_t *);
1122bd670b35SErik Nordmark extern void	sctp_ootb_send_abort(uint32_t, uint16_t, char *, size_t,
1123bd670b35SErik Nordmark 		    const mblk_t *, int, boolean_t, ip_recv_attr_t *,
1124bd670b35SErik Nordmark 		    ip_stack_t *);
11257c478bd9Sstevel@tonic-gate extern void	sctp_send_cookie_ack(sctp_t *);
1126bd670b35SErik Nordmark extern void	sctp_send_cookie_echo(sctp_t *, sctp_chunk_hdr_t *, mblk_t *,
1127bd670b35SErik Nordmark 			ip_recv_attr_t *);
1128d7ab25acSkp extern void	sctp_send_initack(sctp_t *, sctp_hdr_t *, sctp_chunk_hdr_t *,
1129bd670b35SErik Nordmark 		    mblk_t *, ip_recv_attr_t *);
11307c478bd9Sstevel@tonic-gate extern void	sctp_send_shutdown(sctp_t *, int);
11317c478bd9Sstevel@tonic-gate extern void	sctp_send_heartbeat(sctp_t *, sctp_faddr_t *);
11327c478bd9Sstevel@tonic-gate extern void	sctp_sendfail_event(sctp_t *, mblk_t *, int, boolean_t);
113377c67f2fSkcpoon extern void	sctp_set_faddr_current(sctp_t *, sctp_faddr_t *);
113477c67f2fSkcpoon extern int	sctp_set_hdraddrs(sctp_t *);
1135769b977dSvi extern void	sctp_set_saddr(sctp_t *, sctp_faddr_t *);
113645916cd2Sjpk extern void	sctp_sets_init(void);
113745916cd2Sjpk extern void	sctp_sets_fini(void);
11387c478bd9Sstevel@tonic-gate extern void	sctp_shutdown_event(sctp_t *);
11397c478bd9Sstevel@tonic-gate extern void	sctp_stop_faddr_timers(sctp_t *);
114077c67f2fSkcpoon extern int	sctp_shutdown_received(sctp_t *, sctp_chunk_hdr_t *, boolean_t,
114177c67f2fSkcpoon 		    boolean_t, sctp_faddr_t *);
11427c478bd9Sstevel@tonic-gate extern void	sctp_shutdown_complete(sctp_t *);
11437c478bd9Sstevel@tonic-gate extern void	sctp_set_if_mtu(sctp_t *);
1144bd670b35SErik Nordmark extern void	sctp_set_iplen(sctp_t *, mblk_t *, ip_xmit_attr_t *);
11457c478bd9Sstevel@tonic-gate extern void	sctp_set_ulp_prop(sctp_t *);
114677c67f2fSkcpoon extern void	sctp_ss_rexmit(sctp_t *);
11475dd46ab5SKacheong Poon extern void	sctp_stack_cpu_add(sctp_stack_t *, processorid_t);
11487c478bd9Sstevel@tonic-gate extern size_t	sctp_supaddr_param_len(sctp_t *);
11497c478bd9Sstevel@tonic-gate extern size_t	sctp_supaddr_param(sctp_t *, uchar_t *);
11507c478bd9Sstevel@tonic-gate 
11517c478bd9Sstevel@tonic-gate extern void	sctp_timer(sctp_t *, mblk_t *, clock_t);
1152121e5416Skcpoon extern mblk_t	*sctp_timer_alloc(sctp_t *, pfv_t, int);
11537c478bd9Sstevel@tonic-gate extern void	sctp_timer_call(sctp_t *sctp, mblk_t *);
11547c478bd9Sstevel@tonic-gate extern void	sctp_timer_free(mblk_t *);
11557c478bd9Sstevel@tonic-gate extern void	sctp_timer_stop(mblk_t *);
11567c478bd9Sstevel@tonic-gate extern void	sctp_unlink_faddr(sctp_t *, sctp_faddr_t *);
11577c478bd9Sstevel@tonic-gate 
1158bd670b35SErik Nordmark extern void	sctp_update_dce(sctp_t *sctp);
1159f4b3ec61Sdh extern in_port_t sctp_update_next_port(in_port_t, zone_t *zone, sctp_stack_t *);
11607c478bd9Sstevel@tonic-gate extern void	sctp_update_rtt(sctp_t *, sctp_faddr_t *, clock_t);
1161e6f13f86SKacheong Poon extern void	sctp_user_abort(sctp_t *, mblk_t *);
11627c478bd9Sstevel@tonic-gate 
11637c478bd9Sstevel@tonic-gate extern void	sctp_validate_peer(sctp_t *);
11647c478bd9Sstevel@tonic-gate 
11657c478bd9Sstevel@tonic-gate extern int	sctp_xmit_list_clean(sctp_t *, ssize_t);
11667c478bd9Sstevel@tonic-gate 
11677c478bd9Sstevel@tonic-gate extern void	sctp_zap_addrs(sctp_t *);
11687c478bd9Sstevel@tonic-gate extern void	sctp_zap_faddrs(sctp_t *, int);
1169a5407c02SAnil udupa extern sctp_chunk_hdr_t	*sctp_first_chunk(uchar_t *, ssize_t);
11703e1dae9fSAnil udupa extern void	sctp_send_shutdown_ack(sctp_t *, sctp_faddr_t *, boolean_t);
11717c478bd9Sstevel@tonic-gate 
11721d8c4025Svi /* Contract private interface between SCTP and Clustering - PSARC/2005/602 */
11731d8c4025Svi 
11741d8c4025Svi extern void	(*cl_sctp_listen)(sa_family_t, uchar_t *, uint_t, in_port_t);
11751d8c4025Svi extern void	(*cl_sctp_unlisten)(sa_family_t, uchar_t *, uint_t, in_port_t);
11761d8c4025Svi extern void 	(*cl_sctp_connect)(sa_family_t, uchar_t *, uint_t, in_port_t,
11771d8c4025Svi 		    uchar_t *, uint_t, in_port_t, boolean_t, cl_sctp_handle_t);
11781d8c4025Svi extern void	(*cl_sctp_disconnect)(sa_family_t, cl_sctp_handle_t);
11791d8c4025Svi extern void	(*cl_sctp_assoc_change)(sa_family_t, uchar_t *, size_t, uint_t,
11801d8c4025Svi 		    uchar_t *, size_t, uint_t, int, cl_sctp_handle_t);
11811d8c4025Svi extern void	(*cl_sctp_check_addrs)(sa_family_t, in_port_t, uchar_t **,
11821d8c4025Svi 		    size_t, uint_t *, boolean_t);
11831d8c4025Svi 
11847c478bd9Sstevel@tonic-gate #define	RUN_SCTP(sctp)						\
11857c478bd9Sstevel@tonic-gate {								\
11867c478bd9Sstevel@tonic-gate 	mutex_enter(&(sctp)->sctp_lock);			\
11877c478bd9Sstevel@tonic-gate 	while ((sctp)->sctp_running)				\
11887c478bd9Sstevel@tonic-gate 		cv_wait(&(sctp)->sctp_cv, &(sctp)->sctp_lock);	\
11897c478bd9Sstevel@tonic-gate 	(sctp)->sctp_running = B_TRUE;				\
11907c478bd9Sstevel@tonic-gate 	mutex_exit(&(sctp)->sctp_lock);				\
11917c478bd9Sstevel@tonic-gate }
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate /* Wake up recvq taskq */
11947c478bd9Sstevel@tonic-gate #define	WAKE_SCTP(sctp)				\
11957c478bd9Sstevel@tonic-gate {						\
11967c478bd9Sstevel@tonic-gate 	mutex_enter(&(sctp)->sctp_lock);	\
11977c478bd9Sstevel@tonic-gate 	if ((sctp)->sctp_timer_mp != NULL)	\
11987c478bd9Sstevel@tonic-gate 		sctp_process_timer(sctp);	\
11997c478bd9Sstevel@tonic-gate 	(sctp)->sctp_running = B_FALSE;		\
12007c478bd9Sstevel@tonic-gate 	cv_broadcast(&(sctp)->sctp_cv);		\
12017c478bd9Sstevel@tonic-gate 	mutex_exit(&(sctp)->sctp_lock);		\
12027c478bd9Sstevel@tonic-gate }
12037c478bd9Sstevel@tonic-gate 
12047c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
12057c478bd9Sstevel@tonic-gate }
12067c478bd9Sstevel@tonic-gate #endif
12077c478bd9Sstevel@tonic-gate 
12087c478bd9Sstevel@tonic-gate #endif	/* _INET_SCTP_SCTP_IMPL_H */
1209