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 2005 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/cmn_err.h>
33*0Sstevel@tonic-gate #include <sys/tihdr.h>
34*0Sstevel@tonic-gate #include <sys/kmem.h>
35*0Sstevel@tonic-gate #define	_SUN_TPI_VERSION 2
36*0Sstevel@tonic-gate #include <sys/tihdr.h>
37*0Sstevel@tonic-gate #include <sys/socket.h>
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #include <netinet/in.h>
40*0Sstevel@tonic-gate #include <netinet/sctp.h>
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate #include <inet/common.h>
43*0Sstevel@tonic-gate #include <inet/ip.h>
44*0Sstevel@tonic-gate #include "sctp_impl.h"
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate static void
47*0Sstevel@tonic-gate sctp_notify(sctp_t *sctp, mblk_t *emp, size_t len)
48*0Sstevel@tonic-gate {
49*0Sstevel@tonic-gate 	struct T_unitdata_ind *tudi;
50*0Sstevel@tonic-gate 	mblk_t *mp;
51*0Sstevel@tonic-gate 	sctp_faddr_t *fp;
52*0Sstevel@tonic-gate 	int32_t rwnd = 0;
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate 	if ((mp = allocb(sizeof (*tudi) + sizeof (void *) +
55*0Sstevel@tonic-gate 		sizeof (struct sockaddr_in6), BPRI_HI)) == NULL) {
56*0Sstevel@tonic-gate 		/* XXX trouble: don't want to drop events. should queue it. */
57*0Sstevel@tonic-gate 		freemsg(emp);
58*0Sstevel@tonic-gate 		return;
59*0Sstevel@tonic-gate 	}
60*0Sstevel@tonic-gate 	dprint(3, ("sctp_notify: event %d\n", (*(uint16_t *)emp->b_rptr)));
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate 	mp->b_datap->db_type = M_PROTO;
63*0Sstevel@tonic-gate 	mp->b_flag |= MSGMARK;
64*0Sstevel@tonic-gate 	mp->b_rptr += sizeof (void *); /* pointer worth of padding */
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate 	tudi = (struct T_unitdata_ind *)mp->b_rptr;
67*0Sstevel@tonic-gate 	tudi->PRIM_type = T_UNITDATA_IND;
68*0Sstevel@tonic-gate 	tudi->SRC_offset = sizeof (*tudi);
69*0Sstevel@tonic-gate 	tudi->OPT_length = 0;
70*0Sstevel@tonic-gate 	tudi->OPT_offset = 0;
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate 	fp = sctp->sctp_primary;
73*0Sstevel@tonic-gate 	ASSERT(fp);
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate 	/*
76*0Sstevel@tonic-gate 	 * Fill in primary remote address.
77*0Sstevel@tonic-gate 	 */
78*0Sstevel@tonic-gate 	if (IN6_IS_ADDR_V4MAPPED(&fp->faddr)) {
79*0Sstevel@tonic-gate 		struct sockaddr_in *sin4;
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate 		tudi->SRC_length = sizeof (*sin4);
82*0Sstevel@tonic-gate 		sin4 = (struct sockaddr_in *)(tudi + 1);
83*0Sstevel@tonic-gate 		sin4->sin_family = AF_INET;
84*0Sstevel@tonic-gate 		sin4->sin_port = sctp->sctp_fport;
85*0Sstevel@tonic-gate 		IN6_V4MAPPED_TO_IPADDR(&fp->faddr, sin4->sin_addr.s_addr);
86*0Sstevel@tonic-gate 		mp->b_wptr = (uchar_t *)(sin4 + 1);
87*0Sstevel@tonic-gate 	} else {
88*0Sstevel@tonic-gate 		struct sockaddr_in6 *sin6;
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 		tudi->SRC_length = sizeof (*sin6);
91*0Sstevel@tonic-gate 		sin6 = (struct sockaddr_in6 *)(tudi + 1);
92*0Sstevel@tonic-gate 		sin6->sin6_family = AF_INET6;
93*0Sstevel@tonic-gate 		sin6->sin6_port = sctp->sctp_fport;
94*0Sstevel@tonic-gate 		sin6->sin6_addr = fp->faddr;
95*0Sstevel@tonic-gate 		mp->b_wptr = (uchar_t *)(sin6 + 1);
96*0Sstevel@tonic-gate 	}
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate 	mp->b_cont = emp;
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate 	/*
101*0Sstevel@tonic-gate 	 * Notifications are queued regardless of socket rx space.  So
102*0Sstevel@tonic-gate 	 * we do not decrement sctp_rwnd here as this will confuse the
103*0Sstevel@tonic-gate 	 * other side.
104*0Sstevel@tonic-gate 	 */
105*0Sstevel@tonic-gate #ifdef DEBUG
106*0Sstevel@tonic-gate 	for (emp = mp->b_cont; emp; emp = emp->b_cont) {
107*0Sstevel@tonic-gate 		rwnd += emp->b_wptr - emp->b_rptr;
108*0Sstevel@tonic-gate 	}
109*0Sstevel@tonic-gate 	ASSERT(len == rwnd);
110*0Sstevel@tonic-gate #endif
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate 	rwnd = sctp->sctp_ulp_recv(sctp->sctp_ulpd, mp, SCTP_NOTIFICATION);
113*0Sstevel@tonic-gate 	if (rwnd > sctp->sctp_rwnd) {
114*0Sstevel@tonic-gate 		sctp->sctp_rwnd = rwnd;
115*0Sstevel@tonic-gate 	}
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate void
119*0Sstevel@tonic-gate sctp_assoc_event(sctp_t *sctp, uint16_t state, uint16_t error,
120*0Sstevel@tonic-gate     sctp_chunk_hdr_t *ch)
121*0Sstevel@tonic-gate {
122*0Sstevel@tonic-gate 	struct sctp_assoc_change *sacp;
123*0Sstevel@tonic-gate 	mblk_t *mp;
124*0Sstevel@tonic-gate 	uint16_t ch_len;
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 	if (!sctp->sctp_recvassocevnt) {
127*0Sstevel@tonic-gate 		return;
128*0Sstevel@tonic-gate 	}
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate 	ch_len = (ch != NULL) ? ntohs(ch->sch_len) : 0;
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 	if ((mp = allocb(sizeof (*sacp) + ch_len, BPRI_MED)) == NULL) {
133*0Sstevel@tonic-gate 		return;
134*0Sstevel@tonic-gate 	}
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate 	sacp = (struct sctp_assoc_change *)mp->b_rptr;
137*0Sstevel@tonic-gate 	sacp->sac_type = SCTP_ASSOC_CHANGE;
138*0Sstevel@tonic-gate 	sacp->sac_flags = sctp->sctp_prsctp_aware ? SCTP_PRSCTP_CAPABLE : 0;
139*0Sstevel@tonic-gate 	sacp->sac_length = sizeof (*sacp) + ch_len;
140*0Sstevel@tonic-gate 	sacp->sac_state = state;
141*0Sstevel@tonic-gate 	sacp->sac_error = error;
142*0Sstevel@tonic-gate 	sacp->sac_outbound_streams = sctp->sctp_num_ostr;
143*0Sstevel@tonic-gate 	sacp->sac_inbound_streams = sctp->sctp_num_istr;
144*0Sstevel@tonic-gate 	sacp->sac_assoc_id = 0;
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate 	if (ch != NULL)
147*0Sstevel@tonic-gate 		bcopy(ch, sacp + 1, ch_len);
148*0Sstevel@tonic-gate 	mp->b_wptr += sacp->sac_length;
149*0Sstevel@tonic-gate 	sctp_notify(sctp, mp, sacp->sac_length);
150*0Sstevel@tonic-gate }
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate /*
153*0Sstevel@tonic-gate  * Send failure event. Message is expected to have message header still
154*0Sstevel@tonic-gate  * in place, data follows in subsequent mblk's.
155*0Sstevel@tonic-gate  */
156*0Sstevel@tonic-gate static void
157*0Sstevel@tonic-gate sctp_sendfail(sctp_t *sctp, mblk_t *msghdr, uint16_t flags, int error)
158*0Sstevel@tonic-gate {
159*0Sstevel@tonic-gate 	struct sctp_send_failed *sfp;
160*0Sstevel@tonic-gate 	mblk_t *mp;
161*0Sstevel@tonic-gate 	sctp_msg_hdr_t *smh;
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate 	/* Allocate a mblk for the notification header */
164*0Sstevel@tonic-gate 	if ((mp = allocb(sizeof (*sfp), BPRI_MED)) == NULL) {
165*0Sstevel@tonic-gate 		/* give up */
166*0Sstevel@tonic-gate 		freemsg(msghdr);
167*0Sstevel@tonic-gate 		return;
168*0Sstevel@tonic-gate 	}
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate 	smh = (sctp_msg_hdr_t *)msghdr->b_rptr;
171*0Sstevel@tonic-gate 	sfp = (struct sctp_send_failed *)mp->b_rptr;
172*0Sstevel@tonic-gate 	sfp->ssf_type = SCTP_SEND_FAILED;
173*0Sstevel@tonic-gate 	sfp->ssf_flags = flags;
174*0Sstevel@tonic-gate 	sfp->ssf_length = smh->smh_msglen + sizeof (*sfp);
175*0Sstevel@tonic-gate 	sfp->ssf_error = error;
176*0Sstevel@tonic-gate 	sfp->ssf_assoc_id = 0;
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate 	bzero(&sfp->ssf_info, sizeof (sfp->ssf_info));
179*0Sstevel@tonic-gate 	sfp->ssf_info.sinfo_stream = smh->smh_sid;
180*0Sstevel@tonic-gate 	sfp->ssf_info.sinfo_flags = smh->smh_flags;
181*0Sstevel@tonic-gate 	sfp->ssf_info.sinfo_ppid = smh->smh_ppid;
182*0Sstevel@tonic-gate 	sfp->ssf_info.sinfo_context = smh->smh_context;
183*0Sstevel@tonic-gate 	sfp->ssf_info.sinfo_timetolive = TICK_TO_MSEC(smh->smh_ttl);
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate 	mp->b_wptr = (uchar_t *)(sfp + 1);
186*0Sstevel@tonic-gate 	mp->b_cont = msghdr->b_cont;
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate 	freeb(msghdr);
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate 	sctp_notify(sctp, mp, sfp->ssf_length);
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate }
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate /*
195*0Sstevel@tonic-gate  * Send failure when the message has been fully chunkified.
196*0Sstevel@tonic-gate  */
197*0Sstevel@tonic-gate static void
198*0Sstevel@tonic-gate sctp_sendfail_sent(sctp_t *sctp, mblk_t *meta, int error)
199*0Sstevel@tonic-gate {
200*0Sstevel@tonic-gate 	mblk_t		*mp;
201*0Sstevel@tonic-gate 	mblk_t		*nmp;
202*0Sstevel@tonic-gate 	mblk_t		*tail;
203*0Sstevel@tonic-gate 	uint16_t	flags = SCTP_DATA_SENT;
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate 	if (!sctp->sctp_recvsendfailevnt) {
206*0Sstevel@tonic-gate 		sctp_free_msg(meta);
207*0Sstevel@tonic-gate 		return;
208*0Sstevel@tonic-gate 	}
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate 	/*
211*0Sstevel@tonic-gate 	 * We need to remove all data_hdr's.
212*0Sstevel@tonic-gate 	 */
213*0Sstevel@tonic-gate 	nmp = meta->b_cont;
214*0Sstevel@tonic-gate 	tail = meta;
215*0Sstevel@tonic-gate 	do {
216*0Sstevel@tonic-gate 		mp = nmp->b_next;
217*0Sstevel@tonic-gate 		nmp->b_next = NULL;
218*0Sstevel@tonic-gate 
219*0Sstevel@tonic-gate 		/*
220*0Sstevel@tonic-gate 		 * If one of the chunks hasn't been sent yet, say that
221*0Sstevel@tonic-gate 		 * the message hasn't been sent.
222*0Sstevel@tonic-gate 		 */
223*0Sstevel@tonic-gate 		if (!SCTP_CHUNK_ISSENT(nmp)) {
224*0Sstevel@tonic-gate 			flags = SCTP_DATA_UNSENT;
225*0Sstevel@tonic-gate 		}
226*0Sstevel@tonic-gate 		nmp->b_rptr += sizeof (sctp_data_hdr_t);
227*0Sstevel@tonic-gate 		if (nmp->b_rptr == nmp->b_wptr) {
228*0Sstevel@tonic-gate 			tail->b_cont = nmp->b_cont;
229*0Sstevel@tonic-gate 			freeb(nmp);
230*0Sstevel@tonic-gate 		} else {
231*0Sstevel@tonic-gate 			tail->b_cont = nmp;
232*0Sstevel@tonic-gate 		}
233*0Sstevel@tonic-gate 		while (tail->b_cont) {
234*0Sstevel@tonic-gate 			tail = tail->b_cont;
235*0Sstevel@tonic-gate 		}
236*0Sstevel@tonic-gate 	} while ((nmp = mp) != NULL);
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate 	sctp_sendfail(sctp, meta, flags, error);
239*0Sstevel@tonic-gate }
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate /*
242*0Sstevel@tonic-gate  * Send failure when the message hasn't been fully chunkified.
243*0Sstevel@tonic-gate  */
244*0Sstevel@tonic-gate void
245*0Sstevel@tonic-gate sctp_sendfail_event(sctp_t *sctp, mblk_t *meta, int error, boolean_t chunkified)
246*0Sstevel@tonic-gate {
247*0Sstevel@tonic-gate 	mblk_t	*mp;
248*0Sstevel@tonic-gate 	mblk_t	*nmp;
249*0Sstevel@tonic-gate 	mblk_t	*tail;
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate 	if (meta == NULL)
252*0Sstevel@tonic-gate 		return;
253*0Sstevel@tonic-gate 
254*0Sstevel@tonic-gate 	if (!sctp->sctp_recvsendfailevnt) {
255*0Sstevel@tonic-gate 		sctp_free_msg(meta);
256*0Sstevel@tonic-gate 		return;
257*0Sstevel@tonic-gate 	}
258*0Sstevel@tonic-gate 
259*0Sstevel@tonic-gate 	/* If the message is fully chunkified */
260*0Sstevel@tonic-gate 	if (chunkified) {
261*0Sstevel@tonic-gate 		sctp_sendfail_sent(sctp, meta, error);
262*0Sstevel@tonic-gate 		return;
263*0Sstevel@tonic-gate 	}
264*0Sstevel@tonic-gate 	/*
265*0Sstevel@tonic-gate 	 * Message might be partially chunkified, we need to remove
266*0Sstevel@tonic-gate 	 * all data_hdr's.
267*0Sstevel@tonic-gate 	 */
268*0Sstevel@tonic-gate 	mp = meta->b_cont;
269*0Sstevel@tonic-gate 	tail = meta;
270*0Sstevel@tonic-gate 	while ((nmp = mp->b_next) != NULL) {
271*0Sstevel@tonic-gate 		mp->b_next = nmp->b_next;
272*0Sstevel@tonic-gate 		nmp->b_next = NULL;
273*0Sstevel@tonic-gate 		nmp->b_rptr += sizeof (sctp_data_hdr_t);
274*0Sstevel@tonic-gate 		if (nmp->b_rptr == nmp->b_wptr) {
275*0Sstevel@tonic-gate 			tail->b_cont = nmp->b_cont;
276*0Sstevel@tonic-gate 			freeb(nmp);
277*0Sstevel@tonic-gate 		} else {
278*0Sstevel@tonic-gate 			tail->b_cont = nmp;
279*0Sstevel@tonic-gate 		}
280*0Sstevel@tonic-gate 		while (tail->b_cont) {
281*0Sstevel@tonic-gate 			tail = tail->b_cont;
282*0Sstevel@tonic-gate 		}
283*0Sstevel@tonic-gate 	}
284*0Sstevel@tonic-gate 	tail->b_cont = mp;
285*0Sstevel@tonic-gate 
286*0Sstevel@tonic-gate 	sctp_sendfail(sctp, meta, SCTP_DATA_UNSENT, error);
287*0Sstevel@tonic-gate }
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate void
290*0Sstevel@tonic-gate sctp_regift_xmitlist(sctp_t *sctp)
291*0Sstevel@tonic-gate {
292*0Sstevel@tonic-gate 	mblk_t *mp;
293*0Sstevel@tonic-gate 
294*0Sstevel@tonic-gate 	if (!sctp->sctp_recvsendfailevnt) {
295*0Sstevel@tonic-gate 		return;
296*0Sstevel@tonic-gate 	}
297*0Sstevel@tonic-gate 
298*0Sstevel@tonic-gate 	while ((mp = sctp->sctp_xmit_head) != NULL) {
299*0Sstevel@tonic-gate 		sctp->sctp_xmit_head = mp->b_next;
300*0Sstevel@tonic-gate 		mp->b_next = NULL;
301*0Sstevel@tonic-gate 		if (sctp->sctp_xmit_head != NULL)
302*0Sstevel@tonic-gate 			sctp->sctp_xmit_head->b_prev = NULL;
303*0Sstevel@tonic-gate 		sctp_sendfail_event(sctp, mp, 0, B_TRUE);
304*0Sstevel@tonic-gate 	}
305*0Sstevel@tonic-gate 	while ((mp = sctp->sctp_xmit_unsent) != NULL) {
306*0Sstevel@tonic-gate 		sctp->sctp_xmit_unsent = mp->b_next;
307*0Sstevel@tonic-gate 		mp->b_next = NULL;
308*0Sstevel@tonic-gate 		sctp_sendfail_event(sctp, mp, 0, B_FALSE);
309*0Sstevel@tonic-gate 	}
310*0Sstevel@tonic-gate 	sctp->sctp_xmit_tail = sctp->sctp_xmit_unsent_tail = NULL;
311*0Sstevel@tonic-gate 	sctp->sctp_unacked = sctp->sctp_unsent = 0;
312*0Sstevel@tonic-gate }
313*0Sstevel@tonic-gate 
314*0Sstevel@tonic-gate void
315*0Sstevel@tonic-gate sctp_intf_event(sctp_t *sctp, in6_addr_t addr, int state, int error)
316*0Sstevel@tonic-gate {
317*0Sstevel@tonic-gate 	struct sctp_paddr_change *spc;
318*0Sstevel@tonic-gate 	ipaddr_t addr4;
319*0Sstevel@tonic-gate 	struct sockaddr_in *sin;
320*0Sstevel@tonic-gate 	struct sockaddr_in6 *sin6;
321*0Sstevel@tonic-gate 	mblk_t *mp;
322*0Sstevel@tonic-gate 
323*0Sstevel@tonic-gate 	if (!sctp->sctp_recvpathevnt) {
324*0Sstevel@tonic-gate 		return;
325*0Sstevel@tonic-gate 	}
326*0Sstevel@tonic-gate 
327*0Sstevel@tonic-gate 	if ((mp = allocb(sizeof (*spc), BPRI_MED)) == NULL) {
328*0Sstevel@tonic-gate 		return;
329*0Sstevel@tonic-gate 	}
330*0Sstevel@tonic-gate 
331*0Sstevel@tonic-gate 	spc = (struct sctp_paddr_change *)mp->b_rptr;
332*0Sstevel@tonic-gate 	spc->spc_type = SCTP_PEER_ADDR_CHANGE;
333*0Sstevel@tonic-gate 	spc->spc_flags = 0;
334*0Sstevel@tonic-gate 	spc->spc_length = sizeof (*spc);
335*0Sstevel@tonic-gate 	if (IN6_IS_ADDR_V4MAPPED(&addr)) {
336*0Sstevel@tonic-gate 		IN6_V4MAPPED_TO_IPADDR(&addr, addr4);
337*0Sstevel@tonic-gate 		sin = (struct sockaddr_in *)&spc->spc_aaddr;
338*0Sstevel@tonic-gate 		sin->sin_family = AF_INET;
339*0Sstevel@tonic-gate 		sin->sin_port = 0;
340*0Sstevel@tonic-gate 		sin->sin_addr.s_addr = addr4;
341*0Sstevel@tonic-gate 	} else {
342*0Sstevel@tonic-gate 		sin6 = (struct sockaddr_in6 *)&spc->spc_aaddr;
343*0Sstevel@tonic-gate 		sin6->sin6_family = AF_INET6;
344*0Sstevel@tonic-gate 		sin6->sin6_port = 0;
345*0Sstevel@tonic-gate 		sin6->sin6_addr = addr;
346*0Sstevel@tonic-gate 	}
347*0Sstevel@tonic-gate 	spc->spc_state = state;
348*0Sstevel@tonic-gate 	spc->spc_error = error;
349*0Sstevel@tonic-gate 	spc->spc_assoc_id = 0;
350*0Sstevel@tonic-gate 
351*0Sstevel@tonic-gate 	mp->b_wptr = (uchar_t *)(spc + 1);
352*0Sstevel@tonic-gate 	sctp_notify(sctp, mp, spc->spc_length);
353*0Sstevel@tonic-gate }
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate void
356*0Sstevel@tonic-gate sctp_error_event(sctp_t *sctp, sctp_chunk_hdr_t *ch)
357*0Sstevel@tonic-gate {
358*0Sstevel@tonic-gate 	struct sctp_remote_error *sre;
359*0Sstevel@tonic-gate 	mblk_t *mp;
360*0Sstevel@tonic-gate 	size_t len;
361*0Sstevel@tonic-gate 	sctp_parm_hdr_t *errh;
362*0Sstevel@tonic-gate 	uint16_t dlen = 0;
363*0Sstevel@tonic-gate 	uint16_t error = 0;
364*0Sstevel@tonic-gate 	void *dtail = NULL;
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate 	if (!sctp->sctp_recvpeererr) {
367*0Sstevel@tonic-gate 		return;
368*0Sstevel@tonic-gate 	}
369*0Sstevel@tonic-gate 
370*0Sstevel@tonic-gate 	if (ntohs(ch->sch_len) > sizeof (*ch)) {
371*0Sstevel@tonic-gate 		errh = (sctp_parm_hdr_t *)(ch + 1);
372*0Sstevel@tonic-gate 		error = ntohs(errh->sph_type);
373*0Sstevel@tonic-gate 		dlen = ntohs(errh->sph_len) - sizeof (*errh);
374*0Sstevel@tonic-gate 		if (dlen > 0) {
375*0Sstevel@tonic-gate 			dtail = errh + 1;
376*0Sstevel@tonic-gate 		}
377*0Sstevel@tonic-gate 	}
378*0Sstevel@tonic-gate 
379*0Sstevel@tonic-gate 	len = sizeof (*sre) + dlen;
380*0Sstevel@tonic-gate 	if ((mp = allocb(len, BPRI_MED)) == NULL) {
381*0Sstevel@tonic-gate 		return;
382*0Sstevel@tonic-gate 	}
383*0Sstevel@tonic-gate 
384*0Sstevel@tonic-gate 	sre = (struct sctp_remote_error *)mp->b_rptr;
385*0Sstevel@tonic-gate 	sre->sre_type = SCTP_REMOTE_ERROR;
386*0Sstevel@tonic-gate 	sre->sre_flags = 0;
387*0Sstevel@tonic-gate 	sre->sre_length = len;
388*0Sstevel@tonic-gate 	sre->sre_assoc_id = 0;
389*0Sstevel@tonic-gate 	sre->sre_error = error;
390*0Sstevel@tonic-gate 	if (dtail) {
391*0Sstevel@tonic-gate 		bcopy(dtail, sre + 1, dlen);
392*0Sstevel@tonic-gate 	}
393*0Sstevel@tonic-gate 
394*0Sstevel@tonic-gate 	mp->b_wptr = mp->b_rptr + len;
395*0Sstevel@tonic-gate 	sctp_notify(sctp, mp, len);
396*0Sstevel@tonic-gate }
397*0Sstevel@tonic-gate 
398*0Sstevel@tonic-gate void
399*0Sstevel@tonic-gate sctp_shutdown_event(sctp_t *sctp)
400*0Sstevel@tonic-gate {
401*0Sstevel@tonic-gate 	struct sctp_shutdown_event *sse;
402*0Sstevel@tonic-gate 	mblk_t *mp;
403*0Sstevel@tonic-gate 
404*0Sstevel@tonic-gate 	if (!sctp->sctp_recvshutdownevnt) {
405*0Sstevel@tonic-gate 		return;
406*0Sstevel@tonic-gate 	}
407*0Sstevel@tonic-gate 
408*0Sstevel@tonic-gate 	if ((mp = allocb(sizeof (*sse), BPRI_MED)) == NULL) {
409*0Sstevel@tonic-gate 		return;
410*0Sstevel@tonic-gate 	}
411*0Sstevel@tonic-gate 
412*0Sstevel@tonic-gate 	sse = (struct sctp_shutdown_event *)mp->b_rptr;
413*0Sstevel@tonic-gate 	sse->sse_type = SCTP_SHUTDOWN_EVENT;
414*0Sstevel@tonic-gate 	sse->sse_flags = 0;
415*0Sstevel@tonic-gate 	sse->sse_length = sizeof (*sse);
416*0Sstevel@tonic-gate 	sse->sse_assoc_id = 0;
417*0Sstevel@tonic-gate 
418*0Sstevel@tonic-gate 	mp->b_wptr = (uchar_t *)(sse + 1);
419*0Sstevel@tonic-gate 	sctp_notify(sctp, mp, sse->sse_length);
420*0Sstevel@tonic-gate }
421*0Sstevel@tonic-gate 
422*0Sstevel@tonic-gate void
423*0Sstevel@tonic-gate sctp_adaption_event(sctp_t *sctp)
424*0Sstevel@tonic-gate {
425*0Sstevel@tonic-gate 	struct sctp_adaption_event *sai;
426*0Sstevel@tonic-gate 	mblk_t *mp;
427*0Sstevel@tonic-gate 
428*0Sstevel@tonic-gate 	if (!sctp->sctp_recvalevnt || !sctp->sctp_recv_adaption) {
429*0Sstevel@tonic-gate 		return;
430*0Sstevel@tonic-gate 	}
431*0Sstevel@tonic-gate 	if ((mp = allocb(sizeof (*sai), BPRI_MED)) == NULL) {
432*0Sstevel@tonic-gate 		return;
433*0Sstevel@tonic-gate 	}
434*0Sstevel@tonic-gate 
435*0Sstevel@tonic-gate 	sai = (struct sctp_adaption_event *)mp->b_rptr;
436*0Sstevel@tonic-gate 	sai->sai_type = SCTP_ADAPTION_INDICATION;
437*0Sstevel@tonic-gate 	sai->sai_flags = 0;
438*0Sstevel@tonic-gate 	sai->sai_length = sizeof (*sai);
439*0Sstevel@tonic-gate 	sai->sai_assoc_id = 0;
440*0Sstevel@tonic-gate 	/*
441*0Sstevel@tonic-gate 	 * Adaptation code delivered in network byte order.
442*0Sstevel@tonic-gate 	 */
443*0Sstevel@tonic-gate 	sai->sai_adaption_ind = sctp->sctp_rx_adaption_code;
444*0Sstevel@tonic-gate 
445*0Sstevel@tonic-gate 	mp->b_wptr = (uchar_t *)(sai + 1);
446*0Sstevel@tonic-gate 	sctp_notify(sctp, mp, sai->sai_length);
447*0Sstevel@tonic-gate 
448*0Sstevel@tonic-gate 	sctp->sctp_recv_adaption = 0; /* in case there's a restart later */
449*0Sstevel@tonic-gate }
450*0Sstevel@tonic-gate 
451*0Sstevel@tonic-gate /* Send partial deliver event */
452*0Sstevel@tonic-gate void
453*0Sstevel@tonic-gate sctp_partial_delivery_event(sctp_t *sctp)
454*0Sstevel@tonic-gate {
455*0Sstevel@tonic-gate 	struct sctp_pdapi_event	*pdapi;
456*0Sstevel@tonic-gate 	mblk_t			*mp;
457*0Sstevel@tonic-gate 
458*0Sstevel@tonic-gate 	if (!sctp->sctp_recvpdevnt)
459*0Sstevel@tonic-gate 		return;
460*0Sstevel@tonic-gate 
461*0Sstevel@tonic-gate 	if ((mp = allocb(sizeof (*pdapi), BPRI_MED)) == NULL)
462*0Sstevel@tonic-gate 		return;
463*0Sstevel@tonic-gate 
464*0Sstevel@tonic-gate 	pdapi = (struct sctp_pdapi_event *)mp->b_rptr;
465*0Sstevel@tonic-gate 	pdapi->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT;
466*0Sstevel@tonic-gate 	pdapi->pdapi_flags = 0;
467*0Sstevel@tonic-gate 	pdapi->pdapi_length = sizeof (*pdapi);
468*0Sstevel@tonic-gate 	pdapi->pdapi_indication = SCTP_PARTIAL_DELIVERY_ABORTED;
469*0Sstevel@tonic-gate 	pdapi->pdapi_assoc_id = 0;
470*0Sstevel@tonic-gate 	mp->b_wptr = (uchar_t *)(pdapi + 1);
471*0Sstevel@tonic-gate 	sctp_notify(sctp, mp, pdapi->pdapi_length);
472*0Sstevel@tonic-gate }
473