1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/systm.h>
31*0Sstevel@tonic-gate #include <sys/stream.h>
32*0Sstevel@tonic-gate #include <sys/ddi.h>
33*0Sstevel@tonic-gate #include <sys/sunddi.h>
34*0Sstevel@tonic-gate #include <sys/strsubr.h>
35*0Sstevel@tonic-gate #include <sys/strsun.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #include <netinet/in.h>
38*0Sstevel@tonic-gate #include <netinet/ip6.h>
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #include <inet/common.h>
41*0Sstevel@tonic-gate #include <inet/ip.h>
42*0Sstevel@tonic-gate #include <inet/ip6.h>
43*0Sstevel@tonic-gate #include <inet/mib2.h>
44*0Sstevel@tonic-gate #include <inet/nd.h>
45*0Sstevel@tonic-gate #include <inet/optcom.h>
46*0Sstevel@tonic-gate #include <inet/sctp_ip.h>
47*0Sstevel@tonic-gate #include "sctp_impl.h"
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate void
50*0Sstevel@tonic-gate sctp_send_shutdown(sctp_t *sctp, int rexmit)
51*0Sstevel@tonic-gate {
52*0Sstevel@tonic-gate 	mblk_t *smp;
53*0Sstevel@tonic-gate 	mblk_t *sendmp;
54*0Sstevel@tonic-gate 	sctp_chunk_hdr_t *sch;
55*0Sstevel@tonic-gate 	uint32_t *ctsn;
56*0Sstevel@tonic-gate 	sctp_faddr_t *fp;
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 	if (sctp->sctp_state != SCTPS_ESTABLISHED &&
59*0Sstevel@tonic-gate 	    sctp->sctp_state != SCTPS_SHUTDOWN_PENDING &&
60*0Sstevel@tonic-gate 	    sctp->sctp_state != SCTPS_SHUTDOWN_SENT) {
61*0Sstevel@tonic-gate 		return;
62*0Sstevel@tonic-gate 	}
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate 	if (sctp->sctp_state == SCTPS_ESTABLISHED) {
65*0Sstevel@tonic-gate 		sctp->sctp_state = SCTPS_SHUTDOWN_PENDING;
66*0Sstevel@tonic-gate 		/*
67*0Sstevel@tonic-gate 		 * We set an upper bound on how long we will
68*0Sstevel@tonic-gate 		 * wait for a shutdown-ack from the peer. This
69*0Sstevel@tonic-gate 		 * is to prevent the receiver from attempting
70*0Sstevel@tonic-gate 		 * to create a half-closed state indefinately.
71*0Sstevel@tonic-gate 		 * See archive from IETF TSVWG mailing list
72*0Sstevel@tonic-gate 		 * for June 2001 for more information.
73*0Sstevel@tonic-gate 		 * Since we will not be calculating RTTs after
74*0Sstevel@tonic-gate 		 * sending the shutdown, we can overload out_time
75*0Sstevel@tonic-gate 		 * to track how long we have waited.
76*0Sstevel@tonic-gate 		 */
77*0Sstevel@tonic-gate 		sctp->sctp_out_time = lbolt64;
78*0Sstevel@tonic-gate 	}
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate 	/*
81*0Sstevel@tonic-gate 	 * If there is unsent (or unacked) data, wait for it to get ack'd
82*0Sstevel@tonic-gate 	 */
83*0Sstevel@tonic-gate 	if (sctp->sctp_xmit_head != NULL || sctp->sctp_xmit_unsent != NULL) {
84*0Sstevel@tonic-gate 		return;
85*0Sstevel@tonic-gate 	}
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate 	/* rotate faddrs if we are retransmitting */
88*0Sstevel@tonic-gate 	if (!rexmit) {
89*0Sstevel@tonic-gate 		fp = sctp->sctp_current;
90*0Sstevel@tonic-gate 	} else {
91*0Sstevel@tonic-gate 		fp = sctp_rotate_faddr(sctp, sctp->sctp_shutdown_faddr);
92*0Sstevel@tonic-gate 	}
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate 	sctp->sctp_shutdown_faddr = fp;
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate 	/* Link in a SACK if resending the shutdown */
97*0Sstevel@tonic-gate 	if (sctp->sctp_state > SCTPS_SHUTDOWN_PENDING &&
98*0Sstevel@tonic-gate 	    (sendmp = sctp_make_sack(sctp, fp, NULL)) != NULL) {
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate 		smp = allocb(sizeof (*sch) + sizeof (*ctsn), BPRI_MED);
101*0Sstevel@tonic-gate 		if (smp == NULL) {
102*0Sstevel@tonic-gate 			freemsg(sendmp);
103*0Sstevel@tonic-gate 			goto done;
104*0Sstevel@tonic-gate 		}
105*0Sstevel@tonic-gate 		linkb(sendmp, smp);
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 		sch = (sctp_chunk_hdr_t *)smp->b_rptr;
108*0Sstevel@tonic-gate 		smp->b_wptr = smp->b_rptr + sizeof (*sch) + sizeof (*ctsn);
109*0Sstevel@tonic-gate 	} else {
110*0Sstevel@tonic-gate 		sendmp = sctp_make_mp(sctp, fp,
111*0Sstevel@tonic-gate 		    sizeof (*sch) + sizeof (*ctsn));
112*0Sstevel@tonic-gate 		if (sendmp == NULL) {
113*0Sstevel@tonic-gate 			goto done;
114*0Sstevel@tonic-gate 		}
115*0Sstevel@tonic-gate 		sch = (sctp_chunk_hdr_t *)sendmp->b_wptr;
116*0Sstevel@tonic-gate 		sendmp->b_wptr += sizeof (*sch) + sizeof (*ctsn);
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate 		/* shutdown w/o sack, update lastacked */
119*0Sstevel@tonic-gate 		sctp->sctp_lastacked = sctp->sctp_ftsn - 1;
120*0Sstevel@tonic-gate 	}
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate 	sch->sch_id = CHUNK_SHUTDOWN;
123*0Sstevel@tonic-gate 	sch->sch_flags = 0;
124*0Sstevel@tonic-gate 	sch->sch_len = htons(sizeof (*sch) + sizeof (*ctsn));
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 	ctsn = (uint32_t *)(sch + 1);
127*0Sstevel@tonic-gate 	*ctsn = htonl(sctp->sctp_lastacked);
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 	/* Link the shutdown chunk in after the IP/SCTP header */
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	sctp_set_iplen(sctp, sendmp);
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 	/* Send the shutdown and restart the timer */
136*0Sstevel@tonic-gate 	sctp_add_sendq(sctp, sendmp);
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate done:
139*0Sstevel@tonic-gate 	sctp->sctp_state = SCTPS_SHUTDOWN_SENT;
140*0Sstevel@tonic-gate 	SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current,
141*0Sstevel@tonic-gate 	    sctp->sctp_current->rto);
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate int
145*0Sstevel@tonic-gate sctp_shutdown_received(sctp_t *sctp, sctp_chunk_hdr_t *sch, int crwsd,
146*0Sstevel@tonic-gate     int rexmit)
147*0Sstevel@tonic-gate {
148*0Sstevel@tonic-gate 	mblk_t *samp;
149*0Sstevel@tonic-gate 	sctp_chunk_hdr_t *sach;
150*0Sstevel@tonic-gate 	uint32_t *tsn;
151*0Sstevel@tonic-gate 	int trysend = 0;
152*0Sstevel@tonic-gate 	sctp_faddr_t *fp;
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate 	if (sctp->sctp_state != SCTPS_SHUTDOWN_ACK_SENT)
155*0Sstevel@tonic-gate 		sctp->sctp_state = SCTPS_SHUTDOWN_RECEIVED;
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate 	/* Extract and process the TSN in the shutdown chunk */
158*0Sstevel@tonic-gate 	if (sch != NULL) {
159*0Sstevel@tonic-gate 		tsn = (uint32_t *)(sch + 1);
160*0Sstevel@tonic-gate 		trysend = sctp_cumack(sctp, ntohl(*tsn), &samp);
161*0Sstevel@tonic-gate 	}
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate 	/* Don't allow sending new data */
164*0Sstevel@tonic-gate 	if (!SCTP_IS_DETACHED(sctp))
165*0Sstevel@tonic-gate 		sctp->sctp_ulp_disconnecting(sctp->sctp_ulpd);
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate 	/*
168*0Sstevel@tonic-gate 	 * If there is unsent or unacked data, try sending them out now.
169*0Sstevel@tonic-gate 	 * The other side should acknowledge them.  After we have flushed
170*0Sstevel@tonic-gate 	 * the transmit queue, we can complete the shutdown sequence.
171*0Sstevel@tonic-gate 	 */
172*0Sstevel@tonic-gate 	if (sctp->sctp_xmit_head != NULL || sctp->sctp_xmit_unsent != NULL)
173*0Sstevel@tonic-gate 		return (1);
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate 	/* rotate faddrs if we are retransmitting */
176*0Sstevel@tonic-gate 	if (!rexmit)
177*0Sstevel@tonic-gate 		fp = sctp->sctp_current;
178*0Sstevel@tonic-gate 	else
179*0Sstevel@tonic-gate 		fp = sctp_rotate_faddr(sctp, sctp->sctp_shutdown_faddr);
180*0Sstevel@tonic-gate 
181*0Sstevel@tonic-gate 	samp = sctp_make_mp(sctp, fp, sizeof (*sach));
182*0Sstevel@tonic-gate 	if (samp == NULL)
183*0Sstevel@tonic-gate 		goto dotimer;
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate 	sach = (sctp_chunk_hdr_t *)samp->b_wptr;
186*0Sstevel@tonic-gate 	sach->sch_id = CHUNK_SHUTDOWN_ACK;
187*0Sstevel@tonic-gate 	sach->sch_flags = 0;
188*0Sstevel@tonic-gate 	sach->sch_len = htons(sizeof (*sach));
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate 	samp->b_wptr += sizeof (*sach);
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate 	/*
193*0Sstevel@tonic-gate 	 * bundle a "cookie received while shutting down" error if
194*0Sstevel@tonic-gate 	 * the caller asks for it.
195*0Sstevel@tonic-gate 	 */
196*0Sstevel@tonic-gate 	if (crwsd) {
197*0Sstevel@tonic-gate 		mblk_t *errmp;
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate 		errmp = sctp_make_err(sctp, SCTP_ERR_COOKIE_SHUT, NULL, 0);
200*0Sstevel@tonic-gate 		if (errmp != NULL) {
201*0Sstevel@tonic-gate 			linkb(samp, errmp);
202*0Sstevel@tonic-gate 			BUMP_LOCAL(sctp->sctp_obchunks);
203*0Sstevel@tonic-gate 		}
204*0Sstevel@tonic-gate 	}
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate 	sctp_set_iplen(sctp, samp);
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate 	sctp_add_sendq(sctp, samp);
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate dotimer:
213*0Sstevel@tonic-gate 	sctp->sctp_state = SCTPS_SHUTDOWN_ACK_SENT;
214*0Sstevel@tonic-gate 	SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current,
215*0Sstevel@tonic-gate 	    sctp->sctp_current->rto);
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate 	return (trysend);
218*0Sstevel@tonic-gate }
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate void
221*0Sstevel@tonic-gate sctp_shutdown_complete(sctp_t *sctp)
222*0Sstevel@tonic-gate {
223*0Sstevel@tonic-gate 	mblk_t *scmp;
224*0Sstevel@tonic-gate 	sctp_chunk_hdr_t *scch;
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate 	scmp = sctp_make_mp(sctp, NULL, sizeof (*scch));
227*0Sstevel@tonic-gate 	if (scmp == NULL) {
228*0Sstevel@tonic-gate 		/* XXX use timer approach */
229*0Sstevel@tonic-gate 		return;
230*0Sstevel@tonic-gate 	}
231*0Sstevel@tonic-gate 
232*0Sstevel@tonic-gate 	scch = (sctp_chunk_hdr_t *)scmp->b_wptr;
233*0Sstevel@tonic-gate 	scch->sch_id = CHUNK_SHUTDOWN_COMPLETE;
234*0Sstevel@tonic-gate 	scch->sch_flags = 0;
235*0Sstevel@tonic-gate 	scch->sch_len = htons(sizeof (*scch));
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate 	scmp->b_wptr += sizeof (*scch);
238*0Sstevel@tonic-gate 
239*0Sstevel@tonic-gate 	sctp_set_iplen(sctp, scmp);
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 	sctp_add_sendq(sctp, scmp);
244*0Sstevel@tonic-gate }
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate /*
247*0Sstevel@tonic-gate  * Similar to sctp_shutdown_complete(), except that since this
248*0Sstevel@tonic-gate  * is out-of-the-blue, we can't use an sctp's association information,
249*0Sstevel@tonic-gate  * and instead must draw all necessary info from the incoming packet.
250*0Sstevel@tonic-gate  */
251*0Sstevel@tonic-gate void
252*0Sstevel@tonic-gate sctp_ootb_shutdown_ack(sctp_t *gsctp, mblk_t *inmp, uint_t ip_hdr_len)
253*0Sstevel@tonic-gate {
254*0Sstevel@tonic-gate 	boolean_t		isv4;
255*0Sstevel@tonic-gate 	ipha_t			*inip4h;
256*0Sstevel@tonic-gate 	ip6_t			*inip6h;
257*0Sstevel@tonic-gate 	sctp_hdr_t		*insctph;
258*0Sstevel@tonic-gate 	sctp_chunk_hdr_t	*scch;
259*0Sstevel@tonic-gate 	int			i;
260*0Sstevel@tonic-gate 	uint16_t		port;
261*0Sstevel@tonic-gate 	mblk_t			*mp1;
262*0Sstevel@tonic-gate 
263*0Sstevel@tonic-gate 	isv4 = (IPH_HDR_VERSION(inmp->b_rptr) == IPV4_VERSION);
264*0Sstevel@tonic-gate 
265*0Sstevel@tonic-gate 	/*
266*0Sstevel@tonic-gate 	 * The gsctp should contain the minimal IP header.  So the
267*0Sstevel@tonic-gate 	 * incoming mblk should be able to hold the new SCTP packet.
268*0Sstevel@tonic-gate 	 */
269*0Sstevel@tonic-gate 	ASSERT(MBLKL(inmp) >= sizeof (*insctph) + sizeof (*scch) +
270*0Sstevel@tonic-gate 	    (isv4 ? gsctp->sctp_ip_hdr_len : gsctp->sctp_ip_hdr6_len));
271*0Sstevel@tonic-gate 
272*0Sstevel@tonic-gate 	/*
273*0Sstevel@tonic-gate 	 * Check to see if we can reuse the incoming mblk.  There should
274*0Sstevel@tonic-gate 	 * not be other reference.  Since this packet comes from below,
275*0Sstevel@tonic-gate 	 * there should be enough header space to fill in what the lower
276*0Sstevel@tonic-gate 	 * layers want to add.  And we will not stash anything there.
277*0Sstevel@tonic-gate 	 */
278*0Sstevel@tonic-gate 	if (DB_REF(inmp) != 1) {
279*0Sstevel@tonic-gate 		mp1 = allocb(MBLKL(inmp) + sctp_wroff_xtra, BPRI_MED);
280*0Sstevel@tonic-gate 		if (mp1 == NULL) {
281*0Sstevel@tonic-gate 			freeb(inmp);
282*0Sstevel@tonic-gate 			return;
283*0Sstevel@tonic-gate 		}
284*0Sstevel@tonic-gate 		mp1->b_rptr += sctp_wroff_xtra;
285*0Sstevel@tonic-gate 		mp1->b_wptr = mp1->b_rptr + MBLKL(inmp);
286*0Sstevel@tonic-gate 		bcopy(inmp->b_rptr, mp1->b_rptr, MBLKL(inmp));
287*0Sstevel@tonic-gate 		freeb(inmp);
288*0Sstevel@tonic-gate 		inmp = mp1;
289*0Sstevel@tonic-gate 	}
290*0Sstevel@tonic-gate 
291*0Sstevel@tonic-gate 	/*
292*0Sstevel@tonic-gate 	 * We follow the logic in tcp_xmit_early_reset() in that we skip
293*0Sstevel@tonic-gate 	 * reversing source route (i.e. relpace all IP options with EOL).
294*0Sstevel@tonic-gate 	 */
295*0Sstevel@tonic-gate 	if (isv4) {
296*0Sstevel@tonic-gate 		ipaddr_t	v4addr;
297*0Sstevel@tonic-gate 
298*0Sstevel@tonic-gate 		inip4h = (ipha_t *)inmp->b_rptr;
299*0Sstevel@tonic-gate 		for (i = IP_SIMPLE_HDR_LENGTH; i < (int)ip_hdr_len; i++)
300*0Sstevel@tonic-gate 			inmp->b_rptr[i] = IPOPT_EOL;
301*0Sstevel@tonic-gate 		/* Swap addresses */
302*0Sstevel@tonic-gate 		inip4h->ipha_length = htons(ip_hdr_len + sizeof (*insctph) +
303*0Sstevel@tonic-gate 		    sizeof (*scch));
304*0Sstevel@tonic-gate 		v4addr = inip4h->ipha_src;
305*0Sstevel@tonic-gate 		inip4h->ipha_src = inip4h->ipha_dst;
306*0Sstevel@tonic-gate 		inip4h->ipha_dst = v4addr;
307*0Sstevel@tonic-gate 		inip4h->ipha_ident = 0;
308*0Sstevel@tonic-gate 		inip4h->ipha_ttl = (uchar_t)sctp_ipv4_ttl;
309*0Sstevel@tonic-gate 	} else {
310*0Sstevel@tonic-gate 		in6_addr_t	v6addr;
311*0Sstevel@tonic-gate 
312*0Sstevel@tonic-gate 		inip6h = (ip6_t *)inmp->b_rptr;
313*0Sstevel@tonic-gate 		/* Remove any extension headers assuming partial overlay */
314*0Sstevel@tonic-gate 		if (ip_hdr_len > IPV6_HDR_LEN) {
315*0Sstevel@tonic-gate 			uint8_t	*to;
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate 			to = inmp->b_rptr + ip_hdr_len - IPV6_HDR_LEN;
318*0Sstevel@tonic-gate 			ovbcopy(inip6h, to, IPV6_HDR_LEN);
319*0Sstevel@tonic-gate 			inmp->b_rptr += ip_hdr_len - IPV6_HDR_LEN;
320*0Sstevel@tonic-gate 			ip_hdr_len = IPV6_HDR_LEN;
321*0Sstevel@tonic-gate 			inip6h = (ip6_t *)inmp->b_rptr;
322*0Sstevel@tonic-gate 			inip6h->ip6_nxt = IPPROTO_SCTP;
323*0Sstevel@tonic-gate 		}
324*0Sstevel@tonic-gate 		inip6h->ip6_plen = htons(ip_hdr_len + sizeof (*insctph) +
325*0Sstevel@tonic-gate 		    sizeof (*scch) - IPV6_HDR_LEN);
326*0Sstevel@tonic-gate 		v6addr = inip6h->ip6_src;
327*0Sstevel@tonic-gate 		inip6h->ip6_src = inip6h->ip6_dst;
328*0Sstevel@tonic-gate 		inip6h->ip6_dst = v6addr;
329*0Sstevel@tonic-gate 		inip6h->ip6_hops = (uchar_t)sctp_ipv6_hoplimit;
330*0Sstevel@tonic-gate 	}
331*0Sstevel@tonic-gate 	insctph = (sctp_hdr_t *)(inmp->b_rptr + ip_hdr_len);
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate 	/* Swap ports.  Verification tag is reused. */
334*0Sstevel@tonic-gate 	port = insctph->sh_sport;
335*0Sstevel@tonic-gate 	insctph->sh_sport = insctph->sh_dport;
336*0Sstevel@tonic-gate 	insctph->sh_dport = port;
337*0Sstevel@tonic-gate 
338*0Sstevel@tonic-gate 	/* Lay in the shutdown complete chunk */
339*0Sstevel@tonic-gate 	scch = (sctp_chunk_hdr_t *)(insctph + 1);
340*0Sstevel@tonic-gate 	scch->sch_id = CHUNK_SHUTDOWN_COMPLETE;
341*0Sstevel@tonic-gate 	scch->sch_len = htons(sizeof (*scch));
342*0Sstevel@tonic-gate 	scch->sch_flags = 0;
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate 	/* Set the T-bit */
345*0Sstevel@tonic-gate 	SCTP_SET_TBIT(scch);
346*0Sstevel@tonic-gate 
347*0Sstevel@tonic-gate 	BUMP_LOCAL(gsctp->sctp_obchunks);
348*0Sstevel@tonic-gate 	/* Nothing to stash... */
349*0Sstevel@tonic-gate 	SCTP_STASH_IPINFO(inmp, (ire_t *)NULL);
350*0Sstevel@tonic-gate 
351*0Sstevel@tonic-gate 	sctp_add_sendq(gsctp, inmp);
352*0Sstevel@tonic-gate }
353