1f8829a4aSRandall Stewart /*- 2b1006367SRandall Stewart * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 3f8829a4aSRandall Stewart * 4f8829a4aSRandall Stewart * Redistribution and use in source and binary forms, with or without 5f8829a4aSRandall Stewart * modification, are permitted provided that the following conditions are met: 6f8829a4aSRandall Stewart * 7f8829a4aSRandall Stewart * a) Redistributions of source code must retain the above copyright notice, 8f8829a4aSRandall Stewart * this list of conditions and the following disclaimer. 9f8829a4aSRandall Stewart * 10f8829a4aSRandall Stewart * b) Redistributions in binary form must reproduce the above copyright 11f8829a4aSRandall Stewart * notice, this list of conditions and the following disclaimer in 12f8829a4aSRandall Stewart * the documentation and/or other materials provided with the distribution. 13f8829a4aSRandall Stewart * 14f8829a4aSRandall Stewart * c) Neither the name of Cisco Systems, Inc. nor the names of its 15f8829a4aSRandall Stewart * contributors may be used to endorse or promote products derived 16f8829a4aSRandall Stewart * from this software without specific prior written permission. 17f8829a4aSRandall Stewart * 18f8829a4aSRandall Stewart * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19f8829a4aSRandall Stewart * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20f8829a4aSRandall Stewart * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21f8829a4aSRandall Stewart * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22f8829a4aSRandall Stewart * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23f8829a4aSRandall Stewart * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24f8829a4aSRandall Stewart * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25f8829a4aSRandall Stewart * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26f8829a4aSRandall Stewart * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27f8829a4aSRandall Stewart * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28f8829a4aSRandall Stewart * THE POSSIBILITY OF SUCH DAMAGE. 29f8829a4aSRandall Stewart */ 30f8829a4aSRandall Stewart 31a5d547adSRandall Stewart /* $KAME: sctp_indata.c,v 1.36 2005/03/06 16:04:17 itojun Exp $ */ 32f8829a4aSRandall Stewart 33f8829a4aSRandall Stewart #include <sys/cdefs.h> 34f8829a4aSRandall Stewart __FBSDID("$FreeBSD$"); 35f8829a4aSRandall Stewart 36f8829a4aSRandall Stewart #include <netinet/sctp_os.h> 37f8829a4aSRandall Stewart #include <netinet/sctp_var.h> 3842551e99SRandall Stewart #include <netinet/sctp_sysctl.h> 39f8829a4aSRandall Stewart #include <netinet/sctp_pcb.h> 40f8829a4aSRandall Stewart #include <netinet/sctp_header.h> 41f8829a4aSRandall Stewart #include <netinet/sctputil.h> 42f8829a4aSRandall Stewart #include <netinet/sctp_output.h> 43f8829a4aSRandall Stewart #include <netinet/sctp_input.h> 44f8829a4aSRandall Stewart #include <netinet/sctp_indata.h> 45f8829a4aSRandall Stewart #include <netinet/sctp_uio.h> 46f8829a4aSRandall Stewart #include <netinet/sctp_timer.h> 47f8829a4aSRandall Stewart 48f8829a4aSRandall Stewart 49f8829a4aSRandall Stewart /* 50f8829a4aSRandall Stewart * NOTES: On the outbound side of things I need to check the sack timer to 51f8829a4aSRandall Stewart * see if I should generate a sack into the chunk queue (if I have data to 52f8829a4aSRandall Stewart * send that is and will be sending it .. for bundling. 53f8829a4aSRandall Stewart * 54f8829a4aSRandall Stewart * The callback in sctp_usrreq.c will get called when the socket is read from. 55f8829a4aSRandall Stewart * This will cause sctp_service_queues() to get called on the top entry in 56f8829a4aSRandall Stewart * the list. 57f8829a4aSRandall Stewart */ 58f8829a4aSRandall Stewart 5972fb6fdbSRandall Stewart void 60f8829a4aSRandall Stewart sctp_set_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc) 61f8829a4aSRandall Stewart { 62b3f1ea41SRandall Stewart asoc->my_rwnd = sctp_calc_rwnd(stcb, asoc); 63f8829a4aSRandall Stewart } 64f8829a4aSRandall Stewart 65f8829a4aSRandall Stewart /* Calculate what the rwnd would be */ 6672fb6fdbSRandall Stewart uint32_t 67f8829a4aSRandall Stewart sctp_calc_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc) 68f8829a4aSRandall Stewart { 69b3f1ea41SRandall Stewart uint32_t calc = 0; 70f8829a4aSRandall Stewart 71f8829a4aSRandall Stewart /* 72f8829a4aSRandall Stewart * This is really set wrong with respect to a 1-2-m socket. Since 73f8829a4aSRandall Stewart * the sb_cc is the count that everyone as put up. When we re-write 74f8829a4aSRandall Stewart * sctp_soreceive then we will fix this so that ONLY this 75f8829a4aSRandall Stewart * associations data is taken into account. 76f8829a4aSRandall Stewart */ 77f8829a4aSRandall Stewart if (stcb->sctp_socket == NULL) 78f8829a4aSRandall Stewart return (calc); 79f8829a4aSRandall Stewart 80f8829a4aSRandall Stewart if (stcb->asoc.sb_cc == 0 && 81f8829a4aSRandall Stewart asoc->size_on_reasm_queue == 0 && 82f8829a4aSRandall Stewart asoc->size_on_all_streams == 0) { 83f8829a4aSRandall Stewart /* Full rwnd granted */ 84b3f1ea41SRandall Stewart calc = max(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), SCTP_MINIMAL_RWND); 85f8829a4aSRandall Stewart return (calc); 86f8829a4aSRandall Stewart } 87f8829a4aSRandall Stewart /* get actual space */ 88f8829a4aSRandall Stewart calc = (uint32_t) sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv); 89f8829a4aSRandall Stewart 90f8829a4aSRandall Stewart /* 91f8829a4aSRandall Stewart * take out what has NOT been put on socket queue and we yet hold 92f8829a4aSRandall Stewart * for putting up. 93f8829a4aSRandall Stewart */ 94f8829a4aSRandall Stewart calc = sctp_sbspace_sub(calc, (uint32_t) asoc->size_on_reasm_queue); 95f8829a4aSRandall Stewart calc = sctp_sbspace_sub(calc, (uint32_t) asoc->size_on_all_streams); 96f8829a4aSRandall Stewart 97f8829a4aSRandall Stewart if (calc == 0) { 98f8829a4aSRandall Stewart /* out of space */ 99f8829a4aSRandall Stewart return (calc); 100f8829a4aSRandall Stewart } 101f8829a4aSRandall Stewart /* what is the overhead of all these rwnd's */ 1022afb3e84SRandall Stewart calc = sctp_sbspace_sub(calc, stcb->asoc.my_rwnd_control_len); 103b3f1ea41SRandall Stewart /* 104b3f1ea41SRandall Stewart * If the window gets too small due to ctrl-stuff, reduce it to 1, 105b3f1ea41SRandall Stewart * even it is 0. SWS engaged 106f8829a4aSRandall Stewart */ 107b3f1ea41SRandall Stewart if (calc < stcb->asoc.my_rwnd_control_len) { 108b3f1ea41SRandall Stewart calc = 1; 1092afb3e84SRandall Stewart } 110b3f1ea41SRandall Stewart return (calc); 111f8829a4aSRandall Stewart } 112f8829a4aSRandall Stewart 113f8829a4aSRandall Stewart 114f8829a4aSRandall Stewart 115f8829a4aSRandall Stewart /* 116f8829a4aSRandall Stewart * Build out our readq entry based on the incoming packet. 117f8829a4aSRandall Stewart */ 118f8829a4aSRandall Stewart struct sctp_queued_to_read * 119f8829a4aSRandall Stewart sctp_build_readq_entry(struct sctp_tcb *stcb, 120f8829a4aSRandall Stewart struct sctp_nets *net, 121f8829a4aSRandall Stewart uint32_t tsn, uint32_t ppid, 122f8829a4aSRandall Stewart uint32_t context, uint16_t stream_no, 123f8829a4aSRandall Stewart uint16_t stream_seq, uint8_t flags, 124f8829a4aSRandall Stewart struct mbuf *dm) 125f8829a4aSRandall Stewart { 126f8829a4aSRandall Stewart struct sctp_queued_to_read *read_queue_e = NULL; 127f8829a4aSRandall Stewart 128f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, read_queue_e); 129f8829a4aSRandall Stewart if (read_queue_e == NULL) { 130f8829a4aSRandall Stewart goto failed_build; 131f8829a4aSRandall Stewart } 132f8829a4aSRandall Stewart read_queue_e->sinfo_stream = stream_no; 133f8829a4aSRandall Stewart read_queue_e->sinfo_ssn = stream_seq; 134f8829a4aSRandall Stewart read_queue_e->sinfo_flags = (flags << 8); 135f8829a4aSRandall Stewart read_queue_e->sinfo_ppid = ppid; 136f8829a4aSRandall Stewart read_queue_e->sinfo_context = stcb->asoc.context; 137f8829a4aSRandall Stewart read_queue_e->sinfo_timetolive = 0; 138f8829a4aSRandall Stewart read_queue_e->sinfo_tsn = tsn; 139f8829a4aSRandall Stewart read_queue_e->sinfo_cumtsn = tsn; 140f8829a4aSRandall Stewart read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb); 141f8829a4aSRandall Stewart read_queue_e->whoFrom = net; 142f8829a4aSRandall Stewart read_queue_e->length = 0; 143f8829a4aSRandall Stewart atomic_add_int(&net->ref_count, 1); 144f8829a4aSRandall Stewart read_queue_e->data = dm; 145139bc87fSRandall Stewart read_queue_e->spec_flags = 0; 146f8829a4aSRandall Stewart read_queue_e->tail_mbuf = NULL; 14717205eccSRandall Stewart read_queue_e->aux_data = NULL; 148f8829a4aSRandall Stewart read_queue_e->stcb = stcb; 149f8829a4aSRandall Stewart read_queue_e->port_from = stcb->rport; 150f8829a4aSRandall Stewart read_queue_e->do_not_ref_stcb = 0; 151f8829a4aSRandall Stewart read_queue_e->end_added = 0; 1529a6142d8SRandall Stewart read_queue_e->some_taken = 0; 15303b0b021SRandall Stewart read_queue_e->pdapi_aborted = 0; 154f8829a4aSRandall Stewart failed_build: 155f8829a4aSRandall Stewart return (read_queue_e); 156f8829a4aSRandall Stewart } 157f8829a4aSRandall Stewart 158f8829a4aSRandall Stewart 159f8829a4aSRandall Stewart /* 160f8829a4aSRandall Stewart * Build out our readq entry based on the incoming packet. 161f8829a4aSRandall Stewart */ 162f8829a4aSRandall Stewart static struct sctp_queued_to_read * 163f8829a4aSRandall Stewart sctp_build_readq_entry_chk(struct sctp_tcb *stcb, 164f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk) 165f8829a4aSRandall Stewart { 166f8829a4aSRandall Stewart struct sctp_queued_to_read *read_queue_e = NULL; 167f8829a4aSRandall Stewart 168f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, read_queue_e); 169f8829a4aSRandall Stewart if (read_queue_e == NULL) { 170f8829a4aSRandall Stewart goto failed_build; 171f8829a4aSRandall Stewart } 172f8829a4aSRandall Stewart read_queue_e->sinfo_stream = chk->rec.data.stream_number; 173f8829a4aSRandall Stewart read_queue_e->sinfo_ssn = chk->rec.data.stream_seq; 174f8829a4aSRandall Stewart read_queue_e->sinfo_flags = (chk->rec.data.rcv_flags << 8); 175f8829a4aSRandall Stewart read_queue_e->sinfo_ppid = chk->rec.data.payloadtype; 176f8829a4aSRandall Stewart read_queue_e->sinfo_context = stcb->asoc.context; 177f8829a4aSRandall Stewart read_queue_e->sinfo_timetolive = 0; 178f8829a4aSRandall Stewart read_queue_e->sinfo_tsn = chk->rec.data.TSN_seq; 179f8829a4aSRandall Stewart read_queue_e->sinfo_cumtsn = chk->rec.data.TSN_seq; 180f8829a4aSRandall Stewart read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb); 181f8829a4aSRandall Stewart read_queue_e->whoFrom = chk->whoTo; 18217205eccSRandall Stewart read_queue_e->aux_data = NULL; 183f8829a4aSRandall Stewart read_queue_e->length = 0; 184f8829a4aSRandall Stewart atomic_add_int(&chk->whoTo->ref_count, 1); 185f8829a4aSRandall Stewart read_queue_e->data = chk->data; 186f8829a4aSRandall Stewart read_queue_e->tail_mbuf = NULL; 187f8829a4aSRandall Stewart read_queue_e->stcb = stcb; 188f8829a4aSRandall Stewart read_queue_e->port_from = stcb->rport; 189139bc87fSRandall Stewart read_queue_e->spec_flags = 0; 190f8829a4aSRandall Stewart read_queue_e->do_not_ref_stcb = 0; 191f8829a4aSRandall Stewart read_queue_e->end_added = 0; 1929a6142d8SRandall Stewart read_queue_e->some_taken = 0; 19303b0b021SRandall Stewart read_queue_e->pdapi_aborted = 0; 194f8829a4aSRandall Stewart failed_build: 195f8829a4aSRandall Stewart return (read_queue_e); 196f8829a4aSRandall Stewart } 197f8829a4aSRandall Stewart 198f8829a4aSRandall Stewart 199f8829a4aSRandall Stewart struct mbuf * 200f8829a4aSRandall Stewart sctp_build_ctl_nchunk(struct sctp_inpcb *inp, 201f8829a4aSRandall Stewart struct sctp_sndrcvinfo *sinfo) 202f8829a4aSRandall Stewart { 203f8829a4aSRandall Stewart struct sctp_sndrcvinfo *outinfo; 204f8829a4aSRandall Stewart struct cmsghdr *cmh; 205f8829a4aSRandall Stewart struct mbuf *ret; 206f8829a4aSRandall Stewart int len; 207f8829a4aSRandall Stewart int use_extended = 0; 208f8829a4aSRandall Stewart 209f8829a4aSRandall Stewart if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) { 210f8829a4aSRandall Stewart /* user does not want the sndrcv ctl */ 211f8829a4aSRandall Stewart return (NULL); 212f8829a4aSRandall Stewart } 213f8829a4aSRandall Stewart if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) { 214f8829a4aSRandall Stewart use_extended = 1; 215f8829a4aSRandall Stewart len = CMSG_LEN(sizeof(struct sctp_extrcvinfo)); 216f8829a4aSRandall Stewart } else { 217f8829a4aSRandall Stewart len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 218f8829a4aSRandall Stewart } 219f8829a4aSRandall Stewart 220f8829a4aSRandall Stewart 221f8829a4aSRandall Stewart ret = sctp_get_mbuf_for_msg(len, 222139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 223f8829a4aSRandall Stewart 224f8829a4aSRandall Stewart if (ret == NULL) { 225f8829a4aSRandall Stewart /* No space */ 226f8829a4aSRandall Stewart return (ret); 227f8829a4aSRandall Stewart } 228f8829a4aSRandall Stewart /* We need a CMSG header followed by the struct */ 229f8829a4aSRandall Stewart cmh = mtod(ret, struct cmsghdr *); 230f8829a4aSRandall Stewart outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh); 231f8829a4aSRandall Stewart cmh->cmsg_level = IPPROTO_SCTP; 232f8829a4aSRandall Stewart if (use_extended) { 233f8829a4aSRandall Stewart cmh->cmsg_type = SCTP_EXTRCV; 234f8829a4aSRandall Stewart cmh->cmsg_len = len; 235f8829a4aSRandall Stewart memcpy(outinfo, sinfo, len); 236f8829a4aSRandall Stewart } else { 237f8829a4aSRandall Stewart cmh->cmsg_type = SCTP_SNDRCV; 238f8829a4aSRandall Stewart cmh->cmsg_len = len; 239f8829a4aSRandall Stewart *outinfo = *sinfo; 240f8829a4aSRandall Stewart } 241139bc87fSRandall Stewart SCTP_BUF_LEN(ret) = cmh->cmsg_len; 242f8829a4aSRandall Stewart return (ret); 243f8829a4aSRandall Stewart } 244f8829a4aSRandall Stewart 245139bc87fSRandall Stewart 24617205eccSRandall Stewart char * 24717205eccSRandall Stewart sctp_build_ctl_cchunk(struct sctp_inpcb *inp, 24817205eccSRandall Stewart int *control_len, 24917205eccSRandall Stewart struct sctp_sndrcvinfo *sinfo) 25017205eccSRandall Stewart { 25117205eccSRandall Stewart struct sctp_sndrcvinfo *outinfo; 25217205eccSRandall Stewart struct cmsghdr *cmh; 25317205eccSRandall Stewart char *buf; 25417205eccSRandall Stewart int len; 25517205eccSRandall Stewart int use_extended = 0; 25617205eccSRandall Stewart 25717205eccSRandall Stewart if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) { 25817205eccSRandall Stewart /* user does not want the sndrcv ctl */ 25917205eccSRandall Stewart return (NULL); 26017205eccSRandall Stewart } 26117205eccSRandall Stewart if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) { 26217205eccSRandall Stewart use_extended = 1; 26317205eccSRandall Stewart len = CMSG_LEN(sizeof(struct sctp_extrcvinfo)); 26417205eccSRandall Stewart } else { 26517205eccSRandall Stewart len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 26617205eccSRandall Stewart } 267207304d4SRandall Stewart SCTP_MALLOC(buf, char *, len, SCTP_M_CMSG); 26817205eccSRandall Stewart if (buf == NULL) { 26917205eccSRandall Stewart /* No space */ 27017205eccSRandall Stewart return (buf); 27117205eccSRandall Stewart } 27217205eccSRandall Stewart /* We need a CMSG header followed by the struct */ 27317205eccSRandall Stewart cmh = (struct cmsghdr *)buf; 27417205eccSRandall Stewart outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh); 27517205eccSRandall Stewart cmh->cmsg_level = IPPROTO_SCTP; 27617205eccSRandall Stewart if (use_extended) { 27717205eccSRandall Stewart cmh->cmsg_type = SCTP_EXTRCV; 27817205eccSRandall Stewart cmh->cmsg_len = len; 27917205eccSRandall Stewart memcpy(outinfo, sinfo, len); 28017205eccSRandall Stewart } else { 28117205eccSRandall Stewart cmh->cmsg_type = SCTP_SNDRCV; 28217205eccSRandall Stewart cmh->cmsg_len = len; 28317205eccSRandall Stewart *outinfo = *sinfo; 28417205eccSRandall Stewart } 28517205eccSRandall Stewart *control_len = len; 28617205eccSRandall Stewart return (buf); 28717205eccSRandall Stewart } 28817205eccSRandall Stewart 28917205eccSRandall Stewart 290f8829a4aSRandall Stewart /* 291f8829a4aSRandall Stewart * We are delivering currently from the reassembly queue. We must continue to 292f8829a4aSRandall Stewart * deliver until we either: 1) run out of space. 2) run out of sequential 293f8829a4aSRandall Stewart * TSN's 3) hit the SCTP_DATA_LAST_FRAG flag. 294f8829a4aSRandall Stewart */ 295f8829a4aSRandall Stewart static void 296f8829a4aSRandall Stewart sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc) 297f8829a4aSRandall Stewart { 298f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 299f8829a4aSRandall Stewart uint16_t nxt_todel; 300f8829a4aSRandall Stewart uint16_t stream_no; 301f8829a4aSRandall Stewart int end = 0; 302f8829a4aSRandall Stewart int cntDel; 303830d754dSRandall Stewart 304830d754dSRandall Stewart /* EY if any out-of-order delivered, then tag it nr on nr_map */ 305830d754dSRandall Stewart uint32_t nr_tsn, nr_gap; 306830d754dSRandall Stewart 307f8829a4aSRandall Stewart struct sctp_queued_to_read *control, *ctl, *ctlat; 308f8829a4aSRandall Stewart 309ad81507eSRandall Stewart if (stcb == NULL) 310ad81507eSRandall Stewart return; 311ad81507eSRandall Stewart 312f42a358aSRandall Stewart cntDel = stream_no = 0; 313ad81507eSRandall Stewart if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || 314851b7298SRandall Stewart (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) || 315ad81507eSRandall Stewart (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) { 316851b7298SRandall Stewart /* socket above is long gone or going.. */ 317851b7298SRandall Stewart abandon: 318f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 319f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 320f8829a4aSRandall Stewart while (chk) { 321f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 322f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 323f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 324f8829a4aSRandall Stewart /* 325f8829a4aSRandall Stewart * Lose the data pointer, since its in the socket 326f8829a4aSRandall Stewart * buffer 327f8829a4aSRandall Stewart */ 328f8829a4aSRandall Stewart if (chk->data) { 329f8829a4aSRandall Stewart sctp_m_freem(chk->data); 330f8829a4aSRandall Stewart chk->data = NULL; 331f8829a4aSRandall Stewart } 332f8829a4aSRandall Stewart /* Now free the address and data */ 333f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 3343c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 335f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 336f8829a4aSRandall Stewart } 337f8829a4aSRandall Stewart return; 338f8829a4aSRandall Stewart } 339f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 340f8829a4aSRandall Stewart do { 341f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 342f8829a4aSRandall Stewart if (chk == NULL) { 343f8829a4aSRandall Stewart return; 344f8829a4aSRandall Stewart } 345f8829a4aSRandall Stewart if (chk->rec.data.TSN_seq != (asoc->tsn_last_delivered + 1)) { 346f8829a4aSRandall Stewart /* Can't deliver more :< */ 347f8829a4aSRandall Stewart return; 348f8829a4aSRandall Stewart } 349f8829a4aSRandall Stewart stream_no = chk->rec.data.stream_number; 350f8829a4aSRandall Stewart nxt_todel = asoc->strmin[stream_no].last_sequence_delivered + 1; 351f8829a4aSRandall Stewart if (nxt_todel != chk->rec.data.stream_seq && 352f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { 353f8829a4aSRandall Stewart /* 354f8829a4aSRandall Stewart * Not the next sequence to deliver in its stream OR 355f8829a4aSRandall Stewart * unordered 356f8829a4aSRandall Stewart */ 357f8829a4aSRandall Stewart return; 358f8829a4aSRandall Stewart } 359f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 360f8829a4aSRandall Stewart 361f8829a4aSRandall Stewart control = sctp_build_readq_entry_chk(stcb, chk); 362f8829a4aSRandall Stewart if (control == NULL) { 363f8829a4aSRandall Stewart /* out of memory? */ 364f8829a4aSRandall Stewart return; 365f8829a4aSRandall Stewart } 366f8829a4aSRandall Stewart /* save it off for our future deliveries */ 367f8829a4aSRandall Stewart stcb->asoc.control_pdapi = control; 368f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) 369f8829a4aSRandall Stewart end = 1; 370f8829a4aSRandall Stewart else 371f8829a4aSRandall Stewart end = 0; 372f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, 373ceaad40aSRandall Stewart stcb, control, &stcb->sctp_socket->so_rcv, end, SCTP_SO_NOT_LOCKED); 374f8829a4aSRandall Stewart cntDel++; 375f8829a4aSRandall Stewart } else { 376f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) 377f8829a4aSRandall Stewart end = 1; 378f8829a4aSRandall Stewart else 379f8829a4aSRandall Stewart end = 0; 380f8829a4aSRandall Stewart if (sctp_append_to_readq(stcb->sctp_ep, stcb, 381f8829a4aSRandall Stewart stcb->asoc.control_pdapi, 382f8829a4aSRandall Stewart chk->data, end, chk->rec.data.TSN_seq, 383f8829a4aSRandall Stewart &stcb->sctp_socket->so_rcv)) { 384f8829a4aSRandall Stewart /* 385f8829a4aSRandall Stewart * something is very wrong, either 386f8829a4aSRandall Stewart * control_pdapi is NULL, or the tail_mbuf 387f8829a4aSRandall Stewart * is corrupt, or there is a EOM already on 388f8829a4aSRandall Stewart * the mbuf chain. 389f8829a4aSRandall Stewart */ 390851b7298SRandall Stewart if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { 391851b7298SRandall Stewart goto abandon; 392851b7298SRandall Stewart } else { 393df6e0cc3SRandall Stewart #ifdef INVARIANTS 394ad81507eSRandall Stewart if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) { 395f8829a4aSRandall Stewart panic("This should not happen control_pdapi NULL?"); 396f8829a4aSRandall Stewart } 397f8829a4aSRandall Stewart /* if we did not panic, it was a EOM */ 398f8829a4aSRandall Stewart panic("Bad chunking ??"); 399df6e0cc3SRandall Stewart #else 400df6e0cc3SRandall Stewart if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) { 401df6e0cc3SRandall Stewart SCTP_PRINTF("This should not happen control_pdapi NULL?\n"); 402df6e0cc3SRandall Stewart } 403df6e0cc3SRandall Stewart SCTP_PRINTF("Bad chunking ??\n"); 404df6e0cc3SRandall Stewart SCTP_PRINTF("Dumping re-assembly queue this will probably hose the association\n"); 405df6e0cc3SRandall Stewart 406df6e0cc3SRandall Stewart #endif 407df6e0cc3SRandall Stewart goto abandon; 408f8829a4aSRandall Stewart } 409851b7298SRandall Stewart } 410f8829a4aSRandall Stewart cntDel++; 411f8829a4aSRandall Stewart } 412f8829a4aSRandall Stewart /* pull it we did it */ 413f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 414830d754dSRandall Stewart /* 415830d754dSRandall Stewart * EY this is the chunk that should be tagged nr gapped 416830d754dSRandall Stewart * calculate the gap and such then tag this TSN nr 417830d754dSRandall Stewart * chk->rec.data.TSN_seq 418830d754dSRandall Stewart */ 419830d754dSRandall Stewart /* 420830d754dSRandall Stewart * EY!-TODO- this tsn should be tagged nr only if it is 421830d754dSRandall Stewart * out-of-order, the if statement should be modified 422830d754dSRandall Stewart */ 423830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 424830d754dSRandall Stewart 425830d754dSRandall Stewart nr_tsn = chk->rec.data.TSN_seq; 426830d754dSRandall Stewart if (nr_tsn >= asoc->nr_mapping_array_base_tsn) { 427830d754dSRandall Stewart nr_gap = nr_tsn - asoc->nr_mapping_array_base_tsn; 428830d754dSRandall Stewart } else { 429830d754dSRandall Stewart nr_gap = (MAX_TSN - asoc->nr_mapping_array_base_tsn) + nr_tsn + 1; 430830d754dSRandall Stewart } 431830d754dSRandall Stewart if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) || 432830d754dSRandall Stewart (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) { 433830d754dSRandall Stewart /* 434830d754dSRandall Stewart * EY The 1st should never happen, as in 435830d754dSRandall Stewart * process_a_data_chunk method this check 436830d754dSRandall Stewart * should be done 437830d754dSRandall Stewart */ 438830d754dSRandall Stewart /* 439830d754dSRandall Stewart * EY The 2nd should never happen, because 440830d754dSRandall Stewart * nr_mapping_array is always expanded when 441830d754dSRandall Stewart * mapping_array is expanded 442830d754dSRandall Stewart */ 443830d754dSRandall Stewart } else { 444830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 445830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap); 446830d754dSRandall Stewart if (nr_tsn > asoc->highest_tsn_inside_nr_map) 447830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = nr_tsn; 448830d754dSRandall Stewart } 449830d754dSRandall Stewart } 450f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 451f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 452f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { 453f8829a4aSRandall Stewart asoc->strmin[stream_no].last_sequence_delivered++; 454f8829a4aSRandall Stewart } 455f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { 456f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); 457f8829a4aSRandall Stewart } 458f8829a4aSRandall Stewart } else if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 459f8829a4aSRandall Stewart /* 460f8829a4aSRandall Stewart * turn the flag back on since we just delivered 461f8829a4aSRandall Stewart * yet another one. 462f8829a4aSRandall Stewart */ 463f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 464f8829a4aSRandall Stewart } 465f8829a4aSRandall Stewart asoc->tsn_of_pdapi_last_delivered = chk->rec.data.TSN_seq; 466f8829a4aSRandall Stewart asoc->last_flags_delivered = chk->rec.data.rcv_flags; 467f8829a4aSRandall Stewart asoc->last_strm_seq_delivered = chk->rec.data.stream_seq; 468f8829a4aSRandall Stewart asoc->last_strm_no_delivered = chk->rec.data.stream_number; 469f8829a4aSRandall Stewart 470f8829a4aSRandall Stewart asoc->tsn_last_delivered = chk->rec.data.TSN_seq; 471f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 472f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 473f8829a4aSRandall Stewart /* free up the chk */ 474f8829a4aSRandall Stewart chk->data = NULL; 475f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 476f8829a4aSRandall Stewart 477f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 478f8829a4aSRandall Stewart /* 479f8829a4aSRandall Stewart * Now lets see if we can deliver the next one on 480f8829a4aSRandall Stewart * the stream 481f8829a4aSRandall Stewart */ 482f8829a4aSRandall Stewart struct sctp_stream_in *strm; 483f8829a4aSRandall Stewart 484f8829a4aSRandall Stewart strm = &asoc->strmin[stream_no]; 485f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 486f8829a4aSRandall Stewart ctl = TAILQ_FIRST(&strm->inqueue); 487f8829a4aSRandall Stewart if (ctl && (nxt_todel == ctl->sinfo_ssn)) { 488f8829a4aSRandall Stewart while (ctl != NULL) { 489f8829a4aSRandall Stewart /* Deliver more if we can. */ 490f8829a4aSRandall Stewart if (nxt_todel == ctl->sinfo_ssn) { 491f8829a4aSRandall Stewart ctlat = TAILQ_NEXT(ctl, next); 492f8829a4aSRandall Stewart TAILQ_REMOVE(&strm->inqueue, ctl, next); 493f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 494f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 495f8829a4aSRandall Stewart strm->last_sequence_delivered++; 496830d754dSRandall Stewart /* 497830d754dSRandall Stewart * EY will be used to 498830d754dSRandall Stewart * calculate nr-gap 499830d754dSRandall Stewart */ 500830d754dSRandall Stewart nr_tsn = ctl->sinfo_tsn; 501f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 502f8829a4aSRandall Stewart ctl, 503ceaad40aSRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_SO_NOT_LOCKED); 504830d754dSRandall Stewart /* 505830d754dSRandall Stewart * EY -now something is 506830d754dSRandall Stewart * delivered, calculate 507830d754dSRandall Stewart * nr_gap and tag this tsn 508830d754dSRandall Stewart * NR 509830d754dSRandall Stewart */ 510830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 511830d754dSRandall Stewart 512830d754dSRandall Stewart if (nr_tsn >= asoc->nr_mapping_array_base_tsn) { 513830d754dSRandall Stewart nr_gap = nr_tsn - asoc->nr_mapping_array_base_tsn; 514830d754dSRandall Stewart } else { 515830d754dSRandall Stewart nr_gap = (MAX_TSN - asoc->nr_mapping_array_base_tsn) + nr_tsn + 1; 516830d754dSRandall Stewart } 517830d754dSRandall Stewart if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) || 518830d754dSRandall Stewart (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) { 519830d754dSRandall Stewart /* 520830d754dSRandall Stewart * EY The 521830d754dSRandall Stewart * 1st 522830d754dSRandall Stewart * should 523830d754dSRandall Stewart * never 524830d754dSRandall Stewart * happen, 525830d754dSRandall Stewart * as in 526830d754dSRandall Stewart * process_a_ 527830d754dSRandall Stewart * data_chunk 528830d754dSRandall Stewart * method 529830d754dSRandall Stewart * this 530830d754dSRandall Stewart * check 531830d754dSRandall Stewart * should be 532830d754dSRandall Stewart * done 533830d754dSRandall Stewart */ 534830d754dSRandall Stewart /* 535830d754dSRandall Stewart * EY The 536830d754dSRandall Stewart * 2nd 537830d754dSRandall Stewart * should 538830d754dSRandall Stewart * never 539830d754dSRandall Stewart * happen, 540830d754dSRandall Stewart * because 541830d754dSRandall Stewart * nr_mapping 542830d754dSRandall Stewart * _array is 543830d754dSRandall Stewart * always 544830d754dSRandall Stewart * expanded 545830d754dSRandall Stewart * when 546830d754dSRandall Stewart * mapping_ar 547830d754dSRandall Stewart * ray is 548830d754dSRandall Stewart * expanded 549830d754dSRandall Stewart */ 550830d754dSRandall Stewart } else { 551830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 552830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap); 553830d754dSRandall Stewart if (nr_tsn > asoc->highest_tsn_inside_nr_map) 554830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = nr_tsn; 555830d754dSRandall Stewart } 556830d754dSRandall Stewart } 557f8829a4aSRandall Stewart ctl = ctlat; 558f8829a4aSRandall Stewart } else { 559f8829a4aSRandall Stewart break; 560f8829a4aSRandall Stewart } 561f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 562f8829a4aSRandall Stewart } 563f8829a4aSRandall Stewart } 564139bc87fSRandall Stewart break; 565f8829a4aSRandall Stewart } 5663c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 567f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 568f8829a4aSRandall Stewart } while (chk); 569f8829a4aSRandall Stewart } 570f8829a4aSRandall Stewart 571f8829a4aSRandall Stewart /* 572f8829a4aSRandall Stewart * Queue the chunk either right into the socket buffer if it is the next one 573f8829a4aSRandall Stewart * to go OR put it in the correct place in the delivery queue. If we do 574f8829a4aSRandall Stewart * append to the so_buf, keep doing so until we are out of order. One big 575f8829a4aSRandall Stewart * question still remains, what to do when the socket buffer is FULL?? 576f8829a4aSRandall Stewart */ 577f8829a4aSRandall Stewart static void 578f8829a4aSRandall Stewart sctp_queue_data_to_stream(struct sctp_tcb *stcb, struct sctp_association *asoc, 579f8829a4aSRandall Stewart struct sctp_queued_to_read *control, int *abort_flag) 580f8829a4aSRandall Stewart { 581f8829a4aSRandall Stewart /* 582f8829a4aSRandall Stewart * FIX-ME maybe? What happens when the ssn wraps? If we are getting 583f8829a4aSRandall Stewart * all the data in one stream this could happen quite rapidly. One 584f8829a4aSRandall Stewart * could use the TSN to keep track of things, but this scheme breaks 585f8829a4aSRandall Stewart * down in the other type of stream useage that could occur. Send a 586f8829a4aSRandall Stewart * single msg to stream 0, send 4Billion messages to stream 1, now 587f8829a4aSRandall Stewart * send a message to stream 0. You have a situation where the TSN 588f8829a4aSRandall Stewart * has wrapped but not in the stream. Is this worth worrying about 589f8829a4aSRandall Stewart * or should we just change our queue sort at the bottom to be by 590f8829a4aSRandall Stewart * TSN. 591f8829a4aSRandall Stewart * 592f8829a4aSRandall Stewart * Could it also be legal for a peer to send ssn 1 with TSN 2 and ssn 2 593f8829a4aSRandall Stewart * with TSN 1? If the peer is doing some sort of funky TSN/SSN 594f8829a4aSRandall Stewart * assignment this could happen... and I don't see how this would be 595f8829a4aSRandall Stewart * a violation. So for now I am undecided an will leave the sort by 596f8829a4aSRandall Stewart * SSN alone. Maybe a hybred approach is the answer 597f8829a4aSRandall Stewart * 598f8829a4aSRandall Stewart */ 599f8829a4aSRandall Stewart struct sctp_stream_in *strm; 600f8829a4aSRandall Stewart struct sctp_queued_to_read *at; 601f8829a4aSRandall Stewart int queue_needed; 602f8829a4aSRandall Stewart uint16_t nxt_todel; 603f8829a4aSRandall Stewart struct mbuf *oper; 604f8829a4aSRandall Stewart 605830d754dSRandall Stewart /* EY- will be used to calculate nr-gap for a tsn */ 606830d754dSRandall Stewart uint32_t nr_tsn, nr_gap; 607830d754dSRandall Stewart 608f8829a4aSRandall Stewart queue_needed = 1; 609f8829a4aSRandall Stewart asoc->size_on_all_streams += control->length; 610f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_all_streams); 611f8829a4aSRandall Stewart strm = &asoc->strmin[control->sinfo_stream]; 612f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 613b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 614f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD); 61580fefe0aSRandall Stewart } 616ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, 617ad81507eSRandall Stewart "queue to stream called for ssn:%u lastdel:%u nxt:%u\n", 618f8829a4aSRandall Stewart (uint32_t) control->sinfo_stream, 619ad81507eSRandall Stewart (uint32_t) strm->last_sequence_delivered, 620ad81507eSRandall Stewart (uint32_t) nxt_todel); 621f8829a4aSRandall Stewart if (compare_with_wrap(strm->last_sequence_delivered, 622f8829a4aSRandall Stewart control->sinfo_ssn, MAX_SEQ) || 623f8829a4aSRandall Stewart (strm->last_sequence_delivered == control->sinfo_ssn)) { 624f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 625ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ:%d delivered:%d from peer, Abort association\n", 626ad81507eSRandall Stewart control->sinfo_ssn, strm->last_sequence_delivered); 627c40e9cf2SRandall Stewart protocol_error: 628f8829a4aSRandall Stewart /* 629f8829a4aSRandall Stewart * throw it in the stream so it gets cleaned up in 630f8829a4aSRandall Stewart * association destruction 631f8829a4aSRandall Stewart */ 632f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&strm->inqueue, control, next); 633139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 634f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 635f8829a4aSRandall Stewart if (oper) { 636f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 637f8829a4aSRandall Stewart uint32_t *ippp; 638f8829a4aSRandall Stewart 639139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 640f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 641f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 642f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 643139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 644f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 645a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_1); 646f8829a4aSRandall Stewart ippp++; 647f8829a4aSRandall Stewart *ippp = control->sinfo_tsn; 648f8829a4aSRandall Stewart ippp++; 649f8829a4aSRandall Stewart *ippp = ((control->sinfo_stream << 16) | control->sinfo_ssn); 650f8829a4aSRandall Stewart } 651a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_1; 652f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 653ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 654f8829a4aSRandall Stewart 655f8829a4aSRandall Stewart *abort_flag = 1; 656f8829a4aSRandall Stewart return; 657f8829a4aSRandall Stewart 658f8829a4aSRandall Stewart } 659f8829a4aSRandall Stewart if (nxt_todel == control->sinfo_ssn) { 660f8829a4aSRandall Stewart /* can be delivered right away? */ 661b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 662f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_IMMED_DEL); 66380fefe0aSRandall Stewart } 664830d754dSRandall Stewart /* EY it wont be queued if it could be delivered directly */ 665f8829a4aSRandall Stewart queue_needed = 0; 666f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 667f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 668f8829a4aSRandall Stewart strm->last_sequence_delivered++; 669830d754dSRandall Stewart /* EY will be used to calculate nr-gap */ 670830d754dSRandall Stewart nr_tsn = control->sinfo_tsn; 671f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 672f8829a4aSRandall Stewart control, 673ceaad40aSRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_SO_NOT_LOCKED); 674830d754dSRandall Stewart 675830d754dSRandall Stewart /* 676830d754dSRandall Stewart * EY this is the chunk that should be tagged nr gapped 677830d754dSRandall Stewart * calculate the gap and such then tag this TSN nr 678830d754dSRandall Stewart * chk->rec.data.TSN_seq 679830d754dSRandall Stewart */ 680830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 681830d754dSRandall Stewart 682830d754dSRandall Stewart if (nr_tsn >= asoc->nr_mapping_array_base_tsn) { 683830d754dSRandall Stewart nr_gap = nr_tsn - asoc->nr_mapping_array_base_tsn; 684830d754dSRandall Stewart } else { 685830d754dSRandall Stewart nr_gap = (MAX_TSN - asoc->nr_mapping_array_base_tsn) + nr_tsn + 1; 686830d754dSRandall Stewart } 687830d754dSRandall Stewart if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) || 688830d754dSRandall Stewart (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) { 689830d754dSRandall Stewart /* 690830d754dSRandall Stewart * EY The 1st should never happen, as in 691830d754dSRandall Stewart * process_a_data_chunk method this check 692830d754dSRandall Stewart * should be done 693830d754dSRandall Stewart */ 694830d754dSRandall Stewart /* 695830d754dSRandall Stewart * EY The 2nd should never happen, because 696830d754dSRandall Stewart * nr_mapping_array is always expanded when 697830d754dSRandall Stewart * mapping_array is expanded 698830d754dSRandall Stewart */ 699830d754dSRandall Stewart } else { 700830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 701830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap); 702830d754dSRandall Stewart if (nr_tsn > asoc->highest_tsn_inside_nr_map) 703830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = nr_tsn; 704830d754dSRandall Stewart } 705830d754dSRandall Stewart } 706f8829a4aSRandall Stewart control = TAILQ_FIRST(&strm->inqueue); 707f8829a4aSRandall Stewart while (control != NULL) { 708f8829a4aSRandall Stewart /* all delivered */ 709f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 710f8829a4aSRandall Stewart if (nxt_todel == control->sinfo_ssn) { 711f8829a4aSRandall Stewart at = TAILQ_NEXT(control, next); 712f8829a4aSRandall Stewart TAILQ_REMOVE(&strm->inqueue, control, next); 713f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 714f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 715f8829a4aSRandall Stewart strm->last_sequence_delivered++; 716f8829a4aSRandall Stewart /* 717f8829a4aSRandall Stewart * We ignore the return of deliver_data here 718f8829a4aSRandall Stewart * since we always can hold the chunk on the 719f8829a4aSRandall Stewart * d-queue. And we have a finite number that 720f8829a4aSRandall Stewart * can be delivered from the strq. 721f8829a4aSRandall Stewart */ 722b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 723f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, 724f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_IMMED_DEL); 72580fefe0aSRandall Stewart } 726830d754dSRandall Stewart /* EY will be used to calculate nr-gap */ 727830d754dSRandall Stewart nr_tsn = control->sinfo_tsn; 728f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 729f8829a4aSRandall Stewart control, 730ceaad40aSRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_SO_NOT_LOCKED); 731830d754dSRandall Stewart /* 732830d754dSRandall Stewart * EY this is the chunk that should be 733830d754dSRandall Stewart * tagged nr gapped calculate the gap and 734830d754dSRandall Stewart * such then tag this TSN nr 735830d754dSRandall Stewart * chk->rec.data.TSN_seq 736830d754dSRandall Stewart */ 737830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 738830d754dSRandall Stewart 739830d754dSRandall Stewart if (nr_tsn >= asoc->nr_mapping_array_base_tsn) { 740830d754dSRandall Stewart nr_gap = nr_tsn - asoc->nr_mapping_array_base_tsn; 741830d754dSRandall Stewart } else { 742830d754dSRandall Stewart nr_gap = (MAX_TSN - asoc->nr_mapping_array_base_tsn) + nr_tsn + 1; 743830d754dSRandall Stewart } 744830d754dSRandall Stewart if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) || 745830d754dSRandall Stewart (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) { 746830d754dSRandall Stewart /* 747830d754dSRandall Stewart * EY The 1st should never 748830d754dSRandall Stewart * happen, as in 749830d754dSRandall Stewart * process_a_data_chunk 750830d754dSRandall Stewart * method this check should 751830d754dSRandall Stewart * be done 752830d754dSRandall Stewart */ 753830d754dSRandall Stewart /* 754830d754dSRandall Stewart * EY The 2nd should never 755830d754dSRandall Stewart * happen, because 756830d754dSRandall Stewart * nr_mapping_array is 757830d754dSRandall Stewart * always expanded when 758830d754dSRandall Stewart * mapping_array is expanded 759830d754dSRandall Stewart */ 760830d754dSRandall Stewart } else { 761830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 762830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap); 763830d754dSRandall Stewart if (nr_tsn > asoc->highest_tsn_inside_nr_map) 764830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = nr_tsn; 765830d754dSRandall Stewart } 766830d754dSRandall Stewart } 767f8829a4aSRandall Stewart control = at; 768f8829a4aSRandall Stewart continue; 769f8829a4aSRandall Stewart } 770f8829a4aSRandall Stewart break; 771f8829a4aSRandall Stewart } 772f8829a4aSRandall Stewart } 773f8829a4aSRandall Stewart if (queue_needed) { 774f8829a4aSRandall Stewart /* 775f8829a4aSRandall Stewart * Ok, we did not deliver this guy, find the correct place 776f8829a4aSRandall Stewart * to put it on the queue. 777f8829a4aSRandall Stewart */ 778c40e9cf2SRandall Stewart if ((compare_with_wrap(asoc->cumulative_tsn, 779c40e9cf2SRandall Stewart control->sinfo_tsn, MAX_TSN)) || 780c40e9cf2SRandall Stewart (control->sinfo_tsn == asoc->cumulative_tsn)) { 781c40e9cf2SRandall Stewart goto protocol_error; 782c40e9cf2SRandall Stewart } 783f8829a4aSRandall Stewart if (TAILQ_EMPTY(&strm->inqueue)) { 784f8829a4aSRandall Stewart /* Empty queue */ 785b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 786f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INSERT_HD); 78780fefe0aSRandall Stewart } 788f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&strm->inqueue, control, next); 789f8829a4aSRandall Stewart } else { 790f8829a4aSRandall Stewart TAILQ_FOREACH(at, &strm->inqueue, next) { 791f8829a4aSRandall Stewart if (compare_with_wrap(at->sinfo_ssn, 792f8829a4aSRandall Stewart control->sinfo_ssn, MAX_SEQ)) { 793f8829a4aSRandall Stewart /* 794f8829a4aSRandall Stewart * one in queue is bigger than the 795f8829a4aSRandall Stewart * new one, insert before this one 796f8829a4aSRandall Stewart */ 797b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 798f8829a4aSRandall Stewart sctp_log_strm_del(control, at, 799f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_INSERT_MD); 80080fefe0aSRandall Stewart } 801f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(at, control, next); 802f8829a4aSRandall Stewart break; 803f8829a4aSRandall Stewart } else if (at->sinfo_ssn == control->sinfo_ssn) { 804f8829a4aSRandall Stewart /* 805f8829a4aSRandall Stewart * Gak, He sent me a duplicate str 806f8829a4aSRandall Stewart * seq number 807f8829a4aSRandall Stewart */ 808f8829a4aSRandall Stewart /* 809f8829a4aSRandall Stewart * foo bar, I guess I will just free 810f8829a4aSRandall Stewart * this new guy, should we abort 811f8829a4aSRandall Stewart * too? FIX ME MAYBE? Or it COULD be 812f8829a4aSRandall Stewart * that the SSN's have wrapped. 813f8829a4aSRandall Stewart * Maybe I should compare to TSN 814f8829a4aSRandall Stewart * somehow... sigh for now just blow 815f8829a4aSRandall Stewart * away the chunk! 816f8829a4aSRandall Stewart */ 817f8829a4aSRandall Stewart 818f8829a4aSRandall Stewart if (control->data) 819f8829a4aSRandall Stewart sctp_m_freem(control->data); 820f8829a4aSRandall Stewart control->data = NULL; 821f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 822f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 8235bead436SRandall Stewart if (control->whoFrom) 824f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 8255bead436SRandall Stewart control->whoFrom = NULL; 826f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 827f8829a4aSRandall Stewart return; 828f8829a4aSRandall Stewart } else { 829f8829a4aSRandall Stewart if (TAILQ_NEXT(at, next) == NULL) { 830f8829a4aSRandall Stewart /* 831f8829a4aSRandall Stewart * We are at the end, insert 832f8829a4aSRandall Stewart * it after this one 833f8829a4aSRandall Stewart */ 834b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 835f8829a4aSRandall Stewart sctp_log_strm_del(control, at, 836f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_INSERT_TL); 83780fefe0aSRandall Stewart } 838f8829a4aSRandall Stewart TAILQ_INSERT_AFTER(&strm->inqueue, 839f8829a4aSRandall Stewart at, control, next); 840f8829a4aSRandall Stewart break; 841f8829a4aSRandall Stewart } 842f8829a4aSRandall Stewart } 843f8829a4aSRandall Stewart } 844f8829a4aSRandall Stewart } 845f8829a4aSRandall Stewart } 846f8829a4aSRandall Stewart } 847f8829a4aSRandall Stewart 848f8829a4aSRandall Stewart /* 849f8829a4aSRandall Stewart * Returns two things: You get the total size of the deliverable parts of the 850f8829a4aSRandall Stewart * first fragmented message on the reassembly queue. And you get a 1 back if 851f8829a4aSRandall Stewart * all of the message is ready or a 0 back if the message is still incomplete 852f8829a4aSRandall Stewart */ 853f8829a4aSRandall Stewart static int 854f8829a4aSRandall Stewart sctp_is_all_msg_on_reasm(struct sctp_association *asoc, uint32_t * t_size) 855f8829a4aSRandall Stewart { 856f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 857f8829a4aSRandall Stewart uint32_t tsn; 858f8829a4aSRandall Stewart 859f8829a4aSRandall Stewart *t_size = 0; 860f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 861f8829a4aSRandall Stewart if (chk == NULL) { 862f8829a4aSRandall Stewart /* nothing on the queue */ 863f8829a4aSRandall Stewart return (0); 864f8829a4aSRandall Stewart } 865f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { 866f8829a4aSRandall Stewart /* Not a first on the queue */ 867f8829a4aSRandall Stewart return (0); 868f8829a4aSRandall Stewart } 869f8829a4aSRandall Stewart tsn = chk->rec.data.TSN_seq; 870f8829a4aSRandall Stewart while (chk) { 871f8829a4aSRandall Stewart if (tsn != chk->rec.data.TSN_seq) { 872f8829a4aSRandall Stewart return (0); 873f8829a4aSRandall Stewart } 874f8829a4aSRandall Stewart *t_size += chk->send_size; 875f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 876f8829a4aSRandall Stewart return (1); 877f8829a4aSRandall Stewart } 878f8829a4aSRandall Stewart tsn++; 879f8829a4aSRandall Stewart chk = TAILQ_NEXT(chk, sctp_next); 880f8829a4aSRandall Stewart } 881f8829a4aSRandall Stewart return (0); 882f8829a4aSRandall Stewart } 883f8829a4aSRandall Stewart 884f8829a4aSRandall Stewart static void 885f8829a4aSRandall Stewart sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc) 886f8829a4aSRandall Stewart { 887f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 888f8829a4aSRandall Stewart uint16_t nxt_todel; 889f8829a4aSRandall Stewart uint32_t tsize; 890f8829a4aSRandall Stewart 891139bc87fSRandall Stewart doit_again: 892f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 893f8829a4aSRandall Stewart if (chk == NULL) { 894f8829a4aSRandall Stewart /* Huh? */ 895f8829a4aSRandall Stewart asoc->size_on_reasm_queue = 0; 896f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue = 0; 897f8829a4aSRandall Stewart return; 898f8829a4aSRandall Stewart } 899f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 900f8829a4aSRandall Stewart nxt_todel = 901f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1; 902f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) && 903f8829a4aSRandall Stewart (nxt_todel == chk->rec.data.stream_seq || 904f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) { 905f8829a4aSRandall Stewart /* 906f8829a4aSRandall Stewart * Yep the first one is here and its ok to deliver 907f8829a4aSRandall Stewart * but should we? 908f8829a4aSRandall Stewart */ 909f8829a4aSRandall Stewart if ((sctp_is_all_msg_on_reasm(asoc, &tsize) || 910c4739e2fSRandall Stewart (tsize >= stcb->sctp_ep->partial_delivery_point))) { 911f8829a4aSRandall Stewart 912f8829a4aSRandall Stewart /* 913f8829a4aSRandall Stewart * Yes, we setup to start reception, by 914f8829a4aSRandall Stewart * backing down the TSN just in case we 915f8829a4aSRandall Stewart * can't deliver. If we 916f8829a4aSRandall Stewart */ 917f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 918f8829a4aSRandall Stewart asoc->tsn_last_delivered = 919f8829a4aSRandall Stewart chk->rec.data.TSN_seq - 1; 920f8829a4aSRandall Stewart asoc->str_of_pdapi = 921f8829a4aSRandall Stewart chk->rec.data.stream_number; 922f8829a4aSRandall Stewart asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 923f8829a4aSRandall Stewart asoc->pdapi_ppid = chk->rec.data.payloadtype; 924f8829a4aSRandall Stewart asoc->fragment_flags = chk->rec.data.rcv_flags; 925f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 926f8829a4aSRandall Stewart } 927f8829a4aSRandall Stewart } 928f8829a4aSRandall Stewart } else { 929139bc87fSRandall Stewart /* 930139bc87fSRandall Stewart * Service re-assembly will deliver stream data queued at 931139bc87fSRandall Stewart * the end of fragmented delivery.. but it wont know to go 932139bc87fSRandall Stewart * back and call itself again... we do that here with the 933139bc87fSRandall Stewart * got doit_again 934139bc87fSRandall Stewart */ 935f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 936139bc87fSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 937139bc87fSRandall Stewart /* 938139bc87fSRandall Stewart * finished our Fragmented delivery, could be more 939139bc87fSRandall Stewart * waiting? 940139bc87fSRandall Stewart */ 941139bc87fSRandall Stewart goto doit_again; 942139bc87fSRandall Stewart } 943f8829a4aSRandall Stewart } 944f8829a4aSRandall Stewart } 945f8829a4aSRandall Stewart 946f8829a4aSRandall Stewart /* 947f8829a4aSRandall Stewart * Dump onto the re-assembly queue, in its proper place. After dumping on the 948f8829a4aSRandall Stewart * queue, see if anthing can be delivered. If so pull it off (or as much as 949f8829a4aSRandall Stewart * we can. If we run out of space then we must dump what we can and set the 950f8829a4aSRandall Stewart * appropriate flag to say we queued what we could. 951f8829a4aSRandall Stewart */ 952f8829a4aSRandall Stewart static void 953f8829a4aSRandall Stewart sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, 954f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk, int *abort_flag) 955f8829a4aSRandall Stewart { 956f8829a4aSRandall Stewart struct mbuf *oper; 957f8829a4aSRandall Stewart uint32_t cum_ackp1, last_tsn, prev_tsn, post_tsn; 958f8829a4aSRandall Stewart u_char last_flags; 959f8829a4aSRandall Stewart struct sctp_tmit_chunk *at, *prev, *next; 960f8829a4aSRandall Stewart 961f8829a4aSRandall Stewart prev = next = NULL; 962f8829a4aSRandall Stewart cum_ackp1 = asoc->tsn_last_delivered + 1; 963f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue)) { 964f8829a4aSRandall Stewart /* This is the first one on the queue */ 965f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&asoc->reasmqueue, chk, sctp_next); 966f8829a4aSRandall Stewart /* 967f8829a4aSRandall Stewart * we do not check for delivery of anything when only one 968f8829a4aSRandall Stewart * fragment is here 969f8829a4aSRandall Stewart */ 970f8829a4aSRandall Stewart asoc->size_on_reasm_queue = chk->send_size; 971f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 972f8829a4aSRandall Stewart if (chk->rec.data.TSN_seq == cum_ackp1) { 973f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0 && 974f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) != 975f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 976f8829a4aSRandall Stewart /* 977f8829a4aSRandall Stewart * An empty queue, no delivery inprogress, 978f8829a4aSRandall Stewart * we hit the next one and it does NOT have 979f8829a4aSRandall Stewart * a FIRST fragment mark. 980f8829a4aSRandall Stewart */ 981ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not first, no fragmented delivery in progress\n"); 982139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 983f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 984f8829a4aSRandall Stewart 985f8829a4aSRandall Stewart if (oper) { 986f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 987f8829a4aSRandall Stewart uint32_t *ippp; 988f8829a4aSRandall Stewart 989139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 990f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 991f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 992f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 993f8829a4aSRandall Stewart ph->param_type = 994f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 995139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 996f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 997a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_2); 998f8829a4aSRandall Stewart ippp++; 999f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1000f8829a4aSRandall Stewart ippp++; 1001f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1002f8829a4aSRandall Stewart 1003f8829a4aSRandall Stewart } 1004a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2; 1005f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1006ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1007f8829a4aSRandall Stewart *abort_flag = 1; 1008f8829a4aSRandall Stewart } else if (asoc->fragmented_delivery_inprogress && 1009f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) { 1010f8829a4aSRandall Stewart /* 1011f8829a4aSRandall Stewart * We are doing a partial delivery and the 1012f8829a4aSRandall Stewart * NEXT chunk MUST be either the LAST or 1013f8829a4aSRandall Stewart * MIDDLE fragment NOT a FIRST 1014f8829a4aSRandall Stewart */ 1015ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS a first and fragmented delivery in progress\n"); 1016139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1017f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1018f8829a4aSRandall Stewart if (oper) { 1019f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1020f8829a4aSRandall Stewart uint32_t *ippp; 1021f8829a4aSRandall Stewart 1022139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1023f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1024f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1025f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 1026f8829a4aSRandall Stewart ph->param_type = 1027f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1028139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 1029f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1030a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_3); 1031f8829a4aSRandall Stewart ippp++; 1032f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1033f8829a4aSRandall Stewart ippp++; 1034f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1035f8829a4aSRandall Stewart } 1036a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_3; 1037f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1038ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1039f8829a4aSRandall Stewart *abort_flag = 1; 1040f8829a4aSRandall Stewart } else if (asoc->fragmented_delivery_inprogress) { 1041f8829a4aSRandall Stewart /* 1042f8829a4aSRandall Stewart * Here we are ok with a MIDDLE or LAST 1043f8829a4aSRandall Stewart * piece 1044f8829a4aSRandall Stewart */ 1045f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 1046f8829a4aSRandall Stewart asoc->str_of_pdapi) { 1047f8829a4aSRandall Stewart /* Got to be the right STR No */ 1048ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream number %d vs %d\n", 1049f8829a4aSRandall Stewart chk->rec.data.stream_number, 1050f8829a4aSRandall Stewart asoc->str_of_pdapi); 1051139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1052f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1053f8829a4aSRandall Stewart if (oper) { 1054f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1055f8829a4aSRandall Stewart uint32_t *ippp; 1056f8829a4aSRandall Stewart 1057139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1058f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1059f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 1060f8829a4aSRandall Stewart ph = mtod(oper, 1061f8829a4aSRandall Stewart struct sctp_paramhdr *); 1062f8829a4aSRandall Stewart ph->param_type = 1063f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1064f8829a4aSRandall Stewart ph->param_length = 1065139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1066f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1067a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_4); 1068f8829a4aSRandall Stewart ippp++; 1069f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1070f8829a4aSRandall Stewart ippp++; 1071f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1072f8829a4aSRandall Stewart } 1073a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_4; 1074f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1075ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1076f8829a4aSRandall Stewart *abort_flag = 1; 1077f8829a4aSRandall Stewart } else if ((asoc->fragment_flags & SCTP_DATA_UNORDERED) != 1078f8829a4aSRandall Stewart SCTP_DATA_UNORDERED && 1079f8829a4aSRandall Stewart chk->rec.data.stream_seq != 1080f8829a4aSRandall Stewart asoc->ssn_of_pdapi) { 1081f8829a4aSRandall Stewart /* Got to be the right STR Seq */ 1082ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream seq %d vs %d\n", 1083f8829a4aSRandall Stewart chk->rec.data.stream_seq, 1084f8829a4aSRandall Stewart asoc->ssn_of_pdapi); 1085139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1086f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1087f8829a4aSRandall Stewart if (oper) { 1088f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1089f8829a4aSRandall Stewart uint32_t *ippp; 1090f8829a4aSRandall Stewart 1091139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1092f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1093f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1094f8829a4aSRandall Stewart ph = mtod(oper, 1095f8829a4aSRandall Stewart struct sctp_paramhdr *); 1096f8829a4aSRandall Stewart ph->param_type = 1097f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1098f8829a4aSRandall Stewart ph->param_length = 1099139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1100f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1101a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_5); 1102f8829a4aSRandall Stewart ippp++; 1103f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1104f8829a4aSRandall Stewart ippp++; 1105f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1106f8829a4aSRandall Stewart 1107f8829a4aSRandall Stewart } 1108a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_5; 1109f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1110ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1111f8829a4aSRandall Stewart *abort_flag = 1; 1112f8829a4aSRandall Stewart } 1113f8829a4aSRandall Stewart } 1114f8829a4aSRandall Stewart } 1115f8829a4aSRandall Stewart return; 1116f8829a4aSRandall Stewart } 1117f8829a4aSRandall Stewart /* Find its place */ 1118f8829a4aSRandall Stewart TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) { 1119f8829a4aSRandall Stewart if (compare_with_wrap(at->rec.data.TSN_seq, 1120f8829a4aSRandall Stewart chk->rec.data.TSN_seq, MAX_TSN)) { 1121f8829a4aSRandall Stewart /* 1122f8829a4aSRandall Stewart * one in queue is bigger than the new one, insert 1123f8829a4aSRandall Stewart * before this one 1124f8829a4aSRandall Stewart */ 1125f8829a4aSRandall Stewart /* A check */ 1126f8829a4aSRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 1127f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 1128f8829a4aSRandall Stewart next = at; 1129f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(at, chk, sctp_next); 1130f8829a4aSRandall Stewart break; 1131f8829a4aSRandall Stewart } else if (at->rec.data.TSN_seq == chk->rec.data.TSN_seq) { 1132f8829a4aSRandall Stewart /* Gak, He sent me a duplicate str seq number */ 1133f8829a4aSRandall Stewart /* 1134f8829a4aSRandall Stewart * foo bar, I guess I will just free this new guy, 1135f8829a4aSRandall Stewart * should we abort too? FIX ME MAYBE? Or it COULD be 1136f8829a4aSRandall Stewart * that the SSN's have wrapped. Maybe I should 1137f8829a4aSRandall Stewart * compare to TSN somehow... sigh for now just blow 1138f8829a4aSRandall Stewart * away the chunk! 1139f8829a4aSRandall Stewart */ 1140f8829a4aSRandall Stewart if (chk->data) { 1141f8829a4aSRandall Stewart sctp_m_freem(chk->data); 1142f8829a4aSRandall Stewart chk->data = NULL; 1143f8829a4aSRandall Stewart } 1144f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 1145f8829a4aSRandall Stewart return; 1146f8829a4aSRandall Stewart } else { 1147f8829a4aSRandall Stewart last_flags = at->rec.data.rcv_flags; 1148f8829a4aSRandall Stewart last_tsn = at->rec.data.TSN_seq; 1149f8829a4aSRandall Stewart prev = at; 1150f8829a4aSRandall Stewart if (TAILQ_NEXT(at, sctp_next) == NULL) { 1151f8829a4aSRandall Stewart /* 1152f8829a4aSRandall Stewart * We are at the end, insert it after this 1153f8829a4aSRandall Stewart * one 1154f8829a4aSRandall Stewart */ 1155f8829a4aSRandall Stewart /* check it first */ 1156f8829a4aSRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 1157f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 1158f8829a4aSRandall Stewart TAILQ_INSERT_AFTER(&asoc->reasmqueue, at, chk, sctp_next); 1159f8829a4aSRandall Stewart break; 1160f8829a4aSRandall Stewart } 1161f8829a4aSRandall Stewart } 1162f8829a4aSRandall Stewart } 1163f8829a4aSRandall Stewart /* Now the audits */ 1164f8829a4aSRandall Stewart if (prev) { 1165f8829a4aSRandall Stewart prev_tsn = chk->rec.data.TSN_seq - 1; 1166f8829a4aSRandall Stewart if (prev_tsn == prev->rec.data.TSN_seq) { 1167f8829a4aSRandall Stewart /* 1168f8829a4aSRandall Stewart * Ok the one I am dropping onto the end is the 1169f8829a4aSRandall Stewart * NEXT. A bit of valdiation here. 1170f8829a4aSRandall Stewart */ 1171f8829a4aSRandall Stewart if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1172f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG || 1173f8829a4aSRandall Stewart (prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1174f8829a4aSRandall Stewart SCTP_DATA_MIDDLE_FRAG) { 1175f8829a4aSRandall Stewart /* 1176f8829a4aSRandall Stewart * Insert chk MUST be a MIDDLE or LAST 1177f8829a4aSRandall Stewart * fragment 1178f8829a4aSRandall Stewart */ 1179f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1180f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1181ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - It can be a midlle or last but not a first\n"); 1182ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it's a FIRST!\n"); 1183139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1184f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1185f8829a4aSRandall Stewart if (oper) { 1186f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1187f8829a4aSRandall Stewart uint32_t *ippp; 1188f8829a4aSRandall Stewart 1189139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1190f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1191f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1192f8829a4aSRandall Stewart ph = mtod(oper, 1193f8829a4aSRandall Stewart struct sctp_paramhdr *); 1194f8829a4aSRandall Stewart ph->param_type = 1195f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1196f8829a4aSRandall Stewart ph->param_length = 1197139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1198f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1199a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_6); 1200f8829a4aSRandall Stewart ippp++; 1201f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1202f8829a4aSRandall Stewart ippp++; 1203f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1204f8829a4aSRandall Stewart 1205f8829a4aSRandall Stewart } 1206a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_6; 1207f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1208ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1209f8829a4aSRandall Stewart *abort_flag = 1; 1210f8829a4aSRandall Stewart return; 1211f8829a4aSRandall Stewart } 1212f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 1213f8829a4aSRandall Stewart prev->rec.data.stream_number) { 1214f8829a4aSRandall Stewart /* 1215f8829a4aSRandall Stewart * Huh, need the correct STR here, 1216f8829a4aSRandall Stewart * they must be the same. 1217f8829a4aSRandall Stewart */ 1218ad81507eSRandall Stewart SCTP_PRINTF("Prev check - Gak, Evil plot, ssn:%d not the same as at:%d\n", 1219f8829a4aSRandall Stewart chk->rec.data.stream_number, 1220f8829a4aSRandall Stewart prev->rec.data.stream_number); 1221139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1222f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1223f8829a4aSRandall Stewart if (oper) { 1224f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1225f8829a4aSRandall Stewart uint32_t *ippp; 1226f8829a4aSRandall Stewart 1227139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1228f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1229f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1230f8829a4aSRandall Stewart ph = mtod(oper, 1231f8829a4aSRandall Stewart struct sctp_paramhdr *); 1232f8829a4aSRandall Stewart ph->param_type = 1233f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1234f8829a4aSRandall Stewart ph->param_length = 1235139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1236f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1237a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_7); 1238f8829a4aSRandall Stewart ippp++; 1239f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1240f8829a4aSRandall Stewart ippp++; 1241f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1242f8829a4aSRandall Stewart } 1243a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_7; 1244f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1245ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1246f8829a4aSRandall Stewart 1247f8829a4aSRandall Stewart *abort_flag = 1; 1248f8829a4aSRandall Stewart return; 1249f8829a4aSRandall Stewart } 1250f8829a4aSRandall Stewart if ((prev->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 && 1251f8829a4aSRandall Stewart chk->rec.data.stream_seq != 1252f8829a4aSRandall Stewart prev->rec.data.stream_seq) { 1253f8829a4aSRandall Stewart /* 1254f8829a4aSRandall Stewart * Huh, need the correct STR here, 1255f8829a4aSRandall Stewart * they must be the same. 1256f8829a4aSRandall Stewart */ 1257ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, Evil plot, sseq:%d not the same as at:%d\n", 1258f8829a4aSRandall Stewart chk->rec.data.stream_seq, 1259f8829a4aSRandall Stewart prev->rec.data.stream_seq); 1260139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1261f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1262f8829a4aSRandall Stewart if (oper) { 1263f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1264f8829a4aSRandall Stewart uint32_t *ippp; 1265f8829a4aSRandall Stewart 1266139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1267f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1268f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1269f8829a4aSRandall Stewart ph = mtod(oper, 1270f8829a4aSRandall Stewart struct sctp_paramhdr *); 1271f8829a4aSRandall Stewart ph->param_type = 1272f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1273f8829a4aSRandall Stewart ph->param_length = 1274139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1275f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1276a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_8); 1277f8829a4aSRandall Stewart ippp++; 1278f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1279f8829a4aSRandall Stewart ippp++; 1280f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1281f8829a4aSRandall Stewart } 1282a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_8; 1283f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1284ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1285f8829a4aSRandall Stewart 1286f8829a4aSRandall Stewart *abort_flag = 1; 1287f8829a4aSRandall Stewart return; 1288f8829a4aSRandall Stewart } 1289f8829a4aSRandall Stewart } else if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1290f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1291f8829a4aSRandall Stewart /* Insert chk MUST be a FIRST */ 1292f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1293f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1294ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, evil plot, its not FIRST and it must be!\n"); 1295139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1296f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1297f8829a4aSRandall Stewart if (oper) { 1298f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1299f8829a4aSRandall Stewart uint32_t *ippp; 1300f8829a4aSRandall Stewart 1301139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1302f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1303f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1304f8829a4aSRandall Stewart ph = mtod(oper, 1305f8829a4aSRandall Stewart struct sctp_paramhdr *); 1306f8829a4aSRandall Stewart ph->param_type = 1307f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1308f8829a4aSRandall Stewart ph->param_length = 1309139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1310f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1311a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_9); 1312f8829a4aSRandall Stewart ippp++; 1313f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1314f8829a4aSRandall Stewart ippp++; 1315f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1316f8829a4aSRandall Stewart 1317f8829a4aSRandall Stewart } 1318a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_9; 1319f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1320ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1321f8829a4aSRandall Stewart 1322f8829a4aSRandall Stewart *abort_flag = 1; 1323f8829a4aSRandall Stewart return; 1324f8829a4aSRandall Stewart } 1325f8829a4aSRandall Stewart } 1326f8829a4aSRandall Stewart } 1327f8829a4aSRandall Stewart } 1328f8829a4aSRandall Stewart if (next) { 1329f8829a4aSRandall Stewart post_tsn = chk->rec.data.TSN_seq + 1; 1330f8829a4aSRandall Stewart if (post_tsn == next->rec.data.TSN_seq) { 1331f8829a4aSRandall Stewart /* 1332f8829a4aSRandall Stewart * Ok the one I am inserting ahead of is my NEXT 1333f8829a4aSRandall Stewart * one. A bit of valdiation here. 1334f8829a4aSRandall Stewart */ 1335f8829a4aSRandall Stewart if (next->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 1336f8829a4aSRandall Stewart /* Insert chk MUST be a last fragment */ 1337f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) 1338f8829a4aSRandall Stewart != SCTP_DATA_LAST_FRAG) { 1339ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is FIRST, we must be LAST\n"); 1340ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not a last!\n"); 1341139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1342f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1343f8829a4aSRandall Stewart if (oper) { 1344f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1345f8829a4aSRandall Stewart uint32_t *ippp; 1346f8829a4aSRandall Stewart 1347139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1348f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1349f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1350f8829a4aSRandall Stewart ph = mtod(oper, 1351f8829a4aSRandall Stewart struct sctp_paramhdr *); 1352f8829a4aSRandall Stewart ph->param_type = 1353f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1354f8829a4aSRandall Stewart ph->param_length = 1355139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1356f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1357a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_10); 1358f8829a4aSRandall Stewart ippp++; 1359f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1360f8829a4aSRandall Stewart ippp++; 1361f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1362f8829a4aSRandall Stewart } 1363a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_10; 1364f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1365ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1366f8829a4aSRandall Stewart 1367f8829a4aSRandall Stewart *abort_flag = 1; 1368f8829a4aSRandall Stewart return; 1369f8829a4aSRandall Stewart } 1370f8829a4aSRandall Stewart } else if ((next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1371f8829a4aSRandall Stewart SCTP_DATA_MIDDLE_FRAG || 1372f8829a4aSRandall Stewart (next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1373f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1374f8829a4aSRandall Stewart /* 1375f8829a4aSRandall Stewart * Insert chk CAN be MIDDLE or FIRST NOT 1376f8829a4aSRandall Stewart * LAST 1377f8829a4aSRandall Stewart */ 1378f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1379f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1380ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is a MIDDLE/LAST\n"); 1381ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, new prev chunk is a LAST\n"); 1382139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1383f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1384f8829a4aSRandall Stewart if (oper) { 1385f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1386f8829a4aSRandall Stewart uint32_t *ippp; 1387f8829a4aSRandall Stewart 1388139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1389f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1390f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1391f8829a4aSRandall Stewart ph = mtod(oper, 1392f8829a4aSRandall Stewart struct sctp_paramhdr *); 1393f8829a4aSRandall Stewart ph->param_type = 1394f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1395f8829a4aSRandall Stewart ph->param_length = 1396139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1397f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1398a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_11); 1399f8829a4aSRandall Stewart ippp++; 1400f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1401f8829a4aSRandall Stewart ippp++; 1402f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1403f8829a4aSRandall Stewart 1404f8829a4aSRandall Stewart } 1405a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_11; 1406f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1407ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1408f8829a4aSRandall Stewart 1409f8829a4aSRandall Stewart *abort_flag = 1; 1410f8829a4aSRandall Stewart return; 1411f8829a4aSRandall Stewart } 1412f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 1413f8829a4aSRandall Stewart next->rec.data.stream_number) { 1414f8829a4aSRandall Stewart /* 1415f8829a4aSRandall Stewart * Huh, need the correct STR here, 1416f8829a4aSRandall Stewart * they must be the same. 1417f8829a4aSRandall Stewart */ 1418ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, ssn:%d not the same as at:%d\n", 1419f8829a4aSRandall Stewart chk->rec.data.stream_number, 1420f8829a4aSRandall Stewart next->rec.data.stream_number); 1421139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1422f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1423f8829a4aSRandall Stewart if (oper) { 1424f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1425f8829a4aSRandall Stewart uint32_t *ippp; 1426f8829a4aSRandall Stewart 1427139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1428f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1429f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1430f8829a4aSRandall Stewart ph = mtod(oper, 1431f8829a4aSRandall Stewart struct sctp_paramhdr *); 1432f8829a4aSRandall Stewart ph->param_type = 1433f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1434f8829a4aSRandall Stewart ph->param_length = 1435139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1436f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1437a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_12); 1438f8829a4aSRandall Stewart ippp++; 1439f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1440f8829a4aSRandall Stewart ippp++; 1441f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1442f8829a4aSRandall Stewart 1443f8829a4aSRandall Stewart } 1444a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_12; 1445f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1446ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1447f8829a4aSRandall Stewart 1448f8829a4aSRandall Stewart *abort_flag = 1; 1449f8829a4aSRandall Stewart return; 1450f8829a4aSRandall Stewart } 1451f8829a4aSRandall Stewart if ((next->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 && 1452f8829a4aSRandall Stewart chk->rec.data.stream_seq != 1453f8829a4aSRandall Stewart next->rec.data.stream_seq) { 1454f8829a4aSRandall Stewart /* 1455f8829a4aSRandall Stewart * Huh, need the correct STR here, 1456f8829a4aSRandall Stewart * they must be the same. 1457f8829a4aSRandall Stewart */ 1458ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, sseq:%d not the same as at:%d\n", 1459f8829a4aSRandall Stewart chk->rec.data.stream_seq, 1460f8829a4aSRandall Stewart next->rec.data.stream_seq); 1461139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1462f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1463f8829a4aSRandall Stewart if (oper) { 1464f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1465f8829a4aSRandall Stewart uint32_t *ippp; 1466f8829a4aSRandall Stewart 1467139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1468f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1469f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1470f8829a4aSRandall Stewart ph = mtod(oper, 1471f8829a4aSRandall Stewart struct sctp_paramhdr *); 1472f8829a4aSRandall Stewart ph->param_type = 1473f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1474f8829a4aSRandall Stewart ph->param_length = 1475139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1476f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1477a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_13); 1478f8829a4aSRandall Stewart ippp++; 1479f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1480f8829a4aSRandall Stewart ippp++; 1481f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1482f8829a4aSRandall Stewart } 1483a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_13; 1484f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1485ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1486f8829a4aSRandall Stewart 1487f8829a4aSRandall Stewart *abort_flag = 1; 1488f8829a4aSRandall Stewart return; 1489f8829a4aSRandall Stewart } 1490f8829a4aSRandall Stewart } 1491f8829a4aSRandall Stewart } 1492f8829a4aSRandall Stewart } 1493f8829a4aSRandall Stewart /* Do we need to do some delivery? check */ 1494f8829a4aSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 1495f8829a4aSRandall Stewart } 1496f8829a4aSRandall Stewart 1497f8829a4aSRandall Stewart /* 1498f8829a4aSRandall Stewart * This is an unfortunate routine. It checks to make sure a evil guy is not 1499f8829a4aSRandall Stewart * stuffing us full of bad packet fragments. A broken peer could also do this 1500f8829a4aSRandall Stewart * but this is doubtful. It is to bad I must worry about evil crackers sigh 1501f8829a4aSRandall Stewart * :< more cycles. 1502f8829a4aSRandall Stewart */ 1503f8829a4aSRandall Stewart static int 1504f8829a4aSRandall Stewart sctp_does_tsn_belong_to_reasm(struct sctp_association *asoc, 1505f8829a4aSRandall Stewart uint32_t TSN_seq) 1506f8829a4aSRandall Stewart { 1507f8829a4aSRandall Stewart struct sctp_tmit_chunk *at; 1508f8829a4aSRandall Stewart uint32_t tsn_est; 1509f8829a4aSRandall Stewart 1510f8829a4aSRandall Stewart TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) { 1511f8829a4aSRandall Stewart if (compare_with_wrap(TSN_seq, 1512f8829a4aSRandall Stewart at->rec.data.TSN_seq, MAX_TSN)) { 1513f8829a4aSRandall Stewart /* is it one bigger? */ 1514f8829a4aSRandall Stewart tsn_est = at->rec.data.TSN_seq + 1; 1515f8829a4aSRandall Stewart if (tsn_est == TSN_seq) { 1516f8829a4aSRandall Stewart /* yep. It better be a last then */ 1517f8829a4aSRandall Stewart if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1518f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1519f8829a4aSRandall Stewart /* 1520f8829a4aSRandall Stewart * Ok this guy belongs next to a guy 1521f8829a4aSRandall Stewart * that is NOT last, it should be a 1522f8829a4aSRandall Stewart * middle/last, not a complete 1523f8829a4aSRandall Stewart * chunk. 1524f8829a4aSRandall Stewart */ 1525f8829a4aSRandall Stewart return (1); 1526f8829a4aSRandall Stewart } else { 1527f8829a4aSRandall Stewart /* 1528f8829a4aSRandall Stewart * This guy is ok since its a LAST 1529f8829a4aSRandall Stewart * and the new chunk is a fully 1530f8829a4aSRandall Stewart * self- contained one. 1531f8829a4aSRandall Stewart */ 1532f8829a4aSRandall Stewart return (0); 1533f8829a4aSRandall Stewart } 1534f8829a4aSRandall Stewart } 1535f8829a4aSRandall Stewart } else if (TSN_seq == at->rec.data.TSN_seq) { 1536f8829a4aSRandall Stewart /* Software error since I have a dup? */ 1537f8829a4aSRandall Stewart return (1); 1538f8829a4aSRandall Stewart } else { 1539f8829a4aSRandall Stewart /* 1540f8829a4aSRandall Stewart * Ok, 'at' is larger than new chunk but does it 1541f8829a4aSRandall Stewart * need to be right before it. 1542f8829a4aSRandall Stewart */ 1543f8829a4aSRandall Stewart tsn_est = TSN_seq + 1; 1544f8829a4aSRandall Stewart if (tsn_est == at->rec.data.TSN_seq) { 1545f8829a4aSRandall Stewart /* Yep, It better be a first */ 1546f8829a4aSRandall Stewart if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1547f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1548f8829a4aSRandall Stewart return (1); 1549f8829a4aSRandall Stewart } else { 1550f8829a4aSRandall Stewart return (0); 1551f8829a4aSRandall Stewart } 1552f8829a4aSRandall Stewart } 1553f8829a4aSRandall Stewart } 1554f8829a4aSRandall Stewart } 1555f8829a4aSRandall Stewart return (0); 1556f8829a4aSRandall Stewart } 1557f8829a4aSRandall Stewart 1558f8829a4aSRandall Stewart 1559f8829a4aSRandall Stewart static int 1560f8829a4aSRandall Stewart sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, 1561f8829a4aSRandall Stewart struct mbuf **m, int offset, struct sctp_data_chunk *ch, int chk_length, 1562f8829a4aSRandall Stewart struct sctp_nets *net, uint32_t * high_tsn, int *abort_flag, 1563f8829a4aSRandall Stewart int *break_flag, int last_chunk) 1564f8829a4aSRandall Stewart { 1565f8829a4aSRandall Stewart /* Process a data chunk */ 1566f8829a4aSRandall Stewart /* struct sctp_tmit_chunk *chk; */ 1567f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 1568f8829a4aSRandall Stewart uint32_t tsn, gap; 1569830d754dSRandall Stewart 1570830d754dSRandall Stewart /* EY - for nr_sack */ 1571830d754dSRandall Stewart uint32_t nr_gap; 1572f8829a4aSRandall Stewart struct mbuf *dmbuf; 1573f8829a4aSRandall Stewart int indx, the_len; 1574139bc87fSRandall Stewart int need_reasm_check = 0; 1575f8829a4aSRandall Stewart uint16_t strmno, strmseq; 1576f8829a4aSRandall Stewart struct mbuf *oper; 1577f8829a4aSRandall Stewart struct sctp_queued_to_read *control; 1578f42a358aSRandall Stewart int ordered; 1579f42a358aSRandall Stewart uint32_t protocol_id; 1580f42a358aSRandall Stewart uint8_t chunk_flags; 158117205eccSRandall Stewart struct sctp_stream_reset_list *liste; 1582f8829a4aSRandall Stewart 1583f8829a4aSRandall Stewart chk = NULL; 1584f8829a4aSRandall Stewart tsn = ntohl(ch->dp.tsn); 1585f42a358aSRandall Stewart chunk_flags = ch->ch.chunk_flags; 1586b3f1ea41SRandall Stewart if ((chunk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) { 1587b3f1ea41SRandall Stewart asoc->send_sack = 1; 1588b3f1ea41SRandall Stewart } 1589f42a358aSRandall Stewart protocol_id = ch->dp.protocol_id; 1590f42a358aSRandall Stewart ordered = ((ch->ch.chunk_flags & SCTP_DATA_UNORDERED) == 0); 1591b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 1592c4739e2fSRandall Stewart sctp_log_map(tsn, asoc->cumulative_tsn, asoc->highest_tsn_inside_map, SCTP_MAP_TSN_ENTERS); 159380fefe0aSRandall Stewart } 1594ad81507eSRandall Stewart if (stcb == NULL) { 1595ad81507eSRandall Stewart return (0); 1596ad81507eSRandall Stewart } 159780fefe0aSRandall Stewart SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, ch->ch.chunk_type, tsn); 1598f8829a4aSRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, tsn, MAX_TSN) || 1599f8829a4aSRandall Stewart asoc->cumulative_tsn == tsn) { 1600f8829a4aSRandall Stewart /* It is a duplicate */ 1601f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1602f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1603f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1604f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1605f8829a4aSRandall Stewart asoc->numduptsns++; 1606f8829a4aSRandall Stewart } 1607b201f536SRandall Stewart asoc->send_sack = 1; 1608f8829a4aSRandall Stewart return (0); 1609f8829a4aSRandall Stewart } 1610f8829a4aSRandall Stewart /* Calculate the number of TSN's between the base and this TSN */ 1611f8829a4aSRandall Stewart if (tsn >= asoc->mapping_array_base_tsn) { 1612f8829a4aSRandall Stewart gap = tsn - asoc->mapping_array_base_tsn; 1613f8829a4aSRandall Stewart } else { 1614f8829a4aSRandall Stewart gap = (MAX_TSN - asoc->mapping_array_base_tsn) + tsn + 1; 1615f8829a4aSRandall Stewart } 1616f8829a4aSRandall Stewart if (gap >= (SCTP_MAPPING_ARRAY << 3)) { 1617f8829a4aSRandall Stewart /* Can't hold the bit in the mapping at max array, toss it */ 1618f8829a4aSRandall Stewart return (0); 1619f8829a4aSRandall Stewart } 1620f8829a4aSRandall Stewart if (gap >= (uint32_t) (asoc->mapping_array_size << 3)) { 1621207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 16220696e120SRandall Stewart if (sctp_expand_mapping_array(asoc, gap)) { 1623f8829a4aSRandall Stewart /* Can't expand, drop it */ 1624f8829a4aSRandall Stewart return (0); 1625f8829a4aSRandall Stewart } 1626f8829a4aSRandall Stewart } 1627830d754dSRandall Stewart /* EY - for nr_sack */ 1628830d754dSRandall Stewart nr_gap = gap; 1629830d754dSRandall Stewart 1630f8829a4aSRandall Stewart if (compare_with_wrap(tsn, *high_tsn, MAX_TSN)) { 1631f8829a4aSRandall Stewart *high_tsn = tsn; 1632f8829a4aSRandall Stewart } 1633f8829a4aSRandall Stewart /* See if we have received this one already */ 1634f8829a4aSRandall Stewart if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) { 1635f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1636f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1637f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1638f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1639f8829a4aSRandall Stewart asoc->numduptsns++; 1640f8829a4aSRandall Stewart } 164142551e99SRandall Stewart asoc->send_sack = 1; 1642f8829a4aSRandall Stewart return (0); 1643f8829a4aSRandall Stewart } 1644f8829a4aSRandall Stewart /* 1645f8829a4aSRandall Stewart * Check to see about the GONE flag, duplicates would cause a sack 1646f8829a4aSRandall Stewart * to be sent up above 1647f8829a4aSRandall Stewart */ 1648ad81507eSRandall Stewart if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || 1649f8829a4aSRandall Stewart (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || 1650f8829a4aSRandall Stewart (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) 1651f8829a4aSRandall Stewart ) { 1652f8829a4aSRandall Stewart /* 1653f8829a4aSRandall Stewart * wait a minute, this guy is gone, there is no longer a 1654f8829a4aSRandall Stewart * receiver. Send peer an ABORT! 1655f8829a4aSRandall Stewart */ 1656f8829a4aSRandall Stewart struct mbuf *op_err; 1657f8829a4aSRandall Stewart 1658f8829a4aSRandall Stewart op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC); 1659ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 0, op_err, SCTP_SO_NOT_LOCKED); 1660f8829a4aSRandall Stewart *abort_flag = 1; 1661f8829a4aSRandall Stewart return (0); 1662f8829a4aSRandall Stewart } 1663f8829a4aSRandall Stewart /* 1664f8829a4aSRandall Stewart * Now before going further we see if there is room. If NOT then we 1665f8829a4aSRandall Stewart * MAY let one through only IF this TSN is the one we are waiting 1666f8829a4aSRandall Stewart * for on a partial delivery API. 1667f8829a4aSRandall Stewart */ 1668f8829a4aSRandall Stewart 1669f8829a4aSRandall Stewart /* now do the tests */ 1670f8829a4aSRandall Stewart if (((asoc->cnt_on_all_streams + 1671f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue + 1672b3f1ea41SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) || 1673f8829a4aSRandall Stewart (((int)asoc->my_rwnd) <= 0)) { 1674f8829a4aSRandall Stewart /* 1675f8829a4aSRandall Stewart * When we have NO room in the rwnd we check to make sure 1676f8829a4aSRandall Stewart * the reader is doing its job... 1677f8829a4aSRandall Stewart */ 1678f8829a4aSRandall Stewart if (stcb->sctp_socket->so_rcv.sb_cc) { 1679f8829a4aSRandall Stewart /* some to read, wake-up */ 1680ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 1681ceaad40aSRandall Stewart struct socket *so; 1682ceaad40aSRandall Stewart 1683ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 1684ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 1685ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 1686ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 1687ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 1688ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 1689ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 1690ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 1691ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 1692ceaad40aSRandall Stewart return (0); 1693ceaad40aSRandall Stewart } 1694ceaad40aSRandall Stewart #endif 1695f8829a4aSRandall Stewart sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket); 1696ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 1697ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 1698ceaad40aSRandall Stewart #endif 1699f8829a4aSRandall Stewart } 1700f8829a4aSRandall Stewart /* now is it in the mapping array of what we have accepted? */ 1701b3f1ea41SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) { 1702f8829a4aSRandall Stewart /* Nope not in the valid range dump it */ 1703f8829a4aSRandall Stewart sctp_set_rwnd(stcb, asoc); 1704f8829a4aSRandall Stewart if ((asoc->cnt_on_all_streams + 1705f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue + 1706b3f1ea41SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) { 1707f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_datadropchklmt); 1708f8829a4aSRandall Stewart } else { 1709f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_datadroprwnd); 1710f8829a4aSRandall Stewart } 1711f8829a4aSRandall Stewart indx = *break_flag; 1712f8829a4aSRandall Stewart *break_flag = 1; 1713f8829a4aSRandall Stewart return (0); 1714f8829a4aSRandall Stewart } 1715f8829a4aSRandall Stewart } 1716f8829a4aSRandall Stewart strmno = ntohs(ch->dp.stream_id); 1717f8829a4aSRandall Stewart if (strmno >= asoc->streamincnt) { 1718f8829a4aSRandall Stewart struct sctp_paramhdr *phdr; 1719f8829a4aSRandall Stewart struct mbuf *mb; 1720f8829a4aSRandall Stewart 1721f8829a4aSRandall Stewart mb = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) * 2), 1722139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1723f8829a4aSRandall Stewart if (mb != NULL) { 1724f8829a4aSRandall Stewart /* add some space up front so prepend will work well */ 1725139bc87fSRandall Stewart SCTP_BUF_RESV_UF(mb, sizeof(struct sctp_chunkhdr)); 1726f8829a4aSRandall Stewart phdr = mtod(mb, struct sctp_paramhdr *); 1727f8829a4aSRandall Stewart /* 1728f8829a4aSRandall Stewart * Error causes are just param's and this one has 1729f8829a4aSRandall Stewart * two back to back phdr, one with the error type 1730f8829a4aSRandall Stewart * and size, the other with the streamid and a rsvd 1731f8829a4aSRandall Stewart */ 1732139bc87fSRandall Stewart SCTP_BUF_LEN(mb) = (sizeof(struct sctp_paramhdr) * 2); 1733f8829a4aSRandall Stewart phdr->param_type = htons(SCTP_CAUSE_INVALID_STREAM); 1734f8829a4aSRandall Stewart phdr->param_length = 1735f8829a4aSRandall Stewart htons(sizeof(struct sctp_paramhdr) * 2); 1736f8829a4aSRandall Stewart phdr++; 1737f8829a4aSRandall Stewart /* We insert the stream in the type field */ 1738f8829a4aSRandall Stewart phdr->param_type = ch->dp.stream_id; 1739f8829a4aSRandall Stewart /* And set the length to 0 for the rsvd field */ 1740f8829a4aSRandall Stewart phdr->param_length = 0; 1741f8829a4aSRandall Stewart sctp_queue_op_err(stcb, mb); 1742f8829a4aSRandall Stewart } 1743f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_badsid); 1744207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1745d06c82f1SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap); 1746830d754dSRandall Stewart /* EY set this tsn present in nr_sack's nr_mapping_array */ 1747830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 1748830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1749830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 1750830d754dSRandall Stewart } 1751d06c82f1SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) { 1752d06c82f1SRandall Stewart /* we have a new high score */ 1753d06c82f1SRandall Stewart asoc->highest_tsn_inside_map = tsn; 1754830d754dSRandall Stewart /* EY nr_sack version of the above */ 1755830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) 1756830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 1757b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 1758d06c82f1SRandall Stewart sctp_log_map(0, 2, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 175980fefe0aSRandall Stewart } 1760d06c82f1SRandall Stewart } 1761d06c82f1SRandall Stewart if (tsn == (asoc->cumulative_tsn + 1)) { 1762d06c82f1SRandall Stewart /* Update cum-ack */ 1763d06c82f1SRandall Stewart asoc->cumulative_tsn = tsn; 1764d06c82f1SRandall Stewart } 1765f8829a4aSRandall Stewart return (0); 1766f8829a4aSRandall Stewart } 1767f8829a4aSRandall Stewart /* 1768f8829a4aSRandall Stewart * Before we continue lets validate that we are not being fooled by 1769f8829a4aSRandall Stewart * an evil attacker. We can only have 4k chunks based on our TSN 1770f8829a4aSRandall Stewart * spread allowed by the mapping array 512 * 8 bits, so there is no 1771f8829a4aSRandall Stewart * way our stream sequence numbers could have wrapped. We of course 1772f8829a4aSRandall Stewart * only validate the FIRST fragment so the bit must be set. 1773f8829a4aSRandall Stewart */ 1774f8829a4aSRandall Stewart strmseq = ntohs(ch->dp.stream_sequence); 1775f42a358aSRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 177618e198d3SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 177718e198d3SRandall Stewart if (asoc->tsn_in_at >= SCTP_TSN_LOG_SIZE) { 177818e198d3SRandall Stewart asoc->tsn_in_at = 0; 177918e198d3SRandall Stewart asoc->tsn_in_wrapped = 1; 178018e198d3SRandall Stewart } 1781f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].tsn = tsn; 1782f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].strm = strmno; 1783f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].seq = strmseq; 1784f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].sz = chk_length; 1785f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].flgs = chunk_flags; 178618e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].stcb = (void *)stcb; 178718e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_pos = asoc->tsn_in_at; 178818e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_out = 1; 1789f42a358aSRandall Stewart asoc->tsn_in_at++; 1790f42a358aSRandall Stewart #endif 1791f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_FIRST_FRAG) && 1792d61a0ae0SRandall Stewart (TAILQ_EMPTY(&asoc->resetHead)) && 1793f42a358aSRandall Stewart (chunk_flags & SCTP_DATA_UNORDERED) == 0 && 1794f8829a4aSRandall Stewart (compare_with_wrap(asoc->strmin[strmno].last_sequence_delivered, 1795f8829a4aSRandall Stewart strmseq, MAX_SEQ) || 1796f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered == strmseq)) { 1797f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 1798ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ:%d delivered:%d from peer, Abort!\n", 1799ad81507eSRandall Stewart strmseq, asoc->strmin[strmno].last_sequence_delivered); 1800139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1801f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1802f8829a4aSRandall Stewart if (oper) { 1803f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1804f8829a4aSRandall Stewart uint32_t *ippp; 1805f8829a4aSRandall Stewart 1806139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 1807f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1808f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 1809f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1810139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 1811f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1812a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_14); 1813f8829a4aSRandall Stewart ippp++; 1814f8829a4aSRandall Stewart *ippp = tsn; 1815f8829a4aSRandall Stewart ippp++; 1816f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 1817f8829a4aSRandall Stewart 1818f8829a4aSRandall Stewart } 1819a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_14; 1820f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1821ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1822f8829a4aSRandall Stewart *abort_flag = 1; 1823f8829a4aSRandall Stewart return (0); 1824f8829a4aSRandall Stewart } 1825f42a358aSRandall Stewart /************************************ 1826f42a358aSRandall Stewart * From here down we may find ch-> invalid 1827f42a358aSRandall Stewart * so its a good idea NOT to use it. 1828f42a358aSRandall Stewart *************************************/ 1829f42a358aSRandall Stewart 1830f8829a4aSRandall Stewart the_len = (chk_length - sizeof(struct sctp_data_chunk)); 1831f8829a4aSRandall Stewart if (last_chunk == 0) { 183244b7479bSRandall Stewart dmbuf = SCTP_M_COPYM(*m, 1833f8829a4aSRandall Stewart (offset + sizeof(struct sctp_data_chunk)), 1834f8829a4aSRandall Stewart the_len, M_DONTWAIT); 1835f8829a4aSRandall Stewart #ifdef SCTP_MBUF_LOGGING 1836b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { 1837f8829a4aSRandall Stewart struct mbuf *mat; 1838f8829a4aSRandall Stewart 1839f8829a4aSRandall Stewart mat = dmbuf; 1840f8829a4aSRandall Stewart while (mat) { 1841139bc87fSRandall Stewart if (SCTP_BUF_IS_EXTENDED(mat)) { 1842f8829a4aSRandall Stewart sctp_log_mb(mat, SCTP_MBUF_ICOPY); 1843f8829a4aSRandall Stewart } 1844139bc87fSRandall Stewart mat = SCTP_BUF_NEXT(mat); 1845f8829a4aSRandall Stewart } 1846f8829a4aSRandall Stewart } 1847f8829a4aSRandall Stewart #endif 1848f8829a4aSRandall Stewart } else { 1849f8829a4aSRandall Stewart /* We can steal the last chunk */ 1850139bc87fSRandall Stewart int l_len; 1851139bc87fSRandall Stewart 1852f8829a4aSRandall Stewart dmbuf = *m; 1853f8829a4aSRandall Stewart /* lop off the top part */ 1854f8829a4aSRandall Stewart m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk))); 1855139bc87fSRandall Stewart if (SCTP_BUF_NEXT(dmbuf) == NULL) { 1856139bc87fSRandall Stewart l_len = SCTP_BUF_LEN(dmbuf); 1857139bc87fSRandall Stewart } else { 1858139bc87fSRandall Stewart /* 1859139bc87fSRandall Stewart * need to count up the size hopefully does not hit 1860139bc87fSRandall Stewart * this to often :-0 1861139bc87fSRandall Stewart */ 1862139bc87fSRandall Stewart struct mbuf *lat; 1863139bc87fSRandall Stewart 1864139bc87fSRandall Stewart l_len = 0; 1865139bc87fSRandall Stewart lat = dmbuf; 1866139bc87fSRandall Stewart while (lat) { 1867139bc87fSRandall Stewart l_len += SCTP_BUF_LEN(lat); 1868139bc87fSRandall Stewart lat = SCTP_BUF_NEXT(lat); 1869139bc87fSRandall Stewart } 1870139bc87fSRandall Stewart } 1871139bc87fSRandall Stewart if (l_len > the_len) { 1872f8829a4aSRandall Stewart /* Trim the end round bytes off too */ 1873139bc87fSRandall Stewart m_adj(dmbuf, -(l_len - the_len)); 1874f8829a4aSRandall Stewart } 1875f8829a4aSRandall Stewart } 1876f8829a4aSRandall Stewart if (dmbuf == NULL) { 1877f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1878f8829a4aSRandall Stewart return (0); 1879f8829a4aSRandall Stewart } 1880f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG && 1881f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress == 0 && 1882f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->resetHead) && 1883f42a358aSRandall Stewart ((ordered == 0) || 1884f8829a4aSRandall Stewart ((asoc->strmin[strmno].last_sequence_delivered + 1) == strmseq && 1885f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->strmin[strmno].inqueue)))) { 1886f8829a4aSRandall Stewart /* Candidate for express delivery */ 1887f8829a4aSRandall Stewart /* 1888f8829a4aSRandall Stewart * Its not fragmented, No PD-API is up, Nothing in the 1889f8829a4aSRandall Stewart * delivery queue, Its un-ordered OR ordered and the next to 1890f8829a4aSRandall Stewart * deliver AND nothing else is stuck on the stream queue, 1891f8829a4aSRandall Stewart * And there is room for it in the socket buffer. Lets just 1892f8829a4aSRandall Stewart * stuff it up the buffer.... 1893f8829a4aSRandall Stewart */ 1894f8829a4aSRandall Stewart 1895f8829a4aSRandall Stewart /* It would be nice to avoid this copy if we could :< */ 1896f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, control); 1897f8829a4aSRandall Stewart sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, 1898f42a358aSRandall Stewart protocol_id, 1899f8829a4aSRandall Stewart stcb->asoc.context, 1900f8829a4aSRandall Stewart strmno, strmseq, 1901f42a358aSRandall Stewart chunk_flags, 1902f8829a4aSRandall Stewart dmbuf); 1903f8829a4aSRandall Stewart if (control == NULL) { 1904f8829a4aSRandall Stewart goto failed_express_del; 1905f8829a4aSRandall Stewart } 1906ceaad40aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, control, &stcb->sctp_socket->so_rcv, 1, SCTP_SO_NOT_LOCKED); 1907830d754dSRandall Stewart 1908830d754dSRandall Stewart /* 1909830d754dSRandall Stewart * EY here I should check if this delivered tsn is 1910830d754dSRandall Stewart * out_of_order, if yes then update the nr_map 1911830d754dSRandall Stewart */ 1912830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 1913830d754dSRandall Stewart /* 1914830d754dSRandall Stewart * EY check if the mapping_array and nr_mapping 1915830d754dSRandall Stewart * array are consistent 1916830d754dSRandall Stewart */ 1917830d754dSRandall Stewart if (asoc->mapping_array_base_tsn != asoc->nr_mapping_array_base_tsn) 1918830d754dSRandall Stewart /* 1919830d754dSRandall Stewart * printf("EY-IN 1920830d754dSRandall Stewart * sctp_process_a_data_chunk(5): Something 1921830d754dSRandall Stewart * is wrong the map base tsn" "\nEY-and 1922830d754dSRandall Stewart * nr_map base tsn should be equal."); 1923830d754dSRandall Stewart */ 1924830d754dSRandall Stewart /* EY debugging block */ 1925830d754dSRandall Stewart { 1926830d754dSRandall Stewart /* 1927830d754dSRandall Stewart * printf("\nEY-Calculating an 1928830d754dSRandall Stewart * nr_gap!!\nmapping_array_size = %d 1929830d754dSRandall Stewart * nr_mapping_array_size = %d" 1930830d754dSRandall Stewart * "\nEY-mapping_array_base = %d 1931830d754dSRandall Stewart * nr_mapping_array_base = 1932830d754dSRandall Stewart * %d\nEY-highest_tsn_inside_map = %d" 1933830d754dSRandall Stewart * "highest_tsn_inside_nr_map = %d\nEY-TSN = 1934830d754dSRandall Stewart * %d nr_gap = %d",asoc->mapping_array_size, 1935830d754dSRandall Stewart * asoc->nr_mapping_array_size, 1936830d754dSRandall Stewart * asoc->mapping_array_base_tsn, 1937830d754dSRandall Stewart * asoc->nr_mapping_array_base_tsn, 1938830d754dSRandall Stewart * asoc->highest_tsn_inside_map, 1939830d754dSRandall Stewart * asoc->highest_tsn_inside_nr_map,tsn,nr_gap 1940830d754dSRandall Stewart * ); 1941830d754dSRandall Stewart */ 1942830d754dSRandall Stewart } 1943830d754dSRandall Stewart /* EY - not %100 sure about the lock thing */ 1944830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1945830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap); 1946830d754dSRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) 1947830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 1948830d754dSRandall Stewart } 1949f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { 1950f8829a4aSRandall Stewart /* for ordered, bump what we delivered */ 1951f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered++; 1952f8829a4aSRandall Stewart } 1953f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvexpress); 1954b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 19556a91f103SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, 1956f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_EXPRS_DEL); 195780fefe0aSRandall Stewart } 1958f8829a4aSRandall Stewart control = NULL; 1959f8829a4aSRandall Stewart goto finish_express_del; 1960f8829a4aSRandall Stewart } 1961f8829a4aSRandall Stewart failed_express_del: 1962f8829a4aSRandall Stewart /* If we reach here this is a new chunk */ 1963f8829a4aSRandall Stewart chk = NULL; 1964f8829a4aSRandall Stewart control = NULL; 1965f8829a4aSRandall Stewart /* Express for fragmented delivery? */ 1966f8829a4aSRandall Stewart if ((asoc->fragmented_delivery_inprogress) && 1967f8829a4aSRandall Stewart (stcb->asoc.control_pdapi) && 1968f8829a4aSRandall Stewart (asoc->str_of_pdapi == strmno) && 1969f8829a4aSRandall Stewart (asoc->ssn_of_pdapi == strmseq) 1970f8829a4aSRandall Stewart ) { 1971f8829a4aSRandall Stewart control = stcb->asoc.control_pdapi; 1972f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) { 1973f8829a4aSRandall Stewart /* Can't be another first? */ 1974f8829a4aSRandall Stewart goto failed_pdapi_express_del; 1975f8829a4aSRandall Stewart } 1976f8829a4aSRandall Stewart if (tsn == (control->sinfo_tsn + 1)) { 1977f8829a4aSRandall Stewart /* Yep, we can add it on */ 1978f8829a4aSRandall Stewart int end = 0; 1979f8829a4aSRandall Stewart uint32_t cumack; 1980f8829a4aSRandall Stewart 1981f42a358aSRandall Stewart if (chunk_flags & SCTP_DATA_LAST_FRAG) { 1982f8829a4aSRandall Stewart end = 1; 1983f8829a4aSRandall Stewart } 1984f8829a4aSRandall Stewart cumack = asoc->cumulative_tsn; 1985f8829a4aSRandall Stewart if ((cumack + 1) == tsn) 1986f8829a4aSRandall Stewart cumack = tsn; 1987f8829a4aSRandall Stewart 1988f8829a4aSRandall Stewart if (sctp_append_to_readq(stcb->sctp_ep, stcb, control, dmbuf, end, 1989f8829a4aSRandall Stewart tsn, 1990f8829a4aSRandall Stewart &stcb->sctp_socket->so_rcv)) { 1991ad81507eSRandall Stewart SCTP_PRINTF("Append fails end:%d\n", end); 1992f8829a4aSRandall Stewart goto failed_pdapi_express_del; 1993f8829a4aSRandall Stewart } 1994830d754dSRandall Stewart /* 1995830d754dSRandall Stewart * EY It is appended to the read queue in prev if 1996830d754dSRandall Stewart * block here I should check if this delivered tsn 1997830d754dSRandall Stewart * is out_of_order, if yes then update the nr_map 1998830d754dSRandall Stewart */ 1999830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 2000830d754dSRandall Stewart /* EY debugging block */ 2001830d754dSRandall Stewart { 2002830d754dSRandall Stewart /* 2003830d754dSRandall Stewart * printf("\nEY-Calculating an 2004830d754dSRandall Stewart * nr_gap!!\nEY-mapping_array_size = 2005830d754dSRandall Stewart * %d nr_mapping_array_size = %d" 2006830d754dSRandall Stewart * "\nEY-mapping_array_base = %d 2007830d754dSRandall Stewart * nr_mapping_array_base = 2008830d754dSRandall Stewart * %d\nEY-highest_tsn_inside_map = 2009830d754dSRandall Stewart * %d" "highest_tsn_inside_nr_map = 2010830d754dSRandall Stewart * %d\nEY-TSN = %d nr_gap = 2011830d754dSRandall Stewart * %d",asoc->mapping_array_size, 2012830d754dSRandall Stewart * asoc->nr_mapping_array_size, 2013830d754dSRandall Stewart * asoc->mapping_array_base_tsn, 2014830d754dSRandall Stewart * asoc->nr_mapping_array_base_tsn, 2015830d754dSRandall Stewart * asoc->highest_tsn_inside_map, 2016830d754dSRandall Stewart * asoc->highest_tsn_inside_nr_map,ts 2017830d754dSRandall Stewart * n,nr_gap); 2018830d754dSRandall Stewart */ 2019830d754dSRandall Stewart } 2020830d754dSRandall Stewart /* EY - not %100 sure about the lock thing */ 2021830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 2022830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap); 2023830d754dSRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) 2024830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 2025830d754dSRandall Stewart } 2026f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvexpressm); 2027f8829a4aSRandall Stewart control->sinfo_tsn = tsn; 2028f8829a4aSRandall Stewart asoc->tsn_last_delivered = tsn; 2029f42a358aSRandall Stewart asoc->fragment_flags = chunk_flags; 2030f8829a4aSRandall Stewart asoc->tsn_of_pdapi_last_delivered = tsn; 2031f42a358aSRandall Stewart asoc->last_flags_delivered = chunk_flags; 2032f8829a4aSRandall Stewart asoc->last_strm_seq_delivered = strmseq; 2033f8829a4aSRandall Stewart asoc->last_strm_no_delivered = strmno; 2034f8829a4aSRandall Stewart if (end) { 2035f8829a4aSRandall Stewart /* clean up the flags and such */ 2036f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 2037f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { 2038f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered++; 2039a5d547adSRandall Stewart } 2040f8829a4aSRandall Stewart stcb->asoc.control_pdapi = NULL; 2041139bc87fSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue) == 0) { 2042139bc87fSRandall Stewart /* 2043139bc87fSRandall Stewart * There could be another message 2044139bc87fSRandall Stewart * ready 2045139bc87fSRandall Stewart */ 2046139bc87fSRandall Stewart need_reasm_check = 1; 2047139bc87fSRandall Stewart } 2048f8829a4aSRandall Stewart } 2049f8829a4aSRandall Stewart control = NULL; 2050f8829a4aSRandall Stewart goto finish_express_del; 2051f8829a4aSRandall Stewart } 2052f8829a4aSRandall Stewart } 2053f8829a4aSRandall Stewart failed_pdapi_express_del: 2054f8829a4aSRandall Stewart control = NULL; 2055f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { 2056f8829a4aSRandall Stewart sctp_alloc_a_chunk(stcb, chk); 2057f8829a4aSRandall Stewart if (chk == NULL) { 2058f8829a4aSRandall Stewart /* No memory so we drop the chunk */ 2059f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 2060f8829a4aSRandall Stewart if (last_chunk == 0) { 2061f8829a4aSRandall Stewart /* we copied it, free the copy */ 2062f8829a4aSRandall Stewart sctp_m_freem(dmbuf); 2063f8829a4aSRandall Stewart } 2064f8829a4aSRandall Stewart return (0); 2065f8829a4aSRandall Stewart } 2066f8829a4aSRandall Stewart chk->rec.data.TSN_seq = tsn; 2067f8829a4aSRandall Stewart chk->no_fr_allowed = 0; 2068f8829a4aSRandall Stewart chk->rec.data.stream_seq = strmseq; 2069f8829a4aSRandall Stewart chk->rec.data.stream_number = strmno; 2070f42a358aSRandall Stewart chk->rec.data.payloadtype = protocol_id; 2071f8829a4aSRandall Stewart chk->rec.data.context = stcb->asoc.context; 2072f8829a4aSRandall Stewart chk->rec.data.doing_fast_retransmit = 0; 2073f42a358aSRandall Stewart chk->rec.data.rcv_flags = chunk_flags; 2074f8829a4aSRandall Stewart chk->asoc = asoc; 2075f8829a4aSRandall Stewart chk->send_size = the_len; 2076f8829a4aSRandall Stewart chk->whoTo = net; 2077f8829a4aSRandall Stewart atomic_add_int(&net->ref_count, 1); 2078f8829a4aSRandall Stewart chk->data = dmbuf; 2079f8829a4aSRandall Stewart } else { 2080f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, control); 2081f8829a4aSRandall Stewart sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, 2082f42a358aSRandall Stewart protocol_id, 2083f8829a4aSRandall Stewart stcb->asoc.context, 2084f8829a4aSRandall Stewart strmno, strmseq, 2085f42a358aSRandall Stewart chunk_flags, 2086f8829a4aSRandall Stewart dmbuf); 2087f8829a4aSRandall Stewart if (control == NULL) { 2088f8829a4aSRandall Stewart /* No memory so we drop the chunk */ 2089f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 2090f8829a4aSRandall Stewart if (last_chunk == 0) { 2091f8829a4aSRandall Stewart /* we copied it, free the copy */ 2092f8829a4aSRandall Stewart sctp_m_freem(dmbuf); 2093f8829a4aSRandall Stewart } 2094f8829a4aSRandall Stewart return (0); 2095f8829a4aSRandall Stewart } 2096f8829a4aSRandall Stewart control->length = the_len; 2097f8829a4aSRandall Stewart } 2098f8829a4aSRandall Stewart 2099f8829a4aSRandall Stewart /* Mark it as received */ 2100f8829a4aSRandall Stewart /* Now queue it where it belongs */ 2101f8829a4aSRandall Stewart if (control != NULL) { 2102f8829a4aSRandall Stewart /* First a sanity check */ 2103f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 2104f8829a4aSRandall Stewart /* 2105f8829a4aSRandall Stewart * Ok, we have a fragmented delivery in progress if 2106f8829a4aSRandall Stewart * this chunk is next to deliver OR belongs in our 2107f8829a4aSRandall Stewart * view to the reassembly, the peer is evil or 2108f8829a4aSRandall Stewart * broken. 2109f8829a4aSRandall Stewart */ 2110f8829a4aSRandall Stewart uint32_t estimate_tsn; 2111f8829a4aSRandall Stewart 2112f8829a4aSRandall Stewart estimate_tsn = asoc->tsn_last_delivered + 1; 2113f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue) && 2114f8829a4aSRandall Stewart (estimate_tsn == control->sinfo_tsn)) { 2115f8829a4aSRandall Stewart /* Evil/Broke peer */ 2116f8829a4aSRandall Stewart sctp_m_freem(control->data); 2117f8829a4aSRandall Stewart control->data = NULL; 21185bead436SRandall Stewart if (control->whoFrom) { 2119f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 21205bead436SRandall Stewart control->whoFrom = NULL; 21215bead436SRandall Stewart } 2122f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 2123139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 2124f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 2125f8829a4aSRandall Stewart if (oper) { 2126f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 2127f8829a4aSRandall Stewart uint32_t *ippp; 2128f8829a4aSRandall Stewart 2129139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 2130f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 2131f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 2132f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 2133f8829a4aSRandall Stewart ph->param_type = 2134f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 2135139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 2136f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 2137a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_15); 2138f8829a4aSRandall Stewart ippp++; 2139f8829a4aSRandall Stewart *ippp = tsn; 2140f8829a4aSRandall Stewart ippp++; 2141f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 2142f8829a4aSRandall Stewart } 2143a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_15; 2144f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 2145ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 2146f8829a4aSRandall Stewart 2147f8829a4aSRandall Stewart *abort_flag = 1; 2148f8829a4aSRandall Stewart return (0); 2149f8829a4aSRandall Stewart } else { 2150f8829a4aSRandall Stewart if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) { 2151f8829a4aSRandall Stewart sctp_m_freem(control->data); 2152f8829a4aSRandall Stewart control->data = NULL; 21535bead436SRandall Stewart if (control->whoFrom) { 2154f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 21555bead436SRandall Stewart control->whoFrom = NULL; 21565bead436SRandall Stewart } 2157f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 2158f8829a4aSRandall Stewart 2159139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 2160f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 2161f8829a4aSRandall Stewart if (oper) { 2162f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 2163f8829a4aSRandall Stewart uint32_t *ippp; 2164f8829a4aSRandall Stewart 2165139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 2166f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 2167f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 2168f8829a4aSRandall Stewart ph = mtod(oper, 2169f8829a4aSRandall Stewart struct sctp_paramhdr *); 2170f8829a4aSRandall Stewart ph->param_type = 2171f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 2172f8829a4aSRandall Stewart ph->param_length = 2173139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 2174f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 2175a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_16); 2176f8829a4aSRandall Stewart ippp++; 2177f8829a4aSRandall Stewart *ippp = tsn; 2178f8829a4aSRandall Stewart ippp++; 2179f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 2180f8829a4aSRandall Stewart } 2181a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16; 2182f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 2183ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 2184f8829a4aSRandall Stewart 2185f8829a4aSRandall Stewart *abort_flag = 1; 2186f8829a4aSRandall Stewart return (0); 2187f8829a4aSRandall Stewart } 2188f8829a4aSRandall Stewart } 2189f8829a4aSRandall Stewart } else { 2190f8829a4aSRandall Stewart /* No PDAPI running */ 2191f8829a4aSRandall Stewart if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 2192f8829a4aSRandall Stewart /* 2193f8829a4aSRandall Stewart * Reassembly queue is NOT empty validate 2194f8829a4aSRandall Stewart * that this tsn does not need to be in 2195f8829a4aSRandall Stewart * reasembly queue. If it does then our peer 2196f8829a4aSRandall Stewart * is broken or evil. 2197f8829a4aSRandall Stewart */ 2198f8829a4aSRandall Stewart if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) { 2199f8829a4aSRandall Stewart sctp_m_freem(control->data); 2200f8829a4aSRandall Stewart control->data = NULL; 22015bead436SRandall Stewart if (control->whoFrom) { 2202f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 22035bead436SRandall Stewart control->whoFrom = NULL; 22045bead436SRandall Stewart } 2205f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 2206139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 2207f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 2208f8829a4aSRandall Stewart if (oper) { 2209f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 2210f8829a4aSRandall Stewart uint32_t *ippp; 2211f8829a4aSRandall Stewart 2212139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 2213f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 2214f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 2215f8829a4aSRandall Stewart ph = mtod(oper, 2216f8829a4aSRandall Stewart struct sctp_paramhdr *); 2217f8829a4aSRandall Stewart ph->param_type = 2218f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 2219f8829a4aSRandall Stewart ph->param_length = 2220139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 2221f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 2222a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_17); 2223f8829a4aSRandall Stewart ippp++; 2224f8829a4aSRandall Stewart *ippp = tsn; 2225f8829a4aSRandall Stewart ippp++; 2226f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 2227f8829a4aSRandall Stewart } 2228a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_17; 2229f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 2230ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 2231f8829a4aSRandall Stewart 2232f8829a4aSRandall Stewart *abort_flag = 1; 2233f8829a4aSRandall Stewart return (0); 2234f8829a4aSRandall Stewart } 2235f8829a4aSRandall Stewart } 2236f8829a4aSRandall Stewart } 2237f8829a4aSRandall Stewart /* ok, if we reach here we have passed the sanity checks */ 2238f42a358aSRandall Stewart if (chunk_flags & SCTP_DATA_UNORDERED) { 2239f8829a4aSRandall Stewart /* queue directly into socket buffer */ 2240f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 2241f8829a4aSRandall Stewart control, 2242ceaad40aSRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_SO_NOT_LOCKED); 2243830d754dSRandall Stewart 2244830d754dSRandall Stewart /* 2245830d754dSRandall Stewart * EY It is added to the read queue in prev if block 2246830d754dSRandall Stewart * here I should check if this delivered tsn is 2247830d754dSRandall Stewart * out_of_order, if yes then update the nr_map 2248830d754dSRandall Stewart */ 2249830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 2250830d754dSRandall Stewart /* 2251830d754dSRandall Stewart * EY check if the mapping_array and 2252830d754dSRandall Stewart * nr_mapping array are consistent 2253830d754dSRandall Stewart */ 2254830d754dSRandall Stewart if (asoc->mapping_array_base_tsn != asoc->nr_mapping_array_base_tsn) 2255830d754dSRandall Stewart /* 2256830d754dSRandall Stewart * printf("EY-IN 2257830d754dSRandall Stewart * sctp_process_a_data_chunk(6): 2258830d754dSRandall Stewart * Something is wrong the map base 2259830d754dSRandall Stewart * tsn" "\nEY-and nr_map base tsn 2260830d754dSRandall Stewart * should be equal."); 2261830d754dSRandall Stewart */ 2262830d754dSRandall Stewart /* 2263830d754dSRandall Stewart * EY - not %100 sure about the lock 2264830d754dSRandall Stewart * thing, i think we don't need the 2265830d754dSRandall Stewart * below, 2266830d754dSRandall Stewart */ 2267830d754dSRandall Stewart /* SCTP_TCB_LOCK_ASSERT(stcb); */ 2268830d754dSRandall Stewart { 2269830d754dSRandall Stewart /* 2270830d754dSRandall Stewart * printf("\nEY-Calculating an 2271830d754dSRandall Stewart * nr_gap!!\nEY-mapping_array_size = 2272830d754dSRandall Stewart * %d nr_mapping_array_size = %d" 2273830d754dSRandall Stewart * "\nEY-mapping_array_base = %d 2274830d754dSRandall Stewart * nr_mapping_array_base = 2275830d754dSRandall Stewart * %d\nEY-highest_tsn_inside_map = 2276830d754dSRandall Stewart * %d" "highest_tsn_inside_nr_map = 2277830d754dSRandall Stewart * %d\nEY-TSN = %d nr_gap = 2278830d754dSRandall Stewart * %d",asoc->mapping_array_size, 2279830d754dSRandall Stewart * asoc->nr_mapping_array_size, 2280830d754dSRandall Stewart * asoc->mapping_array_base_tsn, 2281830d754dSRandall Stewart * asoc->nr_mapping_array_base_tsn, 2282830d754dSRandall Stewart * asoc->highest_tsn_inside_map, 2283830d754dSRandall Stewart * asoc->highest_tsn_inside_nr_map,ts 2284830d754dSRandall Stewart * n,nr_gap); 2285830d754dSRandall Stewart */ 2286830d754dSRandall Stewart } 2287830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 2288830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap); 2289830d754dSRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) 2290830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 2291830d754dSRandall Stewart } 2292f8829a4aSRandall Stewart } else { 2293f8829a4aSRandall Stewart /* 2294f8829a4aSRandall Stewart * Special check for when streams are resetting. We 2295f8829a4aSRandall Stewart * could be more smart about this and check the 2296f8829a4aSRandall Stewart * actual stream to see if it is not being reset.. 2297f8829a4aSRandall Stewart * that way we would not create a HOLB when amongst 2298f8829a4aSRandall Stewart * streams being reset and those not being reset. 2299f8829a4aSRandall Stewart * 2300f8829a4aSRandall Stewart * We take complete messages that have a stream reset 2301f8829a4aSRandall Stewart * intervening (aka the TSN is after where our 2302f8829a4aSRandall Stewart * cum-ack needs to be) off and put them on a 2303f8829a4aSRandall Stewart * pending_reply_queue. The reassembly ones we do 2304f8829a4aSRandall Stewart * not have to worry about since they are all sorted 2305f8829a4aSRandall Stewart * and proceessed by TSN order. It is only the 2306f8829a4aSRandall Stewart * singletons I must worry about. 2307f8829a4aSRandall Stewart */ 2308f8829a4aSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 2309d61a0ae0SRandall Stewart ((compare_with_wrap(tsn, liste->tsn, MAX_TSN))) 2310f8829a4aSRandall Stewart ) { 2311f8829a4aSRandall Stewart /* 2312f8829a4aSRandall Stewart * yep its past where we need to reset... go 2313f8829a4aSRandall Stewart * ahead and queue it. 2314f8829a4aSRandall Stewart */ 2315f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->pending_reply_queue)) { 2316f8829a4aSRandall Stewart /* first one on */ 2317f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2318f8829a4aSRandall Stewart } else { 2319f8829a4aSRandall Stewart struct sctp_queued_to_read *ctlOn; 2320f8829a4aSRandall Stewart unsigned char inserted = 0; 2321f8829a4aSRandall Stewart 2322f8829a4aSRandall Stewart ctlOn = TAILQ_FIRST(&asoc->pending_reply_queue); 2323f8829a4aSRandall Stewart while (ctlOn) { 2324f8829a4aSRandall Stewart if (compare_with_wrap(control->sinfo_tsn, 2325f8829a4aSRandall Stewart ctlOn->sinfo_tsn, MAX_TSN)) { 2326f8829a4aSRandall Stewart ctlOn = TAILQ_NEXT(ctlOn, next); 2327f8829a4aSRandall Stewart } else { 2328f8829a4aSRandall Stewart /* found it */ 2329f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(ctlOn, control, next); 2330f8829a4aSRandall Stewart inserted = 1; 2331f8829a4aSRandall Stewart break; 2332f8829a4aSRandall Stewart } 2333f8829a4aSRandall Stewart } 2334f8829a4aSRandall Stewart if (inserted == 0) { 2335f8829a4aSRandall Stewart /* 2336f8829a4aSRandall Stewart * must be put at end, use 2337f8829a4aSRandall Stewart * prevP (all setup from 2338f8829a4aSRandall Stewart * loop) to setup nextP. 2339f8829a4aSRandall Stewart */ 2340f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2341f8829a4aSRandall Stewart } 2342f8829a4aSRandall Stewart } 2343f8829a4aSRandall Stewart } else { 2344f8829a4aSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, control, abort_flag); 2345f8829a4aSRandall Stewart if (*abort_flag) { 2346f8829a4aSRandall Stewart return (0); 2347f8829a4aSRandall Stewart } 2348f8829a4aSRandall Stewart } 2349f8829a4aSRandall Stewart } 2350f8829a4aSRandall Stewart } else { 2351f8829a4aSRandall Stewart /* Into the re-assembly queue */ 2352f8829a4aSRandall Stewart sctp_queue_data_for_reasm(stcb, asoc, chk, abort_flag); 2353f8829a4aSRandall Stewart if (*abort_flag) { 2354a5d547adSRandall Stewart /* 2355a5d547adSRandall Stewart * the assoc is now gone and chk was put onto the 2356a5d547adSRandall Stewart * reasm queue, which has all been freed. 2357a5d547adSRandall Stewart */ 2358a5d547adSRandall Stewart *m = NULL; 2359f8829a4aSRandall Stewart return (0); 2360f8829a4aSRandall Stewart } 2361f8829a4aSRandall Stewart } 2362f8829a4aSRandall Stewart finish_express_del: 2363f8829a4aSRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) { 2364f8829a4aSRandall Stewart /* we have a new high score */ 2365f8829a4aSRandall Stewart asoc->highest_tsn_inside_map = tsn; 2366b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2367f8829a4aSRandall Stewart sctp_log_map(0, 2, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 236880fefe0aSRandall Stewart } 2369f8829a4aSRandall Stewart } 2370f8829a4aSRandall Stewart if (tsn == (asoc->cumulative_tsn + 1)) { 2371f8829a4aSRandall Stewart /* Update cum-ack */ 2372f8829a4aSRandall Stewart asoc->cumulative_tsn = tsn; 2373f8829a4aSRandall Stewart } 2374f8829a4aSRandall Stewart if (last_chunk) { 2375f8829a4aSRandall Stewart *m = NULL; 2376f8829a4aSRandall Stewart } 2377f42a358aSRandall Stewart if (ordered) { 2378f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inorderchunks); 2379f8829a4aSRandall Stewart } else { 2380f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inunorderchunks); 2381f8829a4aSRandall Stewart } 2382f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdata); 2383f8829a4aSRandall Stewart /* Set it present please */ 2384b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 23856a91f103SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, SCTP_STR_LOG_FROM_MARK_TSN); 238680fefe0aSRandall Stewart } 2387b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2388f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, 2389f8829a4aSRandall Stewart asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE); 239080fefe0aSRandall Stewart } 2391207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 2392f8829a4aSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap); 239317205eccSRandall Stewart /* check the special flag for stream resets */ 239417205eccSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 2395d61a0ae0SRandall Stewart ((compare_with_wrap(asoc->cumulative_tsn, liste->tsn, MAX_TSN)) || 2396d61a0ae0SRandall Stewart (asoc->cumulative_tsn == liste->tsn)) 239717205eccSRandall Stewart ) { 239817205eccSRandall Stewart /* 239917205eccSRandall Stewart * we have finished working through the backlogged TSN's now 240017205eccSRandall Stewart * time to reset streams. 1: call reset function. 2: free 240117205eccSRandall Stewart * pending_reply space 3: distribute any chunks in 240217205eccSRandall Stewart * pending_reply_queue. 240317205eccSRandall Stewart */ 240417205eccSRandall Stewart struct sctp_queued_to_read *ctl; 240517205eccSRandall Stewart 240617205eccSRandall Stewart sctp_reset_in_stream(stcb, liste->number_entries, liste->req.list_of_streams); 240717205eccSRandall Stewart TAILQ_REMOVE(&asoc->resetHead, liste, next_resp); 2408207304d4SRandall Stewart SCTP_FREE(liste, SCTP_M_STRESET); 24093c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 241017205eccSRandall Stewart liste = TAILQ_FIRST(&asoc->resetHead); 241117205eccSRandall Stewart ctl = TAILQ_FIRST(&asoc->pending_reply_queue); 241217205eccSRandall Stewart if (ctl && (liste == NULL)) { 241317205eccSRandall Stewart /* All can be removed */ 241417205eccSRandall Stewart while (ctl) { 241517205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 241617205eccSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag); 241717205eccSRandall Stewart if (*abort_flag) { 241817205eccSRandall Stewart return (0); 241917205eccSRandall Stewart } 242017205eccSRandall Stewart ctl = TAILQ_FIRST(&asoc->pending_reply_queue); 242117205eccSRandall Stewart } 242217205eccSRandall Stewart } else if (ctl) { 242317205eccSRandall Stewart /* more than one in queue */ 2424d61a0ae0SRandall Stewart while (!compare_with_wrap(ctl->sinfo_tsn, liste->tsn, MAX_TSN)) { 242517205eccSRandall Stewart /* 242617205eccSRandall Stewart * if ctl->sinfo_tsn is <= liste->tsn we can 242717205eccSRandall Stewart * process it which is the NOT of 242817205eccSRandall Stewart * ctl->sinfo_tsn > liste->tsn 242917205eccSRandall Stewart */ 243017205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 243117205eccSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag); 243217205eccSRandall Stewart if (*abort_flag) { 243317205eccSRandall Stewart return (0); 243417205eccSRandall Stewart } 243517205eccSRandall Stewart ctl = TAILQ_FIRST(&asoc->pending_reply_queue); 243617205eccSRandall Stewart } 243717205eccSRandall Stewart } 243817205eccSRandall Stewart /* 243917205eccSRandall Stewart * Now service re-assembly to pick up anything that has been 244017205eccSRandall Stewart * held on reassembly queue? 244117205eccSRandall Stewart */ 244217205eccSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 244317205eccSRandall Stewart need_reasm_check = 0; 244417205eccSRandall Stewart } 2445139bc87fSRandall Stewart if (need_reasm_check) { 2446139bc87fSRandall Stewart /* Another one waits ? */ 2447139bc87fSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 2448139bc87fSRandall Stewart } 2449f8829a4aSRandall Stewart return (1); 2450f8829a4aSRandall Stewart } 2451f8829a4aSRandall Stewart 2452f8829a4aSRandall Stewart int8_t sctp_map_lookup_tab[256] = { 2453f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2454f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 3, 2455f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2456f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 4, 2457f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2458f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 3, 2459f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2460f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 5, 2461f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2462f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 3, 2463f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2464f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 4, 2465f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2466f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 3, 2467f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2468f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 6, 2469f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2470f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 3, 2471f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2472f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 4, 2473f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2474f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 3, 2475f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2476f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 5, 2477f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2478f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 3, 2479f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2480f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 4, 2481f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2482f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 3, 2483f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 2, 2484f8829a4aSRandall Stewart -1, 0, -1, 1, -1, 0, -1, 7, 2485f8829a4aSRandall Stewart }; 2486f8829a4aSRandall Stewart 2487f8829a4aSRandall Stewart 2488f8829a4aSRandall Stewart void 2489f8829a4aSRandall Stewart sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort_flag) 2490f8829a4aSRandall Stewart { 2491f8829a4aSRandall Stewart /* 2492f8829a4aSRandall Stewart * Now we also need to check the mapping array in a couple of ways. 2493f8829a4aSRandall Stewart * 1) Did we move the cum-ack point? 2494f8829a4aSRandall Stewart */ 2495f8829a4aSRandall Stewart struct sctp_association *asoc; 2496b3f1ea41SRandall Stewart int at; 2497c4739e2fSRandall Stewart int last_all_ones = 0; 2498f8829a4aSRandall Stewart int slide_from, slide_end, lgap, distance; 2499830d754dSRandall Stewart 2500830d754dSRandall Stewart /* EY nr_mapping array variables */ 2501830d754dSRandall Stewart int nr_at; 2502830d754dSRandall Stewart int nr_last_all_ones = 0; 2503830d754dSRandall Stewart int nr_slide_from, nr_slide_end, nr_lgap, nr_distance; 2504830d754dSRandall Stewart 2505f8829a4aSRandall Stewart uint32_t old_cumack, old_base, old_highest; 2506f8829a4aSRandall Stewart unsigned char aux_array[64]; 2507f8829a4aSRandall Stewart 2508830d754dSRandall Stewart /* 2509830d754dSRandall Stewart * EY! Don't think this is required but I am immitating the code for 2510830d754dSRandall Stewart * map just to make sure 2511830d754dSRandall Stewart */ 2512830d754dSRandall Stewart unsigned char nr_aux_array[64]; 2513f8829a4aSRandall Stewart 2514f8829a4aSRandall Stewart asoc = &stcb->asoc; 2515f8829a4aSRandall Stewart at = 0; 2516f8829a4aSRandall Stewart 2517f8829a4aSRandall Stewart old_cumack = asoc->cumulative_tsn; 2518f8829a4aSRandall Stewart old_base = asoc->mapping_array_base_tsn; 2519f8829a4aSRandall Stewart old_highest = asoc->highest_tsn_inside_map; 2520f8829a4aSRandall Stewart if (asoc->mapping_array_size < 64) 2521f8829a4aSRandall Stewart memcpy(aux_array, asoc->mapping_array, 2522f8829a4aSRandall Stewart asoc->mapping_array_size); 2523f8829a4aSRandall Stewart else 2524f8829a4aSRandall Stewart memcpy(aux_array, asoc->mapping_array, 64); 2525830d754dSRandall Stewart /* EY do the same for nr_mapping_array */ 2526830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 2527f8829a4aSRandall Stewart 2528830d754dSRandall Stewart if (asoc->nr_mapping_array_size != asoc->mapping_array_size) { 2529830d754dSRandall Stewart /* 2530830d754dSRandall Stewart * printf("\nEY-IN sack_check method: \nEY-" "The 2531830d754dSRandall Stewart * size of map and nr_map are inconsitent") 2532830d754dSRandall Stewart */ ; 2533830d754dSRandall Stewart } 2534830d754dSRandall Stewart if (asoc->nr_mapping_array_base_tsn != asoc->mapping_array_base_tsn) { 2535830d754dSRandall Stewart /* 2536830d754dSRandall Stewart * printf("\nEY-IN sack_check method VERY CRUCIAL 2537830d754dSRandall Stewart * error: \nEY-" "The base tsns of map and nr_map 2538830d754dSRandall Stewart * are inconsitent") 2539830d754dSRandall Stewart */ ; 2540830d754dSRandall Stewart } 2541830d754dSRandall Stewart /* EY! just immitating the above code */ 2542830d754dSRandall Stewart if (asoc->nr_mapping_array_size < 64) 2543830d754dSRandall Stewart memcpy(nr_aux_array, asoc->nr_mapping_array, 2544830d754dSRandall Stewart asoc->nr_mapping_array_size); 2545830d754dSRandall Stewart else 2546830d754dSRandall Stewart memcpy(aux_array, asoc->nr_mapping_array, 64); 2547830d754dSRandall Stewart } 2548f8829a4aSRandall Stewart /* 2549f8829a4aSRandall Stewart * We could probably improve this a small bit by calculating the 2550f8829a4aSRandall Stewart * offset of the current cum-ack as the starting point. 2551f8829a4aSRandall Stewart */ 2552f8829a4aSRandall Stewart at = 0; 2553b3f1ea41SRandall Stewart for (slide_from = 0; slide_from < stcb->asoc.mapping_array_size; slide_from++) { 2554d06c82f1SRandall Stewart 2555b3f1ea41SRandall Stewart if (asoc->mapping_array[slide_from] == 0xff) { 2556f8829a4aSRandall Stewart at += 8; 255793164cf9SRandall Stewart last_all_ones = 1; 2558f8829a4aSRandall Stewart } else { 2559f8829a4aSRandall Stewart /* there is a 0 bit */ 2560b3f1ea41SRandall Stewart at += sctp_map_lookup_tab[asoc->mapping_array[slide_from]]; 256193164cf9SRandall Stewart last_all_ones = 0; 2562f8829a4aSRandall Stewart break; 2563f8829a4aSRandall Stewart } 2564f8829a4aSRandall Stewart } 256593164cf9SRandall Stewart asoc->cumulative_tsn = asoc->mapping_array_base_tsn + (at - last_all_ones); 2566f8829a4aSRandall Stewart /* at is one off, since in the table a embedded -1 is present */ 2567f8829a4aSRandall Stewart at++; 2568f8829a4aSRandall Stewart 2569f8829a4aSRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, 2570f8829a4aSRandall Stewart asoc->highest_tsn_inside_map, 2571f8829a4aSRandall Stewart MAX_TSN)) { 2572a5d547adSRandall Stewart #ifdef INVARIANTS 2573ceaad40aSRandall Stewart panic("huh, cumack 0x%x greater than high-tsn 0x%x in map", 2574ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 2575f8829a4aSRandall Stewart #else 2576ceaad40aSRandall Stewart SCTP_PRINTF("huh, cumack 0x%x greater than high-tsn 0x%x in map - should panic?\n", 2577ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 2578b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2579b3f1ea41SRandall Stewart sctp_log_map(0, 6, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 2580b3f1ea41SRandall Stewart } 2581f8829a4aSRandall Stewart asoc->highest_tsn_inside_map = asoc->cumulative_tsn; 2582830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn; 2583f8829a4aSRandall Stewart #endif 2584f8829a4aSRandall Stewart } 2585c4739e2fSRandall Stewart if ((asoc->cumulative_tsn == asoc->highest_tsn_inside_map) && (at >= 8)) { 2586f8829a4aSRandall Stewart /* The complete array was completed by a single FR */ 2587f8829a4aSRandall Stewart /* higest becomes the cum-ack */ 2588f8829a4aSRandall Stewart int clr; 2589f8829a4aSRandall Stewart 2590f8829a4aSRandall Stewart asoc->cumulative_tsn = asoc->highest_tsn_inside_map; 2591f8829a4aSRandall Stewart /* clear the array */ 2592f8829a4aSRandall Stewart clr = (at >> 3) + 1; 2593c4739e2fSRandall Stewart if (clr > asoc->mapping_array_size) { 2594f8829a4aSRandall Stewart clr = asoc->mapping_array_size; 2595f8829a4aSRandall Stewart } 2596f8829a4aSRandall Stewart memset(asoc->mapping_array, 0, clr); 2597f8829a4aSRandall Stewart /* base becomes one ahead of the cum-ack */ 2598f8829a4aSRandall Stewart asoc->mapping_array_base_tsn = asoc->cumulative_tsn + 1; 2599830d754dSRandall Stewart 2600830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 2601830d754dSRandall Stewart 2602830d754dSRandall Stewart if (clr > asoc->nr_mapping_array_size) 2603830d754dSRandall Stewart clr = asoc->nr_mapping_array_size; 2604830d754dSRandall Stewart 2605830d754dSRandall Stewart memset(asoc->nr_mapping_array, 0, clr); 2606830d754dSRandall Stewart /* base becomes one ahead of the cum-ack */ 2607830d754dSRandall Stewart asoc->nr_mapping_array_base_tsn = asoc->cumulative_tsn + 1; 2608830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn; 2609830d754dSRandall Stewart } 2610b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2611f8829a4aSRandall Stewart sctp_log_map(old_base, old_cumack, old_highest, 2612f8829a4aSRandall Stewart SCTP_MAP_PREPARE_SLIDE); 2613f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, 2614f8829a4aSRandall Stewart asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_CLEARED); 261580fefe0aSRandall Stewart } 2616f8829a4aSRandall Stewart } else if (at >= 8) { 2617f8829a4aSRandall Stewart /* we can slide the mapping array down */ 2618b3f1ea41SRandall Stewart /* slide_from holds where we hit the first NON 0xff byte */ 2619b3f1ea41SRandall Stewart 2620f8829a4aSRandall Stewart /* 2621f8829a4aSRandall Stewart * now calculate the ceiling of the move using our highest 2622f8829a4aSRandall Stewart * TSN value 2623f8829a4aSRandall Stewart */ 2624f8829a4aSRandall Stewart if (asoc->highest_tsn_inside_map >= asoc->mapping_array_base_tsn) { 2625f8829a4aSRandall Stewart lgap = asoc->highest_tsn_inside_map - 2626f8829a4aSRandall Stewart asoc->mapping_array_base_tsn; 2627f8829a4aSRandall Stewart } else { 2628f8829a4aSRandall Stewart lgap = (MAX_TSN - asoc->mapping_array_base_tsn) + 2629f8829a4aSRandall Stewart asoc->highest_tsn_inside_map + 1; 2630f8829a4aSRandall Stewart } 2631f8829a4aSRandall Stewart slide_end = lgap >> 3; 2632f8829a4aSRandall Stewart if (slide_end < slide_from) { 2633d55b0b1bSRandall Stewart #ifdef INVARIANTS 2634f8829a4aSRandall Stewart panic("impossible slide"); 2635d55b0b1bSRandall Stewart #else 2636d55b0b1bSRandall Stewart printf("impossible slide?\n"); 2637d55b0b1bSRandall Stewart return; 2638d55b0b1bSRandall Stewart #endif 2639f8829a4aSRandall Stewart } 2640b3f1ea41SRandall Stewart if (slide_end > asoc->mapping_array_size) { 2641b3f1ea41SRandall Stewart #ifdef INVARIANTS 2642b3f1ea41SRandall Stewart panic("would overrun buffer"); 2643b3f1ea41SRandall Stewart #else 2644b3f1ea41SRandall Stewart printf("Gak, would have overrun map end:%d slide_end:%d\n", 2645b3f1ea41SRandall Stewart asoc->mapping_array_size, slide_end); 2646b3f1ea41SRandall Stewart slide_end = asoc->mapping_array_size; 2647b3f1ea41SRandall Stewart #endif 2648b3f1ea41SRandall Stewart } 2649f8829a4aSRandall Stewart distance = (slide_end - slide_from) + 1; 2650b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2651f8829a4aSRandall Stewart sctp_log_map(old_base, old_cumack, old_highest, 2652f8829a4aSRandall Stewart SCTP_MAP_PREPARE_SLIDE); 2653f8829a4aSRandall Stewart sctp_log_map((uint32_t) slide_from, (uint32_t) slide_end, 2654f8829a4aSRandall Stewart (uint32_t) lgap, SCTP_MAP_SLIDE_FROM); 265580fefe0aSRandall Stewart } 2656f8829a4aSRandall Stewart if (distance + slide_from > asoc->mapping_array_size || 2657f8829a4aSRandall Stewart distance < 0) { 2658f8829a4aSRandall Stewart /* 2659f8829a4aSRandall Stewart * Here we do NOT slide forward the array so that 2660f8829a4aSRandall Stewart * hopefully when more data comes in to fill it up 2661f8829a4aSRandall Stewart * we will be able to slide it forward. Really I 2662f8829a4aSRandall Stewart * don't think this should happen :-0 2663f8829a4aSRandall Stewart */ 2664f8829a4aSRandall Stewart 2665b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2666f8829a4aSRandall Stewart sctp_log_map((uint32_t) distance, (uint32_t) slide_from, 2667f8829a4aSRandall Stewart (uint32_t) asoc->mapping_array_size, 2668f8829a4aSRandall Stewart SCTP_MAP_SLIDE_NONE); 266980fefe0aSRandall Stewart } 2670f8829a4aSRandall Stewart } else { 2671f8829a4aSRandall Stewart int ii; 2672f8829a4aSRandall Stewart 2673f8829a4aSRandall Stewart for (ii = 0; ii < distance; ii++) { 2674f8829a4aSRandall Stewart asoc->mapping_array[ii] = 2675f8829a4aSRandall Stewart asoc->mapping_array[slide_from + ii]; 2676f8829a4aSRandall Stewart } 2677f8829a4aSRandall Stewart for (ii = distance; ii <= slide_end; ii++) { 2678f8829a4aSRandall Stewart asoc->mapping_array[ii] = 0; 2679f8829a4aSRandall Stewart } 2680f8829a4aSRandall Stewart asoc->mapping_array_base_tsn += (slide_from << 3); 2681b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2682f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, 2683f8829a4aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map, 2684f8829a4aSRandall Stewart SCTP_MAP_SLIDE_RESULT); 268580fefe0aSRandall Stewart } 2686f8829a4aSRandall Stewart } 2687f8829a4aSRandall Stewart } 2688f8829a4aSRandall Stewart /* 2689830d754dSRandall Stewart * EY if doing nr_sacks then slide the nr_mapping_array accordingly 2690830d754dSRandall Stewart * please 2691830d754dSRandall Stewart */ 2692830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 2693830d754dSRandall Stewart 2694830d754dSRandall Stewart nr_at = 0; 2695830d754dSRandall Stewart for (nr_slide_from = 0; nr_slide_from < stcb->asoc.nr_mapping_array_size; nr_slide_from++) { 2696830d754dSRandall Stewart 2697830d754dSRandall Stewart if (asoc->nr_mapping_array[nr_slide_from] == 0xff) { 2698830d754dSRandall Stewart nr_at += 8; 2699830d754dSRandall Stewart nr_last_all_ones = 1; 2700830d754dSRandall Stewart } else { 2701830d754dSRandall Stewart /* there is a 0 bit */ 2702830d754dSRandall Stewart nr_at += sctp_map_lookup_tab[asoc->nr_mapping_array[nr_slide_from]]; 2703830d754dSRandall Stewart nr_last_all_ones = 0; 2704830d754dSRandall Stewart break; 2705830d754dSRandall Stewart } 2706830d754dSRandall Stewart } 2707830d754dSRandall Stewart 2708830d754dSRandall Stewart nr_at++; 2709830d754dSRandall Stewart 2710830d754dSRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, 2711830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map, MAX_TSN) && (at >= 8)) { 2712830d754dSRandall Stewart /* The complete array was completed by a single FR */ 2713830d754dSRandall Stewart /* higest becomes the cum-ack */ 2714830d754dSRandall Stewart int clr; 2715830d754dSRandall Stewart 2716830d754dSRandall Stewart clr = (nr_at >> 3) + 1; 2717830d754dSRandall Stewart 2718830d754dSRandall Stewart if (clr > asoc->nr_mapping_array_size) 2719830d754dSRandall Stewart clr = asoc->nr_mapping_array_size; 2720830d754dSRandall Stewart 2721830d754dSRandall Stewart memset(asoc->nr_mapping_array, 0, clr); 2722830d754dSRandall Stewart /* base becomes one ahead of the cum-ack */ 2723830d754dSRandall Stewart asoc->nr_mapping_array_base_tsn = asoc->cumulative_tsn + 1; 2724830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn; 2725830d754dSRandall Stewart 2726830d754dSRandall Stewart } else if (nr_at >= 8) { 2727830d754dSRandall Stewart /* we can slide the mapping array down */ 2728830d754dSRandall Stewart /* Calculate the new byte postion we can move down */ 2729830d754dSRandall Stewart 2730830d754dSRandall Stewart /* 2731830d754dSRandall Stewart * now calculate the ceiling of the move using our 2732830d754dSRandall Stewart * highest TSN value 2733830d754dSRandall Stewart */ 2734830d754dSRandall Stewart if (asoc->highest_tsn_inside_nr_map >= asoc->nr_mapping_array_base_tsn) { 2735830d754dSRandall Stewart nr_lgap = asoc->highest_tsn_inside_nr_map - 2736830d754dSRandall Stewart asoc->nr_mapping_array_base_tsn; 2737830d754dSRandall Stewart } else { 2738830d754dSRandall Stewart nr_lgap = (MAX_TSN - asoc->nr_mapping_array_base_tsn) + 2739830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map + 1; 2740830d754dSRandall Stewart } 2741830d754dSRandall Stewart nr_slide_end = nr_lgap >> 3; 2742830d754dSRandall Stewart if (nr_slide_end < nr_slide_from) { 2743830d754dSRandall Stewart #ifdef INVARIANTS 2744830d754dSRandall Stewart panic("impossible slide"); 2745830d754dSRandall Stewart #else 2746830d754dSRandall Stewart printf("impossible slide?\n"); 2747830d754dSRandall Stewart return; 2748830d754dSRandall Stewart #endif 2749830d754dSRandall Stewart } 2750830d754dSRandall Stewart if (nr_slide_end > asoc->nr_mapping_array_size) { 2751830d754dSRandall Stewart #ifdef INVARIANTS 2752830d754dSRandall Stewart panic("would overrun buffer"); 2753830d754dSRandall Stewart #else 2754830d754dSRandall Stewart printf("Gak, would have overrun map end:%d nr_slide_end:%d\n", 2755830d754dSRandall Stewart asoc->nr_mapping_array_size, nr_slide_end); 2756830d754dSRandall Stewart nr_slide_end = asoc->nr_mapping_array_size; 2757830d754dSRandall Stewart #endif 2758830d754dSRandall Stewart } 2759830d754dSRandall Stewart nr_distance = (nr_slide_end - nr_slide_from) + 1; 2760830d754dSRandall Stewart 2761830d754dSRandall Stewart if (nr_distance + nr_slide_from > asoc->nr_mapping_array_size || 2762830d754dSRandall Stewart nr_distance < 0) { 2763830d754dSRandall Stewart /* 2764830d754dSRandall Stewart * Here we do NOT slide forward the array so 2765830d754dSRandall Stewart * that hopefully when more data comes in to 2766830d754dSRandall Stewart * fill it up we will be able to slide it 2767830d754dSRandall Stewart * forward. Really I don't think this should 2768830d754dSRandall Stewart * happen :-0 2769830d754dSRandall Stewart */ 2770830d754dSRandall Stewart ; 2771830d754dSRandall Stewart } else { 2772830d754dSRandall Stewart int ii; 2773830d754dSRandall Stewart 2774830d754dSRandall Stewart for (ii = 0; ii < nr_distance; ii++) { 2775830d754dSRandall Stewart asoc->nr_mapping_array[ii] = 2776830d754dSRandall Stewart asoc->nr_mapping_array[nr_slide_from + ii]; 2777830d754dSRandall Stewart } 2778830d754dSRandall Stewart for (ii = nr_distance; ii <= nr_slide_end; ii++) { 2779830d754dSRandall Stewart asoc->nr_mapping_array[ii] = 0; 2780830d754dSRandall Stewart } 2781830d754dSRandall Stewart asoc->nr_mapping_array_base_tsn += (nr_slide_from << 3); 2782830d754dSRandall Stewart } 2783830d754dSRandall Stewart } 2784830d754dSRandall Stewart } 2785830d754dSRandall Stewart /* 2786f8829a4aSRandall Stewart * Now we need to see if we need to queue a sack or just start the 2787f8829a4aSRandall Stewart * timer (if allowed). 2788f8829a4aSRandall Stewart */ 2789f8829a4aSRandall Stewart if (ok_to_sack) { 2790f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 2791f8829a4aSRandall Stewart /* 2792f8829a4aSRandall Stewart * Ok special case, in SHUTDOWN-SENT case. here we 2793f8829a4aSRandall Stewart * maker sure SACK timer is off and instead send a 2794f8829a4aSRandall Stewart * SHUTDOWN and a SACK 2795f8829a4aSRandall Stewart */ 2796139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2797f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_RECV, 2798a5d547adSRandall Stewart stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_INDATA + SCTP_LOC_18); 2799f8829a4aSRandall Stewart } 2800f8829a4aSRandall Stewart sctp_send_shutdown(stcb, stcb->asoc.primary_destination); 2801830d754dSRandall Stewart /* 2802830d754dSRandall Stewart * EY if nr_sacks used then send an nr-sack , a sack 2803830d754dSRandall Stewart * otherwise 2804830d754dSRandall Stewart */ 2805830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) 2806830d754dSRandall Stewart sctp_send_nr_sack(stcb); 2807830d754dSRandall Stewart else 2808f8829a4aSRandall Stewart sctp_send_sack(stcb); 2809f8829a4aSRandall Stewart } else { 2810f8829a4aSRandall Stewart int is_a_gap; 2811f8829a4aSRandall Stewart 2812f8829a4aSRandall Stewart /* is there a gap now ? */ 2813f8829a4aSRandall Stewart is_a_gap = compare_with_wrap(stcb->asoc.highest_tsn_inside_map, 2814f8829a4aSRandall Stewart stcb->asoc.cumulative_tsn, MAX_TSN); 2815f8829a4aSRandall Stewart 2816f8829a4aSRandall Stewart /* 2817f8829a4aSRandall Stewart * CMT DAC algorithm: increase number of packets 2818f8829a4aSRandall Stewart * received since last ack 2819f8829a4aSRandall Stewart */ 2820f8829a4aSRandall Stewart stcb->asoc.cmt_dac_pkts_rcvd++; 2821f8829a4aSRandall Stewart 282242551e99SRandall Stewart if ((stcb->asoc.send_sack == 1) || /* We need to send a 282342551e99SRandall Stewart * SACK */ 2824f8829a4aSRandall Stewart ((was_a_gap) && (is_a_gap == 0)) || /* was a gap, but no 2825f8829a4aSRandall Stewart * longer is one */ 2826f8829a4aSRandall Stewart (stcb->asoc.numduptsns) || /* we have dup's */ 2827f8829a4aSRandall Stewart (is_a_gap) || /* is still a gap */ 282842551e99SRandall Stewart (stcb->asoc.delayed_ack == 0) || /* Delayed sack disabled */ 282942551e99SRandall Stewart (stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) /* hit limit of pkts */ 2830f8829a4aSRandall Stewart ) { 2831f8829a4aSRandall Stewart 2832b3f1ea41SRandall Stewart if ((SCTP_BASE_SYSCTL(sctp_cmt_on_off)) && 2833b3f1ea41SRandall Stewart (SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) && 283442551e99SRandall Stewart (stcb->asoc.send_sack == 0) && 2835f8829a4aSRandall Stewart (stcb->asoc.numduptsns == 0) && 2836f8829a4aSRandall Stewart (stcb->asoc.delayed_ack) && 2837139bc87fSRandall Stewart (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer))) { 2838f8829a4aSRandall Stewart 2839f8829a4aSRandall Stewart /* 2840f8829a4aSRandall Stewart * CMT DAC algorithm: With CMT, 2841f8829a4aSRandall Stewart * delay acks even in the face of 2842f8829a4aSRandall Stewart * 2843f8829a4aSRandall Stewart * reordering. Therefore, if acks that 2844f8829a4aSRandall Stewart * do not have to be sent because of 2845f8829a4aSRandall Stewart * the above reasons, will be 2846f8829a4aSRandall Stewart * delayed. That is, acks that would 2847f8829a4aSRandall Stewart * have been sent due to gap reports 2848f8829a4aSRandall Stewart * will be delayed with DAC. Start 2849f8829a4aSRandall Stewart * the delayed ack timer. 2850f8829a4aSRandall Stewart */ 2851f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2852f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2853f8829a4aSRandall Stewart } else { 2854f8829a4aSRandall Stewart /* 2855f8829a4aSRandall Stewart * Ok we must build a SACK since the 2856f8829a4aSRandall Stewart * timer is pending, we got our 2857f8829a4aSRandall Stewart * first packet OR there are gaps or 2858f8829a4aSRandall Stewart * duplicates. 2859f8829a4aSRandall Stewart */ 2860ad81507eSRandall Stewart (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer); 2861830d754dSRandall Stewart /* 2862830d754dSRandall Stewart * EY if nr_sacks used then send an 2863830d754dSRandall Stewart * nr-sack , a sack otherwise 2864830d754dSRandall Stewart */ 2865830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && stcb->asoc.peer_supports_nr_sack) 2866830d754dSRandall Stewart sctp_send_nr_sack(stcb); 2867830d754dSRandall Stewart else 2868f8829a4aSRandall Stewart sctp_send_sack(stcb); 2869f8829a4aSRandall Stewart } 2870f8829a4aSRandall Stewart } else { 287142551e99SRandall Stewart if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2872f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2873f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2874f8829a4aSRandall Stewart } 2875f8829a4aSRandall Stewart } 2876f8829a4aSRandall Stewart } 2877f8829a4aSRandall Stewart } 287842551e99SRandall Stewart } 2879f8829a4aSRandall Stewart 2880f8829a4aSRandall Stewart void 2881f8829a4aSRandall Stewart sctp_service_queues(struct sctp_tcb *stcb, struct sctp_association *asoc) 2882f8829a4aSRandall Stewart { 2883f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 2884f8829a4aSRandall Stewart uint32_t tsize; 2885f8829a4aSRandall Stewart uint16_t nxt_todel; 2886f8829a4aSRandall Stewart 2887f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 2888f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 2889f8829a4aSRandall Stewart } 2890f8829a4aSRandall Stewart /* Can we proceed further, i.e. the PD-API is complete */ 2891f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 2892f8829a4aSRandall Stewart /* no */ 2893f8829a4aSRandall Stewart return; 2894f8829a4aSRandall Stewart } 2895f8829a4aSRandall Stewart /* 2896f8829a4aSRandall Stewart * Now is there some other chunk I can deliver from the reassembly 2897f8829a4aSRandall Stewart * queue. 2898f8829a4aSRandall Stewart */ 2899139bc87fSRandall Stewart doit_again: 2900f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 2901f8829a4aSRandall Stewart if (chk == NULL) { 2902f8829a4aSRandall Stewart asoc->size_on_reasm_queue = 0; 2903f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue = 0; 2904f8829a4aSRandall Stewart return; 2905f8829a4aSRandall Stewart } 2906f8829a4aSRandall Stewart nxt_todel = asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1; 2907f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) && 2908f8829a4aSRandall Stewart ((nxt_todel == chk->rec.data.stream_seq) || 2909f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) { 2910f8829a4aSRandall Stewart /* 2911f8829a4aSRandall Stewart * Yep the first one is here. We setup to start reception, 2912f8829a4aSRandall Stewart * by backing down the TSN just in case we can't deliver. 2913f8829a4aSRandall Stewart */ 2914f8829a4aSRandall Stewart 2915f8829a4aSRandall Stewart /* 2916f8829a4aSRandall Stewart * Before we start though either all of the message should 2917f8829a4aSRandall Stewart * be here or 1/4 the socket buffer max or nothing on the 2918f8829a4aSRandall Stewart * delivery queue and something can be delivered. 2919f8829a4aSRandall Stewart */ 2920f8829a4aSRandall Stewart if ((sctp_is_all_msg_on_reasm(asoc, &tsize) || 2921c4739e2fSRandall Stewart (tsize >= stcb->sctp_ep->partial_delivery_point))) { 2922f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 2923f8829a4aSRandall Stewart asoc->tsn_last_delivered = chk->rec.data.TSN_seq - 1; 2924f8829a4aSRandall Stewart asoc->str_of_pdapi = chk->rec.data.stream_number; 2925f8829a4aSRandall Stewart asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 2926f8829a4aSRandall Stewart asoc->pdapi_ppid = chk->rec.data.payloadtype; 2927f8829a4aSRandall Stewart asoc->fragment_flags = chk->rec.data.rcv_flags; 2928f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 2929139bc87fSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 2930139bc87fSRandall Stewart goto doit_again; 2931139bc87fSRandall Stewart } 2932f8829a4aSRandall Stewart } 2933f8829a4aSRandall Stewart } 2934f8829a4aSRandall Stewart } 2935f8829a4aSRandall Stewart 2936f8829a4aSRandall Stewart int 2937f8829a4aSRandall Stewart sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, 2938f8829a4aSRandall Stewart struct sctphdr *sh, struct sctp_inpcb *inp, struct sctp_tcb *stcb, 2939f8829a4aSRandall Stewart struct sctp_nets *net, uint32_t * high_tsn) 2940f8829a4aSRandall Stewart { 2941f8829a4aSRandall Stewart struct sctp_data_chunk *ch, chunk_buf; 2942f8829a4aSRandall Stewart struct sctp_association *asoc; 2943f8829a4aSRandall Stewart int num_chunks = 0; /* number of control chunks processed */ 2944f8829a4aSRandall Stewart int stop_proc = 0; 2945f8829a4aSRandall Stewart int chk_length, break_flag, last_chunk; 2946f8829a4aSRandall Stewart int abort_flag = 0, was_a_gap = 0; 2947f8829a4aSRandall Stewart struct mbuf *m; 2948f8829a4aSRandall Stewart 2949f8829a4aSRandall Stewart /* set the rwnd */ 2950f8829a4aSRandall Stewart sctp_set_rwnd(stcb, &stcb->asoc); 2951f8829a4aSRandall Stewart 2952f8829a4aSRandall Stewart m = *mm; 2953f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 2954f8829a4aSRandall Stewart asoc = &stcb->asoc; 2955f8829a4aSRandall Stewart if (compare_with_wrap(stcb->asoc.highest_tsn_inside_map, 2956f8829a4aSRandall Stewart stcb->asoc.cumulative_tsn, MAX_TSN)) { 2957f8829a4aSRandall Stewart /* there was a gap before this data was processed */ 2958f8829a4aSRandall Stewart was_a_gap = 1; 2959f8829a4aSRandall Stewart } 2960f8829a4aSRandall Stewart /* 2961f8829a4aSRandall Stewart * setup where we got the last DATA packet from for any SACK that 2962f8829a4aSRandall Stewart * may need to go out. Don't bump the net. This is done ONLY when a 2963f8829a4aSRandall Stewart * chunk is assigned. 2964f8829a4aSRandall Stewart */ 2965f8829a4aSRandall Stewart asoc->last_data_chunk_from = net; 2966f8829a4aSRandall Stewart 2967d06c82f1SRandall Stewart /*- 2968f8829a4aSRandall Stewart * Now before we proceed we must figure out if this is a wasted 2969f8829a4aSRandall Stewart * cluster... i.e. it is a small packet sent in and yet the driver 2970f8829a4aSRandall Stewart * underneath allocated a full cluster for it. If so we must copy it 2971f8829a4aSRandall Stewart * to a smaller mbuf and free up the cluster mbuf. This will help 2972d06c82f1SRandall Stewart * with cluster starvation. Note for __Panda__ we don't do this 2973d06c82f1SRandall Stewart * since it has clusters all the way down to 64 bytes. 2974f8829a4aSRandall Stewart */ 297544b7479bSRandall Stewart if (SCTP_BUF_LEN(m) < (long)MLEN && SCTP_BUF_NEXT(m) == NULL) { 2976f8829a4aSRandall Stewart /* we only handle mbufs that are singletons.. not chains */ 2977139bc87fSRandall Stewart m = sctp_get_mbuf_for_msg(SCTP_BUF_LEN(m), 0, M_DONTWAIT, 1, MT_DATA); 2978f8829a4aSRandall Stewart if (m) { 2979f8829a4aSRandall Stewart /* ok lets see if we can copy the data up */ 2980f8829a4aSRandall Stewart caddr_t *from, *to; 2981f8829a4aSRandall Stewart 2982f8829a4aSRandall Stewart /* get the pointers and copy */ 2983f8829a4aSRandall Stewart to = mtod(m, caddr_t *); 2984f8829a4aSRandall Stewart from = mtod((*mm), caddr_t *); 2985139bc87fSRandall Stewart memcpy(to, from, SCTP_BUF_LEN((*mm))); 2986f8829a4aSRandall Stewart /* copy the length and free up the old */ 2987139bc87fSRandall Stewart SCTP_BUF_LEN(m) = SCTP_BUF_LEN((*mm)); 2988f8829a4aSRandall Stewart sctp_m_freem(*mm); 2989f8829a4aSRandall Stewart /* sucess, back copy */ 2990f8829a4aSRandall Stewart *mm = m; 2991f8829a4aSRandall Stewart } else { 2992f8829a4aSRandall Stewart /* We are in trouble in the mbuf world .. yikes */ 2993f8829a4aSRandall Stewart m = *mm; 2994f8829a4aSRandall Stewart } 2995f8829a4aSRandall Stewart } 2996f8829a4aSRandall Stewart /* get pointer to the first chunk header */ 2997f8829a4aSRandall Stewart ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset, 2998f8829a4aSRandall Stewart sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); 2999f8829a4aSRandall Stewart if (ch == NULL) { 3000f8829a4aSRandall Stewart return (1); 3001f8829a4aSRandall Stewart } 3002f8829a4aSRandall Stewart /* 3003f8829a4aSRandall Stewart * process all DATA chunks... 3004f8829a4aSRandall Stewart */ 3005f8829a4aSRandall Stewart *high_tsn = asoc->cumulative_tsn; 3006f8829a4aSRandall Stewart break_flag = 0; 300742551e99SRandall Stewart asoc->data_pkts_seen++; 3008f8829a4aSRandall Stewart while (stop_proc == 0) { 3009f8829a4aSRandall Stewart /* validate chunk length */ 3010f8829a4aSRandall Stewart chk_length = ntohs(ch->ch.chunk_length); 3011f8829a4aSRandall Stewart if (length - *offset < chk_length) { 3012f8829a4aSRandall Stewart /* all done, mutulated chunk */ 3013f8829a4aSRandall Stewart stop_proc = 1; 3014f8829a4aSRandall Stewart break; 3015f8829a4aSRandall Stewart } 3016f8829a4aSRandall Stewart if (ch->ch.chunk_type == SCTP_DATA) { 3017f8829a4aSRandall Stewart if ((size_t)chk_length < sizeof(struct sctp_data_chunk) + 1) { 3018f8829a4aSRandall Stewart /* 3019f8829a4aSRandall Stewart * Need to send an abort since we had a 3020f8829a4aSRandall Stewart * invalid data chunk. 3021f8829a4aSRandall Stewart */ 3022f8829a4aSRandall Stewart struct mbuf *op_err; 3023f8829a4aSRandall Stewart 3024139bc87fSRandall Stewart op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 2 * sizeof(uint32_t)), 3025f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 3026f8829a4aSRandall Stewart 3027f8829a4aSRandall Stewart if (op_err) { 3028f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 3029f8829a4aSRandall Stewart uint32_t *ippp; 3030f8829a4aSRandall Stewart 3031139bc87fSRandall Stewart SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr) + 3032f8829a4aSRandall Stewart (2 * sizeof(uint32_t)); 3033f8829a4aSRandall Stewart ph = mtod(op_err, struct sctp_paramhdr *); 3034f8829a4aSRandall Stewart ph->param_type = 3035f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 3036139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(op_err)); 3037f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 3038a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_19); 3039f8829a4aSRandall Stewart ippp++; 3040f8829a4aSRandall Stewart *ippp = asoc->cumulative_tsn; 3041f8829a4aSRandall Stewart 3042f8829a4aSRandall Stewart } 3043a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_19; 3044f8829a4aSRandall Stewart sctp_abort_association(inp, stcb, m, iphlen, sh, 3045c54a18d2SRandall Stewart op_err, 0, net->port); 3046f8829a4aSRandall Stewart return (2); 3047f8829a4aSRandall Stewart } 3048f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 3049f8829a4aSRandall Stewart sctp_audit_log(0xB1, 0); 3050f8829a4aSRandall Stewart #endif 3051f8829a4aSRandall Stewart if (SCTP_SIZE32(chk_length) == (length - *offset)) { 3052f8829a4aSRandall Stewart last_chunk = 1; 3053f8829a4aSRandall Stewart } else { 3054f8829a4aSRandall Stewart last_chunk = 0; 3055f8829a4aSRandall Stewart } 3056f8829a4aSRandall Stewart if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset, ch, 3057f8829a4aSRandall Stewart chk_length, net, high_tsn, &abort_flag, &break_flag, 3058f8829a4aSRandall Stewart last_chunk)) { 3059f8829a4aSRandall Stewart num_chunks++; 3060f8829a4aSRandall Stewart } 3061f8829a4aSRandall Stewart if (abort_flag) 3062f8829a4aSRandall Stewart return (2); 3063f8829a4aSRandall Stewart 3064f8829a4aSRandall Stewart if (break_flag) { 3065f8829a4aSRandall Stewart /* 3066f8829a4aSRandall Stewart * Set because of out of rwnd space and no 3067f8829a4aSRandall Stewart * drop rep space left. 3068f8829a4aSRandall Stewart */ 3069f8829a4aSRandall Stewart stop_proc = 1; 3070f8829a4aSRandall Stewart break; 3071f8829a4aSRandall Stewart } 3072f8829a4aSRandall Stewart } else { 3073f8829a4aSRandall Stewart /* not a data chunk in the data region */ 3074f8829a4aSRandall Stewart switch (ch->ch.chunk_type) { 3075f8829a4aSRandall Stewart case SCTP_INITIATION: 3076f8829a4aSRandall Stewart case SCTP_INITIATION_ACK: 3077f8829a4aSRandall Stewart case SCTP_SELECTIVE_ACK: 3078830d754dSRandall Stewart case SCTP_NR_SELECTIVE_ACK: /* EY */ 3079f8829a4aSRandall Stewart case SCTP_HEARTBEAT_REQUEST: 3080f8829a4aSRandall Stewart case SCTP_HEARTBEAT_ACK: 3081f8829a4aSRandall Stewart case SCTP_ABORT_ASSOCIATION: 3082f8829a4aSRandall Stewart case SCTP_SHUTDOWN: 3083f8829a4aSRandall Stewart case SCTP_SHUTDOWN_ACK: 3084f8829a4aSRandall Stewart case SCTP_OPERATION_ERROR: 3085f8829a4aSRandall Stewart case SCTP_COOKIE_ECHO: 3086f8829a4aSRandall Stewart case SCTP_COOKIE_ACK: 3087f8829a4aSRandall Stewart case SCTP_ECN_ECHO: 3088f8829a4aSRandall Stewart case SCTP_ECN_CWR: 3089f8829a4aSRandall Stewart case SCTP_SHUTDOWN_COMPLETE: 3090f8829a4aSRandall Stewart case SCTP_AUTHENTICATION: 3091f8829a4aSRandall Stewart case SCTP_ASCONF_ACK: 3092f8829a4aSRandall Stewart case SCTP_PACKET_DROPPED: 3093f8829a4aSRandall Stewart case SCTP_STREAM_RESET: 3094f8829a4aSRandall Stewart case SCTP_FORWARD_CUM_TSN: 3095f8829a4aSRandall Stewart case SCTP_ASCONF: 3096f8829a4aSRandall Stewart /* 3097f8829a4aSRandall Stewart * Now, what do we do with KNOWN chunks that 3098f8829a4aSRandall Stewart * are NOT in the right place? 3099f8829a4aSRandall Stewart * 3100f8829a4aSRandall Stewart * For now, I do nothing but ignore them. We 3101f8829a4aSRandall Stewart * may later want to add sysctl stuff to 3102f8829a4aSRandall Stewart * switch out and do either an ABORT() or 3103f8829a4aSRandall Stewart * possibly process them. 3104f8829a4aSRandall Stewart */ 3105b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_data_order)) { 3106f8829a4aSRandall Stewart struct mbuf *op_err; 3107f8829a4aSRandall Stewart 3108f8829a4aSRandall Stewart op_err = sctp_generate_invmanparam(SCTP_CAUSE_PROTOCOL_VIOLATION); 3109c54a18d2SRandall Stewart sctp_abort_association(inp, stcb, m, iphlen, sh, op_err, 0, net->port); 3110f8829a4aSRandall Stewart return (2); 3111f8829a4aSRandall Stewart } 3112f8829a4aSRandall Stewart break; 3113f8829a4aSRandall Stewart default: 3114f8829a4aSRandall Stewart /* unknown chunk type, use bit rules */ 3115f8829a4aSRandall Stewart if (ch->ch.chunk_type & 0x40) { 3116f8829a4aSRandall Stewart /* Add a error report to the queue */ 3117d61a0ae0SRandall Stewart struct mbuf *merr; 3118f8829a4aSRandall Stewart struct sctp_paramhdr *phd; 3119f8829a4aSRandall Stewart 3120d61a0ae0SRandall Stewart merr = sctp_get_mbuf_for_msg(sizeof(*phd), 0, M_DONTWAIT, 1, MT_DATA); 3121d61a0ae0SRandall Stewart if (merr) { 3122d61a0ae0SRandall Stewart phd = mtod(merr, struct sctp_paramhdr *); 3123f8829a4aSRandall Stewart /* 3124f8829a4aSRandall Stewart * We cheat and use param 3125f8829a4aSRandall Stewart * type since we did not 3126f8829a4aSRandall Stewart * bother to define a error 3127f8829a4aSRandall Stewart * cause struct. They are 3128f8829a4aSRandall Stewart * the same basic format 3129f8829a4aSRandall Stewart * with different names. 3130f8829a4aSRandall Stewart */ 3131f8829a4aSRandall Stewart phd->param_type = 3132f8829a4aSRandall Stewart htons(SCTP_CAUSE_UNRECOG_CHUNK); 3133f8829a4aSRandall Stewart phd->param_length = 3134f8829a4aSRandall Stewart htons(chk_length + sizeof(*phd)); 3135d61a0ae0SRandall Stewart SCTP_BUF_LEN(merr) = sizeof(*phd); 3136d61a0ae0SRandall Stewart SCTP_BUF_NEXT(merr) = SCTP_M_COPYM(m, *offset, 3137f8829a4aSRandall Stewart SCTP_SIZE32(chk_length), 3138f8829a4aSRandall Stewart M_DONTWAIT); 3139d61a0ae0SRandall Stewart if (SCTP_BUF_NEXT(merr)) { 3140d61a0ae0SRandall Stewart sctp_queue_op_err(stcb, merr); 3141f8829a4aSRandall Stewart } else { 3142d61a0ae0SRandall Stewart sctp_m_freem(merr); 3143f8829a4aSRandall Stewart } 3144f8829a4aSRandall Stewart } 3145f8829a4aSRandall Stewart } 3146f8829a4aSRandall Stewart if ((ch->ch.chunk_type & 0x80) == 0) { 3147f8829a4aSRandall Stewart /* discard the rest of this packet */ 3148f8829a4aSRandall Stewart stop_proc = 1; 3149f8829a4aSRandall Stewart } /* else skip this bad chunk and 3150f8829a4aSRandall Stewart * continue... */ 3151f8829a4aSRandall Stewart break; 3152f8829a4aSRandall Stewart }; /* switch of chunk type */ 3153f8829a4aSRandall Stewart } 3154f8829a4aSRandall Stewart *offset += SCTP_SIZE32(chk_length); 3155f8829a4aSRandall Stewart if ((*offset >= length) || stop_proc) { 3156f8829a4aSRandall Stewart /* no more data left in the mbuf chain */ 3157f8829a4aSRandall Stewart stop_proc = 1; 3158f8829a4aSRandall Stewart continue; 3159f8829a4aSRandall Stewart } 3160f8829a4aSRandall Stewart ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset, 3161f8829a4aSRandall Stewart sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); 3162f8829a4aSRandall Stewart if (ch == NULL) { 3163f8829a4aSRandall Stewart *offset = length; 3164f8829a4aSRandall Stewart stop_proc = 1; 3165f8829a4aSRandall Stewart break; 3166f8829a4aSRandall Stewart 3167f8829a4aSRandall Stewart } 3168f8829a4aSRandall Stewart } /* while */ 3169f8829a4aSRandall Stewart if (break_flag) { 3170f8829a4aSRandall Stewart /* 3171f8829a4aSRandall Stewart * we need to report rwnd overrun drops. 3172f8829a4aSRandall Stewart */ 3173f8829a4aSRandall Stewart sctp_send_packet_dropped(stcb, net, *mm, iphlen, 0); 3174f8829a4aSRandall Stewart } 3175f8829a4aSRandall Stewart if (num_chunks) { 3176f8829a4aSRandall Stewart /* 3177ceaad40aSRandall Stewart * Did we get data, if so update the time for auto-close and 3178f8829a4aSRandall Stewart * give peer credit for being alive. 3179f8829a4aSRandall Stewart */ 3180f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvpktwithdata); 3181b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 3182c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 3183c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 3184c4739e2fSRandall Stewart 0, 3185c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 3186c4739e2fSRandall Stewart __LINE__); 3187c4739e2fSRandall Stewart } 3188f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 31896e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_last_rcvd); 3190f8829a4aSRandall Stewart } 3191f8829a4aSRandall Stewart /* now service all of the reassm queue if needed */ 3192f8829a4aSRandall Stewart if (!(TAILQ_EMPTY(&asoc->reasmqueue))) 3193f8829a4aSRandall Stewart sctp_service_queues(stcb, asoc); 3194f8829a4aSRandall Stewart 3195f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 319642551e99SRandall Stewart /* Assure that we ack right away */ 319742551e99SRandall Stewart stcb->asoc.send_sack = 1; 3198f8829a4aSRandall Stewart } 3199f8829a4aSRandall Stewart /* Start a sack timer or QUEUE a SACK for sending */ 3200f8829a4aSRandall Stewart if ((stcb->asoc.cumulative_tsn == stcb->asoc.highest_tsn_inside_map) && 320142551e99SRandall Stewart (stcb->asoc.mapping_array[0] != 0xff)) { 320242551e99SRandall Stewart if ((stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) || 320342551e99SRandall Stewart (stcb->asoc.delayed_ack == 0) || 3204b201f536SRandall Stewart (stcb->asoc.numduptsns) || 320542551e99SRandall Stewart (stcb->asoc.send_sack == 1)) { 3206139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 3207ad81507eSRandall Stewart (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer); 320842551e99SRandall Stewart } 3209830d754dSRandall Stewart /* 3210830d754dSRandall Stewart * EY if nr_sacks used then send an nr-sack , a sack 3211830d754dSRandall Stewart * otherwise 3212830d754dSRandall Stewart */ 3213830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && stcb->asoc.peer_supports_nr_sack) 3214830d754dSRandall Stewart sctp_send_nr_sack(stcb); 3215830d754dSRandall Stewart else 3216f8829a4aSRandall Stewart sctp_send_sack(stcb); 3217f8829a4aSRandall Stewart } else { 321842551e99SRandall Stewart if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 3219f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 3220f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 3221f8829a4aSRandall Stewart } 3222f8829a4aSRandall Stewart } 3223f8829a4aSRandall Stewart } else { 3224f8829a4aSRandall Stewart sctp_sack_check(stcb, 1, was_a_gap, &abort_flag); 3225f8829a4aSRandall Stewart } 3226f8829a4aSRandall Stewart if (abort_flag) 3227f8829a4aSRandall Stewart return (2); 3228f8829a4aSRandall Stewart 3229f8829a4aSRandall Stewart return (0); 3230f8829a4aSRandall Stewart } 3231f8829a4aSRandall Stewart 3232f8829a4aSRandall Stewart static void 3233458303daSRandall Stewart sctp_handle_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct sctp_association *asoc, 3234f8829a4aSRandall Stewart struct sctp_sack_chunk *ch, uint32_t last_tsn, uint32_t * biggest_tsn_acked, 3235139bc87fSRandall Stewart uint32_t * biggest_newly_acked_tsn, uint32_t * this_sack_lowest_newack, 3236139bc87fSRandall Stewart int num_seg, int *ecn_seg_sums) 3237f8829a4aSRandall Stewart { 3238f8829a4aSRandall Stewart /************************************************/ 3239f8829a4aSRandall Stewart /* process fragments and update sendqueue */ 3240f8829a4aSRandall Stewart /************************************************/ 3241f8829a4aSRandall Stewart struct sctp_sack *sack; 3242458303daSRandall Stewart struct sctp_gap_ack_block *frag, block; 3243f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3244a1e13272SRandall Stewart int i, j; 3245a1e13272SRandall Stewart unsigned int theTSN; 3246f8829a4aSRandall Stewart int num_frs = 0; 3247f8829a4aSRandall Stewart 3248f8829a4aSRandall Stewart uint16_t frag_strt, frag_end, primary_flag_set; 3249f8829a4aSRandall Stewart u_long last_frag_high; 3250f8829a4aSRandall Stewart 3251f8829a4aSRandall Stewart /* 3252f8829a4aSRandall Stewart * @@@ JRI : TODO: This flag is not used anywhere .. remove? 3253f8829a4aSRandall Stewart */ 3254f8829a4aSRandall Stewart if (asoc->primary_destination->dest_state & SCTP_ADDR_SWITCH_PRIMARY) { 3255f8829a4aSRandall Stewart primary_flag_set = 1; 3256f8829a4aSRandall Stewart } else { 3257f8829a4aSRandall Stewart primary_flag_set = 0; 3258f8829a4aSRandall Stewart } 3259f8829a4aSRandall Stewart sack = &ch->sack; 3260458303daSRandall Stewart 3261458303daSRandall Stewart frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, 3262458303daSRandall Stewart sizeof(struct sctp_gap_ack_block), (uint8_t *) & block); 3263458303daSRandall Stewart *offset += sizeof(block); 3264458303daSRandall Stewart if (frag == NULL) { 3265458303daSRandall Stewart return; 3266458303daSRandall Stewart } 3267f8829a4aSRandall Stewart tp1 = NULL; 3268f8829a4aSRandall Stewart last_frag_high = 0; 3269f8829a4aSRandall Stewart for (i = 0; i < num_seg; i++) { 3270f8829a4aSRandall Stewart frag_strt = ntohs(frag->start); 3271f8829a4aSRandall Stewart frag_end = ntohs(frag->end); 3272830d754dSRandall Stewart /* some sanity checks on the fragment offsets */ 3273f8829a4aSRandall Stewart if (frag_strt > frag_end) { 3274f8829a4aSRandall Stewart /* this one is malformed, skip */ 3275f8829a4aSRandall Stewart frag++; 3276f8829a4aSRandall Stewart continue; 3277f8829a4aSRandall Stewart } 3278f8829a4aSRandall Stewart if (compare_with_wrap((frag_end + last_tsn), *biggest_tsn_acked, 3279f8829a4aSRandall Stewart MAX_TSN)) 3280f8829a4aSRandall Stewart *biggest_tsn_acked = frag_end + last_tsn; 3281f8829a4aSRandall Stewart 3282f8829a4aSRandall Stewart /* mark acked dgs and find out the highestTSN being acked */ 3283f8829a4aSRandall Stewart if (tp1 == NULL) { 3284f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3285f8829a4aSRandall Stewart 3286f8829a4aSRandall Stewart /* save the locations of the last frags */ 3287f8829a4aSRandall Stewart last_frag_high = frag_end + last_tsn; 3288f8829a4aSRandall Stewart } else { 3289f8829a4aSRandall Stewart /* 3290f8829a4aSRandall Stewart * now lets see if we need to reset the queue due to 3291f8829a4aSRandall Stewart * a out-of-order SACK fragment 3292f8829a4aSRandall Stewart */ 3293f8829a4aSRandall Stewart if (compare_with_wrap(frag_strt + last_tsn, 3294f8829a4aSRandall Stewart last_frag_high, MAX_TSN)) { 3295f8829a4aSRandall Stewart /* 3296f8829a4aSRandall Stewart * if the new frag starts after the last TSN 3297f8829a4aSRandall Stewart * frag covered, we are ok and this one is 3298f8829a4aSRandall Stewart * beyond the last one 3299f8829a4aSRandall Stewart */ 3300f8829a4aSRandall Stewart ; 3301f8829a4aSRandall Stewart } else { 3302f8829a4aSRandall Stewart /* 3303f8829a4aSRandall Stewart * ok, they have reset us, so we need to 3304f8829a4aSRandall Stewart * reset the queue this will cause extra 3305f8829a4aSRandall Stewart * hunting but hey, they chose the 3306f8829a4aSRandall Stewart * performance hit when they failed to order 3307830d754dSRandall Stewart * their gaps 3308f8829a4aSRandall Stewart */ 3309f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3310f8829a4aSRandall Stewart } 3311f8829a4aSRandall Stewart last_frag_high = frag_end + last_tsn; 3312f8829a4aSRandall Stewart } 3313a1e13272SRandall Stewart for (j = frag_strt; j <= frag_end; j++) { 3314a1e13272SRandall Stewart theTSN = j + last_tsn; 3315f8829a4aSRandall Stewart while (tp1) { 3316f8829a4aSRandall Stewart if (tp1->rec.data.doing_fast_retransmit) 3317f8829a4aSRandall Stewart num_frs++; 3318f8829a4aSRandall Stewart 3319f8829a4aSRandall Stewart /* 3320f8829a4aSRandall Stewart * CMT: CUCv2 algorithm. For each TSN being 3321f8829a4aSRandall Stewart * processed from the sent queue, track the 3322f8829a4aSRandall Stewart * next expected pseudo-cumack, or 3323f8829a4aSRandall Stewart * rtx_pseudo_cumack, if required. Separate 3324f8829a4aSRandall Stewart * cumack trackers for first transmissions, 3325f8829a4aSRandall Stewart * and retransmissions. 3326f8829a4aSRandall Stewart */ 3327f8829a4aSRandall Stewart if ((tp1->whoTo->find_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 3328f8829a4aSRandall Stewart (tp1->snd_count == 1)) { 3329f8829a4aSRandall Stewart tp1->whoTo->pseudo_cumack = tp1->rec.data.TSN_seq; 3330f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 0; 3331f8829a4aSRandall Stewart } 3332f8829a4aSRandall Stewart if ((tp1->whoTo->find_rtx_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 3333f8829a4aSRandall Stewart (tp1->snd_count > 1)) { 3334f8829a4aSRandall Stewart tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.TSN_seq; 3335f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 0; 3336f8829a4aSRandall Stewart } 3337a1e13272SRandall Stewart if (tp1->rec.data.TSN_seq == theTSN) { 3338f8829a4aSRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 3339f8829a4aSRandall Stewart /* 3340f8829a4aSRandall Stewart * must be held until 3341f8829a4aSRandall Stewart * cum-ack passes 3342f8829a4aSRandall Stewart */ 3343f8829a4aSRandall Stewart /* 3344f8829a4aSRandall Stewart * ECN Nonce: Add the nonce 3345f8829a4aSRandall Stewart * value to the sender's 3346f8829a4aSRandall Stewart * nonce sum 3347f8829a4aSRandall Stewart */ 3348c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3349c105859eSRandall Stewart /*- 3350c105859eSRandall Stewart * If it is less than RESEND, it is 3351c105859eSRandall Stewart * now no-longer in flight. 3352c105859eSRandall Stewart * Higher values may already be set 3353c105859eSRandall Stewart * via previous Gap Ack Blocks... 3354c105859eSRandall Stewart * i.e. ACKED or RESEND. 3355f8829a4aSRandall Stewart */ 3356f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 3357f8829a4aSRandall Stewart *biggest_newly_acked_tsn, MAX_TSN)) { 3358f8829a4aSRandall Stewart *biggest_newly_acked_tsn = tp1->rec.data.TSN_seq; 3359f8829a4aSRandall Stewart } 3360f8829a4aSRandall Stewart /* 3361f8829a4aSRandall Stewart * CMT: SFR algo 3362f8829a4aSRandall Stewart * (and HTNA) - set 3363f8829a4aSRandall Stewart * saw_newack to 1 3364f8829a4aSRandall Stewart * for dest being 3365f8829a4aSRandall Stewart * newly acked. 3366f8829a4aSRandall Stewart * update 3367f8829a4aSRandall Stewart * this_sack_highest_ 3368f8829a4aSRandall Stewart * newack if 3369f8829a4aSRandall Stewart * appropriate. 3370f8829a4aSRandall Stewart */ 3371f8829a4aSRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) 3372f8829a4aSRandall Stewart tp1->whoTo->saw_newack = 1; 3373f8829a4aSRandall Stewart 3374f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 3375f8829a4aSRandall Stewart tp1->whoTo->this_sack_highest_newack, 3376f8829a4aSRandall Stewart MAX_TSN)) { 3377f8829a4aSRandall Stewart tp1->whoTo->this_sack_highest_newack = 3378f8829a4aSRandall Stewart tp1->rec.data.TSN_seq; 3379f8829a4aSRandall Stewart } 3380f8829a4aSRandall Stewart /* 3381f8829a4aSRandall Stewart * CMT DAC algo: 3382f8829a4aSRandall Stewart * also update 3383f8829a4aSRandall Stewart * this_sack_lowest_n 3384f8829a4aSRandall Stewart * ewack 3385f8829a4aSRandall Stewart */ 3386f8829a4aSRandall Stewart if (*this_sack_lowest_newack == 0) { 3387b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 3388f8829a4aSRandall Stewart sctp_log_sack(*this_sack_lowest_newack, 3389d0cf96b4SMax Laier last_tsn, 3390f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3391f8829a4aSRandall Stewart 0, 3392f8829a4aSRandall Stewart 0, 3393f8829a4aSRandall Stewart SCTP_LOG_TSN_ACKED); 339480fefe0aSRandall Stewart } 3395f8829a4aSRandall Stewart *this_sack_lowest_newack = tp1->rec.data.TSN_seq; 3396f8829a4aSRandall Stewart } 3397f8829a4aSRandall Stewart /* 3398f8829a4aSRandall Stewart * CMT: CUCv2 3399f8829a4aSRandall Stewart * algorithm. If 3400f8829a4aSRandall Stewart * (rtx-)pseudo-cumac 3401f8829a4aSRandall Stewart * k for corresp 3402f8829a4aSRandall Stewart * dest is being 3403f8829a4aSRandall Stewart * acked, then we 3404f8829a4aSRandall Stewart * have a new 3405f8829a4aSRandall Stewart * (rtx-)pseudo-cumac 3406f8829a4aSRandall Stewart * k. Set 3407f8829a4aSRandall Stewart * new_(rtx_)pseudo_c 3408f8829a4aSRandall Stewart * umack to TRUE so 3409f8829a4aSRandall Stewart * that the cwnd for 3410f8829a4aSRandall Stewart * this dest can be 3411f8829a4aSRandall Stewart * updated. Also 3412f8829a4aSRandall Stewart * trigger search 3413f8829a4aSRandall Stewart * for the next 3414f8829a4aSRandall Stewart * expected 3415f8829a4aSRandall Stewart * (rtx-)pseudo-cumac 3416f8829a4aSRandall Stewart * k. Separate 3417f8829a4aSRandall Stewart * pseudo_cumack 3418f8829a4aSRandall Stewart * trackers for 3419f8829a4aSRandall Stewart * first 3420f8829a4aSRandall Stewart * transmissions and 3421f8829a4aSRandall Stewart * retransmissions. 3422f8829a4aSRandall Stewart */ 3423f8829a4aSRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->pseudo_cumack) { 3424f8829a4aSRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 3425f8829a4aSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 3426f8829a4aSRandall Stewart } 3427f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 3428f8829a4aSRandall Stewart } 3429b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 3430f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 343180fefe0aSRandall Stewart } 3432f8829a4aSRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->rtx_pseudo_cumack) { 3433f8829a4aSRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 3434f8829a4aSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 3435f8829a4aSRandall Stewart } 3436f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 3437f8829a4aSRandall Stewart } 3438b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 3439f8829a4aSRandall Stewart sctp_log_sack(*biggest_newly_acked_tsn, 3440f8829a4aSRandall Stewart last_tsn, 3441f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3442f8829a4aSRandall Stewart frag_strt, 3443f8829a4aSRandall Stewart frag_end, 3444f8829a4aSRandall Stewart SCTP_LOG_TSN_ACKED); 344580fefe0aSRandall Stewart } 3446b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3447c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP, 3448a5d547adSRandall Stewart tp1->whoTo->flight_size, 3449a5d547adSRandall Stewart tp1->book_size, 3450c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3451a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 345280fefe0aSRandall Stewart } 3453c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 3454c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 3455f8829a4aSRandall Stewart 3456f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 3457f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 3458f8829a4aSRandall Stewart /* 3459a5d547adSRandall Stewart * True 3460a5d547adSRandall Stewart * non-retran 3461a5d547adSRandall Stewart * smited 3462a5d547adSRandall Stewart * chunk */ 3463f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += tp1->send_size; 3464f8829a4aSRandall Stewart 3465f8829a4aSRandall Stewart /* 3466a5d547adSRandall Stewart * update RTO 3467a5d547adSRandall Stewart * too ? */ 3468f8829a4aSRandall Stewart if (tp1->do_rtt) { 3469f8829a4aSRandall Stewart tp1->whoTo->RTO = 3470f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 3471f8829a4aSRandall Stewart asoc, 3472f8829a4aSRandall Stewart tp1->whoTo, 347318e198d3SRandall Stewart &tp1->sent_rcv_time, 347418e198d3SRandall Stewart sctp_align_safe_nocopy); 3475f8829a4aSRandall Stewart tp1->do_rtt = 0; 3476f8829a4aSRandall Stewart } 3477f8829a4aSRandall Stewart } 3478f8829a4aSRandall Stewart } 3479c105859eSRandall Stewart if (tp1->sent <= SCTP_DATAGRAM_RESEND) { 3480c105859eSRandall Stewart (*ecn_seg_sums) += tp1->rec.data.ect_nonce; 3481c105859eSRandall Stewart (*ecn_seg_sums) &= SCTP_SACK_NONCE_SUM; 3482c105859eSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 3483f8829a4aSRandall Stewart asoc->this_sack_highest_gap, 3484f8829a4aSRandall Stewart MAX_TSN)) { 3485f8829a4aSRandall Stewart asoc->this_sack_highest_gap = 3486f8829a4aSRandall Stewart tp1->rec.data.TSN_seq; 3487f8829a4aSRandall Stewart } 3488f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 3489f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 3490f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 3491f8829a4aSRandall Stewart sctp_audit_log(0xB2, 3492f8829a4aSRandall Stewart (asoc->sent_queue_retran_cnt & 0x000000ff)); 3493f8829a4aSRandall Stewart #endif 3494f8829a4aSRandall Stewart } 3495c105859eSRandall Stewart } 3496c105859eSRandall Stewart /* 3497c105859eSRandall Stewart * All chunks NOT UNSENT 3498c105859eSRandall Stewart * fall through here and are 3499c105859eSRandall Stewart * marked 3500c105859eSRandall Stewart */ 3501f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_MARKED; 350242551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 350342551e99SRandall Stewart /* deflate the cwnd */ 350442551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 350542551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 350642551e99SRandall Stewart } 3507f8829a4aSRandall Stewart } 3508f8829a4aSRandall Stewart break; 3509a1e13272SRandall Stewart } /* if (tp1->TSN_seq == theTSN) */ 3510a1e13272SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, theTSN, 3511f8829a4aSRandall Stewart MAX_TSN)) 3512f8829a4aSRandall Stewart break; 3513f8829a4aSRandall Stewart 3514f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3515f8829a4aSRandall Stewart } /* end while (tp1) */ 3516f8829a4aSRandall Stewart } /* end for (j = fragStart */ 3517458303daSRandall Stewart frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, 3518458303daSRandall Stewart sizeof(struct sctp_gap_ack_block), (uint8_t *) & block); 3519458303daSRandall Stewart *offset += sizeof(block); 3520458303daSRandall Stewart if (frag == NULL) { 3521458303daSRandall Stewart break; 3522458303daSRandall Stewart } 3523f8829a4aSRandall Stewart } 3524b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 352580fefe0aSRandall Stewart if (num_frs) 352680fefe0aSRandall Stewart sctp_log_fr(*biggest_tsn_acked, 352780fefe0aSRandall Stewart *biggest_newly_acked_tsn, 352880fefe0aSRandall Stewart last_tsn, SCTP_FR_LOG_BIGGEST_TSNS); 352980fefe0aSRandall Stewart } 3530f8829a4aSRandall Stewart } 3531f8829a4aSRandall Stewart 3532f8829a4aSRandall Stewart static void 3533c105859eSRandall Stewart sctp_check_for_revoked(struct sctp_tcb *stcb, 3534c105859eSRandall Stewart struct sctp_association *asoc, uint32_t cumack, 3535f8829a4aSRandall Stewart u_long biggest_tsn_acked) 3536f8829a4aSRandall Stewart { 3537f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3538f8829a4aSRandall Stewart int tot_revoked = 0; 3539f8829a4aSRandall Stewart 3540f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3541f8829a4aSRandall Stewart while (tp1) { 3542f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, cumack, 3543f8829a4aSRandall Stewart MAX_TSN)) { 3544f8829a4aSRandall Stewart /* 3545f8829a4aSRandall Stewart * ok this guy is either ACK or MARKED. If it is 3546f8829a4aSRandall Stewart * ACKED it has been previously acked but not this 3547f8829a4aSRandall Stewart * time i.e. revoked. If it is MARKED it was ACK'ed 3548f8829a4aSRandall Stewart * again. 3549f8829a4aSRandall Stewart */ 3550d06c82f1SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked, 3551d06c82f1SRandall Stewart MAX_TSN)) 3552d06c82f1SRandall Stewart break; 3553d06c82f1SRandall Stewart 3554d06c82f1SRandall Stewart 3555f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_ACKED) { 3556f8829a4aSRandall Stewart /* it has been revoked */ 3557f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 3558f8829a4aSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 3559a5d547adSRandall Stewart /* 356042551e99SRandall Stewart * We must add this stuff back in to assure 356142551e99SRandall Stewart * timers and such get started. 3562a5d547adSRandall Stewart */ 3563b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3564c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 3565c105859eSRandall Stewart tp1->whoTo->flight_size, 3566c105859eSRandall Stewart tp1->book_size, 3567c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3568c105859eSRandall Stewart tp1->rec.data.TSN_seq); 356980fefe0aSRandall Stewart } 3570c105859eSRandall Stewart sctp_flight_size_increase(tp1); 3571c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 357242551e99SRandall Stewart /* 357342551e99SRandall Stewart * We inflate the cwnd to compensate for our 357442551e99SRandall Stewart * artificial inflation of the flight_size. 357542551e99SRandall Stewart */ 357642551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 3577f8829a4aSRandall Stewart tot_revoked++; 3578b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 3579f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 3580f8829a4aSRandall Stewart cumack, 3581f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3582f8829a4aSRandall Stewart 0, 3583f8829a4aSRandall Stewart 0, 3584f8829a4aSRandall Stewart SCTP_LOG_TSN_REVOKED); 358580fefe0aSRandall Stewart } 3586f8829a4aSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_MARKED) { 3587f8829a4aSRandall Stewart /* it has been re-acked in this SACK */ 3588f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 3589f8829a4aSRandall Stewart } 3590f8829a4aSRandall Stewart } 3591f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) 3592f8829a4aSRandall Stewart break; 3593f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3594f8829a4aSRandall Stewart } 3595f8829a4aSRandall Stewart if (tot_revoked > 0) { 3596f8829a4aSRandall Stewart /* 3597f8829a4aSRandall Stewart * Setup the ecn nonce re-sync point. We do this since once 3598f8829a4aSRandall Stewart * data is revoked we begin to retransmit things, which do 3599f8829a4aSRandall Stewart * NOT have the ECN bits set. This means we are now out of 3600f8829a4aSRandall Stewart * sync and must wait until we get back in sync with the 3601f8829a4aSRandall Stewart * peer to check ECN bits. 3602f8829a4aSRandall Stewart */ 3603f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->send_queue); 3604f8829a4aSRandall Stewart if (tp1 == NULL) { 3605f8829a4aSRandall Stewart asoc->nonce_resync_tsn = asoc->sending_seq; 3606f8829a4aSRandall Stewart } else { 3607f8829a4aSRandall Stewart asoc->nonce_resync_tsn = tp1->rec.data.TSN_seq; 3608f8829a4aSRandall Stewart } 3609f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 0; 3610f8829a4aSRandall Stewart asoc->nonce_sum_check = 0; 3611f8829a4aSRandall Stewart } 3612f8829a4aSRandall Stewart } 3613f8829a4aSRandall Stewart 3614830d754dSRandall Stewart 3615f8829a4aSRandall Stewart static void 3616f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, 3617f8829a4aSRandall Stewart u_long biggest_tsn_acked, u_long biggest_tsn_newly_acked, u_long this_sack_lowest_newack, int accum_moved) 3618f8829a4aSRandall Stewart { 3619f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3620f8829a4aSRandall Stewart int strike_flag = 0; 3621f8829a4aSRandall Stewart struct timeval now; 3622f8829a4aSRandall Stewart int tot_retrans = 0; 3623f8829a4aSRandall Stewart uint32_t sending_seq; 3624f8829a4aSRandall Stewart struct sctp_nets *net; 3625f8829a4aSRandall Stewart int num_dests_sacked = 0; 3626f8829a4aSRandall Stewart 3627f8829a4aSRandall Stewart /* 3628f8829a4aSRandall Stewart * select the sending_seq, this is either the next thing ready to be 3629f8829a4aSRandall Stewart * sent but not transmitted, OR, the next seq we assign. 3630f8829a4aSRandall Stewart */ 3631f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.send_queue); 3632f8829a4aSRandall Stewart if (tp1 == NULL) { 3633f8829a4aSRandall Stewart sending_seq = asoc->sending_seq; 3634f8829a4aSRandall Stewart } else { 3635f8829a4aSRandall Stewart sending_seq = tp1->rec.data.TSN_seq; 3636f8829a4aSRandall Stewart } 3637f8829a4aSRandall Stewart 3638f8829a4aSRandall Stewart /* CMT DAC algo: finding out if SACK is a mixed SACK */ 3639b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3640f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 3641f8829a4aSRandall Stewart if (net->saw_newack) 3642f8829a4aSRandall Stewart num_dests_sacked++; 3643f8829a4aSRandall Stewart } 3644f8829a4aSRandall Stewart } 3645f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_prsctp) { 36466e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 3647f8829a4aSRandall Stewart } 3648f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3649f8829a4aSRandall Stewart while (tp1) { 3650f8829a4aSRandall Stewart strike_flag = 0; 3651f8829a4aSRandall Stewart if (tp1->no_fr_allowed) { 3652f8829a4aSRandall Stewart /* this one had a timeout or something */ 3653f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3654f8829a4aSRandall Stewart continue; 3655f8829a4aSRandall Stewart } 3656b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3657f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) 3658f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3659f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3660f8829a4aSRandall Stewart tp1->sent, 3661f8829a4aSRandall Stewart SCTP_FR_LOG_CHECK_STRIKE); 366280fefe0aSRandall Stewart } 3663f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked, 3664f8829a4aSRandall Stewart MAX_TSN) || 3665f8829a4aSRandall Stewart tp1->sent == SCTP_DATAGRAM_UNSENT) { 3666f8829a4aSRandall Stewart /* done */ 3667f8829a4aSRandall Stewart break; 3668f8829a4aSRandall Stewart } 3669f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_prsctp) { 3670f8829a4aSRandall Stewart if ((PR_SCTP_TTL_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) { 3671f8829a4aSRandall Stewart /* Is it expired? */ 36725e54f665SRandall Stewart if ( 3673fc14de76SRandall Stewart /* 3674fc14de76SRandall Stewart * TODO sctp_constants.h needs alternative 3675fc14de76SRandall Stewart * time macros when _KERNEL is undefined. 3676fc14de76SRandall Stewart */ 36775e54f665SRandall Stewart (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) 36785e54f665SRandall Stewart ) { 3679f8829a4aSRandall Stewart /* Yes so drop it */ 3680f8829a4aSRandall Stewart if (tp1->data != NULL) { 3681ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3682f8829a4aSRandall Stewart (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 3683ceaad40aSRandall Stewart &asoc->sent_queue, SCTP_SO_NOT_LOCKED); 3684f8829a4aSRandall Stewart } 3685f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3686f8829a4aSRandall Stewart continue; 3687f8829a4aSRandall Stewart } 3688f8829a4aSRandall Stewart } 3689f8829a4aSRandall Stewart if ((PR_SCTP_RTX_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) { 3690f8829a4aSRandall Stewart /* Has it been retransmitted tv_sec times? */ 3691f8829a4aSRandall Stewart if (tp1->snd_count > tp1->rec.data.timetodrop.tv_sec) { 3692f8829a4aSRandall Stewart /* Yes, so drop it */ 3693f8829a4aSRandall Stewart if (tp1->data != NULL) { 3694ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3695f8829a4aSRandall Stewart (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 3696ceaad40aSRandall Stewart &asoc->sent_queue, SCTP_SO_NOT_LOCKED); 3697f8829a4aSRandall Stewart } 3698f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3699f8829a4aSRandall Stewart continue; 3700f8829a4aSRandall Stewart } 3701f8829a4aSRandall Stewart } 3702f8829a4aSRandall Stewart } 3703f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 3704f8829a4aSRandall Stewart asoc->this_sack_highest_gap, MAX_TSN)) { 3705f8829a4aSRandall Stewart /* we are beyond the tsn in the sack */ 3706f8829a4aSRandall Stewart break; 3707f8829a4aSRandall Stewart } 3708f8829a4aSRandall Stewart if (tp1->sent >= SCTP_DATAGRAM_RESEND) { 3709f8829a4aSRandall Stewart /* either a RESEND, ACKED, or MARKED */ 3710f8829a4aSRandall Stewart /* skip */ 3711f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3712f8829a4aSRandall Stewart continue; 3713f8829a4aSRandall Stewart } 3714f8829a4aSRandall Stewart /* 3715f8829a4aSRandall Stewart * CMT : SFR algo (covers part of DAC and HTNA as well) 3716f8829a4aSRandall Stewart */ 3717ad81507eSRandall Stewart if (tp1->whoTo && tp1->whoTo->saw_newack == 0) { 3718f8829a4aSRandall Stewart /* 3719f8829a4aSRandall Stewart * No new acks were receieved for data sent to this 3720f8829a4aSRandall Stewart * dest. Therefore, according to the SFR algo for 3721f8829a4aSRandall Stewart * CMT, no data sent to this dest can be marked for 3722c105859eSRandall Stewart * FR using this SACK. 3723f8829a4aSRandall Stewart */ 3724f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3725f8829a4aSRandall Stewart continue; 3726ad81507eSRandall Stewart } else if (tp1->whoTo && compare_with_wrap(tp1->rec.data.TSN_seq, 3727f8829a4aSRandall Stewart tp1->whoTo->this_sack_highest_newack, MAX_TSN)) { 3728f8829a4aSRandall Stewart /* 3729f8829a4aSRandall Stewart * CMT: New acks were receieved for data sent to 3730f8829a4aSRandall Stewart * this dest. But no new acks were seen for data 3731f8829a4aSRandall Stewart * sent after tp1. Therefore, according to the SFR 3732f8829a4aSRandall Stewart * algo for CMT, tp1 cannot be marked for FR using 3733f8829a4aSRandall Stewart * this SACK. This step covers part of the DAC algo 3734f8829a4aSRandall Stewart * and the HTNA algo as well. 3735f8829a4aSRandall Stewart */ 3736f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3737f8829a4aSRandall Stewart continue; 3738f8829a4aSRandall Stewart } 3739f8829a4aSRandall Stewart /* 3740f8829a4aSRandall Stewart * Here we check to see if we were have already done a FR 3741f8829a4aSRandall Stewart * and if so we see if the biggest TSN we saw in the sack is 3742f8829a4aSRandall Stewart * smaller than the recovery point. If so we don't strike 3743f8829a4aSRandall Stewart * the tsn... otherwise we CAN strike the TSN. 3744f8829a4aSRandall Stewart */ 3745f8829a4aSRandall Stewart /* 374642551e99SRandall Stewart * @@@ JRI: Check for CMT if (accum_moved && 374742551e99SRandall Stewart * asoc->fast_retran_loss_recovery && (sctp_cmt_on_off == 374842551e99SRandall Stewart * 0)) { 3749f8829a4aSRandall Stewart */ 375042551e99SRandall Stewart if (accum_moved && asoc->fast_retran_loss_recovery) { 3751f8829a4aSRandall Stewart /* 3752f8829a4aSRandall Stewart * Strike the TSN if in fast-recovery and cum-ack 3753f8829a4aSRandall Stewart * moved. 3754f8829a4aSRandall Stewart */ 3755b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3756f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3757f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3758f8829a4aSRandall Stewart tp1->sent, 3759f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 376080fefe0aSRandall Stewart } 37615e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3762f8829a4aSRandall Stewart tp1->sent++; 37635e54f665SRandall Stewart } 3764b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3765f8829a4aSRandall Stewart /* 3766f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK flag is set to 3767f8829a4aSRandall Stewart * 0, then lowest_newack test will not pass 3768f8829a4aSRandall Stewart * because it would have been set to the 3769f8829a4aSRandall Stewart * cumack earlier. If not already to be 3770f8829a4aSRandall Stewart * rtx'd, If not a mixed sack and if tp1 is 3771f8829a4aSRandall Stewart * not between two sacked TSNs, then mark by 3772c105859eSRandall Stewart * one more. NOTE that we are marking by one 3773c105859eSRandall Stewart * additional time since the SACK DAC flag 3774c105859eSRandall Stewart * indicates that two packets have been 3775c105859eSRandall Stewart * received after this missing TSN. 37765e54f665SRandall Stewart */ 37775e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && 3778f8829a4aSRandall Stewart compare_with_wrap(this_sack_lowest_newack, tp1->rec.data.TSN_seq, MAX_TSN)) { 3779b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3780f8829a4aSRandall Stewart sctp_log_fr(16 + num_dests_sacked, 3781f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3782f8829a4aSRandall Stewart tp1->sent, 3783f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 378480fefe0aSRandall Stewart } 3785f8829a4aSRandall Stewart tp1->sent++; 3786f8829a4aSRandall Stewart } 3787f8829a4aSRandall Stewart } 3788b3f1ea41SRandall Stewart } else if ((tp1->rec.data.doing_fast_retransmit) && (SCTP_BASE_SYSCTL(sctp_cmt_on_off) == 0)) { 3789f8829a4aSRandall Stewart /* 3790f8829a4aSRandall Stewart * For those that have done a FR we must take 3791f8829a4aSRandall Stewart * special consideration if we strike. I.e the 3792f8829a4aSRandall Stewart * biggest_newly_acked must be higher than the 3793f8829a4aSRandall Stewart * sending_seq at the time we did the FR. 3794f8829a4aSRandall Stewart */ 37955e54f665SRandall Stewart if ( 3796f8829a4aSRandall Stewart #ifdef SCTP_FR_TO_ALTERNATE 3797f8829a4aSRandall Stewart /* 3798f8829a4aSRandall Stewart * If FR's go to new networks, then we must only do 3799f8829a4aSRandall Stewart * this for singly homed asoc's. However if the FR's 3800f8829a4aSRandall Stewart * go to the same network (Armando's work) then its 3801f8829a4aSRandall Stewart * ok to FR multiple times. 3802f8829a4aSRandall Stewart */ 38035e54f665SRandall Stewart (asoc->numnets < 2) 3804f8829a4aSRandall Stewart #else 38055e54f665SRandall Stewart (1) 3806f8829a4aSRandall Stewart #endif 38075e54f665SRandall Stewart ) { 38085e54f665SRandall Stewart 3809f8829a4aSRandall Stewart if ((compare_with_wrap(biggest_tsn_newly_acked, 3810f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn, MAX_TSN)) || 3811f8829a4aSRandall Stewart (biggest_tsn_newly_acked == 3812f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn)) { 3813f8829a4aSRandall Stewart /* 3814f8829a4aSRandall Stewart * Strike the TSN, since this ack is 3815f8829a4aSRandall Stewart * beyond where things were when we 3816f8829a4aSRandall Stewart * did a FR. 3817f8829a4aSRandall Stewart */ 3818b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3819f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3820f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3821f8829a4aSRandall Stewart tp1->sent, 3822f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 382380fefe0aSRandall Stewart } 38245e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3825f8829a4aSRandall Stewart tp1->sent++; 38265e54f665SRandall Stewart } 3827f8829a4aSRandall Stewart strike_flag = 1; 3828b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3829f8829a4aSRandall Stewart /* 3830f8829a4aSRandall Stewart * CMT DAC algorithm: If 3831f8829a4aSRandall Stewart * SACK flag is set to 0, 3832f8829a4aSRandall Stewart * then lowest_newack test 3833f8829a4aSRandall Stewart * will not pass because it 3834f8829a4aSRandall Stewart * would have been set to 3835f8829a4aSRandall Stewart * the cumack earlier. If 3836f8829a4aSRandall Stewart * not already to be rtx'd, 3837f8829a4aSRandall Stewart * If not a mixed sack and 3838f8829a4aSRandall Stewart * if tp1 is not between two 3839f8829a4aSRandall Stewart * sacked TSNs, then mark by 3840c105859eSRandall Stewart * one more. NOTE that we 3841c105859eSRandall Stewart * are marking by one 3842c105859eSRandall Stewart * additional time since the 3843c105859eSRandall Stewart * SACK DAC flag indicates 3844c105859eSRandall Stewart * that two packets have 3845c105859eSRandall Stewart * been received after this 3846c105859eSRandall Stewart * missing TSN. 3847f8829a4aSRandall Stewart */ 38485e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && 38495e54f665SRandall Stewart (num_dests_sacked == 1) && 38505e54f665SRandall Stewart compare_with_wrap(this_sack_lowest_newack, 38515e54f665SRandall Stewart tp1->rec.data.TSN_seq, MAX_TSN)) { 3852b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3853f8829a4aSRandall Stewart sctp_log_fr(32 + num_dests_sacked, 3854f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3855f8829a4aSRandall Stewart tp1->sent, 3856f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 385780fefe0aSRandall Stewart } 38585e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3859f8829a4aSRandall Stewart tp1->sent++; 38605e54f665SRandall Stewart } 3861f8829a4aSRandall Stewart } 3862f8829a4aSRandall Stewart } 3863f8829a4aSRandall Stewart } 3864f8829a4aSRandall Stewart } 3865f8829a4aSRandall Stewart /* 386642551e99SRandall Stewart * JRI: TODO: remove code for HTNA algo. CMT's SFR 386742551e99SRandall Stewart * algo covers HTNA. 3868f8829a4aSRandall Stewart */ 3869f8829a4aSRandall Stewart } else if (compare_with_wrap(tp1->rec.data.TSN_seq, 3870f8829a4aSRandall Stewart biggest_tsn_newly_acked, MAX_TSN)) { 3871f8829a4aSRandall Stewart /* 3872f8829a4aSRandall Stewart * We don't strike these: This is the HTNA 3873f8829a4aSRandall Stewart * algorithm i.e. we don't strike If our TSN is 3874f8829a4aSRandall Stewart * larger than the Highest TSN Newly Acked. 3875f8829a4aSRandall Stewart */ 3876f8829a4aSRandall Stewart ; 3877f8829a4aSRandall Stewart } else { 3878f8829a4aSRandall Stewart /* Strike the TSN */ 3879b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3880f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3881f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3882f8829a4aSRandall Stewart tp1->sent, 3883f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 388480fefe0aSRandall Stewart } 38855e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3886f8829a4aSRandall Stewart tp1->sent++; 38875e54f665SRandall Stewart } 3888b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3889f8829a4aSRandall Stewart /* 3890f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK flag is set to 3891f8829a4aSRandall Stewart * 0, then lowest_newack test will not pass 3892f8829a4aSRandall Stewart * because it would have been set to the 3893f8829a4aSRandall Stewart * cumack earlier. If not already to be 3894f8829a4aSRandall Stewart * rtx'd, If not a mixed sack and if tp1 is 3895f8829a4aSRandall Stewart * not between two sacked TSNs, then mark by 3896c105859eSRandall Stewart * one more. NOTE that we are marking by one 3897c105859eSRandall Stewart * additional time since the SACK DAC flag 3898c105859eSRandall Stewart * indicates that two packets have been 3899c105859eSRandall Stewart * received after this missing TSN. 3900f8829a4aSRandall Stewart */ 39015e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && 3902f8829a4aSRandall Stewart compare_with_wrap(this_sack_lowest_newack, tp1->rec.data.TSN_seq, MAX_TSN)) { 3903b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3904f8829a4aSRandall Stewart sctp_log_fr(48 + num_dests_sacked, 3905f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3906f8829a4aSRandall Stewart tp1->sent, 3907f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 390880fefe0aSRandall Stewart } 3909f8829a4aSRandall Stewart tp1->sent++; 3910f8829a4aSRandall Stewart } 3911f8829a4aSRandall Stewart } 3912f8829a4aSRandall Stewart } 3913f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 3914f8829a4aSRandall Stewart /* Increment the count to resend */ 3915f8829a4aSRandall Stewart struct sctp_nets *alt; 3916f8829a4aSRandall Stewart 3917f8829a4aSRandall Stewart /* printf("OK, we are now ready to FR this guy\n"); */ 3918b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3919f8829a4aSRandall Stewart sctp_log_fr(tp1->rec.data.TSN_seq, tp1->snd_count, 3920f8829a4aSRandall Stewart 0, SCTP_FR_MARKED); 392180fefe0aSRandall Stewart } 3922f8829a4aSRandall Stewart if (strike_flag) { 3923f8829a4aSRandall Stewart /* This is a subsequent FR */ 3924f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_sendmultfastretrans); 3925f8829a4aSRandall Stewart } 39265e54f665SRandall Stewart sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); 3927b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) { 3928f8829a4aSRandall Stewart /* 3929f8829a4aSRandall Stewart * CMT: Using RTX_SSTHRESH policy for CMT. 3930f8829a4aSRandall Stewart * If CMT is being used, then pick dest with 3931f8829a4aSRandall Stewart * largest ssthresh for any retransmission. 3932f8829a4aSRandall Stewart */ 3933f8829a4aSRandall Stewart tp1->no_fr_allowed = 1; 3934f8829a4aSRandall Stewart alt = tp1->whoTo; 39353c503c28SRandall Stewart /* sa_ignore NO_NULL_CHK */ 3936b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_pf)) { 3937b54d3a6cSRandall Stewart /* 3938b54d3a6cSRandall Stewart * JRS 5/18/07 - If CMT PF is on, 3939b54d3a6cSRandall Stewart * use the PF version of 3940b54d3a6cSRandall Stewart * find_alt_net() 3941b54d3a6cSRandall Stewart */ 3942b54d3a6cSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 2); 3943b54d3a6cSRandall Stewart } else { 3944b54d3a6cSRandall Stewart /* 3945b54d3a6cSRandall Stewart * JRS 5/18/07 - If only CMT is on, 3946b54d3a6cSRandall Stewart * use the CMT version of 3947b54d3a6cSRandall Stewart * find_alt_net() 3948b54d3a6cSRandall Stewart */ 394952be287eSRandall Stewart /* sa_ignore NO_NULL_CHK */ 3950f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 1); 3951b54d3a6cSRandall Stewart } 3952ad81507eSRandall Stewart if (alt == NULL) { 3953ad81507eSRandall Stewart alt = tp1->whoTo; 3954ad81507eSRandall Stewart } 3955f8829a4aSRandall Stewart /* 3956f8829a4aSRandall Stewart * CUCv2: If a different dest is picked for 3957f8829a4aSRandall Stewart * the retransmission, then new 3958f8829a4aSRandall Stewart * (rtx-)pseudo_cumack needs to be tracked 3959f8829a4aSRandall Stewart * for orig dest. Let CUCv2 track new (rtx-) 3960f8829a4aSRandall Stewart * pseudo-cumack always. 3961f8829a4aSRandall Stewart */ 3962ad81507eSRandall Stewart if (tp1->whoTo) { 3963f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 3964f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 3965ad81507eSRandall Stewart } 3966f8829a4aSRandall Stewart } else {/* CMT is OFF */ 3967f8829a4aSRandall Stewart 3968f8829a4aSRandall Stewart #ifdef SCTP_FR_TO_ALTERNATE 3969f8829a4aSRandall Stewart /* Can we find an alternate? */ 3970f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, tp1->whoTo, 0); 3971f8829a4aSRandall Stewart #else 3972f8829a4aSRandall Stewart /* 3973f8829a4aSRandall Stewart * default behavior is to NOT retransmit 3974f8829a4aSRandall Stewart * FR's to an alternate. Armando Caro's 3975f8829a4aSRandall Stewart * paper details why. 3976f8829a4aSRandall Stewart */ 3977f8829a4aSRandall Stewart alt = tp1->whoTo; 3978f8829a4aSRandall Stewart #endif 3979f8829a4aSRandall Stewart } 3980f8829a4aSRandall Stewart 3981f8829a4aSRandall Stewart tp1->rec.data.doing_fast_retransmit = 1; 3982f8829a4aSRandall Stewart tot_retrans++; 3983f8829a4aSRandall Stewart /* mark the sending seq for possible subsequent FR's */ 3984f8829a4aSRandall Stewart /* 3985f8829a4aSRandall Stewart * printf("Marking TSN for FR new value %x\n", 3986f8829a4aSRandall Stewart * (uint32_t)tpi->rec.data.TSN_seq); 3987f8829a4aSRandall Stewart */ 3988f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue)) { 3989f8829a4aSRandall Stewart /* 3990f8829a4aSRandall Stewart * If the queue of send is empty then its 3991f8829a4aSRandall Stewart * the next sequence number that will be 3992f8829a4aSRandall Stewart * assigned so we subtract one from this to 3993f8829a4aSRandall Stewart * get the one we last sent. 3994f8829a4aSRandall Stewart */ 3995f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = sending_seq; 3996f8829a4aSRandall Stewart } else { 3997f8829a4aSRandall Stewart /* 3998f8829a4aSRandall Stewart * If there are chunks on the send queue 3999f8829a4aSRandall Stewart * (unsent data that has made it from the 4000f8829a4aSRandall Stewart * stream queues but not out the door, we 4001f8829a4aSRandall Stewart * take the first one (which will have the 4002f8829a4aSRandall Stewart * lowest TSN) and subtract one to get the 4003f8829a4aSRandall Stewart * one we last sent. 4004f8829a4aSRandall Stewart */ 4005f8829a4aSRandall Stewart struct sctp_tmit_chunk *ttt; 4006f8829a4aSRandall Stewart 4007f8829a4aSRandall Stewart ttt = TAILQ_FIRST(&asoc->send_queue); 4008f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = 4009f8829a4aSRandall Stewart ttt->rec.data.TSN_seq; 4010f8829a4aSRandall Stewart } 4011f8829a4aSRandall Stewart 4012f8829a4aSRandall Stewart if (tp1->do_rtt) { 4013f8829a4aSRandall Stewart /* 4014f8829a4aSRandall Stewart * this guy had a RTO calculation pending on 4015f8829a4aSRandall Stewart * it, cancel it 4016f8829a4aSRandall Stewart */ 4017f8829a4aSRandall Stewart tp1->do_rtt = 0; 4018f8829a4aSRandall Stewart } 4019f8829a4aSRandall Stewart /* fix counts and things */ 4020b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4021c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND, 4022eacc51c5SRandall Stewart (tp1->whoTo ? (tp1->whoTo->flight_size) : 0), 4023a5d547adSRandall Stewart tp1->book_size, 4024c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4025a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 402680fefe0aSRandall Stewart } 4027ad81507eSRandall Stewart if (tp1->whoTo) { 4028f8829a4aSRandall Stewart tp1->whoTo->net_ack++; 4029c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 4030ad81507eSRandall Stewart } 4031b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4032f8829a4aSRandall Stewart sctp_log_rwnd(SCTP_INCREASE_PEER_RWND, 4033b3f1ea41SRandall Stewart asoc->peers_rwnd, tp1->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 403480fefe0aSRandall Stewart } 4035f8829a4aSRandall Stewart /* add back to the rwnd */ 4036b3f1ea41SRandall Stewart asoc->peers_rwnd += (tp1->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 4037f8829a4aSRandall Stewart 4038f8829a4aSRandall Stewart /* remove from the total flight */ 4039c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 4040f8829a4aSRandall Stewart if (alt != tp1->whoTo) { 4041f8829a4aSRandall Stewart /* yes, there is an alternate. */ 4042f8829a4aSRandall Stewart sctp_free_remote_addr(tp1->whoTo); 40433c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 4044f8829a4aSRandall Stewart tp1->whoTo = alt; 4045f8829a4aSRandall Stewart atomic_add_int(&alt->ref_count, 1); 4046f8829a4aSRandall Stewart } 4047f8829a4aSRandall Stewart } 4048f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 4049f8829a4aSRandall Stewart } /* while (tp1) */ 4050f8829a4aSRandall Stewart 4051f8829a4aSRandall Stewart if (tot_retrans > 0) { 4052f8829a4aSRandall Stewart /* 4053f8829a4aSRandall Stewart * Setup the ecn nonce re-sync point. We do this since once 4054f8829a4aSRandall Stewart * we go to FR something we introduce a Karn's rule scenario 4055f8829a4aSRandall Stewart * and won't know the totals for the ECN bits. 4056f8829a4aSRandall Stewart */ 4057f8829a4aSRandall Stewart asoc->nonce_resync_tsn = sending_seq; 4058f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 0; 4059f8829a4aSRandall Stewart asoc->nonce_sum_check = 0; 4060f8829a4aSRandall Stewart } 4061f8829a4aSRandall Stewart } 4062f8829a4aSRandall Stewart 4063f8829a4aSRandall Stewart struct sctp_tmit_chunk * 4064f8829a4aSRandall Stewart sctp_try_advance_peer_ack_point(struct sctp_tcb *stcb, 4065f8829a4aSRandall Stewart struct sctp_association *asoc) 4066f8829a4aSRandall Stewart { 4067f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2, *a_adv = NULL; 4068f8829a4aSRandall Stewart struct timeval now; 4069f8829a4aSRandall Stewart int now_filled = 0; 4070f8829a4aSRandall Stewart 4071f8829a4aSRandall Stewart if (asoc->peer_supports_prsctp == 0) { 4072f8829a4aSRandall Stewart return (NULL); 4073f8829a4aSRandall Stewart } 4074f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 4075f8829a4aSRandall Stewart while (tp1) { 4076f8829a4aSRandall Stewart if (tp1->sent != SCTP_FORWARD_TSN_SKIP && 4077f8829a4aSRandall Stewart tp1->sent != SCTP_DATAGRAM_RESEND) { 4078f8829a4aSRandall Stewart /* no chance to advance, out of here */ 4079f8829a4aSRandall Stewart break; 4080f8829a4aSRandall Stewart } 4081f8829a4aSRandall Stewart if (!PR_SCTP_ENABLED(tp1->flags)) { 4082f8829a4aSRandall Stewart /* 4083f8829a4aSRandall Stewart * We can't fwd-tsn past any that are reliable aka 4084f8829a4aSRandall Stewart * retransmitted until the asoc fails. 4085f8829a4aSRandall Stewart */ 4086f8829a4aSRandall Stewart break; 4087f8829a4aSRandall Stewart } 4088f8829a4aSRandall Stewart if (!now_filled) { 40896e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 4090f8829a4aSRandall Stewart now_filled = 1; 4091f8829a4aSRandall Stewart } 4092f8829a4aSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 4093f8829a4aSRandall Stewart /* 4094f8829a4aSRandall Stewart * now we got a chunk which is marked for another 4095f8829a4aSRandall Stewart * retransmission to a PR-stream but has run out its chances 4096f8829a4aSRandall Stewart * already maybe OR has been marked to skip now. Can we skip 4097f8829a4aSRandall Stewart * it if its a resend? 4098f8829a4aSRandall Stewart */ 4099f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND && 4100f8829a4aSRandall Stewart (PR_SCTP_TTL_ENABLED(tp1->flags))) { 4101f8829a4aSRandall Stewart /* 4102f8829a4aSRandall Stewart * Now is this one marked for resend and its time is 4103f8829a4aSRandall Stewart * now up? 4104f8829a4aSRandall Stewart */ 4105f8829a4aSRandall Stewart if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) { 4106f8829a4aSRandall Stewart /* Yes so drop it */ 4107f8829a4aSRandall Stewart if (tp1->data) { 4108ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 4109f8829a4aSRandall Stewart (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 4110ceaad40aSRandall Stewart &asoc->sent_queue, SCTP_SO_NOT_LOCKED); 4111f8829a4aSRandall Stewart } 4112f8829a4aSRandall Stewart } else { 4113f8829a4aSRandall Stewart /* 4114f8829a4aSRandall Stewart * No, we are done when hit one for resend 4115f8829a4aSRandall Stewart * whos time as not expired. 4116f8829a4aSRandall Stewart */ 4117f8829a4aSRandall Stewart break; 4118f8829a4aSRandall Stewart } 4119f8829a4aSRandall Stewart } 4120f8829a4aSRandall Stewart /* 4121f8829a4aSRandall Stewart * Ok now if this chunk is marked to drop it we can clean up 4122f8829a4aSRandall Stewart * the chunk, advance our peer ack point and we can check 4123f8829a4aSRandall Stewart * the next chunk. 4124f8829a4aSRandall Stewart */ 4125f8829a4aSRandall Stewart if (tp1->sent == SCTP_FORWARD_TSN_SKIP) { 4126f8829a4aSRandall Stewart /* advance PeerAckPoint goes forward */ 4127f8829a4aSRandall Stewart asoc->advanced_peer_ack_point = tp1->rec.data.TSN_seq; 4128f8829a4aSRandall Stewart a_adv = tp1; 4129f8829a4aSRandall Stewart } else { 4130f8829a4aSRandall Stewart /* 4131f8829a4aSRandall Stewart * If it is still in RESEND we can advance no 4132f8829a4aSRandall Stewart * further 4133f8829a4aSRandall Stewart */ 4134f8829a4aSRandall Stewart break; 4135f8829a4aSRandall Stewart } 4136f8829a4aSRandall Stewart /* 4137f8829a4aSRandall Stewart * If we hit here we just dumped tp1, move to next tsn on 4138f8829a4aSRandall Stewart * sent queue. 4139f8829a4aSRandall Stewart */ 4140f8829a4aSRandall Stewart tp1 = tp2; 4141f8829a4aSRandall Stewart } 4142f8829a4aSRandall Stewart return (a_adv); 4143f8829a4aSRandall Stewart } 4144f8829a4aSRandall Stewart 4145bff64a4dSRandall Stewart static void 4146c105859eSRandall Stewart sctp_fs_audit(struct sctp_association *asoc) 4147bff64a4dSRandall Stewart { 4148bff64a4dSRandall Stewart struct sctp_tmit_chunk *chk; 4149bff64a4dSRandall Stewart int inflight = 0, resend = 0, inbetween = 0, acked = 0, above = 0; 4150bff64a4dSRandall Stewart 4151bff64a4dSRandall Stewart TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { 4152bff64a4dSRandall Stewart if (chk->sent < SCTP_DATAGRAM_RESEND) { 4153bff64a4dSRandall Stewart inflight++; 4154bff64a4dSRandall Stewart } else if (chk->sent == SCTP_DATAGRAM_RESEND) { 4155bff64a4dSRandall Stewart resend++; 4156bff64a4dSRandall Stewart } else if (chk->sent < SCTP_DATAGRAM_ACKED) { 4157bff64a4dSRandall Stewart inbetween++; 4158bff64a4dSRandall Stewart } else if (chk->sent > SCTP_DATAGRAM_ACKED) { 4159bff64a4dSRandall Stewart above++; 4160bff64a4dSRandall Stewart } else { 4161bff64a4dSRandall Stewart acked++; 4162bff64a4dSRandall Stewart } 4163bff64a4dSRandall Stewart } 4164f1f73e57SRandall Stewart 4165c105859eSRandall Stewart if ((inflight > 0) || (inbetween > 0)) { 4166f1f73e57SRandall Stewart #ifdef INVARIANTS 4167c105859eSRandall Stewart panic("Flight size-express incorrect? \n"); 4168f1f73e57SRandall Stewart #else 4169ad81507eSRandall Stewart SCTP_PRINTF("Flight size-express incorrect inflight:%d inbetween:%d\n", 4170f1f73e57SRandall Stewart inflight, inbetween); 4171f1f73e57SRandall Stewart #endif 4172bff64a4dSRandall Stewart } 4173c105859eSRandall Stewart } 4174c105859eSRandall Stewart 4175c105859eSRandall Stewart 4176c105859eSRandall Stewart static void 4177c105859eSRandall Stewart sctp_window_probe_recovery(struct sctp_tcb *stcb, 4178c105859eSRandall Stewart struct sctp_association *asoc, 4179c105859eSRandall Stewart struct sctp_nets *net, 4180c105859eSRandall Stewart struct sctp_tmit_chunk *tp1) 4181c105859eSRandall Stewart { 4182dfb11ef8SRandall Stewart tp1->window_probe = 0; 41835171328bSRandall Stewart if ((tp1->sent >= SCTP_DATAGRAM_ACKED) || (tp1->data == NULL)) { 4184dfb11ef8SRandall Stewart /* TSN's skipped we do NOT move back. */ 4185dfb11ef8SRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DWN_WP_FWD, 4186dfb11ef8SRandall Stewart tp1->whoTo->flight_size, 4187dfb11ef8SRandall Stewart tp1->book_size, 4188dfb11ef8SRandall Stewart (uintptr_t) tp1->whoTo, 4189dfb11ef8SRandall Stewart tp1->rec.data.TSN_seq); 4190dfb11ef8SRandall Stewart return; 4191dfb11ef8SRandall Stewart } 41925171328bSRandall Stewart /* First setup this by shrinking flight */ 41935171328bSRandall Stewart sctp_flight_size_decrease(tp1); 41945171328bSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 41955171328bSRandall Stewart /* Now mark for resend */ 41965171328bSRandall Stewart tp1->sent = SCTP_DATAGRAM_RESEND; 41975171328bSRandall Stewart asoc->sent_queue_retran_cnt++; 4198b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4199c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_WP, 4200c105859eSRandall Stewart tp1->whoTo->flight_size, 4201c105859eSRandall Stewart tp1->book_size, 4202c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4203c105859eSRandall Stewart tp1->rec.data.TSN_seq); 420480fefe0aSRandall Stewart } 4205c105859eSRandall Stewart } 4206c105859eSRandall Stewart 4207f8829a4aSRandall Stewart void 4208f8829a4aSRandall Stewart sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, 4209f8829a4aSRandall Stewart uint32_t rwnd, int nonce_sum_flag, int *abort_now) 4210f8829a4aSRandall Stewart { 4211f8829a4aSRandall Stewart struct sctp_nets *net; 4212f8829a4aSRandall Stewart struct sctp_association *asoc; 4213f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 42145e54f665SRandall Stewart uint32_t old_rwnd; 42155e54f665SRandall Stewart int win_probe_recovery = 0; 4216c105859eSRandall Stewart int win_probe_recovered = 0; 4217d06c82f1SRandall Stewart int j, done_once = 0; 4218f8829a4aSRandall Stewart 4219b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 4220d06c82f1SRandall Stewart sctp_misc_ints(SCTP_SACK_LOG_EXPRESS, cumack, 4221d06c82f1SRandall Stewart rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 422280fefe0aSRandall Stewart } 4223f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 422418e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 422518e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cumack; 422618e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 422718e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 422818e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 422918e198d3SRandall Stewart } 423018e198d3SRandall Stewart #endif 4231f8829a4aSRandall Stewart asoc = &stcb->asoc; 4232d06c82f1SRandall Stewart old_rwnd = asoc->peers_rwnd; 42335e54f665SRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, cumack, MAX_TSN)) { 42345e54f665SRandall Stewart /* old ack */ 42355e54f665SRandall Stewart return; 4236d06c82f1SRandall Stewart } else if (asoc->last_acked_seq == cumack) { 4237d06c82f1SRandall Stewart /* Window update sack */ 4238d06c82f1SRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 4239b3f1ea41SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 4240d06c82f1SRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4241d06c82f1SRandall Stewart /* SWS sender side engages */ 4242d06c82f1SRandall Stewart asoc->peers_rwnd = 0; 4243d06c82f1SRandall Stewart } 4244d06c82f1SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 4245d06c82f1SRandall Stewart goto again; 4246d06c82f1SRandall Stewart } 4247d06c82f1SRandall Stewart return; 42485e54f665SRandall Stewart } 4249f8829a4aSRandall Stewart /* First setup for CC stuff */ 4250f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4251f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 4252f8829a4aSRandall Stewart net->net_ack = 0; 4253f8829a4aSRandall Stewart net->net_ack2 = 0; 4254132dea7dSRandall Stewart 4255132dea7dSRandall Stewart /* 4256132dea7dSRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 4257132dea7dSRandall Stewart * SACK processing 4258132dea7dSRandall Stewart */ 4259132dea7dSRandall Stewart net->new_pseudo_cumack = 0; 4260132dea7dSRandall Stewart net->will_exit_fast_recovery = 0; 4261f8829a4aSRandall Stewart } 4262b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 4263139bc87fSRandall Stewart uint32_t send_s; 4264139bc87fSRandall Stewart 4265c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 4266c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 4267c105859eSRandall Stewart sctpchunk_listhead); 4268c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 4269139bc87fSRandall Stewart } else { 4270c105859eSRandall Stewart send_s = asoc->sending_seq; 4271139bc87fSRandall Stewart } 4272139bc87fSRandall Stewart if ((cumack == send_s) || 4273139bc87fSRandall Stewart compare_with_wrap(cumack, send_s, MAX_TSN)) { 4274c105859eSRandall Stewart #ifndef INVARIANTS 4275139bc87fSRandall Stewart struct mbuf *oper; 4276139bc87fSRandall Stewart 4277c105859eSRandall Stewart #endif 4278c105859eSRandall Stewart #ifdef INVARIANTS 4279c105859eSRandall Stewart panic("Impossible sack 1"); 4280c105859eSRandall Stewart #else 4281139bc87fSRandall Stewart *abort_now = 1; 4282139bc87fSRandall Stewart /* XXX */ 4283139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4284139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4285139bc87fSRandall Stewart if (oper) { 4286139bc87fSRandall Stewart struct sctp_paramhdr *ph; 4287139bc87fSRandall Stewart uint32_t *ippp; 4288139bc87fSRandall Stewart 4289139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4290139bc87fSRandall Stewart sizeof(uint32_t); 4291139bc87fSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4292139bc87fSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 4293139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4294139bc87fSRandall Stewart ippp = (uint32_t *) (ph + 1); 4295139bc87fSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 4296139bc87fSRandall Stewart } 4297139bc87fSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 4298ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 4299139bc87fSRandall Stewart return; 4300139bc87fSRandall Stewart #endif 4301139bc87fSRandall Stewart } 4302139bc87fSRandall Stewart } 4303f8829a4aSRandall Stewart asoc->this_sack_highest_gap = cumack; 4304b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 4305c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 4306c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 4307c4739e2fSRandall Stewart 0, 4308c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 4309c4739e2fSRandall Stewart __LINE__); 4310c4739e2fSRandall Stewart } 4311f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 43125e54f665SRandall Stewart if (compare_with_wrap(cumack, asoc->last_acked_seq, MAX_TSN)) { 4313f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 4314f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 4315f8829a4aSRandall Stewart while (tp1) { 4316f8829a4aSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 4317f8829a4aSRandall Stewart if (compare_with_wrap(cumack, tp1->rec.data.TSN_seq, 4318f8829a4aSRandall Stewart MAX_TSN) || 4319f8829a4aSRandall Stewart cumack == tp1->rec.data.TSN_seq) { 432018e198d3SRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 432118e198d3SRandall Stewart printf("Warning, an unsent is now acked?\n"); 432218e198d3SRandall Stewart } 4323f8829a4aSRandall Stewart /* 432418e198d3SRandall Stewart * ECN Nonce: Add the nonce to the sender's 432518e198d3SRandall Stewart * nonce sum 4326f8829a4aSRandall Stewart */ 4327f8829a4aSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 4328f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 4329f8829a4aSRandall Stewart /* 433018e198d3SRandall Stewart * If it is less than ACKED, it is 433118e198d3SRandall Stewart * now no-longer in flight. Higher 433218e198d3SRandall Stewart * values may occur during marking 4333f8829a4aSRandall Stewart */ 4334c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4335b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4336c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 4337a5d547adSRandall Stewart tp1->whoTo->flight_size, 4338a5d547adSRandall Stewart tp1->book_size, 4339c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4340a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 434180fefe0aSRandall Stewart } 4342c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 434304ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4344c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 4345f8829a4aSRandall Stewart } 4346f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 4347f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 4348f8829a4aSRandall Stewart /* 434918e198d3SRandall Stewart * True non-retransmited 4350f8829a4aSRandall Stewart * chunk 4351f8829a4aSRandall Stewart */ 4352f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 4353f8829a4aSRandall Stewart tp1->send_size; 4354f8829a4aSRandall Stewart 4355f8829a4aSRandall Stewart /* update RTO too? */ 435662c1ff9cSRandall Stewart if (tp1->do_rtt) { 4357f8829a4aSRandall Stewart tp1->whoTo->RTO = 435804ee05e8SRandall Stewart /* 435904ee05e8SRandall Stewart * sa_ignore 436004ee05e8SRandall Stewart * NO_NULL_CHK 436104ee05e8SRandall Stewart */ 4362f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 4363f8829a4aSRandall Stewart asoc, tp1->whoTo, 436418e198d3SRandall Stewart &tp1->sent_rcv_time, 436518e198d3SRandall Stewart sctp_align_safe_nocopy); 4366f8829a4aSRandall Stewart tp1->do_rtt = 0; 4367f8829a4aSRandall Stewart } 4368f8829a4aSRandall Stewart } 4369132dea7dSRandall Stewart /* 437018e198d3SRandall Stewart * CMT: CUCv2 algorithm. From the 437118e198d3SRandall Stewart * cumack'd TSNs, for each TSN being 437218e198d3SRandall Stewart * acked for the first time, set the 437318e198d3SRandall Stewart * following variables for the 437418e198d3SRandall Stewart * corresp destination. 437518e198d3SRandall Stewart * new_pseudo_cumack will trigger a 437618e198d3SRandall Stewart * cwnd update. 437718e198d3SRandall Stewart * find_(rtx_)pseudo_cumack will 437818e198d3SRandall Stewart * trigger search for the next 437918e198d3SRandall Stewart * expected (rtx-)pseudo-cumack. 4380132dea7dSRandall Stewart */ 4381132dea7dSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 4382132dea7dSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 4383132dea7dSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 4384132dea7dSRandall Stewart 4385b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 438604ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4387f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 438880fefe0aSRandall Stewart } 4389f8829a4aSRandall Stewart } 4390f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4391f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 4392f8829a4aSRandall Stewart } 439342551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 439442551e99SRandall Stewart /* deflate the cwnd */ 439542551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 439642551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 439742551e99SRandall Stewart } 4398f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 4399f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 4400f8829a4aSRandall Stewart if (tp1->data) { 440104ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4402f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 4403f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 4404f8829a4aSRandall Stewart } 4405b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4406f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4407f8829a4aSRandall Stewart cumack, 4408f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4409f8829a4aSRandall Stewart 0, 4410f8829a4aSRandall Stewart 0, 4411f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 441280fefe0aSRandall Stewart } 4413f8829a4aSRandall Stewart tp1->data = NULL; 4414f8829a4aSRandall Stewart asoc->sent_queue_cnt--; 4415f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, tp1); 4416f8829a4aSRandall Stewart tp1 = tp2; 441718e198d3SRandall Stewart } else { 441818e198d3SRandall Stewart break; 4419f8829a4aSRandall Stewart } 44205e54f665SRandall Stewart } 442118e198d3SRandall Stewart 442218e198d3SRandall Stewart } 442304ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4424f8829a4aSRandall Stewart if (stcb->sctp_socket) { 4425ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4426ceaad40aSRandall Stewart struct socket *so; 4427ceaad40aSRandall Stewart 4428ceaad40aSRandall Stewart #endif 4429ceaad40aSRandall Stewart 4430f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 4431b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 443204ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4433f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_WAKESND_FROM_SACK); 443480fefe0aSRandall Stewart } 4435ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4436ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 4437ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 4438ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 4439ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 4440ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 4441ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 4442ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 4443ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 4444ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4445ceaad40aSRandall Stewart return; 4446ceaad40aSRandall Stewart } 4447ceaad40aSRandall Stewart #endif 4448f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 4449ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4450ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4451ceaad40aSRandall Stewart #endif 4452f8829a4aSRandall Stewart } else { 4453b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4454f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_NOWAKE_FROM_SACK); 445580fefe0aSRandall Stewart } 4456f8829a4aSRandall Stewart } 4457f8829a4aSRandall Stewart 4458b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4459f8829a4aSRandall Stewart if (asoc->last_acked_seq != cumack) 4460b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, 1, 0, 0); 44615e54f665SRandall Stewart 4462f8829a4aSRandall Stewart asoc->last_acked_seq = cumack; 44635e54f665SRandall Stewart 4464f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 4465f8829a4aSRandall Stewart /* nothing left in-flight */ 4466f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4467f8829a4aSRandall Stewart net->flight_size = 0; 4468f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4469f8829a4aSRandall Stewart } 4470f8829a4aSRandall Stewart asoc->total_flight = 0; 4471f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4472f8829a4aSRandall Stewart } 4473f8829a4aSRandall Stewart /* ECN Nonce updates */ 4474f8829a4aSRandall Stewart if (asoc->ecn_nonce_allowed) { 4475f8829a4aSRandall Stewart if (asoc->nonce_sum_check) { 4476f8829a4aSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base) & SCTP_SACK_NONCE_SUM)) { 4477f8829a4aSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 4478f8829a4aSRandall Stewart struct sctp_tmit_chunk *lchk; 4479f8829a4aSRandall Stewart 4480f8829a4aSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 4481f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 1; 4482f8829a4aSRandall Stewart if (lchk) { 4483f8829a4aSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 4484f8829a4aSRandall Stewart } else { 4485f8829a4aSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 4486f8829a4aSRandall Stewart } 4487f8829a4aSRandall Stewart } else { 4488f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) || 4489f8829a4aSRandall Stewart (asoc->last_acked_seq == asoc->nonce_wait_tsn)) { 4490f8829a4aSRandall Stewart /* 4491f8829a4aSRandall Stewart * Misbehaving peer. We need 4492f8829a4aSRandall Stewart * to react to this guy 4493f8829a4aSRandall Stewart */ 4494f8829a4aSRandall Stewart asoc->ecn_allowed = 0; 4495f8829a4aSRandall Stewart asoc->ecn_nonce_allowed = 0; 4496f8829a4aSRandall Stewart } 4497f8829a4aSRandall Stewart } 4498f8829a4aSRandall Stewart } 4499f8829a4aSRandall Stewart } else { 4500f8829a4aSRandall Stewart /* See if Resynchronization Possible */ 4501f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) { 4502f8829a4aSRandall Stewart asoc->nonce_sum_check = 1; 4503f8829a4aSRandall Stewart /* 4504f8829a4aSRandall Stewart * now we must calculate what the base is. 4505f8829a4aSRandall Stewart * We do this based on two things, we know 4506f8829a4aSRandall Stewart * the total's for all the segments 4507f8829a4aSRandall Stewart * gap-acked in the SACK (none), We also 4508f8829a4aSRandall Stewart * know the SACK's nonce sum, its in 4509f8829a4aSRandall Stewart * nonce_sum_flag. So we can build a truth 4510f8829a4aSRandall Stewart * table to back-calculate the new value of 4511f8829a4aSRandall Stewart * asoc->nonce_sum_expect_base: 4512f8829a4aSRandall Stewart * 4513f8829a4aSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 4514f8829a4aSRandall Stewart * 1 0 1 0 1 1 1 4515f8829a4aSRandall Stewart * 1 0 4516f8829a4aSRandall Stewart */ 4517f8829a4aSRandall Stewart asoc->nonce_sum_expect_base = (0 ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 4518f8829a4aSRandall Stewart } 4519f8829a4aSRandall Stewart } 4520f8829a4aSRandall Stewart } 4521f8829a4aSRandall Stewart /* RWND update */ 4522f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 4523b3f1ea41SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 4524f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4525f8829a4aSRandall Stewart /* SWS sender side engages */ 4526f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4527f8829a4aSRandall Stewart } 45285e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 45295e54f665SRandall Stewart win_probe_recovery = 1; 45305e54f665SRandall Stewart } 4531f8829a4aSRandall Stewart /* Now assure a timer where data is queued at */ 4532a5d547adSRandall Stewart again: 4533a5d547adSRandall Stewart j = 0; 4534f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 45355171328bSRandall Stewart int to_ticks; 45365171328bSRandall Stewart 45375e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 4538c105859eSRandall Stewart win_probe_recovered = 1; 45395e54f665SRandall Stewart /* 45405e54f665SRandall Stewart * Find first chunk that was used with window probe 45415e54f665SRandall Stewart * and clear the sent 45425e54f665SRandall Stewart */ 45433c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 45445e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 45455e54f665SRandall Stewart if (tp1->window_probe) { 4546c105859eSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 45475e54f665SRandall Stewart break; 45485e54f665SRandall Stewart } 45495e54f665SRandall Stewart } 45505e54f665SRandall Stewart } 4551f8829a4aSRandall Stewart if (net->RTO == 0) { 4552f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto); 4553f8829a4aSRandall Stewart } else { 4554f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(net->RTO); 4555f8829a4aSRandall Stewart } 45565171328bSRandall Stewart if (net->flight_size) { 4557a5d547adSRandall Stewart j++; 4558ad81507eSRandall Stewart (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 4559f8829a4aSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 45605171328bSRandall Stewart if (net->window_probe) { 45615171328bSRandall Stewart net->window_probe = 0; 45625171328bSRandall Stewart } 4563f8829a4aSRandall Stewart } else { 45645171328bSRandall Stewart if (net->window_probe) { 45655171328bSRandall Stewart /* 45665171328bSRandall Stewart * In window probes we must assure a timer 45675171328bSRandall Stewart * is still running there 45685171328bSRandall Stewart */ 45695171328bSRandall Stewart net->window_probe = 0; 45705171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 45715171328bSRandall Stewart SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 45725171328bSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 45735171328bSRandall Stewart } 45745171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 4575f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4576a5d547adSRandall Stewart stcb, net, 4577a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 4578f8829a4aSRandall Stewart } 4579b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4580139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4581f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 4582a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4583a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 4584f8829a4aSRandall Stewart } 4585f8829a4aSRandall Stewart } 4586f8829a4aSRandall Stewart } 4587f8829a4aSRandall Stewart } 4588bff64a4dSRandall Stewart if ((j == 0) && 4589bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 4590bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 4591c105859eSRandall Stewart (win_probe_recovered == 0) && 4592bff64a4dSRandall Stewart (done_once == 0)) { 4593a5d547adSRandall Stewart /* huh, this should not happen */ 4594c105859eSRandall Stewart sctp_fs_audit(asoc); 4595a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4596a5d547adSRandall Stewart net->flight_size = 0; 4597a5d547adSRandall Stewart } 4598a5d547adSRandall Stewart asoc->total_flight = 0; 4599a5d547adSRandall Stewart asoc->total_flight_count = 0; 4600a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4601a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4602a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4603c105859eSRandall Stewart sctp_flight_size_increase(tp1); 4604c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 4605a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4606a5d547adSRandall Stewart asoc->sent_queue_retran_cnt++; 4607a5d547adSRandall Stewart } 4608a5d547adSRandall Stewart } 4609bff64a4dSRandall Stewart done_once = 1; 4610a5d547adSRandall Stewart goto again; 4611a5d547adSRandall Stewart } 4612f8829a4aSRandall Stewart /**********************************/ 4613f8829a4aSRandall Stewart /* Now what about shutdown issues */ 4614f8829a4aSRandall Stewart /**********************************/ 4615f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 4616f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 4617f8829a4aSRandall Stewart /* clean up */ 4618f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 4619f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 4620f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 4621f8829a4aSRandall Stewart (asoc->locked_on_sending) 4622f8829a4aSRandall Stewart ) { 4623f8829a4aSRandall Stewart struct sctp_stream_queue_pending *sp; 4624f8829a4aSRandall Stewart 4625f8829a4aSRandall Stewart /* 4626f8829a4aSRandall Stewart * I may be in a state where we got all across.. but 4627f8829a4aSRandall Stewart * cannot write more due to a shutdown... we abort 4628f8829a4aSRandall Stewart * since the user did not indicate EOR in this case. 4629f8829a4aSRandall Stewart * The sp will be cleaned during free of the asoc. 4630f8829a4aSRandall Stewart */ 4631f8829a4aSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 4632f8829a4aSRandall Stewart sctp_streamhead); 46332afb3e84SRandall Stewart if ((sp) && (sp->length == 0)) { 46342afb3e84SRandall Stewart /* Let cleanup code purge it */ 46352afb3e84SRandall Stewart if (sp->msg_is_complete) { 46362afb3e84SRandall Stewart asoc->stream_queue_cnt--; 46372afb3e84SRandall Stewart } else { 4638f8829a4aSRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 4639f8829a4aSRandall Stewart asoc->locked_on_sending = NULL; 4640f8829a4aSRandall Stewart asoc->stream_queue_cnt--; 4641f8829a4aSRandall Stewart } 4642f8829a4aSRandall Stewart } 46432afb3e84SRandall Stewart } 4644f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 4645f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4646f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4647f8829a4aSRandall Stewart /* Need to abort here */ 4648f8829a4aSRandall Stewart struct mbuf *oper; 4649f8829a4aSRandall Stewart 4650f8829a4aSRandall Stewart abort_out_now: 4651f8829a4aSRandall Stewart *abort_now = 1; 4652f8829a4aSRandall Stewart /* XXX */ 4653f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4654f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4655f8829a4aSRandall Stewart if (oper) { 4656f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 4657f8829a4aSRandall Stewart uint32_t *ippp; 4658f8829a4aSRandall Stewart 4659139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4660f8829a4aSRandall Stewart sizeof(uint32_t); 4661f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4662f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 4663139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4664f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 4665a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_24); 4666f8829a4aSRandall Stewart } 4667a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24; 4668ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 4669f8829a4aSRandall Stewart } else { 4670f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 4671f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 4672f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4673f42a358aSRandall Stewart } 4674c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 4675b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4676f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 4677f8829a4aSRandall Stewart sctp_send_shutdown(stcb, 4678f8829a4aSRandall Stewart stcb->asoc.primary_destination); 4679f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 4680f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4681f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 4682f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4683f8829a4aSRandall Stewart } 4684f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 4685f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4686f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4687f8829a4aSRandall Stewart goto abort_out_now; 4688f8829a4aSRandall Stewart } 4689f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4690c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 4691b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4692f8829a4aSRandall Stewart sctp_send_shutdown_ack(stcb, 4693f8829a4aSRandall Stewart stcb->asoc.primary_destination); 4694f8829a4aSRandall Stewart 4695f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 4696f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4697f8829a4aSRandall Stewart } 4698f8829a4aSRandall Stewart } 4699dfb11ef8SRandall Stewart /*********************************************/ 4700dfb11ef8SRandall Stewart /* Here we perform PR-SCTP procedures */ 4701dfb11ef8SRandall Stewart /* (section 4.2) */ 4702dfb11ef8SRandall Stewart /*********************************************/ 4703dfb11ef8SRandall Stewart /* C1. update advancedPeerAckPoint */ 4704dfb11ef8SRandall Stewart if (compare_with_wrap(cumack, asoc->advanced_peer_ack_point, MAX_TSN)) { 4705dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cumack; 4706dfb11ef8SRandall Stewart } 4707830d754dSRandall Stewart /* PR-Sctp issues need to be addressed too */ 4708830d754dSRandall Stewart if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) { 4709830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 4710830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 4711830d754dSRandall Stewart 4712830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 4713830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 4714830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 4715830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, cumack, 4716830d754dSRandall Stewart MAX_TSN)) { 4717830d754dSRandall Stewart /* 4718830d754dSRandall Stewart * ISSUE with ECN, see FWD-TSN processing for notes 4719830d754dSRandall Stewart * on issues that will occur when the ECN NONCE 4720830d754dSRandall Stewart * stuff is put into SCTP for cross checking. 4721830d754dSRandall Stewart */ 4722830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, old_adv_peer_ack_point, 4723830d754dSRandall Stewart MAX_TSN)) { 4724830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 4725830d754dSRandall Stewart /* 4726830d754dSRandall Stewart * ECN Nonce: Disable Nonce Sum check when 4727830d754dSRandall Stewart * FWD TSN is sent and store resync tsn 4728830d754dSRandall Stewart */ 4729830d754dSRandall Stewart asoc->nonce_sum_check = 0; 4730830d754dSRandall Stewart asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point; 4731830d754dSRandall Stewart } 4732830d754dSRandall Stewart } 4733830d754dSRandall Stewart if (lchk) { 4734830d754dSRandall Stewart /* Assure a timer is up */ 4735830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 4736830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 4737830d754dSRandall Stewart } 4738830d754dSRandall Stewart } 4739b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 4740f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 4741f8829a4aSRandall Stewart rwnd, 4742f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 4743f8829a4aSRandall Stewart stcb->asoc.total_flight, 4744f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 474580fefe0aSRandall Stewart } 4746f8829a4aSRandall Stewart } 4747f8829a4aSRandall Stewart 4748f8829a4aSRandall Stewart void 4749458303daSRandall Stewart sctp_handle_sack(struct mbuf *m, int offset, 4750458303daSRandall Stewart struct sctp_sack_chunk *ch, struct sctp_tcb *stcb, 4751d06c82f1SRandall Stewart struct sctp_nets *net_from, int *abort_now, int sack_len, uint32_t rwnd) 4752f8829a4aSRandall Stewart { 4753f8829a4aSRandall Stewart struct sctp_association *asoc; 4754f8829a4aSRandall Stewart struct sctp_sack *sack; 4755f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 4756f8829a4aSRandall Stewart uint32_t cum_ack, last_tsn, biggest_tsn_acked, biggest_tsn_newly_acked, 4757f8829a4aSRandall Stewart this_sack_lowest_newack; 4758bff64a4dSRandall Stewart uint32_t sav_cum_ack; 4759f8829a4aSRandall Stewart uint16_t num_seg, num_dup; 4760f8829a4aSRandall Stewart uint16_t wake_him = 0; 4761f8829a4aSRandall Stewart unsigned int sack_length; 4762c105859eSRandall Stewart uint32_t send_s = 0; 4763f8829a4aSRandall Stewart long j; 4764f8829a4aSRandall Stewart int accum_moved = 0; 4765f8829a4aSRandall Stewart int will_exit_fast_recovery = 0; 47665e54f665SRandall Stewart uint32_t a_rwnd, old_rwnd; 47675e54f665SRandall Stewart int win_probe_recovery = 0; 4768c105859eSRandall Stewart int win_probe_recovered = 0; 4769f8829a4aSRandall Stewart struct sctp_nets *net = NULL; 4770f8829a4aSRandall Stewart int nonce_sum_flag, ecn_seg_sums = 0; 4771bff64a4dSRandall Stewart int done_once; 4772f8829a4aSRandall Stewart uint8_t reneged_all = 0; 4773f8829a4aSRandall Stewart uint8_t cmt_dac_flag; 4774f8829a4aSRandall Stewart 4775f8829a4aSRandall Stewart /* 4776f8829a4aSRandall Stewart * we take any chance we can to service our queues since we cannot 4777f8829a4aSRandall Stewart * get awoken when the socket is read from :< 4778f8829a4aSRandall Stewart */ 4779f8829a4aSRandall Stewart /* 4780f8829a4aSRandall Stewart * Now perform the actual SACK handling: 1) Verify that it is not an 4781f8829a4aSRandall Stewart * old sack, if so discard. 2) If there is nothing left in the send 4782f8829a4aSRandall Stewart * queue (cum-ack is equal to last acked) then you have a duplicate 4783f8829a4aSRandall Stewart * too, update any rwnd change and verify no timers are running. 4784f8829a4aSRandall Stewart * then return. 3) Process any new consequtive data i.e. cum-ack 4785f8829a4aSRandall Stewart * moved process these first and note that it moved. 4) Process any 4786f8829a4aSRandall Stewart * sack blocks. 5) Drop any acked from the queue. 6) Check for any 4787f8829a4aSRandall Stewart * revoked blocks and mark. 7) Update the cwnd. 8) Nothing left, 4788f8829a4aSRandall Stewart * sync up flightsizes and things, stop all timers and also check 4789f8829a4aSRandall Stewart * for shutdown_pending state. If so then go ahead and send off the 4790f8829a4aSRandall Stewart * shutdown. If in shutdown recv, send off the shutdown-ack and 4791f8829a4aSRandall Stewart * start that timer, Ret. 9) Strike any non-acked things and do FR 4792f8829a4aSRandall Stewart * procedure if needed being sure to set the FR flag. 10) Do pr-sctp 4793f8829a4aSRandall Stewart * procedures. 11) Apply any FR penalties. 12) Assure we will SACK 4794f8829a4aSRandall Stewart * if in shutdown_recv state. 4795f8829a4aSRandall Stewart */ 4796f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 4797f8829a4aSRandall Stewart sack = &ch->sack; 4798f8829a4aSRandall Stewart /* CMT DAC algo */ 4799f8829a4aSRandall Stewart this_sack_lowest_newack = 0; 4800f8829a4aSRandall Stewart j = 0; 4801d06c82f1SRandall Stewart sack_length = (unsigned int)sack_len; 4802f8829a4aSRandall Stewart /* ECN Nonce */ 4803f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_slowpath_sack); 4804f8829a4aSRandall Stewart nonce_sum_flag = ch->ch.chunk_flags & SCTP_SACK_NONCE_SUM; 4805f8829a4aSRandall Stewart cum_ack = last_tsn = ntohl(sack->cum_tsn_ack); 480618e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 480718e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cum_ack; 480818e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 480918e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 481018e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 481118e198d3SRandall Stewart } 481218e198d3SRandall Stewart #endif 4813f8829a4aSRandall Stewart num_seg = ntohs(sack->num_gap_ack_blks); 4814d06c82f1SRandall Stewart a_rwnd = rwnd; 4815f8829a4aSRandall Stewart 4816b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 4817d06c82f1SRandall Stewart sctp_misc_ints(SCTP_SACK_LOG_NORMAL, cum_ack, 4818d06c82f1SRandall Stewart rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 481980fefe0aSRandall Stewart } 4820f8829a4aSRandall Stewart /* CMT DAC algo */ 4821f8829a4aSRandall Stewart cmt_dac_flag = ch->ch.chunk_flags & SCTP_SACK_CMT_DAC; 4822f8829a4aSRandall Stewart num_dup = ntohs(sack->num_dup_tsns); 4823f8829a4aSRandall Stewart 48245e54f665SRandall Stewart old_rwnd = stcb->asoc.peers_rwnd; 4825b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 4826c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 4827c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 4828c4739e2fSRandall Stewart 0, 4829c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 4830c4739e2fSRandall Stewart __LINE__); 4831c4739e2fSRandall Stewart } 4832f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 4833f8829a4aSRandall Stewart asoc = &stcb->asoc; 4834b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4835f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4836f8829a4aSRandall Stewart cum_ack, 4837f8829a4aSRandall Stewart 0, 4838f8829a4aSRandall Stewart num_seg, 4839f8829a4aSRandall Stewart num_dup, 4840f8829a4aSRandall Stewart SCTP_LOG_NEW_SACK); 484180fefe0aSRandall Stewart } 4842b3f1ea41SRandall Stewart if ((num_dup) && (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_FR_LOGGING_ENABLE | SCTP_EARLYFR_LOGGING_ENABLE))) { 4843f8829a4aSRandall Stewart int off_to_dup, iii; 4844458303daSRandall Stewart uint32_t *dupdata, dblock; 4845f8829a4aSRandall Stewart 4846f8829a4aSRandall Stewart off_to_dup = (num_seg * sizeof(struct sctp_gap_ack_block)) + sizeof(struct sctp_sack_chunk); 4847f8829a4aSRandall Stewart if ((off_to_dup + (num_dup * sizeof(uint32_t))) <= sack_length) { 4848458303daSRandall Stewart dupdata = (uint32_t *) sctp_m_getptr(m, off_to_dup, 4849458303daSRandall Stewart sizeof(uint32_t), (uint8_t *) & dblock); 4850458303daSRandall Stewart off_to_dup += sizeof(uint32_t); 4851458303daSRandall Stewart if (dupdata) { 4852f8829a4aSRandall Stewart for (iii = 0; iii < num_dup; iii++) { 4853f8829a4aSRandall Stewart sctp_log_fr(*dupdata, 0, 0, SCTP_FR_DUPED); 4854458303daSRandall Stewart dupdata = (uint32_t *) sctp_m_getptr(m, off_to_dup, 4855458303daSRandall Stewart sizeof(uint32_t), (uint8_t *) & dblock); 4856458303daSRandall Stewart if (dupdata == NULL) 4857458303daSRandall Stewart break; 4858458303daSRandall Stewart off_to_dup += sizeof(uint32_t); 4859458303daSRandall Stewart } 4860f8829a4aSRandall Stewart } 4861f8829a4aSRandall Stewart } else { 4862ad81507eSRandall Stewart SCTP_PRINTF("Size invalid offset to dups:%d number dups:%d sack_len:%d num gaps:%d\n", 4863f8829a4aSRandall Stewart off_to_dup, num_dup, sack_length, num_seg); 4864f8829a4aSRandall Stewart } 4865f8829a4aSRandall Stewart } 4866b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 4867c105859eSRandall Stewart /* reality check */ 4868c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 4869c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 4870c105859eSRandall Stewart sctpchunk_listhead); 4871c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 4872c105859eSRandall Stewart } else { 4873c105859eSRandall Stewart send_s = asoc->sending_seq; 4874c105859eSRandall Stewart } 4875f8829a4aSRandall Stewart if (cum_ack == send_s || 4876f8829a4aSRandall Stewart compare_with_wrap(cum_ack, send_s, MAX_TSN)) { 4877c105859eSRandall Stewart #ifndef INVARIANTS 4878c105859eSRandall Stewart struct mbuf *oper; 4879c105859eSRandall Stewart 4880c105859eSRandall Stewart #endif 4881c105859eSRandall Stewart #ifdef INVARIANTS 4882139bc87fSRandall Stewart hopeless_peer: 4883139bc87fSRandall Stewart panic("Impossible sack 1"); 4884139bc87fSRandall Stewart #else 4885c105859eSRandall Stewart 4886f8829a4aSRandall Stewart 4887f8829a4aSRandall Stewart /* 4888f8829a4aSRandall Stewart * no way, we have not even sent this TSN out yet. 4889f8829a4aSRandall Stewart * Peer is hopelessly messed up with us. 4890f8829a4aSRandall Stewart */ 4891f8829a4aSRandall Stewart hopeless_peer: 4892f8829a4aSRandall Stewart *abort_now = 1; 4893f8829a4aSRandall Stewart /* XXX */ 4894f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4895f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4896f8829a4aSRandall Stewart if (oper) { 4897f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 4898f8829a4aSRandall Stewart uint32_t *ippp; 4899f8829a4aSRandall Stewart 4900139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4901f8829a4aSRandall Stewart sizeof(uint32_t); 4902f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4903f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 4904139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4905f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 4906a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 4907f8829a4aSRandall Stewart } 4908a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 4909ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 4910f8829a4aSRandall Stewart return; 4911139bc87fSRandall Stewart #endif 4912f8829a4aSRandall Stewart } 4913f8829a4aSRandall Stewart } 4914f8829a4aSRandall Stewart /**********************/ 4915f8829a4aSRandall Stewart /* 1) check the range */ 4916f8829a4aSRandall Stewart /**********************/ 4917f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, last_tsn, MAX_TSN)) { 4918f8829a4aSRandall Stewart /* acking something behind */ 4919f8829a4aSRandall Stewart return; 4920f8829a4aSRandall Stewart } 4921bff64a4dSRandall Stewart sav_cum_ack = asoc->last_acked_seq; 4922bff64a4dSRandall Stewart 4923f8829a4aSRandall Stewart /* update the Rwnd of the peer */ 4924f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue) && 4925f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->send_queue) && 4926f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0) 4927f8829a4aSRandall Stewart ) { 4928f8829a4aSRandall Stewart /* nothing left on send/sent and strmq */ 4929b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4930f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 4931f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 493280fefe0aSRandall Stewart } 4933f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 4934f8829a4aSRandall Stewart if (asoc->sent_queue_retran_cnt) { 4935f8829a4aSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4936f8829a4aSRandall Stewart } 4937f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4938f8829a4aSRandall Stewart /* SWS sender side engages */ 4939f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4940f8829a4aSRandall Stewart } 4941f8829a4aSRandall Stewart /* stop any timers */ 4942f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4943f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4944a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 4945b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4946139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4947f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck1); 4948a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4949a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 4950f8829a4aSRandall Stewart } 4951f8829a4aSRandall Stewart } 4952f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4953f8829a4aSRandall Stewart net->flight_size = 0; 4954f8829a4aSRandall Stewart } 4955f8829a4aSRandall Stewart asoc->total_flight = 0; 4956f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4957f8829a4aSRandall Stewart return; 4958f8829a4aSRandall Stewart } 4959f8829a4aSRandall Stewart /* 4960f8829a4aSRandall Stewart * We init netAckSz and netAckSz2 to 0. These are used to track 2 4961f8829a4aSRandall Stewart * things. The total byte count acked is tracked in netAckSz AND 4962f8829a4aSRandall Stewart * netAck2 is used to track the total bytes acked that are un- 4963f8829a4aSRandall Stewart * amibguious and were never retransmitted. We track these on a per 4964f8829a4aSRandall Stewart * destination address basis. 4965f8829a4aSRandall Stewart */ 4966f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4967f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 4968f8829a4aSRandall Stewart net->net_ack = 0; 4969f8829a4aSRandall Stewart net->net_ack2 = 0; 4970f8829a4aSRandall Stewart 4971f8829a4aSRandall Stewart /* 497242551e99SRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 497342551e99SRandall Stewart * SACK processing 4974f8829a4aSRandall Stewart */ 4975f8829a4aSRandall Stewart net->new_pseudo_cumack = 0; 4976f8829a4aSRandall Stewart net->will_exit_fast_recovery = 0; 4977f8829a4aSRandall Stewart } 4978f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 4979f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 4980f8829a4aSRandall Stewart while (tp1) { 4981f8829a4aSRandall Stewart if (compare_with_wrap(last_tsn, tp1->rec.data.TSN_seq, 4982f8829a4aSRandall Stewart MAX_TSN) || 4983f8829a4aSRandall Stewart last_tsn == tp1->rec.data.TSN_seq) { 4984f8829a4aSRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 4985f8829a4aSRandall Stewart /* 4986f8829a4aSRandall Stewart * ECN Nonce: Add the nonce to the sender's 4987f8829a4aSRandall Stewart * nonce sum 4988f8829a4aSRandall Stewart */ 4989f8829a4aSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 4990f8829a4aSRandall Stewart accum_moved = 1; 4991f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 4992f8829a4aSRandall Stewart /* 4993f8829a4aSRandall Stewart * If it is less than ACKED, it is 4994f8829a4aSRandall Stewart * now no-longer in flight. Higher 4995f8829a4aSRandall Stewart * values may occur during marking 4996f8829a4aSRandall Stewart */ 4997f8829a4aSRandall Stewart if ((tp1->whoTo->dest_state & 4998f8829a4aSRandall Stewart SCTP_ADDR_UNCONFIRMED) && 4999f8829a4aSRandall Stewart (tp1->snd_count < 2)) { 5000f8829a4aSRandall Stewart /* 5001f8829a4aSRandall Stewart * If there was no retran 5002f8829a4aSRandall Stewart * and the address is 5003f8829a4aSRandall Stewart * un-confirmed and we sent 5004f8829a4aSRandall Stewart * there and are now 5005f8829a4aSRandall Stewart * sacked.. its confirmed, 5006f8829a4aSRandall Stewart * mark it so. 5007f8829a4aSRandall Stewart */ 5008f8829a4aSRandall Stewart tp1->whoTo->dest_state &= 5009f8829a4aSRandall Stewart ~SCTP_ADDR_UNCONFIRMED; 5010f8829a4aSRandall Stewart } 5011c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 5012b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 5013c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 5014a5d547adSRandall Stewart tp1->whoTo->flight_size, 5015a5d547adSRandall Stewart tp1->book_size, 5016c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 5017a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 501880fefe0aSRandall Stewart } 5019c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 5020c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 5021f8829a4aSRandall Stewart } 5022f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 5023f8829a4aSRandall Stewart 5024f8829a4aSRandall Stewart /* CMT SFR and DAC algos */ 5025f8829a4aSRandall Stewart this_sack_lowest_newack = tp1->rec.data.TSN_seq; 5026f8829a4aSRandall Stewart tp1->whoTo->saw_newack = 1; 5027f8829a4aSRandall Stewart 5028f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 5029f8829a4aSRandall Stewart /* 5030f8829a4aSRandall Stewart * True non-retransmited 5031f8829a4aSRandall Stewart * chunk 5032f8829a4aSRandall Stewart */ 5033f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 5034f8829a4aSRandall Stewart tp1->send_size; 5035f8829a4aSRandall Stewart 5036f8829a4aSRandall Stewart /* update RTO too? */ 5037f8829a4aSRandall Stewart if (tp1->do_rtt) { 5038f8829a4aSRandall Stewart tp1->whoTo->RTO = 5039f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 5040f8829a4aSRandall Stewart asoc, tp1->whoTo, 504118e198d3SRandall Stewart &tp1->sent_rcv_time, 504218e198d3SRandall Stewart sctp_align_safe_nocopy); 5043f8829a4aSRandall Stewart tp1->do_rtt = 0; 5044f8829a4aSRandall Stewart } 5045f8829a4aSRandall Stewart } 5046f8829a4aSRandall Stewart /* 5047f8829a4aSRandall Stewart * CMT: CUCv2 algorithm. From the 5048f8829a4aSRandall Stewart * cumack'd TSNs, for each TSN being 5049f8829a4aSRandall Stewart * acked for the first time, set the 5050f8829a4aSRandall Stewart * following variables for the 5051f8829a4aSRandall Stewart * corresp destination. 5052f8829a4aSRandall Stewart * new_pseudo_cumack will trigger a 5053f8829a4aSRandall Stewart * cwnd update. 5054f8829a4aSRandall Stewart * find_(rtx_)pseudo_cumack will 5055f8829a4aSRandall Stewart * trigger search for the next 5056f8829a4aSRandall Stewart * expected (rtx-)pseudo-cumack. 5057f8829a4aSRandall Stewart */ 5058f8829a4aSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 5059f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 5060f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 5061f8829a4aSRandall Stewart 5062f8829a4aSRandall Stewart 5063b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 5064f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 5065f8829a4aSRandall Stewart cum_ack, 5066f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 5067f8829a4aSRandall Stewart 0, 5068f8829a4aSRandall Stewart 0, 5069f8829a4aSRandall Stewart SCTP_LOG_TSN_ACKED); 507080fefe0aSRandall Stewart } 5071b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 5072f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 507380fefe0aSRandall Stewart } 5074f8829a4aSRandall Stewart } 5075f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 5076f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 5077f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 5078f8829a4aSRandall Stewart sctp_audit_log(0xB3, 5079f8829a4aSRandall Stewart (asoc->sent_queue_retran_cnt & 0x000000ff)); 5080f8829a4aSRandall Stewart #endif 5081f8829a4aSRandall Stewart } 508242551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 508342551e99SRandall Stewart /* deflate the cwnd */ 508442551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 508542551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 508642551e99SRandall Stewart } 5087f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 5088f8829a4aSRandall Stewart } 5089f8829a4aSRandall Stewart } else { 5090f8829a4aSRandall Stewart break; 5091f8829a4aSRandall Stewart } 5092f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 5093f8829a4aSRandall Stewart } 5094f8829a4aSRandall Stewart biggest_tsn_newly_acked = biggest_tsn_acked = last_tsn; 5095f8829a4aSRandall Stewart /* always set this up to cum-ack */ 5096f8829a4aSRandall Stewart asoc->this_sack_highest_gap = last_tsn; 5097f8829a4aSRandall Stewart 5098458303daSRandall Stewart /* Move offset up to point to gaps/dups */ 5099458303daSRandall Stewart offset += sizeof(struct sctp_sack_chunk); 5100f8829a4aSRandall Stewart if (((num_seg * (sizeof(struct sctp_gap_ack_block))) + sizeof(struct sctp_sack_chunk)) > sack_length) { 5101f8829a4aSRandall Stewart 5102f8829a4aSRandall Stewart /* skip corrupt segments */ 5103f8829a4aSRandall Stewart goto skip_segments; 5104f8829a4aSRandall Stewart } 5105f8829a4aSRandall Stewart if (num_seg > 0) { 5106f8829a4aSRandall Stewart 5107f8829a4aSRandall Stewart /* 5108f8829a4aSRandall Stewart * CMT: SFR algo (and HTNA) - this_sack_highest_newack has 5109f8829a4aSRandall Stewart * to be greater than the cumack. Also reset saw_newack to 0 5110f8829a4aSRandall Stewart * for all dests. 5111f8829a4aSRandall Stewart */ 5112f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5113f8829a4aSRandall Stewart net->saw_newack = 0; 5114f8829a4aSRandall Stewart net->this_sack_highest_newack = last_tsn; 5115f8829a4aSRandall Stewart } 5116f8829a4aSRandall Stewart 5117f8829a4aSRandall Stewart /* 5118f8829a4aSRandall Stewart * thisSackHighestGap will increase while handling NEW 5119f8829a4aSRandall Stewart * segments this_sack_highest_newack will increase while 5120f8829a4aSRandall Stewart * handling NEWLY ACKED chunks. this_sack_lowest_newack is 5121f8829a4aSRandall Stewart * used for CMT DAC algo. saw_newack will also change. 5122f8829a4aSRandall Stewart */ 5123458303daSRandall Stewart sctp_handle_segments(m, &offset, stcb, asoc, ch, last_tsn, 5124f8829a4aSRandall Stewart &biggest_tsn_acked, &biggest_tsn_newly_acked, &this_sack_lowest_newack, 5125f8829a4aSRandall Stewart num_seg, &ecn_seg_sums); 5126f8829a4aSRandall Stewart 5127b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 5128f8829a4aSRandall Stewart /* 5129f8829a4aSRandall Stewart * validate the biggest_tsn_acked in the gap acks if 5130f8829a4aSRandall Stewart * strict adherence is wanted. 5131f8829a4aSRandall Stewart */ 5132f8829a4aSRandall Stewart if ((biggest_tsn_acked == send_s) || 5133f8829a4aSRandall Stewart (compare_with_wrap(biggest_tsn_acked, send_s, MAX_TSN))) { 5134f8829a4aSRandall Stewart /* 5135f8829a4aSRandall Stewart * peer is either confused or we are under 5136f8829a4aSRandall Stewart * attack. We must abort. 5137f8829a4aSRandall Stewart */ 5138f8829a4aSRandall Stewart goto hopeless_peer; 5139f8829a4aSRandall Stewart } 5140f8829a4aSRandall Stewart } 5141f8829a4aSRandall Stewart } 5142f8829a4aSRandall Stewart skip_segments: 5143f8829a4aSRandall Stewart /*******************************************/ 5144f8829a4aSRandall Stewart /* cancel ALL T3-send timer if accum moved */ 5145f8829a4aSRandall Stewart /*******************************************/ 5146b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) { 5147f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5148f8829a4aSRandall Stewart if (net->new_pseudo_cumack) 5149f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 5150a5d547adSRandall Stewart stcb, net, 5151a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_27); 5152f8829a4aSRandall Stewart 5153f8829a4aSRandall Stewart } 5154f8829a4aSRandall Stewart } else { 5155f8829a4aSRandall Stewart if (accum_moved) { 5156f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5157f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 5158a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_28); 5159f8829a4aSRandall Stewart } 5160f8829a4aSRandall Stewart } 5161f8829a4aSRandall Stewart } 5162f8829a4aSRandall Stewart /********************************************/ 5163f8829a4aSRandall Stewart /* drop the acked chunks from the sendqueue */ 5164f8829a4aSRandall Stewart /********************************************/ 5165f8829a4aSRandall Stewart asoc->last_acked_seq = cum_ack; 5166f8829a4aSRandall Stewart 5167f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 5168f8829a4aSRandall Stewart if (tp1 == NULL) 5169f8829a4aSRandall Stewart goto done_with_it; 5170f8829a4aSRandall Stewart do { 5171f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, cum_ack, 5172f8829a4aSRandall Stewart MAX_TSN)) { 5173f8829a4aSRandall Stewart break; 5174f8829a4aSRandall Stewart } 5175f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 5176f8829a4aSRandall Stewart /* no more sent on list */ 517718e198d3SRandall Stewart printf("Warning, tp1->sent == %d and its now acked?\n", 517818e198d3SRandall Stewart tp1->sent); 5179f8829a4aSRandall Stewart } 5180f8829a4aSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 5181f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 5182f8829a4aSRandall Stewart if (tp1->pr_sctp_on) { 5183f8829a4aSRandall Stewart if (asoc->pr_sctp_cnt != 0) 5184f8829a4aSRandall Stewart asoc->pr_sctp_cnt--; 5185f8829a4aSRandall Stewart } 5186f8829a4aSRandall Stewart if ((TAILQ_FIRST(&asoc->sent_queue) == NULL) && 5187f8829a4aSRandall Stewart (asoc->total_flight > 0)) { 5188f1f73e57SRandall Stewart #ifdef INVARIANTS 5189c105859eSRandall Stewart panic("Warning flight size is postive and should be 0"); 5190f1f73e57SRandall Stewart #else 5191ad81507eSRandall Stewart SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n", 5192f8829a4aSRandall Stewart asoc->total_flight); 5193f1f73e57SRandall Stewart #endif 5194f8829a4aSRandall Stewart asoc->total_flight = 0; 5195f8829a4aSRandall Stewart } 5196f8829a4aSRandall Stewart if (tp1->data) { 519704ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 5198f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 5199f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 5200f8829a4aSRandall Stewart if (PR_SCTP_BUF_ENABLED(tp1->flags)) { 5201f8829a4aSRandall Stewart asoc->sent_queue_cnt_removeable--; 5202f8829a4aSRandall Stewart } 5203f8829a4aSRandall Stewart } 5204b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 5205f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 5206f8829a4aSRandall Stewart cum_ack, 5207f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 5208f8829a4aSRandall Stewart 0, 5209f8829a4aSRandall Stewart 0, 5210f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 521180fefe0aSRandall Stewart } 5212f8829a4aSRandall Stewart tp1->data = NULL; 5213f8829a4aSRandall Stewart asoc->sent_queue_cnt--; 5214f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, tp1); 5215f8829a4aSRandall Stewart wake_him++; 5216f8829a4aSRandall Stewart tp1 = tp2; 5217f8829a4aSRandall Stewart } while (tp1 != NULL); 5218f8829a4aSRandall Stewart 5219f8829a4aSRandall Stewart done_with_it: 522004ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 5221f8829a4aSRandall Stewart if ((wake_him) && (stcb->sctp_socket)) { 5222ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 5223ceaad40aSRandall Stewart struct socket *so; 5224ceaad40aSRandall Stewart 5225ceaad40aSRandall Stewart #endif 5226f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 5227b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 5228f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_WAKESND_FROM_SACK); 522980fefe0aSRandall Stewart } 5230ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 5231ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 5232ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 5233ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 5234ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 5235ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 5236ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 5237ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 5238ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 5239ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 5240ceaad40aSRandall Stewart return; 5241ceaad40aSRandall Stewart } 5242ceaad40aSRandall Stewart #endif 5243f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 5244ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 5245ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 5246ceaad40aSRandall Stewart #endif 5247f8829a4aSRandall Stewart } else { 5248b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 5249f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_NOWAKE_FROM_SACK); 525080fefe0aSRandall Stewart } 5251f8829a4aSRandall Stewart } 5252f8829a4aSRandall Stewart 525342551e99SRandall Stewart if (asoc->fast_retran_loss_recovery && accum_moved) { 5254f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, 5255f8829a4aSRandall Stewart asoc->fast_recovery_tsn, MAX_TSN) || 5256f8829a4aSRandall Stewart asoc->last_acked_seq == asoc->fast_recovery_tsn) { 5257f8829a4aSRandall Stewart /* Setup so we will exit RFC2582 fast recovery */ 5258f8829a4aSRandall Stewart will_exit_fast_recovery = 1; 5259f8829a4aSRandall Stewart } 5260f8829a4aSRandall Stewart } 5261f8829a4aSRandall Stewart /* 5262f8829a4aSRandall Stewart * Check for revoked fragments: 5263f8829a4aSRandall Stewart * 5264f8829a4aSRandall Stewart * if Previous sack - Had no frags then we can't have any revoked if 5265f8829a4aSRandall Stewart * Previous sack - Had frag's then - If we now have frags aka 5266f8829a4aSRandall Stewart * num_seg > 0 call sctp_check_for_revoked() to tell if peer revoked 5267f8829a4aSRandall Stewart * some of them. else - The peer revoked all ACKED fragments, since 5268f8829a4aSRandall Stewart * we had some before and now we have NONE. 5269f8829a4aSRandall Stewart */ 5270f8829a4aSRandall Stewart 5271f42a358aSRandall Stewart if (num_seg) 5272c105859eSRandall Stewart sctp_check_for_revoked(stcb, asoc, cum_ack, biggest_tsn_acked); 5273f8829a4aSRandall Stewart else if (asoc->saw_sack_with_frags) { 5274f8829a4aSRandall Stewart int cnt_revoked = 0; 5275f8829a4aSRandall Stewart 5276f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 5277f8829a4aSRandall Stewart if (tp1 != NULL) { 5278f8829a4aSRandall Stewart /* Peer revoked all dg's marked or acked */ 5279f8829a4aSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 5280f8829a4aSRandall Stewart if ((tp1->sent > SCTP_DATAGRAM_RESEND) && 5281f8829a4aSRandall Stewart (tp1->sent < SCTP_FORWARD_TSN_SKIP)) { 5282f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 5283b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 5284c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 5285c105859eSRandall Stewart tp1->whoTo->flight_size, 5286c105859eSRandall Stewart tp1->book_size, 5287c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 5288c105859eSRandall Stewart tp1->rec.data.TSN_seq); 528980fefe0aSRandall Stewart } 5290c105859eSRandall Stewart sctp_flight_size_increase(tp1); 5291c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 5292a5d547adSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 529342551e99SRandall Stewart /* 529442551e99SRandall Stewart * To ensure that this increase in 529542551e99SRandall Stewart * flightsize, which is artificial, 529642551e99SRandall Stewart * does not throttle the sender, we 529742551e99SRandall Stewart * also increase the cwnd 529842551e99SRandall Stewart * artificially. 529942551e99SRandall Stewart */ 530042551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 5301f8829a4aSRandall Stewart cnt_revoked++; 5302f8829a4aSRandall Stewart } 5303f8829a4aSRandall Stewart } 5304f8829a4aSRandall Stewart if (cnt_revoked) { 5305f8829a4aSRandall Stewart reneged_all = 1; 5306f8829a4aSRandall Stewart } 5307f8829a4aSRandall Stewart } 5308f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 0; 5309f8829a4aSRandall Stewart } 5310f8829a4aSRandall Stewart if (num_seg) 5311f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 1; 5312f8829a4aSRandall Stewart else 5313f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 0; 5314f8829a4aSRandall Stewart 5315b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 5316b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, accum_moved, reneged_all, will_exit_fast_recovery); 5317f8829a4aSRandall Stewart 5318f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 5319f8829a4aSRandall Stewart /* nothing left in-flight */ 5320f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5321f8829a4aSRandall Stewart /* stop all timers */ 5322b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 5323139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 5324f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 5325a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 5326a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_29); 5327f8829a4aSRandall Stewart } 5328f8829a4aSRandall Stewart } 5329f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 5330a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_30); 5331f8829a4aSRandall Stewart net->flight_size = 0; 5332f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 5333f8829a4aSRandall Stewart } 5334f8829a4aSRandall Stewart asoc->total_flight = 0; 5335f8829a4aSRandall Stewart asoc->total_flight_count = 0; 5336f8829a4aSRandall Stewart } 5337f8829a4aSRandall Stewart /**********************************/ 5338f8829a4aSRandall Stewart /* Now what about shutdown issues */ 5339f8829a4aSRandall Stewart /**********************************/ 5340f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 5341f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 5342b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 5343f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 5344f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 534580fefe0aSRandall Stewart } 5346f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 5347f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 5348f8829a4aSRandall Stewart /* SWS sender side engages */ 5349f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 5350f8829a4aSRandall Stewart } 5351f8829a4aSRandall Stewart /* clean up */ 5352f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 5353f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 5354f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 5355f8829a4aSRandall Stewart (asoc->locked_on_sending) 5356f8829a4aSRandall Stewart ) { 5357f8829a4aSRandall Stewart struct sctp_stream_queue_pending *sp; 5358f8829a4aSRandall Stewart 5359f8829a4aSRandall Stewart /* 5360f8829a4aSRandall Stewart * I may be in a state where we got all across.. but 5361f8829a4aSRandall Stewart * cannot write more due to a shutdown... we abort 5362f8829a4aSRandall Stewart * since the user did not indicate EOR in this case. 5363f8829a4aSRandall Stewart */ 5364f8829a4aSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 5365f8829a4aSRandall Stewart sctp_streamhead); 53662afb3e84SRandall Stewart if ((sp) && (sp->length == 0)) { 5367f8829a4aSRandall Stewart asoc->locked_on_sending = NULL; 53682afb3e84SRandall Stewart if (sp->msg_is_complete) { 5369f8829a4aSRandall Stewart asoc->stream_queue_cnt--; 53702afb3e84SRandall Stewart } else { 53712afb3e84SRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 53722afb3e84SRandall Stewart asoc->stream_queue_cnt--; 53732afb3e84SRandall Stewart } 5374f8829a4aSRandall Stewart } 5375f8829a4aSRandall Stewart } 5376f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 5377f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 5378f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 5379f8829a4aSRandall Stewart /* Need to abort here */ 5380f8829a4aSRandall Stewart struct mbuf *oper; 5381f8829a4aSRandall Stewart 5382f8829a4aSRandall Stewart abort_out_now: 5383f8829a4aSRandall Stewart *abort_now = 1; 5384f8829a4aSRandall Stewart /* XXX */ 5385f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 5386f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 5387f8829a4aSRandall Stewart if (oper) { 5388f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 5389f8829a4aSRandall Stewart uint32_t *ippp; 5390f8829a4aSRandall Stewart 5391139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 5392f8829a4aSRandall Stewart sizeof(uint32_t); 5393f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 5394f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 5395139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 5396f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 5397a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_31); 5398f8829a4aSRandall Stewart } 5399a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_31; 5400ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 5401f8829a4aSRandall Stewart return; 5402f8829a4aSRandall Stewart } else { 5403f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 5404f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 5405f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 5406f42a358aSRandall Stewart } 5407c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 5408b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 5409f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 5410f8829a4aSRandall Stewart sctp_send_shutdown(stcb, 5411f8829a4aSRandall Stewart stcb->asoc.primary_destination); 5412f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 5413f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 5414f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 5415f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 5416f8829a4aSRandall Stewart } 5417f8829a4aSRandall Stewart return; 5418f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 5419f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 5420f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 5421f8829a4aSRandall Stewart goto abort_out_now; 5422f8829a4aSRandall Stewart } 5423f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 5424c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 5425b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 5426f8829a4aSRandall Stewart sctp_send_shutdown_ack(stcb, 5427f8829a4aSRandall Stewart stcb->asoc.primary_destination); 5428f8829a4aSRandall Stewart 5429f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 5430f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 5431f8829a4aSRandall Stewart return; 5432f8829a4aSRandall Stewart } 5433f8829a4aSRandall Stewart } 5434f8829a4aSRandall Stewart /* 5435f8829a4aSRandall Stewart * Now here we are going to recycle net_ack for a different use... 5436f8829a4aSRandall Stewart * HEADS UP. 5437f8829a4aSRandall Stewart */ 5438f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5439f8829a4aSRandall Stewart net->net_ack = 0; 5440f8829a4aSRandall Stewart } 5441f8829a4aSRandall Stewart 5442f8829a4aSRandall Stewart /* 5443f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK DAC flag was 0, then no extra marking 5444f8829a4aSRandall Stewart * to be done. Setting this_sack_lowest_newack to the cum_ack will 5445f8829a4aSRandall Stewart * automatically ensure that. 5446f8829a4aSRandall Stewart */ 5447b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac) && (cmt_dac_flag == 0)) { 5448f8829a4aSRandall Stewart this_sack_lowest_newack = cum_ack; 5449f8829a4aSRandall Stewart } 5450f8829a4aSRandall Stewart if (num_seg > 0) { 5451f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(stcb, asoc, biggest_tsn_acked, 5452f8829a4aSRandall Stewart biggest_tsn_newly_acked, this_sack_lowest_newack, accum_moved); 5453f8829a4aSRandall Stewart } 5454b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 5455b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_fr(stcb, asoc); 5456f8829a4aSRandall Stewart 5457f8829a4aSRandall Stewart /****************************************************************** 5458f8829a4aSRandall Stewart * Here we do the stuff with ECN Nonce checking. 5459f8829a4aSRandall Stewart * We basically check to see if the nonce sum flag was incorrect 5460f8829a4aSRandall Stewart * or if resynchronization needs to be done. Also if we catch a 5461f8829a4aSRandall Stewart * misbehaving receiver we give him the kick. 5462f8829a4aSRandall Stewart ******************************************************************/ 5463f8829a4aSRandall Stewart 5464f8829a4aSRandall Stewart if (asoc->ecn_nonce_allowed) { 5465f8829a4aSRandall Stewart if (asoc->nonce_sum_check) { 5466f8829a4aSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base + ecn_seg_sums) & SCTP_SACK_NONCE_SUM)) { 5467f8829a4aSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 5468f8829a4aSRandall Stewart struct sctp_tmit_chunk *lchk; 5469f8829a4aSRandall Stewart 5470f8829a4aSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 5471f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 1; 5472f8829a4aSRandall Stewart if (lchk) { 5473f8829a4aSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 5474f8829a4aSRandall Stewart } else { 5475f8829a4aSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 5476f8829a4aSRandall Stewart } 5477f8829a4aSRandall Stewart } else { 5478f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) || 5479f8829a4aSRandall Stewart (asoc->last_acked_seq == asoc->nonce_wait_tsn)) { 5480f8829a4aSRandall Stewart /* 5481f8829a4aSRandall Stewart * Misbehaving peer. We need 5482f8829a4aSRandall Stewart * to react to this guy 5483f8829a4aSRandall Stewart */ 5484f8829a4aSRandall Stewart asoc->ecn_allowed = 0; 5485f8829a4aSRandall Stewart asoc->ecn_nonce_allowed = 0; 5486f8829a4aSRandall Stewart } 5487f8829a4aSRandall Stewart } 5488f8829a4aSRandall Stewart } 5489f8829a4aSRandall Stewart } else { 5490f8829a4aSRandall Stewart /* See if Resynchronization Possible */ 5491f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) { 5492f8829a4aSRandall Stewart asoc->nonce_sum_check = 1; 5493f8829a4aSRandall Stewart /* 5494f8829a4aSRandall Stewart * now we must calculate what the base is. 5495f8829a4aSRandall Stewart * We do this based on two things, we know 5496f8829a4aSRandall Stewart * the total's for all the segments 5497f8829a4aSRandall Stewart * gap-acked in the SACK, its stored in 5498f8829a4aSRandall Stewart * ecn_seg_sums. We also know the SACK's 5499f8829a4aSRandall Stewart * nonce sum, its in nonce_sum_flag. So we 5500f8829a4aSRandall Stewart * can build a truth table to back-calculate 5501f8829a4aSRandall Stewart * the new value of 5502f8829a4aSRandall Stewart * asoc->nonce_sum_expect_base: 5503f8829a4aSRandall Stewart * 5504f8829a4aSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 5505f8829a4aSRandall Stewart * 1 0 1 0 1 1 1 5506f8829a4aSRandall Stewart * 1 0 5507f8829a4aSRandall Stewart */ 5508f8829a4aSRandall Stewart asoc->nonce_sum_expect_base = (ecn_seg_sums ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 5509f8829a4aSRandall Stewart } 5510f8829a4aSRandall Stewart } 5511f8829a4aSRandall Stewart } 5512f8829a4aSRandall Stewart /* Now are we exiting loss recovery ? */ 5513f8829a4aSRandall Stewart if (will_exit_fast_recovery) { 5514f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 5515f8829a4aSRandall Stewart asoc->fast_retran_loss_recovery = 0; 5516f8829a4aSRandall Stewart } 5517f8829a4aSRandall Stewart if ((asoc->sat_t3_loss_recovery) && 5518f8829a4aSRandall Stewart ((compare_with_wrap(asoc->last_acked_seq, asoc->sat_t3_recovery_tsn, 5519f8829a4aSRandall Stewart MAX_TSN) || 5520f8829a4aSRandall Stewart (asoc->last_acked_seq == asoc->sat_t3_recovery_tsn)))) { 5521f8829a4aSRandall Stewart /* end satellite t3 loss recovery */ 5522f8829a4aSRandall Stewart asoc->sat_t3_loss_recovery = 0; 5523f8829a4aSRandall Stewart } 552442551e99SRandall Stewart /* 552542551e99SRandall Stewart * CMT Fast recovery 552642551e99SRandall Stewart */ 5527f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5528f8829a4aSRandall Stewart if (net->will_exit_fast_recovery) { 5529f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 5530f8829a4aSRandall Stewart net->fast_retran_loss_recovery = 0; 5531f8829a4aSRandall Stewart } 5532f8829a4aSRandall Stewart } 5533f8829a4aSRandall Stewart 5534f8829a4aSRandall Stewart /* Adjust and set the new rwnd value */ 5535b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 5536f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 5537b3f1ea41SRandall Stewart asoc->peers_rwnd, asoc->total_flight, (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)), a_rwnd); 553880fefe0aSRandall Stewart } 5539f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd, 5540b3f1ea41SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 5541f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 5542f8829a4aSRandall Stewart /* SWS sender side engages */ 5543f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 5544f8829a4aSRandall Stewart } 55455e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 55465e54f665SRandall Stewart win_probe_recovery = 1; 55475e54f665SRandall Stewart } 5548f8829a4aSRandall Stewart /* 5549f8829a4aSRandall Stewart * Now we must setup so we have a timer up for anyone with 5550f8829a4aSRandall Stewart * outstanding data. 5551f8829a4aSRandall Stewart */ 5552bff64a4dSRandall Stewart done_once = 0; 5553a5d547adSRandall Stewart again: 5554a5d547adSRandall Stewart j = 0; 5555f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 55565e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 5557c105859eSRandall Stewart win_probe_recovered = 1; 55585e54f665SRandall Stewart /*- 55595e54f665SRandall Stewart * Find first chunk that was used with 55605e54f665SRandall Stewart * window probe and clear the event. Put 55615e54f665SRandall Stewart * it back into the send queue as if has 55625e54f665SRandall Stewart * not been sent. 55635e54f665SRandall Stewart */ 55645e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 55655e54f665SRandall Stewart if (tp1->window_probe) { 5566c105859eSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 55675e54f665SRandall Stewart break; 55685e54f665SRandall Stewart } 55695e54f665SRandall Stewart } 55705e54f665SRandall Stewart } 5571f8829a4aSRandall Stewart if (net->flight_size) { 5572a5d547adSRandall Stewart j++; 5573f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5574f8829a4aSRandall Stewart stcb->sctp_ep, stcb, net); 55755171328bSRandall Stewart if (net->window_probe) { 55765171328bSRandall Stewart } 5577c105859eSRandall Stewart } else { 55785171328bSRandall Stewart if (net->window_probe) { 55795171328bSRandall Stewart /* 55805171328bSRandall Stewart * In window probes we must assure a timer 55815171328bSRandall Stewart * is still running there 55825171328bSRandall Stewart */ 55835171328bSRandall Stewart 55845171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 55855171328bSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 55865171328bSRandall Stewart stcb->sctp_ep, stcb, net); 55875171328bSRandall Stewart 55885171328bSRandall Stewart } 55895171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 5590c105859eSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 5591c105859eSRandall Stewart stcb, net, 5592c105859eSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 5593c105859eSRandall Stewart } 5594b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 5595c105859eSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 5596c105859eSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 5597c105859eSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 5598c105859eSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 5599c105859eSRandall Stewart } 5600c105859eSRandall Stewart } 5601f8829a4aSRandall Stewart } 5602f8829a4aSRandall Stewart } 5603bff64a4dSRandall Stewart if ((j == 0) && 5604bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 5605bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 5606c105859eSRandall Stewart (win_probe_recovered == 0) && 5607bff64a4dSRandall Stewart (done_once == 0)) { 5608a5d547adSRandall Stewart /* huh, this should not happen */ 5609c105859eSRandall Stewart sctp_fs_audit(asoc); 5610a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5611a5d547adSRandall Stewart net->flight_size = 0; 5612a5d547adSRandall Stewart } 5613a5d547adSRandall Stewart asoc->total_flight = 0; 5614a5d547adSRandall Stewart asoc->total_flight_count = 0; 5615a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 5616a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 5617a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 5618c105859eSRandall Stewart sctp_flight_size_increase(tp1); 5619c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 5620a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 5621a5d547adSRandall Stewart asoc->sent_queue_retran_cnt++; 5622a5d547adSRandall Stewart } 5623a5d547adSRandall Stewart } 5624bff64a4dSRandall Stewart done_once = 1; 5625a5d547adSRandall Stewart goto again; 5626a5d547adSRandall Stewart } 5627dfb11ef8SRandall Stewart /* Fix up the a-p-a-p for future PR-SCTP sends */ 5628dfb11ef8SRandall Stewart if (compare_with_wrap(cum_ack, asoc->advanced_peer_ack_point, MAX_TSN)) { 5629dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cum_ack; 5630dfb11ef8SRandall Stewart } 5631830d754dSRandall Stewart /* C2. try to further move advancedPeerAckPoint ahead */ 5632830d754dSRandall Stewart if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) { 5633830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 5634830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 5635830d754dSRandall Stewart 5636830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 5637830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 5638830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 5639830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, cum_ack, 5640830d754dSRandall Stewart MAX_TSN)) { 5641830d754dSRandall Stewart /* 5642830d754dSRandall Stewart * ISSUE with ECN, see FWD-TSN processing for notes 5643830d754dSRandall Stewart * on issues that will occur when the ECN NONCE 5644830d754dSRandall Stewart * stuff is put into SCTP for cross checking. 5645830d754dSRandall Stewart */ 5646830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, old_adv_peer_ack_point, 5647830d754dSRandall Stewart MAX_TSN)) { 5648830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 5649830d754dSRandall Stewart /* 5650830d754dSRandall Stewart * ECN Nonce: Disable Nonce Sum check when 5651830d754dSRandall Stewart * FWD TSN is sent and store resync tsn 5652830d754dSRandall Stewart */ 5653830d754dSRandall Stewart asoc->nonce_sum_check = 0; 5654830d754dSRandall Stewart asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point; 5655830d754dSRandall Stewart } 5656830d754dSRandall Stewart } 5657830d754dSRandall Stewart if (lchk) { 5658830d754dSRandall Stewart /* Assure a timer is up */ 5659830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5660830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 5661830d754dSRandall Stewart } 5662830d754dSRandall Stewart } 5663b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 5664f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 5665f8829a4aSRandall Stewart a_rwnd, 5666f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 5667f8829a4aSRandall Stewart stcb->asoc.total_flight, 5668f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 566980fefe0aSRandall Stewart } 5670f8829a4aSRandall Stewart } 5671f8829a4aSRandall Stewart 5672f8829a4aSRandall Stewart void 5673f8829a4aSRandall Stewart sctp_update_acked(struct sctp_tcb *stcb, struct sctp_shutdown_chunk *cp, 5674f8829a4aSRandall Stewart struct sctp_nets *netp, int *abort_flag) 5675f8829a4aSRandall Stewart { 5676f8829a4aSRandall Stewart /* Copy cum-ack */ 5677f8829a4aSRandall Stewart uint32_t cum_ack, a_rwnd; 5678f8829a4aSRandall Stewart 5679f8829a4aSRandall Stewart cum_ack = ntohl(cp->cumulative_tsn_ack); 5680f8829a4aSRandall Stewart /* Arrange so a_rwnd does NOT change */ 5681f8829a4aSRandall Stewart a_rwnd = stcb->asoc.peers_rwnd + stcb->asoc.total_flight; 5682f8829a4aSRandall Stewart 5683f8829a4aSRandall Stewart /* Now call the express sack handling */ 5684f8829a4aSRandall Stewart sctp_express_handle_sack(stcb, cum_ack, a_rwnd, 0, abort_flag); 5685f8829a4aSRandall Stewart } 5686f8829a4aSRandall Stewart 5687f8829a4aSRandall Stewart static void 5688f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb, 5689f8829a4aSRandall Stewart struct sctp_stream_in *strmin) 5690f8829a4aSRandall Stewart { 5691f8829a4aSRandall Stewart struct sctp_queued_to_read *ctl, *nctl; 5692f8829a4aSRandall Stewart struct sctp_association *asoc; 5693f8829a4aSRandall Stewart int tt; 5694f8829a4aSRandall Stewart 5695830d754dSRandall Stewart /* EY -used to calculate nr_gap information */ 5696830d754dSRandall Stewart uint32_t nr_tsn, nr_gap; 5697830d754dSRandall Stewart 5698f8829a4aSRandall Stewart asoc = &stcb->asoc; 5699f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered; 5700f8829a4aSRandall Stewart /* 5701f8829a4aSRandall Stewart * First deliver anything prior to and including the stream no that 5702f8829a4aSRandall Stewart * came in 5703f8829a4aSRandall Stewart */ 5704f8829a4aSRandall Stewart ctl = TAILQ_FIRST(&strmin->inqueue); 5705f8829a4aSRandall Stewart while (ctl) { 5706f8829a4aSRandall Stewart nctl = TAILQ_NEXT(ctl, next); 5707f8829a4aSRandall Stewart if (compare_with_wrap(tt, ctl->sinfo_ssn, MAX_SEQ) || 5708f8829a4aSRandall Stewart (tt == ctl->sinfo_ssn)) { 5709f8829a4aSRandall Stewart /* this is deliverable now */ 5710f8829a4aSRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next); 5711f8829a4aSRandall Stewart /* subtract pending on streams */ 5712f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5713f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5714f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5715f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5716830d754dSRandall Stewart /* EY need the tsn info for calculating nr */ 5717830d754dSRandall Stewart nr_tsn = ctl->sinfo_tsn; 5718f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5719f8829a4aSRandall Stewart ctl, 5720ceaad40aSRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_SO_NOT_LOCKED); 5721830d754dSRandall Stewart /* 5722830d754dSRandall Stewart * EY this is the chunk that should be 5723830d754dSRandall Stewart * tagged nr gapped calculate the gap and 5724830d754dSRandall Stewart * such then tag this TSN nr 5725830d754dSRandall Stewart * chk->rec.data.TSN_seq 5726830d754dSRandall Stewart */ 5727830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 5728830d754dSRandall Stewart 5729830d754dSRandall Stewart if (nr_tsn >= asoc->nr_mapping_array_base_tsn) { 5730830d754dSRandall Stewart nr_gap = nr_tsn - asoc->nr_mapping_array_base_tsn; 5731830d754dSRandall Stewart } else { 5732830d754dSRandall Stewart nr_gap = (MAX_TSN - asoc->nr_mapping_array_base_tsn) + nr_tsn + 1; 5733830d754dSRandall Stewart } 5734830d754dSRandall Stewart if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) || 5735830d754dSRandall Stewart (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) { 5736830d754dSRandall Stewart /* 5737830d754dSRandall Stewart * EY These should never 5738830d754dSRandall Stewart * happen- explained before 5739830d754dSRandall Stewart */ 5740830d754dSRandall Stewart } else { 5741830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 5742830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap); 5743830d754dSRandall Stewart if (nr_tsn > asoc->highest_tsn_inside_nr_map) 5744830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = nr_tsn; 5745830d754dSRandall Stewart } 5746830d754dSRandall Stewart 5747830d754dSRandall Stewart if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, nr_gap)) 5748830d754dSRandall Stewart /* 5749830d754dSRandall Stewart * printf("In 5750830d754dSRandall Stewart * sctp_kick_prsctp_reorder_q 5751830d754dSRandall Stewart * ueue(7): Something wrong, 5752830d754dSRandall Stewart * the TSN to be tagged" 5753830d754dSRandall Stewart * "\nas NR is not even in 5754830d754dSRandall Stewart * the mapping_array, or map 5755830d754dSRandall Stewart * and nr_map are 5756830d754dSRandall Stewart * inconsistent"); 5757830d754dSRandall Stewart */ 5758830d754dSRandall Stewart /* 5759830d754dSRandall Stewart * EY - not %100 sure about 5760830d754dSRandall Stewart * the lock thing, don't 5761830d754dSRandall Stewart * think its required 5762830d754dSRandall Stewart */ 5763830d754dSRandall Stewart /* 5764830d754dSRandall Stewart * SCTP_TCB_LOCK_ASSERT(stcb) 5765830d754dSRandall Stewart * ; 5766830d754dSRandall Stewart */ 5767830d754dSRandall Stewart { 5768830d754dSRandall Stewart /* 5769830d754dSRandall Stewart * printf("\nCalculating an 5770830d754dSRandall Stewart * nr_gap!!\nmapping_array_si 5771830d754dSRandall Stewart * ze = %d 5772830d754dSRandall Stewart * nr_mapping_array_size = 5773830d754dSRandall Stewart * %d" "\nmapping_array_base 5774830d754dSRandall Stewart * = %d 5775830d754dSRandall Stewart * nr_mapping_array_base = 5776830d754dSRandall Stewart * %d\nhighest_tsn_inside_map 5777830d754dSRandall Stewart * = %d" 5778830d754dSRandall Stewart * "highest_tsn_inside_nr_map 5779830d754dSRandall Stewart * = %d\nTSN = %d nr_gap = 5780830d754dSRandall Stewart * %d",asoc->mapping_array_si 5781830d754dSRandall Stewart * ze, 5782830d754dSRandall Stewart * asoc->nr_mapping_array_siz 5783830d754dSRandall Stewart * e, 5784830d754dSRandall Stewart * asoc->mapping_array_base_t 5785830d754dSRandall Stewart * sn, 5786830d754dSRandall Stewart * asoc->nr_mapping_array_bas 5787830d754dSRandall Stewart * e_tsn, 5788830d754dSRandall Stewart * asoc->highest_tsn_inside_m 5789830d754dSRandall Stewart * ap, 5790830d754dSRandall Stewart * asoc->highest_tsn_inside_n 5791830d754dSRandall Stewart * r_map,tsn,nr_gap); 5792830d754dSRandall Stewart */ 5793830d754dSRandall Stewart } 5794830d754dSRandall Stewart } 5795f8829a4aSRandall Stewart } 5796f8829a4aSRandall Stewart } else { 5797f8829a4aSRandall Stewart /* no more delivery now. */ 5798f8829a4aSRandall Stewart break; 5799f8829a4aSRandall Stewart } 5800f8829a4aSRandall Stewart ctl = nctl; 5801f8829a4aSRandall Stewart } 5802f8829a4aSRandall Stewart /* 5803f8829a4aSRandall Stewart * now we must deliver things in queue the normal way if any are 5804f8829a4aSRandall Stewart * now ready. 5805f8829a4aSRandall Stewart */ 5806f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 5807f8829a4aSRandall Stewart ctl = TAILQ_FIRST(&strmin->inqueue); 5808f8829a4aSRandall Stewart while (ctl) { 5809f8829a4aSRandall Stewart nctl = TAILQ_NEXT(ctl, next); 5810f8829a4aSRandall Stewart if (tt == ctl->sinfo_ssn) { 5811f8829a4aSRandall Stewart /* this is deliverable now */ 5812f8829a4aSRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next); 5813f8829a4aSRandall Stewart /* subtract pending on streams */ 5814f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5815f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5816f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5817f8829a4aSRandall Stewart strmin->last_sequence_delivered = ctl->sinfo_ssn; 5818f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5819830d754dSRandall Stewart /* EY */ 5820830d754dSRandall Stewart nr_tsn = ctl->sinfo_tsn; 5821f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5822f8829a4aSRandall Stewart ctl, 5823ceaad40aSRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_SO_NOT_LOCKED); 5824830d754dSRandall Stewart /* 5825830d754dSRandall Stewart * EY this is the chunk that should be 5826830d754dSRandall Stewart * tagged nr gapped calculate the gap and 5827830d754dSRandall Stewart * such then tag this TSN nr 5828830d754dSRandall Stewart * chk->rec.data.TSN_seq 5829830d754dSRandall Stewart */ 5830830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 5831830d754dSRandall Stewart 5832830d754dSRandall Stewart if (nr_tsn >= asoc->nr_mapping_array_base_tsn) { 5833830d754dSRandall Stewart nr_gap = nr_tsn - asoc->nr_mapping_array_base_tsn; 5834830d754dSRandall Stewart } else { 5835830d754dSRandall Stewart nr_gap = (MAX_TSN - asoc->nr_mapping_array_base_tsn) + nr_tsn + 1; 5836830d754dSRandall Stewart } 5837830d754dSRandall Stewart if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) || 5838830d754dSRandall Stewart (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) { 5839830d754dSRandall Stewart /* 5840830d754dSRandall Stewart * EY These should never 5841830d754dSRandall Stewart * happen, explained before 5842830d754dSRandall Stewart */ 5843830d754dSRandall Stewart } else { 5844830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 5845830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap); 5846830d754dSRandall Stewart if (nr_tsn > asoc->highest_tsn_inside_nr_map) 5847830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = nr_tsn; 5848830d754dSRandall Stewart } 5849830d754dSRandall Stewart 5850830d754dSRandall Stewart 5851830d754dSRandall Stewart if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, nr_gap)) 5852830d754dSRandall Stewart /* 5853830d754dSRandall Stewart * printf("In 5854830d754dSRandall Stewart * sctp_kick_prsctp_reorder_q 5855830d754dSRandall Stewart * ueue(8): Something wrong, 5856830d754dSRandall Stewart * the TSN to be tagged" 5857830d754dSRandall Stewart * "\nas NR is not even in 5858830d754dSRandall Stewart * the mapping_array, or map 5859830d754dSRandall Stewart * and nr_map are 5860830d754dSRandall Stewart * inconsistent"); 5861830d754dSRandall Stewart */ 5862830d754dSRandall Stewart /* 5863830d754dSRandall Stewart * EY - not %100 sure about 5864830d754dSRandall Stewart * the lock thing, don't 5865830d754dSRandall Stewart * think its required 5866830d754dSRandall Stewart */ 5867830d754dSRandall Stewart /* 5868830d754dSRandall Stewart * SCTP_TCB_LOCK_ASSERT(stcb) 5869830d754dSRandall Stewart * ; 5870830d754dSRandall Stewart */ 5871830d754dSRandall Stewart { 5872830d754dSRandall Stewart /* 5873830d754dSRandall Stewart * printf("\nCalculating an 5874830d754dSRandall Stewart * nr_gap!!\nmapping_array_si 5875830d754dSRandall Stewart * ze = %d 5876830d754dSRandall Stewart * nr_mapping_array_size = 5877830d754dSRandall Stewart * %d" "\nmapping_array_base 5878830d754dSRandall Stewart * = %d 5879830d754dSRandall Stewart * nr_mapping_array_base = 5880830d754dSRandall Stewart * %d\nhighest_tsn_inside_map 5881830d754dSRandall Stewart * = %d" 5882830d754dSRandall Stewart * "highest_tsn_inside_nr_map 5883830d754dSRandall Stewart * = %d\nTSN = %d nr_gap = 5884830d754dSRandall Stewart * %d",asoc->mapping_array_si 5885830d754dSRandall Stewart * ze, 5886830d754dSRandall Stewart * asoc->nr_mapping_array_siz 5887830d754dSRandall Stewart * e, 5888830d754dSRandall Stewart * asoc->mapping_array_base_t 5889830d754dSRandall Stewart * sn, 5890830d754dSRandall Stewart * asoc->nr_mapping_array_bas 5891830d754dSRandall Stewart * e_tsn, 5892830d754dSRandall Stewart * asoc->highest_tsn_inside_m 5893830d754dSRandall Stewart * ap, 5894830d754dSRandall Stewart * asoc->highest_tsn_inside_n 5895830d754dSRandall Stewart * r_map,tsn,nr_gap); 5896830d754dSRandall Stewart */ 5897830d754dSRandall Stewart } 5898830d754dSRandall Stewart } 5899f8829a4aSRandall Stewart } 5900f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 5901f8829a4aSRandall Stewart } else { 5902f8829a4aSRandall Stewart break; 5903f8829a4aSRandall Stewart } 5904f8829a4aSRandall Stewart ctl = nctl; 5905f8829a4aSRandall Stewart } 5906f8829a4aSRandall Stewart } 5907f8829a4aSRandall Stewart 5908f8829a4aSRandall Stewart void 5909f8829a4aSRandall Stewart sctp_handle_forward_tsn(struct sctp_tcb *stcb, 5910671d309cSRandall Stewart struct sctp_forward_tsn_chunk *fwd, int *abort_flag, struct mbuf *m, int offset) 5911f8829a4aSRandall Stewart { 5912f8829a4aSRandall Stewart /* 5913f8829a4aSRandall Stewart * ISSUES that MUST be fixed for ECN! When we are the sender of the 5914f8829a4aSRandall Stewart * forward TSN, when the SACK comes back that acknowledges the 5915f8829a4aSRandall Stewart * FWD-TSN we must reset the NONCE sum to match correctly. This will 5916f8829a4aSRandall Stewart * get quite tricky since we may have sent more data interveneing 5917f8829a4aSRandall Stewart * and must carefully account for what the SACK says on the nonce 5918f8829a4aSRandall Stewart * and any gaps that are reported. This work will NOT be done here, 5919f8829a4aSRandall Stewart * but I note it here since it is really related to PR-SCTP and 5920f8829a4aSRandall Stewart * FWD-TSN's 5921f8829a4aSRandall Stewart */ 5922f8829a4aSRandall Stewart 5923f8829a4aSRandall Stewart /* The pr-sctp fwd tsn */ 5924f8829a4aSRandall Stewart /* 5925f8829a4aSRandall Stewart * here we will perform all the data receiver side steps for 5926f8829a4aSRandall Stewart * processing FwdTSN, as required in by pr-sctp draft: 5927f8829a4aSRandall Stewart * 5928f8829a4aSRandall Stewart * Assume we get FwdTSN(x): 5929f8829a4aSRandall Stewart * 5930f8829a4aSRandall Stewart * 1) update local cumTSN to x 2) try to further advance cumTSN to x + 5931f8829a4aSRandall Stewart * others we have 3) examine and update re-ordering queue on 5932f8829a4aSRandall Stewart * pr-in-streams 4) clean up re-assembly queue 5) Send a sack to 5933f8829a4aSRandall Stewart * report where we are. 5934f8829a4aSRandall Stewart */ 5935f8829a4aSRandall Stewart struct sctp_association *asoc; 59362afb3e84SRandall Stewart uint32_t new_cum_tsn, gap; 5937f8829a4aSRandall Stewart unsigned int i, cnt_gone, fwd_sz, cumack_set_flag, m_size; 5938f8829a4aSRandall Stewart struct sctp_stream_in *strm; 5939f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk, *at; 5940f8829a4aSRandall Stewart 5941f8829a4aSRandall Stewart cumack_set_flag = 0; 5942f8829a4aSRandall Stewart asoc = &stcb->asoc; 5943f8829a4aSRandall Stewart cnt_gone = 0; 5944f8829a4aSRandall Stewart if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) { 5945ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, 5946ad81507eSRandall Stewart "Bad size too small/big fwd-tsn\n"); 5947f8829a4aSRandall Stewart return; 5948f8829a4aSRandall Stewart } 5949f8829a4aSRandall Stewart m_size = (stcb->asoc.mapping_array_size << 3); 5950f8829a4aSRandall Stewart /*************************************************************/ 5951f8829a4aSRandall Stewart /* 1. Here we update local cumTSN and shift the bitmap array */ 5952f8829a4aSRandall Stewart /*************************************************************/ 5953f8829a4aSRandall Stewart new_cum_tsn = ntohl(fwd->new_cumulative_tsn); 5954f8829a4aSRandall Stewart 5955f8829a4aSRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, new_cum_tsn, MAX_TSN) || 5956f8829a4aSRandall Stewart asoc->cumulative_tsn == new_cum_tsn) { 5957f8829a4aSRandall Stewart /* Already got there ... */ 5958f8829a4aSRandall Stewart return; 5959f8829a4aSRandall Stewart } 5960f8829a4aSRandall Stewart if (compare_with_wrap(new_cum_tsn, asoc->highest_tsn_inside_map, 5961f8829a4aSRandall Stewart MAX_TSN)) { 5962f8829a4aSRandall Stewart asoc->highest_tsn_inside_map = new_cum_tsn; 5963830d754dSRandall Stewart /* EY nr_mapping_array version of the above */ 5964830d754dSRandall Stewart /* 5965830d754dSRandall Stewart * if(SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && 5966830d754dSRandall Stewart * asoc->peer_supports_nr_sack) 5967830d754dSRandall Stewart */ 5968830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = new_cum_tsn; 5969b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 5970f8829a4aSRandall Stewart sctp_log_map(0, 0, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 597180fefe0aSRandall Stewart } 5972f8829a4aSRandall Stewart } 5973f8829a4aSRandall Stewart /* 5974f8829a4aSRandall Stewart * now we know the new TSN is more advanced, let's find the actual 5975f8829a4aSRandall Stewart * gap 5976f8829a4aSRandall Stewart */ 5977f8829a4aSRandall Stewart if ((compare_with_wrap(new_cum_tsn, asoc->mapping_array_base_tsn, 5978f8829a4aSRandall Stewart MAX_TSN)) || 5979f8829a4aSRandall Stewart (new_cum_tsn == asoc->mapping_array_base_tsn)) { 5980f8829a4aSRandall Stewart gap = new_cum_tsn - asoc->mapping_array_base_tsn; 5981f8829a4aSRandall Stewart } else { 5982f8829a4aSRandall Stewart /* try to prevent underflow here */ 5983f8829a4aSRandall Stewart gap = new_cum_tsn + (MAX_TSN - asoc->mapping_array_base_tsn) + 1; 5984f8829a4aSRandall Stewart } 5985f8829a4aSRandall Stewart 59862afb3e84SRandall Stewart if (gap >= m_size) { 5987b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 5988c4739e2fSRandall Stewart sctp_log_map(0, 0, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 5989c4739e2fSRandall Stewart } 5990f8829a4aSRandall Stewart if ((long)gap > sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv)) { 599117205eccSRandall Stewart struct mbuf *oper; 599217205eccSRandall Stewart 5993f8829a4aSRandall Stewart /* 5994f8829a4aSRandall Stewart * out of range (of single byte chunks in the rwnd I 599517205eccSRandall Stewart * give out). This must be an attacker. 5996f8829a4aSRandall Stewart */ 599717205eccSRandall Stewart *abort_flag = 1; 599817205eccSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 599917205eccSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 600017205eccSRandall Stewart if (oper) { 600117205eccSRandall Stewart struct sctp_paramhdr *ph; 600217205eccSRandall Stewart uint32_t *ippp; 600317205eccSRandall Stewart 600417205eccSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 600517205eccSRandall Stewart (sizeof(uint32_t) * 3); 600617205eccSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 600717205eccSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 600817205eccSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 600917205eccSRandall Stewart ippp = (uint32_t *) (ph + 1); 601017205eccSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_33); 601117205eccSRandall Stewart ippp++; 601217205eccSRandall Stewart *ippp = asoc->highest_tsn_inside_map; 601317205eccSRandall Stewart ippp++; 601417205eccSRandall Stewart *ippp = new_cum_tsn; 601517205eccSRandall Stewart } 601617205eccSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_33; 601717205eccSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 6018ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 6019f8829a4aSRandall Stewart return; 6020f8829a4aSRandall Stewart } 6021207304d4SRandall Stewart SCTP_STAT_INCR(sctps_fwdtsn_map_over); 60222afb3e84SRandall Stewart slide_out: 60232afb3e84SRandall Stewart memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size); 6024f8829a4aSRandall Stewart cumack_set_flag = 1; 60252afb3e84SRandall Stewart asoc->mapping_array_base_tsn = new_cum_tsn + 1; 60262afb3e84SRandall Stewart asoc->cumulative_tsn = asoc->highest_tsn_inside_map = new_cum_tsn; 6027830d754dSRandall Stewart /* EY - nr_sack: nr_mapping_array version of the above */ 6028830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) { 6029830d754dSRandall Stewart memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.nr_mapping_array_size); 6030830d754dSRandall Stewart asoc->nr_mapping_array_base_tsn = new_cum_tsn + 1; 6031830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = new_cum_tsn; 6032830d754dSRandall Stewart if (asoc->nr_mapping_array_size != asoc->mapping_array_size) { 6033830d754dSRandall Stewart /* 6034830d754dSRandall Stewart * printf("IN sctp_handle_forward_tsn: 6035830d754dSRandall Stewart * Something is wrong the size of" "map and 6036830d754dSRandall Stewart * nr_map should be equal!") 6037830d754dSRandall Stewart */ ; 6038830d754dSRandall Stewart } 6039830d754dSRandall Stewart } 6040b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 6041f8829a4aSRandall Stewart sctp_log_map(0, 3, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 604280fefe0aSRandall Stewart } 6043f8829a4aSRandall Stewart asoc->last_echo_tsn = asoc->highest_tsn_inside_map; 60442afb3e84SRandall Stewart } else { 60452afb3e84SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 60462afb3e84SRandall Stewart if ((compare_with_wrap(((uint32_t) asoc->cumulative_tsn + gap), asoc->highest_tsn_inside_map, MAX_TSN)) || 60472afb3e84SRandall Stewart (((uint32_t) asoc->cumulative_tsn + gap) == asoc->highest_tsn_inside_map)) { 60482afb3e84SRandall Stewart goto slide_out; 60492afb3e84SRandall Stewart } else { 60502afb3e84SRandall Stewart for (i = 0; i <= gap; i++) { 60512afb3e84SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->mapping_array, i); 6052f8829a4aSRandall Stewart } 60532afb3e84SRandall Stewart } 60542afb3e84SRandall Stewart /* 60552afb3e84SRandall Stewart * Now after marking all, slide thing forward but no sack 60562afb3e84SRandall Stewart * please. 60572afb3e84SRandall Stewart */ 60582afb3e84SRandall Stewart sctp_sack_check(stcb, 0, 0, abort_flag); 60592afb3e84SRandall Stewart if (*abort_flag) 60602afb3e84SRandall Stewart return; 60612afb3e84SRandall Stewart } 60622afb3e84SRandall Stewart 6063f8829a4aSRandall Stewart /*************************************************************/ 6064f8829a4aSRandall Stewart /* 2. Clear up re-assembly queue */ 6065f8829a4aSRandall Stewart /*************************************************************/ 6066f8829a4aSRandall Stewart /* 6067f8829a4aSRandall Stewart * First service it if pd-api is up, just in case we can progress it 6068f8829a4aSRandall Stewart * forward 6069f8829a4aSRandall Stewart */ 6070f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 6071f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 6072f8829a4aSRandall Stewart } 6073f8829a4aSRandall Stewart if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 6074f8829a4aSRandall Stewart /* For each one on here see if we need to toss it */ 6075f8829a4aSRandall Stewart /* 6076f8829a4aSRandall Stewart * For now large messages held on the reasmqueue that are 6077f8829a4aSRandall Stewart * complete will be tossed too. We could in theory do more 6078f8829a4aSRandall Stewart * work to spin through and stop after dumping one msg aka 6079f8829a4aSRandall Stewart * seeing the start of a new msg at the head, and call the 6080f8829a4aSRandall Stewart * delivery function... to see if it can be delivered... But 6081f8829a4aSRandall Stewart * for now we just dump everything on the queue. 6082f8829a4aSRandall Stewart */ 6083f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 6084f8829a4aSRandall Stewart while (chk) { 6085f8829a4aSRandall Stewart at = TAILQ_NEXT(chk, sctp_next); 6086f8829a4aSRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, 6087f8829a4aSRandall Stewart chk->rec.data.TSN_seq, MAX_TSN) || 6088f8829a4aSRandall Stewart asoc->cumulative_tsn == chk->rec.data.TSN_seq) { 6089f8829a4aSRandall Stewart /* It needs to be tossed */ 6090f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 6091f8829a4aSRandall Stewart if (compare_with_wrap(chk->rec.data.TSN_seq, 6092f8829a4aSRandall Stewart asoc->tsn_last_delivered, MAX_TSN)) { 6093f8829a4aSRandall Stewart asoc->tsn_last_delivered = 6094f8829a4aSRandall Stewart chk->rec.data.TSN_seq; 6095f8829a4aSRandall Stewart asoc->str_of_pdapi = 6096f8829a4aSRandall Stewart chk->rec.data.stream_number; 6097f8829a4aSRandall Stewart asoc->ssn_of_pdapi = 6098f8829a4aSRandall Stewart chk->rec.data.stream_seq; 6099f8829a4aSRandall Stewart asoc->fragment_flags = 6100f8829a4aSRandall Stewart chk->rec.data.rcv_flags; 6101f8829a4aSRandall Stewart } 6102f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 6103f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 6104f8829a4aSRandall Stewart cnt_gone++; 6105f8829a4aSRandall Stewart 6106f8829a4aSRandall Stewart /* Clear up any stream problem */ 6107f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) != 6108f8829a4aSRandall Stewart SCTP_DATA_UNORDERED && 6109f8829a4aSRandall Stewart (compare_with_wrap(chk->rec.data.stream_seq, 6110f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered, 6111f8829a4aSRandall Stewart MAX_SEQ))) { 6112f8829a4aSRandall Stewart /* 6113f8829a4aSRandall Stewart * We must dump forward this streams 6114f8829a4aSRandall Stewart * sequence number if the chunk is 6115f8829a4aSRandall Stewart * not unordered that is being 6116f8829a4aSRandall Stewart * skipped. There is a chance that 6117f8829a4aSRandall Stewart * if the peer does not include the 6118f8829a4aSRandall Stewart * last fragment in its FWD-TSN we 6119f8829a4aSRandall Stewart * WILL have a problem here since 6120f8829a4aSRandall Stewart * you would have a partial chunk in 6121f8829a4aSRandall Stewart * queue that may not be 6122f8829a4aSRandall Stewart * deliverable. Also if a Partial 6123f8829a4aSRandall Stewart * delivery API as started the user 6124f8829a4aSRandall Stewart * may get a partial chunk. The next 6125f8829a4aSRandall Stewart * read returning a new chunk... 6126f8829a4aSRandall Stewart * really ugly but I see no way 6127f8829a4aSRandall Stewart * around it! Maybe a notify?? 6128f8829a4aSRandall Stewart */ 6129f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered = 6130f8829a4aSRandall Stewart chk->rec.data.stream_seq; 6131f8829a4aSRandall Stewart } 6132f8829a4aSRandall Stewart if (chk->data) { 6133f8829a4aSRandall Stewart sctp_m_freem(chk->data); 6134f8829a4aSRandall Stewart chk->data = NULL; 6135f8829a4aSRandall Stewart } 6136f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 6137f8829a4aSRandall Stewart } else { 6138f8829a4aSRandall Stewart /* 6139f8829a4aSRandall Stewart * Ok we have gone beyond the end of the 6140f8829a4aSRandall Stewart * fwd-tsn's mark. Some checks... 6141f8829a4aSRandall Stewart */ 6142f8829a4aSRandall Stewart if ((asoc->fragmented_delivery_inprogress) && 6143f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG)) { 61449a6142d8SRandall Stewart uint32_t str_seq; 61459a6142d8SRandall Stewart 6146f8829a4aSRandall Stewart /* 6147f8829a4aSRandall Stewart * Special case PD-API is up and 6148f8829a4aSRandall Stewart * what we fwd-tsn' over includes 6149f8829a4aSRandall Stewart * one that had the LAST_FRAG. We no 6150f8829a4aSRandall Stewart * longer need to do the PD-API. 6151f8829a4aSRandall Stewart */ 6152f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 61539a6142d8SRandall Stewart 61549a6142d8SRandall Stewart str_seq = (asoc->str_of_pdapi << 16) | asoc->ssn_of_pdapi; 6155f8829a4aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION, 6156ceaad40aSRandall Stewart stcb, SCTP_PARTIAL_DELIVERY_ABORTED, (void *)&str_seq, SCTP_SO_NOT_LOCKED); 6157f8829a4aSRandall Stewart 6158f8829a4aSRandall Stewart } 6159f8829a4aSRandall Stewart break; 6160f8829a4aSRandall Stewart } 6161f8829a4aSRandall Stewart chk = at; 6162f8829a4aSRandall Stewart } 6163f8829a4aSRandall Stewart } 6164f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 6165f8829a4aSRandall Stewart /* 6166f8829a4aSRandall Stewart * Ok we removed cnt_gone chunks in the PD-API queue that 6167f8829a4aSRandall Stewart * were being delivered. So now we must turn off the flag. 6168f8829a4aSRandall Stewart */ 61699a6142d8SRandall Stewart uint32_t str_seq; 61709a6142d8SRandall Stewart 61719a6142d8SRandall Stewart str_seq = (asoc->str_of_pdapi << 16) | asoc->ssn_of_pdapi; 6172f8829a4aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION, 6173ceaad40aSRandall Stewart stcb, SCTP_PARTIAL_DELIVERY_ABORTED, (void *)&str_seq, SCTP_SO_NOT_LOCKED); 6174f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 6175f8829a4aSRandall Stewart } 6176f8829a4aSRandall Stewart /*************************************************************/ 6177f8829a4aSRandall Stewart /* 3. Update the PR-stream re-ordering queues */ 6178f8829a4aSRandall Stewart /*************************************************************/ 6179f8829a4aSRandall Stewart fwd_sz -= sizeof(*fwd); 6180671d309cSRandall Stewart if (m && fwd_sz) { 6181f8829a4aSRandall Stewart /* New method. */ 6182d61a0ae0SRandall Stewart unsigned int num_str; 6183671d309cSRandall Stewart struct sctp_strseq *stseq, strseqbuf; 6184671d309cSRandall Stewart 6185671d309cSRandall Stewart offset += sizeof(*fwd); 6186f8829a4aSRandall Stewart 6187f8829a4aSRandall Stewart num_str = fwd_sz / sizeof(struct sctp_strseq); 6188f8829a4aSRandall Stewart for (i = 0; i < num_str; i++) { 6189f8829a4aSRandall Stewart uint16_t st; 6190f8829a4aSRandall Stewart 6191671d309cSRandall Stewart stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset, 6192671d309cSRandall Stewart sizeof(struct sctp_strseq), 6193671d309cSRandall Stewart (uint8_t *) & strseqbuf); 6194671d309cSRandall Stewart offset += sizeof(struct sctp_strseq); 61952afb3e84SRandall Stewart if (stseq == NULL) { 6196671d309cSRandall Stewart break; 61972afb3e84SRandall Stewart } 6198f8829a4aSRandall Stewart /* Convert */ 6199851b7298SRandall Stewart st = ntohs(stseq->stream); 6200851b7298SRandall Stewart stseq->stream = st; 6201851b7298SRandall Stewart st = ntohs(stseq->sequence); 6202851b7298SRandall Stewart stseq->sequence = st; 6203f8829a4aSRandall Stewart /* now process */ 6204851b7298SRandall Stewart if (stseq->stream >= asoc->streamincnt) { 62052afb3e84SRandall Stewart /* screwed up streams, stop! */ 62062afb3e84SRandall Stewart break; 6207f8829a4aSRandall Stewart } 6208851b7298SRandall Stewart strm = &asoc->strmin[stseq->stream]; 6209851b7298SRandall Stewart if (compare_with_wrap(stseq->sequence, 6210f8829a4aSRandall Stewart strm->last_sequence_delivered, MAX_SEQ)) { 6211f8829a4aSRandall Stewart /* Update the sequence number */ 6212f8829a4aSRandall Stewart strm->last_sequence_delivered = 6213851b7298SRandall Stewart stseq->sequence; 6214f8829a4aSRandall Stewart } 6215f8829a4aSRandall Stewart /* now kick the stream the new way */ 621604ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 6217f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(stcb, strm); 6218f8829a4aSRandall Stewart } 6219f8829a4aSRandall Stewart } 6220139bc87fSRandall Stewart if (TAILQ_FIRST(&asoc->reasmqueue)) { 6221139bc87fSRandall Stewart /* now lets kick out and check for more fragmented delivery */ 622204ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 6223139bc87fSRandall Stewart sctp_deliver_reasm_check(stcb, &stcb->asoc); 6224139bc87fSRandall Stewart } 6225f8829a4aSRandall Stewart } 6226830d754dSRandall Stewart 6227830d754dSRandall Stewart /* EY fully identical to sctp_express_handle_sack, duplicated for only naming convention */ 6228830d754dSRandall Stewart void 6229830d754dSRandall Stewart sctp_express_handle_nr_sack(struct sctp_tcb *stcb, uint32_t cumack, 6230830d754dSRandall Stewart uint32_t rwnd, int nonce_sum_flag, int *abort_now) 6231830d754dSRandall Stewart { 6232830d754dSRandall Stewart struct sctp_nets *net; 6233830d754dSRandall Stewart struct sctp_association *asoc; 6234830d754dSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 6235830d754dSRandall Stewart uint32_t old_rwnd; 6236830d754dSRandall Stewart int win_probe_recovery = 0; 6237830d754dSRandall Stewart int win_probe_recovered = 0; 6238830d754dSRandall Stewart int j, done_once = 0; 6239830d754dSRandall Stewart 6240830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 6241830d754dSRandall Stewart sctp_misc_ints(SCTP_SACK_LOG_EXPRESS, cumack, 6242830d754dSRandall Stewart rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 6243830d754dSRandall Stewart } 6244830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 6245830d754dSRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 6246830d754dSRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cumack; 6247830d754dSRandall Stewart stcb->asoc.cumack_log_at++; 6248830d754dSRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 6249830d754dSRandall Stewart stcb->asoc.cumack_log_at = 0; 6250830d754dSRandall Stewart } 6251830d754dSRandall Stewart #endif 6252830d754dSRandall Stewart asoc = &stcb->asoc; 6253830d754dSRandall Stewart old_rwnd = asoc->peers_rwnd; 6254830d754dSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, cumack, MAX_TSN)) { 6255830d754dSRandall Stewart /* old ack */ 6256830d754dSRandall Stewart return; 6257830d754dSRandall Stewart } else if (asoc->last_acked_seq == cumack) { 6258830d754dSRandall Stewart /* Window update sack */ 6259830d754dSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 6260830d754dSRandall Stewart (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 6261830d754dSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 6262830d754dSRandall Stewart /* SWS sender side engages */ 6263830d754dSRandall Stewart asoc->peers_rwnd = 0; 6264830d754dSRandall Stewart } 6265830d754dSRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 6266830d754dSRandall Stewart goto again; 6267830d754dSRandall Stewart } 6268830d754dSRandall Stewart return; 6269830d754dSRandall Stewart } 6270830d754dSRandall Stewart /* First setup for CC stuff */ 6271830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 6272830d754dSRandall Stewart net->prev_cwnd = net->cwnd; 6273830d754dSRandall Stewart net->net_ack = 0; 6274830d754dSRandall Stewart net->net_ack2 = 0; 6275830d754dSRandall Stewart 6276830d754dSRandall Stewart /* 6277830d754dSRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 6278830d754dSRandall Stewart * SACK processing 6279830d754dSRandall Stewart */ 6280830d754dSRandall Stewart net->new_pseudo_cumack = 0; 6281830d754dSRandall Stewart net->will_exit_fast_recovery = 0; 6282830d754dSRandall Stewart } 6283830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 6284830d754dSRandall Stewart uint32_t send_s; 6285830d754dSRandall Stewart 6286830d754dSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 6287830d754dSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 6288830d754dSRandall Stewart sctpchunk_listhead); 6289830d754dSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 6290830d754dSRandall Stewart } else { 6291830d754dSRandall Stewart send_s = asoc->sending_seq; 6292830d754dSRandall Stewart } 6293830d754dSRandall Stewart if ((cumack == send_s) || 6294830d754dSRandall Stewart compare_with_wrap(cumack, send_s, MAX_TSN)) { 6295830d754dSRandall Stewart #ifndef INVARIANTS 6296830d754dSRandall Stewart struct mbuf *oper; 6297830d754dSRandall Stewart 6298830d754dSRandall Stewart #endif 6299830d754dSRandall Stewart #ifdef INVARIANTS 6300830d754dSRandall Stewart panic("Impossible sack 1"); 6301830d754dSRandall Stewart #else 6302830d754dSRandall Stewart *abort_now = 1; 6303830d754dSRandall Stewart /* XXX */ 6304830d754dSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 6305830d754dSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 6306830d754dSRandall Stewart if (oper) { 6307830d754dSRandall Stewart struct sctp_paramhdr *ph; 6308830d754dSRandall Stewart uint32_t *ippp; 6309830d754dSRandall Stewart 6310830d754dSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 6311830d754dSRandall Stewart sizeof(uint32_t); 6312830d754dSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 6313830d754dSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 6314830d754dSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 6315830d754dSRandall Stewart ippp = (uint32_t *) (ph + 1); 6316830d754dSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 6317830d754dSRandall Stewart } 6318830d754dSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 6319830d754dSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 6320830d754dSRandall Stewart return; 6321830d754dSRandall Stewart #endif 6322830d754dSRandall Stewart } 6323830d754dSRandall Stewart } 6324830d754dSRandall Stewart asoc->this_sack_highest_gap = cumack; 6325830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 6326830d754dSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 6327830d754dSRandall Stewart stcb->asoc.overall_error_count, 6328830d754dSRandall Stewart 0, 6329830d754dSRandall Stewart SCTP_FROM_SCTP_INDATA, 6330830d754dSRandall Stewart __LINE__); 6331830d754dSRandall Stewart } 6332830d754dSRandall Stewart stcb->asoc.overall_error_count = 0; 6333830d754dSRandall Stewart if (compare_with_wrap(cumack, asoc->last_acked_seq, MAX_TSN)) { 6334830d754dSRandall Stewart /* process the new consecutive TSN first */ 6335830d754dSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 6336830d754dSRandall Stewart while (tp1) { 6337830d754dSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 6338830d754dSRandall Stewart if (compare_with_wrap(cumack, tp1->rec.data.TSN_seq, 6339830d754dSRandall Stewart MAX_TSN) || 6340830d754dSRandall Stewart cumack == tp1->rec.data.TSN_seq) { 6341830d754dSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 6342830d754dSRandall Stewart printf("Warning, an unsent is now acked?\n"); 6343830d754dSRandall Stewart } 6344830d754dSRandall Stewart /* 6345830d754dSRandall Stewart * ECN Nonce: Add the nonce to the sender's 6346830d754dSRandall Stewart * nonce sum 6347830d754dSRandall Stewart */ 6348830d754dSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 6349830d754dSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 6350830d754dSRandall Stewart /* 6351830d754dSRandall Stewart * If it is less than ACKED, it is 6352830d754dSRandall Stewart * now no-longer in flight. Higher 6353830d754dSRandall Stewart * values may occur during marking 6354830d754dSRandall Stewart */ 6355830d754dSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 6356830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 6357830d754dSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 6358830d754dSRandall Stewart tp1->whoTo->flight_size, 6359830d754dSRandall Stewart tp1->book_size, 6360830d754dSRandall Stewart (uintptr_t) tp1->whoTo, 6361830d754dSRandall Stewart tp1->rec.data.TSN_seq); 6362830d754dSRandall Stewart } 6363830d754dSRandall Stewart sctp_flight_size_decrease(tp1); 6364830d754dSRandall Stewart /* sa_ignore NO_NULL_CHK */ 6365830d754dSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 6366830d754dSRandall Stewart } 6367830d754dSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 6368830d754dSRandall Stewart if (tp1->snd_count < 2) { 6369830d754dSRandall Stewart /* 6370830d754dSRandall Stewart * True non-retransmited 6371830d754dSRandall Stewart * chunk 6372830d754dSRandall Stewart */ 6373830d754dSRandall Stewart tp1->whoTo->net_ack2 += 6374830d754dSRandall Stewart tp1->send_size; 6375830d754dSRandall Stewart 6376830d754dSRandall Stewart /* update RTO too? */ 6377830d754dSRandall Stewart if (tp1->do_rtt) { 6378830d754dSRandall Stewart tp1->whoTo->RTO = 6379830d754dSRandall Stewart /* 6380830d754dSRandall Stewart * sa_ignore 6381830d754dSRandall Stewart * NO_NULL_CHK 6382830d754dSRandall Stewart */ 6383830d754dSRandall Stewart sctp_calculate_rto(stcb, 6384830d754dSRandall Stewart asoc, tp1->whoTo, 6385830d754dSRandall Stewart &tp1->sent_rcv_time, 6386830d754dSRandall Stewart sctp_align_safe_nocopy); 6387830d754dSRandall Stewart tp1->do_rtt = 0; 6388830d754dSRandall Stewart } 6389830d754dSRandall Stewart } 6390830d754dSRandall Stewart /* 6391830d754dSRandall Stewart * CMT: CUCv2 algorithm. From the 6392830d754dSRandall Stewart * cumack'd TSNs, for each TSN being 6393830d754dSRandall Stewart * acked for the first time, set the 6394830d754dSRandall Stewart * following variables for the 6395830d754dSRandall Stewart * corresp destination. 6396830d754dSRandall Stewart * new_pseudo_cumack will trigger a 6397830d754dSRandall Stewart * cwnd update. 6398830d754dSRandall Stewart * find_(rtx_)pseudo_cumack will 6399830d754dSRandall Stewart * trigger search for the next 6400830d754dSRandall Stewart * expected (rtx-)pseudo-cumack. 6401830d754dSRandall Stewart */ 6402830d754dSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 6403830d754dSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 6404830d754dSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 6405830d754dSRandall Stewart 6406830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 6407830d754dSRandall Stewart /* sa_ignore NO_NULL_CHK */ 6408830d754dSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 6409830d754dSRandall Stewart } 6410830d754dSRandall Stewart } 6411830d754dSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 6412830d754dSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 6413830d754dSRandall Stewart } 6414830d754dSRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 6415830d754dSRandall Stewart /* deflate the cwnd */ 6416830d754dSRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 6417830d754dSRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 6418830d754dSRandall Stewart } 6419830d754dSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 6420830d754dSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 6421830d754dSRandall Stewart if (tp1->data) { 6422830d754dSRandall Stewart /* sa_ignore NO_NULL_CHK */ 6423830d754dSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 6424830d754dSRandall Stewart sctp_m_freem(tp1->data); 6425830d754dSRandall Stewart } 6426830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 6427830d754dSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 6428830d754dSRandall Stewart cumack, 6429830d754dSRandall Stewart tp1->rec.data.TSN_seq, 6430830d754dSRandall Stewart 0, 6431830d754dSRandall Stewart 0, 6432830d754dSRandall Stewart SCTP_LOG_FREE_SENT); 6433830d754dSRandall Stewart } 6434830d754dSRandall Stewart tp1->data = NULL; 6435830d754dSRandall Stewart asoc->sent_queue_cnt--; 6436830d754dSRandall Stewart sctp_free_a_chunk(stcb, tp1); 6437830d754dSRandall Stewart tp1 = tp2; 6438830d754dSRandall Stewart } else { 6439830d754dSRandall Stewart break; 6440830d754dSRandall Stewart } 6441830d754dSRandall Stewart } 6442830d754dSRandall Stewart 6443830d754dSRandall Stewart } 6444830d754dSRandall Stewart /* sa_ignore NO_NULL_CHK */ 6445830d754dSRandall Stewart if (stcb->sctp_socket) { 6446830d754dSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 6447830d754dSRandall Stewart struct socket *so; 6448830d754dSRandall Stewart 6449830d754dSRandall Stewart #endif 6450830d754dSRandall Stewart 6451830d754dSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 6452830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 6453830d754dSRandall Stewart /* sa_ignore NO_NULL_CHK */ 6454830d754dSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_WAKESND_FROM_SACK); 6455830d754dSRandall Stewart } 6456830d754dSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 6457830d754dSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 6458830d754dSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 6459830d754dSRandall Stewart SCTP_TCB_UNLOCK(stcb); 6460830d754dSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 6461830d754dSRandall Stewart SCTP_TCB_LOCK(stcb); 6462830d754dSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 6463830d754dSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 6464830d754dSRandall Stewart /* assoc was freed while we were unlocked */ 6465830d754dSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 6466830d754dSRandall Stewart return; 6467830d754dSRandall Stewart } 6468830d754dSRandall Stewart #endif 6469830d754dSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 6470830d754dSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 6471830d754dSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 6472830d754dSRandall Stewart #endif 6473830d754dSRandall Stewart } else { 6474830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 6475830d754dSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_NOWAKE_FROM_SACK); 6476830d754dSRandall Stewart } 6477830d754dSRandall Stewart } 6478830d754dSRandall Stewart 6479830d754dSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 6480830d754dSRandall Stewart if (asoc->last_acked_seq != cumack) 6481830d754dSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, 1, 0, 0); 6482830d754dSRandall Stewart 6483830d754dSRandall Stewart asoc->last_acked_seq = cumack; 6484830d754dSRandall Stewart 6485830d754dSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 6486830d754dSRandall Stewart /* nothing left in-flight */ 6487830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 6488830d754dSRandall Stewart net->flight_size = 0; 6489830d754dSRandall Stewart net->partial_bytes_acked = 0; 6490830d754dSRandall Stewart } 6491830d754dSRandall Stewart asoc->total_flight = 0; 6492830d754dSRandall Stewart asoc->total_flight_count = 0; 6493830d754dSRandall Stewart } 6494830d754dSRandall Stewart /* Fix up the a-p-a-p for future PR-SCTP sends */ 6495830d754dSRandall Stewart if (compare_with_wrap(cumack, asoc->advanced_peer_ack_point, MAX_TSN)) { 6496830d754dSRandall Stewart asoc->advanced_peer_ack_point = cumack; 6497830d754dSRandall Stewart } 6498830d754dSRandall Stewart /* ECN Nonce updates */ 6499830d754dSRandall Stewart if (asoc->ecn_nonce_allowed) { 6500830d754dSRandall Stewart if (asoc->nonce_sum_check) { 6501830d754dSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base) & SCTP_SACK_NONCE_SUM)) { 6502830d754dSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 6503830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 6504830d754dSRandall Stewart 6505830d754dSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 6506830d754dSRandall Stewart asoc->nonce_wait_for_ecne = 1; 6507830d754dSRandall Stewart if (lchk) { 6508830d754dSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 6509830d754dSRandall Stewart } else { 6510830d754dSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 6511830d754dSRandall Stewart } 6512830d754dSRandall Stewart } else { 6513830d754dSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) || 6514830d754dSRandall Stewart (asoc->last_acked_seq == asoc->nonce_wait_tsn)) { 6515830d754dSRandall Stewart /* 6516830d754dSRandall Stewart * Misbehaving peer. We need 6517830d754dSRandall Stewart * to react to this guy 6518830d754dSRandall Stewart */ 6519830d754dSRandall Stewart asoc->ecn_allowed = 0; 6520830d754dSRandall Stewart asoc->ecn_nonce_allowed = 0; 6521830d754dSRandall Stewart } 6522830d754dSRandall Stewart } 6523830d754dSRandall Stewart } 6524830d754dSRandall Stewart } else { 6525830d754dSRandall Stewart /* See if Resynchronization Possible */ 6526830d754dSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) { 6527830d754dSRandall Stewart asoc->nonce_sum_check = 1; 6528830d754dSRandall Stewart /* 6529830d754dSRandall Stewart * now we must calculate what the base is. 6530830d754dSRandall Stewart * We do this based on two things, we know 6531830d754dSRandall Stewart * the total's for all the segments 6532830d754dSRandall Stewart * gap-acked in the SACK (none), We also 6533830d754dSRandall Stewart * know the SACK's nonce sum, its in 6534830d754dSRandall Stewart * nonce_sum_flag. So we can build a truth 6535830d754dSRandall Stewart * table to back-calculate the new value of 6536830d754dSRandall Stewart * asoc->nonce_sum_expect_base: 6537830d754dSRandall Stewart * 6538830d754dSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 6539830d754dSRandall Stewart * 1 0 1 0 1 1 1 1 0 6540830d754dSRandall Stewart */ 6541830d754dSRandall Stewart asoc->nonce_sum_expect_base = (0 ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 6542830d754dSRandall Stewart } 6543830d754dSRandall Stewart } 6544830d754dSRandall Stewart } 6545830d754dSRandall Stewart /* RWND update */ 6546830d754dSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 6547830d754dSRandall Stewart (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 6548830d754dSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 6549830d754dSRandall Stewart /* SWS sender side engages */ 6550830d754dSRandall Stewart asoc->peers_rwnd = 0; 6551830d754dSRandall Stewart } 6552830d754dSRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 6553830d754dSRandall Stewart win_probe_recovery = 1; 6554830d754dSRandall Stewart } 6555830d754dSRandall Stewart /* Now assure a timer where data is queued at */ 6556830d754dSRandall Stewart again: 6557830d754dSRandall Stewart j = 0; 6558830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 65595171328bSRandall Stewart int to_ticks; 65605171328bSRandall Stewart 6561830d754dSRandall Stewart if (win_probe_recovery && (net->window_probe)) { 6562830d754dSRandall Stewart win_probe_recovered = 1; 6563830d754dSRandall Stewart /* 6564830d754dSRandall Stewart * Find first chunk that was used with window probe 6565830d754dSRandall Stewart * and clear the sent 6566830d754dSRandall Stewart */ 6567830d754dSRandall Stewart /* sa_ignore FREED_MEMORY */ 6568830d754dSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 6569830d754dSRandall Stewart if (tp1->window_probe) { 6570830d754dSRandall Stewart /* move back to data send queue */ 6571830d754dSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 6572830d754dSRandall Stewart break; 6573830d754dSRandall Stewart } 6574830d754dSRandall Stewart } 6575830d754dSRandall Stewart } 6576830d754dSRandall Stewart if (net->RTO == 0) { 6577830d754dSRandall Stewart to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto); 6578830d754dSRandall Stewart } else { 6579830d754dSRandall Stewart to_ticks = MSEC_TO_TICKS(net->RTO); 6580830d754dSRandall Stewart } 65815171328bSRandall Stewart if (net->flight_size) { 65825171328bSRandall Stewart 6583830d754dSRandall Stewart j++; 6584830d754dSRandall Stewart (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 6585830d754dSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 65865171328bSRandall Stewart if (net->window_probe) { 65875171328bSRandall Stewart net->window_probe = 0; 65885171328bSRandall Stewart } 6589830d754dSRandall Stewart } else { 65905171328bSRandall Stewart if (net->window_probe) { 65915171328bSRandall Stewart /* 65925171328bSRandall Stewart * In window probes we must assure a timer 65935171328bSRandall Stewart * is still running there 65945171328bSRandall Stewart */ 65955171328bSRandall Stewart net->window_probe = 0; 65965171328bSRandall Stewart (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 65975171328bSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 65985171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 6599830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 6600830d754dSRandall Stewart stcb, net, 6601830d754dSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 6602830d754dSRandall Stewart } 6603830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 6604830d754dSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 6605830d754dSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 6606830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 6607830d754dSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 6608830d754dSRandall Stewart } 6609830d754dSRandall Stewart } 6610830d754dSRandall Stewart } 6611830d754dSRandall Stewart } 6612830d754dSRandall Stewart if ((j == 0) && 6613830d754dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 6614830d754dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 6615830d754dSRandall Stewart (win_probe_recovered == 0) && 6616830d754dSRandall Stewart (done_once == 0)) { 6617830d754dSRandall Stewart /* huh, this should not happen */ 6618830d754dSRandall Stewart sctp_fs_audit(asoc); 6619830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 6620830d754dSRandall Stewart net->flight_size = 0; 6621830d754dSRandall Stewart } 6622830d754dSRandall Stewart asoc->total_flight = 0; 6623830d754dSRandall Stewart asoc->total_flight_count = 0; 6624830d754dSRandall Stewart asoc->sent_queue_retran_cnt = 0; 6625830d754dSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 6626830d754dSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 6627830d754dSRandall Stewart sctp_flight_size_increase(tp1); 6628830d754dSRandall Stewart sctp_total_flight_increase(stcb, tp1); 6629830d754dSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 6630830d754dSRandall Stewart asoc->sent_queue_retran_cnt++; 6631830d754dSRandall Stewart } 6632830d754dSRandall Stewart } 6633830d754dSRandall Stewart done_once = 1; 6634830d754dSRandall Stewart goto again; 6635830d754dSRandall Stewart } 6636830d754dSRandall Stewart /**********************************/ 6637830d754dSRandall Stewart /* Now what about shutdown issues */ 6638830d754dSRandall Stewart /**********************************/ 6639830d754dSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 6640830d754dSRandall Stewart /* nothing left on sendqueue.. consider done */ 6641830d754dSRandall Stewart /* clean up */ 6642830d754dSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 6643830d754dSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 6644830d754dSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 6645830d754dSRandall Stewart (asoc->locked_on_sending) 6646830d754dSRandall Stewart ) { 6647830d754dSRandall Stewart struct sctp_stream_queue_pending *sp; 6648830d754dSRandall Stewart 6649830d754dSRandall Stewart /* 6650830d754dSRandall Stewart * I may be in a state where we got all across.. but 6651830d754dSRandall Stewart * cannot write more due to a shutdown... we abort 6652830d754dSRandall Stewart * since the user did not indicate EOR in this case. 6653830d754dSRandall Stewart * The sp will be cleaned during free of the asoc. 6654830d754dSRandall Stewart */ 6655830d754dSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 6656830d754dSRandall Stewart sctp_streamhead); 6657830d754dSRandall Stewart if ((sp) && (sp->length == 0)) { 6658830d754dSRandall Stewart /* Let cleanup code purge it */ 6659830d754dSRandall Stewart if (sp->msg_is_complete) { 6660830d754dSRandall Stewart asoc->stream_queue_cnt--; 6661830d754dSRandall Stewart } else { 6662830d754dSRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 6663830d754dSRandall Stewart asoc->locked_on_sending = NULL; 6664830d754dSRandall Stewart asoc->stream_queue_cnt--; 6665830d754dSRandall Stewart } 6666830d754dSRandall Stewart } 6667830d754dSRandall Stewart } 6668830d754dSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 6669830d754dSRandall Stewart (asoc->stream_queue_cnt == 0)) { 6670830d754dSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 6671830d754dSRandall Stewart /* Need to abort here */ 6672830d754dSRandall Stewart struct mbuf *oper; 6673830d754dSRandall Stewart 6674830d754dSRandall Stewart abort_out_now: 6675830d754dSRandall Stewart *abort_now = 1; 6676830d754dSRandall Stewart /* XXX */ 6677830d754dSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 6678830d754dSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 6679830d754dSRandall Stewart if (oper) { 6680830d754dSRandall Stewart struct sctp_paramhdr *ph; 6681830d754dSRandall Stewart uint32_t *ippp; 6682830d754dSRandall Stewart 6683830d754dSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 6684830d754dSRandall Stewart sizeof(uint32_t); 6685830d754dSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 6686830d754dSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 6687830d754dSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 6688830d754dSRandall Stewart ippp = (uint32_t *) (ph + 1); 6689830d754dSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_24); 6690830d754dSRandall Stewart } 6691830d754dSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24; 6692830d754dSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 6693830d754dSRandall Stewart } else { 6694830d754dSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 6695830d754dSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 6696830d754dSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 6697830d754dSRandall Stewart } 6698830d754dSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 6699830d754dSRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 6700830d754dSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 6701830d754dSRandall Stewart sctp_send_shutdown(stcb, 6702830d754dSRandall Stewart stcb->asoc.primary_destination); 6703830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 6704830d754dSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 6705830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 6706830d754dSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 6707830d754dSRandall Stewart } 6708830d754dSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 6709830d754dSRandall Stewart (asoc->stream_queue_cnt == 0)) { 6710830d754dSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 6711830d754dSRandall Stewart goto abort_out_now; 6712830d754dSRandall Stewart } 6713830d754dSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 6714830d754dSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 6715830d754dSRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 6716830d754dSRandall Stewart sctp_send_shutdown_ack(stcb, 6717830d754dSRandall Stewart stcb->asoc.primary_destination); 6718830d754dSRandall Stewart 6719830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 6720830d754dSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 6721830d754dSRandall Stewart } 6722830d754dSRandall Stewart } 6723830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 6724830d754dSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 6725830d754dSRandall Stewart rwnd, 6726830d754dSRandall Stewart stcb->asoc.peers_rwnd, 6727830d754dSRandall Stewart stcb->asoc.total_flight, 6728830d754dSRandall Stewart stcb->asoc.total_output_queue_size); 6729830d754dSRandall Stewart } 6730830d754dSRandall Stewart } 6731830d754dSRandall Stewart 6732830d754dSRandall Stewart /* EY! nr_sack version of sctp_handle_segments, nr-gapped TSNs get removed from RtxQ in this method*/ 6733830d754dSRandall Stewart static void 6734830d754dSRandall Stewart sctp_handle_nr_sack_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct sctp_association *asoc, 6735830d754dSRandall Stewart struct sctp_nr_sack_chunk *ch, uint32_t last_tsn, uint32_t * biggest_tsn_acked, 6736830d754dSRandall Stewart uint32_t * biggest_newly_acked_tsn, uint32_t * this_sack_lowest_newack, 6737830d754dSRandall Stewart uint32_t num_seg, uint32_t num_nr_seg, int *ecn_seg_sums) 6738830d754dSRandall Stewart { 6739830d754dSRandall Stewart /************************************************/ 6740830d754dSRandall Stewart /* process fragments and update sendqueue */ 6741830d754dSRandall Stewart /************************************************/ 6742830d754dSRandall Stewart struct sctp_nr_sack *nr_sack; 6743830d754dSRandall Stewart struct sctp_gap_ack_block *frag, block; 6744830d754dSRandall Stewart struct sctp_nr_gap_ack_block *nr_frag, nr_block; 6745830d754dSRandall Stewart struct sctp_tmit_chunk *tp1; 6746830d754dSRandall Stewart uint32_t i, j, all_bit; 6747830d754dSRandall Stewart int wake_him = 0; 6748830d754dSRandall Stewart uint32_t theTSN; 6749830d754dSRandall Stewart int num_frs = 0; 6750830d754dSRandall Stewart 6751830d754dSRandall Stewart uint16_t frag_strt, frag_end, primary_flag_set; 6752830d754dSRandall Stewart uint16_t nr_frag_strt, nr_frag_end; 6753830d754dSRandall Stewart 6754830d754dSRandall Stewart uint32_t last_frag_high; 6755830d754dSRandall Stewart uint32_t last_nr_frag_high; 6756830d754dSRandall Stewart 6757830d754dSRandall Stewart all_bit = ch->ch.chunk_flags & SCTP_NR_SACK_ALL_BIT; 6758830d754dSRandall Stewart 6759830d754dSRandall Stewart /* 6760830d754dSRandall Stewart * @@@ JRI : TODO: This flag is not used anywhere .. remove? 6761830d754dSRandall Stewart */ 6762830d754dSRandall Stewart if (asoc->primary_destination->dest_state & SCTP_ADDR_SWITCH_PRIMARY) { 6763830d754dSRandall Stewart primary_flag_set = 1; 6764830d754dSRandall Stewart } else { 6765830d754dSRandall Stewart primary_flag_set = 0; 6766830d754dSRandall Stewart } 6767830d754dSRandall Stewart nr_sack = &ch->nr_sack; 6768830d754dSRandall Stewart 6769830d754dSRandall Stewart /* 6770830d754dSRandall Stewart * EY! - I will process nr_gaps similarly,by going to this position 6771830d754dSRandall Stewart * again if All bit is set 6772830d754dSRandall Stewart */ 6773830d754dSRandall Stewart frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, 6774830d754dSRandall Stewart sizeof(struct sctp_gap_ack_block), (uint8_t *) & block); 6775830d754dSRandall Stewart *offset += sizeof(block); 6776830d754dSRandall Stewart if (frag == NULL) { 6777830d754dSRandall Stewart return; 6778830d754dSRandall Stewart } 6779830d754dSRandall Stewart tp1 = NULL; 6780830d754dSRandall Stewart last_frag_high = 0; 6781830d754dSRandall Stewart for (i = 0; i < num_seg; i++) { 6782830d754dSRandall Stewart frag_strt = ntohs(frag->start); 6783830d754dSRandall Stewart frag_end = ntohs(frag->end); 6784830d754dSRandall Stewart /* some sanity checks on the fargment offsets */ 6785830d754dSRandall Stewart if (frag_strt > frag_end) { 6786830d754dSRandall Stewart /* this one is malformed, skip */ 6787830d754dSRandall Stewart frag++; 6788830d754dSRandall Stewart continue; 6789830d754dSRandall Stewart } 6790830d754dSRandall Stewart if (compare_with_wrap((frag_end + last_tsn), *biggest_tsn_acked, 6791830d754dSRandall Stewart MAX_TSN)) 6792830d754dSRandall Stewart *biggest_tsn_acked = frag_end + last_tsn; 6793830d754dSRandall Stewart 6794830d754dSRandall Stewart /* mark acked dgs and find out the highestTSN being acked */ 6795830d754dSRandall Stewart if (tp1 == NULL) { 6796830d754dSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 6797830d754dSRandall Stewart 6798830d754dSRandall Stewart /* save the locations of the last frags */ 6799830d754dSRandall Stewart last_frag_high = frag_end + last_tsn; 6800830d754dSRandall Stewart } else { 6801830d754dSRandall Stewart /* 6802830d754dSRandall Stewart * now lets see if we need to reset the queue due to 6803830d754dSRandall Stewart * a out-of-order SACK fragment 6804830d754dSRandall Stewart */ 6805830d754dSRandall Stewart if (compare_with_wrap(frag_strt + last_tsn, 6806830d754dSRandall Stewart last_frag_high, MAX_TSN)) { 6807830d754dSRandall Stewart /* 6808830d754dSRandall Stewart * if the new frag starts after the last TSN 6809830d754dSRandall Stewart * frag covered, we are ok and this one is 6810830d754dSRandall Stewart * beyond the last one 6811830d754dSRandall Stewart */ 6812830d754dSRandall Stewart ; 6813830d754dSRandall Stewart } else { 6814830d754dSRandall Stewart /* 6815830d754dSRandall Stewart * ok, they have reset us, so we need to 6816830d754dSRandall Stewart * reset the queue this will cause extra 6817830d754dSRandall Stewart * hunting but hey, they chose the 6818830d754dSRandall Stewart * performance hit when they failed to order 6819830d754dSRandall Stewart * there gaps.. 6820830d754dSRandall Stewart */ 6821830d754dSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 6822830d754dSRandall Stewart } 6823830d754dSRandall Stewart last_frag_high = frag_end + last_tsn; 6824830d754dSRandall Stewart } 6825830d754dSRandall Stewart for (j = frag_strt; j <= frag_end; j++) { 6826830d754dSRandall Stewart theTSN = j + last_tsn; 6827830d754dSRandall Stewart while (tp1) { 6828830d754dSRandall Stewart if (tp1->rec.data.doing_fast_retransmit) 6829830d754dSRandall Stewart num_frs++; 6830830d754dSRandall Stewart 6831830d754dSRandall Stewart /* 6832830d754dSRandall Stewart * CMT: CUCv2 algorithm. For each TSN being 6833830d754dSRandall Stewart * processed from the sent queue, track the 6834830d754dSRandall Stewart * next expected pseudo-cumack, or 6835830d754dSRandall Stewart * rtx_pseudo_cumack, if required. Separate 6836830d754dSRandall Stewart * cumack trackers for first transmissions, 6837830d754dSRandall Stewart * and retransmissions. 6838830d754dSRandall Stewart */ 6839830d754dSRandall Stewart if ((tp1->whoTo->find_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 6840830d754dSRandall Stewart (tp1->snd_count == 1)) { 6841830d754dSRandall Stewart tp1->whoTo->pseudo_cumack = tp1->rec.data.TSN_seq; 6842830d754dSRandall Stewart tp1->whoTo->find_pseudo_cumack = 0; 6843830d754dSRandall Stewart } 6844830d754dSRandall Stewart if ((tp1->whoTo->find_rtx_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 6845830d754dSRandall Stewart (tp1->snd_count > 1)) { 6846830d754dSRandall Stewart tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.TSN_seq; 6847830d754dSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 0; 6848830d754dSRandall Stewart } 6849830d754dSRandall Stewart if (tp1->rec.data.TSN_seq == theTSN) { 6850830d754dSRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 6851830d754dSRandall Stewart /* 6852830d754dSRandall Stewart * must be held until 6853830d754dSRandall Stewart * cum-ack passes 6854830d754dSRandall Stewart */ 6855830d754dSRandall Stewart /* 6856830d754dSRandall Stewart * ECN Nonce: Add the nonce 6857830d754dSRandall Stewart * value to the sender's 6858830d754dSRandall Stewart * nonce sum 6859830d754dSRandall Stewart */ 6860830d754dSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 6861830d754dSRandall Stewart /*- 6862830d754dSRandall Stewart * If it is less than RESEND, it is 6863830d754dSRandall Stewart * now no-longer in flight. 6864830d754dSRandall Stewart * Higher values may already be set 6865830d754dSRandall Stewart * via previous Gap Ack Blocks... 6866830d754dSRandall Stewart * i.e. ACKED or RESEND. 6867830d754dSRandall Stewart */ 6868830d754dSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 6869830d754dSRandall Stewart *biggest_newly_acked_tsn, MAX_TSN)) { 6870830d754dSRandall Stewart *biggest_newly_acked_tsn = tp1->rec.data.TSN_seq; 6871830d754dSRandall Stewart } 6872830d754dSRandall Stewart /* 6873830d754dSRandall Stewart * CMT: SFR algo 6874830d754dSRandall Stewart * (and HTNA) - set 6875830d754dSRandall Stewart * saw_newack to 1 6876830d754dSRandall Stewart * for dest being 6877830d754dSRandall Stewart * newly acked. 6878830d754dSRandall Stewart * update 6879830d754dSRandall Stewart * this_sack_highest_ 6880830d754dSRandall Stewart * newack if 6881830d754dSRandall Stewart * appropriate. 6882830d754dSRandall Stewart */ 6883830d754dSRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) 6884830d754dSRandall Stewart tp1->whoTo->saw_newack = 1; 6885830d754dSRandall Stewart 6886830d754dSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 6887830d754dSRandall Stewart tp1->whoTo->this_sack_highest_newack, 6888830d754dSRandall Stewart MAX_TSN)) { 6889830d754dSRandall Stewart tp1->whoTo->this_sack_highest_newack = 6890830d754dSRandall Stewart tp1->rec.data.TSN_seq; 6891830d754dSRandall Stewart } 6892830d754dSRandall Stewart /* 6893830d754dSRandall Stewart * CMT DAC algo: 6894830d754dSRandall Stewart * also update 6895830d754dSRandall Stewart * this_sack_lowest_n 6896830d754dSRandall Stewart * ewack 6897830d754dSRandall Stewart */ 6898830d754dSRandall Stewart if (*this_sack_lowest_newack == 0) { 6899830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 6900830d754dSRandall Stewart sctp_log_sack(*this_sack_lowest_newack, 6901830d754dSRandall Stewart last_tsn, 6902830d754dSRandall Stewart tp1->rec.data.TSN_seq, 6903830d754dSRandall Stewart 0, 6904830d754dSRandall Stewart 0, 6905830d754dSRandall Stewart SCTP_LOG_TSN_ACKED); 6906830d754dSRandall Stewart } 6907830d754dSRandall Stewart *this_sack_lowest_newack = tp1->rec.data.TSN_seq; 6908830d754dSRandall Stewart } 6909830d754dSRandall Stewart /* 6910830d754dSRandall Stewart * CMT: CUCv2 6911830d754dSRandall Stewart * algorithm. If 6912830d754dSRandall Stewart * (rtx-)pseudo-cumac 6913830d754dSRandall Stewart * k for corresp 6914830d754dSRandall Stewart * dest is being 6915830d754dSRandall Stewart * acked, then we 6916830d754dSRandall Stewart * have a new 6917830d754dSRandall Stewart * (rtx-)pseudo-cumac 6918830d754dSRandall Stewart * k. Set 6919830d754dSRandall Stewart * new_(rtx_)pseudo_c 6920830d754dSRandall Stewart * umack to TRUE so 6921830d754dSRandall Stewart * that the cwnd for 6922830d754dSRandall Stewart * this dest can be 6923830d754dSRandall Stewart * updated. Also 6924830d754dSRandall Stewart * trigger search 6925830d754dSRandall Stewart * for the next 6926830d754dSRandall Stewart * expected 6927830d754dSRandall Stewart * (rtx-)pseudo-cumac 6928830d754dSRandall Stewart * k. Separate 6929830d754dSRandall Stewart * pseudo_cumack 6930830d754dSRandall Stewart * trackers for 6931830d754dSRandall Stewart * first 6932830d754dSRandall Stewart * transmissions and 6933830d754dSRandall Stewart * retransmissions. 6934830d754dSRandall Stewart */ 6935830d754dSRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->pseudo_cumack) { 6936830d754dSRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 6937830d754dSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 6938830d754dSRandall Stewart } 6939830d754dSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 6940830d754dSRandall Stewart } 6941830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 6942830d754dSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 6943830d754dSRandall Stewart } 6944830d754dSRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->rtx_pseudo_cumack) { 6945830d754dSRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 6946830d754dSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 6947830d754dSRandall Stewart } 6948830d754dSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 6949830d754dSRandall Stewart } 6950830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 6951830d754dSRandall Stewart sctp_log_sack(*biggest_newly_acked_tsn, 6952830d754dSRandall Stewart last_tsn, 6953830d754dSRandall Stewart tp1->rec.data.TSN_seq, 6954830d754dSRandall Stewart frag_strt, 6955830d754dSRandall Stewart frag_end, 6956830d754dSRandall Stewart SCTP_LOG_TSN_ACKED); 6957830d754dSRandall Stewart } 6958830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 6959830d754dSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP, 6960830d754dSRandall Stewart tp1->whoTo->flight_size, 6961830d754dSRandall Stewart tp1->book_size, 6962830d754dSRandall Stewart (uintptr_t) tp1->whoTo, 6963830d754dSRandall Stewart tp1->rec.data.TSN_seq); 6964830d754dSRandall Stewart } 6965830d754dSRandall Stewart sctp_flight_size_decrease(tp1); 6966830d754dSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 6967830d754dSRandall Stewart 6968830d754dSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 6969830d754dSRandall Stewart if (tp1->snd_count < 2) { 6970830d754dSRandall Stewart /* 6971830d754dSRandall Stewart * True 6972830d754dSRandall Stewart * non-retran 6973830d754dSRandall Stewart * smited 6974830d754dSRandall Stewart * chunk 6975830d754dSRandall Stewart */ 6976830d754dSRandall Stewart tp1->whoTo->net_ack2 += tp1->send_size; 6977830d754dSRandall Stewart 6978830d754dSRandall Stewart /* 6979830d754dSRandall Stewart * update 6980830d754dSRandall Stewart * RTO too ? 6981830d754dSRandall Stewart */ 6982830d754dSRandall Stewart if (tp1->do_rtt) { 6983830d754dSRandall Stewart tp1->whoTo->RTO = 6984830d754dSRandall Stewart sctp_calculate_rto(stcb, 6985830d754dSRandall Stewart asoc, 6986830d754dSRandall Stewart tp1->whoTo, 6987830d754dSRandall Stewart &tp1->sent_rcv_time, 6988830d754dSRandall Stewart sctp_align_safe_nocopy); 6989830d754dSRandall Stewart tp1->do_rtt = 0; 6990830d754dSRandall Stewart } 6991830d754dSRandall Stewart } 6992830d754dSRandall Stewart } 6993830d754dSRandall Stewart if (tp1->sent <= SCTP_DATAGRAM_RESEND) { 6994830d754dSRandall Stewart (*ecn_seg_sums) += tp1->rec.data.ect_nonce; 6995830d754dSRandall Stewart (*ecn_seg_sums) &= SCTP_SACK_NONCE_SUM; 6996830d754dSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 6997830d754dSRandall Stewart asoc->this_sack_highest_gap, 6998830d754dSRandall Stewart MAX_TSN)) { 6999830d754dSRandall Stewart asoc->this_sack_highest_gap = 7000830d754dSRandall Stewart tp1->rec.data.TSN_seq; 7001830d754dSRandall Stewart } 7002830d754dSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 7003830d754dSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 7004830d754dSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 7005830d754dSRandall Stewart sctp_audit_log(0xB2, 7006830d754dSRandall Stewart (asoc->sent_queue_retran_cnt & 0x000000ff)); 7007830d754dSRandall Stewart #endif 7008830d754dSRandall Stewart } 7009830d754dSRandall Stewart } 7010830d754dSRandall Stewart /* 7011830d754dSRandall Stewart * All chunks NOT UNSENT 7012830d754dSRandall Stewart * fall through here and are 7013830d754dSRandall Stewart * marked 7014830d754dSRandall Stewart */ 7015830d754dSRandall Stewart tp1->sent = SCTP_DATAGRAM_MARKED; 7016830d754dSRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 7017830d754dSRandall Stewart /* deflate the cwnd */ 7018830d754dSRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 7019830d754dSRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 7020830d754dSRandall Stewart } 7021830d754dSRandall Stewart /* 7022830d754dSRandall Stewart * EY - if all bit is set 7023830d754dSRandall Stewart * then this TSN is 7024830d754dSRandall Stewart * nr_marked 7025830d754dSRandall Stewart */ 7026830d754dSRandall Stewart if (all_bit) { 7027830d754dSRandall Stewart tp1->sent = SCTP_DATAGRAM_NR_MARKED; 7028830d754dSRandall Stewart /* 7029830d754dSRandall Stewart * TAILQ_REMOVE(&asoc 7030830d754dSRandall Stewart * ->sent_queue, 7031830d754dSRandall Stewart * tp1, sctp_next); 7032830d754dSRandall Stewart */ 7033830d754dSRandall Stewart if (tp1->data) { 7034830d754dSRandall Stewart /* 7035830d754dSRandall Stewart * sa_ignore 7036830d754dSRandall Stewart * NO_NULL_CH 7037830d754dSRandall Stewart * K 7038830d754dSRandall Stewart */ 7039830d754dSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 7040830d754dSRandall Stewart sctp_m_freem(tp1->data); 7041830d754dSRandall Stewart } 7042830d754dSRandall Stewart tp1->data = NULL; 7043830d754dSRandall Stewart /* 7044830d754dSRandall Stewart * asoc->sent_queue_c 7045830d754dSRandall Stewart * nt--; 7046830d754dSRandall Stewart */ 7047830d754dSRandall Stewart /* 7048830d754dSRandall Stewart * sctp_free_a_chunk( 7049830d754dSRandall Stewart * stcb, tp1); 7050830d754dSRandall Stewart */ 7051830d754dSRandall Stewart wake_him++; 7052830d754dSRandall Stewart } 7053830d754dSRandall Stewart } 7054830d754dSRandall Stewart break; 7055830d754dSRandall Stewart } /* if (tp1->TSN_seq == theTSN) */ 7056830d754dSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, theTSN, 7057830d754dSRandall Stewart MAX_TSN)) 7058830d754dSRandall Stewart break; 7059830d754dSRandall Stewart 7060830d754dSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 7061830d754dSRandall Stewart } /* end while (tp1) */ 7062830d754dSRandall Stewart } /* end for (j = fragStart */ 7063830d754dSRandall Stewart frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, 7064830d754dSRandall Stewart sizeof(struct sctp_gap_ack_block), (uint8_t *) & block); 7065830d754dSRandall Stewart *offset += sizeof(block); 7066830d754dSRandall Stewart if (frag == NULL) { 7067830d754dSRandall Stewart break; 7068830d754dSRandall Stewart } 7069830d754dSRandall Stewart } 7070830d754dSRandall Stewart 7071830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 7072830d754dSRandall Stewart if (num_frs) 7073830d754dSRandall Stewart sctp_log_fr(*biggest_tsn_acked, 7074830d754dSRandall Stewart *biggest_newly_acked_tsn, 7075830d754dSRandall Stewart last_tsn, SCTP_FR_LOG_BIGGEST_TSNS); 7076830d754dSRandall Stewart } 7077830d754dSRandall Stewart /* 7078830d754dSRandall Stewart * EY - if all bit is not set then there should be other loops to 7079830d754dSRandall Stewart * identify nr TSNs 7080830d754dSRandall Stewart */ 7081830d754dSRandall Stewart if (!all_bit) { 7082830d754dSRandall Stewart 7083830d754dSRandall Stewart nr_frag = (struct sctp_nr_gap_ack_block *)sctp_m_getptr(m, *offset, 7084830d754dSRandall Stewart sizeof(struct sctp_nr_gap_ack_block), (uint8_t *) & nr_block); 7085830d754dSRandall Stewart *offset += sizeof(nr_block); 7086830d754dSRandall Stewart 7087830d754dSRandall Stewart 7088830d754dSRandall Stewart 7089830d754dSRandall Stewart if (nr_frag == NULL) { 7090830d754dSRandall Stewart return; 7091830d754dSRandall Stewart } 7092830d754dSRandall Stewart tp1 = NULL; 7093830d754dSRandall Stewart last_nr_frag_high = 0; 7094830d754dSRandall Stewart 7095830d754dSRandall Stewart for (i = 0; i < num_nr_seg; i++) { 7096830d754dSRandall Stewart 7097830d754dSRandall Stewart nr_frag_strt = ntohs(nr_frag->start); 7098830d754dSRandall Stewart nr_frag_end = ntohs(nr_frag->end); 7099830d754dSRandall Stewart 7100830d754dSRandall Stewart /* some sanity checks on the nr fargment offsets */ 7101830d754dSRandall Stewart if (nr_frag_strt > nr_frag_end) { 7102830d754dSRandall Stewart /* this one is malformed, skip */ 7103830d754dSRandall Stewart nr_frag++; 7104830d754dSRandall Stewart continue; 7105830d754dSRandall Stewart } 7106830d754dSRandall Stewart /* 7107830d754dSRandall Stewart * mark acked dgs and find out the highestTSN being 7108830d754dSRandall Stewart * acked 7109830d754dSRandall Stewart */ 7110830d754dSRandall Stewart if (tp1 == NULL) { 7111830d754dSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 7112830d754dSRandall Stewart 7113830d754dSRandall Stewart /* save the locations of the last frags */ 7114830d754dSRandall Stewart last_nr_frag_high = nr_frag_end + last_tsn; 7115830d754dSRandall Stewart } else { 7116830d754dSRandall Stewart /* 7117830d754dSRandall Stewart * now lets see if we need to reset the 7118830d754dSRandall Stewart * queue due to a out-of-order SACK fragment 7119830d754dSRandall Stewart */ 7120830d754dSRandall Stewart if (compare_with_wrap(nr_frag_strt + last_tsn, 7121830d754dSRandall Stewart last_nr_frag_high, MAX_TSN)) { 7122830d754dSRandall Stewart /* 7123830d754dSRandall Stewart * if the new frag starts after the 7124830d754dSRandall Stewart * last TSN frag covered, we are ok 7125830d754dSRandall Stewart * and this one is beyond the last 7126830d754dSRandall Stewart * one 7127830d754dSRandall Stewart */ 7128830d754dSRandall Stewart ; 7129830d754dSRandall Stewart } else { 7130830d754dSRandall Stewart /* 7131830d754dSRandall Stewart * ok, they have reset us, so we 7132830d754dSRandall Stewart * need to reset the queue this will 7133830d754dSRandall Stewart * cause extra hunting but hey, they 7134830d754dSRandall Stewart * chose the performance hit when 7135830d754dSRandall Stewart * they failed to order there gaps.. 7136830d754dSRandall Stewart */ 7137830d754dSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 7138830d754dSRandall Stewart } 7139830d754dSRandall Stewart last_nr_frag_high = nr_frag_end + last_tsn; 7140830d754dSRandall Stewart } 7141830d754dSRandall Stewart 7142830d754dSRandall Stewart for (j = nr_frag_strt + last_tsn; (compare_with_wrap((nr_frag_end + last_tsn), j, MAX_TSN)); j++) { 7143830d754dSRandall Stewart while (tp1) { 7144830d754dSRandall Stewart if (tp1->rec.data.TSN_seq == j) { 7145830d754dSRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 7146830d754dSRandall Stewart tp1->sent = SCTP_DATAGRAM_NR_MARKED; 7147830d754dSRandall Stewart /* 7148830d754dSRandall Stewart * TAILQ_REMOVE(&asoc 7149830d754dSRandall Stewart * ->sent_queue, 7150830d754dSRandall Stewart * tp1, sctp_next); 7151830d754dSRandall Stewart */ 7152830d754dSRandall Stewart if (tp1->data) { 7153830d754dSRandall Stewart /* 7154830d754dSRandall Stewart * sa_ignore 7155830d754dSRandall Stewart * NO_NULL_CH 7156830d754dSRandall Stewart * K 7157830d754dSRandall Stewart */ 7158830d754dSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 7159830d754dSRandall Stewart sctp_m_freem(tp1->data); 7160830d754dSRandall Stewart } 7161830d754dSRandall Stewart tp1->data = NULL; 7162830d754dSRandall Stewart /* 7163830d754dSRandall Stewart * asoc->sent_queue_c 7164830d754dSRandall Stewart * nt--; 7165830d754dSRandall Stewart */ 7166830d754dSRandall Stewart /* 7167830d754dSRandall Stewart * sctp_free_a_chunk( 7168830d754dSRandall Stewart * stcb, tp1); 7169830d754dSRandall Stewart */ 7170830d754dSRandall Stewart wake_him++; 7171830d754dSRandall Stewart } 7172830d754dSRandall Stewart break; 7173830d754dSRandall Stewart } /* if (tp1->TSN_seq == j) */ 7174830d754dSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, j, 7175830d754dSRandall Stewart MAX_TSN)) 7176830d754dSRandall Stewart break; 7177830d754dSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 7178830d754dSRandall Stewart } /* end while (tp1) */ 7179830d754dSRandall Stewart 7180830d754dSRandall Stewart } /* end for (j = nrFragStart */ 7181830d754dSRandall Stewart 7182830d754dSRandall Stewart nr_frag = (struct sctp_nr_gap_ack_block *)sctp_m_getptr(m, *offset, 7183830d754dSRandall Stewart sizeof(struct sctp_nr_gap_ack_block), (uint8_t *) & nr_block); 7184830d754dSRandall Stewart *offset += sizeof(nr_block); 7185830d754dSRandall Stewart if (nr_frag == NULL) { 7186830d754dSRandall Stewart break; 7187830d754dSRandall Stewart } 7188830d754dSRandall Stewart } /* end of if(!all_bit) */ 7189830d754dSRandall Stewart } 7190830d754dSRandall Stewart /* 7191830d754dSRandall Stewart * EY- wake up the socket if things have been removed from the sent 7192830d754dSRandall Stewart * queue 7193830d754dSRandall Stewart */ 7194830d754dSRandall Stewart if ((wake_him) && (stcb->sctp_socket)) { 7195830d754dSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 7196830d754dSRandall Stewart struct socket *so; 7197830d754dSRandall Stewart 7198830d754dSRandall Stewart #endif 7199830d754dSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 7200830d754dSRandall Stewart /* 7201830d754dSRandall Stewart * if (SCTP_BASE_SYSCTL(sctp_logging_level) & 7202830d754dSRandall Stewart * SCTP_WAKE_LOGGING_ENABLE) { sctp_wakeup_log(stcb, 7203830d754dSRandall Stewart * cum_ack, wake_him, SCTP_WAKESND_FROM_SACK);} 7204830d754dSRandall Stewart */ 7205830d754dSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 7206830d754dSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 7207830d754dSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 7208830d754dSRandall Stewart SCTP_TCB_UNLOCK(stcb); 7209830d754dSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 7210830d754dSRandall Stewart SCTP_TCB_LOCK(stcb); 7211830d754dSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 7212830d754dSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 7213830d754dSRandall Stewart /* assoc was freed while we were unlocked */ 7214830d754dSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 7215830d754dSRandall Stewart return; 7216830d754dSRandall Stewart } 7217830d754dSRandall Stewart #endif 7218830d754dSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 7219830d754dSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 7220830d754dSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 7221830d754dSRandall Stewart #endif 7222830d754dSRandall Stewart } /* else { if 7223830d754dSRandall Stewart * (SCTP_BASE_SYSCTL(sctp_logging_level) & 7224830d754dSRandall Stewart * SCTP_WAKE_LOGGING_ENABLE) { 7225830d754dSRandall Stewart * sctp_wakeup_log(stcb, cum_ack, wake_him, 7226830d754dSRandall Stewart * SCTP_NOWAKE_FROM_SACK); } } */ 7227830d754dSRandall Stewart } 7228830d754dSRandall Stewart 7229830d754dSRandall Stewart /* EY- nr_sack */ 7230830d754dSRandall Stewart /* Identifies the non-renegable tsns that are revoked*/ 7231830d754dSRandall Stewart static void 7232830d754dSRandall Stewart sctp_check_for_nr_revoked(struct sctp_tcb *stcb, 7233830d754dSRandall Stewart struct sctp_association *asoc, uint32_t cumack, 7234830d754dSRandall Stewart u_long biggest_tsn_acked) 7235830d754dSRandall Stewart { 7236830d754dSRandall Stewart struct sctp_tmit_chunk *tp1; 7237830d754dSRandall Stewart 7238830d754dSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 7239830d754dSRandall Stewart while (tp1) { 7240830d754dSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, cumack, 7241830d754dSRandall Stewart MAX_TSN)) { 7242830d754dSRandall Stewart /* 7243830d754dSRandall Stewart * ok this guy is either ACK or MARKED. If it is 7244830d754dSRandall Stewart * ACKED it has been previously acked but not this 7245830d754dSRandall Stewart * time i.e. revoked. If it is MARKED it was ACK'ed 7246830d754dSRandall Stewart * again. 7247830d754dSRandall Stewart */ 7248830d754dSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked, 7249830d754dSRandall Stewart MAX_TSN)) 7250830d754dSRandall Stewart break; 7251830d754dSRandall Stewart 7252830d754dSRandall Stewart 7253830d754dSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_NR_ACKED) { 7254830d754dSRandall Stewart /* 7255830d754dSRandall Stewart * EY! a non-renegable TSN is revoked, need 7256830d754dSRandall Stewart * to abort the association 7257830d754dSRandall Stewart */ 7258830d754dSRandall Stewart /* 7259830d754dSRandall Stewart * EY TODO: put in the code to abort the 7260830d754dSRandall Stewart * assoc. 7261830d754dSRandall Stewart */ 7262830d754dSRandall Stewart return; 7263830d754dSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_NR_MARKED) { 7264830d754dSRandall Stewart /* it has been re-acked in this SACK */ 7265830d754dSRandall Stewart tp1->sent = SCTP_DATAGRAM_NR_ACKED; 7266830d754dSRandall Stewart } 7267830d754dSRandall Stewart } 7268830d754dSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) 7269830d754dSRandall Stewart break; 7270830d754dSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 7271830d754dSRandall Stewart } 7272830d754dSRandall Stewart } 7273830d754dSRandall Stewart 7274830d754dSRandall Stewart /* EY! nr_sack version of sctp_handle_sack, nr_gap_ack processing should be added to this method*/ 7275830d754dSRandall Stewart void 7276830d754dSRandall Stewart sctp_handle_nr_sack(struct mbuf *m, int offset, 7277830d754dSRandall Stewart struct sctp_nr_sack_chunk *ch, struct sctp_tcb *stcb, 7278830d754dSRandall Stewart struct sctp_nets *net_from, int *abort_now, int nr_sack_len, uint32_t rwnd) 7279830d754dSRandall Stewart { 7280830d754dSRandall Stewart struct sctp_association *asoc; 7281830d754dSRandall Stewart 7282830d754dSRandall Stewart /* EY sack */ 7283830d754dSRandall Stewart struct sctp_nr_sack *nr_sack; 7284830d754dSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 7285830d754dSRandall Stewart uint32_t cum_ack, last_tsn, biggest_tsn_acked, biggest_tsn_newly_acked, 7286830d754dSRandall Stewart this_sack_lowest_newack; 7287830d754dSRandall Stewart uint32_t sav_cum_ack; 7288830d754dSRandall Stewart 7289830d754dSRandall Stewart /* EY num_seg */ 7290830d754dSRandall Stewart uint16_t num_seg, num_nr_seg, num_dup; 7291830d754dSRandall Stewart uint16_t wake_him = 0; 7292830d754dSRandall Stewart unsigned int nr_sack_length; 7293830d754dSRandall Stewart uint32_t send_s = 0; 7294830d754dSRandall Stewart long j; 7295830d754dSRandall Stewart int accum_moved = 0; 7296830d754dSRandall Stewart int will_exit_fast_recovery = 0; 7297830d754dSRandall Stewart uint32_t a_rwnd, old_rwnd; 7298830d754dSRandall Stewart int win_probe_recovery = 0; 7299830d754dSRandall Stewart int win_probe_recovered = 0; 7300830d754dSRandall Stewart struct sctp_nets *net = NULL; 7301830d754dSRandall Stewart int nonce_sum_flag, ecn_seg_sums = 0, all_bit; 7302830d754dSRandall Stewart int done_once; 7303830d754dSRandall Stewart uint8_t reneged_all = 0; 7304830d754dSRandall Stewart uint8_t cmt_dac_flag; 7305830d754dSRandall Stewart 7306830d754dSRandall Stewart /* 7307830d754dSRandall Stewart * we take any chance we can to service our queues since we cannot 7308830d754dSRandall Stewart * get awoken when the socket is read from :< 7309830d754dSRandall Stewart */ 7310830d754dSRandall Stewart /* 7311830d754dSRandall Stewart * Now perform the actual SACK handling: 1) Verify that it is not an 7312830d754dSRandall Stewart * old sack, if so discard. 2) If there is nothing left in the send 7313830d754dSRandall Stewart * queue (cum-ack is equal to last acked) then you have a duplicate 7314830d754dSRandall Stewart * too, update any rwnd change and verify no timers are running. 7315830d754dSRandall Stewart * then return. 3) Process any new consequtive data i.e. cum-ack 7316830d754dSRandall Stewart * moved process these first and note that it moved. 4) Process any 7317830d754dSRandall Stewart * sack blocks. 5) Drop any acked from the queue. 6) Check for any 7318830d754dSRandall Stewart * revoked blocks and mark. 7) Update the cwnd. 8) Nothing left, 7319830d754dSRandall Stewart * sync up flightsizes and things, stop all timers and also check 7320830d754dSRandall Stewart * for shutdown_pending state. If so then go ahead and send off the 7321830d754dSRandall Stewart * shutdown. If in shutdown recv, send off the shutdown-ack and 7322830d754dSRandall Stewart * start that timer, Ret. 9) Strike any non-acked things and do FR 7323830d754dSRandall Stewart * procedure if needed being sure to set the FR flag. 10) Do pr-sctp 7324830d754dSRandall Stewart * procedures. 11) Apply any FR penalties. 12) Assure we will SACK 7325830d754dSRandall Stewart * if in shutdown_recv state. 7326830d754dSRandall Stewart */ 7327830d754dSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 7328830d754dSRandall Stewart nr_sack = &ch->nr_sack; 7329830d754dSRandall Stewart /* CMT DAC algo */ 7330830d754dSRandall Stewart this_sack_lowest_newack = 0; 7331830d754dSRandall Stewart j = 0; 7332830d754dSRandall Stewart nr_sack_length = (unsigned int)nr_sack_len; 7333830d754dSRandall Stewart /* ECN Nonce */ 7334830d754dSRandall Stewart SCTP_STAT_INCR(sctps_slowpath_sack); 7335830d754dSRandall Stewart nonce_sum_flag = ch->ch.chunk_flags & SCTP_SACK_NONCE_SUM; 7336830d754dSRandall Stewart cum_ack = last_tsn = ntohl(nr_sack->cum_tsn_ack); 7337830d754dSRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 7338830d754dSRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cum_ack; 7339830d754dSRandall Stewart stcb->asoc.cumack_log_at++; 7340830d754dSRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 7341830d754dSRandall Stewart stcb->asoc.cumack_log_at = 0; 7342830d754dSRandall Stewart } 7343830d754dSRandall Stewart #endif 7344830d754dSRandall Stewart all_bit = ch->ch.chunk_flags & SCTP_NR_SACK_ALL_BIT; 7345830d754dSRandall Stewart num_seg = ntohs(nr_sack->num_gap_ack_blks); 7346830d754dSRandall Stewart num_nr_seg = ntohs(nr_sack->num_nr_gap_ack_blks); 7347830d754dSRandall Stewart if (all_bit) 7348830d754dSRandall Stewart num_seg = num_nr_seg; 7349830d754dSRandall Stewart a_rwnd = rwnd; 7350830d754dSRandall Stewart 7351830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 7352830d754dSRandall Stewart sctp_misc_ints(SCTP_SACK_LOG_NORMAL, cum_ack, 7353830d754dSRandall Stewart rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 7354830d754dSRandall Stewart } 7355830d754dSRandall Stewart /* CMT DAC algo */ 7356830d754dSRandall Stewart cmt_dac_flag = ch->ch.chunk_flags & SCTP_SACK_CMT_DAC; 7357830d754dSRandall Stewart num_dup = ntohs(nr_sack->num_dup_tsns); 7358830d754dSRandall Stewart 7359830d754dSRandall Stewart old_rwnd = stcb->asoc.peers_rwnd; 7360830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 7361830d754dSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 7362830d754dSRandall Stewart stcb->asoc.overall_error_count, 7363830d754dSRandall Stewart 0, 7364830d754dSRandall Stewart SCTP_FROM_SCTP_INDATA, 7365830d754dSRandall Stewart __LINE__); 7366830d754dSRandall Stewart } 7367830d754dSRandall Stewart stcb->asoc.overall_error_count = 0; 7368830d754dSRandall Stewart asoc = &stcb->asoc; 7369830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 7370830d754dSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 7371830d754dSRandall Stewart cum_ack, 7372830d754dSRandall Stewart 0, 7373830d754dSRandall Stewart num_seg, 7374830d754dSRandall Stewart num_dup, 7375830d754dSRandall Stewart SCTP_LOG_NEW_SACK); 7376830d754dSRandall Stewart } 7377830d754dSRandall Stewart if ((num_dup) && (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_FR_LOGGING_ENABLE | SCTP_EARLYFR_LOGGING_ENABLE))) { 7378830d754dSRandall Stewart int off_to_dup, iii; 7379830d754dSRandall Stewart uint32_t *dupdata, dblock; 7380830d754dSRandall Stewart 7381830d754dSRandall Stewart /* EY! gotta be careful here */ 7382830d754dSRandall Stewart if (all_bit) { 7383830d754dSRandall Stewart off_to_dup = (num_nr_seg * sizeof(struct sctp_nr_gap_ack_block)) + 7384830d754dSRandall Stewart sizeof(struct sctp_nr_sack_chunk); 7385830d754dSRandall Stewart } else { 7386830d754dSRandall Stewart off_to_dup = (num_seg * sizeof(struct sctp_gap_ack_block)) + 7387830d754dSRandall Stewart (num_nr_seg * sizeof(struct sctp_nr_gap_ack_block)) + sizeof(struct sctp_nr_sack_chunk); 7388830d754dSRandall Stewart } 7389830d754dSRandall Stewart if ((off_to_dup + (num_dup * sizeof(uint32_t))) <= nr_sack_length) { 7390830d754dSRandall Stewart dupdata = (uint32_t *) sctp_m_getptr(m, off_to_dup, 7391830d754dSRandall Stewart sizeof(uint32_t), (uint8_t *) & dblock); 7392830d754dSRandall Stewart off_to_dup += sizeof(uint32_t); 7393830d754dSRandall Stewart if (dupdata) { 7394830d754dSRandall Stewart for (iii = 0; iii < num_dup; iii++) { 7395830d754dSRandall Stewart sctp_log_fr(*dupdata, 0, 0, SCTP_FR_DUPED); 7396830d754dSRandall Stewart dupdata = (uint32_t *) sctp_m_getptr(m, off_to_dup, 7397830d754dSRandall Stewart sizeof(uint32_t), (uint8_t *) & dblock); 7398830d754dSRandall Stewart if (dupdata == NULL) 7399830d754dSRandall Stewart break; 7400830d754dSRandall Stewart off_to_dup += sizeof(uint32_t); 7401830d754dSRandall Stewart } 7402830d754dSRandall Stewart } 7403830d754dSRandall Stewart } else { 7404830d754dSRandall Stewart SCTP_PRINTF("Size invalid offset to dups:%d number dups:%d nr_sack_len:%d num gaps:%d num nr_gaps:%d\n", 7405830d754dSRandall Stewart off_to_dup, num_dup, nr_sack_length, num_seg, num_nr_seg); 7406830d754dSRandall Stewart } 7407830d754dSRandall Stewart } 7408830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 7409830d754dSRandall Stewart /* reality check */ 7410830d754dSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 7411830d754dSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 7412830d754dSRandall Stewart sctpchunk_listhead); 7413830d754dSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 7414830d754dSRandall Stewart } else { 7415830d754dSRandall Stewart send_s = asoc->sending_seq; 7416830d754dSRandall Stewart } 7417830d754dSRandall Stewart if (cum_ack == send_s || 7418830d754dSRandall Stewart compare_with_wrap(cum_ack, send_s, MAX_TSN)) { 7419830d754dSRandall Stewart #ifndef INVARIANTS 7420830d754dSRandall Stewart struct mbuf *oper; 7421830d754dSRandall Stewart 7422830d754dSRandall Stewart #endif 7423830d754dSRandall Stewart #ifdef INVARIANTS 7424830d754dSRandall Stewart hopeless_peer: 7425830d754dSRandall Stewart panic("Impossible sack 1"); 7426830d754dSRandall Stewart #else 7427830d754dSRandall Stewart 7428830d754dSRandall Stewart 7429830d754dSRandall Stewart /* 7430830d754dSRandall Stewart * no way, we have not even sent this TSN out yet. 7431830d754dSRandall Stewart * Peer is hopelessly messed up with us. 7432830d754dSRandall Stewart */ 7433830d754dSRandall Stewart hopeless_peer: 7434830d754dSRandall Stewart *abort_now = 1; 7435830d754dSRandall Stewart /* XXX */ 7436830d754dSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 7437830d754dSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 7438830d754dSRandall Stewart if (oper) { 7439830d754dSRandall Stewart struct sctp_paramhdr *ph; 7440830d754dSRandall Stewart uint32_t *ippp; 7441830d754dSRandall Stewart 7442830d754dSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 7443830d754dSRandall Stewart sizeof(uint32_t); 7444830d754dSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 7445830d754dSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 7446830d754dSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 7447830d754dSRandall Stewart ippp = (uint32_t *) (ph + 1); 7448830d754dSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 7449830d754dSRandall Stewart } 7450830d754dSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 7451830d754dSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 7452830d754dSRandall Stewart return; 7453830d754dSRandall Stewart #endif 7454830d754dSRandall Stewart } 7455830d754dSRandall Stewart } 7456830d754dSRandall Stewart /**********************/ 7457830d754dSRandall Stewart /* 1) check the range */ 7458830d754dSRandall Stewart /**********************/ 7459830d754dSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, last_tsn, MAX_TSN)) { 7460830d754dSRandall Stewart /* acking something behind */ 7461830d754dSRandall Stewart return; 7462830d754dSRandall Stewart } 7463830d754dSRandall Stewart sav_cum_ack = asoc->last_acked_seq; 7464830d754dSRandall Stewart 7465830d754dSRandall Stewart /* update the Rwnd of the peer */ 7466830d754dSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue) && 7467830d754dSRandall Stewart TAILQ_EMPTY(&asoc->send_queue) && 7468830d754dSRandall Stewart (asoc->stream_queue_cnt == 0) 7469830d754dSRandall Stewart ) { 7470830d754dSRandall Stewart /* nothing left on send/sent and strmq */ 7471830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 7472830d754dSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 7473830d754dSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 7474830d754dSRandall Stewart } 7475830d754dSRandall Stewart asoc->peers_rwnd = a_rwnd; 7476830d754dSRandall Stewart if (asoc->sent_queue_retran_cnt) { 7477830d754dSRandall Stewart asoc->sent_queue_retran_cnt = 0; 7478830d754dSRandall Stewart } 7479830d754dSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 7480830d754dSRandall Stewart /* SWS sender side engages */ 7481830d754dSRandall Stewart asoc->peers_rwnd = 0; 7482830d754dSRandall Stewart } 7483830d754dSRandall Stewart /* stop any timers */ 7484830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 7485830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 7486830d754dSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 7487830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 7488830d754dSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 7489830d754dSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck1); 7490830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 7491830d754dSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 7492830d754dSRandall Stewart } 7493830d754dSRandall Stewart } 7494830d754dSRandall Stewart net->partial_bytes_acked = 0; 7495830d754dSRandall Stewart net->flight_size = 0; 7496830d754dSRandall Stewart } 7497830d754dSRandall Stewart asoc->total_flight = 0; 7498830d754dSRandall Stewart asoc->total_flight_count = 0; 7499830d754dSRandall Stewart return; 7500830d754dSRandall Stewart } 7501830d754dSRandall Stewart /* 7502830d754dSRandall Stewart * We init netAckSz and netAckSz2 to 0. These are used to track 2 7503830d754dSRandall Stewart * things. The total byte count acked is tracked in netAckSz AND 7504830d754dSRandall Stewart * netAck2 is used to track the total bytes acked that are un- 7505830d754dSRandall Stewart * amibguious and were never retransmitted. We track these on a per 7506830d754dSRandall Stewart * destination address basis. 7507830d754dSRandall Stewart */ 7508830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 7509830d754dSRandall Stewart net->prev_cwnd = net->cwnd; 7510830d754dSRandall Stewart net->net_ack = 0; 7511830d754dSRandall Stewart net->net_ack2 = 0; 7512830d754dSRandall Stewart 7513830d754dSRandall Stewart /* 7514830d754dSRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 7515830d754dSRandall Stewart * SACK processing 7516830d754dSRandall Stewart */ 7517830d754dSRandall Stewart net->new_pseudo_cumack = 0; 7518830d754dSRandall Stewart net->will_exit_fast_recovery = 0; 7519830d754dSRandall Stewart } 7520830d754dSRandall Stewart /* process the new consecutive TSN first */ 7521830d754dSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 7522830d754dSRandall Stewart while (tp1) { 7523830d754dSRandall Stewart if (compare_with_wrap(last_tsn, tp1->rec.data.TSN_seq, 7524830d754dSRandall Stewart MAX_TSN) || 7525830d754dSRandall Stewart last_tsn == tp1->rec.data.TSN_seq) { 7526830d754dSRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 7527830d754dSRandall Stewart /* 7528830d754dSRandall Stewart * ECN Nonce: Add the nonce to the sender's 7529830d754dSRandall Stewart * nonce sum 7530830d754dSRandall Stewart */ 7531830d754dSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 7532830d754dSRandall Stewart accum_moved = 1; 7533830d754dSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 7534830d754dSRandall Stewart /* 7535830d754dSRandall Stewart * If it is less than ACKED, it is 7536830d754dSRandall Stewart * now no-longer in flight. Higher 7537830d754dSRandall Stewart * values may occur during marking 7538830d754dSRandall Stewart */ 7539830d754dSRandall Stewart if ((tp1->whoTo->dest_state & 7540830d754dSRandall Stewart SCTP_ADDR_UNCONFIRMED) && 7541830d754dSRandall Stewart (tp1->snd_count < 2)) { 7542830d754dSRandall Stewart /* 7543830d754dSRandall Stewart * If there was no retran 7544830d754dSRandall Stewart * and the address is 7545830d754dSRandall Stewart * un-confirmed and we sent 7546830d754dSRandall Stewart * there and are now 7547830d754dSRandall Stewart * sacked.. its confirmed, 7548830d754dSRandall Stewart * mark it so. 7549830d754dSRandall Stewart */ 7550830d754dSRandall Stewart tp1->whoTo->dest_state &= 7551830d754dSRandall Stewart ~SCTP_ADDR_UNCONFIRMED; 7552830d754dSRandall Stewart } 7553830d754dSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 7554830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 7555830d754dSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 7556830d754dSRandall Stewart tp1->whoTo->flight_size, 7557830d754dSRandall Stewart tp1->book_size, 7558830d754dSRandall Stewart (uintptr_t) tp1->whoTo, 7559830d754dSRandall Stewart tp1->rec.data.TSN_seq); 7560830d754dSRandall Stewart } 7561830d754dSRandall Stewart sctp_flight_size_decrease(tp1); 7562830d754dSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 7563830d754dSRandall Stewart } 7564830d754dSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 7565830d754dSRandall Stewart 7566830d754dSRandall Stewart /* CMT SFR and DAC algos */ 7567830d754dSRandall Stewart this_sack_lowest_newack = tp1->rec.data.TSN_seq; 7568830d754dSRandall Stewart tp1->whoTo->saw_newack = 1; 7569830d754dSRandall Stewart 7570830d754dSRandall Stewart if (tp1->snd_count < 2) { 7571830d754dSRandall Stewart /* 7572830d754dSRandall Stewart * True non-retransmited 7573830d754dSRandall Stewart * chunk 7574830d754dSRandall Stewart */ 7575830d754dSRandall Stewart tp1->whoTo->net_ack2 += 7576830d754dSRandall Stewart tp1->send_size; 7577830d754dSRandall Stewart 7578830d754dSRandall Stewart /* update RTO too? */ 7579830d754dSRandall Stewart if (tp1->do_rtt) { 7580830d754dSRandall Stewart tp1->whoTo->RTO = 7581830d754dSRandall Stewart sctp_calculate_rto(stcb, 7582830d754dSRandall Stewart asoc, tp1->whoTo, 7583830d754dSRandall Stewart &tp1->sent_rcv_time, 7584830d754dSRandall Stewart sctp_align_safe_nocopy); 7585830d754dSRandall Stewart tp1->do_rtt = 0; 7586830d754dSRandall Stewart } 7587830d754dSRandall Stewart } 7588830d754dSRandall Stewart /* 7589830d754dSRandall Stewart * CMT: CUCv2 algorithm. From the 7590830d754dSRandall Stewart * cumack'd TSNs, for each TSN being 7591830d754dSRandall Stewart * acked for the first time, set the 7592830d754dSRandall Stewart * following variables for the 7593830d754dSRandall Stewart * corresp destination. 7594830d754dSRandall Stewart * new_pseudo_cumack will trigger a 7595830d754dSRandall Stewart * cwnd update. 7596830d754dSRandall Stewart * find_(rtx_)pseudo_cumack will 7597830d754dSRandall Stewart * trigger search for the next 7598830d754dSRandall Stewart * expected (rtx-)pseudo-cumack. 7599830d754dSRandall Stewart */ 7600830d754dSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 7601830d754dSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 7602830d754dSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 7603830d754dSRandall Stewart 7604830d754dSRandall Stewart 7605830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 7606830d754dSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 7607830d754dSRandall Stewart cum_ack, 7608830d754dSRandall Stewart tp1->rec.data.TSN_seq, 7609830d754dSRandall Stewart 0, 7610830d754dSRandall Stewart 0, 7611830d754dSRandall Stewart SCTP_LOG_TSN_ACKED); 7612830d754dSRandall Stewart } 7613830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 7614830d754dSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 7615830d754dSRandall Stewart } 7616830d754dSRandall Stewart } 7617830d754dSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 7618830d754dSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 7619830d754dSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 7620830d754dSRandall Stewart sctp_audit_log(0xB3, 7621830d754dSRandall Stewart (asoc->sent_queue_retran_cnt & 0x000000ff)); 7622830d754dSRandall Stewart #endif 7623830d754dSRandall Stewart } 7624830d754dSRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 7625830d754dSRandall Stewart /* deflate the cwnd */ 7626830d754dSRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 7627830d754dSRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 7628830d754dSRandall Stewart } 7629830d754dSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 7630830d754dSRandall Stewart } 7631830d754dSRandall Stewart } else { 7632830d754dSRandall Stewart break; 7633830d754dSRandall Stewart } 7634830d754dSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 7635830d754dSRandall Stewart } 7636830d754dSRandall Stewart biggest_tsn_newly_acked = biggest_tsn_acked = last_tsn; 7637830d754dSRandall Stewart /* always set this up to cum-ack */ 7638830d754dSRandall Stewart asoc->this_sack_highest_gap = last_tsn; 7639830d754dSRandall Stewart 7640830d754dSRandall Stewart /* Move offset up to point to gaps/dups */ 7641830d754dSRandall Stewart offset += sizeof(struct sctp_nr_sack_chunk); 7642830d754dSRandall Stewart if (((num_seg * (sizeof(struct sctp_gap_ack_block))) + sizeof(struct sctp_nr_sack_chunk)) > nr_sack_length) { 7643830d754dSRandall Stewart 7644830d754dSRandall Stewart /* skip corrupt segments */ 7645830d754dSRandall Stewart goto skip_segments; 7646830d754dSRandall Stewart } 7647830d754dSRandall Stewart if (num_seg > 0) { 7648830d754dSRandall Stewart 7649830d754dSRandall Stewart /* 7650830d754dSRandall Stewart * CMT: SFR algo (and HTNA) - this_sack_highest_newack has 7651830d754dSRandall Stewart * to be greater than the cumack. Also reset saw_newack to 0 7652830d754dSRandall Stewart * for all dests. 7653830d754dSRandall Stewart */ 7654830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 7655830d754dSRandall Stewart net->saw_newack = 0; 7656830d754dSRandall Stewart net->this_sack_highest_newack = last_tsn; 7657830d754dSRandall Stewart } 7658830d754dSRandall Stewart 7659830d754dSRandall Stewart /* 7660830d754dSRandall Stewart * thisSackHighestGap will increase while handling NEW 7661830d754dSRandall Stewart * segments this_sack_highest_newack will increase while 7662830d754dSRandall Stewart * handling NEWLY ACKED chunks. this_sack_lowest_newack is 7663830d754dSRandall Stewart * used for CMT DAC algo. saw_newack will also change. 7664830d754dSRandall Stewart */ 7665830d754dSRandall Stewart 7666830d754dSRandall Stewart sctp_handle_nr_sack_segments(m, &offset, stcb, asoc, ch, last_tsn, 7667830d754dSRandall Stewart &biggest_tsn_acked, &biggest_tsn_newly_acked, &this_sack_lowest_newack, 7668830d754dSRandall Stewart num_seg, num_nr_seg, &ecn_seg_sums); 7669830d754dSRandall Stewart 7670830d754dSRandall Stewart 7671830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 7672830d754dSRandall Stewart /* 7673830d754dSRandall Stewart * validate the biggest_tsn_acked in the gap acks if 7674830d754dSRandall Stewart * strict adherence is wanted. 7675830d754dSRandall Stewart */ 7676830d754dSRandall Stewart if ((biggest_tsn_acked == send_s) || 7677830d754dSRandall Stewart (compare_with_wrap(biggest_tsn_acked, send_s, MAX_TSN))) { 7678830d754dSRandall Stewart /* 7679830d754dSRandall Stewart * peer is either confused or we are under 7680830d754dSRandall Stewart * attack. We must abort. 7681830d754dSRandall Stewart */ 7682830d754dSRandall Stewart goto hopeless_peer; 7683830d754dSRandall Stewart } 7684830d754dSRandall Stewart } 7685830d754dSRandall Stewart } 7686830d754dSRandall Stewart skip_segments: 7687830d754dSRandall Stewart /*******************************************/ 7688830d754dSRandall Stewart /* cancel ALL T3-send timer if accum moved */ 7689830d754dSRandall Stewart /*******************************************/ 7690830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) { 7691830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 7692830d754dSRandall Stewart if (net->new_pseudo_cumack) 7693830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 7694830d754dSRandall Stewart stcb, net, 7695830d754dSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_27); 7696830d754dSRandall Stewart 7697830d754dSRandall Stewart } 7698830d754dSRandall Stewart } else { 7699830d754dSRandall Stewart if (accum_moved) { 7700830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 7701830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 7702830d754dSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_28); 7703830d754dSRandall Stewart } 7704830d754dSRandall Stewart } 7705830d754dSRandall Stewart } 7706830d754dSRandall Stewart /********************************************/ 7707830d754dSRandall Stewart /* drop the acked chunks from the sendqueue */ 7708830d754dSRandall Stewart /********************************************/ 7709830d754dSRandall Stewart asoc->last_acked_seq = cum_ack; 7710830d754dSRandall Stewart 7711830d754dSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 7712830d754dSRandall Stewart if (tp1 == NULL) 7713830d754dSRandall Stewart goto done_with_it; 7714830d754dSRandall Stewart do { 7715830d754dSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, cum_ack, 7716830d754dSRandall Stewart MAX_TSN)) { 7717830d754dSRandall Stewart break; 7718830d754dSRandall Stewart } 7719830d754dSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 7720830d754dSRandall Stewart /* no more sent on list */ 7721830d754dSRandall Stewart printf("Warning, tp1->sent == %d and its now acked?\n", 7722830d754dSRandall Stewart tp1->sent); 7723830d754dSRandall Stewart } 7724830d754dSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 7725830d754dSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 7726830d754dSRandall Stewart if (tp1->pr_sctp_on) { 7727830d754dSRandall Stewart if (asoc->pr_sctp_cnt != 0) 7728830d754dSRandall Stewart asoc->pr_sctp_cnt--; 7729830d754dSRandall Stewart } 7730830d754dSRandall Stewart if ((TAILQ_FIRST(&asoc->sent_queue) == NULL) && 7731830d754dSRandall Stewart (asoc->total_flight > 0)) { 7732830d754dSRandall Stewart #ifdef INVARIANTS 7733830d754dSRandall Stewart panic("Warning flight size is postive and should be 0"); 7734830d754dSRandall Stewart #else 7735830d754dSRandall Stewart SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n", 7736830d754dSRandall Stewart asoc->total_flight); 7737830d754dSRandall Stewart #endif 7738830d754dSRandall Stewart asoc->total_flight = 0; 7739830d754dSRandall Stewart } 7740830d754dSRandall Stewart if (tp1->data) { 7741830d754dSRandall Stewart /* sa_ignore NO_NULL_CHK */ 7742830d754dSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 7743830d754dSRandall Stewart sctp_m_freem(tp1->data); 7744830d754dSRandall Stewart if (PR_SCTP_BUF_ENABLED(tp1->flags)) { 7745830d754dSRandall Stewart asoc->sent_queue_cnt_removeable--; 7746830d754dSRandall Stewart } 7747830d754dSRandall Stewart } 7748830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 7749830d754dSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 7750830d754dSRandall Stewart cum_ack, 7751830d754dSRandall Stewart tp1->rec.data.TSN_seq, 7752830d754dSRandall Stewart 0, 7753830d754dSRandall Stewart 0, 7754830d754dSRandall Stewart SCTP_LOG_FREE_SENT); 7755830d754dSRandall Stewart } 7756830d754dSRandall Stewart tp1->data = NULL; 7757830d754dSRandall Stewart asoc->sent_queue_cnt--; 7758830d754dSRandall Stewart sctp_free_a_chunk(stcb, tp1); 7759830d754dSRandall Stewart wake_him++; 7760830d754dSRandall Stewart tp1 = tp2; 7761830d754dSRandall Stewart } while (tp1 != NULL); 7762830d754dSRandall Stewart 7763830d754dSRandall Stewart done_with_it: 7764830d754dSRandall Stewart /* sa_ignore NO_NULL_CHK */ 7765830d754dSRandall Stewart if ((wake_him) && (stcb->sctp_socket)) { 7766830d754dSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 7767830d754dSRandall Stewart struct socket *so; 7768830d754dSRandall Stewart 7769830d754dSRandall Stewart #endif 7770830d754dSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 7771830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 7772830d754dSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_WAKESND_FROM_SACK); 7773830d754dSRandall Stewart } 7774830d754dSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 7775830d754dSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 7776830d754dSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 7777830d754dSRandall Stewart SCTP_TCB_UNLOCK(stcb); 7778830d754dSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 7779830d754dSRandall Stewart SCTP_TCB_LOCK(stcb); 7780830d754dSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 7781830d754dSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 7782830d754dSRandall Stewart /* assoc was freed while we were unlocked */ 7783830d754dSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 7784830d754dSRandall Stewart return; 7785830d754dSRandall Stewart } 7786830d754dSRandall Stewart #endif 7787830d754dSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 7788830d754dSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 7789830d754dSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 7790830d754dSRandall Stewart #endif 7791830d754dSRandall Stewart } else { 7792830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 7793830d754dSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_NOWAKE_FROM_SACK); 7794830d754dSRandall Stewart } 7795830d754dSRandall Stewart } 7796830d754dSRandall Stewart 7797830d754dSRandall Stewart if (asoc->fast_retran_loss_recovery && accum_moved) { 7798830d754dSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, 7799830d754dSRandall Stewart asoc->fast_recovery_tsn, MAX_TSN) || 7800830d754dSRandall Stewart asoc->last_acked_seq == asoc->fast_recovery_tsn) { 7801830d754dSRandall Stewart /* Setup so we will exit RFC2582 fast recovery */ 7802830d754dSRandall Stewart will_exit_fast_recovery = 1; 7803830d754dSRandall Stewart } 7804830d754dSRandall Stewart } 7805830d754dSRandall Stewart /* 7806830d754dSRandall Stewart * Check for revoked fragments: 7807830d754dSRandall Stewart * 7808830d754dSRandall Stewart * if Previous sack - Had no frags then we can't have any revoked if 7809830d754dSRandall Stewart * Previous sack - Had frag's then - If we now have frags aka 7810830d754dSRandall Stewart * num_seg > 0 call sctp_check_for_revoked() to tell if peer revoked 7811830d754dSRandall Stewart * some of them. else - The peer revoked all ACKED fragments, since 7812830d754dSRandall Stewart * we had some before and now we have NONE. 7813830d754dSRandall Stewart */ 7814830d754dSRandall Stewart 7815830d754dSRandall Stewart if (num_seg) 7816830d754dSRandall Stewart sctp_check_for_revoked(stcb, asoc, cum_ack, biggest_tsn_acked); 7817830d754dSRandall Stewart 7818830d754dSRandall Stewart else if (asoc->saw_sack_with_frags) { 7819830d754dSRandall Stewart int cnt_revoked = 0; 7820830d754dSRandall Stewart 7821830d754dSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 7822830d754dSRandall Stewart if (tp1 != NULL) { 7823830d754dSRandall Stewart /* Peer revoked all dg's marked or acked */ 7824830d754dSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 7825830d754dSRandall Stewart /* 7826830d754dSRandall Stewart * EY- maybe check only if it is nr_acked 7827830d754dSRandall Stewart * nr_marked may not be possible 7828830d754dSRandall Stewart */ 7829830d754dSRandall Stewart if ((tp1->sent == SCTP_DATAGRAM_NR_ACKED) || 7830830d754dSRandall Stewart (tp1->sent == SCTP_DATAGRAM_NR_MARKED)) { 7831830d754dSRandall Stewart /* 7832830d754dSRandall Stewart * EY! - TODO: Something previously 7833830d754dSRandall Stewart * nr_gapped is reneged, abort the 7834830d754dSRandall Stewart * association 7835830d754dSRandall Stewart */ 7836830d754dSRandall Stewart return; 7837830d754dSRandall Stewart } 7838830d754dSRandall Stewart if ((tp1->sent > SCTP_DATAGRAM_RESEND) && 7839830d754dSRandall Stewart (tp1->sent < SCTP_FORWARD_TSN_SKIP)) { 7840830d754dSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 7841830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 7842830d754dSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 7843830d754dSRandall Stewart tp1->whoTo->flight_size, 7844830d754dSRandall Stewart tp1->book_size, 7845830d754dSRandall Stewart (uintptr_t) tp1->whoTo, 7846830d754dSRandall Stewart tp1->rec.data.TSN_seq); 7847830d754dSRandall Stewart } 7848830d754dSRandall Stewart sctp_flight_size_increase(tp1); 7849830d754dSRandall Stewart sctp_total_flight_increase(stcb, tp1); 7850830d754dSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 7851830d754dSRandall Stewart /* 7852830d754dSRandall Stewart * To ensure that this increase in 7853830d754dSRandall Stewart * flightsize, which is artificial, 7854830d754dSRandall Stewart * does not throttle the sender, we 7855830d754dSRandall Stewart * also increase the cwnd 7856830d754dSRandall Stewart * artificially. 7857830d754dSRandall Stewart */ 7858830d754dSRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 7859830d754dSRandall Stewart cnt_revoked++; 7860830d754dSRandall Stewart } 7861830d754dSRandall Stewart } 7862830d754dSRandall Stewart if (cnt_revoked) { 7863830d754dSRandall Stewart reneged_all = 1; 7864830d754dSRandall Stewart } 7865830d754dSRandall Stewart } 7866830d754dSRandall Stewart asoc->saw_sack_with_frags = 0; 7867830d754dSRandall Stewart } 7868830d754dSRandall Stewart if (num_seg) 7869830d754dSRandall Stewart asoc->saw_sack_with_frags = 1; 7870830d754dSRandall Stewart else 7871830d754dSRandall Stewart asoc->saw_sack_with_frags = 0; 7872830d754dSRandall Stewart 7873830d754dSRandall Stewart /* EY! - not sure about if there should be an IF */ 7874830d754dSRandall Stewart if (num_nr_seg) 7875830d754dSRandall Stewart sctp_check_for_nr_revoked(stcb, asoc, cum_ack, biggest_tsn_acked); 7876830d754dSRandall Stewart else if (asoc->saw_sack_with_nr_frags) { 7877830d754dSRandall Stewart /* 7878830d754dSRandall Stewart * EY!- TODO: all previously nr_gapped chunks have been 7879830d754dSRandall Stewart * reneged abort the association 7880830d754dSRandall Stewart */ 7881830d754dSRandall Stewart asoc->saw_sack_with_nr_frags = 0; 7882830d754dSRandall Stewart } 7883830d754dSRandall Stewart if (num_nr_seg) 7884830d754dSRandall Stewart asoc->saw_sack_with_nr_frags = 1; 7885830d754dSRandall Stewart else 7886830d754dSRandall Stewart asoc->saw_sack_with_nr_frags = 0; 7887830d754dSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 7888830d754dSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, accum_moved, reneged_all, will_exit_fast_recovery); 7889830d754dSRandall Stewart 7890830d754dSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 7891830d754dSRandall Stewart /* nothing left in-flight */ 7892830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 7893830d754dSRandall Stewart /* stop all timers */ 7894830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 7895830d754dSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 7896830d754dSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 7897830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 7898830d754dSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_29); 7899830d754dSRandall Stewart } 7900830d754dSRandall Stewart } 7901830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 7902830d754dSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_30); 7903830d754dSRandall Stewart net->flight_size = 0; 7904830d754dSRandall Stewart net->partial_bytes_acked = 0; 7905830d754dSRandall Stewart } 7906830d754dSRandall Stewart asoc->total_flight = 0; 7907830d754dSRandall Stewart asoc->total_flight_count = 0; 7908830d754dSRandall Stewart } 7909830d754dSRandall Stewart /**********************************/ 7910830d754dSRandall Stewart /* Now what about shutdown issues */ 7911830d754dSRandall Stewart /**********************************/ 7912830d754dSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 7913830d754dSRandall Stewart /* nothing left on sendqueue.. consider done */ 7914830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 7915830d754dSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 7916830d754dSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 7917830d754dSRandall Stewart } 7918830d754dSRandall Stewart asoc->peers_rwnd = a_rwnd; 7919830d754dSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 7920830d754dSRandall Stewart /* SWS sender side engages */ 7921830d754dSRandall Stewart asoc->peers_rwnd = 0; 7922830d754dSRandall Stewart } 7923830d754dSRandall Stewart /* clean up */ 7924830d754dSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 7925830d754dSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 7926830d754dSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 7927830d754dSRandall Stewart (asoc->locked_on_sending) 7928830d754dSRandall Stewart ) { 7929830d754dSRandall Stewart struct sctp_stream_queue_pending *sp; 7930830d754dSRandall Stewart 7931830d754dSRandall Stewart /* 7932830d754dSRandall Stewart * I may be in a state where we got all across.. but 7933830d754dSRandall Stewart * cannot write more due to a shutdown... we abort 7934830d754dSRandall Stewart * since the user did not indicate EOR in this case. 7935830d754dSRandall Stewart */ 7936830d754dSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 7937830d754dSRandall Stewart sctp_streamhead); 7938830d754dSRandall Stewart if ((sp) && (sp->length == 0)) { 7939830d754dSRandall Stewart asoc->locked_on_sending = NULL; 7940830d754dSRandall Stewart if (sp->msg_is_complete) { 7941830d754dSRandall Stewart asoc->stream_queue_cnt--; 7942830d754dSRandall Stewart } else { 7943830d754dSRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 7944830d754dSRandall Stewart asoc->stream_queue_cnt--; 7945830d754dSRandall Stewart } 7946830d754dSRandall Stewart } 7947830d754dSRandall Stewart } 7948830d754dSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 7949830d754dSRandall Stewart (asoc->stream_queue_cnt == 0)) { 7950830d754dSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 7951830d754dSRandall Stewart /* Need to abort here */ 7952830d754dSRandall Stewart struct mbuf *oper; 7953830d754dSRandall Stewart 7954830d754dSRandall Stewart abort_out_now: 7955830d754dSRandall Stewart *abort_now = 1; 7956830d754dSRandall Stewart /* XXX */ 7957830d754dSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 7958830d754dSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 7959830d754dSRandall Stewart if (oper) { 7960830d754dSRandall Stewart struct sctp_paramhdr *ph; 7961830d754dSRandall Stewart uint32_t *ippp; 7962830d754dSRandall Stewart 7963830d754dSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 7964830d754dSRandall Stewart sizeof(uint32_t); 7965830d754dSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 7966830d754dSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 7967830d754dSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 7968830d754dSRandall Stewart ippp = (uint32_t *) (ph + 1); 7969830d754dSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_31); 7970830d754dSRandall Stewart } 7971830d754dSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_31; 7972830d754dSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 7973830d754dSRandall Stewart return; 7974830d754dSRandall Stewart } else { 7975830d754dSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 7976830d754dSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 7977830d754dSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 7978830d754dSRandall Stewart } 7979830d754dSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 7980830d754dSRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 7981830d754dSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 7982830d754dSRandall Stewart sctp_send_shutdown(stcb, 7983830d754dSRandall Stewart stcb->asoc.primary_destination); 7984830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 7985830d754dSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 7986830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 7987830d754dSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 7988830d754dSRandall Stewart } 7989830d754dSRandall Stewart return; 7990830d754dSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 7991830d754dSRandall Stewart (asoc->stream_queue_cnt == 0)) { 7992830d754dSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 7993830d754dSRandall Stewart goto abort_out_now; 7994830d754dSRandall Stewart } 7995830d754dSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 7996830d754dSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 7997830d754dSRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 7998830d754dSRandall Stewart sctp_send_shutdown_ack(stcb, 7999830d754dSRandall Stewart stcb->asoc.primary_destination); 8000830d754dSRandall Stewart 8001830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 8002830d754dSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 8003830d754dSRandall Stewart return; 8004830d754dSRandall Stewart } 8005830d754dSRandall Stewart } 8006830d754dSRandall Stewart /* 8007830d754dSRandall Stewart * Now here we are going to recycle net_ack for a different use... 8008830d754dSRandall Stewart * HEADS UP. 8009830d754dSRandall Stewart */ 8010830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 8011830d754dSRandall Stewart net->net_ack = 0; 8012830d754dSRandall Stewart } 8013830d754dSRandall Stewart 8014830d754dSRandall Stewart /* 8015830d754dSRandall Stewart * CMT DAC algorithm: If SACK DAC flag was 0, then no extra marking 8016830d754dSRandall Stewart * to be done. Setting this_sack_lowest_newack to the cum_ack will 8017830d754dSRandall Stewart * automatically ensure that. 8018830d754dSRandall Stewart */ 8019830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac) && (cmt_dac_flag == 0)) { 8020830d754dSRandall Stewart this_sack_lowest_newack = cum_ack; 8021830d754dSRandall Stewart } 8022830d754dSRandall Stewart if (num_seg > 0) { 8023830d754dSRandall Stewart sctp_strike_gap_ack_chunks(stcb, asoc, biggest_tsn_acked, 8024830d754dSRandall Stewart biggest_tsn_newly_acked, this_sack_lowest_newack, accum_moved); 8025830d754dSRandall Stewart } 8026830d754dSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 8027830d754dSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_fr(stcb, asoc); 8028830d754dSRandall Stewart 8029830d754dSRandall Stewart /****************************************************************** 8030830d754dSRandall Stewart * Here we do the stuff with ECN Nonce checking. 8031830d754dSRandall Stewart * We basically check to see if the nonce sum flag was incorrect 8032830d754dSRandall Stewart * or if resynchronization needs to be done. Also if we catch a 8033830d754dSRandall Stewart * misbehaving receiver we give him the kick. 8034830d754dSRandall Stewart ******************************************************************/ 8035830d754dSRandall Stewart 8036830d754dSRandall Stewart if (asoc->ecn_nonce_allowed) { 8037830d754dSRandall Stewart if (asoc->nonce_sum_check) { 8038830d754dSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base + ecn_seg_sums) & SCTP_SACK_NONCE_SUM)) { 8039830d754dSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 8040830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 8041830d754dSRandall Stewart 8042830d754dSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 8043830d754dSRandall Stewart asoc->nonce_wait_for_ecne = 1; 8044830d754dSRandall Stewart if (lchk) { 8045830d754dSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 8046830d754dSRandall Stewart } else { 8047830d754dSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 8048830d754dSRandall Stewart } 8049830d754dSRandall Stewart } else { 8050830d754dSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) || 8051830d754dSRandall Stewart (asoc->last_acked_seq == asoc->nonce_wait_tsn)) { 8052830d754dSRandall Stewart /* 8053830d754dSRandall Stewart * Misbehaving peer. We need 8054830d754dSRandall Stewart * to react to this guy 8055830d754dSRandall Stewart */ 8056830d754dSRandall Stewart asoc->ecn_allowed = 0; 8057830d754dSRandall Stewart asoc->ecn_nonce_allowed = 0; 8058830d754dSRandall Stewart } 8059830d754dSRandall Stewart } 8060830d754dSRandall Stewart } 8061830d754dSRandall Stewart } else { 8062830d754dSRandall Stewart /* See if Resynchronization Possible */ 8063830d754dSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) { 8064830d754dSRandall Stewart asoc->nonce_sum_check = 1; 8065830d754dSRandall Stewart /* 8066830d754dSRandall Stewart * now we must calculate what the base is. 8067830d754dSRandall Stewart * We do this based on two things, we know 8068830d754dSRandall Stewart * the total's for all the segments 8069830d754dSRandall Stewart * gap-acked in the SACK, its stored in 8070830d754dSRandall Stewart * ecn_seg_sums. We also know the SACK's 8071830d754dSRandall Stewart * nonce sum, its in nonce_sum_flag. So we 8072830d754dSRandall Stewart * can build a truth table to back-calculate 8073830d754dSRandall Stewart * the new value of 8074830d754dSRandall Stewart * asoc->nonce_sum_expect_base: 8075830d754dSRandall Stewart * 8076830d754dSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 8077830d754dSRandall Stewart * 1 0 1 0 1 1 1 1 0 8078830d754dSRandall Stewart */ 8079830d754dSRandall Stewart asoc->nonce_sum_expect_base = (ecn_seg_sums ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 8080830d754dSRandall Stewart } 8081830d754dSRandall Stewart } 8082830d754dSRandall Stewart } 8083830d754dSRandall Stewart /* Now are we exiting loss recovery ? */ 8084830d754dSRandall Stewart if (will_exit_fast_recovery) { 8085830d754dSRandall Stewart /* Ok, we must exit fast recovery */ 8086830d754dSRandall Stewart asoc->fast_retran_loss_recovery = 0; 8087830d754dSRandall Stewart } 8088830d754dSRandall Stewart if ((asoc->sat_t3_loss_recovery) && 8089830d754dSRandall Stewart ((compare_with_wrap(asoc->last_acked_seq, asoc->sat_t3_recovery_tsn, 8090830d754dSRandall Stewart MAX_TSN) || 8091830d754dSRandall Stewart (asoc->last_acked_seq == asoc->sat_t3_recovery_tsn)))) { 8092830d754dSRandall Stewart /* end satellite t3 loss recovery */ 8093830d754dSRandall Stewart asoc->sat_t3_loss_recovery = 0; 8094830d754dSRandall Stewart } 8095830d754dSRandall Stewart /* 8096830d754dSRandall Stewart * CMT Fast recovery 8097830d754dSRandall Stewart */ 8098830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 8099830d754dSRandall Stewart if (net->will_exit_fast_recovery) { 8100830d754dSRandall Stewart /* Ok, we must exit fast recovery */ 8101830d754dSRandall Stewart net->fast_retran_loss_recovery = 0; 8102830d754dSRandall Stewart } 8103830d754dSRandall Stewart } 8104830d754dSRandall Stewart 8105830d754dSRandall Stewart /* Adjust and set the new rwnd value */ 8106830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 8107830d754dSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 8108830d754dSRandall Stewart asoc->peers_rwnd, asoc->total_flight, (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)), a_rwnd); 8109830d754dSRandall Stewart } 8110830d754dSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd, 8111830d754dSRandall Stewart (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 8112830d754dSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 8113830d754dSRandall Stewart /* SWS sender side engages */ 8114830d754dSRandall Stewart asoc->peers_rwnd = 0; 8115830d754dSRandall Stewart } 8116830d754dSRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 8117830d754dSRandall Stewart win_probe_recovery = 1; 8118830d754dSRandall Stewart } 8119830d754dSRandall Stewart /* 8120830d754dSRandall Stewart * Now we must setup so we have a timer up for anyone with 8121830d754dSRandall Stewart * outstanding data. 8122830d754dSRandall Stewart */ 8123830d754dSRandall Stewart done_once = 0; 8124830d754dSRandall Stewart again: 8125830d754dSRandall Stewart j = 0; 8126830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 8127830d754dSRandall Stewart if (win_probe_recovery && (net->window_probe)) { 8128830d754dSRandall Stewart win_probe_recovered = 1; 8129830d754dSRandall Stewart /*- 8130830d754dSRandall Stewart * Find first chunk that was used with 8131830d754dSRandall Stewart * window probe and clear the event. Put 8132830d754dSRandall Stewart * it back into the send queue as if has 8133830d754dSRandall Stewart * not been sent. 8134830d754dSRandall Stewart */ 8135830d754dSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 8136830d754dSRandall Stewart if (tp1->window_probe) { 8137830d754dSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 8138830d754dSRandall Stewart break; 8139830d754dSRandall Stewart } 8140830d754dSRandall Stewart } 8141830d754dSRandall Stewart } 8142830d754dSRandall Stewart if (net->flight_size) { 8143830d754dSRandall Stewart j++; 8144830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 8145830d754dSRandall Stewart stcb->sctp_ep, stcb, net); 81465171328bSRandall Stewart if (net->window_probe) { 81475171328bSRandall Stewart net->window_probe = 0; 81485171328bSRandall Stewart } 8149830d754dSRandall Stewart } else { 81505171328bSRandall Stewart if (net->window_probe) { 81515171328bSRandall Stewart net->window_probe = 0; 81525171328bSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 81535171328bSRandall Stewart stcb->sctp_ep, stcb, net); 81545171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 8155830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 8156830d754dSRandall Stewart stcb, net, 8157830d754dSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 8158830d754dSRandall Stewart } 8159830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 8160830d754dSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 8161830d754dSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 8162830d754dSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 8163830d754dSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 8164830d754dSRandall Stewart } 8165830d754dSRandall Stewart } 8166830d754dSRandall Stewart } 8167830d754dSRandall Stewart } 8168830d754dSRandall Stewart if ((j == 0) && 8169830d754dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 8170830d754dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 8171830d754dSRandall Stewart (win_probe_recovered == 0) && 8172830d754dSRandall Stewart (done_once == 0)) { 8173830d754dSRandall Stewart /* huh, this should not happen */ 8174830d754dSRandall Stewart sctp_fs_audit(asoc); 8175830d754dSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 8176830d754dSRandall Stewart net->flight_size = 0; 8177830d754dSRandall Stewart } 8178830d754dSRandall Stewart asoc->total_flight = 0; 8179830d754dSRandall Stewart asoc->total_flight_count = 0; 8180830d754dSRandall Stewart asoc->sent_queue_retran_cnt = 0; 8181830d754dSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 8182830d754dSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 8183830d754dSRandall Stewart sctp_flight_size_increase(tp1); 8184830d754dSRandall Stewart sctp_total_flight_increase(stcb, tp1); 8185830d754dSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 8186830d754dSRandall Stewart asoc->sent_queue_retran_cnt++; 8187830d754dSRandall Stewart } 8188830d754dSRandall Stewart } 8189830d754dSRandall Stewart done_once = 1; 8190830d754dSRandall Stewart goto again; 8191830d754dSRandall Stewart } 8192830d754dSRandall Stewart /*********************************************/ 8193830d754dSRandall Stewart /* Here we perform PR-SCTP procedures */ 8194830d754dSRandall Stewart /* (section 4.2) */ 8195830d754dSRandall Stewart /*********************************************/ 8196830d754dSRandall Stewart /* C1. update advancedPeerAckPoint */ 8197830d754dSRandall Stewart if (compare_with_wrap(cum_ack, asoc->advanced_peer_ack_point, MAX_TSN)) { 8198830d754dSRandall Stewart asoc->advanced_peer_ack_point = cum_ack; 8199830d754dSRandall Stewart } 8200830d754dSRandall Stewart /* C2. try to further move advancedPeerAckPoint ahead */ 8201830d754dSRandall Stewart if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) { 8202830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 8203830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 8204830d754dSRandall Stewart 8205830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 8206830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 8207830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 8208830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, cum_ack, 8209830d754dSRandall Stewart MAX_TSN)) { 8210830d754dSRandall Stewart /* 8211830d754dSRandall Stewart * ISSUE with ECN, see FWD-TSN processing for notes 8212830d754dSRandall Stewart * on issues that will occur when the ECN NONCE 8213830d754dSRandall Stewart * stuff is put into SCTP for cross checking. 8214830d754dSRandall Stewart */ 8215830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, old_adv_peer_ack_point, 8216830d754dSRandall Stewart MAX_TSN)) { 8217830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 8218830d754dSRandall Stewart /* 8219830d754dSRandall Stewart * ECN Nonce: Disable Nonce Sum check when 8220830d754dSRandall Stewart * FWD TSN is sent and store resync tsn 8221830d754dSRandall Stewart */ 8222830d754dSRandall Stewart asoc->nonce_sum_check = 0; 8223830d754dSRandall Stewart asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point; 8224830d754dSRandall Stewart } 8225830d754dSRandall Stewart } 8226830d754dSRandall Stewart if (lchk) { 8227830d754dSRandall Stewart /* Assure a timer is up */ 8228830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 8229830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 8230830d754dSRandall Stewart } 8231830d754dSRandall Stewart } 8232830d754dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 8233830d754dSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 8234830d754dSRandall Stewart a_rwnd, 8235830d754dSRandall Stewart stcb->asoc.peers_rwnd, 8236830d754dSRandall Stewart stcb->asoc.total_flight, 8237830d754dSRandall Stewart stcb->asoc.total_output_queue_size); 8238830d754dSRandall Stewart } 8239830d754dSRandall Stewart } 8240