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