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