xref: /titanic_51/usr/src/uts/common/inet/sctp/sctp_impl.h (revision e49962a00eea60555f3c78ebf58a9a641590802c)
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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_INET_SCTP_SCTP_IMPL_H
27 #define	_INET_SCTP_SCTP_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/inttypes.h>
36 #include <sys/taskq.h>
37 #include <sys/list.h>
38 #include <sys/strsun.h>
39 #include <sys/zone.h>
40 #include <netinet/ip6.h>
41 #include <inet/optcom.h>
42 #include <netinet/sctp.h>
43 #include <inet/sctp_itf.h>
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  * faddr timer mblks are not allocated until first use. This macro
66  * will allocate the timer mblk if necessary, set the faddr, and then
67  * start the timer.
68  */
69 #define	SCTP_FADDR_TIMER_RESTART(sctp, fp, intvl)			\
70 	if ((fp)->timer_mp == NULL) {					\
71 		(fp)->timer_mp = sctp_timer_alloc((sctp), sctp_rexmit_timer); \
72 	}								\
73 	if ((fp)->timer_mp != NULL) {					\
74 		((sctpt_t *)((fp)->timer_mp->b_rptr))->sctpt_faddr = fp;  \
75 		dprint(3, ("faddr_timer_restart: fp=%p %x:%x:%x:%x %d\n", \
76 		    (void *)(fp), SCTP_PRINTADDR((fp)->faddr),		\
77 		    (int)(intvl)));					\
78 		sctp_timer((sctp), (fp)->timer_mp, (intvl));		\
79 		(fp)->timer_running = 1;				\
80 	}
81 
82 #define	SCTP_FADDR_TIMER_STOP(fp)				\
83 	if ((fp)->timer_running && (fp)->timer_mp != NULL) {	\
84 		sctp_timer_stop((fp)->timer_mp);		\
85 		(fp)->timer_running = 0;			\
86 	}
87 
88 #define	SCTP_CALC_RXT(fp, max)		\
89 {					\
90 	if (((fp)->rto <<= 1) > (max))	\
91 		(fp)->rto = (max);	\
92 }
93 
94 /*
95  * Maximum number of duplicate TSNs we can report. This is currently
96  * static, and governs the size of the mblk used to hold the duplicate
97  * reports. The use of duplcate TSN reports is currently experimental,
98  * so for now a static limit should suffice.
99  */
100 #define	SCTP_DUP_MBLK_SZ	64
101 
102 #define	SCTP_IS_ADDR_UNSPEC(isv4, addr)		\
103 	((isv4) ? IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) :	\
104 	IN6_IS_ADDR_UNSPECIFIED(&(addr)))
105 
106 extern int	sctp_g_num_epriv_ports;
107 extern uint16_t	sctp_g_epriv_ports[];
108 extern kmutex_t	sctp_epriv_port_lock;
109 
110 extern uint_t	sctp_next_port_to_try;
111 /*
112  * SCTP parameters
113  */
114 /* Named Dispatch Parameter Management Structure */
115 typedef struct sctpparam_s {
116 	uint32_t	sctp_param_min;
117 	uint32_t	sctp_param_max;
118 	uint32_t	sctp_param_val;
119 	char		*sctp_param_name;
120 } sctpparam_t;
121 
122 extern sctpparam_t sctp_param_arr[];
123 #define	sctp_max_init_retr		sctp_param_arr[0].sctp_param_val
124 #define	sctp_max_init_retr_high		sctp_param_arr[0].sctp_param_max
125 #define	sctp_max_init_retr_low		sctp_param_arr[0].sctp_param_min
126 #define	sctp_pa_max_retr		sctp_param_arr[1].sctp_param_val
127 #define	sctp_pa_max_retr_high		sctp_param_arr[1].sctp_param_max
128 #define	sctp_pa_max_retr_low		sctp_param_arr[1].sctp_param_min
129 #define	sctp_pp_max_retr		sctp_param_arr[2].sctp_param_val
130 #define	sctp_pp_max_retr_high		sctp_param_arr[2].sctp_param_max
131 #define	sctp_pp_max_retr_low		sctp_param_arr[2].sctp_param_min
132 #define	sctp_cwnd_max_			sctp_param_arr[3].sctp_param_val
133 #define	sctp_dbg			sctp_param_arr[4].sctp_param_val
134 #define	sctp_smallest_nonpriv_port	sctp_param_arr[5].sctp_param_val
135 #define	sctp_ipv4_ttl			sctp_param_arr[6].sctp_param_val
136 #define	sctp_heartbeat_interval		sctp_param_arr[7].sctp_param_val
137 #define	sctp_heartbeat_interval_high	sctp_param_arr[7].sctp_param_max
138 #define	sctp_heartbeat_interval_low	sctp_param_arr[7].sctp_param_min
139 #define	sctp_initial_mtu		sctp_param_arr[8].sctp_param_val
140 #define	sctp_mtu_probe_interval		sctp_param_arr[9].sctp_param_val
141 #define	sctp_new_secret_interval	sctp_param_arr[10].sctp_param_val
142 #define	sctp_deferred_ack_interval	sctp_param_arr[11].sctp_param_val
143 #define	sctp_snd_lowat_fraction		sctp_param_arr[12].sctp_param_val
144 #define	sctp_ignore_path_mtu		sctp_param_arr[13].sctp_param_val
145 #define	sctp_initial_ssthresh		sctp_param_arr[14].sctp_param_val
146 #define	sctp_smallest_anon_port		sctp_param_arr[15].sctp_param_val
147 #define	sctp_largest_anon_port		sctp_param_arr[16].sctp_param_val
148 #define	sctp_xmit_hiwat			sctp_param_arr[17].sctp_param_val
149 #define	sctp_xmit_lowat			sctp_param_arr[18].sctp_param_val
150 #define	sctp_recv_hiwat			sctp_param_arr[19].sctp_param_val
151 #define	sctp_max_buf			sctp_param_arr[20].sctp_param_val
152 #define	sctp_rtt_updates		sctp_param_arr[21].sctp_param_val
153 #define	sctp_ipv6_hoplimit		sctp_param_arr[22].sctp_param_val
154 #define	sctp_rto_ming			sctp_param_arr[23].sctp_param_val
155 #define	sctp_rto_ming_high		sctp_param_arr[23].sctp_param_max
156 #define	sctp_rto_ming_low		sctp_param_arr[23].sctp_param_min
157 #define	sctp_rto_maxg			sctp_param_arr[24].sctp_param_val
158 #define	sctp_rto_maxg_high		sctp_param_arr[24].sctp_param_max
159 #define	sctp_rto_maxg_low		sctp_param_arr[24].sctp_param_min
160 #define	sctp_rto_initialg		sctp_param_arr[25].sctp_param_val
161 #define	sctp_rto_initialg_high		sctp_param_arr[25].sctp_param_max
162 #define	sctp_rto_initialg_low		sctp_param_arr[25].sctp_param_min
163 #define	sctp_cookie_life		sctp_param_arr[26].sctp_param_val
164 #define	sctp_cookie_life_high		sctp_param_arr[26].sctp_param_max
165 #define	sctp_cookie_life_low		sctp_param_arr[26].sctp_param_min
166 #define	sctp_max_in_streams		sctp_param_arr[27].sctp_param_val
167 #define	sctp_max_in_streams_high	sctp_param_arr[27].sctp_param_max
168 #define	sctp_max_in_streams_low		sctp_param_arr[27].sctp_param_min
169 #define	sctp_initial_out_streams	sctp_param_arr[28].sctp_param_val
170 #define	sctp_initial_out_streams_high	sctp_param_arr[28].sctp_param_max
171 #define	sctp_initial_out_streams_low	sctp_param_arr[28].sctp_param_min
172 #define	sctp_shutack_wait_bound		sctp_param_arr[29].sctp_param_val
173 #define	sctp_maxburst			sctp_param_arr[30].sctp_param_val
174 #define	sctp_addip_enabled		sctp_param_arr[31].sctp_param_val
175 #define	sctp_recv_hiwat_minmss		sctp_param_arr[32].sctp_param_val
176 #define	sctp_slow_start_initial		sctp_param_arr[33].sctp_param_val
177 #define	sctp_slow_start_after_idle	sctp_param_arr[34].sctp_param_val
178 #define	sctp_prsctp_enabled		sctp_param_arr[35].sctp_param_val
179 #define	sctp_fast_rxt_thresh		sctp_param_arr[36].sctp_param_val
180 /*
181  * sctp_wroff_xtra is the extra space in front of SCTP/IP header for link
182  * layer header.  It has to be a multiple of 4.
183  */
184 extern sctpparam_t sctp_wroff_xtra_param;
185 #define	sctp_wroff_xtra	sctp_wroff_xtra_param.sctp_param_val
186 
187 #define	SCTP_MAX_COMBINED_HEADER_LENGTH	(60 + 12) /* Maxed out ip + sctp */
188 #define	SCTP_MAX_IP_OPTIONS_LENGTH	(60 - IP_SIMPLE_HDR_LENGTH)
189 #define	SCTP_MAX_HDR_LENGTH		60
190 
191 #define	SCTP_SECRET_LEN	16
192 
193 #define	SCTP_REFHOLD(sctp) {			\
194 	mutex_enter(&(sctp)->sctp_reflock);	\
195 	(sctp)->sctp_refcnt++;			\
196 	ASSERT((sctp)->sctp_refcnt != 0);	\
197 	mutex_exit(&(sctp)->sctp_reflock);	\
198 }
199 
200 #define	SCTP_REFRELE(sctp) {				\
201 	mutex_enter(&(sctp)->sctp_reflock);		\
202 	ASSERT((sctp)->sctp_refcnt != 0);		\
203 	if (--(sctp)->sctp_refcnt == 0) {		\
204 		mutex_exit(&(sctp)->sctp_reflock);	\
205 		CONN_DEC_REF((sctp)->sctp_connp);	\
206 	} else {					\
207 		mutex_exit(&(sctp)->sctp_reflock);	\
208 	}						\
209 }
210 
211 #define	SCTP_PRINTADDR(a)	(a).s6_addr32[0], (a).s6_addr32[1],\
212 				(a).s6_addr32[2], (a).s6_addr32[3]
213 
214 #define	CONN2SCTP(conn)	((sctp_t *)(&((conn_t *)conn)[1]))
215 
216 /*
217  * Outbound data, flags and macros for per-message, per-chunk info
218  */
219 typedef struct {
220 	int64_t		smh_ttl;		/* Time to Live */
221 	int64_t		smh_tob;		/* Time of Birth */
222 	uint32_t	smh_context;
223 	uint16_t	smh_sid;
224 	uint16_t	smh_ssn;
225 	uint32_t	smh_ppid;
226 	uint16_t	smh_flags;
227 	uint32_t	smh_msglen;
228 } sctp_msg_hdr_t;
229 
230 #define	SCTP_CHUNK_FLAG_SENT		0x01
231 #define	SCTP_CHUNK_FLAG_REXMIT		0x02
232 #define	SCTP_CHUNK_FLAG_ACKED		0x04
233 #define	SCTP_MSG_FLAG_CHUNKED		0x08
234 #define	SCTP_MSG_FLAG_ABANDONED		0x10
235 #define	SCTP_CHUNK_FLAG_ABANDONED	0x20
236 
237 #define	SCTP_CHUNK_CLEAR_FLAGS(mp) ((mp)->b_flag = 0)
238 /*
239  * If we are transmitting the chunk for the first time we assign the TSN and
240  * SSN here. The reason we assign the SSN here (as opposed to doing it in
241  * sctp_chunkify()) is that the chunk may expire, if PRSCTP is enabled, before
242  * we get a chance to send it out. If we assign the SSN in sctp_chunkify()
243  * and this happens, then we need to send a Forward TSN to the peer, which
244  * will be expecting this SSN, assuming ordered. If we assign it here we
245  * can just take out the chunk from the transmit list without having to
246  * send a Forward TSN chunk. While assigning the SSN we use (meta)->b_cont
247  * to determine if it needs a new SSN (i.e. the next SSN for the stream),
248  * since (meta)->b_cont signifies the first chunk of a message (if the message
249  * is unordered, then the SSN is 0).
250  *
251  */
252 #define	SCTP_CHUNK_SENT(sctp, mp, sdc, fp, chunkdata, meta) {		\
253 	if (!SCTP_CHUNK_ISSENT(mp)) {					\
254 		sctp_msg_hdr_t	*mhdr = (sctp_msg_hdr_t *)(meta)->b_rptr; \
255 		ASSERT(!SCTP_CHUNK_ABANDONED(mp));			\
256 		(mp)->b_flag = SCTP_CHUNK_FLAG_SENT;			\
257 		(sdc)->sdh_tsn = htonl((sctp)->sctp_ltsn++);		\
258 		if ((mhdr)->smh_flags & MSG_UNORDERED) {		\
259 			(sdc)->sdh_ssn = 0;				\
260 			SCTP_DATA_SET_UBIT(sdc);			\
261 			BUMP_LOCAL((sctp)->sctp_oudchunks);		\
262 		} else {						\
263 			BUMP_LOCAL((sctp)->sctp_odchunks);		\
264 			if ((mp) == (meta)->b_cont) {			\
265 				mhdr->smh_ssn = htons(			\
266 				    (sctp)->sctp_ostrcntrs[mhdr->smh_sid]++); \
267 			}						\
268 			(sdc)->sdh_ssn = mhdr->smh_ssn;			\
269 		}							\
270 		(sctp)->sctp_unacked += (chunkdata);			\
271 		(sctp)->sctp_unsent -= (chunkdata);			\
272 		(sctp)->sctp_frwnd -= (chunkdata);			\
273 	} else {							\
274 		if (SCTP_CHUNK_ISACKED(mp)) {				\
275 			(sctp)->sctp_unacked += (chunkdata);		\
276 		} else {						\
277 			ASSERT(SCTP_CHUNK_DEST(mp)->suna >= ((chunkdata) + \
278 							sizeof (*sdc))); \
279 			SCTP_CHUNK_DEST(mp)->suna -= ((chunkdata) + 	\
280 					sizeof (*sdc));			\
281 		}							\
282 		(mp)->b_flag &= ~(SCTP_CHUNK_FLAG_REXMIT |		\
283 			SCTP_CHUNK_FLAG_ACKED);				\
284 		SCTP_CHUNK_SET_SACKCNT(mp, 0);				\
285 		BUMP_LOCAL(sctp->sctp_rxtchunks);			\
286 		BUMP_LOCAL((sctp)->sctp_T3expire);			\
287 		BUMP_LOCAL((fp)->T3expire);				\
288 	}								\
289 	SCTP_SET_CHUNK_DEST(mp, fp);					\
290 	(fp)->suna += ((chunkdata) + sizeof (*sdc));			\
291 }
292 
293 #define	SCTP_CHUNK_ISSENT(mp)	((mp)->b_flag & SCTP_CHUNK_FLAG_SENT)
294 #define	SCTP_CHUNK_CANSEND(mp)	\
295 	(!(SCTP_CHUNK_ABANDONED(mp)) &&	\
296 	(((mp)->b_flag & (SCTP_CHUNK_FLAG_REXMIT|SCTP_CHUNK_FLAG_SENT)) != \
297 	SCTP_CHUNK_FLAG_SENT))
298 
299 #define	SCTP_CHUNK_DEST(mp)		((sctp_faddr_t *)(mp)->b_queue)
300 #define	SCTP_SET_CHUNK_DEST(mp, fp)	((mp)->b_queue = (queue_t *)fp)
301 
302 #define	SCTP_CHUNK_REXMIT(mp)	((mp)->b_flag |= SCTP_CHUNK_FLAG_REXMIT)
303 #define	SCTP_CHUNK_CLEAR_REXMIT(mp) ((mp)->b_flag &= ~SCTP_CHUNK_FLAG_REXMIT)
304 #define	SCTP_CHUNK_WANT_REXMIT(mp) ((mp)->b_flag & SCTP_CHUNK_FLAG_REXMIT)
305 
306 #define	SCTP_CHUNK_ACKED(mp) \
307 	((mp)->b_flag = (SCTP_CHUNK_FLAG_SENT|SCTP_CHUNK_FLAG_ACKED))
308 #define	SCTP_CHUNK_ISACKED(mp)	((mp)->b_flag & SCTP_CHUNK_FLAG_ACKED)
309 #define	SCTP_CHUNK_CLEAR_ACKED(mp) ((mp)->b_flag &= ~SCTP_CHUNK_FLAG_ACKED)
310 
311 #define	SCTP_CHUNK_SACKCNT(mp)	((intptr_t)((mp)->b_prev))
312 #define	SCTP_CHUNK_SET_SACKCNT(mp, val) ((mp)->b_prev = \
313 					(mblk_t *)(uintptr_t)(val))
314 
315 #define	SCTP_MSG_SET_CHUNKED(mp)	((mp)->b_flag |= SCTP_MSG_FLAG_CHUNKED)
316 #define	SCTP_MSG_CLEAR_CHUNKED(mp)((mp)->b_flag &= ~SCTP_MSG_FLAG_CHUNKED)
317 #define	SCTP_IS_MSG_CHUNKED(mp)	((mp)->b_flag & SCTP_MSG_FLAG_CHUNKED)
318 
319 /* For PR-SCTP */
320 #define	SCTP_ABANDON_CHUNK(mp)	((mp)->b_flag |= SCTP_CHUNK_FLAG_ABANDONED)
321 #define	SCTP_CHUNK_ABANDONED(mp) \
322 	((mp)->b_flag & SCTP_CHUNK_FLAG_ABANDONED)
323 
324 #define	SCTP_MSG_SET_ABANDONED(mp)	\
325 	((mp)->b_flag |= SCTP_MSG_FLAG_ABANDONED)
326 #define	SCTP_MSG_CLEAR_ABANDONED(mp)((mp)->b_flag &= ~SCTP_MSG_FLAG_ABANDONED)
327 #define	SCTP_IS_MSG_ABANDONED(mp)	((mp)->b_flag & SCTP_MSG_FLAG_ABANDONED)
328 
329 /*
330  * Check if a message has expired.  A message is expired if
331  *	1. It has a non-zero time to live value and has not been sent before
332  *	that time expires.
333  *	2. It is sent using PRSCTP and it has not been SACK'ed before
334  *	its lifetime expires.
335  */
336 #define	SCTP_MSG_TO_BE_ABANDONED(meta, mhdr, sctp)			     \
337 	(((!SCTP_CHUNK_ISSENT((meta)->b_cont) && (mhdr)->smh_ttl > 0) ||     \
338 	((sctp)->sctp_prsctp_aware && ((mhdr)->smh_flags & MSG_PR_SCTP))) && \
339 	((lbolt64 - (mhdr)->smh_tob) > (mhdr)->smh_ttl))
340 
341 /* SCTP association hash function. */
342 #define	SCTP_CONN_HASH(ports)	\
343 	((((ports) ^ ((ports) >> 16)) * 31) & (sctp_conn_hash_size - 1))
344 
345 /*
346  * Bind hash array size and hash function.  The size must be a power
347  * of 2 and lport must be in host byte order.
348  */
349 #define	SCTP_BIND_FANOUT_SIZE	2048
350 #define	SCTP_BIND_HASH(lport)	(((lport) * 31) & (SCTP_BIND_FANOUT_SIZE - 1))
351 
352 /* options that SCTP negotiates during association establishment */
353 #define	SCTP_PRSCTP_OPTION	0x01
354 
355 /*
356  * Listener hash array size and hash function.  The size must be a power
357  * of 2 and lport must be in host byte order.
358  */
359 #define	SCTP_LISTEN_FANOUT_SIZE	512
360 #define	SCTP_LISTEN_HASH(lport) (((lport) * 31) & (SCTP_LISTEN_FANOUT_SIZE - 1))
361 
362 typedef struct sctp_tf_s {
363 	struct sctp_s	*tf_sctp;
364 	kmutex_t	tf_lock;
365 } sctp_tf_t;
366 
367 /* SCTP association hash list */
368 extern sctp_tf_t	*sctp_conn_fanout;
369 /* Size of sctp_conn_fanout */
370 extern uint_t	sctp_conn_hash_size;
371 
372 /* SCTP bind hash list - all sctp_t with state >= BOUND. */
373 extern sctp_tf_t	sctp_bind_fanout[];
374 
375 /* SCTP listener hash list - all sctp_t with state == LISTEN. */
376 extern sctp_tf_t	sctp_listen_fanout[];
377 
378 /* Round up the value to the nearest mss. */
379 #define	MSS_ROUNDUP(value, mss)		((((value) - 1) / (mss) + 1) * (mss))
380 
381 extern sin_t	sctp_sin_null;	/* Zero address for quick clears */
382 extern sin6_t	sctp_sin6_null;	/* Zero address for quick clears */
383 
384 #define	SCTP_IS_DETACHED(sctp)		((sctp)->sctp_detached)
385 
386 extern mib2_sctp_t	sctp_mib;	/* SNMP fixed size info */
387 
388 /*
389  * Object to represent database of options to search passed to
390  * {sock,tpi}optcom_req() interface routine to take care of option
391  * management and associated methods.
392  * XXX These and other externs should ideally move to a SCTP header
393  */
394 extern optdb_obj_t	sctp_opt_obj;
395 extern uint_t		sctp_max_optbuf_len;
396 
397 /* Data structure used to track received TSNs */
398 typedef struct sctp_set_s {
399 	struct sctp_set_s *next;
400 	struct sctp_set_s *prev;
401 	uint32_t begin;
402 	uint32_t end;
403 } sctp_set_t;
404 
405 /* Data structure used to track TSNs for PR-SCTP */
406 typedef struct sctp_ftsn_set_s {
407 	struct sctp_ftsn_set_s *next;
408 	ftsn_entry_t	ftsn_entries;
409 } sctp_ftsn_set_t;
410 
411 /* Data structure used to track incoming SCTP streams */
412 typedef struct sctp_instr_s {
413 	mblk_t		*istr_msgs;
414 	int		istr_nmsgs;
415 	uint16_t	nextseq;
416 	struct sctp_s	*sctp;
417 	mblk_t		*istr_reass;
418 } sctp_instr_t;
419 
420 /* Reassembly data structure (per-stream) */
421 typedef struct sctp_reass_s {
422 	uint16_t	ssn;
423 	uint16_t	needed;
424 	uint16_t	got;
425 	mblk_t		*tail;
426 	boolean_t	partial_delivered;
427 } sctp_reass_t;
428 
429 /* debugging */
430 #undef	dprint
431 #ifdef DEBUG
432 extern int sctpdebug;
433 #define	dprint(level, args)	{ if (sctpdebug > (level)) printf args; }
434 #else
435 #define	dprint(level, args) {}
436 #endif
437 
438 
439 /* Peer address tracking */
440 
441 /*
442  * States for peer addresses
443  *
444  * SCTP_FADDRS_UNCONFIRMED: we have not communicated with this peer address
445  *     before, mark it as unconfirmed so that we will not send data to it.
446  *     All addresses initially are in unconfirmed state and required
447  *     validation.  SCTP sends a heartbeat to each of them and when it gets
448  *     back a heartbeat ACK, the address will be marked as alive.  This
449  *     validation fixes a security issue with multihoming.  If an attacker
450  *     establishes an association with us and tells us that it has addresses
451  *     belonging to another host A, this will prevent A from communicating
452  *     with us.  This is fixed by peer address validation.  In the above case,
453  *     A will respond with an abort.
454  *
455  * SCTP_FADDRS_ALIVE: this peer address is alive and we can communicate with
456  *     it with no problem.
457  *
458  * SCTP_FADDRS_DOWN: we have exceeded the retransmission limit to this
459  *     peer address.  Once an address is marked down, we will only send
460  *     a heartbeat to it every hb_interval in case it becomes alive now.
461  *
462  * SCTP_FADDRS_UNREACH: there is no suitable source address to send to
463  *     this peer address.  For example, the peer address is v6 but we only
464  *     have v4 addresses.  It is marked unreachable until there is an
465  *     address configuration change.  At that time, mark these addresses
466  *     as unconfirmed and try again to see if those unreachable addresses
467  *     are OK as we may have more source addresses.
468  */
469 typedef enum {
470 	SCTP_FADDRS_UNREACH,
471 	SCTP_FADDRS_DOWN,
472 	SCTP_FADDRS_ALIVE,
473 	SCTP_FADDRS_UNCONFIRMED
474 } faddr_state_t;
475 
476 typedef struct sctp_faddr_s {
477 	struct sctp_faddr_s *next;
478 	faddr_state_t	state;
479 
480 	in6_addr_t	faddr;
481 	in6_addr_t	saddr;
482 
483 	int64_t		hb_expiry;	/* time to retransmit heartbeat */
484 	uint32_t	hb_interval;	/* the heartbeat interval */
485 
486 	int		rto;		/* RTO in tick */
487 	int		srtt;		/* Smoothed RTT in tick */
488 	int		rttvar;		/* RTT variance in tick */
489 	uint32_t	rtt_updates;
490 	int		strikes;
491 	int		max_retr;
492 	uint32_t	sfa_pmss;
493 	uint32_t	cwnd;
494 	uint32_t	ssthresh;
495 	uint32_t	suna;		/* sent - unack'ed */
496 	uint32_t	pba;		/* partial bytes acked */
497 	uint32_t	acked;
498 	int64_t		lastactive;
499 	mblk_t		*timer_mp;	/* retransmission timer control */
500 	uint32_t
501 			hb_pending : 1,
502 			timer_running : 1,
503 			df : 1,
504 			pmtu_discovered : 1,
505 
506 			rc_timer_running : 1,
507 			isv4 : 1;
508 
509 	mblk_t		*rc_timer_mp;	/* reliable control chunk timer */
510 	ire_t		*ire;		/* cached IRE */
511 	uint32_t	T3expire;	/* # of times T3 timer expired */
512 
513 	uint64_t	hb_secret;	/* per addr "secret" in heartbeat */
514 } sctp_faddr_t;
515 
516 /* Flags to indicate supported address type in the PARM_SUP_ADDRS. */
517 #define	PARM_SUPP_V6	0x1
518 #define	PARM_SUPP_V4	0x2
519 
520 /*
521  * Set heartbeat interval plus jitter.  The jitter is supposed to be random,
522  * up to +/- 50% of the RTO.  We use gethrtime() here for  performance reason
523  * as the jitter does not really need to be "very" random.
524  */
525 #define	SET_HB_INTVL(fp)					\
526 	((fp)->hb_interval + (fp)->rto + ((fp)->rto >> 1) -	\
527 	(uint_t)gethrtime() % (fp)->rto);
528 
529 #define	SCTP_IPIF_HASH	16
530 
531 typedef	struct	sctp_ipif_hash_s {
532 	list_t	sctp_ipif_list;
533 	int	ipif_count;
534 } sctp_ipif_hash_t;
535 
536 struct sctp_s;
537 
538 /*
539  * Control structure for each open SCTP stream,
540  * defined only within the kernel or for a kmem user.
541  * NOTE: sctp_reinit_values MUST have a line for each field in this structure!
542  */
543 #if (defined(_KERNEL) || defined(_KMEMUSER))
544 
545 typedef struct sctp_s {
546 
547 	/*
548 	 * The following is shared with (and duplicated) in IP, so if you
549 	 * make changes, make sure you also change things in ip_sctp.c.
550 	 */
551 	struct sctp_s	*sctp_conn_hash_next;
552 	struct sctp_s	*sctp_conn_hash_prev;
553 
554 	struct sctp_s	*sctp_listen_hash_next;
555 	struct sctp_s	*sctp_listen_hash_prev;
556 
557 	sctp_tf_t	*sctp_listen_tfp;	/* Ptr to tf */
558 	sctp_tf_t	*sctp_conn_tfp;		/* Ptr to tf */
559 
560 	/* Global list of sctp */
561 	list_node_t	sctp_list;
562 
563 	sctp_faddr_t		*sctp_faddrs;
564 	int			sctp_nfaddrs;
565 	sctp_ipif_hash_t	sctp_saddrs[SCTP_IPIF_HASH];
566 	int			sctp_nsaddrs;
567 
568 	/*
569 	 * These fields contain the same information as sctp_sctph->th_*port.
570 	 * However, the lookup functions can not use the header fields
571 	 * since during IP option manipulation the sctp_sctph pointer
572 	 * changes.
573 	 */
574 	union {
575 		struct {
576 			in_port_t	sctpu_fport;	/* Remote port */
577 			in_port_t	sctpu_lport;	/* Local port */
578 		} sctpu_ports1;
579 		uint32_t		sctpu_ports2;	/* Rem port, */
580 							/* local port */
581 					/* Used for SCTP_MATCH performance */
582 	} sctp_sctpu;
583 #define	sctp_fport	sctp_sctpu.sctpu_ports1.sctpu_fport
584 #define	sctp_lport	sctp_sctpu.sctpu_ports1.sctpu_lport
585 #define	sctp_ports	sctp_sctpu.sctpu_ports2
586 
587 	kmutex_t	sctp_lock;
588 	kcondvar_t	sctp_cv;
589 	boolean_t	sctp_running;
590 
591 	void		*sctp_ulpd;	/* SCTP upper layer desc. */
592 
593 	struct sctp_upcalls_s	sctp_upcalls;  /* upcalls for sctp_ulpd */
594 #define	sctp_ulp_newconn	sctp_upcalls.su_newconn
595 #define	sctp_ulp_connected	sctp_upcalls.su_connected
596 #define	sctp_ulp_disconnected	sctp_upcalls.su_disconnected
597 #define	sctp_ulp_disconnecting	sctp_upcalls.su_disconnecting
598 #define	sctp_ulp_recv		sctp_upcalls.su_recv
599 #define	sctp_ulp_xmitted	sctp_upcalls.su_xmitted
600 #define	sctp_ulp_prop		sctp_upcalls.su_properties
601 
602 	int32_t		sctp_state;
603 
604 	conn_t		*sctp_connp;		/* conn_t stuff */
605 #define	sctp_zoneid	sctp_connp->conn_zoneid
606 #define	sctp_credp	sctp_connp->conn_cred
607 
608 	/* Peer address tracking */
609 	sctp_faddr_t	*sctp_lastfaddr;	/* last faddr in list */
610 	sctp_faddr_t	*sctp_primary;		/* primary faddr */
611 	sctp_faddr_t	*sctp_current;		/* current faddr */
612 	sctp_faddr_t	*sctp_lastdata;		/* last data seen from this */
613 
614 	/* Outbound data tracking */
615 	mblk_t		*sctp_xmit_head;
616 	mblk_t		*sctp_xmit_tail;
617 	mblk_t		*sctp_xmit_unsent;
618 	mblk_t		*sctp_xmit_unsent_tail;
619 	mblk_t		*sctp_xmit_unacked;
620 
621 	int32_t		sctp_unacked;		/* # of unacked bytes */
622 	int32_t		sctp_unsent;		/* # of unsent bytes in hand */
623 
624 	uint32_t	sctp_ltsn;		/* Local instance TSN */
625 	uint32_t	sctp_lastack_rxd;	/* Last rx'd cumtsn */
626 	uint32_t	sctp_recovery_tsn;	/* Exit from fast recovery */
627 	uint32_t	sctp_adv_pap;		/* Adv. Peer Ack Point */
628 
629 	uint16_t	sctp_num_ostr;
630 	uint16_t	*sctp_ostrcntrs;
631 
632 	/* sendmsg() default parameters */
633 	uint16_t	sctp_def_stream;	/* default stream id */
634 	uint16_t	sctp_def_flags;		/* default xmit flags */
635 	uint32_t	sctp_def_ppid;		/* default payload id */
636 	uint32_t	sctp_def_context;	/* default context */
637 	uint32_t	sctp_def_timetolive;	/* default msg TTL */
638 
639 	/* Inbound data tracking */
640 	sctp_set_t	*sctp_sack_info;	/* Sack tracking */
641 	mblk_t		*sctp_ack_mp;		/* Delayed ACK timer block */
642 	sctp_instr_t	*sctp_instr;		/* Instream trackers */
643 	mblk_t		*sctp_uo_frags;		/* Un-ordered msg. fragments */
644 	uint32_t	sctp_ftsn;		/* Peer's TSN */
645 	uint32_t	sctp_lastacked;		/* last cumtsn SACKd */
646 	uint16_t	sctp_num_istr;		/* No. of instreams */
647 	int32_t		sctp_istr_nmsgs;	/* No. of chunks in instreams */
648 	int32_t		sctp_sack_gaps;		/* No. of received gaps */
649 	int32_t		sctp_sack_toggle;	/* SACK every other pkt */
650 
651 	/* RTT calculation */
652 	uint32_t	sctp_rtt_tsn;
653 	int64_t		sctp_out_time;
654 
655 	/* Stats */
656 	uint64_t	sctp_opkts;		/* sent pkts */
657 	uint64_t	sctp_obchunks;		/* sent control chunks */
658 	uint64_t	sctp_odchunks;		/* sent ordered data chunks */
659 	uint64_t	sctp_oudchunks;		/* sent unord data chunks */
660 	uint64_t	sctp_rxtchunks;		/* retransmitted chunks */
661 	uint64_t	sctp_ipkts;		/* recv pkts */
662 	uint64_t	sctp_ibchunks;		/* recv control chunks */
663 	uint64_t	sctp_idchunks;		/* recv ordered data chunks */
664 	uint64_t	sctp_iudchunks;		/* recv unord data chunks */
665 	uint64_t	sctp_fragdmsgs;
666 	uint64_t	sctp_reassmsgs;
667 	uint32_t	sctp_T1expire;		/* # of times T1timer expired */
668 	uint32_t	sctp_T2expire;		/* # of times T2timer expired */
669 	uint32_t	sctp_T3expire;		/* # of times T3timer expired */
670 	uint32_t	sctp_assoc_start_time;	/* time when assoc was est. */
671 
672 	/* Outbound flow control */
673 	int32_t		sctp_xmit_hiwater;	/* Send high water mark */
674 	int32_t		sctp_xmit_lowater;	/* Send low water mark */
675 	uint32_t	sctp_frwnd;		/* Peer RWND */
676 	uint32_t	sctp_cwnd_max;
677 
678 	/* Inbound flow control */
679 	int32_t		sctp_rwnd;		/* Current receive window */
680 	int32_t		sctp_irwnd;		/* Initial receive window */
681 	int32_t		sctp_rxqueued;		/* No. of bytes in RX q's */
682 
683 	/* Pre-initialized composite headers */
684 	char		*sctp_iphc;	/* v4 sctp/ip hdr template buffer */
685 	char		*sctp_iphc6;	/* v6 sctp/ip hdr template buffer */
686 
687 	int32_t		sctp_iphc_len;	/* actual allocated v4 buffer size */
688 	int32_t		sctp_iphc6_len;	/* actual allocated v6 buffer size */
689 
690 	int32_t		sctp_hdr_len;	/* len of combined SCTP/IP v4 hdr */
691 	int32_t		sctp_hdr6_len;	/* len of combined SCTP/IP v6 hdr */
692 
693 	ipha_t		*sctp_ipha;	/* IPv4 header in the buffer */
694 	ip6_t		*sctp_ip6h;	/* IPv6 header in the buffer */
695 
696 	int32_t		sctp_ip_hdr_len; /* Byte len of our current v4 hdr */
697 	int32_t		sctp_ip_hdr6_len; /* Byte len of our current v6 hdr */
698 
699 	sctp_hdr_t	*sctp_sctph;	/* sctp header in combined v4 hdr */
700 	sctp_hdr_t	*sctp_sctph6;	/* sctp header in combined v6 hdr */
701 
702 	uint32_t	sctp_lvtag;	/* local SCTP instance verf tag */
703 	uint32_t	sctp_fvtag;	/* Peer's SCTP verf tag */
704 
705 	/* Path MTU Discovery */
706 	int64_t		sctp_last_mtu_probe;
707 	clock_t		sctp_mtu_probe_intvl;
708 	uint32_t	sctp_mss;	/* Max send size (not TCP MSS!) */
709 
710 	/* structs sctp_bits, sctp_events are for clearing all bits at once */
711 	struct {
712 		uint32_t
713 
714 		sctp_understands_asconf : 1, /* Peer handles ASCONF chunks */
715 		sctp_debug : 1,		/* SO_DEBUG "socket" option. */
716 		sctp_dontroute : 1,	/* SO_DONTROUTE "socket" option. */
717 		sctp_broadcast : 1,	/* SO_BROADCAST "socket" option. */
718 
719 		sctp_useloopback : 1,	/* SO_USELOOPBACK "socket" option. */
720 		sctp_cchunk_pend : 1,	/* Control chunk in flight. */
721 		sctp_dgram_errind : 1,	/* SO_DGRAM_ERRIND option */
722 		sctp_reuseaddr	: 1,	/* SO_REUSEADDR "socket" option. */
723 
724 		sctp_linger : 1,	/* SO_LINGER turned on */
725 		sctp_lingering : 1,	/* Lingering in close */
726 		sctp_loopback: 1,	/* src and dst are the same machine */
727 		sctp_force_sack : 1,
728 
729 		sctp_ack_timer_running: 1,	/* Delayed ACK timer running */
730 		sctp_recvdstaddr : 1,	/* return T_EXTCONN_IND with dstaddr */
731 		sctp_hwcksum : 1,	/* The NIC is capable of hwcksum */
732 		sctp_understands_addip : 1,
733 
734 		sctp_bound_to_all : 1,
735 		sctp_cansleep : 1,	/* itf routines can sleep */
736 		sctp_detached : 1,	/* If we're detached from a stream */
737 		sctp_send_adaption : 1,	/* send adaption layer ind */
738 
739 		sctp_recv_adaption : 1,	/* received adaption layer ind */
740 		sctp_ndelay : 1,	/* turn off Nagle */
741 		sctp_condemned : 1,	/* this sctp is about to disappear */
742 		sctp_chk_fast_rexmit : 1, /* check for fast rexmit message */
743 
744 		sctp_prsctp_aware : 1,	/* is peer PR-SCTP aware? */
745 		sctp_linklocal : 1,	/* is linklocal assoc. */
746 		sctp_mac_exempt : 1,	/* SO_MAC_EXEMPT */
747 		sctp_dummy : 5;
748 	} sctp_bits;
749 	struct {
750 		uint32_t
751 
752 		sctp_recvsndrcvinfo : 1,
753 		sctp_recvassocevnt : 1,
754 		sctp_recvpathevnt : 1,
755 		sctp_recvsendfailevnt : 1,
756 
757 		sctp_recvpeererr : 1,
758 		sctp_recvshutdownevnt : 1,
759 		sctp_recvpdevnt : 1,
760 		sctp_recvalevnt : 1;
761 	} sctp_events;
762 #define	sctp_priv_stream sctp_bits.sctp_priv_stream
763 #define	sctp_understands_asconf sctp_bits.sctp_understands_asconf
764 #define	sctp_debug sctp_bits.sctp_debug
765 #define	sctp_dontroute sctp_bits.sctp_dontroute
766 #define	sctp_broadcast sctp_bits.sctp_broadcast
767 #define	sctp_useloopback sctp_bits.sctp_useloopback
768 #define	sctp_cchunk_pend sctp_bits.sctp_cchunk_pend
769 #define	sctp_dgram_errind sctp_bits.sctp_dgram_errind
770 #define	sctp_reuseaddr sctp_bits.sctp_reuseaddr
771 #define	sctp_linger sctp_bits.sctp_linger
772 #define	sctp_lingering sctp_bits.sctp_lingering
773 #define	sctp_loopback sctp_bits.sctp_loopback
774 #define	sctp_force_sack sctp_bits.sctp_force_sack
775 #define	sctp_ack_timer_running sctp_bits.sctp_ack_timer_running
776 #define	sctp_recvdstaddr sctp_bits.sctp_recvdstaddr
777 #define	sctp_hwcksum sctp_bits.sctp_hwcksum
778 #define	sctp_understands_addip sctp_bits.sctp_understands_addip
779 #define	sctp_bound_to_all sctp_bits.sctp_bound_to_all
780 #define	sctp_cansleep sctp_bits.sctp_cansleep
781 #define	sctp_detached sctp_bits.sctp_detached
782 #define	sctp_send_adaption sctp_bits.sctp_send_adaption
783 #define	sctp_recv_adaption sctp_bits.sctp_recv_adaption
784 #define	sctp_ndelay sctp_bits.sctp_ndelay
785 #define	sctp_condemned sctp_bits.sctp_condemned
786 #define	sctp_chk_fast_rexmit sctp_bits.sctp_chk_fast_rexmit
787 #define	sctp_prsctp_aware sctp_bits.sctp_prsctp_aware
788 #define	sctp_linklocal sctp_bits.sctp_linklocal
789 #define	sctp_mac_exempt sctp_bits.sctp_mac_exempt
790 
791 #define	sctp_recvsndrcvinfo sctp_events.sctp_recvsndrcvinfo
792 #define	sctp_recvassocevnt sctp_events.sctp_recvassocevnt
793 #define	sctp_recvpathevnt sctp_events.sctp_recvpathevnt
794 #define	sctp_recvsendfailevnt sctp_events.sctp_recvsendfailevnt
795 #define	sctp_recvpeererr sctp_events.sctp_recvpeererr
796 #define	sctp_recvshutdownevnt sctp_events.sctp_recvshutdownevnt
797 #define	sctp_recvpdevnt sctp_events.sctp_recvpdevnt
798 #define	sctp_recvalevnt sctp_events.sctp_recvalevnt
799 
800 	/* Retransmit info */
801 	mblk_t		*sctp_cookie_mp; /* cookie chunk, if rxt needed */
802 	int32_t		sctp_strikes;	/* Total number of assoc strikes */
803 	int32_t		sctp_max_init_rxt;
804 	int32_t		sctp_pa_max_rxt; /* Max per-assoc retransmit cnt */
805 	int32_t		sctp_pp_max_rxt; /* Max per-path retransmit cnt */
806 	uint32_t	sctp_rto_max;
807 	uint32_t	sctp_init_rto_max;
808 	uint32_t	sctp_rto_min;
809 	uint32_t	sctp_rto_initial;
810 
811 	int64_t		sctp_last_secret_update;
812 	uint8_t		sctp_secret[SCTP_SECRET_LEN]; /* for cookie auth */
813 	uint8_t		sctp_old_secret[SCTP_SECRET_LEN];
814 	uint32_t	sctp_cookie_lifetime;	/* cookie lifetime in ms */
815 
816 	/*
817 	 * Address family that app wishes returned addrsses to be in.
818 	 * Currently taken from address family used in T_BIND_REQ, but
819 	 * should really come from family used in original socket() call.
820 	 * Value can be AF_INET or AF_INET6.
821 	 */
822 	uint_t		sctp_family;
823 	ushort_t	sctp_ipversion;
824 
825 	/* Bind hash tables */
826 	kmutex_t	*sctp_bind_lockp;	/* Ptr to tf_lock */
827 	struct sctp_s	*sctp_bind_hash;
828 	struct sctp_s **sctp_ptpbhn;
829 
830 	/* Shutdown / cleanup */
831 	sctp_faddr_t	*sctp_shutdown_faddr;	/* rotate faddr during shutd */
832 	int32_t		sctp_client_errno;	/* How the client screwed up */
833 	int		sctp_lingertime; /* Close linger time (in seconds) */
834 	kmutex_t	sctp_reflock;	/* Protects sctp_refcnt & timer mp */
835 	ushort_t	sctp_refcnt;	/* No. of pending upstream msg */
836 	mblk_t		*sctp_timer_mp;	/* List of fired timers. */
837 
838 	/* Misc */
839 	uint_t		sctp_bound_if;	/* IPV6_BOUND_IF */
840 
841 	mblk_t		*sctp_heartbeat_mp; /* Timer block for heartbeats */
842 	uint32_t	sctp_hb_interval; /* Default hb_interval */
843 
844 	int32_t		sctp_autoclose;	/* Auto disconnect in ticks */
845 	int64_t		sctp_active;	/* Last time data/sack on this conn */
846 	uint32_t	sctp_tx_adaption_code;	/* TX adaptation code */
847 	uint32_t	sctp_rx_adaption_code;	/* RX adaptation code */
848 
849 	/* Reliable control chunks */
850 	mblk_t		*sctp_cxmit_list; /* Xmit list for control chunks */
851 	uint32_t	sctp_lcsn;	/* Our serial number */
852 	uint32_t	sctp_fcsn;	/* Peer serial number */
853 
854 	/* Per association receive queue */
855 	kmutex_t	sctp_recvq_lock;
856 	mblk_t		*sctp_recvq;
857 	mblk_t		*sctp_recvq_tail;
858 	taskq_t		*sctp_recvq_tq;
859 
860 	/* Send queue to IP */
861 	kmutex_t	sctp_sendq_lock;
862 	mblk_t		*sctp_sendq;
863 	mblk_t		*sctp_sendq_tail;
864 	boolean_t	sctp_sendq_sending;
865 
866 	/* IPv6 ancillary data */
867 	uint_t		sctp_ipv6_recvancillary;	/* flags */
868 #define	SCTP_IPV6_RECVPKTINFO	0x01		/* IPV6_RECVPKTINFO opt */
869 #define	SCTP_IPV6_RECVHOPLIMIT	0x02		/* IPV6_RECVHOPLIMIT opt */
870 #define	SCTP_IPV6_RECVHOPOPTS	0x04		/* IPV6_RECVHOPOPTS opt */
871 #define	SCTP_IPV6_RECVDSTOPTS	0x08		/* IPV6_RECVDSTOPTS opt */
872 #define	SCTP_IPV6_RECVRTHDR	0x10		/* IPV6_RECVRTHDR opt */
873 #define	SCTP_IPV6_RECVRTDSTOPTS	0x20		/* IPV6_RECVRTHDRDSTOPTS opt */
874 
875 	uint_t		sctp_recvifindex;	/* last rcvd IPV6_RCVPKTINFO */
876 	uint_t		sctp_recvhops;		/*  " IPV6_RECVHOPLIMIT */
877 	ip6_hbh_t	*sctp_hopopts;		/*  " IPV6_RECVHOPOPTS */
878 	ip6_dest_t	*sctp_dstopts;		/*  " IPV6_RECVDSTOPTS */
879 	ip6_dest_t	*sctp_rtdstopts;	/*  " IPV6_RECVRTHDRDSTOPTS */
880 	ip6_rthdr_t	*sctp_rthdr;		/*  " IPV6_RECVRTHDR */
881 	uint_t		sctp_hopoptslen;
882 	uint_t		sctp_dstoptslen;
883 	uint_t		sctp_rtdstoptslen;
884 	uint_t		sctp_rthdrlen;
885 
886 	ip6_pkt_t	sctp_sticky_ipp;	/* Sticky options */
887 #define	sctp_ipp_fields		sctp_sticky_ipp.ipp_fields
888 #define	sctp_ipp_ifindex	sctp_sticky_ipp.ipp_ifindex
889 #define	sctp_ipp_addr		sctp_sticky_ipp.ipp_addr
890 #define	sctp_ipp_hoplimit	sctp_sticky_ipp.ipp_hoplimit
891 #define	sctp_ipp_hopoptslen	sctp_sticky_ipp.ipp_hopoptslen
892 #define	sctp_ipp_rtdstoptslen	sctp_sticky_ipp.ipp_rtdstoptslen
893 #define	sctp_ipp_rthdrlen	sctp_sticky_ipp.ipp_rthdrlen
894 #define	sctp_ipp_dstoptslen	sctp_sticky_ipp.ipp_dstoptslen
895 #define	sctp_ipp_hopopts	sctp_sticky_ipp.ipp_hopopts
896 #define	sctp_ipp_rtdstopts	sctp_sticky_ipp.ipp_rtdstopts
897 #define	sctp_ipp_rthdr		sctp_sticky_ipp.ipp_rthdr
898 #define	sctp_ipp_dstopts	sctp_sticky_ipp.ipp_dstopts
899 #define	sctp_ipp_nexthop	sctp_sticky_ipp.ipp_nexthop
900 	/* Stats */
901 	uint64_t	sctp_msgcount;
902 	uint64_t	sctp_prsctpdrop;
903 
904 	uint_t		sctp_v4label_len;	/* length of cached v4 label */
905 	uint_t		sctp_v6label_len;	/* length of cached v6 label */
906 } sctp_t;
907 
908 extern list_t	sctp_g_list;	/* Head of SCTP instance data chain */
909 extern kmutex_t sctp_g_lock;
910 
911 #endif	/* (defined(_KERNEL) || defined(_KMEMUSER)) */
912 
913 extern queue_t *sctp_g_q;	/* Default queue used during detached closes */
914 extern sctp_t *gsctp;
915 
916 /* Padding mblk for SCTP chunks. */
917 extern mblk_t *sctp_pad_mp;
918 
919 extern void	sctp_ack_timer(sctp_t *);
920 extern size_t	sctp_adaption_code_param(sctp_t *, uchar_t *);
921 extern void	sctp_adaption_event(sctp_t *);
922 extern int	sctp_add_faddr(sctp_t *, in6_addr_t *, int);
923 extern int	sctp_add_faddr_first(sctp_t *, in6_addr_t *, int);
924 extern boolean_t sctp_add_ftsn_set(sctp_ftsn_set_t **, sctp_faddr_t *, mblk_t *,
925 		    uint_t *, uint32_t *);
926 extern boolean_t sctp_add_recvq(sctp_t *, mblk_t *, boolean_t);
927 extern void	sctp_add_sendq(sctp_t *, mblk_t *);
928 extern void	sctp_add_unrec_parm(sctp_parm_hdr_t *, mblk_t **);
929 extern size_t	sctp_addr_params(sctp_t *, int, uchar_t *);
930 extern size_t	sctp_addr_params_len(sctp_t *, int, boolean_t);
931 extern mblk_t	*sctp_add_proto_hdr(sctp_t *, sctp_faddr_t *, mblk_t *, int,
932 		    int *);
933 extern void	sctp_addr_req(sctp_t *, mblk_t *);
934 extern sctp_t	*sctp_addrlist2sctp(mblk_t *, sctp_hdr_t *, sctp_chunk_hdr_t *,
935 		    uint_t, zoneid_t);
936 extern void	sctp_add_hdr(sctp_t *, uchar_t *, size_t);
937 extern void	sctp_check_adv_ack_pt(sctp_t *, mblk_t *, mblk_t *);
938 extern void	sctp_assoc_event(sctp_t *, uint16_t, uint16_t,
939 		    sctp_chunk_hdr_t *);
940 
941 extern void	sctp_bind_hash_insert(sctp_tf_t *, sctp_t *, int);
942 extern void	sctp_bind_hash_remove(sctp_t *);
943 extern int	sctp_bindi(sctp_t *, in_port_t, boolean_t, int, in_port_t *);
944 extern int	sctp_bind_add(sctp_t *, const void *, uint32_t, boolean_t,
945 		    in_port_t);
946 extern int	sctp_bind_del(sctp_t *, const void *, uint32_t, boolean_t);
947 extern int	sctp_build_hdrs(sctp_t *);
948 
949 extern int	sctp_check_abandoned_msg(sctp_t *, mblk_t *);
950 extern void	sctp_chunkify(sctp_t *, int, int);
951 extern void	sctp_clean_death(sctp_t *, int);
952 extern void	sctp_close_eager(sctp_t *);
953 extern int	sctp_compare_faddrsets(sctp_faddr_t *, sctp_faddr_t *);
954 extern void	sctp_congest_reset(sctp_t *);
955 extern void	sctp_conn_hash_insert(sctp_tf_t *, sctp_t *, int);
956 extern void	sctp_conn_hash_remove(sctp_t *);
957 extern sctp_t	*sctp_conn_match(in6_addr_t *, in6_addr_t *, uint32_t, uint_t,
958 		    zoneid_t);
959 extern sctp_t	*sctp_conn_request(sctp_t *, mblk_t *, uint_t, uint_t,
960 		    sctp_init_chunk_t *, mblk_t *);
961 extern int	sctp_conprim_opt_process(queue_t *, mblk_t *, int *, int *,
962 		    int *);
963 extern uint32_t	sctp_cumack(sctp_t *, uint32_t, mblk_t **);
964 extern sctp_t	*sctp_create_eager(sctp_t *);
965 
966 extern void	sctp_dispatch_rput(queue_t *, sctp_t *, sctp_hdr_t *, mblk_t *,
967 		    uint_t, uint_t, in6_addr_t);
968 extern char	*sctp_display(sctp_t *, char *);
969 extern void	sctp_display_all(void);
970 
971 extern void	sctp_error_event(sctp_t *, sctp_chunk_hdr_t *);
972 
973 extern void	sctp_faddr_alive(sctp_t *, sctp_faddr_t *);
974 extern int	sctp_faddr_dead(sctp_t *, sctp_faddr_t *, int);
975 extern void	sctp_faddr_fini(void);
976 extern void	sctp_faddr_init(void);
977 extern void	sctp_faddr2hdraddr(sctp_faddr_t *, sctp_t *);
978 extern void	sctp_faddr2ire(sctp_t *, sctp_faddr_t *);
979 extern void	sctp_fast_rexmit(sctp_t *);
980 extern void	sctp_fill_sack(sctp_t *, unsigned char *, int);
981 extern void	sctp_free_faddr_timers(sctp_t *);
982 extern void	sctp_free_ftsn_set(sctp_ftsn_set_t *);
983 extern void	sctp_free_msg(mblk_t *);
984 extern void	sctp_free_reass(sctp_instr_t *);
985 extern void	sctp_free_set(sctp_set_t *);
986 extern void	sctp_ftsn_sets_fini(void);
987 extern void	sctp_ftsn_sets_init(void);
988 
989 extern int	sctp_get_addrlist(sctp_t *, const void *, uint32_t *,
990 		    uchar_t **, int *, size_t *);
991 extern int	sctp_get_addrparams(sctp_t *, sctp_t *, mblk_t *,
992 		    sctp_chunk_hdr_t *, uint_t *);
993 extern void	sctp_get_faddr_list(sctp_t *, uchar_t *, size_t);
994 extern mblk_t	*sctp_get_first_sent(sctp_t *);
995 extern mblk_t	*sctp_get_msg_to_send(sctp_t *, mblk_t **, mblk_t *, int  *,
996 		    int32_t, uint32_t, sctp_faddr_t *);
997 extern void	sctp_get_saddr_list(sctp_t *, uchar_t *, size_t);
998 
999 extern int	sctp_handle_error(sctp_t *, sctp_hdr_t *, sctp_chunk_hdr_t *,
1000 		    mblk_t *);
1001 extern void	sctp_hash_destroy(void);
1002 extern void	sctp_hash_init(void);
1003 extern int	sctp_header_init_ipv4(sctp_t *, int);
1004 extern int	sctp_header_init_ipv6(sctp_t *, int);
1005 extern void	sctp_heartbeat_timer(sctp_t *);
1006 
1007 extern void	sctp_icmp_error(sctp_t *, mblk_t *);
1008 extern void	sctp_inc_taskq(void);
1009 extern void	sctp_info_req(sctp_t *, mblk_t *);
1010 extern mblk_t	*sctp_init_mp(sctp_t *);
1011 extern boolean_t sctp_initialize_params(sctp_t *, sctp_init_chunk_t *,
1012 		    sctp_init_chunk_t *);
1013 extern uint32_t	sctp_init2vtag(sctp_chunk_hdr_t *);
1014 extern void	sctp_intf_event(sctp_t *, in6_addr_t, int, int);
1015 extern void	sctp_input_data(sctp_t *, mblk_t *, mblk_t *);
1016 extern void	sctp_instream_cleanup(sctp_t *, boolean_t);
1017 extern void	sctp_ire2faddr(sctp_t *, sctp_faddr_t *);
1018 extern int	sctp_is_a_faddr_clean(sctp_t *);
1019 
1020 extern void	sctp_kstat_init(void);
1021 extern void	sctp_kstat_fini(void);
1022 
1023 extern ssize_t	sctp_link_abort(mblk_t *, uint16_t, char *, size_t, int,
1024 		    boolean_t);
1025 extern void	sctp_listen_hash_insert(sctp_tf_t *, sctp_t *);
1026 extern void	sctp_listen_hash_remove(sctp_t *);
1027 extern sctp_t	*sctp_lookup(sctp_t *, in6_addr_t *, sctp_tf_t *, uint32_t *,
1028 		    int);
1029 extern sctp_faddr_t *sctp_lookup_faddr(sctp_t *, in6_addr_t *);
1030 
1031 extern mblk_t	*sctp_make_err(sctp_t *, uint16_t, void *, size_t);
1032 extern mblk_t	*sctp_make_ftsn_chunk(sctp_t *, sctp_faddr_t *,
1033 		    sctp_ftsn_set_t *, uint_t, uint32_t);
1034 extern void	sctp_make_ftsns(sctp_t *, mblk_t *, mblk_t *, mblk_t **,
1035 		    sctp_faddr_t *, uint32_t *);
1036 extern mblk_t	*sctp_make_mp(sctp_t *, sctp_faddr_t *, int);
1037 extern mblk_t	*sctp_make_sack(sctp_t *, sctp_faddr_t *, mblk_t *);
1038 extern void	sctp_maxpsz_set(sctp_t *);
1039 extern void	sctp_move_faddr_timers(queue_t *, sctp_t *);
1040 
1041 extern void	sctp_nd_free(void);
1042 extern int	sctp_nd_getset(queue_t *, MBLKP);
1043 extern boolean_t sctp_nd_init(void);
1044 extern sctp_parm_hdr_t *sctp_next_parm(sctp_parm_hdr_t *, ssize_t *);
1045 
1046 extern void	sctp_ootb_shutdown_ack(sctp_t *, mblk_t *, uint_t);
1047 extern size_t	sctp_options_param(const sctp_t *, void *, int);
1048 extern size_t	sctp_options_param_len(const sctp_t *, int);
1049 extern void	sctp_output(sctp_t *sctp);
1050 
1051 extern boolean_t sctp_param_register(sctpparam_t *, int);
1052 extern void	sctp_partial_delivery_event(sctp_t *);
1053 extern int	sctp_process_cookie(sctp_t *, sctp_chunk_hdr_t *, mblk_t *,
1054 		    sctp_init_chunk_t **, sctp_hdr_t *, int *, in6_addr_t *);
1055 extern void	sctp_process_heartbeat(sctp_t *, sctp_chunk_hdr_t *);
1056 extern void	sctp_process_sendq(sctp_t *);
1057 extern void	sctp_process_timer(sctp_t *);
1058 
1059 extern void	sctp_redo_faddr_srcs(sctp_t *);
1060 extern void	sctp_regift_xmitlist(sctp_t *);
1061 extern void	sctp_return_heartbeat(sctp_t *, sctp_chunk_hdr_t *, mblk_t *);
1062 extern void	sctp_rexmit(sctp_t *, sctp_faddr_t *);
1063 extern void	sctp_rexmit_timer(sctp_t *, sctp_faddr_t *);
1064 extern sctp_faddr_t *sctp_rotate_faddr(sctp_t *, sctp_faddr_t *);
1065 
1066 extern void	sctp_sack(sctp_t *, mblk_t *);
1067 extern int	sctp_secure_restart_check(mblk_t *, sctp_chunk_hdr_t *,
1068 		    uint32_t, int);
1069 extern void	sctp_send_abort(sctp_t *, uint32_t, uint16_t, char *, size_t,
1070 		    mblk_t *, int, boolean_t);
1071 extern void	sctp_send_cookie_ack(sctp_t *);
1072 extern void	sctp_send_cookie_echo(sctp_t *, sctp_chunk_hdr_t *, mblk_t *);
1073 extern void	sctp_send_err(sctp_t *, mblk_t *, sctp_faddr_t *);
1074 extern void	sctp_send_initack(sctp_t *, sctp_chunk_hdr_t *, mblk_t *);
1075 extern void	sctp_send_shutdown(sctp_t *, int);
1076 extern void	sctp_send_heartbeat(sctp_t *, sctp_faddr_t *);
1077 extern void	sctp_sendfail_event(sctp_t *, mblk_t *, int, boolean_t);
1078 extern int	sctp_set_hdraddrs(sctp_t *, cred_t *);
1079 extern void	sctp_sets_init(void);
1080 extern void	sctp_sets_fini(void);
1081 extern void	sctp_shutdown_event(sctp_t *);
1082 extern void	sctp_stop_faddr_timers(sctp_t *);
1083 extern int	sctp_shutdown_received(sctp_t *, sctp_chunk_hdr_t *, int, int);
1084 extern void	sctp_shutdown_complete(sctp_t *);
1085 extern void	sctp_set_if_mtu(sctp_t *);
1086 extern void	sctp_set_iplen(sctp_t *, mblk_t *);
1087 extern void	sctp_set_ulp_prop(sctp_t *);
1088 extern size_t	sctp_supaddr_param_len(sctp_t *);
1089 extern size_t	sctp_supaddr_param(sctp_t *, uchar_t *);
1090 
1091 extern void	sctp_timer(sctp_t *, mblk_t *, clock_t);
1092 extern mblk_t	*sctp_timer_alloc(sctp_t *, pfv_t);
1093 extern void	sctp_timer_call(sctp_t *sctp, mblk_t *);
1094 extern void	sctp_timer_free(mblk_t *);
1095 extern void	sctp_timer_stop(mblk_t *);
1096 extern void	sctp_unlink_faddr(sctp_t *, sctp_faddr_t *);
1097 
1098 extern in_port_t sctp_update_next_port(in_port_t, zone_t *zone);
1099 extern void	sctp_update_rtt(sctp_t *, sctp_faddr_t *, clock_t);
1100 extern void	sctp_user_abort(sctp_t *, mblk_t *, boolean_t);
1101 
1102 extern void	sctp_validate_peer(sctp_t *);
1103 
1104 extern void	sctp_wput_ioctl(queue_t *, mblk_t *);
1105 
1106 extern int	sctp_xmit_list_clean(sctp_t *, ssize_t);
1107 
1108 extern void	sctp_zap_addrs(sctp_t *);
1109 extern void	sctp_zap_faddrs(sctp_t *, int);
1110 
1111 /* Contract private interface between SCTP and Clustering - PSARC/2005/602 */
1112 
1113 extern void	(*cl_sctp_listen)(sa_family_t, uchar_t *, uint_t, in_port_t);
1114 extern void	(*cl_sctp_unlisten)(sa_family_t, uchar_t *, uint_t, in_port_t);
1115 extern void 	(*cl_sctp_connect)(sa_family_t, uchar_t *, uint_t, in_port_t,
1116 		    uchar_t *, uint_t, in_port_t, boolean_t, cl_sctp_handle_t);
1117 extern void	(*cl_sctp_disconnect)(sa_family_t, cl_sctp_handle_t);
1118 extern void	(*cl_sctp_assoc_change)(sa_family_t, uchar_t *, size_t, uint_t,
1119 		    uchar_t *, size_t, uint_t, int, cl_sctp_handle_t);
1120 extern void	(*cl_sctp_check_addrs)(sa_family_t, in_port_t, uchar_t **,
1121 		    size_t, uint_t *, boolean_t);
1122 
1123 /* Send a mp to IP. */
1124 #define	IP_PUT(mp, conn, isv4)						\
1125 {									\
1126 	if ((isv4))							\
1127 		ip_output((conn), (mp), WR(sctp_g_q), IP_WPUT);		\
1128 	else								\
1129 		ip_output_v6((conn), (mp), WR(sctp_g_q), IP_WPUT);	\
1130 }
1131 
1132 #define	RUN_SCTP(sctp)						\
1133 {								\
1134 	mutex_enter(&(sctp)->sctp_lock);			\
1135 	while ((sctp)->sctp_running)				\
1136 		cv_wait(&(sctp)->sctp_cv, &(sctp)->sctp_lock);	\
1137 	(sctp)->sctp_running = B_TRUE;				\
1138 	mutex_exit(&(sctp)->sctp_lock);				\
1139 }
1140 
1141 /* Wake up recvq taskq */
1142 #define	WAKE_SCTP(sctp)				\
1143 {						\
1144 	mutex_enter(&(sctp)->sctp_lock);	\
1145 	if ((sctp)->sctp_timer_mp != NULL)	\
1146 		sctp_process_timer(sctp);	\
1147 	(sctp)->sctp_running = B_FALSE;		\
1148 	cv_broadcast(&(sctp)->sctp_cv);		\
1149 	mutex_exit(&(sctp)->sctp_lock);		\
1150 }
1151 
1152 #ifdef	__cplusplus
1153 }
1154 #endif
1155 
1156 #endif	/* _INET_SCTP_SCTP_IMPL_H */
1157