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*8348SEric.Yu@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #include <sys/types.h> 270Sstevel@tonic-gate #include <sys/systm.h> 280Sstevel@tonic-gate #include <sys/stream.h> 290Sstevel@tonic-gate #include <sys/cmn_err.h> 300Sstevel@tonic-gate #include <sys/tihdr.h> 310Sstevel@tonic-gate #include <sys/kmem.h> 320Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 330Sstevel@tonic-gate #include <sys/tihdr.h> 340Sstevel@tonic-gate #include <sys/socket.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <netinet/in.h> 370Sstevel@tonic-gate #include <netinet/sctp.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #include <inet/common.h> 40*8348SEric.Yu@Sun.COM #include <inet/ipclassifier.h> 410Sstevel@tonic-gate #include <inet/ip.h> 42*8348SEric.Yu@Sun.COM 430Sstevel@tonic-gate #include "sctp_impl.h" 440Sstevel@tonic-gate 45*8348SEric.Yu@Sun.COM /* ARGSUSED */ 460Sstevel@tonic-gate static void 470Sstevel@tonic-gate sctp_notify(sctp_t *sctp, mblk_t *emp, size_t len) 480Sstevel@tonic-gate { 490Sstevel@tonic-gate struct T_unitdata_ind *tudi; 500Sstevel@tonic-gate mblk_t *mp; 510Sstevel@tonic-gate sctp_faddr_t *fp; 520Sstevel@tonic-gate int32_t rwnd = 0; 53*8348SEric.Yu@Sun.COM int error; 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 */ 790Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&fp->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; 850Sstevel@tonic-gate sin4->sin_port = sctp->sctp_fport; 860Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->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; 940Sstevel@tonic-gate sin6->sin6_port = sctp->sctp_fport; 950Sstevel@tonic-gate sin6->sin6_addr = fp->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 113*8348SEric.Yu@Sun.COM /* 114*8348SEric.Yu@Sun.COM * Override b_flag for SCTP sockfs internal use 115*8348SEric.Yu@Sun.COM */ 116*8348SEric.Yu@Sun.COM mp->b_flag = (short)SCTP_NOTIFICATION; 117*8348SEric.Yu@Sun.COM 118*8348SEric.Yu@Sun.COM rwnd = sctp->sctp_ulp_recv(sctp->sctp_ulpd, mp, msgdsize(mp), 0, 119*8348SEric.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 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 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 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 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 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 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 3630Sstevel@tonic-gate sctp_error_event(sctp_t *sctp, sctp_chunk_hdr_t *ch) 3640Sstevel@tonic-gate { 3650Sstevel@tonic-gate struct sctp_remote_error *sre; 3660Sstevel@tonic-gate mblk_t *mp; 3670Sstevel@tonic-gate size_t len; 3680Sstevel@tonic-gate sctp_parm_hdr_t *errh; 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 3770Sstevel@tonic-gate if (ntohs(ch->sch_len) > sizeof (*ch)) { 3780Sstevel@tonic-gate errh = (sctp_parm_hdr_t *)(ch + 1); 3790Sstevel@tonic-gate error = ntohs(errh->sph_type); 3800Sstevel@tonic-gate dlen = ntohs(errh->sph_len) - sizeof (*errh); 3810Sstevel@tonic-gate if (dlen > 0) { 3820Sstevel@tonic-gate dtail = errh + 1; 3830Sstevel@tonic-gate } 3840Sstevel@tonic-gate } 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate len = sizeof (*sre) + dlen; 3870Sstevel@tonic-gate if ((mp = allocb(len, BPRI_MED)) == NULL) { 3880Sstevel@tonic-gate return; 3890Sstevel@tonic-gate } 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate sre = (struct sctp_remote_error *)mp->b_rptr; 3920Sstevel@tonic-gate sre->sre_type = SCTP_REMOTE_ERROR; 3930Sstevel@tonic-gate sre->sre_flags = 0; 3940Sstevel@tonic-gate sre->sre_length = len; 3950Sstevel@tonic-gate sre->sre_assoc_id = 0; 3960Sstevel@tonic-gate sre->sre_error = error; 3970Sstevel@tonic-gate if (dtail) { 3980Sstevel@tonic-gate bcopy(dtail, sre + 1, dlen); 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + len; 4020Sstevel@tonic-gate sctp_notify(sctp, mp, len); 4030Sstevel@tonic-gate } 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate void 4060Sstevel@tonic-gate sctp_shutdown_event(sctp_t *sctp) 4070Sstevel@tonic-gate { 4080Sstevel@tonic-gate struct sctp_shutdown_event *sse; 4090Sstevel@tonic-gate mblk_t *mp; 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate if (!sctp->sctp_recvshutdownevnt) { 4120Sstevel@tonic-gate return; 4130Sstevel@tonic-gate } 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate if ((mp = allocb(sizeof (*sse), BPRI_MED)) == NULL) { 4160Sstevel@tonic-gate return; 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate sse = (struct sctp_shutdown_event *)mp->b_rptr; 4200Sstevel@tonic-gate sse->sse_type = SCTP_SHUTDOWN_EVENT; 4210Sstevel@tonic-gate sse->sse_flags = 0; 4220Sstevel@tonic-gate sse->sse_length = sizeof (*sse); 4230Sstevel@tonic-gate sse->sse_assoc_id = 0; 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sse + 1); 4260Sstevel@tonic-gate sctp_notify(sctp, mp, sse->sse_length); 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate void 4305586Skcpoon sctp_adaptation_event(sctp_t *sctp) 4310Sstevel@tonic-gate { 4325586Skcpoon struct sctp_adaptation_event *sai; 4330Sstevel@tonic-gate mblk_t *mp; 4340Sstevel@tonic-gate 4355586Skcpoon if (!sctp->sctp_recvalevnt || !sctp->sctp_recv_adaptation) { 4360Sstevel@tonic-gate return; 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate if ((mp = allocb(sizeof (*sai), BPRI_MED)) == NULL) { 4390Sstevel@tonic-gate return; 4400Sstevel@tonic-gate } 4410Sstevel@tonic-gate 4425586Skcpoon sai = (struct sctp_adaptation_event *)mp->b_rptr; 4435586Skcpoon sai->sai_type = SCTP_ADAPTATION_INDICATION; 4440Sstevel@tonic-gate sai->sai_flags = 0; 4450Sstevel@tonic-gate sai->sai_length = sizeof (*sai); 4460Sstevel@tonic-gate sai->sai_assoc_id = 0; 4470Sstevel@tonic-gate /* 4480Sstevel@tonic-gate * Adaptation code delivered in network byte order. 4490Sstevel@tonic-gate */ 4505586Skcpoon sai->sai_adaptation_ind = sctp->sctp_rx_adaptation_code; 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sai + 1); 4530Sstevel@tonic-gate sctp_notify(sctp, mp, sai->sai_length); 4540Sstevel@tonic-gate 4555586Skcpoon sctp->sctp_recv_adaptation = 0; /* in case there's a restart later */ 4560Sstevel@tonic-gate } 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate /* Send partial deliver event */ 4590Sstevel@tonic-gate void 4600Sstevel@tonic-gate sctp_partial_delivery_event(sctp_t *sctp) 4610Sstevel@tonic-gate { 4620Sstevel@tonic-gate struct sctp_pdapi_event *pdapi; 4630Sstevel@tonic-gate mblk_t *mp; 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate if (!sctp->sctp_recvpdevnt) 4660Sstevel@tonic-gate return; 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate if ((mp = allocb(sizeof (*pdapi), BPRI_MED)) == NULL) 4690Sstevel@tonic-gate return; 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate pdapi = (struct sctp_pdapi_event *)mp->b_rptr; 4720Sstevel@tonic-gate pdapi->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT; 4730Sstevel@tonic-gate pdapi->pdapi_flags = 0; 4740Sstevel@tonic-gate pdapi->pdapi_length = sizeof (*pdapi); 4750Sstevel@tonic-gate pdapi->pdapi_indication = SCTP_PARTIAL_DELIVERY_ABORTED; 4760Sstevel@tonic-gate pdapi->pdapi_assoc_id = 0; 4770Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(pdapi + 1); 4780Sstevel@tonic-gate sctp_notify(sctp, mp, pdapi->pdapi_length); 4790Sstevel@tonic-gate } 480