Home | History | Annotate | Download | only in sctp
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 
     22 /*
     23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 #ifndef	_INET_SCTP_SCTP_IMPL_H
     28 #define	_INET_SCTP_SCTP_IMPL_H
     29 
     30 #include <sys/inttypes.h>
     31 #include <sys/taskq.h>
     32 #include <sys/list.h>
     33 #include <sys/strsun.h>
     34 #include <sys/zone.h>
     35 #include <netinet/ip6.h>
     36 #include <inet/optcom.h>
     37 #include <netinet/sctp.h>
     38 #include <inet/sctp_itf.h>
     39 #include "sctp_stack.h"
     40 
     41 #ifdef	__cplusplus
     42 extern "C" {
     43 #endif
     44 
     45 /* Streams device identifying info and version */
     46 #define	SCTP_DEV_IDINFO	"SCTP Streams device 1.0"
     47 
     48 #define	SSN_GT(a, b)	((int16_t)((a)-(b)) > 0)
     49 #define	SSN_GE(a, b)	((int16_t)((a)-(b)) >= 0)
     50 
     51 /* Default buffer size and flow control wake up threshold. */
     52 #define	SCTP_XMIT_LOWATER	8192
     53 #define	SCTP_XMIT_HIWATER	102400
     54 #define	SCTP_RECV_LOWATER	8192
     55 #define	SCTP_RECV_HIWATER	102400
     56 
     57 /* SCTP Timer control structure */
     58 typedef struct sctpt_s {
     59 	pfv_t	sctpt_pfv;	/* The routine we are to call */
     60 	struct sctp_s *sctpt_sctp;	/* The parameter we are to pass in */
     61 	struct sctp_faddr_s *sctpt_faddr;
     62 } sctpt_t;
     63 
     64 /*
     65  * Maximum number of duplicate TSNs we can report. This is currently
     66  * static, and governs the size of the mblk used to hold the duplicate
     67  * reports. The use of duplcate TSN reports is currently experimental,
     68  * so for now a static limit should suffice.
     69  */
     70 #define	SCTP_DUP_MBLK_SZ	64
     71 
     72 #define	SCTP_IS_ADDR_UNSPEC(isv4, addr)		\
     73 	((isv4) ? IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) :	\
     74 	IN6_IS_ADDR_UNSPECIFIED(&(addr)))
     75 
     76 /*
     77  * SCTP parameters
     78  */
     79 /* Named Dispatch Parameter Management Structure */
     80 typedef struct sctpparam_s {
     81 	uint32_t	sctp_param_min;
     82 	uint32_t	sctp_param_max;
     83 	uint32_t	sctp_param_val;
     84 	char		*sctp_param_name;
     85 } sctpparam_t;
     86 
     87 #define	sctps_max_init_retr		sctps_params[0].sctp_param_val
     88 #define	sctps_max_init_retr_high	sctps_params[0].sctp_param_max
     89 #define	sctps_max_init_retr_low		sctps_params[0].sctp_param_min
     90 #define	sctps_pa_max_retr		sctps_params[1].sctp_param_val
     91 #define	sctps_pa_max_retr_high		sctps_params[1].sctp_param_max
     92 #define	sctps_pa_max_retr_low		sctps_params[1].sctp_param_min
     93 #define	sctps_pp_max_retr		sctps_params[2].sctp_param_val
     94 #define	sctps_pp_max_retr_high		sctps_params[2].sctp_param_max
     95 #define	sctps_pp_max_retr_low		sctps_params[2].sctp_param_min
     96 #define	sctps_cwnd_max_			sctps_params[3].sctp_param_val
     97 #define	__sctps_not_used1		sctps_params[4].sctp_param_val
     98 #define	sctps_smallest_nonpriv_port	sctps_params[5].sctp_param_val
     99 #define	sctps_ipv4_ttl			sctps_params[6].sctp_param_val
    100 #define	sctps_heartbeat_interval	sctps_params[7].sctp_param_val
    101 #define	sctps_heartbeat_interval_high	sctps_params[7].sctp_param_max
    102 #define	sctps_heartbeat_interval_low	sctps_params[7].sctp_param_min
    103 #define	sctps_initial_mtu		sctps_params[8].sctp_param_val
    104 #define	sctps_mtu_probe_interval	sctps_params[9].sctp_param_val
    105 #define	sctps_new_secret_interval	sctps_params[10].sctp_param_val
    106 #define	sctps_deferred_ack_interval	sctps_params[11].sctp_param_val
    107 #define	sctps_snd_lowat_fraction	sctps_params[12].sctp_param_val
    108 #define	sctps_ignore_path_mtu		sctps_params[13].sctp_param_val
    109 #define	sctps_initial_ssthresh		sctps_params[14].sctp_param_val
    110 #define	sctps_smallest_anon_port	sctps_params[15].sctp_param_val
    111 #define	sctps_largest_anon_port		sctps_params[16].sctp_param_val
    112 #define	sctps_xmit_hiwat		sctps_params[17].sctp_param_val
    113 #define	sctps_xmit_lowat		sctps_params[18].sctp_param_val
    114 #define	sctps_recv_hiwat		sctps_params[19].sctp_param_val
    115 #define	sctps_max_buf			sctps_params[20].sctp_param_val
    116 #define	sctps_rtt_updates		sctps_params[21].sctp_param_val
    117 #define	sctps_ipv6_hoplimit		sctps_params[22].sctp_param_val
    118 #define	sctps_rto_ming			sctps_params[23].sctp_param_val
    119 #define	sctps_rto_ming_high		sctps_params[23].sctp_param_max
    120 #define	sctps_rto_ming_low		sctps_params[23].sctp_param_min
    121 #define	sctps_rto_maxg			sctps_params[24].sctp_param_val
    122 #define	sctps_rto_maxg_high		sctps_params[24].sctp_param_max
    123 #define	sctps_rto_maxg_low		sctps_params[24].sctp_param_min
    124 #define	sctps_rto_initialg		sctps_params[25].sctp_param_val
    125 #define	sctps_rto_initialg_high		sctps_params[25].sctp_param_max
    126 #define	sctps_rto_initialg_low		sctps_params[25].sctp_param_min
    127 #define	sctps_cookie_life		sctps_params[26].sctp_param_val
    128 #define	sctps_cookie_life_high		sctps_params[26].sctp_param_max
    129 #define	sctps_cookie_life_low		sctps_params[26].sctp_param_min
    130 #define	sctps_max_in_streams		sctps_params[27].sctp_param_val
    131 #define	sctps_max_in_streams_high	sctps_params[27].sctp_param_max
    132 #define	sctps_max_in_streams_low	sctps_params[27].sctp_param_min
    133 #define	sctps_initial_out_streams	sctps_params[28].sctp_param_val
    134 #define	sctps_initial_out_streams_high	sctps_params[28].sctp_param_max
    135 #define	sctps_initial_out_streams_low	sctps_params[28].sctp_param_min
    136 #define	sctps_shutack_wait_bound	sctps_params[29].sctp_param_val
    137 #define	sctps_maxburst			sctps_params[30].sctp_param_val
    138 #define	sctps_addip_enabled		sctps_params[31].sctp_param_val
    139 #define	sctps_recv_hiwat_minmss		sctps_params[32].sctp_param_val
    140 #define	sctps_slow_start_initial	sctps_params[33].sctp_param_val
    141 #define	sctps_slow_start_after_idle	sctps_params[34].sctp_param_val
    142 #define	sctps_prsctp_enabled		sctps_params[35].sctp_param_val
    143 #define	sctps_fast_rxt_thresh		sctps_params[36].sctp_param_val
    144 #define	sctps_deferred_acks_max		sctps_params[37].sctp_param_val
    145 
    146 /*
    147  * sctp_wroff_xtra is the extra space in front of SCTP/IP header for link
    148  * layer header.  It has to be a multiple of 4.
    149  */
    150 #define	sctps_wroff_xtra	sctps_wroff_xtra_param->sctp_param_val
    151 
    152 /*
    153  * Retransmission timer start and stop macro for a given faddr.
    154  */
    155 #define	SCTP_FADDR_TIMER_RESTART(sctp, fp, intvl)			\
    156 {									\
    157 	dprint(3, ("faddr_timer_restart: fp=%p %x:%x:%x:%x %d\n",	\
    158 	    (void *)(fp), SCTP_PRINTADDR((fp)->faddr), (int)(intvl)));	\
    159 	sctp_timer((sctp), (fp)->timer_mp, (intvl));			\
    160 	(fp)->timer_running = 1;					\
    161 }
    162 
    163 #define	SCTP_FADDR_TIMER_STOP(fp)			\
    164 	ASSERT((fp)->timer_mp != NULL);			\
    165 	if ((fp)->timer_running) {			\
    166 		sctp_timer_stop((fp)->timer_mp);	\
    167 		(fp)->timer_running = 0;		\
    168 	}
    169 
    170 /* For per endpoint association statistics */
    171 #define	SCTP_MAX_RTO(sctp, fp) {			\
    172 	/*						\
    173 	 * Record the maximum observed RTO,		\
    174 	 * sctp_maxrto is zeroed elsewhere		\
    175 	 * at the end of each stats request.		\
    176 	 */						\
    177 	(sctp)->sctp_maxrto =				\
    178 	    MAX((sctp)->sctp_maxrto, (fp)->rto);	\
    179 	DTRACE_PROBE2(sctp__maxrto, sctp_t *,		\
    180 	    sctp, struct sctp_faddr_s, fp);		\
    181 }
    182 
    183 #define	SCTP_CALC_RXT(sctp, fp)				\
    184 {							\
    185 	if (((fp)->rto <<= 1) > (sctp)->sctp_rto_max)	\
    186 		(fp)->rto = (sctp)->sctp_rto_max;	\
    187 	SCTP_MAX_RTO(sctp, fp);				\
    188 }
    189 
    190 
    191 #define	SCTP_MAX_COMBINED_HEADER_LENGTH	(60 + 12) /* Maxed out ip + sctp */
    192 #define	SCTP_MAX_IP_OPTIONS_LENGTH	(60 - IP_SIMPLE_HDR_LENGTH)
    193 #define	SCTP_MAX_HDR_LENGTH		60
    194 
    195 #define	SCTP_SECRET_LEN	16
    196 
    197 #define	SCTP_REFHOLD(sctp) {			\
    198 	mutex_enter(&(sctp)->sctp_reflock);	\
    199 	(sctp)->sctp_refcnt++;			\
    200 	ASSERT((sctp)->sctp_refcnt != 0);	\
    201 	mutex_exit(&(sctp)->sctp_reflock);	\
    202 }
    203 
    204 #define	SCTP_REFRELE(sctp) {				\
    205 	mutex_enter(&(sctp)->sctp_reflock);		\
    206 	ASSERT((sctp)->sctp_refcnt != 0);		\
    207 	if (--(sctp)->sctp_refcnt == 0) {		\
    208 		mutex_exit(&(sctp)->sctp_reflock);	\
    209 		CONN_DEC_REF((sctp)->sctp_connp);	\
    210 	} else {					\
    211 		mutex_exit(&(sctp)->sctp_reflock);	\
    212 	}						\
    213 }
    214 
    215 #define	SCTP_PRINTADDR(a)	(a).s6_addr32[0], (a).s6_addr32[1],\
    216 				(a).s6_addr32[2], (a).s6_addr32[3]
    217 
    218 #define	CONN2SCTP(conn)	((sctp_t *)(&((conn_t *)conn)[1]))
    219 
    220 /*
    221  * Outbound data, flags and macros for per-message, per-chunk info
    222  */
    223 typedef struct {
    224 	int64_t		smh_ttl;		/* Time to Live */
    225 	int64_t		smh_tob;		/* Time of Birth */
    226 	uint32_t	smh_context;
    227 	uint16_t	smh_sid;
    228 	uint16_t	smh_ssn;
    229 	uint32_t	smh_ppid;
    230 	uint16_t	smh_flags;
    231 	uint32_t	smh_msglen;
    232 } sctp_msg_hdr_t;
    233 
    234 #define	SCTP_CHUNK_FLAG_SENT		0x01
    235 #define	SCTP_CHUNK_FLAG_REXMIT		0x02
    236 #define	SCTP_CHUNK_FLAG_ACKED		0x04
    237 #define	SCTP_MSG_FLAG_CHUNKED		0x08
    238 #define	SCTP_MSG_FLAG_ABANDONED		0x10
    239 #define	SCTP_CHUNK_FLAG_ABANDONED	0x20
    240 
    241 #define	SCTP_CHUNK_CLEAR_FLAGS(mp) ((mp)->b_flag = 0)
    242 /*
    243  * If we are transmitting the chunk for the first time we assign the TSN and
    244  * SSN here. The reason we assign the SSN here (as opposed to doing it in
    245  * sctp_chunkify()) is that the chunk may expire, if PRSCTP is enabled, before
    246  * we get a chance to send it out. If we assign the SSN in sctp_chunkify()
    247  * and this happens, then we need to send a Forward TSN to the peer, which
    248  * will be expecting this SSN, assuming ordered. If we assign it here we
    249  * can just take out the chunk from the transmit list without having to
    250  * send a Forward TSN chunk. While assigning the SSN we use (meta)->b_cont
    251  * to determine if it needs a new SSN (i.e. the next SSN for the stream),
    252  * since (meta)->b_cont signifies the first chunk of a message (if the message
    253  * is unordered, then the SSN is 0).
    254  *
    255  */
    256 #define	SCTP_CHUNK_SENT(sctp, mp, sdc, fp, chunkdata, meta) {		\
    257 	if (!SCTP_CHUNK_ISSENT(mp)) {					\
    258 		sctp_msg_hdr_t	*mhdr = (sctp_msg_hdr_t *)(meta)->b_rptr; \
    259 		ASSERT(!SCTP_CHUNK_ABANDONED(mp));			\
    260 		(mp)->b_flag = SCTP_CHUNK_FLAG_SENT;			\
    261 		(sdc)->sdh_tsn = htonl((sctp)->sctp_ltsn++);		\
    262 		if ((mhdr)->smh_flags & MSG_UNORDERED) {		\
    263 			(sdc)->sdh_ssn = 0;				\
    264 			SCTP_DATA_SET_UBIT(sdc);			\
    265 			BUMP_LOCAL((sctp)->sctp_oudchunks);		\
    266 		} else {						\
    267 			BUMP_LOCAL((sctp)->sctp_odchunks);		\
    268 			if ((mp) == (meta)->b_cont) {			\
    269 				mhdr->smh_ssn = htons(			\
    270 				    (sctp)->sctp_ostrcntrs[mhdr->smh_sid]++); \
    271 			}						\
    272 			(sdc)->sdh_ssn = mhdr->smh_ssn;			\
    273 		}							\
    274 		(sctp)->sctp_unacked += (chunkdata);			\
    275 		(sctp)->sctp_unsent -= (chunkdata);			\
    276 		(sctp)->sctp_frwnd -= (chunkdata);			\
    277 	} else {							\
    278 		if (SCTP_CHUNK_ISACKED(mp)) {				\
    279 			(sctp)->sctp_unacked += (chunkdata);		\
    280 		} else {						\
    281 			ASSERT(SCTP_CHUNK_DEST(mp)->suna >= ((chunkdata) + \
    282 							sizeof (*sdc))); \
    283 			SCTP_CHUNK_DEST(mp)->suna -= ((chunkdata) + 	\
    284 					sizeof (*sdc));			\
    285 		}							\
    286 		(mp)->b_flag &= ~(SCTP_CHUNK_FLAG_REXMIT |		\
    287 			SCTP_CHUNK_FLAG_ACKED);				\
    288 		SCTP_CHUNK_SET_SACKCNT(mp, 0);				\
    289 		BUMP_LOCAL(sctp->sctp_rxtchunks);			\
    290 		BUMP_LOCAL((sctp)->sctp_T3expire);			\
    291 		BUMP_LOCAL((fp)->T3expire);				\
    292 	}								\
    293 	SCTP_SET_CHUNK_DEST(mp, fp);					\
    294 	(fp)->suna += ((chunkdata) + sizeof (*sdc));			\
    295 }
    296 
    297 #define	SCTP_CHUNK_ISSENT(mp)	((mp)->b_flag & SCTP_CHUNK_FLAG_SENT)
    298 #define	SCTP_CHUNK_CANSEND(mp)	\
    299 	(!(SCTP_CHUNK_ABANDONED(mp)) &&	\
    300 	(((mp)->b_flag & (SCTP_CHUNK_FLAG_REXMIT|SCTP_CHUNK_FLAG_SENT)) != \
    301 	SCTP_CHUNK_FLAG_SENT))
    302 
    303 #define	SCTP_CHUNK_DEST(mp)		((sctp_faddr_t *)(mp)->b_queue)
    304 #define	SCTP_SET_CHUNK_DEST(mp, fp)	((mp)->b_queue = (queue_t *)fp)
    305 
    306 #define	SCTP_CHUNK_REXMIT(mp)	((mp)->b_flag |= SCTP_CHUNK_FLAG_REXMIT)
    307 #define	SCTP_CHUNK_CLEAR_REXMIT(mp) ((mp)->b_flag &= ~SCTP_CHUNK_FLAG_REXMIT)
    308 #define	SCTP_CHUNK_WANT_REXMIT(mp) ((mp)->b_flag & SCTP_CHUNK_FLAG_REXMIT)
    309 
    310 #define	SCTP_CHUNK_ACKED(mp) \
    311 	((mp)->b_flag = (SCTP_CHUNK_FLAG_SENT|SCTP_CHUNK_FLAG_ACKED))
    312 #define	SCTP_CHUNK_ISACKED(mp)	((mp)->b_flag & SCTP_CHUNK_FLAG_ACKED)
    313 #define	SCTP_CHUNK_CLEAR_ACKED(mp) ((mp)->b_flag &= ~SCTP_CHUNK_FLAG_ACKED)
    314 
    315 #define	SCTP_CHUNK_SACKCNT(mp)	((intptr_t)((mp)->b_prev))
    316 #define	SCTP_CHUNK_SET_SACKCNT(mp, val) ((mp)->b_prev = \
    317 					(mblk_t *)(uintptr_t)(val))
    318 
    319 #define	SCTP_MSG_SET_CHUNKED(mp)	((mp)->b_flag |= SCTP_MSG_FLAG_CHUNKED)
    320 #define	SCTP_MSG_CLEAR_CHUNKED(mp)((mp)->b_flag &= ~SCTP_MSG_FLAG_CHUNKED)
    321 #define	SCTP_IS_MSG_CHUNKED(mp)	((mp)->b_flag & SCTP_MSG_FLAG_CHUNKED)
    322 
    323 /* For PR-SCTP */
    324 #define	SCTP_ABANDON_CHUNK(mp)	((mp)->b_flag |= SCTP_CHUNK_FLAG_ABANDONED)
    325 #define	SCTP_CHUNK_ABANDONED(mp) \
    326 	((mp)->b_flag & SCTP_CHUNK_FLAG_ABANDONED)
    327 
    328 #define	SCTP_MSG_SET_ABANDONED(mp)	\
    329 	((mp)->b_flag |= SCTP_MSG_FLAG_ABANDONED)
    330 #define	SCTP_MSG_CLEAR_ABANDONED(mp)((mp)->b_flag &= ~SCTP_MSG_FLAG_ABANDONED)
    331 #define	SCTP_IS_MSG_ABANDONED(mp)	((mp)->b_flag & SCTP_MSG_FLAG_ABANDONED)
    332 
    333 /*
    334  * Check if a message has expired.  A message is expired if
    335  *	1. It has a non-zero time to live value and has not been sent before
    336  *	that time expires.
    337  *	2. It is sent using PRSCTP and it has not been SACK'ed before
    338  *	its lifetime expires.
    339  */
    340 #define	SCTP_MSG_TO_BE_ABANDONED(meta, mhdr, sctp)			     \
    341 	(((!SCTP_CHUNK_ISSENT((meta)->b_cont) && (mhdr)->smh_ttl > 0) ||     \
    342 	((sctp)->sctp_prsctp_aware && ((mhdr)->smh_flags & MSG_PR_SCTP))) && \
    343 	((ddi_get_lbolt64() - (mhdr)->smh_tob) > (mhdr)->smh_ttl))
    344 
    345 /* SCTP association hash function. */
    346 #define	SCTP_CONN_HASH(sctps, ports)			\
    347 	((((ports) ^ ((ports) >> 16)) * 31) & 		\
    348 	    ((sctps)->sctps_conn_hash_size - 1))
    349 
    350 /*
    351  * Bind hash array size and hash function.  The size must be a power
    352  * of 2 and lport must be in host byte order.
    353  */
    354 #define	SCTP_BIND_FANOUT_SIZE	2048
    355 #define	SCTP_BIND_HASH(lport)	(((lport) * 31) & (SCTP_BIND_FANOUT_SIZE - 1))
    356 
    357 /* options that SCTP negotiates during association establishment */
    358 #define	SCTP_PRSCTP_OPTION	0x01
    359 
    360 /*
    361  * Listener hash array size and hash function.  The size must be a power
    362  * of 2 and lport must be in host byte order.
    363  */
    364 #define	SCTP_LISTEN_FANOUT_SIZE	512
    365 #define	SCTP_LISTEN_HASH(lport) (((lport) * 31) & (SCTP_LISTEN_FANOUT_SIZE - 1))
    366 
    367 typedef struct sctp_tf_s {
    368 	struct sctp_s	*tf_sctp;
    369 	kmutex_t	tf_lock;
    370 } sctp_tf_t;
    371 
    372 /* Round up the value to the nearest mss. */
    373 #define	MSS_ROUNDUP(value, mss)		((((value) - 1) / (mss) + 1) * (mss))
    374 
    375 extern sin_t	sctp_sin_null;	/* Zero address for quick clears */
    376 extern sin6_t	sctp_sin6_null;	/* Zero address for quick clears */
    377 
    378 #define	SCTP_IS_DETACHED(sctp)		((sctp)->sctp_detached)
    379 
    380 /* Data structure used to track received TSNs */
    381 typedef struct sctp_set_s {
    382 	struct sctp_set_s *next;
    383 	struct sctp_set_s *prev;
    384 	uint32_t begin;
    385 	uint32_t end;
    386 } sctp_set_t;
    387 
    388 /* Data structure used to track TSNs for PR-SCTP */
    389 typedef struct sctp_ftsn_set_s {
    390 	struct sctp_ftsn_set_s *next;
    391 	ftsn_entry_t	ftsn_entries;
    392 } sctp_ftsn_set_t;
    393 
    394 /* Data structure used to track incoming SCTP streams */
    395 typedef struct sctp_instr_s {
    396 	mblk_t		*istr_msgs;
    397 	int		istr_nmsgs;
    398 	uint16_t	nextseq;
    399 	struct sctp_s	*sctp;
    400 	mblk_t		*istr_reass;
    401 } sctp_instr_t;
    402 
    403 /* Reassembly data structure (per-stream) */
    404 typedef struct sctp_reass_s {
    405 	uint16_t	ssn;
    406 	uint16_t	needed;
    407 	uint16_t	got;
    408 	uint16_t	msglen;		/* len of consecutive fragments */
    409 					/* from the begining (B-bit) */
    410 	mblk_t		*tail;
    411 	boolean_t	hasBchunk;	/* If the fragment list begins with */
    412 					/* a B-bit set chunk */
    413 	uint32_t	nexttsn;	/* TSN of the next fragment we */
    414 					/* are expecting */
    415 	boolean_t	partial_delivered;
    416 } sctp_reass_t;
    417 
    418 /* debugging */
    419 #undef	dprint
    420 #ifdef DEBUG
    421 extern int sctpdebug;
    422 #define	dprint(level, args)	{ if (sctpdebug > (level)) printf args; }
    423 #else
    424 #define	dprint(level, args) {}
    425 #endif
    426 
    427 
    428 /* Peer address tracking */
    429 
    430 /*
    431  * States for peer addresses
    432  *
    433  * SCTP_FADDRS_UNCONFIRMED: we have not communicated with this peer address
    434  *     before, mark it as unconfirmed so that we will not send data to it.
    435  *     All addresses initially are in unconfirmed state and required
    436  *     validation.  SCTP sends a heartbeat to each of them and when it gets
    437  *     back a heartbeat ACK, the address will be marked as alive.  This
    438  *     validation fixes a security issue with multihoming.  If an attacker
    439  *     establishes an association with us and tells us that it has addresses
    440  *     belonging to another host A, this will prevent A from communicating
    441  *     with us.  This is fixed by peer address validation.  In the above case,
    442  *     A will respond with an abort.
    443  *
    444  * SCTP_FADDRS_ALIVE: this peer address is alive and we can communicate with
    445  *     it with no problem.
    446  *
    447  * SCTP_FADDRS_DOWN: we have exceeded the retransmission limit to this
    448  *     peer address.  Once an address is marked down, we will only send
    449  *     a heartbeat to it every hb_interval in case it becomes alive now.
    450  *
    451  * SCTP_FADDRS_UNREACH: there is no suitable source address to send to
    452  *     this peer address.  For example, the peer address is v6 but we only
    453  *     have v4 addresses.  It is marked unreachable until there is an
    454  *     address configuration change.  At that time, mark these addresses
    455  *     as unconfirmed and try again to see if those unreachable addresses
    456  *     are OK as we may have more source addresses.
    457  */
    458 typedef enum {
    459 	SCTP_FADDRS_UNREACH,
    460 	SCTP_FADDRS_DOWN,
    461 	SCTP_FADDRS_ALIVE,
    462 	SCTP_FADDRS_UNCONFIRMED
    463 } faddr_state_t;
    464 
    465 typedef struct sctp_faddr_s {
    466 	struct sctp_faddr_s *next;
    467 	faddr_state_t	state;
    468 
    469 	in6_addr_t	faddr;
    470 	in6_addr_t	saddr;
    471 
    472 	int64_t		hb_expiry;	/* time to retransmit heartbeat */
    473 	uint32_t	hb_interval;	/* the heartbeat interval */
    474 
    475 	int		rto;		/* RTO in tick */
    476 	int		srtt;		/* Smoothed RTT in tick */
    477 	int		rttvar;		/* RTT variance in tick */
    478 	uint32_t	rtt_updates;
    479 	int		strikes;
    480 	int		max_retr;
    481 	uint32_t	sfa_pmss;
    482 	uint32_t	cwnd;
    483 	uint32_t	ssthresh;
    484 	uint32_t	suna;		/* sent - unack'ed */
    485 	uint32_t	pba;		/* partial bytes acked */
    486 	uint32_t	acked;
    487 	int64_t		lastactive;
    488 	mblk_t		*timer_mp;	/* retransmission timer control */
    489 	uint32_t
    490 			hb_pending : 1,
    491 			timer_running : 1,
    492 			df : 1,
    493 			pmtu_discovered : 1,
    494 
    495 			rc_timer_running : 1,
    496 			isv4 : 1,
    497 			hb_enabled : 1;
    498 
    499 	mblk_t		*rc_timer_mp;	/* reliable control chunk timer */
    500 	ip_xmit_attr_t	*ixa;		/* Transmit attributes */
    501 	uint32_t	T3expire;	/* # of times T3 timer expired */
    502 
    503 	uint64_t	hb_secret;	/* per addr "secret" in heartbeat */
    504 	uint32_t	rxt_unacked;	/* # unack'ed retransmitted bytes */
    505 } sctp_faddr_t;
    506 
    507 /* Flags to indicate supported address type in the PARM_SUP_ADDRS. */
    508 #define	PARM_SUPP_V6	0x1
    509 #define	PARM_SUPP_V4	0x2
    510 
    511 /*
    512  * Set heartbeat interval plus jitter.  The jitter is supposed to be random,
    513  * up to +/- 50% of the RTO.  We use gethrtime() here for  performance reason
    514  * as the jitter does not really need to be "very" random.
    515  */
    516 #define	SET_HB_INTVL(fp)					\
    517 	((fp)->hb_interval + (fp)->rto + ((fp)->rto >> 1) -	\
    518 	(uint_t)gethrtime() % (fp)->rto)
    519 
    520 #define	SCTP_IPIF_HASH	16
    521 
    522 typedef	struct	sctp_ipif_hash_s {
    523 	list_t	sctp_ipif_list;
    524 	int	ipif_count;
    525 } sctp_ipif_hash_t;
    526 
    527 
    528 /*
    529  * Initialize cwnd according to RFC 3390.  def_max_init_cwnd is
    530  * either sctp_slow_start_initial or sctp_slow_start_after idle
    531  * depending on the caller.
    532  */
    533 #define	SET_CWND(fp, mss, def_max_init_cwnd)				\
    534 {									\
    535 	(fp)->cwnd = MIN(def_max_init_cwnd * (mss),			\
    536 	    MIN(4 * (mss), MAX(2 * (mss), 4380 / (mss) * (mss))));	\
    537 }
    538 
    539 
    540 struct sctp_s;
    541 
    542 /*
    543  * Control structure for each open SCTP stream,
    544  * defined only within the kernel or for a kmem user.
    545  * NOTE: sctp_reinit_values MUST have a line for each field in this structure!
    546  */
    547 #if (defined(_KERNEL) || defined(_KMEMUSER))
    548 
    549 typedef struct sctp_s {
    550 
    551 	/*
    552 	 * The following is shared with (and duplicated) in IP, so if you
    553 	 * make changes, make sure you also change things in ip_sctp.c.
    554 	 */
    555 	struct sctp_s	*sctp_conn_hash_next;
    556 	struct sctp_s	*sctp_conn_hash_prev;
    557 
    558 	struct sctp_s	*sctp_listen_hash_next;
    559 	struct sctp_s	*sctp_listen_hash_prev;
    560 
    561 	sctp_tf_t	*sctp_listen_tfp;	/* Ptr to tf */
    562 	sctp_tf_t	*sctp_conn_tfp;		/* Ptr to tf */
    563 
    564 	/* Global list of sctp */
    565 	list_node_t	sctp_list;
    566 
    567 	sctp_faddr_t		*sctp_faddrs;
    568 	int			sctp_nfaddrs;
    569 	sctp_ipif_hash_t	sctp_saddrs[SCTP_IPIF_HASH];
    570 	int			sctp_nsaddrs;
    571 
    572 	kmutex_t	sctp_lock;
    573 	kcondvar_t	sctp_cv;
    574 	boolean_t	sctp_running;
    575 
    576 #define	sctp_ulpd	sctp_connp->conn_upper_handle
    577 #define	sctp_upcalls	sctp_connp->conn_upcalls
    578 
    579 #define	sctp_ulp_newconn	sctp_upcalls->su_newconn
    580 #define	sctp_ulp_connected	sctp_upcalls->su_connected
    581 #define	sctp_ulp_disconnected	sctp_upcalls->su_disconnected
    582 #define	sctp_ulp_opctl		sctp_upcalls->su_opctl
    583 #define	sctp_ulp_recv		sctp_upcalls->su_recv
    584 #define	sctp_ulp_xmitted	sctp_upcalls->su_txq_full
    585 #define	sctp_ulp_prop		sctp_upcalls->su_set_proto_props
    586 
    587 	int32_t		sctp_state;
    588 
    589 	conn_t		*sctp_connp;		/* conn_t stuff */
    590 	sctp_stack_t	*sctp_sctps;
    591 
    592 	/* Peer address tracking */
    593 	sctp_faddr_t	*sctp_lastfaddr;	/* last faddr in list */
    594 	sctp_faddr_t	*sctp_primary;		/* primary faddr */
    595 	sctp_faddr_t	*sctp_current;		/* current faddr */
    596 	sctp_faddr_t	*sctp_lastdata;		/* last data seen from this */
    597 
    598 	/* Outbound data tracking */
    599 	mblk_t		*sctp_xmit_head;
    600 	mblk_t		*sctp_xmit_tail;
    601 	mblk_t		*sctp_xmit_unsent;
    602 	mblk_t		*sctp_xmit_unsent_tail;
    603 	mblk_t		*sctp_xmit_unacked;
    604 
    605 	int32_t		sctp_unacked;		/* # of unacked bytes */
    606 	int32_t		sctp_unsent;		/* # of unsent bytes in hand */
    607 
    608 	uint32_t	sctp_ltsn;		/* Local instance TSN */
    609 	uint32_t	sctp_lastack_rxd;	/* Last rx'd cumtsn */
    610 	uint32_t	sctp_recovery_tsn;	/* Exit from fast recovery */
    611 	uint32_t	sctp_adv_pap;		/* Adv. Peer Ack Point */
    612 
    613 	uint16_t	sctp_num_ostr;
    614 	uint16_t	*sctp_ostrcntrs;
    615 
    616 	mblk_t		*sctp_pad_mp;		/* pad unaligned data chunks */
    617 
    618 	/* sendmsg() default parameters */
    619 	uint16_t	sctp_def_stream;	/* default stream id */
    620 	uint16_t	sctp_def_flags;		/* default xmit flags */
    621 	uint32_t	sctp_def_ppid;		/* default payload id */
    622 	uint32_t	sctp_def_context;	/* default context */
    623 	uint32_t	sctp_def_timetolive;	/* default msg TTL */
    624 
    625 	/* Inbound data tracking */
    626 	sctp_set_t	*sctp_sack_info;	/* Sack tracking */
    627 	mblk_t		*sctp_ack_mp;		/* Delayed ACK timer block */
    628 	sctp_instr_t	*sctp_instr;		/* Instream trackers */
    629 	mblk_t		*sctp_uo_frags;		/* Un-ordered msg. fragments */
    630 	uint32_t	sctp_ftsn;		/* Peer's TSN */
    631 	uint32_t	sctp_lastacked;		/* last cumtsn SACKd */
    632 	uint16_t	sctp_num_istr;		/* No. of instreams */
    633 	int32_t		sctp_istr_nmsgs;	/* No. of chunks in instreams */
    634 	int32_t		sctp_sack_gaps;		/* No. of received gaps */
    635 	int32_t		sctp_sack_toggle;	/* SACK every other pkt */
    636 
    637 	/* RTT calculation */
    638 	uint32_t	sctp_rtt_tsn;
    639 	int64_t		sctp_out_time;
    640 
    641 	/* Stats can be reset by snmp users kstat, netstat and snmp agents */
    642 	uint64_t	sctp_opkts;		/* sent pkts */
    643 	uint64_t	sctp_obchunks;		/* sent control chunks */
    644 	uint64_t	sctp_odchunks;		/* sent ordered data chunks */
    645 	uint64_t	sctp_oudchunks;		/* sent unord data chunks */
    646 	uint64_t	sctp_rxtchunks;		/* retransmitted chunks */
    647 	uint64_t	sctp_ipkts;		/* recv pkts */
    648 	uint64_t	sctp_ibchunks;		/* recv control chunks */
    649 	uint64_t	sctp_idchunks;		/* recv ordered data chunks */
    650 	uint64_t	sctp_iudchunks;		/* recv unord data chunks */
    651 	uint64_t	sctp_fragdmsgs;
    652 	uint64_t	sctp_reassmsgs;
    653 	uint32_t	sctp_T1expire;		/* # of times T1timer expired */
    654 	uint32_t	sctp_T2expire;		/* # of times T2timer expired */
    655 	uint32_t	sctp_T3expire;		/* # of times T3timer expired */
    656 	uint32_t	sctp_assoc_start_time;	/* time when assoc was est. */
    657 
    658 	uint32_t	sctp_frwnd;		/* Peer RWND */
    659 	uint32_t	sctp_cwnd_max;
    660 
    661 	/* Inbound flow control */
    662 	int32_t		sctp_rwnd;		/* Current receive window */
    663 	int32_t		sctp_irwnd;		/* Initial receive window */
    664 	int32_t		sctp_rxqueued;		/* No. of bytes in RX q's */
    665 
    666 	/* Pre-initialized composite headers */
    667 	uchar_t		*sctp_iphc;	/* v4 sctp/ip hdr template buffer */
    668 	uchar_t		*sctp_iphc6;	/* v6 sctp/ip hdr template buffer */
    669 
    670 	int32_t		sctp_iphc_len;	/* actual allocated v4 buffer size */
    671 	int32_t		sctp_iphc6_len;	/* actual allocated v6 buffer size */
    672 
    673 	int32_t		sctp_hdr_len;	/* len of combined SCTP/IP v4 hdr */
    674 	int32_t		sctp_hdr6_len;	/* len of combined SCTP/IP v6 hdr */
    675 
    676 	ipha_t		*sctp_ipha;	/* IPv4 header in the buffer */
    677 	ip6_t		*sctp_ip6h;	/* IPv6 header in the buffer */
    678 
    679 	int32_t		sctp_ip_hdr_len; /* Byte len of our current v4 hdr */
    680 	int32_t		sctp_ip_hdr6_len; /* Byte len of our current v6 hdr */
    681 
    682 	sctp_hdr_t	*sctp_sctph;	/* sctp header in combined v4 hdr */
    683 	sctp_hdr_t	*sctp_sctph6;	/* sctp header in combined v6 hdr */
    684 
    685 	uint32_t	sctp_lvtag;	/* local SCTP instance verf tag */
    686 	uint32_t	sctp_fvtag;	/* Peer's SCTP verf tag */
    687 
    688 	/* Path MTU Discovery */
    689 	int64_t		sctp_last_mtu_probe;
    690 	clock_t		sctp_mtu_probe_intvl;
    691 	uint32_t	sctp_mss;	/* Max send size (not TCP MSS!) */
    692 
    693 	/* structs sctp_bits, sctp_events are for clearing all bits at once */
    694 	struct {
    695 		uint32_t
    696 
    697 		sctp_understands_asconf : 1, /* Peer handles ASCONF chunks */
    698 		sctp_cchunk_pend : 1,	/* Control chunk in flight. */
    699 		sctp_lingering : 1,	/* Lingering in close */
    700 		sctp_loopback: 1,	/* src and dst are the same machine */
    701 
    702 		sctp_force_sack : 1,
    703 		sctp_ack_timer_running: 1,	/* Delayed ACK timer running */
    704 		sctp_hwcksum : 1,	/* The NIC is capable of hwcksum */
    705 		sctp_understands_addip : 1,
    706 
    707 		sctp_bound_to_all : 1,
    708 		sctp_cansleep : 1,	/* itf routines can sleep */
    709 		sctp_detached : 1,	/* If we're detached from a stream */
    710 		sctp_send_adaptation : 1,	/* send adaptation layer ind */
    711 
    712 		sctp_recv_adaptation : 1,	/* recv adaptation layer ind */
    713 		sctp_ndelay : 1,	/* turn off Nagle */
    714 		sctp_condemned : 1,	/* this sctp is about to disappear */
    715 		sctp_chk_fast_rexmit : 1, /* check for fast rexmit message */
    716 
    717 		sctp_prsctp_aware : 1,	/* is peer PR-SCTP aware? */
    718 		sctp_linklocal : 1,	/* is linklocal assoc. */
    719 		sctp_rexmitting : 1,	/* SCTP is retransmitting */
    720 		sctp_zero_win_probe : 1,	/* doing zero win probe */
    721 
    722 		sctp_txq_full : 1,	/* the tx queue is full */
    723 		sctp_ulp_discon_done : 1,	/* ulp_disconnecting done */
    724 		sctp_dummy : 6;
    725 	} sctp_bits;
    726 	struct {
    727 		uint32_t
    728 
    729 		sctp_recvsndrcvinfo : 1,
    730 		sctp_recvassocevnt : 1,
    731 		sctp_recvpathevnt : 1,
    732 		sctp_recvsendfailevnt : 1,
    733 
    734 		sctp_recvpeererr : 1,
    735 		sctp_recvshutdownevnt : 1,
    736 		sctp_recvpdevnt : 1,
    737 		sctp_recvalevnt : 1;
    738 	} sctp_events;
    739 #define	sctp_priv_stream sctp_bits.sctp_priv_stream
    740 #define	sctp_understands_asconf sctp_bits.sctp_understands_asconf
    741 #define	sctp_cchunk_pend sctp_bits.sctp_cchunk_pend
    742 #define	sctp_lingering sctp_bits.sctp_lingering
    743 #define	sctp_loopback sctp_bits.sctp_loopback
    744 #define	sctp_force_sack sctp_bits.sctp_force_sack
    745 #define	sctp_ack_timer_running sctp_bits.sctp_ack_timer_running
    746 #define	sctp_hwcksum sctp_bits.sctp_hwcksum
    747 #define	sctp_understands_addip sctp_bits.sctp_understands_addip
    748 #define	sctp_bound_to_all sctp_bits.sctp_bound_to_all
    749 #define	sctp_cansleep sctp_bits.sctp_cansleep
    750 #define	sctp_detached sctp_bits.sctp_detached
    751 #define	sctp_send_adaptation sctp_bits.sctp_send_adaptation
    752 #define	sctp_recv_adaptation sctp_bits.sctp_recv_adaptation
    753 #define	sctp_ndelay sctp_bits.sctp_ndelay
    754 #define	sctp_condemned sctp_bits.sctp_condemned
    755 #define	sctp_chk_fast_rexmit sctp_bits.sctp_chk_fast_rexmit
    756 #define	sctp_prsctp_aware sctp_bits.sctp_prsctp_aware
    757 #define	sctp_linklocal sctp_bits.sctp_linklocal
    758 #define	sctp_rexmitting sctp_bits.sctp_rexmitting
    759 #define	sctp_zero_win_probe sctp_bits.sctp_zero_win_probe
    760 #define	sctp_txq_full sctp_bits.sctp_txq_full
    761 #define	sctp_ulp_discon_done sctp_bits.sctp_ulp_discon_done
    762 
    763 #define	sctp_recvsndrcvinfo sctp_events.sctp_recvsndrcvinfo
    764 #define	sctp_recvassocevnt sctp_events.sctp_recvassocevnt
    765 #define	sctp_recvpathevnt sctp_events.sctp_recvpathevnt
    766 #define	sctp_recvsendfailevnt sctp_events.sctp_recvsendfailevnt
    767 #define	sctp_recvpeererr sctp_events.sctp_recvpeererr
    768 #define	sctp_recvshutdownevnt sctp_events.sctp_recvshutdownevnt
    769 #define	sctp_recvpdevnt sctp_events.sctp_recvpdevnt
    770 #define	sctp_recvalevnt sctp_events.sctp_recvalevnt
    771 
    772 	/* Retransmit info */
    773 	mblk_t		*sctp_cookie_mp; /* cookie chunk, if rxt needed */
    774 	int32_t		sctp_strikes;	/* Total number of assoc strikes */
    775 	int32_t		sctp_max_init_rxt;
    776 	int32_t		sctp_pa_max_rxt; /* Max per-assoc retransmit cnt */
    777 	int32_t		sctp_pp_max_rxt; /* Max per-path retransmit cnt */
    778 	uint32_t	sctp_rto_max;
    779 	uint32_t	sctp_init_rto_max;
    780 	uint32_t	sctp_rto_min;
    781 	uint32_t	sctp_rto_initial;
    782 
    783 	int64_t		sctp_last_secret_update;
    784 	uint8_t		sctp_secret[SCTP_SECRET_LEN]; /* for cookie auth */
    785 	uint8_t		sctp_old_secret[SCTP_SECRET_LEN];
    786 	uint32_t	sctp_cookie_lifetime;	/* cookie lifetime in tick */
    787 
    788 	/* Bind hash tables */
    789 	kmutex_t	*sctp_bind_lockp;	/* Ptr to tf_lock */
    790 	struct sctp_s	*sctp_bind_hash;
    791 	struct sctp_s **sctp_ptpbhn;
    792 
    793 	/* Shutdown / cleanup */
    794 	sctp_faddr_t	*sctp_shutdown_faddr;	/* rotate faddr during shutd */
    795 	int32_t		sctp_client_errno;	/* How the client screwed up */
    796 	kmutex_t	sctp_reflock;	/* Protects sctp_refcnt & timer mp */
    797 	ushort_t	sctp_refcnt;	/* No. of pending upstream msg */
    798 	mblk_t		*sctp_timer_mp;	/* List of fired timers. */
    799 
    800 	mblk_t		*sctp_heartbeat_mp; /* Timer block for heartbeats */
    801 	uint32_t	sctp_hb_interval; /* Default hb_interval */
    802 
    803 	int32_t		sctp_autoclose;	/* Auto disconnect in ticks */
    804 	int64_t		sctp_active;	/* Last time data/sack on this conn */
    805 	uint32_t	sctp_tx_adaptation_code; /* TX adaptation code */
    806 	uint32_t	sctp_rx_adaptation_code; /* RX adaptation code */
    807 
    808 	/* Reliable control chunks */
    809 	mblk_t		*sctp_cxmit_list; /* Xmit list for control chunks */
    810 	uint32_t	sctp_lcsn;	/* Our serial number */
    811 	uint32_t	sctp_fcsn;	/* Peer serial number */
    812 
    813 	/* Per association receive queue */
    814 	kmutex_t	sctp_recvq_lock;
    815 	mblk_t		*sctp_recvq;
    816 	mblk_t		*sctp_recvq_tail;
    817 	taskq_t		*sctp_recvq_tq;
    818 
    819 	/* IPv6 ancillary data */
    820 	uint_t		sctp_recvifindex;	/* last rcvd IPV6_RCVPKTINFO */
    821 	uint_t		sctp_recvhops;		/*  " IPV6_RECVHOPLIMIT */
    822 	uint_t		sctp_recvtclass;	/*  " IPV6_RECVTCLASS */
    823 	ip6_hbh_t	*sctp_hopopts;		/*  " IPV6_RECVHOPOPTS */
    824 	ip6_dest_t	*sctp_dstopts;		/*  " IPV6_RECVDSTOPTS */
    825 	ip6_dest_t	*sctp_rthdrdstopts;	/*  " IPV6_RECVRTHDRDSTOPTS */
    826 	ip6_rthdr_t	*sctp_rthdr;		/*  " IPV6_RECVRTHDR */
    827 	uint_t		sctp_hopoptslen;
    828 	uint_t		sctp_dstoptslen;
    829 	uint_t		sctp_rthdrdstoptslen;
    830 	uint_t		sctp_rthdrlen;
    831 
    832 	/* Stats */
    833 	uint64_t	sctp_msgcount;
    834 	uint64_t	sctp_prsctpdrop;
    835 
    836 	uint_t		sctp_v4label_len;	/* length of cached v4 label */
    837 	uint_t		sctp_v6label_len;	/* length of cached v6 label */
    838 	uint32_t	sctp_rxt_nxttsn;	/* Next TSN to be rexmitted */
    839 	uint32_t	sctp_rxt_maxtsn;	/* Max TSN sent at time out */
    840 
    841 	int		sctp_pd_point;		/* Partial delivery point */
    842 	mblk_t		*sctp_err_chunks;	/* Error chunks */
    843 	uint32_t	sctp_err_len;		/* Total error chunks length */
    844 
    845 	/* additional source data for per endpoint association statistics */
    846 	uint64_t	sctp_outseqtsns;	/* TSN rx > expected TSN */
    847 	uint64_t	sctp_osacks;		/* total sacks sent */
    848 	uint64_t	sctp_isacks;		/* total sacks received */
    849 	uint64_t	sctp_idupchunks;	/* rx dups, ord or unord */
    850 	uint64_t	sctp_gapcnt;		/* total gap acks rx */
    851 	/*
    852 	 * Add the current data from the counters which are reset by snmp
    853 	 * to these cumulative counters to use in per endpoint statistics.
    854 	 */
    855 	uint64_t	sctp_cum_obchunks;	/* sent control chunks */
    856 	uint64_t	sctp_cum_odchunks;	/* sent ordered data chunks */
    857 	uint64_t	sctp_cum_oudchunks;	/* sent unord data chunks */
    858 	uint64_t	sctp_cum_rxtchunks;	/* retransmitted chunks */
    859 	uint64_t	sctp_cum_ibchunks;	/* recv control chunks */
    860 	uint64_t	sctp_cum_idchunks;	/* recv ordered data chunks */
    861 	uint64_t	sctp_cum_iudchunks;	/* recv unord data chunks */
    862 
    863 	/*
    864 	 * When non-zero, this is the maximum observed RTO since assoc stats
    865 	 * were last requested. When zero, no RTO update has occurred since
    866 	 * the previous user request for stats on this endpoint.
    867 	 */
    868 	int	sctp_maxrto;
    869 	/*
    870 	 * The stored value of sctp_maxrto passed to user during the previous
    871 	 * user request for stats on this endpoint.
    872 	 */
    873 	int	sctp_prev_maxrto;
    874 } sctp_t;
    875 
    876 #define	SCTP_TXQ_LEN(sctp)	((sctp)->sctp_unsent + (sctp)->sctp_unacked)
    877 #define	SCTP_TXQ_UPDATE(sctp)					\
    878 	if ((sctp)->sctp_txq_full && SCTP_TXQ_LEN(sctp) <=	\
    879 	    (sctp)->sctp_connp->conn_sndlowat) {		\
    880 		(sctp)->sctp_txq_full = 0;			\
    881 		(sctp)->sctp_ulp_xmitted((sctp)->sctp_ulpd,	\
    882 		    B_FALSE);					\
    883 	}
    884 
    885 #endif	/* (defined(_KERNEL) || defined(_KMEMUSER)) */
    886 
    887 extern void	sctp_ack_timer(sctp_t *);
    888 extern size_t	sctp_adaptation_code_param(sctp_t *, uchar_t *);
    889 extern void	sctp_adaptation_event(sctp_t *);
    890 extern void	sctp_add_err(sctp_t *, uint16_t, void *, size_t,
    891 		    sctp_faddr_t *);
    892 extern int	sctp_add_faddr(sctp_t *, in6_addr_t *, int, boolean_t);
    893 extern boolean_t sctp_add_ftsn_set(sctp_ftsn_set_t **, sctp_faddr_t *, mblk_t *,
    894 		    uint_t *, uint32_t *);
    895 extern void	sctp_add_recvq(sctp_t *, mblk_t *, boolean_t,
    896 		    ip_recv_attr_t *);
    897 extern void	sctp_add_unrec_parm(sctp_parm_hdr_t *, mblk_t **, boolean_t);
    898 extern size_t	sctp_addr_params(sctp_t *, int, uchar_t *, boolean_t);
    899 extern mblk_t	*sctp_add_proto_hdr(sctp_t *, sctp_faddr_t *, mblk_t *, int,
    900 		    int *);
    901 extern void	sctp_addr_req(sctp_t *, mblk_t *);
    902 extern sctp_t	*sctp_addrlist2sctp(mblk_t *, sctp_hdr_t *, sctp_chunk_hdr_t *,
    903 		    zoneid_t, sctp_stack_t *);
    904 extern void	sctp_check_adv_ack_pt(sctp_t *, mblk_t *, mblk_t *);
    905 extern void	sctp_assoc_event(sctp_t *, uint16_t, uint16_t,
    906 		    sctp_chunk_hdr_t *);
    907 
    908 extern void	sctp_bind_hash_insert(sctp_tf_t *, sctp_t *, int);
    909 extern void	sctp_bind_hash_remove(sctp_t *);
    910 extern int	sctp_bindi(sctp_t *, in_port_t, boolean_t, int, in_port_t *);
    911 extern int	sctp_bind_add(sctp_t *, const void *, uint32_t, boolean_t,
    912 		    in_port_t);
    913 extern int	sctp_bind_del(sctp_t *, const void *, uint32_t, boolean_t);
    914 extern int	sctp_build_hdrs(sctp_t *, int);
    915 
    916 extern int	sctp_check_abandoned_msg(sctp_t *, mblk_t *);
    917 extern void	sctp_clean_death(sctp_t *, int);
    918 extern void	sctp_close_eager(sctp_t *);
    919 extern int	sctp_compare_faddrsets(sctp_faddr_t *, sctp_faddr_t *);
    920 extern void	sctp_congest_reset(sctp_t *);
    921 extern void	sctp_conn_hash_insert(sctp_tf_t *, sctp_t *, int);
    922 extern void	sctp_conn_hash_remove(sctp_t *);
    923 extern void	sctp_conn_init(conn_t *);
    924 extern sctp_t	*sctp_conn_match(in6_addr_t *, in6_addr_t *, uint32_t,
    925 		    zoneid_t, iaflags_t, sctp_stack_t *);
    926 extern sctp_t	*sctp_conn_request(sctp_t *, mblk_t *, uint_t, uint_t,
    927 		    sctp_init_chunk_t *, ip_recv_attr_t *);
    928 extern uint32_t	sctp_cumack(sctp_t *, uint32_t, mblk_t **);
    929 extern sctp_t	*sctp_create_eager(sctp_t *);
    930 
    931 extern void	sctp_dispatch_rput(queue_t *, sctp_t *, sctp_hdr_t *, mblk_t *,
    932 		    uint_t, uint_t, in6_addr_t);
    933 extern char	*sctp_display(sctp_t *, char *);
    934 extern void	sctp_display_all(sctp_stack_t *);
    935 
    936 extern void	sctp_error_event(sctp_t *, sctp_chunk_hdr_t *);
    937 
    938 extern void	sctp_faddr_alive(sctp_t *, sctp_faddr_t *);
    939 extern int	sctp_faddr_dead(sctp_t *, sctp_faddr_t *, int);
    940 extern void	sctp_faddr_fini(void);
    941 extern void	sctp_faddr_init(void);
    942 extern void	sctp_fast_rexmit(sctp_t *);
    943 extern void	sctp_fill_sack(sctp_t *, unsigned char *, int);
    944 extern void	sctp_free_faddr_timers(sctp_t *);
    945 extern void	sctp_free_ftsn_set(sctp_ftsn_set_t *);
    946 extern void	sctp_free_msg(mblk_t *);
    947 extern void	sctp_free_reass(sctp_instr_t *);
    948 extern void	sctp_free_set(sctp_set_t *);
    949 extern void	sctp_ftsn_sets_fini(void);
    950 extern void	sctp_ftsn_sets_init(void);
    951 
    952 extern int	sctp_get_addrlist(sctp_t *, const void *, uint32_t *,
    953 		    uchar_t **, int *, size_t *);
    954 extern int	sctp_get_addrparams(sctp_t *, sctp_t *, mblk_t *,
    955 		    sctp_chunk_hdr_t *, uint_t *);
    956 extern void	sctp_get_dest(sctp_t *, sctp_faddr_t *);
    957 extern void	sctp_get_faddr_list(sctp_t *, uchar_t *, size_t);
    958 extern mblk_t	*sctp_get_first_sent(sctp_t *);
    959 extern mblk_t	*sctp_get_msg_to_send(sctp_t *, mblk_t **, mblk_t *, int  *,
    960 		    int32_t, uint32_t, sctp_faddr_t *);
    961 extern void	sctp_get_saddr_list(sctp_t *, uchar_t *, size_t);
    962 
    963 extern int	sctp_handle_error(sctp_t *, sctp_hdr_t *, sctp_chunk_hdr_t *,
    964 		    mblk_t *, ip_recv_attr_t *);
    965 extern void	sctp_hash_destroy(sctp_stack_t *);
    966 extern void	sctp_hash_init(sctp_stack_t *);
    967 extern void	sctp_heartbeat_timer(sctp_t *);
    968 
    969 extern void	sctp_icmp_error(sctp_t *, mblk_t *);
    970 extern void	sctp_inc_taskq(sctp_stack_t *);
    971 extern void	sctp_info_req(sctp_t *, mblk_t *);
    972 extern mblk_t	*sctp_init_mp(sctp_t *, sctp_faddr_t *);
    973 extern boolean_t sctp_initialize_params(sctp_t *, sctp_init_chunk_t *,
    974 		    sctp_init_chunk_t *);
    975 extern uint32_t	sctp_init2vtag(sctp_chunk_hdr_t *);
    976 extern void	sctp_intf_event(sctp_t *, in6_addr_t, int, int);
    977 extern void	sctp_input_data(sctp_t *, mblk_t *, ip_recv_attr_t *);
    978 extern void	sctp_instream_cleanup(sctp_t *, boolean_t);
    979 extern int	sctp_is_a_faddr_clean(sctp_t *);
    980 
    981 extern void	*sctp_kstat_init(netstackid_t);
    982 extern void	sctp_kstat_fini(netstackid_t, kstat_t *);
    983 extern void	*sctp_kstat2_init(netstackid_t, sctp_kstat_t *);
    984 extern void	sctp_kstat2_fini(netstackid_t, kstat_t *);
    985 
    986 extern ssize_t	sctp_link_abort(mblk_t *, uint16_t, char *, size_t, int,
    987 		    boolean_t);
    988 extern void	sctp_listen_hash_insert(sctp_tf_t *, sctp_t *);
    989 extern void	sctp_listen_hash_remove(sctp_t *);
    990 extern sctp_t	*sctp_lookup(sctp_t *, in6_addr_t *, sctp_tf_t *, uint32_t *,
    991 		    int);
    992 extern sctp_faddr_t *sctp_lookup_faddr(sctp_t *, in6_addr_t *);
    993 
    994 extern mblk_t	*sctp_make_err(sctp_t *, uint16_t, void *, size_t);
    995 extern mblk_t	*sctp_make_ftsn_chunk(sctp_t *, sctp_faddr_t *,
    996 		    sctp_ftsn_set_t *, uint_t, uint32_t);
    997 extern void	sctp_make_ftsns(sctp_t *, mblk_t *, mblk_t *, mblk_t **,
    998 		    sctp_faddr_t *, uint32_t *);
    999 extern mblk_t	*sctp_make_mp(sctp_t *, sctp_faddr_t *, int);
   1000 extern mblk_t	*sctp_make_sack(sctp_t *, sctp_faddr_t *, mblk_t *);
   1001 extern void	sctp_maxpsz_set(sctp_t *);
   1002 extern void	sctp_move_faddr_timers(queue_t *, sctp_t *);
   1003 
   1004 extern void	sctp_nd_free(sctp_stack_t *);
   1005 extern int	sctp_nd_getset(queue_t *, MBLKP);
   1006 extern boolean_t sctp_nd_init(sctp_stack_t *);
   1007 extern sctp_parm_hdr_t *sctp_next_parm(sctp_parm_hdr_t *, ssize_t *);
   1008 
   1009 extern void	sctp_ootb_shutdown_ack(mblk_t *, uint_t, ip_recv_attr_t *,
   1010 		    ip_stack_t *);
   1011 extern size_t	sctp_options_param(const sctp_t *, void *, int);
   1012 extern size_t	sctp_options_param_len(const sctp_t *, int);
   1013 extern void	sctp_output(sctp_t *, uint_t);
   1014 
   1015 extern boolean_t sctp_param_register(IDP *, sctpparam_t *, int, sctp_stack_t *);
   1016 extern void	sctp_partial_delivery_event(sctp_t *);
   1017 extern int	sctp_process_cookie(sctp_t *, sctp_chunk_hdr_t *, mblk_t *,
   1018 		    sctp_init_chunk_t **, sctp_hdr_t *, int *, in6_addr_t *,
   1019 		    ip_recv_attr_t *);
   1020 extern void	sctp_process_err(sctp_t *);
   1021 extern void	sctp_process_heartbeat(sctp_t *, sctp_chunk_hdr_t *);
   1022 extern void	sctp_process_timer(sctp_t *);
   1023 
   1024 extern void	sctp_redo_faddr_srcs(sctp_t *);
   1025 extern void	sctp_regift_xmitlist(sctp_t *);
   1026 extern void	sctp_return_heartbeat(sctp_t *, sctp_chunk_hdr_t *, mblk_t *);
   1027 extern void	sctp_rexmit(sctp_t *, sctp_faddr_t *);
   1028 extern mblk_t	*sctp_rexmit_packet(sctp_t *, mblk_t **, mblk_t **,
   1029 		    sctp_faddr_t *, uint_t *);
   1030 extern void	sctp_rexmit_timer(sctp_t *, sctp_faddr_t *);
   1031 extern sctp_faddr_t *sctp_rotate_faddr(sctp_t *, sctp_faddr_t *);
   1032 
   1033 extern boolean_t sctp_sack(sctp_t *, mblk_t *);
   1034 extern int	sctp_secure_restart_check(mblk_t *, sctp_chunk_hdr_t *,
   1035 		    uint32_t, int, sctp_stack_t *, ip_recv_attr_t *);
   1036 extern void	sctp_send_abort(sctp_t *, uint32_t, uint16_t, char *, size_t,
   1037 		    mblk_t *, int, boolean_t, ip_recv_attr_t *);
   1038 extern void	sctp_ootb_send_abort(uint32_t, uint16_t, char *, size_t,
   1039 		    const mblk_t *, int, boolean_t, ip_recv_attr_t *,
   1040 		    ip_stack_t *);
   1041 extern void	sctp_send_cookie_ack(sctp_t *);
   1042 extern void	sctp_send_cookie_echo(sctp_t *, sctp_chunk_hdr_t *, mblk_t *,
   1043 			ip_recv_attr_t *);
   1044 extern void	sctp_send_initack(sctp_t *, sctp_hdr_t *, sctp_chunk_hdr_t *,
   1045 		    mblk_t *, ip_recv_attr_t *);
   1046 extern void	sctp_send_shutdown(sctp_t *, int);
   1047 extern void	sctp_send_heartbeat(sctp_t *, sctp_faddr_t *);
   1048 extern void	sctp_sendfail_event(sctp_t *, mblk_t *, int, boolean_t);
   1049 extern void	sctp_set_faddr_current(sctp_t *, sctp_faddr_t *);
   1050 extern int	sctp_set_hdraddrs(sctp_t *);
   1051 extern void	sctp_set_saddr(sctp_t *, sctp_faddr_t *);
   1052 extern void	sctp_sets_init(void);
   1053 extern void	sctp_sets_fini(void);
   1054 extern void	sctp_shutdown_event(sctp_t *);
   1055 extern void	sctp_stop_faddr_timers(sctp_t *);
   1056 extern int	sctp_shutdown_received(sctp_t *, sctp_chunk_hdr_t *, boolean_t,
   1057 		    boolean_t, sctp_faddr_t *);
   1058 extern void	sctp_shutdown_complete(sctp_t *);
   1059 extern void	sctp_set_if_mtu(sctp_t *);
   1060 extern void	sctp_set_iplen(sctp_t *, mblk_t *, ip_xmit_attr_t *);
   1061 extern void	sctp_set_ulp_prop(sctp_t *);
   1062 extern void	sctp_ss_rexmit(sctp_t *);
   1063 extern size_t	sctp_supaddr_param_len(sctp_t *);
   1064 extern size_t	sctp_supaddr_param(sctp_t *, uchar_t *);
   1065 
   1066 extern void	sctp_timer(sctp_t *, mblk_t *, clock_t);
   1067 extern mblk_t	*sctp_timer_alloc(sctp_t *, pfv_t, int);
   1068 extern void	sctp_timer_call(sctp_t *sctp, mblk_t *);
   1069 extern void	sctp_timer_free(mblk_t *);
   1070 extern void	sctp_timer_stop(mblk_t *);
   1071 extern void	sctp_unlink_faddr(sctp_t *, sctp_faddr_t *);
   1072 
   1073 extern void	sctp_update_dce(sctp_t *sctp);
   1074 extern in_port_t sctp_update_next_port(in_port_t, zone_t *zone, sctp_stack_t *);
   1075 extern void	sctp_update_rtt(sctp_t *, sctp_faddr_t *, clock_t);
   1076 extern void	sctp_user_abort(sctp_t *, mblk_t *);
   1077 
   1078 extern void	sctp_validate_peer(sctp_t *);
   1079 
   1080 extern void	sctp_wput_ioctl(queue_t *, mblk_t *);
   1081 
   1082 extern int	sctp_xmit_list_clean(sctp_t *, ssize_t);
   1083 
   1084 extern void	sctp_zap_addrs(sctp_t *);
   1085 extern void	sctp_zap_faddrs(sctp_t *, int);
   1086 
   1087 /* Contract private interface between SCTP and Clustering - PSARC/2005/602 */
   1088 
   1089 extern void	(*cl_sctp_listen)(sa_family_t, uchar_t *, uint_t, in_port_t);
   1090 extern void	(*cl_sctp_unlisten)(sa_family_t, uchar_t *, uint_t, in_port_t);
   1091 extern void 	(*cl_sctp_connect)(sa_family_t, uchar_t *, uint_t, in_port_t,
   1092 		    uchar_t *, uint_t, in_port_t, boolean_t, cl_sctp_handle_t);
   1093 extern void	(*cl_sctp_disconnect)(sa_family_t, cl_sctp_handle_t);
   1094 extern void	(*cl_sctp_assoc_change)(sa_family_t, uchar_t *, size_t, uint_t,
   1095 		    uchar_t *, size_t, uint_t, int, cl_sctp_handle_t);
   1096 extern void	(*cl_sctp_check_addrs)(sa_family_t, in_port_t, uchar_t **,
   1097 		    size_t, uint_t *, boolean_t);
   1098 
   1099 #define	RUN_SCTP(sctp)						\
   1100 {								\
   1101 	mutex_enter(&(sctp)->sctp_lock);			\
   1102 	while ((sctp)->sctp_running)				\
   1103 		cv_wait(&(sctp)->sctp_cv, &(sctp)->sctp_lock);	\
   1104 	(sctp)->sctp_running = B_TRUE;				\
   1105 	mutex_exit(&(sctp)->sctp_lock);				\
   1106 }
   1107 
   1108 /* Wake up recvq taskq */
   1109 #define	WAKE_SCTP(sctp)				\
   1110 {						\
   1111 	mutex_enter(&(sctp)->sctp_lock);	\
   1112 	if ((sctp)->sctp_timer_mp != NULL)	\
   1113 		sctp_process_timer(sctp);	\
   1114 	(sctp)->sctp_running = B_FALSE;		\
   1115 	cv_broadcast(&(sctp)->sctp_cv);		\
   1116 	mutex_exit(&(sctp)->sctp_lock);		\
   1117 }
   1118 
   1119 #ifdef	__cplusplus
   1120 }
   1121 #endif
   1122 
   1123 #endif	/* _INET_SCTP_SCTP_IMPL_H */
   1124