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 /* 236374Sgeorges * Copyright 2008 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> 450Sstevel@tonic-gate #include <inet/ip6.h> 460Sstevel@tonic-gate #include <inet/mib2.h> 470Sstevel@tonic-gate #include <inet/ipclassifier.h> 480Sstevel@tonic-gate #include <inet/ipp_common.h> 490Sstevel@tonic-gate #include <inet/ipsec_impl.h> 500Sstevel@tonic-gate #include <inet/sctp_ip.h> 510Sstevel@tonic-gate 520Sstevel@tonic-gate #include "sctp_impl.h" 530Sstevel@tonic-gate #include "sctp_asconf.h" 540Sstevel@tonic-gate #include "sctp_addr.h" 550Sstevel@tonic-gate 560Sstevel@tonic-gate static struct kmem_cache *sctp_kmem_set_cache; 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * PR-SCTP comments. 600Sstevel@tonic-gate * 610Sstevel@tonic-gate * When we get a valid Forward TSN chunk, we check the fragment list for this 620Sstevel@tonic-gate * SSN and preceeding SSNs free all them. Further, if this Forward TSN causes 630Sstevel@tonic-gate * the next expected SSN to be present in the stream queue, we deliver any 640Sstevel@tonic-gate * such stranded messages upstream. We also update the SACK info. appropriately. 650Sstevel@tonic-gate * When checking for advancing the cumulative ack (in sctp_cumack()) we must 660Sstevel@tonic-gate * check for abandoned chunks and messages. While traversing the tramsmit 670Sstevel@tonic-gate * list if we come across an abandoned chunk, we can skip the message (i.e. 680Sstevel@tonic-gate * take it out of the (re)transmit list) since this message, and hence this 690Sstevel@tonic-gate * chunk, has been marked abandoned by sctp_rexmit(). If we come across an 700Sstevel@tonic-gate * unsent chunk for a message this now abandoned we need to check if a 710Sstevel@tonic-gate * Forward TSN needs to be sent, this could be a case where we deferred sending 720Sstevel@tonic-gate * a Forward TSN in sctp_get_msg_to_send(). Further, after processing a 730Sstevel@tonic-gate * SACK we check if the Advanced peer ack point can be moved ahead, i.e. 740Sstevel@tonic-gate * if we can send a Forward TSN via sctp_check_abandoned_data(). 750Sstevel@tonic-gate */ 760Sstevel@tonic-gate void 770Sstevel@tonic-gate sctp_free_set(sctp_set_t *s) 780Sstevel@tonic-gate { 790Sstevel@tonic-gate sctp_set_t *p; 800Sstevel@tonic-gate 810Sstevel@tonic-gate while (s) { 820Sstevel@tonic-gate p = s->next; 830Sstevel@tonic-gate kmem_cache_free(sctp_kmem_set_cache, s); 840Sstevel@tonic-gate s = p; 850Sstevel@tonic-gate } 860Sstevel@tonic-gate } 870Sstevel@tonic-gate 880Sstevel@tonic-gate static void 890Sstevel@tonic-gate sctp_ack_add(sctp_set_t **head, uint32_t tsn, int *num) 900Sstevel@tonic-gate { 910Sstevel@tonic-gate sctp_set_t *p, *t; 920Sstevel@tonic-gate 930Sstevel@tonic-gate if (head == NULL || num == NULL) 940Sstevel@tonic-gate return; 950Sstevel@tonic-gate 960Sstevel@tonic-gate ASSERT(*num >= 0); 970Sstevel@tonic-gate ASSERT((*num == 0 && *head == NULL) || (*num > 0 && *head != NULL)); 980Sstevel@tonic-gate 990Sstevel@tonic-gate if (*head == NULL) { 1000Sstevel@tonic-gate *head = kmem_cache_alloc(sctp_kmem_set_cache, KM_NOSLEEP); 1010Sstevel@tonic-gate if (*head == NULL) 1020Sstevel@tonic-gate return; 1030Sstevel@tonic-gate (*head)->prev = (*head)->next = NULL; 1040Sstevel@tonic-gate (*head)->begin = tsn; 1050Sstevel@tonic-gate (*head)->end = tsn; 1060Sstevel@tonic-gate *num = 1; 1070Sstevel@tonic-gate return; 1080Sstevel@tonic-gate } 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate ASSERT((*head)->prev == NULL); 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* 1130Sstevel@tonic-gate * Handle this special case here so we don't have to check 1140Sstevel@tonic-gate * for it each time in the loop. 1150Sstevel@tonic-gate */ 1160Sstevel@tonic-gate if (SEQ_LT(tsn + 1, (*head)->begin)) { 1170Sstevel@tonic-gate /* add a new set, and move the head pointer */ 1180Sstevel@tonic-gate t = kmem_cache_alloc(sctp_kmem_set_cache, KM_NOSLEEP); 1190Sstevel@tonic-gate if (t == NULL) 1200Sstevel@tonic-gate return; 1210Sstevel@tonic-gate t->next = *head; 1220Sstevel@tonic-gate t->prev = NULL; 1230Sstevel@tonic-gate (*head)->prev = t; 1240Sstevel@tonic-gate t->begin = tsn; 1250Sstevel@tonic-gate t->end = tsn; 1260Sstevel@tonic-gate (*num)++; 1270Sstevel@tonic-gate *head = t; 1280Sstevel@tonic-gate return; 1290Sstevel@tonic-gate } 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate /* 1320Sstevel@tonic-gate * We need to handle the following cases, where p points to 1330Sstevel@tonic-gate * the current set (as we walk through the loop): 1340Sstevel@tonic-gate * 1350Sstevel@tonic-gate * 1. tsn is entirely less than p; create a new set before p. 1360Sstevel@tonic-gate * 2. tsn borders p from less; coalesce p with tsn. 1370Sstevel@tonic-gate * 3. tsn is withing p; do nothing. 1380Sstevel@tonic-gate * 4. tsn borders p from greater; coalesce p with tsn. 1390Sstevel@tonic-gate * 4a. p may now border p->next from less; if so, coalesce those 1400Sstevel@tonic-gate * two sets. 1410Sstevel@tonic-gate * 5. tsn is entirely greater then all sets; add a new set at 1420Sstevel@tonic-gate * the end. 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate for (p = *head; ; p = p->next) { 1450Sstevel@tonic-gate if (SEQ_LT(tsn + 1, p->begin)) { 1460Sstevel@tonic-gate /* 1: add a new set before p. */ 1470Sstevel@tonic-gate t = kmem_cache_alloc(sctp_kmem_set_cache, KM_NOSLEEP); 1480Sstevel@tonic-gate if (t == NULL) 1490Sstevel@tonic-gate return; 1500Sstevel@tonic-gate t->next = p; 1510Sstevel@tonic-gate t->prev = NULL; 1520Sstevel@tonic-gate t->begin = tsn; 1530Sstevel@tonic-gate t->end = tsn; 1540Sstevel@tonic-gate if (p->prev) { 1550Sstevel@tonic-gate t->prev = p->prev; 1560Sstevel@tonic-gate p->prev->next = t; 1570Sstevel@tonic-gate } 1580Sstevel@tonic-gate p->prev = t; 1590Sstevel@tonic-gate (*num)++; 1600Sstevel@tonic-gate return; 1610Sstevel@tonic-gate } 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate if ((tsn + 1) == p->begin) { 1640Sstevel@tonic-gate /* 2: adjust p->begin */ 1650Sstevel@tonic-gate p->begin = tsn; 1660Sstevel@tonic-gate return; 1670Sstevel@tonic-gate } 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate if (SEQ_GEQ(tsn, p->begin) && SEQ_LEQ(tsn, p->end)) { 1700Sstevel@tonic-gate /* 3; do nothing */ 1710Sstevel@tonic-gate return; 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate if ((p->end + 1) == tsn) { 1750Sstevel@tonic-gate /* 4; adjust p->end */ 1760Sstevel@tonic-gate p->end = tsn; 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate if (p->next != NULL && (tsn + 1) == p->next->begin) { 1790Sstevel@tonic-gate /* 4a: coalesce p and p->next */ 1800Sstevel@tonic-gate t = p->next; 1810Sstevel@tonic-gate p->end = t->end; 1820Sstevel@tonic-gate p->next = t->next; 1830Sstevel@tonic-gate if (t->next != NULL) 1840Sstevel@tonic-gate t->next->prev = p; 1850Sstevel@tonic-gate kmem_cache_free(sctp_kmem_set_cache, t); 1860Sstevel@tonic-gate (*num)--; 1870Sstevel@tonic-gate } 1880Sstevel@tonic-gate return; 1890Sstevel@tonic-gate } 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate if (p->next == NULL) { 1920Sstevel@tonic-gate /* 5: add new set at the end */ 1930Sstevel@tonic-gate t = kmem_cache_alloc(sctp_kmem_set_cache, KM_NOSLEEP); 1940Sstevel@tonic-gate if (t == NULL) 1950Sstevel@tonic-gate return; 1960Sstevel@tonic-gate t->next = NULL; 1970Sstevel@tonic-gate t->prev = p; 1980Sstevel@tonic-gate t->begin = tsn; 1990Sstevel@tonic-gate t->end = tsn; 2000Sstevel@tonic-gate p->next = t; 2010Sstevel@tonic-gate (*num)++; 2020Sstevel@tonic-gate return; 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate if (SEQ_GT(tsn, p->end + 1)) 2060Sstevel@tonic-gate continue; 2070Sstevel@tonic-gate } 2080Sstevel@tonic-gate } 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate static void 2110Sstevel@tonic-gate sctp_ack_rem(sctp_set_t **head, uint32_t end, int *num) 2120Sstevel@tonic-gate { 2130Sstevel@tonic-gate sctp_set_t *p, *t; 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate if (head == NULL || *head == NULL || num == NULL) 2160Sstevel@tonic-gate return; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate /* Nothing to remove */ 2190Sstevel@tonic-gate if (SEQ_LT(end, (*head)->begin)) 2200Sstevel@tonic-gate return; 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate /* Find out where to start removing sets */ 2230Sstevel@tonic-gate for (p = *head; p->next; p = p->next) { 2240Sstevel@tonic-gate if (SEQ_LEQ(end, p->end)) 2250Sstevel@tonic-gate break; 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate if (SEQ_LT(end, p->end) && SEQ_GEQ(end, p->begin)) { 2290Sstevel@tonic-gate /* adjust p */ 2300Sstevel@tonic-gate p->begin = end + 1; 2310Sstevel@tonic-gate /* all done */ 2320Sstevel@tonic-gate if (p == *head) 2330Sstevel@tonic-gate return; 2340Sstevel@tonic-gate } else if (SEQ_GEQ(end, p->end)) { 2350Sstevel@tonic-gate /* remove this set too */ 2360Sstevel@tonic-gate p = p->next; 2370Sstevel@tonic-gate } 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate /* unlink everything before this set */ 2400Sstevel@tonic-gate t = *head; 2410Sstevel@tonic-gate *head = p; 2420Sstevel@tonic-gate if (p != NULL && p->prev != NULL) { 2430Sstevel@tonic-gate p->prev->next = NULL; 2440Sstevel@tonic-gate p->prev = NULL; 2450Sstevel@tonic-gate } 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate sctp_free_set(t); 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate /* recount the number of sets */ 2500Sstevel@tonic-gate *num = 0; 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate for (p = *head; p != NULL; p = p->next) 2530Sstevel@tonic-gate (*num)++; 2540Sstevel@tonic-gate } 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate void 2570Sstevel@tonic-gate sctp_sets_init() 2580Sstevel@tonic-gate { 2590Sstevel@tonic-gate sctp_kmem_set_cache = kmem_cache_create("sctp_set_cache", 2600Sstevel@tonic-gate sizeof (sctp_set_t), 0, NULL, NULL, NULL, NULL, 2610Sstevel@tonic-gate NULL, 0); 2620Sstevel@tonic-gate } 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate void 2650Sstevel@tonic-gate sctp_sets_fini() 2660Sstevel@tonic-gate { 2670Sstevel@tonic-gate kmem_cache_destroy(sctp_kmem_set_cache); 2680Sstevel@tonic-gate } 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate sctp_chunk_hdr_t * 2710Sstevel@tonic-gate sctp_first_chunk(uchar_t *rptr, ssize_t remaining) 2720Sstevel@tonic-gate { 2730Sstevel@tonic-gate sctp_chunk_hdr_t *ch; 2740Sstevel@tonic-gate uint16_t ch_len; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate if (remaining < sizeof (*ch)) { 2770Sstevel@tonic-gate return (NULL); 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate ch = (sctp_chunk_hdr_t *)rptr; 2810Sstevel@tonic-gate ch_len = ntohs(ch->sch_len); 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate if (ch_len < sizeof (*ch) || remaining < ch_len) { 2840Sstevel@tonic-gate return (NULL); 2850Sstevel@tonic-gate } 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate return (ch); 2880Sstevel@tonic-gate } 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate sctp_chunk_hdr_t * 2910Sstevel@tonic-gate sctp_next_chunk(sctp_chunk_hdr_t *ch, ssize_t *remaining) 2920Sstevel@tonic-gate { 2930Sstevel@tonic-gate int pad; 2940Sstevel@tonic-gate uint16_t ch_len; 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate if (!ch) { 2970Sstevel@tonic-gate return (NULL); 2980Sstevel@tonic-gate } 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate ch_len = ntohs(ch->sch_len); 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate if ((pad = ch_len & (SCTP_ALIGN - 1)) != 0) { 3030Sstevel@tonic-gate pad = SCTP_ALIGN - pad; 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate *remaining -= (ch_len + pad); 3070Sstevel@tonic-gate ch = (sctp_chunk_hdr_t *)((char *)ch + ch_len + pad); 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate return (sctp_first_chunk((uchar_t *)ch, *remaining)); 3100Sstevel@tonic-gate } 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate /* 3130Sstevel@tonic-gate * Attach ancillary data to a received SCTP segments. 3140Sstevel@tonic-gate * If the source address (fp) is not the primary, send up a 3150Sstevel@tonic-gate * unitdata_ind so recvfrom() can populate the msg_name field. 3160Sstevel@tonic-gate * If ancillary data is also requested, we append it to the 3170Sstevel@tonic-gate * unitdata_req. Otherwise, we just send up an optdata_ind. 3180Sstevel@tonic-gate */ 3190Sstevel@tonic-gate static int 3200Sstevel@tonic-gate sctp_input_add_ancillary(sctp_t *sctp, mblk_t **mp, sctp_data_hdr_t *dcp, 3210Sstevel@tonic-gate sctp_faddr_t *fp, ip6_pkt_t *ipp) 3220Sstevel@tonic-gate { 3230Sstevel@tonic-gate struct T_unitdata_ind *tudi; 3240Sstevel@tonic-gate int optlen; 3250Sstevel@tonic-gate int hdrlen; 3260Sstevel@tonic-gate uchar_t *optptr; 3270Sstevel@tonic-gate struct cmsghdr *cmsg; 3280Sstevel@tonic-gate mblk_t *mp1; 3290Sstevel@tonic-gate struct sockaddr_in6 sin_buf[1]; 3300Sstevel@tonic-gate struct sockaddr_in6 *sin6; 3310Sstevel@tonic-gate struct sockaddr_in *sin4; 3320Sstevel@tonic-gate uint_t addflag = 0; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate sin4 = NULL; 3350Sstevel@tonic-gate sin6 = NULL; 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate optlen = hdrlen = 0; 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate /* Figure out address size */ 3400Sstevel@tonic-gate if (sctp->sctp_ipversion == IPV4_VERSION) { 3410Sstevel@tonic-gate sin4 = (struct sockaddr_in *)sin_buf; 3420Sstevel@tonic-gate sin4->sin_family = AF_INET; 3430Sstevel@tonic-gate sin4->sin_port = sctp->sctp_fport; 3440Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->faddr, sin4->sin_addr.s_addr); 3450Sstevel@tonic-gate hdrlen = sizeof (*tudi) + sizeof (*sin4); 3460Sstevel@tonic-gate } else { 3470Sstevel@tonic-gate sin6 = sin_buf; 3480Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 3490Sstevel@tonic-gate sin6->sin6_port = sctp->sctp_fport; 3500Sstevel@tonic-gate sin6->sin6_addr = fp->faddr; 3510Sstevel@tonic-gate hdrlen = sizeof (*tudi) + sizeof (*sin6); 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate /* If app asked to receive send / recv info */ 3550Sstevel@tonic-gate if (sctp->sctp_recvsndrcvinfo) { 3560Sstevel@tonic-gate optlen += sizeof (*cmsg) + sizeof (struct sctp_sndrcvinfo); 3570Sstevel@tonic-gate if (hdrlen == 0) 3580Sstevel@tonic-gate hdrlen = sizeof (struct T_optdata_ind); 3590Sstevel@tonic-gate } 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate if (sctp->sctp_ipv6_recvancillary == 0) 3620Sstevel@tonic-gate goto noancillary; 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate if ((ipp->ipp_fields & IPPF_IFINDEX) && 3650Sstevel@tonic-gate ipp->ipp_ifindex != sctp->sctp_recvifindex && 3660Sstevel@tonic-gate (sctp->sctp_ipv6_recvancillary & SCTP_IPV6_RECVPKTINFO)) { 3670Sstevel@tonic-gate optlen += sizeof (*cmsg) + sizeof (struct in6_pktinfo); 3680Sstevel@tonic-gate if (hdrlen == 0) 3690Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 3700Sstevel@tonic-gate addflag |= SCTP_IPV6_RECVPKTINFO; 3710Sstevel@tonic-gate } 3720Sstevel@tonic-gate /* If app asked for hoplimit and it has changed ... */ 3730Sstevel@tonic-gate if ((ipp->ipp_fields & IPPF_HOPLIMIT) && 3740Sstevel@tonic-gate ipp->ipp_hoplimit != sctp->sctp_recvhops && 3750Sstevel@tonic-gate (sctp->sctp_ipv6_recvancillary & SCTP_IPV6_RECVHOPLIMIT)) { 3760Sstevel@tonic-gate optlen += sizeof (*cmsg) + sizeof (uint_t); 3770Sstevel@tonic-gate if (hdrlen == 0) 3780Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 3790Sstevel@tonic-gate addflag |= SCTP_IPV6_RECVHOPLIMIT; 3800Sstevel@tonic-gate } 3810Sstevel@tonic-gate /* If app asked for hopbyhop headers and it has changed ... */ 3820Sstevel@tonic-gate if ((sctp->sctp_ipv6_recvancillary & SCTP_IPV6_RECVHOPOPTS) && 3831676Sjpk ip_cmpbuf(sctp->sctp_hopopts, sctp->sctp_hopoptslen, 3844964Skcpoon (ipp->ipp_fields & IPPF_HOPOPTS), 3854964Skcpoon ipp->ipp_hopopts, ipp->ipp_hopoptslen)) { 3861676Sjpk optlen += sizeof (*cmsg) + ipp->ipp_hopoptslen - 3871676Sjpk sctp->sctp_v6label_len; 3880Sstevel@tonic-gate if (hdrlen == 0) 3890Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 3900Sstevel@tonic-gate addflag |= SCTP_IPV6_RECVHOPOPTS; 3911676Sjpk if (!ip_allocbuf((void **)&sctp->sctp_hopopts, 3920Sstevel@tonic-gate &sctp->sctp_hopoptslen, 3930Sstevel@tonic-gate (ipp->ipp_fields & IPPF_HOPOPTS), 3940Sstevel@tonic-gate ipp->ipp_hopopts, ipp->ipp_hopoptslen)) 3950Sstevel@tonic-gate return (-1); 3960Sstevel@tonic-gate } 3970Sstevel@tonic-gate /* If app asked for dst headers before routing headers ... */ 3980Sstevel@tonic-gate if ((sctp->sctp_ipv6_recvancillary & SCTP_IPV6_RECVRTDSTOPTS) && 3991676Sjpk ip_cmpbuf(sctp->sctp_rtdstopts, sctp->sctp_rtdstoptslen, 4004964Skcpoon (ipp->ipp_fields & IPPF_RTDSTOPTS), 4014964Skcpoon ipp->ipp_rtdstopts, ipp->ipp_rtdstoptslen)) { 4020Sstevel@tonic-gate optlen += sizeof (*cmsg) + ipp->ipp_rtdstoptslen; 4030Sstevel@tonic-gate if (hdrlen == 0) 4040Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 4050Sstevel@tonic-gate addflag |= SCTP_IPV6_RECVRTDSTOPTS; 4061676Sjpk if (!ip_allocbuf((void **)&sctp->sctp_rtdstopts, 4070Sstevel@tonic-gate &sctp->sctp_rtdstoptslen, 4080Sstevel@tonic-gate (ipp->ipp_fields & IPPF_RTDSTOPTS), 4090Sstevel@tonic-gate ipp->ipp_rtdstopts, ipp->ipp_rtdstoptslen)) 4100Sstevel@tonic-gate return (-1); 4110Sstevel@tonic-gate } 4120Sstevel@tonic-gate /* If app asked for routing headers and it has changed ... */ 4130Sstevel@tonic-gate if (sctp->sctp_ipv6_recvancillary & SCTP_IPV6_RECVRTHDR) { 4141676Sjpk if (ip_cmpbuf(sctp->sctp_rthdr, sctp->sctp_rthdrlen, 4150Sstevel@tonic-gate (ipp->ipp_fields & IPPF_RTHDR), 4160Sstevel@tonic-gate ipp->ipp_rthdr, ipp->ipp_rthdrlen)) { 4170Sstevel@tonic-gate optlen += sizeof (*cmsg) + ipp->ipp_rthdrlen; 4180Sstevel@tonic-gate if (hdrlen == 0) 4190Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 4200Sstevel@tonic-gate addflag |= SCTP_IPV6_RECVRTHDR; 4211676Sjpk if (!ip_allocbuf((void **)&sctp->sctp_rthdr, 4220Sstevel@tonic-gate &sctp->sctp_rthdrlen, 4230Sstevel@tonic-gate (ipp->ipp_fields & IPPF_RTHDR), 4240Sstevel@tonic-gate ipp->ipp_rthdr, ipp->ipp_rthdrlen)) 4250Sstevel@tonic-gate return (-1); 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate /* If app asked for dest headers and it has changed ... */ 4290Sstevel@tonic-gate if ((sctp->sctp_ipv6_recvancillary & SCTP_IPV6_RECVDSTOPTS) && 4301676Sjpk ip_cmpbuf(sctp->sctp_dstopts, sctp->sctp_dstoptslen, 4314964Skcpoon (ipp->ipp_fields & IPPF_DSTOPTS), 4324964Skcpoon ipp->ipp_dstopts, ipp->ipp_dstoptslen)) { 4330Sstevel@tonic-gate optlen += sizeof (*cmsg) + ipp->ipp_dstoptslen; 4340Sstevel@tonic-gate if (hdrlen == 0) 4350Sstevel@tonic-gate hdrlen = sizeof (struct T_unitdata_ind); 4360Sstevel@tonic-gate addflag |= SCTP_IPV6_RECVDSTOPTS; 4371676Sjpk if (!ip_allocbuf((void **)&sctp->sctp_dstopts, 4380Sstevel@tonic-gate &sctp->sctp_dstoptslen, 4390Sstevel@tonic-gate (ipp->ipp_fields & IPPF_DSTOPTS), 4400Sstevel@tonic-gate ipp->ipp_dstopts, ipp->ipp_dstoptslen)) 4410Sstevel@tonic-gate return (-1); 4420Sstevel@tonic-gate } 4430Sstevel@tonic-gate noancillary: 4440Sstevel@tonic-gate /* Nothing to add */ 4450Sstevel@tonic-gate if (hdrlen == 0) 4460Sstevel@tonic-gate return (-1); 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate mp1 = allocb(hdrlen + optlen + sizeof (void *), BPRI_MED); 4490Sstevel@tonic-gate if (mp1 == NULL) 4500Sstevel@tonic-gate return (-1); 4510Sstevel@tonic-gate mp1->b_cont = *mp; 4520Sstevel@tonic-gate *mp = mp1; 4530Sstevel@tonic-gate mp1->b_rptr += sizeof (void *); /* pointer worth of padding */ 4540Sstevel@tonic-gate mp1->b_wptr = mp1->b_rptr + hdrlen + optlen; 4550Sstevel@tonic-gate DB_TYPE(mp1) = M_PROTO; 4560Sstevel@tonic-gate tudi = (struct T_unitdata_ind *)mp1->b_rptr; 4570Sstevel@tonic-gate tudi->PRIM_type = T_UNITDATA_IND; 4580Sstevel@tonic-gate tudi->SRC_length = sin4 ? sizeof (*sin4) : sizeof (*sin6); 4590Sstevel@tonic-gate tudi->SRC_offset = sizeof (*tudi); 4600Sstevel@tonic-gate tudi->OPT_offset = sizeof (*tudi) + tudi->SRC_length; 4610Sstevel@tonic-gate tudi->OPT_length = optlen; 4620Sstevel@tonic-gate if (sin4) { 4630Sstevel@tonic-gate bcopy(sin4, tudi + 1, sizeof (*sin4)); 4640Sstevel@tonic-gate } else { 4650Sstevel@tonic-gate bcopy(sin6, tudi + 1, sizeof (*sin6)); 4660Sstevel@tonic-gate } 4670Sstevel@tonic-gate optptr = (uchar_t *)tudi + tudi->OPT_offset; 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate if (sctp->sctp_recvsndrcvinfo) { 4700Sstevel@tonic-gate /* XXX need backout method if memory allocation fails. */ 4710Sstevel@tonic-gate struct sctp_sndrcvinfo *sri; 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 4740Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_SCTP; 4750Sstevel@tonic-gate cmsg->cmsg_type = SCTP_SNDRCV; 4760Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + sizeof (*sri); 4770Sstevel@tonic-gate optptr += sizeof (*cmsg); 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate sri = (struct sctp_sndrcvinfo *)(cmsg + 1); 4800Sstevel@tonic-gate ASSERT(OK_32PTR(sri)); 4810Sstevel@tonic-gate sri->sinfo_stream = ntohs(dcp->sdh_sid); 4820Sstevel@tonic-gate sri->sinfo_ssn = ntohs(dcp->sdh_ssn); 4830Sstevel@tonic-gate if (SCTP_DATA_GET_UBIT(dcp)) { 4840Sstevel@tonic-gate sri->sinfo_flags = MSG_UNORDERED; 4850Sstevel@tonic-gate } else { 4860Sstevel@tonic-gate sri->sinfo_flags = 0; 4870Sstevel@tonic-gate } 4880Sstevel@tonic-gate sri->sinfo_ppid = dcp->sdh_payload_id; 4890Sstevel@tonic-gate sri->sinfo_context = 0; 4900Sstevel@tonic-gate sri->sinfo_timetolive = 0; 4910Sstevel@tonic-gate sri->sinfo_tsn = ntohl(dcp->sdh_tsn); 4920Sstevel@tonic-gate sri->sinfo_cumtsn = sctp->sctp_ftsn; 4930Sstevel@tonic-gate sri->sinfo_assoc_id = 0; 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate optptr += sizeof (*sri); 4960Sstevel@tonic-gate } 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate /* 4990Sstevel@tonic-gate * If app asked for pktinfo and the index has changed ... 5000Sstevel@tonic-gate * Note that the local address never changes for the connection. 5010Sstevel@tonic-gate */ 5020Sstevel@tonic-gate if (addflag & SCTP_IPV6_RECVPKTINFO) { 5030Sstevel@tonic-gate struct in6_pktinfo *pkti; 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5060Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5070Sstevel@tonic-gate cmsg->cmsg_type = IPV6_PKTINFO; 5080Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + sizeof (*pkti); 5090Sstevel@tonic-gate optptr += sizeof (*cmsg); 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate pkti = (struct in6_pktinfo *)optptr; 5120Sstevel@tonic-gate if (sctp->sctp_ipversion == IPV6_VERSION) 5130Sstevel@tonic-gate pkti->ipi6_addr = sctp->sctp_ip6h->ip6_src; 5140Sstevel@tonic-gate else 5150Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(sctp->sctp_ipha->ipha_src, 5160Sstevel@tonic-gate &pkti->ipi6_addr); 5170Sstevel@tonic-gate pkti->ipi6_ifindex = ipp->ipp_ifindex; 5180Sstevel@tonic-gate optptr += sizeof (*pkti); 5190Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5200Sstevel@tonic-gate /* Save as "last" value */ 5210Sstevel@tonic-gate sctp->sctp_recvifindex = ipp->ipp_ifindex; 5220Sstevel@tonic-gate } 5230Sstevel@tonic-gate /* If app asked for hoplimit and it has changed ... */ 5240Sstevel@tonic-gate if (addflag & SCTP_IPV6_RECVHOPLIMIT) { 5250Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5260Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5270Sstevel@tonic-gate cmsg->cmsg_type = IPV6_HOPLIMIT; 5280Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + sizeof (uint_t); 5290Sstevel@tonic-gate optptr += sizeof (*cmsg); 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate *(uint_t *)optptr = ipp->ipp_hoplimit; 5320Sstevel@tonic-gate optptr += sizeof (uint_t); 5330Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5340Sstevel@tonic-gate /* Save as "last" value */ 5350Sstevel@tonic-gate sctp->sctp_recvhops = ipp->ipp_hoplimit; 5360Sstevel@tonic-gate } 5370Sstevel@tonic-gate if (addflag & SCTP_IPV6_RECVHOPOPTS) { 5380Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5390Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5400Sstevel@tonic-gate cmsg->cmsg_type = IPV6_HOPOPTS; 5410Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + ipp->ipp_hopoptslen; 5420Sstevel@tonic-gate optptr += sizeof (*cmsg); 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate bcopy(ipp->ipp_hopopts, optptr, ipp->ipp_hopoptslen); 5450Sstevel@tonic-gate optptr += ipp->ipp_hopoptslen; 5460Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5470Sstevel@tonic-gate /* Save as last value */ 5481676Sjpk ip_savebuf((void **)&sctp->sctp_hopopts, 5490Sstevel@tonic-gate &sctp->sctp_hopoptslen, 5500Sstevel@tonic-gate (ipp->ipp_fields & IPPF_HOPOPTS), 5510Sstevel@tonic-gate ipp->ipp_hopopts, ipp->ipp_hopoptslen); 5520Sstevel@tonic-gate } 5530Sstevel@tonic-gate if (addflag & SCTP_IPV6_RECVRTDSTOPTS) { 5540Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5550Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5560Sstevel@tonic-gate cmsg->cmsg_type = IPV6_RTHDRDSTOPTS; 5570Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + ipp->ipp_rtdstoptslen; 5580Sstevel@tonic-gate optptr += sizeof (*cmsg); 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate bcopy(ipp->ipp_rtdstopts, optptr, ipp->ipp_rtdstoptslen); 5610Sstevel@tonic-gate optptr += ipp->ipp_rtdstoptslen; 5620Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5630Sstevel@tonic-gate /* Save as last value */ 5641676Sjpk ip_savebuf((void **)&sctp->sctp_rtdstopts, 5650Sstevel@tonic-gate &sctp->sctp_rtdstoptslen, 5660Sstevel@tonic-gate (ipp->ipp_fields & IPPF_RTDSTOPTS), 5670Sstevel@tonic-gate ipp->ipp_rtdstopts, ipp->ipp_rtdstoptslen); 5680Sstevel@tonic-gate } 5690Sstevel@tonic-gate if (addflag & SCTP_IPV6_RECVRTHDR) { 5700Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5710Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5720Sstevel@tonic-gate cmsg->cmsg_type = IPV6_RTHDR; 5730Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + ipp->ipp_rthdrlen; 5740Sstevel@tonic-gate optptr += sizeof (*cmsg); 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate bcopy(ipp->ipp_rthdr, optptr, ipp->ipp_rthdrlen); 5770Sstevel@tonic-gate optptr += ipp->ipp_rthdrlen; 5780Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5790Sstevel@tonic-gate /* Save as last value */ 5801676Sjpk ip_savebuf((void **)&sctp->sctp_rthdr, 5810Sstevel@tonic-gate &sctp->sctp_rthdrlen, 5820Sstevel@tonic-gate (ipp->ipp_fields & IPPF_RTHDR), 5830Sstevel@tonic-gate ipp->ipp_rthdr, ipp->ipp_rthdrlen); 5840Sstevel@tonic-gate } 5850Sstevel@tonic-gate if (addflag & SCTP_IPV6_RECVDSTOPTS) { 5860Sstevel@tonic-gate cmsg = (struct cmsghdr *)optptr; 5870Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_IPV6; 5880Sstevel@tonic-gate cmsg->cmsg_type = IPV6_DSTOPTS; 5890Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + ipp->ipp_dstoptslen; 5900Sstevel@tonic-gate optptr += sizeof (*cmsg); 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate bcopy(ipp->ipp_dstopts, optptr, ipp->ipp_dstoptslen); 5930Sstevel@tonic-gate optptr += ipp->ipp_dstoptslen; 5940Sstevel@tonic-gate ASSERT(OK_32PTR(optptr)); 5950Sstevel@tonic-gate /* Save as last value */ 5961676Sjpk ip_savebuf((void **)&sctp->sctp_dstopts, 5970Sstevel@tonic-gate &sctp->sctp_dstoptslen, 5980Sstevel@tonic-gate (ipp->ipp_fields & IPPF_DSTOPTS), 5990Sstevel@tonic-gate ipp->ipp_dstopts, ipp->ipp_dstoptslen); 6000Sstevel@tonic-gate } 6010Sstevel@tonic-gate 6020Sstevel@tonic-gate ASSERT(optptr == mp1->b_wptr); 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate return (0); 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate void 6080Sstevel@tonic-gate sctp_free_reass(sctp_instr_t *sip) 6090Sstevel@tonic-gate { 6100Sstevel@tonic-gate mblk_t *mp, *mpnext, *mctl; 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate for (mp = sip->istr_reass; mp != NULL; mp = mpnext) { 6130Sstevel@tonic-gate mpnext = mp->b_next; 6140Sstevel@tonic-gate mp->b_next = NULL; 6150Sstevel@tonic-gate mp->b_prev = NULL; 6160Sstevel@tonic-gate if (DB_TYPE(mp) == M_CTL) { 6170Sstevel@tonic-gate mctl = mp; 6180Sstevel@tonic-gate ASSERT(mp->b_cont != NULL); 6190Sstevel@tonic-gate mp = mp->b_cont; 6200Sstevel@tonic-gate mctl->b_cont = NULL; 6210Sstevel@tonic-gate freeb(mctl); 6220Sstevel@tonic-gate } 6230Sstevel@tonic-gate freemsg(mp); 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate /* 6280Sstevel@tonic-gate * If the series of data fragments of which dmp is a part is successfully 6290Sstevel@tonic-gate * reassembled, the first mblk in the series is returned. dc is adjusted 6300Sstevel@tonic-gate * to point at the data chunk in the lead mblk, and b_rptr also points to 6310Sstevel@tonic-gate * the data chunk; the following mblk's b_rptr's point at the actual payload. 6320Sstevel@tonic-gate * 6330Sstevel@tonic-gate * If the series is not yet reassembled, NULL is returned. dc is not changed. 6340Sstevel@tonic-gate * XXX should probably move this up into the state machine. 6350Sstevel@tonic-gate */ 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate /* Fragment list for un-ordered messages. Partial delivery is not supported */ 6380Sstevel@tonic-gate static mblk_t * 6390Sstevel@tonic-gate sctp_uodata_frag(sctp_t *sctp, mblk_t *dmp, sctp_data_hdr_t **dc) 6400Sstevel@tonic-gate { 6410Sstevel@tonic-gate mblk_t *hmp; 6420Sstevel@tonic-gate mblk_t *begin = NULL; 6430Sstevel@tonic-gate mblk_t *end = NULL; 6440Sstevel@tonic-gate sctp_data_hdr_t *qdc; 6450Sstevel@tonic-gate uint32_t ntsn; 6460Sstevel@tonic-gate uint32_t tsn = ntohl((*dc)->sdh_tsn); 6470Sstevel@tonic-gate #ifdef DEBUG 6480Sstevel@tonic-gate mblk_t *mp1; 6490Sstevel@tonic-gate #endif 6500Sstevel@tonic-gate 6510Sstevel@tonic-gate /* First frag. */ 6520Sstevel@tonic-gate if (sctp->sctp_uo_frags == NULL) { 6530Sstevel@tonic-gate sctp->sctp_uo_frags = dmp; 6540Sstevel@tonic-gate return (NULL); 6550Sstevel@tonic-gate } 6560Sstevel@tonic-gate hmp = sctp->sctp_uo_frags; 6570Sstevel@tonic-gate /* 6580Sstevel@tonic-gate * Insert the segment according to the TSN, fragmented unordered 6590Sstevel@tonic-gate * chunks are sequenced by TSN. 6600Sstevel@tonic-gate */ 6610Sstevel@tonic-gate while (hmp != NULL) { 6620Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)hmp->b_rptr; 6630Sstevel@tonic-gate ntsn = ntohl(qdc->sdh_tsn); 6640Sstevel@tonic-gate if (SEQ_GT(ntsn, tsn)) { 6650Sstevel@tonic-gate if (hmp->b_prev == NULL) { 6660Sstevel@tonic-gate dmp->b_next = hmp; 6670Sstevel@tonic-gate hmp->b_prev = dmp; 6680Sstevel@tonic-gate sctp->sctp_uo_frags = dmp; 6690Sstevel@tonic-gate } else { 6700Sstevel@tonic-gate dmp->b_next = hmp; 6710Sstevel@tonic-gate dmp->b_prev = hmp->b_prev; 6720Sstevel@tonic-gate hmp->b_prev->b_next = dmp; 6730Sstevel@tonic-gate hmp->b_prev = dmp; 6740Sstevel@tonic-gate } 6750Sstevel@tonic-gate break; 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate if (hmp->b_next == NULL) { 6780Sstevel@tonic-gate hmp->b_next = dmp; 6790Sstevel@tonic-gate dmp->b_prev = hmp; 6800Sstevel@tonic-gate break; 6810Sstevel@tonic-gate } 6820Sstevel@tonic-gate hmp = hmp->b_next; 6830Sstevel@tonic-gate } 6840Sstevel@tonic-gate /* check if we completed a msg */ 6850Sstevel@tonic-gate if (SCTP_DATA_GET_BBIT(*dc)) { 6860Sstevel@tonic-gate begin = dmp; 6870Sstevel@tonic-gate } else if (SCTP_DATA_GET_EBIT(*dc)) { 6880Sstevel@tonic-gate end = dmp; 6890Sstevel@tonic-gate } 6900Sstevel@tonic-gate /* 6910Sstevel@tonic-gate * We walk consecutive TSNs backwards till we get a seg. with 6920Sstevel@tonic-gate * the B bit 6930Sstevel@tonic-gate */ 6940Sstevel@tonic-gate if (begin == NULL) { 6950Sstevel@tonic-gate for (hmp = dmp->b_prev; hmp != NULL; hmp = hmp->b_prev) { 6960Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)hmp->b_rptr; 6970Sstevel@tonic-gate ntsn = ntohl(qdc->sdh_tsn); 6980Sstevel@tonic-gate if ((int32_t)(tsn - ntsn) > 1) { 6990Sstevel@tonic-gate return (NULL); 7000Sstevel@tonic-gate } 7010Sstevel@tonic-gate if (SCTP_DATA_GET_BBIT(qdc)) { 7020Sstevel@tonic-gate begin = hmp; 7030Sstevel@tonic-gate break; 7040Sstevel@tonic-gate } 7050Sstevel@tonic-gate tsn = ntsn; 7060Sstevel@tonic-gate } 7070Sstevel@tonic-gate } 7080Sstevel@tonic-gate tsn = ntohl((*dc)->sdh_tsn); 7090Sstevel@tonic-gate /* 7100Sstevel@tonic-gate * We walk consecutive TSNs till we get a seg. with the E bit 7110Sstevel@tonic-gate */ 7120Sstevel@tonic-gate if (end == NULL) { 7130Sstevel@tonic-gate for (hmp = dmp->b_next; hmp != NULL; hmp = hmp->b_next) { 7140Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)hmp->b_rptr; 7150Sstevel@tonic-gate ntsn = ntohl(qdc->sdh_tsn); 7160Sstevel@tonic-gate if ((int32_t)(ntsn - tsn) > 1) { 7170Sstevel@tonic-gate return (NULL); 7180Sstevel@tonic-gate } 7190Sstevel@tonic-gate if (SCTP_DATA_GET_EBIT(qdc)) { 7200Sstevel@tonic-gate end = hmp; 7210Sstevel@tonic-gate break; 7220Sstevel@tonic-gate } 7230Sstevel@tonic-gate tsn = ntsn; 7240Sstevel@tonic-gate } 7250Sstevel@tonic-gate } 7260Sstevel@tonic-gate if (begin == NULL || end == NULL) { 7270Sstevel@tonic-gate return (NULL); 7280Sstevel@tonic-gate } 7290Sstevel@tonic-gate /* Got one!, Remove the msg from the list */ 7300Sstevel@tonic-gate if (sctp->sctp_uo_frags == begin) { 7310Sstevel@tonic-gate ASSERT(begin->b_prev == NULL); 7320Sstevel@tonic-gate sctp->sctp_uo_frags = end->b_next; 7330Sstevel@tonic-gate if (end->b_next != NULL) 7340Sstevel@tonic-gate end->b_next->b_prev = NULL; 7350Sstevel@tonic-gate } else { 7360Sstevel@tonic-gate begin->b_prev->b_next = end->b_next; 7370Sstevel@tonic-gate if (end->b_next != NULL) 7380Sstevel@tonic-gate end->b_next->b_prev = begin->b_prev; 7390Sstevel@tonic-gate } 7400Sstevel@tonic-gate begin->b_prev = NULL; 7410Sstevel@tonic-gate end->b_next = NULL; 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate /* 7440Sstevel@tonic-gate * Null out b_next and b_prev and chain using b_cont. 7450Sstevel@tonic-gate */ 7460Sstevel@tonic-gate dmp = end = begin; 7470Sstevel@tonic-gate hmp = begin->b_next; 7480Sstevel@tonic-gate *dc = (sctp_data_hdr_t *)begin->b_rptr; 7490Sstevel@tonic-gate begin->b_next = NULL; 7500Sstevel@tonic-gate while (hmp != NULL) { 7510Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)hmp->b_rptr; 7520Sstevel@tonic-gate hmp->b_rptr = (uchar_t *)(qdc + 1); 7530Sstevel@tonic-gate end = hmp->b_next; 7540Sstevel@tonic-gate dmp->b_cont = hmp; 7550Sstevel@tonic-gate dmp = hmp; 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate if (end != NULL) 7580Sstevel@tonic-gate hmp->b_next = NULL; 7590Sstevel@tonic-gate hmp->b_prev = NULL; 7600Sstevel@tonic-gate hmp = end; 7610Sstevel@tonic-gate } 7620Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_reassmsgs); 7630Sstevel@tonic-gate #ifdef DEBUG 7640Sstevel@tonic-gate mp1 = begin; 7650Sstevel@tonic-gate while (mp1 != NULL) { 7660Sstevel@tonic-gate ASSERT(mp1->b_next == NULL); 7670Sstevel@tonic-gate ASSERT(mp1->b_prev == NULL); 7680Sstevel@tonic-gate mp1 = mp1->b_cont; 7690Sstevel@tonic-gate } 7700Sstevel@tonic-gate #endif 7710Sstevel@tonic-gate return (begin); 7720Sstevel@tonic-gate } 7733845Svi117747 7743845Svi117747 /* 7753845Svi117747 * Try partial delivery. 7763845Svi117747 */ 7773845Svi117747 static mblk_t * 7783845Svi117747 sctp_try_partial_delivery(sctp_t *sctp, mblk_t *hmp, sctp_reass_t *srp, 7793845Svi117747 sctp_data_hdr_t **dc) 7803845Svi117747 { 7813845Svi117747 mblk_t *first_mp; 7823845Svi117747 mblk_t *mp; 7833845Svi117747 mblk_t *dmp; 7843845Svi117747 mblk_t *qmp; 7853845Svi117747 mblk_t *prev; 7863845Svi117747 sctp_data_hdr_t *qdc; 7873845Svi117747 uint32_t tsn; 7883845Svi117747 7893845Svi117747 ASSERT(DB_TYPE(hmp) == M_CTL); 7903845Svi117747 7913845Svi117747 dprint(4, ("trypartial: got=%d, needed=%d\n", 7923845Svi117747 (int)(srp->got), (int)(srp->needed))); 7933845Svi117747 7943845Svi117747 first_mp = hmp->b_cont; 7953845Svi117747 mp = first_mp; 7963845Svi117747 qdc = (sctp_data_hdr_t *)mp->b_rptr; 7973845Svi117747 7983845Svi117747 ASSERT(SCTP_DATA_GET_BBIT(qdc) && srp->hasBchunk); 7993845Svi117747 8003845Svi117747 tsn = ntohl(qdc->sdh_tsn) + 1; 8013845Svi117747 8023845Svi117747 /* 8033845Svi117747 * This loop has two exit conditions: the 8043845Svi117747 * end of received chunks has been reached, or 8053845Svi117747 * there is a break in the sequence. We want 8063845Svi117747 * to chop the reassembly list as follows (the 8073845Svi117747 * numbers are TSNs): 8083845Svi117747 * 10 -> 11 -> (end of chunks) 8093845Svi117747 * 10 -> 11 -> | 13 (break in sequence) 8103845Svi117747 */ 8113845Svi117747 prev = mp; 8123845Svi117747 mp = mp->b_cont; 8133845Svi117747 while (mp != NULL) { 8143845Svi117747 qdc = (sctp_data_hdr_t *)mp->b_rptr; 8153845Svi117747 if (ntohl(qdc->sdh_tsn) != tsn) 8163845Svi117747 break; 8173845Svi117747 prev = mp; 8183845Svi117747 mp = mp->b_cont; 8193845Svi117747 tsn++; 8203845Svi117747 } 8213845Svi117747 /* 8223845Svi117747 * We are sending all the fragments upstream, we have to retain 8233845Svi117747 * the srp info for further fragments. 8243845Svi117747 */ 8253845Svi117747 if (mp == NULL) { 8263845Svi117747 dmp = hmp->b_cont; 8273845Svi117747 hmp->b_cont = NULL; 8283845Svi117747 srp->nexttsn = tsn; 8293845Svi117747 srp->msglen = 0; 8303845Svi117747 srp->needed = 0; 8313845Svi117747 srp->got = 0; 8323845Svi117747 srp->partial_delivered = B_TRUE; 8333845Svi117747 srp->tail = NULL; 8343845Svi117747 } else { 8353845Svi117747 dmp = hmp->b_cont; 8363845Svi117747 hmp->b_cont = mp; 8373845Svi117747 } 8383845Svi117747 srp->hasBchunk = B_FALSE; 8393845Svi117747 /* 8403845Svi117747 * mp now points at the last chunk in the sequence, 8413845Svi117747 * and prev points to mp's previous in the list. 8423845Svi117747 * We chop the list at prev, and convert mp into the 8433845Svi117747 * new list head by setting the B bit. Subsequence 8443845Svi117747 * fragment deliveries will follow the normal reassembly 8453845Svi117747 * path. 8463845Svi117747 */ 8473845Svi117747 prev->b_cont = NULL; 8483845Svi117747 srp->partial_delivered = B_TRUE; 8493845Svi117747 8503845Svi117747 dprint(4, ("trypartial: got some, got=%d, needed=%d\n", 8513845Svi117747 (int)(srp->got), (int)(srp->needed))); 8523845Svi117747 8533845Svi117747 /* 8543845Svi117747 * Adjust all mblk's except the lead so their rptr's point to the 8553845Svi117747 * payload. sctp_data_chunk() will need to process the lead's 8563845Svi117747 * data chunk section, so leave it's rptr pointing at the data chunk. 8573845Svi117747 */ 8583845Svi117747 *dc = (sctp_data_hdr_t *)dmp->b_rptr; 8593845Svi117747 if (srp->tail != NULL) { 8603845Svi117747 srp->got--; 8613845Svi117747 ASSERT(srp->got != 0); 8623845Svi117747 if (srp->needed != 0) { 8633845Svi117747 srp->needed--; 8643845Svi117747 ASSERT(srp->needed != 0); 8653845Svi117747 } 8663845Svi117747 srp->msglen -= ntohs((*dc)->sdh_len); 8673845Svi117747 } 8683845Svi117747 for (qmp = dmp->b_cont; qmp != NULL; qmp = qmp->b_cont) { 8693845Svi117747 qdc = (sctp_data_hdr_t *)qmp->b_rptr; 8703845Svi117747 qmp->b_rptr = (uchar_t *)(qdc + 1); 8713845Svi117747 8723845Svi117747 /* 8733845Svi117747 * Deduct the balance from got and needed here, now that 8743845Svi117747 * we know we are actually delivering these data. 8753845Svi117747 */ 8763845Svi117747 if (srp->tail != NULL) { 8773845Svi117747 srp->got--; 8783845Svi117747 ASSERT(srp->got != 0); 8793845Svi117747 if (srp->needed != 0) { 8803845Svi117747 srp->needed--; 8813845Svi117747 ASSERT(srp->needed != 0); 8823845Svi117747 } 8833845Svi117747 srp->msglen -= ntohs(qdc->sdh_len); 8843845Svi117747 } 8853845Svi117747 } 8863845Svi117747 ASSERT(srp->msglen == 0); 8873845Svi117747 BUMP_LOCAL(sctp->sctp_reassmsgs); 8883845Svi117747 8893845Svi117747 return (dmp); 8903845Svi117747 } 8913845Svi117747 8920Sstevel@tonic-gate /* 8930Sstevel@tonic-gate * Fragment list for ordered messages. 8940Sstevel@tonic-gate * If no error occures, error is set to 0. If we run out of memory, error 8950Sstevel@tonic-gate * is set to 1. If the peer commits a fatal error (like using different 8960Sstevel@tonic-gate * sequence numbers for the same data fragment series), the association is 8973845Svi117747 * aborted and error is set to 2. tpfinished indicates whether we have 8983845Svi117747 * assembled a complete message, this is used in sctp_data_chunk() to 8993845Svi117747 * see if we can try to send any queued message for this stream. 9000Sstevel@tonic-gate */ 9010Sstevel@tonic-gate static mblk_t * 9020Sstevel@tonic-gate sctp_data_frag(sctp_t *sctp, mblk_t *dmp, sctp_data_hdr_t **dc, int *error, 9033845Svi117747 sctp_instr_t *sip, boolean_t *tpfinished) 9040Sstevel@tonic-gate { 9050Sstevel@tonic-gate mblk_t *hmp; 9060Sstevel@tonic-gate mblk_t *pmp; 9070Sstevel@tonic-gate mblk_t *qmp; 9080Sstevel@tonic-gate mblk_t *first_mp; 9090Sstevel@tonic-gate sctp_reass_t *srp; 9100Sstevel@tonic-gate sctp_data_hdr_t *qdc; 9110Sstevel@tonic-gate sctp_data_hdr_t *bdc; 9120Sstevel@tonic-gate sctp_data_hdr_t *edc; 9130Sstevel@tonic-gate uint32_t tsn; 9143845Svi117747 uint16_t fraglen = 0; 9150Sstevel@tonic-gate 9160Sstevel@tonic-gate *error = 0; 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate /* find the reassembly queue for this data chunk */ 9190Sstevel@tonic-gate hmp = qmp = sip->istr_reass; 9200Sstevel@tonic-gate for (; hmp != NULL; hmp = hmp->b_next) { 9210Sstevel@tonic-gate srp = (sctp_reass_t *)DB_BASE(hmp); 9220Sstevel@tonic-gate if (ntohs((*dc)->sdh_ssn) == srp->ssn) 9230Sstevel@tonic-gate goto foundit; 9240Sstevel@tonic-gate else if (SSN_GT(srp->ssn, ntohs((*dc)->sdh_ssn))) 9250Sstevel@tonic-gate break; 9260Sstevel@tonic-gate qmp = hmp; 9270Sstevel@tonic-gate } 9280Sstevel@tonic-gate 9293845Svi117747 /* 9303845Svi117747 * Allocate a M_CTL that will contain information about this 9313845Svi117747 * fragmented message. 9323845Svi117747 */ 9333845Svi117747 if ((pmp = allocb(sizeof (*srp), BPRI_MED)) == NULL) { 9343845Svi117747 *error = 1; 9353845Svi117747 return (NULL); 9363845Svi117747 } 9373845Svi117747 DB_TYPE(pmp) = M_CTL; 9383845Svi117747 srp = (sctp_reass_t *)DB_BASE(pmp); 9393845Svi117747 pmp->b_cont = dmp; 9400Sstevel@tonic-gate 9410Sstevel@tonic-gate if (hmp != NULL) { 9420Sstevel@tonic-gate if (sip->istr_reass == hmp) { 9430Sstevel@tonic-gate sip->istr_reass = pmp; 9440Sstevel@tonic-gate pmp->b_next = hmp; 9450Sstevel@tonic-gate pmp->b_prev = NULL; 9460Sstevel@tonic-gate hmp->b_prev = pmp; 9470Sstevel@tonic-gate } else { 9480Sstevel@tonic-gate qmp->b_next = pmp; 9490Sstevel@tonic-gate pmp->b_prev = qmp; 9500Sstevel@tonic-gate pmp->b_next = hmp; 9510Sstevel@tonic-gate hmp->b_prev = pmp; 9520Sstevel@tonic-gate } 9530Sstevel@tonic-gate } else { 9540Sstevel@tonic-gate /* make a new reass head and stick it on the end */ 9550Sstevel@tonic-gate if (sip->istr_reass == NULL) { 9560Sstevel@tonic-gate sip->istr_reass = pmp; 9570Sstevel@tonic-gate pmp->b_prev = NULL; 9580Sstevel@tonic-gate } else { 9590Sstevel@tonic-gate qmp->b_next = pmp; 9600Sstevel@tonic-gate pmp->b_prev = qmp; 9610Sstevel@tonic-gate } 9620Sstevel@tonic-gate pmp->b_next = NULL; 9630Sstevel@tonic-gate } 9643845Svi117747 srp->partial_delivered = B_FALSE; 9653845Svi117747 srp->ssn = ntohs((*dc)->sdh_ssn); 9663845Svi117747 empty_srp: 9673845Svi117747 srp->needed = 0; 9683845Svi117747 srp->got = 1; 9693845Svi117747 srp->tail = dmp; 9703845Svi117747 if (SCTP_DATA_GET_BBIT(*dc)) { 9713845Svi117747 srp->msglen = ntohs((*dc)->sdh_len); 9723845Svi117747 srp->nexttsn = ntohl((*dc)->sdh_tsn) + 1; 9733845Svi117747 srp->hasBchunk = B_TRUE; 9743845Svi117747 } else if (srp->partial_delivered && 9753845Svi117747 srp->nexttsn == ntohl((*dc)->sdh_tsn)) { 9763845Svi117747 SCTP_DATA_SET_BBIT(*dc); 9773845Svi117747 /* Last fragment */ 9783845Svi117747 if (SCTP_DATA_GET_EBIT(*dc)) { 9793845Svi117747 srp->needed = 1; 9803845Svi117747 goto frag_done; 9813845Svi117747 } 9823845Svi117747 srp->hasBchunk = B_TRUE; 9833845Svi117747 srp->msglen = ntohs((*dc)->sdh_len); 9843845Svi117747 srp->nexttsn++; 9853845Svi117747 } 9860Sstevel@tonic-gate return (NULL); 9870Sstevel@tonic-gate foundit: 9880Sstevel@tonic-gate /* 9890Sstevel@tonic-gate * else already have a reassembly queue. Insert the new data chunk 9900Sstevel@tonic-gate * in the reassemble queue. Try the tail first, on the assumption 9910Sstevel@tonic-gate * that the fragments are coming in in order. 9920Sstevel@tonic-gate */ 9930Sstevel@tonic-gate qmp = srp->tail; 9943845Svi117747 9953845Svi117747 /* 9963845Svi117747 * This means the message was partially delivered. 9973845Svi117747 */ 9983845Svi117747 if (qmp == NULL) { 9993845Svi117747 ASSERT(srp->got == 0 && srp->needed == 0 && 10003845Svi117747 srp->partial_delivered); 10013845Svi117747 ASSERT(hmp->b_cont == NULL); 10023845Svi117747 hmp->b_cont = dmp; 10033845Svi117747 goto empty_srp; 10043845Svi117747 } 10050Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)qmp->b_rptr; 10060Sstevel@tonic-gate ASSERT(qmp->b_cont == NULL); 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate /* XXXIs it fine to do this just here? */ 10090Sstevel@tonic-gate if ((*dc)->sdh_sid != qdc->sdh_sid) { 10100Sstevel@tonic-gate /* our peer is fatally confused; XXX abort the assc */ 10110Sstevel@tonic-gate *error = 2; 10120Sstevel@tonic-gate return (NULL); 10130Sstevel@tonic-gate } 10140Sstevel@tonic-gate if (SEQ_GT(ntohl((*dc)->sdh_tsn), ntohl(qdc->sdh_tsn))) { 10150Sstevel@tonic-gate qmp->b_cont = dmp; 10160Sstevel@tonic-gate srp->tail = dmp; 10170Sstevel@tonic-gate dmp->b_cont = NULL; 10183845Svi117747 if (srp->hasBchunk && srp->nexttsn == ntohl((*dc)->sdh_tsn)) { 10193845Svi117747 srp->msglen += ntohs((*dc)->sdh_len); 10203845Svi117747 srp->nexttsn++; 10213845Svi117747 } 10220Sstevel@tonic-gate goto inserted; 10230Sstevel@tonic-gate } 10240Sstevel@tonic-gate 10250Sstevel@tonic-gate /* Next check for insertion at the beginning */ 10263845Svi117747 qmp = hmp->b_cont; 10270Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)qmp->b_rptr; 10280Sstevel@tonic-gate if (SEQ_LT(ntohl((*dc)->sdh_tsn), ntohl(qdc->sdh_tsn))) { 10293845Svi117747 dmp->b_cont = qmp; 10303845Svi117747 hmp->b_cont = dmp; 10313845Svi117747 if (SCTP_DATA_GET_BBIT(*dc)) { 10323845Svi117747 srp->hasBchunk = B_TRUE; 10333845Svi117747 srp->nexttsn = ntohl((*dc)->sdh_tsn); 10340Sstevel@tonic-gate } 10353845Svi117747 goto preinserted; 10360Sstevel@tonic-gate } 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate /* Insert somewhere in the middle */ 10390Sstevel@tonic-gate for (;;) { 10400Sstevel@tonic-gate /* Tail check above should have caught this */ 10410Sstevel@tonic-gate ASSERT(qmp->b_cont != NULL); 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)qmp->b_cont->b_rptr; 10440Sstevel@tonic-gate if (SEQ_LT(ntohl((*dc)->sdh_tsn), ntohl(qdc->sdh_tsn))) { 10450Sstevel@tonic-gate /* insert here */ 10460Sstevel@tonic-gate dmp->b_cont = qmp->b_cont; 10470Sstevel@tonic-gate qmp->b_cont = dmp; 10480Sstevel@tonic-gate break; 10490Sstevel@tonic-gate } 10500Sstevel@tonic-gate qmp = qmp->b_cont; 10510Sstevel@tonic-gate } 10523845Svi117747 preinserted: 10533845Svi117747 if (!srp->hasBchunk || ntohl((*dc)->sdh_tsn) != srp->nexttsn) 10543845Svi117747 goto inserted; 10553845Svi117747 /* 10563845Svi117747 * fraglen contains the length of consecutive chunks of fragments. 10573845Svi117747 * starting from the chunk inserted recently. 10583845Svi117747 */ 10593845Svi117747 tsn = srp->nexttsn; 10603845Svi117747 for (qmp = dmp; qmp != NULL; qmp = qmp->b_cont) { 10613845Svi117747 qdc = (sctp_data_hdr_t *)qmp->b_rptr; 10623845Svi117747 if (tsn != ntohl(qdc->sdh_tsn)) 10633845Svi117747 break; 10643845Svi117747 fraglen += ntohs(qdc->sdh_len); 10653845Svi117747 tsn++; 10663845Svi117747 } 10673845Svi117747 srp->nexttsn = tsn; 10683845Svi117747 srp->msglen += fraglen; 10690Sstevel@tonic-gate inserted: 10703845Svi117747 srp->got++; 10713845Svi117747 first_mp = hmp->b_cont; 10720Sstevel@tonic-gate if (srp->needed == 0) { 10730Sstevel@tonic-gate /* check if we have the first and last fragments */ 10740Sstevel@tonic-gate bdc = (sctp_data_hdr_t *)first_mp->b_rptr; 10750Sstevel@tonic-gate edc = (sctp_data_hdr_t *)srp->tail->b_rptr; 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate /* calculate how many fragments are needed, if possible */ 10783845Svi117747 if (SCTP_DATA_GET_BBIT(bdc) && SCTP_DATA_GET_EBIT(edc)) { 10790Sstevel@tonic-gate srp->needed = ntohl(edc->sdh_tsn) - 10800Sstevel@tonic-gate ntohl(bdc->sdh_tsn) + 1; 10810Sstevel@tonic-gate } 10823845Svi117747 } 10833845Svi117747 10843845Svi117747 /* 10853845Svi117747 * Try partial delivery if the message length has exceeded the 10863845Svi117747 * partial delivery point. Only do this if we can immediately 10873845Svi117747 * deliver the partially assembled message, and only partially 10883845Svi117747 * deliver one message at a time (i.e. messages cannot be 10893845Svi117747 * intermixed arriving at the upper layer). A simple way to 10903845Svi117747 * enforce this is to only try partial delivery if this TSN is 10913845Svi117747 * the next expected TSN. Partial Delivery not supported 10923845Svi117747 * for un-ordered message. 10933845Svi117747 */ 10943845Svi117747 if (srp->needed != srp->got) { 10953845Svi117747 dmp = NULL; 10963845Svi117747 if (ntohl((*dc)->sdh_tsn) == sctp->sctp_ftsn && 10973845Svi117747 srp->msglen >= sctp->sctp_pd_point) { 10983845Svi117747 dmp = sctp_try_partial_delivery(sctp, hmp, srp, dc); 10993845Svi117747 *tpfinished = B_FALSE; 11000Sstevel@tonic-gate } 11013845Svi117747 return (dmp); 11020Sstevel@tonic-gate } 11033845Svi117747 frag_done: 11040Sstevel@tonic-gate /* 11050Sstevel@tonic-gate * else reassembly done; prepare the data for delivery. 11060Sstevel@tonic-gate * First unlink hmp from the ssn list. 11070Sstevel@tonic-gate */ 11080Sstevel@tonic-gate if (sip->istr_reass == hmp) { 11090Sstevel@tonic-gate sip->istr_reass = hmp->b_next; 11103845Svi117747 if (hmp->b_next) 11110Sstevel@tonic-gate hmp->b_next->b_prev = NULL; 11120Sstevel@tonic-gate } else { 11130Sstevel@tonic-gate ASSERT(hmp->b_prev != NULL); 11140Sstevel@tonic-gate hmp->b_prev->b_next = hmp->b_next; 11153845Svi117747 if (hmp->b_next) 11160Sstevel@tonic-gate hmp->b_next->b_prev = hmp->b_prev; 11170Sstevel@tonic-gate } 11180Sstevel@tonic-gate 11190Sstevel@tonic-gate /* 11200Sstevel@tonic-gate * Using b_prev and b_next was a little sinful, but OK since 11210Sstevel@tonic-gate * this mblk is never put*'d. However, freeb() will still 11220Sstevel@tonic-gate * ASSERT that they are unused, so we need to NULL them out now. 11230Sstevel@tonic-gate */ 11240Sstevel@tonic-gate hmp->b_next = NULL; 11250Sstevel@tonic-gate hmp->b_prev = NULL; 11260Sstevel@tonic-gate dmp = hmp; 11273845Svi117747 dmp = dmp->b_cont; 11283845Svi117747 hmp->b_cont = NULL; 11293845Svi117747 freeb(hmp); 11303845Svi117747 *tpfinished = B_TRUE; 11313845Svi117747 11320Sstevel@tonic-gate /* 11330Sstevel@tonic-gate * Adjust all mblk's except the lead so their rptr's point to the 11340Sstevel@tonic-gate * payload. sctp_data_chunk() will need to process the lead's 11350Sstevel@tonic-gate * data chunk section, so leave it's rptr pointing at the data chunk. 11360Sstevel@tonic-gate */ 11370Sstevel@tonic-gate *dc = (sctp_data_hdr_t *)dmp->b_rptr; 11383845Svi117747 for (qmp = dmp->b_cont; qmp != NULL; qmp = qmp->b_cont) { 11390Sstevel@tonic-gate qdc = (sctp_data_hdr_t *)qmp->b_rptr; 11400Sstevel@tonic-gate qmp->b_rptr = (uchar_t *)(qdc + 1); 11410Sstevel@tonic-gate } 11420Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_reassmsgs); 11430Sstevel@tonic-gate 11440Sstevel@tonic-gate return (dmp); 11450Sstevel@tonic-gate } 11460Sstevel@tonic-gate static void 11470Sstevel@tonic-gate sctp_add_dup(uint32_t tsn, mblk_t **dups) 11480Sstevel@tonic-gate { 11490Sstevel@tonic-gate mblk_t *mp; 11500Sstevel@tonic-gate size_t bsize = SCTP_DUP_MBLK_SZ * sizeof (tsn); 11510Sstevel@tonic-gate 11520Sstevel@tonic-gate if (dups == NULL) { 11530Sstevel@tonic-gate return; 11540Sstevel@tonic-gate } 11550Sstevel@tonic-gate 11560Sstevel@tonic-gate /* first time? */ 11570Sstevel@tonic-gate if (*dups == NULL) { 11580Sstevel@tonic-gate *dups = allocb(bsize, BPRI_MED); 11590Sstevel@tonic-gate if (*dups == NULL) { 11600Sstevel@tonic-gate return; 11610Sstevel@tonic-gate } 11620Sstevel@tonic-gate } 11630Sstevel@tonic-gate 11640Sstevel@tonic-gate mp = *dups; 11650Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr) >= bsize) { 11660Sstevel@tonic-gate /* maximum reached */ 11670Sstevel@tonic-gate return; 11680Sstevel@tonic-gate } 11690Sstevel@tonic-gate 11700Sstevel@tonic-gate /* add the duplicate tsn */ 11710Sstevel@tonic-gate bcopy(&tsn, mp->b_wptr, sizeof (tsn)); 11720Sstevel@tonic-gate mp->b_wptr += sizeof (tsn); 11730Sstevel@tonic-gate ASSERT((mp->b_wptr - mp->b_rptr) <= bsize); 11740Sstevel@tonic-gate } 11750Sstevel@tonic-gate 11760Sstevel@tonic-gate static void 11770Sstevel@tonic-gate sctp_data_chunk(sctp_t *sctp, sctp_chunk_hdr_t *ch, mblk_t *mp, mblk_t **dups, 11780Sstevel@tonic-gate sctp_faddr_t *fp, ip6_pkt_t *ipp) 11790Sstevel@tonic-gate { 11800Sstevel@tonic-gate sctp_data_hdr_t *dc; 11810Sstevel@tonic-gate mblk_t *dmp, *pmp; 11820Sstevel@tonic-gate sctp_instr_t *instr; 11830Sstevel@tonic-gate int ubit; 11840Sstevel@tonic-gate int isfrag; 11850Sstevel@tonic-gate uint16_t ssn; 11860Sstevel@tonic-gate uint32_t oftsn; 11870Sstevel@tonic-gate boolean_t can_deliver = B_TRUE; 11880Sstevel@tonic-gate uint32_t tsn; 11890Sstevel@tonic-gate int dlen; 11903845Svi117747 boolean_t tpfinished = B_TRUE; 11910Sstevel@tonic-gate int32_t new_rwnd; 11923448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 1193*8348SEric.Yu@Sun.COM int error; 11940Sstevel@tonic-gate 11950Sstevel@tonic-gate /* The following are used multiple times, so we inline them */ 11960Sstevel@tonic-gate #define SCTP_ACK_IT(sctp, tsn) \ 11970Sstevel@tonic-gate if (tsn == sctp->sctp_ftsn) { \ 11980Sstevel@tonic-gate dprint(2, ("data_chunk: acking next %x\n", tsn)); \ 11991932Svi117747 (sctp)->sctp_ftsn++; \ 12001932Svi117747 if ((sctp)->sctp_sack_gaps > 0) \ 12011932Svi117747 (sctp)->sctp_force_sack = 1; \ 12020Sstevel@tonic-gate } else if (SEQ_GT(tsn, sctp->sctp_ftsn)) { \ 12030Sstevel@tonic-gate /* Got a gap; record it */ \ 12040Sstevel@tonic-gate dprint(2, ("data_chunk: acking gap %x\n", tsn)); \ 12051932Svi117747 sctp_ack_add(&sctp->sctp_sack_info, tsn, \ 12061932Svi117747 &sctp->sctp_sack_gaps); \ 12070Sstevel@tonic-gate sctp->sctp_force_sack = 1; \ 12080Sstevel@tonic-gate } 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate dmp = NULL; 12110Sstevel@tonic-gate 12120Sstevel@tonic-gate dc = (sctp_data_hdr_t *)ch; 12130Sstevel@tonic-gate tsn = ntohl(dc->sdh_tsn); 12140Sstevel@tonic-gate 12151676Sjpk dprint(3, ("sctp_data_chunk: mp=%p tsn=%x\n", (void *)mp, tsn)); 12160Sstevel@tonic-gate 12170Sstevel@tonic-gate /* Check for duplicates */ 12180Sstevel@tonic-gate if (SEQ_LT(tsn, sctp->sctp_ftsn)) { 12190Sstevel@tonic-gate dprint(4, ("sctp_data_chunk: dropping duplicate\n")); 12200Sstevel@tonic-gate sctp->sctp_force_sack = 1; 12210Sstevel@tonic-gate sctp_add_dup(dc->sdh_tsn, dups); 12220Sstevel@tonic-gate return; 12230Sstevel@tonic-gate } 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL) { 12260Sstevel@tonic-gate sctp_set_t *sp; 12270Sstevel@tonic-gate 12280Sstevel@tonic-gate for (sp = sctp->sctp_sack_info; sp; sp = sp->next) { 12290Sstevel@tonic-gate if (SEQ_GEQ(tsn, sp->begin) && SEQ_LEQ(tsn, sp->end)) { 12300Sstevel@tonic-gate dprint(4, 12314964Skcpoon ("sctp_data_chunk: dropping dup > " 12324964Skcpoon "cumtsn\n")); 12330Sstevel@tonic-gate sctp->sctp_force_sack = 1; 12340Sstevel@tonic-gate sctp_add_dup(dc->sdh_tsn, dups); 12350Sstevel@tonic-gate return; 12360Sstevel@tonic-gate } 12370Sstevel@tonic-gate } 12380Sstevel@tonic-gate } 12390Sstevel@tonic-gate 12400Sstevel@tonic-gate /* We cannot deliver anything up now but we still need to handle it. */ 12410Sstevel@tonic-gate if (SCTP_IS_DETACHED(sctp)) { 12423448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInClosed); 12430Sstevel@tonic-gate can_deliver = B_FALSE; 12440Sstevel@tonic-gate } 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate dlen = ntohs(dc->sdh_len) - sizeof (*dc); 12470Sstevel@tonic-gate 12480Sstevel@tonic-gate /* Check for buffer space */ 12490Sstevel@tonic-gate if (sctp->sctp_rwnd - sctp->sctp_rxqueued < dlen) { 12500Sstevel@tonic-gate /* Drop and SACK, but don't advance the cumulative TSN. */ 12510Sstevel@tonic-gate sctp->sctp_force_sack = 1; 12520Sstevel@tonic-gate dprint(0, ("sctp_data_chunk: exceed rwnd %d rxqueued %d " 12533795Skcpoon "dlen %d ssn %d tsn %x\n", sctp->sctp_rwnd, 12543795Skcpoon sctp->sctp_rxqueued, dlen, ntohs(dc->sdh_ssn), 12553795Skcpoon ntohl(dc->sdh_tsn))); 12560Sstevel@tonic-gate return; 12570Sstevel@tonic-gate } 12580Sstevel@tonic-gate 12590Sstevel@tonic-gate if (ntohs(dc->sdh_sid) >= sctp->sctp_num_istr) { 12600Sstevel@tonic-gate uint16_t inval_parm[2]; 12610Sstevel@tonic-gate 12620Sstevel@tonic-gate inval_parm[0] = dc->sdh_sid; 12630Sstevel@tonic-gate /* RESERVED to be ignored at the receiving end */ 12640Sstevel@tonic-gate inval_parm[1] = 0; 12650Sstevel@tonic-gate /* ack and drop it */ 12664964Skcpoon sctp_add_err(sctp, SCTP_ERR_BAD_SID, inval_parm, 12674964Skcpoon sizeof (inval_parm), fp); 12680Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 12690Sstevel@tonic-gate return; 12700Sstevel@tonic-gate } 12710Sstevel@tonic-gate 12720Sstevel@tonic-gate ubit = SCTP_DATA_GET_UBIT(dc); 12730Sstevel@tonic-gate ASSERT(sctp->sctp_instr != NULL); 12740Sstevel@tonic-gate instr = &sctp->sctp_instr[ntohs(dc->sdh_sid)]; 12750Sstevel@tonic-gate /* Initialize the stream, if not yet used */ 12760Sstevel@tonic-gate if (instr->sctp == NULL) 12770Sstevel@tonic-gate instr->sctp = sctp; 12783845Svi117747 12790Sstevel@tonic-gate isfrag = !(SCTP_DATA_GET_BBIT(dc) && SCTP_DATA_GET_EBIT(dc)); 12800Sstevel@tonic-gate ssn = ntohs(dc->sdh_ssn); 12810Sstevel@tonic-gate 12820Sstevel@tonic-gate dmp = dupb(mp); 12830Sstevel@tonic-gate if (dmp == NULL) { 12840Sstevel@tonic-gate /* drop it and don't ack it, causing the peer to retransmit */ 12850Sstevel@tonic-gate return; 12860Sstevel@tonic-gate } 12870Sstevel@tonic-gate dmp->b_wptr = (uchar_t *)ch + ntohs(ch->sch_len); 12880Sstevel@tonic-gate 12890Sstevel@tonic-gate sctp->sctp_rxqueued += dlen; 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate oftsn = sctp->sctp_ftsn; 12920Sstevel@tonic-gate 12930Sstevel@tonic-gate if (isfrag) { 1294*8348SEric.Yu@Sun.COM 1295*8348SEric.Yu@Sun.COM error = 0; 12960Sstevel@tonic-gate /* fragmented data chunk */ 12970Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)dc; 12980Sstevel@tonic-gate if (ubit) { 12990Sstevel@tonic-gate dmp = sctp_uodata_frag(sctp, dmp, &dc); 13000Sstevel@tonic-gate #if DEBUG 13010Sstevel@tonic-gate if (dmp != NULL) { 13020Sstevel@tonic-gate ASSERT(instr == 13030Sstevel@tonic-gate &sctp->sctp_instr[ntohs(dc->sdh_sid)]); 13040Sstevel@tonic-gate } 13050Sstevel@tonic-gate #endif 13060Sstevel@tonic-gate } else { 13070Sstevel@tonic-gate dmp = sctp_data_frag(sctp, dmp, &dc, &error, instr, 13083845Svi117747 &tpfinished); 13090Sstevel@tonic-gate } 13100Sstevel@tonic-gate if (error != 0) { 13110Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 13120Sstevel@tonic-gate if (error == 1) { 13130Sstevel@tonic-gate /* 13140Sstevel@tonic-gate * out of memory; don't ack it so 13150Sstevel@tonic-gate * the peer retransmits 13160Sstevel@tonic-gate */ 13170Sstevel@tonic-gate return; 13180Sstevel@tonic-gate } else if (error == 2) { 13190Sstevel@tonic-gate /* 13200Sstevel@tonic-gate * fatal error (i.e. peer used different 13210Sstevel@tonic-gate * ssn's for same fragmented data) -- 13220Sstevel@tonic-gate * the association has been aborted. 13230Sstevel@tonic-gate * XXX need to return errval so state 13240Sstevel@tonic-gate * machine can also abort processing. 13250Sstevel@tonic-gate */ 13260Sstevel@tonic-gate dprint(0, ("error 2: must not happen!\n")); 13270Sstevel@tonic-gate return; 13280Sstevel@tonic-gate } 13290Sstevel@tonic-gate } 13300Sstevel@tonic-gate 13310Sstevel@tonic-gate if (dmp == NULL) { 13320Sstevel@tonic-gate /* 13330Sstevel@tonic-gate * Can't process this data now, but the cumulative 13340Sstevel@tonic-gate * TSN may be advanced, so do the checks at done. 13350Sstevel@tonic-gate */ 13360Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 13370Sstevel@tonic-gate goto done; 13380Sstevel@tonic-gate } 13390Sstevel@tonic-gate } 13400Sstevel@tonic-gate 13416374Sgeorges /* 13426374Sgeorges * Insert complete messages in correct order for ordered delivery. 13436374Sgeorges * tpfinished is true when the incoming chunk contains a complete 13446374Sgeorges * message or is the final missing fragment which completed a message. 13456374Sgeorges */ 13466374Sgeorges if (!ubit && tpfinished && ssn != instr->nextseq) { 13470Sstevel@tonic-gate /* Adjust rptr to point at the data chunk for compares */ 13480Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)dc; 13490Sstevel@tonic-gate 13500Sstevel@tonic-gate dprint(2, 13510Sstevel@tonic-gate ("data_chunk: inserted %x in pq (ssn %d expected %d)\n", 13520Sstevel@tonic-gate ntohl(dc->sdh_tsn), (int)(ssn), (int)(instr->nextseq))); 13530Sstevel@tonic-gate 13540Sstevel@tonic-gate if (instr->istr_msgs == NULL) { 13550Sstevel@tonic-gate instr->istr_msgs = dmp; 13560Sstevel@tonic-gate ASSERT(dmp->b_prev == NULL && dmp->b_next == NULL); 13570Sstevel@tonic-gate } else { 13580Sstevel@tonic-gate mblk_t *imblk = instr->istr_msgs; 13590Sstevel@tonic-gate sctp_data_hdr_t *idc; 13600Sstevel@tonic-gate 13610Sstevel@tonic-gate /* 13620Sstevel@tonic-gate * XXXNeed to take sequence wraps into account, 13630Sstevel@tonic-gate * ... and a more efficient insertion algo. 13640Sstevel@tonic-gate */ 13650Sstevel@tonic-gate for (;;) { 13660Sstevel@tonic-gate idc = (sctp_data_hdr_t *)imblk->b_rptr; 13670Sstevel@tonic-gate if (SSN_GT(ntohs(idc->sdh_ssn), 13684964Skcpoon ntohs(dc->sdh_ssn))) { 13690Sstevel@tonic-gate if (instr->istr_msgs == imblk) { 13700Sstevel@tonic-gate instr->istr_msgs = dmp; 13710Sstevel@tonic-gate dmp->b_next = imblk; 13720Sstevel@tonic-gate imblk->b_prev = dmp; 13730Sstevel@tonic-gate } else { 13740Sstevel@tonic-gate ASSERT(imblk->b_prev != NULL); 13750Sstevel@tonic-gate imblk->b_prev->b_next = dmp; 13760Sstevel@tonic-gate dmp->b_prev = imblk->b_prev; 13770Sstevel@tonic-gate imblk->b_prev = dmp; 13780Sstevel@tonic-gate dmp->b_next = imblk; 13790Sstevel@tonic-gate } 13800Sstevel@tonic-gate break; 13810Sstevel@tonic-gate } 13820Sstevel@tonic-gate if (imblk->b_next == NULL) { 13830Sstevel@tonic-gate imblk->b_next = dmp; 13840Sstevel@tonic-gate dmp->b_prev = imblk; 13850Sstevel@tonic-gate break; 13860Sstevel@tonic-gate } 13870Sstevel@tonic-gate imblk = imblk->b_next; 13880Sstevel@tonic-gate } 13890Sstevel@tonic-gate } 13900Sstevel@tonic-gate (instr->istr_nmsgs)++; 13910Sstevel@tonic-gate (sctp->sctp_istr_nmsgs)++; 13920Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 13930Sstevel@tonic-gate return; 13940Sstevel@tonic-gate } 13950Sstevel@tonic-gate 13960Sstevel@tonic-gate /* 13970Sstevel@tonic-gate * Else we can deliver the data directly. Recalculate 13980Sstevel@tonic-gate * dlen now since we may have reassembled data. 13990Sstevel@tonic-gate */ 14000Sstevel@tonic-gate dlen = dmp->b_wptr - (uchar_t *)dc - sizeof (*dc); 14010Sstevel@tonic-gate for (pmp = dmp->b_cont; pmp != NULL; pmp = pmp->b_cont) 14020Sstevel@tonic-gate dlen += pmp->b_wptr - pmp->b_rptr; 14030Sstevel@tonic-gate ASSERT(sctp->sctp_rxqueued >= dlen); 14040Sstevel@tonic-gate ASSERT(sctp->sctp_rwnd >= dlen); 14050Sstevel@tonic-gate 14060Sstevel@tonic-gate /* Deliver the message. */ 14070Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 14080Sstevel@tonic-gate 14090Sstevel@tonic-gate if (can_deliver) { 1410*8348SEric.Yu@Sun.COM 14110Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)(dc + 1); 14120Sstevel@tonic-gate if (sctp_input_add_ancillary(sctp, &dmp, dc, fp, ipp) == 0) { 14130Sstevel@tonic-gate dprint(1, ("sctp_data_chunk: delivering %lu bytes\n", 14140Sstevel@tonic-gate msgdsize(dmp))); 14150Sstevel@tonic-gate sctp->sctp_rwnd -= dlen; 1416*8348SEric.Yu@Sun.COM /* 1417*8348SEric.Yu@Sun.COM * Override b_flag for SCTP sockfs internal use 1418*8348SEric.Yu@Sun.COM */ 1419*8348SEric.Yu@Sun.COM dmp->b_flag = tpfinished ? 0 : SCTP_PARTIAL_DATA; 14200Sstevel@tonic-gate new_rwnd = sctp->sctp_ulp_recv(sctp->sctp_ulpd, dmp, 1421*8348SEric.Yu@Sun.COM msgdsize(dmp), 0, &error, NULL); 14220Sstevel@tonic-gate if (new_rwnd > sctp->sctp_rwnd) { 14230Sstevel@tonic-gate sctp->sctp_rwnd = new_rwnd; 14240Sstevel@tonic-gate } 14250Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 14260Sstevel@tonic-gate } else { 14270Sstevel@tonic-gate /* Just free the message if we don't have memory. */ 14280Sstevel@tonic-gate freemsg(dmp); 14290Sstevel@tonic-gate return; 14300Sstevel@tonic-gate } 14310Sstevel@tonic-gate } else { 14320Sstevel@tonic-gate /* About to free the data */ 14330Sstevel@tonic-gate freemsg(dmp); 14340Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 14350Sstevel@tonic-gate } 14360Sstevel@tonic-gate 14370Sstevel@tonic-gate /* 14380Sstevel@tonic-gate * data, now enqueued, may already have been processed and free'd 14390Sstevel@tonic-gate * by the ULP (or we may have just freed it above, if we could not 14400Sstevel@tonic-gate * deliver it), so we must not reference it (this is why we kept 14410Sstevel@tonic-gate * the ssn and ubit above). 14420Sstevel@tonic-gate */ 14430Sstevel@tonic-gate if (ubit != 0) { 14440Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_iudchunks); 14450Sstevel@tonic-gate goto done; 14460Sstevel@tonic-gate } 14470Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_idchunks); 14480Sstevel@tonic-gate 14490Sstevel@tonic-gate /* 14500Sstevel@tonic-gate * If there was a partial delivery and it has not finished, 14510Sstevel@tonic-gate * don't pull anything from the pqueues. 14520Sstevel@tonic-gate */ 14530Sstevel@tonic-gate if (!tpfinished) { 14540Sstevel@tonic-gate goto done; 14550Sstevel@tonic-gate } 14560Sstevel@tonic-gate 14570Sstevel@tonic-gate instr->nextseq = ssn + 1; 14580Sstevel@tonic-gate /* Deliver any successive data chunks in the instr queue */ 14590Sstevel@tonic-gate while (instr->istr_nmsgs > 0) { 14600Sstevel@tonic-gate dmp = (mblk_t *)instr->istr_msgs; 14610Sstevel@tonic-gate dc = (sctp_data_hdr_t *)dmp->b_rptr; 14620Sstevel@tonic-gate ssn = ntohs(dc->sdh_ssn); 14630Sstevel@tonic-gate /* Gap in the sequence */ 14640Sstevel@tonic-gate if (ssn != instr->nextseq) 14650Sstevel@tonic-gate break; 14660Sstevel@tonic-gate 14670Sstevel@tonic-gate /* Else deliver the data */ 14680Sstevel@tonic-gate (instr->istr_nmsgs)--; 14690Sstevel@tonic-gate (instr->nextseq)++; 14700Sstevel@tonic-gate (sctp->sctp_istr_nmsgs)--; 14710Sstevel@tonic-gate 14720Sstevel@tonic-gate instr->istr_msgs = instr->istr_msgs->b_next; 14730Sstevel@tonic-gate if (instr->istr_msgs != NULL) 14740Sstevel@tonic-gate instr->istr_msgs->b_prev = NULL; 14750Sstevel@tonic-gate dmp->b_next = dmp->b_prev = NULL; 14760Sstevel@tonic-gate 14770Sstevel@tonic-gate dprint(2, ("data_chunk: pulling %x from pq (ssn %d)\n", 14780Sstevel@tonic-gate ntohl(dc->sdh_tsn), (int)ssn)); 14790Sstevel@tonic-gate 14800Sstevel@tonic-gate /* 14810Sstevel@tonic-gate * If this chunk was reassembled, each b_cont represents 14820Sstevel@tonic-gate * another TSN; advance ftsn now. 14830Sstevel@tonic-gate */ 14840Sstevel@tonic-gate dlen = dmp->b_wptr - dmp->b_rptr - sizeof (*dc); 14850Sstevel@tonic-gate for (pmp = dmp->b_cont; pmp; pmp = pmp->b_cont) 14860Sstevel@tonic-gate dlen += pmp->b_wptr - pmp->b_rptr; 14870Sstevel@tonic-gate 14880Sstevel@tonic-gate ASSERT(sctp->sctp_rxqueued >= dlen); 14890Sstevel@tonic-gate ASSERT(sctp->sctp_rwnd >= dlen); 14900Sstevel@tonic-gate 14910Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 14920Sstevel@tonic-gate if (can_deliver) { 14930Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)(dc + 1); 14940Sstevel@tonic-gate if (sctp_input_add_ancillary(sctp, &dmp, dc, fp, 14950Sstevel@tonic-gate ipp) == 0) { 14960Sstevel@tonic-gate dprint(1, ("sctp_data_chunk: delivering %lu " 14970Sstevel@tonic-gate "bytes\n", msgdsize(dmp))); 14980Sstevel@tonic-gate sctp->sctp_rwnd -= dlen; 1499*8348SEric.Yu@Sun.COM /* 1500*8348SEric.Yu@Sun.COM * Override b_flag for SCTP sockfs internal use 1501*8348SEric.Yu@Sun.COM */ 1502*8348SEric.Yu@Sun.COM dmp->b_flag = tpfinished ? 1503*8348SEric.Yu@Sun.COM 0 : SCTP_PARTIAL_DATA; 15040Sstevel@tonic-gate new_rwnd = sctp->sctp_ulp_recv(sctp->sctp_ulpd, 1505*8348SEric.Yu@Sun.COM dmp, msgdsize(dmp), 0, &error, NULL); 15060Sstevel@tonic-gate if (new_rwnd > sctp->sctp_rwnd) { 15070Sstevel@tonic-gate sctp->sctp_rwnd = new_rwnd; 15080Sstevel@tonic-gate } 15090Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 15100Sstevel@tonic-gate } else { 15110Sstevel@tonic-gate freemsg(dmp); 15120Sstevel@tonic-gate return; 15130Sstevel@tonic-gate } 15140Sstevel@tonic-gate } else { 15150Sstevel@tonic-gate /* About to free the data */ 15160Sstevel@tonic-gate freemsg(dmp); 15170Sstevel@tonic-gate SCTP_ACK_IT(sctp, tsn); 15180Sstevel@tonic-gate } 15190Sstevel@tonic-gate } 15200Sstevel@tonic-gate 15210Sstevel@tonic-gate done: 15220Sstevel@tonic-gate 15230Sstevel@tonic-gate /* 15240Sstevel@tonic-gate * If there are gap reports pending, check if advancing 15250Sstevel@tonic-gate * the ftsn here closes a gap. If so, we can advance 15260Sstevel@tonic-gate * ftsn to the end of the set. 15270Sstevel@tonic-gate */ 15280Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL && 15290Sstevel@tonic-gate sctp->sctp_ftsn == sctp->sctp_sack_info->begin) { 15300Sstevel@tonic-gate sctp->sctp_ftsn = sctp->sctp_sack_info->end + 1; 15310Sstevel@tonic-gate } 15320Sstevel@tonic-gate /* 15330Sstevel@tonic-gate * If ftsn has moved forward, maybe we can remove gap reports. 15340Sstevel@tonic-gate * NB: dmp may now be NULL, so don't dereference it here. 15350Sstevel@tonic-gate */ 15360Sstevel@tonic-gate if (oftsn != sctp->sctp_ftsn && sctp->sctp_sack_info != NULL) { 15370Sstevel@tonic-gate sctp_ack_rem(&sctp->sctp_sack_info, sctp->sctp_ftsn - 1, 15380Sstevel@tonic-gate &sctp->sctp_sack_gaps); 15390Sstevel@tonic-gate dprint(2, ("data_chunk: removed acks before %x (num=%d)\n", 15400Sstevel@tonic-gate sctp->sctp_ftsn - 1, sctp->sctp_sack_gaps)); 15410Sstevel@tonic-gate } 15420Sstevel@tonic-gate 15430Sstevel@tonic-gate #ifdef DEBUG 15440Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL) { 15450Sstevel@tonic-gate ASSERT(sctp->sctp_ftsn != sctp->sctp_sack_info->begin); 15460Sstevel@tonic-gate } 15470Sstevel@tonic-gate #endif 15480Sstevel@tonic-gate 15490Sstevel@tonic-gate #undef SCTP_ACK_IT 15500Sstevel@tonic-gate } 15510Sstevel@tonic-gate 15520Sstevel@tonic-gate void 15530Sstevel@tonic-gate sctp_fill_sack(sctp_t *sctp, unsigned char *dst, int sacklen) 15540Sstevel@tonic-gate { 15550Sstevel@tonic-gate sctp_chunk_hdr_t *sch; 15560Sstevel@tonic-gate sctp_sack_chunk_t *sc; 15570Sstevel@tonic-gate sctp_sack_frag_t *sf; 15580Sstevel@tonic-gate uint16_t num_gaps = sctp->sctp_sack_gaps; 15590Sstevel@tonic-gate sctp_set_t *sp; 15600Sstevel@tonic-gate 15610Sstevel@tonic-gate /* Chunk hdr */ 15620Sstevel@tonic-gate sch = (sctp_chunk_hdr_t *)dst; 15630Sstevel@tonic-gate sch->sch_id = CHUNK_SACK; 15640Sstevel@tonic-gate sch->sch_flags = 0; 15650Sstevel@tonic-gate sch->sch_len = htons(sacklen); 15660Sstevel@tonic-gate 15670Sstevel@tonic-gate /* SACK chunk */ 15680Sstevel@tonic-gate sctp->sctp_lastacked = sctp->sctp_ftsn - 1; 15690Sstevel@tonic-gate 15700Sstevel@tonic-gate sc = (sctp_sack_chunk_t *)(sch + 1); 15710Sstevel@tonic-gate sc->ssc_cumtsn = htonl(sctp->sctp_lastacked); 15720Sstevel@tonic-gate if (sctp->sctp_rxqueued < sctp->sctp_rwnd) { 15730Sstevel@tonic-gate sc->ssc_a_rwnd = htonl(sctp->sctp_rwnd - sctp->sctp_rxqueued); 15740Sstevel@tonic-gate } else { 15750Sstevel@tonic-gate sc->ssc_a_rwnd = 0; 15760Sstevel@tonic-gate } 15770Sstevel@tonic-gate sc->ssc_numfrags = htons(num_gaps); 15780Sstevel@tonic-gate sc->ssc_numdups = 0; 15790Sstevel@tonic-gate 15800Sstevel@tonic-gate /* lay in gap reports */ 15810Sstevel@tonic-gate sf = (sctp_sack_frag_t *)(sc + 1); 15820Sstevel@tonic-gate for (sp = sctp->sctp_sack_info; sp; sp = sp->next) { 15830Sstevel@tonic-gate uint16_t offset; 15840Sstevel@tonic-gate 15850Sstevel@tonic-gate /* start */ 15860Sstevel@tonic-gate if (sp->begin > sctp->sctp_lastacked) { 15870Sstevel@tonic-gate offset = (uint16_t)(sp->begin - sctp->sctp_lastacked); 15880Sstevel@tonic-gate } else { 15890Sstevel@tonic-gate /* sequence number wrap */ 15900Sstevel@tonic-gate offset = (uint16_t)(UINT32_MAX - sctp->sctp_lastacked + 15910Sstevel@tonic-gate sp->begin); 15920Sstevel@tonic-gate } 15930Sstevel@tonic-gate sf->ssf_start = htons(offset); 15940Sstevel@tonic-gate 15950Sstevel@tonic-gate /* end */ 15960Sstevel@tonic-gate if (sp->end >= sp->begin) { 15970Sstevel@tonic-gate offset += (uint16_t)(sp->end - sp->begin); 15980Sstevel@tonic-gate } else { 15990Sstevel@tonic-gate /* sequence number wrap */ 16000Sstevel@tonic-gate offset += (uint16_t)(UINT32_MAX - sp->begin + sp->end); 16010Sstevel@tonic-gate } 16020Sstevel@tonic-gate sf->ssf_end = htons(offset); 16030Sstevel@tonic-gate 16040Sstevel@tonic-gate sf++; 16050Sstevel@tonic-gate /* This is just for debugging (a la the following assertion) */ 16060Sstevel@tonic-gate num_gaps--; 16070Sstevel@tonic-gate } 16080Sstevel@tonic-gate 16090Sstevel@tonic-gate ASSERT(num_gaps == 0); 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate /* If the SACK timer is running, stop it */ 16120Sstevel@tonic-gate if (sctp->sctp_ack_timer_running) { 16130Sstevel@tonic-gate sctp_timer_stop(sctp->sctp_ack_mp); 16140Sstevel@tonic-gate sctp->sctp_ack_timer_running = B_FALSE; 16150Sstevel@tonic-gate } 16160Sstevel@tonic-gate 16170Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_obchunks); 16180Sstevel@tonic-gate } 16190Sstevel@tonic-gate 16200Sstevel@tonic-gate mblk_t * 16210Sstevel@tonic-gate sctp_make_sack(sctp_t *sctp, sctp_faddr_t *sendto, mblk_t *dups) 16220Sstevel@tonic-gate { 16230Sstevel@tonic-gate mblk_t *smp; 16240Sstevel@tonic-gate size_t slen; 16250Sstevel@tonic-gate sctp_chunk_hdr_t *sch; 16260Sstevel@tonic-gate sctp_sack_chunk_t *sc; 16273430Skcpoon int32_t acks_max; 16283448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 16294964Skcpoon uint32_t dups_len; 16304964Skcpoon sctp_faddr_t *fp; 16310Sstevel@tonic-gate 16320Sstevel@tonic-gate if (sctp->sctp_force_sack) { 16330Sstevel@tonic-gate sctp->sctp_force_sack = 0; 16340Sstevel@tonic-gate goto checks_done; 16350Sstevel@tonic-gate } 16360Sstevel@tonic-gate 16373448Sdh155122 acks_max = sctps->sctps_deferred_acks_max; 16380Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_ESTABLISHED) { 16393430Skcpoon if (sctp->sctp_sack_toggle < acks_max) { 16400Sstevel@tonic-gate /* no need to SACK right now */ 16410Sstevel@tonic-gate dprint(2, ("sctp_make_sack: %p no sack (toggle)\n", 16421676Sjpk (void *)sctp)); 16430Sstevel@tonic-gate return (NULL); 16443430Skcpoon } else if (sctp->sctp_sack_toggle >= acks_max) { 16450Sstevel@tonic-gate sctp->sctp_sack_toggle = 0; 16460Sstevel@tonic-gate } 16470Sstevel@tonic-gate } 16480Sstevel@tonic-gate 16490Sstevel@tonic-gate if (sctp->sctp_ftsn == sctp->sctp_lastacked + 1) { 16501676Sjpk dprint(2, ("sctp_make_sack: %p no sack (already)\n", 16511676Sjpk (void *)sctp)); 16520Sstevel@tonic-gate return (NULL); 16530Sstevel@tonic-gate } 16540Sstevel@tonic-gate 16550Sstevel@tonic-gate checks_done: 16560Sstevel@tonic-gate dprint(2, ("sctp_make_sack: acking %x\n", sctp->sctp_ftsn - 1)); 16570Sstevel@tonic-gate 16584964Skcpoon if (dups != NULL) 16594964Skcpoon dups_len = MBLKL(dups); 16604964Skcpoon else 16614964Skcpoon dups_len = 0; 16620Sstevel@tonic-gate slen = sizeof (*sch) + sizeof (*sc) + 16630Sstevel@tonic-gate (sizeof (sctp_sack_frag_t) * sctp->sctp_sack_gaps); 16644964Skcpoon 16654964Skcpoon /* 16664964Skcpoon * If there are error chunks, check and see if we can send the 16674964Skcpoon * SACK chunk and error chunks together in one packet. If not, 16684964Skcpoon * send the error chunks out now. 16694964Skcpoon */ 16704964Skcpoon if (sctp->sctp_err_chunks != NULL) { 16714964Skcpoon fp = SCTP_CHUNK_DEST(sctp->sctp_err_chunks); 16724964Skcpoon if (sctp->sctp_err_len + slen + dups_len > fp->sfa_pmss) { 16734964Skcpoon if ((smp = sctp_make_mp(sctp, fp, 0)) == NULL) { 16744964Skcpoon SCTP_KSTAT(sctps, sctp_send_err_failed); 16754964Skcpoon SCTP_KSTAT(sctps, sctp_send_sack_failed); 16764964Skcpoon freemsg(sctp->sctp_err_chunks); 16774964Skcpoon sctp->sctp_err_chunks = NULL; 16784964Skcpoon sctp->sctp_err_len = 0; 16794964Skcpoon return (NULL); 16804964Skcpoon } 16814964Skcpoon smp->b_cont = sctp->sctp_err_chunks; 16824964Skcpoon sctp_set_iplen(sctp, smp); 16834964Skcpoon sctp_add_sendq(sctp, smp); 16844964Skcpoon sctp->sctp_err_chunks = NULL; 16854964Skcpoon sctp->sctp_err_len = 0; 16864964Skcpoon } 16874964Skcpoon } 16880Sstevel@tonic-gate smp = sctp_make_mp(sctp, sendto, slen); 16890Sstevel@tonic-gate if (smp == NULL) { 16903448Sdh155122 SCTP_KSTAT(sctps, sctp_send_sack_failed); 16910Sstevel@tonic-gate return (NULL); 16920Sstevel@tonic-gate } 16930Sstevel@tonic-gate sch = (sctp_chunk_hdr_t *)smp->b_wptr; 16940Sstevel@tonic-gate 16950Sstevel@tonic-gate sctp_fill_sack(sctp, smp->b_wptr, slen); 16960Sstevel@tonic-gate smp->b_wptr += slen; 16974964Skcpoon if (dups != NULL) { 16980Sstevel@tonic-gate sc = (sctp_sack_chunk_t *)(sch + 1); 16994964Skcpoon sc->ssc_numdups = htons(MBLKL(dups) / sizeof (uint32_t)); 17004964Skcpoon sch->sch_len = htons(slen + dups_len); 17010Sstevel@tonic-gate smp->b_cont = dups; 17020Sstevel@tonic-gate } 17030Sstevel@tonic-gate 17044964Skcpoon if (sctp->sctp_err_chunks != NULL) { 17054964Skcpoon linkb(smp, sctp->sctp_err_chunks); 17064964Skcpoon sctp->sctp_err_chunks = NULL; 17074964Skcpoon sctp->sctp_err_len = 0; 17084964Skcpoon } 17090Sstevel@tonic-gate return (smp); 17100Sstevel@tonic-gate } 17110Sstevel@tonic-gate 17124964Skcpoon /* 17134964Skcpoon * Check and see if we need to send a SACK chunk. If it is needed, 17144964Skcpoon * send it out. Return true if a SACK chunk is sent, false otherwise. 17154964Skcpoon */ 17164964Skcpoon boolean_t 17170Sstevel@tonic-gate sctp_sack(sctp_t *sctp, mblk_t *dups) 17180Sstevel@tonic-gate { 17190Sstevel@tonic-gate mblk_t *smp; 17203448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 17210Sstevel@tonic-gate 17220Sstevel@tonic-gate /* If we are shutting down, let send_shutdown() bundle the SACK */ 17230Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_SHUTDOWN_SENT) { 17240Sstevel@tonic-gate sctp_send_shutdown(sctp, 0); 17250Sstevel@tonic-gate } 17260Sstevel@tonic-gate 17270Sstevel@tonic-gate ASSERT(sctp->sctp_lastdata != NULL); 17280Sstevel@tonic-gate 17290Sstevel@tonic-gate if ((smp = sctp_make_sack(sctp, sctp->sctp_lastdata, dups)) == NULL) { 17300Sstevel@tonic-gate /* The caller of sctp_sack() will not free the dups mblk. */ 17310Sstevel@tonic-gate if (dups != NULL) 17320Sstevel@tonic-gate freeb(dups); 17334964Skcpoon return (B_FALSE); 17340Sstevel@tonic-gate } 17350Sstevel@tonic-gate sctp_set_iplen(sctp, smp); 17360Sstevel@tonic-gate 17370Sstevel@tonic-gate dprint(2, ("sctp_sack: sending to %p %x:%x:%x:%x\n", 17381676Sjpk (void *)sctp->sctp_lastdata, 17391676Sjpk SCTP_PRINTADDR(sctp->sctp_lastdata->faddr))); 17400Sstevel@tonic-gate 17410Sstevel@tonic-gate sctp->sctp_active = lbolt64; 17420Sstevel@tonic-gate 17433448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpOutAck); 17440Sstevel@tonic-gate sctp_add_sendq(sctp, smp); 17454964Skcpoon return (B_TRUE); 17460Sstevel@tonic-gate } 17470Sstevel@tonic-gate 17480Sstevel@tonic-gate /* 17490Sstevel@tonic-gate * This is called if we have a message that was partially sent and is 17500Sstevel@tonic-gate * abandoned. The cum TSN will be the last chunk sent for this message, 17510Sstevel@tonic-gate * subsequent chunks will be marked ABANDONED. We send a Forward TSN 17520Sstevel@tonic-gate * chunk in this case with the TSN of the last sent chunk so that the 17530Sstevel@tonic-gate * peer can clean up its fragment list for this message. This message 17540Sstevel@tonic-gate * will be removed from the transmit list when the peer sends a SACK 17550Sstevel@tonic-gate * back. 17560Sstevel@tonic-gate */ 17570Sstevel@tonic-gate int 17580Sstevel@tonic-gate sctp_check_abandoned_msg(sctp_t *sctp, mblk_t *meta) 17590Sstevel@tonic-gate { 17600Sstevel@tonic-gate sctp_data_hdr_t *dh; 17610Sstevel@tonic-gate mblk_t *nmp; 17620Sstevel@tonic-gate mblk_t *head; 17630Sstevel@tonic-gate int32_t unsent = 0; 17640Sstevel@tonic-gate mblk_t *mp1 = meta->b_cont; 17650Sstevel@tonic-gate uint32_t adv_pap = sctp->sctp_adv_pap; 17660Sstevel@tonic-gate sctp_faddr_t *fp = sctp->sctp_current; 17673448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 17680Sstevel@tonic-gate 17690Sstevel@tonic-gate dh = (sctp_data_hdr_t *)mp1->b_rptr; 17700Sstevel@tonic-gate if (SEQ_GEQ(sctp->sctp_lastack_rxd, ntohl(dh->sdh_tsn))) { 17710Sstevel@tonic-gate sctp_ftsn_set_t *sets = NULL; 17720Sstevel@tonic-gate uint_t nsets = 0; 17730Sstevel@tonic-gate uint32_t seglen = sizeof (uint32_t); 17740Sstevel@tonic-gate boolean_t ubit = SCTP_DATA_GET_UBIT(dh); 17750Sstevel@tonic-gate 17760Sstevel@tonic-gate while (mp1->b_next != NULL && SCTP_CHUNK_ISSENT(mp1->b_next)) 17770Sstevel@tonic-gate mp1 = mp1->b_next; 17780Sstevel@tonic-gate dh = (sctp_data_hdr_t *)mp1->b_rptr; 17790Sstevel@tonic-gate sctp->sctp_adv_pap = ntohl(dh->sdh_tsn); 17800Sstevel@tonic-gate if (!ubit && 17810Sstevel@tonic-gate !sctp_add_ftsn_set(&sets, fp, meta, &nsets, &seglen)) { 17820Sstevel@tonic-gate sctp->sctp_adv_pap = adv_pap; 17830Sstevel@tonic-gate return (ENOMEM); 17840Sstevel@tonic-gate } 17850Sstevel@tonic-gate nmp = sctp_make_ftsn_chunk(sctp, fp, sets, nsets, seglen); 17860Sstevel@tonic-gate sctp_free_ftsn_set(sets); 17870Sstevel@tonic-gate if (nmp == NULL) { 17880Sstevel@tonic-gate sctp->sctp_adv_pap = adv_pap; 17890Sstevel@tonic-gate return (ENOMEM); 17900Sstevel@tonic-gate } 1791252Svi117747 head = sctp_add_proto_hdr(sctp, fp, nmp, 0, NULL); 17920Sstevel@tonic-gate if (head == NULL) { 17930Sstevel@tonic-gate sctp->sctp_adv_pap = adv_pap; 17940Sstevel@tonic-gate freemsg(nmp); 17953448Sdh155122 SCTP_KSTAT(sctps, sctp_send_ftsn_failed); 17960Sstevel@tonic-gate return (ENOMEM); 17970Sstevel@tonic-gate } 17980Sstevel@tonic-gate SCTP_MSG_SET_ABANDONED(meta); 17990Sstevel@tonic-gate sctp_set_iplen(sctp, head); 18000Sstevel@tonic-gate sctp_add_sendq(sctp, head); 18010Sstevel@tonic-gate if (!fp->timer_running) 18020Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto); 18030Sstevel@tonic-gate mp1 = mp1->b_next; 18040Sstevel@tonic-gate while (mp1 != NULL) { 18050Sstevel@tonic-gate ASSERT(!SCTP_CHUNK_ISSENT(mp1)); 18060Sstevel@tonic-gate ASSERT(!SCTP_CHUNK_ABANDONED(mp1)); 18070Sstevel@tonic-gate SCTP_ABANDON_CHUNK(mp1); 18080Sstevel@tonic-gate dh = (sctp_data_hdr_t *)mp1->b_rptr; 18090Sstevel@tonic-gate unsent += ntohs(dh->sdh_len) - sizeof (*dh); 18100Sstevel@tonic-gate mp1 = mp1->b_next; 18110Sstevel@tonic-gate } 18120Sstevel@tonic-gate ASSERT(sctp->sctp_unsent >= unsent); 18130Sstevel@tonic-gate sctp->sctp_unsent -= unsent; 18140Sstevel@tonic-gate /* 18150Sstevel@tonic-gate * Update ULP the amount of queued data, which is 18160Sstevel@tonic-gate * sent-unack'ed + unsent. 18170Sstevel@tonic-gate */ 1818*8348SEric.Yu@Sun.COM if (!SCTP_IS_DETACHED(sctp)) 1819*8348SEric.Yu@Sun.COM SCTP_TXQ_UPDATE(sctp); 18200Sstevel@tonic-gate return (0); 18210Sstevel@tonic-gate } 18220Sstevel@tonic-gate return (-1); 18230Sstevel@tonic-gate } 18240Sstevel@tonic-gate 18250Sstevel@tonic-gate uint32_t 18260Sstevel@tonic-gate sctp_cumack(sctp_t *sctp, uint32_t tsn, mblk_t **first_unacked) 18270Sstevel@tonic-gate { 18280Sstevel@tonic-gate mblk_t *ump, *nump, *mp = NULL; 18290Sstevel@tonic-gate uint16_t chunklen; 18300Sstevel@tonic-gate uint32_t xtsn; 18310Sstevel@tonic-gate sctp_faddr_t *fp; 18320Sstevel@tonic-gate sctp_data_hdr_t *sdc; 18330Sstevel@tonic-gate uint32_t cumack_forward = 0; 18340Sstevel@tonic-gate sctp_msg_hdr_t *mhdr; 18353448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 18360Sstevel@tonic-gate 18370Sstevel@tonic-gate ump = sctp->sctp_xmit_head; 18380Sstevel@tonic-gate 18390Sstevel@tonic-gate /* 18400Sstevel@tonic-gate * Free messages only when they're completely acked. 18410Sstevel@tonic-gate */ 18420Sstevel@tonic-gate while (ump != NULL) { 18430Sstevel@tonic-gate mhdr = (sctp_msg_hdr_t *)ump->b_rptr; 18440Sstevel@tonic-gate for (mp = ump->b_cont; mp != NULL; mp = mp->b_next) { 18450Sstevel@tonic-gate if (SCTP_CHUNK_ABANDONED(mp)) { 18460Sstevel@tonic-gate ASSERT(SCTP_IS_MSG_ABANDONED(ump)); 18470Sstevel@tonic-gate mp = NULL; 18480Sstevel@tonic-gate break; 18490Sstevel@tonic-gate } 18500Sstevel@tonic-gate /* 18510Sstevel@tonic-gate * We check for abandoned message if we are PR-SCTP 18520Sstevel@tonic-gate * aware, if this is not the first chunk in the 18530Sstevel@tonic-gate * message (b_cont) and if the message is marked 18540Sstevel@tonic-gate * abandoned. 18550Sstevel@tonic-gate */ 18560Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(mp)) { 18570Sstevel@tonic-gate if (sctp->sctp_prsctp_aware && 18580Sstevel@tonic-gate mp != ump->b_cont && 18590Sstevel@tonic-gate (SCTP_IS_MSG_ABANDONED(ump) || 18600Sstevel@tonic-gate SCTP_MSG_TO_BE_ABANDONED(ump, mhdr, 18610Sstevel@tonic-gate sctp))) { 18620Sstevel@tonic-gate (void) sctp_check_abandoned_msg(sctp, 18630Sstevel@tonic-gate ump); 18640Sstevel@tonic-gate } 18650Sstevel@tonic-gate goto cum_ack_done; 18660Sstevel@tonic-gate } 18670Sstevel@tonic-gate sdc = (sctp_data_hdr_t *)mp->b_rptr; 18680Sstevel@tonic-gate xtsn = ntohl(sdc->sdh_tsn); 18690Sstevel@tonic-gate if (SEQ_GEQ(sctp->sctp_lastack_rxd, xtsn)) 18700Sstevel@tonic-gate continue; 18710Sstevel@tonic-gate if (SEQ_GEQ(tsn, xtsn)) { 18720Sstevel@tonic-gate fp = SCTP_CHUNK_DEST(mp); 18730Sstevel@tonic-gate chunklen = ntohs(sdc->sdh_len); 18740Sstevel@tonic-gate 18750Sstevel@tonic-gate if (sctp->sctp_out_time != 0 && 18760Sstevel@tonic-gate xtsn == sctp->sctp_rtt_tsn) { 18770Sstevel@tonic-gate /* Got a new RTT measurement */ 18780Sstevel@tonic-gate sctp_update_rtt(sctp, fp, 18790Sstevel@tonic-gate lbolt64 - sctp->sctp_out_time); 18800Sstevel@tonic-gate sctp->sctp_out_time = 0; 18810Sstevel@tonic-gate } 18820Sstevel@tonic-gate if (SCTP_CHUNK_ISACKED(mp)) 18830Sstevel@tonic-gate continue; 18841735Skcpoon SCTP_CHUNK_SET_SACKCNT(mp, 0); 18850Sstevel@tonic-gate SCTP_CHUNK_ACKED(mp); 18860Sstevel@tonic-gate ASSERT(fp->suna >= chunklen); 18870Sstevel@tonic-gate fp->suna -= chunklen; 18880Sstevel@tonic-gate fp->acked += chunklen; 18890Sstevel@tonic-gate cumack_forward += chunklen; 18900Sstevel@tonic-gate ASSERT(sctp->sctp_unacked >= 18910Sstevel@tonic-gate (chunklen - sizeof (*sdc))); 18920Sstevel@tonic-gate sctp->sctp_unacked -= 18930Sstevel@tonic-gate (chunklen - sizeof (*sdc)); 18940Sstevel@tonic-gate if (fp->suna == 0) { 18950Sstevel@tonic-gate /* all outstanding data acked */ 18960Sstevel@tonic-gate fp->pba = 0; 18970Sstevel@tonic-gate SCTP_FADDR_TIMER_STOP(fp); 18980Sstevel@tonic-gate } else { 18990Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, 19000Sstevel@tonic-gate fp->rto); 19010Sstevel@tonic-gate } 19020Sstevel@tonic-gate } else { 19030Sstevel@tonic-gate goto cum_ack_done; 19040Sstevel@tonic-gate } 19050Sstevel@tonic-gate } 19060Sstevel@tonic-gate nump = ump->b_next; 19070Sstevel@tonic-gate if (nump != NULL) 19080Sstevel@tonic-gate nump->b_prev = NULL; 19090Sstevel@tonic-gate if (ump == sctp->sctp_xmit_tail) 19100Sstevel@tonic-gate sctp->sctp_xmit_tail = nump; 19110Sstevel@tonic-gate if (SCTP_IS_MSG_ABANDONED(ump)) { 19120Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_prsctpdrop); 19130Sstevel@tonic-gate ump->b_next = NULL; 19140Sstevel@tonic-gate sctp_sendfail_event(sctp, ump, 0, B_TRUE); 19150Sstevel@tonic-gate } else { 19160Sstevel@tonic-gate sctp_free_msg(ump); 19170Sstevel@tonic-gate } 19180Sstevel@tonic-gate sctp->sctp_xmit_head = ump = nump; 19190Sstevel@tonic-gate } 19200Sstevel@tonic-gate cum_ack_done: 19210Sstevel@tonic-gate *first_unacked = mp; 19220Sstevel@tonic-gate if (cumack_forward > 0) { 19233448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInAck); 19240Sstevel@tonic-gate if (SEQ_GT(sctp->sctp_lastack_rxd, sctp->sctp_recovery_tsn)) { 19250Sstevel@tonic-gate sctp->sctp_recovery_tsn = sctp->sctp_lastack_rxd; 19260Sstevel@tonic-gate } 19270Sstevel@tonic-gate 19280Sstevel@tonic-gate /* 19290Sstevel@tonic-gate * Update ULP the amount of queued data, which is 19300Sstevel@tonic-gate * sent-unack'ed + unsent. 19310Sstevel@tonic-gate */ 1932*8348SEric.Yu@Sun.COM if (!SCTP_IS_DETACHED(sctp)) 1933*8348SEric.Yu@Sun.COM SCTP_TXQ_UPDATE(sctp); 19340Sstevel@tonic-gate 19350Sstevel@tonic-gate /* Time to send a shutdown? */ 19360Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_SHUTDOWN_PENDING) { 19370Sstevel@tonic-gate sctp_send_shutdown(sctp, 0); 19380Sstevel@tonic-gate } 19390Sstevel@tonic-gate sctp->sctp_xmit_unacked = mp; 19400Sstevel@tonic-gate } else { 19410Sstevel@tonic-gate /* dup ack */ 19423448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInDupAck); 19430Sstevel@tonic-gate } 19440Sstevel@tonic-gate sctp->sctp_lastack_rxd = tsn; 19450Sstevel@tonic-gate if (SEQ_LT(sctp->sctp_adv_pap, sctp->sctp_lastack_rxd)) 19460Sstevel@tonic-gate sctp->sctp_adv_pap = sctp->sctp_lastack_rxd; 19470Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_head || sctp->sctp_unacked == 0); 19480Sstevel@tonic-gate 19490Sstevel@tonic-gate return (cumack_forward); 19500Sstevel@tonic-gate } 19510Sstevel@tonic-gate 19520Sstevel@tonic-gate static int 19530Sstevel@tonic-gate sctp_set_frwnd(sctp_t *sctp, uint32_t frwnd) 19540Sstevel@tonic-gate { 19550Sstevel@tonic-gate uint32_t orwnd; 19560Sstevel@tonic-gate 19570Sstevel@tonic-gate if (sctp->sctp_unacked > frwnd) { 19580Sstevel@tonic-gate sctp->sctp_frwnd = 0; 19590Sstevel@tonic-gate return (0); 19600Sstevel@tonic-gate } 19610Sstevel@tonic-gate orwnd = sctp->sctp_frwnd; 19620Sstevel@tonic-gate sctp->sctp_frwnd = frwnd - sctp->sctp_unacked; 19630Sstevel@tonic-gate if (orwnd < sctp->sctp_frwnd) { 19640Sstevel@tonic-gate return (1); 19650Sstevel@tonic-gate } else { 19660Sstevel@tonic-gate return (0); 19670Sstevel@tonic-gate } 19680Sstevel@tonic-gate } 19690Sstevel@tonic-gate 19700Sstevel@tonic-gate /* 19710Sstevel@tonic-gate * For un-ordered messages. 19720Sstevel@tonic-gate * Walk the sctp->sctp_uo_frag list and remove any fragments with TSN 19730Sstevel@tonic-gate * less than/equal to ftsn. Fragments for un-ordered messages are 19740Sstevel@tonic-gate * strictly in sequence (w.r.t TSN). 19750Sstevel@tonic-gate */ 19760Sstevel@tonic-gate static int 19770Sstevel@tonic-gate sctp_ftsn_check_uo_frag(sctp_t *sctp, uint32_t ftsn) 19780Sstevel@tonic-gate { 19790Sstevel@tonic-gate mblk_t *hmp; 19800Sstevel@tonic-gate mblk_t *hmp_next; 19810Sstevel@tonic-gate sctp_data_hdr_t *dc; 19820Sstevel@tonic-gate int dlen = 0; 19830Sstevel@tonic-gate 19840Sstevel@tonic-gate hmp = sctp->sctp_uo_frags; 19850Sstevel@tonic-gate while (hmp != NULL) { 19860Sstevel@tonic-gate hmp_next = hmp->b_next; 19870Sstevel@tonic-gate dc = (sctp_data_hdr_t *)hmp->b_rptr; 19880Sstevel@tonic-gate if (SEQ_GT(ntohl(dc->sdh_tsn), ftsn)) 19890Sstevel@tonic-gate return (dlen); 19900Sstevel@tonic-gate sctp->sctp_uo_frags = hmp_next; 19910Sstevel@tonic-gate if (hmp_next != NULL) 19920Sstevel@tonic-gate hmp_next->b_prev = NULL; 19930Sstevel@tonic-gate hmp->b_next = NULL; 19940Sstevel@tonic-gate dlen += ntohs(dc->sdh_len) - sizeof (*dc); 19950Sstevel@tonic-gate freeb(hmp); 19960Sstevel@tonic-gate hmp = hmp_next; 19970Sstevel@tonic-gate } 19980Sstevel@tonic-gate return (dlen); 19990Sstevel@tonic-gate } 20000Sstevel@tonic-gate 20010Sstevel@tonic-gate /* 20020Sstevel@tonic-gate * For ordered messages. 20030Sstevel@tonic-gate * Check for existing fragments for an sid-ssn pair reported as abandoned, 20040Sstevel@tonic-gate * hence will not receive, in the Forward TSN. If there are fragments, then 20050Sstevel@tonic-gate * we just nuke them. If and when Partial Delivery API is supported, we 20060Sstevel@tonic-gate * would need to send a notification to the upper layer about this. 20070Sstevel@tonic-gate */ 20080Sstevel@tonic-gate static int 20090Sstevel@tonic-gate sctp_ftsn_check_frag(sctp_t *sctp, uint16_t ssn, sctp_instr_t *sip) 20100Sstevel@tonic-gate { 20110Sstevel@tonic-gate sctp_reass_t *srp; 20120Sstevel@tonic-gate mblk_t *hmp; 20130Sstevel@tonic-gate mblk_t *dmp; 20140Sstevel@tonic-gate mblk_t *hmp_next; 20150Sstevel@tonic-gate sctp_data_hdr_t *dc; 20160Sstevel@tonic-gate int dlen = 0; 20170Sstevel@tonic-gate 20180Sstevel@tonic-gate hmp = sip->istr_reass; 20190Sstevel@tonic-gate while (hmp != NULL) { 20200Sstevel@tonic-gate hmp_next = hmp->b_next; 20210Sstevel@tonic-gate srp = (sctp_reass_t *)DB_BASE(hmp); 20220Sstevel@tonic-gate if (SSN_GT(srp->ssn, ssn)) 20230Sstevel@tonic-gate return (dlen); 20240Sstevel@tonic-gate /* 20250Sstevel@tonic-gate * If we had sent part of this message up, send a partial 20260Sstevel@tonic-gate * delivery event. Since this is ordered delivery, we should 20270Sstevel@tonic-gate * have sent partial message only for the next in sequence, 20280Sstevel@tonic-gate * hence the ASSERT. See comments in sctp_data_chunk() for 20290Sstevel@tonic-gate * trypartial. 20300Sstevel@tonic-gate */ 20310Sstevel@tonic-gate if (srp->partial_delivered) { 20320Sstevel@tonic-gate ASSERT(sip->nextseq == srp->ssn); 20330Sstevel@tonic-gate sctp_partial_delivery_event(sctp); 20340Sstevel@tonic-gate } 20350Sstevel@tonic-gate /* Take it out of the reass queue */ 20360Sstevel@tonic-gate sip->istr_reass = hmp_next; 20370Sstevel@tonic-gate if (hmp_next != NULL) 20380Sstevel@tonic-gate hmp_next->b_prev = NULL; 20390Sstevel@tonic-gate hmp->b_next = NULL; 20400Sstevel@tonic-gate ASSERT(hmp->b_prev == NULL); 20410Sstevel@tonic-gate dmp = hmp; 20423845Svi117747 ASSERT(DB_TYPE(hmp) == M_CTL); 20433845Svi117747 dmp = hmp->b_cont; 20443845Svi117747 hmp->b_cont = NULL; 20453845Svi117747 freeb(hmp); 20463845Svi117747 hmp = dmp; 20470Sstevel@tonic-gate while (dmp != NULL) { 20480Sstevel@tonic-gate dc = (sctp_data_hdr_t *)dmp->b_rptr; 20490Sstevel@tonic-gate dlen += ntohs(dc->sdh_len) - sizeof (*dc); 20500Sstevel@tonic-gate dmp = dmp->b_cont; 20510Sstevel@tonic-gate } 20520Sstevel@tonic-gate freemsg(hmp); 20530Sstevel@tonic-gate hmp = hmp_next; 20540Sstevel@tonic-gate } 20550Sstevel@tonic-gate return (dlen); 20560Sstevel@tonic-gate } 20570Sstevel@tonic-gate 20580Sstevel@tonic-gate /* 20590Sstevel@tonic-gate * Update sctp_ftsn to the cumulative TSN from the Forward TSN chunk. Remove 20600Sstevel@tonic-gate * any SACK gaps less than the newly updated sctp_ftsn. Walk through the 20610Sstevel@tonic-gate * sid-ssn pair in the Forward TSN and for each, clean the fragment list 20620Sstevel@tonic-gate * for this pair, if needed, and check if we can deliver subsequent 20630Sstevel@tonic-gate * messages, if any, from the instream queue (that were waiting for this 20640Sstevel@tonic-gate * sid-ssn message to show up). Once we are done try to update the SACK 20650Sstevel@tonic-gate * info. We could get a duplicate Forward TSN, in which case just send 20660Sstevel@tonic-gate * a SACK. If any of the sid values in the the Forward TSN is invalid, 20670Sstevel@tonic-gate * send back an "Invalid Stream Identifier" error and continue processing 20680Sstevel@tonic-gate * the rest. 20690Sstevel@tonic-gate */ 20700Sstevel@tonic-gate static void 20710Sstevel@tonic-gate sctp_process_forward_tsn(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp, 20720Sstevel@tonic-gate ip6_pkt_t *ipp) 20730Sstevel@tonic-gate { 20740Sstevel@tonic-gate uint32_t *ftsn = (uint32_t *)(ch + 1); 20750Sstevel@tonic-gate ftsn_entry_t *ftsn_entry; 20760Sstevel@tonic-gate sctp_instr_t *instr; 20770Sstevel@tonic-gate boolean_t can_deliver = B_TRUE; 20780Sstevel@tonic-gate size_t dlen; 20790Sstevel@tonic-gate int flen; 20800Sstevel@tonic-gate mblk_t *dmp; 20810Sstevel@tonic-gate mblk_t *pmp; 20820Sstevel@tonic-gate sctp_data_hdr_t *dc; 20830Sstevel@tonic-gate ssize_t remaining; 20843448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 20850Sstevel@tonic-gate 20860Sstevel@tonic-gate *ftsn = ntohl(*ftsn); 20870Sstevel@tonic-gate remaining = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*ftsn); 20880Sstevel@tonic-gate 20890Sstevel@tonic-gate if (SCTP_IS_DETACHED(sctp)) { 20903448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInClosed); 20910Sstevel@tonic-gate can_deliver = B_FALSE; 20920Sstevel@tonic-gate } 20930Sstevel@tonic-gate /* 20940Sstevel@tonic-gate * un-ordered messages don't have SID-SSN pair entries, we check 20950Sstevel@tonic-gate * for any fragments (for un-ordered message) to be discarded using 20960Sstevel@tonic-gate * the cumulative FTSN. 20970Sstevel@tonic-gate */ 20980Sstevel@tonic-gate flen = sctp_ftsn_check_uo_frag(sctp, *ftsn); 20990Sstevel@tonic-gate if (flen > 0) { 21000Sstevel@tonic-gate ASSERT(sctp->sctp_rxqueued >= flen); 21010Sstevel@tonic-gate sctp->sctp_rxqueued -= flen; 21020Sstevel@tonic-gate } 21030Sstevel@tonic-gate ftsn_entry = (ftsn_entry_t *)(ftsn + 1); 21040Sstevel@tonic-gate while (remaining >= sizeof (*ftsn_entry)) { 21050Sstevel@tonic-gate ftsn_entry->ftsn_sid = ntohs(ftsn_entry->ftsn_sid); 21060Sstevel@tonic-gate ftsn_entry->ftsn_ssn = ntohs(ftsn_entry->ftsn_ssn); 21070Sstevel@tonic-gate if (ftsn_entry->ftsn_sid >= sctp->sctp_num_istr) { 21080Sstevel@tonic-gate uint16_t inval_parm[2]; 21090Sstevel@tonic-gate 21100Sstevel@tonic-gate inval_parm[0] = htons(ftsn_entry->ftsn_sid); 21110Sstevel@tonic-gate /* RESERVED to be ignored at the receiving end */ 21120Sstevel@tonic-gate inval_parm[1] = 0; 21134964Skcpoon sctp_add_err(sctp, SCTP_ERR_BAD_SID, inval_parm, 21144964Skcpoon sizeof (inval_parm), fp); 21150Sstevel@tonic-gate ftsn_entry++; 21160Sstevel@tonic-gate remaining -= sizeof (*ftsn_entry); 21170Sstevel@tonic-gate continue; 21180Sstevel@tonic-gate } 21190Sstevel@tonic-gate instr = &sctp->sctp_instr[ftsn_entry->ftsn_sid]; 21200Sstevel@tonic-gate flen = sctp_ftsn_check_frag(sctp, ftsn_entry->ftsn_ssn, instr); 21210Sstevel@tonic-gate /* Indicates frags were nuked, update rxqueued */ 21220Sstevel@tonic-gate if (flen > 0) { 21230Sstevel@tonic-gate ASSERT(sctp->sctp_rxqueued >= flen); 21240Sstevel@tonic-gate sctp->sctp_rxqueued -= flen; 21250Sstevel@tonic-gate } 21260Sstevel@tonic-gate /* 21270Sstevel@tonic-gate * It is possible to receive an FTSN chunk with SSN smaller 21280Sstevel@tonic-gate * than then nextseq if this chunk is a retransmission because 21290Sstevel@tonic-gate * of incomplete processing when it was first processed. 21300Sstevel@tonic-gate */ 21310Sstevel@tonic-gate if (SSN_GE(ftsn_entry->ftsn_ssn, instr->nextseq)) 21320Sstevel@tonic-gate instr->nextseq = ftsn_entry->ftsn_ssn + 1; 21330Sstevel@tonic-gate while (instr->istr_nmsgs > 0) { 21340Sstevel@tonic-gate mblk_t *next; 21350Sstevel@tonic-gate 21360Sstevel@tonic-gate dmp = (mblk_t *)instr->istr_msgs; 21370Sstevel@tonic-gate dc = (sctp_data_hdr_t *)dmp->b_rptr; 21380Sstevel@tonic-gate if (ntohs(dc->sdh_ssn) != instr->nextseq) 21390Sstevel@tonic-gate break; 21400Sstevel@tonic-gate 21410Sstevel@tonic-gate next = dmp->b_next; 21420Sstevel@tonic-gate dlen = dmp->b_wptr - dmp->b_rptr - sizeof (*dc); 21430Sstevel@tonic-gate for (pmp = dmp->b_cont; pmp != NULL; 21440Sstevel@tonic-gate pmp = pmp->b_cont) { 21450Sstevel@tonic-gate dlen += pmp->b_wptr - pmp->b_rptr; 21460Sstevel@tonic-gate } 21470Sstevel@tonic-gate if (can_deliver) { 21480Sstevel@tonic-gate int32_t nrwnd; 2149*8348SEric.Yu@Sun.COM int error; 21500Sstevel@tonic-gate 21510Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)(dc + 1); 21520Sstevel@tonic-gate dmp->b_next = NULL; 21530Sstevel@tonic-gate ASSERT(dmp->b_prev == NULL); 21540Sstevel@tonic-gate if (sctp_input_add_ancillary(sctp, 21550Sstevel@tonic-gate &dmp, dc, fp, ipp) == 0) { 21560Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 21570Sstevel@tonic-gate sctp->sctp_rwnd -= dlen; 2158*8348SEric.Yu@Sun.COM /* 2159*8348SEric.Yu@Sun.COM * Override b_flag for SCTP sockfs 2160*8348SEric.Yu@Sun.COM * internal use 2161*8348SEric.Yu@Sun.COM */ 2162*8348SEric.Yu@Sun.COM 2163*8348SEric.Yu@Sun.COM dmp->b_flag = 0; 21640Sstevel@tonic-gate nrwnd = sctp->sctp_ulp_recv( 2165*8348SEric.Yu@Sun.COM sctp->sctp_ulpd, dmp, msgdsize(dmp), 2166*8348SEric.Yu@Sun.COM 0, &error, NULL); 21670Sstevel@tonic-gate if (nrwnd > sctp->sctp_rwnd) 21680Sstevel@tonic-gate sctp->sctp_rwnd = nrwnd; 21690Sstevel@tonic-gate } else { 21700Sstevel@tonic-gate /* 21710Sstevel@tonic-gate * We will resume processing when 21720Sstevel@tonic-gate * the FTSN chunk is re-xmitted. 21730Sstevel@tonic-gate */ 21740Sstevel@tonic-gate dmp->b_rptr = (uchar_t *)dc; 21750Sstevel@tonic-gate dmp->b_next = next; 21760Sstevel@tonic-gate dprint(0, 21770Sstevel@tonic-gate ("FTSN dequeuing %u failed\n", 21780Sstevel@tonic-gate ntohs(dc->sdh_ssn))); 21790Sstevel@tonic-gate return; 21800Sstevel@tonic-gate } 21810Sstevel@tonic-gate } else { 21820Sstevel@tonic-gate sctp->sctp_rxqueued -= dlen; 21830Sstevel@tonic-gate ASSERT(dmp->b_prev == NULL); 21840Sstevel@tonic-gate dmp->b_next = NULL; 21850Sstevel@tonic-gate freemsg(dmp); 21860Sstevel@tonic-gate } 21870Sstevel@tonic-gate instr->istr_nmsgs--; 21880Sstevel@tonic-gate instr->nextseq++; 21890Sstevel@tonic-gate sctp->sctp_istr_nmsgs--; 21900Sstevel@tonic-gate if (next != NULL) 21910Sstevel@tonic-gate next->b_prev = NULL; 21920Sstevel@tonic-gate instr->istr_msgs = next; 21930Sstevel@tonic-gate } 21940Sstevel@tonic-gate ftsn_entry++; 21950Sstevel@tonic-gate remaining -= sizeof (*ftsn_entry); 21960Sstevel@tonic-gate } 21970Sstevel@tonic-gate /* Duplicate FTSN */ 21980Sstevel@tonic-gate if (*ftsn <= (sctp->sctp_ftsn - 1)) { 21990Sstevel@tonic-gate sctp->sctp_force_sack = 1; 22000Sstevel@tonic-gate return; 22010Sstevel@tonic-gate } 22020Sstevel@tonic-gate /* Advance cum TSN to that reported in the Forward TSN chunk */ 22030Sstevel@tonic-gate sctp->sctp_ftsn = *ftsn + 1; 22040Sstevel@tonic-gate 22050Sstevel@tonic-gate /* Remove all the SACK gaps before the new cum TSN */ 22060Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL) { 22070Sstevel@tonic-gate sctp_ack_rem(&sctp->sctp_sack_info, sctp->sctp_ftsn - 1, 22080Sstevel@tonic-gate &sctp->sctp_sack_gaps); 22090Sstevel@tonic-gate } 22100Sstevel@tonic-gate /* 22110Sstevel@tonic-gate * If there are gap reports pending, check if advancing 22120Sstevel@tonic-gate * the ftsn here closes a gap. If so, we can advance 22130Sstevel@tonic-gate * ftsn to the end of the set. 22140Sstevel@tonic-gate * If ftsn has moved forward, maybe we can remove gap reports. 22150Sstevel@tonic-gate */ 22160Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL && 22170Sstevel@tonic-gate sctp->sctp_ftsn == sctp->sctp_sack_info->begin) { 22180Sstevel@tonic-gate sctp->sctp_ftsn = sctp->sctp_sack_info->end + 1; 22190Sstevel@tonic-gate sctp_ack_rem(&sctp->sctp_sack_info, sctp->sctp_ftsn - 1, 22200Sstevel@tonic-gate &sctp->sctp_sack_gaps); 22210Sstevel@tonic-gate } 22220Sstevel@tonic-gate } 22230Sstevel@tonic-gate 22240Sstevel@tonic-gate /* 22250Sstevel@tonic-gate * When we have processed a SACK we check to see if we can advance the 22260Sstevel@tonic-gate * cumulative TSN if there are abandoned chunks immediately following 22270Sstevel@tonic-gate * the updated cumulative TSN. If there are, we attempt to send a 22280Sstevel@tonic-gate * Forward TSN chunk. 22290Sstevel@tonic-gate */ 22300Sstevel@tonic-gate static void 22310Sstevel@tonic-gate sctp_check_abandoned_data(sctp_t *sctp, sctp_faddr_t *fp) 22320Sstevel@tonic-gate { 22330Sstevel@tonic-gate mblk_t *meta = sctp->sctp_xmit_head; 22340Sstevel@tonic-gate mblk_t *mp; 22350Sstevel@tonic-gate mblk_t *nmp; 22360Sstevel@tonic-gate uint32_t seglen; 22370Sstevel@tonic-gate uint32_t adv_pap = sctp->sctp_adv_pap; 22380Sstevel@tonic-gate 22390Sstevel@tonic-gate /* 22400Sstevel@tonic-gate * We only check in the first meta since otherwise we can't 22410Sstevel@tonic-gate * advance the cumulative ack point. We just look for chunks 22420Sstevel@tonic-gate * marked for retransmission, else we might prematurely 22430Sstevel@tonic-gate * send an FTSN for a sent, but unacked, chunk. 22440Sstevel@tonic-gate */ 22450Sstevel@tonic-gate for (mp = meta->b_cont; mp != NULL; mp = mp->b_next) { 22460Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(mp)) 22470Sstevel@tonic-gate return; 22480Sstevel@tonic-gate if (SCTP_CHUNK_WANT_REXMIT(mp)) 22490Sstevel@tonic-gate break; 22500Sstevel@tonic-gate } 22510Sstevel@tonic-gate if (mp == NULL) 22520Sstevel@tonic-gate return; 22530Sstevel@tonic-gate sctp_check_adv_ack_pt(sctp, meta, mp); 22540Sstevel@tonic-gate if (SEQ_GT(sctp->sctp_adv_pap, adv_pap)) { 22550Sstevel@tonic-gate sctp_make_ftsns(sctp, meta, mp, &nmp, fp, &seglen); 22560Sstevel@tonic-gate if (nmp == NULL) { 22570Sstevel@tonic-gate sctp->sctp_adv_pap = adv_pap; 22580Sstevel@tonic-gate if (!fp->timer_running) 22590Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto); 22600Sstevel@tonic-gate return; 22610Sstevel@tonic-gate } 22620Sstevel@tonic-gate sctp_set_iplen(sctp, nmp); 22630Sstevel@tonic-gate sctp_add_sendq(sctp, nmp); 22640Sstevel@tonic-gate if (!fp->timer_running) 22650Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto); 22660Sstevel@tonic-gate } 22670Sstevel@tonic-gate } 22680Sstevel@tonic-gate 2269852Svi117747 /* 2270852Svi117747 * The processing here follows the same logic in sctp_got_sack(), the reason 2271852Svi117747 * we do this separately is because, usually, gap blocks are ordered and 2272852Svi117747 * we can process it in sctp_got_sack(). However if they aren't we would 2273852Svi117747 * need to do some additional non-optimal stuff when we start processing the 2274852Svi117747 * unordered gaps. To that effect sctp_got_sack() does the processing in the 2275852Svi117747 * simple case and this does the same in the more involved case. 2276852Svi117747 */ 2277852Svi117747 static uint32_t 2278852Svi117747 sctp_process_uo_gaps(sctp_t *sctp, uint32_t ctsn, sctp_sack_frag_t *ssf, 2279852Svi117747 int num_gaps, mblk_t *umphead, mblk_t *mphead, int *trysend, 2280852Svi117747 boolean_t *fast_recovery, uint32_t fr_xtsn) 2281852Svi117747 { 2282852Svi117747 uint32_t xtsn; 2283852Svi117747 uint32_t gapstart = 0; 2284852Svi117747 uint32_t gapend = 0; 2285852Svi117747 int gapcnt; 2286852Svi117747 uint16_t chunklen; 2287852Svi117747 sctp_data_hdr_t *sdc; 2288852Svi117747 int gstart; 2289852Svi117747 mblk_t *ump = umphead; 2290852Svi117747 mblk_t *mp = mphead; 2291852Svi117747 sctp_faddr_t *fp; 2292852Svi117747 uint32_t acked = 0; 22933448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 2294852Svi117747 2295852Svi117747 /* 2296852Svi117747 * gstart tracks the last (in the order of TSN) gapstart that 2297852Svi117747 * we process in this SACK gaps walk. 2298852Svi117747 */ 2299852Svi117747 gstart = ctsn; 2300852Svi117747 2301852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2302852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2303852Svi117747 for (gapcnt = 0; gapcnt < num_gaps; gapcnt++, ssf++) { 2304852Svi117747 if (gapstart != 0) { 2305852Svi117747 /* 2306852Svi117747 * If we have reached the end of the transmit list or 2307852Svi117747 * hit an unsent chunk or encountered an unordered gap 2308852Svi117747 * block start from the ctsn again. 2309852Svi117747 */ 2310852Svi117747 if (ump == NULL || !SCTP_CHUNK_ISSENT(mp) || 2311852Svi117747 SEQ_LT(ctsn + ntohs(ssf->ssf_start), xtsn)) { 2312852Svi117747 ump = umphead; 2313852Svi117747 mp = mphead; 2314852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2315852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2316852Svi117747 } 2317852Svi117747 } 2318852Svi117747 2319852Svi117747 gapstart = ctsn + ntohs(ssf->ssf_start); 2320852Svi117747 gapend = ctsn + ntohs(ssf->ssf_end); 2321852Svi117747 2322852Svi117747 /* SACK for TSN we have not sent - ABORT */ 2323852Svi117747 if (SEQ_GT(gapstart, sctp->sctp_ltsn - 1) || 2324852Svi117747 SEQ_GT(gapend, sctp->sctp_ltsn - 1)) { 23253448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInAckUnsent); 2326852Svi117747 *trysend = -1; 2327852Svi117747 return (acked); 2328852Svi117747 } else if (SEQ_LT(gapend, gapstart)) { 2329852Svi117747 break; 2330852Svi117747 } 2331852Svi117747 /* 2332852Svi117747 * The xtsn can be the TSN processed for the last gap 2333852Svi117747 * (gapend) or it could be the cumulative TSN. We continue 2334852Svi117747 * with the last xtsn as long as the gaps are ordered, when 2335852Svi117747 * we hit an unordered gap, we re-start from the cumulative 2336852Svi117747 * TSN. For the first gap it is always the cumulative TSN. 2337852Svi117747 */ 2338852Svi117747 while (xtsn != gapstart) { 2339852Svi117747 /* 2340852Svi117747 * We can't reliably check for reneged chunks 2341852Svi117747 * when walking the unordered list, so we don't. 2342852Svi117747 * In case the peer reneges then we will end up 2343852Svi117747 * sending the reneged chunk via timeout. 2344852Svi117747 */ 2345852Svi117747 mp = mp->b_next; 2346852Svi117747 if (mp == NULL) { 2347852Svi117747 ump = ump->b_next; 2348852Svi117747 /* 2349852Svi117747 * ump can't be NULL because of the sanity 2350852Svi117747 * check above. 2351852Svi117747 */ 2352852Svi117747 ASSERT(ump != NULL); 2353852Svi117747 mp = ump->b_cont; 2354852Svi117747 } 2355852Svi117747 /* 2356852Svi117747 * mp can't be unsent because of the sanity check 2357852Svi117747 * above. 2358852Svi117747 */ 2359852Svi117747 ASSERT(SCTP_CHUNK_ISSENT(mp)); 2360852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2361852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2362852Svi117747 } 2363852Svi117747 /* 2364852Svi117747 * Now that we have found the chunk with TSN == 'gapstart', 2365852Svi117747 * let's walk till we hit the chunk with TSN == 'gapend'. 2366852Svi117747 * All intermediate chunks will be marked ACKED, if they 2367852Svi117747 * haven't already been. 2368852Svi117747 */ 2369852Svi117747 while (SEQ_LEQ(xtsn, gapend)) { 2370852Svi117747 /* 2371852Svi117747 * SACKed 2372852Svi117747 */ 2373852Svi117747 SCTP_CHUNK_SET_SACKCNT(mp, 0); 2374852Svi117747 if (!SCTP_CHUNK_ISACKED(mp)) { 2375852Svi117747 SCTP_CHUNK_ACKED(mp); 2376852Svi117747 2377852Svi117747 fp = SCTP_CHUNK_DEST(mp); 2378852Svi117747 chunklen = ntohs(sdc->sdh_len); 2379852Svi117747 ASSERT(fp->suna >= chunklen); 2380852Svi117747 fp->suna -= chunklen; 2381852Svi117747 if (fp->suna == 0) { 2382852Svi117747 /* All outstanding data acked. */ 2383852Svi117747 fp->pba = 0; 2384852Svi117747 SCTP_FADDR_TIMER_STOP(fp); 2385852Svi117747 } 2386852Svi117747 fp->acked += chunklen; 2387852Svi117747 acked += chunklen; 2388852Svi117747 sctp->sctp_unacked -= chunklen - sizeof (*sdc); 2389852Svi117747 ASSERT(sctp->sctp_unacked >= 0); 2390852Svi117747 } 2391852Svi117747 /* 2392852Svi117747 * Move to the next message in the transmit list 2393852Svi117747 * if we are done with all the chunks from the current 2394852Svi117747 * message. Note, it is possible to hit the end of the 2395852Svi117747 * transmit list here, i.e. if we have already completed 2396852Svi117747 * processing the gap block. 2397852Svi117747 */ 2398852Svi117747 mp = mp->b_next; 2399852Svi117747 if (mp == NULL) { 2400852Svi117747 ump = ump->b_next; 2401852Svi117747 if (ump == NULL) { 2402852Svi117747 ASSERT(xtsn == gapend); 2403852Svi117747 break; 2404852Svi117747 } 2405852Svi117747 mp = ump->b_cont; 2406852Svi117747 } 2407852Svi117747 /* 2408852Svi117747 * Likewise, we can hit an unsent chunk once we have 2409852Svi117747 * completed processing the gap block. 2410852Svi117747 */ 2411852Svi117747 if (!SCTP_CHUNK_ISSENT(mp)) { 2412852Svi117747 ASSERT(xtsn == gapend); 2413852Svi117747 break; 2414852Svi117747 } 2415852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2416852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2417852Svi117747 } 2418852Svi117747 /* 2419852Svi117747 * We keep track of the last gap we successfully processed 2420852Svi117747 * so that we can terminate the walk below for incrementing 2421852Svi117747 * the SACK count. 2422852Svi117747 */ 2423852Svi117747 if (SEQ_LT(gstart, gapstart)) 2424852Svi117747 gstart = gapstart; 2425852Svi117747 } 2426852Svi117747 /* 2427852Svi117747 * Check if have incremented the SACK count for all unacked TSNs in 2428852Svi117747 * sctp_got_sack(), if so we are done. 2429852Svi117747 */ 2430852Svi117747 if (SEQ_LEQ(gstart, fr_xtsn)) 2431852Svi117747 return (acked); 2432852Svi117747 2433852Svi117747 ump = umphead; 2434852Svi117747 mp = mphead; 2435852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2436852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2437852Svi117747 while (SEQ_LT(xtsn, gstart)) { 2438852Svi117747 /* 2439852Svi117747 * We have incremented SACK count for TSNs less than fr_tsn 2440852Svi117747 * in sctp_got_sack(), so don't increment them again here. 2441852Svi117747 */ 2442852Svi117747 if (SEQ_GT(xtsn, fr_xtsn) && !SCTP_CHUNK_ISACKED(mp)) { 2443852Svi117747 SCTP_CHUNK_SET_SACKCNT(mp, SCTP_CHUNK_SACKCNT(mp) + 1); 24443448Sdh155122 if (SCTP_CHUNK_SACKCNT(mp) == 24453448Sdh155122 sctps->sctps_fast_rxt_thresh) { 2446852Svi117747 SCTP_CHUNK_REXMIT(mp); 2447852Svi117747 sctp->sctp_chk_fast_rexmit = B_TRUE; 2448852Svi117747 *trysend = 1; 2449852Svi117747 if (!*fast_recovery) { 2450852Svi117747 /* 2451852Svi117747 * Entering fast recovery. 2452852Svi117747 */ 2453852Svi117747 fp = SCTP_CHUNK_DEST(mp); 2454852Svi117747 fp->ssthresh = fp->cwnd / 2; 2455852Svi117747 if (fp->ssthresh < 2 * fp->sfa_pmss) { 2456852Svi117747 fp->ssthresh = 2457852Svi117747 2 * fp->sfa_pmss; 2458852Svi117747 } 2459852Svi117747 fp->cwnd = fp->ssthresh; 2460852Svi117747 fp->pba = 0; 2461852Svi117747 sctp->sctp_recovery_tsn = 2462852Svi117747 sctp->sctp_ltsn - 1; 2463852Svi117747 *fast_recovery = B_TRUE; 2464852Svi117747 } 2465852Svi117747 } 2466852Svi117747 } 2467852Svi117747 mp = mp->b_next; 2468852Svi117747 if (mp == NULL) { 2469852Svi117747 ump = ump->b_next; 2470852Svi117747 /* We can't get to the end of the transmit list here */ 2471852Svi117747 ASSERT(ump != NULL); 2472852Svi117747 mp = ump->b_cont; 2473852Svi117747 } 2474852Svi117747 /* We can't hit an unsent chunk here */ 2475852Svi117747 ASSERT(SCTP_CHUNK_ISSENT(mp)); 2476852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2477852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2478852Svi117747 } 2479852Svi117747 return (acked); 2480852Svi117747 } 2481852Svi117747 24820Sstevel@tonic-gate static int 24830Sstevel@tonic-gate sctp_got_sack(sctp_t *sctp, sctp_chunk_hdr_t *sch) 24840Sstevel@tonic-gate { 24850Sstevel@tonic-gate sctp_sack_chunk_t *sc; 24860Sstevel@tonic-gate sctp_data_hdr_t *sdc; 24870Sstevel@tonic-gate sctp_sack_frag_t *ssf; 24880Sstevel@tonic-gate mblk_t *ump; 24890Sstevel@tonic-gate mblk_t *mp; 2490852Svi117747 mblk_t *mp1; 2491852Svi117747 uint32_t cumtsn; 24920Sstevel@tonic-gate uint32_t xtsn; 2493852Svi117747 uint32_t gapstart = 0; 2494852Svi117747 uint32_t gapend = 0; 24950Sstevel@tonic-gate uint32_t acked = 0; 24960Sstevel@tonic-gate uint16_t chunklen; 24970Sstevel@tonic-gate sctp_faddr_t *fp; 24980Sstevel@tonic-gate int num_gaps; 24990Sstevel@tonic-gate int trysend = 0; 25000Sstevel@tonic-gate int i; 25010Sstevel@tonic-gate boolean_t fast_recovery = B_FALSE; 25020Sstevel@tonic-gate boolean_t cumack_forward = B_FALSE; 25030Sstevel@tonic-gate boolean_t fwd_tsn = B_FALSE; 25043448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 25050Sstevel@tonic-gate 25060Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 25070Sstevel@tonic-gate chunklen = ntohs(sch->sch_len); 25080Sstevel@tonic-gate if (chunklen < (sizeof (*sch) + sizeof (*sc))) 25090Sstevel@tonic-gate return (0); 25100Sstevel@tonic-gate 25110Sstevel@tonic-gate sc = (sctp_sack_chunk_t *)(sch + 1); 2512852Svi117747 cumtsn = ntohl(sc->ssc_cumtsn); 2513852Svi117747 2514852Svi117747 dprint(2, ("got sack cumtsn %x -> %x\n", sctp->sctp_lastack_rxd, 2515852Svi117747 cumtsn)); 25160Sstevel@tonic-gate 25170Sstevel@tonic-gate /* out of order */ 2518852Svi117747 if (SEQ_LT(cumtsn, sctp->sctp_lastack_rxd)) 25190Sstevel@tonic-gate return (0); 25200Sstevel@tonic-gate 2521852Svi117747 if (SEQ_GT(cumtsn, sctp->sctp_ltsn - 1)) { 25223448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInAckUnsent); 2523852Svi117747 /* Send an ABORT */ 2524852Svi117747 return (-1); 25250Sstevel@tonic-gate } 25260Sstevel@tonic-gate 25270Sstevel@tonic-gate /* 25280Sstevel@tonic-gate * Cwnd only done when not in fast recovery mode. 25290Sstevel@tonic-gate */ 25300Sstevel@tonic-gate if (SEQ_LT(sctp->sctp_lastack_rxd, sctp->sctp_recovery_tsn)) 25310Sstevel@tonic-gate fast_recovery = B_TRUE; 25320Sstevel@tonic-gate 25330Sstevel@tonic-gate /* 25340Sstevel@tonic-gate * .. and if the cum TSN is not moving ahead on account Forward TSN 25350Sstevel@tonic-gate */ 25360Sstevel@tonic-gate if (SEQ_LT(sctp->sctp_lastack_rxd, sctp->sctp_adv_pap)) 25370Sstevel@tonic-gate fwd_tsn = B_TRUE; 25380Sstevel@tonic-gate 2539852Svi117747 if (cumtsn == sctp->sctp_lastack_rxd && 25400Sstevel@tonic-gate (sctp->sctp_xmit_unacked == NULL || 25410Sstevel@tonic-gate !SCTP_CHUNK_ABANDONED(sctp->sctp_xmit_unacked))) { 25420Sstevel@tonic-gate if (sctp->sctp_xmit_unacked != NULL) 25430Sstevel@tonic-gate mp = sctp->sctp_xmit_unacked; 25440Sstevel@tonic-gate else if (sctp->sctp_xmit_head != NULL) 25450Sstevel@tonic-gate mp = sctp->sctp_xmit_head->b_cont; 25460Sstevel@tonic-gate else 25470Sstevel@tonic-gate mp = NULL; 25483448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInDupAck); 25491932Svi117747 /* 25501932Svi117747 * If we were doing a zero win probe and the win 25511932Svi117747 * has now opened to at least MSS, re-transmit the 25521932Svi117747 * zero win probe via sctp_rexmit_packet(). 25531932Svi117747 */ 25541932Svi117747 if (mp != NULL && sctp->sctp_zero_win_probe && 25551932Svi117747 ntohl(sc->ssc_a_rwnd) >= sctp->sctp_current->sfa_pmss) { 25561932Svi117747 mblk_t *pkt; 25571932Svi117747 uint_t pkt_len; 25581932Svi117747 mblk_t *mp1 = mp; 25591932Svi117747 mblk_t *meta = sctp->sctp_xmit_head; 25601932Svi117747 25611932Svi117747 /* 25621932Svi117747 * Reset the RTO since we have been backing-off 25631932Svi117747 * to send the ZWP. 25641932Svi117747 */ 25651932Svi117747 fp = sctp->sctp_current; 25661932Svi117747 fp->rto = fp->srtt + 4 * fp->rttvar; 25671932Svi117747 /* Resend the ZWP */ 25681932Svi117747 pkt = sctp_rexmit_packet(sctp, &meta, &mp1, fp, 25691932Svi117747 &pkt_len); 25701932Svi117747 if (pkt == NULL) { 25713448Sdh155122 SCTP_KSTAT(sctps, sctp_ss_rexmit_failed); 25721932Svi117747 return (0); 25731932Svi117747 } 25741932Svi117747 ASSERT(pkt_len <= fp->sfa_pmss); 25751932Svi117747 sctp->sctp_zero_win_probe = B_FALSE; 25761932Svi117747 sctp->sctp_rxt_nxttsn = sctp->sctp_ltsn; 25771932Svi117747 sctp->sctp_rxt_maxtsn = sctp->sctp_ltsn; 25781932Svi117747 sctp_set_iplen(sctp, pkt); 25791932Svi117747 sctp_add_sendq(sctp, pkt); 25801932Svi117747 } 25810Sstevel@tonic-gate } else { 25821932Svi117747 if (sctp->sctp_zero_win_probe) { 25831932Svi117747 /* 25841932Svi117747 * Reset the RTO since we have been backing-off 25851932Svi117747 * to send the ZWP. 25861932Svi117747 */ 25871932Svi117747 fp = sctp->sctp_current; 25881932Svi117747 fp->rto = fp->srtt + 4 * fp->rttvar; 25891932Svi117747 sctp->sctp_zero_win_probe = B_FALSE; 25901932Svi117747 /* This is probably not required */ 25911932Svi117747 if (!sctp->sctp_rexmitting) { 25921932Svi117747 sctp->sctp_rxt_nxttsn = sctp->sctp_ltsn; 25931932Svi117747 sctp->sctp_rxt_maxtsn = sctp->sctp_ltsn; 25941932Svi117747 } 25951932Svi117747 } 2596852Svi117747 acked = sctp_cumack(sctp, cumtsn, &mp); 25970Sstevel@tonic-gate sctp->sctp_xmit_unacked = mp; 25980Sstevel@tonic-gate if (acked > 0) { 25990Sstevel@tonic-gate trysend = 1; 26000Sstevel@tonic-gate cumack_forward = B_TRUE; 26010Sstevel@tonic-gate if (fwd_tsn && SEQ_GEQ(sctp->sctp_lastack_rxd, 26020Sstevel@tonic-gate sctp->sctp_adv_pap)) { 26030Sstevel@tonic-gate cumack_forward = B_FALSE; 26040Sstevel@tonic-gate } 26050Sstevel@tonic-gate } 26060Sstevel@tonic-gate } 26070Sstevel@tonic-gate num_gaps = ntohs(sc->ssc_numfrags); 26080Sstevel@tonic-gate if (num_gaps == 0 || mp == NULL || !SCTP_CHUNK_ISSENT(mp) || 26090Sstevel@tonic-gate chunklen < (sizeof (*sch) + sizeof (*sc) + 26100Sstevel@tonic-gate num_gaps * sizeof (*ssf))) { 26110Sstevel@tonic-gate goto ret; 26120Sstevel@tonic-gate } 2613852Svi117747 #ifdef DEBUG 2614852Svi117747 /* 2615852Svi117747 * Since we delete any message that has been acked completely, 2616852Svi117747 * the unacked chunk must belong to sctp_xmit_head (as 2617852Svi117747 * we don't have a back pointer from the mp to the meta data 2618852Svi117747 * we do this). 2619852Svi117747 */ 2620852Svi117747 { 2621852Svi117747 mblk_t *mp2 = sctp->sctp_xmit_head->b_cont; 2622852Svi117747 2623852Svi117747 while (mp2 != NULL) { 2624852Svi117747 if (mp2 == mp) 2625852Svi117747 break; 2626852Svi117747 mp2 = mp2->b_next; 2627852Svi117747 } 2628852Svi117747 ASSERT(mp2 != NULL); 2629852Svi117747 } 2630852Svi117747 #endif 26310Sstevel@tonic-gate ump = sctp->sctp_xmit_head; 26320Sstevel@tonic-gate 26330Sstevel@tonic-gate /* 2634852Svi117747 * Just remember where we started from, in case we need to call 2635852Svi117747 * sctp_process_uo_gaps() if the gap blocks are unordered. 2636852Svi117747 */ 2637852Svi117747 mp1 = mp; 2638852Svi117747 2639852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2640852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2641852Svi117747 ASSERT(xtsn == cumtsn + 1); 2642852Svi117747 2643852Svi117747 /* 26440Sstevel@tonic-gate * Go through SACK gaps. They are ordered based on start TSN. 26450Sstevel@tonic-gate */ 26460Sstevel@tonic-gate ssf = (sctp_sack_frag_t *)(sc + 1); 2647852Svi117747 for (i = 0; i < num_gaps; i++, ssf++) { 2648852Svi117747 if (gapstart != 0) { 2649852Svi117747 /* check for unordered gap */ 2650852Svi117747 if (SEQ_LEQ(cumtsn + ntohs(ssf->ssf_start), gapstart)) { 2651852Svi117747 acked += sctp_process_uo_gaps(sctp, 2652852Svi117747 cumtsn, ssf, num_gaps - i, 2653852Svi117747 sctp->sctp_xmit_head, mp1, 2654852Svi117747 &trysend, &fast_recovery, gapstart); 2655852Svi117747 if (trysend < 0) { 26563448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 26573448Sdh155122 sctpInAckUnsent); 2658852Svi117747 return (-1); 2659852Svi117747 } 2660852Svi117747 break; 2661852Svi117747 } 2662852Svi117747 } 2663852Svi117747 gapstart = cumtsn + ntohs(ssf->ssf_start); 2664852Svi117747 gapend = cumtsn + ntohs(ssf->ssf_end); 2665852Svi117747 2666852Svi117747 /* SACK for TSN we have not sent - ABORT */ 2667852Svi117747 if (SEQ_GT(gapstart, sctp->sctp_ltsn - 1) || 2668852Svi117747 SEQ_GT(gapend, sctp->sctp_ltsn - 1)) { 26693448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInAckUnsent); 2670852Svi117747 return (-1); 2671852Svi117747 } else if (SEQ_LT(gapend, gapstart)) { 2672852Svi117747 break; 2673852Svi117747 } 2674852Svi117747 /* 2675852Svi117747 * Let's start at the current TSN (for the 1st gap we start 2676852Svi117747 * from the cumulative TSN, for subsequent ones we start from 2677852Svi117747 * where the previous gapend was found - second while loop 2678852Svi117747 * below) and walk the transmit list till we find the TSN 2679852Svi117747 * corresponding to gapstart. All the unacked chunks till we 2680852Svi117747 * get to the chunk with TSN == gapstart will have their 2681852Svi117747 * SACKCNT incremented by 1. Note since the gap blocks are 2682852Svi117747 * ordered, we won't be incrementing the SACKCNT for an 2683852Svi117747 * unacked chunk by more than one while processing the gap 2684852Svi117747 * blocks. If the SACKCNT for any unacked chunk exceeds 2685852Svi117747 * the fast retransmit threshold, we will fast retransmit 2686852Svi117747 * after processing all the gap blocks. 2687852Svi117747 */ 2688852Svi117747 ASSERT(SEQ_LT(xtsn, gapstart)); 26890Sstevel@tonic-gate while (xtsn != gapstart) { 26900Sstevel@tonic-gate SCTP_CHUNK_SET_SACKCNT(mp, SCTP_CHUNK_SACKCNT(mp) + 1); 26913448Sdh155122 if (SCTP_CHUNK_SACKCNT(mp) == 26923448Sdh155122 sctps->sctps_fast_rxt_thresh) { 26930Sstevel@tonic-gate SCTP_CHUNK_REXMIT(mp); 26940Sstevel@tonic-gate sctp->sctp_chk_fast_rexmit = B_TRUE; 26950Sstevel@tonic-gate trysend = 1; 26960Sstevel@tonic-gate if (!fast_recovery) { 26970Sstevel@tonic-gate /* 26980Sstevel@tonic-gate * Entering fast recovery. 26990Sstevel@tonic-gate */ 27000Sstevel@tonic-gate fp = SCTP_CHUNK_DEST(mp); 27010Sstevel@tonic-gate fp->ssthresh = fp->cwnd / 2; 27020Sstevel@tonic-gate if (fp->ssthresh < 2 * fp->sfa_pmss) { 27030Sstevel@tonic-gate fp->ssthresh = 27040Sstevel@tonic-gate 2 * fp->sfa_pmss; 27050Sstevel@tonic-gate } 27060Sstevel@tonic-gate fp->cwnd = fp->ssthresh; 27070Sstevel@tonic-gate fp->pba = 0; 27080Sstevel@tonic-gate sctp->sctp_recovery_tsn = 27090Sstevel@tonic-gate sctp->sctp_ltsn - 1; 27100Sstevel@tonic-gate fast_recovery = B_TRUE; 27110Sstevel@tonic-gate } 27120Sstevel@tonic-gate } 27130Sstevel@tonic-gate 27140Sstevel@tonic-gate /* 27150Sstevel@tonic-gate * Peer may have reneged on this chunk, so un-sack 27160Sstevel@tonic-gate * it now. If the peer did renege, we need to 27170Sstevel@tonic-gate * readjust unacked. 27180Sstevel@tonic-gate */ 27190Sstevel@tonic-gate if (SCTP_CHUNK_ISACKED(mp)) { 27200Sstevel@tonic-gate chunklen = ntohs(sdc->sdh_len); 27210Sstevel@tonic-gate fp = SCTP_CHUNK_DEST(mp); 27220Sstevel@tonic-gate fp->suna += chunklen; 27230Sstevel@tonic-gate sctp->sctp_unacked += chunklen - sizeof (*sdc); 27240Sstevel@tonic-gate SCTP_CHUNK_CLEAR_ACKED(mp); 27250Sstevel@tonic-gate if (!fp->timer_running) { 27260Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, 27270Sstevel@tonic-gate fp->rto); 27280Sstevel@tonic-gate } 27290Sstevel@tonic-gate } 27300Sstevel@tonic-gate 27310Sstevel@tonic-gate mp = mp->b_next; 27320Sstevel@tonic-gate if (mp == NULL) { 27330Sstevel@tonic-gate ump = ump->b_next; 2734852Svi117747 /* 2735852Svi117747 * ump can't be NULL given the sanity check 2736852Svi117747 * above. 2737852Svi117747 */ 2738852Svi117747 ASSERT(ump != NULL); 27390Sstevel@tonic-gate mp = ump->b_cont; 27400Sstevel@tonic-gate } 2741852Svi117747 /* 2742852Svi117747 * mp can't be unsent given the sanity check above. 2743852Svi117747 */ 2744852Svi117747 ASSERT(SCTP_CHUNK_ISSENT(mp)); 27450Sstevel@tonic-gate sdc = (sctp_data_hdr_t *)mp->b_rptr; 27460Sstevel@tonic-gate xtsn = ntohl(sdc->sdh_tsn); 27470Sstevel@tonic-gate } 2748852Svi117747 /* 2749852Svi117747 * Now that we have found the chunk with TSN == 'gapstart', 2750852Svi117747 * let's walk till we hit the chunk with TSN == 'gapend'. 2751852Svi117747 * All intermediate chunks will be marked ACKED, if they 2752852Svi117747 * haven't already been. 2753852Svi117747 */ 27540Sstevel@tonic-gate while (SEQ_LEQ(xtsn, gapend)) { 27550Sstevel@tonic-gate /* 27560Sstevel@tonic-gate * SACKed 27570Sstevel@tonic-gate */ 27580Sstevel@tonic-gate SCTP_CHUNK_SET_SACKCNT(mp, 0); 27590Sstevel@tonic-gate if (!SCTP_CHUNK_ISACKED(mp)) { 27600Sstevel@tonic-gate SCTP_CHUNK_ACKED(mp); 27610Sstevel@tonic-gate 27620Sstevel@tonic-gate fp = SCTP_CHUNK_DEST(mp); 27630Sstevel@tonic-gate chunklen = ntohs(sdc->sdh_len); 27640Sstevel@tonic-gate ASSERT(fp->suna >= chunklen); 27650Sstevel@tonic-gate fp->suna -= chunklen; 27660Sstevel@tonic-gate if (fp->suna == 0) { 27670Sstevel@tonic-gate /* All outstanding data acked. */ 27680Sstevel@tonic-gate fp->pba = 0; 27690Sstevel@tonic-gate SCTP_FADDR_TIMER_STOP(fp); 27700Sstevel@tonic-gate } 27710Sstevel@tonic-gate fp->acked += chunklen; 27720Sstevel@tonic-gate acked += chunklen; 27730Sstevel@tonic-gate sctp->sctp_unacked -= chunklen - sizeof (*sdc); 27740Sstevel@tonic-gate ASSERT(sctp->sctp_unacked >= 0); 27750Sstevel@tonic-gate } 2776852Svi117747 /* Go to the next chunk of the current message */ 27770Sstevel@tonic-gate mp = mp->b_next; 2778852Svi117747 /* 2779852Svi117747 * Move to the next message in the transmit list 2780852Svi117747 * if we are done with all the chunks from the current 2781852Svi117747 * message. Note, it is possible to hit the end of the 2782852Svi117747 * transmit list here, i.e. if we have already completed 2783852Svi117747 * processing the gap block. 2784852Svi117747 * Also, note that we break here, which means we 2785852Svi117747 * continue processing gap blocks, if any. In case of 2786852Svi117747 * ordered gap blocks there can't be any following 2787852Svi117747 * this (if there is it will fail the sanity check 2788852Svi117747 * above). In case of un-ordered gap blocks we will 2789852Svi117747 * switch to sctp_process_uo_gaps(). In either case 2790852Svi117747 * it should be fine to continue with NULL ump/mp, 2791852Svi117747 * but we just reset it to xmit_head. 2792852Svi117747 */ 27930Sstevel@tonic-gate if (mp == NULL) { 27940Sstevel@tonic-gate ump = ump->b_next; 27950Sstevel@tonic-gate if (ump == NULL) { 2796852Svi117747 ASSERT(xtsn == gapend); 2797852Svi117747 ump = sctp->sctp_xmit_head; 2798852Svi117747 mp = mp1; 2799852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2800852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2801852Svi117747 break; 28020Sstevel@tonic-gate } 28030Sstevel@tonic-gate mp = ump->b_cont; 28040Sstevel@tonic-gate } 2805852Svi117747 /* 2806852Svi117747 * Likewise, we could hit an unsent chunk once we have 2807852Svi117747 * completed processing the gap block. Again, it is 2808852Svi117747 * fine to continue processing gap blocks with mp 2809852Svi117747 * pointing to the unsent chunk, because if there 2810852Svi117747 * are more ordered gap blocks, they will fail the 2811852Svi117747 * sanity check, and if there are un-ordered gap blocks, 2812852Svi117747 * we will continue processing in sctp_process_uo_gaps() 2813852Svi117747 * We just reset the mp to the one we started with. 2814852Svi117747 */ 28150Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(mp)) { 2816852Svi117747 ASSERT(xtsn == gapend); 2817852Svi117747 ump = sctp->sctp_xmit_head; 2818852Svi117747 mp = mp1; 2819852Svi117747 sdc = (sctp_data_hdr_t *)mp->b_rptr; 2820852Svi117747 xtsn = ntohl(sdc->sdh_tsn); 2821852Svi117747 break; 28220Sstevel@tonic-gate } 28230Sstevel@tonic-gate sdc = (sctp_data_hdr_t *)mp->b_rptr; 28240Sstevel@tonic-gate xtsn = ntohl(sdc->sdh_tsn); 28250Sstevel@tonic-gate } 28260Sstevel@tonic-gate } 28270Sstevel@tonic-gate if (sctp->sctp_prsctp_aware) 28280Sstevel@tonic-gate sctp_check_abandoned_data(sctp, sctp->sctp_current); 28290Sstevel@tonic-gate if (sctp->sctp_chk_fast_rexmit) 28300Sstevel@tonic-gate sctp_fast_rexmit(sctp); 28310Sstevel@tonic-gate ret: 28320Sstevel@tonic-gate trysend += sctp_set_frwnd(sctp, ntohl(sc->ssc_a_rwnd)); 28330Sstevel@tonic-gate 28340Sstevel@tonic-gate /* 28350Sstevel@tonic-gate * If receive window is closed while there is unsent data, 28360Sstevel@tonic-gate * set a timer for doing zero window probes. 28370Sstevel@tonic-gate */ 28380Sstevel@tonic-gate if (sctp->sctp_frwnd == 0 && sctp->sctp_unacked == 0 && 28390Sstevel@tonic-gate sctp->sctp_unsent != 0) { 28400Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current, 28410Sstevel@tonic-gate sctp->sctp_current->rto); 28420Sstevel@tonic-gate } 28430Sstevel@tonic-gate 28440Sstevel@tonic-gate /* 28450Sstevel@tonic-gate * Set cwnd for all destinations. 28460Sstevel@tonic-gate * Congestion window gets increased only when cumulative 28470Sstevel@tonic-gate * TSN moves forward, we're not in fast recovery, and 28480Sstevel@tonic-gate * cwnd has been fully utilized (almost fully, need to allow 28490Sstevel@tonic-gate * some leeway due to non-MSS sized messages). 28500Sstevel@tonic-gate */ 28510Sstevel@tonic-gate if (sctp->sctp_current->acked == acked) { 28520Sstevel@tonic-gate /* 28530Sstevel@tonic-gate * Fast-path, only data sent to sctp_current got acked. 28540Sstevel@tonic-gate */ 28550Sstevel@tonic-gate fp = sctp->sctp_current; 28560Sstevel@tonic-gate if (cumack_forward && !fast_recovery && 28570Sstevel@tonic-gate (fp->acked + fp->suna > fp->cwnd - fp->sfa_pmss)) { 28580Sstevel@tonic-gate if (fp->cwnd < fp->ssthresh) { 28590Sstevel@tonic-gate /* 28600Sstevel@tonic-gate * Slow start 28610Sstevel@tonic-gate */ 28620Sstevel@tonic-gate if (fp->acked > fp->sfa_pmss) { 28630Sstevel@tonic-gate fp->cwnd += fp->sfa_pmss; 28640Sstevel@tonic-gate } else { 28650Sstevel@tonic-gate fp->cwnd += fp->acked; 28660Sstevel@tonic-gate } 28670Sstevel@tonic-gate fp->cwnd = MIN(fp->cwnd, sctp->sctp_cwnd_max); 28680Sstevel@tonic-gate } else { 28690Sstevel@tonic-gate /* 28700Sstevel@tonic-gate * Congestion avoidance 28710Sstevel@tonic-gate */ 28720Sstevel@tonic-gate fp->pba += fp->acked; 28730Sstevel@tonic-gate if (fp->pba >= fp->cwnd) { 28740Sstevel@tonic-gate fp->pba -= fp->cwnd; 28750Sstevel@tonic-gate fp->cwnd += fp->sfa_pmss; 28760Sstevel@tonic-gate fp->cwnd = MIN(fp->cwnd, 28770Sstevel@tonic-gate sctp->sctp_cwnd_max); 28780Sstevel@tonic-gate } 28790Sstevel@tonic-gate } 28800Sstevel@tonic-gate } 28810Sstevel@tonic-gate /* 28820Sstevel@tonic-gate * Limit the burst of transmitted data segments. 28830Sstevel@tonic-gate */ 28843448Sdh155122 if (fp->suna + sctps->sctps_maxburst * fp->sfa_pmss < 28853448Sdh155122 fp->cwnd) { 28863448Sdh155122 fp->cwnd = fp->suna + sctps->sctps_maxburst * 28873448Sdh155122 fp->sfa_pmss; 28880Sstevel@tonic-gate } 28890Sstevel@tonic-gate fp->acked = 0; 28901735Skcpoon goto check_ss_rxmit; 28910Sstevel@tonic-gate } 28921932Svi117747 for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 28930Sstevel@tonic-gate if (cumack_forward && fp->acked && !fast_recovery && 28940Sstevel@tonic-gate (fp->acked + fp->suna > fp->cwnd - fp->sfa_pmss)) { 28950Sstevel@tonic-gate if (fp->cwnd < fp->ssthresh) { 28960Sstevel@tonic-gate if (fp->acked > fp->sfa_pmss) { 28970Sstevel@tonic-gate fp->cwnd += fp->sfa_pmss; 28980Sstevel@tonic-gate } else { 28990Sstevel@tonic-gate fp->cwnd += fp->acked; 29000Sstevel@tonic-gate } 29010Sstevel@tonic-gate fp->cwnd = MIN(fp->cwnd, sctp->sctp_cwnd_max); 29020Sstevel@tonic-gate } else { 29030Sstevel@tonic-gate fp->pba += fp->acked; 29040Sstevel@tonic-gate if (fp->pba >= fp->cwnd) { 29050Sstevel@tonic-gate fp->pba -= fp->cwnd; 29060Sstevel@tonic-gate fp->cwnd += fp->sfa_pmss; 29070Sstevel@tonic-gate fp->cwnd = MIN(fp->cwnd, 29080Sstevel@tonic-gate sctp->sctp_cwnd_max); 29090Sstevel@tonic-gate } 29100Sstevel@tonic-gate } 29110Sstevel@tonic-gate } 29123448Sdh155122 if (fp->suna + sctps->sctps_maxburst * fp->sfa_pmss < 29133448Sdh155122 fp->cwnd) { 29143448Sdh155122 fp->cwnd = fp->suna + sctps->sctps_maxburst * 29153448Sdh155122 fp->sfa_pmss; 29160Sstevel@tonic-gate } 29170Sstevel@tonic-gate fp->acked = 0; 29180Sstevel@tonic-gate } 29194311Svi117747 fp = sctp->sctp_current; 29201735Skcpoon check_ss_rxmit: 29211735Skcpoon /* 29221735Skcpoon * If this is a SACK following a timeout, check if there are 29231735Skcpoon * still unacked chunks (sent before the timeout) that we can 29241735Skcpoon * send. 29251735Skcpoon */ 29261735Skcpoon if (sctp->sctp_rexmitting) { 29271735Skcpoon if (SEQ_LT(sctp->sctp_lastack_rxd, sctp->sctp_rxt_maxtsn)) { 29281735Skcpoon /* 29291735Skcpoon * As we are in retransmission phase, we may get a 29301735Skcpoon * SACK which indicates some new chunks are received 29311735Skcpoon * but cum_tsn does not advance. During this 29321735Skcpoon * phase, the other side advances cum_tsn only because 29331735Skcpoon * it receives our retransmitted chunks. Only 29341735Skcpoon * this signals that some chunks are still 29351735Skcpoon * missing. 29361735Skcpoon */ 29373795Skcpoon if (cumack_forward) { 29383795Skcpoon fp->rxt_unacked -= acked; 29391735Skcpoon sctp_ss_rexmit(sctp); 29403795Skcpoon } 29411735Skcpoon } else { 29421735Skcpoon sctp->sctp_rexmitting = B_FALSE; 29431735Skcpoon sctp->sctp_rxt_nxttsn = sctp->sctp_ltsn; 29441735Skcpoon sctp->sctp_rxt_maxtsn = sctp->sctp_ltsn; 29453795Skcpoon fp->rxt_unacked = 0; 29461735Skcpoon } 29471735Skcpoon } 29480Sstevel@tonic-gate return (trysend); 29490Sstevel@tonic-gate } 29500Sstevel@tonic-gate 29510Sstevel@tonic-gate /* 29520Sstevel@tonic-gate * Returns 0 if the caller should stop processing any more chunks, 29530Sstevel@tonic-gate * 1 if the caller should skip this chunk and continue processing. 29540Sstevel@tonic-gate */ 29550Sstevel@tonic-gate static int 29560Sstevel@tonic-gate sctp_strange_chunk(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp) 29570Sstevel@tonic-gate { 29580Sstevel@tonic-gate size_t len; 29590Sstevel@tonic-gate 29600Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 29610Sstevel@tonic-gate /* check top two bits for action required */ 29620Sstevel@tonic-gate if (ch->sch_id & 0x40) { /* also matches 0xc0 */ 29630Sstevel@tonic-gate len = ntohs(ch->sch_len); 29644964Skcpoon sctp_add_err(sctp, SCTP_ERR_UNREC_CHUNK, ch, len, fp); 29654964Skcpoon 29660Sstevel@tonic-gate if ((ch->sch_id & 0xc0) == 0xc0) { 29670Sstevel@tonic-gate /* skip and continue */ 29680Sstevel@tonic-gate return (1); 29690Sstevel@tonic-gate } else { 29700Sstevel@tonic-gate /* stop processing */ 29710Sstevel@tonic-gate return (0); 29720Sstevel@tonic-gate } 29730Sstevel@tonic-gate } 29740Sstevel@tonic-gate if (ch->sch_id & 0x80) { 29750Sstevel@tonic-gate /* skip and continue, no error */ 29760Sstevel@tonic-gate return (1); 29770Sstevel@tonic-gate } 29780Sstevel@tonic-gate /* top two bits are clear; stop processing and no error */ 29790Sstevel@tonic-gate return (0); 29800Sstevel@tonic-gate } 29810Sstevel@tonic-gate 29820Sstevel@tonic-gate /* 29830Sstevel@tonic-gate * Basic sanity checks on all input chunks and parameters: they must 29840Sstevel@tonic-gate * be of legitimate size for their purported type, and must follow 29850Sstevel@tonic-gate * ordering conventions as defined in rfc2960. 29860Sstevel@tonic-gate * 29870Sstevel@tonic-gate * Returns 1 if the chunk and all encloded params are legitimate, 29880Sstevel@tonic-gate * 0 otherwise. 29890Sstevel@tonic-gate */ 29900Sstevel@tonic-gate /*ARGSUSED*/ 29910Sstevel@tonic-gate static int 29920Sstevel@tonic-gate sctp_check_input(sctp_t *sctp, sctp_chunk_hdr_t *ch, ssize_t len, int first) 29930Sstevel@tonic-gate { 29940Sstevel@tonic-gate sctp_parm_hdr_t *ph; 29950Sstevel@tonic-gate void *p = NULL; 29960Sstevel@tonic-gate ssize_t clen; 29970Sstevel@tonic-gate uint16_t ch_len; 29980Sstevel@tonic-gate 29990Sstevel@tonic-gate ch_len = ntohs(ch->sch_len); 30000Sstevel@tonic-gate if (ch_len > len) { 30010Sstevel@tonic-gate return (0); 30020Sstevel@tonic-gate } 30030Sstevel@tonic-gate 30040Sstevel@tonic-gate switch (ch->sch_id) { 30050Sstevel@tonic-gate case CHUNK_DATA: 30060Sstevel@tonic-gate if (ch_len < sizeof (sctp_data_hdr_t)) { 30070Sstevel@tonic-gate return (0); 30080Sstevel@tonic-gate } 30090Sstevel@tonic-gate return (1); 30100Sstevel@tonic-gate case CHUNK_INIT: 30110Sstevel@tonic-gate case CHUNK_INIT_ACK: 30120Sstevel@tonic-gate { 30130Sstevel@tonic-gate ssize_t remlen = len; 30140Sstevel@tonic-gate 30150Sstevel@tonic-gate /* 30160Sstevel@tonic-gate * INIT and INIT-ACK chunks must not be bundled with 30170Sstevel@tonic-gate * any other. 30180Sstevel@tonic-gate */ 30190Sstevel@tonic-gate if (!first || sctp_next_chunk(ch, &remlen) != NULL || 30200Sstevel@tonic-gate (ch_len < (sizeof (*ch) + 30210Sstevel@tonic-gate sizeof (sctp_init_chunk_t)))) { 30220Sstevel@tonic-gate return (0); 30230Sstevel@tonic-gate } 30240Sstevel@tonic-gate /* may have params that need checking */ 30250Sstevel@tonic-gate p = (char *)(ch + 1) + sizeof (sctp_init_chunk_t); 30260Sstevel@tonic-gate clen = ch_len - (sizeof (*ch) + 30270Sstevel@tonic-gate sizeof (sctp_init_chunk_t)); 30280Sstevel@tonic-gate } 30290Sstevel@tonic-gate break; 30300Sstevel@tonic-gate case CHUNK_SACK: 30310Sstevel@tonic-gate if (ch_len < (sizeof (*ch) + sizeof (sctp_sack_chunk_t))) { 30320Sstevel@tonic-gate return (0); 30330Sstevel@tonic-gate } 30340Sstevel@tonic-gate /* dup and gap reports checked by got_sack() */ 30350Sstevel@tonic-gate return (1); 30360Sstevel@tonic-gate case CHUNK_SHUTDOWN: 30370Sstevel@tonic-gate if (ch_len < (sizeof (*ch) + sizeof (uint32_t))) { 30380Sstevel@tonic-gate return (0); 30390Sstevel@tonic-gate } 30400Sstevel@tonic-gate return (1); 30410Sstevel@tonic-gate case CHUNK_ABORT: 30420Sstevel@tonic-gate case CHUNK_ERROR: 30430Sstevel@tonic-gate if (ch_len < sizeof (*ch)) { 30440Sstevel@tonic-gate return (0); 30450Sstevel@tonic-gate } 30460Sstevel@tonic-gate /* may have params that need checking */ 30470Sstevel@tonic-gate p = ch + 1; 30480Sstevel@tonic-gate clen = ch_len - sizeof (*ch); 30490Sstevel@tonic-gate break; 30500Sstevel@tonic-gate case CHUNK_ECNE: 30510Sstevel@tonic-gate case CHUNK_CWR: 30520Sstevel@tonic-gate case CHUNK_HEARTBEAT: 30530Sstevel@tonic-gate case CHUNK_HEARTBEAT_ACK: 30540Sstevel@tonic-gate /* Full ASCONF chunk and parameter checks are in asconf.c */ 30550Sstevel@tonic-gate case CHUNK_ASCONF: 30560Sstevel@tonic-gate case CHUNK_ASCONF_ACK: 30570Sstevel@tonic-gate if (ch_len < sizeof (*ch)) { 30580Sstevel@tonic-gate return (0); 30590Sstevel@tonic-gate } 30600Sstevel@tonic-gate /* heartbeat data checked by process_heartbeat() */ 30610Sstevel@tonic-gate return (1); 30620Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 30630Sstevel@tonic-gate { 30640Sstevel@tonic-gate ssize_t remlen = len; 30650Sstevel@tonic-gate 30660Sstevel@tonic-gate /* 30670Sstevel@tonic-gate * SHUTDOWN-COMPLETE chunk must not be bundled with any 30680Sstevel@tonic-gate * other 30690Sstevel@tonic-gate */ 30700Sstevel@tonic-gate if (!first || sctp_next_chunk(ch, &remlen) != NULL || 30710Sstevel@tonic-gate ch_len < sizeof (*ch)) { 30720Sstevel@tonic-gate return (0); 30730Sstevel@tonic-gate } 30740Sstevel@tonic-gate } 30750Sstevel@tonic-gate return (1); 30760Sstevel@tonic-gate case CHUNK_COOKIE: 30770Sstevel@tonic-gate case CHUNK_COOKIE_ACK: 30780Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 30790Sstevel@tonic-gate if (ch_len < sizeof (*ch) || !first) { 30800Sstevel@tonic-gate return (0); 30810Sstevel@tonic-gate } 30820Sstevel@tonic-gate return (1); 30830Sstevel@tonic-gate case CHUNK_FORWARD_TSN: 30840Sstevel@tonic-gate if (ch_len < (sizeof (*ch) + sizeof (uint32_t))) 30850Sstevel@tonic-gate return (0); 30860Sstevel@tonic-gate return (1); 30870Sstevel@tonic-gate default: 30880Sstevel@tonic-gate return (1); /* handled by strange_chunk() */ 30890Sstevel@tonic-gate } 30900Sstevel@tonic-gate 30910Sstevel@tonic-gate /* check and byteorder parameters */ 30920Sstevel@tonic-gate if (clen <= 0) { 30930Sstevel@tonic-gate return (1); 30940Sstevel@tonic-gate } 30950Sstevel@tonic-gate ASSERT(p != NULL); 30960Sstevel@tonic-gate 30970Sstevel@tonic-gate ph = p; 30980Sstevel@tonic-gate while (ph != NULL && clen > 0) { 30990Sstevel@tonic-gate ch_len = ntohs(ph->sph_len); 31000Sstevel@tonic-gate if (ch_len > len || ch_len < sizeof (*ph)) { 31010Sstevel@tonic-gate return (0); 31020Sstevel@tonic-gate } 31030Sstevel@tonic-gate ph = sctp_next_parm(ph, &clen); 31040Sstevel@tonic-gate } 31050Sstevel@tonic-gate 31060Sstevel@tonic-gate /* All OK */ 31070Sstevel@tonic-gate return (1); 31080Sstevel@tonic-gate } 31090Sstevel@tonic-gate 31100Sstevel@tonic-gate /* ARGSUSED */ 31110Sstevel@tonic-gate static sctp_hdr_t * 31120Sstevel@tonic-gate find_sctp_hdrs(mblk_t *mp, in6_addr_t *src, in6_addr_t *dst, 31133318Srshoaib uint_t *ifindex, uint_t *ip_hdr_len, ip6_pkt_t *ipp, ip_pktinfo_t *pinfo) 31140Sstevel@tonic-gate { 31150Sstevel@tonic-gate uchar_t *rptr; 31160Sstevel@tonic-gate ipha_t *ip4h; 31170Sstevel@tonic-gate ip6_t *ip6h; 31180Sstevel@tonic-gate mblk_t *mp1; 31190Sstevel@tonic-gate 31200Sstevel@tonic-gate rptr = mp->b_rptr; 31210Sstevel@tonic-gate if (IPH_HDR_VERSION(rptr) == IPV4_VERSION) { 31220Sstevel@tonic-gate *ip_hdr_len = IPH_HDR_LENGTH(rptr); 31230Sstevel@tonic-gate ip4h = (ipha_t *)rptr; 31240Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ip4h->ipha_src, src); 31250Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ip4h->ipha_dst, dst); 31260Sstevel@tonic-gate 31270Sstevel@tonic-gate ipp->ipp_fields |= IPPF_HOPLIMIT; 31280Sstevel@tonic-gate ipp->ipp_hoplimit = ((ipha_t *)rptr)->ipha_ttl; 31293318Srshoaib if (pinfo != NULL && (pinfo->ip_pkt_flags & IPF_RECVIF)) { 31300Sstevel@tonic-gate ipp->ipp_fields |= IPPF_IFINDEX; 31313318Srshoaib ipp->ipp_ifindex = pinfo->ip_pkt_ifindex; 31320Sstevel@tonic-gate } 31330Sstevel@tonic-gate } else { 31340Sstevel@tonic-gate ASSERT(IPH_HDR_VERSION(rptr) == IPV6_VERSION); 31350Sstevel@tonic-gate ip6h = (ip6_t *)rptr; 31360Sstevel@tonic-gate ipp->ipp_fields = IPPF_HOPLIMIT; 31370Sstevel@tonic-gate ipp->ipp_hoplimit = ip6h->ip6_hops; 31380Sstevel@tonic-gate 31390Sstevel@tonic-gate if (ip6h->ip6_nxt != IPPROTO_SCTP) { 31400Sstevel@tonic-gate /* Look for ifindex information */ 31410Sstevel@tonic-gate if (ip6h->ip6_nxt == IPPROTO_RAW) { 31420Sstevel@tonic-gate ip6i_t *ip6i = (ip6i_t *)ip6h; 31430Sstevel@tonic-gate 31440Sstevel@tonic-gate if (ip6i->ip6i_flags & IP6I_IFINDEX) { 31450Sstevel@tonic-gate ASSERT(ip6i->ip6i_ifindex != 0); 31460Sstevel@tonic-gate ipp->ipp_fields |= IPPF_IFINDEX; 31470Sstevel@tonic-gate ipp->ipp_ifindex = ip6i->ip6i_ifindex; 31480Sstevel@tonic-gate } 31490Sstevel@tonic-gate rptr = (uchar_t *)&ip6i[1]; 31500Sstevel@tonic-gate mp->b_rptr = rptr; 31510Sstevel@tonic-gate if (rptr == mp->b_wptr) { 31520Sstevel@tonic-gate mp1 = mp->b_cont; 31530Sstevel@tonic-gate freeb(mp); 31540Sstevel@tonic-gate mp = mp1; 31550Sstevel@tonic-gate rptr = mp->b_rptr; 31560Sstevel@tonic-gate } 31570Sstevel@tonic-gate ASSERT(mp->b_wptr - rptr >= 31580Sstevel@tonic-gate IPV6_HDR_LEN + sizeof (sctp_hdr_t)); 31590Sstevel@tonic-gate ip6h = (ip6_t *)rptr; 31600Sstevel@tonic-gate } 31610Sstevel@tonic-gate /* 31620Sstevel@tonic-gate * Find any potentially interesting extension headers 31630Sstevel@tonic-gate * as well as the length of the IPv6 + extension 31640Sstevel@tonic-gate * headers. 31650Sstevel@tonic-gate */ 31660Sstevel@tonic-gate *ip_hdr_len = ip_find_hdr_v6(mp, ip6h, ipp, NULL); 31670Sstevel@tonic-gate } else { 31680Sstevel@tonic-gate *ip_hdr_len = IPV6_HDR_LEN; 31690Sstevel@tonic-gate } 31700Sstevel@tonic-gate *src = ip6h->ip6_src; 31710Sstevel@tonic-gate *dst = ip6h->ip6_dst; 31720Sstevel@tonic-gate } 31730Sstevel@tonic-gate ASSERT((uintptr_t)(mp->b_wptr - rptr) <= (uintptr_t)INT_MAX); 31740Sstevel@tonic-gate return ((sctp_hdr_t *)&rptr[*ip_hdr_len]); 31750Sstevel@tonic-gate #undef IPVER 31760Sstevel@tonic-gate } 31770Sstevel@tonic-gate 31780Sstevel@tonic-gate static mblk_t * 31790Sstevel@tonic-gate sctp_check_in_policy(mblk_t *mp, mblk_t *ipsec_mp) 31800Sstevel@tonic-gate { 31810Sstevel@tonic-gate ipsec_in_t *ii; 31820Sstevel@tonic-gate boolean_t check = B_TRUE; 31830Sstevel@tonic-gate boolean_t policy_present; 31840Sstevel@tonic-gate ipha_t *ipha; 31850Sstevel@tonic-gate ip6_t *ip6h; 31863448Sdh155122 netstack_t *ns; 31873448Sdh155122 ipsec_stack_t *ipss; 31880Sstevel@tonic-gate 31890Sstevel@tonic-gate ii = (ipsec_in_t *)ipsec_mp->b_rptr; 31900Sstevel@tonic-gate ASSERT(ii->ipsec_in_type == IPSEC_IN); 31913448Sdh155122 ns = ii->ipsec_in_ns; 31923448Sdh155122 ipss = ns->netstack_ipsec; 31933448Sdh155122 31940Sstevel@tonic-gate if (ii->ipsec_in_dont_check) { 31950Sstevel@tonic-gate check = B_FALSE; 31960Sstevel@tonic-gate if (!ii->ipsec_in_secure) { 31970Sstevel@tonic-gate freeb(ipsec_mp); 31980Sstevel@tonic-gate ipsec_mp = NULL; 31990Sstevel@tonic-gate } 32000Sstevel@tonic-gate } 32010Sstevel@tonic-gate if (IPH_HDR_VERSION(mp->b_rptr) == IPV4_VERSION) { 32023448Sdh155122 policy_present = ipss->ipsec_inbound_v4_policy_present; 32030Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 32040Sstevel@tonic-gate ip6h = NULL; 32050Sstevel@tonic-gate } else { 32063448Sdh155122 policy_present = ipss->ipsec_inbound_v6_policy_present; 32070Sstevel@tonic-gate ipha = NULL; 32080Sstevel@tonic-gate ip6h = (ip6_t *)mp->b_rptr; 32090Sstevel@tonic-gate } 32100Sstevel@tonic-gate 32110Sstevel@tonic-gate if (check && policy_present) { 32120Sstevel@tonic-gate /* 32130Sstevel@tonic-gate * The conn_t parameter is NULL because we already know 32140Sstevel@tonic-gate * nobody's home. 32150Sstevel@tonic-gate */ 32160Sstevel@tonic-gate ipsec_mp = ipsec_check_global_policy(ipsec_mp, (conn_t *)NULL, 32173448Sdh155122 ipha, ip6h, B_TRUE, ns); 32180Sstevel@tonic-gate if (ipsec_mp == NULL) 32190Sstevel@tonic-gate return (NULL); 32200Sstevel@tonic-gate } 32210Sstevel@tonic-gate if (ipsec_mp != NULL) 32220Sstevel@tonic-gate freeb(ipsec_mp); 32230Sstevel@tonic-gate return (mp); 32240Sstevel@tonic-gate } 32250Sstevel@tonic-gate 32260Sstevel@tonic-gate /* Handle out-of-the-blue packets */ 32270Sstevel@tonic-gate void 32283510Svi117747 sctp_ootb_input(mblk_t *mp, ill_t *recv_ill, zoneid_t zoneid, 32293510Svi117747 boolean_t mctl_present) 32300Sstevel@tonic-gate { 32310Sstevel@tonic-gate sctp_t *sctp; 32320Sstevel@tonic-gate sctp_chunk_hdr_t *ch; 32330Sstevel@tonic-gate sctp_hdr_t *sctph; 32340Sstevel@tonic-gate in6_addr_t src, dst; 32350Sstevel@tonic-gate uint_t ip_hdr_len; 32360Sstevel@tonic-gate uint_t ifindex; 32370Sstevel@tonic-gate ip6_pkt_t ipp; 32380Sstevel@tonic-gate ssize_t mlen; 32393318Srshoaib ip_pktinfo_t *pinfo = NULL; 32400Sstevel@tonic-gate mblk_t *first_mp; 32413448Sdh155122 sctp_stack_t *sctps; 32423448Sdh155122 ip_stack_t *ipst; 32433448Sdh155122 32443448Sdh155122 ASSERT(recv_ill != NULL); 32453448Sdh155122 ipst = recv_ill->ill_ipst; 32463448Sdh155122 sctps = ipst->ips_netstack->netstack_sctp; 32473448Sdh155122 32483448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpOutOfBlue); 32493448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpInSCTPPkts); 32503448Sdh155122 32513448Sdh155122 if (sctps->sctps_gsctp == NULL) { 32523448Sdh155122 /* 32533448Sdh155122 * For non-zero stackids the default queue isn't created 32543448Sdh155122 * until the first open, thus there can be a need to send 32553448Sdh155122 * an error before then. But we can't do that, hence we just 32563448Sdh155122 * drop the packet. Later during boot, when the default queue 32573448Sdh155122 * has been setup, a retransmitted packet from the peer 32583448Sdh155122 * will result in a error. 32593448Sdh155122 */ 32603448Sdh155122 ASSERT(sctps->sctps_netstack->netstack_stackid != 32613448Sdh155122 GLOBAL_NETSTACKID); 32623448Sdh155122 freemsg(mp); 32633448Sdh155122 return; 32643448Sdh155122 } 32650Sstevel@tonic-gate 32660Sstevel@tonic-gate first_mp = mp; 32670Sstevel@tonic-gate if (mctl_present) 32680Sstevel@tonic-gate mp = mp->b_cont; 32690Sstevel@tonic-gate 32700Sstevel@tonic-gate /* Initiate IPPf processing, if needed. */ 32713448Sdh155122 if (IPP_ENABLED(IPP_LOCAL_IN, ipst)) { 32720Sstevel@tonic-gate ip_process(IPP_LOCAL_IN, &mp, 32730Sstevel@tonic-gate recv_ill->ill_phyint->phyint_ifindex); 32740Sstevel@tonic-gate if (mp == NULL) { 32750Sstevel@tonic-gate if (mctl_present) 32760Sstevel@tonic-gate freeb(first_mp); 32770Sstevel@tonic-gate return; 32780Sstevel@tonic-gate } 32790Sstevel@tonic-gate } 32800Sstevel@tonic-gate 32810Sstevel@tonic-gate if (mp->b_cont != NULL) { 32820Sstevel@tonic-gate /* 32830Sstevel@tonic-gate * All subsequent code is vastly simplified if it can 32840Sstevel@tonic-gate * assume a single contiguous chunk of data. 32850Sstevel@tonic-gate */ 32860Sstevel@tonic-gate if (pullupmsg(mp, -1) == 0) { 32873284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, ipIfStatsInDiscards); 32880Sstevel@tonic-gate freemsg(first_mp); 32890Sstevel@tonic-gate return; 32900Sstevel@tonic-gate } 32910Sstevel@tonic-gate } 32920Sstevel@tonic-gate 32930Sstevel@tonic-gate /* 32940Sstevel@tonic-gate * We don't really need to call this function... Need to 32950Sstevel@tonic-gate * optimize later. 32960Sstevel@tonic-gate */ 32970Sstevel@tonic-gate sctph = find_sctp_hdrs(mp, &src, &dst, &ifindex, &ip_hdr_len, 32980Sstevel@tonic-gate &ipp, pinfo); 32990Sstevel@tonic-gate mlen = mp->b_wptr - (uchar_t *)(sctph + 1); 33000Sstevel@tonic-gate if ((ch = sctp_first_chunk((uchar_t *)(sctph + 1), mlen)) == NULL) { 33010Sstevel@tonic-gate dprint(3, ("sctp_ootb_input: invalid packet\n")); 33023284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, ipIfStatsInDiscards); 33030Sstevel@tonic-gate freemsg(first_mp); 33040Sstevel@tonic-gate return; 33050Sstevel@tonic-gate } 33060Sstevel@tonic-gate 33070Sstevel@tonic-gate switch (ch->sch_id) { 33080Sstevel@tonic-gate case CHUNK_INIT: 33090Sstevel@tonic-gate /* no listener; send abort */ 33100Sstevel@tonic-gate if (mctl_present && sctp_check_in_policy(mp, first_mp) == NULL) 33110Sstevel@tonic-gate return; 33123448Sdh155122 sctp_send_abort(sctps->sctps_gsctp, sctp_init2vtag(ch), 0, 33130Sstevel@tonic-gate NULL, 0, mp, 0, B_TRUE); 33140Sstevel@tonic-gate break; 33150Sstevel@tonic-gate case CHUNK_INIT_ACK: 33160Sstevel@tonic-gate /* check for changed src addr */ 33173510Svi117747 sctp = sctp_addrlist2sctp(mp, sctph, ch, zoneid, sctps); 33180Sstevel@tonic-gate if (sctp != NULL) { 33190Sstevel@tonic-gate /* success; proceed to normal path */ 33200Sstevel@tonic-gate mutex_enter(&sctp->sctp_lock); 33210Sstevel@tonic-gate if (sctp->sctp_running) { 33220Sstevel@tonic-gate if (!sctp_add_recvq(sctp, mp, B_FALSE)) { 33233284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, 33243284Sapersson ipIfStatsInDiscards); 33250Sstevel@tonic-gate freemsg(mp); 33260Sstevel@tonic-gate } 33270Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 33280Sstevel@tonic-gate } else { 33290Sstevel@tonic-gate /* 33300Sstevel@tonic-gate * If the source address is changed, we 33310Sstevel@tonic-gate * don't need to worry too much about 33320Sstevel@tonic-gate * out of order processing. So we don't 33330Sstevel@tonic-gate * check if the recvq is empty or not here. 33340Sstevel@tonic-gate */ 33350Sstevel@tonic-gate sctp->sctp_running = B_TRUE; 33360Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 33370Sstevel@tonic-gate sctp_input_data(sctp, mp, NULL); 33380Sstevel@tonic-gate WAKE_SCTP(sctp); 33390Sstevel@tonic-gate sctp_process_sendq(sctp); 33400Sstevel@tonic-gate } 33410Sstevel@tonic-gate SCTP_REFRELE(sctp); 33420Sstevel@tonic-gate return; 33430Sstevel@tonic-gate } 33440Sstevel@tonic-gate if (mctl_present) 33450Sstevel@tonic-gate freeb(first_mp); 33460Sstevel@tonic-gate /* else bogus init ack; drop it */ 33470Sstevel@tonic-gate break; 33480Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 33490Sstevel@tonic-gate if (mctl_present && sctp_check_in_policy(mp, first_mp) == NULL) 33500Sstevel@tonic-gate return; 33513448Sdh155122 sctp_ootb_shutdown_ack(sctps->sctps_gsctp, mp, ip_hdr_len); 33523448Sdh155122 sctp_process_sendq(sctps->sctps_gsctp); 33530Sstevel@tonic-gate return; 33540Sstevel@tonic-gate case CHUNK_ERROR: 33550Sstevel@tonic-gate case CHUNK_ABORT: 33560Sstevel@tonic-gate case CHUNK_COOKIE_ACK: 33570Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 33580Sstevel@tonic-gate if (mctl_present) 33590Sstevel@tonic-gate freeb(first_mp); 33600Sstevel@tonic-gate break; 33610Sstevel@tonic-gate default: 33620Sstevel@tonic-gate if (mctl_present && sctp_check_in_policy(mp, first_mp) == NULL) 33630Sstevel@tonic-gate return; 33643448Sdh155122 sctp_send_abort(sctps->sctps_gsctp, sctph->sh_verf, 0, 33653448Sdh155122 NULL, 0, mp, 0, B_TRUE); 33660Sstevel@tonic-gate break; 33670Sstevel@tonic-gate } 33683448Sdh155122 sctp_process_sendq(sctps->sctps_gsctp); 33690Sstevel@tonic-gate freemsg(mp); 33700Sstevel@tonic-gate } 33710Sstevel@tonic-gate 33720Sstevel@tonic-gate void 33730Sstevel@tonic-gate sctp_input(conn_t *connp, ipha_t *ipha, mblk_t *mp, mblk_t *first_mp, 33740Sstevel@tonic-gate ill_t *recv_ill, boolean_t isv4, boolean_t mctl_present) 33750Sstevel@tonic-gate { 33760Sstevel@tonic-gate sctp_t *sctp = CONN2SCTP(connp); 33773448Sdh155122 ip_stack_t *ipst = recv_ill->ill_ipst; 33783448Sdh155122 ipsec_stack_t *ipss = ipst->ips_netstack->netstack_ipsec; 33790Sstevel@tonic-gate 33800Sstevel@tonic-gate /* 33810Sstevel@tonic-gate * We check some fields in conn_t without holding a lock. 33820Sstevel@tonic-gate * This should be fine. 33830Sstevel@tonic-gate */ 33843448Sdh155122 if (CONN_INBOUND_POLICY_PRESENT(connp, ipss) || mctl_present) { 33850Sstevel@tonic-gate first_mp = ipsec_check_inbound_policy(first_mp, connp, 33860Sstevel@tonic-gate ipha, NULL, mctl_present); 33870Sstevel@tonic-gate if (first_mp == NULL) { 33883284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, ipIfStatsInDiscards); 33890Sstevel@tonic-gate SCTP_REFRELE(sctp); 33900Sstevel@tonic-gate return; 33910Sstevel@tonic-gate } 33920Sstevel@tonic-gate } 33930Sstevel@tonic-gate 33940Sstevel@tonic-gate /* Initiate IPPF processing for fastpath */ 33953448Sdh155122 if (IPP_ENABLED(IPP_LOCAL_IN, ipst)) { 33960Sstevel@tonic-gate ip_process(IPP_LOCAL_IN, &mp, 33970Sstevel@tonic-gate recv_ill->ill_phyint->phyint_ifindex); 33980Sstevel@tonic-gate if (mp == NULL) { 33990Sstevel@tonic-gate SCTP_REFRELE(sctp); 34000Sstevel@tonic-gate if (mctl_present) 34010Sstevel@tonic-gate freeb(first_mp); 34020Sstevel@tonic-gate return; 34030Sstevel@tonic-gate } else if (mctl_present) { 34040Sstevel@tonic-gate /* 34050Sstevel@tonic-gate * ip_process might return a new mp. 34060Sstevel@tonic-gate */ 34070Sstevel@tonic-gate ASSERT(first_mp != mp); 34080Sstevel@tonic-gate first_mp->b_cont = mp; 34090Sstevel@tonic-gate } else { 34100Sstevel@tonic-gate first_mp = mp; 34110Sstevel@tonic-gate } 34120Sstevel@tonic-gate } 34130Sstevel@tonic-gate 34140Sstevel@tonic-gate if (connp->conn_recvif || connp->conn_recvslla || 34153318Srshoaib connp->conn_ip_recvpktinfo) { 34160Sstevel@tonic-gate int in_flags = 0; 34170Sstevel@tonic-gate 34183318Srshoaib if (connp->conn_recvif || connp->conn_ip_recvpktinfo) { 34190Sstevel@tonic-gate in_flags = IPF_RECVIF; 34200Sstevel@tonic-gate } 34210Sstevel@tonic-gate if (connp->conn_recvslla) { 34220Sstevel@tonic-gate in_flags |= IPF_RECVSLLA; 34230Sstevel@tonic-gate } 34240Sstevel@tonic-gate if (isv4) { 34253318Srshoaib mp = ip_add_info(mp, recv_ill, in_flags, 34263448Sdh155122 IPCL_ZONEID(connp), ipst); 34270Sstevel@tonic-gate } else { 34280Sstevel@tonic-gate mp = ip_add_info_v6(mp, recv_ill, 34290Sstevel@tonic-gate &(((ip6_t *)ipha)->ip6_dst)); 34300Sstevel@tonic-gate } 34310Sstevel@tonic-gate if (mp == NULL) { 34323284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, ipIfStatsInDiscards); 34330Sstevel@tonic-gate SCTP_REFRELE(sctp); 34340Sstevel@tonic-gate if (mctl_present) 34350Sstevel@tonic-gate freeb(first_mp); 34360Sstevel@tonic-gate return; 34370Sstevel@tonic-gate } else if (mctl_present) { 34380Sstevel@tonic-gate /* 34390Sstevel@tonic-gate * ip_add_info might return a new mp. 34400Sstevel@tonic-gate */ 34410Sstevel@tonic-gate ASSERT(first_mp != mp); 34420Sstevel@tonic-gate first_mp->b_cont = mp; 34430Sstevel@tonic-gate } else { 34440Sstevel@tonic-gate first_mp = mp; 34450Sstevel@tonic-gate } 34460Sstevel@tonic-gate } 34470Sstevel@tonic-gate 34480Sstevel@tonic-gate mutex_enter(&sctp->sctp_lock); 34490Sstevel@tonic-gate if (sctp->sctp_running) { 34500Sstevel@tonic-gate if (mctl_present) 34510Sstevel@tonic-gate mp->b_prev = first_mp; 34520Sstevel@tonic-gate if (!sctp_add_recvq(sctp, mp, B_FALSE)) { 34533284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, ipIfStatsInDiscards); 34540Sstevel@tonic-gate freemsg(first_mp); 34550Sstevel@tonic-gate } 34560Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 34570Sstevel@tonic-gate SCTP_REFRELE(sctp); 34580Sstevel@tonic-gate return; 34590Sstevel@tonic-gate } else { 34600Sstevel@tonic-gate sctp->sctp_running = B_TRUE; 34610Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 34620Sstevel@tonic-gate 34630Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 34640Sstevel@tonic-gate if (sctp->sctp_recvq != NULL) { 34650Sstevel@tonic-gate if (mctl_present) 34660Sstevel@tonic-gate mp->b_prev = first_mp; 34670Sstevel@tonic-gate if (!sctp_add_recvq(sctp, mp, B_TRUE)) { 34683284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, 34693284Sapersson ipIfStatsInDiscards); 34700Sstevel@tonic-gate freemsg(first_mp); 34710Sstevel@tonic-gate } 34720Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 34730Sstevel@tonic-gate WAKE_SCTP(sctp); 34740Sstevel@tonic-gate SCTP_REFRELE(sctp); 34750Sstevel@tonic-gate return; 34760Sstevel@tonic-gate } 34770Sstevel@tonic-gate } 34780Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 34790Sstevel@tonic-gate sctp_input_data(sctp, mp, (mctl_present ? first_mp : NULL)); 34800Sstevel@tonic-gate WAKE_SCTP(sctp); 34810Sstevel@tonic-gate sctp_process_sendq(sctp); 34820Sstevel@tonic-gate SCTP_REFRELE(sctp); 34830Sstevel@tonic-gate } 34840Sstevel@tonic-gate 34850Sstevel@tonic-gate static void 34860Sstevel@tonic-gate sctp_process_abort(sctp_t *sctp, sctp_chunk_hdr_t *ch, int err) 34870Sstevel@tonic-gate { 34883448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 34893448Sdh155122 34903448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpAborted); 34910Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 34920Sstevel@tonic-gate 34930Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_LOST, 34940Sstevel@tonic-gate ntohs(((sctp_parm_hdr_t *)(ch + 1))->sph_type), ch); 34950Sstevel@tonic-gate sctp_clean_death(sctp, err); 34960Sstevel@tonic-gate } 34970Sstevel@tonic-gate 34980Sstevel@tonic-gate void 34990Sstevel@tonic-gate sctp_input_data(sctp_t *sctp, mblk_t *mp, mblk_t *ipsec_mp) 35000Sstevel@tonic-gate { 35010Sstevel@tonic-gate sctp_chunk_hdr_t *ch; 35020Sstevel@tonic-gate ssize_t mlen; 35030Sstevel@tonic-gate int gotdata; 35040Sstevel@tonic-gate int trysend; 35050Sstevel@tonic-gate sctp_faddr_t *fp; 35060Sstevel@tonic-gate sctp_init_chunk_t *iack; 35070Sstevel@tonic-gate uint32_t tsn; 35080Sstevel@tonic-gate sctp_data_hdr_t *sdc; 35090Sstevel@tonic-gate ip6_pkt_t ipp; 35100Sstevel@tonic-gate in6_addr_t src; 35110Sstevel@tonic-gate in6_addr_t dst; 35120Sstevel@tonic-gate uint_t ifindex; 35130Sstevel@tonic-gate sctp_hdr_t *sctph; 35140Sstevel@tonic-gate uint_t ip_hdr_len; 35150Sstevel@tonic-gate mblk_t *dups = NULL; 35165586Skcpoon int recv_adaptation; 35170Sstevel@tonic-gate boolean_t wake_eager = B_FALSE; 35180Sstevel@tonic-gate mblk_t *pinfo_mp; 35193318Srshoaib ip_pktinfo_t *pinfo = NULL; 35200Sstevel@tonic-gate in6_addr_t peer_src; 35210Sstevel@tonic-gate int64_t now; 35223448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 35233448Sdh155122 ip_stack_t *ipst = sctps->sctps_netstack->netstack_ip; 35244964Skcpoon boolean_t hb_already = B_FALSE; 35250Sstevel@tonic-gate 35260Sstevel@tonic-gate if (DB_TYPE(mp) != M_DATA) { 35270Sstevel@tonic-gate ASSERT(DB_TYPE(mp) == M_CTL); 35283318Srshoaib if (MBLKL(mp) == sizeof (ip_pktinfo_t) && 35293318Srshoaib ((ip_pktinfo_t *)mp->b_rptr)->ip_pkt_ulp_type == 35300Sstevel@tonic-gate IN_PKTINFO) { 35313318Srshoaib pinfo = (ip_pktinfo_t *)mp->b_rptr; 35320Sstevel@tonic-gate pinfo_mp = mp; 35330Sstevel@tonic-gate mp = mp->b_cont; 35340Sstevel@tonic-gate } else { 35350Sstevel@tonic-gate if (ipsec_mp != NULL) 35360Sstevel@tonic-gate freeb(ipsec_mp); 35370Sstevel@tonic-gate sctp_icmp_error(sctp, mp); 35380Sstevel@tonic-gate return; 35390Sstevel@tonic-gate } 35400Sstevel@tonic-gate } 35410Sstevel@tonic-gate ASSERT(DB_TYPE(mp) == M_DATA); 35420Sstevel@tonic-gate 35430Sstevel@tonic-gate if (mp->b_cont != NULL) { 35440Sstevel@tonic-gate /* 35450Sstevel@tonic-gate * All subsequent code is vastly simplified if it can 35460Sstevel@tonic-gate * assume a single contiguous chunk of data. 35470Sstevel@tonic-gate */ 35480Sstevel@tonic-gate if (pullupmsg(mp, -1) == 0) { 35493448Sdh155122 BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 35500Sstevel@tonic-gate if (ipsec_mp != NULL) 35510Sstevel@tonic-gate freeb(ipsec_mp); 35520Sstevel@tonic-gate if (pinfo != NULL) 35530Sstevel@tonic-gate freeb(pinfo_mp); 35540Sstevel@tonic-gate freemsg(mp); 35550Sstevel@tonic-gate return; 35560Sstevel@tonic-gate } 35570Sstevel@tonic-gate } 35580Sstevel@tonic-gate 35590Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ipkts); 35600Sstevel@tonic-gate sctph = find_sctp_hdrs(mp, &src, &dst, &ifindex, &ip_hdr_len, 35610Sstevel@tonic-gate &ipp, pinfo); 35620Sstevel@tonic-gate if (pinfo != NULL) 35630Sstevel@tonic-gate freeb(pinfo_mp); 35640Sstevel@tonic-gate mlen = mp->b_wptr - (uchar_t *)(sctph + 1); 35650Sstevel@tonic-gate ch = sctp_first_chunk((uchar_t *)(sctph + 1), mlen); 35660Sstevel@tonic-gate if (ch == NULL) { 35673448Sdh155122 BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 35680Sstevel@tonic-gate if (ipsec_mp != NULL) 35690Sstevel@tonic-gate freeb(ipsec_mp); 35700Sstevel@tonic-gate freemsg(mp); 35710Sstevel@tonic-gate return; 35720Sstevel@tonic-gate } 35730Sstevel@tonic-gate 35740Sstevel@tonic-gate if (!sctp_check_input(sctp, ch, mlen, 1)) { 35753448Sdh155122 BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 35760Sstevel@tonic-gate goto done; 35770Sstevel@tonic-gate } 35780Sstevel@tonic-gate /* 35790Sstevel@tonic-gate * Check verfication tag (special handling for INIT, 35800Sstevel@tonic-gate * COOKIE, SHUTDOWN_COMPLETE and SHUTDOWN_ACK chunks). 35810Sstevel@tonic-gate * ABORTs are handled in the chunk processing loop, since 35820Sstevel@tonic-gate * may not appear first. All other checked chunks must 35830Sstevel@tonic-gate * appear first, or will have been dropped by check_input(). 35840Sstevel@tonic-gate */ 35850Sstevel@tonic-gate switch (ch->sch_id) { 35860Sstevel@tonic-gate case CHUNK_INIT: 35870Sstevel@tonic-gate if (sctph->sh_verf != 0) { 35880Sstevel@tonic-gate /* drop it */ 35890Sstevel@tonic-gate goto done; 35900Sstevel@tonic-gate } 35910Sstevel@tonic-gate break; 35920Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 35930Sstevel@tonic-gate if (sctph->sh_verf == sctp->sctp_lvtag) 35940Sstevel@tonic-gate break; 35950Sstevel@tonic-gate if (sctph->sh_verf == sctp->sctp_fvtag && 35960Sstevel@tonic-gate SCTP_GET_TBIT(ch)) { 35970Sstevel@tonic-gate break; 35980Sstevel@tonic-gate } 35990Sstevel@tonic-gate /* else drop it */ 36000Sstevel@tonic-gate goto done; 36010Sstevel@tonic-gate case CHUNK_ABORT: 36020Sstevel@tonic-gate case CHUNK_COOKIE: 36030Sstevel@tonic-gate /* handled below */ 36040Sstevel@tonic-gate break; 36050Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 36060Sstevel@tonic-gate if (sctp->sctp_state > SCTPS_BOUND && 36070Sstevel@tonic-gate sctp->sctp_state < SCTPS_ESTABLISHED) { 36080Sstevel@tonic-gate /* treat as OOTB */ 36090Sstevel@tonic-gate sctp_ootb_shutdown_ack(sctp, mp, ip_hdr_len); 36100Sstevel@tonic-gate if (ipsec_mp != NULL) 36110Sstevel@tonic-gate freeb(ipsec_mp); 36120Sstevel@tonic-gate return; 36130Sstevel@tonic-gate } 36140Sstevel@tonic-gate /* else fallthru */ 36150Sstevel@tonic-gate default: 36160Sstevel@tonic-gate /* 36170Sstevel@tonic-gate * All other packets must have a valid 36180Sstevel@tonic-gate * verification tag, however if this is a 36190Sstevel@tonic-gate * listener, we use a refined version of 36200Sstevel@tonic-gate * out-of-the-blue logic. 36210Sstevel@tonic-gate */ 36220Sstevel@tonic-gate if (sctph->sh_verf != sctp->sctp_lvtag && 36230Sstevel@tonic-gate sctp->sctp_state != SCTPS_LISTEN) { 36240Sstevel@tonic-gate /* drop it */ 36250Sstevel@tonic-gate goto done; 36260Sstevel@tonic-gate } 36270Sstevel@tonic-gate break; 36280Sstevel@tonic-gate } 36290Sstevel@tonic-gate 36300Sstevel@tonic-gate /* Have a valid sctp for this packet */ 36310Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &src); 36321676Sjpk dprint(2, ("sctp_dispatch_rput: mp=%p fp=%p sctp=%p\n", (void *)mp, 36331676Sjpk (void *)fp, (void *)sctp)); 36340Sstevel@tonic-gate 36350Sstevel@tonic-gate gotdata = 0; 36360Sstevel@tonic-gate trysend = 0; 36370Sstevel@tonic-gate 36380Sstevel@tonic-gate now = lbolt64; 36390Sstevel@tonic-gate /* Process the chunks */ 36400Sstevel@tonic-gate do { 36410Sstevel@tonic-gate dprint(3, ("sctp_dispatch_rput: state=%d, chunk id=%d\n", 36420Sstevel@tonic-gate sctp->sctp_state, (int)(ch->sch_id))); 36430Sstevel@tonic-gate 36440Sstevel@tonic-gate if (ch->sch_id == CHUNK_ABORT) { 36450Sstevel@tonic-gate if (sctph->sh_verf != sctp->sctp_lvtag && 36460Sstevel@tonic-gate sctph->sh_verf != sctp->sctp_fvtag) { 36470Sstevel@tonic-gate /* drop it */ 36480Sstevel@tonic-gate goto done; 36490Sstevel@tonic-gate } 36500Sstevel@tonic-gate } 36510Sstevel@tonic-gate 36520Sstevel@tonic-gate switch (sctp->sctp_state) { 36530Sstevel@tonic-gate 36540Sstevel@tonic-gate case SCTPS_ESTABLISHED: 36550Sstevel@tonic-gate case SCTPS_SHUTDOWN_PENDING: 36560Sstevel@tonic-gate case SCTPS_SHUTDOWN_SENT: 36570Sstevel@tonic-gate switch (ch->sch_id) { 36580Sstevel@tonic-gate case CHUNK_DATA: 36590Sstevel@tonic-gate /* 0-length data chunks are not allowed */ 36600Sstevel@tonic-gate if (ntohs(ch->sch_len) == sizeof (*sdc)) { 36610Sstevel@tonic-gate sdc = (sctp_data_hdr_t *)ch; 36620Sstevel@tonic-gate tsn = sdc->sdh_tsn; 36630Sstevel@tonic-gate sctp_send_abort(sctp, sctp->sctp_fvtag, 36640Sstevel@tonic-gate SCTP_ERR_NO_USR_DATA, (char *)&tsn, 36650Sstevel@tonic-gate sizeof (tsn), mp, 0, B_FALSE); 36660Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_LOST, 36670Sstevel@tonic-gate 0, NULL); 36680Sstevel@tonic-gate sctp_clean_death(sctp, ECONNABORTED); 36690Sstevel@tonic-gate goto done; 36700Sstevel@tonic-gate } 36710Sstevel@tonic-gate 36720Sstevel@tonic-gate ASSERT(fp != NULL); 36730Sstevel@tonic-gate sctp->sctp_lastdata = fp; 36740Sstevel@tonic-gate sctp_data_chunk(sctp, ch, mp, &dups, fp, &ipp); 36750Sstevel@tonic-gate gotdata = 1; 36760Sstevel@tonic-gate /* Restart shutdown timer if shutting down */ 36770Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_SHUTDOWN_SENT) { 36780Sstevel@tonic-gate /* 36790Sstevel@tonic-gate * If we have exceeded our max 36800Sstevel@tonic-gate * wait bound for waiting for a 36810Sstevel@tonic-gate * shutdown ack from the peer, 36820Sstevel@tonic-gate * abort the association. 36830Sstevel@tonic-gate */ 36843448Sdh155122 if (sctps->sctps_shutack_wait_bound != 36853448Sdh155122 0 && 36860Sstevel@tonic-gate TICK_TO_MSEC(now - 36870Sstevel@tonic-gate sctp->sctp_out_time) > 36883448Sdh155122 sctps->sctps_shutack_wait_bound) { 36890Sstevel@tonic-gate sctp_send_abort(sctp, 36900Sstevel@tonic-gate sctp->sctp_fvtag, 0, NULL, 36910Sstevel@tonic-gate 0, mp, 0, B_FALSE); 36920Sstevel@tonic-gate sctp_assoc_event(sctp, 36930Sstevel@tonic-gate SCTP_COMM_LOST, 0, NULL); 36940Sstevel@tonic-gate sctp_clean_death(sctp, 36950Sstevel@tonic-gate ECONNABORTED); 36960Sstevel@tonic-gate goto done; 36970Sstevel@tonic-gate } 36980Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, fp, 36990Sstevel@tonic-gate fp->rto); 37000Sstevel@tonic-gate } 37010Sstevel@tonic-gate break; 37020Sstevel@tonic-gate case CHUNK_SACK: 37030Sstevel@tonic-gate ASSERT(fp != NULL); 37040Sstevel@tonic-gate /* 37050Sstevel@tonic-gate * Peer is real and alive if it can ack our 37060Sstevel@tonic-gate * data. 37070Sstevel@tonic-gate */ 37080Sstevel@tonic-gate sctp_faddr_alive(sctp, fp); 37090Sstevel@tonic-gate trysend = sctp_got_sack(sctp, ch); 3710852Svi117747 if (trysend < 0) { 3711852Svi117747 sctp_send_abort(sctp, sctph->sh_verf, 3712852Svi117747 0, NULL, 0, mp, 0, B_FALSE); 3713852Svi117747 sctp_assoc_event(sctp, 3714852Svi117747 SCTP_COMM_LOST, 0, NULL); 3715852Svi117747 sctp_clean_death(sctp, 3716852Svi117747 ECONNABORTED); 3717852Svi117747 goto done; 3718852Svi117747 } 37190Sstevel@tonic-gate break; 37200Sstevel@tonic-gate case CHUNK_HEARTBEAT: 37214964Skcpoon if (!hb_already) { 37224964Skcpoon /* 37234964Skcpoon * In any one packet, there should 37244964Skcpoon * only be one heartbeat chunk. So 37254964Skcpoon * we should not process more than 37264964Skcpoon * once. 37274964Skcpoon */ 37284964Skcpoon sctp_return_heartbeat(sctp, ch, mp); 37294964Skcpoon hb_already = B_TRUE; 37304964Skcpoon } 37310Sstevel@tonic-gate break; 37320Sstevel@tonic-gate case CHUNK_HEARTBEAT_ACK: 37330Sstevel@tonic-gate sctp_process_heartbeat(sctp, ch); 37340Sstevel@tonic-gate break; 37350Sstevel@tonic-gate case CHUNK_SHUTDOWN: 37360Sstevel@tonic-gate sctp_shutdown_event(sctp); 37370Sstevel@tonic-gate trysend = sctp_shutdown_received(sctp, ch, 37381735Skcpoon B_FALSE, B_FALSE, fp); 37390Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 37400Sstevel@tonic-gate break; 37410Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 37420Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 37430Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_SHUTDOWN_SENT) { 37440Sstevel@tonic-gate sctp_shutdown_complete(sctp); 37453448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 37463448Sdh155122 sctpShutdowns); 37470Sstevel@tonic-gate sctp_assoc_event(sctp, 37480Sstevel@tonic-gate SCTP_SHUTDOWN_COMP, 0, NULL); 37490Sstevel@tonic-gate sctp_clean_death(sctp, 0); 37500Sstevel@tonic-gate goto done; 37510Sstevel@tonic-gate } 37520Sstevel@tonic-gate break; 37530Sstevel@tonic-gate case CHUNK_ABORT: { 37540Sstevel@tonic-gate sctp_saddr_ipif_t *sp; 37550Sstevel@tonic-gate 37560Sstevel@tonic-gate /* Ignore if delete pending */ 3757852Svi117747 sp = sctp_saddr_lookup(sctp, &dst, 0); 37580Sstevel@tonic-gate ASSERT(sp != NULL); 37590Sstevel@tonic-gate if (sp->saddr_ipif_delete_pending) { 37600Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 37610Sstevel@tonic-gate break; 37620Sstevel@tonic-gate } 37630Sstevel@tonic-gate 37640Sstevel@tonic-gate sctp_process_abort(sctp, ch, ECONNRESET); 37650Sstevel@tonic-gate goto done; 37660Sstevel@tonic-gate } 37670Sstevel@tonic-gate case CHUNK_INIT: 37682776Skp158701 sctp_send_initack(sctp, sctph, ch, mp); 37690Sstevel@tonic-gate break; 37700Sstevel@tonic-gate case CHUNK_COOKIE: 37710Sstevel@tonic-gate if (sctp_process_cookie(sctp, ch, mp, &iack, 37725586Skcpoon sctph, &recv_adaptation, NULL) != -1) { 37730Sstevel@tonic-gate sctp_send_cookie_ack(sctp); 37740Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_RESTART, 37750Sstevel@tonic-gate 0, NULL); 37765586Skcpoon if (recv_adaptation) { 37775586Skcpoon sctp->sctp_recv_adaptation = 1; 37785586Skcpoon sctp_adaptation_event(sctp); 37790Sstevel@tonic-gate } 37800Sstevel@tonic-gate } else { 37813448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 37820Sstevel@tonic-gate sctpInInvalidCookie); 37830Sstevel@tonic-gate } 37840Sstevel@tonic-gate break; 37850Sstevel@tonic-gate case CHUNK_ERROR: { 37860Sstevel@tonic-gate int error; 37870Sstevel@tonic-gate 37880Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 37890Sstevel@tonic-gate error = sctp_handle_error(sctp, sctph, ch, mp); 37900Sstevel@tonic-gate if (error != 0) { 37913314Skcpoon sctp_assoc_event(sctp, SCTP_COMM_LOST, 37923314Skcpoon 0, NULL); 37930Sstevel@tonic-gate sctp_clean_death(sctp, error); 37940Sstevel@tonic-gate goto done; 37950Sstevel@tonic-gate } 37960Sstevel@tonic-gate break; 37970Sstevel@tonic-gate } 37980Sstevel@tonic-gate case CHUNK_ASCONF: 37990Sstevel@tonic-gate ASSERT(fp != NULL); 38000Sstevel@tonic-gate sctp_input_asconf(sctp, ch, fp); 38010Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 38020Sstevel@tonic-gate break; 38030Sstevel@tonic-gate case CHUNK_ASCONF_ACK: 38040Sstevel@tonic-gate ASSERT(fp != NULL); 38050Sstevel@tonic-gate sctp_faddr_alive(sctp, fp); 38060Sstevel@tonic-gate sctp_input_asconf_ack(sctp, ch, fp); 38070Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 38080Sstevel@tonic-gate break; 38090Sstevel@tonic-gate case CHUNK_FORWARD_TSN: 38100Sstevel@tonic-gate ASSERT(fp != NULL); 38110Sstevel@tonic-gate sctp->sctp_lastdata = fp; 38120Sstevel@tonic-gate sctp_process_forward_tsn(sctp, ch, fp, &ipp); 38130Sstevel@tonic-gate gotdata = 1; 38140Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 38150Sstevel@tonic-gate break; 38160Sstevel@tonic-gate default: 38170Sstevel@tonic-gate if (sctp_strange_chunk(sctp, ch, fp) == 0) { 38180Sstevel@tonic-gate goto nomorechunks; 38190Sstevel@tonic-gate } /* else skip and continue processing */ 38200Sstevel@tonic-gate break; 38210Sstevel@tonic-gate } 38220Sstevel@tonic-gate break; 38230Sstevel@tonic-gate 38240Sstevel@tonic-gate case SCTPS_LISTEN: 38250Sstevel@tonic-gate switch (ch->sch_id) { 38260Sstevel@tonic-gate case CHUNK_INIT: 38272776Skp158701 sctp_send_initack(sctp, sctph, ch, mp); 38280Sstevel@tonic-gate break; 38290Sstevel@tonic-gate case CHUNK_COOKIE: { 38300Sstevel@tonic-gate sctp_t *eager; 38310Sstevel@tonic-gate 38320Sstevel@tonic-gate if (sctp_process_cookie(sctp, ch, mp, &iack, 38335586Skcpoon sctph, &recv_adaptation, &peer_src) == -1) { 38343448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 38350Sstevel@tonic-gate sctpInInvalidCookie); 38360Sstevel@tonic-gate goto done; 38370Sstevel@tonic-gate } 38380Sstevel@tonic-gate 38390Sstevel@tonic-gate /* 38400Sstevel@tonic-gate * The cookie is good; ensure that 38410Sstevel@tonic-gate * the peer used the verification 38420Sstevel@tonic-gate * tag from the init ack in the header. 38430Sstevel@tonic-gate */ 38440Sstevel@tonic-gate if (iack->sic_inittag != sctph->sh_verf) 38450Sstevel@tonic-gate goto done; 38460Sstevel@tonic-gate 38470Sstevel@tonic-gate eager = sctp_conn_request(sctp, mp, ifindex, 38480Sstevel@tonic-gate ip_hdr_len, iack, ipsec_mp); 38490Sstevel@tonic-gate if (eager == NULL) { 38500Sstevel@tonic-gate sctp_send_abort(sctp, sctph->sh_verf, 38510Sstevel@tonic-gate SCTP_ERR_NO_RESOURCES, NULL, 0, mp, 38520Sstevel@tonic-gate 0, B_FALSE); 38530Sstevel@tonic-gate goto done; 38540Sstevel@tonic-gate } 38550Sstevel@tonic-gate 38560Sstevel@tonic-gate /* 38570Sstevel@tonic-gate * If there were extra chunks 38580Sstevel@tonic-gate * bundled with the cookie, 38590Sstevel@tonic-gate * they must be processed 38600Sstevel@tonic-gate * on the eager's queue. We 38610Sstevel@tonic-gate * accomplish this by refeeding 38620Sstevel@tonic-gate * the whole packet into the 38630Sstevel@tonic-gate * state machine on the right 38640Sstevel@tonic-gate * q. The packet (mp) gets 38650Sstevel@tonic-gate * there via the eager's 38660Sstevel@tonic-gate * cookie_mp field (overloaded 38670Sstevel@tonic-gate * with the active open role). 38680Sstevel@tonic-gate * This is picked up when 38690Sstevel@tonic-gate * processing the null bind 38700Sstevel@tonic-gate * request put on the eager's 38710Sstevel@tonic-gate * q by sctp_accept(). We must 38720Sstevel@tonic-gate * first revert the cookie 38730Sstevel@tonic-gate * chunk's length field to network 38740Sstevel@tonic-gate * byteorder so it can be 38750Sstevel@tonic-gate * properly reprocessed on the 38760Sstevel@tonic-gate * eager's queue. 38770Sstevel@tonic-gate */ 38783448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpPassiveEstab); 38790Sstevel@tonic-gate if (mlen > ntohs(ch->sch_len)) { 38800Sstevel@tonic-gate eager->sctp_cookie_mp = dupb(mp); 38811676Sjpk mblk_setcred(eager->sctp_cookie_mp, 38821676Sjpk CONN_CRED(eager->sctp_connp)); 38830Sstevel@tonic-gate /* 38840Sstevel@tonic-gate * If no mem, just let 38850Sstevel@tonic-gate * the peer retransmit. 38860Sstevel@tonic-gate */ 38870Sstevel@tonic-gate } 38880Sstevel@tonic-gate sctp_assoc_event(eager, SCTP_COMM_UP, 0, NULL); 38895586Skcpoon if (recv_adaptation) { 38905586Skcpoon eager->sctp_recv_adaptation = 1; 38915586Skcpoon eager->sctp_rx_adaptation_code = 38925586Skcpoon sctp->sctp_rx_adaptation_code; 38935586Skcpoon sctp_adaptation_event(eager); 38940Sstevel@tonic-gate } 38950Sstevel@tonic-gate 38960Sstevel@tonic-gate eager->sctp_active = now; 38970Sstevel@tonic-gate sctp_send_cookie_ack(eager); 38980Sstevel@tonic-gate 38990Sstevel@tonic-gate wake_eager = B_TRUE; 39000Sstevel@tonic-gate 39010Sstevel@tonic-gate /* 39020Sstevel@tonic-gate * Process rest of the chunks with eager. 39030Sstevel@tonic-gate */ 39040Sstevel@tonic-gate sctp = eager; 39050Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &peer_src); 39060Sstevel@tonic-gate /* 39070Sstevel@tonic-gate * Confirm peer's original source. fp can 39080Sstevel@tonic-gate * only be NULL if peer does not use the 39090Sstevel@tonic-gate * original source as one of its addresses... 39100Sstevel@tonic-gate */ 39110Sstevel@tonic-gate if (fp == NULL) 39120Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &src); 39130Sstevel@tonic-gate else 39140Sstevel@tonic-gate sctp_faddr_alive(sctp, fp); 39150Sstevel@tonic-gate 39160Sstevel@tonic-gate /* 39170Sstevel@tonic-gate * Validate the peer addresses. It also starts 39180Sstevel@tonic-gate * the heartbeat timer. 39190Sstevel@tonic-gate */ 39200Sstevel@tonic-gate sctp_validate_peer(sctp); 39210Sstevel@tonic-gate break; 39220Sstevel@tonic-gate } 39230Sstevel@tonic-gate /* Anything else is considered out-of-the-blue */ 39240Sstevel@tonic-gate case CHUNK_ERROR: 39250Sstevel@tonic-gate case CHUNK_ABORT: 39260Sstevel@tonic-gate case CHUNK_COOKIE_ACK: 39270Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 39280Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 39290Sstevel@tonic-gate goto done; 39300Sstevel@tonic-gate default: 39310Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 39320Sstevel@tonic-gate sctp_send_abort(sctp, sctph->sh_verf, 0, NULL, 39330Sstevel@tonic-gate 0, mp, 0, B_TRUE); 39340Sstevel@tonic-gate goto done; 39350Sstevel@tonic-gate } 39360Sstevel@tonic-gate break; 39370Sstevel@tonic-gate 39380Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 39390Sstevel@tonic-gate switch (ch->sch_id) { 39400Sstevel@tonic-gate case CHUNK_INIT_ACK: 39410Sstevel@tonic-gate sctp_stop_faddr_timers(sctp); 39420Sstevel@tonic-gate sctp_faddr_alive(sctp, sctp->sctp_current); 39430Sstevel@tonic-gate sctp_send_cookie_echo(sctp, ch, mp); 39440Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 39450Sstevel@tonic-gate break; 39460Sstevel@tonic-gate case CHUNK_ABORT: 39470Sstevel@tonic-gate sctp_process_abort(sctp, ch, ECONNREFUSED); 39480Sstevel@tonic-gate goto done; 39490Sstevel@tonic-gate case CHUNK_INIT: 39502776Skp158701 sctp_send_initack(sctp, sctph, ch, mp); 39510Sstevel@tonic-gate break; 39520Sstevel@tonic-gate case CHUNK_COOKIE: 39530Sstevel@tonic-gate if (sctp_process_cookie(sctp, ch, mp, &iack, 39545586Skcpoon sctph, &recv_adaptation, NULL) == -1) { 39553448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 39560Sstevel@tonic-gate sctpInInvalidCookie); 39570Sstevel@tonic-gate break; 39580Sstevel@tonic-gate } 39590Sstevel@tonic-gate sctp_send_cookie_ack(sctp); 39600Sstevel@tonic-gate sctp_stop_faddr_timers(sctp); 39610Sstevel@tonic-gate if (!SCTP_IS_DETACHED(sctp)) { 39624964Skcpoon sctp->sctp_ulp_connected( 3963*8348SEric.Yu@Sun.COM sctp->sctp_ulpd, 0, NULL, -1); 39644964Skcpoon sctp_set_ulp_prop(sctp); 39650Sstevel@tonic-gate } 39660Sstevel@tonic-gate sctp->sctp_state = SCTPS_ESTABLISHED; 39670Sstevel@tonic-gate sctp->sctp_assoc_start_time = (uint32_t)lbolt; 39683448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpActiveEstab); 39690Sstevel@tonic-gate if (sctp->sctp_cookie_mp) { 39700Sstevel@tonic-gate freemsg(sctp->sctp_cookie_mp); 39710Sstevel@tonic-gate sctp->sctp_cookie_mp = NULL; 39720Sstevel@tonic-gate } 39730Sstevel@tonic-gate 39740Sstevel@tonic-gate /* Validate the peer addresses. */ 39750Sstevel@tonic-gate sctp->sctp_active = now; 39760Sstevel@tonic-gate sctp_validate_peer(sctp); 39770Sstevel@tonic-gate 39780Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_UP, 0, NULL); 39795586Skcpoon if (recv_adaptation) { 39805586Skcpoon sctp->sctp_recv_adaptation = 1; 39815586Skcpoon sctp_adaptation_event(sctp); 39820Sstevel@tonic-gate } 39830Sstevel@tonic-gate /* Try sending queued data, or ASCONFs */ 39840Sstevel@tonic-gate trysend = 1; 39850Sstevel@tonic-gate break; 39860Sstevel@tonic-gate default: 39870Sstevel@tonic-gate if (sctp_strange_chunk(sctp, ch, fp) == 0) { 39880Sstevel@tonic-gate goto nomorechunks; 39890Sstevel@tonic-gate } /* else skip and continue processing */ 39900Sstevel@tonic-gate break; 39910Sstevel@tonic-gate } 39920Sstevel@tonic-gate break; 39930Sstevel@tonic-gate 39940Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 39950Sstevel@tonic-gate switch (ch->sch_id) { 39960Sstevel@tonic-gate case CHUNK_COOKIE_ACK: 39970Sstevel@tonic-gate if (!SCTP_IS_DETACHED(sctp)) { 39984964Skcpoon sctp->sctp_ulp_connected( 3999*8348SEric.Yu@Sun.COM sctp->sctp_ulpd, 0, NULL, -1); 40004964Skcpoon sctp_set_ulp_prop(sctp); 40010Sstevel@tonic-gate } 40020Sstevel@tonic-gate if (sctp->sctp_unacked == 0) 40030Sstevel@tonic-gate sctp_stop_faddr_timers(sctp); 40040Sstevel@tonic-gate sctp->sctp_state = SCTPS_ESTABLISHED; 40050Sstevel@tonic-gate sctp->sctp_assoc_start_time = (uint32_t)lbolt; 40063448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpActiveEstab); 40070Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 40080Sstevel@tonic-gate if (sctp->sctp_cookie_mp) { 40090Sstevel@tonic-gate freemsg(sctp->sctp_cookie_mp); 40100Sstevel@tonic-gate sctp->sctp_cookie_mp = NULL; 40110Sstevel@tonic-gate } 40120Sstevel@tonic-gate sctp_faddr_alive(sctp, fp); 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 /* Try sending queued data, or ASCONFs */ 40180Sstevel@tonic-gate trysend = 1; 40190Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_UP, 0, NULL); 40205586Skcpoon sctp_adaptation_event(sctp); 40210Sstevel@tonic-gate break; 40220Sstevel@tonic-gate case CHUNK_ABORT: 40230Sstevel@tonic-gate sctp_process_abort(sctp, ch, ECONNREFUSED); 40240Sstevel@tonic-gate goto done; 40250Sstevel@tonic-gate case CHUNK_COOKIE: 40260Sstevel@tonic-gate if (sctp_process_cookie(sctp, ch, mp, &iack, 40275586Skcpoon sctph, &recv_adaptation, NULL) == -1) { 40283448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 40290Sstevel@tonic-gate sctpInInvalidCookie); 40300Sstevel@tonic-gate break; 40310Sstevel@tonic-gate } 40320Sstevel@tonic-gate sctp_send_cookie_ack(sctp); 40330Sstevel@tonic-gate 40340Sstevel@tonic-gate if (!SCTP_IS_DETACHED(sctp)) { 40354964Skcpoon sctp->sctp_ulp_connected( 4036*8348SEric.Yu@Sun.COM sctp->sctp_ulpd, 0, NULL, -1); 40374964Skcpoon sctp_set_ulp_prop(sctp); 40380Sstevel@tonic-gate } 40390Sstevel@tonic-gate if (sctp->sctp_unacked == 0) 40400Sstevel@tonic-gate sctp_stop_faddr_timers(sctp); 40410Sstevel@tonic-gate sctp->sctp_state = SCTPS_ESTABLISHED; 40420Sstevel@tonic-gate sctp->sctp_assoc_start_time = (uint32_t)lbolt; 40433448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpActiveEstab); 40440Sstevel@tonic-gate if (sctp->sctp_cookie_mp) { 40450Sstevel@tonic-gate freemsg(sctp->sctp_cookie_mp); 40460Sstevel@tonic-gate sctp->sctp_cookie_mp = NULL; 40470Sstevel@tonic-gate } 40480Sstevel@tonic-gate /* Validate the peer addresses. */ 40490Sstevel@tonic-gate sctp->sctp_active = now; 40500Sstevel@tonic-gate sctp_validate_peer(sctp); 40510Sstevel@tonic-gate 40520Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_UP, 0, NULL); 40535586Skcpoon if (recv_adaptation) { 40545586Skcpoon sctp->sctp_recv_adaptation = 1; 40555586Skcpoon sctp_adaptation_event(sctp); 40560Sstevel@tonic-gate } 40570Sstevel@tonic-gate /* Try sending queued data, or ASCONFs */ 40580Sstevel@tonic-gate trysend = 1; 40590Sstevel@tonic-gate break; 40600Sstevel@tonic-gate case CHUNK_INIT: 40612776Skp158701 sctp_send_initack(sctp, sctph, ch, mp); 40620Sstevel@tonic-gate break; 40630Sstevel@tonic-gate case CHUNK_ERROR: { 40640Sstevel@tonic-gate sctp_parm_hdr_t *p; 40650Sstevel@tonic-gate 40660Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 40670Sstevel@tonic-gate /* check for a stale cookie */ 40680Sstevel@tonic-gate if (ntohs(ch->sch_len) >= 40690Sstevel@tonic-gate (sizeof (*p) + sizeof (*ch)) + 40700Sstevel@tonic-gate sizeof (uint32_t)) { 40710Sstevel@tonic-gate 40720Sstevel@tonic-gate p = (sctp_parm_hdr_t *)(ch + 1); 40730Sstevel@tonic-gate if (p->sph_type == 40740Sstevel@tonic-gate htons(SCTP_ERR_STALE_COOKIE)) { 40753448Sdh155122 BUMP_MIB(&sctps->sctps_mib, 40760Sstevel@tonic-gate sctpAborted); 40770Sstevel@tonic-gate sctp_error_event(sctp, ch); 40783314Skcpoon sctp_assoc_event(sctp, 40793314Skcpoon SCTP_COMM_LOST, 0, NULL); 40800Sstevel@tonic-gate sctp_clean_death(sctp, 40810Sstevel@tonic-gate ECONNREFUSED); 40820Sstevel@tonic-gate goto done; 40830Sstevel@tonic-gate } 40840Sstevel@tonic-gate } 40850Sstevel@tonic-gate break; 40860Sstevel@tonic-gate } 40870Sstevel@tonic-gate case CHUNK_HEARTBEAT: 40884964Skcpoon if (!hb_already) { 40894964Skcpoon sctp_return_heartbeat(sctp, ch, mp); 40904964Skcpoon hb_already = B_TRUE; 40914964Skcpoon } 40920Sstevel@tonic-gate break; 40930Sstevel@tonic-gate default: 40940Sstevel@tonic-gate if (sctp_strange_chunk(sctp, ch, fp) == 0) { 40950Sstevel@tonic-gate goto nomorechunks; 40960Sstevel@tonic-gate } /* else skip and continue processing */ 40970Sstevel@tonic-gate } /* switch (ch->sch_id) */ 40980Sstevel@tonic-gate break; 40990Sstevel@tonic-gate 41000Sstevel@tonic-gate case SCTPS_SHUTDOWN_ACK_SENT: 41010Sstevel@tonic-gate switch (ch->sch_id) { 41020Sstevel@tonic-gate case CHUNK_ABORT: 41030Sstevel@tonic-gate /* Pass gathered wisdom to IP for keeping */ 41041735Skcpoon sctp_update_ire(sctp); 41050Sstevel@tonic-gate sctp_process_abort(sctp, ch, 0); 41060Sstevel@tonic-gate goto done; 41070Sstevel@tonic-gate case CHUNK_SHUTDOWN_COMPLETE: 41080Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 41093448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpShutdowns); 41100Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_SHUTDOWN_COMP, 0, 41110Sstevel@tonic-gate NULL); 41120Sstevel@tonic-gate 41130Sstevel@tonic-gate /* Pass gathered wisdom to IP for keeping */ 41141735Skcpoon sctp_update_ire(sctp); 41150Sstevel@tonic-gate sctp_clean_death(sctp, 0); 41160Sstevel@tonic-gate goto done; 41170Sstevel@tonic-gate case CHUNK_SHUTDOWN_ACK: 41180Sstevel@tonic-gate sctp_shutdown_complete(sctp); 41190Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 41203448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpShutdowns); 41210Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_SHUTDOWN_COMP, 0, 41220Sstevel@tonic-gate NULL); 41230Sstevel@tonic-gate sctp_clean_death(sctp, 0); 41240Sstevel@tonic-gate goto done; 41250Sstevel@tonic-gate case CHUNK_COOKIE: 41260Sstevel@tonic-gate (void) sctp_shutdown_received(sctp, NULL, 41271735Skcpoon B_TRUE, B_FALSE, fp); 41280Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_ibchunks); 41290Sstevel@tonic-gate break; 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 case SCTPS_SHUTDOWN_RECEIVED: 41450Sstevel@tonic-gate switch (ch->sch_id) { 41460Sstevel@tonic-gate case CHUNK_SHUTDOWN: 41470Sstevel@tonic-gate trysend = sctp_shutdown_received(sctp, ch, 41481735Skcpoon B_FALSE, B_FALSE, fp); 41490Sstevel@tonic-gate break; 41500Sstevel@tonic-gate case CHUNK_SACK: 41510Sstevel@tonic-gate trysend = sctp_got_sack(sctp, ch); 4152852Svi117747 if (trysend < 0) { 4153852Svi117747 sctp_send_abort(sctp, sctph->sh_verf, 4154852Svi117747 0, NULL, 0, mp, 0, B_FALSE); 4155852Svi117747 sctp_assoc_event(sctp, 4156852Svi117747 SCTP_COMM_LOST, 0, NULL); 4157852Svi117747 sctp_clean_death(sctp, 4158852Svi117747 ECONNABORTED); 4159852Svi117747 goto done; 4160852Svi117747 } 41610Sstevel@tonic-gate break; 41620Sstevel@tonic-gate case CHUNK_ABORT: 41630Sstevel@tonic-gate sctp_process_abort(sctp, ch, ECONNRESET); 41640Sstevel@tonic-gate goto done; 41650Sstevel@tonic-gate case CHUNK_HEARTBEAT: 41664964Skcpoon if (!hb_already) { 41674964Skcpoon sctp_return_heartbeat(sctp, ch, mp); 41684964Skcpoon hb_already = B_TRUE; 41694964Skcpoon } 41700Sstevel@tonic-gate break; 41710Sstevel@tonic-gate default: 41720Sstevel@tonic-gate if (sctp_strange_chunk(sctp, ch, fp) == 0) { 41730Sstevel@tonic-gate goto nomorechunks; 41740Sstevel@tonic-gate } /* else skip and continue processing */ 41750Sstevel@tonic-gate break; 41760Sstevel@tonic-gate } 41770Sstevel@tonic-gate break; 41780Sstevel@tonic-gate 41790Sstevel@tonic-gate default: 41801932Svi117747 /* 41811932Svi117747 * The only remaining states are SCTPS_IDLE and 41821932Svi117747 * SCTPS_BOUND, and we should not be getting here 41831932Svi117747 * for these. 41841932Svi117747 */ 41851932Svi117747 ASSERT(0); 41860Sstevel@tonic-gate } /* switch (sctp->sctp_state) */ 41870Sstevel@tonic-gate 41880Sstevel@tonic-gate ch = sctp_next_chunk(ch, &mlen); 41890Sstevel@tonic-gate if (ch != NULL && !sctp_check_input(sctp, ch, mlen, 0)) 41900Sstevel@tonic-gate goto done; 41910Sstevel@tonic-gate } while (ch != NULL); 41920Sstevel@tonic-gate 41930Sstevel@tonic-gate /* Finished processing all chunks in packet */ 41940Sstevel@tonic-gate 41950Sstevel@tonic-gate nomorechunks: 41960Sstevel@tonic-gate /* SACK if necessary */ 41970Sstevel@tonic-gate if (gotdata) { 41984964Skcpoon boolean_t sack_sent; 41994964Skcpoon 42000Sstevel@tonic-gate (sctp->sctp_sack_toggle)++; 42014964Skcpoon sack_sent = sctp_sack(sctp, dups); 42020Sstevel@tonic-gate dups = NULL; 42030Sstevel@tonic-gate 42044964Skcpoon /* If a SACK is sent, no need to restart the timer. */ 42054964Skcpoon if (!sack_sent && !sctp->sctp_ack_timer_running) { 42060Sstevel@tonic-gate sctp->sctp_ack_timer_running = B_TRUE; 42070Sstevel@tonic-gate sctp_timer(sctp, sctp->sctp_ack_mp, 42083448Sdh155122 MSEC_TO_TICK(sctps->sctps_deferred_ack_interval)); 42090Sstevel@tonic-gate } 42100Sstevel@tonic-gate } 42110Sstevel@tonic-gate 42120Sstevel@tonic-gate if (trysend) { 42133795Skcpoon sctp_output(sctp, UINT_MAX); 42140Sstevel@tonic-gate if (sctp->sctp_cxmit_list != NULL) 42150Sstevel@tonic-gate sctp_wput_asconf(sctp, NULL); 42160Sstevel@tonic-gate } 42170Sstevel@tonic-gate /* If there is unsent data, make sure a timer is running */ 42180Sstevel@tonic-gate if (sctp->sctp_unsent > 0 && !sctp->sctp_current->timer_running) { 42190Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current, 42200Sstevel@tonic-gate sctp->sctp_current->rto); 42210Sstevel@tonic-gate } 42220Sstevel@tonic-gate 42230Sstevel@tonic-gate done: 42240Sstevel@tonic-gate if (dups != NULL) 42250Sstevel@tonic-gate freeb(dups); 42260Sstevel@tonic-gate if (ipsec_mp != NULL) 42270Sstevel@tonic-gate freeb(ipsec_mp); 42280Sstevel@tonic-gate freemsg(mp); 42290Sstevel@tonic-gate 42304964Skcpoon if (sctp->sctp_err_chunks != NULL) 42314964Skcpoon sctp_process_err(sctp); 42324964Skcpoon 42330Sstevel@tonic-gate if (wake_eager) { 42340Sstevel@tonic-gate /* 42350Sstevel@tonic-gate * sctp points to newly created control block, need to 42360Sstevel@tonic-gate * release it before exiting. Before releasing it and 42370Sstevel@tonic-gate * processing the sendq, need to grab a hold on it. 42380Sstevel@tonic-gate * Otherwise, another thread can close it while processing 42390Sstevel@tonic-gate * the sendq. 42400Sstevel@tonic-gate */ 42410Sstevel@tonic-gate SCTP_REFHOLD(sctp); 42420Sstevel@tonic-gate WAKE_SCTP(sctp); 42430Sstevel@tonic-gate sctp_process_sendq(sctp); 42440Sstevel@tonic-gate SCTP_REFRELE(sctp); 42450Sstevel@tonic-gate } 42460Sstevel@tonic-gate } 42470Sstevel@tonic-gate 42480Sstevel@tonic-gate /* 42490Sstevel@tonic-gate * Some amount of data got removed from rx q. 42500Sstevel@tonic-gate * Check if we should send a window update. 42510Sstevel@tonic-gate * 42520Sstevel@tonic-gate * Due to way sctp_rwnd updates are made, ULP can give reports out-of-order. 42530Sstevel@tonic-gate * To keep from dropping incoming data due to this, we only update 42540Sstevel@tonic-gate * sctp_rwnd when if it's larger than what we've reported to peer earlier. 42550Sstevel@tonic-gate */ 42560Sstevel@tonic-gate void 42570Sstevel@tonic-gate sctp_recvd(sctp_t *sctp, int len) 42580Sstevel@tonic-gate { 42590Sstevel@tonic-gate int32_t old, new; 42603448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 42610Sstevel@tonic-gate 42620Sstevel@tonic-gate ASSERT(sctp != NULL); 42630Sstevel@tonic-gate RUN_SCTP(sctp); 42640Sstevel@tonic-gate 42650Sstevel@tonic-gate if (len < sctp->sctp_rwnd) { 42660Sstevel@tonic-gate WAKE_SCTP(sctp); 42670Sstevel@tonic-gate return; 42680Sstevel@tonic-gate } 42690Sstevel@tonic-gate ASSERT(sctp->sctp_rwnd >= sctp->sctp_rxqueued); 42700Sstevel@tonic-gate old = sctp->sctp_rwnd - sctp->sctp_rxqueued; 42710Sstevel@tonic-gate new = len - sctp->sctp_rxqueued; 42720Sstevel@tonic-gate sctp->sctp_rwnd = len; 42730Sstevel@tonic-gate 42740Sstevel@tonic-gate if (sctp->sctp_state >= SCTPS_ESTABLISHED && 42750Sstevel@tonic-gate ((old <= new >> 1) || (old < sctp->sctp_mss))) { 42760Sstevel@tonic-gate sctp->sctp_force_sack = 1; 42773448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpOutWinUpdate); 42784964Skcpoon (void) sctp_sack(sctp, NULL); 42790Sstevel@tonic-gate old = 1; 42800Sstevel@tonic-gate } else { 42810Sstevel@tonic-gate old = 0; 42820Sstevel@tonic-gate } 42830Sstevel@tonic-gate WAKE_SCTP(sctp); 42840Sstevel@tonic-gate if (old > 0) { 42850Sstevel@tonic-gate sctp_process_sendq(sctp); 42860Sstevel@tonic-gate } 42870Sstevel@tonic-gate } 4288