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
5*77c67f2fSkcpoon  * Common Development and Distribution License (the "License").
6*77c67f2fSkcpoon  * 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  */
21*77c67f2fSkcpoon 
227c478bd9Sstevel@tonic-gate /*
23*77c67f2fSkcpoon  * Copyright 2006 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>
477c478bd9Sstevel@tonic-gate #include "sctp_impl.h"
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate void
507c478bd9Sstevel@tonic-gate sctp_send_shutdown(sctp_t *sctp, int rexmit)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	mblk_t *smp;
537c478bd9Sstevel@tonic-gate 	mblk_t *sendmp;
547c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t *sch;
557c478bd9Sstevel@tonic-gate 	uint32_t *ctsn;
567c478bd9Sstevel@tonic-gate 	sctp_faddr_t *fp;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	if (sctp->sctp_state != SCTPS_ESTABLISHED &&
597c478bd9Sstevel@tonic-gate 	    sctp->sctp_state != SCTPS_SHUTDOWN_PENDING &&
607c478bd9Sstevel@tonic-gate 	    sctp->sctp_state != SCTPS_SHUTDOWN_SENT) {
617c478bd9Sstevel@tonic-gate 		return;
627c478bd9Sstevel@tonic-gate 	}
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	if (sctp->sctp_state == SCTPS_ESTABLISHED) {
657c478bd9Sstevel@tonic-gate 		sctp->sctp_state = SCTPS_SHUTDOWN_PENDING;
667c478bd9Sstevel@tonic-gate 		/*
677c478bd9Sstevel@tonic-gate 		 * We set an upper bound on how long we will
687c478bd9Sstevel@tonic-gate 		 * wait for a shutdown-ack from the peer. This
697c478bd9Sstevel@tonic-gate 		 * is to prevent the receiver from attempting
707c478bd9Sstevel@tonic-gate 		 * to create a half-closed state indefinately.
717c478bd9Sstevel@tonic-gate 		 * See archive from IETF TSVWG mailing list
727c478bd9Sstevel@tonic-gate 		 * for June 2001 for more information.
737c478bd9Sstevel@tonic-gate 		 * Since we will not be calculating RTTs after
747c478bd9Sstevel@tonic-gate 		 * sending the shutdown, we can overload out_time
757c478bd9Sstevel@tonic-gate 		 * to track how long we have waited.
767c478bd9Sstevel@tonic-gate 		 */
777c478bd9Sstevel@tonic-gate 		sctp->sctp_out_time = lbolt64;
787c478bd9Sstevel@tonic-gate 	}
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	/*
817c478bd9Sstevel@tonic-gate 	 * If there is unsent (or unacked) data, wait for it to get ack'd
827c478bd9Sstevel@tonic-gate 	 */
837c478bd9Sstevel@tonic-gate 	if (sctp->sctp_xmit_head != NULL || sctp->sctp_xmit_unsent != NULL) {
847c478bd9Sstevel@tonic-gate 		return;
857c478bd9Sstevel@tonic-gate 	}
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	/* rotate faddrs if we are retransmitting */
887c478bd9Sstevel@tonic-gate 	if (!rexmit) {
897c478bd9Sstevel@tonic-gate 		fp = sctp->sctp_current;
907c478bd9Sstevel@tonic-gate 	} else {
917c478bd9Sstevel@tonic-gate 		fp = sctp_rotate_faddr(sctp, sctp->sctp_shutdown_faddr);
927c478bd9Sstevel@tonic-gate 	}
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	sctp->sctp_shutdown_faddr = fp;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	/* Link in a SACK if resending the shutdown */
977c478bd9Sstevel@tonic-gate 	if (sctp->sctp_state > SCTPS_SHUTDOWN_PENDING &&
987c478bd9Sstevel@tonic-gate 	    (sendmp = sctp_make_sack(sctp, fp, NULL)) != NULL) {
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 		smp = allocb(sizeof (*sch) + sizeof (*ctsn), BPRI_MED);
1017c478bd9Sstevel@tonic-gate 		if (smp == NULL) {
1027c478bd9Sstevel@tonic-gate 			freemsg(sendmp);
1037c478bd9Sstevel@tonic-gate 			goto done;
1047c478bd9Sstevel@tonic-gate 		}
1057c478bd9Sstevel@tonic-gate 		linkb(sendmp, smp);
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 		sch = (sctp_chunk_hdr_t *)smp->b_rptr;
1087c478bd9Sstevel@tonic-gate 		smp->b_wptr = smp->b_rptr + sizeof (*sch) + sizeof (*ctsn);
1097c478bd9Sstevel@tonic-gate 	} else {
1107c478bd9Sstevel@tonic-gate 		sendmp = sctp_make_mp(sctp, fp,
1117c478bd9Sstevel@tonic-gate 		    sizeof (*sch) + sizeof (*ctsn));
1127c478bd9Sstevel@tonic-gate 		if (sendmp == NULL) {
113*77c67f2fSkcpoon 			SCTP_KSTAT(sctp_send_shutdown_failed);
1147c478bd9Sstevel@tonic-gate 			goto done;
1157c478bd9Sstevel@tonic-gate 		}
1167c478bd9Sstevel@tonic-gate 		sch = (sctp_chunk_hdr_t *)sendmp->b_wptr;
1177c478bd9Sstevel@tonic-gate 		sendmp->b_wptr += sizeof (*sch) + sizeof (*ctsn);
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 		/* shutdown w/o sack, update lastacked */
1207c478bd9Sstevel@tonic-gate 		sctp->sctp_lastacked = sctp->sctp_ftsn - 1;
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	sch->sch_id = CHUNK_SHUTDOWN;
1247c478bd9Sstevel@tonic-gate 	sch->sch_flags = 0;
1257c478bd9Sstevel@tonic-gate 	sch->sch_len = htons(sizeof (*sch) + sizeof (*ctsn));
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	ctsn = (uint32_t *)(sch + 1);
1287c478bd9Sstevel@tonic-gate 	*ctsn = htonl(sctp->sctp_lastacked);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/* Link the shutdown chunk in after the IP/SCTP header */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	sctp_set_iplen(sctp, sendmp);
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	/* Send the shutdown and restart the timer */
1377c478bd9Sstevel@tonic-gate 	sctp_add_sendq(sctp, sendmp);
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate done:
1407c478bd9Sstevel@tonic-gate 	sctp->sctp_state = SCTPS_SHUTDOWN_SENT;
1417c478bd9Sstevel@tonic-gate 	SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current,
1427c478bd9Sstevel@tonic-gate 	    sctp->sctp_current->rto);
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate int
146*77c67f2fSkcpoon sctp_shutdown_received(sctp_t *sctp, sctp_chunk_hdr_t *sch, boolean_t crwsd,
147*77c67f2fSkcpoon     boolean_t rexmit, sctp_faddr_t *fp)
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate 	mblk_t *samp;
1507c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t *sach;
1517c478bd9Sstevel@tonic-gate 	uint32_t *tsn;
1527c478bd9Sstevel@tonic-gate 	int trysend = 0;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	if (sctp->sctp_state != SCTPS_SHUTDOWN_ACK_SENT)
1557c478bd9Sstevel@tonic-gate 		sctp->sctp_state = SCTPS_SHUTDOWN_RECEIVED;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	/* Extract and process the TSN in the shutdown chunk */
1587c478bd9Sstevel@tonic-gate 	if (sch != NULL) {
1597c478bd9Sstevel@tonic-gate 		tsn = (uint32_t *)(sch + 1);
1607c478bd9Sstevel@tonic-gate 		trysend = sctp_cumack(sctp, ntohl(*tsn), &samp);
1617c478bd9Sstevel@tonic-gate 	}
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	/* Don't allow sending new data */
1647c478bd9Sstevel@tonic-gate 	if (!SCTP_IS_DETACHED(sctp))
1657c478bd9Sstevel@tonic-gate 		sctp->sctp_ulp_disconnecting(sctp->sctp_ulpd);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	/*
1687c478bd9Sstevel@tonic-gate 	 * If there is unsent or unacked data, try sending them out now.
1697c478bd9Sstevel@tonic-gate 	 * The other side should acknowledge them.  After we have flushed
1707c478bd9Sstevel@tonic-gate 	 * the transmit queue, we can complete the shutdown sequence.
1717c478bd9Sstevel@tonic-gate 	 */
1727c478bd9Sstevel@tonic-gate 	if (sctp->sctp_xmit_head != NULL || sctp->sctp_xmit_unsent != NULL)
1737c478bd9Sstevel@tonic-gate 		return (1);
1747c478bd9Sstevel@tonic-gate 
175*77c67f2fSkcpoon 	if (fp == NULL) {
1767c478bd9Sstevel@tonic-gate 		/* rotate faddrs if we are retransmitting */
1777c478bd9Sstevel@tonic-gate 		if (!rexmit)
1787c478bd9Sstevel@tonic-gate 			fp = sctp->sctp_current;
1797c478bd9Sstevel@tonic-gate 		else
1807c478bd9Sstevel@tonic-gate 			fp = sctp_rotate_faddr(sctp, sctp->sctp_shutdown_faddr);
181*77c67f2fSkcpoon 	}
182*77c67f2fSkcpoon 	sctp->sctp_shutdown_faddr = fp;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	samp = sctp_make_mp(sctp, fp, sizeof (*sach));
185*77c67f2fSkcpoon 	if (samp == NULL) {
186*77c67f2fSkcpoon 		SCTP_KSTAT(sctp_send_shutdown_ack_failed);
1877c478bd9Sstevel@tonic-gate 		goto dotimer;
188*77c67f2fSkcpoon 	}
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	sach = (sctp_chunk_hdr_t *)samp->b_wptr;
1917c478bd9Sstevel@tonic-gate 	sach->sch_id = CHUNK_SHUTDOWN_ACK;
1927c478bd9Sstevel@tonic-gate 	sach->sch_flags = 0;
1937c478bd9Sstevel@tonic-gate 	sach->sch_len = htons(sizeof (*sach));
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	samp->b_wptr += sizeof (*sach);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	/*
1987c478bd9Sstevel@tonic-gate 	 * bundle a "cookie received while shutting down" error if
1997c478bd9Sstevel@tonic-gate 	 * the caller asks for it.
2007c478bd9Sstevel@tonic-gate 	 */
2017c478bd9Sstevel@tonic-gate 	if (crwsd) {
2027c478bd9Sstevel@tonic-gate 		mblk_t *errmp;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 		errmp = sctp_make_err(sctp, SCTP_ERR_COOKIE_SHUT, NULL, 0);
2057c478bd9Sstevel@tonic-gate 		if (errmp != NULL) {
2067c478bd9Sstevel@tonic-gate 			linkb(samp, errmp);
2077c478bd9Sstevel@tonic-gate 			BUMP_LOCAL(sctp->sctp_obchunks);
2087c478bd9Sstevel@tonic-gate 		}
2097c478bd9Sstevel@tonic-gate 	}
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	sctp_set_iplen(sctp, samp);
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	sctp_add_sendq(sctp, samp);
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate dotimer:
2187c478bd9Sstevel@tonic-gate 	sctp->sctp_state = SCTPS_SHUTDOWN_ACK_SENT;
2197c478bd9Sstevel@tonic-gate 	SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current,
2207c478bd9Sstevel@tonic-gate 	    sctp->sctp_current->rto);
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	return (trysend);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate void
2267c478bd9Sstevel@tonic-gate sctp_shutdown_complete(sctp_t *sctp)
2277c478bd9Sstevel@tonic-gate {
2287c478bd9Sstevel@tonic-gate 	mblk_t *scmp;
2297c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t *scch;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	scmp = sctp_make_mp(sctp, NULL, sizeof (*scch));
2327c478bd9Sstevel@tonic-gate 	if (scmp == NULL) {
2337c478bd9Sstevel@tonic-gate 		/* XXX use timer approach */
234*77c67f2fSkcpoon 		SCTP_KSTAT(sctp_send_shutdown_comp_failed);
2357c478bd9Sstevel@tonic-gate 		return;
2367c478bd9Sstevel@tonic-gate 	}
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	scch = (sctp_chunk_hdr_t *)scmp->b_wptr;
2397c478bd9Sstevel@tonic-gate 	scch->sch_id = CHUNK_SHUTDOWN_COMPLETE;
2407c478bd9Sstevel@tonic-gate 	scch->sch_flags = 0;
2417c478bd9Sstevel@tonic-gate 	scch->sch_len = htons(sizeof (*scch));
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	scmp->b_wptr += sizeof (*scch);
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	sctp_set_iplen(sctp, scmp);
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	sctp_add_sendq(sctp, scmp);
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * Similar to sctp_shutdown_complete(), except that since this
2547c478bd9Sstevel@tonic-gate  * is out-of-the-blue, we can't use an sctp's association information,
2557c478bd9Sstevel@tonic-gate  * and instead must draw all necessary info from the incoming packet.
2567c478bd9Sstevel@tonic-gate  */
2577c478bd9Sstevel@tonic-gate void
2587c478bd9Sstevel@tonic-gate sctp_ootb_shutdown_ack(sctp_t *gsctp, mblk_t *inmp, uint_t ip_hdr_len)
2597c478bd9Sstevel@tonic-gate {
2607c478bd9Sstevel@tonic-gate 	boolean_t		isv4;
2617c478bd9Sstevel@tonic-gate 	ipha_t			*inip4h;
2627c478bd9Sstevel@tonic-gate 	ip6_t			*inip6h;
2637c478bd9Sstevel@tonic-gate 	sctp_hdr_t		*insctph;
2647c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t	*scch;
2657c478bd9Sstevel@tonic-gate 	int			i;
2667c478bd9Sstevel@tonic-gate 	uint16_t		port;
2677c478bd9Sstevel@tonic-gate 	mblk_t			*mp1;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	isv4 = (IPH_HDR_VERSION(inmp->b_rptr) == IPV4_VERSION);
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	/*
2727c478bd9Sstevel@tonic-gate 	 * The gsctp should contain the minimal IP header.  So the
2737c478bd9Sstevel@tonic-gate 	 * incoming mblk should be able to hold the new SCTP packet.
2747c478bd9Sstevel@tonic-gate 	 */
2757c478bd9Sstevel@tonic-gate 	ASSERT(MBLKL(inmp) >= sizeof (*insctph) + sizeof (*scch) +
2767c478bd9Sstevel@tonic-gate 	    (isv4 ? gsctp->sctp_ip_hdr_len : gsctp->sctp_ip_hdr6_len));
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	/*
2797c478bd9Sstevel@tonic-gate 	 * Check to see if we can reuse the incoming mblk.  There should
280*77c67f2fSkcpoon 	 * not be other reference and the db_base of the mblk should be
281*77c67f2fSkcpoon 	 * properly aligned.  Since this packet comes from below,
2827c478bd9Sstevel@tonic-gate 	 * there should be enough header space to fill in what the lower
2837c478bd9Sstevel@tonic-gate 	 * layers want to add.  And we will not stash anything there.
2847c478bd9Sstevel@tonic-gate 	 */
285*77c67f2fSkcpoon 	if (!IS_P2ALIGNED(DB_BASE(inmp), sizeof (ire_t *)) ||
286*77c67f2fSkcpoon 	    DB_REF(inmp) != 1) {
2877c478bd9Sstevel@tonic-gate 		mp1 = allocb(MBLKL(inmp) + sctp_wroff_xtra, BPRI_MED);
2887c478bd9Sstevel@tonic-gate 		if (mp1 == NULL) {
2897c478bd9Sstevel@tonic-gate 			freeb(inmp);
2907c478bd9Sstevel@tonic-gate 			return;
2917c478bd9Sstevel@tonic-gate 		}
2927c478bd9Sstevel@tonic-gate 		mp1->b_rptr += sctp_wroff_xtra;
2937c478bd9Sstevel@tonic-gate 		mp1->b_wptr = mp1->b_rptr + MBLKL(inmp);
2947c478bd9Sstevel@tonic-gate 		bcopy(inmp->b_rptr, mp1->b_rptr, MBLKL(inmp));
2957c478bd9Sstevel@tonic-gate 		freeb(inmp);
2967c478bd9Sstevel@tonic-gate 		inmp = mp1;
2977c478bd9Sstevel@tonic-gate 	}
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	/*
3007c478bd9Sstevel@tonic-gate 	 * We follow the logic in tcp_xmit_early_reset() in that we skip
3017c478bd9Sstevel@tonic-gate 	 * reversing source route (i.e. relpace all IP options with EOL).
3027c478bd9Sstevel@tonic-gate 	 */
3037c478bd9Sstevel@tonic-gate 	if (isv4) {
3047c478bd9Sstevel@tonic-gate 		ipaddr_t	v4addr;
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 		inip4h = (ipha_t *)inmp->b_rptr;
3077c478bd9Sstevel@tonic-gate 		for (i = IP_SIMPLE_HDR_LENGTH; i < (int)ip_hdr_len; i++)
3087c478bd9Sstevel@tonic-gate 			inmp->b_rptr[i] = IPOPT_EOL;
3097c478bd9Sstevel@tonic-gate 		/* Swap addresses */
3107c478bd9Sstevel@tonic-gate 		inip4h->ipha_length = htons(ip_hdr_len + sizeof (*insctph) +
3117c478bd9Sstevel@tonic-gate 		    sizeof (*scch));
3127c478bd9Sstevel@tonic-gate 		v4addr = inip4h->ipha_src;
3137c478bd9Sstevel@tonic-gate 		inip4h->ipha_src = inip4h->ipha_dst;
3147c478bd9Sstevel@tonic-gate 		inip4h->ipha_dst = v4addr;
3157c478bd9Sstevel@tonic-gate 		inip4h->ipha_ident = 0;
3167c478bd9Sstevel@tonic-gate 		inip4h->ipha_ttl = (uchar_t)sctp_ipv4_ttl;
3177c478bd9Sstevel@tonic-gate 	} else {
3187c478bd9Sstevel@tonic-gate 		in6_addr_t	v6addr;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 		inip6h = (ip6_t *)inmp->b_rptr;
3217c478bd9Sstevel@tonic-gate 		/* Remove any extension headers assuming partial overlay */
3227c478bd9Sstevel@tonic-gate 		if (ip_hdr_len > IPV6_HDR_LEN) {
3237c478bd9Sstevel@tonic-gate 			uint8_t	*to;
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 			to = inmp->b_rptr + ip_hdr_len - IPV6_HDR_LEN;
3267c478bd9Sstevel@tonic-gate 			ovbcopy(inip6h, to, IPV6_HDR_LEN);
3277c478bd9Sstevel@tonic-gate 			inmp->b_rptr += ip_hdr_len - IPV6_HDR_LEN;
3287c478bd9Sstevel@tonic-gate 			ip_hdr_len = IPV6_HDR_LEN;
3297c478bd9Sstevel@tonic-gate 			inip6h = (ip6_t *)inmp->b_rptr;
3307c478bd9Sstevel@tonic-gate 			inip6h->ip6_nxt = IPPROTO_SCTP;
3317c478bd9Sstevel@tonic-gate 		}
3327c478bd9Sstevel@tonic-gate 		inip6h->ip6_plen = htons(ip_hdr_len + sizeof (*insctph) +
3337c478bd9Sstevel@tonic-gate 		    sizeof (*scch) - IPV6_HDR_LEN);
3347c478bd9Sstevel@tonic-gate 		v6addr = inip6h->ip6_src;
3357c478bd9Sstevel@tonic-gate 		inip6h->ip6_src = inip6h->ip6_dst;
3367c478bd9Sstevel@tonic-gate 		inip6h->ip6_dst = v6addr;
3377c478bd9Sstevel@tonic-gate 		inip6h->ip6_hops = (uchar_t)sctp_ipv6_hoplimit;
3387c478bd9Sstevel@tonic-gate 	}
3397c478bd9Sstevel@tonic-gate 	insctph = (sctp_hdr_t *)(inmp->b_rptr + ip_hdr_len);
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	/* Swap ports.  Verification tag is reused. */
3427c478bd9Sstevel@tonic-gate 	port = insctph->sh_sport;
3437c478bd9Sstevel@tonic-gate 	insctph->sh_sport = insctph->sh_dport;
3447c478bd9Sstevel@tonic-gate 	insctph->sh_dport = port;
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 	/* Lay in the shutdown complete chunk */
3477c478bd9Sstevel@tonic-gate 	scch = (sctp_chunk_hdr_t *)(insctph + 1);
3487c478bd9Sstevel@tonic-gate 	scch->sch_id = CHUNK_SHUTDOWN_COMPLETE;
3497c478bd9Sstevel@tonic-gate 	scch->sch_len = htons(sizeof (*scch));
3507c478bd9Sstevel@tonic-gate 	scch->sch_flags = 0;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	/* Set the T-bit */
3537c478bd9Sstevel@tonic-gate 	SCTP_SET_TBIT(scch);
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(gsctp->sctp_obchunks);
3567c478bd9Sstevel@tonic-gate 	/* Nothing to stash... */
3577c478bd9Sstevel@tonic-gate 	SCTP_STASH_IPINFO(inmp, (ire_t *)NULL);
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	sctp_add_sendq(gsctp, inmp);
3607c478bd9Sstevel@tonic-gate }
361