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*11953Sanil.udupa@sun.com * Copyright 2010 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> 408348SEric.Yu@Sun.COM #include <inet/ipclassifier.h> 410Sstevel@tonic-gate #include <inet/ip.h> 428348SEric.Yu@Sun.COM 430Sstevel@tonic-gate #include "sctp_impl.h" 440Sstevel@tonic-gate 458348SEric.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; 538348SEric.Yu@Sun.COM int error; 5411042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 550Sstevel@tonic-gate 560Sstevel@tonic-gate if ((mp = allocb(sizeof (*tudi) + sizeof (void *) + 570Sstevel@tonic-gate sizeof (struct sockaddr_in6), BPRI_HI)) == NULL) { 580Sstevel@tonic-gate /* XXX trouble: don't want to drop events. should queue it. */ 590Sstevel@tonic-gate freemsg(emp); 600Sstevel@tonic-gate return; 610Sstevel@tonic-gate } 620Sstevel@tonic-gate dprint(3, ("sctp_notify: event %d\n", (*(uint16_t *)emp->b_rptr))); 630Sstevel@tonic-gate 640Sstevel@tonic-gate mp->b_datap->db_type = M_PROTO; 650Sstevel@tonic-gate mp->b_flag |= MSGMARK; 660Sstevel@tonic-gate mp->b_rptr += sizeof (void *); /* pointer worth of padding */ 670Sstevel@tonic-gate 680Sstevel@tonic-gate tudi = (struct T_unitdata_ind *)mp->b_rptr; 690Sstevel@tonic-gate tudi->PRIM_type = T_UNITDATA_IND; 700Sstevel@tonic-gate tudi->SRC_offset = sizeof (*tudi); 710Sstevel@tonic-gate tudi->OPT_length = 0; 720Sstevel@tonic-gate tudi->OPT_offset = 0; 730Sstevel@tonic-gate 740Sstevel@tonic-gate fp = sctp->sctp_primary; 750Sstevel@tonic-gate ASSERT(fp); 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * Fill in primary remote address. 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&fp->faddr)) { 810Sstevel@tonic-gate struct sockaddr_in *sin4; 820Sstevel@tonic-gate 830Sstevel@tonic-gate tudi->SRC_length = sizeof (*sin4); 840Sstevel@tonic-gate sin4 = (struct sockaddr_in *)(tudi + 1); 850Sstevel@tonic-gate sin4->sin_family = AF_INET; 8611042SErik.Nordmark@Sun.COM sin4->sin_port = connp->conn_fport; 870Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->faddr, sin4->sin_addr.s_addr); 880Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sin4 + 1); 890Sstevel@tonic-gate } else { 900Sstevel@tonic-gate struct sockaddr_in6 *sin6; 910Sstevel@tonic-gate 920Sstevel@tonic-gate tudi->SRC_length = sizeof (*sin6); 930Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)(tudi + 1); 940Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 9511042SErik.Nordmark@Sun.COM sin6->sin6_port = connp->conn_fport; 960Sstevel@tonic-gate sin6->sin6_addr = fp->faddr; 970Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sin6 + 1); 980Sstevel@tonic-gate } 990Sstevel@tonic-gate 1000Sstevel@tonic-gate mp->b_cont = emp; 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate /* 1030Sstevel@tonic-gate * Notifications are queued regardless of socket rx space. So 1040Sstevel@tonic-gate * we do not decrement sctp_rwnd here as this will confuse the 1050Sstevel@tonic-gate * other side. 1060Sstevel@tonic-gate */ 1070Sstevel@tonic-gate #ifdef DEBUG 1080Sstevel@tonic-gate for (emp = mp->b_cont; emp; emp = emp->b_cont) { 1090Sstevel@tonic-gate rwnd += emp->b_wptr - emp->b_rptr; 1100Sstevel@tonic-gate } 1110Sstevel@tonic-gate ASSERT(len == rwnd); 1120Sstevel@tonic-gate #endif 1130Sstevel@tonic-gate 1148348SEric.Yu@Sun.COM /* 1158348SEric.Yu@Sun.COM * Override b_flag for SCTP sockfs internal use 1168348SEric.Yu@Sun.COM */ 1178348SEric.Yu@Sun.COM mp->b_flag = (short)SCTP_NOTIFICATION; 1188348SEric.Yu@Sun.COM 1198348SEric.Yu@Sun.COM rwnd = sctp->sctp_ulp_recv(sctp->sctp_ulpd, mp, msgdsize(mp), 0, 1208348SEric.Yu@Sun.COM &error, NULL); 1210Sstevel@tonic-gate if (rwnd > sctp->sctp_rwnd) { 1220Sstevel@tonic-gate sctp->sctp_rwnd = rwnd; 1230Sstevel@tonic-gate } 1240Sstevel@tonic-gate } 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate void 1270Sstevel@tonic-gate sctp_assoc_event(sctp_t *sctp, uint16_t state, uint16_t error, 1280Sstevel@tonic-gate sctp_chunk_hdr_t *ch) 1290Sstevel@tonic-gate { 1300Sstevel@tonic-gate struct sctp_assoc_change *sacp; 1310Sstevel@tonic-gate mblk_t *mp; 1320Sstevel@tonic-gate uint16_t ch_len; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate if (!sctp->sctp_recvassocevnt) { 1350Sstevel@tonic-gate return; 1360Sstevel@tonic-gate } 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate ch_len = (ch != NULL) ? ntohs(ch->sch_len) : 0; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate if ((mp = allocb(sizeof (*sacp) + ch_len, BPRI_MED)) == NULL) { 1410Sstevel@tonic-gate return; 1420Sstevel@tonic-gate } 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate sacp = (struct sctp_assoc_change *)mp->b_rptr; 1450Sstevel@tonic-gate sacp->sac_type = SCTP_ASSOC_CHANGE; 1460Sstevel@tonic-gate sacp->sac_flags = sctp->sctp_prsctp_aware ? SCTP_PRSCTP_CAPABLE : 0; 1470Sstevel@tonic-gate sacp->sac_length = sizeof (*sacp) + ch_len; 1480Sstevel@tonic-gate sacp->sac_state = state; 1490Sstevel@tonic-gate sacp->sac_error = error; 1500Sstevel@tonic-gate sacp->sac_outbound_streams = sctp->sctp_num_ostr; 1510Sstevel@tonic-gate sacp->sac_inbound_streams = sctp->sctp_num_istr; 1520Sstevel@tonic-gate sacp->sac_assoc_id = 0; 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate if (ch != NULL) 1550Sstevel@tonic-gate bcopy(ch, sacp + 1, ch_len); 1560Sstevel@tonic-gate mp->b_wptr += sacp->sac_length; 1570Sstevel@tonic-gate sctp_notify(sctp, mp, sacp->sac_length); 1580Sstevel@tonic-gate } 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate /* 1610Sstevel@tonic-gate * Send failure event. Message is expected to have message header still 1620Sstevel@tonic-gate * in place, data follows in subsequent mblk's. 1630Sstevel@tonic-gate */ 1640Sstevel@tonic-gate static void 1650Sstevel@tonic-gate sctp_sendfail(sctp_t *sctp, mblk_t *msghdr, uint16_t flags, int error) 1660Sstevel@tonic-gate { 1670Sstevel@tonic-gate struct sctp_send_failed *sfp; 1680Sstevel@tonic-gate mblk_t *mp; 1690Sstevel@tonic-gate sctp_msg_hdr_t *smh; 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* Allocate a mblk for the notification header */ 1720Sstevel@tonic-gate if ((mp = allocb(sizeof (*sfp), BPRI_MED)) == NULL) { 1730Sstevel@tonic-gate /* give up */ 1740Sstevel@tonic-gate freemsg(msghdr); 1750Sstevel@tonic-gate return; 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate smh = (sctp_msg_hdr_t *)msghdr->b_rptr; 1790Sstevel@tonic-gate sfp = (struct sctp_send_failed *)mp->b_rptr; 1800Sstevel@tonic-gate sfp->ssf_type = SCTP_SEND_FAILED; 1810Sstevel@tonic-gate sfp->ssf_flags = flags; 1820Sstevel@tonic-gate sfp->ssf_length = smh->smh_msglen + sizeof (*sfp); 1830Sstevel@tonic-gate sfp->ssf_error = error; 1840Sstevel@tonic-gate sfp->ssf_assoc_id = 0; 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate bzero(&sfp->ssf_info, sizeof (sfp->ssf_info)); 1870Sstevel@tonic-gate sfp->ssf_info.sinfo_stream = smh->smh_sid; 1880Sstevel@tonic-gate sfp->ssf_info.sinfo_flags = smh->smh_flags; 1890Sstevel@tonic-gate sfp->ssf_info.sinfo_ppid = smh->smh_ppid; 1900Sstevel@tonic-gate sfp->ssf_info.sinfo_context = smh->smh_context; 1910Sstevel@tonic-gate sfp->ssf_info.sinfo_timetolive = TICK_TO_MSEC(smh->smh_ttl); 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sfp + 1); 1940Sstevel@tonic-gate mp->b_cont = msghdr->b_cont; 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate freeb(msghdr); 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate sctp_notify(sctp, mp, sfp->ssf_length); 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* 2030Sstevel@tonic-gate * Send failure when the message has been fully chunkified. 2040Sstevel@tonic-gate */ 2050Sstevel@tonic-gate static void 2060Sstevel@tonic-gate sctp_sendfail_sent(sctp_t *sctp, mblk_t *meta, int error) 2070Sstevel@tonic-gate { 2080Sstevel@tonic-gate mblk_t *mp; 2090Sstevel@tonic-gate mblk_t *nmp; 2100Sstevel@tonic-gate mblk_t *tail; 2110Sstevel@tonic-gate uint16_t flags = SCTP_DATA_SENT; 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate if (!sctp->sctp_recvsendfailevnt) { 2140Sstevel@tonic-gate sctp_free_msg(meta); 2150Sstevel@tonic-gate return; 2160Sstevel@tonic-gate } 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate /* 2190Sstevel@tonic-gate * We need to remove all data_hdr's. 2200Sstevel@tonic-gate */ 2210Sstevel@tonic-gate nmp = meta->b_cont; 2220Sstevel@tonic-gate tail = meta; 2230Sstevel@tonic-gate do { 2240Sstevel@tonic-gate mp = nmp->b_next; 2250Sstevel@tonic-gate nmp->b_next = NULL; 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate /* 2280Sstevel@tonic-gate * If one of the chunks hasn't been sent yet, say that 2290Sstevel@tonic-gate * the message hasn't been sent. 2300Sstevel@tonic-gate */ 2310Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(nmp)) { 2320Sstevel@tonic-gate flags = SCTP_DATA_UNSENT; 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate nmp->b_rptr += sizeof (sctp_data_hdr_t); 2350Sstevel@tonic-gate if (nmp->b_rptr == nmp->b_wptr) { 2360Sstevel@tonic-gate tail->b_cont = nmp->b_cont; 2370Sstevel@tonic-gate freeb(nmp); 2380Sstevel@tonic-gate } else { 2390Sstevel@tonic-gate tail->b_cont = nmp; 2400Sstevel@tonic-gate } 2410Sstevel@tonic-gate while (tail->b_cont) { 2420Sstevel@tonic-gate tail = tail->b_cont; 2430Sstevel@tonic-gate } 2440Sstevel@tonic-gate } while ((nmp = mp) != NULL); 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate sctp_sendfail(sctp, meta, flags, error); 2470Sstevel@tonic-gate } 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate /* 2500Sstevel@tonic-gate * Send failure when the message hasn't been fully chunkified. 2510Sstevel@tonic-gate */ 2520Sstevel@tonic-gate void 2530Sstevel@tonic-gate sctp_sendfail_event(sctp_t *sctp, mblk_t *meta, int error, boolean_t chunkified) 2540Sstevel@tonic-gate { 2550Sstevel@tonic-gate mblk_t *mp; 2560Sstevel@tonic-gate mblk_t *nmp; 2570Sstevel@tonic-gate mblk_t *tail; 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate if (meta == NULL) 2600Sstevel@tonic-gate return; 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate if (!sctp->sctp_recvsendfailevnt) { 2630Sstevel@tonic-gate sctp_free_msg(meta); 2640Sstevel@tonic-gate return; 2650Sstevel@tonic-gate } 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate /* If the message is fully chunkified */ 2680Sstevel@tonic-gate if (chunkified) { 2690Sstevel@tonic-gate sctp_sendfail_sent(sctp, meta, error); 2700Sstevel@tonic-gate return; 2710Sstevel@tonic-gate } 2720Sstevel@tonic-gate /* 2730Sstevel@tonic-gate * Message might be partially chunkified, we need to remove 2740Sstevel@tonic-gate * all data_hdr's. 2750Sstevel@tonic-gate */ 2760Sstevel@tonic-gate mp = meta->b_cont; 2770Sstevel@tonic-gate tail = meta; 2780Sstevel@tonic-gate while ((nmp = mp->b_next) != NULL) { 2790Sstevel@tonic-gate mp->b_next = nmp->b_next; 2800Sstevel@tonic-gate nmp->b_next = NULL; 2810Sstevel@tonic-gate nmp->b_rptr += sizeof (sctp_data_hdr_t); 2820Sstevel@tonic-gate if (nmp->b_rptr == nmp->b_wptr) { 2830Sstevel@tonic-gate tail->b_cont = nmp->b_cont; 2840Sstevel@tonic-gate freeb(nmp); 2850Sstevel@tonic-gate } else { 2860Sstevel@tonic-gate tail->b_cont = nmp; 2870Sstevel@tonic-gate } 2880Sstevel@tonic-gate while (tail->b_cont) { 2890Sstevel@tonic-gate tail = tail->b_cont; 2900Sstevel@tonic-gate } 2910Sstevel@tonic-gate } 2920Sstevel@tonic-gate tail->b_cont = mp; 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate sctp_sendfail(sctp, meta, SCTP_DATA_UNSENT, error); 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate void 2980Sstevel@tonic-gate sctp_regift_xmitlist(sctp_t *sctp) 2990Sstevel@tonic-gate { 3000Sstevel@tonic-gate mblk_t *mp; 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate if (!sctp->sctp_recvsendfailevnt) { 3030Sstevel@tonic-gate return; 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate while ((mp = sctp->sctp_xmit_head) != NULL) { 3070Sstevel@tonic-gate sctp->sctp_xmit_head = mp->b_next; 3080Sstevel@tonic-gate mp->b_next = NULL; 3090Sstevel@tonic-gate if (sctp->sctp_xmit_head != NULL) 3100Sstevel@tonic-gate sctp->sctp_xmit_head->b_prev = NULL; 3110Sstevel@tonic-gate sctp_sendfail_event(sctp, mp, 0, B_TRUE); 3120Sstevel@tonic-gate } 3130Sstevel@tonic-gate while ((mp = sctp->sctp_xmit_unsent) != NULL) { 3140Sstevel@tonic-gate sctp->sctp_xmit_unsent = mp->b_next; 3150Sstevel@tonic-gate mp->b_next = NULL; 3160Sstevel@tonic-gate sctp_sendfail_event(sctp, mp, 0, B_FALSE); 3170Sstevel@tonic-gate } 3180Sstevel@tonic-gate sctp->sctp_xmit_tail = sctp->sctp_xmit_unsent_tail = NULL; 3190Sstevel@tonic-gate sctp->sctp_unacked = sctp->sctp_unsent = 0; 3200Sstevel@tonic-gate } 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate void 3230Sstevel@tonic-gate sctp_intf_event(sctp_t *sctp, in6_addr_t addr, int state, int error) 3240Sstevel@tonic-gate { 3250Sstevel@tonic-gate struct sctp_paddr_change *spc; 3260Sstevel@tonic-gate ipaddr_t addr4; 3270Sstevel@tonic-gate struct sockaddr_in *sin; 3280Sstevel@tonic-gate struct sockaddr_in6 *sin6; 3290Sstevel@tonic-gate mblk_t *mp; 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate if (!sctp->sctp_recvpathevnt) { 3320Sstevel@tonic-gate return; 3330Sstevel@tonic-gate } 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate if ((mp = allocb(sizeof (*spc), BPRI_MED)) == NULL) { 3360Sstevel@tonic-gate return; 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate spc = (struct sctp_paddr_change *)mp->b_rptr; 3400Sstevel@tonic-gate spc->spc_type = SCTP_PEER_ADDR_CHANGE; 3410Sstevel@tonic-gate spc->spc_flags = 0; 3420Sstevel@tonic-gate spc->spc_length = sizeof (*spc); 3430Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&addr)) { 3440Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&addr, addr4); 3450Sstevel@tonic-gate sin = (struct sockaddr_in *)&spc->spc_aaddr; 3460Sstevel@tonic-gate sin->sin_family = AF_INET; 3470Sstevel@tonic-gate sin->sin_port = 0; 3480Sstevel@tonic-gate sin->sin_addr.s_addr = addr4; 3490Sstevel@tonic-gate } else { 3500Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&spc->spc_aaddr; 3510Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 3520Sstevel@tonic-gate sin6->sin6_port = 0; 3530Sstevel@tonic-gate sin6->sin6_addr = addr; 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate spc->spc_state = state; 3560Sstevel@tonic-gate spc->spc_error = error; 3570Sstevel@tonic-gate spc->spc_assoc_id = 0; 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(spc + 1); 3600Sstevel@tonic-gate sctp_notify(sctp, mp, spc->spc_length); 3610Sstevel@tonic-gate } 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate void 364*11953Sanil.udupa@sun.com sctp_error_event(sctp_t *sctp, sctp_chunk_hdr_t *ch, boolean_t is_asconf) 3650Sstevel@tonic-gate { 3660Sstevel@tonic-gate struct sctp_remote_error *sre; 3670Sstevel@tonic-gate mblk_t *mp; 3680Sstevel@tonic-gate size_t len; 369*11953Sanil.udupa@sun.com sctp_parm_hdr_t *errh = NULL; 3700Sstevel@tonic-gate uint16_t dlen = 0; 3710Sstevel@tonic-gate uint16_t error = 0; 3720Sstevel@tonic-gate void *dtail = NULL; 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate if (!sctp->sctp_recvpeererr) { 3750Sstevel@tonic-gate return; 3760Sstevel@tonic-gate } 3770Sstevel@tonic-gate 378*11953Sanil.udupa@sun.com /* 379*11953Sanil.udupa@sun.com * ASCONF PARM error chunks : 380*11953Sanil.udupa@sun.com * PARM_ERROR_IND parm type is always followed by correlation id. 381*11953Sanil.udupa@sun.com * See sctp_asconf_adderr() and sctp_asconf_prepend_errwrap() as to 382*11953Sanil.udupa@sun.com * how these error chunks are build. 383*11953Sanil.udupa@sun.com * error cause wrapper (PARM_ERROR_IND) + correlation id + 384*11953Sanil.udupa@sun.com * error cause + error cause details. 385*11953Sanil.udupa@sun.com * 386*11953Sanil.udupa@sun.com * Regular error chunks : 387*11953Sanil.udupa@sun.com * See sctp_make_err() as to how these error chunks are build. 388*11953Sanil.udupa@sun.com * error chunk header (CHUNK_ERROR) + error cause + error cause details. 389*11953Sanil.udupa@sun.com */ 390*11953Sanil.udupa@sun.com if (is_asconf) { 391*11953Sanil.udupa@sun.com if (ntohs(ch->sch_len) > 392*11953Sanil.udupa@sun.com (sizeof (*ch) + sizeof (uint32_t))) { 393*11953Sanil.udupa@sun.com errh = (sctp_parm_hdr_t *)((char *)ch + 394*11953Sanil.udupa@sun.com sizeof (uint32_t) + sizeof (sctp_parm_hdr_t)); 395*11953Sanil.udupa@sun.com } 396*11953Sanil.udupa@sun.com } else { 397*11953Sanil.udupa@sun.com if (ntohs(ch->sch_len) > sizeof (*ch)) { 398*11953Sanil.udupa@sun.com errh = (sctp_parm_hdr_t *)(ch + 1); 399*11953Sanil.udupa@sun.com } 400*11953Sanil.udupa@sun.com } 401*11953Sanil.udupa@sun.com 402*11953Sanil.udupa@sun.com if (errh != NULL) { 4030Sstevel@tonic-gate error = ntohs(errh->sph_type); 4040Sstevel@tonic-gate dlen = ntohs(errh->sph_len) - sizeof (*errh); 4050Sstevel@tonic-gate if (dlen > 0) { 4060Sstevel@tonic-gate dtail = errh + 1; 4070Sstevel@tonic-gate } 4080Sstevel@tonic-gate } 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate len = sizeof (*sre) + dlen; 4110Sstevel@tonic-gate if ((mp = allocb(len, BPRI_MED)) == NULL) { 4120Sstevel@tonic-gate return; 4130Sstevel@tonic-gate } 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate sre = (struct sctp_remote_error *)mp->b_rptr; 4160Sstevel@tonic-gate sre->sre_type = SCTP_REMOTE_ERROR; 4170Sstevel@tonic-gate sre->sre_flags = 0; 4180Sstevel@tonic-gate sre->sre_length = len; 4190Sstevel@tonic-gate sre->sre_assoc_id = 0; 4200Sstevel@tonic-gate sre->sre_error = error; 421*11953Sanil.udupa@sun.com if (dtail != NULL) { 4220Sstevel@tonic-gate bcopy(dtail, sre + 1, dlen); 4230Sstevel@tonic-gate } 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + len; 4260Sstevel@tonic-gate sctp_notify(sctp, mp, len); 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate void 4300Sstevel@tonic-gate sctp_shutdown_event(sctp_t *sctp) 4310Sstevel@tonic-gate { 4320Sstevel@tonic-gate struct sctp_shutdown_event *sse; 4330Sstevel@tonic-gate mblk_t *mp; 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate if (!sctp->sctp_recvshutdownevnt) { 4360Sstevel@tonic-gate return; 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate if ((mp = allocb(sizeof (*sse), BPRI_MED)) == NULL) { 4400Sstevel@tonic-gate return; 4410Sstevel@tonic-gate } 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate sse = (struct sctp_shutdown_event *)mp->b_rptr; 4440Sstevel@tonic-gate sse->sse_type = SCTP_SHUTDOWN_EVENT; 4450Sstevel@tonic-gate sse->sse_flags = 0; 4460Sstevel@tonic-gate sse->sse_length = sizeof (*sse); 4470Sstevel@tonic-gate sse->sse_assoc_id = 0; 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sse + 1); 4500Sstevel@tonic-gate sctp_notify(sctp, mp, sse->sse_length); 4510Sstevel@tonic-gate } 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate void 4545586Skcpoon sctp_adaptation_event(sctp_t *sctp) 4550Sstevel@tonic-gate { 4565586Skcpoon struct sctp_adaptation_event *sai; 4570Sstevel@tonic-gate mblk_t *mp; 4580Sstevel@tonic-gate 4595586Skcpoon if (!sctp->sctp_recvalevnt || !sctp->sctp_recv_adaptation) { 4600Sstevel@tonic-gate return; 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate if ((mp = allocb(sizeof (*sai), BPRI_MED)) == NULL) { 4630Sstevel@tonic-gate return; 4640Sstevel@tonic-gate } 4650Sstevel@tonic-gate 4665586Skcpoon sai = (struct sctp_adaptation_event *)mp->b_rptr; 4675586Skcpoon sai->sai_type = SCTP_ADAPTATION_INDICATION; 4680Sstevel@tonic-gate sai->sai_flags = 0; 4690Sstevel@tonic-gate sai->sai_length = sizeof (*sai); 4700Sstevel@tonic-gate sai->sai_assoc_id = 0; 4710Sstevel@tonic-gate /* 4720Sstevel@tonic-gate * Adaptation code delivered in network byte order. 4730Sstevel@tonic-gate */ 4745586Skcpoon sai->sai_adaptation_ind = sctp->sctp_rx_adaptation_code; 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(sai + 1); 4770Sstevel@tonic-gate sctp_notify(sctp, mp, sai->sai_length); 4780Sstevel@tonic-gate 4795586Skcpoon sctp->sctp_recv_adaptation = 0; /* in case there's a restart later */ 4800Sstevel@tonic-gate } 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate /* Send partial deliver event */ 4830Sstevel@tonic-gate void 4840Sstevel@tonic-gate sctp_partial_delivery_event(sctp_t *sctp) 4850Sstevel@tonic-gate { 4860Sstevel@tonic-gate struct sctp_pdapi_event *pdapi; 4870Sstevel@tonic-gate mblk_t *mp; 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate if (!sctp->sctp_recvpdevnt) 4900Sstevel@tonic-gate return; 4910Sstevel@tonic-gate 4920Sstevel@tonic-gate if ((mp = allocb(sizeof (*pdapi), BPRI_MED)) == NULL) 4930Sstevel@tonic-gate return; 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate pdapi = (struct sctp_pdapi_event *)mp->b_rptr; 4960Sstevel@tonic-gate pdapi->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT; 4970Sstevel@tonic-gate pdapi->pdapi_flags = 0; 4980Sstevel@tonic-gate pdapi->pdapi_length = sizeof (*pdapi); 4990Sstevel@tonic-gate pdapi->pdapi_indication = SCTP_PARTIAL_DELIVERY_ABORTED; 5000Sstevel@tonic-gate pdapi->pdapi_assoc_id = 0; 5010Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(pdapi + 1); 5020Sstevel@tonic-gate sctp_notify(sctp, mp, pdapi->pdapi_length); 5030Sstevel@tonic-gate } 504