xref: /titanic_41/usr/src/uts/common/inet/sctp/sctp_conn.c (revision cde2885fdf538266ee2a3b08dee2d5075ce8fa2b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <sys/types.h>
28 #include <sys/systm.h>
29 #include <sys/stream.h>
30 #include <sys/cmn_err.h>
31 #include <sys/kmem.h>
32 #define	_SUN_TPI_VERSION 2
33 #include <sys/tihdr.h>
34 #include <sys/stropts.h>
35 #include <sys/strsubr.h>
36 #include <sys/socket.h>
37 #include <sys/tsol/tndb.h>
38 
39 #include <netinet/in.h>
40 #include <netinet/ip6.h>
41 
42 #include <inet/common.h>
43 #include <inet/ip.h>
44 #include <inet/ip6.h>
45 #include <inet/ipclassifier.h>
46 #include <inet/ipsec_impl.h>
47 
48 #include "sctp_impl.h"
49 #include "sctp_addr.h"
50 
51 /*
52  * Common accept code.  Called by sctp_conn_request.
53  * cr_pkt is the INIT / INIT ACK packet.
54  */
55 static int
56 sctp_accept_comm(sctp_t *listener, sctp_t *acceptor, mblk_t *cr_pkt,
57     uint_t ip_hdr_len, sctp_init_chunk_t *iack)
58 {
59 
60 	sctp_hdr_t		*sctph;
61 	sctp_chunk_hdr_t	*ich;
62 	sctp_init_chunk_t	*init;
63 	int			err;
64 	uint_t			sctp_options;
65 	conn_t			*aconnp;
66 	conn_t			*lconnp;
67 	cred_t			*cr;
68 	sctp_stack_t	*sctps = listener->sctp_sctps;
69 
70 	sctph = (sctp_hdr_t *)(cr_pkt->b_rptr + ip_hdr_len);
71 	ASSERT(OK_32PTR(sctph));
72 
73 	acceptor->sctp_lport = listener->sctp_lport;
74 	acceptor->sctp_fport = sctph->sh_sport;
75 
76 	ich = (sctp_chunk_hdr_t *)(iack + 1);
77 	init = (sctp_init_chunk_t *)(ich + 1);
78 
79 	/* acceptor isn't in any fanouts yet, so don't need to hold locks */
80 	ASSERT(acceptor->sctp_faddrs == NULL);
81 	err = sctp_get_addrparams(acceptor, listener, cr_pkt, ich,
82 	    &sctp_options);
83 	if (err != 0)
84 		return (err);
85 
86 	aconnp = acceptor->sctp_connp;
87 	lconnp = listener->sctp_connp;
88 	if (lconnp->conn_mlp_type != mlptSingle) {
89 		cr = aconnp->conn_peercred = msg_getcred(cr_pkt, NULL);
90 		if (cr != NULL)
91 			crhold(cr);
92 	}
93 
94 	if ((err = sctp_set_hdraddrs(acceptor)) != 0)
95 		return (err);
96 
97 	if ((sctp_options & SCTP_PRSCTP_OPTION) &&
98 	    listener->sctp_prsctp_aware && sctps->sctps_prsctp_enabled) {
99 		acceptor->sctp_prsctp_aware = B_TRUE;
100 	} else {
101 		acceptor->sctp_prsctp_aware = B_FALSE;
102 	}
103 	/* The new sctp_t is fully bound now. */
104 	acceptor->sctp_connp->conn_fully_bound = B_TRUE;
105 
106 	/* Get  initial TSNs */
107 	acceptor->sctp_ltsn = ntohl(iack->sic_inittsn);
108 	acceptor->sctp_recovery_tsn = acceptor->sctp_lastack_rxd =
109 	    acceptor->sctp_ltsn - 1;
110 	acceptor->sctp_adv_pap = acceptor->sctp_lastack_rxd;
111 	/* Serial numbers are initialized to the same value as the TSNs */
112 	acceptor->sctp_lcsn = acceptor->sctp_ltsn;
113 
114 	if (!sctp_initialize_params(acceptor, init, iack))
115 		return (ENOMEM);
116 
117 	/*
118 	 * Copy sctp_secret from the listener in case we need to validate
119 	 * a possibly delayed cookie.
120 	 */
121 	bcopy(listener->sctp_secret, acceptor->sctp_secret, SCTP_SECRET_LEN);
122 	bcopy(listener->sctp_old_secret, acceptor->sctp_old_secret,
123 	    SCTP_SECRET_LEN);
124 	acceptor->sctp_last_secret_update = lbolt64;
125 
126 	/*
127 	 * After acceptor is inserted in the hash list, it can be found.
128 	 * So we need to lock it here.
129 	 */
130 	RUN_SCTP(acceptor);
131 
132 	sctp_conn_hash_insert(&sctps->sctps_conn_fanout[
133 	    SCTP_CONN_HASH(sctps, acceptor->sctp_ports)], acceptor, 0);
134 	sctp_bind_hash_insert(&sctps->sctps_bind_fanout[
135 	    SCTP_BIND_HASH(ntohs(acceptor->sctp_lport))], acceptor, 0);
136 
137 	/*
138 	 * No need to check for multicast destination since ip will only pass
139 	 * up multicasts to those that have expressed interest
140 	 * TODO: what about rejecting broadcasts?
141 	 * Also check that source is not a multicast or broadcast address.
142 	 */
143 	/* XXXSCTP */
144 	acceptor->sctp_state = SCTPS_ESTABLISHED;
145 	acceptor->sctp_assoc_start_time = (uint32_t)lbolt;
146 	/*
147 	 * listener->sctp_rwnd should be the default window size or a
148 	 * window size changed via SO_RCVBUF option.
149 	 */
150 	acceptor->sctp_rwnd = listener->sctp_rwnd;
151 	acceptor->sctp_irwnd = acceptor->sctp_rwnd;
152 	acceptor->sctp_pd_point = acceptor->sctp_rwnd;
153 	acceptor->sctp_upcalls = listener->sctp_upcalls;
154 
155 	return (0);
156 }
157 
158 /* Process the COOKIE packet, mp, directed at the listener 'sctp' */
159 sctp_t *
160 sctp_conn_request(sctp_t *sctp, mblk_t *mp, uint_t ifindex, uint_t ip_hdr_len,
161     sctp_init_chunk_t *iack, mblk_t *ipsec_mp)
162 {
163 	sctp_t	*eager;
164 	uint_t	ipvers;
165 	ip6_t	*ip6h;
166 	int	err;
167 	conn_t	*connp, *econnp;
168 	sctp_stack_t	*sctps;
169 	struct sock_proto_props sopp;
170 	cred_t		*cr;
171 	pid_t		cpid;
172 
173 	/*
174 	 * No need to check for duplicate as this is the listener
175 	 * and we are holding the lock.  This means that no new
176 	 * connection can be created out of it.  And since the
177 	 * fanout already done cannot find a match, it means that
178 	 * there is no duplicate.
179 	 */
180 	ipvers = IPH_HDR_VERSION(mp->b_rptr);
181 	ASSERT(ipvers == IPV6_VERSION || ipvers == IPV4_VERSION);
182 	ASSERT(OK_32PTR(mp->b_rptr));
183 
184 	if ((eager = sctp_create_eager(sctp)) == NULL) {
185 		return (NULL);
186 	}
187 
188 	if (ipvers != IPV4_VERSION) {
189 		ip6h = (ip6_t *)mp->b_rptr;
190 		if (IN6_IS_ADDR_LINKLOCAL(&ip6h->ip6_src))
191 			eager->sctp_linklocal = 1;
192 		/*
193 		 * Record ifindex (might be zero) to tie this connection to
194 		 * that interface if either the listener was bound or
195 		 * if the connection is using link-local addresses.
196 		 */
197 		if (sctp->sctp_bound_if == ifindex ||
198 		    IN6_IS_ADDR_LINKLOCAL(&ip6h->ip6_src))
199 			eager->sctp_bound_if = ifindex;
200 		/*
201 		 * XXX broken. bound_if is always overwritten by statement
202 		 * below. What is the right thing to do here?
203 		 */
204 		eager->sctp_bound_if = sctp->sctp_bound_if;
205 	}
206 
207 	connp = sctp->sctp_connp;
208 	sctps = sctp->sctp_sctps;
209 	econnp = eager->sctp_connp;
210 
211 	if (connp->conn_policy != NULL) {
212 		ipsec_in_t *ii;
213 
214 		ASSERT(ipsec_mp != NULL);
215 		ii = (ipsec_in_t *)(ipsec_mp->b_rptr);
216 		ASSERT(ii->ipsec_in_policy == NULL);
217 		IPPH_REFHOLD(connp->conn_policy);
218 		ii->ipsec_in_policy = connp->conn_policy;
219 
220 		ipsec_mp->b_datap->db_type = IPSEC_POLICY_SET;
221 		if (!ip_bind_ipsec_policy_set(econnp, ipsec_mp)) {
222 			sctp_close_eager(eager);
223 			BUMP_MIB(&sctps->sctps_mib, sctpListenDrop);
224 			return (NULL);
225 		}
226 	}
227 
228 	if (ipsec_mp != NULL) {
229 		/*
230 		 * XXX need to fix the cached policy issue here.
231 		 * We temporarily set the conn_src/conn_rem here so
232 		 * that IPsec can use it for the latched policy
233 		 * selector.  This is obvioursly wrong as SCTP can
234 		 * use different addresses...
235 		 */
236 		if (ipvers == IPV4_VERSION) {
237 			ipha_t	*ipha;
238 
239 			ipha = (ipha_t *)mp->b_rptr;
240 			econnp->conn_src = ipha->ipha_dst;
241 			econnp->conn_rem = ipha->ipha_src;
242 		} else {
243 			econnp->conn_srcv6 = ip6h->ip6_dst;
244 			econnp->conn_remv6 = ip6h->ip6_src;
245 		}
246 	}
247 	if (ipsec_conn_cache_policy(econnp, ipvers == IPV4_VERSION) != 0) {
248 		sctp_close_eager(eager);
249 		BUMP_MIB(&sctps->sctps_mib, sctpListenDrop);
250 		return (NULL);
251 	}
252 
253 	/* Save for getpeerucred */
254 	cr = msg_getcred(mp, &cpid);
255 
256 	err = sctp_accept_comm(sctp, eager, mp, ip_hdr_len, iack);
257 	if (err) {
258 		sctp_close_eager(eager);
259 		BUMP_MIB(&sctps->sctps_mib, sctpListenDrop);
260 		return (NULL);
261 	}
262 
263 	/*
264 	 * On a clustered note send this notification to the clustering
265 	 * subsystem.
266 	 */
267 	if (cl_sctp_connect != NULL) {
268 		uchar_t	*slist;
269 		uchar_t	*flist;
270 		size_t	fsize;
271 		size_t	ssize;
272 
273 		fsize = sizeof (in6_addr_t) * eager->sctp_nfaddrs;
274 		ssize = sizeof (in6_addr_t) * eager->sctp_nsaddrs;
275 		slist = kmem_alloc(ssize, KM_NOSLEEP);
276 		flist = kmem_alloc(fsize, KM_NOSLEEP);
277 		if (slist == NULL || flist == NULL) {
278 			if (slist != NULL)
279 				kmem_free(slist, ssize);
280 			if (flist != NULL)
281 				kmem_free(flist, fsize);
282 			sctp_close_eager(eager);
283 			BUMP_MIB(&sctps->sctps_mib, sctpListenDrop);
284 			SCTP_KSTAT(sctps, sctp_cl_connect);
285 			return (NULL);
286 		}
287 		/* The clustering module frees these list */
288 		sctp_get_saddr_list(eager, slist, ssize);
289 		sctp_get_faddr_list(eager, flist, fsize);
290 		(*cl_sctp_connect)(eager->sctp_family, slist,
291 		    eager->sctp_nsaddrs, eager->sctp_lport, flist,
292 		    eager->sctp_nfaddrs, eager->sctp_fport, B_FALSE,
293 		    (cl_sctp_handle_t)eager);
294 	}
295 
296 	/* Connection established, so send up the conn_ind */
297 	if ((eager->sctp_ulpd = sctp->sctp_ulp_newconn(sctp->sctp_ulpd,
298 	    (sock_lower_handle_t)eager, NULL, cr, cpid,
299 	    &eager->sctp_upcalls)) == NULL) {
300 		sctp_close_eager(eager);
301 		BUMP_MIB(&sctps->sctps_mib, sctpListenDrop);
302 		return (NULL);
303 	}
304 	ASSERT(SCTP_IS_DETACHED(eager));
305 	eager->sctp_detached = B_FALSE;
306 	bzero(&sopp, sizeof (sopp));
307 	sopp.sopp_flags = SOCKOPT_MAXBLK|SOCKOPT_WROFF;
308 	sopp.sopp_maxblk = strmsgsz;
309 	if (eager->sctp_family == AF_INET) {
310 		sopp.sopp_wroff = sctps->sctps_wroff_xtra +
311 		    sizeof (sctp_data_hdr_t) + sctp->sctp_hdr_len;
312 	} else {
313 		sopp.sopp_wroff = sctps->sctps_wroff_xtra +
314 		    sizeof (sctp_data_hdr_t) + sctp->sctp_hdr6_len;
315 	}
316 	eager->sctp_ulp_prop(eager->sctp_ulpd, &sopp);
317 	return (eager);
318 }
319 
320 /*
321  * Connect to a peer - this function inserts the sctp in the
322  * bind and conn fanouts, sends the INIT, and replies to the client
323  * with an OK ack.
324  */
325 int
326 sctp_connect(sctp_t *sctp, const struct sockaddr *dst, uint32_t addrlen)
327 {
328 	sin_t		*sin;
329 	sin6_t		*sin6;
330 	in6_addr_t	dstaddr;
331 	in_port_t	dstport;
332 	mblk_t		*initmp;
333 	sctp_tf_t	*tbf;
334 	sctp_t		*lsctp;
335 	char		buf[INET6_ADDRSTRLEN];
336 	int		sleep = sctp->sctp_cansleep ? KM_SLEEP : KM_NOSLEEP;
337 	int 		hdrlen;
338 	ip6_rthdr_t	*rth;
339 	int		err;
340 	sctp_faddr_t	*cur_fp;
341 	sctp_stack_t	*sctps = sctp->sctp_sctps;
342 	struct sock_proto_props sopp;
343 
344 	/*
345 	 * Determine packet type based on type of address passed in
346 	 * the request should contain an IPv4 or IPv6 address.
347 	 * Make sure that address family matches the type of
348 	 * family of the the address passed down
349 	 */
350 	if (addrlen < sizeof (sin_t)) {
351 		return (EINVAL);
352 	}
353 	switch (dst->sa_family) {
354 	case AF_INET:
355 		sin = (sin_t *)dst;
356 
357 		/* Check for attempt to connect to non-unicast */
358 		if (CLASSD(sin->sin_addr.s_addr) ||
359 		    (sin->sin_addr.s_addr == INADDR_BROADCAST)) {
360 			ip0dbg(("sctp_connect: non-unicast\n"));
361 			return (EINVAL);
362 		}
363 		if (sctp->sctp_connp->conn_ipv6_v6only)
364 			return (EAFNOSUPPORT);
365 
366 		/* convert to v6 mapped */
367 		/* Check for attempt to connect to INADDR_ANY */
368 		if (sin->sin_addr.s_addr == INADDR_ANY)  {
369 			struct in_addr v4_addr;
370 			/*
371 			 * SunOS 4.x and 4.3 BSD allow an application
372 			 * to connect a TCP socket to INADDR_ANY.
373 			 * When they do this, the kernel picks the
374 			 * address of one interface and uses it
375 			 * instead.  The kernel usually ends up
376 			 * picking the address of the loopback
377 			 * interface.  This is an undocumented feature.
378 			 * However, we provide the same thing here
379 			 * in case any TCP apps that use this feature
380 			 * are being ported to SCTP...
381 			 */
382 			v4_addr.s_addr = htonl(INADDR_LOOPBACK);
383 			IN6_INADDR_TO_V4MAPPED(&v4_addr, &dstaddr);
384 		} else {
385 			IN6_INADDR_TO_V4MAPPED(&sin->sin_addr, &dstaddr);
386 		}
387 		dstport = sin->sin_port;
388 		if (sin->sin_family == AF_INET) {
389 			hdrlen = sctp->sctp_hdr_len;
390 		} else {
391 			hdrlen = sctp->sctp_hdr6_len;
392 		}
393 		break;
394 	case AF_INET6:
395 		sin6 = (sin6_t *)dst;
396 		/* Check for attempt to connect to non-unicast. */
397 		if ((addrlen < sizeof (sin6_t)) ||
398 		    IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
399 			ip0dbg(("sctp_connect: non-unicast\n"));
400 			return (EINVAL);
401 		}
402 		if (sctp->sctp_connp->conn_ipv6_v6only &&
403 		    IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
404 			return (EAFNOSUPPORT);
405 		}
406 		/* check for attempt to connect to unspec */
407 		if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
408 			dstaddr = ipv6_loopback;
409 		} else {
410 			dstaddr = sin6->sin6_addr;
411 			if (IN6_IS_ADDR_LINKLOCAL(&dstaddr))
412 				sctp->sctp_linklocal = 1;
413 		}
414 		dstport = sin6->sin6_port;
415 		hdrlen = sctp->sctp_hdr6_len;
416 		break;
417 	default:
418 		dprint(1, ("sctp_connect: unknown family %d\n",
419 		    dst->sa_family));
420 		return (EAFNOSUPPORT);
421 	}
422 
423 	(void) inet_ntop(AF_INET6, &dstaddr, buf, sizeof (buf));
424 	dprint(1, ("sctp_connect: attempting connect to %s...\n", buf));
425 
426 	RUN_SCTP(sctp);
427 
428 	if (sctp->sctp_family != dst->sa_family ||
429 	    (sctp->sctp_connp->conn_state_flags & CONN_CLOSING)) {
430 		WAKE_SCTP(sctp);
431 		return (EINVAL);
432 	}
433 
434 	switch (sctp->sctp_state) {
435 	case SCTPS_IDLE: {
436 		struct sockaddr_storage	ss;
437 
438 		/*
439 		 * We support a quick connect capability here, allowing
440 		 * clients to transition directly from IDLE to COOKIE_WAIT.
441 		 * sctp_bindi will pick an unused port, insert the connection
442 		 * in the bind hash and transition to BOUND state. SCTP
443 		 * picks and uses what it considers the optimal local address
444 		 * set (just like specifiying INADDR_ANY to bind()).
445 		 */
446 		dprint(1, ("sctp_connect: idle, attempting bind...\n"));
447 		ASSERT(sctp->sctp_nsaddrs == 0);
448 
449 		bzero(&ss, sizeof (ss));
450 		ss.ss_family = sctp->sctp_family;
451 		WAKE_SCTP(sctp);
452 		if ((err = sctp_bind(sctp, (struct sockaddr *)&ss,
453 		    sizeof (ss))) != 0) {
454 			return (err);
455 		}
456 		RUN_SCTP(sctp);
457 		/* FALLTHRU */
458 	}
459 
460 	case SCTPS_BOUND:
461 		ASSERT(sctp->sctp_nsaddrs > 0);
462 
463 		/* do the connect */
464 		/* XXX check for attempt to connect to self */
465 		sctp->sctp_fport = dstport;
466 
467 		ASSERT(sctp->sctp_iphc);
468 		ASSERT(sctp->sctp_iphc6);
469 
470 		/*
471 		 * Don't allow this connection to completely duplicate
472 		 * an existing connection.
473 		 *
474 		 * Ensure that the duplicate check and insertion is atomic.
475 		 */
476 		sctp_conn_hash_remove(sctp);
477 		tbf = &sctps->sctps_conn_fanout[SCTP_CONN_HASH(sctps,
478 		    sctp->sctp_ports)];
479 		mutex_enter(&tbf->tf_lock);
480 		lsctp = sctp_lookup(sctp, &dstaddr, tbf, &sctp->sctp_ports,
481 		    SCTPS_COOKIE_WAIT);
482 		if (lsctp != NULL) {
483 			/* found a duplicate connection */
484 			mutex_exit(&tbf->tf_lock);
485 			SCTP_REFRELE(lsctp);
486 			WAKE_SCTP(sctp);
487 			return (EADDRINUSE);
488 		}
489 		/*
490 		 * OK; set up the peer addr (this may grow after we get
491 		 * the INIT ACK from the peer with additional addresses).
492 		 */
493 		if ((err = sctp_add_faddr(sctp, &dstaddr, sleep,
494 		    B_FALSE)) != 0) {
495 			mutex_exit(&tbf->tf_lock);
496 			WAKE_SCTP(sctp);
497 			return (err);
498 		}
499 		cur_fp = sctp->sctp_faddrs;
500 
501 		/* No valid src addr, return. */
502 		if (cur_fp->state == SCTP_FADDRS_UNREACH) {
503 			mutex_exit(&tbf->tf_lock);
504 			WAKE_SCTP(sctp);
505 			return (EADDRNOTAVAIL);
506 		}
507 
508 		sctp->sctp_primary = cur_fp;
509 		sctp->sctp_current = cur_fp;
510 		sctp->sctp_mss = cur_fp->sfa_pmss;
511 		sctp_conn_hash_insert(tbf, sctp, 1);
512 		mutex_exit(&tbf->tf_lock);
513 
514 		/* initialize composite headers */
515 		if ((err = sctp_set_hdraddrs(sctp)) != 0) {
516 			sctp_conn_hash_remove(sctp);
517 			WAKE_SCTP(sctp);
518 			return (err);
519 		}
520 
521 		/*
522 		 * Massage a routing header (if present) putting the first hop
523 		 * in ip6_dst.
524 		 */
525 		rth = ip_find_rthdr_v6(sctp->sctp_ip6h,
526 		    (uint8_t *)sctp->sctp_sctph6);
527 		if (rth != NULL) {
528 			(void) ip_massage_options_v6(sctp->sctp_ip6h, rth,
529 			    sctps->sctps_netstack);
530 		}
531 
532 		/*
533 		 * Turn off the don't fragment bit on the (only) faddr,
534 		 * so that if one of the messages exchanged during the
535 		 * initialization sequence exceeds the path mtu, it
536 		 * at least has a chance to get there. SCTP does no
537 		 * fragmentation of initialization messages.  The DF bit
538 		 * will be turned on again in sctp_send_cookie_echo()
539 		 * (but the cookie echo will still be sent with the df bit
540 		 * off).
541 		 */
542 		cur_fp->df = B_FALSE;
543 
544 		/* Mark this address as alive */
545 		cur_fp->state = SCTP_FADDRS_ALIVE;
546 
547 		/* This sctp_t is fully bound now. */
548 		sctp->sctp_connp->conn_fully_bound = B_TRUE;
549 
550 		/* Send the INIT to the peer */
551 		SCTP_FADDR_TIMER_RESTART(sctp, cur_fp, cur_fp->rto);
552 		sctp->sctp_state = SCTPS_COOKIE_WAIT;
553 		/*
554 		 * sctp_init_mp() could result in modifying the source
555 		 * address list, so take the hash lock.
556 		 */
557 		mutex_enter(&tbf->tf_lock);
558 		initmp = sctp_init_mp(sctp);
559 		if (initmp == NULL) {
560 			mutex_exit(&tbf->tf_lock);
561 			/*
562 			 * It may happen that all the source addresses
563 			 * (loopback/link local) are removed.  In that case,
564 			 * faile the connect.
565 			 */
566 			if (sctp->sctp_nsaddrs == 0) {
567 				sctp_conn_hash_remove(sctp);
568 				SCTP_FADDR_TIMER_STOP(cur_fp);
569 				WAKE_SCTP(sctp);
570 				return (EADDRNOTAVAIL);
571 			}
572 
573 			/* Otherwise, let the retransmission timer retry */
574 			WAKE_SCTP(sctp);
575 			goto notify_ulp;
576 		}
577 		mutex_exit(&tbf->tf_lock);
578 
579 		/*
580 		 * On a clustered note send this notification to the clustering
581 		 * subsystem.
582 		 */
583 		if (cl_sctp_connect != NULL) {
584 			uchar_t		*slist;
585 			uchar_t		*flist;
586 			size_t		ssize;
587 			size_t		fsize;
588 
589 			fsize = sizeof (in6_addr_t) * sctp->sctp_nfaddrs;
590 			ssize = sizeof (in6_addr_t) * sctp->sctp_nsaddrs;
591 			slist = kmem_alloc(ssize, KM_SLEEP);
592 			flist = kmem_alloc(fsize, KM_SLEEP);
593 			/* The clustering module frees the lists */
594 			sctp_get_saddr_list(sctp, slist, ssize);
595 			sctp_get_faddr_list(sctp, flist, fsize);
596 			(*cl_sctp_connect)(sctp->sctp_family, slist,
597 			    sctp->sctp_nsaddrs, sctp->sctp_lport,
598 			    flist, sctp->sctp_nfaddrs, sctp->sctp_fport,
599 			    B_TRUE, (cl_sctp_handle_t)sctp);
600 		}
601 		WAKE_SCTP(sctp);
602 		/* OK to call IP_PUT() here instead of sctp_add_sendq(). */
603 		CONN_INC_REF(sctp->sctp_connp);
604 		initmp->b_flag |= MSGHASREF;
605 		IP_PUT(initmp, sctp->sctp_connp, sctp->sctp_current->isv4);
606 		BUMP_LOCAL(sctp->sctp_opkts);
607 
608 notify_ulp:
609 		bzero(&sopp, sizeof (sopp));
610 		sopp.sopp_flags = SOCKOPT_WROFF;
611 		sopp.sopp_wroff = sctps->sctps_wroff_xtra + hdrlen +
612 		    sizeof (sctp_data_hdr_t);
613 		sctp->sctp_ulp_prop(sctp->sctp_ulpd, &sopp);
614 
615 		return (0);
616 	default:
617 		ip0dbg(("sctp_connect: invalid state. %d\n", sctp->sctp_state));
618 		WAKE_SCTP(sctp);
619 		return (EINVAL);
620 	}
621 }
622