sctp_input.c revision 1d19ca101f1c458100349d59ba2d115d8e2c6f9d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define _SUN_TPI_VERSION 2
#include <inet/ipclassifier.h>
#include <inet/ipp_common.h>
#include <inet/ipsec_impl.h>
#include "sctp_impl.h"
#include "sctp_asconf.h"
#include "sctp_addr.h"
static struct kmem_cache *sctp_kmem_set_cache;
/*
* PR-SCTP comments.
*
* When we get a valid Forward TSN chunk, we check the fragment list for this
* SSN and preceeding SSNs free all them. Further, if this Forward TSN causes
* the next expected SSN to be present in the stream queue, we deliver any
* such stranded messages upstream. We also update the SACK info. appropriately.
* When checking for advancing the cumulative ack (in sctp_cumack()) we must
* check for abandoned chunks and messages. While traversing the tramsmit
* list if we come across an abandoned chunk, we can skip the message (i.e.
* take it out of the (re)transmit list) since this message, and hence this
* chunk, has been marked abandoned by sctp_rexmit(). If we come across an
* unsent chunk for a message this now abandoned we need to check if a
* Forward TSN needs to be sent, this could be a case where we deferred sending
* a Forward TSN in sctp_get_msg_to_send(). Further, after processing a
* SACK we check if the Advanced peer ack point can be moved ahead, i.e.
* if we can send a Forward TSN via sctp_check_abandoned_data().
*/
void
{
sctp_set_t *p;
while (s) {
p = s->next;
s = p;
}
}
static void
{
sctp_set_t *p, *t;
return;
return;
*num = 1;
return;
}
/*
* Handle this special case here so we don't have to check
* for it each time in the loop.
*/
/* add a new set, and move the head pointer */
if (t == NULL)
return;
(*num)++;
*head = t;
return;
}
/*
* We need to handle the following cases, where p points to
* the current set (as we walk through the loop):
*
* 1. tsn is entirely less than p; create a new set before p.
* 2. tsn borders p from less; coalesce p with tsn.
* 3. tsn is withing p; do nothing.
* 4. tsn borders p from greater; coalesce p with tsn.
* 4a. p may now border p->next from less; if so, coalesce those
* two sets.
* 5. tsn is entirely greater then all sets; add a new set at
* the end.
*/
/* 1: add a new set before p. */
if (t == NULL)
return;
t->next = p;
if (p->prev) {
}
p->prev = t;
(*num)++;
return;
}
/* 2: adjust p->begin */
return;
}
/* 3; do nothing */
return;
}
/* 4; adjust p->end */
/* 4a: coalesce p and p->next */
t = p->next;
(*num)--;
}
return;
}
/* 5: add new set at the end */
if (t == NULL)
return;
t->prev = p;
p->next = t;
(*num)++;
return;
}
continue;
}
}
static void
{
sctp_set_t *p, *t;
return;
/* Nothing to remove */
return;
/* Find out where to start removing sets */
break;
}
/* adjust p */
/* all done */
if (p == *head)
return;
/* remove this set too */
p = p->next;
}
/* unlink everything before this set */
t = *head;
*head = p;
}
sctp_free_set(t);
/* recount the number of sets */
*num = 0;
(*num)++;
}
void
{
NULL, 0);
}
void
{
}
{
return (NULL);
}
return (NULL);
}
return (ch);
}
{
int pad;
if (!ch) {
return (NULL);
}
}
}
/*
* Attach ancillary data to a received SCTP segments.
* If the source address (fp) is not the primary, send up a
* unitdata_ind so recvfrom() can populate the msg_name field.
* If ancillary data is also requested, we append it to the
* unitdata_req. Otherwise, we just send up an optdata_ind.
*/
static int
{
struct T_unitdata_ind *tudi;
int optlen;
int hdrlen;
struct sockaddr_in6 *sin6;
struct sockaddr_in *sin4;
/* Figure out address size */
} else {
}
/* If app asked to receive send / recv info */
if (sctp->sctp_recvsndrcvinfo) {
if (hdrlen == 0)
hdrlen = sizeof (struct T_optdata_ind);
}
if (sctp->sctp_ipv6_recvancillary == 0)
goto noancillary;
if (hdrlen == 0)
hdrlen = sizeof (struct T_unitdata_ind);
}
/* If app asked for hoplimit and it has changed ... */
if (hdrlen == 0)
hdrlen = sizeof (struct T_unitdata_ind);
}
/* If app asked for hopbyhop headers and it has changed ... */
if (hdrlen == 0)
hdrlen = sizeof (struct T_unitdata_ind);
return (-1);
}
/* If app asked for dst headers before routing headers ... */
if (hdrlen == 0)
hdrlen = sizeof (struct T_unitdata_ind);
return (-1);
}
/* If app asked for routing headers and it has changed ... */
if (hdrlen == 0)
hdrlen = sizeof (struct T_unitdata_ind);
return (-1);
}
}
/* If app asked for dest headers and it has changed ... */
if (hdrlen == 0)
hdrlen = sizeof (struct T_unitdata_ind);
return (-1);
}
/* Nothing to add */
if (hdrlen == 0)
return (-1);
return (-1);
if (sin4) {
} else {
}
if (sctp->sctp_recvsndrcvinfo) {
/* XXX need backout method if memory allocation fails. */
struct sctp_sndrcvinfo *sri;
if (SCTP_DATA_GET_UBIT(dcp)) {
} else {
sri->sinfo_flags = 0;
}
sri->sinfo_context = 0;
sri->sinfo_timetolive = 0;
sri->sinfo_assoc_id = 0;
}
/*
* If app asked for pktinfo and the index has changed ...
* Note that the local address never changes for the connection.
*/
if (addflag & SCTP_IPV6_RECVPKTINFO) {
struct in6_pktinfo *pkti;
else
/* Save as "last" value */
}
/* If app asked for hoplimit and it has changed ... */
if (addflag & SCTP_IPV6_RECVHOPLIMIT) {
/* Save as "last" value */
}
if (addflag & SCTP_IPV6_RECVHOPOPTS) {
/* Save as last value */
}
if (addflag & SCTP_IPV6_RECVRTDSTOPTS) {
/* Save as last value */
}
if (addflag & SCTP_IPV6_RECVRTHDR) {
/* Save as last value */
}
if (addflag & SCTP_IPV6_RECVDSTOPTS) {
/* Save as last value */
}
return (0);
}
void
{
}
}
}
/*
* If the series of data fragments of which dmp is a part is successfully
* reassembled, the first mblk in the series is returned. dc is adjusted
* to point at the data chunk in the lead mblk, and b_rptr also points to
* the data chunk; the following mblk's b_rptr's point at the actual payload.
*
* If the series is not yet reassembled, NULL is returned. dc is not changed.
* XXX should probably move this up into the state machine.
*/
/* Fragment list for un-ordered messages. Partial delivery is not supported */
static mblk_t *
{
#ifdef DEBUG
#endif
/* First frag. */
return (NULL);
}
/*
* Insert the segment according to the TSN, fragmented unordered
* chunks are sequenced by TSN.
*/
} else {
}
break;
}
break;
}
}
/* check if we completed a msg */
if (SCTP_DATA_GET_BBIT(*dc)) {
} else if (SCTP_DATA_GET_EBIT(*dc)) {
}
/*
* We walk consecutive TSNs backwards till we get a seg. with
* the B bit
*/
return (NULL);
}
if (SCTP_DATA_GET_BBIT(qdc)) {
break;
}
}
}
/*
* We walk consecutive TSNs till we get a seg. with the E bit
*/
return (NULL);
}
if (SCTP_DATA_GET_EBIT(qdc)) {
break;
}
}
}
return (NULL);
}
/* Got one!, Remove the msg from the list */
} else {
}
/*
* Null out b_next and b_prev and chain using b_cont.
*/
}
#ifdef DEBUG
}
#endif
return (begin);
}
/*
* Try partial delivery.
*/
static mblk_t *
{
/*
* This loop has two exit conditions: the
* end of received chunks has been reached, or
* there is a break in the sequence. We want
* to chop the reassembly list as follows (the
* numbers are TSNs):
* 10 -> 11 -> (end of chunks)
* 10 -> 11 -> | 13 (break in sequence)
*/
break;
tsn++;
}
/*
* We are sending all the fragments upstream, we have to retain
* the srp info for further fragments.
*/
} else {
}
/*
* mp now points at the last chunk in the sequence,
* and prev points to mp's previous in the list.
* We chop the list at prev, and convert mp into the
* new list head by setting the B bit. Subsequence
* fragment deliveries will follow the normal reassembly
* path.
*/
/*
* Adjust all mblk's except the lead so their rptr's point to the
* payload. sctp_data_chunk() will need to process the lead's
* data chunk section, so leave it's rptr pointing at the data chunk.
*/
}
}
/*
* Deduct the balance from got and needed here, now that
* we know we are actually delivering these data.
*/
}
}
}
return (dmp);
}
/*
* Fragment list for ordered messages.
* If no error occures, error is set to 0. If we run out of memory, error
* is set to 1. If the peer commits a fatal error (like using different
* sequence numbers for the same data fragment series), the association is
* aborted and error is set to 2. tpfinished indicates whether we have
* assembled a complete message, this is used in sctp_data_chunk() to
* see if we can try to send any queued message for this stream.
*/
static mblk_t *
{
*error = 0;
/* find the reassembly queue for this data chunk */
goto foundit;
break;
}
/*
* Allocate a M_CTL that will contain information about this
* fragmented message.
*/
*error = 1;
return (NULL);
}
} else {
}
} else {
/* make a new reass head and stick it on the end */
} else {
}
}
if (SCTP_DATA_GET_BBIT(*dc)) {
} else if (srp->partial_delivered &&
/* Last fragment */
if (SCTP_DATA_GET_EBIT(*dc)) {
goto frag_done;
}
}
return (NULL);
/*
* else already have a reassembly queue. Insert the new data chunk
* in the reassemble queue. Try the tail first, on the assumption
* that the fragments are coming in in order.
*/
/*
* This means the message was partially delivered.
*/
goto empty_srp;
}
/* XXXIs it fine to do this just here? */
/* our peer is fatally confused; XXX abort the assc */
*error = 2;
return (NULL);
}
}
goto inserted;
}
/* Next check for insertion at the beginning */
if (SCTP_DATA_GET_BBIT(*dc)) {
}
goto preinserted;
}
/* Insert somewhere in the middle */
for (;;) {
/* Tail check above should have caught this */
/* insert here */
break;
}
}
goto inserted;
/*
* fraglen contains the length of consecutive chunks of fragments.
* starting from the chunk inserted recently.
*/
break;
tsn++;
}
/* check if we have the first and last fragments */
/* calculate how many fragments are needed, if possible */
}
}
/*
* Try partial delivery if the message length has exceeded the
* partial delivery point. Only do this if we can immediately
* deliver the partially assembled message, and only partially
* deliver one message at a time (i.e. messages cannot be
* intermixed arriving at the upper layer). A simple way to
* enforce this is to only try partial delivery if this TSN is
* the next expected TSN. Partial Delivery not supported
* for un-ordered message.
*/
*tpfinished = B_FALSE;
}
return (dmp);
}
/*
* else reassembly done; prepare the data for delivery.
* First unlink hmp from the ssn list.
*/
} else {
}
/*
* Using b_prev and b_next was a little sinful, but OK since
* this mblk is never put*'d. However, freeb() will still
* ASSERT that they are unused, so we need to NULL them out now.
*/
*tpfinished = B_TRUE;
/*
* Adjust all mblk's except the lead so their rptr's point to the
* payload. sctp_data_chunk() will need to process the lead's
* data chunk section, so leave it's rptr pointing at the data chunk.
*/
}
return (dmp);
}
static void
{
return;
}
/* first time? */
return;
}
}
/* maximum reached */
return;
}
/* add the duplicate tsn */
}
static void
{
int ubit;
int isfrag;
int dlen;
/* The following are used multiple times, so we inline them */
if ((sctp)->sctp_sack_gaps > 0) \
/* Got a gap; record it */ \
&sctp->sctp_sack_gaps); \
}
/* Check for duplicates */
return;
}
sctp_set_t *sp;
dprint(4,
("sctp_data_chunk: dropping dup > cumtsn\n"));
return;
}
}
}
/* We cannot deliver anything up now but we still need to handle it. */
if (SCTP_IS_DETACHED(sctp)) {
}
/* Check for buffer space */
/* Drop and SACK, but don't advance the cumulative TSN. */
dprint(0, ("sctp_data_chunk: exceed rwnd %d rxqueued %d "
return;
}
/* RESERVED to be ignored at the receiving end */
inval_parm[1] = 0;
/* ack and drop it */
(char *)inval_parm, sizeof (inval_parm));
return;
}
/* Initialize the stream, if not yet used */
/* drop it and don't ack it, causing the peer to retransmit */
return;
}
if (isfrag) {
int error = 0;
/* fragmented data chunk */
if (ubit) {
#if DEBUG
}
#endif
} else {
&tpfinished);
}
if (error != 0) {
if (error == 1) {
/*
* out of memory; don't ack it so
* the peer retransmits
*/
return;
} else if (error == 2) {
/*
* fatal error (i.e. peer used different
* ssn's for same fragmented data) --
* the association has been aborted.
* XXX need to return errval so state
* machine can also abort processing.
*/
dprint(0, ("error 2: must not happen!\n"));
return;
}
}
/*
* Can't process this data now, but the cumulative
* TSN may be advanced, so do the checks at done.
*/
goto done;
}
}
/* Adjust rptr to point at the data chunk for compares */
dprint(2,
("data_chunk: inserted %x in pq (ssn %d expected %d)\n",
} else {
/*
* XXXNeed to take sequence wraps into account,
* ... and a more efficient insertion algo.
*/
for (;;) {
} else {
}
break;
}
break;
}
}
}
(instr->istr_nmsgs)++;
(sctp->sctp_istr_nmsgs)++;
return;
}
/*
* Else we can deliver the data directly. Recalculate
* dlen now since we may have reassembled data.
*/
/* Deliver the message. */
if (can_deliver) {
tpfinished ? 0 : SCTP_PARTIAL_DATA);
}
} else {
/* Just free the message if we don't have memory. */
return;
}
} else {
/* About to free the data */
}
/*
* data, now enqueued, may already have been processed and free'd
* by the ULP (or we may have just freed it above, if we could not
* deliver it), so we must not reference it (this is why we kept
* the ssn and ubit above).
*/
if (ubit != 0) {
goto done;
}
/*
* If there was a partial delivery and it has not finished,
* don't pull anything from the pqueues.
*/
if (!tpfinished) {
goto done;
}
/* Deliver any successive data chunks in the instr queue */
while (instr->istr_nmsgs > 0) {
/* Gap in the sequence */
break;
/* Else deliver the data */
(instr->istr_nmsgs)--;
(sctp->sctp_istr_nmsgs)--;
/*
* If this chunk was reassembled, each b_cont represents
* another TSN; advance ftsn now.
*/
if (can_deliver) {
ipp) == 0) {
}
} else {
return;
}
} else {
/* About to free the data */
}
}
done:
/*
* If there are gap reports pending, check if advancing
* the ftsn here closes a gap. If so, we can advance
* ftsn to the end of the set.
*/
}
/*
* If ftsn has moved forward, maybe we can remove gap reports.
* NB: dmp may now be NULL, so don't dereference it here.
*/
&sctp->sctp_sack_gaps);
}
#ifdef DEBUG
}
#endif
}
void
{
sctp_set_t *sp;
/* Chunk hdr */
/* SACK chunk */
} else {
sc->ssc_a_rwnd = 0;
}
sc->ssc_numdups = 0;
/* lay in gap reports */
/* start */
} else {
/* sequence number wrap */
}
/* end */
} else {
/* sequence number wrap */
}
sf++;
/* This is just for debugging (a la the following assertion) */
num_gaps--;
}
/* If the SACK timer is running, stop it */
if (sctp->sctp_ack_timer_running) {
}
}
mblk_t *
{
if (sctp->sctp_force_sack) {
sctp->sctp_force_sack = 0;
goto checks_done;
}
/* no need to SACK right now */
(void *)sctp));
return (NULL);
sctp->sctp_sack_toggle = 0;
}
}
(void *)sctp));
return (NULL);
}
return (NULL);
}
if (dups) {
/ sizeof (uint32_t));
}
return (smp);
}
void
{
/* If we are shutting down, let send_shutdown() bundle the SACK */
sctp_send_shutdown(sctp, 0);
}
/* The caller of sctp_sack() will not free the dups mblk. */
return;
}
(void *)sctp->sctp_lastdata,
}
/*
* This is called if we have a message that was partially sent and is
* abandoned. The cum TSN will be the last chunk sent for this message,
* subsequent chunks will be marked ABANDONED. We send a Forward TSN
* chunk in this case with the TSN of the last sent chunk so that the
* peer can clean up its fragment list for this message. This message
* will be removed from the transmit list when the peer sends a SACK
* back.
*/
int
{
if (!ubit &&
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
if (!fp->timer_running)
}
/*
* Update ULP the amount of queued data, which is
* sent-unack'ed + unsent.
*/
if (!SCTP_IS_DETACHED(sctp)) {
}
return (0);
}
return (-1);
}
{
uint32_t cumack_forward = 0;
/*
* Free messages only when they're completely acked.
*/
if (SCTP_CHUNK_ABANDONED(mp)) {
break;
}
/*
* We check for abandoned message if we are PR-SCTP
* aware, if this is not the first chunk in the
* message (b_cont) and if the message is marked
* abandoned.
*/
if (!SCTP_CHUNK_ISSENT(mp)) {
if (sctp->sctp_prsctp_aware &&
(SCTP_IS_MSG_ABANDONED(ump) ||
sctp))) {
(void) sctp_check_abandoned_msg(sctp,
ump);
}
goto cum_ack_done;
}
continue;
if (sctp->sctp_out_time != 0 &&
/* Got a new RTT measurement */
sctp->sctp_out_time = 0;
}
if (SCTP_CHUNK_ISACKED(mp))
continue;
SCTP_CHUNK_SET_SACKCNT(mp, 0);
sctp->sctp_unacked -=
/* all outstanding data acked */
} else {
}
} else {
goto cum_ack_done;
}
}
if (SCTP_IS_MSG_ABANDONED(ump)) {
} else {
}
}
*first_unacked = mp;
if (cumack_forward > 0) {
}
/*
* Update ULP the amount of queued data, which is
* sent-unack'ed + unsent.
*/
if (!SCTP_IS_DETACHED(sctp)) {
}
/* Time to send a shutdown? */
sctp_send_shutdown(sctp, 0);
}
} else {
/* dup ack */
}
return (cumack_forward);
}
static int
{
sctp->sctp_frwnd = 0;
return (0);
}
return (1);
} else {
return (0);
}
}
/*
* For un-ordered messages.
* Walk the sctp->sctp_uo_frag list and remove any fragments with TSN
* strictly in sequence (w.r.t TSN).
*/
static int
{
int dlen = 0;
return (dlen);
}
return (dlen);
}
/*
* For ordered messages.
* Check for existing fragments for an sid-ssn pair reported as abandoned,
* hence will not receive, in the Forward TSN. If there are fragments, then
* we just nuke them. If and when Partial Delivery API is supported, we
* would need to send a notification to the upper layer about this.
*/
static int
{
int dlen = 0;
return (dlen);
/*
* If we had sent part of this message up, send a partial
* delivery event. Since this is ordered delivery, we should
* have sent partial message only for the next in sequence,
* hence the ASSERT. See comments in sctp_data_chunk() for
* trypartial.
*/
if (srp->partial_delivered) {
}
/* Take it out of the reass queue */
}
}
return (dlen);
}
/*
* Update sctp_ftsn to the cumulative TSN from the Forward TSN chunk. Remove
* any SACK gaps less than the newly updated sctp_ftsn. Walk through the
* sid-ssn pair in the Forward TSN and for each, clean the fragment list
* for this pair, if needed, and check if we can deliver subsequent
* messages, if any, from the instream queue (that were waiting for this
* sid-ssn message to show up). Once we are done try to update the SACK
* info. We could get a duplicate Forward TSN, in which case just send
* a SACK. If any of the sid values in the the Forward TSN is invalid,
* send back an "Invalid Stream Identifier" error and continue processing
* the rest.
*/
static void
{
int flen;
if (SCTP_IS_DETACHED(sctp)) {
}
/*
* un-ordered messages don't have SID-SSN pair entries, we check
* for any fragments (for un-ordered message) to be discarded using
* the cumulative FTSN.
*/
if (flen > 0) {
}
while (remaining >= sizeof (*ftsn_entry)) {
/* RESERVED to be ignored at the receiving end */
inval_parm[1] = 0;
(char *)inval_parm, sizeof (inval_parm));
ftsn_entry++;
remaining -= sizeof (*ftsn_entry);
continue;
}
/* Indicates frags were nuked, update rxqueued */
if (flen > 0) {
}
/*
* It is possible to receive an FTSN chunk with SSN smaller
* than then nextseq if this chunk is a retransmission because
* of incomplete processing when it was first processed.
*/
while (instr->istr_nmsgs > 0) {
break;
}
if (can_deliver) {
} else {
/*
* We will resume processing when
* the FTSN chunk is re-xmitted.
*/
dprint(0,
("FTSN dequeuing %u failed\n",
return;
}
} else {
}
instr->istr_nmsgs--;
sctp->sctp_istr_nmsgs--;
}
ftsn_entry++;
remaining -= sizeof (*ftsn_entry);
}
/* Duplicate FTSN */
return;
}
/* Advance cum TSN to that reported in the Forward TSN chunk */
/* Remove all the SACK gaps before the new cum TSN */
&sctp->sctp_sack_gaps);
}
/*
* If there are gap reports pending, check if advancing
* the ftsn here closes a gap. If so, we can advance
* ftsn to the end of the set.
* If ftsn has moved forward, maybe we can remove gap reports.
*/
&sctp->sctp_sack_gaps);
}
}
/*
* When we have processed a SACK we check to see if we can advance the
* cumulative TSN if there are abandoned chunks immediately following
* the updated cumulative TSN. If there are, we attempt to send a
* Forward TSN chunk.
*/
static void
{
/*
* We only check in the first meta since otherwise we can't
* advance the cumulative ack point. We just look for chunks
* marked for retransmission, else we might prematurely
* send an FTSN for a sent, but unacked, chunk.
*/
if (!SCTP_CHUNK_ISSENT(mp))
return;
if (SCTP_CHUNK_WANT_REXMIT(mp))
break;
}
return;
if (!fp->timer_running)
return;
}
if (!fp->timer_running)
}
}
/*
* The processing here follows the same logic in sctp_got_sack(), the reason
* we do this separately is because, usually, gap blocks are ordered and
* we can process it in sctp_got_sack(). However if they aren't we would
* need to do some additional non-optimal stuff when we start processing the
* unordered gaps. To that effect sctp_got_sack() does the processing in the
* simple case and this does the same in the more involved case.
*/
static uint32_t
{
int gapcnt;
int gstart;
/*
* gstart tracks the last (in the order of TSN) gapstart that
* we process in this SACK gaps walk.
*/
if (gapstart != 0) {
/*
* If we have reached the end of the transmit list or
* hit an unsent chunk or encountered an unordered gap
* block start from the ctsn again.
*/
}
}
/* SACK for TSN we have not sent - ABORT */
*trysend = -1;
return (acked);
break;
}
/*
* The xtsn can be the TSN processed for the last gap
* (gapend) or it could be the cumulative TSN. We continue
* with the last xtsn as long as the gaps are ordered, when
* we hit an unordered gap, we re-start from the cumulative
* TSN. For the first gap it is always the cumulative TSN.
*/
/*
* We can't reliably check for reneged chunks
* when walking the unordered list, so we don't.
* In case the peer reneges then we will end up
* sending the reneged chunk via timeout.
*/
/*
* ump can't be NULL because of the sanity
* check above.
*/
}
/*
* mp can't be unsent because of the sanity check
* above.
*/
}
/*
* Now that we have found the chunk with TSN == 'gapstart',
* let's walk till we hit the chunk with TSN == 'gapend'.
* All intermediate chunks will be marked ACKED, if they
* haven't already been.
*/
/*
* SACKed
*/
SCTP_CHUNK_SET_SACKCNT(mp, 0);
if (!SCTP_CHUNK_ISACKED(mp)) {
/* All outstanding data acked. */
}
}
/*
* Move to the next message in the transmit list
* if we are done with all the chunks from the current
* message. Note, it is possible to hit the end of the
* transmit list here, i.e. if we have already completed
* processing the gap block.
*/
break;
}
}
/*
* Likewise, we can hit an unsent chunk once we have
* completed processing the gap block.
*/
if (!SCTP_CHUNK_ISSENT(mp)) {
break;
}
}
/*
* We keep track of the last gap we successfully processed
* so that we can terminate the walk below for incrementing
* the SACK count.
*/
}
/*
* Check if have incremented the SACK count for all unacked TSNs in
* sctp_got_sack(), if so we are done.
*/
return (acked);
/*
* We have incremented SACK count for TSNs less than fr_tsn
* in sctp_got_sack(), so don't increment them again here.
*/
if (SCTP_CHUNK_SACKCNT(mp) ==
*trysend = 1;
if (!*fast_recovery) {
/*
* Entering fast recovery.
*/
}
*fast_recovery = B_TRUE;
}
}
}
/* We can't get to the end of the transmit list here */
}
/* We can't hit an unsent chunk here */
}
return (acked);
}
static int
{
int num_gaps;
int trysend = 0;
int i;
return (0);
cumtsn));
/* out of order */
return (0);
/* Send an ABORT */
return (-1);
}
/*
* Cwnd only done when not in fast recovery mode.
*/
/*
* .. and if the cum TSN is not moving ahead on account Forward TSN
*/
else
/*
* If we were doing a zero win probe and the win
* has now opened to at least MSS, re-transmit the
* zero win probe via sctp_rexmit_packet().
*/
/*
* Reset the RTO since we have been backing-off
* to send the ZWP.
*/
/* Resend the ZWP */
&pkt_len);
return (0);
}
}
} else {
if (sctp->sctp_zero_win_probe) {
/*
* Reset the RTO since we have been backing-off
* to send the ZWP.
*/
/* This is probably not required */
if (!sctp->sctp_rexmitting) {
}
}
if (acked > 0) {
trysend = 1;
sctp->sctp_adv_pap)) {
}
}
}
goto ret;
}
#ifdef DEBUG
/*
* Since we delete any message that has been acked completely,
* the unacked chunk must belong to sctp_xmit_head (as
* we don't have a back pointer from the mp to the meta data
* we do this).
*/
{
break;
}
}
#endif
/*
* Just remember where we started from, in case we need to call
* sctp_process_uo_gaps() if the gap blocks are unordered.
*/
/*
* Go through SACK gaps. They are ordered based on start TSN.
*/
if (gapstart != 0) {
/* check for unordered gap */
if (trysend < 0) {
return (-1);
}
break;
}
}
/* SACK for TSN we have not sent - ABORT */
return (-1);
break;
}
/*
* Let's start at the current TSN (for the 1st gap we start
* from the cumulative TSN, for subsequent ones we start from
* where the previous gapend was found - second while loop
* below) and walk the transmit list till we find the TSN
* corresponding to gapstart. All the unacked chunks till we
* get to the chunk with TSN == gapstart will have their
* SACKCNT incremented by 1. Note since the gap blocks are
* ordered, we won't be incrementing the SACKCNT for an
* unacked chunk by more than one while processing the gap
* blocks. If the SACKCNT for any unacked chunk exceeds
* the fast retransmit threshold, we will fast retransmit
* after processing all the gap blocks.
*/
if (SCTP_CHUNK_SACKCNT(mp) ==
trysend = 1;
if (!fast_recovery) {
/*
* Entering fast recovery.
*/
}
}
}
/*
* Peer may have reneged on this chunk, so un-sack
* it now. If the peer did renege, we need to
* readjust unacked.
*/
if (SCTP_CHUNK_ISACKED(mp)) {
if (!fp->timer_running) {
}
}
/*
* ump can't be NULL given the sanity check
* above.
*/
}
/*
* mp can't be unsent given the sanity check above.
*/
}
/*
* Now that we have found the chunk with TSN == 'gapstart',
* let's walk till we hit the chunk with TSN == 'gapend'.
* All intermediate chunks will be marked ACKED, if they
* haven't already been.
*/
/*
* SACKed
*/
SCTP_CHUNK_SET_SACKCNT(mp, 0);
if (!SCTP_CHUNK_ISACKED(mp)) {
/* All outstanding data acked. */
}
}
/* Go to the next chunk of the current message */
/*
* Move to the next message in the transmit list
* if we are done with all the chunks from the current
* message. Note, it is possible to hit the end of the
* transmit list here, i.e. if we have already completed
* processing the gap block.
* Also, note that we break here, which means we
* continue processing gap blocks, if any. In case of
* ordered gap blocks there can't be any following
* this (if there is it will fail the sanity check
* above). In case of un-ordered gap blocks we will
* switch to sctp_process_uo_gaps(). In either case
* but we just reset it to xmit_head.
*/
break;
}
}
/*
* Likewise, we could hit an unsent chunk once we have
* completed processing the gap block. Again, it is
* fine to continue processing gap blocks with mp
* pointing to the unsent chunk, because if there
* are more ordered gap blocks, they will fail the
* sanity check, and if there are un-ordered gap blocks,
* we will continue processing in sctp_process_uo_gaps()
* We just reset the mp to the one we started with.
*/
if (!SCTP_CHUNK_ISSENT(mp)) {
break;
}
}
}
if (sctp->sctp_prsctp_aware)
if (sctp->sctp_chk_fast_rexmit)
ret:
/*
* If receive window is closed while there is unsent data,
* set a timer for doing zero window probes.
*/
sctp->sctp_unsent != 0) {
}
/*
* Set cwnd for all destinations.
* Congestion window gets increased only when cumulative
* TSN moves forward, we're not in fast recovery, and
* cwnd has been fully utilized (almost fully, need to allow
* some leeway due to non-MSS sized messages).
*/
/*
* Fast-path, only data sent to sctp_current got acked.
*/
if (cumack_forward && !fast_recovery &&
/*
* Slow start
*/
} else {
}
} else {
/*
* Congestion avoidance
*/
}
}
}
/*
* Limit the burst of transmitted data segments.
*/
}
goto check_ss_rxmit;
}
} else {
}
} else {
}
}
}
}
}
/*
* If this is a SACK following a timeout, check if there are
* still unacked chunks (sent before the timeout) that we can
* send.
*/
if (sctp->sctp_rexmitting) {
/*
* As we are in retransmission phase, we may get a
* SACK which indicates some new chunks are received
* but cum_tsn does not advance. During this
* phase, the other side advances cum_tsn only because
* it receives our retransmitted chunks. Only
* this signals that some chunks are still
* missing.
*/
if (cumack_forward) {
}
} else {
fp->rxt_unacked = 0;
}
}
return (trysend);
}
/*
* Returns 0 if the caller should stop processing any more chunks,
* 1 if the caller should skip this chunk and continue processing.
*/
static int
{
/* check top two bits for action required */
/* skip and continue */
return (1);
} else {
/* stop processing */
return (0);
}
}
/* skip and continue, no error */
return (1);
}
/* top two bits are clear; stop processing and no error */
return (0);
}
/*
* Basic sanity checks on all input chunks and parameters: they must
* be of legitimate size for their purported type, and must follow
* ordering conventions as defined in rfc2960.
*
* Returns 1 if the chunk and all encloded params are legitimate,
* 0 otherwise.
*/
/*ARGSUSED*/
static int
{
void *p = NULL;
return (0);
}
case CHUNK_DATA:
if (ch_len < sizeof (sctp_data_hdr_t)) {
return (0);
}
return (1);
case CHUNK_INIT:
case CHUNK_INIT_ACK:
{
/*
* INIT and INIT-ACK chunks must not be bundled with
* any other.
*/
sizeof (sctp_init_chunk_t)))) {
return (0);
}
/* may have params that need checking */
sizeof (sctp_init_chunk_t));
}
break;
case CHUNK_SACK:
return (0);
}
/* dup and gap reports checked by got_sack() */
return (1);
case CHUNK_SHUTDOWN:
return (0);
}
return (1);
case CHUNK_ABORT:
case CHUNK_ERROR:
return (0);
}
/* may have params that need checking */
p = ch + 1;
break;
case CHUNK_ECNE:
case CHUNK_CWR:
case CHUNK_HEARTBEAT:
case CHUNK_HEARTBEAT_ACK:
/* Full ASCONF chunk and parameter checks are in asconf.c */
case CHUNK_ASCONF:
case CHUNK_ASCONF_ACK:
return (0);
}
/* heartbeat data checked by process_heartbeat() */
return (1);
case CHUNK_SHUTDOWN_COMPLETE:
{
/*
* SHUTDOWN-COMPLETE chunk must not be bundled with any
* other
*/
return (0);
}
}
return (1);
case CHUNK_COOKIE:
case CHUNK_COOKIE_ACK:
case CHUNK_SHUTDOWN_ACK:
return (0);
}
return (1);
case CHUNK_FORWARD_TSN:
return (0);
return (1);
default:
return (1); /* handled by strange_chunk() */
}
/* check and byteorder parameters */
if (clen <= 0) {
return (1);
}
ph = p;
return (0);
}
}
/* All OK */
return (1);
}
/* ARGSUSED */
static sctp_hdr_t *
{
}
} else {
/* Look for ifindex information */
}
}
IPV6_HDR_LEN + sizeof (sctp_hdr_t));
}
/*
* Find any potentially interesting extension headers
* as well as the length of the IPv6 + extension
* headers.
*/
} else {
}
}
}
static mblk_t *
{
ipsec_in_t *ii;
netstack_t *ns;
if (ii->ipsec_in_dont_check) {
if (!ii->ipsec_in_secure) {
}
}
} else {
}
if (check && policy_present) {
/*
* The conn_t parameter is NULL because we already know
* nobody's home.
*/
return (NULL);
}
return (mp);
}
/* Handle out-of-the-blue packets */
void
{
/*
* For non-zero stackids the default queue isn't created
* until the first open, thus there can be a need to send
* an error before then. But we can't do that, hence we just
* drop the packet. Later during boot, when the default queue
* has been setup, a retransmitted packet from the peer
* will result in a error.
*/
return;
}
if (mctl_present)
/* Initiate IPPf processing, if needed. */
if (mctl_present)
return;
}
}
/*
* All subsequent code is vastly simplified if it can
* assume a single contiguous chunk of data.
*/
return;
}
}
/*
* We don't really need to call this function... Need to
* optimize later.
*/
return;
}
case CHUNK_INIT:
/* no listener; send abort */
return;
break;
case CHUNK_INIT_ACK:
/* check for changed src addr */
/* success; proceed to normal path */
if (sctp->sctp_running) {
}
} else {
/*
* If the source address is changed, we
* don't need to worry too much about
* out of order processing. So we don't
* check if the recvq is empty or not here.
*/
}
return;
}
if (mctl_present)
/* else bogus init ack; drop it */
break;
case CHUNK_SHUTDOWN_ACK:
return;
return;
case CHUNK_ERROR:
case CHUNK_ABORT:
case CHUNK_COOKIE_ACK:
case CHUNK_SHUTDOWN_COMPLETE:
if (mctl_present)
break;
default:
return;
break;
}
}
void
{
/*
* We check some fields in conn_t without holding a lock.
* This should be fine.
*/
return;
}
}
/* Initiate IPPF processing for fastpath */
if (mctl_present)
return;
} else if (mctl_present) {
/*
* ip_process might return a new mp.
*/
} else {
}
}
int in_flags = 0;
}
if (connp->conn_recvslla) {
in_flags |= IPF_RECVSLLA;
}
if (isv4) {
} else {
}
if (mctl_present)
return;
} else if (mctl_present) {
/*
* ip_add_info might return a new mp.
*/
} else {
}
}
if (sctp->sctp_running) {
if (mctl_present)
}
return;
} else {
if (mctl_present)
}
return;
}
}
}
static void
{
}
void
{
int gotdata;
int trysend;
int recv_adaption;
IN_PKTINFO) {
} else {
return;
}
}
/*
* All subsequent code is vastly simplified if it can
* assume a single contiguous chunk of data.
*/
return;
}
}
return;
}
goto done;
}
/*
* Check verfication tag (special handling for INIT,
* COOKIE, SHUTDOWN_COMPLETE and SHUTDOWN_ACK chunks).
* ABORTs are handled in the chunk processing loop, since
* may not appear first. All other checked chunks must
* appear first, or will have been dropped by check_input().
*/
case CHUNK_INIT:
/* drop it */
goto done;
}
break;
case CHUNK_SHUTDOWN_COMPLETE:
break;
SCTP_GET_TBIT(ch)) {
break;
}
/* else drop it */
goto done;
case CHUNK_ABORT:
case CHUNK_COOKIE:
/* handled below */
break;
case CHUNK_SHUTDOWN_ACK:
/* treat as OOTB */
return;
}
/* else fallthru */
default:
/*
* All other packets must have a valid
* verification tag, however if this is a
* listener, we use a refined version of
* out-of-the-blue logic.
*/
/* drop it */
goto done;
}
break;
}
/* Have a valid sctp for this packet */
gotdata = 0;
trysend = 0;
/* Process the chunks */
do {
/* drop it */
goto done;
}
}
switch (sctp->sctp_state) {
case SCTPS_ESTABLISHED:
case SCTPS_SHUTDOWN_PENDING:
case SCTPS_SHUTDOWN_SENT:
case CHUNK_DATA:
/* 0-length data chunks are not allowed */
SCTP_ERR_NO_USR_DATA, (char *)&tsn,
0, NULL);
goto done;
}
gotdata = 1;
/* Restart shutdown timer if shutting down */
/*
* If we have exceeded our max
* wait bound for waiting for a
* shutdown ack from the peer,
* abort the association.
*/
if (sctps->sctps_shutack_wait_bound !=
0 &&
sctp->sctp_out_time) >
SCTP_COMM_LOST, 0, NULL);
goto done;
}
}
break;
case CHUNK_SACK:
/*
* Peer is real and alive if it can ack our
* data.
*/
if (trysend < 0) {
SCTP_COMM_LOST, 0, NULL);
goto done;
}
break;
case CHUNK_HEARTBEAT:
break;
case CHUNK_HEARTBEAT_ACK:
break;
case CHUNK_SHUTDOWN:
break;
case CHUNK_SHUTDOWN_ACK:
SCTP_SHUTDOWN_COMP, 0, NULL);
sctp_clean_death(sctp, 0);
goto done;
}
break;
case CHUNK_ABORT: {
/* Ignore if delete pending */
if (sp->saddr_ipif_delete_pending) {
break;
}
goto done;
}
case CHUNK_INIT:
break;
case CHUNK_COOKIE:
0, NULL);
if (recv_adaption) {
}
} else {
}
break;
case CHUNK_ERROR: {
int error;
if (error != 0) {
0, NULL);
goto done;
}
break;
}
case CHUNK_ASCONF:
break;
case CHUNK_ASCONF_ACK:
break;
case CHUNK_FORWARD_TSN:
gotdata = 1;
break;
default:
goto nomorechunks;
} /* else skip and continue processing */
break;
}
break;
case SCTPS_LISTEN:
case CHUNK_INIT:
break;
case CHUNK_COOKIE: {
goto done;
}
/*
* The cookie is good; ensure that
* the peer used the verification
* tag from the init ack in the header.
*/
goto done;
0, B_FALSE);
goto done;
}
/*
* If there were extra chunks
* bundled with the cookie,
* they must be processed
* on the eager's queue. We
* accomplish this by refeeding
* the whole packet into the
* state machine on the right
* q. The packet (mp) gets
* there via the eager's
* cookie_mp field (overloaded
* with the active open role).
* This is picked up when
* processing the null bind
* request put on the eager's
* q by sctp_accept(). We must
* first revert the cookie
* chunk's length field to network
* byteorder so it can be
* properly reprocessed on the
* eager's queue.
*/
/*
* If no mem, just let
* the peer retransmit.
*/
}
if (recv_adaption) {
}
wake_eager = B_TRUE;
/*
* Process rest of the chunks with eager.
*/
/*
* Confirm peer's original source. fp can
* only be NULL if peer does not use the
* original source as one of its addresses...
*/
else
/*
* Validate the peer addresses. It also starts
* the heartbeat timer.
*/
break;
}
/* Anything else is considered out-of-the-blue */
case CHUNK_ERROR:
case CHUNK_ABORT:
case CHUNK_COOKIE_ACK:
case CHUNK_SHUTDOWN_COMPLETE:
goto done;
default:
goto done;
}
break;
case SCTPS_COOKIE_WAIT:
case CHUNK_INIT_ACK:
break;
case CHUNK_ABORT:
goto done;
case CHUNK_INIT:
break;
case CHUNK_COOKIE:
break;
}
if (!SCTP_IS_DETACHED(sctp)) {
}
if (sctp->sctp_cookie_mp) {
}
/* Validate the peer addresses. */
if (recv_adaption) {
}
/* Try sending queued data, or ASCONFs */
trysend = 1;
break;
default:
goto nomorechunks;
} /* else skip and continue processing */
break;
}
break;
case SCTPS_COOKIE_ECHOED:
case CHUNK_COOKIE_ACK:
if (!SCTP_IS_DETACHED(sctp)) {
}
if (sctp->sctp_unacked == 0)
if (sctp->sctp_cookie_mp) {
}
/* Validate the peer addresses. */
/* Try sending queued data, or ASCONFs */
trysend = 1;
break;
case CHUNK_ABORT:
goto done;
case CHUNK_COOKIE:
break;
}
if (!SCTP_IS_DETACHED(sctp)) {
}
if (sctp->sctp_unacked == 0)
if (sctp->sctp_cookie_mp) {
}
/* Validate the peer addresses. */
if (recv_adaption) {
}
/* Try sending queued data, or ASCONFs */
trysend = 1;
break;
case CHUNK_INIT:
break;
case CHUNK_ERROR: {
sctp_parm_hdr_t *p;
/* check for a stale cookie */
(sizeof (*p) + sizeof (*ch)) +
sizeof (uint32_t)) {
if (p->sph_type ==
SCTP_COMM_LOST, 0, NULL);
goto done;
}
}
break;
}
case CHUNK_HEARTBEAT:
break;
default:
goto nomorechunks;
} /* else skip and continue processing */
} /* switch (ch->sch_id) */
break;
case SCTPS_SHUTDOWN_ACK_SENT:
case CHUNK_ABORT:
/* Pass gathered wisdom to IP for keeping */
goto done;
case CHUNK_SHUTDOWN_COMPLETE:
NULL);
/* Pass gathered wisdom to IP for keeping */
sctp_clean_death(sctp, 0);
goto done;
case CHUNK_SHUTDOWN_ACK:
NULL);
sctp_clean_death(sctp, 0);
goto done;
case CHUNK_COOKIE:
break;
case CHUNK_HEARTBEAT:
break;
default:
goto nomorechunks;
} /* else skip and continue processing */
break;
}
break;
case SCTPS_SHUTDOWN_RECEIVED:
case CHUNK_SHUTDOWN:
break;
case CHUNK_SACK:
if (trysend < 0) {
SCTP_COMM_LOST, 0, NULL);
goto done;
}
break;
case CHUNK_ABORT:
goto done;
case CHUNK_HEARTBEAT:
break;
default:
goto nomorechunks;
} /* else skip and continue processing */
break;
}
break;
default:
/*
* The only remaining states are SCTPS_IDLE and
* SCTPS_BOUND, and we should not be getting here
* for these.
*/
ASSERT(0);
} /* switch (sctp->sctp_state) */
goto done;
/* Finished processing all chunks in packet */
/* SACK if necessary */
if (gotdata) {
(sctp->sctp_sack_toggle)++;
if (!sctp->sctp_ack_timer_running) {
}
}
if (trysend) {
}
/* If there is unsent data, make sure a timer is running */
}
done:
if (wake_eager) {
/*
* sctp points to newly created control block, need to
* release it before exiting. Before releasing it and
* processing the sendq, need to grab a hold on it.
* Otherwise, another thread can close it while processing
* the sendq.
*/
}
}
/*
* Some amount of data got removed from rx q.
* Check if we should send a window update.
*
* Due to way sctp_rwnd updates are made, ULP can give reports out-of-order.
* To keep from dropping incoming data due to this, we only update
* sctp_rwnd when if it's larger than what we've reported to peer earlier.
*/
void
{
return;
}
old = 1;
} else {
old = 0;
}
if (old > 0) {
}
}