17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
577c67f2fSkcpoon  * Common Development and Distribution License (the "License").
677c67f2fSkcpoon  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2177c67f2fSkcpoon 
227c478bd9Sstevel@tonic-gate /*
23f4b3ec61Sdh  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/stream.h>
327c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
337c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
347c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
357c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include <netinet/in.h>
387c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <inet/common.h>
417c478bd9Sstevel@tonic-gate #include <inet/ip.h>
427c478bd9Sstevel@tonic-gate #include <inet/ip6.h>
437c478bd9Sstevel@tonic-gate #include <inet/mib2.h>
447c478bd9Sstevel@tonic-gate #include <inet/nd.h>
457c478bd9Sstevel@tonic-gate #include <inet/optcom.h>
467c478bd9Sstevel@tonic-gate #include <inet/sctp_ip.h>
47f4b3ec61Sdh #include <inet/ipclassifier.h>
487c478bd9Sstevel@tonic-gate #include "sctp_impl.h"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate void
517c478bd9Sstevel@tonic-gate sctp_send_shutdown(sctp_t *sctp, int rexmit)
527c478bd9Sstevel@tonic-gate {
537c478bd9Sstevel@tonic-gate 	mblk_t *smp;
547c478bd9Sstevel@tonic-gate 	mblk_t *sendmp;
557c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t *sch;
567c478bd9Sstevel@tonic-gate 	uint32_t *ctsn;
577c478bd9Sstevel@tonic-gate 	sctp_faddr_t *fp;
58f4b3ec61Sdh 	sctp_stack_t	*sctps = sctp->sctp_sctps;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	if (sctp->sctp_state != SCTPS_ESTABLISHED &&
617c478bd9Sstevel@tonic-gate 	    sctp->sctp_state != SCTPS_SHUTDOWN_PENDING &&
627c478bd9Sstevel@tonic-gate 	    sctp->sctp_state != SCTPS_SHUTDOWN_SENT) {
637c478bd9Sstevel@tonic-gate 		return;
647c478bd9Sstevel@tonic-gate 	}
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	if (sctp->sctp_state == SCTPS_ESTABLISHED) {
677c478bd9Sstevel@tonic-gate 		sctp->sctp_state = SCTPS_SHUTDOWN_PENDING;
687c478bd9Sstevel@tonic-gate 		/*
697c478bd9Sstevel@tonic-gate 		 * We set an upper bound on how long we will
707c478bd9Sstevel@tonic-gate 		 * wait for a shutdown-ack from the peer. This
717c478bd9Sstevel@tonic-gate 		 * is to prevent the receiver from attempting
727c478bd9Sstevel@tonic-gate 		 * to create a half-closed state indefinately.
737c478bd9Sstevel@tonic-gate 		 * See archive from IETF TSVWG mailing list
747c478bd9Sstevel@tonic-gate 		 * for June 2001 for more information.
757c478bd9Sstevel@tonic-gate 		 * Since we will not be calculating RTTs after
767c478bd9Sstevel@tonic-gate 		 * sending the shutdown, we can overload out_time
777c478bd9Sstevel@tonic-gate 		 * to track how long we have waited.
787c478bd9Sstevel@tonic-gate 		 */
797c478bd9Sstevel@tonic-gate 		sctp->sctp_out_time = lbolt64;
807c478bd9Sstevel@tonic-gate 	}
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	/*
837c478bd9Sstevel@tonic-gate 	 * If there is unsent (or unacked) data, wait for it to get ack'd
847c478bd9Sstevel@tonic-gate 	 */
857c478bd9Sstevel@tonic-gate 	if (sctp->sctp_xmit_head != NULL || sctp->sctp_xmit_unsent != NULL) {
867c478bd9Sstevel@tonic-gate 		return;
877c478bd9Sstevel@tonic-gate 	}
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	/* rotate faddrs if we are retransmitting */
907c478bd9Sstevel@tonic-gate 	if (!rexmit) {
917c478bd9Sstevel@tonic-gate 		fp = sctp->sctp_current;
927c478bd9Sstevel@tonic-gate 	} else {
937c478bd9Sstevel@tonic-gate 		fp = sctp_rotate_faddr(sctp, sctp->sctp_shutdown_faddr);
947c478bd9Sstevel@tonic-gate 	}
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	sctp->sctp_shutdown_faddr = fp;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	/* Link in a SACK if resending the shutdown */
997c478bd9Sstevel@tonic-gate 	if (sctp->sctp_state > SCTPS_SHUTDOWN_PENDING &&
1007c478bd9Sstevel@tonic-gate 	    (sendmp = sctp_make_sack(sctp, fp, NULL)) != NULL) {
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 		smp = allocb(sizeof (*sch) + sizeof (*ctsn), BPRI_MED);
1037c478bd9Sstevel@tonic-gate 		if (smp == NULL) {
1047c478bd9Sstevel@tonic-gate 			freemsg(sendmp);
1057c478bd9Sstevel@tonic-gate 			goto done;
1067c478bd9Sstevel@tonic-gate 		}
1077c478bd9Sstevel@tonic-gate 		linkb(sendmp, smp);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 		sch = (sctp_chunk_hdr_t *)smp->b_rptr;
1107c478bd9Sstevel@tonic-gate 		smp->b_wptr = smp->b_rptr + sizeof (*sch) + sizeof (*ctsn);
1117c478bd9Sstevel@tonic-gate 	} else {
1127c478bd9Sstevel@tonic-gate 		sendmp = sctp_make_mp(sctp, fp,
1137c478bd9Sstevel@tonic-gate 		    sizeof (*sch) + sizeof (*ctsn));
1147c478bd9Sstevel@tonic-gate 		if (sendmp == NULL) {
115f4b3ec61Sdh 			SCTP_KSTAT(sctps, sctp_send_shutdown_failed);
1167c478bd9Sstevel@tonic-gate 			goto done;
1177c478bd9Sstevel@tonic-gate 		}
1187c478bd9Sstevel@tonic-gate 		sch = (sctp_chunk_hdr_t *)sendmp->b_wptr;
1197c478bd9Sstevel@tonic-gate 		sendmp->b_wptr += sizeof (*sch) + sizeof (*ctsn);
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 		/* shutdown w/o sack, update lastacked */
1227c478bd9Sstevel@tonic-gate 		sctp->sctp_lastacked = sctp->sctp_ftsn - 1;
1237c478bd9Sstevel@tonic-gate 	}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	sch->sch_id = CHUNK_SHUTDOWN;
1267c478bd9Sstevel@tonic-gate 	sch->sch_flags = 0;
1277c478bd9Sstevel@tonic-gate 	sch->sch_len = htons(sizeof (*sch) + sizeof (*ctsn));
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	ctsn = (uint32_t *)(sch + 1);
1307c478bd9Sstevel@tonic-gate 	*ctsn = htonl(sctp->sctp_lastacked);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	/* Link the shutdown chunk in after the IP/SCTP header */
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	sctp_set_iplen(sctp, sendmp);
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	/* Send the shutdown and restart the timer */
1397c478bd9Sstevel@tonic-gate 	sctp_add_sendq(sctp, sendmp);
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate done:
1427c478bd9Sstevel@tonic-gate 	sctp->sctp_state = SCTPS_SHUTDOWN_SENT;
1437c478bd9Sstevel@tonic-gate 	SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current,
1447c478bd9Sstevel@tonic-gate 	    sctp->sctp_current->rto);
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate int
14877c67f2fSkcpoon sctp_shutdown_received(sctp_t *sctp, sctp_chunk_hdr_t *sch, boolean_t crwsd,
14977c67f2fSkcpoon     boolean_t rexmit, sctp_faddr_t *fp)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate 	mblk_t *samp;
1527c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t *sach;
1537c478bd9Sstevel@tonic-gate 	uint32_t *tsn;
1547c478bd9Sstevel@tonic-gate 	int trysend = 0;
155f4b3ec61Sdh 	sctp_stack_t	*sctps = sctp->sctp_sctps;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	if (sctp->sctp_state != SCTPS_SHUTDOWN_ACK_SENT)
1587c478bd9Sstevel@tonic-gate 		sctp->sctp_state = SCTPS_SHUTDOWN_RECEIVED;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	/* Extract and process the TSN in the shutdown chunk */
1617c478bd9Sstevel@tonic-gate 	if (sch != NULL) {
1627c478bd9Sstevel@tonic-gate 		tsn = (uint32_t *)(sch + 1);
1637c478bd9Sstevel@tonic-gate 		trysend = sctp_cumack(sctp, ntohl(*tsn), &samp);
1647c478bd9Sstevel@tonic-gate 	}
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/* Don't allow sending new data */
167*c31292eeSkcpoon 	if (!SCTP_IS_DETACHED(sctp) && !sctp->sctp_ulp_discon_done) {
1687c478bd9Sstevel@tonic-gate 		sctp->sctp_ulp_disconnecting(sctp->sctp_ulpd);
169*c31292eeSkcpoon 		sctp->sctp_ulp_discon_done = B_TRUE;
170*c31292eeSkcpoon 	}
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	/*
1737c478bd9Sstevel@tonic-gate 	 * If there is unsent or unacked data, try sending them out now.
1747c478bd9Sstevel@tonic-gate 	 * The other side should acknowledge them.  After we have flushed
1757c478bd9Sstevel@tonic-gate 	 * the transmit queue, we can complete the shutdown sequence.
1767c478bd9Sstevel@tonic-gate 	 */
1777c478bd9Sstevel@tonic-gate 	if (sctp->sctp_xmit_head != NULL || sctp->sctp_xmit_unsent != NULL)
1787c478bd9Sstevel@tonic-gate 		return (1);
1797c478bd9Sstevel@tonic-gate 
18077c67f2fSkcpoon 	if (fp == NULL) {
18177c67f2fSkcpoon 		/* rotate faddrs if we are retransmitting */
18277c67f2fSkcpoon 		if (!rexmit)
18377c67f2fSkcpoon 			fp = sctp->sctp_current;
18477c67f2fSkcpoon 		else
18577c67f2fSkcpoon 			fp = sctp_rotate_faddr(sctp, sctp->sctp_shutdown_faddr);
18677c67f2fSkcpoon 	}
18777c67f2fSkcpoon 	sctp->sctp_shutdown_faddr = fp;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	samp = sctp_make_mp(sctp, fp, sizeof (*sach));
19077c67f2fSkcpoon 	if (samp == NULL) {
191f4b3ec61Sdh 		SCTP_KSTAT(sctps, sctp_send_shutdown_ack_failed);
1927c478bd9Sstevel@tonic-gate 		goto dotimer;
19377c67f2fSkcpoon 	}
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	sach = (sctp_chunk_hdr_t *)samp->b_wptr;
1967c478bd9Sstevel@tonic-gate 	sach->sch_id = CHUNK_SHUTDOWN_ACK;
1977c478bd9Sstevel@tonic-gate 	sach->sch_flags = 0;
1987c478bd9Sstevel@tonic-gate 	sach->sch_len = htons(sizeof (*sach));
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	samp->b_wptr += sizeof (*sach);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	/*
2037c478bd9Sstevel@tonic-gate 	 * bundle a "cookie received while shutting down" error if
2047c478bd9Sstevel@tonic-gate 	 * the caller asks for it.
2057c478bd9Sstevel@tonic-gate 	 */
2067c478bd9Sstevel@tonic-gate 	if (crwsd) {
2077c478bd9Sstevel@tonic-gate 		mblk_t *errmp;
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 		errmp = sctp_make_err(sctp, SCTP_ERR_COOKIE_SHUT, NULL, 0);
2107c478bd9Sstevel@tonic-gate 		if (errmp != NULL) {
2117c478bd9Sstevel@tonic-gate 			linkb(samp, errmp);
2127c478bd9Sstevel@tonic-gate 			BUMP_LOCAL(sctp->sctp_obchunks);
2137c478bd9Sstevel@tonic-gate 		}
2147c478bd9Sstevel@tonic-gate 	}
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	sctp_set_iplen(sctp, samp);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	sctp_add_sendq(sctp, samp);
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate dotimer:
2237c478bd9Sstevel@tonic-gate 	sctp->sctp_state = SCTPS_SHUTDOWN_ACK_SENT;
2247c478bd9Sstevel@tonic-gate 	SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current,
2257c478bd9Sstevel@tonic-gate 	    sctp->sctp_current->rto);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	return (trysend);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate void
2317c478bd9Sstevel@tonic-gate sctp_shutdown_complete(sctp_t *sctp)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate 	mblk_t *scmp;
2347c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t *scch;
235f4b3ec61Sdh 	sctp_stack_t	*sctps = sctp->sctp_sctps;
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 	scmp = sctp_make_mp(sctp, NULL, sizeof (*scch));
2387c478bd9Sstevel@tonic-gate 	if (scmp == NULL) {
2397c478bd9Sstevel@tonic-gate 		/* XXX use timer approach */
240f4b3ec61Sdh 		SCTP_KSTAT(sctps, sctp_send_shutdown_comp_failed);
2417c478bd9Sstevel@tonic-gate 		return;
2427c478bd9Sstevel@tonic-gate 	}
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	scch = (sctp_chunk_hdr_t *)scmp->b_wptr;
2457c478bd9Sstevel@tonic-gate 	scch->sch_id = CHUNK_SHUTDOWN_COMPLETE;
2467c478bd9Sstevel@tonic-gate 	scch->sch_flags = 0;
2477c478bd9Sstevel@tonic-gate 	scch->sch_len = htons(sizeof (*scch));
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	scmp->b_wptr += sizeof (*scch);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	sctp_set_iplen(sctp, scmp);
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	sctp_add_sendq(sctp, scmp);
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate /*
2597c478bd9Sstevel@tonic-gate  * Similar to sctp_shutdown_complete(), except that since this
2607c478bd9Sstevel@tonic-gate  * is out-of-the-blue, we can't use an sctp's association information,
2617c478bd9Sstevel@tonic-gate  * and instead must draw all necessary info from the incoming packet.
2627c478bd9Sstevel@tonic-gate  */
2637c478bd9Sstevel@tonic-gate void
2647c478bd9Sstevel@tonic-gate sctp_ootb_shutdown_ack(sctp_t *gsctp, mblk_t *inmp, uint_t ip_hdr_len)
2657c478bd9Sstevel@tonic-gate {
2667c478bd9Sstevel@tonic-gate 	boolean_t		isv4;
2677c478bd9Sstevel@tonic-gate 	ipha_t			*inip4h;
2687c478bd9Sstevel@tonic-gate 	ip6_t			*inip6h;
2697c478bd9Sstevel@tonic-gate 	sctp_hdr_t		*insctph;
2707c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t	*scch;
2717c478bd9Sstevel@tonic-gate 	int			i;
2727c478bd9Sstevel@tonic-gate 	uint16_t		port;
2737c478bd9Sstevel@tonic-gate 	mblk_t			*mp1;
274f4b3ec61Sdh 	sctp_stack_t	*sctps = gsctp->sctp_sctps;
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 	isv4 = (IPH_HDR_VERSION(inmp->b_rptr) == IPV4_VERSION);
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	/*
2797c478bd9Sstevel@tonic-gate 	 * The gsctp should contain the minimal IP header.  So the
2807c478bd9Sstevel@tonic-gate 	 * incoming mblk should be able to hold the new SCTP packet.
2817c478bd9Sstevel@tonic-gate 	 */
2827c478bd9Sstevel@tonic-gate 	ASSERT(MBLKL(inmp) >= sizeof (*insctph) + sizeof (*scch) +
2837c478bd9Sstevel@tonic-gate 	    (isv4 ? gsctp->sctp_ip_hdr_len : gsctp->sctp_ip_hdr6_len));
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 	/*
2867c478bd9Sstevel@tonic-gate 	 * Check to see if we can reuse the incoming mblk.  There should
28777c67f2fSkcpoon 	 * not be other reference and the db_base of the mblk should be
28877c67f2fSkcpoon 	 * properly aligned.  Since this packet comes from below,
2897c478bd9Sstevel@tonic-gate 	 * there should be enough header space to fill in what the lower
2907c478bd9Sstevel@tonic-gate 	 * layers want to add.  And we will not stash anything there.
2917c478bd9Sstevel@tonic-gate 	 */
29277c67f2fSkcpoon 	if (!IS_P2ALIGNED(DB_BASE(inmp), sizeof (ire_t *)) ||
29377c67f2fSkcpoon 	    DB_REF(inmp) != 1) {
294f4b3ec61Sdh 		mp1 = allocb(MBLKL(inmp) + sctps->sctps_wroff_xtra, BPRI_MED);
2957c478bd9Sstevel@tonic-gate 		if (mp1 == NULL) {
2967c478bd9Sstevel@tonic-gate 			freeb(inmp);
2977c478bd9Sstevel@tonic-gate 			return;
2987c478bd9Sstevel@tonic-gate 		}
299f4b3ec61Sdh 		mp1->b_rptr += sctps->sctps_wroff_xtra;
3007c478bd9Sstevel@tonic-gate 		mp1->b_wptr = mp1->b_rptr + MBLKL(inmp);
3017c478bd9Sstevel@tonic-gate 		bcopy(inmp->b_rptr, mp1->b_rptr, MBLKL(inmp));
3027c478bd9Sstevel@tonic-gate 		freeb(inmp);
3037c478bd9Sstevel@tonic-gate 		inmp = mp1;
304769b977dSvi 	} else {
305769b977dSvi 		ASSERT(DB_CKSUMFLAGS(inmp) == 0);
3067c478bd9Sstevel@tonic-gate 	}
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	/*
3097c478bd9Sstevel@tonic-gate 	 * We follow the logic in tcp_xmit_early_reset() in that we skip
3107c478bd9Sstevel@tonic-gate 	 * reversing source route (i.e. relpace all IP options with EOL).
3117c478bd9Sstevel@tonic-gate 	 */
3127c478bd9Sstevel@tonic-gate 	if (isv4) {
3137c478bd9Sstevel@tonic-gate 		ipaddr_t	v4addr;
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 		inip4h = (ipha_t *)inmp->b_rptr;
3167c478bd9Sstevel@tonic-gate 		for (i = IP_SIMPLE_HDR_LENGTH; i < (int)ip_hdr_len; i++)
3177c478bd9Sstevel@tonic-gate 			inmp->b_rptr[i] = IPOPT_EOL;
3187c478bd9Sstevel@tonic-gate 		/* Swap addresses */
3197c478bd9Sstevel@tonic-gate 		inip4h->ipha_length = htons(ip_hdr_len + sizeof (*insctph) +
3207c478bd9Sstevel@tonic-gate 		    sizeof (*scch));
3217c478bd9Sstevel@tonic-gate 		v4addr = inip4h->ipha_src;
3227c478bd9Sstevel@tonic-gate 		inip4h->ipha_src = inip4h->ipha_dst;
3237c478bd9Sstevel@tonic-gate 		inip4h->ipha_dst = v4addr;
3247c478bd9Sstevel@tonic-gate 		inip4h->ipha_ident = 0;
325f4b3ec61Sdh 		inip4h->ipha_ttl = (uchar_t)sctps->sctps_ipv4_ttl;
3267c478bd9Sstevel@tonic-gate 	} else {
3277c478bd9Sstevel@tonic-gate 		in6_addr_t	v6addr;
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 		inip6h = (ip6_t *)inmp->b_rptr;
3307c478bd9Sstevel@tonic-gate 		/* Remove any extension headers assuming partial overlay */
3317c478bd9Sstevel@tonic-gate 		if (ip_hdr_len > IPV6_HDR_LEN) {
3327c478bd9Sstevel@tonic-gate 			uint8_t	*to;
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 			to = inmp->b_rptr + ip_hdr_len - IPV6_HDR_LEN;
3357c478bd9Sstevel@tonic-gate 			ovbcopy(inip6h, to, IPV6_HDR_LEN);
3367c478bd9Sstevel@tonic-gate 			inmp->b_rptr += ip_hdr_len - IPV6_HDR_LEN;
3377c478bd9Sstevel@tonic-gate 			ip_hdr_len = IPV6_HDR_LEN;
3387c478bd9Sstevel@tonic-gate 			inip6h = (ip6_t *)inmp->b_rptr;
3397c478bd9Sstevel@tonic-gate 			inip6h->ip6_nxt = IPPROTO_SCTP;
3407c478bd9Sstevel@tonic-gate 		}
3417c478bd9Sstevel@tonic-gate 		inip6h->ip6_plen = htons(ip_hdr_len + sizeof (*insctph) +
3427c478bd9Sstevel@tonic-gate 		    sizeof (*scch) - IPV6_HDR_LEN);
3437c478bd9Sstevel@tonic-gate 		v6addr = inip6h->ip6_src;
3447c478bd9Sstevel@tonic-gate 		inip6h->ip6_src = inip6h->ip6_dst;
3457c478bd9Sstevel@tonic-gate 		inip6h->ip6_dst = v6addr;
346f4b3ec61Sdh 		inip6h->ip6_hops = (uchar_t)sctps->sctps_ipv6_hoplimit;
3477c478bd9Sstevel@tonic-gate 	}
3487c478bd9Sstevel@tonic-gate 	insctph = (sctp_hdr_t *)(inmp->b_rptr + ip_hdr_len);
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	/* Swap ports.  Verification tag is reused. */
3517c478bd9Sstevel@tonic-gate 	port = insctph->sh_sport;
3527c478bd9Sstevel@tonic-gate 	insctph->sh_sport = insctph->sh_dport;
3537c478bd9Sstevel@tonic-gate 	insctph->sh_dport = port;
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 	/* Lay in the shutdown complete chunk */
3567c478bd9Sstevel@tonic-gate 	scch = (sctp_chunk_hdr_t *)(insctph + 1);
3577c478bd9Sstevel@tonic-gate 	scch->sch_id = CHUNK_SHUTDOWN_COMPLETE;
3587c478bd9Sstevel@tonic-gate 	scch->sch_len = htons(sizeof (*scch));
3597c478bd9Sstevel@tonic-gate 	scch->sch_flags = 0;
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 	/* Set the T-bit */
3627c478bd9Sstevel@tonic-gate 	SCTP_SET_TBIT(scch);
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(gsctp->sctp_obchunks);
3657c478bd9Sstevel@tonic-gate 	/* Nothing to stash... */
3667c478bd9Sstevel@tonic-gate 	SCTP_STASH_IPINFO(inmp, (ire_t *)NULL);
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 	sctp_add_sendq(gsctp, inmp);
3697c478bd9Sstevel@tonic-gate }
370