10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55586Skcpoon * Common Development and Distribution License (the "License").
65586Skcpoon * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*13009SChandrasekar.Marimuthu@Sun.COM * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate #include <sys/types.h>
260Sstevel@tonic-gate #include <sys/systm.h>
270Sstevel@tonic-gate #include <sys/stream.h>
280Sstevel@tonic-gate #include <sys/cmn_err.h>
290Sstevel@tonic-gate #include <sys/tihdr.h>
300Sstevel@tonic-gate #include <sys/kmem.h>
310Sstevel@tonic-gate #define _SUN_TPI_VERSION 2
320Sstevel@tonic-gate #include <sys/tihdr.h>
330Sstevel@tonic-gate #include <sys/socket.h>
340Sstevel@tonic-gate
350Sstevel@tonic-gate #include <netinet/in.h>
360Sstevel@tonic-gate #include <netinet/sctp.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate #include <inet/common.h>
398348SEric.Yu@Sun.COM #include <inet/ipclassifier.h>
400Sstevel@tonic-gate #include <inet/ip.h>
418348SEric.Yu@Sun.COM
420Sstevel@tonic-gate #include "sctp_impl.h"
430Sstevel@tonic-gate
448348SEric.Yu@Sun.COM /* ARGSUSED */
450Sstevel@tonic-gate static void
sctp_notify(sctp_t * sctp,mblk_t * emp,size_t len)460Sstevel@tonic-gate sctp_notify(sctp_t *sctp, mblk_t *emp, size_t len)
470Sstevel@tonic-gate {
480Sstevel@tonic-gate struct T_unitdata_ind *tudi;
490Sstevel@tonic-gate mblk_t *mp;
500Sstevel@tonic-gate sctp_faddr_t *fp;
510Sstevel@tonic-gate int32_t rwnd = 0;
528348SEric.Yu@Sun.COM int error;
5311042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp;
540Sstevel@tonic-gate
550Sstevel@tonic-gate if ((mp = allocb(sizeof (*tudi) + sizeof (void *) +
560Sstevel@tonic-gate sizeof (struct sockaddr_in6), BPRI_HI)) == NULL) {
570Sstevel@tonic-gate /* XXX trouble: don't want to drop events. should queue it. */
580Sstevel@tonic-gate freemsg(emp);
590Sstevel@tonic-gate return;
600Sstevel@tonic-gate }
610Sstevel@tonic-gate dprint(3, ("sctp_notify: event %d\n", (*(uint16_t *)emp->b_rptr)));
620Sstevel@tonic-gate
630Sstevel@tonic-gate mp->b_datap->db_type = M_PROTO;
640Sstevel@tonic-gate mp->b_flag |= MSGMARK;
650Sstevel@tonic-gate mp->b_rptr += sizeof (void *); /* pointer worth of padding */
660Sstevel@tonic-gate
670Sstevel@tonic-gate tudi = (struct T_unitdata_ind *)mp->b_rptr;
680Sstevel@tonic-gate tudi->PRIM_type = T_UNITDATA_IND;
690Sstevel@tonic-gate tudi->SRC_offset = sizeof (*tudi);
700Sstevel@tonic-gate tudi->OPT_length = 0;
710Sstevel@tonic-gate tudi->OPT_offset = 0;
720Sstevel@tonic-gate
730Sstevel@tonic-gate fp = sctp->sctp_primary;
740Sstevel@tonic-gate ASSERT(fp);
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * Fill in primary remote address.
780Sstevel@tonic-gate */
79*13009SChandrasekar.Marimuthu@Sun.COM if (IN6_IS_ADDR_V4MAPPED(&fp->sf_faddr)) {
800Sstevel@tonic-gate struct sockaddr_in *sin4;
810Sstevel@tonic-gate
820Sstevel@tonic-gate tudi->SRC_length = sizeof (*sin4);
830Sstevel@tonic-gate sin4 = (struct sockaddr_in *)(tudi + 1);
840Sstevel@tonic-gate sin4->sin_family = AF_INET;
8511042SErik.Nordmark@Sun.COM sin4->sin_port = connp->conn_fport;
86*13009SChandrasekar.Marimuthu@Sun.COM IN6_V4MAPPED_TO_IPADDR(&fp->sf_faddr, sin4->sin_addr.s_addr);
870Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sin4 + 1);
880Sstevel@tonic-gate } else {
890Sstevel@tonic-gate struct sockaddr_in6 *sin6;
900Sstevel@tonic-gate
910Sstevel@tonic-gate tudi->SRC_length = sizeof (*sin6);
920Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)(tudi + 1);
930Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
9411042SErik.Nordmark@Sun.COM sin6->sin6_port = connp->conn_fport;
95*13009SChandrasekar.Marimuthu@Sun.COM sin6->sin6_addr = fp->sf_faddr;
960Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sin6 + 1);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate mp->b_cont = emp;
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate * Notifications are queued regardless of socket rx space. So
1030Sstevel@tonic-gate * we do not decrement sctp_rwnd here as this will confuse the
1040Sstevel@tonic-gate * other side.
1050Sstevel@tonic-gate */
1060Sstevel@tonic-gate #ifdef DEBUG
1070Sstevel@tonic-gate for (emp = mp->b_cont; emp; emp = emp->b_cont) {
1080Sstevel@tonic-gate rwnd += emp->b_wptr - emp->b_rptr;
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate ASSERT(len == rwnd);
1110Sstevel@tonic-gate #endif
1120Sstevel@tonic-gate
1138348SEric.Yu@Sun.COM /*
1148348SEric.Yu@Sun.COM * Override b_flag for SCTP sockfs internal use
1158348SEric.Yu@Sun.COM */
1168348SEric.Yu@Sun.COM mp->b_flag = (short)SCTP_NOTIFICATION;
1178348SEric.Yu@Sun.COM
1188348SEric.Yu@Sun.COM rwnd = sctp->sctp_ulp_recv(sctp->sctp_ulpd, mp, msgdsize(mp), 0,
1198348SEric.Yu@Sun.COM &error, NULL);
1200Sstevel@tonic-gate if (rwnd > sctp->sctp_rwnd) {
1210Sstevel@tonic-gate sctp->sctp_rwnd = rwnd;
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate void
sctp_assoc_event(sctp_t * sctp,uint16_t state,uint16_t error,sctp_chunk_hdr_t * ch)1260Sstevel@tonic-gate sctp_assoc_event(sctp_t *sctp, uint16_t state, uint16_t error,
1270Sstevel@tonic-gate sctp_chunk_hdr_t *ch)
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate struct sctp_assoc_change *sacp;
1300Sstevel@tonic-gate mblk_t *mp;
1310Sstevel@tonic-gate uint16_t ch_len;
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate if (!sctp->sctp_recvassocevnt) {
1340Sstevel@tonic-gate return;
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate ch_len = (ch != NULL) ? ntohs(ch->sch_len) : 0;
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate if ((mp = allocb(sizeof (*sacp) + ch_len, BPRI_MED)) == NULL) {
1400Sstevel@tonic-gate return;
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate sacp = (struct sctp_assoc_change *)mp->b_rptr;
1440Sstevel@tonic-gate sacp->sac_type = SCTP_ASSOC_CHANGE;
1450Sstevel@tonic-gate sacp->sac_flags = sctp->sctp_prsctp_aware ? SCTP_PRSCTP_CAPABLE : 0;
1460Sstevel@tonic-gate sacp->sac_length = sizeof (*sacp) + ch_len;
1470Sstevel@tonic-gate sacp->sac_state = state;
1480Sstevel@tonic-gate sacp->sac_error = error;
1490Sstevel@tonic-gate sacp->sac_outbound_streams = sctp->sctp_num_ostr;
1500Sstevel@tonic-gate sacp->sac_inbound_streams = sctp->sctp_num_istr;
1510Sstevel@tonic-gate sacp->sac_assoc_id = 0;
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate if (ch != NULL)
1540Sstevel@tonic-gate bcopy(ch, sacp + 1, ch_len);
1550Sstevel@tonic-gate mp->b_wptr += sacp->sac_length;
1560Sstevel@tonic-gate sctp_notify(sctp, mp, sacp->sac_length);
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate * Send failure event. Message is expected to have message header still
1610Sstevel@tonic-gate * in place, data follows in subsequent mblk's.
1620Sstevel@tonic-gate */
1630Sstevel@tonic-gate static void
sctp_sendfail(sctp_t * sctp,mblk_t * msghdr,uint16_t flags,int error)1640Sstevel@tonic-gate sctp_sendfail(sctp_t *sctp, mblk_t *msghdr, uint16_t flags, int error)
1650Sstevel@tonic-gate {
1660Sstevel@tonic-gate struct sctp_send_failed *sfp;
1670Sstevel@tonic-gate mblk_t *mp;
1680Sstevel@tonic-gate sctp_msg_hdr_t *smh;
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate /* Allocate a mblk for the notification header */
1710Sstevel@tonic-gate if ((mp = allocb(sizeof (*sfp), BPRI_MED)) == NULL) {
1720Sstevel@tonic-gate /* give up */
1730Sstevel@tonic-gate freemsg(msghdr);
1740Sstevel@tonic-gate return;
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate smh = (sctp_msg_hdr_t *)msghdr->b_rptr;
1780Sstevel@tonic-gate sfp = (struct sctp_send_failed *)mp->b_rptr;
1790Sstevel@tonic-gate sfp->ssf_type = SCTP_SEND_FAILED;
1800Sstevel@tonic-gate sfp->ssf_flags = flags;
1810Sstevel@tonic-gate sfp->ssf_length = smh->smh_msglen + sizeof (*sfp);
1820Sstevel@tonic-gate sfp->ssf_error = error;
1830Sstevel@tonic-gate sfp->ssf_assoc_id = 0;
1840Sstevel@tonic-gate
1850Sstevel@tonic-gate bzero(&sfp->ssf_info, sizeof (sfp->ssf_info));
1860Sstevel@tonic-gate sfp->ssf_info.sinfo_stream = smh->smh_sid;
1870Sstevel@tonic-gate sfp->ssf_info.sinfo_flags = smh->smh_flags;
1880Sstevel@tonic-gate sfp->ssf_info.sinfo_ppid = smh->smh_ppid;
1890Sstevel@tonic-gate sfp->ssf_info.sinfo_context = smh->smh_context;
1900Sstevel@tonic-gate sfp->ssf_info.sinfo_timetolive = TICK_TO_MSEC(smh->smh_ttl);
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sfp + 1);
1930Sstevel@tonic-gate mp->b_cont = msghdr->b_cont;
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate freeb(msghdr);
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate sctp_notify(sctp, mp, sfp->ssf_length);
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate
2010Sstevel@tonic-gate /*
2020Sstevel@tonic-gate * Send failure when the message has been fully chunkified.
2030Sstevel@tonic-gate */
2040Sstevel@tonic-gate static void
sctp_sendfail_sent(sctp_t * sctp,mblk_t * meta,int error)2050Sstevel@tonic-gate sctp_sendfail_sent(sctp_t *sctp, mblk_t *meta, int error)
2060Sstevel@tonic-gate {
2070Sstevel@tonic-gate mblk_t *mp;
2080Sstevel@tonic-gate mblk_t *nmp;
2090Sstevel@tonic-gate mblk_t *tail;
2100Sstevel@tonic-gate uint16_t flags = SCTP_DATA_SENT;
2110Sstevel@tonic-gate
2120Sstevel@tonic-gate if (!sctp->sctp_recvsendfailevnt) {
2130Sstevel@tonic-gate sctp_free_msg(meta);
2140Sstevel@tonic-gate return;
2150Sstevel@tonic-gate }
2160Sstevel@tonic-gate
2170Sstevel@tonic-gate /*
2180Sstevel@tonic-gate * We need to remove all data_hdr's.
2190Sstevel@tonic-gate */
2200Sstevel@tonic-gate nmp = meta->b_cont;
2210Sstevel@tonic-gate tail = meta;
2220Sstevel@tonic-gate do {
2230Sstevel@tonic-gate mp = nmp->b_next;
2240Sstevel@tonic-gate nmp->b_next = NULL;
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate /*
2270Sstevel@tonic-gate * If one of the chunks hasn't been sent yet, say that
2280Sstevel@tonic-gate * the message hasn't been sent.
2290Sstevel@tonic-gate */
2300Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(nmp)) {
2310Sstevel@tonic-gate flags = SCTP_DATA_UNSENT;
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate nmp->b_rptr += sizeof (sctp_data_hdr_t);
2340Sstevel@tonic-gate if (nmp->b_rptr == nmp->b_wptr) {
2350Sstevel@tonic-gate tail->b_cont = nmp->b_cont;
2360Sstevel@tonic-gate freeb(nmp);
2370Sstevel@tonic-gate } else {
2380Sstevel@tonic-gate tail->b_cont = nmp;
2390Sstevel@tonic-gate }
2400Sstevel@tonic-gate while (tail->b_cont) {
2410Sstevel@tonic-gate tail = tail->b_cont;
2420Sstevel@tonic-gate }
2430Sstevel@tonic-gate } while ((nmp = mp) != NULL);
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate sctp_sendfail(sctp, meta, flags, error);
2460Sstevel@tonic-gate }
2470Sstevel@tonic-gate
2480Sstevel@tonic-gate /*
2490Sstevel@tonic-gate * Send failure when the message hasn't been fully chunkified.
2500Sstevel@tonic-gate */
2510Sstevel@tonic-gate void
sctp_sendfail_event(sctp_t * sctp,mblk_t * meta,int error,boolean_t chunkified)2520Sstevel@tonic-gate sctp_sendfail_event(sctp_t *sctp, mblk_t *meta, int error, boolean_t chunkified)
2530Sstevel@tonic-gate {
2540Sstevel@tonic-gate mblk_t *mp;
2550Sstevel@tonic-gate mblk_t *nmp;
2560Sstevel@tonic-gate mblk_t *tail;
2570Sstevel@tonic-gate
2580Sstevel@tonic-gate if (meta == NULL)
2590Sstevel@tonic-gate return;
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate if (!sctp->sctp_recvsendfailevnt) {
2620Sstevel@tonic-gate sctp_free_msg(meta);
2630Sstevel@tonic-gate return;
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate /* If the message is fully chunkified */
2670Sstevel@tonic-gate if (chunkified) {
2680Sstevel@tonic-gate sctp_sendfail_sent(sctp, meta, error);
2690Sstevel@tonic-gate return;
2700Sstevel@tonic-gate }
2710Sstevel@tonic-gate /*
2720Sstevel@tonic-gate * Message might be partially chunkified, we need to remove
2730Sstevel@tonic-gate * all data_hdr's.
2740Sstevel@tonic-gate */
2750Sstevel@tonic-gate mp = meta->b_cont;
2760Sstevel@tonic-gate tail = meta;
2770Sstevel@tonic-gate while ((nmp = mp->b_next) != NULL) {
2780Sstevel@tonic-gate mp->b_next = nmp->b_next;
2790Sstevel@tonic-gate nmp->b_next = NULL;
2800Sstevel@tonic-gate nmp->b_rptr += sizeof (sctp_data_hdr_t);
2810Sstevel@tonic-gate if (nmp->b_rptr == nmp->b_wptr) {
2820Sstevel@tonic-gate tail->b_cont = nmp->b_cont;
2830Sstevel@tonic-gate freeb(nmp);
2840Sstevel@tonic-gate } else {
2850Sstevel@tonic-gate tail->b_cont = nmp;
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate while (tail->b_cont) {
2880Sstevel@tonic-gate tail = tail->b_cont;
2890Sstevel@tonic-gate }
2900Sstevel@tonic-gate }
2910Sstevel@tonic-gate tail->b_cont = mp;
2920Sstevel@tonic-gate
2930Sstevel@tonic-gate sctp_sendfail(sctp, meta, SCTP_DATA_UNSENT, error);
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate void
sctp_regift_xmitlist(sctp_t * sctp)2970Sstevel@tonic-gate sctp_regift_xmitlist(sctp_t *sctp)
2980Sstevel@tonic-gate {
2990Sstevel@tonic-gate mblk_t *mp;
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate if (!sctp->sctp_recvsendfailevnt) {
3020Sstevel@tonic-gate return;
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate while ((mp = sctp->sctp_xmit_head) != NULL) {
3060Sstevel@tonic-gate sctp->sctp_xmit_head = mp->b_next;
3070Sstevel@tonic-gate mp->b_next = NULL;
3080Sstevel@tonic-gate if (sctp->sctp_xmit_head != NULL)
3090Sstevel@tonic-gate sctp->sctp_xmit_head->b_prev = NULL;
3100Sstevel@tonic-gate sctp_sendfail_event(sctp, mp, 0, B_TRUE);
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate while ((mp = sctp->sctp_xmit_unsent) != NULL) {
3130Sstevel@tonic-gate sctp->sctp_xmit_unsent = mp->b_next;
3140Sstevel@tonic-gate mp->b_next = NULL;
3150Sstevel@tonic-gate sctp_sendfail_event(sctp, mp, 0, B_FALSE);
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate sctp->sctp_xmit_tail = sctp->sctp_xmit_unsent_tail = NULL;
3180Sstevel@tonic-gate sctp->sctp_unacked = sctp->sctp_unsent = 0;
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate
3210Sstevel@tonic-gate void
sctp_intf_event(sctp_t * sctp,in6_addr_t addr,int state,int error)3220Sstevel@tonic-gate sctp_intf_event(sctp_t *sctp, in6_addr_t addr, int state, int error)
3230Sstevel@tonic-gate {
3240Sstevel@tonic-gate struct sctp_paddr_change *spc;
3250Sstevel@tonic-gate ipaddr_t addr4;
3260Sstevel@tonic-gate struct sockaddr_in *sin;
3270Sstevel@tonic-gate struct sockaddr_in6 *sin6;
3280Sstevel@tonic-gate mblk_t *mp;
3290Sstevel@tonic-gate
3300Sstevel@tonic-gate if (!sctp->sctp_recvpathevnt) {
3310Sstevel@tonic-gate return;
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate if ((mp = allocb(sizeof (*spc), BPRI_MED)) == NULL) {
3350Sstevel@tonic-gate return;
3360Sstevel@tonic-gate }
3370Sstevel@tonic-gate
3380Sstevel@tonic-gate spc = (struct sctp_paddr_change *)mp->b_rptr;
3390Sstevel@tonic-gate spc->spc_type = SCTP_PEER_ADDR_CHANGE;
3400Sstevel@tonic-gate spc->spc_flags = 0;
3410Sstevel@tonic-gate spc->spc_length = sizeof (*spc);
3420Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&addr)) {
3430Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&addr, addr4);
3440Sstevel@tonic-gate sin = (struct sockaddr_in *)&spc->spc_aaddr;
3450Sstevel@tonic-gate sin->sin_family = AF_INET;
3460Sstevel@tonic-gate sin->sin_port = 0;
3470Sstevel@tonic-gate sin->sin_addr.s_addr = addr4;
3480Sstevel@tonic-gate } else {
3490Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&spc->spc_aaddr;
3500Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
3510Sstevel@tonic-gate sin6->sin6_port = 0;
3520Sstevel@tonic-gate sin6->sin6_addr = addr;
3530Sstevel@tonic-gate }
3540Sstevel@tonic-gate spc->spc_state = state;
3550Sstevel@tonic-gate spc->spc_error = error;
3560Sstevel@tonic-gate spc->spc_assoc_id = 0;
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(spc + 1);
3590Sstevel@tonic-gate sctp_notify(sctp, mp, spc->spc_length);
3600Sstevel@tonic-gate }
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate void
sctp_error_event(sctp_t * sctp,sctp_chunk_hdr_t * ch,boolean_t is_asconf)36311953Sanil.udupa@sun.com sctp_error_event(sctp_t *sctp, sctp_chunk_hdr_t *ch, boolean_t is_asconf)
3640Sstevel@tonic-gate {
3650Sstevel@tonic-gate struct sctp_remote_error *sre;
3660Sstevel@tonic-gate mblk_t *mp;
3670Sstevel@tonic-gate size_t len;
36811953Sanil.udupa@sun.com sctp_parm_hdr_t *errh = NULL;
3690Sstevel@tonic-gate uint16_t dlen = 0;
3700Sstevel@tonic-gate uint16_t error = 0;
3710Sstevel@tonic-gate void *dtail = NULL;
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate if (!sctp->sctp_recvpeererr) {
3740Sstevel@tonic-gate return;
3750Sstevel@tonic-gate }
3760Sstevel@tonic-gate
37711953Sanil.udupa@sun.com /*
37811953Sanil.udupa@sun.com * ASCONF PARM error chunks :
37911953Sanil.udupa@sun.com * PARM_ERROR_IND parm type is always followed by correlation id.
38011953Sanil.udupa@sun.com * See sctp_asconf_adderr() and sctp_asconf_prepend_errwrap() as to
38111953Sanil.udupa@sun.com * how these error chunks are build.
38211953Sanil.udupa@sun.com * error cause wrapper (PARM_ERROR_IND) + correlation id +
38311953Sanil.udupa@sun.com * error cause + error cause details.
38411953Sanil.udupa@sun.com *
38511953Sanil.udupa@sun.com * Regular error chunks :
38611953Sanil.udupa@sun.com * See sctp_make_err() as to how these error chunks are build.
38711953Sanil.udupa@sun.com * error chunk header (CHUNK_ERROR) + error cause + error cause details.
38811953Sanil.udupa@sun.com */
38911953Sanil.udupa@sun.com if (is_asconf) {
39011953Sanil.udupa@sun.com if (ntohs(ch->sch_len) >
39111953Sanil.udupa@sun.com (sizeof (*ch) + sizeof (uint32_t))) {
39211953Sanil.udupa@sun.com errh = (sctp_parm_hdr_t *)((char *)ch +
39311953Sanil.udupa@sun.com sizeof (uint32_t) + sizeof (sctp_parm_hdr_t));
39411953Sanil.udupa@sun.com }
39511953Sanil.udupa@sun.com } else {
39611953Sanil.udupa@sun.com if (ntohs(ch->sch_len) > sizeof (*ch)) {
39711953Sanil.udupa@sun.com errh = (sctp_parm_hdr_t *)(ch + 1);
39811953Sanil.udupa@sun.com }
39911953Sanil.udupa@sun.com }
40011953Sanil.udupa@sun.com
40111953Sanil.udupa@sun.com if (errh != NULL) {
4020Sstevel@tonic-gate error = ntohs(errh->sph_type);
4030Sstevel@tonic-gate dlen = ntohs(errh->sph_len) - sizeof (*errh);
4040Sstevel@tonic-gate if (dlen > 0) {
4050Sstevel@tonic-gate dtail = errh + 1;
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate }
4080Sstevel@tonic-gate
4090Sstevel@tonic-gate len = sizeof (*sre) + dlen;
4100Sstevel@tonic-gate if ((mp = allocb(len, BPRI_MED)) == NULL) {
4110Sstevel@tonic-gate return;
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate sre = (struct sctp_remote_error *)mp->b_rptr;
4150Sstevel@tonic-gate sre->sre_type = SCTP_REMOTE_ERROR;
4160Sstevel@tonic-gate sre->sre_flags = 0;
4170Sstevel@tonic-gate sre->sre_length = len;
4180Sstevel@tonic-gate sre->sre_assoc_id = 0;
4190Sstevel@tonic-gate sre->sre_error = error;
42011953Sanil.udupa@sun.com if (dtail != NULL) {
4210Sstevel@tonic-gate bcopy(dtail, sre + 1, dlen);
4220Sstevel@tonic-gate }
4230Sstevel@tonic-gate
4240Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + len;
4250Sstevel@tonic-gate sctp_notify(sctp, mp, len);
4260Sstevel@tonic-gate }
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate void
sctp_shutdown_event(sctp_t * sctp)4290Sstevel@tonic-gate sctp_shutdown_event(sctp_t *sctp)
4300Sstevel@tonic-gate {
4310Sstevel@tonic-gate struct sctp_shutdown_event *sse;
4320Sstevel@tonic-gate mblk_t *mp;
4330Sstevel@tonic-gate
4340Sstevel@tonic-gate if (!sctp->sctp_recvshutdownevnt) {
4350Sstevel@tonic-gate return;
4360Sstevel@tonic-gate }
4370Sstevel@tonic-gate
4380Sstevel@tonic-gate if ((mp = allocb(sizeof (*sse), BPRI_MED)) == NULL) {
4390Sstevel@tonic-gate return;
4400Sstevel@tonic-gate }
4410Sstevel@tonic-gate
4420Sstevel@tonic-gate sse = (struct sctp_shutdown_event *)mp->b_rptr;
4430Sstevel@tonic-gate sse->sse_type = SCTP_SHUTDOWN_EVENT;
4440Sstevel@tonic-gate sse->sse_flags = 0;
4450Sstevel@tonic-gate sse->sse_length = sizeof (*sse);
4460Sstevel@tonic-gate sse->sse_assoc_id = 0;
4470Sstevel@tonic-gate
4480Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sse + 1);
4490Sstevel@tonic-gate sctp_notify(sctp, mp, sse->sse_length);
4500Sstevel@tonic-gate }
4510Sstevel@tonic-gate
4520Sstevel@tonic-gate void
sctp_adaptation_event(sctp_t * sctp)4535586Skcpoon sctp_adaptation_event(sctp_t *sctp)
4540Sstevel@tonic-gate {
4555586Skcpoon struct sctp_adaptation_event *sai;
4560Sstevel@tonic-gate mblk_t *mp;
4570Sstevel@tonic-gate
4585586Skcpoon if (!sctp->sctp_recvalevnt || !sctp->sctp_recv_adaptation) {
4590Sstevel@tonic-gate return;
4600Sstevel@tonic-gate }
4610Sstevel@tonic-gate if ((mp = allocb(sizeof (*sai), BPRI_MED)) == NULL) {
4620Sstevel@tonic-gate return;
4630Sstevel@tonic-gate }
4640Sstevel@tonic-gate
4655586Skcpoon sai = (struct sctp_adaptation_event *)mp->b_rptr;
4665586Skcpoon sai->sai_type = SCTP_ADAPTATION_INDICATION;
4670Sstevel@tonic-gate sai->sai_flags = 0;
4680Sstevel@tonic-gate sai->sai_length = sizeof (*sai);
4690Sstevel@tonic-gate sai->sai_assoc_id = 0;
4700Sstevel@tonic-gate /*
4710Sstevel@tonic-gate * Adaptation code delivered in network byte order.
4720Sstevel@tonic-gate */
4735586Skcpoon sai->sai_adaptation_ind = sctp->sctp_rx_adaptation_code;
4740Sstevel@tonic-gate
4750Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sai + 1);
4760Sstevel@tonic-gate sctp_notify(sctp, mp, sai->sai_length);
4770Sstevel@tonic-gate
4785586Skcpoon sctp->sctp_recv_adaptation = 0; /* in case there's a restart later */
4790Sstevel@tonic-gate }
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate /* Send partial deliver event */
4820Sstevel@tonic-gate void
sctp_partial_delivery_event(sctp_t * sctp)4830Sstevel@tonic-gate sctp_partial_delivery_event(sctp_t *sctp)
4840Sstevel@tonic-gate {
4850Sstevel@tonic-gate struct sctp_pdapi_event *pdapi;
4860Sstevel@tonic-gate mblk_t *mp;
4870Sstevel@tonic-gate
4880Sstevel@tonic-gate if (!sctp->sctp_recvpdevnt)
4890Sstevel@tonic-gate return;
4900Sstevel@tonic-gate
4910Sstevel@tonic-gate if ((mp = allocb(sizeof (*pdapi), BPRI_MED)) == NULL)
4920Sstevel@tonic-gate return;
4930Sstevel@tonic-gate
4940Sstevel@tonic-gate pdapi = (struct sctp_pdapi_event *)mp->b_rptr;
4950Sstevel@tonic-gate pdapi->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT;
4960Sstevel@tonic-gate pdapi->pdapi_flags = 0;
4970Sstevel@tonic-gate pdapi->pdapi_length = sizeof (*pdapi);
4980Sstevel@tonic-gate pdapi->pdapi_indication = SCTP_PARTIAL_DELIVERY_ABORTED;
4990Sstevel@tonic-gate pdapi->pdapi_assoc_id = 0;
5000Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(pdapi + 1);
5010Sstevel@tonic-gate sctp_notify(sctp, mp, pdapi->pdapi_length);
5020Sstevel@tonic-gate }
503