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 5*5586Skcpoon * Common Development and Distribution License (the "License"). 6*5586Skcpoon * 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*5586Skcpoon * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/systm.h> 300Sstevel@tonic-gate #include <sys/stream.h> 310Sstevel@tonic-gate #include <sys/cmn_err.h> 320Sstevel@tonic-gate #include <sys/tihdr.h> 330Sstevel@tonic-gate #include <sys/kmem.h> 340Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 350Sstevel@tonic-gate #include <sys/tihdr.h> 360Sstevel@tonic-gate #include <sys/socket.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <netinet/in.h> 390Sstevel@tonic-gate #include <netinet/sctp.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate #include <inet/common.h> 420Sstevel@tonic-gate #include <inet/ip.h> 430Sstevel@tonic-gate #include "sctp_impl.h" 440Sstevel@tonic-gate 450Sstevel@tonic-gate static void 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; 520Sstevel@tonic-gate 530Sstevel@tonic-gate if ((mp = allocb(sizeof (*tudi) + sizeof (void *) + 540Sstevel@tonic-gate sizeof (struct sockaddr_in6), BPRI_HI)) == NULL) { 550Sstevel@tonic-gate /* XXX trouble: don't want to drop events. should queue it. */ 560Sstevel@tonic-gate freemsg(emp); 570Sstevel@tonic-gate return; 580Sstevel@tonic-gate } 590Sstevel@tonic-gate dprint(3, ("sctp_notify: event %d\n", (*(uint16_t *)emp->b_rptr))); 600Sstevel@tonic-gate 610Sstevel@tonic-gate mp->b_datap->db_type = M_PROTO; 620Sstevel@tonic-gate mp->b_flag |= MSGMARK; 630Sstevel@tonic-gate mp->b_rptr += sizeof (void *); /* pointer worth of padding */ 640Sstevel@tonic-gate 650Sstevel@tonic-gate tudi = (struct T_unitdata_ind *)mp->b_rptr; 660Sstevel@tonic-gate tudi->PRIM_type = T_UNITDATA_IND; 670Sstevel@tonic-gate tudi->SRC_offset = sizeof (*tudi); 680Sstevel@tonic-gate tudi->OPT_length = 0; 690Sstevel@tonic-gate tudi->OPT_offset = 0; 700Sstevel@tonic-gate 710Sstevel@tonic-gate fp = sctp->sctp_primary; 720Sstevel@tonic-gate ASSERT(fp); 730Sstevel@tonic-gate 740Sstevel@tonic-gate /* 750Sstevel@tonic-gate * Fill in primary remote address. 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&fp->faddr)) { 780Sstevel@tonic-gate struct sockaddr_in *sin4; 790Sstevel@tonic-gate 800Sstevel@tonic-gate tudi->SRC_length = sizeof (*sin4); 810Sstevel@tonic-gate sin4 = (struct sockaddr_in *)(tudi + 1); 820Sstevel@tonic-gate sin4->sin_family = AF_INET; 830Sstevel@tonic-gate sin4->sin_port = sctp->sctp_fport; 840Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->faddr, sin4->sin_addr.s_addr); 850Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sin4 + 1); 860Sstevel@tonic-gate } else { 870Sstevel@tonic-gate struct sockaddr_in6 *sin6; 880Sstevel@tonic-gate 890Sstevel@tonic-gate tudi->SRC_length = sizeof (*sin6); 900Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)(tudi + 1); 910Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 920Sstevel@tonic-gate sin6->sin6_port = sctp->sctp_fport; 930Sstevel@tonic-gate sin6->sin6_addr = fp->faddr; 940Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sin6 + 1); 950Sstevel@tonic-gate } 960Sstevel@tonic-gate 970Sstevel@tonic-gate mp->b_cont = emp; 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* 1000Sstevel@tonic-gate * Notifications are queued regardless of socket rx space. So 1010Sstevel@tonic-gate * we do not decrement sctp_rwnd here as this will confuse the 1020Sstevel@tonic-gate * other side. 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate #ifdef DEBUG 1050Sstevel@tonic-gate for (emp = mp->b_cont; emp; emp = emp->b_cont) { 1060Sstevel@tonic-gate rwnd += emp->b_wptr - emp->b_rptr; 1070Sstevel@tonic-gate } 1080Sstevel@tonic-gate ASSERT(len == rwnd); 1090Sstevel@tonic-gate #endif 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate rwnd = sctp->sctp_ulp_recv(sctp->sctp_ulpd, mp, SCTP_NOTIFICATION); 1120Sstevel@tonic-gate if (rwnd > sctp->sctp_rwnd) { 1130Sstevel@tonic-gate sctp->sctp_rwnd = rwnd; 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate } 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate void 1180Sstevel@tonic-gate sctp_assoc_event(sctp_t *sctp, uint16_t state, uint16_t error, 1190Sstevel@tonic-gate sctp_chunk_hdr_t *ch) 1200Sstevel@tonic-gate { 1210Sstevel@tonic-gate struct sctp_assoc_change *sacp; 1220Sstevel@tonic-gate mblk_t *mp; 1230Sstevel@tonic-gate uint16_t ch_len; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate if (!sctp->sctp_recvassocevnt) { 1260Sstevel@tonic-gate return; 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate ch_len = (ch != NULL) ? ntohs(ch->sch_len) : 0; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate if ((mp = allocb(sizeof (*sacp) + ch_len, BPRI_MED)) == NULL) { 1320Sstevel@tonic-gate return; 1330Sstevel@tonic-gate } 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate sacp = (struct sctp_assoc_change *)mp->b_rptr; 1360Sstevel@tonic-gate sacp->sac_type = SCTP_ASSOC_CHANGE; 1370Sstevel@tonic-gate sacp->sac_flags = sctp->sctp_prsctp_aware ? SCTP_PRSCTP_CAPABLE : 0; 1380Sstevel@tonic-gate sacp->sac_length = sizeof (*sacp) + ch_len; 1390Sstevel@tonic-gate sacp->sac_state = state; 1400Sstevel@tonic-gate sacp->sac_error = error; 1410Sstevel@tonic-gate sacp->sac_outbound_streams = sctp->sctp_num_ostr; 1420Sstevel@tonic-gate sacp->sac_inbound_streams = sctp->sctp_num_istr; 1430Sstevel@tonic-gate sacp->sac_assoc_id = 0; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate if (ch != NULL) 1460Sstevel@tonic-gate bcopy(ch, sacp + 1, ch_len); 1470Sstevel@tonic-gate mp->b_wptr += sacp->sac_length; 1480Sstevel@tonic-gate sctp_notify(sctp, mp, sacp->sac_length); 1490Sstevel@tonic-gate } 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* 1520Sstevel@tonic-gate * Send failure event. Message is expected to have message header still 1530Sstevel@tonic-gate * in place, data follows in subsequent mblk's. 1540Sstevel@tonic-gate */ 1550Sstevel@tonic-gate static void 1560Sstevel@tonic-gate sctp_sendfail(sctp_t *sctp, mblk_t *msghdr, uint16_t flags, int error) 1570Sstevel@tonic-gate { 1580Sstevel@tonic-gate struct sctp_send_failed *sfp; 1590Sstevel@tonic-gate mblk_t *mp; 1600Sstevel@tonic-gate sctp_msg_hdr_t *smh; 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate /* Allocate a mblk for the notification header */ 1630Sstevel@tonic-gate if ((mp = allocb(sizeof (*sfp), BPRI_MED)) == NULL) { 1640Sstevel@tonic-gate /* give up */ 1650Sstevel@tonic-gate freemsg(msghdr); 1660Sstevel@tonic-gate return; 1670Sstevel@tonic-gate } 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate smh = (sctp_msg_hdr_t *)msghdr->b_rptr; 1700Sstevel@tonic-gate sfp = (struct sctp_send_failed *)mp->b_rptr; 1710Sstevel@tonic-gate sfp->ssf_type = SCTP_SEND_FAILED; 1720Sstevel@tonic-gate sfp->ssf_flags = flags; 1730Sstevel@tonic-gate sfp->ssf_length = smh->smh_msglen + sizeof (*sfp); 1740Sstevel@tonic-gate sfp->ssf_error = error; 1750Sstevel@tonic-gate sfp->ssf_assoc_id = 0; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate bzero(&sfp->ssf_info, sizeof (sfp->ssf_info)); 1780Sstevel@tonic-gate sfp->ssf_info.sinfo_stream = smh->smh_sid; 1790Sstevel@tonic-gate sfp->ssf_info.sinfo_flags = smh->smh_flags; 1800Sstevel@tonic-gate sfp->ssf_info.sinfo_ppid = smh->smh_ppid; 1810Sstevel@tonic-gate sfp->ssf_info.sinfo_context = smh->smh_context; 1820Sstevel@tonic-gate sfp->ssf_info.sinfo_timetolive = TICK_TO_MSEC(smh->smh_ttl); 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sfp + 1); 1850Sstevel@tonic-gate mp->b_cont = msghdr->b_cont; 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate freeb(msghdr); 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate sctp_notify(sctp, mp, sfp->ssf_length); 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate /* 1940Sstevel@tonic-gate * Send failure when the message has been fully chunkified. 1950Sstevel@tonic-gate */ 1960Sstevel@tonic-gate static void 1970Sstevel@tonic-gate sctp_sendfail_sent(sctp_t *sctp, mblk_t *meta, int error) 1980Sstevel@tonic-gate { 1990Sstevel@tonic-gate mblk_t *mp; 2000Sstevel@tonic-gate mblk_t *nmp; 2010Sstevel@tonic-gate mblk_t *tail; 2020Sstevel@tonic-gate uint16_t flags = SCTP_DATA_SENT; 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate if (!sctp->sctp_recvsendfailevnt) { 2050Sstevel@tonic-gate sctp_free_msg(meta); 2060Sstevel@tonic-gate return; 2070Sstevel@tonic-gate } 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate /* 2100Sstevel@tonic-gate * We need to remove all data_hdr's. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate nmp = meta->b_cont; 2130Sstevel@tonic-gate tail = meta; 2140Sstevel@tonic-gate do { 2150Sstevel@tonic-gate mp = nmp->b_next; 2160Sstevel@tonic-gate nmp->b_next = NULL; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate /* 2190Sstevel@tonic-gate * If one of the chunks hasn't been sent yet, say that 2200Sstevel@tonic-gate * the message hasn't been sent. 2210Sstevel@tonic-gate */ 2220Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(nmp)) { 2230Sstevel@tonic-gate flags = SCTP_DATA_UNSENT; 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate nmp->b_rptr += sizeof (sctp_data_hdr_t); 2260Sstevel@tonic-gate if (nmp->b_rptr == nmp->b_wptr) { 2270Sstevel@tonic-gate tail->b_cont = nmp->b_cont; 2280Sstevel@tonic-gate freeb(nmp); 2290Sstevel@tonic-gate } else { 2300Sstevel@tonic-gate tail->b_cont = nmp; 2310Sstevel@tonic-gate } 2320Sstevel@tonic-gate while (tail->b_cont) { 2330Sstevel@tonic-gate tail = tail->b_cont; 2340Sstevel@tonic-gate } 2350Sstevel@tonic-gate } while ((nmp = mp) != NULL); 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate sctp_sendfail(sctp, meta, flags, error); 2380Sstevel@tonic-gate } 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate /* 2410Sstevel@tonic-gate * Send failure when the message hasn't been fully chunkified. 2420Sstevel@tonic-gate */ 2430Sstevel@tonic-gate void 2440Sstevel@tonic-gate sctp_sendfail_event(sctp_t *sctp, mblk_t *meta, int error, boolean_t chunkified) 2450Sstevel@tonic-gate { 2460Sstevel@tonic-gate mblk_t *mp; 2470Sstevel@tonic-gate mblk_t *nmp; 2480Sstevel@tonic-gate mblk_t *tail; 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate if (meta == NULL) 2510Sstevel@tonic-gate return; 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate if (!sctp->sctp_recvsendfailevnt) { 2540Sstevel@tonic-gate sctp_free_msg(meta); 2550Sstevel@tonic-gate return; 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate /* If the message is fully chunkified */ 2590Sstevel@tonic-gate if (chunkified) { 2600Sstevel@tonic-gate sctp_sendfail_sent(sctp, meta, error); 2610Sstevel@tonic-gate return; 2620Sstevel@tonic-gate } 2630Sstevel@tonic-gate /* 2640Sstevel@tonic-gate * Message might be partially chunkified, we need to remove 2650Sstevel@tonic-gate * all data_hdr's. 2660Sstevel@tonic-gate */ 2670Sstevel@tonic-gate mp = meta->b_cont; 2680Sstevel@tonic-gate tail = meta; 2690Sstevel@tonic-gate while ((nmp = mp->b_next) != NULL) { 2700Sstevel@tonic-gate mp->b_next = nmp->b_next; 2710Sstevel@tonic-gate nmp->b_next = NULL; 2720Sstevel@tonic-gate nmp->b_rptr += sizeof (sctp_data_hdr_t); 2730Sstevel@tonic-gate if (nmp->b_rptr == nmp->b_wptr) { 2740Sstevel@tonic-gate tail->b_cont = nmp->b_cont; 2750Sstevel@tonic-gate freeb(nmp); 2760Sstevel@tonic-gate } else { 2770Sstevel@tonic-gate tail->b_cont = nmp; 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate while (tail->b_cont) { 2800Sstevel@tonic-gate tail = tail->b_cont; 2810Sstevel@tonic-gate } 2820Sstevel@tonic-gate } 2830Sstevel@tonic-gate tail->b_cont = mp; 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate sctp_sendfail(sctp, meta, SCTP_DATA_UNSENT, error); 2860Sstevel@tonic-gate } 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate void 2890Sstevel@tonic-gate sctp_regift_xmitlist(sctp_t *sctp) 2900Sstevel@tonic-gate { 2910Sstevel@tonic-gate mblk_t *mp; 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate if (!sctp->sctp_recvsendfailevnt) { 2940Sstevel@tonic-gate return; 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate while ((mp = sctp->sctp_xmit_head) != NULL) { 2980Sstevel@tonic-gate sctp->sctp_xmit_head = mp->b_next; 2990Sstevel@tonic-gate mp->b_next = NULL; 3000Sstevel@tonic-gate if (sctp->sctp_xmit_head != NULL) 3010Sstevel@tonic-gate sctp->sctp_xmit_head->b_prev = NULL; 3020Sstevel@tonic-gate sctp_sendfail_event(sctp, mp, 0, B_TRUE); 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate while ((mp = sctp->sctp_xmit_unsent) != NULL) { 3050Sstevel@tonic-gate sctp->sctp_xmit_unsent = mp->b_next; 3060Sstevel@tonic-gate mp->b_next = NULL; 3070Sstevel@tonic-gate sctp_sendfail_event(sctp, mp, 0, B_FALSE); 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate sctp->sctp_xmit_tail = sctp->sctp_xmit_unsent_tail = NULL; 3100Sstevel@tonic-gate sctp->sctp_unacked = sctp->sctp_unsent = 0; 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate void 3140Sstevel@tonic-gate sctp_intf_event(sctp_t *sctp, in6_addr_t addr, int state, int error) 3150Sstevel@tonic-gate { 3160Sstevel@tonic-gate struct sctp_paddr_change *spc; 3170Sstevel@tonic-gate ipaddr_t addr4; 3180Sstevel@tonic-gate struct sockaddr_in *sin; 3190Sstevel@tonic-gate struct sockaddr_in6 *sin6; 3200Sstevel@tonic-gate mblk_t *mp; 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate if (!sctp->sctp_recvpathevnt) { 3230Sstevel@tonic-gate return; 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate if ((mp = allocb(sizeof (*spc), BPRI_MED)) == NULL) { 3270Sstevel@tonic-gate return; 3280Sstevel@tonic-gate } 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate spc = (struct sctp_paddr_change *)mp->b_rptr; 3310Sstevel@tonic-gate spc->spc_type = SCTP_PEER_ADDR_CHANGE; 3320Sstevel@tonic-gate spc->spc_flags = 0; 3330Sstevel@tonic-gate spc->spc_length = sizeof (*spc); 3340Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&addr)) { 3350Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&addr, addr4); 3360Sstevel@tonic-gate sin = (struct sockaddr_in *)&spc->spc_aaddr; 3370Sstevel@tonic-gate sin->sin_family = AF_INET; 3380Sstevel@tonic-gate sin->sin_port = 0; 3390Sstevel@tonic-gate sin->sin_addr.s_addr = addr4; 3400Sstevel@tonic-gate } else { 3410Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&spc->spc_aaddr; 3420Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 3430Sstevel@tonic-gate sin6->sin6_port = 0; 3440Sstevel@tonic-gate sin6->sin6_addr = addr; 3450Sstevel@tonic-gate } 3460Sstevel@tonic-gate spc->spc_state = state; 3470Sstevel@tonic-gate spc->spc_error = error; 3480Sstevel@tonic-gate spc->spc_assoc_id = 0; 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(spc + 1); 3510Sstevel@tonic-gate sctp_notify(sctp, mp, spc->spc_length); 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate void 3550Sstevel@tonic-gate sctp_error_event(sctp_t *sctp, sctp_chunk_hdr_t *ch) 3560Sstevel@tonic-gate { 3570Sstevel@tonic-gate struct sctp_remote_error *sre; 3580Sstevel@tonic-gate mblk_t *mp; 3590Sstevel@tonic-gate size_t len; 3600Sstevel@tonic-gate sctp_parm_hdr_t *errh; 3610Sstevel@tonic-gate uint16_t dlen = 0; 3620Sstevel@tonic-gate uint16_t error = 0; 3630Sstevel@tonic-gate void *dtail = NULL; 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate if (!sctp->sctp_recvpeererr) { 3660Sstevel@tonic-gate return; 3670Sstevel@tonic-gate } 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate if (ntohs(ch->sch_len) > sizeof (*ch)) { 3700Sstevel@tonic-gate errh = (sctp_parm_hdr_t *)(ch + 1); 3710Sstevel@tonic-gate error = ntohs(errh->sph_type); 3720Sstevel@tonic-gate dlen = ntohs(errh->sph_len) - sizeof (*errh); 3730Sstevel@tonic-gate if (dlen > 0) { 3740Sstevel@tonic-gate dtail = errh + 1; 3750Sstevel@tonic-gate } 3760Sstevel@tonic-gate } 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate len = sizeof (*sre) + dlen; 3790Sstevel@tonic-gate if ((mp = allocb(len, BPRI_MED)) == NULL) { 3800Sstevel@tonic-gate return; 3810Sstevel@tonic-gate } 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate sre = (struct sctp_remote_error *)mp->b_rptr; 3840Sstevel@tonic-gate sre->sre_type = SCTP_REMOTE_ERROR; 3850Sstevel@tonic-gate sre->sre_flags = 0; 3860Sstevel@tonic-gate sre->sre_length = len; 3870Sstevel@tonic-gate sre->sre_assoc_id = 0; 3880Sstevel@tonic-gate sre->sre_error = error; 3890Sstevel@tonic-gate if (dtail) { 3900Sstevel@tonic-gate bcopy(dtail, sre + 1, dlen); 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + len; 3940Sstevel@tonic-gate sctp_notify(sctp, mp, len); 3950Sstevel@tonic-gate } 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate void 3980Sstevel@tonic-gate sctp_shutdown_event(sctp_t *sctp) 3990Sstevel@tonic-gate { 4000Sstevel@tonic-gate struct sctp_shutdown_event *sse; 4010Sstevel@tonic-gate mblk_t *mp; 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate if (!sctp->sctp_recvshutdownevnt) { 4040Sstevel@tonic-gate return; 4050Sstevel@tonic-gate } 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate if ((mp = allocb(sizeof (*sse), BPRI_MED)) == NULL) { 4080Sstevel@tonic-gate return; 4090Sstevel@tonic-gate } 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate sse = (struct sctp_shutdown_event *)mp->b_rptr; 4120Sstevel@tonic-gate sse->sse_type = SCTP_SHUTDOWN_EVENT; 4130Sstevel@tonic-gate sse->sse_flags = 0; 4140Sstevel@tonic-gate sse->sse_length = sizeof (*sse); 4150Sstevel@tonic-gate sse->sse_assoc_id = 0; 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sse + 1); 4180Sstevel@tonic-gate sctp_notify(sctp, mp, sse->sse_length); 4190Sstevel@tonic-gate } 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate void 422*5586Skcpoon sctp_adaptation_event(sctp_t *sctp) 4230Sstevel@tonic-gate { 424*5586Skcpoon struct sctp_adaptation_event *sai; 4250Sstevel@tonic-gate mblk_t *mp; 4260Sstevel@tonic-gate 427*5586Skcpoon if (!sctp->sctp_recvalevnt || !sctp->sctp_recv_adaptation) { 4280Sstevel@tonic-gate return; 4290Sstevel@tonic-gate } 4300Sstevel@tonic-gate if ((mp = allocb(sizeof (*sai), BPRI_MED)) == NULL) { 4310Sstevel@tonic-gate return; 4320Sstevel@tonic-gate } 4330Sstevel@tonic-gate 434*5586Skcpoon sai = (struct sctp_adaptation_event *)mp->b_rptr; 435*5586Skcpoon sai->sai_type = SCTP_ADAPTATION_INDICATION; 4360Sstevel@tonic-gate sai->sai_flags = 0; 4370Sstevel@tonic-gate sai->sai_length = sizeof (*sai); 4380Sstevel@tonic-gate sai->sai_assoc_id = 0; 4390Sstevel@tonic-gate /* 4400Sstevel@tonic-gate * Adaptation code delivered in network byte order. 4410Sstevel@tonic-gate */ 442*5586Skcpoon sai->sai_adaptation_ind = sctp->sctp_rx_adaptation_code; 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sai + 1); 4450Sstevel@tonic-gate sctp_notify(sctp, mp, sai->sai_length); 4460Sstevel@tonic-gate 447*5586Skcpoon sctp->sctp_recv_adaptation = 0; /* in case there's a restart later */ 4480Sstevel@tonic-gate } 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate /* Send partial deliver event */ 4510Sstevel@tonic-gate void 4520Sstevel@tonic-gate sctp_partial_delivery_event(sctp_t *sctp) 4530Sstevel@tonic-gate { 4540Sstevel@tonic-gate struct sctp_pdapi_event *pdapi; 4550Sstevel@tonic-gate mblk_t *mp; 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate if (!sctp->sctp_recvpdevnt) 4580Sstevel@tonic-gate return; 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate if ((mp = allocb(sizeof (*pdapi), BPRI_MED)) == NULL) 4610Sstevel@tonic-gate return; 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate pdapi = (struct sctp_pdapi_event *)mp->b_rptr; 4640Sstevel@tonic-gate pdapi->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT; 4650Sstevel@tonic-gate pdapi->pdapi_flags = 0; 4660Sstevel@tonic-gate pdapi->pdapi_length = sizeof (*pdapi); 4670Sstevel@tonic-gate pdapi->pdapi_indication = SCTP_PARTIAL_DELIVERY_ABORTED; 4680Sstevel@tonic-gate pdapi->pdapi_assoc_id = 0; 4690Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(pdapi + 1); 4700Sstevel@tonic-gate sctp_notify(sctp, mp, pdapi->pdapi_length); 4710Sstevel@tonic-gate } 472