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