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 51676Sjpk * Common Development and Distribution License (the "License"). 61676Sjpk * 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 */ 211735Skcpoon 220Sstevel@tonic-gate /* 238778SErik.Nordmark@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #include <sys/types.h> 280Sstevel@tonic-gate #include <sys/systm.h> 290Sstevel@tonic-gate #include <sys/stream.h> 300Sstevel@tonic-gate #include <sys/cmn_err.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 #include <sys/strsun.h> 360Sstevel@tonic-gate #include <sys/strsubr.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <netinet/in.h> 390Sstevel@tonic-gate #include <netinet/ip6.h> 400Sstevel@tonic-gate #include <netinet/tcp_seq.h> 410Sstevel@tonic-gate #include <netinet/sctp.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate #include <inet/common.h> 440Sstevel@tonic-gate #include <inet/ip.h> 4511042SErik.Nordmark@Sun.COM #include <inet/ip_if.h> 460Sstevel@tonic-gate #include <inet/ip6.h> 470Sstevel@tonic-gate #include <inet/mib2.h> 480Sstevel@tonic-gate #include <inet/ipclassifier.h> 490Sstevel@tonic-gate #include <inet/ipp_common.h> 500Sstevel@tonic-gate #include <inet/ipsec_impl.h> 510Sstevel@tonic-gate #include <inet/sctp_ip.h> 520Sstevel@tonic-gate 530Sstevel@tonic-gate #include "sctp_impl.h" 540Sstevel@tonic-gate #include "sctp_asconf.h" 550Sstevel@tonic-gate #include "sctp_addr.h" 560Sstevel@tonic-gate 570Sstevel@tonic-gate static struct kmem_cache *sctp_kmem_set_cache; 580Sstevel@tonic-gate 590Sstevel@tonic-gate /* 600Sstevel@tonic-gate * PR-SCTP comments. 610Sstevel@tonic-gate * 620Sstevel@tonic-gate * When we get a valid Forward TSN chunk, we check the fragment list for this 630Sstevel@tonic-gate * SSN and preceeding SSNs free all them. Further, if this Forward TSN causes 640Sstevel@tonic-gate * the next expected SSN to be present in the stream queue, we deliver any 650Sstevel@tonic-gate * such stranded messages upstream. We also update the SACK info. appropriately. 660Sstevel@tonic-gate * When checking for advancing the cumulative ack (in sctp_cumack()) we must 670Sstevel@tonic-gate * check for abandoned chunks and messages. While traversing the tramsmit 680Sstevel@tonic-gate * list if we come across an abandoned chunk, we can skip the message (i.e. 690Sstevel@tonic-gate * take it out of the (re)transmit list) since this message, and hence this 700Sstevel@tonic-gate * chunk, has been marked abandoned by sctp_rexmit(). If we come across an 710Sstevel@tonic-gate * unsent chunk for a message this now abandoned we need to check if a 720Sstevel@tonic-gate * Forward TSN needs to be sent, this could be a case where we deferred sending 730Sstevel@tonic-gate * a Forward TSN in sctp_get_msg_to_send(). Further, after processing a 740Sstevel@tonic-gate * SACK we check if the Advanced peer ack point can be moved ahead, i.e. 750Sstevel@tonic-gate * if we can send a Forward TSN via sctp_check_abandoned_data(). 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate void 780Sstevel@tonic-gate sctp_free_set(sctp_set_t *s) 790Sstevel@tonic-gate { 800Sstevel@tonic-gate sctp_set_t *p; 810Sstevel@tonic-gate 820Sstevel@tonic-gate while (s) { 830Sstevel@tonic-gate p = s->next; 840Sstevel@tonic-gate kmem_cache_free(sctp_kmem_set_cache, s); 850Sstevel@tonic-gate s = p; 860Sstevel@tonic-gate } 870Sstevel@tonic-gate } 880Sstevel@tonic-gate 890Sstevel@tonic-gate static void 900Sstevel@tonic-gate sctp_ack_add(sctp_set_t **head, uint32_t tsn, int *num) 910Sstevel@tonic-gate { 920Sstevel@tonic-gate sctp_set_t *p, *t; 930Sstevel@tonic-gate 940Sstevel@tonic-gate if (head == NULL || num == NULL) 950Sstevel@tonic-gate return; 960Sstevel@tonic-gate 970Sstevel@tonic-gate ASSERT(*num >= 0); 980Sstevel@tonic-gate ASSERT((*num == 0 && *head == NULL) || (*num > 0 && *head != NULL)); 990Sstevel@tonic-gate 1000Sstevel@tonic-gate if (*head == NULL) { 1010Sstevel@tonic-gate *head = kmem_cache_alloc(sctp_kmem_set_cache, KM_NOSLEEP); 1020Sstevel@tonic-gate if (*head == NULL) 1030Sstevel@tonic-gate return; 1040Sstevel@tonic-gate (*head)->prev = (*head)->next = NULL; 1050Sstevel@tonic-gate (*head)->begin = tsn; 1060Sstevel@tonic-gate (*head)->end = tsn; 1070Sstevel@tonic-gate *num = 1; 1080Sstevel@tonic-gate return; 1090Sstevel@tonic-gate } 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate ASSERT((*head)->prev == NULL); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* 1140Sstevel@tonic-gate * Handle this special case here so we don't have to check 1150Sstevel@tonic-gate * for it each time in the loop. 1160Sstevel@tonic-gate */ 1170Sstevel@tonic-gate if (SEQ_LT(tsn + 1, (*head)->begin)) { 1180Sstevel@tonic-gate /* add a new set, and move the head pointer */ 1190Sstevel@tonic-gate t = kmem_cache_alloc(sctp_kmem_set_cache, KM_NOSLEEP); 1200Sstevel@tonic-gate if (t == NULL) 1210Sstevel@tonic-gate return; 1220Sstevel@tonic-gate t->next = *head; 1230Sstevel@tonic-gate t->prev = NULL; 1240Sstevel@tonic-gate (*head)->prev = t; 1250Sstevel@tonic-gate t->begin = tsn; 1260Sstevel@tonic-gate t->end = tsn; 1270Sstevel@tonic-gate (*num)++; 1280Sstevel@tonic-gate *head = t; 1290Sstevel@tonic-gate return; 1300Sstevel@tonic-gate } 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate * We need to handle the following cases, where p points to 1340Sstevel@tonic-gate * the current set (as we walk through the loop): 1350Sstevel@tonic-gate * 1360Sstevel@tonic-gate * 1. tsn is entirely less than p; create a new set before p. 1370Sstevel@tonic-gate * 2. tsn borders p from less; coalesce p with tsn. 1380Sstevel@tonic-gate * 3. tsn is withing p; do nothing. 1390Sstevel@tonic-gate * 4. tsn borders p from greater; coalesce p with tsn. 1400Sstevel@tonic-gate * 4a. p may now border p->next from less; if so, coalesce those 1410Sstevel@tonic-gate * two sets. 1420Sstevel@tonic-gate * 5. tsn is entirely greater then all sets; add a new set at 1430Sstevel@tonic-gate * the end. 1440Sstevel@tonic-gate */ 1450Sstevel@tonic-gate for (p = *head; ; p = p->next) { 1460Sstevel@tonic-gate if (SEQ_LT(tsn + 1, p->begin)) { 1470Sstevel@tonic-gate /* 1: add a new set before p. */ 1480Sstevel@tonic-gate t = kmem_cache_alloc(sctp_kmem_set_cache, KM_NOSLEEP); 1490Sstevel@tonic-gate if (t == NULL) 1500Sstevel@tonic-gate return; 1510Sstevel@tonic-gate t->next = p; 1520Sstevel@tonic-gate t->prev = NULL; 1530Sstevel@tonic-gate t->begin = tsn; 1540Sstevel@tonic-gate t->end = tsn; 1550Sstevel@tonic-gate if (p->prev) { 1560Sstevel@tonic-gate t->prev = p->prev; 1570Sstevel@tonic-gate p->prev->next = t; 1580Sstevel@tonic-gate } 1590Sstevel@tonic-gate p->prev = t; 1600Sstevel@tonic-gate (*num)++; 1610Sstevel@tonic-gate return; 1620Sstevel@tonic-gate } 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate if ((tsn + 1) == p->begin) { 1650Sstevel@tonic-gate /* 2: adjust p->begin */ 1660Sstevel@tonic-gate p->begin = tsn; 1670Sstevel@tonic-gate return; 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate if (SEQ_GEQ(tsn, p->begin) && SEQ_LEQ(tsn, p->end)) { 1710Sstevel@tonic-gate /* 3; do nothing */ 1720Sstevel@tonic-gate return; 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate if ((p->end + 1) == tsn) { 1760Sstevel@tonic-gate /* 4; adjust p->end */ 1770Sstevel@tonic-gate p->end = tsn; 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate if (p->next != NULL && (tsn + 1) == p->next->begin) { 1800Sstevel@tonic-gate /* 4a: coalesce p and p->next */ 1810Sstevel@tonic-gate t = p->next; 1820Sstevel@tonic-gate p->end = t->end; 1830Sstevel@tonic-gate p->next = t->next; 1840Sstevel@tonic-gate if (t->next != NULL) 1850Sstevel@tonic-gate t->next->prev = p; 1860Sstevel@tonic-gate kmem_cache_free(sctp_kmem_set_cache, t); 1870Sstevel@tonic-gate (*num)--; 1880Sstevel@tonic-gate } 1890Sstevel@tonic-gate return; 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate if (p->next == NULL) { 1930Sstevel@tonic-gate /* 5: add new set at the end */ 1940Sstevel@tonic-gate t = kmem_cache_alloc(sctp_kmem_set_cache, KM_NOSLEEP); 1950Sstevel@tonic-gate if (t == NULL) 1960Sstevel@tonic-gate return; 1970Sstevel@tonic-gate t->next = NULL; 1980Sstevel@tonic-gate t->prev = p; 1990Sstevel@tonic-gate t->begin = tsn; 2000Sstevel@tonic-gate t->end = tsn; 2010Sstevel@tonic-gate p->next = t; 2020Sstevel@tonic-gate (*num)++; 2030Sstevel@tonic-gate return; 2040Sstevel@tonic-gate } 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate if (SEQ_GT(tsn, p->end + 1)) 2070Sstevel@tonic-gate continue; 2080Sstevel@tonic-gate } 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate static void 2120Sstevel@tonic-gate sctp_ack_rem(sctp_set_t **head, uint32_t end, int *num) 2130Sstevel@tonic-gate { 2140Sstevel@tonic-gate sctp_set_t *p, *t; 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate if (head == NULL || *head == NULL || num == NULL) 2170Sstevel@tonic-gate return; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate /* Nothing to remove */ 2200Sstevel@tonic-gate if (SEQ_LT(end, (*head)->begin)) 2210Sstevel@tonic-gate return; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate /* Find out where to start removing sets */ 2240Sstevel@tonic-gate for (p = *head; p->next; p = p->next) { 2250Sstevel@tonic-gate if (SEQ_LEQ(end, p->end)) 2260Sstevel@tonic-gate break; 2270Sstevel@tonic-gate } 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate if (SEQ_LT(end, p->end) && SEQ_GEQ(end, p->begin)) { 2300Sstevel@tonic-gate /* adjust p */ 2310Sstevel@tonic-gate p->begin = end + 1; 2320Sstevel@tonic-gate /* all done */ 2330Sstevel@tonic-gate if (p == *head) 2340Sstevel@tonic-gate return; 2350Sstevel@tonic-gate } else if (SEQ_GEQ(end, p->end)) { 2360Sstevel@tonic-gate /* remove this set too */ 2370Sstevel@tonic-gate p = p->next; 2380Sstevel@tonic-gate } 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate /* unlink everything before this set */ 2410Sstevel@tonic-gate t = *head; 2420Sstevel@tonic-gate *head = p; 2430Sstevel@tonic-gate if (p != NULL && p->prev != NULL) { 2440Sstevel@tonic-gate p->prev->next = NULL; 2450Sstevel@tonic-gate p->prev = NULL; 2460Sstevel@tonic-gate } 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate sctp_free_set(t); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* recount the number of sets */ 2510Sstevel@tonic-gate *num = 0; 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate for (p = *head; p != NULL; p = p->next) 2540Sstevel@tonic-gate (*num)++; 2550Sstevel@tonic-gate } 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate void 2580Sstevel@tonic-gate sctp_sets_init() 2590Sstevel@tonic-gate { 2600Sstevel@tonic-gate sctp_kmem_set_cache = kmem_cache_create("sctp_set_cache", 2610Sstevel@tonic-gate sizeof (sctp_set_t), 0, NULL, NULL, NULL, NULL, 2620Sstevel@tonic-gate NULL, 0); 2630Sstevel@tonic-gate } 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate void 2660Sstevel@tonic-gate sctp_sets_fini() 2670Sstevel@tonic-gate { 2680Sstevel@tonic-gate kmem_cache_destroy(sctp_kmem_set_cache); 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate sctp_chunk_hdr_t * 2720Sstevel@tonic-gate sctp_first_chunk(uchar_t *rptr, ssize_t remaining) 2730Sstevel@tonic-gate { 2740Sstevel@tonic-gate sctp_chunk_hdr_t *ch; 2750Sstevel@tonic-gate uint16_t ch_len; 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate if (remaining < sizeof (*ch)) { 2780Sstevel@tonic-gate return (NULL); 2790Sstevel@tonic-gate } 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate ch = (sctp_chunk_hdr_t *)rptr; 2820Sstevel@tonic-gate ch_len = ntohs(ch->sch_len); 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate if (ch_len < sizeof (*ch) || remaining < ch_len) { 2850Sstevel@tonic-gate return (NULL); 2860Sstevel@tonic-gate } 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate return (ch); 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate sctp_chunk_hdr_t * 2920Sstevel@tonic-gate sctp_next_chunk(sctp_chunk_hdr_t *ch, ssize_t *remaining) 2930Sstevel@tonic-gate { 2940Sstevel@tonic-gate int pad; 2950Sstevel@tonic-gate uint16_t ch_len; 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate if (!ch) { 2980Sstevel@tonic-gate return (NULL); 2990Sstevel@tonic-gate } 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate ch_len = ntohs(ch->sch_len); 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate if ((pad = ch_len & (SCTP_ALIGN - 1)) != 0) { 3040Sstevel@tonic-gate pad = SCTP_ALIGN - pad; 3050Sstevel@tonic-gate } 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate *remaining -= (ch_len + pad); 3080Sstevel@tonic-gate ch = (sctp_chunk_hdr_t *)((char *)ch + ch_len + pad); 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate return (sctp_first_chunk((uchar_t *)ch, *remaining)); 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate /* 3140Sstevel@tonic-gate * Attach ancillary data to a received SCTP segments. 3150Sstevel@tonic-gate * If the source address (fp) is not the primary, send up a 3160Sstevel@tonic-gate * unitdata_ind so recvfrom() can populate the msg_name field. 3170Sstevel@tonic-gate * If ancillary data is also requested, we append it to the 3180Sstevel@tonic-gate * unitdata_req. Otherwise, we just send up an optdata_ind. 3190Sstevel@tonic-gate */ 3200Sstevel@tonic-gate static int 3210Sstevel@tonic-gate sctp_input_add_ancillary(sctp_t *sctp, mblk_t **mp, sctp_data_hdr_t *dcp, 32211042SErik.Nordmark@Sun.COM sctp_faddr_t *fp, ip_pkt_t *ipp, ip_recv_attr_t *ira) 3230Sstevel@tonic-gate { 3240Sstevel@tonic-gate struct T_unitdata_ind *tudi; 3250Sstevel@tonic-gate int optlen; 3260Sstevel@tonic-gate int hdrlen; 3270Sstevel@tonic-gate uchar_t *optptr; 3280Sstevel@tonic-gate struct cmsghdr *cmsg; 3290Sstevel@tonic-gate mblk_t *mp1; 3300Sstevel@tonic-gate struct sockaddr_in6 sin_buf[1]; 3310Sstevel@tonic-gate struct sockaddr_in6 *sin6; 3320Sstevel@tonic-gate struct sockaddr_in *sin4; 33311042SErik.Nordmark@Sun.COM crb_t addflag; /* Which pieces to add */ 33411042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate sin4 = NULL; 3370Sstevel@tonic-gate sin6 = NULL; 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate optlen = hdrlen = 0; 34011042SErik.Nordmark@Sun.COM addflag.crb_all = 0; 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate /* Figure out address size */ 34311042SErik.Nordmark@Sun.COM if (connp->conn_family == AF_INET) { 3440Sstevel@tonic-gate sin4 = (struct sockaddr_in *)sin_buf; 3450Sstevel@tonic-gate sin4->sin_family = AF_INET; 34611042SErik.Nordmark@Sun.COM sin4->sin_port = connp->conn_fport; 3470Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->faddr, sin4->sin_addr.s_addr); 3480Sstevel@tonic-gate hdrlen = sizeof (*tudi) + sizeof (*sin4); 3490Sstevel@tonic-gate } else { 3500Sstevel@tonic-gate sin6 = sin_buf; 3510Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 35211042SErik.Nordmark@Sun.COM sin6->sin6_port = connp->conn_fport; 3530Sstevel@tonic-gate sin6->sin6_addr = fp->faddr; 3540Sstevel@tonic-gate hdrlen = sizeof (*tudi) + sizeof (*sin6); 3550Sstevel@tonic-gate } 3560Sstevel@tonic-gate /* If app asked to receive send / recv info */ 35711042SErik.Nordmark@Sun.COM if (sctp->sctp_recvsndrcvinfo) 3580Sstevel@tonic-gate optlen += sizeof (*cmsg) + sizeof (struct sctp_sndrcvinfo); 35911042SErik.Nordmark@Sun.COM 36011042SErik.Nordmark@Sun.COM if (connp->conn_recv_ancillary.crb_all == 0) 3610Sstevel@tonic-gate goto noancillary; 3620Sstevel@tonic-gate 36311042SErik.Nordmark@Sun.COM if (connp->conn_recv_ancillary.crb_ip_recvpktinfo && 36411042SErik.Nordmark@Sun.COM ira->ira_ruifindex != sctp->sctp_recvifindex) { 3650Sstevel@tonic-gate optlen += sizeof (*cmsg) + sizeof (struct in6_pktinfo); 3660Sstevel@tonic-gate if (hdrlen == 0) 3670Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 36811042SErik.Nordmark@Sun.COM addflag.crb_ip_recvpktinfo = 1; 3690Sstevel@tonic-gate } 3700Sstevel@tonic-gate /* If app asked for hoplimit and it has changed ... */ 37111042SErik.Nordmark@Sun.COM if (connp->conn_recv_ancillary.crb_ipv6_recvhoplimit && 37211042SErik.Nordmark@Sun.COM ipp->ipp_hoplimit != sctp->sctp_recvhops) { 3730Sstevel@tonic-gate optlen += sizeof (*cmsg) + sizeof (uint_t); 3740Sstevel@tonic-gate if (hdrlen == 0) 3750Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 37611042SErik.Nordmark@Sun.COM addflag.crb_ipv6_recvhoplimit = 1; 37711042SErik.Nordmark@Sun.COM } 37811042SErik.Nordmark@Sun.COM /* If app asked for tclass and it has changed ... */ 37911042SErik.Nordmark@Sun.COM if (connp->conn_recv_ancillary.crb_ipv6_recvtclass && 38011042SErik.Nordmark@Sun.COM ipp->ipp_tclass != sctp->sctp_recvtclass) { 38111042SErik.Nordmark@Sun.COM optlen += sizeof (struct T_opthdr) + sizeof (uint_t); 38211042SErik.Nordmark@Sun.COM if (hdrlen == 0) 38311042SErik.Nordmark@Sun.COM hdrlen = sizeof (struct T_unitdata_ind); 38411042SErik.Nordmark@Sun.COM addflag.crb_ipv6_recvtclass = 1; 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate /* If app asked for hopbyhop headers and it has changed ... */ 38711042SErik.Nordmark@Sun.COM if (connp->conn_recv_ancillary.crb_ipv6_recvhopopts && 3881676Sjpk ip_cmpbuf(sctp->sctp_hopopts, sctp->sctp_hopoptslen, 3894964Skcpoon (ipp->ipp_fields & IPPF_HOPOPTS), 3904964Skcpoon ipp->ipp_hopopts, ipp->ipp_hopoptslen)) { 3911676Sjpk optlen += sizeof (*cmsg) + ipp->ipp_hopoptslen - 3921676Sjpk sctp->sctp_v6label_len; 3930Sstevel@tonic-gate if (hdrlen == 0) 3940Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 39511042SErik.Nordmark@Sun.COM addflag.crb_ipv6_recvhopopts = 1; 3961676Sjpk if (!ip_allocbuf((void **)&sctp->sctp_hopopts, 3970Sstevel@tonic-gate &sctp->sctp_hopoptslen, 3980Sstevel@tonic-gate (ipp->ipp_fields & IPPF_HOPOPTS), 3990Sstevel@tonic-gate ipp->ipp_hopopts, ipp->ipp_hopoptslen)) 4000Sstevel@tonic-gate return (-1); 4010Sstevel@tonic-gate } 4020Sstevel@tonic-gate /* If app asked for dst headers before routing headers ... */ 40311042SErik.Nordmark@Sun.COM if (connp->conn_recv_ancillary.crb_ipv6_recvrthdrdstopts && 40411042SErik.Nordmark@Sun.COM ip_cmpbuf(sctp->sctp_rthdrdstopts, sctp->sctp_rthdrdstoptslen, 40511042SErik.Nordmark@Sun.COM (ipp->ipp_fields & IPPF_RTHDRDSTOPTS), 40611042SErik.Nordmark@Sun.COM ipp->ipp_rthdrdstopts, ipp->ipp_rthdrdstoptslen)) { 40711042SErik.Nordmark@Sun.COM optlen += sizeof (*cmsg) + ipp->ipp_rthdrdstoptslen; 4080Sstevel@tonic-gate if (hdrlen == 0) 4090Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 41011042SErik.Nordmark@Sun.COM addflag.crb_ipv6_recvrthdrdstopts = 1; 41111042SErik.Nordmark@Sun.COM if (!ip_allocbuf((void **)&sctp->sctp_rthdrdstopts, 41211042SErik.Nordmark@Sun.COM &sctp->sctp_rthdrdstoptslen, 41311042SErik.Nordmark@Sun.COM (ipp->ipp_fields & IPPF_RTHDRDSTOPTS), 41411042SErik.Nordmark@Sun.COM ipp->ipp_rthdrdstopts, ipp->ipp_rthdrdstoptslen)) 4150Sstevel@tonic-gate return (-1); 4160Sstevel@tonic-gate } 4170Sstevel@tonic-gate /* If app asked for routing headers and it has changed ... */ 41811042SErik.Nordmark@Sun.COM if (connp->conn_recv_ancillary.crb_ipv6_recvrthdr && 41911042SErik.Nordmark@Sun.COM ip_cmpbuf(sctp->sctp_rthdr, sctp->sctp_rthdrlen, 42011042SErik.Nordmark@Sun.COM (ipp->ipp_fields & IPPF_RTHDR), 42111042SErik.Nordmark@Sun.COM ipp->ipp_rthdr, ipp->ipp_rthdrlen)) { 42211042SErik.Nordmark@Sun.COM optlen += sizeof (*cmsg) + ipp->ipp_rthdrlen; 42311042SErik.Nordmark@Sun.COM if (hdrlen == 0) 42411042SErik.Nordmark@Sun.COM hdrlen = sizeof (struct T_unitdata_ind); 42511042SErik.Nordmark@Sun.COM addflag.crb_ipv6_recvrthdr = 1; 42611042SErik.Nordmark@Sun.COM if (!ip_allocbuf((void **)&sctp->sctp_rthdr, 42711042SErik.Nordmark@Sun.COM &sctp->sctp_rthdrlen, 4280Sstevel@tonic-gate (ipp->ipp_fields & IPPF_RTHDR), 42911042SErik.Nordmark@Sun.COM ipp->ipp_rthdr, ipp->ipp_rthdrlen)) 43011042SErik.Nordmark@Sun.COM return (-1); 4310Sstevel@tonic-gate } 4320Sstevel@tonic-gate /* If app asked for dest headers and it has changed ... */ 43311042SErik.Nordmark@Sun.COM if (connp->conn_recv_ancillary.crb_ipv6_recvdstopts && 4341676Sjpk ip_cmpbuf(sctp->sctp_dstopts, sctp->sctp_dstoptslen, 4354964Skcpoon (ipp->ipp_fields & IPPF_DSTOPTS), 4364964Skcpoon ipp->ipp_dstopts, ipp->ipp_dstoptslen)) { 4370Sstevel@tonic-gate optlen += sizeof (*cmsg) + ipp->ipp_dstoptslen; 4380Sstevel@tonic-gate if (hdrlen == 0) 4390Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 44011042SErik.Nordmark@Sun.COM addflag.crb_ipv6_recvdstopts = 1; 4411676Sjpk if (!ip_allocbuf((void **)&sctp->sctp_dstopts, 4420Sstevel@tonic-gate &sctp->sctp_dstoptslen, 4430Sstevel@tonic-gate (ipp->ipp_fields & IPPF_DSTOPTS), 4440Sstevel@tonic-gate ipp->ipp_dstopts, ipp->ipp_dstoptslen)) 4450Sstevel@tonic-gate return (-1); 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate noancillary: 4480Sstevel@tonic-gate /* Nothing to add */ 4490Sstevel@tonic-gate if (hdrlen == 0) 4500Sstevel@tonic-gate return (-1); 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate mp1 = allocb(hdrlen + optlen + sizeof (void *), BPRI_MED); 4530Sstevel@tonic-gate if (mp1 == NULL) 4540Sstevel@tonic-gate return (-1); 4550Sstevel@tonic-gate mp1->b_cont = *mp; 4560Sstevel@tonic-gate *mp = mp1; 4570Sstevel@tonic-gate mp1->b_rptr += sizeof (void *); /* pointer worth of padding */ 4580Sstevel@tonic-gate mp1->b_wptr = mp1->b_rptr + hdrlen + optlen; 4590Sstevel@tonic-gate DB_TYPE(mp1) = M_PROTO; 4600Sstevel@tonic-gate tudi = (struct T_unitdata_ind *)mp1->b_rptr; 4610Sstevel@tonic-gate tudi->PRIM_type = T_UNITDATA_IND; 4620Sstevel@tonic-gate tudi->SRC_length = sin4 ? sizeof (*sin4) : sizeof (*sin6); 4630Sstevel@tonic-gate tudi->SRC_offset = sizeof (*tudi); 4640Sstevel@tonic-gate tudi->OPT_offset = sizeof (*tudi) + tudi->SRC_length; 4650Sstevel@tonic-gate tudi->OPT_length = optlen; 4660Sstevel@tonic-gate if (sin4) { 4670Sstevel@tonic-gate bcopy(sin4, tudi + 1, sizeof (*sin4)); 4680Sstevel@tonic-gate } else { 4690Sstevel@tonic-gate bcopy(sin6, tudi + 1, sizeof (*sin6)); 4700Sstevel@tonic-gate } 4710Sstevel@tonic-gate optptr = (uchar_t *)tudi + tudi->OPT_offset; 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate if (sctp->sctp_recvsndrcvinfo) { 4740Sstevel@tonic-gate /* XXX need backout method if memory allocation fails. */ 4750Sstevel@tonic-gate struct sctp_sndrcvinfo *sri; 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 4780Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_SCTP; 4790Sstevel@tonic-gate cmsg->cmsg_type = SCTP_SNDRCV; 4800Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + sizeof (*sri); 4810Sstevel@tonic-gate optptr += sizeof (*cmsg); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate sri = (struct sctp_sndrcvinfo *)(cmsg + 1); 4840Sstevel@tonic-gate ASSERT(OK_32PTR(sri)); 4850Sstevel@tonic-gate sri->sinfo_stream = ntohs(dcp->sdh_sid); 4860Sstevel@tonic-gate sri->sinfo_ssn = ntohs(dcp->sdh_ssn); 4870Sstevel@tonic-gate if (SCTP_DATA_GET_UBIT(dcp)) { 4880Sstevel@tonic-gate sri->sinfo_flags = MSG_UNORDERED; 4890Sstevel@tonic-gate } else { 4900Sstevel@tonic-gate sri->sinfo_flags = 0; 4910Sstevel@tonic-gate } 4920Sstevel@tonic-gate sri->sinfo_ppid = dcp->sdh_payload_id; 4930Sstevel@tonic-gate sri->sinfo_context = 0; 4940Sstevel@tonic-gate sri->sinfo_timetolive = 0; 4950Sstevel@tonic-gate sri->sinfo_tsn = ntohl(dcp->sdh_tsn); 4960Sstevel@tonic-gate sri->sinfo_cumtsn = sctp->sctp_ftsn; 4970Sstevel@tonic-gate sri->sinfo_assoc_id = 0; 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate optptr += sizeof (*sri); 5000Sstevel@tonic-gate } 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate /* 5030Sstevel@tonic-gate * If app asked for pktinfo and the index has changed ... 5040Sstevel@tonic-gate * Note that the local address never changes for the connection. 5050Sstevel@tonic-gate */ 50611042SErik.Nordmark@Sun.COM if (addflag.crb_ip_recvpktinfo) { 5070Sstevel@tonic-gate struct in6_pktinfo *pkti; 50811042SErik.Nordmark@Sun.COM uint_t ifindex; 50911042SErik.Nordmark@Sun.COM 51011042SErik.Nordmark@Sun.COM ifindex = ira->ira_ruifindex; 5110Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5120Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5130Sstevel@tonic-gate cmsg->cmsg_type = IPV6_PKTINFO; 5140Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + sizeof (*pkti); 5150Sstevel@tonic-gate optptr += sizeof (*cmsg); 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate pkti = (struct in6_pktinfo *)optptr; 51811042SErik.Nordmark@Sun.COM if (connp->conn_family == AF_INET6) 5190Sstevel@tonic-gate pkti->ipi6_addr = sctp->sctp_ip6h->ip6_src; 5200Sstevel@tonic-gate else 5210Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(sctp->sctp_ipha->ipha_src, 5220Sstevel@tonic-gate &pkti->ipi6_addr); 52311042SErik.Nordmark@Sun.COM 52411042SErik.Nordmark@Sun.COM pkti->ipi6_ifindex = ifindex; 5250Sstevel@tonic-gate optptr += sizeof (*pkti); 5260Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5270Sstevel@tonic-gate /* Save as "last" value */ 52811042SErik.Nordmark@Sun.COM sctp->sctp_recvifindex = ifindex; 5290Sstevel@tonic-gate } 5300Sstevel@tonic-gate /* If app asked for hoplimit and it has changed ... */ 53111042SErik.Nordmark@Sun.COM if (addflag.crb_ipv6_recvhoplimit) { 5320Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5330Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5340Sstevel@tonic-gate cmsg->cmsg_type = IPV6_HOPLIMIT; 5350Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + sizeof (uint_t); 5360Sstevel@tonic-gate optptr += sizeof (*cmsg); 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate *(uint_t *)optptr = ipp->ipp_hoplimit; 5390Sstevel@tonic-gate optptr += sizeof (uint_t); 5400Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5410Sstevel@tonic-gate /* Save as "last" value */ 5420Sstevel@tonic-gate sctp->sctp_recvhops = ipp->ipp_hoplimit; 5430Sstevel@tonic-gate } 54411042SErik.Nordmark@Sun.COM /* If app asked for tclass and it has changed ... */ 54511042SErik.Nordmark@Sun.COM if (addflag.crb_ipv6_recvtclass) { 54611042SErik.Nordmark@Sun.COM cmsg = (struct cmsghdr *)optptr; 54711042SErik.Nordmark@Sun.COM cmsg->cmsg_level = IPPROTO_IPV6; 54811042SErik.Nordmark@Sun.COM cmsg->cmsg_type = IPV6_TCLASS; 54911042SErik.Nordmark@Sun.COM cmsg->cmsg_len = sizeof (*cmsg) + sizeof (uint_t); 55011042SErik.Nordmark@Sun.COM optptr += sizeof (*cmsg); 55111042SErik.Nordmark@Sun.COM 55211042SErik.Nordmark@Sun.COM *(uint_t *)optptr = ipp->ipp_tclass; 55311042SErik.Nordmark@Sun.COM optptr += sizeof (uint_t); 55411042SErik.Nordmark@Sun.COM ASSERT(OK_32PTR(optptr)); 55511042SErik.Nordmark@Sun.COM /* Save as "last" value */ 55611042SErik.Nordmark@Sun.COM sctp->sctp_recvtclass = ipp->ipp_tclass; 55711042SErik.Nordmark@Sun.COM } 55811042SErik.Nordmark@Sun.COM if (addflag.crb_ipv6_recvhopopts) { 5590Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5600Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5610Sstevel@tonic-gate cmsg->cmsg_type = IPV6_HOPOPTS; 5620Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + ipp->ipp_hopoptslen; 5630Sstevel@tonic-gate optptr += sizeof (*cmsg); 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate bcopy(ipp->ipp_hopopts, optptr, ipp->ipp_hopoptslen); 5660Sstevel@tonic-gate optptr += ipp->ipp_hopoptslen; 5670Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5680Sstevel@tonic-gate /* Save as last value */ 5691676Sjpk ip_savebuf((void **)&sctp->sctp_hopopts, 5700Sstevel@tonic-gate &sctp->sctp_hopoptslen, 5710Sstevel@tonic-gate (ipp->ipp_fields & IPPF_HOPOPTS), 5720Sstevel@tonic-gate ipp->ipp_hopopts, ipp->ipp_hopoptslen); 5730Sstevel@tonic-gate } 57411042SErik.Nordmark@Sun.COM if (addflag.crb_ipv6_recvrthdrdstopts) { 5750Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5760Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5770Sstevel@tonic-gate cmsg->cmsg_type = IPV6_RTHDRDSTOPTS; 57811042SErik.Nordmark@Sun.COM cmsg->cmsg_len = sizeof (*cmsg) + ipp->ipp_rthdrdstoptslen; 5790Sstevel@tonic-gate optptr += sizeof (*cmsg); 5800Sstevel@tonic-gate 58111042SErik.Nordmark@Sun.COM bcopy(ipp->ipp_rthdrdstopts, optptr, ipp->ipp_rthdrdstoptslen); 58211042SErik.Nordmark@Sun.COM optptr += ipp->ipp_rthdrdstoptslen; 5830Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5840Sstevel@tonic-gate /* Save as last value */ 58511042SErik.Nordmark@Sun.COM ip_savebuf((void **)&sctp->sctp_rthdrdstopts, 58611042SErik.Nordmark@Sun.COM &sctp->sctp_rthdrdstoptslen, 58711042SErik.Nordmark@Sun.COM (ipp->ipp_fields & IPPF_RTHDRDSTOPTS), 58811042SErik.Nordmark@Sun.COM ipp->ipp_rthdrdstopts, ipp->ipp_rthdrdstoptslen); 5890Sstevel@tonic-gate } 59011042SErik.Nordmark@Sun.COM if (addflag.crb_ipv6_recvrthdr) { 5910Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5920Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5930Sstevel@tonic-gate cmsg->cmsg_type = IPV6_RTHDR; 5940Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + ipp->ipp_rthdrlen; 5950Sstevel@tonic-gate optptr += sizeof (*cmsg); 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate bcopy(ipp->ipp_rthdr, optptr, ipp->ipp_rthdrlen); 5980Sstevel@tonic-gate optptr += ipp->ipp_rthdrlen; 5990Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 6000Sstevel@tonic-gate /* Save as last value */ 6011676Sjpk ip_savebuf((void **)&sctp->sctp_rthdr, 6020Sstevel@tonic-gate &sctp->sctp_rthdrlen, 6030Sstevel@tonic-gate (ipp->ipp_fields & IPPF_RTHDR), 6040Sstevel@tonic-gate ipp->ipp_rthdr, ipp->ipp_rthdrlen); 6050Sstevel@tonic-gate } 60611042SErik.Nordmark@Sun.COM if (addflag.crb_ipv6_recvdstopts) { 6070Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 6080Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 6090Sstevel@tonic-gate cmsg->cmsg_type = IPV6_DSTOPTS; 6100Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + ipp->ipp_dstoptslen; 6110Sstevel@tonic-gate optptr += sizeof (*cmsg); 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate bcopy(ipp->ipp_dstopts, optptr, ipp->ipp_dstoptslen); 6140Sstevel@tonic-gate optptr += ipp->ipp_dstoptslen; 6150Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 6160Sstevel@tonic-gate /* Save as last value */ 6171676Sjpk ip_savebuf((void **)&sctp->sctp_dstopts, 6180Sstevel@tonic-gate &sctp->sctp_dstoptslen, 6190Sstevel@tonic-gate (ipp->ipp_fields & IPPF_DSTOPTS), 6200Sstevel@tonic-gate ipp->ipp_dstopts, ipp->ipp_dstoptslen); 6210Sstevel@tonic-gate } 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate ASSERT(optptr == mp1->b_wptr); 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate return (0); 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate void 6290Sstevel@tonic-gate sctp_free_reass(sctp_instr_t *sip) 6300Sstevel@tonic-gate { 6310Sstevel@tonic-gate mblk_t *mp, *mpnext, *mctl; 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate for (mp = sip->istr_reass; mp != NULL; mp = mpnext) { 6340Sstevel@tonic-gate mpnext = mp->b_next; 6350Sstevel@tonic-gate mp->b_next = NULL; 6360Sstevel@tonic-gate mp->b_prev = NULL; 6370Sstevel@tonic-gate if (DB_TYPE(mp) == M_CTL) { 6380Sstevel@tonic-gate mctl = mp; 6390Sstevel@tonic-gate ASSERT(mp->b_cont != NULL); 6400Sstevel@tonic-gate mp = mp->b_cont; 6410Sstevel@tonic-gate mctl->b_cont = NULL; 6420Sstevel@tonic-gate freeb(mctl); 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate freemsg(mp); 6450Sstevel@tonic-gate } 6460Sstevel@tonic-gate } 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate /* 6490Sstevel@tonic-gate * If the series of data fragments of which dmp is a part is successfully 6500Sstevel@tonic-gate * reassembled, the first mblk in the series is returned. dc is adjusted 6510Sstevel@tonic-gate * to point at the data chunk in the lead mblk, and b_rptr also points to 6520Sstevel@tonic-gate * the data chunk; the following mblk's b_rptr's point at the actual payload. 6530Sstevel@tonic-gate * 6540Sstevel@tonic-gate * If the series is not yet reassembled, NULL is returned. dc is not changed. 6550Sstevel@tonic-gate * XXX should probably move this up into the state machine. 6560Sstevel@tonic-gate */ 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate /* Fragment list for un-ordered messages. Partial delivery is not supported */ 6590Sstevel@tonic-gate static mblk_t * 6600Sstevel@tonic-gate sctp_uodata_frag(sctp_t *sctp, mblk_t *dmp, sctp_data_hdr_t **dc) 6610Sstevel@tonic-gate { 6620Sstevel@tonic-gate mblk_t *hmp; 6630Sstevel@tonic-gate mblk_t *begin = NULL; 6640Sstevel@tonic-gate mblk_t *end = NULL; 6650Sstevel@tonic-gate sctp_data_hdr_t *qdc; 6660Sstevel@tonic-gate uint32_t ntsn; 6670Sstevel@tonic-gate uint32_t tsn = ntohl((*dc)->sdh_tsn); 6680Sstevel@tonic-gate #ifdef DEBUG 6690Sstevel@tonic-gate mblk_t *mp1; 6700Sstevel@tonic-gate #endif 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate /* First frag. */ 6730Sstevel@tonic-gate if (sctp->sctp_uo_frags == NULL) { 6740Sstevel@tonic-gate sctp->sctp_uo_frags = dmp; 6750Sstevel@tonic-gate return (NULL); 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate hmp = sctp->sctp_uo_frags; 6780Sstevel@tonic-gate /* 6790Sstevel@tonic-gate * Insert the segment according to the TSN, fragmented unordered 6800Sstevel@tonic-gate * chunks are sequenced by TSN. 6810Sstevel@tonic-gate */ 6820Sstevel@tonic-gate while (hmp != NULL) { 6830Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)hmp->b_rptr; 6840Sstevel@tonic-gate ntsn = ntohl(qdc->sdh_tsn); 6850Sstevel@tonic-gate if (SEQ_GT(ntsn, tsn)) { 6860Sstevel@tonic-gate if (hmp->b_prev == NULL) { 6870Sstevel@tonic-gate dmp->b_next = hmp; 6880Sstevel@tonic-gate hmp->b_prev = dmp; 6890Sstevel@tonic-gate sctp->sctp_uo_frags = dmp; 6900Sstevel@tonic-gate } else { 6910Sstevel@tonic-gate dmp->b_next = hmp; 6920Sstevel@tonic-gate dmp->b_prev = hmp->b_prev; 6930Sstevel@tonic-gate hmp->b_prev->b_next = dmp; 6940Sstevel@tonic-gate hmp->b_prev = dmp; 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate break; 6970Sstevel@tonic-gate } 6980Sstevel@tonic-gate if (hmp->b_next == NULL) { 6990Sstevel@tonic-gate hmp->b_next = dmp; 7000Sstevel@tonic-gate dmp->b_prev = hmp; 7010Sstevel@tonic-gate break; 7020Sstevel@tonic-gate } 7030Sstevel@tonic-gate hmp = hmp->b_next; 7040Sstevel@tonic-gate } 7050Sstevel@tonic-gate /* check if we completed a msg */ 7060Sstevel@tonic-gate if (SCTP_DATA_GET_BBIT(*dc)) { 7070Sstevel@tonic-gate begin = dmp; 7080Sstevel@tonic-gate } else if (SCTP_DATA_GET_EBIT(*dc)) { 7090Sstevel@tonic-gate end = dmp; 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate /* 7120Sstevel@tonic-gate * We walk consecutive TSNs backwards till we get a seg. with 7130Sstevel@tonic-gate * the B bit 7140Sstevel@tonic-gate */ 7150Sstevel@tonic-gate if (begin == NULL) { 7160Sstevel@tonic-gate for (hmp = dmp->b_prev; hmp != NULL; hmp = hmp->b_prev) { 7170Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)hmp->b_rptr; 7180Sstevel@tonic-gate ntsn = ntohl(qdc->sdh_tsn); 7190Sstevel@tonic-gate if ((int32_t)(tsn - ntsn) > 1) { 7200Sstevel@tonic-gate return (NULL); 7210Sstevel@tonic-gate } 7220Sstevel@tonic-gate if (SCTP_DATA_GET_BBIT(qdc)) { 7230Sstevel@tonic-gate begin = hmp; 7240Sstevel@tonic-gate break; 7250Sstevel@tonic-gate } 7260Sstevel@tonic-gate tsn = ntsn; 7270Sstevel@tonic-gate } 7280Sstevel@tonic-gate } 7290Sstevel@tonic-gate tsn = ntohl((*dc)->sdh_tsn); 7300Sstevel@tonic-gate /* 7310Sstevel@tonic-gate * We walk consecutive TSNs till we get a seg. with the E bit 7320Sstevel@tonic-gate */ 7330Sstevel@tonic-gate if (end == NULL) { 7340Sstevel@tonic-gate for (hmp = dmp->b_next; hmp != NULL; hmp = hmp->b_next) { 7350Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)hmp->b_rptr; 7360Sstevel@tonic-gate ntsn = ntohl(qdc->sdh_tsn); 7370Sstevel@tonic-gate if ((int32_t)(ntsn - tsn) > 1) { 7380Sstevel@tonic-gate return (NULL); 7390Sstevel@tonic-gate } 7400Sstevel@tonic-gate if (SCTP_DATA_GET_EBIT(qdc)) { 7410Sstevel@tonic-gate end = hmp; 7420Sstevel@tonic-gate break; 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate tsn = ntsn; 7450Sstevel@tonic-gate } 7460Sstevel@tonic-gate } 7470Sstevel@tonic-gate if (begin == NULL || end == NULL) { 7480Sstevel@tonic-gate return (NULL); 7490Sstevel@tonic-gate } 7500Sstevel@tonic-gate /* Got one!, Remove the msg from the list */ 7510Sstevel@tonic-gate if (sctp->sctp_uo_frags == begin) { 7520Sstevel@tonic-gate ASSERT(begin->b_prev == NULL); 7530Sstevel@tonic-gate sctp->sctp_uo_frags = end->b_next; 7540Sstevel@tonic-gate if (end->b_next != NULL) 7550Sstevel@tonic-gate end->b_next->b_prev = NULL; 7560Sstevel@tonic-gate } else { 7570Sstevel@tonic-gate begin->b_prev->b_next = end->b_next; 7580Sstevel@tonic-gate if (end->b_next != NULL) 7590Sstevel@tonic-gate end->b_next->b_prev = begin->b_prev; 7600Sstevel@tonic-gate } 7610Sstevel@tonic-gate begin->b_prev = NULL; 7620Sstevel@tonic-gate end->b_next = NULL; 7630Sstevel@tonic-gate 7640Sstevel@tonic-gate /* 7650Sstevel@tonic-gate * Null out b_next and b_prev and chain using b_cont. 7660Sstevel@tonic-gate */ 7670Sstevel@tonic-gate dmp = end = begin; 7680Sstevel@tonic-gate hmp = begin->b_next; 7690Sstevel@tonic-gate *dc = (sctp_data_hdr_t *)begin->b_rptr; 7700Sstevel@tonic-gate begin->b_next = NULL; 7710Sstevel@tonic-gate while (hmp != NULL) { 7720Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)hmp->b_rptr; 7730Sstevel@tonic-gate hmp->b_rptr = (uchar_t *)(qdc + 1); 7740Sstevel@tonic-gate end = hmp->b_next; 7750Sstevel@tonic-gate dmp->b_cont = hmp; 7760Sstevel@tonic-gate dmp = hmp; 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate if (end != NULL) 7790Sstevel@tonic-gate hmp->b_next = NULL; 7800Sstevel@tonic-gate hmp->b_prev = NULL; 7810Sstevel@tonic-gate hmp = end; 7820Sstevel@tonic-gate } 7830Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_reassmsgs); 7840Sstevel@tonic-gate #ifdef DEBUG 7850Sstevel@tonic-gate mp1 = begin; 7860Sstevel@tonic-gate while (mp1 != NULL) { 7870Sstevel@tonic-gate ASSERT(mp1->b_next == NULL); 7880Sstevel@tonic-gate ASSERT(mp1->b_prev == NULL); 7890Sstevel@tonic-gate mp1 = mp1->b_cont; 7900Sstevel@tonic-gate } 7910Sstevel@tonic-gate #endif 7920Sstevel@tonic-gate return (begin); 7930Sstevel@tonic-gate } 7943845Svi117747 7953845Svi117747 /* 7963845Svi117747 * Try partial delivery. 7973845Svi117747 */ 7983845Svi117747 static mblk_t * 7993845Svi117747 sctp_try_partial_delivery(sctp_t *sctp, mblk_t *hmp, sctp_reass_t *srp, 8003845Svi117747 sctp_data_hdr_t **dc) 8013845Svi117747 { 8023845Svi117747 mblk_t *mp; 8033845Svi117747 mblk_t *dmp; 8043845Svi117747 mblk_t *qmp; 8053845Svi117747 mblk_t *prev; 8063845Svi117747 sctp_data_hdr_t *qdc; 8073845Svi117747 uint32_t tsn; 8083845Svi117747 8093845Svi117747 ASSERT(DB_TYPE(hmp) == M_CTL); 8103845Svi117747 8113845Svi117747 dprint(4, ("trypartial: got=%d, needed=%d\n", 8123845Svi117747 (int)(srp->got), (int)(srp->needed))); 8133845Svi117747 81411042SErik.Nordmark@Sun.COM mp = hmp->b_cont; 8153845Svi117747 qdc = (sctp_data_hdr_t *)mp->b_rptr; 8163845Svi117747 8173845Svi117747 ASSERT(SCTP_DATA_GET_BBIT(qdc) && srp->hasBchunk); 8183845Svi117747 8193845Svi117747 tsn = ntohl(qdc->sdh_tsn) + 1; 8203845Svi117747 8213845Svi117747 /* 8223845Svi117747 * This loop has two exit conditions: the 8233845Svi117747 * end of received chunks has been reached, or 8243845Svi117747 * there is a break in the sequence. We want 8253845Svi117747 * to chop the reassembly list as follows (the 8263845Svi117747 * numbers are TSNs): 8273845Svi117747 * 10 -> 11 -> (end of chunks) 8283845Svi117747 * 10 -> 11 -> | 13 (break in sequence) 8293845Svi117747 */ 8303845Svi117747 prev = mp; 8313845Svi117747 mp = mp->b_cont; 8323845Svi117747 while (mp != NULL) { 8333845Svi117747 qdc = (sctp_data_hdr_t *)mp->b_rptr; 8343845Svi117747 if (ntohl(qdc->sdh_tsn) != tsn) 8353845Svi117747 break; 8363845Svi117747 prev = mp; 8373845Svi117747 mp = mp->b_cont; 8383845Svi117747 tsn++; 8393845Svi117747 } 8403845Svi117747 /* 8413845Svi117747 * We are sending all the fragments upstream, we have to retain 8423845Svi117747 * the srp info for further fragments. 8433845Svi117747 */ 8443845Svi117747 if (mp == NULL) { 8453845Svi117747 dmp = hmp->b_cont; 8463845Svi117747 hmp->b_cont = NULL; 8473845Svi117747 srp->nexttsn = tsn; 8483845Svi117747 srp->msglen = 0; 8493845Svi117747 srp->needed = 0; 8503845Svi117747 srp->got = 0; 8513845Svi117747 srp->partial_delivered = B_TRUE; 8523845Svi117747 srp->tail = NULL; 8533845Svi117747 } else { 8543845Svi117747 dmp = hmp->b_cont; 8553845Svi117747 hmp->b_cont = mp; 8563845Svi117747 } 8573845Svi117747 srp->hasBchunk = B_FALSE; 8583845Svi117747 /* 8593845Svi117747 * mp now points at the last chunk in the sequence, 8603845Svi117747 * and prev points to mp's previous in the list. 8613845Svi117747 * We chop the list at prev, and convert mp into the 8623845Svi117747 * new list head by setting the B bit. Subsequence 8633845Svi117747 * fragment deliveries will follow the normal reassembly 8643845Svi117747 * path. 8653845Svi117747 */ 8663845Svi117747 prev->b_cont = NULL; 8673845Svi117747 srp->partial_delivered = B_TRUE; 8683845Svi117747 8693845Svi117747 dprint(4, ("trypartial: got some, got=%d, needed=%d\n", 8703845Svi117747 (int)(srp->got), (int)(srp->needed))); 8713845Svi117747 8723845Svi117747 /* 8733845Svi117747 * Adjust all mblk's except the lead so their rptr's point to the 8743845Svi117747 * payload. sctp_data_chunk() will need to process the lead's 8753845Svi117747 * data chunk section, so leave it's rptr pointing at the data chunk. 8763845Svi117747 */ 8773845Svi117747 *dc = (sctp_data_hdr_t *)dmp->b_rptr; 8783845Svi117747 if (srp->tail != NULL) { 8793845Svi117747 srp->got--; 8803845Svi117747 ASSERT(srp->got != 0); 8813845Svi117747 if (srp->needed != 0) { 8823845Svi117747 srp->needed--; 8833845Svi117747 ASSERT(srp->needed != 0); 8843845Svi117747 } 8853845Svi117747 srp->msglen -= ntohs((*dc)->sdh_len); 8863845Svi117747 } 8873845Svi117747 for (qmp = dmp->b_cont; qmp != NULL; qmp = qmp->b_cont) { 8883845Svi117747 qdc = (sctp_data_hdr_t *)qmp->b_rptr; 8893845Svi117747 qmp->b_rptr = (uchar_t *)(qdc + 1); 8903845Svi117747 8913845Svi117747 /* 8923845Svi117747 * Deduct the balance from got and needed here, now that 8933845Svi117747 * we know we are actually delivering these data. 8943845Svi117747 */ 8953845Svi117747 if (srp->tail != NULL) { 8963845Svi117747 srp->got--; 8973845Svi117747 ASSERT(srp->got != 0); 8983845Svi117747 if (srp->needed != 0) { 8993845Svi117747 srp->needed--; 9003845Svi117747 ASSERT(srp->needed != 0); 9013845Svi117747 } 9023845Svi117747 srp->msglen -= ntohs(qdc->sdh_len); 9033845Svi117747 } 9043845Svi117747 } 9053845Svi117747 ASSERT(srp->msglen == 0); 9063845Svi117747 BUMP_LOCAL(sctp->sctp_reassmsgs); 9073845Svi117747 9083845Svi117747 return (dmp); 9093845Svi117747 } 9103845Svi117747 9110Sstevel@tonic-gate /* 9120Sstevel@tonic-gate * Fragment list for ordered messages. 9130Sstevel@tonic-gate * If no error occures, error is set to 0. If we run out of memory, error 9140Sstevel@tonic-gate * is set to 1. If the peer commits a fatal error (like using different 9150Sstevel@tonic-gate * sequence numbers for the same data fragment series), the association is 9163845Svi117747 * aborted and error is set to 2. tpfinished indicates whether we have 9173845Svi117747 * assembled a complete message, this is used in sctp_data_chunk() to 9183845Svi117747 * see if we can try to send any queued message for this stream. 9190Sstevel@tonic-gate */ 9200Sstevel@tonic-gate static mblk_t * 9210Sstevel@tonic-gate sctp_data_frag(sctp_t *sctp, mblk_t *dmp, sctp_data_hdr_t **dc, int *error, 9223845Svi117747 sctp_instr_t *sip, boolean_t *tpfinished) 9230Sstevel@tonic-gate { 9240Sstevel@tonic-gate mblk_t *hmp; 9250Sstevel@tonic-gate mblk_t *pmp; 9260Sstevel@tonic-gate mblk_t *qmp; 9270Sstevel@tonic-gate mblk_t *first_mp; 9280Sstevel@tonic-gate sctp_reass_t *srp; 9290Sstevel@tonic-gate sctp_data_hdr_t *qdc; 9300Sstevel@tonic-gate sctp_data_hdr_t *bdc; 9310Sstevel@tonic-gate sctp_data_hdr_t *edc; 9320Sstevel@tonic-gate uint32_t tsn; 9333845Svi117747 uint16_t fraglen = 0; 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate *error = 0; 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate /* find the reassembly queue for this data chunk */ 9380Sstevel@tonic-gate hmp = qmp = sip->istr_reass; 9390Sstevel@tonic-gate for (; hmp != NULL; hmp = hmp->b_next) { 9400Sstevel@tonic-gate srp = (sctp_reass_t *)DB_BASE(hmp); 9410Sstevel@tonic-gate if (ntohs((*dc)->sdh_ssn) == srp->ssn) 9420Sstevel@tonic-gate goto foundit; 9430Sstevel@tonic-gate else if (SSN_GT(srp->ssn, ntohs((*dc)->sdh_ssn))) 9440Sstevel@tonic-gate break; 9450Sstevel@tonic-gate qmp = hmp; 9460Sstevel@tonic-gate } 9470Sstevel@tonic-gate 9483845Svi117747 /* 9493845Svi117747 * Allocate a M_CTL that will contain information about this 9503845Svi117747 * fragmented message. 9513845Svi117747 */ 9523845Svi117747 if ((pmp = allocb(sizeof (*srp), BPRI_MED)) == NULL) { 9533845Svi117747 *error = 1; 9543845Svi117747 return (NULL); 9553845Svi117747 } 9563845Svi117747 DB_TYPE(pmp) = M_CTL; 9573845Svi117747 srp = (sctp_reass_t *)DB_BASE(pmp); 9583845Svi117747 pmp->b_cont = dmp; 9590Sstevel@tonic-gate 9600Sstevel@tonic-gate if (hmp != NULL) { 9610Sstevel@tonic-gate if (sip->istr_reass == hmp) { 9620Sstevel@tonic-gate sip->istr_reass = pmp; 9630Sstevel@tonic-gate pmp->b_next = hmp; 9640Sstevel@tonic-gate pmp->b_prev = NULL; 9650Sstevel@tonic-gate hmp->b_prev = pmp; 9660Sstevel@tonic-gate } else { 9670Sstevel@tonic-gate qmp->b_next = pmp; 9680Sstevel@tonic-gate pmp->b_prev = qmp; 9690Sstevel@tonic-gate pmp->b_next = hmp; 9700Sstevel@tonic-gate hmp->b_prev = pmp; 9710Sstevel@tonic-gate } 9720Sstevel@tonic-gate } else { 9730Sstevel@tonic-gate /* make a new reass head and stick it on the end */ 9740Sstevel@tonic-gate if (sip->istr_reass == NULL) { 9750Sstevel@tonic-gate sip->istr_reass = pmp; 9760Sstevel@tonic-gate pmp->b_prev = NULL; 9770Sstevel@tonic-gate } else { 9780Sstevel@tonic-gate qmp->b_next = pmp; 9790Sstevel@tonic-gate pmp->b_prev = qmp; 9800Sstevel@tonic-gate } 9810Sstevel@tonic-gate pmp->b_next = NULL; 9820Sstevel@tonic-gate } 9833845Svi117747 srp->partial_delivered = B_FALSE; 9843845Svi117747 srp->ssn = ntohs((*dc)->sdh_ssn); 9853845Svi117747 empty_srp: 9863845Svi117747 srp->needed = 0; 9873845Svi117747 srp->got = 1; 9883845Svi117747 srp->tail = dmp; 9893845Svi117747 if (SCTP_DATA_GET_BBIT(*dc)) { 9903845Svi117747 srp->msglen = ntohs((*dc)->sdh_len); 9913845Svi117747 srp->nexttsn = ntohl((*dc)->sdh_tsn) + 1; 9923845Svi117747 srp->hasBchunk = B_TRUE; 9933845Svi117747 } else if (srp->partial_delivered && 9943845Svi117747 srp->nexttsn == ntohl((*dc)->sdh_tsn)) { 9953845Svi117747 SCTP_DATA_SET_BBIT(*dc); 9963845Svi117747 /* Last fragment */ 9973845Svi117747 if (SCTP_DATA_GET_EBIT(*dc)) { 9983845Svi117747 srp->needed = 1; 9993845Svi117747 goto frag_done; 10003845Svi117747 } 10013845Svi117747 srp->hasBchunk = B_TRUE; 10023845Svi117747 srp->msglen = ntohs((*dc)->sdh_len); 10033845Svi117747 srp->nexttsn++; 10043845Svi117747 } 10050Sstevel@tonic-gate return (NULL); 10060Sstevel@tonic-gate foundit: 10070Sstevel@tonic-gate /* 10080Sstevel@tonic-gate * else already have a reassembly queue. Insert the new data chunk 10090Sstevel@tonic-gate * in the reassemble queue. Try the tail first, on the assumption 10100Sstevel@tonic-gate * that the fragments are coming in in order. 10110Sstevel@tonic-gate */ 10120Sstevel@tonic-gate qmp = srp->tail; 10133845Svi117747 10143845Svi117747 /* 10153845Svi117747 * This means the message was partially delivered. 10163845Svi117747 */ 10173845Svi117747 if (qmp == NULL) { 10183845Svi117747 ASSERT(srp->got == 0 && srp->needed == 0 && 10193845Svi117747 srp->partial_delivered); 10203845Svi117747 ASSERT(hmp->b_cont == NULL); 10213845Svi117747 hmp->b_cont = dmp; 10223845Svi117747 goto empty_srp; 10233845Svi117747 } 10240Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)qmp->b_rptr; 10250Sstevel@tonic-gate ASSERT(qmp->b_cont == NULL); 10260Sstevel@tonic-gate 10270Sstevel@tonic-gate /* XXXIs it fine to do this just here? */ 10280Sstevel@tonic-gate if ((*dc)->sdh_sid != qdc->sdh_sid) { 10290Sstevel@tonic-gate /* our peer is fatally confused; XXX abort the assc */ 10300Sstevel@tonic-gate *error = 2; 10310Sstevel@tonic-gate return (NULL); 10320Sstevel@tonic-gate } 10330Sstevel@tonic-gate if (SEQ_GT(ntohl((*dc)->sdh_tsn), ntohl(qdc->sdh_tsn))) { 10340Sstevel@tonic-gate qmp->b_cont = dmp; 10350Sstevel@tonic-gate srp->tail = dmp; 10360Sstevel@tonic-gate dmp->b_cont = NULL; 10373845Svi117747 if (srp->hasBchunk && srp->nexttsn == ntohl((*dc)->sdh_tsn)) { 10383845Svi117747 srp->msglen += ntohs((*dc)->sdh_len); 10393845Svi117747 srp->nexttsn++; 10403845Svi117747 } 10410Sstevel@tonic-gate goto inserted; 10420Sstevel@tonic-gate } 10430Sstevel@tonic-gate 10440Sstevel@tonic-gate /* Next check for insertion at the beginning */ 10453845Svi117747 qmp = hmp->b_cont; 10460Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)qmp->b_rptr; 10470Sstevel@tonic-gate if (SEQ_LT(ntohl((*dc)->sdh_tsn), ntohl(qdc->sdh_tsn))) { 10483845Svi117747 dmp->b_cont = qmp; 10493845Svi117747 hmp->b_cont = dmp; 10503845Svi117747 if (SCTP_DATA_GET_BBIT(*dc)) { 10513845Svi117747 srp->hasBchunk = B_TRUE; 10523845Svi117747 srp->nexttsn = ntohl((*dc)->sdh_tsn); 10530Sstevel@tonic-gate } 10543845Svi117747 goto preinserted; 10550Sstevel@tonic-gate } 10560Sstevel@tonic-gate 10570Sstevel@tonic-gate /* Insert somewhere in the middle */ 10580Sstevel@tonic-gate for (;;) { 10590Sstevel@tonic-gate /* Tail check above should have caught this */ 10600Sstevel@tonic-gate ASSERT(qmp->b_cont != NULL); 10610Sstevel@tonic-gate 10620Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)qmp->b_cont->b_rptr; 10630Sstevel@tonic-gate if (SEQ_LT(ntohl((*dc)->sdh_tsn), ntohl(qdc->sdh_tsn))) { 10640Sstevel@tonic-gate /* insert here */ 10650Sstevel@tonic-gate dmp->b_cont = qmp->b_cont; 10660Sstevel@tonic-gate qmp->b_cont = dmp; 10670Sstevel@tonic-gate break; 10680Sstevel@tonic-gate } 10690Sstevel@tonic-gate qmp = qmp->b_cont; 10700Sstevel@tonic-gate } 10713845Svi117747 preinserted: 10723845Svi117747 if (!srp->hasBchunk || ntohl((*dc)->sdh_tsn) != srp->nexttsn) 10733845Svi117747 goto inserted; 10743845Svi117747 /* 10753845Svi117747 * fraglen contains the length of consecutive chunks of fragments. 10763845Svi117747 * starting from the chunk inserted recently. 10773845Svi117747 */ 10783845Svi117747 tsn = srp->nexttsn; 10793845Svi117747 for (qmp = dmp; qmp != NULL; qmp = qmp->b_cont) { 10803845Svi117747 qdc = (sctp_data_hdr_t *)qmp->b_rptr; 10813845Svi117747 if (tsn != ntohl(qdc->sdh_tsn)) 10823845Svi117747 break; 10833845Svi117747 fraglen += ntohs(qdc->sdh_len); 10843845Svi117747 tsn++; 10853845Svi117747 } 10863845Svi117747 srp->nexttsn = tsn; 10873845Svi117747 srp->msglen += fraglen; 10880Sstevel@tonic-gate inserted: 10893845Svi117747 srp->got++; 10903845Svi117747 first_mp = hmp->b_cont; 10910Sstevel@tonic-gate if (srp->needed == 0) { 10920Sstevel@tonic-gate /* check if we have the first and last fragments */ 10930Sstevel@tonic-gate bdc = (sctp_data_hdr_t *)first_mp->b_rptr; 10940Sstevel@tonic-gate edc = (sctp_data_hdr_t *)srp->tail->b_rptr; 10950Sstevel@tonic-gate 10960Sstevel@tonic-gate /* calculate how many fragments are needed, if possible */ 10973845Svi117747 if (SCTP_DATA_GET_BBIT(bdc) && SCTP_DATA_GET_EBIT(edc)) { 10980Sstevel@tonic-gate srp->needed = ntohl(edc->sdh_tsn) - 10990Sstevel@tonic-gate ntohl(bdc->sdh_tsn) + 1; 11000Sstevel@tonic-gate } 11013845Svi117747 } 11023845Svi117747 11033845Svi117747 /* 11043845Svi117747 * Try partial delivery if the message length has exceeded the 11053845Svi117747 * partial delivery point. Only do this if we can immediately 11063845Svi117747 * deliver the partially assembled message, and only partially 11073845Svi117747 * deliver one message at a time (i.e. messages cannot be 11083845Svi117747 * intermixed arriving at the upper layer). A simple way to 11093845Svi117747 * enforce this is to only try partial delivery if this TSN is 11103845Svi117747 * the next expected TSN. Partial Delivery not supported 11113845Svi117747 * for un-ordered message. 11123845Svi117747 */ 11133845Svi117747 if (srp->needed != srp->got) { 11143845Svi117747 dmp = NULL; 11153845Svi117747 if (ntohl((*dc)->sdh_tsn) == sctp->sctp_ftsn && 11163845Svi117747 srp->msglen >= sctp->sctp_pd_point) { 11173845Svi117747 dmp = sctp_try_partial_delivery(sctp, hmp, srp, dc); 11183845Svi117747 *tpfinished = B_FALSE; 11190Sstevel@tonic-gate } 11203845Svi117747 return (dmp); 11210Sstevel@tonic-gate } 11223845Svi117747 frag_done: 11230Sstevel@tonic-gate /* 11240Sstevel@tonic-gate * else reassembly done; prepare the data for delivery. 11250Sstevel@tonic-gate * First unlink hmp from the ssn list. 11260Sstevel@tonic-gate */ 11270Sstevel@tonic-gate if (sip->istr_reass == hmp) { 11280Sstevel@tonic-gate sip->istr_reass = hmp->b_next; 11293845Svi117747 if (hmp->b_next) 11300Sstevel@tonic-gate hmp->b_next->b_prev = NULL; 11310Sstevel@tonic-gate } else { 11320Sstevel@tonic-gate ASSERT(hmp->b_prev != NULL); 11330Sstevel@tonic-gate hmp->b_prev->b_next = hmp->b_next; 11343845Svi117747 if (hmp->b_next) 11350Sstevel@tonic-gate hmp->b_next->b_prev = hmp->b_prev; 11360Sstevel@tonic-gate } 11370Sstevel@tonic-gate 11380Sstevel@tonic-gate /* 11390Sstevel@tonic-gate * Using b_prev and b_next was a little sinful, but OK since 11400Sstevel@tonic-gate * this mblk is never put*'d. However, freeb() will still 11410Sstevel@tonic-gate * ASSERT that they are unused, so we need to NULL them out now. 11420Sstevel@tonic-gate */ 11430Sstevel@tonic-gate hmp->b_next = NULL; 11440Sstevel@tonic-gate hmp->b_prev = NULL; 11450Sstevel@tonic-gate dmp = hmp; 11463845Svi117747 dmp = dmp->b_cont; 11473845Svi117747 hmp->b_cont = NULL; 11483845Svi117747 freeb(hmp); 11493845Svi117747 *tpfinished = B_TRUE; 11503845Svi117747 11510Sstevel@tonic-gate /* 11520Sstevel@tonic-gate * Adjust all mblk's except the lead so their rptr's point to the 11530Sstevel@tonic-gate * payload. sctp_data_chunk() will need to process the lead's 11540Sstevel@tonic-gate * data chunk section, so leave it's rptr pointing at the data chunk. 11550Sstevel@tonic-gate */ 11560Sstevel@tonic-gate *dc = (sctp_data_hdr_t *)dmp->b_rptr; 11573845Svi117747 for (qmp = dmp->b_cont; qmp != NULL; qmp = qmp->b_cont) { 11580Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)qmp->b_rptr; 11590Sstevel@tonic-gate qmp->b_rptr = (uchar_t *)(qdc + 1); 11600Sstevel@tonic-gate } 11610Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_reassmsgs); 11620Sstevel@tonic-gate 11630Sstevel@tonic-gate return (dmp); 11640Sstevel@tonic-gate } 11650Sstevel@tonic-gate static void 11660Sstevel@tonic-gate sctp_add_dup(uint32_t tsn, mblk_t **dups) 11670Sstevel@tonic-gate { 11680Sstevel@tonic-gate mblk_t *mp; 11690Sstevel@tonic-gate size_t bsize = SCTP_DUP_MBLK_SZ * sizeof (tsn); 11700Sstevel@tonic-gate 11710Sstevel@tonic-gate if (dups == NULL) { 11720Sstevel@tonic-gate return; 11730Sstevel@tonic-gate } 11740Sstevel@tonic-gate 11750Sstevel@tonic-gate /* first time? */ 11760Sstevel@tonic-gate if (*dups == NULL) { 11770Sstevel@tonic-gate *dups = allocb(bsize, BPRI_MED); 11780Sstevel@tonic-gate if (*dups == NULL) { 11790Sstevel@tonic-gate return; 11800Sstevel@tonic-gate } 11810Sstevel@tonic-gate } 11820Sstevel@tonic-gate 11830Sstevel@tonic-gate mp = *dups; 11840Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr) >= bsize) { 11850Sstevel@tonic-gate /* maximum reached */ 11860Sstevel@tonic-gate return; 11870Sstevel@tonic-gate } 11880Sstevel@tonic-gate 11890Sstevel@tonic-gate /* add the duplicate tsn */ 11900Sstevel@tonic-gate bcopy(&tsn, mp->b_wptr, sizeof (tsn)); 11910Sstevel@tonic-gate mp->b_wptr += sizeof (tsn); 11920Sstevel@tonic-gate ASSERT((mp->b_wptr - mp->b_rptr) <= bsize); 11930Sstevel@tonic-gate } 11940Sstevel@tonic-gate 11950Sstevel@tonic-gate static void 11960Sstevel@tonic-gate sctp_data_chunk(sctp_t *sctp, sctp_chunk_hdr_t *ch, mblk_t *mp, mblk_t **dups, 119711042SErik.Nordmark@Sun.COM sctp_faddr_t *fp, ip_pkt_t *ipp, ip_recv_attr_t *ira) 11980Sstevel@tonic-gate { 11990Sstevel@tonic-gate sctp_data_hdr_t *dc; 12000Sstevel@tonic-gate mblk_t *dmp, *pmp; 12010Sstevel@tonic-gate sctp_instr_t *instr; 12020Sstevel@tonic-gate int ubit; 12030Sstevel@tonic-gate int isfrag; 12040Sstevel@tonic-gate uint16_t ssn; 12050Sstevel@tonic-gate uint32_t oftsn; 12060Sstevel@tonic-gate boolean_t can_deliver = B_TRUE; 12070Sstevel@tonic-gate uint32_t tsn; 12080Sstevel@tonic-gate int dlen; 12093845Svi117747 boolean_t tpfinished = B_TRUE; 12100Sstevel@tonic-gate int32_t new_rwnd; 12113448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 12128348SEric.Yu@Sun.COM int error; 12130Sstevel@tonic-gate 12140Sstevel@tonic-gate /* The following are used multiple times, so we inline them */ 12150Sstevel@tonic-gate #define SCTP_ACK_IT(sctp, tsn) \ 12160Sstevel@tonic-gate if (tsn == sctp->sctp_ftsn) { \ 12170Sstevel@tonic-gate dprint(2, ("data_chunk: acking next %x\n", tsn)); \ 12181932Svi117747 (sctp)->sctp_ftsn++; \ 12191932Svi117747 if ((sctp)->sctp_sack_gaps > 0) \ 12201932Svi117747 (sctp)->sctp_force_sack = 1; \ 12210Sstevel@tonic-gate } else if (SEQ_GT(tsn, sctp->sctp_ftsn)) { \ 12220Sstevel@tonic-gate /* Got a gap; record it */ \ 122310212SGeorge.Shepherd@Sun.COM BUMP_LOCAL(sctp->sctp_outseqtsns); \ 12240Sstevel@tonic-gate dprint(2, ("data_chunk: acking gap %x\n", tsn)); \ 12251932Svi117747 sctp_ack_add(&sctp->sctp_sack_info, tsn, \ 12261932Svi117747 &sctp->sctp_sack_gaps); \ 12270Sstevel@tonic-gate sctp->sctp_force_sack = 1; \ 12280Sstevel@tonic-gate } 12290Sstevel@tonic-gate 12300Sstevel@tonic-gate dmp = NULL; 12310Sstevel@tonic-gate 12320Sstevel@tonic-gate dc = (sctp_data_hdr_t *)ch; 12330Sstevel@tonic-gate tsn = ntohl(dc->sdh_tsn); 12340Sstevel@tonic-gate 12351676Sjpk dprint(3, ("sctp_data_chunk: mp=%p tsn=%x\n", (void *)mp, tsn)); 12360Sstevel@tonic-gate 12370Sstevel@tonic-gate /* Check for duplicates */ 12380Sstevel@tonic-gate if (SEQ_LT(tsn, sctp->sctp_ftsn)) { 12390Sstevel@tonic-gate dprint(4, ("sctp_data_chunk: dropping duplicate\n")); 124010212SGeorge.Shepherd@Sun.COM BUMP_LOCAL(sctp->sctp_idupchunks); 12410Sstevel@tonic-gate sctp->sctp_force_sack = 1; 12420Sstevel@tonic-gate sctp_add_dup(dc->sdh_tsn, dups); 12430Sstevel@tonic-gate return; 12440Sstevel@tonic-gate } 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL) { 12470Sstevel@tonic-gate sctp_set_t *sp; 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate for (sp = sctp->sctp_sack_info; sp; sp = sp->next) { 12500Sstevel@tonic-gate if (SEQ_GEQ(tsn, sp->begin) && SEQ_LEQ(tsn, sp->end)) { 12510Sstevel@tonic-gate dprint(4, 12524964Skcpoon ("sctp_data_chunk: dropping dup > " 12534964Skcpoon "cumtsn\n")); 125410212SGeorge.Shepherd@Sun.COM BUMP_LOCAL(sctp->sctp_idupchunks); 12550Sstevel@tonic-gate sctp->sctp_force_sack = 1; 12560Sstevel@tonic-gate sctp_add_dup(dc->sdh_tsn, dups); 12570Sstevel@tonic-gate return; 12580Sstevel@tonic-gate } 12590Sstevel@tonic-gate } 12600Sstevel@tonic-gate } 12610Sstevel@tonic-gate 12620Sstevel@tonic-gate /* We cannot deliver anything up now but we still need to handle it. */ 12630Sstevel@tonic-gate if (SCTP_IS_DETACHED(sctp)) { 12643448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInClosed); 12650Sstevel@tonic-gate can_deliver = B_FALSE; 12660Sstevel@tonic-gate } 12670Sstevel@tonic-gate 12680Sstevel@tonic-gate dlen = ntohs(dc->sdh_len) - sizeof (*dc); 12690Sstevel@tonic-gate 127010828SGeorge.Shepherd@Sun.COM /* 127110828SGeorge.Shepherd@Sun.COM * Check for buffer space. Note if this is the next expected TSN 127210828SGeorge.Shepherd@Sun.COM * we have to take it to avoid deadlock because we cannot deliver 127310828SGeorge.Shepherd@Sun.COM * later queued TSNs and thus clear buffer space without it. 127410828SGeorge.Shepherd@Sun.COM * We drop anything that is purely zero window probe data here. 127510828SGeorge.Shepherd@Sun.COM */ 127610828SGeorge.Shepherd@Sun.COM if ((sctp->sctp_rwnd - sctp->sctp_rxqueued < dlen) && 127710828SGeorge.Shepherd@Sun.COM (tsn != sctp->sctp_ftsn || sctp->sctp_rwnd == 0)) { 12780Sstevel@tonic-gate /* Drop and SACK, but don't advance the cumulative TSN. */ 12790Sstevel@tonic-gate sctp->sctp_force_sack = 1; 12800Sstevel@tonic-gate dprint(0, ("sctp_data_chunk: exceed rwnd %d rxqueued %d " 12813795Skcpoon "dlen %d ssn %d tsn %x\n", sctp->sctp_rwnd, 12823795Skcpoon sctp->sctp_rxqueued, dlen, ntohs(dc->sdh_ssn), 12833795Skcpoon ntohl(dc->sdh_tsn))); 12840Sstevel@tonic-gate return; 12850Sstevel@tonic-gate } 12860Sstevel@tonic-gate 12870Sstevel@tonic-gate if (ntohs(dc->sdh_sid) >= sctp->sctp_num_istr) { 12889451SGeorge.Shepherd@Sun.COM sctp_bsc_t inval_parm; 12899451SGeorge.Shepherd@Sun.COM 12909451SGeorge.Shepherd@Sun.COM /* Will populate the CAUSE block in the ERROR chunk. */ 12919451SGeorge.Shepherd@Sun.COM inval_parm.bsc_sid = dc->sdh_sid; 12929451SGeorge.Shepherd@Sun.COM /* RESERVED, ignored at the receiving end */ 12939451SGeorge.Shepherd@Sun.COM inval_parm.bsc_pad = 0; 12949451SGeorge.Shepherd@Sun.COM 12950Sstevel@tonic-gate /* ack and drop it */ 12969451SGeorge.Shepherd@Sun.COM sctp_add_err(sctp, SCTP_ERR_BAD_SID, (void *)&inval_parm, 12979451SGeorge.Shepherd@Sun.COM sizeof (sctp_bsc_t), fp); 12980Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 12990Sstevel@tonic-gate return; 13000Sstevel@tonic-gate } 13010Sstevel@tonic-gate 13020Sstevel@tonic-gate ubit = SCTP_DATA_GET_UBIT(dc); 13030Sstevel@tonic-gate ASSERT(sctp->sctp_instr != NULL); 13040Sstevel@tonic-gate instr = &sctp->sctp_instr[ntohs(dc->sdh_sid)]; 13050Sstevel@tonic-gate /* Initialize the stream, if not yet used */ 13060Sstevel@tonic-gate if (instr->sctp == NULL) 13070Sstevel@tonic-gate instr->sctp = sctp; 13083845Svi117747 13090Sstevel@tonic-gate isfrag = !(SCTP_DATA_GET_BBIT(dc) && SCTP_DATA_GET_EBIT(dc)); 13100Sstevel@tonic-gate ssn = ntohs(dc->sdh_ssn); 13110Sstevel@tonic-gate 13120Sstevel@tonic-gate dmp = dupb(mp); 13130Sstevel@tonic-gate if (dmp == NULL) { 13140Sstevel@tonic-gate /* drop it and don't ack it, causing the peer to retransmit */ 13150Sstevel@tonic-gate return; 13160Sstevel@tonic-gate } 13170Sstevel@tonic-gate dmp->b_wptr = (uchar_t *)ch + ntohs(ch->sch_len); 13180Sstevel@tonic-gate 13190Sstevel@tonic-gate sctp->sctp_rxqueued += dlen; 13200Sstevel@tonic-gate 13210Sstevel@tonic-gate oftsn = sctp->sctp_ftsn; 13220Sstevel@tonic-gate 13230Sstevel@tonic-gate if (isfrag) { 13248348SEric.Yu@Sun.COM 13258348SEric.Yu@Sun.COM error = 0; 13260Sstevel@tonic-gate /* fragmented data chunk */ 13270Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)dc; 13280Sstevel@tonic-gate if (ubit) { 13290Sstevel@tonic-gate dmp = sctp_uodata_frag(sctp, dmp, &dc); 13300Sstevel@tonic-gate #if DEBUG 13310Sstevel@tonic-gate if (dmp != NULL) { 13320Sstevel@tonic-gate ASSERT(instr == 13330Sstevel@tonic-gate &sctp->sctp_instr[ntohs(dc->sdh_sid)]); 13340Sstevel@tonic-gate } 13350Sstevel@tonic-gate #endif 13360Sstevel@tonic-gate } else { 13370Sstevel@tonic-gate dmp = sctp_data_frag(sctp, dmp, &dc, &error, instr, 13383845Svi117747 &tpfinished); 13390Sstevel@tonic-gate } 13400Sstevel@tonic-gate if (error != 0) { 13410Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 13420Sstevel@tonic-gate if (error == 1) { 13430Sstevel@tonic-gate /* 13440Sstevel@tonic-gate * out of memory; don't ack it so 13450Sstevel@tonic-gate * the peer retransmits 13460Sstevel@tonic-gate */ 13470Sstevel@tonic-gate return; 13480Sstevel@tonic-gate } else if (error == 2) { 13490Sstevel@tonic-gate /* 13500Sstevel@tonic-gate * fatal error (i.e. peer used different 13510Sstevel@tonic-gate * ssn's for same fragmented data) -- 13520Sstevel@tonic-gate * the association has been aborted. 13530Sstevel@tonic-gate * XXX need to return errval so state 13540Sstevel@tonic-gate * machine can also abort processing. 13550Sstevel@tonic-gate */ 13560Sstevel@tonic-gate dprint(0, ("error 2: must not happen!\n")); 13570Sstevel@tonic-gate return; 13580Sstevel@tonic-gate } 13590Sstevel@tonic-gate } 13600Sstevel@tonic-gate 13610Sstevel@tonic-gate if (dmp == NULL) { 13620Sstevel@tonic-gate /* 13630Sstevel@tonic-gate * Can't process this data now, but the cumulative 13640Sstevel@tonic-gate * TSN may be advanced, so do the checks at done. 13650Sstevel@tonic-gate */ 13660Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 13670Sstevel@tonic-gate goto done; 13680Sstevel@tonic-gate } 13690Sstevel@tonic-gate } 13700Sstevel@tonic-gate 13716374Sgeorges /* 13726374Sgeorges * Insert complete messages in correct order for ordered delivery. 13736374Sgeorges * tpfinished is true when the incoming chunk contains a complete 13746374Sgeorges * message or is the final missing fragment which completed a message. 13756374Sgeorges */ 13766374Sgeorges if (!ubit && tpfinished && ssn != instr->nextseq) { 13770Sstevel@tonic-gate /* Adjust rptr to point at the data chunk for compares */ 13780Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)dc; 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate dprint(2, 13810Sstevel@tonic-gate ("data_chunk: inserted %x in pq (ssn %d expected %d)\n", 13820Sstevel@tonic-gate ntohl(dc->sdh_tsn), (int)(ssn), (int)(instr->nextseq))); 13830Sstevel@tonic-gate 13840Sstevel@tonic-gate if (instr->istr_msgs == NULL) { 13850Sstevel@tonic-gate instr->istr_msgs = dmp; 13860Sstevel@tonic-gate ASSERT(dmp->b_prev == NULL && dmp->b_next == NULL); 13870Sstevel@tonic-gate } else { 13880Sstevel@tonic-gate mblk_t *imblk = instr->istr_msgs; 13890Sstevel@tonic-gate sctp_data_hdr_t *idc; 13900Sstevel@tonic-gate 13910Sstevel@tonic-gate /* 13920Sstevel@tonic-gate * XXXNeed to take sequence wraps into account, 13930Sstevel@tonic-gate * ... and a more efficient insertion algo. 13940Sstevel@tonic-gate */ 13950Sstevel@tonic-gate for (;;) { 13960Sstevel@tonic-gate idc = (sctp_data_hdr_t *)imblk->b_rptr; 13970Sstevel@tonic-gate if (SSN_GT(ntohs(idc->sdh_ssn), 13984964Skcpoon ntohs(dc->sdh_ssn))) { 13990Sstevel@tonic-gate if (instr->istr_msgs == imblk) { 14000Sstevel@tonic-gate instr->istr_msgs = dmp; 14010Sstevel@tonic-gate dmp->b_next = imblk; 14020Sstevel@tonic-gate imblk->b_prev = dmp; 14030Sstevel@tonic-gate } else { 14040Sstevel@tonic-gate ASSERT(imblk->b_prev != NULL); 14050Sstevel@tonic-gate imblk->b_prev->b_next = dmp; 14060Sstevel@tonic-gate dmp->b_prev = imblk->b_prev; 14070Sstevel@tonic-gate imblk->b_prev = dmp; 14080Sstevel@tonic-gate dmp->b_next = imblk; 14090Sstevel@tonic-gate } 14100Sstevel@tonic-gate break; 14110Sstevel@tonic-gate } 14120Sstevel@tonic-gate if (imblk->b_next == NULL) { 14130Sstevel@tonic-gate imblk->b_next = dmp; 14140Sstevel@tonic-gate dmp->b_prev = imblk; 14150Sstevel@tonic-gate break; 14160Sstevel@tonic-gate } 14170Sstevel@tonic-gate imblk = imblk->b_next; 14180Sstevel@tonic-gate } 14190Sstevel@tonic-gate } 14200Sstevel@tonic-gate (instr->istr_nmsgs)++; 14210Sstevel@tonic-gate (sctp->sctp_istr_nmsgs)++; 14220Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 14230Sstevel@tonic-gate return; 14240Sstevel@tonic-gate } 14250Sstevel@tonic-gate 14260Sstevel@tonic-gate /* 14270Sstevel@tonic-gate * Else we can deliver the data directly. Recalculate 14280Sstevel@tonic-gate * dlen now since we may have reassembled data. 14290Sstevel@tonic-gate */ 14300Sstevel@tonic-gate dlen = dmp->b_wptr - (uchar_t *)dc - sizeof (*dc); 14310Sstevel@tonic-gate for (pmp = dmp->b_cont; pmp != NULL; pmp = pmp->b_cont) 143210828SGeorge.Shepherd@Sun.COM dlen += MBLKL(pmp); 14330Sstevel@tonic-gate ASSERT(sctp->sctp_rxqueued >= dlen); 14340Sstevel@tonic-gate 14350Sstevel@tonic-gate /* Deliver the message. */ 14360Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 14370Sstevel@tonic-gate 14380Sstevel@tonic-gate if (can_deliver) { 14398348SEric.Yu@Sun.COM 14400Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)(dc + 1); 144111042SErik.Nordmark@Sun.COM if (sctp_input_add_ancillary(sctp, &dmp, dc, fp, 144211042SErik.Nordmark@Sun.COM ipp, ira) == 0) { 14430Sstevel@tonic-gate dprint(1, ("sctp_data_chunk: delivering %lu bytes\n", 14440Sstevel@tonic-gate msgdsize(dmp))); 14450Sstevel@tonic-gate sctp->sctp_rwnd -= dlen; 14468348SEric.Yu@Sun.COM /* 14478348SEric.Yu@Sun.COM * Override b_flag for SCTP sockfs internal use 14488348SEric.Yu@Sun.COM */ 14498348SEric.Yu@Sun.COM dmp->b_flag = tpfinished ? 0 : SCTP_PARTIAL_DATA; 14500Sstevel@tonic-gate new_rwnd = sctp->sctp_ulp_recv(sctp->sctp_ulpd, dmp, 14518348SEric.Yu@Sun.COM msgdsize(dmp), 0, &error, NULL); 145210828SGeorge.Shepherd@Sun.COM /* 145310828SGeorge.Shepherd@Sun.COM * Since we always deliver the next TSN data chunk, 145410828SGeorge.Shepherd@Sun.COM * we may buffer a little more than allowed. In 145510828SGeorge.Shepherd@Sun.COM * that case, just mark the window as 0. 145610828SGeorge.Shepherd@Sun.COM */ 145710828SGeorge.Shepherd@Sun.COM if (new_rwnd < 0) 145810828SGeorge.Shepherd@Sun.COM sctp->sctp_rwnd = 0; 145910828SGeorge.Shepherd@Sun.COM else if (new_rwnd > sctp->sctp_rwnd) 14600Sstevel@tonic-gate sctp->sctp_rwnd = new_rwnd; 14610Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 14620Sstevel@tonic-gate } else { 14630Sstevel@tonic-gate /* Just free the message if we don't have memory. */ 14640Sstevel@tonic-gate freemsg(dmp); 14650Sstevel@tonic-gate return; 14660Sstevel@tonic-gate } 14670Sstevel@tonic-gate } else { 14680Sstevel@tonic-gate /* About to free the data */ 14690Sstevel@tonic-gate freemsg(dmp); 14700Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 14710Sstevel@tonic-gate } 14720Sstevel@tonic-gate 14730Sstevel@tonic-gate /* 14740Sstevel@tonic-gate * data, now enqueued, may already have been processed and free'd 14750Sstevel@tonic-gate * by the ULP (or we may have just freed it above, if we could not 14760Sstevel@tonic-gate * deliver it), so we must not reference it (this is why we kept 14770Sstevel@tonic-gate * the ssn and ubit above). 14780Sstevel@tonic-gate */ 14790Sstevel@tonic-gate if (ubit != 0) { 14800Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_iudchunks); 14810Sstevel@tonic-gate goto done; 14820Sstevel@tonic-gate } 14830Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_idchunks); 14840Sstevel@tonic-gate 14850Sstevel@tonic-gate /* 14860Sstevel@tonic-gate * If there was a partial delivery and it has not finished, 14870Sstevel@tonic-gate * don't pull anything from the pqueues. 14880Sstevel@tonic-gate */ 14890Sstevel@tonic-gate if (!tpfinished) { 14900Sstevel@tonic-gate goto done; 14910Sstevel@tonic-gate } 14920Sstevel@tonic-gate 14930Sstevel@tonic-gate instr->nextseq = ssn + 1; 14940Sstevel@tonic-gate /* Deliver any successive data chunks in the instr queue */ 14950Sstevel@tonic-gate while (instr->istr_nmsgs > 0) { 14960Sstevel@tonic-gate dmp = (mblk_t *)instr->istr_msgs; 14970Sstevel@tonic-gate dc = (sctp_data_hdr_t *)dmp->b_rptr; 14980Sstevel@tonic-gate ssn = ntohs(dc->sdh_ssn); 14990Sstevel@tonic-gate /* Gap in the sequence */ 15000Sstevel@tonic-gate if (ssn != instr->nextseq) 15010Sstevel@tonic-gate break; 15020Sstevel@tonic-gate 15030Sstevel@tonic-gate /* Else deliver the data */ 15040Sstevel@tonic-gate (instr->istr_nmsgs)--; 15050Sstevel@tonic-gate (instr->nextseq)++; 15060Sstevel@tonic-gate (sctp->sctp_istr_nmsgs)--; 15070Sstevel@tonic-gate 15080Sstevel@tonic-gate instr->istr_msgs = instr->istr_msgs->b_next; 15090Sstevel@tonic-gate if (instr->istr_msgs != NULL) 15100Sstevel@tonic-gate instr->istr_msgs->b_prev = NULL; 15110Sstevel@tonic-gate dmp->b_next = dmp->b_prev = NULL; 15120Sstevel@tonic-gate 15130Sstevel@tonic-gate dprint(2, ("data_chunk: pulling %x from pq (ssn %d)\n", 15140Sstevel@tonic-gate ntohl(dc->sdh_tsn), (int)ssn)); 15150Sstevel@tonic-gate 15160Sstevel@tonic-gate /* 15170Sstevel@tonic-gate * If this chunk was reassembled, each b_cont represents 15180Sstevel@tonic-gate * another TSN; advance ftsn now. 15190Sstevel@tonic-gate */ 15200Sstevel@tonic-gate dlen = dmp->b_wptr - dmp->b_rptr - sizeof (*dc); 15210Sstevel@tonic-gate for (pmp = dmp->b_cont; pmp; pmp = pmp->b_cont) 152210828SGeorge.Shepherd@Sun.COM dlen += MBLKL(pmp); 15230Sstevel@tonic-gate 15240Sstevel@tonic-gate ASSERT(sctp->sctp_rxqueued >= dlen); 15250Sstevel@tonic-gate 15260Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 15270Sstevel@tonic-gate if (can_deliver) { 15280Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)(dc + 1); 15290Sstevel@tonic-gate if (sctp_input_add_ancillary(sctp, &dmp, dc, fp, 153011042SErik.Nordmark@Sun.COM ipp, ira) == 0) { 15310Sstevel@tonic-gate dprint(1, ("sctp_data_chunk: delivering %lu " 15320Sstevel@tonic-gate "bytes\n", msgdsize(dmp))); 15330Sstevel@tonic-gate sctp->sctp_rwnd -= dlen; 15348348SEric.Yu@Sun.COM /* 15358348SEric.Yu@Sun.COM * Override b_flag for SCTP sockfs internal use 15368348SEric.Yu@Sun.COM */ 15378348SEric.Yu@Sun.COM dmp->b_flag = tpfinished ? 15388348SEric.Yu@Sun.COM 0 : SCTP_PARTIAL_DATA; 15390Sstevel@tonic-gate new_rwnd = sctp->sctp_ulp_recv(sctp->sctp_ulpd, 15408348SEric.Yu@Sun.COM dmp, msgdsize(dmp), 0, &error, NULL); 154110828SGeorge.Shepherd@Sun.COM if (new_rwnd < 0) 154210828SGeorge.Shepherd@Sun.COM sctp->sctp_rwnd = 0; 154310828SGeorge.Shepherd@Sun.COM else if (new_rwnd > sctp->sctp_rwnd) 15440Sstevel@tonic-gate sctp->sctp_rwnd = new_rwnd; 15450Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 15460Sstevel@tonic-gate } else { 15470Sstevel@tonic-gate freemsg(dmp); 15480Sstevel@tonic-gate return; 15490Sstevel@tonic-gate } 15500Sstevel@tonic-gate } else { 15510Sstevel@tonic-gate /* About to free the data */ 15520Sstevel@tonic-gate freemsg(dmp); 15530Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 15540Sstevel@tonic-gate } 15550Sstevel@tonic-gate } 15560Sstevel@tonic-gate 15570Sstevel@tonic-gate done: 15580Sstevel@tonic-gate 15590Sstevel@tonic-gate /* 15600Sstevel@tonic-gate * If there are gap reports pending, check if advancing 15610Sstevel@tonic-gate * the ftsn here closes a gap. If so, we can advance 15620Sstevel@tonic-gate * ftsn to the end of the set. 15630Sstevel@tonic-gate */ 15640Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL && 15650Sstevel@tonic-gate sctp->sctp_ftsn == sctp->sctp_sack_info->begin) { 15660Sstevel@tonic-gate sctp->sctp_ftsn = sctp->sctp_sack_info->end + 1; 15670Sstevel@tonic-gate } 15680Sstevel@tonic-gate /* 15690Sstevel@tonic-gate * If ftsn has moved forward, maybe we can remove gap reports. 15700Sstevel@tonic-gate * NB: dmp may now be NULL, so don't dereference it here. 15710Sstevel@tonic-gate */ 15720Sstevel@tonic-gate if (oftsn != sctp->sctp_ftsn && sctp->sctp_sack_info != NULL) { 15730Sstevel@tonic-gate sctp_ack_rem(&sctp->sctp_sack_info, sctp->sctp_ftsn - 1, 15740Sstevel@tonic-gate &sctp->sctp_sack_gaps); 15750Sstevel@tonic-gate dprint(2, ("data_chunk: removed acks before %x (num=%d)\n", 15760Sstevel@tonic-gate sctp->sctp_ftsn - 1, sctp->sctp_sack_gaps)); 15770Sstevel@tonic-gate } 15780Sstevel@tonic-gate 15790Sstevel@tonic-gate #ifdef DEBUG 15800Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL) { 15810Sstevel@tonic-gate ASSERT(sctp->sctp_ftsn != sctp->sctp_sack_info->begin); 15820Sstevel@tonic-gate } 15830Sstevel@tonic-gate #endif 15840Sstevel@tonic-gate 15850Sstevel@tonic-gate #undef SCTP_ACK_IT 15860Sstevel@tonic-gate } 15870Sstevel@tonic-gate 15880Sstevel@tonic-gate void 15890Sstevel@tonic-gate sctp_fill_sack(sctp_t *sctp, unsigned char *dst, int sacklen) 15900Sstevel@tonic-gate { 15910Sstevel@tonic-gate sctp_chunk_hdr_t *sch; 15920Sstevel@tonic-gate sctp_sack_chunk_t *sc; 15930Sstevel@tonic-gate sctp_sack_frag_t *sf; 15940Sstevel@tonic-gate uint16_t num_gaps = sctp->sctp_sack_gaps; 15950Sstevel@tonic-gate sctp_set_t *sp; 15960Sstevel@tonic-gate 15970Sstevel@tonic-gate /* Chunk hdr */ 15980Sstevel@tonic-gate sch = (sctp_chunk_hdr_t *)dst; 15990Sstevel@tonic-gate sch->sch_id = CHUNK_SACK; 16000Sstevel@tonic-gate sch->sch_flags = 0; 16010Sstevel@tonic-gate sch->sch_len = htons(sacklen); 16020Sstevel@tonic-gate 16030Sstevel@tonic-gate /* SACK chunk */ 16040Sstevel@tonic-gate sctp->sctp_lastacked = sctp->sctp_ftsn - 1; 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate sc = (sctp_sack_chunk_t *)(sch + 1); 16070Sstevel@tonic-gate sc->ssc_cumtsn = htonl(sctp->sctp_lastacked); 16080Sstevel@tonic-gate if (sctp->sctp_rxqueued < sctp->sctp_rwnd) { 16090Sstevel@tonic-gate sc->ssc_a_rwnd = htonl(sctp->sctp_rwnd - sctp->sctp_rxqueued); 16100Sstevel@tonic-gate } else { 16110Sstevel@tonic-gate sc->ssc_a_rwnd = 0; 16120Sstevel@tonic-gate } 16130Sstevel@tonic-gate sc->ssc_numfrags = htons(num_gaps); 16140Sstevel@tonic-gate sc->ssc_numdups = 0; 16150Sstevel@tonic-gate 16160Sstevel@tonic-gate /* lay in gap reports */ 16170Sstevel@tonic-gate sf = (sctp_sack_frag_t *)(sc + 1); 16180Sstevel@tonic-gate for (sp = sctp->sctp_sack_info; sp; sp = sp->next) { 16190Sstevel@tonic-gate uint16_t offset; 16200Sstevel@tonic-gate 16210Sstevel@tonic-gate /* start */ 16220Sstevel@tonic-gate if (sp->begin > sctp->sctp_lastacked) { 16230Sstevel@tonic-gate offset = (uint16_t)(sp->begin - sctp->sctp_lastacked); 16240Sstevel@tonic-gate } else { 16250Sstevel@tonic-gate /* sequence number wrap */ 16260Sstevel@tonic-gate offset = (uint16_t)(UINT32_MAX - sctp->sctp_lastacked + 16270Sstevel@tonic-gate sp->begin); 16280Sstevel@tonic-gate } 16290Sstevel@tonic-gate sf->ssf_start = htons(offset); 16300Sstevel@tonic-gate 16310Sstevel@tonic-gate /* end */ 16320Sstevel@tonic-gate if (sp->end >= sp->begin) { 16330Sstevel@tonic-gate offset += (uint16_t)(sp->end - sp->begin); 16340Sstevel@tonic-gate } else { 16350Sstevel@tonic-gate /* sequence number wrap */ 16360Sstevel@tonic-gate offset += (uint16_t)(UINT32_MAX - sp->begin + sp->end); 16370Sstevel@tonic-gate } 16380Sstevel@tonic-gate sf->ssf_end = htons(offset); 16390Sstevel@tonic-gate 16400Sstevel@tonic-gate sf++; 16410Sstevel@tonic-gate /* This is just for debugging (a la the following assertion) */ 16420Sstevel@tonic-gate num_gaps--; 16430Sstevel@tonic-gate } 16440Sstevel@tonic-gate 16450Sstevel@tonic-gate ASSERT(num_gaps == 0); 16460Sstevel@tonic-gate 16470Sstevel@tonic-gate /* If the SACK timer is running, stop it */ 16480Sstevel@tonic-gate if (sctp->sctp_ack_timer_running) { 16490Sstevel@tonic-gate sctp_timer_stop(sctp->sctp_ack_mp); 16500Sstevel@tonic-gate sctp->sctp_ack_timer_running = B_FALSE; 16510Sstevel@tonic-gate } 16520Sstevel@tonic-gate 16530Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_obchunks); 165410212SGeorge.Shepherd@Sun.COM BUMP_LOCAL(sctp->sctp_osacks); 16550Sstevel@tonic-gate } 16560Sstevel@tonic-gate 16570Sstevel@tonic-gate mblk_t * 16580Sstevel@tonic-gate sctp_make_sack(sctp_t *sctp, sctp_faddr_t *sendto, mblk_t *dups) 16590Sstevel@tonic-gate { 16600Sstevel@tonic-gate mblk_t *smp; 16610Sstevel@tonic-gate size_t slen; 16620Sstevel@tonic-gate sctp_chunk_hdr_t *sch; 16630Sstevel@tonic-gate sctp_sack_chunk_t *sc; 16643430Skcpoon int32_t acks_max; 16653448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 16664964Skcpoon uint32_t dups_len; 16674964Skcpoon sctp_faddr_t *fp; 16680Sstevel@tonic-gate 166911042SErik.Nordmark@Sun.COM ASSERT(sendto != NULL); 167011042SErik.Nordmark@Sun.COM 16710Sstevel@tonic-gate if (sctp->sctp_force_sack) { 16720Sstevel@tonic-gate sctp->sctp_force_sack = 0; 16730Sstevel@tonic-gate goto checks_done; 16740Sstevel@tonic-gate } 16750Sstevel@tonic-gate 16763448Sdh155122 acks_max = sctps->sctps_deferred_acks_max; 16770Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_ESTABLISHED) { 16783430Skcpoon if (sctp->sctp_sack_toggle < acks_max) { 16790Sstevel@tonic-gate /* no need to SACK right now */ 16800Sstevel@tonic-gate dprint(2, ("sctp_make_sack: %p no sack (toggle)\n", 16811676Sjpk (void *)sctp)); 16820Sstevel@tonic-gate return (NULL); 16833430Skcpoon } else if (sctp->sctp_sack_toggle >= acks_max) { 16840Sstevel@tonic-gate sctp->sctp_sack_toggle = 0; 16850Sstevel@tonic-gate } 16860Sstevel@tonic-gate } 16870Sstevel@tonic-gate 16880Sstevel@tonic-gate if (sctp->sctp_ftsn == sctp->sctp_lastacked + 1) { 16891676Sjpk dprint(2, ("sctp_make_sack: %p no sack (already)\n", 16901676Sjpk (void *)sctp)); 16910Sstevel@tonic-gate return (NULL); 16920Sstevel@tonic-gate } 16930Sstevel@tonic-gate 16940Sstevel@tonic-gate checks_done: 16950Sstevel@tonic-gate dprint(2, ("sctp_make_sack: acking %x\n", sctp->sctp_ftsn - 1)); 16960Sstevel@tonic-gate 16974964Skcpoon if (dups != NULL) 16984964Skcpoon dups_len = MBLKL(dups); 16994964Skcpoon else 17004964Skcpoon dups_len = 0; 17010Sstevel@tonic-gate slen = sizeof (*sch) + sizeof (*sc) + 17020Sstevel@tonic-gate (sizeof (sctp_sack_frag_t) * sctp->sctp_sack_gaps); 17034964Skcpoon 17044964Skcpoon /* 17054964Skcpoon * If there are error chunks, check and see if we can send the 17064964Skcpoon * SACK chunk and error chunks together in one packet. If not, 17074964Skcpoon * send the error chunks out now. 17084964Skcpoon */ 17094964Skcpoon if (sctp->sctp_err_chunks != NULL) { 17104964Skcpoon fp = SCTP_CHUNK_DEST(sctp->sctp_err_chunks); 17114964Skcpoon if (sctp->sctp_err_len + slen + dups_len > fp->sfa_pmss) { 17124964Skcpoon if ((smp = sctp_make_mp(sctp, fp, 0)) == NULL) { 17134964Skcpoon SCTP_KSTAT(sctps, sctp_send_err_failed); 17144964Skcpoon SCTP_KSTAT(sctps, sctp_send_sack_failed); 17154964Skcpoon freemsg(sctp->sctp_err_chunks); 17164964Skcpoon sctp->sctp_err_chunks = NULL; 17174964Skcpoon sctp->sctp_err_len = 0; 17184964Skcpoon return (NULL); 17194964Skcpoon } 17204964Skcpoon smp->b_cont = sctp->sctp_err_chunks; 172111042SErik.Nordmark@Sun.COM sctp_set_iplen(sctp, smp, fp->ixa); 172211042SErik.Nordmark@Sun.COM (void) conn_ip_output(smp, fp->ixa); 172311042SErik.Nordmark@Sun.COM BUMP_LOCAL(sctp->sctp_opkts); 17244964Skcpoon sctp->sctp_err_chunks = NULL; 17254964Skcpoon sctp->sctp_err_len = 0; 17264964Skcpoon } 17274964Skcpoon } 17280Sstevel@tonic-gate smp = sctp_make_mp(sctp, sendto, slen); 17290Sstevel@tonic-gate if (smp == NULL) { 17303448Sdh155122 SCTP_KSTAT(sctps, sctp_send_sack_failed); 17310Sstevel@tonic-gate return (NULL); 17320Sstevel@tonic-gate } 17330Sstevel@tonic-gate sch = (sctp_chunk_hdr_t *)smp->b_wptr; 17340Sstevel@tonic-gate 17350Sstevel@tonic-gate sctp_fill_sack(sctp, smp->b_wptr, slen); 17360Sstevel@tonic-gate smp->b_wptr += slen; 17374964Skcpoon if (dups != NULL) { 17380Sstevel@tonic-gate sc = (sctp_sack_chunk_t *)(sch + 1); 17394964Skcpoon sc->ssc_numdups = htons(MBLKL(dups) / sizeof (uint32_t)); 17404964Skcpoon sch->sch_len = htons(slen + dups_len); 17410Sstevel@tonic-gate smp->b_cont = dups; 17420Sstevel@tonic-gate } 17430Sstevel@tonic-gate 17444964Skcpoon if (sctp->sctp_err_chunks != NULL) { 17454964Skcpoon linkb(smp, sctp->sctp_err_chunks); 17464964Skcpoon sctp->sctp_err_chunks = NULL; 17474964Skcpoon sctp->sctp_err_len = 0; 17484964Skcpoon } 17490Sstevel@tonic-gate return (smp); 17500Sstevel@tonic-gate } 17510Sstevel@tonic-gate 17524964Skcpoon /* 17534964Skcpoon * Check and see if we need to send a SACK chunk. If it is needed, 17544964Skcpoon * send it out. Return true if a SACK chunk is sent, false otherwise. 17554964Skcpoon */ 17564964Skcpoon boolean_t 17570Sstevel@tonic-gate sctp_sack(sctp_t *sctp, mblk_t *dups) 17580Sstevel@tonic-gate { 17590Sstevel@tonic-gate mblk_t *smp; 17603448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 17610Sstevel@tonic-gate 17620Sstevel@tonic-gate /* If we are shutting down, let send_shutdown() bundle the SACK */ 17630Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_SHUTDOWN_SENT) { 17640Sstevel@tonic-gate sctp_send_shutdown(sctp, 0); 17650Sstevel@tonic-gate } 17660Sstevel@tonic-gate 17670Sstevel@tonic-gate ASSERT(sctp->sctp_lastdata != NULL); 17680Sstevel@tonic-gate 17690Sstevel@tonic-gate if ((smp = sctp_make_sack(sctp, sctp->sctp_lastdata, dups)) == NULL) { 17700Sstevel@tonic-gate /* The caller of sctp_sack() will not free the dups mblk. */ 17710Sstevel@tonic-gate if (dups != NULL) 17720Sstevel@tonic-gate freeb(dups); 17734964Skcpoon return (B_FALSE); 17740Sstevel@tonic-gate } 17750Sstevel@tonic-gate dprint(2, ("sctp_sack: sending to %p %x:%x:%x:%x\n", 17761676Sjpk (void *)sctp->sctp_lastdata, 17771676Sjpk SCTP_PRINTADDR(sctp->sctp_lastdata->faddr))); 17780Sstevel@tonic-gate 1779*11066Srafael.vanoni@sun.com sctp->sctp_active = ddi_get_lbolt64(); 17800Sstevel@tonic-gate 17813448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpOutAck); 178211042SErik.Nordmark@Sun.COM 178311042SErik.Nordmark@Sun.COM sctp_set_iplen(sctp, smp, sctp->sctp_lastdata->ixa); 178411042SErik.Nordmark@Sun.COM (void) conn_ip_output(smp, sctp->sctp_lastdata->ixa); 178511042SErik.Nordmark@Sun.COM BUMP_LOCAL(sctp->sctp_opkts); 17864964Skcpoon return (B_TRUE); 17870Sstevel@tonic-gate } 17880Sstevel@tonic-gate 17890Sstevel@tonic-gate /* 17900Sstevel@tonic-gate * This is called if we have a message that was partially sent and is 17910Sstevel@tonic-gate * abandoned. The cum TSN will be the last chunk sent for this message, 17920Sstevel@tonic-gate * subsequent chunks will be marked ABANDONED. We send a Forward TSN 17930Sstevel@tonic-gate * chunk in this case with the TSN of the last sent chunk so that the 17940Sstevel@tonic-gate * peer can clean up its fragment list for this message. This message 17950Sstevel@tonic-gate * will be removed from the transmit list when the peer sends a SACK 17960Sstevel@tonic-gate * back. 17970Sstevel@tonic-gate */ 17980Sstevel@tonic-gate int 17990Sstevel@tonic-gate sctp_check_abandoned_msg(sctp_t *sctp, mblk_t *meta) 18000Sstevel@tonic-gate { 18010Sstevel@tonic-gate sctp_data_hdr_t *dh; 18020Sstevel@tonic-gate mblk_t *nmp; 18030Sstevel@tonic-gate mblk_t *head; 18040Sstevel@tonic-gate int32_t unsent = 0; 18050Sstevel@tonic-gate mblk_t *mp1 = meta->b_cont; 18060Sstevel@tonic-gate uint32_t adv_pap = sctp->sctp_adv_pap; 18070Sstevel@tonic-gate sctp_faddr_t *fp = sctp->sctp_current; 18083448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 18090Sstevel@tonic-gate 18100Sstevel@tonic-gate dh = (sctp_data_hdr_t *)mp1->b_rptr; 18110Sstevel@tonic-gate if (SEQ_GEQ(sctp->sctp_lastack_rxd, ntohl(dh->sdh_tsn))) { 18120Sstevel@tonic-gate sctp_ftsn_set_t *sets = NULL; 18130Sstevel@tonic-gate uint_t nsets = 0; 18140Sstevel@tonic-gate uint32_t seglen = sizeof (uint32_t); 18150Sstevel@tonic-gate boolean_t ubit = SCTP_DATA_GET_UBIT(dh); 18160Sstevel@tonic-gate 18170Sstevel@tonic-gate while (mp1->b_next != NULL && SCTP_CHUNK_ISSENT(mp1->b_next)) 18180Sstevel@tonic-gate mp1 = mp1->b_next; 18190Sstevel@tonic-gate dh = (sctp_data_hdr_t *)mp1->b_rptr; 18200Sstevel@tonic-gate sctp->sctp_adv_pap = ntohl(dh->sdh_tsn); 18210Sstevel@tonic-gate if (!ubit && 18220Sstevel@tonic-gate !sctp_add_ftsn_set(&sets, fp, meta, &nsets, &seglen)) { 18230Sstevel@tonic-gate sctp->sctp_adv_pap = adv_pap; 18240Sstevel@tonic-gate return (ENOMEM); 18250Sstevel@tonic-gate } 18260Sstevel@tonic-gate nmp = sctp_make_ftsn_chunk(sctp, fp, sets, nsets, seglen); 18270Sstevel@tonic-gate sctp_free_ftsn_set(sets); 18280Sstevel@tonic-gate if (nmp == NULL) { 18290Sstevel@tonic-gate sctp->sctp_adv_pap = adv_pap; 18300Sstevel@tonic-gate return (ENOMEM); 18310Sstevel@tonic-gate } 1832252Svi117747 head = sctp_add_proto_hdr(sctp, fp, nmp, 0, NULL); 18330Sstevel@tonic-gate if (head == NULL) { 18340Sstevel@tonic-gate sctp->sctp_adv_pap = adv_pap; 18350Sstevel@tonic-gate freemsg(nmp); 18363448Sdh155122 SCTP_KSTAT(sctps, sctp_send_ftsn_failed); 18370Sstevel@tonic-gate return (ENOMEM); 18380Sstevel@tonic-gate } 18390Sstevel@tonic-gate SCTP_MSG_SET_ABANDONED(meta); 184011042SErik.Nordmark@Sun.COM sctp_set_iplen(sctp, head, fp->ixa); 184111042SErik.Nordmark@Sun.COM (void) conn_ip_output(head, fp->ixa); 184211042SErik.Nordmark@Sun.COM BUMP_LOCAL(sctp->sctp_opkts); 18430Sstevel@tonic-gate if (!fp->timer_running) 18440Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto); 18450Sstevel@tonic-gate mp1 = mp1->b_next; 18460Sstevel@tonic-gate while (mp1 != NULL) { 18470Sstevel@tonic-gate ASSERT(!SCTP_CHUNK_ISSENT(mp1)); 18480Sstevel@tonic-gate ASSERT(!SCTP_CHUNK_ABANDONED(mp1)); 18490Sstevel@tonic-gate SCTP_ABANDON_CHUNK(mp1); 18500Sstevel@tonic-gate dh = (sctp_data_hdr_t *)mp1->b_rptr; 18510Sstevel@tonic-gate unsent += ntohs(dh->sdh_len) - sizeof (*dh); 18520Sstevel@tonic-gate mp1 = mp1->b_next; 18530Sstevel@tonic-gate } 18540Sstevel@tonic-gate ASSERT(sctp->sctp_unsent >= unsent); 18550Sstevel@tonic-gate sctp->sctp_unsent -= unsent; 18560Sstevel@tonic-gate /* 18570Sstevel@tonic-gate * Update ULP the amount of queued data, which is 18580Sstevel@tonic-gate * sent-unack'ed + unsent. 18590Sstevel@tonic-gate */ 18608348SEric.Yu@Sun.COM if (!SCTP_IS_DETACHED(sctp)) 18618348SEric.Yu@Sun.COM SCTP_TXQ_UPDATE(sctp); 18620Sstevel@tonic-gate return (0); 18630Sstevel@tonic-gate } 18640Sstevel@tonic-gate return (-1); 18650Sstevel@tonic-gate } 18660Sstevel@tonic-gate 18670Sstevel@tonic-gate uint32_t 18680Sstevel@tonic-gate sctp_cumack(sctp_t *sctp, uint32_t tsn, mblk_t **first_unacked) 18690Sstevel@tonic-gate { 18700Sstevel@tonic-gate mblk_t *ump, *nump, *mp = NULL; 18710Sstevel@tonic-gate uint16_t chunklen; 18720Sstevel@tonic-gate uint32_t xtsn; 18730Sstevel@tonic-gate sctp_faddr_t *fp; 18740Sstevel@tonic-gate sctp_data_hdr_t *sdc; 18750Sstevel@tonic-gate uint32_t cumack_forward = 0; 18760Sstevel@tonic-gate sctp_msg_hdr_t *mhdr; 18773448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 18780Sstevel@tonic-gate 18790Sstevel@tonic-gate ump = sctp->sctp_xmit_head; 18800Sstevel@tonic-gate 18810Sstevel@tonic-gate /* 18820Sstevel@tonic-gate * Free messages only when they're completely acked. 18830Sstevel@tonic-gate */ 18840Sstevel@tonic-gate while (ump != NULL) { 18850Sstevel@tonic-gate mhdr = (sctp_msg_hdr_t *)ump->b_rptr; 18860Sstevel@tonic-gate for (mp = ump->b_cont; mp != NULL; mp = mp->b_next) { 18870Sstevel@tonic-gate if (SCTP_CHUNK_ABANDONED(mp)) { 18880Sstevel@tonic-gate ASSERT(SCTP_IS_MSG_ABANDONED(ump)); 18890Sstevel@tonic-gate mp = NULL; 18900Sstevel@tonic-gate break; 18910Sstevel@tonic-gate } 18920Sstevel@tonic-gate /* 18930Sstevel@tonic-gate * We check for abandoned message if we are PR-SCTP 18940Sstevel@tonic-gate * aware, if this is not the first chunk in the 18950Sstevel@tonic-gate * message (b_cont) and if the message is marked 18960Sstevel@tonic-gate * abandoned. 18970Sstevel@tonic-gate */ 18980Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(mp)) { 18990Sstevel@tonic-gate if (sctp->sctp_prsctp_aware && 19000Sstevel@tonic-gate mp != ump->b_cont && 19010Sstevel@tonic-gate (SCTP_IS_MSG_ABANDONED(ump) || 19020Sstevel@tonic-gate SCTP_MSG_TO_BE_ABANDONED(ump, mhdr, 19030Sstevel@tonic-gate sctp))) { 19040Sstevel@tonic-gate (void) sctp_check_abandoned_msg(sctp, 19050Sstevel@tonic-gate ump); 19060Sstevel@tonic-gate } 19070Sstevel@tonic-gate goto cum_ack_done; 19080Sstevel@tonic-gate } 19090Sstevel@tonic-gate sdc = (sctp_data_hdr_t *)mp->b_rptr; 19100Sstevel@tonic-gate xtsn = ntohl(sdc->sdh_tsn); 19110Sstevel@tonic-gate if (SEQ_GEQ(sctp->sctp_lastack_rxd, xtsn)) 19120Sstevel@tonic-gate continue; 19130Sstevel@tonic-gate if (SEQ_GEQ(tsn, xtsn)) { 19140Sstevel@tonic-gate fp = SCTP_CHUNK_DEST(mp); 19150Sstevel@tonic-gate chunklen = ntohs(sdc->sdh_len); 19160Sstevel@tonic-gate 19170Sstevel@tonic-gate if (sctp->sctp_out_time != 0 && 19180Sstevel@tonic-gate xtsn == sctp->sctp_rtt_tsn) { 19190Sstevel@tonic-gate /* Got a new RTT measurement */ 19200Sstevel@tonic-gate sctp_update_rtt(sctp, fp, 1921*11066Srafael.vanoni@sun.com ddi_get_lbolt64() - 1922*11066Srafael.vanoni@sun.com sctp->sctp_out_time); 19230Sstevel@tonic-gate sctp->sctp_out_time = 0; 19240Sstevel@tonic-gate } 19250Sstevel@tonic-gate if (SCTP_CHUNK_ISACKED(mp)) 19260Sstevel@tonic-gate continue; 19271735Skcpoon SCTP_CHUNK_SET_SACKCNT(mp, 0); 19280Sstevel@tonic-gate SCTP_CHUNK_ACKED(mp); 19290Sstevel@tonic-gate ASSERT(fp->suna >= chunklen); 19300Sstevel@tonic-gate fp->suna -= chunklen; 19310Sstevel@tonic-gate fp->acked += chunklen; 19320Sstevel@tonic-gate cumack_forward += chunklen; 19330Sstevel@tonic-gate ASSERT(sctp->sctp_unacked >= 19340Sstevel@tonic-gate (chunklen - sizeof (*sdc))); 19350Sstevel@tonic-gate sctp->sctp_unacked -= 19360Sstevel@tonic-gate (chunklen - sizeof (*sdc)); 19370Sstevel@tonic-gate if (fp->suna == 0) { 19380Sstevel@tonic-gate /* all outstanding data acked */ 19390Sstevel@tonic-gate fp->pba = 0; 19400Sstevel@tonic-gate SCTP_FADDR_TIMER_STOP(fp); 19410Sstevel@tonic-gate } else { 19420Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, 19430Sstevel@tonic-gate fp->rto); 19440Sstevel@tonic-gate } 19450Sstevel@tonic-gate } else { 19460Sstevel@tonic-gate goto cum_ack_done; 19470Sstevel@tonic-gate } 19480Sstevel@tonic-gate } 19490Sstevel@tonic-gate nump = ump->b_next; 19500Sstevel@tonic-gate if (nump != NULL) 19510Sstevel@tonic-gate nump->b_prev = NULL; 19520Sstevel@tonic-gate if (ump == sctp->sctp_xmit_tail) 19530Sstevel@tonic-gate sctp->sctp_xmit_tail = nump; 19540Sstevel@tonic-gate if (SCTP_IS_MSG_ABANDONED(ump)) { 19550Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_prsctpdrop); 19560Sstevel@tonic-gate ump->b_next = NULL; 19570Sstevel@tonic-gate sctp_sendfail_event(sctp, ump, 0, B_TRUE); 19580Sstevel@tonic-gate } else { 19590Sstevel@tonic-gate sctp_free_msg(ump); 19600Sstevel@tonic-gate } 19610Sstevel@tonic-gate sctp->sctp_xmit_head = ump = nump; 19620Sstevel@tonic-gate } 19630Sstevel@tonic-gate cum_ack_done: 19640Sstevel@tonic-gate *first_unacked = mp; 19650Sstevel@tonic-gate if (cumack_forward > 0) { 19663448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInAck); 19670Sstevel@tonic-gate if (SEQ_GT(sctp->sctp_lastack_rxd, sctp->sctp_recovery_tsn)) { 19680Sstevel@tonic-gate sctp->sctp_recovery_tsn = sctp->sctp_lastack_rxd; 19690Sstevel@tonic-gate } 19700Sstevel@tonic-gate 19710Sstevel@tonic-gate /* 19720Sstevel@tonic-gate * Update ULP the amount of queued data, which is 19730Sstevel@tonic-gate * sent-unack'ed + unsent. 19740Sstevel@tonic-gate */ 19758348SEric.Yu@Sun.COM if (!SCTP_IS_DETACHED(sctp)) 19768348SEric.Yu@Sun.COM SCTP_TXQ_UPDATE(sctp); 19770Sstevel@tonic-gate 19780Sstevel@tonic-gate /* Time to send a shutdown? */ 19790Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_SHUTDOWN_PENDING) { 19800Sstevel@tonic-gate sctp_send_shutdown(sctp, 0); 19810Sstevel@tonic-gate } 19820Sstevel@tonic-gate sctp->sctp_xmit_unacked = mp; 19830Sstevel@tonic-gate } else { 19840Sstevel@tonic-gate /* dup ack */ 19853448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInDupAck); 19860Sstevel@tonic-gate } 19870Sstevel@tonic-gate sctp->sctp_lastack_rxd = tsn; 19880Sstevel@tonic-gate if (SEQ_LT(sctp->sctp_adv_pap, sctp->sctp_lastack_rxd)) 19890Sstevel@tonic-gate sctp->sctp_adv_pap = sctp->sctp_lastack_rxd; 19900Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_head || sctp->sctp_unacked == 0); 19910Sstevel@tonic-gate 19920Sstevel@tonic-gate return (cumack_forward); 19930Sstevel@tonic-gate } 19940Sstevel@tonic-gate 19950Sstevel@tonic-gate static int 19960Sstevel@tonic-gate sctp_set_frwnd(sctp_t *sctp, uint32_t frwnd) 19970Sstevel@tonic-gate { 19980Sstevel@tonic-gate uint32_t orwnd; 19990Sstevel@tonic-gate 20000Sstevel@tonic-gate if (sctp->sctp_unacked > frwnd) { 20010Sstevel@tonic-gate sctp->sctp_frwnd = 0; 20020Sstevel@tonic-gate return (0); 20030Sstevel@tonic-gate } 20040Sstevel@tonic-gate orwnd = sctp->sctp_frwnd; 20050Sstevel@tonic-gate sctp->sctp_frwnd = frwnd - sctp->sctp_unacked; 20060Sstevel@tonic-gate if (orwnd < sctp->sctp_frwnd) { 20070Sstevel@tonic-gate return (1); 20080Sstevel@tonic-gate } else { 20090Sstevel@tonic-gate return (0); 20100Sstevel@tonic-gate } 20110Sstevel@tonic-gate } 20120Sstevel@tonic-gate 20130Sstevel@tonic-gate /* 20140Sstevel@tonic-gate * For un-ordered messages. 20150Sstevel@tonic-gate * Walk the sctp->sctp_uo_frag list and remove any fragments with TSN 20160Sstevel@tonic-gate * less than/equal to ftsn. Fragments for un-ordered messages are 20170Sstevel@tonic-gate * strictly in sequence (w.r.t TSN). 20180Sstevel@tonic-gate */ 20190Sstevel@tonic-gate static int 20200Sstevel@tonic-gate sctp_ftsn_check_uo_frag(sctp_t *sctp, uint32_t ftsn) 20210Sstevel@tonic-gate { 20220Sstevel@tonic-gate mblk_t *hmp; 20230Sstevel@tonic-gate mblk_t *hmp_next; 20240Sstevel@tonic-gate sctp_data_hdr_t *dc; 20250Sstevel@tonic-gate int dlen = 0; 20260Sstevel@tonic-gate 20270Sstevel@tonic-gate hmp = sctp->sctp_uo_frags; 20280Sstevel@tonic-gate while (hmp != NULL) { 20290Sstevel@tonic-gate hmp_next = hmp->b_next; 20300Sstevel@tonic-gate dc = (sctp_data_hdr_t *)hmp->b_rptr; 20310Sstevel@tonic-gate if (SEQ_GT(ntohl(dc->sdh_tsn), ftsn)) 20320Sstevel@tonic-gate return (dlen); 20330Sstevel@tonic-gate sctp->sctp_uo_frags = hmp_next; 20340Sstevel@tonic-gate if (hmp_next != NULL) 20350Sstevel@tonic-gate hmp_next->b_prev = NULL; 20360Sstevel@tonic-gate hmp->b_next = NULL; 20370Sstevel@tonic-gate dlen += ntohs(dc->sdh_len) - sizeof (*dc); 20380Sstevel@tonic-gate freeb(hmp); 20390Sstevel@tonic-gate hmp = hmp_next; 20400Sstevel@tonic-gate } 20410Sstevel@tonic-gate return (dlen); 20420Sstevel@tonic-gate } 20430Sstevel@tonic-gate 20440Sstevel@tonic-gate /* 20450Sstevel@tonic-gate * For ordered messages. 20460Sstevel@tonic-gate * Check for existing fragments for an sid-ssn pair reported as abandoned, 20470Sstevel@tonic-gate * hence will not receive, in the Forward TSN. If there are fragments, then 20480Sstevel@tonic-gate * we just nuke them. If and when Partial Delivery API is supported, we 20490Sstevel@tonic-gate * would need to send a notification to the upper layer about this. 20500Sstevel@tonic-gate */ 20510Sstevel@tonic-gate static int 20520Sstevel@tonic-gate sctp_ftsn_check_frag(sctp_t *sctp, uint16_t ssn, sctp_instr_t *sip) 20530Sstevel@tonic-gate { 20540Sstevel@tonic-gate sctp_reass_t *srp; 20550Sstevel@tonic-gate mblk_t *hmp; 20560Sstevel@tonic-gate mblk_t *dmp; 20570Sstevel@tonic-gate mblk_t *hmp_next; 20580Sstevel@tonic-gate sctp_data_hdr_t *dc; 20590Sstevel@tonic-gate int dlen = 0; 20600Sstevel@tonic-gate 20610Sstevel@tonic-gate hmp = sip->istr_reass; 20620Sstevel@tonic-gate while (hmp != NULL) { 20630Sstevel@tonic-gate hmp_next = hmp->b_next; 20640Sstevel@tonic-gate srp = (sctp_reass_t *)DB_BASE(hmp); 20650Sstevel@tonic-gate if (SSN_GT(srp->ssn, ssn)) 20660Sstevel@tonic-gate return (dlen); 20670Sstevel@tonic-gate /* 20680Sstevel@tonic-gate * If we had sent part of this message up, send a partial 20690Sstevel@tonic-gate * delivery event. Since this is ordered delivery, we should 20700Sstevel@tonic-gate * have sent partial message only for the next in sequence, 20710Sstevel@tonic-gate * hence the ASSERT. See comments in sctp_data_chunk() for 20720Sstevel@tonic-gate * trypartial. 20730Sstevel@tonic-gate */ 20740Sstevel@tonic-gate if (srp->partial_delivered) { 20750Sstevel@tonic-gate ASSERT(sip->nextseq == srp->ssn); 20760Sstevel@tonic-gate sctp_partial_delivery_event(sctp); 20770Sstevel@tonic-gate } 20780Sstevel@tonic-gate /* Take it out of the reass queue */ 20790Sstevel@tonic-gate sip->istr_reass = hmp_next; 20800Sstevel@tonic-gate if (hmp_next != NULL) 20810Sstevel@tonic-gate hmp_next->b_prev = NULL; 20820Sstevel@tonic-gate hmp->b_next = NULL; 20830Sstevel@tonic-gate ASSERT(hmp->b_prev == NULL); 20840Sstevel@tonic-gate dmp = hmp; 20853845Svi117747 ASSERT(DB_TYPE(hmp) == M_CTL); 20863845Svi117747 dmp = hmp->b_cont; 20873845Svi117747 hmp->b_cont = NULL; 20883845Svi117747 freeb(hmp); 20893845Svi117747 hmp = dmp; 20900Sstevel@tonic-gate while (dmp != NULL) { 20910Sstevel@tonic-gate dc = (sctp_data_hdr_t *)dmp->b_rptr; 20920Sstevel@tonic-gate dlen += ntohs(dc->sdh_len) - sizeof (*dc); 20930Sstevel@tonic-gate dmp = dmp->b_cont; 20940Sstevel@tonic-gate } 20950Sstevel@tonic-gate freemsg(hmp); 20960Sstevel@tonic-gate hmp = hmp_next; 20970Sstevel@tonic-gate } 20980Sstevel@tonic-gate return (dlen); 20990Sstevel@tonic-gate } 21000Sstevel@tonic-gate 21010Sstevel@tonic-gate /* 21020Sstevel@tonic-gate * Update sctp_ftsn to the cumulative TSN from the Forward TSN chunk. Remove 21030Sstevel@tonic-gate * any SACK gaps less than the newly updated sctp_ftsn. Walk through the 21040Sstevel@tonic-gate * sid-ssn pair in the Forward TSN and for each, clean the fragment list 21050Sstevel@tonic-gate * for this pair, if needed, and check if we can deliver subsequent 21060Sstevel@tonic-gate * messages, if any, from the instream queue (that were waiting for this 21070Sstevel@tonic-gate * sid-ssn message to show up). Once we are done try to update the SACK 21080Sstevel@tonic-gate * info. We could get a duplicate Forward TSN, in which case just send 210911042SErik.Nordmark@Sun.COM * a SACK. If any of the sid values in the Forward TSN is invalid, 21100Sstevel@tonic-gate * send back an "Invalid Stream Identifier" error and continue processing 21110Sstevel@tonic-gate * the rest. 21120Sstevel@tonic-gate */ 21130Sstevel@tonic-gate static void 21140Sstevel@tonic-gate sctp_process_forward_tsn(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp, 211511042SErik.Nordmark@Sun.COM ip_pkt_t *ipp, ip_recv_attr_t *ira) 21160Sstevel@tonic-gate { 21170Sstevel@tonic-gate uint32_t *ftsn = (uint32_t *)(ch + 1); 21180Sstevel@tonic-gate ftsn_entry_t *ftsn_entry; 21190Sstevel@tonic-gate sctp_instr_t *instr; 21200Sstevel@tonic-gate boolean_t can_deliver = B_TRUE; 21210Sstevel@tonic-gate size_t dlen; 21220Sstevel@tonic-gate int flen; 21230Sstevel@tonic-gate mblk_t *dmp; 21240Sstevel@tonic-gate mblk_t *pmp; 21250Sstevel@tonic-gate sctp_data_hdr_t *dc; 21260Sstevel@tonic-gate ssize_t remaining; 21273448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 21280Sstevel@tonic-gate 21290Sstevel@tonic-gate *ftsn = ntohl(*ftsn); 21300Sstevel@tonic-gate remaining = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*ftsn); 21310Sstevel@tonic-gate 21320Sstevel@tonic-gate if (SCTP_IS_DETACHED(sctp)) { 21333448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInClosed); 21340Sstevel@tonic-gate can_deliver = B_FALSE; 21350Sstevel@tonic-gate } 21360Sstevel@tonic-gate /* 21370Sstevel@tonic-gate * un-ordered messages don't have SID-SSN pair entries, we check 21380Sstevel@tonic-gate * for any fragments (for un-ordered message) to be discarded using 21390Sstevel@tonic-gate * the cumulative FTSN. 21400Sstevel@tonic-gate */ 21410Sstevel@tonic-gate flen = sctp_ftsn_check_uo_frag(sctp, *ftsn); 21420Sstevel@tonic-gate if (flen > 0) { 21430Sstevel@tonic-gate ASSERT(sctp->sctp_rxqueued >= flen); 21440Sstevel@tonic-gate sctp->sctp_rxqueued -= flen; 21450Sstevel@tonic-gate } 21460Sstevel@tonic-gate ftsn_entry = (ftsn_entry_t *)(ftsn + 1); 21470Sstevel@tonic-gate while (remaining >= sizeof (*ftsn_entry)) { 21480Sstevel@tonic-gate ftsn_entry->ftsn_sid = ntohs(ftsn_entry->ftsn_sid); 21490Sstevel@tonic-gate ftsn_entry->ftsn_ssn = ntohs(ftsn_entry->ftsn_ssn); 21500Sstevel@tonic-gate if (ftsn_entry->ftsn_sid >= sctp->sctp_num_istr) { 21519451SGeorge.Shepherd@Sun.COM sctp_bsc_t inval_parm; 21529451SGeorge.Shepherd@Sun.COM 21539451SGeorge.Shepherd@Sun.COM /* Will populate the CAUSE block in the ERROR chunk. */ 21549451SGeorge.Shepherd@Sun.COM inval_parm.bsc_sid = htons(ftsn_entry->ftsn_sid); 21559451SGeorge.Shepherd@Sun.COM /* RESERVED, ignored at the receiving end */ 21569451SGeorge.Shepherd@Sun.COM inval_parm.bsc_pad = 0; 21579451SGeorge.Shepherd@Sun.COM 21589451SGeorge.Shepherd@Sun.COM sctp_add_err(sctp, SCTP_ERR_BAD_SID, 21599451SGeorge.Shepherd@Sun.COM (void *)&inval_parm, sizeof (sctp_bsc_t), fp); 21600Sstevel@tonic-gate ftsn_entry++; 21610Sstevel@tonic-gate remaining -= sizeof (*ftsn_entry); 21620Sstevel@tonic-gate continue; 21630Sstevel@tonic-gate } 21640Sstevel@tonic-gate instr = &sctp->sctp_instr[ftsn_entry->ftsn_sid]; 21650Sstevel@tonic-gate flen = sctp_ftsn_check_frag(sctp, ftsn_entry->ftsn_ssn, instr); 21660Sstevel@tonic-gate /* Indicates frags were nuked, update rxqueued */ 21670Sstevel@tonic-gate if (flen > 0) { 21680Sstevel@tonic-gate ASSERT(sctp->sctp_rxqueued >= flen); 21690Sstevel@tonic-gate sctp->sctp_rxqueued -= flen; 21700Sstevel@tonic-gate } 21710Sstevel@tonic-gate /* 21720Sstevel@tonic-gate * It is possible to receive an FTSN chunk with SSN smaller 21730Sstevel@tonic-gate * than then nextseq if this chunk is a retransmission because 21740Sstevel@tonic-gate * of incomplete processing when it was first processed. 21750Sstevel@tonic-gate */ 21760Sstevel@tonic-gate if (SSN_GE(ftsn_entry->ftsn_ssn, instr->nextseq)) 21770Sstevel@tonic-gate instr->nextseq = ftsn_entry->ftsn_ssn + 1; 21780Sstevel@tonic-gate while (instr->istr_nmsgs > 0) { 21790Sstevel@tonic-gate mblk_t *next; 21800Sstevel@tonic-gate 21810Sstevel@tonic-gate dmp = (mblk_t *)instr->istr_msgs; 21820Sstevel@tonic-gate dc = (sctp_data_hdr_t *)dmp->b_rptr; 21830Sstevel@tonic-gate if (ntohs(dc->sdh_ssn) != instr->nextseq) 21840Sstevel@tonic-gate break; 21850Sstevel@tonic-gate 21860Sstevel@tonic-gate next = dmp->b_next; 21870Sstevel@tonic-gate dlen = dmp->b_wptr - dmp->b_rptr - sizeof (*dc); 21880Sstevel@tonic-gate for (pmp = dmp->b_cont; pmp != NULL; 21890Sstevel@tonic-gate pmp = pmp->b_cont) { 219010828SGeorge.Shepherd@Sun.COM dlen += MBLKL(pmp); 21910Sstevel@tonic-gate } 21920Sstevel@tonic-gate if (can_deliver) { 21930Sstevel@tonic-gate int32_t nrwnd; 21948348SEric.Yu@Sun.COM int error; 21950Sstevel@tonic-gate 21960Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)(dc + 1); 21970Sstevel@tonic-gate dmp->b_next = NULL; 21980Sstevel@tonic-gate ASSERT(dmp->b_prev == NULL); 21990Sstevel@tonic-gate if (sctp_input_add_ancillary(sctp, 220011042SErik.Nordmark@Sun.COM &dmp, dc, fp, ipp, ira) == 0) { 22010Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 22020Sstevel@tonic-gate sctp->sctp_rwnd -= dlen; 22038348SEric.Yu@Sun.COM /* 22048348SEric.Yu@Sun.COM * Override b_flag for SCTP sockfs 22058348SEric.Yu@Sun.COM * internal use 22068348SEric.Yu@Sun.COM */ 22078348SEric.Yu@Sun.COM 22088348SEric.Yu@Sun.COM dmp->b_flag = 0; 22090Sstevel@tonic-gate nrwnd = sctp->sctp_ulp_recv( 22108348SEric.Yu@Sun.COM sctp->sctp_ulpd, dmp, msgdsize(dmp), 22118348SEric.Yu@Sun.COM 0, &error, NULL); 221210828SGeorge.Shepherd@Sun.COM if (nrwnd < 0) 221310828SGeorge.Shepherd@Sun.COM sctp->sctp_rwnd = 0; 221410828SGeorge.Shepherd@Sun.COM else if (nrwnd > sctp->sctp_rwnd) 22150Sstevel@tonic-gate sctp->sctp_rwnd = nrwnd; 22160Sstevel@tonic-gate } else { 22170Sstevel@tonic-gate /* 22180Sstevel@tonic-gate * We will resume processing when 22190Sstevel@tonic-gate * the FTSN chunk is re-xmitted. 22200Sstevel@tonic-gate */ 22210Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)dc; 22220Sstevel@tonic-gate dmp->b_next = next; 22230Sstevel@tonic-gate dprint(0, 22240Sstevel@tonic-gate ("FTSN dequeuing %u failed\n", 22250Sstevel@tonic-gate ntohs(dc->sdh_ssn))); 22260Sstevel@tonic-gate return; 22270Sstevel@tonic-gate } 22280Sstevel@tonic-gate } else { 22290Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 22300Sstevel@tonic-gate ASSERT(dmp->b_prev == NULL); 22310Sstevel@tonic-gate dmp->b_next = NULL; 22320Sstevel@tonic-gate freemsg(dmp); 22330Sstevel@tonic-gate } 22340Sstevel@tonic-gate instr->istr_nmsgs--; 22350Sstevel@tonic-gate instr->nextseq++; 22360Sstevel@tonic-gate sctp->sctp_istr_nmsgs--; 22370Sstevel@tonic-gate if (next != NULL) 22380Sstevel@tonic-gate next->b_prev = NULL; 22390Sstevel@tonic-gate instr->istr_msgs = next; 22400Sstevel@tonic-gate } 22410Sstevel@tonic-gate ftsn_entry++; 22420Sstevel@tonic-gate remaining -= sizeof (*ftsn_entry); 22430Sstevel@tonic-gate } 22440Sstevel@tonic-gate /* Duplicate FTSN */ 22450Sstevel@tonic-gate if (*ftsn <= (sctp->sctp_ftsn - 1)) { 22460Sstevel@tonic-gate sctp->sctp_force_sack = 1; 22470Sstevel@tonic-gate return; 22480Sstevel@tonic-gate } 22490Sstevel@tonic-gate /* Advance cum TSN to that reported in the Forward TSN chunk */ 22500Sstevel@tonic-gate sctp->sctp_ftsn = *ftsn + 1; 22510Sstevel@tonic-gate 22520Sstevel@tonic-gate /* Remove all the SACK gaps before the new cum TSN */ 22530Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL) { 22540Sstevel@tonic-gate sctp_ack_rem(&sctp->sctp_sack_info, sctp->sctp_ftsn - 1, 22550Sstevel@tonic-gate &sctp->sctp_sack_gaps); 22560Sstevel@tonic-gate } 22570Sstevel@tonic-gate /* 22580Sstevel@tonic-gate * If there are gap reports pending, check if advancing 22590Sstevel@tonic-gate * the ftsn here closes a gap. If so, we can advance 22600Sstevel@tonic-gate * ftsn to the end of the set. 22610Sstevel@tonic-gate * If ftsn has moved forward, maybe we can remove gap reports. 22620Sstevel@tonic-gate */ 22630Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL && 22640Sstevel@tonic-gate sctp->sctp_ftsn == sctp->sctp_sack_info->begin) { 22650Sstevel@tonic-gate sctp->sctp_ftsn = sctp->sctp_sack_info->end + 1; 22660Sstevel@tonic-gate sctp_ack_rem(&sctp->sctp_sack_info, sctp->sctp_ftsn - 1, 22670Sstevel@tonic-gate &sctp->sctp_sack_gaps); 22680Sstevel@tonic-gate } 22690Sstevel@tonic-gate } 22700Sstevel@tonic-gate 22710Sstevel@tonic-gate /* 22720Sstevel@tonic-gate * When we have processed a SACK we check to see if we can advance the 22730Sstevel@tonic-gate * cumulative TSN if there are abandoned chunks immediately following 22740Sstevel@tonic-gate * the updated cumulative TSN. If there are, we attempt to send a 22750Sstevel@tonic-gate * Forward TSN chunk. 22760Sstevel@tonic-gate */ 22770Sstevel@tonic-gate static void 22780Sstevel@tonic-gate sctp_check_abandoned_data(sctp_t *sctp, sctp_faddr_t *fp) 22790Sstevel@tonic-gate { 22800Sstevel@tonic-gate mblk_t *meta = sctp->sctp_xmit_head; 22810Sstevel@tonic-gate mblk_t *mp; 22820Sstevel@tonic-gate mblk_t *nmp; 22830Sstevel@tonic-gate uint32_t seglen; 22840Sstevel@tonic-gate uint32_t adv_pap = sctp->sctp_adv_pap; 22850Sstevel@tonic-gate 22860Sstevel@tonic-gate /* 22870Sstevel@tonic-gate * We only check in the first meta since otherwise we can't 22880Sstevel@tonic-gate * advance the cumulative ack point. We just look for chunks 22890Sstevel@tonic-gate * marked for retransmission, else we might prematurely 22900Sstevel@tonic-gate * send an FTSN for a sent, but unacked, chunk. 22910Sstevel@tonic-gate */ 22920Sstevel@tonic-gate for (mp = meta->b_cont; mp != NULL; mp = mp->b_next) { 22930Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(mp)) 22940Sstevel@tonic-gate return; 22950Sstevel@tonic-gate if (SCTP_CHUNK_WANT_REXMIT(mp)) 22960Sstevel@tonic-gate break; 22970Sstevel@tonic-gate } 22980Sstevel@tonic-gate if (mp == NULL) 22990Sstevel@tonic-gate return; 23000Sstevel@tonic-gate sctp_check_adv_ack_pt(sctp, meta, mp); 23010Sstevel@tonic-gate if (SEQ_GT(sctp->sctp_adv_pap, adv_pap)) { 23020Sstevel@tonic-gate sctp_make_ftsns(sctp, meta, mp, &nmp, fp, &seglen); 23030Sstevel@tonic-gate if (nmp == NULL) { 23040Sstevel@tonic-gate sctp->sctp_adv_pap = adv_pap; 23050Sstevel@tonic-gate if (!fp->timer_running) 23060Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto); 23070Sstevel@tonic-gate return; 23080Sstevel@tonic-gate } 230911042SErik.Nordmark@Sun.COM sctp_set_iplen(sctp, nmp, fp->ixa); 231011042SErik.Nordmark@Sun.COM (void) conn_ip_output(nmp, fp->ixa); 231111042SErik.Nordmark@Sun.COM BUMP_LOCAL(sctp->sctp_opkts); 23120Sstevel@tonic-gate if (!fp->timer_running) 23130Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto); 23140Sstevel@tonic-gate } 23150Sstevel@tonic-gate } 23160Sstevel@tonic-gate 2317852Svi117747 /* 2318852Svi117747 * The processing here follows the same logic in sctp_got_sack(), the reason 2319852Svi117747 * we do this separately is because, usually, gap blocks are ordered and 2320852Svi117747 * we can process it in sctp_got_sack(). However if they aren't we would 2321852Svi117747 * need to do some additional non-optimal stuff when we start processing the 2322852Svi117747 * unordered gaps. To that effect sctp_got_sack() does the processing in the 2323852Svi117747 * simple case and this does the same in the more involved case. 2324852Svi117747 */ 2325852Svi117747 static uint32_t 2326852Svi117747 sctp_process_uo_gaps(sctp_t *sctp, uint32_t ctsn, sctp_sack_frag_t *ssf, 2327852Svi117747 int num_gaps, mblk_t *umphead, mblk_t *mphead, int *trysend, 2328852Svi117747 boolean_t *fast_recovery, uint32_t fr_xtsn) 2329852Svi117747 { 2330852Svi117747 uint32_t xtsn; 2331852Svi117747 uint32_t gapstart = 0; 2332852Svi117747 uint32_t gapend = 0; 2333852Svi117747 int gapcnt; 2334852Svi117747 uint16_t chunklen; 2335852Svi117747 sctp_data_hdr_t *sdc; 2336852Svi117747 int gstart; 2337852Svi117747 mblk_t *ump = umphead; 2338852Svi117747 mblk_t *mp = mphead; 2339852Svi117747 sctp_faddr_t *fp; 2340852Svi117747 uint32_t acked = 0; 23413448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 2342852Svi117747 2343852Svi117747 /* 2344852Svi117747 * gstart tracks the last (in the order of TSN) gapstart that 2345852Svi117747 * we process in this SACK gaps walk. 2346852Svi117747 */ 2347852Svi117747 gstart = ctsn; 2348852Svi117747 2349852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2350852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2351852Svi117747 for (gapcnt = 0; gapcnt < num_gaps; gapcnt++, ssf++) { 2352852Svi117747 if (gapstart != 0) { 2353852Svi117747 /* 2354852Svi117747 * If we have reached the end of the transmit list or 2355852Svi117747 * hit an unsent chunk or encountered an unordered gap 2356852Svi117747 * block start from the ctsn again. 2357852Svi117747 */ 2358852Svi117747 if (ump == NULL || !SCTP_CHUNK_ISSENT(mp) || 2359852Svi117747 SEQ_LT(ctsn + ntohs(ssf->ssf_start), xtsn)) { 2360852Svi117747 ump = umphead; 2361852Svi117747 mp = mphead; 2362852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2363852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2364852Svi117747 } 2365852Svi117747 } 2366852Svi117747 2367852Svi117747 gapstart = ctsn + ntohs(ssf->ssf_start); 2368852Svi117747 gapend = ctsn + ntohs(ssf->ssf_end); 2369852Svi117747 237010068SChandrasekar.Marimuthu@Sun.COM /* 237110068SChandrasekar.Marimuthu@Sun.COM * Sanity checks: 237210068SChandrasekar.Marimuthu@Sun.COM * 237310068SChandrasekar.Marimuthu@Sun.COM * 1. SACK for TSN we have not sent - ABORT 237410068SChandrasekar.Marimuthu@Sun.COM * 2. Invalid or spurious gaps, ignore all gaps 237510068SChandrasekar.Marimuthu@Sun.COM */ 2376852Svi117747 if (SEQ_GT(gapstart, sctp->sctp_ltsn - 1) || 2377852Svi117747 SEQ_GT(gapend, sctp->sctp_ltsn - 1)) { 23783448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInAckUnsent); 2379852Svi117747 *trysend = -1; 2380852Svi117747 return (acked); 238110068SChandrasekar.Marimuthu@Sun.COM } else if (SEQ_LT(gapend, gapstart) || 238210068SChandrasekar.Marimuthu@Sun.COM SEQ_LEQ(gapstart, ctsn)) { 2383852Svi117747 break; 2384852Svi117747 } 2385852Svi117747 /* 2386852Svi117747 * The xtsn can be the TSN processed for the last gap 2387852Svi117747 * (gapend) or it could be the cumulative TSN. We continue 2388852Svi117747 * with the last xtsn as long as the gaps are ordered, when 2389852Svi117747 * we hit an unordered gap, we re-start from the cumulative 2390852Svi117747 * TSN. For the first gap it is always the cumulative TSN. 2391852Svi117747 */ 2392852Svi117747 while (xtsn != gapstart) { 2393852Svi117747 /* 2394852Svi117747 * We can't reliably check for reneged chunks 2395852Svi117747 * when walking the unordered list, so we don't. 2396852Svi117747 * In case the peer reneges then we will end up 2397852Svi117747 * sending the reneged chunk via timeout. 2398852Svi117747 */ 2399852Svi117747 mp = mp->b_next; 2400852Svi117747 if (mp == NULL) { 2401852Svi117747 ump = ump->b_next; 2402852Svi117747 /* 2403852Svi117747 * ump can't be NULL because of the sanity 2404852Svi117747 * check above. 2405852Svi117747 */ 2406852Svi117747 ASSERT(ump != NULL); 2407852Svi117747 mp = ump->b_cont; 2408852Svi117747 } 2409852Svi117747 /* 2410852Svi117747 * mp can't be unsent because of the sanity check 2411852Svi117747 * above. 2412852Svi117747 */ 2413852Svi117747 ASSERT(SCTP_CHUNK_ISSENT(mp)); 2414852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2415852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2416852Svi117747 } 2417852Svi117747 /* 2418852Svi117747 * Now that we have found the chunk with TSN == 'gapstart', 2419852Svi117747 * let's walk till we hit the chunk with TSN == 'gapend'. 2420852Svi117747 * All intermediate chunks will be marked ACKED, if they 2421852Svi117747 * haven't already been. 2422852Svi117747 */ 2423852Svi117747 while (SEQ_LEQ(xtsn, gapend)) { 2424852Svi117747 /* 2425852Svi117747 * SACKed 2426852Svi117747 */ 2427852Svi117747 SCTP_CHUNK_SET_SACKCNT(mp, 0); 2428852Svi117747 if (!SCTP_CHUNK_ISACKED(mp)) { 2429852Svi117747 SCTP_CHUNK_ACKED(mp); 2430852Svi117747 2431852Svi117747 fp = SCTP_CHUNK_DEST(mp); 2432852Svi117747 chunklen = ntohs(sdc->sdh_len); 2433852Svi117747 ASSERT(fp->suna >= chunklen); 2434852Svi117747 fp->suna -= chunklen; 2435852Svi117747 if (fp->suna == 0) { 2436852Svi117747 /* All outstanding data acked. */ 2437852Svi117747 fp->pba = 0; 2438852Svi117747 SCTP_FADDR_TIMER_STOP(fp); 2439852Svi117747 } 2440852Svi117747 fp->acked += chunklen; 2441852Svi117747 acked += chunklen; 2442852Svi117747 sctp->sctp_unacked -= chunklen - sizeof (*sdc); 2443852Svi117747 ASSERT(sctp->sctp_unacked >= 0); 2444852Svi117747 } 2445852Svi117747 /* 2446852Svi117747 * Move to the next message in the transmit list 2447852Svi117747 * if we are done with all the chunks from the current 2448852Svi117747 * message. Note, it is possible to hit the end of the 2449852Svi117747 * transmit list here, i.e. if we have already completed 2450852Svi117747 * processing the gap block. 2451852Svi117747 */ 2452852Svi117747 mp = mp->b_next; 2453852Svi117747 if (mp == NULL) { 2454852Svi117747 ump = ump->b_next; 2455852Svi117747 if (ump == NULL) { 2456852Svi117747 ASSERT(xtsn == gapend); 2457852Svi117747 break; 2458852Svi117747 } 2459852Svi117747 mp = ump->b_cont; 2460852Svi117747 } 2461852Svi117747 /* 2462852Svi117747 * Likewise, we can hit an unsent chunk once we have 2463852Svi117747 * completed processing the gap block. 2464852Svi117747 */ 2465852Svi117747 if (!SCTP_CHUNK_ISSENT(mp)) { 2466852Svi117747 ASSERT(xtsn == gapend); 2467852Svi117747 break; 2468852Svi117747 } 2469852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2470852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2471852Svi117747 } 2472852Svi117747 /* 2473852Svi117747 * We keep track of the last gap we successfully processed 2474852Svi117747 * so that we can terminate the walk below for incrementing 2475852Svi117747 * the SACK count. 2476852Svi117747 */ 2477852Svi117747 if (SEQ_LT(gstart, gapstart)) 2478852Svi117747 gstart = gapstart; 2479852Svi117747 } 2480852Svi117747 /* 2481852Svi117747 * Check if have incremented the SACK count for all unacked TSNs in 2482852Svi117747 * sctp_got_sack(), if so we are done. 2483852Svi117747 */ 2484852Svi117747 if (SEQ_LEQ(gstart, fr_xtsn)) 2485852Svi117747 return (acked); 2486852Svi117747 2487852Svi117747 ump = umphead; 2488852Svi117747 mp = mphead; 2489852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2490852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2491852Svi117747 while (SEQ_LT(xtsn, gstart)) { 2492852Svi117747 /* 2493852Svi117747 * We have incremented SACK count for TSNs less than fr_tsn 2494852Svi117747 * in sctp_got_sack(), so don't increment them again here. 2495852Svi117747 */ 2496852Svi117747 if (SEQ_GT(xtsn, fr_xtsn) && !SCTP_CHUNK_ISACKED(mp)) { 2497852Svi117747 SCTP_CHUNK_SET_SACKCNT(mp, SCTP_CHUNK_SACKCNT(mp) + 1); 24983448Sdh155122 if (SCTP_CHUNK_SACKCNT(mp) == 24993448Sdh155122 sctps->sctps_fast_rxt_thresh) { 2500852Svi117747 SCTP_CHUNK_REXMIT(mp); 2501852Svi117747 sctp->sctp_chk_fast_rexmit = B_TRUE; 2502852Svi117747 *trysend = 1; 2503852Svi117747 if (!*fast_recovery) { 2504852Svi117747 /* 2505852Svi117747 * Entering fast recovery. 2506852Svi117747 */ 2507852Svi117747 fp = SCTP_CHUNK_DEST(mp); 2508852Svi117747 fp->ssthresh = fp->cwnd / 2; 2509852Svi117747 if (fp->ssthresh < 2 * fp->sfa_pmss) { 2510852Svi117747 fp->ssthresh = 2511852Svi117747 2 * fp->sfa_pmss; 2512852Svi117747 } 2513852Svi117747 fp->cwnd = fp->ssthresh; 2514852Svi117747 fp->pba = 0; 2515852Svi117747 sctp->sctp_recovery_tsn = 2516852Svi117747 sctp->sctp_ltsn - 1; 2517852Svi117747 *fast_recovery = B_TRUE; 2518852Svi117747 } 2519852Svi117747 } 2520852Svi117747 } 2521852Svi117747 mp = mp->b_next; 2522852Svi117747 if (mp == NULL) { 2523852Svi117747 ump = ump->b_next; 2524852Svi117747 /* We can't get to the end of the transmit list here */ 2525852Svi117747 ASSERT(ump != NULL); 2526852Svi117747 mp = ump->b_cont; 2527852Svi117747 } 2528852Svi117747 /* We can't hit an unsent chunk here */ 2529852Svi117747 ASSERT(SCTP_CHUNK_ISSENT(mp)); 2530852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2531852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2532852Svi117747 } 2533852Svi117747 return (acked); 2534852Svi117747 } 2535852Svi117747 25360Sstevel@tonic-gate static int 25370Sstevel@tonic-gate sctp_got_sack(sctp_t *sctp, sctp_chunk_hdr_t *sch) 25380Sstevel@tonic-gate { 25390Sstevel@tonic-gate sctp_sack_chunk_t *sc; 25400Sstevel@tonic-gate sctp_data_hdr_t *sdc; 25410Sstevel@tonic-gate sctp_sack_frag_t *ssf; 25420Sstevel@tonic-gate mblk_t *ump; 25430Sstevel@tonic-gate mblk_t *mp; 2544852Svi117747 mblk_t *mp1; 2545852Svi117747 uint32_t cumtsn; 25460Sstevel@tonic-gate uint32_t xtsn; 2547852Svi117747 uint32_t gapstart = 0; 2548852Svi117747 uint32_t gapend = 0; 25490Sstevel@tonic-gate uint32_t acked = 0; 25500Sstevel@tonic-gate uint16_t chunklen; 25510Sstevel@tonic-gate sctp_faddr_t *fp; 25520Sstevel@tonic-gate int num_gaps; 25530Sstevel@tonic-gate int trysend = 0; 25540Sstevel@tonic-gate int i; 25550Sstevel@tonic-gate boolean_t fast_recovery = B_FALSE; 25560Sstevel@tonic-gate boolean_t cumack_forward = B_FALSE; 25570Sstevel@tonic-gate boolean_t fwd_tsn = B_FALSE; 25583448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 25590Sstevel@tonic-gate 25600Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 256110212SGeorge.Shepherd@Sun.COM BUMP_LOCAL(sctp->sctp_isacks); 25620Sstevel@tonic-gate chunklen = ntohs(sch->sch_len); 25630Sstevel@tonic-gate if (chunklen < (sizeof (*sch) + sizeof (*sc))) 25640Sstevel@tonic-gate return (0); 25650Sstevel@tonic-gate 25660Sstevel@tonic-gate sc = (sctp_sack_chunk_t *)(sch + 1); 2567852Svi117747 cumtsn = ntohl(sc->ssc_cumtsn); 2568852Svi117747 2569852Svi117747 dprint(2, ("got sack cumtsn %x -> %x\n", sctp->sctp_lastack_rxd, 2570852Svi117747 cumtsn)); 25710Sstevel@tonic-gate 25720Sstevel@tonic-gate /* out of order */ 2573852Svi117747 if (SEQ_LT(cumtsn, sctp->sctp_lastack_rxd)) 25740Sstevel@tonic-gate return (0); 25750Sstevel@tonic-gate 2576852Svi117747 if (SEQ_GT(cumtsn, sctp->sctp_ltsn - 1)) { 25773448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInAckUnsent); 2578852Svi117747 /* Send an ABORT */ 2579852Svi117747 return (-1); 25800Sstevel@tonic-gate } 25810Sstevel@tonic-gate 25820Sstevel@tonic-gate /* 25830Sstevel@tonic-gate * Cwnd only done when not in fast recovery mode. 25840Sstevel@tonic-gate */ 25850Sstevel@tonic-gate if (SEQ_LT(sctp->sctp_lastack_rxd, sctp->sctp_recovery_tsn)) 25860Sstevel@tonic-gate fast_recovery = B_TRUE; 25870Sstevel@tonic-gate 25880Sstevel@tonic-gate /* 25890Sstevel@tonic-gate * .. and if the cum TSN is not moving ahead on account Forward TSN 25900Sstevel@tonic-gate */ 25910Sstevel@tonic-gate if (SEQ_LT(sctp->sctp_lastack_rxd, sctp->sctp_adv_pap)) 25920Sstevel@tonic-gate fwd_tsn = B_TRUE; 25930Sstevel@tonic-gate 2594852Svi117747 if (cumtsn == sctp->sctp_lastack_rxd && 25950Sstevel@tonic-gate (sctp->sctp_xmit_unacked == NULL || 25960Sstevel@tonic-gate !SCTP_CHUNK_ABANDONED(sctp->sctp_xmit_unacked))) { 25970Sstevel@tonic-gate if (sctp->sctp_xmit_unacked != NULL) 25980Sstevel@tonic-gate mp = sctp->sctp_xmit_unacked; 25990Sstevel@tonic-gate else if (sctp->sctp_xmit_head != NULL) 26000Sstevel@tonic-gate mp = sctp->sctp_xmit_head->b_cont; 26010Sstevel@tonic-gate else 26020Sstevel@tonic-gate mp = NULL; 26033448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInDupAck); 26041932Svi117747 /* 26051932Svi117747 * If we were doing a zero win probe and the win 26061932Svi117747 * has now opened to at least MSS, re-transmit the 26071932Svi117747 * zero win probe via sctp_rexmit_packet(). 26081932Svi117747 */ 26091932Svi117747 if (mp != NULL && sctp->sctp_zero_win_probe && 26101932Svi117747 ntohl(sc->ssc_a_rwnd) >= sctp->sctp_current->sfa_pmss) { 26111932Svi117747 mblk_t *pkt; 26121932Svi117747 uint_t pkt_len; 26131932Svi117747 mblk_t *mp1 = mp; 26141932Svi117747 mblk_t *meta = sctp->sctp_xmit_head; 26151932Svi117747 26161932Svi117747 /* 26171932Svi117747 * Reset the RTO since we have been backing-off 26181932Svi117747 * to send the ZWP. 26191932Svi117747 */ 26201932Svi117747 fp = sctp->sctp_current; 26211932Svi117747 fp->rto = fp->srtt + 4 * fp->rttvar; 262210212SGeorge.Shepherd@Sun.COM SCTP_MAX_RTO(sctp, fp); 26231932Svi117747 /* Resend the ZWP */ 26241932Svi117747 pkt = sctp_rexmit_packet(sctp, &meta, &mp1, fp, 26251932Svi117747 &pkt_len); 26261932Svi117747 if (pkt == NULL) { 26273448Sdh155122 SCTP_KSTAT(sctps, sctp_ss_rexmit_failed); 26281932Svi117747 return (0); 26291932Svi117747 } 26301932Svi117747 ASSERT(pkt_len <= fp->sfa_pmss); 26311932Svi117747 sctp->sctp_zero_win_probe = B_FALSE; 26321932Svi117747 sctp->sctp_rxt_nxttsn = sctp->sctp_ltsn; 26331932Svi117747 sctp->sctp_rxt_maxtsn = sctp->sctp_ltsn; 263411042SErik.Nordmark@Sun.COM sctp_set_iplen(sctp, pkt, fp->ixa); 263511042SErik.Nordmark@Sun.COM (void) conn_ip_output(pkt, fp->ixa); 263611042SErik.Nordmark@Sun.COM BUMP_LOCAL(sctp->sctp_opkts); 26371932Svi117747 } 26380Sstevel@tonic-gate } else { 26391932Svi117747 if (sctp->sctp_zero_win_probe) { 26401932Svi117747 /* 26411932Svi117747 * Reset the RTO since we have been backing-off 26421932Svi117747 * to send the ZWP. 26431932Svi117747 */ 26441932Svi117747 fp = sctp->sctp_current; 26451932Svi117747 fp->rto = fp->srtt + 4 * fp->rttvar; 264610212SGeorge.Shepherd@Sun.COM SCTP_MAX_RTO(sctp, fp); 26471932Svi117747 sctp->sctp_zero_win_probe = B_FALSE; 26481932Svi117747 /* This is probably not required */ 26491932Svi117747 if (!sctp->sctp_rexmitting) { 26501932Svi117747 sctp->sctp_rxt_nxttsn = sctp->sctp_ltsn; 26511932Svi117747 sctp->sctp_rxt_maxtsn = sctp->sctp_ltsn; 26521932Svi117747 } 26531932Svi117747 } 2654852Svi117747 acked = sctp_cumack(sctp, cumtsn, &mp); 26550Sstevel@tonic-gate sctp->sctp_xmit_unacked = mp; 26560Sstevel@tonic-gate if (acked > 0) { 26570Sstevel@tonic-gate trysend = 1; 26580Sstevel@tonic-gate cumack_forward = B_TRUE; 26590Sstevel@tonic-gate if (fwd_tsn && SEQ_GEQ(sctp->sctp_lastack_rxd, 26600Sstevel@tonic-gate sctp->sctp_adv_pap)) { 26610Sstevel@tonic-gate cumack_forward = B_FALSE; 26620Sstevel@tonic-gate } 26630Sstevel@tonic-gate } 26640Sstevel@tonic-gate } 26650Sstevel@tonic-gate num_gaps = ntohs(sc->ssc_numfrags); 266610212SGeorge.Shepherd@Sun.COM UPDATE_LOCAL(sctp->sctp_gapcnt, num_gaps); 26670Sstevel@tonic-gate if (num_gaps == 0 || mp == NULL || !SCTP_CHUNK_ISSENT(mp) || 26680Sstevel@tonic-gate chunklen < (sizeof (*sch) + sizeof (*sc) + 26690Sstevel@tonic-gate num_gaps * sizeof (*ssf))) { 26700Sstevel@tonic-gate goto ret; 26710Sstevel@tonic-gate } 2672852Svi117747 #ifdef DEBUG 2673852Svi117747 /* 2674852Svi117747 * Since we delete any message that has been acked completely, 2675852Svi117747 * the unacked chunk must belong to sctp_xmit_head (as 2676852Svi117747 * we don't have a back pointer from the mp to the meta data 2677852Svi117747 * we do this). 2678852Svi117747 */ 2679852Svi117747 { 2680852Svi117747 mblk_t *mp2 = sctp->sctp_xmit_head->b_cont; 2681852Svi117747 2682852Svi117747 while (mp2 != NULL) { 2683852Svi117747 if (mp2 == mp) 2684852Svi117747 break; 2685852Svi117747 mp2 = mp2->b_next; 2686852Svi117747 } 2687852Svi117747 ASSERT(mp2 != NULL); 2688852Svi117747 } 2689852Svi117747 #endif 26900Sstevel@tonic-gate ump = sctp->sctp_xmit_head; 26910Sstevel@tonic-gate 26920Sstevel@tonic-gate /* 2693852Svi117747 * Just remember where we started from, in case we need to call 2694852Svi117747 * sctp_process_uo_gaps() if the gap blocks are unordered. 2695852Svi117747 */ 2696852Svi117747 mp1 = mp; 2697852Svi117747 2698852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2699852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2700852Svi117747 ASSERT(xtsn == cumtsn + 1); 2701852Svi117747 2702852Svi117747 /* 27030Sstevel@tonic-gate * Go through SACK gaps. They are ordered based on start TSN. 27040Sstevel@tonic-gate */ 27050Sstevel@tonic-gate ssf = (sctp_sack_frag_t *)(sc + 1); 2706852Svi117747 for (i = 0; i < num_gaps; i++, ssf++) { 2707852Svi117747 if (gapstart != 0) { 2708852Svi117747 /* check for unordered gap */ 2709852Svi117747 if (SEQ_LEQ(cumtsn + ntohs(ssf->ssf_start), gapstart)) { 2710852Svi117747 acked += sctp_process_uo_gaps(sctp, 2711852Svi117747 cumtsn, ssf, num_gaps - i, 2712852Svi117747 sctp->sctp_xmit_head, mp1, 2713852Svi117747 &trysend, &fast_recovery, gapstart); 2714852Svi117747 if (trysend < 0) { 27153448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 27163448Sdh155122 sctpInAckUnsent); 2717852Svi117747 return (-1); 2718852Svi117747 } 2719852Svi117747 break; 2720852Svi117747 } 2721852Svi117747 } 2722852Svi117747 gapstart = cumtsn + ntohs(ssf->ssf_start); 2723852Svi117747 gapend = cumtsn + ntohs(ssf->ssf_end); 2724852Svi117747 272510068SChandrasekar.Marimuthu@Sun.COM /* 272610068SChandrasekar.Marimuthu@Sun.COM * Sanity checks: 272710068SChandrasekar.Marimuthu@Sun.COM * 272810068SChandrasekar.Marimuthu@Sun.COM * 1. SACK for TSN we have not sent - ABORT 272910068SChandrasekar.Marimuthu@Sun.COM * 2. Invalid or spurious gaps, ignore all gaps 273010068SChandrasekar.Marimuthu@Sun.COM */ 2731852Svi117747 if (SEQ_GT(gapstart, sctp->sctp_ltsn - 1) || 2732852Svi117747 SEQ_GT(gapend, sctp->sctp_ltsn - 1)) { 27333448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInAckUnsent); 2734852Svi117747 return (-1); 273510068SChandrasekar.Marimuthu@Sun.COM } else if (SEQ_LT(gapend, gapstart) || 273610068SChandrasekar.Marimuthu@Sun.COM SEQ_LEQ(gapstart, cumtsn)) { 2737852Svi117747 break; 2738852Svi117747 } 2739852Svi117747 /* 2740852Svi117747 * Let's start at the current TSN (for the 1st gap we start 2741852Svi117747 * from the cumulative TSN, for subsequent ones we start from 2742852Svi117747 * where the previous gapend was found - second while loop 2743852Svi117747 * below) and walk the transmit list till we find the TSN 2744852Svi117747 * corresponding to gapstart. All the unacked chunks till we 2745852Svi117747 * get to the chunk with TSN == gapstart will have their 2746852Svi117747 * SACKCNT incremented by 1. Note since the gap blocks are 2747852Svi117747 * ordered, we won't be incrementing the SACKCNT for an 2748852Svi117747 * unacked chunk by more than one while processing the gap 2749852Svi117747 * blocks. If the SACKCNT for any unacked chunk exceeds 2750852Svi117747 * the fast retransmit threshold, we will fast retransmit 2751852Svi117747 * after processing all the gap blocks. 2752852Svi117747 */ 275310068SChandrasekar.Marimuthu@Sun.COM ASSERT(SEQ_LEQ(xtsn, gapstart)); 27540Sstevel@tonic-gate while (xtsn != gapstart) { 27550Sstevel@tonic-gate SCTP_CHUNK_SET_SACKCNT(mp, SCTP_CHUNK_SACKCNT(mp) + 1); 27563448Sdh155122 if (SCTP_CHUNK_SACKCNT(mp) == 27573448Sdh155122 sctps->sctps_fast_rxt_thresh) { 27580Sstevel@tonic-gate SCTP_CHUNK_REXMIT(mp); 27590Sstevel@tonic-gate sctp->sctp_chk_fast_rexmit = B_TRUE; 27600Sstevel@tonic-gate trysend = 1; 27610Sstevel@tonic-gate if (!fast_recovery) { 27620Sstevel@tonic-gate /* 27630Sstevel@tonic-gate * Entering fast recovery. 27640Sstevel@tonic-gate */ 27650Sstevel@tonic-gate fp = SCTP_CHUNK_DEST(mp); 27660Sstevel@tonic-gate fp->ssthresh = fp->cwnd / 2; 27670Sstevel@tonic-gate if (fp->ssthresh < 2 * fp->sfa_pmss) { 27680Sstevel@tonic-gate fp->ssthresh = 27690Sstevel@tonic-gate 2 * fp->sfa_pmss; 27700Sstevel@tonic-gate } 27710Sstevel@tonic-gate fp->cwnd = fp->ssthresh; 27720Sstevel@tonic-gate fp->pba = 0; 27730Sstevel@tonic-gate sctp->sctp_recovery_tsn = 27740Sstevel@tonic-gate sctp->sctp_ltsn - 1; 27750Sstevel@tonic-gate fast_recovery = B_TRUE; 27760Sstevel@tonic-gate } 27770Sstevel@tonic-gate } 27780Sstevel@tonic-gate 27790Sstevel@tonic-gate /* 27800Sstevel@tonic-gate * Peer may have reneged on this chunk, so un-sack 27810Sstevel@tonic-gate * it now. If the peer did renege, we need to 27820Sstevel@tonic-gate * readjust unacked. 27830Sstevel@tonic-gate */ 27840Sstevel@tonic-gate if (SCTP_CHUNK_ISACKED(mp)) { 27850Sstevel@tonic-gate chunklen = ntohs(sdc->sdh_len); 27860Sstevel@tonic-gate fp = SCTP_CHUNK_DEST(mp); 27870Sstevel@tonic-gate fp->suna += chunklen; 27880Sstevel@tonic-gate sctp->sctp_unacked += chunklen - sizeof (*sdc); 27890Sstevel@tonic-gate SCTP_CHUNK_CLEAR_ACKED(mp); 27900Sstevel@tonic-gate if (!fp->timer_running) { 27910Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, 27920Sstevel@tonic-gate fp->rto); 27930Sstevel@tonic-gate } 27940Sstevel@tonic-gate } 27950Sstevel@tonic-gate 27960Sstevel@tonic-gate mp = mp->b_next; 27970Sstevel@tonic-gate if (mp == NULL) { 27980Sstevel@tonic-gate ump = ump->b_next; 2799852Svi117747 /* 2800852Svi117747 * ump can't be NULL given the sanity check 280110068SChandrasekar.Marimuthu@Sun.COM * above. But if it is NULL, it means that 280210068SChandrasekar.Marimuthu@Sun.COM * there is a data corruption. We'd better 280310068SChandrasekar.Marimuthu@Sun.COM * panic. 2804852Svi117747 */ 280510068SChandrasekar.Marimuthu@Sun.COM if (ump == NULL) { 280610068SChandrasekar.Marimuthu@Sun.COM panic("Memory corruption detected: gap " 280710068SChandrasekar.Marimuthu@Sun.COM "start TSN 0x%x missing from the " 280810068SChandrasekar.Marimuthu@Sun.COM "xmit list: %p", gapstart, 280910068SChandrasekar.Marimuthu@Sun.COM (void *)sctp); 281010068SChandrasekar.Marimuthu@Sun.COM } 28110Sstevel@tonic-gate mp = ump->b_cont; 28120Sstevel@tonic-gate } 2813852Svi117747 /* 2814852Svi117747 * mp can't be unsent given the sanity check above. 2815852Svi117747 */ 2816852Svi117747 ASSERT(SCTP_CHUNK_ISSENT(mp)); 28170Sstevel@tonic-gate sdc = (sctp_data_hdr_t *)mp->b_rptr; 28180Sstevel@tonic-gate xtsn = ntohl(sdc->sdh_tsn); 28190Sstevel@tonic-gate } 2820852Svi117747 /* 2821852Svi117747 * Now that we have found the chunk with TSN == 'gapstart', 2822852Svi117747 * let's walk till we hit the chunk with TSN == 'gapend'. 2823852Svi117747 * All intermediate chunks will be marked ACKED, if they 2824852Svi117747 * haven't already been. 2825852Svi117747 */ 28260Sstevel@tonic-gate while (SEQ_LEQ(xtsn, gapend)) { 28270Sstevel@tonic-gate /* 28280Sstevel@tonic-gate * SACKed 28290Sstevel@tonic-gate */ 28300Sstevel@tonic-gate SCTP_CHUNK_SET_SACKCNT(mp, 0); 28310Sstevel@tonic-gate if (!SCTP_CHUNK_ISACKED(mp)) { 28320Sstevel@tonic-gate SCTP_CHUNK_ACKED(mp); 28330Sstevel@tonic-gate 28340Sstevel@tonic-gate fp = SCTP_CHUNK_DEST(mp); 28350Sstevel@tonic-gate chunklen = ntohs(sdc->sdh_len); 28360Sstevel@tonic-gate ASSERT(fp->suna >= chunklen); 28370Sstevel@tonic-gate fp->suna -= chunklen; 28380Sstevel@tonic-gate if (fp->suna == 0) { 28390Sstevel@tonic-gate /* All outstanding data acked. */ 28400Sstevel@tonic-gate fp->pba = 0; 28410Sstevel@tonic-gate SCTP_FADDR_TIMER_STOP(fp); 28420Sstevel@tonic-gate } 28430Sstevel@tonic-gate fp->acked += chunklen; 28440Sstevel@tonic-gate acked += chunklen; 28450Sstevel@tonic-gate sctp->sctp_unacked -= chunklen - sizeof (*sdc); 28460Sstevel@tonic-gate ASSERT(sctp->sctp_unacked >= 0); 28470Sstevel@tonic-gate } 2848852Svi117747 /* Go to the next chunk of the current message */ 28490Sstevel@tonic-gate mp = mp->b_next; 2850852Svi117747 /* 2851852Svi117747 * Move to the next message in the transmit list 2852852Svi117747 * if we are done with all the chunks from the current 2853852Svi117747 * message. Note, it is possible to hit the end of the 2854852Svi117747 * transmit list here, i.e. if we have already completed 285510068SChandrasekar.Marimuthu@Sun.COM * processing the gap block. But the TSN must be equal 285610068SChandrasekar.Marimuthu@Sun.COM * to the gapend because of the above sanity check. 285710068SChandrasekar.Marimuthu@Sun.COM * If it is not equal, it means that some data is 285810068SChandrasekar.Marimuthu@Sun.COM * missing. 2859852Svi117747 * Also, note that we break here, which means we 2860852Svi117747 * continue processing gap blocks, if any. In case of 2861852Svi117747 * ordered gap blocks there can't be any following 2862852Svi117747 * this (if there is it will fail the sanity check 2863852Svi117747 * above). In case of un-ordered gap blocks we will 2864852Svi117747 * switch to sctp_process_uo_gaps(). In either case 2865852Svi117747 * it should be fine to continue with NULL ump/mp, 2866852Svi117747 * but we just reset it to xmit_head. 2867852Svi117747 */ 28680Sstevel@tonic-gate if (mp == NULL) { 28690Sstevel@tonic-gate ump = ump->b_next; 28700Sstevel@tonic-gate if (ump == NULL) { 287110068SChandrasekar.Marimuthu@Sun.COM if (xtsn != gapend) { 287210068SChandrasekar.Marimuthu@Sun.COM panic("Memory corruption " 287310068SChandrasekar.Marimuthu@Sun.COM "detected: gap end TSN " 287410068SChandrasekar.Marimuthu@Sun.COM "0x%x missing from the " 287510068SChandrasekar.Marimuthu@Sun.COM "xmit list: %p", gapend, 287610068SChandrasekar.Marimuthu@Sun.COM (void *)sctp); 287710068SChandrasekar.Marimuthu@Sun.COM } 2878852Svi117747 ump = sctp->sctp_xmit_head; 2879852Svi117747 mp = mp1; 2880852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2881852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2882852Svi117747 break; 28830Sstevel@tonic-gate } 28840Sstevel@tonic-gate mp = ump->b_cont; 28850Sstevel@tonic-gate } 2886852Svi117747 /* 2887852Svi117747 * Likewise, we could hit an unsent chunk once we have 2888852Svi117747 * completed processing the gap block. Again, it is 2889852Svi117747 * fine to continue processing gap blocks with mp 2890852Svi117747 * pointing to the unsent chunk, because if there 2891852Svi117747 * are more ordered gap blocks, they will fail the 2892852Svi117747 * sanity check, and if there are un-ordered gap blocks, 2893852Svi117747 * we will continue processing in sctp_process_uo_gaps() 2894852Svi117747 * We just reset the mp to the one we started with. 2895852Svi117747 */ 28960Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(mp)) { 2897852Svi117747 ASSERT(xtsn == gapend); 2898852Svi117747 ump = sctp->sctp_xmit_head; 2899852Svi117747 mp = mp1; 2900852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2901852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2902852Svi117747 break; 29030Sstevel@tonic-gate } 29040Sstevel@tonic-gate sdc = (sctp_data_hdr_t *)mp->b_rptr; 29050Sstevel@tonic-gate xtsn = ntohl(sdc->sdh_tsn); 29060Sstevel@tonic-gate } 29070Sstevel@tonic-gate } 29080Sstevel@tonic-gate if (sctp->sctp_prsctp_aware) 29090Sstevel@tonic-gate sctp_check_abandoned_data(sctp, sctp->sctp_current); 29100Sstevel@tonic-gate if (sctp->sctp_chk_fast_rexmit) 29110Sstevel@tonic-gate sctp_fast_rexmit(sctp); 29120Sstevel@tonic-gate ret: 29130Sstevel@tonic-gate trysend += sctp_set_frwnd(sctp, ntohl(sc->ssc_a_rwnd)); 29140Sstevel@tonic-gate 29150Sstevel@tonic-gate /* 29160Sstevel@tonic-gate * If receive window is closed while there is unsent data, 29170Sstevel@tonic-gate * set a timer for doing zero window probes. 29180Sstevel@tonic-gate */ 29190Sstevel@tonic-gate if (sctp->sctp_frwnd == 0 && sctp->sctp_unacked == 0 && 29200Sstevel@tonic-gate sctp->sctp_unsent != 0) { 29210Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current, 29220Sstevel@tonic-gate sctp->sctp_current->rto); 29230Sstevel@tonic-gate } 29240Sstevel@tonic-gate 29250Sstevel@tonic-gate /* 29260Sstevel@tonic-gate * Set cwnd for all destinations. 29270Sstevel@tonic-gate * Congestion window gets increased only when cumulative 29280Sstevel@tonic-gate * TSN moves forward, we're not in fast recovery, and 29290Sstevel@tonic-gate * cwnd has been fully utilized (almost fully, need to allow 29300Sstevel@tonic-gate * some leeway due to non-MSS sized messages). 29310Sstevel@tonic-gate */ 29320Sstevel@tonic-gate if (sctp->sctp_current->acked == acked) { 29330Sstevel@tonic-gate /* 29340Sstevel@tonic-gate * Fast-path, only data sent to sctp_current got acked. 29350Sstevel@tonic-gate */ 29360Sstevel@tonic-gate fp = sctp->sctp_current; 29370Sstevel@tonic-gate if (cumack_forward && !fast_recovery && 29380Sstevel@tonic-gate (fp->acked + fp->suna > fp->cwnd - fp->sfa_pmss)) { 29390Sstevel@tonic-gate if (fp->cwnd < fp->ssthresh) { 29400Sstevel@tonic-gate /* 29410Sstevel@tonic-gate * Slow start 29420Sstevel@tonic-gate */ 29430Sstevel@tonic-gate if (fp->acked > fp->sfa_pmss) { 29440Sstevel@tonic-gate fp->cwnd += fp->sfa_pmss; 29450Sstevel@tonic-gate } else { 29460Sstevel@tonic-gate fp->cwnd += fp->acked; 29470Sstevel@tonic-gate } 29480Sstevel@tonic-gate fp->cwnd = MIN(fp->cwnd, sctp->sctp_cwnd_max); 29490Sstevel@tonic-gate } else { 29500Sstevel@tonic-gate /* 29510Sstevel@tonic-gate * Congestion avoidance 29520Sstevel@tonic-gate */ 29530Sstevel@tonic-gate fp->pba += fp->acked; 29540Sstevel@tonic-gate if (fp->pba >= fp->cwnd) { 29550Sstevel@tonic-gate fp->pba -= fp->cwnd; 29560Sstevel@tonic-gate fp->cwnd += fp->sfa_pmss; 29570Sstevel@tonic-gate fp->cwnd = MIN(fp->cwnd, 29580Sstevel@tonic-gate sctp->sctp_cwnd_max); 29590Sstevel@tonic-gate } 29600Sstevel@tonic-gate } 29610Sstevel@tonic-gate } 29620Sstevel@tonic-gate /* 29630Sstevel@tonic-gate * Limit the burst of transmitted data segments. 29640Sstevel@tonic-gate */ 29653448Sdh155122 if (fp->suna + sctps->sctps_maxburst * fp->sfa_pmss < 29663448Sdh155122 fp->cwnd) { 29673448Sdh155122 fp->cwnd = fp->suna + sctps->sctps_maxburst * 29683448Sdh155122 fp->sfa_pmss; 29690Sstevel@tonic-gate } 29700Sstevel@tonic-gate fp->acked = 0; 29711735Skcpoon goto check_ss_rxmit; 29720Sstevel@tonic-gate } 29731932Svi117747 for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 29740Sstevel@tonic-gate if (cumack_forward && fp->acked && !fast_recovery && 29750Sstevel@tonic-gate (fp->acked + fp->suna > fp->cwnd - fp->sfa_pmss)) { 29760Sstevel@tonic-gate if (fp->cwnd < fp->ssthresh) { 29770Sstevel@tonic-gate if (fp->acked > fp->sfa_pmss) { 29780Sstevel@tonic-gate fp->cwnd += fp->sfa_pmss; 29790Sstevel@tonic-gate } else { 29800Sstevel@tonic-gate fp->cwnd += fp->acked; 29810Sstevel@tonic-gate } 29820Sstevel@tonic-gate fp->cwnd = MIN(fp->cwnd, sctp->sctp_cwnd_max); 29830Sstevel@tonic-gate } else { 29840Sstevel@tonic-gate fp->pba += fp->acked; 29850Sstevel@tonic-gate if (fp->pba >= fp->cwnd) { 29860Sstevel@tonic-gate fp->pba -= fp->cwnd; 29870Sstevel@tonic-gate fp->cwnd += fp->sfa_pmss; 29880Sstevel@tonic-gate fp->cwnd = MIN(fp->cwnd, 29890Sstevel@tonic-gate sctp->sctp_cwnd_max); 29900Sstevel@tonic-gate } 29910Sstevel@tonic-gate } 29920Sstevel@tonic-gate } 29933448Sdh155122 if (fp->suna + sctps->sctps_maxburst * fp->sfa_pmss < 29943448Sdh155122 fp->cwnd) { 29953448Sdh155122 fp->cwnd = fp->suna + sctps->sctps_maxburst * 29963448Sdh155122 fp->sfa_pmss; 29970Sstevel@tonic-gate } 29980Sstevel@tonic-gate fp->acked = 0; 29990Sstevel@tonic-gate } 30004311Svi117747 fp = sctp->sctp_current; 30011735Skcpoon check_ss_rxmit: 30021735Skcpoon /* 30031735Skcpoon * If this is a SACK following a timeout, check if there are 30041735Skcpoon * still unacked chunks (sent before the timeout) that we can 30051735Skcpoon * send. 30061735Skcpoon */ 30071735Skcpoon if (sctp->sctp_rexmitting) { 30081735Skcpoon if (SEQ_LT(sctp->sctp_lastack_rxd, sctp->sctp_rxt_maxtsn)) { 30091735Skcpoon /* 30101735Skcpoon * As we are in retransmission phase, we may get a 30111735Skcpoon * SACK which indicates some new chunks are received 30121735Skcpoon * but cum_tsn does not advance. During this 30131735Skcpoon * phase, the other side advances cum_tsn only because 30141735Skcpoon * it receives our retransmitted chunks. Only 30151735Skcpoon * this signals that some chunks are still 30161735Skcpoon * missing. 30171735Skcpoon */ 30183795Skcpoon if (cumack_forward) { 30193795Skcpoon fp->rxt_unacked -= acked; 30201735Skcpoon sctp_ss_rexmit(sctp); 30213795Skcpoon } 30221735Skcpoon } else { 30231735Skcpoon sctp->sctp_rexmitting = B_FALSE; 30241735Skcpoon sctp->sctp_rxt_nxttsn = sctp->sctp_ltsn; 30251735Skcpoon sctp->sctp_rxt_maxtsn = sctp->sctp_ltsn; 30263795Skcpoon fp->rxt_unacked = 0; 30271735Skcpoon } 30281735Skcpoon } 30290Sstevel@tonic-gate return (trysend); 30300Sstevel@tonic-gate } 30310Sstevel@tonic-gate 30320Sstevel@tonic-gate /* 30330Sstevel@tonic-gate * Returns 0 if the caller should stop processing any more chunks, 30340Sstevel@tonic-gate * 1 if the caller should skip this chunk and continue processing. 30350Sstevel@tonic-gate */ 30360Sstevel@tonic-gate static int 30370Sstevel@tonic-gate sctp_strange_chunk(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp) 30380Sstevel@tonic-gate { 30390Sstevel@tonic-gate size_t len; 30400Sstevel@tonic-gate 30410Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 30420Sstevel@tonic-gate /* check top two bits for action required */ 30430Sstevel@tonic-gate if (ch->sch_id & 0x40) { /* also matches 0xc0 */ 30440Sstevel@tonic-gate len = ntohs(ch->sch_len); 30454964Skcpoon sctp_add_err(sctp, SCTP_ERR_UNREC_CHUNK, ch, len, fp); 30464964Skcpoon 30470Sstevel@tonic-gate if ((ch->sch_id & 0xc0) == 0xc0) { 30480Sstevel@tonic-gate /* skip and continue */ 30490Sstevel@tonic-gate return (1); 30500Sstevel@tonic-gate } else { 30510Sstevel@tonic-gate /* stop processing */ 30520Sstevel@tonic-gate return (0); 30530Sstevel@tonic-gate } 30540Sstevel@tonic-gate } 30550Sstevel@tonic-gate if (ch->sch_id & 0x80) { 30560Sstevel@tonic-gate /* skip and continue, no error */ 30570Sstevel@tonic-gate return (1); 30580Sstevel@tonic-gate } 30590Sstevel@tonic-gate /* top two bits are clear; stop processing and no error */ 30600Sstevel@tonic-gate return (0); 30610Sstevel@tonic-gate } 30620Sstevel@tonic-gate 30630Sstevel@tonic-gate /* 30640Sstevel@tonic-gate * Basic sanity checks on all input chunks and parameters: they must 30650Sstevel@tonic-gate * be of legitimate size for their purported type, and must follow 30660Sstevel@tonic-gate * ordering conventions as defined in rfc2960. 30670Sstevel@tonic-gate * 30680Sstevel@tonic-gate * Returns 1 if the chunk and all encloded params are legitimate, 30690Sstevel@tonic-gate * 0 otherwise. 30700Sstevel@tonic-gate */ 30710Sstevel@tonic-gate /*ARGSUSED*/ 30720Sstevel@tonic-gate static int 30730Sstevel@tonic-gate sctp_check_input(sctp_t *sctp, sctp_chunk_hdr_t *ch, ssize_t len, int first) 30740Sstevel@tonic-gate { 30750Sstevel@tonic-gate sctp_parm_hdr_t *ph; 30760Sstevel@tonic-gate void *p = NULL; 30770Sstevel@tonic-gate ssize_t clen; 30780Sstevel@tonic-gate uint16_t ch_len; 30790Sstevel@tonic-gate 30800Sstevel@tonic-gate ch_len = ntohs(ch->sch_len); 30810Sstevel@tonic-gate if (ch_len > len) { 30820Sstevel@tonic-gate return (0); 30830Sstevel@tonic-gate } 30840Sstevel@tonic-gate 30850Sstevel@tonic-gate switch (ch->sch_id) { 30860Sstevel@tonic-gate case CHUNK_DATA: 30870Sstevel@tonic-gate if (ch_len < sizeof (sctp_data_hdr_t)) { 30880Sstevel@tonic-gate return (0); 30890Sstevel@tonic-gate } 30900Sstevel@tonic-gate return (1); 30910Sstevel@tonic-gate case CHUNK_INIT: 30920Sstevel@tonic-gate case CHUNK_INIT_ACK: 30930Sstevel@tonic-gate { 30940Sstevel@tonic-gate ssize_t remlen = len; 30950Sstevel@tonic-gate 30960Sstevel@tonic-gate /* 30970Sstevel@tonic-gate * INIT and INIT-ACK chunks must not be bundled with 30980Sstevel@tonic-gate * any other. 30990Sstevel@tonic-gate */ 31000Sstevel@tonic-gate if (!first || sctp_next_chunk(ch, &remlen) != NULL || 31010Sstevel@tonic-gate (ch_len < (sizeof (*ch) + 31020Sstevel@tonic-gate sizeof (sctp_init_chunk_t)))) { 31030Sstevel@tonic-gate return (0); 31040Sstevel@tonic-gate } 31050Sstevel@tonic-gate /* may have params that need checking */ 31060Sstevel@tonic-gate p = (char *)(ch + 1) + sizeof (sctp_init_chunk_t); 31070Sstevel@tonic-gate clen = ch_len - (sizeof (*ch) + 31080Sstevel@tonic-gate sizeof (sctp_init_chunk_t)); 31090Sstevel@tonic-gate } 31100Sstevel@tonic-gate break; 31110Sstevel@tonic-gate case CHUNK_SACK: 31120Sstevel@tonic-gate if (ch_len < (sizeof (*ch) + sizeof (sctp_sack_chunk_t))) { 31130Sstevel@tonic-gate return (0); 31140Sstevel@tonic-gate } 31150Sstevel@tonic-gate /* dup and gap reports checked by got_sack() */ 31160Sstevel@tonic-gate return (1); 31170Sstevel@tonic-gate case CHUNK_SHUTDOWN: 31180Sstevel@tonic-gate if (ch_len < (sizeof (*ch) + sizeof (uint32_t))) { 31190Sstevel@tonic-gate return (0); 31200Sstevel@tonic-gate } 31210Sstevel@tonic-gate return (1); 31220Sstevel@tonic-gate case CHUNK_ABORT: 31230Sstevel@tonic-gate case CHUNK_ERROR: 31240Sstevel@tonic-gate if (ch_len < sizeof (*ch)) { 31250Sstevel@tonic-gate return (0); 31260Sstevel@tonic-gate } 31270Sstevel@tonic-gate /* may have params that need checking */ 31280Sstevel@tonic-gate p = ch + 1; 31290Sstevel@tonic-gate clen = ch_len - sizeof (*ch); 31300Sstevel@tonic-gate break; 31310Sstevel@tonic-gate case CHUNK_ECNE: 31320Sstevel@tonic-gate case CHUNK_CWR: 31330Sstevel@tonic-gate case CHUNK_HEARTBEAT: 31340Sstevel@tonic-gate case CHUNK_HEARTBEAT_ACK: 31350Sstevel@tonic-gate /* Full ASCONF chunk and parameter checks are in asconf.c */ 31360Sstevel@tonic-gate case CHUNK_ASCONF: 31370Sstevel@tonic-gate case CHUNK_ASCONF_ACK: 31380Sstevel@tonic-gate if (ch_len < sizeof (*ch)) { 31390Sstevel@tonic-gate return (0); 31400Sstevel@tonic-gate } 31410Sstevel@tonic-gate /* heartbeat data checked by process_heartbeat() */ 31420Sstevel@tonic-gate return (1); 31430Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 31440Sstevel@tonic-gate { 31450Sstevel@tonic-gate ssize_t remlen = len; 31460Sstevel@tonic-gate 31470Sstevel@tonic-gate /* 31480Sstevel@tonic-gate * SHUTDOWN-COMPLETE chunk must not be bundled with any 31490Sstevel@tonic-gate * other 31500Sstevel@tonic-gate */ 31510Sstevel@tonic-gate if (!first || sctp_next_chunk(ch, &remlen) != NULL || 31520Sstevel@tonic-gate ch_len < sizeof (*ch)) { 31530Sstevel@tonic-gate return (0); 31540Sstevel@tonic-gate } 31550Sstevel@tonic-gate } 31560Sstevel@tonic-gate return (1); 31570Sstevel@tonic-gate case CHUNK_COOKIE: 31580Sstevel@tonic-gate case CHUNK_COOKIE_ACK: 31590Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 31600Sstevel@tonic-gate if (ch_len < sizeof (*ch) || !first) { 31610Sstevel@tonic-gate return (0); 31620Sstevel@tonic-gate } 31630Sstevel@tonic-gate return (1); 31640Sstevel@tonic-gate case CHUNK_FORWARD_TSN: 31650Sstevel@tonic-gate if (ch_len < (sizeof (*ch) + sizeof (uint32_t))) 31660Sstevel@tonic-gate return (0); 31670Sstevel@tonic-gate return (1); 31680Sstevel@tonic-gate default: 31690Sstevel@tonic-gate return (1); /* handled by strange_chunk() */ 31700Sstevel@tonic-gate } 31710Sstevel@tonic-gate 31720Sstevel@tonic-gate /* check and byteorder parameters */ 31730Sstevel@tonic-gate if (clen <= 0) { 31740Sstevel@tonic-gate return (1); 31750Sstevel@tonic-gate } 31760Sstevel@tonic-gate ASSERT(p != NULL); 31770Sstevel@tonic-gate 31780Sstevel@tonic-gate ph = p; 31790Sstevel@tonic-gate while (ph != NULL && clen > 0) { 31800Sstevel@tonic-gate ch_len = ntohs(ph->sph_len); 31810Sstevel@tonic-gate if (ch_len > len || ch_len < sizeof (*ph)) { 31820Sstevel@tonic-gate return (0); 31830Sstevel@tonic-gate } 31840Sstevel@tonic-gate ph = sctp_next_parm(ph, &clen); 31850Sstevel@tonic-gate } 31860Sstevel@tonic-gate 31870Sstevel@tonic-gate /* All OK */ 31880Sstevel@tonic-gate return (1); 31890Sstevel@tonic-gate } 31900Sstevel@tonic-gate 319111042SErik.Nordmark@Sun.COM static mblk_t * 319211042SErik.Nordmark@Sun.COM sctp_check_in_policy(mblk_t *mp, ip_recv_attr_t *ira, ip_stack_t *ipst) 31930Sstevel@tonic-gate { 31940Sstevel@tonic-gate boolean_t policy_present; 31950Sstevel@tonic-gate ipha_t *ipha; 31960Sstevel@tonic-gate ip6_t *ip6h; 319711042SErik.Nordmark@Sun.COM netstack_t *ns = ipst->ips_netstack; 319811042SErik.Nordmark@Sun.COM ipsec_stack_t *ipss = ns->netstack_ipsec; 319911042SErik.Nordmark@Sun.COM 32000Sstevel@tonic-gate if (IPH_HDR_VERSION(mp->b_rptr) == IPV4_VERSION) { 32013448Sdh155122 policy_present = ipss->ipsec_inbound_v4_policy_present; 32020Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 32030Sstevel@tonic-gate ip6h = NULL; 32040Sstevel@tonic-gate } else { 32053448Sdh155122 policy_present = ipss->ipsec_inbound_v6_policy_present; 32060Sstevel@tonic-gate ipha = NULL; 32070Sstevel@tonic-gate ip6h = (ip6_t *)mp->b_rptr; 32080Sstevel@tonic-gate } 32090Sstevel@tonic-gate 321011042SErik.Nordmark@Sun.COM if (policy_present) { 32110Sstevel@tonic-gate /* 32120Sstevel@tonic-gate * The conn_t parameter is NULL because we already know 32130Sstevel@tonic-gate * nobody's home. 32140Sstevel@tonic-gate */ 321511042SErik.Nordmark@Sun.COM mp = ipsec_check_global_policy(mp, (conn_t *)NULL, 321611042SErik.Nordmark@Sun.COM ipha, ip6h, ira, ns); 321711042SErik.Nordmark@Sun.COM if (mp == NULL) 32180Sstevel@tonic-gate return (NULL); 32190Sstevel@tonic-gate } 32200Sstevel@tonic-gate return (mp); 32210Sstevel@tonic-gate } 32220Sstevel@tonic-gate 32230Sstevel@tonic-gate /* Handle out-of-the-blue packets */ 32240Sstevel@tonic-gate void 322511042SErik.Nordmark@Sun.COM sctp_ootb_input(mblk_t *mp, ip_recv_attr_t *ira, ip_stack_t *ipst) 32260Sstevel@tonic-gate { 32270Sstevel@tonic-gate sctp_t *sctp; 32280Sstevel@tonic-gate sctp_chunk_hdr_t *ch; 32290Sstevel@tonic-gate sctp_hdr_t *sctph; 32300Sstevel@tonic-gate in6_addr_t src, dst; 323111042SErik.Nordmark@Sun.COM uint_t ip_hdr_len = ira->ira_ip_hdr_length; 32320Sstevel@tonic-gate ssize_t mlen; 32333448Sdh155122 sctp_stack_t *sctps; 323411042SErik.Nordmark@Sun.COM boolean_t secure; 323511042SErik.Nordmark@Sun.COM zoneid_t zoneid = ira->ira_zoneid; 323611042SErik.Nordmark@Sun.COM uchar_t *rptr; 323711042SErik.Nordmark@Sun.COM 323811042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ill == NULL); 323911042SErik.Nordmark@Sun.COM 324011042SErik.Nordmark@Sun.COM secure = ira->ira_flags & IRAF_IPSEC_SECURE; 324111042SErik.Nordmark@Sun.COM 32423448Sdh155122 sctps = ipst->ips_netstack->netstack_sctp; 32433448Sdh155122 32443448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpOutOfBlue); 32453448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInSCTPPkts); 32463448Sdh155122 32470Sstevel@tonic-gate if (mp->b_cont != NULL) { 32480Sstevel@tonic-gate /* 32490Sstevel@tonic-gate * All subsequent code is vastly simplified if it can 32500Sstevel@tonic-gate * assume a single contiguous chunk of data. 32510Sstevel@tonic-gate */ 32520Sstevel@tonic-gate if (pullupmsg(mp, -1) == 0) { 325311042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 325411042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, NULL); 325511042SErik.Nordmark@Sun.COM freemsg(mp); 32560Sstevel@tonic-gate return; 32570Sstevel@tonic-gate } 32580Sstevel@tonic-gate } 32590Sstevel@tonic-gate 326011042SErik.Nordmark@Sun.COM rptr = mp->b_rptr; 326111042SErik.Nordmark@Sun.COM sctph = ((sctp_hdr_t *)&rptr[ip_hdr_len]); 326211042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_IS_IPV4) { 326311042SErik.Nordmark@Sun.COM ipha_t *ipha; 326411042SErik.Nordmark@Sun.COM 326511042SErik.Nordmark@Sun.COM ipha = (ipha_t *)rptr; 326611042SErik.Nordmark@Sun.COM IN6_IPADDR_TO_V4MAPPED(ipha->ipha_src, &src); 326711042SErik.Nordmark@Sun.COM IN6_IPADDR_TO_V4MAPPED(ipha->ipha_dst, &dst); 326811042SErik.Nordmark@Sun.COM } else { 326911042SErik.Nordmark@Sun.COM ip6_t *ip6h; 327011042SErik.Nordmark@Sun.COM 327111042SErik.Nordmark@Sun.COM ip6h = (ip6_t *)rptr; 327211042SErik.Nordmark@Sun.COM src = ip6h->ip6_src; 327311042SErik.Nordmark@Sun.COM dst = ip6h->ip6_dst; 327411042SErik.Nordmark@Sun.COM } 327511042SErik.Nordmark@Sun.COM 32760Sstevel@tonic-gate mlen = mp->b_wptr - (uchar_t *)(sctph + 1); 32770Sstevel@tonic-gate if ((ch = sctp_first_chunk((uchar_t *)(sctph + 1), mlen)) == NULL) { 32780Sstevel@tonic-gate dprint(3, ("sctp_ootb_input: invalid packet\n")); 327911042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 328011042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, NULL); 328111042SErik.Nordmark@Sun.COM freemsg(mp); 32820Sstevel@tonic-gate return; 32830Sstevel@tonic-gate } 32840Sstevel@tonic-gate 32850Sstevel@tonic-gate switch (ch->sch_id) { 32860Sstevel@tonic-gate case CHUNK_INIT: 32870Sstevel@tonic-gate /* no listener; send abort */ 328811042SErik.Nordmark@Sun.COM if (secure && sctp_check_in_policy(mp, ira, ipst) == NULL) 32890Sstevel@tonic-gate return; 329011042SErik.Nordmark@Sun.COM sctp_ootb_send_abort(sctp_init2vtag(ch), 0, 329111042SErik.Nordmark@Sun.COM NULL, 0, mp, 0, B_TRUE, ira, ipst); 32920Sstevel@tonic-gate break; 32930Sstevel@tonic-gate case CHUNK_INIT_ACK: 32940Sstevel@tonic-gate /* check for changed src addr */ 32953510Svi117747 sctp = sctp_addrlist2sctp(mp, sctph, ch, zoneid, sctps); 32960Sstevel@tonic-gate if (sctp != NULL) { 32970Sstevel@tonic-gate /* success; proceed to normal path */ 32980Sstevel@tonic-gate mutex_enter(&sctp->sctp_lock); 32990Sstevel@tonic-gate if (sctp->sctp_running) { 330011042SErik.Nordmark@Sun.COM sctp_add_recvq(sctp, mp, B_FALSE, ira); 33010Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 33020Sstevel@tonic-gate } else { 33030Sstevel@tonic-gate /* 33040Sstevel@tonic-gate * If the source address is changed, we 33050Sstevel@tonic-gate * don't need to worry too much about 33060Sstevel@tonic-gate * out of order processing. So we don't 33070Sstevel@tonic-gate * check if the recvq is empty or not here. 33080Sstevel@tonic-gate */ 33090Sstevel@tonic-gate sctp->sctp_running = B_TRUE; 33100Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 331111042SErik.Nordmark@Sun.COM sctp_input_data(sctp, mp, ira); 33120Sstevel@tonic-gate WAKE_SCTP(sctp); 33130Sstevel@tonic-gate } 33140Sstevel@tonic-gate SCTP_REFRELE(sctp); 33150Sstevel@tonic-gate return; 33160Sstevel@tonic-gate } 33170Sstevel@tonic-gate /* else bogus init ack; drop it */ 33180Sstevel@tonic-gate break; 33190Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 332011042SErik.Nordmark@Sun.COM if (secure && sctp_check_in_policy(mp, ira, ipst) == NULL) 33210Sstevel@tonic-gate return; 332211042SErik.Nordmark@Sun.COM sctp_ootb_shutdown_ack(mp, ip_hdr_len, ira, ipst); 33230Sstevel@tonic-gate return; 33240Sstevel@tonic-gate case CHUNK_ERROR: 33250Sstevel@tonic-gate case CHUNK_ABORT: 33260Sstevel@tonic-gate case CHUNK_COOKIE_ACK: 33270Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 33280Sstevel@tonic-gate break; 33290Sstevel@tonic-gate default: 333011042SErik.Nordmark@Sun.COM if (secure && sctp_check_in_policy(mp, ira, ipst) == NULL) 33310Sstevel@tonic-gate return; 333211042SErik.Nordmark@Sun.COM sctp_ootb_send_abort(sctph->sh_verf, 0, 333311042SErik.Nordmark@Sun.COM NULL, 0, mp, 0, B_TRUE, ira, ipst); 33340Sstevel@tonic-gate break; 33350Sstevel@tonic-gate } 33360Sstevel@tonic-gate freemsg(mp); 33370Sstevel@tonic-gate } 33380Sstevel@tonic-gate 333911042SErik.Nordmark@Sun.COM /* 334011042SErik.Nordmark@Sun.COM * Handle sctp packets. 334111042SErik.Nordmark@Sun.COM * Note that we rele the sctp_t (the caller got a reference on it). 334211042SErik.Nordmark@Sun.COM */ 33430Sstevel@tonic-gate void 334411042SErik.Nordmark@Sun.COM sctp_input(conn_t *connp, ipha_t *ipha, ip6_t *ip6h, mblk_t *mp, 334511042SErik.Nordmark@Sun.COM ip_recv_attr_t *ira) 33460Sstevel@tonic-gate { 334711042SErik.Nordmark@Sun.COM sctp_t *sctp = CONN2SCTP(connp); 334811042SErik.Nordmark@Sun.COM boolean_t secure; 334911042SErik.Nordmark@Sun.COM ill_t *ill = ira->ira_ill; 335011042SErik.Nordmark@Sun.COM ip_stack_t *ipst = ill->ill_ipst; 33513448Sdh155122 ipsec_stack_t *ipss = ipst->ips_netstack->netstack_ipsec; 335211042SErik.Nordmark@Sun.COM iaflags_t iraflags = ira->ira_flags; 335311042SErik.Nordmark@Sun.COM ill_t *rill = ira->ira_rill; 335411042SErik.Nordmark@Sun.COM 335511042SErik.Nordmark@Sun.COM secure = iraflags & IRAF_IPSEC_SECURE; 33560Sstevel@tonic-gate 33570Sstevel@tonic-gate /* 33580Sstevel@tonic-gate * We check some fields in conn_t without holding a lock. 33590Sstevel@tonic-gate * This should be fine. 33600Sstevel@tonic-gate */ 336111042SErik.Nordmark@Sun.COM if (((iraflags & IRAF_IS_IPV4) ? 336211042SErik.Nordmark@Sun.COM CONN_INBOUND_POLICY_PRESENT(connp, ipss) : 336311042SErik.Nordmark@Sun.COM CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss)) || 336411042SErik.Nordmark@Sun.COM secure) { 336511042SErik.Nordmark@Sun.COM mp = ipsec_check_inbound_policy(mp, connp, ipha, 336611042SErik.Nordmark@Sun.COM ip6h, ira); 336711042SErik.Nordmark@Sun.COM if (mp == NULL) { 336811042SErik.Nordmark@Sun.COM BUMP_MIB(ill->ill_ip_mib, ipIfStatsInDiscards); 336911042SErik.Nordmark@Sun.COM /* Note that mp is NULL */ 337011042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, ill); 33710Sstevel@tonic-gate SCTP_REFRELE(sctp); 33720Sstevel@tonic-gate return; 33730Sstevel@tonic-gate } 33740Sstevel@tonic-gate } 33750Sstevel@tonic-gate 337611042SErik.Nordmark@Sun.COM ira->ira_ill = ira->ira_rill = NULL; 33770Sstevel@tonic-gate 33780Sstevel@tonic-gate mutex_enter(&sctp->sctp_lock); 33790Sstevel@tonic-gate if (sctp->sctp_running) { 338011042SErik.Nordmark@Sun.COM sctp_add_recvq(sctp, mp, B_FALSE, ira); 33810Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 338211042SErik.Nordmark@Sun.COM goto done; 33830Sstevel@tonic-gate } else { 33840Sstevel@tonic-gate sctp->sctp_running = B_TRUE; 33850Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 33860Sstevel@tonic-gate 33870Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 33880Sstevel@tonic-gate if (sctp->sctp_recvq != NULL) { 338911042SErik.Nordmark@Sun.COM sctp_add_recvq(sctp, mp, B_TRUE, ira); 33900Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 33910Sstevel@tonic-gate WAKE_SCTP(sctp); 339211042SErik.Nordmark@Sun.COM goto done; 33930Sstevel@tonic-gate } 33940Sstevel@tonic-gate } 33950Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 339611042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_ICMP_ERROR) 339711042SErik.Nordmark@Sun.COM sctp_icmp_error(sctp, mp); 339811042SErik.Nordmark@Sun.COM else 339911042SErik.Nordmark@Sun.COM sctp_input_data(sctp, mp, ira); 34000Sstevel@tonic-gate WAKE_SCTP(sctp); 340111042SErik.Nordmark@Sun.COM 340211042SErik.Nordmark@Sun.COM done: 34030Sstevel@tonic-gate SCTP_REFRELE(sctp); 340411042SErik.Nordmark@Sun.COM ira->ira_ill = ill; 340511042SErik.Nordmark@Sun.COM ira->ira_rill = rill; 34060Sstevel@tonic-gate } 34070Sstevel@tonic-gate 34080Sstevel@tonic-gate static void 34090Sstevel@tonic-gate sctp_process_abort(sctp_t *sctp, sctp_chunk_hdr_t *ch, int err) 34100Sstevel@tonic-gate { 34113448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 34123448Sdh155122 34133448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpAborted); 34140Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 34150Sstevel@tonic-gate 34160Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_LOST, 34170Sstevel@tonic-gate ntohs(((sctp_parm_hdr_t *)(ch + 1))->sph_type), ch); 34180Sstevel@tonic-gate sctp_clean_death(sctp, err); 34190Sstevel@tonic-gate } 34200Sstevel@tonic-gate 34210Sstevel@tonic-gate void 342211042SErik.Nordmark@Sun.COM sctp_input_data(sctp_t *sctp, mblk_t *mp, ip_recv_attr_t *ira) 34230Sstevel@tonic-gate { 34240Sstevel@tonic-gate sctp_chunk_hdr_t *ch; 34250Sstevel@tonic-gate ssize_t mlen; 34260Sstevel@tonic-gate int gotdata; 34270Sstevel@tonic-gate int trysend; 34280Sstevel@tonic-gate sctp_faddr_t *fp; 34290Sstevel@tonic-gate sctp_init_chunk_t *iack; 34300Sstevel@tonic-gate uint32_t tsn; 34310Sstevel@tonic-gate sctp_data_hdr_t *sdc; 343211042SErik.Nordmark@Sun.COM ip_pkt_t ipp; 34330Sstevel@tonic-gate in6_addr_t src; 34340Sstevel@tonic-gate in6_addr_t dst; 34350Sstevel@tonic-gate uint_t ifindex; 34360Sstevel@tonic-gate sctp_hdr_t *sctph; 343711042SErik.Nordmark@Sun.COM uint_t ip_hdr_len = ira->ira_ip_hdr_length; 34380Sstevel@tonic-gate mblk_t *dups = NULL; 34395586Skcpoon int recv_adaptation; 34400Sstevel@tonic-gate boolean_t wake_eager = B_FALSE; 34410Sstevel@tonic-gate in6_addr_t peer_src; 34420Sstevel@tonic-gate int64_t now; 34433448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 34443448Sdh155122 ip_stack_t *ipst = sctps->sctps_netstack->netstack_ip; 34454964Skcpoon boolean_t hb_already = B_FALSE; 34468778SErik.Nordmark@Sun.COM cred_t *cr; 34478778SErik.Nordmark@Sun.COM pid_t cpid; 344811042SErik.Nordmark@Sun.COM uchar_t *rptr; 344911042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 345011042SErik.Nordmark@Sun.COM 34510Sstevel@tonic-gate ASSERT(DB_TYPE(mp) == M_DATA); 345211042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ill == NULL); 34530Sstevel@tonic-gate 34540Sstevel@tonic-gate if (mp->b_cont != NULL) { 34550Sstevel@tonic-gate /* 34560Sstevel@tonic-gate * All subsequent code is vastly simplified if it can 34570Sstevel@tonic-gate * assume a single contiguous chunk of data. 34580Sstevel@tonic-gate */ 34590Sstevel@tonic-gate if (pullupmsg(mp, -1) == 0) { 34603448Sdh155122 BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 346111042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, NULL); 34620Sstevel@tonic-gate freemsg(mp); 34630Sstevel@tonic-gate return; 34640Sstevel@tonic-gate } 34650Sstevel@tonic-gate } 34660Sstevel@tonic-gate 34670Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ipkts); 346811042SErik.Nordmark@Sun.COM ifindex = ira->ira_ruifindex; 346911042SErik.Nordmark@Sun.COM 347011042SErik.Nordmark@Sun.COM rptr = mp->b_rptr; 347111042SErik.Nordmark@Sun.COM 347211042SErik.Nordmark@Sun.COM ipp.ipp_fields = 0; 347311042SErik.Nordmark@Sun.COM if (connp->conn_recv_ancillary.crb_all != 0) { 347411042SErik.Nordmark@Sun.COM /* 347511042SErik.Nordmark@Sun.COM * Record packet information in the ip_pkt_t 347611042SErik.Nordmark@Sun.COM */ 347711042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_IS_IPV4) { 347811042SErik.Nordmark@Sun.COM (void) ip_find_hdr_v4((ipha_t *)rptr, &ipp, 347911042SErik.Nordmark@Sun.COM B_FALSE); 348011042SErik.Nordmark@Sun.COM } else { 348111042SErik.Nordmark@Sun.COM uint8_t nexthdrp; 348211042SErik.Nordmark@Sun.COM 348311042SErik.Nordmark@Sun.COM /* 348411042SErik.Nordmark@Sun.COM * IPv6 packets can only be received by applications 348511042SErik.Nordmark@Sun.COM * that are prepared to receive IPv6 addresses. 348611042SErik.Nordmark@Sun.COM * The IP fanout must ensure this. 348711042SErik.Nordmark@Sun.COM */ 348811042SErik.Nordmark@Sun.COM ASSERT(connp->conn_family == AF_INET6); 348911042SErik.Nordmark@Sun.COM 349011042SErik.Nordmark@Sun.COM (void) ip_find_hdr_v6(mp, (ip6_t *)rptr, B_TRUE, &ipp, 349111042SErik.Nordmark@Sun.COM &nexthdrp); 349211042SErik.Nordmark@Sun.COM ASSERT(nexthdrp == IPPROTO_SCTP); 349311042SErik.Nordmark@Sun.COM 349411042SErik.Nordmark@Sun.COM /* Could have caused a pullup? */ 349511042SErik.Nordmark@Sun.COM rptr = mp->b_rptr; 349611042SErik.Nordmark@Sun.COM } 349711042SErik.Nordmark@Sun.COM } 349811042SErik.Nordmark@Sun.COM 349911042SErik.Nordmark@Sun.COM sctph = ((sctp_hdr_t *)&rptr[ip_hdr_len]); 350011042SErik.Nordmark@Sun.COM 350111042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_IS_IPV4) { 350211042SErik.Nordmark@Sun.COM ipha_t *ipha; 350311042SErik.Nordmark@Sun.COM 350411042SErik.Nordmark@Sun.COM ipha = (ipha_t *)rptr; 350511042SErik.Nordmark@Sun.COM IN6_IPADDR_TO_V4MAPPED(ipha->ipha_src, &src); 350611042SErik.Nordmark@Sun.COM IN6_IPADDR_TO_V4MAPPED(ipha->ipha_dst, &dst); 350711042SErik.Nordmark@Sun.COM } else { 350811042SErik.Nordmark@Sun.COM ip6_t *ip6h; 350911042SErik.Nordmark@Sun.COM 351011042SErik.Nordmark@Sun.COM ip6h = (ip6_t *)rptr; 351111042SErik.Nordmark@Sun.COM src = ip6h->ip6_src; 351211042SErik.Nordmark@Sun.COM dst = ip6h->ip6_dst; 351311042SErik.Nordmark@Sun.COM } 351411042SErik.Nordmark@Sun.COM 35150Sstevel@tonic-gate mlen = mp->b_wptr - (uchar_t *)(sctph + 1); 35160Sstevel@tonic-gate ch = sctp_first_chunk((uchar_t *)(sctph + 1), mlen); 35170Sstevel@tonic-gate if (ch == NULL) { 35183448Sdh155122 BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 351911042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, NULL); 35200Sstevel@tonic-gate freemsg(mp); 35210Sstevel@tonic-gate return; 35220Sstevel@tonic-gate } 35230Sstevel@tonic-gate 35240Sstevel@tonic-gate if (!sctp_check_input(sctp, ch, mlen, 1)) { 35253448Sdh155122 BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 352611042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, NULL); 35270Sstevel@tonic-gate goto done; 35280Sstevel@tonic-gate } 35290Sstevel@tonic-gate /* 35300Sstevel@tonic-gate * Check verfication tag (special handling for INIT, 35310Sstevel@tonic-gate * COOKIE, SHUTDOWN_COMPLETE and SHUTDOWN_ACK chunks). 35320Sstevel@tonic-gate * ABORTs are handled in the chunk processing loop, since 35330Sstevel@tonic-gate * may not appear first. All other checked chunks must 35340Sstevel@tonic-gate * appear first, or will have been dropped by check_input(). 35350Sstevel@tonic-gate */ 35360Sstevel@tonic-gate switch (ch->sch_id) { 35370Sstevel@tonic-gate case CHUNK_INIT: 35380Sstevel@tonic-gate if (sctph->sh_verf != 0) { 35390Sstevel@tonic-gate /* drop it */ 35400Sstevel@tonic-gate goto done; 35410Sstevel@tonic-gate } 35420Sstevel@tonic-gate break; 35430Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 35440Sstevel@tonic-gate if (sctph->sh_verf == sctp->sctp_lvtag) 35450Sstevel@tonic-gate break; 35460Sstevel@tonic-gate if (sctph->sh_verf == sctp->sctp_fvtag && 35470Sstevel@tonic-gate SCTP_GET_TBIT(ch)) { 35480Sstevel@tonic-gate break; 35490Sstevel@tonic-gate } 35500Sstevel@tonic-gate /* else drop it */ 35510Sstevel@tonic-gate goto done; 35520Sstevel@tonic-gate case CHUNK_ABORT: 35530Sstevel@tonic-gate case CHUNK_COOKIE: 35540Sstevel@tonic-gate /* handled below */ 35550Sstevel@tonic-gate break; 35560Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 35570Sstevel@tonic-gate if (sctp->sctp_state > SCTPS_BOUND && 35580Sstevel@tonic-gate sctp->sctp_state < SCTPS_ESTABLISHED) { 35590Sstevel@tonic-gate /* treat as OOTB */ 356011042SErik.Nordmark@Sun.COM sctp_ootb_shutdown_ack(mp, ip_hdr_len, ira, ipst); 35610Sstevel@tonic-gate return; 35620Sstevel@tonic-gate } 35630Sstevel@tonic-gate /* else fallthru */ 35640Sstevel@tonic-gate default: 35650Sstevel@tonic-gate /* 35660Sstevel@tonic-gate * All other packets must have a valid 35670Sstevel@tonic-gate * verification tag, however if this is a 35680Sstevel@tonic-gate * listener, we use a refined version of 35690Sstevel@tonic-gate * out-of-the-blue logic. 35700Sstevel@tonic-gate */ 35710Sstevel@tonic-gate if (sctph->sh_verf != sctp->sctp_lvtag && 35720Sstevel@tonic-gate sctp->sctp_state != SCTPS_LISTEN) { 35730Sstevel@tonic-gate /* drop it */ 35740Sstevel@tonic-gate goto done; 35750Sstevel@tonic-gate } 35760Sstevel@tonic-gate break; 35770Sstevel@tonic-gate } 35780Sstevel@tonic-gate 35790Sstevel@tonic-gate /* Have a valid sctp for this packet */ 35800Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &src); 35811676Sjpk dprint(2, ("sctp_dispatch_rput: mp=%p fp=%p sctp=%p\n", (void *)mp, 35821676Sjpk (void *)fp, (void *)sctp)); 35830Sstevel@tonic-gate 35840Sstevel@tonic-gate gotdata = 0; 35850Sstevel@tonic-gate trysend = 0; 35860Sstevel@tonic-gate 3587*11066Srafael.vanoni@sun.com now = ddi_get_lbolt64(); 35880Sstevel@tonic-gate /* Process the chunks */ 35890Sstevel@tonic-gate do { 35900Sstevel@tonic-gate dprint(3, ("sctp_dispatch_rput: state=%d, chunk id=%d\n", 35910Sstevel@tonic-gate sctp->sctp_state, (int)(ch->sch_id))); 35920Sstevel@tonic-gate 35930Sstevel@tonic-gate if (ch->sch_id == CHUNK_ABORT) { 35940Sstevel@tonic-gate if (sctph->sh_verf != sctp->sctp_lvtag && 35950Sstevel@tonic-gate sctph->sh_verf != sctp->sctp_fvtag) { 35960Sstevel@tonic-gate /* drop it */ 35970Sstevel@tonic-gate goto done; 35980Sstevel@tonic-gate } 35990Sstevel@tonic-gate } 36000Sstevel@tonic-gate 36010Sstevel@tonic-gate switch (sctp->sctp_state) { 36020Sstevel@tonic-gate 36030Sstevel@tonic-gate case SCTPS_ESTABLISHED: 36040Sstevel@tonic-gate case SCTPS_SHUTDOWN_PENDING: 36050Sstevel@tonic-gate case SCTPS_SHUTDOWN_SENT: 36060Sstevel@tonic-gate switch (ch->sch_id) { 36070Sstevel@tonic-gate case CHUNK_DATA: 36080Sstevel@tonic-gate /* 0-length data chunks are not allowed */ 36090Sstevel@tonic-gate if (ntohs(ch->sch_len) == sizeof (*sdc)) { 36100Sstevel@tonic-gate sdc = (sctp_data_hdr_t *)ch; 36110Sstevel@tonic-gate tsn = sdc->sdh_tsn; 36120Sstevel@tonic-gate sctp_send_abort(sctp, sctp->sctp_fvtag, 36130Sstevel@tonic-gate SCTP_ERR_NO_USR_DATA, (char *)&tsn, 361411042SErik.Nordmark@Sun.COM sizeof (tsn), mp, 0, B_FALSE, ira); 36150Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_LOST, 36160Sstevel@tonic-gate 0, NULL); 36170Sstevel@tonic-gate sctp_clean_death(sctp, ECONNABORTED); 36180Sstevel@tonic-gate goto done; 36190Sstevel@tonic-gate } 36200Sstevel@tonic-gate 36210Sstevel@tonic-gate ASSERT(fp != NULL); 36220Sstevel@tonic-gate sctp->sctp_lastdata = fp; 362311042SErik.Nordmark@Sun.COM sctp_data_chunk(sctp, ch, mp, &dups, fp, 362411042SErik.Nordmark@Sun.COM &ipp, ira); 36250Sstevel@tonic-gate gotdata = 1; 36260Sstevel@tonic-gate /* Restart shutdown timer if shutting down */ 36270Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_SHUTDOWN_SENT) { 36280Sstevel@tonic-gate /* 36290Sstevel@tonic-gate * If we have exceeded our max 36300Sstevel@tonic-gate * wait bound for waiting for a 36310Sstevel@tonic-gate * shutdown ack from the peer, 36320Sstevel@tonic-gate * abort the association. 36330Sstevel@tonic-gate */ 36343448Sdh155122 if (sctps->sctps_shutack_wait_bound != 36353448Sdh155122 0 && 36360Sstevel@tonic-gate TICK_TO_MSEC(now - 36370Sstevel@tonic-gate sctp->sctp_out_time) > 36383448Sdh155122 sctps->sctps_shutack_wait_bound) { 36390Sstevel@tonic-gate sctp_send_abort(sctp, 36400Sstevel@tonic-gate sctp->sctp_fvtag, 0, NULL, 364111042SErik.Nordmark@Sun.COM 0, mp, 0, B_FALSE, ira); 36420Sstevel@tonic-gate sctp_assoc_event(sctp, 36430Sstevel@tonic-gate SCTP_COMM_LOST, 0, NULL); 36440Sstevel@tonic-gate sctp_clean_death(sctp, 36450Sstevel@tonic-gate ECONNABORTED); 36460Sstevel@tonic-gate goto done; 36470Sstevel@tonic-gate } 36480Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, 36490Sstevel@tonic-gate fp->rto); 36500Sstevel@tonic-gate } 36510Sstevel@tonic-gate break; 36520Sstevel@tonic-gate case CHUNK_SACK: 36530Sstevel@tonic-gate ASSERT(fp != NULL); 36540Sstevel@tonic-gate /* 36550Sstevel@tonic-gate * Peer is real and alive if it can ack our 36560Sstevel@tonic-gate * data. 36570Sstevel@tonic-gate */ 36580Sstevel@tonic-gate sctp_faddr_alive(sctp, fp); 36590Sstevel@tonic-gate trysend = sctp_got_sack(sctp, ch); 3660852Svi117747 if (trysend < 0) { 3661852Svi117747 sctp_send_abort(sctp, sctph->sh_verf, 366211042SErik.Nordmark@Sun.COM 0, NULL, 0, mp, 0, B_FALSE, ira); 3663852Svi117747 sctp_assoc_event(sctp, 3664852Svi117747 SCTP_COMM_LOST, 0, NULL); 3665852Svi117747 sctp_clean_death(sctp, 3666852Svi117747 ECONNABORTED); 3667852Svi117747 goto done; 3668852Svi117747 } 36690Sstevel@tonic-gate break; 36700Sstevel@tonic-gate case CHUNK_HEARTBEAT: 36714964Skcpoon if (!hb_already) { 36724964Skcpoon /* 36734964Skcpoon * In any one packet, there should 36744964Skcpoon * only be one heartbeat chunk. So 36754964Skcpoon * we should not process more than 36764964Skcpoon * once. 36774964Skcpoon */ 36784964Skcpoon sctp_return_heartbeat(sctp, ch, mp); 36794964Skcpoon hb_already = B_TRUE; 36804964Skcpoon } 36810Sstevel@tonic-gate break; 36820Sstevel@tonic-gate case CHUNK_HEARTBEAT_ACK: 36830Sstevel@tonic-gate sctp_process_heartbeat(sctp, ch); 36840Sstevel@tonic-gate break; 36850Sstevel@tonic-gate case CHUNK_SHUTDOWN: 36860Sstevel@tonic-gate sctp_shutdown_event(sctp); 36870Sstevel@tonic-gate trysend = sctp_shutdown_received(sctp, ch, 36881735Skcpoon B_FALSE, B_FALSE, fp); 36890Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 36900Sstevel@tonic-gate break; 36910Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 36920Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 36930Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_SHUTDOWN_SENT) { 36940Sstevel@tonic-gate sctp_shutdown_complete(sctp); 36953448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 36963448Sdh155122 sctpShutdowns); 36970Sstevel@tonic-gate sctp_assoc_event(sctp, 36980Sstevel@tonic-gate SCTP_SHUTDOWN_COMP, 0, NULL); 36990Sstevel@tonic-gate sctp_clean_death(sctp, 0); 37000Sstevel@tonic-gate goto done; 37010Sstevel@tonic-gate } 37020Sstevel@tonic-gate break; 37030Sstevel@tonic-gate case CHUNK_ABORT: { 37040Sstevel@tonic-gate sctp_saddr_ipif_t *sp; 37050Sstevel@tonic-gate 37060Sstevel@tonic-gate /* Ignore if delete pending */ 3707852Svi117747 sp = sctp_saddr_lookup(sctp, &dst, 0); 37080Sstevel@tonic-gate ASSERT(sp != NULL); 37090Sstevel@tonic-gate if (sp->saddr_ipif_delete_pending) { 37100Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 37110Sstevel@tonic-gate break; 37120Sstevel@tonic-gate } 37130Sstevel@tonic-gate 37140Sstevel@tonic-gate sctp_process_abort(sctp, ch, ECONNRESET); 37150Sstevel@tonic-gate goto done; 37160Sstevel@tonic-gate } 37170Sstevel@tonic-gate case CHUNK_INIT: 371811042SErik.Nordmark@Sun.COM sctp_send_initack(sctp, sctph, ch, mp, ira); 37190Sstevel@tonic-gate break; 37200Sstevel@tonic-gate case CHUNK_COOKIE: 37210Sstevel@tonic-gate if (sctp_process_cookie(sctp, ch, mp, &iack, 372211042SErik.Nordmark@Sun.COM sctph, &recv_adaptation, NULL, ira) != -1) { 37230Sstevel@tonic-gate sctp_send_cookie_ack(sctp); 37240Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_RESTART, 37250Sstevel@tonic-gate 0, NULL); 37265586Skcpoon if (recv_adaptation) { 37275586Skcpoon sctp->sctp_recv_adaptation = 1; 37285586Skcpoon sctp_adaptation_event(sctp); 37290Sstevel@tonic-gate } 37300Sstevel@tonic-gate } else { 37313448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 37320Sstevel@tonic-gate sctpInInvalidCookie); 37330Sstevel@tonic-gate } 37340Sstevel@tonic-gate break; 37350Sstevel@tonic-gate case CHUNK_ERROR: { 37360Sstevel@tonic-gate int error; 37370Sstevel@tonic-gate 37380Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 373911042SErik.Nordmark@Sun.COM error = sctp_handle_error(sctp, sctph, ch, mp, 374011042SErik.Nordmark@Sun.COM ira); 37410Sstevel@tonic-gate if (error != 0) { 37423314Skcpoon sctp_assoc_event(sctp, SCTP_COMM_LOST, 37433314Skcpoon 0, NULL); 37440Sstevel@tonic-gate sctp_clean_death(sctp, error); 37450Sstevel@tonic-gate goto done; 37460Sstevel@tonic-gate } 37470Sstevel@tonic-gate break; 37480Sstevel@tonic-gate } 37490Sstevel@tonic-gate case CHUNK_ASCONF: 37500Sstevel@tonic-gate ASSERT(fp != NULL); 37510Sstevel@tonic-gate sctp_input_asconf(sctp, ch, fp); 37520Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 37530Sstevel@tonic-gate break; 37540Sstevel@tonic-gate case CHUNK_ASCONF_ACK: 37550Sstevel@tonic-gate ASSERT(fp != NULL); 37560Sstevel@tonic-gate sctp_faddr_alive(sctp, fp); 37570Sstevel@tonic-gate sctp_input_asconf_ack(sctp, ch, fp); 37580Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 37590Sstevel@tonic-gate break; 37600Sstevel@tonic-gate case CHUNK_FORWARD_TSN: 37610Sstevel@tonic-gate ASSERT(fp != NULL); 37620Sstevel@tonic-gate sctp->sctp_lastdata = fp; 376311042SErik.Nordmark@Sun.COM sctp_process_forward_tsn(sctp, ch, fp, 376411042SErik.Nordmark@Sun.COM &ipp, ira); 37650Sstevel@tonic-gate gotdata = 1; 37660Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 37670Sstevel@tonic-gate break; 37680Sstevel@tonic-gate default: 37690Sstevel@tonic-gate if (sctp_strange_chunk(sctp, ch, fp) == 0) { 37700Sstevel@tonic-gate goto nomorechunks; 37710Sstevel@tonic-gate } /* else skip and continue processing */ 37720Sstevel@tonic-gate break; 37730Sstevel@tonic-gate } 37740Sstevel@tonic-gate break; 37750Sstevel@tonic-gate 37760Sstevel@tonic-gate case SCTPS_LISTEN: 37770Sstevel@tonic-gate switch (ch->sch_id) { 37780Sstevel@tonic-gate case CHUNK_INIT: 377911042SErik.Nordmark@Sun.COM sctp_send_initack(sctp, sctph, ch, mp, ira); 37800Sstevel@tonic-gate break; 37810Sstevel@tonic-gate case CHUNK_COOKIE: { 37820Sstevel@tonic-gate sctp_t *eager; 37830Sstevel@tonic-gate 37840Sstevel@tonic-gate if (sctp_process_cookie(sctp, ch, mp, &iack, 378511042SErik.Nordmark@Sun.COM sctph, &recv_adaptation, &peer_src, 378611042SErik.Nordmark@Sun.COM ira) == -1) { 37873448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 37880Sstevel@tonic-gate sctpInInvalidCookie); 37890Sstevel@tonic-gate goto done; 37900Sstevel@tonic-gate } 37910Sstevel@tonic-gate 37920Sstevel@tonic-gate /* 37930Sstevel@tonic-gate * The cookie is good; ensure that 37940Sstevel@tonic-gate * the peer used the verification 37950Sstevel@tonic-gate * tag from the init ack in the header. 37960Sstevel@tonic-gate */ 37970Sstevel@tonic-gate if (iack->sic_inittag != sctph->sh_verf) 37980Sstevel@tonic-gate goto done; 37990Sstevel@tonic-gate 38000Sstevel@tonic-gate eager = sctp_conn_request(sctp, mp, ifindex, 380111042SErik.Nordmark@Sun.COM ip_hdr_len, iack, ira); 38020Sstevel@tonic-gate if (eager == NULL) { 38030Sstevel@tonic-gate sctp_send_abort(sctp, sctph->sh_verf, 38040Sstevel@tonic-gate SCTP_ERR_NO_RESOURCES, NULL, 0, mp, 380511042SErik.Nordmark@Sun.COM 0, B_FALSE, ira); 38060Sstevel@tonic-gate goto done; 38070Sstevel@tonic-gate } 38080Sstevel@tonic-gate 38090Sstevel@tonic-gate /* 38100Sstevel@tonic-gate * If there were extra chunks 38110Sstevel@tonic-gate * bundled with the cookie, 38120Sstevel@tonic-gate * they must be processed 38130Sstevel@tonic-gate * on the eager's queue. We 38140Sstevel@tonic-gate * accomplish this by refeeding 38150Sstevel@tonic-gate * the whole packet into the 38160Sstevel@tonic-gate * state machine on the right 38170Sstevel@tonic-gate * q. The packet (mp) gets 38180Sstevel@tonic-gate * there via the eager's 38190Sstevel@tonic-gate * cookie_mp field (overloaded 38200Sstevel@tonic-gate * with the active open role). 38210Sstevel@tonic-gate * This is picked up when 38220Sstevel@tonic-gate * processing the null bind 38230Sstevel@tonic-gate * request put on the eager's 38240Sstevel@tonic-gate * q by sctp_accept(). We must 38250Sstevel@tonic-gate * first revert the cookie 38260Sstevel@tonic-gate * chunk's length field to network 38270Sstevel@tonic-gate * byteorder so it can be 38280Sstevel@tonic-gate * properly reprocessed on the 38290Sstevel@tonic-gate * eager's queue. 38300Sstevel@tonic-gate */ 38313448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpPassiveEstab); 38320Sstevel@tonic-gate if (mlen > ntohs(ch->sch_len)) { 38330Sstevel@tonic-gate eager->sctp_cookie_mp = dupb(mp); 38340Sstevel@tonic-gate /* 38350Sstevel@tonic-gate * If no mem, just let 38360Sstevel@tonic-gate * the peer retransmit. 38370Sstevel@tonic-gate */ 38380Sstevel@tonic-gate } 38390Sstevel@tonic-gate sctp_assoc_event(eager, SCTP_COMM_UP, 0, NULL); 38405586Skcpoon if (recv_adaptation) { 38415586Skcpoon eager->sctp_recv_adaptation = 1; 38425586Skcpoon eager->sctp_rx_adaptation_code = 38435586Skcpoon sctp->sctp_rx_adaptation_code; 38445586Skcpoon sctp_adaptation_event(eager); 38450Sstevel@tonic-gate } 38460Sstevel@tonic-gate 38470Sstevel@tonic-gate eager->sctp_active = now; 38480Sstevel@tonic-gate sctp_send_cookie_ack(eager); 38490Sstevel@tonic-gate 38500Sstevel@tonic-gate wake_eager = B_TRUE; 38510Sstevel@tonic-gate 38520Sstevel@tonic-gate /* 38530Sstevel@tonic-gate * Process rest of the chunks with eager. 38540Sstevel@tonic-gate */ 38550Sstevel@tonic-gate sctp = eager; 38560Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &peer_src); 38570Sstevel@tonic-gate /* 38580Sstevel@tonic-gate * Confirm peer's original source. fp can 38590Sstevel@tonic-gate * only be NULL if peer does not use the 38600Sstevel@tonic-gate * original source as one of its addresses... 38610Sstevel@tonic-gate */ 38620Sstevel@tonic-gate if (fp == NULL) 38630Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &src); 38640Sstevel@tonic-gate else 38650Sstevel@tonic-gate sctp_faddr_alive(sctp, fp); 38660Sstevel@tonic-gate 38670Sstevel@tonic-gate /* 38680Sstevel@tonic-gate * Validate the peer addresses. It also starts 38690Sstevel@tonic-gate * the heartbeat timer. 38700Sstevel@tonic-gate */ 38710Sstevel@tonic-gate sctp_validate_peer(sctp); 38720Sstevel@tonic-gate break; 38730Sstevel@tonic-gate } 38740Sstevel@tonic-gate /* Anything else is considered out-of-the-blue */ 38750Sstevel@tonic-gate case CHUNK_ERROR: 38760Sstevel@tonic-gate case CHUNK_ABORT: 38770Sstevel@tonic-gate case CHUNK_COOKIE_ACK: 38780Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 38790Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 38800Sstevel@tonic-gate goto done; 38810Sstevel@tonic-gate default: 38820Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 38830Sstevel@tonic-gate sctp_send_abort(sctp, sctph->sh_verf, 0, NULL, 388411042SErik.Nordmark@Sun.COM 0, mp, 0, B_TRUE, ira); 38850Sstevel@tonic-gate goto done; 38860Sstevel@tonic-gate } 38870Sstevel@tonic-gate break; 38880Sstevel@tonic-gate 38890Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 38900Sstevel@tonic-gate switch (ch->sch_id) { 38910Sstevel@tonic-gate case CHUNK_INIT_ACK: 38920Sstevel@tonic-gate sctp_stop_faddr_timers(sctp); 38930Sstevel@tonic-gate sctp_faddr_alive(sctp, sctp->sctp_current); 389411042SErik.Nordmark@Sun.COM sctp_send_cookie_echo(sctp, ch, mp, ira); 38950Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 38960Sstevel@tonic-gate break; 38970Sstevel@tonic-gate case CHUNK_ABORT: 38980Sstevel@tonic-gate sctp_process_abort(sctp, ch, ECONNREFUSED); 38990Sstevel@tonic-gate goto done; 39000Sstevel@tonic-gate case CHUNK_INIT: 390111042SErik.Nordmark@Sun.COM sctp_send_initack(sctp, sctph, ch, mp, ira); 39020Sstevel@tonic-gate break; 39030Sstevel@tonic-gate case CHUNK_COOKIE: 390411042SErik.Nordmark@Sun.COM cr = ira->ira_cred; 390511042SErik.Nordmark@Sun.COM cpid = ira->ira_cpid; 39068778SErik.Nordmark@Sun.COM 39070Sstevel@tonic-gate if (sctp_process_cookie(sctp, ch, mp, &iack, 390811042SErik.Nordmark@Sun.COM sctph, &recv_adaptation, NULL, ira) == -1) { 39093448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 39100Sstevel@tonic-gate sctpInInvalidCookie); 39110Sstevel@tonic-gate break; 39120Sstevel@tonic-gate } 39130Sstevel@tonic-gate sctp_send_cookie_ack(sctp); 39140Sstevel@tonic-gate sctp_stop_faddr_timers(sctp); 39150Sstevel@tonic-gate if (!SCTP_IS_DETACHED(sctp)) { 39164964Skcpoon sctp->sctp_ulp_connected( 39178778SErik.Nordmark@Sun.COM sctp->sctp_ulpd, 0, cr, cpid); 39184964Skcpoon sctp_set_ulp_prop(sctp); 39198778SErik.Nordmark@Sun.COM 39200Sstevel@tonic-gate } 39210Sstevel@tonic-gate sctp->sctp_state = SCTPS_ESTABLISHED; 3922*11066Srafael.vanoni@sun.com sctp->sctp_assoc_start_time = 3923*11066Srafael.vanoni@sun.com (uint32_t)ddi_get_lbolt(); 39243448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpActiveEstab); 39250Sstevel@tonic-gate if (sctp->sctp_cookie_mp) { 39260Sstevel@tonic-gate freemsg(sctp->sctp_cookie_mp); 39270Sstevel@tonic-gate sctp->sctp_cookie_mp = NULL; 39280Sstevel@tonic-gate } 39290Sstevel@tonic-gate 39300Sstevel@tonic-gate /* Validate the peer addresses. */ 39310Sstevel@tonic-gate sctp->sctp_active = now; 39320Sstevel@tonic-gate sctp_validate_peer(sctp); 39330Sstevel@tonic-gate 39340Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_UP, 0, NULL); 39355586Skcpoon if (recv_adaptation) { 39365586Skcpoon sctp->sctp_recv_adaptation = 1; 39375586Skcpoon sctp_adaptation_event(sctp); 39380Sstevel@tonic-gate } 39390Sstevel@tonic-gate /* Try sending queued data, or ASCONFs */ 39400Sstevel@tonic-gate trysend = 1; 39410Sstevel@tonic-gate break; 39420Sstevel@tonic-gate default: 39430Sstevel@tonic-gate if (sctp_strange_chunk(sctp, ch, fp) == 0) { 39440Sstevel@tonic-gate goto nomorechunks; 39450Sstevel@tonic-gate } /* else skip and continue processing */ 39460Sstevel@tonic-gate break; 39470Sstevel@tonic-gate } 39480Sstevel@tonic-gate break; 39490Sstevel@tonic-gate 39500Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 39510Sstevel@tonic-gate switch (ch->sch_id) { 39520Sstevel@tonic-gate case CHUNK_COOKIE_ACK: 395311042SErik.Nordmark@Sun.COM cr = ira->ira_cred; 395411042SErik.Nordmark@Sun.COM cpid = ira->ira_cpid; 39558778SErik.Nordmark@Sun.COM 39560Sstevel@tonic-gate if (!SCTP_IS_DETACHED(sctp)) { 39574964Skcpoon sctp->sctp_ulp_connected( 39588778SErik.Nordmark@Sun.COM sctp->sctp_ulpd, 0, cr, cpid); 39594964Skcpoon sctp_set_ulp_prop(sctp); 39600Sstevel@tonic-gate } 39610Sstevel@tonic-gate if (sctp->sctp_unacked == 0) 39620Sstevel@tonic-gate sctp_stop_faddr_timers(sctp); 39630Sstevel@tonic-gate sctp->sctp_state = SCTPS_ESTABLISHED; 3964*11066Srafael.vanoni@sun.com sctp->sctp_assoc_start_time = 3965*11066Srafael.vanoni@sun.com (uint32_t)ddi_get_lbolt(); 39663448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpActiveEstab); 39670Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 39680Sstevel@tonic-gate if (sctp->sctp_cookie_mp) { 39690Sstevel@tonic-gate freemsg(sctp->sctp_cookie_mp); 39700Sstevel@tonic-gate sctp->sctp_cookie_mp = NULL; 39710Sstevel@tonic-gate } 39720Sstevel@tonic-gate sctp_faddr_alive(sctp, fp); 39730Sstevel@tonic-gate /* Validate the peer addresses. */ 39740Sstevel@tonic-gate sctp->sctp_active = now; 39750Sstevel@tonic-gate sctp_validate_peer(sctp); 39760Sstevel@tonic-gate 39770Sstevel@tonic-gate /* Try sending queued data, or ASCONFs */ 39780Sstevel@tonic-gate trysend = 1; 39790Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_UP, 0, NULL); 39805586Skcpoon sctp_adaptation_event(sctp); 39810Sstevel@tonic-gate break; 39820Sstevel@tonic-gate case CHUNK_ABORT: 39830Sstevel@tonic-gate sctp_process_abort(sctp, ch, ECONNREFUSED); 39840Sstevel@tonic-gate goto done; 39850Sstevel@tonic-gate case CHUNK_COOKIE: 398611042SErik.Nordmark@Sun.COM cr = ira->ira_cred; 398711042SErik.Nordmark@Sun.COM cpid = ira->ira_cpid; 39888778SErik.Nordmark@Sun.COM 39890Sstevel@tonic-gate if (sctp_process_cookie(sctp, ch, mp, &iack, 399011042SErik.Nordmark@Sun.COM sctph, &recv_adaptation, NULL, ira) == -1) { 39913448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 39920Sstevel@tonic-gate sctpInInvalidCookie); 39930Sstevel@tonic-gate break; 39940Sstevel@tonic-gate } 39950Sstevel@tonic-gate sctp_send_cookie_ack(sctp); 39960Sstevel@tonic-gate 39970Sstevel@tonic-gate if (!SCTP_IS_DETACHED(sctp)) { 39984964Skcpoon sctp->sctp_ulp_connected( 39998778SErik.Nordmark@Sun.COM sctp->sctp_ulpd, 0, cr, cpid); 40004964Skcpoon sctp_set_ulp_prop(sctp); 40018778SErik.Nordmark@Sun.COM 40020Sstevel@tonic-gate } 40030Sstevel@tonic-gate if (sctp->sctp_unacked == 0) 40040Sstevel@tonic-gate sctp_stop_faddr_timers(sctp); 40050Sstevel@tonic-gate sctp->sctp_state = SCTPS_ESTABLISHED; 4006*11066Srafael.vanoni@sun.com sctp->sctp_assoc_start_time = 4007*11066Srafael.vanoni@sun.com (uint32_t)ddi_get_lbolt(); 40083448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpActiveEstab); 40090Sstevel@tonic-gate if (sctp->sctp_cookie_mp) { 40100Sstevel@tonic-gate freemsg(sctp->sctp_cookie_mp); 40110Sstevel@tonic-gate sctp->sctp_cookie_mp = NULL; 40120Sstevel@tonic-gate } 40130Sstevel@tonic-gate /* Validate the peer addresses. */ 40140Sstevel@tonic-gate sctp->sctp_active = now; 40150Sstevel@tonic-gate sctp_validate_peer(sctp); 40160Sstevel@tonic-gate 40170Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_UP, 0, NULL); 40185586Skcpoon if (recv_adaptation) { 40195586Skcpoon sctp->sctp_recv_adaptation = 1; 40205586Skcpoon sctp_adaptation_event(sctp); 40210Sstevel@tonic-gate } 40220Sstevel@tonic-gate /* Try sending queued data, or ASCONFs */ 40230Sstevel@tonic-gate trysend = 1; 40240Sstevel@tonic-gate break; 40250Sstevel@tonic-gate case CHUNK_INIT: 402611042SErik.Nordmark@Sun.COM sctp_send_initack(sctp, sctph, ch, mp, ira); 40270Sstevel@tonic-gate break; 40280Sstevel@tonic-gate case CHUNK_ERROR: { 40290Sstevel@tonic-gate sctp_parm_hdr_t *p; 40300Sstevel@tonic-gate 40310Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 40320Sstevel@tonic-gate /* check for a stale cookie */ 40330Sstevel@tonic-gate if (ntohs(ch->sch_len) >= 40340Sstevel@tonic-gate (sizeof (*p) + sizeof (*ch)) + 40350Sstevel@tonic-gate sizeof (uint32_t)) { 40360Sstevel@tonic-gate 40370Sstevel@tonic-gate p = (sctp_parm_hdr_t *)(ch + 1); 40380Sstevel@tonic-gate if (p->sph_type == 40390Sstevel@tonic-gate htons(SCTP_ERR_STALE_COOKIE)) { 40403448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 40410Sstevel@tonic-gate sctpAborted); 40420Sstevel@tonic-gate sctp_error_event(sctp, ch); 40433314Skcpoon sctp_assoc_event(sctp, 40443314Skcpoon SCTP_COMM_LOST, 0, NULL); 40450Sstevel@tonic-gate sctp_clean_death(sctp, 40460Sstevel@tonic-gate ECONNREFUSED); 40470Sstevel@tonic-gate goto done; 40480Sstevel@tonic-gate } 40490Sstevel@tonic-gate } 40500Sstevel@tonic-gate break; 40510Sstevel@tonic-gate } 40520Sstevel@tonic-gate case CHUNK_HEARTBEAT: 40534964Skcpoon if (!hb_already) { 40544964Skcpoon sctp_return_heartbeat(sctp, ch, mp); 40554964Skcpoon hb_already = B_TRUE; 40564964Skcpoon } 40570Sstevel@tonic-gate break; 40580Sstevel@tonic-gate default: 40590Sstevel@tonic-gate if (sctp_strange_chunk(sctp, ch, fp) == 0) { 40600Sstevel@tonic-gate goto nomorechunks; 40610Sstevel@tonic-gate } /* else skip and continue processing */ 40620Sstevel@tonic-gate } /* switch (ch->sch_id) */ 40630Sstevel@tonic-gate break; 40640Sstevel@tonic-gate 40650Sstevel@tonic-gate case SCTPS_SHUTDOWN_ACK_SENT: 40660Sstevel@tonic-gate switch (ch->sch_id) { 40670Sstevel@tonic-gate case CHUNK_ABORT: 40680Sstevel@tonic-gate /* Pass gathered wisdom to IP for keeping */ 406911042SErik.Nordmark@Sun.COM sctp_update_dce(sctp); 40700Sstevel@tonic-gate sctp_process_abort(sctp, ch, 0); 40710Sstevel@tonic-gate goto done; 40720Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 40730Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 40743448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpShutdowns); 40750Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_SHUTDOWN_COMP, 0, 40760Sstevel@tonic-gate NULL); 40770Sstevel@tonic-gate 40780Sstevel@tonic-gate /* Pass gathered wisdom to IP for keeping */ 407911042SErik.Nordmark@Sun.COM sctp_update_dce(sctp); 40800Sstevel@tonic-gate sctp_clean_death(sctp, 0); 40810Sstevel@tonic-gate goto done; 40820Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 40830Sstevel@tonic-gate sctp_shutdown_complete(sctp); 40840Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 40853448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpShutdowns); 40860Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_SHUTDOWN_COMP, 0, 40870Sstevel@tonic-gate NULL); 40880Sstevel@tonic-gate sctp_clean_death(sctp, 0); 40890Sstevel@tonic-gate goto done; 40900Sstevel@tonic-gate case CHUNK_COOKIE: 40910Sstevel@tonic-gate (void) sctp_shutdown_received(sctp, NULL, 40921735Skcpoon B_TRUE, B_FALSE, fp); 40930Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 40940Sstevel@tonic-gate break; 40950Sstevel@tonic-gate case CHUNK_HEARTBEAT: 40964964Skcpoon if (!hb_already) { 40974964Skcpoon sctp_return_heartbeat(sctp, ch, mp); 40984964Skcpoon hb_already = B_TRUE; 40994964Skcpoon } 41000Sstevel@tonic-gate break; 41010Sstevel@tonic-gate default: 41020Sstevel@tonic-gate if (sctp_strange_chunk(sctp, ch, fp) == 0) { 41030Sstevel@tonic-gate goto nomorechunks; 41040Sstevel@tonic-gate } /* else skip and continue processing */ 41050Sstevel@tonic-gate break; 41060Sstevel@tonic-gate } 41070Sstevel@tonic-gate break; 41080Sstevel@tonic-gate 41090Sstevel@tonic-gate case SCTPS_SHUTDOWN_RECEIVED: 41100Sstevel@tonic-gate switch (ch->sch_id) { 41110Sstevel@tonic-gate case CHUNK_SHUTDOWN: 41120Sstevel@tonic-gate trysend = sctp_shutdown_received(sctp, ch, 41131735Skcpoon B_FALSE, B_FALSE, fp); 41140Sstevel@tonic-gate break; 41150Sstevel@tonic-gate case CHUNK_SACK: 41160Sstevel@tonic-gate trysend = sctp_got_sack(sctp, ch); 4117852Svi117747 if (trysend < 0) { 4118852Svi117747 sctp_send_abort(sctp, sctph->sh_verf, 411911042SErik.Nordmark@Sun.COM 0, NULL, 0, mp, 0, B_FALSE, ira); 4120852Svi117747 sctp_assoc_event(sctp, 4121852Svi117747 SCTP_COMM_LOST, 0, NULL); 4122852Svi117747 sctp_clean_death(sctp, 4123852Svi117747 ECONNABORTED); 4124852Svi117747 goto done; 4125852Svi117747 } 41260Sstevel@tonic-gate break; 41270Sstevel@tonic-gate case CHUNK_ABORT: 41280Sstevel@tonic-gate sctp_process_abort(sctp, ch, ECONNRESET); 41290Sstevel@tonic-gate goto done; 41300Sstevel@tonic-gate case CHUNK_HEARTBEAT: 41314964Skcpoon if (!hb_already) { 41324964Skcpoon sctp_return_heartbeat(sctp, ch, mp); 41334964Skcpoon hb_already = B_TRUE; 41344964Skcpoon } 41350Sstevel@tonic-gate break; 41360Sstevel@tonic-gate default: 41370Sstevel@tonic-gate if (sctp_strange_chunk(sctp, ch, fp) == 0) { 41380Sstevel@tonic-gate goto nomorechunks; 41390Sstevel@tonic-gate } /* else skip and continue processing */ 41400Sstevel@tonic-gate break; 41410Sstevel@tonic-gate } 41420Sstevel@tonic-gate break; 41430Sstevel@tonic-gate 41440Sstevel@tonic-gate default: 41451932Svi117747 /* 41461932Svi117747 * The only remaining states are SCTPS_IDLE and 41471932Svi117747 * SCTPS_BOUND, and we should not be getting here 41481932Svi117747 * for these. 41491932Svi117747 */ 41501932Svi117747 ASSERT(0); 41510Sstevel@tonic-gate } /* switch (sctp->sctp_state) */ 41520Sstevel@tonic-gate 41530Sstevel@tonic-gate ch = sctp_next_chunk(ch, &mlen); 41540Sstevel@tonic-gate if (ch != NULL && !sctp_check_input(sctp, ch, mlen, 0)) 41550Sstevel@tonic-gate goto done; 41560Sstevel@tonic-gate } while (ch != NULL); 41570Sstevel@tonic-gate 41580Sstevel@tonic-gate /* Finished processing all chunks in packet */ 41590Sstevel@tonic-gate 41600Sstevel@tonic-gate nomorechunks: 41610Sstevel@tonic-gate /* SACK if necessary */ 41620Sstevel@tonic-gate if (gotdata) { 41634964Skcpoon boolean_t sack_sent; 41644964Skcpoon 41650Sstevel@tonic-gate (sctp->sctp_sack_toggle)++; 41664964Skcpoon sack_sent = sctp_sack(sctp, dups); 41670Sstevel@tonic-gate dups = NULL; 41680Sstevel@tonic-gate 41694964Skcpoon /* If a SACK is sent, no need to restart the timer. */ 41704964Skcpoon if (!sack_sent && !sctp->sctp_ack_timer_running) { 41710Sstevel@tonic-gate sctp->sctp_ack_timer_running = B_TRUE; 41720Sstevel@tonic-gate sctp_timer(sctp, sctp->sctp_ack_mp, 41733448Sdh155122 MSEC_TO_TICK(sctps->sctps_deferred_ack_interval)); 41740Sstevel@tonic-gate } 41750Sstevel@tonic-gate } 41760Sstevel@tonic-gate 41770Sstevel@tonic-gate if (trysend) { 41783795Skcpoon sctp_output(sctp, UINT_MAX); 41790Sstevel@tonic-gate if (sctp->sctp_cxmit_list != NULL) 41800Sstevel@tonic-gate sctp_wput_asconf(sctp, NULL); 41810Sstevel@tonic-gate } 41820Sstevel@tonic-gate /* If there is unsent data, make sure a timer is running */ 41830Sstevel@tonic-gate if (sctp->sctp_unsent > 0 && !sctp->sctp_current->timer_running) { 41840Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current, 41850Sstevel@tonic-gate sctp->sctp_current->rto); 41860Sstevel@tonic-gate } 41870Sstevel@tonic-gate 41880Sstevel@tonic-gate done: 41890Sstevel@tonic-gate if (dups != NULL) 41900Sstevel@tonic-gate freeb(dups); 41910Sstevel@tonic-gate freemsg(mp); 41920Sstevel@tonic-gate 41934964Skcpoon if (sctp->sctp_err_chunks != NULL) 41944964Skcpoon sctp_process_err(sctp); 41954964Skcpoon 41960Sstevel@tonic-gate if (wake_eager) { 41970Sstevel@tonic-gate /* 41980Sstevel@tonic-gate * sctp points to newly created control block, need to 419911042SErik.Nordmark@Sun.COM * release it before exiting. 42000Sstevel@tonic-gate */ 42010Sstevel@tonic-gate WAKE_SCTP(sctp); 42020Sstevel@tonic-gate } 42030Sstevel@tonic-gate } 42040Sstevel@tonic-gate 42050Sstevel@tonic-gate /* 42060Sstevel@tonic-gate * Some amount of data got removed from rx q. 42070Sstevel@tonic-gate * Check if we should send a window update. 42080Sstevel@tonic-gate * 42090Sstevel@tonic-gate * Due to way sctp_rwnd updates are made, ULP can give reports out-of-order. 42100Sstevel@tonic-gate * To keep from dropping incoming data due to this, we only update 42110Sstevel@tonic-gate * sctp_rwnd when if it's larger than what we've reported to peer earlier. 42120Sstevel@tonic-gate */ 42130Sstevel@tonic-gate void 42140Sstevel@tonic-gate sctp_recvd(sctp_t *sctp, int len) 42150Sstevel@tonic-gate { 42160Sstevel@tonic-gate int32_t old, new; 42173448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 42180Sstevel@tonic-gate 42190Sstevel@tonic-gate ASSERT(sctp != NULL); 42200Sstevel@tonic-gate RUN_SCTP(sctp); 42210Sstevel@tonic-gate 42220Sstevel@tonic-gate if (len < sctp->sctp_rwnd) { 42230Sstevel@tonic-gate WAKE_SCTP(sctp); 42240Sstevel@tonic-gate return; 42250Sstevel@tonic-gate } 42260Sstevel@tonic-gate ASSERT(sctp->sctp_rwnd >= sctp->sctp_rxqueued); 42270Sstevel@tonic-gate old = sctp->sctp_rwnd - sctp->sctp_rxqueued; 42280Sstevel@tonic-gate new = len - sctp->sctp_rxqueued; 42290Sstevel@tonic-gate sctp->sctp_rwnd = len; 42300Sstevel@tonic-gate 42310Sstevel@tonic-gate if (sctp->sctp_state >= SCTPS_ESTABLISHED && 42320Sstevel@tonic-gate ((old <= new >> 1) || (old < sctp->sctp_mss))) { 42330Sstevel@tonic-gate sctp->sctp_force_sack = 1; 42343448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpOutWinUpdate); 42354964Skcpoon (void) sctp_sack(sctp, NULL); 42360Sstevel@tonic-gate } 42370Sstevel@tonic-gate WAKE_SCTP(sctp); 42380Sstevel@tonic-gate } 4239