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 48d50c1d79SRandall 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 28977acdc25SRandall Stewart static void 29077acdc25SRandall Stewart sctp_mark_non_revokable(struct sctp_association *asoc, uint32_t tsn) 29177acdc25SRandall Stewart { 29277acdc25SRandall Stewart uint32_t gap, i; 29377acdc25SRandall Stewart int fnd = 0; 29477acdc25SRandall Stewart 29577acdc25SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) { 29677acdc25SRandall Stewart return; 29777acdc25SRandall Stewart } 29877acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn); 29977acdc25SRandall Stewart if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) { 30077acdc25SRandall Stewart printf("gap:%x tsn:%x\n", gap, tsn); 30177acdc25SRandall Stewart sctp_print_mapping_array(asoc); 302b5c16493SMichael Tuexen #ifdef INVARIANTS 30377acdc25SRandall Stewart panic("Things are really messed up now!!"); 30477acdc25SRandall Stewart #endif 305b5c16493SMichael Tuexen } 30677acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 30777acdc25SRandall Stewart SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, gap); 30877acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 30977acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 31077acdc25SRandall Stewart } 31177acdc25SRandall Stewart if (tsn == asoc->highest_tsn_inside_map) { 31277acdc25SRandall Stewart /* We must back down to see what the new highest is */ 313b5c16493SMichael Tuexen for (i = tsn - 1; (compare_with_wrap(i, asoc->mapping_array_base_tsn, MAX_TSN) || 314b5c16493SMichael Tuexen (i == asoc->mapping_array_base_tsn)); i--) { 31577acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, i, asoc->mapping_array_base_tsn); 31677acdc25SRandall Stewart if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) { 31777acdc25SRandall Stewart asoc->highest_tsn_inside_map = i; 31877acdc25SRandall Stewart fnd = 1; 31977acdc25SRandall Stewart break; 32077acdc25SRandall Stewart } 32177acdc25SRandall Stewart } 32277acdc25SRandall Stewart if (!fnd) { 32377acdc25SRandall Stewart asoc->highest_tsn_inside_map = asoc->mapping_array_base_tsn - 1; 32477acdc25SRandall Stewart } 32577acdc25SRandall Stewart } 32677acdc25SRandall Stewart } 32777acdc25SRandall Stewart 32817205eccSRandall Stewart 329f8829a4aSRandall Stewart /* 330f8829a4aSRandall Stewart * We are delivering currently from the reassembly queue. We must continue to 331f8829a4aSRandall Stewart * deliver until we either: 1) run out of space. 2) run out of sequential 332f8829a4aSRandall Stewart * TSN's 3) hit the SCTP_DATA_LAST_FRAG flag. 333f8829a4aSRandall Stewart */ 334f8829a4aSRandall Stewart static void 335f8829a4aSRandall Stewart sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc) 336f8829a4aSRandall Stewart { 337f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 338f8829a4aSRandall Stewart uint16_t nxt_todel; 339f8829a4aSRandall Stewart uint16_t stream_no; 340f8829a4aSRandall Stewart int end = 0; 341f8829a4aSRandall Stewart int cntDel; 342830d754dSRandall Stewart 343f8829a4aSRandall Stewart struct sctp_queued_to_read *control, *ctl, *ctlat; 344f8829a4aSRandall Stewart 345ad81507eSRandall Stewart if (stcb == NULL) 346ad81507eSRandall Stewart return; 347ad81507eSRandall Stewart 348f42a358aSRandall Stewart cntDel = stream_no = 0; 349ad81507eSRandall Stewart if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || 350851b7298SRandall Stewart (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) || 351ad81507eSRandall Stewart (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) { 352851b7298SRandall Stewart /* socket above is long gone or going.. */ 353851b7298SRandall Stewart abandon: 354f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 355f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 356f8829a4aSRandall Stewart while (chk) { 357f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 358f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 359f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 360f8829a4aSRandall Stewart /* 361f8829a4aSRandall Stewart * Lose the data pointer, since its in the socket 362f8829a4aSRandall Stewart * buffer 363f8829a4aSRandall Stewart */ 364f8829a4aSRandall Stewart if (chk->data) { 365f8829a4aSRandall Stewart sctp_m_freem(chk->data); 366f8829a4aSRandall Stewart chk->data = NULL; 367f8829a4aSRandall Stewart } 368f8829a4aSRandall Stewart /* Now free the address and data */ 369f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 3703c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 371f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 372f8829a4aSRandall Stewart } 373f8829a4aSRandall Stewart return; 374f8829a4aSRandall Stewart } 375f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 376f8829a4aSRandall Stewart do { 377f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 378f8829a4aSRandall Stewart if (chk == NULL) { 379f8829a4aSRandall Stewart return; 380f8829a4aSRandall Stewart } 381f8829a4aSRandall Stewart if (chk->rec.data.TSN_seq != (asoc->tsn_last_delivered + 1)) { 382f8829a4aSRandall Stewart /* Can't deliver more :< */ 383f8829a4aSRandall Stewart return; 384f8829a4aSRandall Stewart } 385f8829a4aSRandall Stewart stream_no = chk->rec.data.stream_number; 386f8829a4aSRandall Stewart nxt_todel = asoc->strmin[stream_no].last_sequence_delivered + 1; 387f8829a4aSRandall Stewart if (nxt_todel != chk->rec.data.stream_seq && 388f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { 389f8829a4aSRandall Stewart /* 390f8829a4aSRandall Stewart * Not the next sequence to deliver in its stream OR 391f8829a4aSRandall Stewart * unordered 392f8829a4aSRandall Stewart */ 393f8829a4aSRandall Stewart return; 394f8829a4aSRandall Stewart } 395f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 396f8829a4aSRandall Stewart 397f8829a4aSRandall Stewart control = sctp_build_readq_entry_chk(stcb, chk); 398f8829a4aSRandall Stewart if (control == NULL) { 399f8829a4aSRandall Stewart /* out of memory? */ 400f8829a4aSRandall Stewart return; 401f8829a4aSRandall Stewart } 402f8829a4aSRandall Stewart /* save it off for our future deliveries */ 403f8829a4aSRandall Stewart stcb->asoc.control_pdapi = control; 404f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) 405f8829a4aSRandall Stewart end = 1; 406f8829a4aSRandall Stewart else 407f8829a4aSRandall Stewart end = 0; 408b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq); 409f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, 410cfde3ff7SRandall Stewart stcb, control, &stcb->sctp_socket->so_rcv, end, 411cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 412f8829a4aSRandall Stewart cntDel++; 413f8829a4aSRandall Stewart } else { 414f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) 415f8829a4aSRandall Stewart end = 1; 416f8829a4aSRandall Stewart else 417f8829a4aSRandall Stewart end = 0; 418b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq); 419f8829a4aSRandall Stewart if (sctp_append_to_readq(stcb->sctp_ep, stcb, 420f8829a4aSRandall Stewart stcb->asoc.control_pdapi, 421f8829a4aSRandall Stewart chk->data, end, chk->rec.data.TSN_seq, 422f8829a4aSRandall Stewart &stcb->sctp_socket->so_rcv)) { 423f8829a4aSRandall Stewart /* 424f8829a4aSRandall Stewart * something is very wrong, either 425f8829a4aSRandall Stewart * control_pdapi is NULL, or the tail_mbuf 426f8829a4aSRandall Stewart * is corrupt, or there is a EOM already on 427f8829a4aSRandall Stewart * the mbuf chain. 428f8829a4aSRandall Stewart */ 429851b7298SRandall Stewart if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { 430851b7298SRandall Stewart goto abandon; 431851b7298SRandall Stewart } else { 432df6e0cc3SRandall Stewart #ifdef INVARIANTS 433ad81507eSRandall Stewart if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) { 434f8829a4aSRandall Stewart panic("This should not happen control_pdapi NULL?"); 435f8829a4aSRandall Stewart } 436f8829a4aSRandall Stewart /* if we did not panic, it was a EOM */ 437f8829a4aSRandall Stewart panic("Bad chunking ??"); 438df6e0cc3SRandall Stewart #else 439df6e0cc3SRandall Stewart if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) { 440df6e0cc3SRandall Stewart SCTP_PRINTF("This should not happen control_pdapi NULL?\n"); 441df6e0cc3SRandall Stewart } 442df6e0cc3SRandall Stewart SCTP_PRINTF("Bad chunking ??\n"); 443df6e0cc3SRandall Stewart SCTP_PRINTF("Dumping re-assembly queue this will probably hose the association\n"); 444df6e0cc3SRandall Stewart 445df6e0cc3SRandall Stewart #endif 446df6e0cc3SRandall Stewart goto abandon; 447f8829a4aSRandall Stewart } 448851b7298SRandall Stewart } 449f8829a4aSRandall Stewart cntDel++; 450f8829a4aSRandall Stewart } 451f8829a4aSRandall Stewart /* pull it we did it */ 452f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 453f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 454f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 455f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { 456f8829a4aSRandall Stewart asoc->strmin[stream_no].last_sequence_delivered++; 457f8829a4aSRandall Stewart } 458f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { 459f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); 460f8829a4aSRandall Stewart } 461f8829a4aSRandall Stewart } else if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 462f8829a4aSRandall Stewart /* 463f8829a4aSRandall Stewart * turn the flag back on since we just delivered 464f8829a4aSRandall Stewart * yet another one. 465f8829a4aSRandall Stewart */ 466f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 467f8829a4aSRandall Stewart } 468f8829a4aSRandall Stewart asoc->tsn_of_pdapi_last_delivered = chk->rec.data.TSN_seq; 469f8829a4aSRandall Stewart asoc->last_flags_delivered = chk->rec.data.rcv_flags; 470f8829a4aSRandall Stewart asoc->last_strm_seq_delivered = chk->rec.data.stream_seq; 471f8829a4aSRandall Stewart asoc->last_strm_no_delivered = chk->rec.data.stream_number; 472f8829a4aSRandall Stewart 473f8829a4aSRandall Stewart asoc->tsn_last_delivered = chk->rec.data.TSN_seq; 474f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 475f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 476f8829a4aSRandall Stewart /* free up the chk */ 477f8829a4aSRandall Stewart chk->data = NULL; 478f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 479f8829a4aSRandall Stewart 480f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 481f8829a4aSRandall Stewart /* 482f8829a4aSRandall Stewart * Now lets see if we can deliver the next one on 483f8829a4aSRandall Stewart * the stream 484f8829a4aSRandall Stewart */ 485f8829a4aSRandall Stewart struct sctp_stream_in *strm; 486f8829a4aSRandall Stewart 487f8829a4aSRandall Stewart strm = &asoc->strmin[stream_no]; 488f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 489f8829a4aSRandall Stewart ctl = TAILQ_FIRST(&strm->inqueue); 490f8829a4aSRandall Stewart if (ctl && (nxt_todel == ctl->sinfo_ssn)) { 491f8829a4aSRandall Stewart while (ctl != NULL) { 492f8829a4aSRandall Stewart /* Deliver more if we can. */ 493f8829a4aSRandall Stewart if (nxt_todel == ctl->sinfo_ssn) { 494f8829a4aSRandall Stewart ctlat = TAILQ_NEXT(ctl, next); 495f8829a4aSRandall Stewart TAILQ_REMOVE(&strm->inqueue, ctl, next); 496f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 497f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 498f8829a4aSRandall Stewart strm->last_sequence_delivered++; 499b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 500f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 501f8829a4aSRandall Stewart ctl, 502cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 503cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 504f8829a4aSRandall Stewart ctl = ctlat; 505f8829a4aSRandall Stewart } else { 506f8829a4aSRandall Stewart break; 507f8829a4aSRandall Stewart } 508f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 509f8829a4aSRandall Stewart } 510f8829a4aSRandall Stewart } 511139bc87fSRandall Stewart break; 512f8829a4aSRandall Stewart } 5133c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 514f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 515f8829a4aSRandall Stewart } while (chk); 516f8829a4aSRandall Stewart } 517f8829a4aSRandall Stewart 518f8829a4aSRandall Stewart /* 519f8829a4aSRandall Stewart * Queue the chunk either right into the socket buffer if it is the next one 520f8829a4aSRandall Stewart * to go OR put it in the correct place in the delivery queue. If we do 521f8829a4aSRandall Stewart * append to the so_buf, keep doing so until we are out of order. One big 522f8829a4aSRandall Stewart * question still remains, what to do when the socket buffer is FULL?? 523f8829a4aSRandall Stewart */ 524f8829a4aSRandall Stewart static void 525f8829a4aSRandall Stewart sctp_queue_data_to_stream(struct sctp_tcb *stcb, struct sctp_association *asoc, 526f8829a4aSRandall Stewart struct sctp_queued_to_read *control, int *abort_flag) 527f8829a4aSRandall Stewart { 528f8829a4aSRandall Stewart /* 529f8829a4aSRandall Stewart * FIX-ME maybe? What happens when the ssn wraps? If we are getting 530f8829a4aSRandall Stewart * all the data in one stream this could happen quite rapidly. One 531f8829a4aSRandall Stewart * could use the TSN to keep track of things, but this scheme breaks 532f8829a4aSRandall Stewart * down in the other type of stream useage that could occur. Send a 533f8829a4aSRandall Stewart * single msg to stream 0, send 4Billion messages to stream 1, now 534f8829a4aSRandall Stewart * send a message to stream 0. You have a situation where the TSN 535f8829a4aSRandall Stewart * has wrapped but not in the stream. Is this worth worrying about 536f8829a4aSRandall Stewart * or should we just change our queue sort at the bottom to be by 537f8829a4aSRandall Stewart * TSN. 538f8829a4aSRandall Stewart * 539f8829a4aSRandall Stewart * Could it also be legal for a peer to send ssn 1 with TSN 2 and ssn 2 540f8829a4aSRandall Stewart * with TSN 1? If the peer is doing some sort of funky TSN/SSN 541f8829a4aSRandall Stewart * assignment this could happen... and I don't see how this would be 542f8829a4aSRandall Stewart * a violation. So for now I am undecided an will leave the sort by 543f8829a4aSRandall Stewart * SSN alone. Maybe a hybred approach is the answer 544f8829a4aSRandall Stewart * 545f8829a4aSRandall Stewart */ 546f8829a4aSRandall Stewart struct sctp_stream_in *strm; 547f8829a4aSRandall Stewart struct sctp_queued_to_read *at; 548f8829a4aSRandall Stewart int queue_needed; 549f8829a4aSRandall Stewart uint16_t nxt_todel; 550f8829a4aSRandall Stewart struct mbuf *oper; 551f8829a4aSRandall Stewart 552f8829a4aSRandall Stewart queue_needed = 1; 553f8829a4aSRandall Stewart asoc->size_on_all_streams += control->length; 554f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_all_streams); 555f8829a4aSRandall Stewart strm = &asoc->strmin[control->sinfo_stream]; 556f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 557b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 558f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD); 55980fefe0aSRandall Stewart } 560ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, 561ad81507eSRandall Stewart "queue to stream called for ssn:%u lastdel:%u nxt:%u\n", 562f8829a4aSRandall Stewart (uint32_t) control->sinfo_stream, 563ad81507eSRandall Stewart (uint32_t) strm->last_sequence_delivered, 564ad81507eSRandall Stewart (uint32_t) nxt_todel); 565f8829a4aSRandall Stewart if (compare_with_wrap(strm->last_sequence_delivered, 566f8829a4aSRandall Stewart control->sinfo_ssn, MAX_SEQ) || 567f8829a4aSRandall Stewart (strm->last_sequence_delivered == control->sinfo_ssn)) { 568f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 569ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ:%d delivered:%d from peer, Abort association\n", 570ad81507eSRandall Stewart control->sinfo_ssn, strm->last_sequence_delivered); 571c40e9cf2SRandall Stewart protocol_error: 572f8829a4aSRandall Stewart /* 573f8829a4aSRandall Stewart * throw it in the stream so it gets cleaned up in 574f8829a4aSRandall Stewart * association destruction 575f8829a4aSRandall Stewart */ 576f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&strm->inqueue, control, next); 577139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 578f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 579f8829a4aSRandall Stewart if (oper) { 580f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 581f8829a4aSRandall Stewart uint32_t *ippp; 582f8829a4aSRandall Stewart 583139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 584f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 585f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 586f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 587139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 588f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 589a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_1); 590f8829a4aSRandall Stewart ippp++; 591f8829a4aSRandall Stewart *ippp = control->sinfo_tsn; 592f8829a4aSRandall Stewart ippp++; 593f8829a4aSRandall Stewart *ippp = ((control->sinfo_stream << 16) | control->sinfo_ssn); 594f8829a4aSRandall Stewart } 595a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_1; 596f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 597ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 598f8829a4aSRandall Stewart 599f8829a4aSRandall Stewart *abort_flag = 1; 600f8829a4aSRandall Stewart return; 601f8829a4aSRandall Stewart 602f8829a4aSRandall Stewart } 603f8829a4aSRandall Stewart if (nxt_todel == control->sinfo_ssn) { 604f8829a4aSRandall Stewart /* can be delivered right away? */ 605b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 606f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_IMMED_DEL); 60780fefe0aSRandall Stewart } 608830d754dSRandall Stewart /* EY it wont be queued if it could be delivered directly */ 609f8829a4aSRandall Stewart queue_needed = 0; 610f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 611f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 612f8829a4aSRandall Stewart strm->last_sequence_delivered++; 61377acdc25SRandall Stewart 614b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 615f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 616f8829a4aSRandall Stewart control, 617cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 618cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 619f8829a4aSRandall Stewart control = TAILQ_FIRST(&strm->inqueue); 620f8829a4aSRandall Stewart while (control != NULL) { 621f8829a4aSRandall Stewart /* all delivered */ 622f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 623f8829a4aSRandall Stewart if (nxt_todel == control->sinfo_ssn) { 624f8829a4aSRandall Stewart at = TAILQ_NEXT(control, next); 625f8829a4aSRandall Stewart TAILQ_REMOVE(&strm->inqueue, control, next); 626f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 627f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 628f8829a4aSRandall Stewart strm->last_sequence_delivered++; 629f8829a4aSRandall Stewart /* 630f8829a4aSRandall Stewart * We ignore the return of deliver_data here 631f8829a4aSRandall Stewart * since we always can hold the chunk on the 632f8829a4aSRandall Stewart * d-queue. And we have a finite number that 633f8829a4aSRandall Stewart * can be delivered from the strq. 634f8829a4aSRandall Stewart */ 635b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 636f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, 637f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_IMMED_DEL); 63880fefe0aSRandall Stewart } 639b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 640f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 641f8829a4aSRandall Stewart control, 642cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 643cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, 644cfde3ff7SRandall Stewart SCTP_SO_NOT_LOCKED); 645f8829a4aSRandall Stewart control = at; 646f8829a4aSRandall Stewart continue; 647f8829a4aSRandall Stewart } 648f8829a4aSRandall Stewart break; 649f8829a4aSRandall Stewart } 650f8829a4aSRandall Stewart } 651f8829a4aSRandall Stewart if (queue_needed) { 652f8829a4aSRandall Stewart /* 653f8829a4aSRandall Stewart * Ok, we did not deliver this guy, find the correct place 654f8829a4aSRandall Stewart * to put it on the queue. 655f8829a4aSRandall Stewart */ 656c40e9cf2SRandall Stewart if ((compare_with_wrap(asoc->cumulative_tsn, 657c40e9cf2SRandall Stewart control->sinfo_tsn, MAX_TSN)) || 658c40e9cf2SRandall Stewart (control->sinfo_tsn == asoc->cumulative_tsn)) { 659c40e9cf2SRandall Stewart goto protocol_error; 660c40e9cf2SRandall Stewart } 661f8829a4aSRandall Stewart if (TAILQ_EMPTY(&strm->inqueue)) { 662f8829a4aSRandall Stewart /* Empty queue */ 663b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 664f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INSERT_HD); 66580fefe0aSRandall Stewart } 666f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&strm->inqueue, control, next); 667f8829a4aSRandall Stewart } else { 668f8829a4aSRandall Stewart TAILQ_FOREACH(at, &strm->inqueue, next) { 669f8829a4aSRandall Stewart if (compare_with_wrap(at->sinfo_ssn, 670f8829a4aSRandall Stewart control->sinfo_ssn, MAX_SEQ)) { 671f8829a4aSRandall Stewart /* 672f8829a4aSRandall Stewart * one in queue is bigger than the 673f8829a4aSRandall Stewart * new one, insert before this one 674f8829a4aSRandall Stewart */ 675b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 676f8829a4aSRandall Stewart sctp_log_strm_del(control, at, 677f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_INSERT_MD); 67880fefe0aSRandall Stewart } 679f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(at, control, next); 680f8829a4aSRandall Stewart break; 681f8829a4aSRandall Stewart } else if (at->sinfo_ssn == control->sinfo_ssn) { 682f8829a4aSRandall Stewart /* 683f8829a4aSRandall Stewart * Gak, He sent me a duplicate str 684f8829a4aSRandall Stewart * seq number 685f8829a4aSRandall Stewart */ 686f8829a4aSRandall Stewart /* 687f8829a4aSRandall Stewart * foo bar, I guess I will just free 688f8829a4aSRandall Stewart * this new guy, should we abort 689f8829a4aSRandall Stewart * too? FIX ME MAYBE? Or it COULD be 690f8829a4aSRandall Stewart * that the SSN's have wrapped. 691f8829a4aSRandall Stewart * Maybe I should compare to TSN 692f8829a4aSRandall Stewart * somehow... sigh for now just blow 693f8829a4aSRandall Stewart * away the chunk! 694f8829a4aSRandall Stewart */ 695f8829a4aSRandall Stewart 696f8829a4aSRandall Stewart if (control->data) 697f8829a4aSRandall Stewart sctp_m_freem(control->data); 698f8829a4aSRandall Stewart control->data = NULL; 699f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 700f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 7015bead436SRandall Stewart if (control->whoFrom) 702f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 7035bead436SRandall Stewart control->whoFrom = NULL; 704f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 705f8829a4aSRandall Stewart return; 706f8829a4aSRandall Stewart } else { 707f8829a4aSRandall Stewart if (TAILQ_NEXT(at, next) == NULL) { 708f8829a4aSRandall Stewart /* 709f8829a4aSRandall Stewart * We are at the end, insert 710f8829a4aSRandall Stewart * it after this one 711f8829a4aSRandall Stewart */ 712b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 713f8829a4aSRandall Stewart sctp_log_strm_del(control, at, 714f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_INSERT_TL); 71580fefe0aSRandall Stewart } 716f8829a4aSRandall Stewart TAILQ_INSERT_AFTER(&strm->inqueue, 717f8829a4aSRandall Stewart at, control, next); 718f8829a4aSRandall Stewart break; 719f8829a4aSRandall Stewart } 720f8829a4aSRandall Stewart } 721f8829a4aSRandall Stewart } 722f8829a4aSRandall Stewart } 723f8829a4aSRandall Stewart } 724f8829a4aSRandall Stewart } 725f8829a4aSRandall Stewart 726f8829a4aSRandall Stewart /* 727f8829a4aSRandall Stewart * Returns two things: You get the total size of the deliverable parts of the 728f8829a4aSRandall Stewart * first fragmented message on the reassembly queue. And you get a 1 back if 729f8829a4aSRandall Stewart * all of the message is ready or a 0 back if the message is still incomplete 730f8829a4aSRandall Stewart */ 731f8829a4aSRandall Stewart static int 732f8829a4aSRandall Stewart sctp_is_all_msg_on_reasm(struct sctp_association *asoc, uint32_t * t_size) 733f8829a4aSRandall Stewart { 734f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 735f8829a4aSRandall Stewart uint32_t tsn; 736f8829a4aSRandall Stewart 737f8829a4aSRandall Stewart *t_size = 0; 738f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 739f8829a4aSRandall Stewart if (chk == NULL) { 740f8829a4aSRandall Stewart /* nothing on the queue */ 741f8829a4aSRandall Stewart return (0); 742f8829a4aSRandall Stewart } 743f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { 744f8829a4aSRandall Stewart /* Not a first on the queue */ 745f8829a4aSRandall Stewart return (0); 746f8829a4aSRandall Stewart } 747f8829a4aSRandall Stewart tsn = chk->rec.data.TSN_seq; 748f8829a4aSRandall Stewart while (chk) { 749f8829a4aSRandall Stewart if (tsn != chk->rec.data.TSN_seq) { 750f8829a4aSRandall Stewart return (0); 751f8829a4aSRandall Stewart } 752f8829a4aSRandall Stewart *t_size += chk->send_size; 753f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 754f8829a4aSRandall Stewart return (1); 755f8829a4aSRandall Stewart } 756f8829a4aSRandall Stewart tsn++; 757f8829a4aSRandall Stewart chk = TAILQ_NEXT(chk, sctp_next); 758f8829a4aSRandall Stewart } 759f8829a4aSRandall Stewart return (0); 760f8829a4aSRandall Stewart } 761f8829a4aSRandall Stewart 762f8829a4aSRandall Stewart static void 763f8829a4aSRandall Stewart sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc) 764f8829a4aSRandall Stewart { 765f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 766f8829a4aSRandall Stewart uint16_t nxt_todel; 767810ec536SMichael Tuexen uint32_t tsize, pd_point; 768f8829a4aSRandall Stewart 769139bc87fSRandall Stewart doit_again: 770f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 771f8829a4aSRandall Stewart if (chk == NULL) { 772f8829a4aSRandall Stewart /* Huh? */ 773f8829a4aSRandall Stewart asoc->size_on_reasm_queue = 0; 774f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue = 0; 775f8829a4aSRandall Stewart return; 776f8829a4aSRandall Stewart } 777f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 778f8829a4aSRandall Stewart nxt_todel = 779f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1; 780f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) && 781f8829a4aSRandall Stewart (nxt_todel == chk->rec.data.stream_seq || 782f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) { 783f8829a4aSRandall Stewart /* 784f8829a4aSRandall Stewart * Yep the first one is here and its ok to deliver 785f8829a4aSRandall Stewart * but should we? 786f8829a4aSRandall Stewart */ 787810ec536SMichael Tuexen if (stcb->sctp_socket) { 78824ae5c4aSMichael Tuexen pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), 789810ec536SMichael Tuexen stcb->sctp_ep->partial_delivery_point); 790810ec536SMichael Tuexen } else { 791810ec536SMichael Tuexen pd_point = stcb->sctp_ep->partial_delivery_point; 792810ec536SMichael Tuexen } 793810ec536SMichael Tuexen if (sctp_is_all_msg_on_reasm(asoc, &tsize) || (tsize >= pd_point)) { 794f8829a4aSRandall Stewart 795f8829a4aSRandall Stewart /* 796f8829a4aSRandall Stewart * Yes, we setup to start reception, by 797f8829a4aSRandall Stewart * backing down the TSN just in case we 798f8829a4aSRandall Stewart * can't deliver. If we 799f8829a4aSRandall Stewart */ 800f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 801f8829a4aSRandall Stewart asoc->tsn_last_delivered = 802f8829a4aSRandall Stewart chk->rec.data.TSN_seq - 1; 803f8829a4aSRandall Stewart asoc->str_of_pdapi = 804f8829a4aSRandall Stewart chk->rec.data.stream_number; 805f8829a4aSRandall Stewart asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 806f8829a4aSRandall Stewart asoc->pdapi_ppid = chk->rec.data.payloadtype; 807f8829a4aSRandall Stewart asoc->fragment_flags = chk->rec.data.rcv_flags; 808f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 809f8829a4aSRandall Stewart } 810f8829a4aSRandall Stewart } 811f8829a4aSRandall Stewart } else { 812139bc87fSRandall Stewart /* 813139bc87fSRandall Stewart * Service re-assembly will deliver stream data queued at 814139bc87fSRandall Stewart * the end of fragmented delivery.. but it wont know to go 815139bc87fSRandall Stewart * back and call itself again... we do that here with the 816139bc87fSRandall Stewart * got doit_again 817139bc87fSRandall Stewart */ 818f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 819139bc87fSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 820139bc87fSRandall Stewart /* 821139bc87fSRandall Stewart * finished our Fragmented delivery, could be more 822139bc87fSRandall Stewart * waiting? 823139bc87fSRandall Stewart */ 824139bc87fSRandall Stewart goto doit_again; 825139bc87fSRandall Stewart } 826f8829a4aSRandall Stewart } 827f8829a4aSRandall Stewart } 828f8829a4aSRandall Stewart 829f8829a4aSRandall Stewart /* 830f8829a4aSRandall Stewart * Dump onto the re-assembly queue, in its proper place. After dumping on the 831f8829a4aSRandall Stewart * queue, see if anthing can be delivered. If so pull it off (or as much as 832f8829a4aSRandall Stewart * we can. If we run out of space then we must dump what we can and set the 833f8829a4aSRandall Stewart * appropriate flag to say we queued what we could. 834f8829a4aSRandall Stewart */ 835f8829a4aSRandall Stewart static void 836f8829a4aSRandall Stewart sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, 837f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk, int *abort_flag) 838f8829a4aSRandall Stewart { 839f8829a4aSRandall Stewart struct mbuf *oper; 840f8829a4aSRandall Stewart uint32_t cum_ackp1, last_tsn, prev_tsn, post_tsn; 841f8829a4aSRandall Stewart u_char last_flags; 842f8829a4aSRandall Stewart struct sctp_tmit_chunk *at, *prev, *next; 843f8829a4aSRandall Stewart 844f8829a4aSRandall Stewart prev = next = NULL; 845f8829a4aSRandall Stewart cum_ackp1 = asoc->tsn_last_delivered + 1; 846f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue)) { 847f8829a4aSRandall Stewart /* This is the first one on the queue */ 848f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&asoc->reasmqueue, chk, sctp_next); 849f8829a4aSRandall Stewart /* 850f8829a4aSRandall Stewart * we do not check for delivery of anything when only one 851f8829a4aSRandall Stewart * fragment is here 852f8829a4aSRandall Stewart */ 853f8829a4aSRandall Stewart asoc->size_on_reasm_queue = chk->send_size; 854f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 855f8829a4aSRandall Stewart if (chk->rec.data.TSN_seq == cum_ackp1) { 856f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0 && 857f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) != 858f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 859f8829a4aSRandall Stewart /* 860f8829a4aSRandall Stewart * An empty queue, no delivery inprogress, 861f8829a4aSRandall Stewart * we hit the next one and it does NOT have 862f8829a4aSRandall Stewart * a FIRST fragment mark. 863f8829a4aSRandall Stewart */ 864ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not first, no fragmented delivery in progress\n"); 865139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 866f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 867f8829a4aSRandall Stewart 868f8829a4aSRandall Stewart if (oper) { 869f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 870f8829a4aSRandall Stewart uint32_t *ippp; 871f8829a4aSRandall Stewart 872139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 873f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 874f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 875f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 876f8829a4aSRandall Stewart ph->param_type = 877f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 878139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 879f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 880a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_2); 881f8829a4aSRandall Stewart ippp++; 882f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 883f8829a4aSRandall Stewart ippp++; 884f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 885f8829a4aSRandall Stewart 886f8829a4aSRandall Stewart } 887a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2; 888f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 889ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 890f8829a4aSRandall Stewart *abort_flag = 1; 891f8829a4aSRandall Stewart } else if (asoc->fragmented_delivery_inprogress && 892f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) { 893f8829a4aSRandall Stewart /* 894f8829a4aSRandall Stewart * We are doing a partial delivery and the 895f8829a4aSRandall Stewart * NEXT chunk MUST be either the LAST or 896f8829a4aSRandall Stewart * MIDDLE fragment NOT a FIRST 897f8829a4aSRandall Stewart */ 898ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS a first and fragmented delivery in progress\n"); 899139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 900f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 901f8829a4aSRandall Stewart if (oper) { 902f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 903f8829a4aSRandall Stewart uint32_t *ippp; 904f8829a4aSRandall Stewart 905139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 906f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 907f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 908f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 909f8829a4aSRandall Stewart ph->param_type = 910f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 911139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 912f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 913a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_3); 914f8829a4aSRandall Stewart ippp++; 915f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 916f8829a4aSRandall Stewart ippp++; 917f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 918f8829a4aSRandall Stewart } 919a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_3; 920f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 921ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 922f8829a4aSRandall Stewart *abort_flag = 1; 923f8829a4aSRandall Stewart } else if (asoc->fragmented_delivery_inprogress) { 924f8829a4aSRandall Stewart /* 925f8829a4aSRandall Stewart * Here we are ok with a MIDDLE or LAST 926f8829a4aSRandall Stewart * piece 927f8829a4aSRandall Stewart */ 928f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 929f8829a4aSRandall Stewart asoc->str_of_pdapi) { 930f8829a4aSRandall Stewart /* Got to be the right STR No */ 931ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream number %d vs %d\n", 932f8829a4aSRandall Stewart chk->rec.data.stream_number, 933f8829a4aSRandall Stewart asoc->str_of_pdapi); 934139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 935f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 936f8829a4aSRandall Stewart if (oper) { 937f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 938f8829a4aSRandall Stewart uint32_t *ippp; 939f8829a4aSRandall Stewart 940139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 941f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 942f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 943f8829a4aSRandall Stewart ph = mtod(oper, 944f8829a4aSRandall Stewart struct sctp_paramhdr *); 945f8829a4aSRandall Stewart ph->param_type = 946f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 947f8829a4aSRandall Stewart ph->param_length = 948139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 949f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 950a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_4); 951f8829a4aSRandall Stewart ippp++; 952f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 953f8829a4aSRandall Stewart ippp++; 954f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 955f8829a4aSRandall Stewart } 956a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_4; 957f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 958ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 959f8829a4aSRandall Stewart *abort_flag = 1; 960f8829a4aSRandall Stewart } else if ((asoc->fragment_flags & SCTP_DATA_UNORDERED) != 961f8829a4aSRandall Stewart SCTP_DATA_UNORDERED && 962b5c16493SMichael Tuexen chk->rec.data.stream_seq != asoc->ssn_of_pdapi) { 963f8829a4aSRandall Stewart /* Got to be the right STR Seq */ 964ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream seq %d vs %d\n", 965f8829a4aSRandall Stewart chk->rec.data.stream_seq, 966f8829a4aSRandall Stewart asoc->ssn_of_pdapi); 967139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 968f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 969f8829a4aSRandall Stewart if (oper) { 970f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 971f8829a4aSRandall Stewart uint32_t *ippp; 972f8829a4aSRandall Stewart 973139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 974f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 975f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 976f8829a4aSRandall Stewart ph = mtod(oper, 977f8829a4aSRandall Stewart struct sctp_paramhdr *); 978f8829a4aSRandall Stewart ph->param_type = 979f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 980f8829a4aSRandall Stewart ph->param_length = 981139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 982f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 983a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_5); 984f8829a4aSRandall Stewart ippp++; 985f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 986f8829a4aSRandall Stewart ippp++; 987f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 988f8829a4aSRandall Stewart 989f8829a4aSRandall Stewart } 990a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_5; 991f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 992ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 993f8829a4aSRandall Stewart *abort_flag = 1; 994f8829a4aSRandall Stewart } 995f8829a4aSRandall Stewart } 996f8829a4aSRandall Stewart } 997f8829a4aSRandall Stewart return; 998f8829a4aSRandall Stewart } 999f8829a4aSRandall Stewart /* Find its place */ 1000f8829a4aSRandall Stewart TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) { 1001f8829a4aSRandall Stewart if (compare_with_wrap(at->rec.data.TSN_seq, 1002f8829a4aSRandall Stewart chk->rec.data.TSN_seq, MAX_TSN)) { 1003f8829a4aSRandall Stewart /* 1004f8829a4aSRandall Stewart * one in queue is bigger than the new one, insert 1005f8829a4aSRandall Stewart * before this one 1006f8829a4aSRandall Stewart */ 1007f8829a4aSRandall Stewart /* A check */ 1008f8829a4aSRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 1009f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 1010f8829a4aSRandall Stewart next = at; 1011f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(at, chk, sctp_next); 1012f8829a4aSRandall Stewart break; 1013f8829a4aSRandall Stewart } else if (at->rec.data.TSN_seq == chk->rec.data.TSN_seq) { 1014f8829a4aSRandall Stewart /* Gak, He sent me a duplicate str seq number */ 1015f8829a4aSRandall Stewart /* 1016f8829a4aSRandall Stewart * foo bar, I guess I will just free this new guy, 1017f8829a4aSRandall Stewart * should we abort too? FIX ME MAYBE? Or it COULD be 1018f8829a4aSRandall Stewart * that the SSN's have wrapped. Maybe I should 1019f8829a4aSRandall Stewart * compare to TSN somehow... sigh for now just blow 1020f8829a4aSRandall Stewart * away the chunk! 1021f8829a4aSRandall Stewart */ 1022f8829a4aSRandall Stewart if (chk->data) { 1023f8829a4aSRandall Stewart sctp_m_freem(chk->data); 1024f8829a4aSRandall Stewart chk->data = NULL; 1025f8829a4aSRandall Stewart } 1026f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 1027f8829a4aSRandall Stewart return; 1028f8829a4aSRandall Stewart } else { 1029f8829a4aSRandall Stewart last_flags = at->rec.data.rcv_flags; 1030f8829a4aSRandall Stewart last_tsn = at->rec.data.TSN_seq; 1031f8829a4aSRandall Stewart prev = at; 1032f8829a4aSRandall Stewart if (TAILQ_NEXT(at, sctp_next) == NULL) { 1033f8829a4aSRandall Stewart /* 1034f8829a4aSRandall Stewart * We are at the end, insert it after this 1035f8829a4aSRandall Stewart * one 1036f8829a4aSRandall Stewart */ 1037f8829a4aSRandall Stewart /* check it first */ 1038f8829a4aSRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 1039f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 1040f8829a4aSRandall Stewart TAILQ_INSERT_AFTER(&asoc->reasmqueue, at, chk, sctp_next); 1041f8829a4aSRandall Stewart break; 1042f8829a4aSRandall Stewart } 1043f8829a4aSRandall Stewart } 1044f8829a4aSRandall Stewart } 1045f8829a4aSRandall Stewart /* Now the audits */ 1046f8829a4aSRandall Stewart if (prev) { 1047f8829a4aSRandall Stewart prev_tsn = chk->rec.data.TSN_seq - 1; 1048f8829a4aSRandall Stewart if (prev_tsn == prev->rec.data.TSN_seq) { 1049f8829a4aSRandall Stewart /* 1050f8829a4aSRandall Stewart * Ok the one I am dropping onto the end is the 1051f8829a4aSRandall Stewart * NEXT. A bit of valdiation here. 1052f8829a4aSRandall Stewart */ 1053f8829a4aSRandall Stewart if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1054f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG || 1055f8829a4aSRandall Stewart (prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1056f8829a4aSRandall Stewart SCTP_DATA_MIDDLE_FRAG) { 1057f8829a4aSRandall Stewart /* 1058f8829a4aSRandall Stewart * Insert chk MUST be a MIDDLE or LAST 1059f8829a4aSRandall Stewart * fragment 1060f8829a4aSRandall Stewart */ 1061f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1062f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1063ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - It can be a midlle or last but not a first\n"); 1064ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it's a FIRST!\n"); 1065139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1066f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1067f8829a4aSRandall Stewart if (oper) { 1068f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1069f8829a4aSRandall Stewart uint32_t *ippp; 1070f8829a4aSRandall Stewart 1071139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1072f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1073f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1074f8829a4aSRandall Stewart ph = mtod(oper, 1075f8829a4aSRandall Stewart struct sctp_paramhdr *); 1076f8829a4aSRandall Stewart ph->param_type = 1077f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1078f8829a4aSRandall Stewart ph->param_length = 1079139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1080f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1081a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_6); 1082f8829a4aSRandall Stewart ippp++; 1083f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1084f8829a4aSRandall Stewart ippp++; 1085f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1086f8829a4aSRandall Stewart 1087f8829a4aSRandall Stewart } 1088a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_6; 1089f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1090ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1091f8829a4aSRandall Stewart *abort_flag = 1; 1092f8829a4aSRandall Stewart return; 1093f8829a4aSRandall Stewart } 1094f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 1095f8829a4aSRandall Stewart prev->rec.data.stream_number) { 1096f8829a4aSRandall Stewart /* 1097f8829a4aSRandall Stewart * Huh, need the correct STR here, 1098f8829a4aSRandall Stewart * they must be the same. 1099f8829a4aSRandall Stewart */ 1100ad81507eSRandall Stewart SCTP_PRINTF("Prev check - Gak, Evil plot, ssn:%d not the same as at:%d\n", 1101f8829a4aSRandall Stewart chk->rec.data.stream_number, 1102f8829a4aSRandall Stewart prev->rec.data.stream_number); 1103139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1104f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1105f8829a4aSRandall Stewart if (oper) { 1106f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1107f8829a4aSRandall Stewart uint32_t *ippp; 1108f8829a4aSRandall Stewart 1109139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1110f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1111f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1112f8829a4aSRandall Stewart ph = mtod(oper, 1113f8829a4aSRandall Stewart struct sctp_paramhdr *); 1114f8829a4aSRandall Stewart ph->param_type = 1115f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1116f8829a4aSRandall Stewart ph->param_length = 1117139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1118f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1119a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_7); 1120f8829a4aSRandall Stewart ippp++; 1121f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1122f8829a4aSRandall Stewart ippp++; 1123f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1124f8829a4aSRandall Stewart } 1125a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_7; 1126f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1127ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1128f8829a4aSRandall Stewart 1129f8829a4aSRandall Stewart *abort_flag = 1; 1130f8829a4aSRandall Stewart return; 1131f8829a4aSRandall Stewart } 1132f8829a4aSRandall Stewart if ((prev->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 && 1133f8829a4aSRandall Stewart chk->rec.data.stream_seq != 1134f8829a4aSRandall Stewart prev->rec.data.stream_seq) { 1135f8829a4aSRandall Stewart /* 1136f8829a4aSRandall Stewart * Huh, need the correct STR here, 1137f8829a4aSRandall Stewart * they must be the same. 1138f8829a4aSRandall Stewart */ 1139ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, Evil plot, sseq:%d not the same as at:%d\n", 1140f8829a4aSRandall Stewart chk->rec.data.stream_seq, 1141f8829a4aSRandall Stewart prev->rec.data.stream_seq); 1142139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1143f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1144f8829a4aSRandall Stewart if (oper) { 1145f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1146f8829a4aSRandall Stewart uint32_t *ippp; 1147f8829a4aSRandall Stewart 1148139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1149f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1150f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1151f8829a4aSRandall Stewart ph = mtod(oper, 1152f8829a4aSRandall Stewart struct sctp_paramhdr *); 1153f8829a4aSRandall Stewart ph->param_type = 1154f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1155f8829a4aSRandall Stewart ph->param_length = 1156139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1157f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1158a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_8); 1159f8829a4aSRandall Stewart ippp++; 1160f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1161f8829a4aSRandall Stewart ippp++; 1162f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1163f8829a4aSRandall Stewart } 1164a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_8; 1165f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1166ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1167f8829a4aSRandall Stewart 1168f8829a4aSRandall Stewart *abort_flag = 1; 1169f8829a4aSRandall Stewart return; 1170f8829a4aSRandall Stewart } 1171f8829a4aSRandall Stewart } else if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1172f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1173f8829a4aSRandall Stewart /* Insert chk MUST be a FIRST */ 1174f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1175f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1176ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, evil plot, its not FIRST and it must be!\n"); 1177139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1178f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1179f8829a4aSRandall Stewart if (oper) { 1180f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1181f8829a4aSRandall Stewart uint32_t *ippp; 1182f8829a4aSRandall Stewart 1183139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1184f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1185f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1186f8829a4aSRandall Stewart ph = mtod(oper, 1187f8829a4aSRandall Stewart struct sctp_paramhdr *); 1188f8829a4aSRandall Stewart ph->param_type = 1189f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1190f8829a4aSRandall Stewart ph->param_length = 1191139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1192f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1193a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_9); 1194f8829a4aSRandall Stewart ippp++; 1195f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1196f8829a4aSRandall Stewart ippp++; 1197f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1198f8829a4aSRandall Stewart 1199f8829a4aSRandall Stewart } 1200a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_9; 1201f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1202ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1203f8829a4aSRandall Stewart 1204f8829a4aSRandall Stewart *abort_flag = 1; 1205f8829a4aSRandall Stewart return; 1206f8829a4aSRandall Stewart } 1207f8829a4aSRandall Stewart } 1208f8829a4aSRandall Stewart } 1209f8829a4aSRandall Stewart } 1210f8829a4aSRandall Stewart if (next) { 1211f8829a4aSRandall Stewart post_tsn = chk->rec.data.TSN_seq + 1; 1212f8829a4aSRandall Stewart if (post_tsn == next->rec.data.TSN_seq) { 1213f8829a4aSRandall Stewart /* 1214f8829a4aSRandall Stewart * Ok the one I am inserting ahead of is my NEXT 1215f8829a4aSRandall Stewart * one. A bit of valdiation here. 1216f8829a4aSRandall Stewart */ 1217f8829a4aSRandall Stewart if (next->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 1218f8829a4aSRandall Stewart /* Insert chk MUST be a last fragment */ 1219f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) 1220f8829a4aSRandall Stewart != SCTP_DATA_LAST_FRAG) { 1221ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is FIRST, we must be LAST\n"); 1222ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not a last!\n"); 1223139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1224f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1225f8829a4aSRandall Stewart if (oper) { 1226f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1227f8829a4aSRandall Stewart uint32_t *ippp; 1228f8829a4aSRandall Stewart 1229139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1230f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1231f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1232f8829a4aSRandall Stewart ph = mtod(oper, 1233f8829a4aSRandall Stewart struct sctp_paramhdr *); 1234f8829a4aSRandall Stewart ph->param_type = 1235f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1236f8829a4aSRandall Stewart ph->param_length = 1237139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1238f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1239a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_10); 1240f8829a4aSRandall Stewart ippp++; 1241f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1242f8829a4aSRandall Stewart ippp++; 1243f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1244f8829a4aSRandall Stewart } 1245a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_10; 1246f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1247ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1248f8829a4aSRandall Stewart 1249f8829a4aSRandall Stewart *abort_flag = 1; 1250f8829a4aSRandall Stewart return; 1251f8829a4aSRandall Stewart } 1252f8829a4aSRandall Stewart } else if ((next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1253f8829a4aSRandall Stewart SCTP_DATA_MIDDLE_FRAG || 1254f8829a4aSRandall Stewart (next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1255f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1256f8829a4aSRandall Stewart /* 1257f8829a4aSRandall Stewart * Insert chk CAN be MIDDLE or FIRST NOT 1258f8829a4aSRandall Stewart * LAST 1259f8829a4aSRandall Stewart */ 1260f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1261f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1262ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is a MIDDLE/LAST\n"); 1263ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, new prev chunk is a LAST\n"); 1264139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1265f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1266f8829a4aSRandall Stewart if (oper) { 1267f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1268f8829a4aSRandall Stewart uint32_t *ippp; 1269f8829a4aSRandall Stewart 1270139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1271f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1272f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1273f8829a4aSRandall Stewart ph = mtod(oper, 1274f8829a4aSRandall Stewart struct sctp_paramhdr *); 1275f8829a4aSRandall Stewart ph->param_type = 1276f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1277f8829a4aSRandall Stewart ph->param_length = 1278139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1279f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1280a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_11); 1281f8829a4aSRandall Stewart ippp++; 1282f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1283f8829a4aSRandall Stewart ippp++; 1284f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1285f8829a4aSRandall Stewart 1286f8829a4aSRandall Stewart } 1287a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_11; 1288f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1289ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1290f8829a4aSRandall Stewart 1291f8829a4aSRandall Stewart *abort_flag = 1; 1292f8829a4aSRandall Stewart return; 1293f8829a4aSRandall Stewart } 1294f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 1295f8829a4aSRandall Stewart next->rec.data.stream_number) { 1296f8829a4aSRandall Stewart /* 1297f8829a4aSRandall Stewart * Huh, need the correct STR here, 1298f8829a4aSRandall Stewart * they must be the same. 1299f8829a4aSRandall Stewart */ 1300ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, ssn:%d not the same as at:%d\n", 1301f8829a4aSRandall Stewart chk->rec.data.stream_number, 1302f8829a4aSRandall Stewart next->rec.data.stream_number); 1303139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1304f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1305f8829a4aSRandall Stewart if (oper) { 1306f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1307f8829a4aSRandall Stewart uint32_t *ippp; 1308f8829a4aSRandall Stewart 1309139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1310f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1311f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1312f8829a4aSRandall Stewart ph = mtod(oper, 1313f8829a4aSRandall Stewart struct sctp_paramhdr *); 1314f8829a4aSRandall Stewart ph->param_type = 1315f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1316f8829a4aSRandall Stewart ph->param_length = 1317139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1318f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1319a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_12); 1320f8829a4aSRandall Stewart ippp++; 1321f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1322f8829a4aSRandall Stewart ippp++; 1323f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1324f8829a4aSRandall Stewart 1325f8829a4aSRandall Stewart } 1326a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_12; 1327f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1328ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1329f8829a4aSRandall Stewart 1330f8829a4aSRandall Stewart *abort_flag = 1; 1331f8829a4aSRandall Stewart return; 1332f8829a4aSRandall Stewart } 1333f8829a4aSRandall Stewart if ((next->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 && 1334f8829a4aSRandall Stewart chk->rec.data.stream_seq != 1335f8829a4aSRandall Stewart next->rec.data.stream_seq) { 1336f8829a4aSRandall Stewart /* 1337f8829a4aSRandall Stewart * Huh, need the correct STR here, 1338f8829a4aSRandall Stewart * they must be the same. 1339f8829a4aSRandall Stewart */ 1340ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, sseq:%d not the same as at:%d\n", 1341f8829a4aSRandall Stewart chk->rec.data.stream_seq, 1342f8829a4aSRandall Stewart next->rec.data.stream_seq); 1343139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1344f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1345f8829a4aSRandall Stewart if (oper) { 1346f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1347f8829a4aSRandall Stewart uint32_t *ippp; 1348f8829a4aSRandall Stewart 1349139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1350f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1351f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1352f8829a4aSRandall Stewart ph = mtod(oper, 1353f8829a4aSRandall Stewart struct sctp_paramhdr *); 1354f8829a4aSRandall Stewart ph->param_type = 1355f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1356f8829a4aSRandall Stewart ph->param_length = 1357139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1358f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1359a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_13); 1360f8829a4aSRandall Stewart ippp++; 1361f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1362f8829a4aSRandall Stewart ippp++; 1363f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1364f8829a4aSRandall Stewart } 1365a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_13; 1366f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1367ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1368f8829a4aSRandall Stewart 1369f8829a4aSRandall Stewart *abort_flag = 1; 1370f8829a4aSRandall Stewart return; 1371f8829a4aSRandall Stewart } 1372f8829a4aSRandall Stewart } 1373f8829a4aSRandall Stewart } 1374f8829a4aSRandall Stewart } 1375f8829a4aSRandall Stewart /* Do we need to do some delivery? check */ 1376f8829a4aSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 1377f8829a4aSRandall Stewart } 1378f8829a4aSRandall Stewart 1379f8829a4aSRandall Stewart /* 1380f8829a4aSRandall Stewart * This is an unfortunate routine. It checks to make sure a evil guy is not 1381f8829a4aSRandall Stewart * stuffing us full of bad packet fragments. A broken peer could also do this 1382f8829a4aSRandall Stewart * but this is doubtful. It is to bad I must worry about evil crackers sigh 1383f8829a4aSRandall Stewart * :< more cycles. 1384f8829a4aSRandall Stewart */ 1385f8829a4aSRandall Stewart static int 1386f8829a4aSRandall Stewart sctp_does_tsn_belong_to_reasm(struct sctp_association *asoc, 1387f8829a4aSRandall Stewart uint32_t TSN_seq) 1388f8829a4aSRandall Stewart { 1389f8829a4aSRandall Stewart struct sctp_tmit_chunk *at; 1390f8829a4aSRandall Stewart uint32_t tsn_est; 1391f8829a4aSRandall Stewart 1392f8829a4aSRandall Stewart TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) { 1393f8829a4aSRandall Stewart if (compare_with_wrap(TSN_seq, 1394f8829a4aSRandall Stewart at->rec.data.TSN_seq, MAX_TSN)) { 1395f8829a4aSRandall Stewart /* is it one bigger? */ 1396f8829a4aSRandall Stewart tsn_est = at->rec.data.TSN_seq + 1; 1397f8829a4aSRandall Stewart if (tsn_est == TSN_seq) { 1398f8829a4aSRandall Stewart /* yep. It better be a last then */ 1399f8829a4aSRandall Stewart if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1400f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1401f8829a4aSRandall Stewart /* 1402f8829a4aSRandall Stewart * Ok this guy belongs next to a guy 1403f8829a4aSRandall Stewart * that is NOT last, it should be a 1404f8829a4aSRandall Stewart * middle/last, not a complete 1405f8829a4aSRandall Stewart * chunk. 1406f8829a4aSRandall Stewart */ 1407f8829a4aSRandall Stewart return (1); 1408f8829a4aSRandall Stewart } else { 1409f8829a4aSRandall Stewart /* 1410f8829a4aSRandall Stewart * This guy is ok since its a LAST 1411f8829a4aSRandall Stewart * and the new chunk is a fully 1412f8829a4aSRandall Stewart * self- contained one. 1413f8829a4aSRandall Stewart */ 1414f8829a4aSRandall Stewart return (0); 1415f8829a4aSRandall Stewart } 1416f8829a4aSRandall Stewart } 1417f8829a4aSRandall Stewart } else if (TSN_seq == at->rec.data.TSN_seq) { 1418f8829a4aSRandall Stewart /* Software error since I have a dup? */ 1419f8829a4aSRandall Stewart return (1); 1420f8829a4aSRandall Stewart } else { 1421f8829a4aSRandall Stewart /* 1422f8829a4aSRandall Stewart * Ok, 'at' is larger than new chunk but does it 1423f8829a4aSRandall Stewart * need to be right before it. 1424f8829a4aSRandall Stewart */ 1425f8829a4aSRandall Stewart tsn_est = TSN_seq + 1; 1426f8829a4aSRandall Stewart if (tsn_est == at->rec.data.TSN_seq) { 1427f8829a4aSRandall Stewart /* Yep, It better be a first */ 1428f8829a4aSRandall Stewart if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1429f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1430f8829a4aSRandall Stewart return (1); 1431f8829a4aSRandall Stewart } else { 1432f8829a4aSRandall Stewart return (0); 1433f8829a4aSRandall Stewart } 1434f8829a4aSRandall Stewart } 1435f8829a4aSRandall Stewart } 1436f8829a4aSRandall Stewart } 1437f8829a4aSRandall Stewart return (0); 1438f8829a4aSRandall Stewart } 1439f8829a4aSRandall Stewart 1440f8829a4aSRandall Stewart 1441f8829a4aSRandall Stewart static int 1442f8829a4aSRandall Stewart sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, 1443f8829a4aSRandall Stewart struct mbuf **m, int offset, struct sctp_data_chunk *ch, int chk_length, 1444f8829a4aSRandall Stewart struct sctp_nets *net, uint32_t * high_tsn, int *abort_flag, 1445f8829a4aSRandall Stewart int *break_flag, int last_chunk) 1446f8829a4aSRandall Stewart { 1447f8829a4aSRandall Stewart /* Process a data chunk */ 1448f8829a4aSRandall Stewart /* struct sctp_tmit_chunk *chk; */ 1449f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 1450f8829a4aSRandall Stewart uint32_t tsn, gap; 1451f8829a4aSRandall Stewart struct mbuf *dmbuf; 1452f8829a4aSRandall Stewart int indx, the_len; 1453139bc87fSRandall Stewart int need_reasm_check = 0; 1454f8829a4aSRandall Stewart uint16_t strmno, strmseq; 1455f8829a4aSRandall Stewart struct mbuf *oper; 1456f8829a4aSRandall Stewart struct sctp_queued_to_read *control; 1457f42a358aSRandall Stewart int ordered; 1458f42a358aSRandall Stewart uint32_t protocol_id; 1459f42a358aSRandall Stewart uint8_t chunk_flags; 146017205eccSRandall Stewart struct sctp_stream_reset_list *liste; 1461f8829a4aSRandall Stewart 1462f8829a4aSRandall Stewart chk = NULL; 1463f8829a4aSRandall Stewart tsn = ntohl(ch->dp.tsn); 1464f42a358aSRandall Stewart chunk_flags = ch->ch.chunk_flags; 1465b3f1ea41SRandall Stewart if ((chunk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) { 1466b3f1ea41SRandall Stewart asoc->send_sack = 1; 1467b3f1ea41SRandall Stewart } 1468f42a358aSRandall Stewart protocol_id = ch->dp.protocol_id; 146937f144ebSMichael Tuexen ordered = ((chunk_flags & SCTP_DATA_UNORDERED) == 0); 1470b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 1471c4739e2fSRandall Stewart sctp_log_map(tsn, asoc->cumulative_tsn, asoc->highest_tsn_inside_map, SCTP_MAP_TSN_ENTERS); 147280fefe0aSRandall Stewart } 1473ad81507eSRandall Stewart if (stcb == NULL) { 1474ad81507eSRandall Stewart return (0); 1475ad81507eSRandall Stewart } 147680fefe0aSRandall Stewart SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, ch->ch.chunk_type, tsn); 1477f8829a4aSRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, tsn, MAX_TSN) || 1478f8829a4aSRandall Stewart asoc->cumulative_tsn == tsn) { 1479f8829a4aSRandall Stewart /* It is a duplicate */ 1480f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1481f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1482f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1483f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1484f8829a4aSRandall Stewart asoc->numduptsns++; 1485f8829a4aSRandall Stewart } 1486b201f536SRandall Stewart asoc->send_sack = 1; 1487f8829a4aSRandall Stewart return (0); 1488f8829a4aSRandall Stewart } 1489f8829a4aSRandall Stewart /* Calculate the number of TSN's between the base and this TSN */ 1490d50c1d79SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn); 1491f8829a4aSRandall Stewart if (gap >= (SCTP_MAPPING_ARRAY << 3)) { 1492f8829a4aSRandall Stewart /* Can't hold the bit in the mapping at max array, toss it */ 1493f8829a4aSRandall Stewart return (0); 1494f8829a4aSRandall Stewart } 1495f8829a4aSRandall Stewart if (gap >= (uint32_t) (asoc->mapping_array_size << 3)) { 1496207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 14970696e120SRandall Stewart if (sctp_expand_mapping_array(asoc, gap)) { 1498f8829a4aSRandall Stewart /* Can't expand, drop it */ 1499f8829a4aSRandall Stewart return (0); 1500f8829a4aSRandall Stewart } 1501f8829a4aSRandall Stewart } 1502f8829a4aSRandall Stewart if (compare_with_wrap(tsn, *high_tsn, MAX_TSN)) { 1503f8829a4aSRandall Stewart *high_tsn = tsn; 1504f8829a4aSRandall Stewart } 1505f8829a4aSRandall Stewart /* See if we have received this one already */ 150677acdc25SRandall Stewart if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap) || 150777acdc25SRandall Stewart SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, gap)) { 1508f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1509f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1510f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1511f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1512f8829a4aSRandall Stewart asoc->numduptsns++; 1513f8829a4aSRandall Stewart } 151442551e99SRandall Stewart asoc->send_sack = 1; 1515f8829a4aSRandall Stewart return (0); 1516f8829a4aSRandall Stewart } 1517f8829a4aSRandall Stewart /* 1518f8829a4aSRandall Stewart * Check to see about the GONE flag, duplicates would cause a sack 1519f8829a4aSRandall Stewart * to be sent up above 1520f8829a4aSRandall Stewart */ 1521ad81507eSRandall Stewart if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || 1522f8829a4aSRandall Stewart (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || 1523f8829a4aSRandall Stewart (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) 1524f8829a4aSRandall Stewart ) { 1525f8829a4aSRandall Stewart /* 1526f8829a4aSRandall Stewart * wait a minute, this guy is gone, there is no longer a 1527f8829a4aSRandall Stewart * receiver. Send peer an ABORT! 1528f8829a4aSRandall Stewart */ 1529f8829a4aSRandall Stewart struct mbuf *op_err; 1530f8829a4aSRandall Stewart 1531f8829a4aSRandall Stewart op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC); 1532ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 0, op_err, SCTP_SO_NOT_LOCKED); 1533f8829a4aSRandall Stewart *abort_flag = 1; 1534f8829a4aSRandall Stewart return (0); 1535f8829a4aSRandall Stewart } 1536f8829a4aSRandall Stewart /* 1537f8829a4aSRandall Stewart * Now before going further we see if there is room. If NOT then we 1538f8829a4aSRandall Stewart * MAY let one through only IF this TSN is the one we are waiting 1539f8829a4aSRandall Stewart * for on a partial delivery API. 1540f8829a4aSRandall Stewart */ 1541f8829a4aSRandall Stewart 1542f8829a4aSRandall Stewart /* now do the tests */ 1543f8829a4aSRandall Stewart if (((asoc->cnt_on_all_streams + 1544f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue + 1545b3f1ea41SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) || 1546f8829a4aSRandall Stewart (((int)asoc->my_rwnd) <= 0)) { 1547f8829a4aSRandall Stewart /* 1548f8829a4aSRandall Stewart * When we have NO room in the rwnd we check to make sure 1549f8829a4aSRandall Stewart * the reader is doing its job... 1550f8829a4aSRandall Stewart */ 1551f8829a4aSRandall Stewart if (stcb->sctp_socket->so_rcv.sb_cc) { 1552f8829a4aSRandall Stewart /* some to read, wake-up */ 1553ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 1554ceaad40aSRandall Stewart struct socket *so; 1555ceaad40aSRandall Stewart 1556ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 1557ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 1558ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 1559ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 1560ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 1561ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 1562ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 1563ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 1564ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 1565ceaad40aSRandall Stewart return (0); 1566ceaad40aSRandall Stewart } 1567ceaad40aSRandall Stewart #endif 1568f8829a4aSRandall Stewart sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket); 1569ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 1570ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 1571ceaad40aSRandall Stewart #endif 1572f8829a4aSRandall Stewart } 1573f8829a4aSRandall Stewart /* now is it in the mapping array of what we have accepted? */ 157477acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN) && 157577acdc25SRandall Stewart compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 1576f8829a4aSRandall Stewart /* Nope not in the valid range dump it */ 1577f8829a4aSRandall Stewart sctp_set_rwnd(stcb, asoc); 1578f8829a4aSRandall Stewart if ((asoc->cnt_on_all_streams + 1579f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue + 1580b3f1ea41SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) { 1581f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_datadropchklmt); 1582f8829a4aSRandall Stewart } else { 1583f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_datadroprwnd); 1584f8829a4aSRandall Stewart } 1585f8829a4aSRandall Stewart indx = *break_flag; 1586f8829a4aSRandall Stewart *break_flag = 1; 1587f8829a4aSRandall Stewart return (0); 1588f8829a4aSRandall Stewart } 1589f8829a4aSRandall Stewart } 1590f8829a4aSRandall Stewart strmno = ntohs(ch->dp.stream_id); 1591f8829a4aSRandall Stewart if (strmno >= asoc->streamincnt) { 1592f8829a4aSRandall Stewart struct sctp_paramhdr *phdr; 1593f8829a4aSRandall Stewart struct mbuf *mb; 1594f8829a4aSRandall Stewart 1595f8829a4aSRandall Stewart mb = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) * 2), 1596139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1597f8829a4aSRandall Stewart if (mb != NULL) { 1598f8829a4aSRandall Stewart /* add some space up front so prepend will work well */ 1599139bc87fSRandall Stewart SCTP_BUF_RESV_UF(mb, sizeof(struct sctp_chunkhdr)); 1600f8829a4aSRandall Stewart phdr = mtod(mb, struct sctp_paramhdr *); 1601f8829a4aSRandall Stewart /* 1602f8829a4aSRandall Stewart * Error causes are just param's and this one has 1603f8829a4aSRandall Stewart * two back to back phdr, one with the error type 1604f8829a4aSRandall Stewart * and size, the other with the streamid and a rsvd 1605f8829a4aSRandall Stewart */ 1606139bc87fSRandall Stewart SCTP_BUF_LEN(mb) = (sizeof(struct sctp_paramhdr) * 2); 1607f8829a4aSRandall Stewart phdr->param_type = htons(SCTP_CAUSE_INVALID_STREAM); 1608f8829a4aSRandall Stewart phdr->param_length = 1609f8829a4aSRandall Stewart htons(sizeof(struct sctp_paramhdr) * 2); 1610f8829a4aSRandall Stewart phdr++; 1611f8829a4aSRandall Stewart /* We insert the stream in the type field */ 1612f8829a4aSRandall Stewart phdr->param_type = ch->dp.stream_id; 1613f8829a4aSRandall Stewart /* And set the length to 0 for the rsvd field */ 1614f8829a4aSRandall Stewart phdr->param_length = 0; 1615f8829a4aSRandall Stewart sctp_queue_op_err(stcb, mb); 1616f8829a4aSRandall Stewart } 1617f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_badsid); 1618207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1619830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 162077acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 1621830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 1622d06c82f1SRandall Stewart } 1623d06c82f1SRandall Stewart if (tsn == (asoc->cumulative_tsn + 1)) { 1624d06c82f1SRandall Stewart /* Update cum-ack */ 1625d06c82f1SRandall Stewart asoc->cumulative_tsn = tsn; 1626d06c82f1SRandall Stewart } 1627f8829a4aSRandall Stewart return (0); 1628f8829a4aSRandall Stewart } 1629f8829a4aSRandall Stewart /* 1630f8829a4aSRandall Stewart * Before we continue lets validate that we are not being fooled by 1631f8829a4aSRandall Stewart * an evil attacker. We can only have 4k chunks based on our TSN 1632f8829a4aSRandall Stewart * spread allowed by the mapping array 512 * 8 bits, so there is no 1633f8829a4aSRandall Stewart * way our stream sequence numbers could have wrapped. We of course 1634f8829a4aSRandall Stewart * only validate the FIRST fragment so the bit must be set. 1635f8829a4aSRandall Stewart */ 1636f8829a4aSRandall Stewart strmseq = ntohs(ch->dp.stream_sequence); 1637f42a358aSRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 163818e198d3SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 163918e198d3SRandall Stewart if (asoc->tsn_in_at >= SCTP_TSN_LOG_SIZE) { 164018e198d3SRandall Stewart asoc->tsn_in_at = 0; 164118e198d3SRandall Stewart asoc->tsn_in_wrapped = 1; 164218e198d3SRandall Stewart } 1643f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].tsn = tsn; 1644f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].strm = strmno; 1645f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].seq = strmseq; 1646f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].sz = chk_length; 1647f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].flgs = chunk_flags; 164818e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].stcb = (void *)stcb; 164918e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_pos = asoc->tsn_in_at; 165018e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_out = 1; 1651f42a358aSRandall Stewart asoc->tsn_in_at++; 1652f42a358aSRandall Stewart #endif 1653f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_FIRST_FRAG) && 1654d61a0ae0SRandall Stewart (TAILQ_EMPTY(&asoc->resetHead)) && 1655f42a358aSRandall Stewart (chunk_flags & SCTP_DATA_UNORDERED) == 0 && 1656f8829a4aSRandall Stewart (compare_with_wrap(asoc->strmin[strmno].last_sequence_delivered, 1657f8829a4aSRandall Stewart strmseq, MAX_SEQ) || 1658f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered == strmseq)) { 1659f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 1660ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ:%d delivered:%d from peer, Abort!\n", 1661ad81507eSRandall Stewart strmseq, asoc->strmin[strmno].last_sequence_delivered); 1662139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1663f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1664f8829a4aSRandall Stewart if (oper) { 1665f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1666f8829a4aSRandall Stewart uint32_t *ippp; 1667f8829a4aSRandall Stewart 1668139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 1669f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1670f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 1671f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1672139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 1673f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1674a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_14); 1675f8829a4aSRandall Stewart ippp++; 1676f8829a4aSRandall Stewart *ippp = tsn; 1677f8829a4aSRandall Stewart ippp++; 1678f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 1679f8829a4aSRandall Stewart 1680f8829a4aSRandall Stewart } 1681a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_14; 1682f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1683ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1684f8829a4aSRandall Stewart *abort_flag = 1; 1685f8829a4aSRandall Stewart return (0); 1686f8829a4aSRandall Stewart } 1687f42a358aSRandall Stewart /************************************ 1688f42a358aSRandall Stewart * From here down we may find ch-> invalid 1689f42a358aSRandall Stewart * so its a good idea NOT to use it. 1690f42a358aSRandall Stewart *************************************/ 1691f42a358aSRandall Stewart 1692f8829a4aSRandall Stewart the_len = (chk_length - sizeof(struct sctp_data_chunk)); 1693f8829a4aSRandall Stewart if (last_chunk == 0) { 169444b7479bSRandall Stewart dmbuf = SCTP_M_COPYM(*m, 1695f8829a4aSRandall Stewart (offset + sizeof(struct sctp_data_chunk)), 1696f8829a4aSRandall Stewart the_len, M_DONTWAIT); 1697f8829a4aSRandall Stewart #ifdef SCTP_MBUF_LOGGING 1698b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { 1699f8829a4aSRandall Stewart struct mbuf *mat; 1700f8829a4aSRandall Stewart 1701f8829a4aSRandall Stewart mat = dmbuf; 1702f8829a4aSRandall Stewart while (mat) { 1703139bc87fSRandall Stewart if (SCTP_BUF_IS_EXTENDED(mat)) { 1704f8829a4aSRandall Stewart sctp_log_mb(mat, SCTP_MBUF_ICOPY); 1705f8829a4aSRandall Stewart } 1706139bc87fSRandall Stewart mat = SCTP_BUF_NEXT(mat); 1707f8829a4aSRandall Stewart } 1708f8829a4aSRandall Stewart } 1709f8829a4aSRandall Stewart #endif 1710f8829a4aSRandall Stewart } else { 1711f8829a4aSRandall Stewart /* We can steal the last chunk */ 1712139bc87fSRandall Stewart int l_len; 1713139bc87fSRandall Stewart 1714f8829a4aSRandall Stewart dmbuf = *m; 1715f8829a4aSRandall Stewart /* lop off the top part */ 1716f8829a4aSRandall Stewart m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk))); 1717139bc87fSRandall Stewart if (SCTP_BUF_NEXT(dmbuf) == NULL) { 1718139bc87fSRandall Stewart l_len = SCTP_BUF_LEN(dmbuf); 1719139bc87fSRandall Stewart } else { 1720139bc87fSRandall Stewart /* 1721139bc87fSRandall Stewart * need to count up the size hopefully does not hit 1722139bc87fSRandall Stewart * this to often :-0 1723139bc87fSRandall Stewart */ 1724139bc87fSRandall Stewart struct mbuf *lat; 1725139bc87fSRandall Stewart 1726139bc87fSRandall Stewart l_len = 0; 1727139bc87fSRandall Stewart lat = dmbuf; 1728139bc87fSRandall Stewart while (lat) { 1729139bc87fSRandall Stewart l_len += SCTP_BUF_LEN(lat); 1730139bc87fSRandall Stewart lat = SCTP_BUF_NEXT(lat); 1731139bc87fSRandall Stewart } 1732139bc87fSRandall Stewart } 1733139bc87fSRandall Stewart if (l_len > the_len) { 1734f8829a4aSRandall Stewart /* Trim the end round bytes off too */ 1735139bc87fSRandall Stewart m_adj(dmbuf, -(l_len - the_len)); 1736f8829a4aSRandall Stewart } 1737f8829a4aSRandall Stewart } 1738f8829a4aSRandall Stewart if (dmbuf == NULL) { 1739f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1740f8829a4aSRandall Stewart return (0); 1741f8829a4aSRandall Stewart } 1742f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG && 1743f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress == 0 && 1744f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->resetHead) && 1745f42a358aSRandall Stewart ((ordered == 0) || 1746f8829a4aSRandall Stewart ((asoc->strmin[strmno].last_sequence_delivered + 1) == strmseq && 1747f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->strmin[strmno].inqueue)))) { 1748f8829a4aSRandall Stewart /* Candidate for express delivery */ 1749f8829a4aSRandall Stewart /* 1750f8829a4aSRandall Stewart * Its not fragmented, No PD-API is up, Nothing in the 1751f8829a4aSRandall Stewart * delivery queue, Its un-ordered OR ordered and the next to 1752f8829a4aSRandall Stewart * deliver AND nothing else is stuck on the stream queue, 1753f8829a4aSRandall Stewart * And there is room for it in the socket buffer. Lets just 1754f8829a4aSRandall Stewart * stuff it up the buffer.... 1755f8829a4aSRandall Stewart */ 1756f8829a4aSRandall Stewart 1757f8829a4aSRandall Stewart /* It would be nice to avoid this copy if we could :< */ 1758f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, control); 1759f8829a4aSRandall Stewart sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, 1760f42a358aSRandall Stewart protocol_id, 1761f8829a4aSRandall Stewart stcb->asoc.context, 1762f8829a4aSRandall Stewart strmno, strmseq, 1763f42a358aSRandall Stewart chunk_flags, 1764f8829a4aSRandall Stewart dmbuf); 1765f8829a4aSRandall Stewart if (control == NULL) { 1766f8829a4aSRandall Stewart goto failed_express_del; 1767f8829a4aSRandall Stewart } 1768cfde3ff7SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 1769cfde3ff7SRandall Stewart control, &stcb->sctp_socket->so_rcv, 1770cfde3ff7SRandall Stewart 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 1771830d754dSRandall Stewart 1772f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { 1773f8829a4aSRandall Stewart /* for ordered, bump what we delivered */ 1774f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered++; 1775f8829a4aSRandall Stewart } 1776f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvexpress); 1777b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 17786a91f103SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, 1779f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_EXPRS_DEL); 178080fefe0aSRandall Stewart } 1781f8829a4aSRandall Stewart control = NULL; 1782b5c16493SMichael Tuexen 178377acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 178477acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 178577acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 178677acdc25SRandall Stewart } 1787f8829a4aSRandall Stewart goto finish_express_del; 1788f8829a4aSRandall Stewart } 1789f8829a4aSRandall Stewart failed_express_del: 1790f8829a4aSRandall Stewart /* If we reach here this is a new chunk */ 1791f8829a4aSRandall Stewart chk = NULL; 1792f8829a4aSRandall Stewart control = NULL; 1793f8829a4aSRandall Stewart /* Express for fragmented delivery? */ 1794f8829a4aSRandall Stewart if ((asoc->fragmented_delivery_inprogress) && 1795f8829a4aSRandall Stewart (stcb->asoc.control_pdapi) && 1796f8829a4aSRandall Stewart (asoc->str_of_pdapi == strmno) && 1797f8829a4aSRandall Stewart (asoc->ssn_of_pdapi == strmseq) 1798f8829a4aSRandall Stewart ) { 1799f8829a4aSRandall Stewart control = stcb->asoc.control_pdapi; 1800f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) { 1801f8829a4aSRandall Stewart /* Can't be another first? */ 1802f8829a4aSRandall Stewart goto failed_pdapi_express_del; 1803f8829a4aSRandall Stewart } 1804f8829a4aSRandall Stewart if (tsn == (control->sinfo_tsn + 1)) { 1805f8829a4aSRandall Stewart /* Yep, we can add it on */ 1806f8829a4aSRandall Stewart int end = 0; 1807f8829a4aSRandall Stewart uint32_t cumack; 1808f8829a4aSRandall Stewart 1809f42a358aSRandall Stewart if (chunk_flags & SCTP_DATA_LAST_FRAG) { 1810f8829a4aSRandall Stewart end = 1; 1811f8829a4aSRandall Stewart } 1812f8829a4aSRandall Stewart cumack = asoc->cumulative_tsn; 1813f8829a4aSRandall Stewart if ((cumack + 1) == tsn) 1814f8829a4aSRandall Stewart cumack = tsn; 1815f8829a4aSRandall Stewart 1816f8829a4aSRandall Stewart if (sctp_append_to_readq(stcb->sctp_ep, stcb, control, dmbuf, end, 1817f8829a4aSRandall Stewart tsn, 1818f8829a4aSRandall Stewart &stcb->sctp_socket->so_rcv)) { 1819ad81507eSRandall Stewart SCTP_PRINTF("Append fails end:%d\n", end); 1820f8829a4aSRandall Stewart goto failed_pdapi_express_del; 1821f8829a4aSRandall Stewart } 182277acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 182377acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 1824830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 1825830d754dSRandall Stewart } 1826f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvexpressm); 1827f8829a4aSRandall Stewart control->sinfo_tsn = tsn; 1828f8829a4aSRandall Stewart asoc->tsn_last_delivered = tsn; 1829f42a358aSRandall Stewart asoc->fragment_flags = chunk_flags; 1830f8829a4aSRandall Stewart asoc->tsn_of_pdapi_last_delivered = tsn; 1831f42a358aSRandall Stewart asoc->last_flags_delivered = chunk_flags; 1832f8829a4aSRandall Stewart asoc->last_strm_seq_delivered = strmseq; 1833f8829a4aSRandall Stewart asoc->last_strm_no_delivered = strmno; 1834f8829a4aSRandall Stewart if (end) { 1835f8829a4aSRandall Stewart /* clean up the flags and such */ 1836f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 1837f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { 1838f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered++; 1839a5d547adSRandall Stewart } 1840f8829a4aSRandall Stewart stcb->asoc.control_pdapi = NULL; 1841139bc87fSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue) == 0) { 1842139bc87fSRandall Stewart /* 1843139bc87fSRandall Stewart * There could be another message 1844139bc87fSRandall Stewart * ready 1845139bc87fSRandall Stewart */ 1846139bc87fSRandall Stewart need_reasm_check = 1; 1847139bc87fSRandall Stewart } 1848f8829a4aSRandall Stewart } 1849f8829a4aSRandall Stewart control = NULL; 1850f8829a4aSRandall Stewart goto finish_express_del; 1851f8829a4aSRandall Stewart } 1852f8829a4aSRandall Stewart } 1853f8829a4aSRandall Stewart failed_pdapi_express_del: 1854f8829a4aSRandall Stewart control = NULL; 185577acdc25SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) { 185677acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 185777acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 185877acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 185977acdc25SRandall Stewart } 186077acdc25SRandall Stewart } else { 186177acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap); 186277acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) { 186377acdc25SRandall Stewart asoc->highest_tsn_inside_map = tsn; 186477acdc25SRandall Stewart } 186577acdc25SRandall Stewart } 1866f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { 1867f8829a4aSRandall Stewart sctp_alloc_a_chunk(stcb, chk); 1868f8829a4aSRandall Stewart if (chk == NULL) { 1869f8829a4aSRandall Stewart /* No memory so we drop the chunk */ 1870f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1871f8829a4aSRandall Stewart if (last_chunk == 0) { 1872f8829a4aSRandall Stewart /* we copied it, free the copy */ 1873f8829a4aSRandall Stewart sctp_m_freem(dmbuf); 1874f8829a4aSRandall Stewart } 1875f8829a4aSRandall Stewart return (0); 1876f8829a4aSRandall Stewart } 1877f8829a4aSRandall Stewart chk->rec.data.TSN_seq = tsn; 1878f8829a4aSRandall Stewart chk->no_fr_allowed = 0; 1879f8829a4aSRandall Stewart chk->rec.data.stream_seq = strmseq; 1880f8829a4aSRandall Stewart chk->rec.data.stream_number = strmno; 1881f42a358aSRandall Stewart chk->rec.data.payloadtype = protocol_id; 1882f8829a4aSRandall Stewart chk->rec.data.context = stcb->asoc.context; 1883f8829a4aSRandall Stewart chk->rec.data.doing_fast_retransmit = 0; 1884f42a358aSRandall Stewart chk->rec.data.rcv_flags = chunk_flags; 1885f8829a4aSRandall Stewart chk->asoc = asoc; 1886f8829a4aSRandall Stewart chk->send_size = the_len; 1887f8829a4aSRandall Stewart chk->whoTo = net; 1888f8829a4aSRandall Stewart atomic_add_int(&net->ref_count, 1); 1889f8829a4aSRandall Stewart chk->data = dmbuf; 1890f8829a4aSRandall Stewart } else { 1891f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, control); 1892f8829a4aSRandall Stewart sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, 1893f42a358aSRandall Stewart protocol_id, 1894f8829a4aSRandall Stewart stcb->asoc.context, 1895f8829a4aSRandall Stewart strmno, strmseq, 1896f42a358aSRandall Stewart chunk_flags, 1897f8829a4aSRandall Stewart dmbuf); 1898f8829a4aSRandall Stewart if (control == NULL) { 1899f8829a4aSRandall Stewart /* No memory so we drop the chunk */ 1900f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1901f8829a4aSRandall Stewart if (last_chunk == 0) { 1902f8829a4aSRandall Stewart /* we copied it, free the copy */ 1903f8829a4aSRandall Stewart sctp_m_freem(dmbuf); 1904f8829a4aSRandall Stewart } 1905f8829a4aSRandall Stewart return (0); 1906f8829a4aSRandall Stewart } 1907f8829a4aSRandall Stewart control->length = the_len; 1908f8829a4aSRandall Stewart } 1909f8829a4aSRandall Stewart 1910f8829a4aSRandall Stewart /* Mark it as received */ 1911f8829a4aSRandall Stewart /* Now queue it where it belongs */ 1912f8829a4aSRandall Stewart if (control != NULL) { 1913f8829a4aSRandall Stewart /* First a sanity check */ 1914f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 1915f8829a4aSRandall Stewart /* 1916f8829a4aSRandall Stewart * Ok, we have a fragmented delivery in progress if 1917f8829a4aSRandall Stewart * this chunk is next to deliver OR belongs in our 1918f8829a4aSRandall Stewart * view to the reassembly, the peer is evil or 1919f8829a4aSRandall Stewart * broken. 1920f8829a4aSRandall Stewart */ 1921f8829a4aSRandall Stewart uint32_t estimate_tsn; 1922f8829a4aSRandall Stewart 1923f8829a4aSRandall Stewart estimate_tsn = asoc->tsn_last_delivered + 1; 1924f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue) && 1925f8829a4aSRandall Stewart (estimate_tsn == control->sinfo_tsn)) { 1926f8829a4aSRandall Stewart /* Evil/Broke peer */ 1927f8829a4aSRandall Stewart sctp_m_freem(control->data); 1928f8829a4aSRandall Stewart control->data = NULL; 19295bead436SRandall Stewart if (control->whoFrom) { 1930f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 19315bead436SRandall Stewart control->whoFrom = NULL; 19325bead436SRandall Stewart } 1933f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 1934139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1935f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1936f8829a4aSRandall Stewart if (oper) { 1937f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1938f8829a4aSRandall Stewart uint32_t *ippp; 1939f8829a4aSRandall Stewart 1940139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1941f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1942f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1943f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 1944f8829a4aSRandall Stewart ph->param_type = 1945f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1946139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 1947f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1948a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_15); 1949f8829a4aSRandall Stewart ippp++; 1950f8829a4aSRandall Stewart *ippp = tsn; 1951f8829a4aSRandall Stewart ippp++; 1952f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 1953f8829a4aSRandall Stewart } 1954a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_15; 1955f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1956ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1957f8829a4aSRandall Stewart 1958f8829a4aSRandall Stewart *abort_flag = 1; 1959f8829a4aSRandall Stewart return (0); 1960f8829a4aSRandall Stewart } else { 1961f8829a4aSRandall Stewart if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) { 1962f8829a4aSRandall Stewart sctp_m_freem(control->data); 1963f8829a4aSRandall Stewart control->data = NULL; 19645bead436SRandall Stewart if (control->whoFrom) { 1965f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 19665bead436SRandall Stewart control->whoFrom = NULL; 19675bead436SRandall Stewart } 1968f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 1969f8829a4aSRandall Stewart 1970139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1971f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1972f8829a4aSRandall Stewart if (oper) { 1973f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1974f8829a4aSRandall Stewart uint32_t *ippp; 1975f8829a4aSRandall Stewart 1976139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1977f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1978f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1979f8829a4aSRandall Stewart ph = mtod(oper, 1980f8829a4aSRandall Stewart struct sctp_paramhdr *); 1981f8829a4aSRandall Stewart ph->param_type = 1982f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1983f8829a4aSRandall Stewart ph->param_length = 1984139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1985f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1986a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_16); 1987f8829a4aSRandall Stewart ippp++; 1988f8829a4aSRandall Stewart *ippp = tsn; 1989f8829a4aSRandall Stewart ippp++; 1990f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 1991f8829a4aSRandall Stewart } 1992a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16; 1993f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1994ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1995f8829a4aSRandall Stewart 1996f8829a4aSRandall Stewart *abort_flag = 1; 1997f8829a4aSRandall Stewart return (0); 1998f8829a4aSRandall Stewart } 1999f8829a4aSRandall Stewart } 2000f8829a4aSRandall Stewart } else { 2001f8829a4aSRandall Stewart /* No PDAPI running */ 2002f8829a4aSRandall Stewart if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 2003f8829a4aSRandall Stewart /* 2004f8829a4aSRandall Stewart * Reassembly queue is NOT empty validate 2005f8829a4aSRandall Stewart * that this tsn does not need to be in 2006f8829a4aSRandall Stewart * reasembly queue. If it does then our peer 2007f8829a4aSRandall Stewart * is broken or evil. 2008f8829a4aSRandall Stewart */ 2009f8829a4aSRandall Stewart if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) { 2010f8829a4aSRandall Stewart sctp_m_freem(control->data); 2011f8829a4aSRandall Stewart control->data = NULL; 20125bead436SRandall Stewart if (control->whoFrom) { 2013f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 20145bead436SRandall Stewart control->whoFrom = NULL; 20155bead436SRandall Stewart } 2016f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 2017139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 2018f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 2019f8829a4aSRandall Stewart if (oper) { 2020f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 2021f8829a4aSRandall Stewart uint32_t *ippp; 2022f8829a4aSRandall Stewart 2023139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 2024f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 2025f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 2026f8829a4aSRandall Stewart ph = mtod(oper, 2027f8829a4aSRandall Stewart struct sctp_paramhdr *); 2028f8829a4aSRandall Stewart ph->param_type = 2029f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 2030f8829a4aSRandall Stewart ph->param_length = 2031139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 2032f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 2033a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_17); 2034f8829a4aSRandall Stewart ippp++; 2035f8829a4aSRandall Stewart *ippp = tsn; 2036f8829a4aSRandall Stewart ippp++; 2037f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 2038f8829a4aSRandall Stewart } 2039a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_17; 2040f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 2041ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 2042f8829a4aSRandall Stewart 2043f8829a4aSRandall Stewart *abort_flag = 1; 2044f8829a4aSRandall Stewart return (0); 2045f8829a4aSRandall Stewart } 2046f8829a4aSRandall Stewart } 2047f8829a4aSRandall Stewart } 2048f8829a4aSRandall Stewart /* ok, if we reach here we have passed the sanity checks */ 2049f42a358aSRandall Stewart if (chunk_flags & SCTP_DATA_UNORDERED) { 2050f8829a4aSRandall Stewart /* queue directly into socket buffer */ 2051b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 2052f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 2053f8829a4aSRandall Stewart control, 2054cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 2055f8829a4aSRandall Stewart } else { 2056f8829a4aSRandall Stewart /* 2057f8829a4aSRandall Stewart * Special check for when streams are resetting. We 2058f8829a4aSRandall Stewart * could be more smart about this and check the 2059f8829a4aSRandall Stewart * actual stream to see if it is not being reset.. 2060f8829a4aSRandall Stewart * that way we would not create a HOLB when amongst 2061f8829a4aSRandall Stewart * streams being reset and those not being reset. 2062f8829a4aSRandall Stewart * 2063f8829a4aSRandall Stewart * We take complete messages that have a stream reset 2064f8829a4aSRandall Stewart * intervening (aka the TSN is after where our 2065f8829a4aSRandall Stewart * cum-ack needs to be) off and put them on a 2066f8829a4aSRandall Stewart * pending_reply_queue. The reassembly ones we do 2067f8829a4aSRandall Stewart * not have to worry about since they are all sorted 2068f8829a4aSRandall Stewart * and proceessed by TSN order. It is only the 2069f8829a4aSRandall Stewart * singletons I must worry about. 2070f8829a4aSRandall Stewart */ 2071f8829a4aSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 2072d61a0ae0SRandall Stewart ((compare_with_wrap(tsn, liste->tsn, MAX_TSN))) 2073f8829a4aSRandall Stewart ) { 2074f8829a4aSRandall Stewart /* 2075f8829a4aSRandall Stewart * yep its past where we need to reset... go 2076f8829a4aSRandall Stewart * ahead and queue it. 2077f8829a4aSRandall Stewart */ 2078f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->pending_reply_queue)) { 2079f8829a4aSRandall Stewart /* first one on */ 2080f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2081f8829a4aSRandall Stewart } else { 2082f8829a4aSRandall Stewart struct sctp_queued_to_read *ctlOn; 2083f8829a4aSRandall Stewart unsigned char inserted = 0; 2084f8829a4aSRandall Stewart 2085f8829a4aSRandall Stewart ctlOn = TAILQ_FIRST(&asoc->pending_reply_queue); 2086f8829a4aSRandall Stewart while (ctlOn) { 2087f8829a4aSRandall Stewart if (compare_with_wrap(control->sinfo_tsn, 2088f8829a4aSRandall Stewart ctlOn->sinfo_tsn, MAX_TSN)) { 2089f8829a4aSRandall Stewart ctlOn = TAILQ_NEXT(ctlOn, next); 2090f8829a4aSRandall Stewart } else { 2091f8829a4aSRandall Stewart /* found it */ 2092f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(ctlOn, control, next); 2093f8829a4aSRandall Stewart inserted = 1; 2094f8829a4aSRandall Stewart break; 2095f8829a4aSRandall Stewart } 2096f8829a4aSRandall Stewart } 2097f8829a4aSRandall Stewart if (inserted == 0) { 2098f8829a4aSRandall Stewart /* 2099f8829a4aSRandall Stewart * must be put at end, use 2100f8829a4aSRandall Stewart * prevP (all setup from 2101f8829a4aSRandall Stewart * loop) to setup nextP. 2102f8829a4aSRandall Stewart */ 2103f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2104f8829a4aSRandall Stewart } 2105f8829a4aSRandall Stewart } 2106f8829a4aSRandall Stewart } else { 2107f8829a4aSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, control, abort_flag); 2108f8829a4aSRandall Stewart if (*abort_flag) { 2109f8829a4aSRandall Stewart return (0); 2110f8829a4aSRandall Stewart } 2111f8829a4aSRandall Stewart } 2112f8829a4aSRandall Stewart } 2113f8829a4aSRandall Stewart } else { 2114f8829a4aSRandall Stewart /* Into the re-assembly queue */ 2115f8829a4aSRandall Stewart sctp_queue_data_for_reasm(stcb, asoc, chk, abort_flag); 2116f8829a4aSRandall Stewart if (*abort_flag) { 2117a5d547adSRandall Stewart /* 2118a5d547adSRandall Stewart * the assoc is now gone and chk was put onto the 2119a5d547adSRandall Stewart * reasm queue, which has all been freed. 2120a5d547adSRandall Stewart */ 2121a5d547adSRandall Stewart *m = NULL; 2122f8829a4aSRandall Stewart return (0); 2123f8829a4aSRandall Stewart } 2124f8829a4aSRandall Stewart } 2125f8829a4aSRandall Stewart finish_express_del: 2126307b49efSMichael Tuexen if (tsn == (asoc->cumulative_tsn + 1)) { 2127307b49efSMichael Tuexen /* Update cum-ack */ 2128307b49efSMichael Tuexen asoc->cumulative_tsn = tsn; 2129307b49efSMichael Tuexen } 2130f8829a4aSRandall Stewart if (last_chunk) { 2131f8829a4aSRandall Stewart *m = NULL; 2132f8829a4aSRandall Stewart } 2133f42a358aSRandall Stewart if (ordered) { 2134f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inorderchunks); 2135f8829a4aSRandall Stewart } else { 2136f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inunorderchunks); 2137f8829a4aSRandall Stewart } 2138f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdata); 2139f8829a4aSRandall Stewart /* Set it present please */ 2140b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 21416a91f103SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, SCTP_STR_LOG_FROM_MARK_TSN); 214280fefe0aSRandall Stewart } 2143b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2144f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, 2145f8829a4aSRandall Stewart asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE); 214680fefe0aSRandall Stewart } 214717205eccSRandall Stewart /* check the special flag for stream resets */ 214817205eccSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 2149d61a0ae0SRandall Stewart ((compare_with_wrap(asoc->cumulative_tsn, liste->tsn, MAX_TSN)) || 2150d61a0ae0SRandall Stewart (asoc->cumulative_tsn == liste->tsn)) 215117205eccSRandall Stewart ) { 215217205eccSRandall Stewart /* 215317205eccSRandall Stewart * we have finished working through the backlogged TSN's now 215417205eccSRandall Stewart * time to reset streams. 1: call reset function. 2: free 215517205eccSRandall Stewart * pending_reply space 3: distribute any chunks in 215617205eccSRandall Stewart * pending_reply_queue. 215717205eccSRandall Stewart */ 215817205eccSRandall Stewart struct sctp_queued_to_read *ctl; 215917205eccSRandall Stewart 216017205eccSRandall Stewart sctp_reset_in_stream(stcb, liste->number_entries, liste->req.list_of_streams); 216117205eccSRandall Stewart TAILQ_REMOVE(&asoc->resetHead, liste, next_resp); 2162207304d4SRandall Stewart SCTP_FREE(liste, SCTP_M_STRESET); 21633c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 216417205eccSRandall Stewart liste = TAILQ_FIRST(&asoc->resetHead); 216517205eccSRandall Stewart ctl = TAILQ_FIRST(&asoc->pending_reply_queue); 216617205eccSRandall Stewart if (ctl && (liste == NULL)) { 216717205eccSRandall Stewart /* All can be removed */ 216817205eccSRandall Stewart while (ctl) { 216917205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 217017205eccSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag); 217117205eccSRandall Stewart if (*abort_flag) { 217217205eccSRandall Stewart return (0); 217317205eccSRandall Stewart } 217417205eccSRandall Stewart ctl = TAILQ_FIRST(&asoc->pending_reply_queue); 217517205eccSRandall Stewart } 217617205eccSRandall Stewart } else if (ctl) { 217717205eccSRandall Stewart /* more than one in queue */ 2178d61a0ae0SRandall Stewart while (!compare_with_wrap(ctl->sinfo_tsn, liste->tsn, MAX_TSN)) { 217917205eccSRandall Stewart /* 218017205eccSRandall Stewart * if ctl->sinfo_tsn is <= liste->tsn we can 218117205eccSRandall Stewart * process it which is the NOT of 218217205eccSRandall Stewart * ctl->sinfo_tsn > liste->tsn 218317205eccSRandall Stewart */ 218417205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 218517205eccSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag); 218617205eccSRandall Stewart if (*abort_flag) { 218717205eccSRandall Stewart return (0); 218817205eccSRandall Stewart } 218917205eccSRandall Stewart ctl = TAILQ_FIRST(&asoc->pending_reply_queue); 219017205eccSRandall Stewart } 219117205eccSRandall Stewart } 219217205eccSRandall Stewart /* 219317205eccSRandall Stewart * Now service re-assembly to pick up anything that has been 219417205eccSRandall Stewart * held on reassembly queue? 219517205eccSRandall Stewart */ 219617205eccSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 219717205eccSRandall Stewart need_reasm_check = 0; 219817205eccSRandall Stewart } 2199139bc87fSRandall Stewart if (need_reasm_check) { 2200139bc87fSRandall Stewart /* Another one waits ? */ 2201139bc87fSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 2202139bc87fSRandall Stewart } 2203f8829a4aSRandall Stewart return (1); 2204f8829a4aSRandall Stewart } 2205f8829a4aSRandall Stewart 2206f8829a4aSRandall Stewart int8_t sctp_map_lookup_tab[256] = { 2207b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2208b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2209b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2210b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2211b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2212b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2213b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2214b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 6, 2215b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2216b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2217b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2218b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2219b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2220b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2221b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2222b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 7, 2223b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2224b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2225b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2226b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2227b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2228b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2229b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2230b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 6, 2231b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2232b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2233b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2234b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2235b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2236b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2237b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2238b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 8 2239f8829a4aSRandall Stewart }; 2240f8829a4aSRandall Stewart 2241f8829a4aSRandall Stewart 2242f8829a4aSRandall Stewart void 2243b5c16493SMichael Tuexen sctp_slide_mapping_arrays(struct sctp_tcb *stcb) 2244f8829a4aSRandall Stewart { 2245f8829a4aSRandall Stewart /* 2246f8829a4aSRandall Stewart * Now we also need to check the mapping array in a couple of ways. 2247f8829a4aSRandall Stewart * 1) Did we move the cum-ack point? 2248f8829a4aSRandall Stewart */ 2249f8829a4aSRandall Stewart struct sctp_association *asoc; 2250b3f1ea41SRandall Stewart int at; 2251f8829a4aSRandall Stewart int slide_from, slide_end, lgap, distance; 2252830d754dSRandall Stewart 2253830d754dSRandall Stewart /* EY nr_mapping array variables */ 22548933fa13SRandall Stewart /* int nr_at; */ 22558933fa13SRandall Stewart /* int nr_last_all_ones = 0; */ 22568933fa13SRandall Stewart /* int nr_slide_from, nr_slide_end, nr_lgap, nr_distance; */ 225777acdc25SRandall Stewart uint32_t old_cumack, old_base, old_highest, highest_tsn; 2258f8829a4aSRandall Stewart 2259f8829a4aSRandall Stewart asoc = &stcb->asoc; 2260f8829a4aSRandall Stewart at = 0; 2261f8829a4aSRandall Stewart 2262f8829a4aSRandall Stewart old_cumack = asoc->cumulative_tsn; 2263f8829a4aSRandall Stewart old_base = asoc->mapping_array_base_tsn; 2264f8829a4aSRandall Stewart old_highest = asoc->highest_tsn_inside_map; 2265f8829a4aSRandall Stewart /* 2266f8829a4aSRandall Stewart * We could probably improve this a small bit by calculating the 2267f8829a4aSRandall Stewart * offset of the current cum-ack as the starting point. 2268f8829a4aSRandall Stewart */ 2269f8829a4aSRandall Stewart at = 0; 2270b5c16493SMichael Tuexen for (slide_from = 0; slide_from < stcb->asoc.mapping_array_size; slide_from++) { 227177acdc25SRandall Stewart if (asoc->nr_mapping_array[slide_from] == 0xff) { 2272f8829a4aSRandall Stewart at += 8; 2273f8829a4aSRandall Stewart } else { 2274f8829a4aSRandall Stewart /* there is a 0 bit */ 227577acdc25SRandall Stewart at += sctp_map_lookup_tab[asoc->nr_mapping_array[slide_from]]; 2276f8829a4aSRandall Stewart break; 2277f8829a4aSRandall Stewart } 2278f8829a4aSRandall Stewart } 2279b5c16493SMichael Tuexen asoc->cumulative_tsn = asoc->mapping_array_base_tsn + (at - 1); 2280f8829a4aSRandall Stewart 228177acdc25SRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, asoc->highest_tsn_inside_map, MAX_TSN) && 2282aed5947cSMichael Tuexen compare_with_wrap(asoc->cumulative_tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 2283a5d547adSRandall Stewart #ifdef INVARIANTS 2284ceaad40aSRandall Stewart panic("huh, cumack 0x%x greater than high-tsn 0x%x in map", 2285ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 2286f8829a4aSRandall Stewart #else 2287ceaad40aSRandall Stewart SCTP_PRINTF("huh, cumack 0x%x greater than high-tsn 0x%x in map - should panic?\n", 2288ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 22890e13104dSRandall Stewart sctp_print_mapping_array(asoc); 2290b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2291b3f1ea41SRandall Stewart sctp_log_map(0, 6, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 2292b3f1ea41SRandall Stewart } 2293f8829a4aSRandall Stewart asoc->highest_tsn_inside_map = asoc->cumulative_tsn; 2294830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn; 2295f8829a4aSRandall Stewart #endif 2296f8829a4aSRandall Stewart } 229777acdc25SRandall Stewart if (compare_with_wrap(asoc->highest_tsn_inside_nr_map, 229877acdc25SRandall Stewart asoc->highest_tsn_inside_map, 229977acdc25SRandall Stewart MAX_TSN)) { 230077acdc25SRandall Stewart highest_tsn = asoc->highest_tsn_inside_nr_map; 230177acdc25SRandall Stewart } else { 230277acdc25SRandall Stewart highest_tsn = asoc->highest_tsn_inside_map; 230377acdc25SRandall Stewart } 230477acdc25SRandall Stewart if ((asoc->cumulative_tsn == highest_tsn) && (at >= 8)) { 2305f8829a4aSRandall Stewart /* The complete array was completed by a single FR */ 230677acdc25SRandall Stewart /* highest becomes the cum-ack */ 230737f144ebSMichael Tuexen int clr; 230837f144ebSMichael Tuexen 230937f144ebSMichael Tuexen #ifdef INVARIANTS 231037f144ebSMichael Tuexen unsigned int i; 231137f144ebSMichael Tuexen 231237f144ebSMichael Tuexen #endif 2313f8829a4aSRandall Stewart 2314f8829a4aSRandall Stewart /* clear the array */ 2315b5c16493SMichael Tuexen clr = ((at + 7) >> 3); 2316c4739e2fSRandall Stewart if (clr > asoc->mapping_array_size) { 2317f8829a4aSRandall Stewart clr = asoc->mapping_array_size; 2318f8829a4aSRandall Stewart } 2319f8829a4aSRandall Stewart memset(asoc->mapping_array, 0, clr); 2320830d754dSRandall Stewart memset(asoc->nr_mapping_array, 0, clr); 232137f144ebSMichael Tuexen #ifdef INVARIANTS 2322b5c16493SMichael Tuexen for (i = 0; i < asoc->mapping_array_size; i++) { 2323b5c16493SMichael Tuexen if ((asoc->mapping_array[i]) || (asoc->nr_mapping_array[i])) { 2324b5c16493SMichael Tuexen printf("Error Mapping array's not clean at clear\n"); 2325b5c16493SMichael Tuexen sctp_print_mapping_array(asoc); 2326b5c16493SMichael Tuexen } 2327b5c16493SMichael Tuexen } 232837f144ebSMichael Tuexen #endif 232977acdc25SRandall Stewart asoc->mapping_array_base_tsn = asoc->cumulative_tsn + 1; 233077acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->highest_tsn_inside_map = asoc->cumulative_tsn; 2331f8829a4aSRandall Stewart } else if (at >= 8) { 2332f8829a4aSRandall Stewart /* we can slide the mapping array down */ 2333b3f1ea41SRandall Stewart /* slide_from holds where we hit the first NON 0xff byte */ 2334b3f1ea41SRandall Stewart 2335f8829a4aSRandall Stewart /* 2336f8829a4aSRandall Stewart * now calculate the ceiling of the move using our highest 2337f8829a4aSRandall Stewart * TSN value 2338f8829a4aSRandall Stewart */ 233977acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(lgap, highest_tsn, asoc->mapping_array_base_tsn); 234077acdc25SRandall Stewart slide_end = (lgap >> 3); 2341f8829a4aSRandall Stewart if (slide_end < slide_from) { 234277acdc25SRandall Stewart sctp_print_mapping_array(asoc); 2343d55b0b1bSRandall Stewart #ifdef INVARIANTS 2344f8829a4aSRandall Stewart panic("impossible slide"); 2345d55b0b1bSRandall Stewart #else 234677acdc25SRandall Stewart printf("impossible slide lgap:%x slide_end:%x slide_from:%x? at:%d\n", 234777acdc25SRandall Stewart lgap, slide_end, slide_from, at); 2348d55b0b1bSRandall Stewart return; 2349d55b0b1bSRandall Stewart #endif 2350f8829a4aSRandall Stewart } 2351b3f1ea41SRandall Stewart if (slide_end > asoc->mapping_array_size) { 2352b3f1ea41SRandall Stewart #ifdef INVARIANTS 2353b3f1ea41SRandall Stewart panic("would overrun buffer"); 2354b3f1ea41SRandall Stewart #else 2355b3f1ea41SRandall Stewart printf("Gak, would have overrun map end:%d slide_end:%d\n", 2356b3f1ea41SRandall Stewart asoc->mapping_array_size, slide_end); 2357b3f1ea41SRandall Stewart slide_end = asoc->mapping_array_size; 2358b3f1ea41SRandall Stewart #endif 2359b3f1ea41SRandall Stewart } 2360f8829a4aSRandall Stewart distance = (slide_end - slide_from) + 1; 2361b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2362f8829a4aSRandall Stewart sctp_log_map(old_base, old_cumack, old_highest, 2363f8829a4aSRandall Stewart SCTP_MAP_PREPARE_SLIDE); 2364f8829a4aSRandall Stewart sctp_log_map((uint32_t) slide_from, (uint32_t) slide_end, 2365f8829a4aSRandall Stewart (uint32_t) lgap, SCTP_MAP_SLIDE_FROM); 236680fefe0aSRandall Stewart } 2367f8829a4aSRandall Stewart if (distance + slide_from > asoc->mapping_array_size || 2368f8829a4aSRandall Stewart distance < 0) { 2369f8829a4aSRandall Stewart /* 2370f8829a4aSRandall Stewart * Here we do NOT slide forward the array so that 2371f8829a4aSRandall Stewart * hopefully when more data comes in to fill it up 2372f8829a4aSRandall Stewart * we will be able to slide it forward. Really I 2373f8829a4aSRandall Stewart * don't think this should happen :-0 2374f8829a4aSRandall Stewart */ 2375f8829a4aSRandall Stewart 2376b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2377f8829a4aSRandall Stewart sctp_log_map((uint32_t) distance, (uint32_t) slide_from, 2378f8829a4aSRandall Stewart (uint32_t) asoc->mapping_array_size, 2379f8829a4aSRandall Stewart SCTP_MAP_SLIDE_NONE); 238080fefe0aSRandall Stewart } 2381f8829a4aSRandall Stewart } else { 2382f8829a4aSRandall Stewart int ii; 2383f8829a4aSRandall Stewart 2384f8829a4aSRandall Stewart for (ii = 0; ii < distance; ii++) { 238537f144ebSMichael Tuexen asoc->mapping_array[ii] = asoc->mapping_array[slide_from + ii]; 238637f144ebSMichael Tuexen asoc->nr_mapping_array[ii] = asoc->nr_mapping_array[slide_from + ii]; 238777acdc25SRandall Stewart 2388f8829a4aSRandall Stewart } 2389aed5947cSMichael Tuexen for (ii = distance; ii < asoc->mapping_array_size; ii++) { 2390f8829a4aSRandall Stewart asoc->mapping_array[ii] = 0; 239177acdc25SRandall Stewart asoc->nr_mapping_array[ii] = 0; 2392f8829a4aSRandall Stewart } 2393ee94f0a2SMichael Tuexen if (asoc->highest_tsn_inside_map + 1 == asoc->mapping_array_base_tsn) { 2394ee94f0a2SMichael Tuexen asoc->highest_tsn_inside_map += (slide_from << 3); 2395ee94f0a2SMichael Tuexen } 2396ee94f0a2SMichael Tuexen if (asoc->highest_tsn_inside_nr_map + 1 == asoc->mapping_array_base_tsn) { 2397ee94f0a2SMichael Tuexen asoc->highest_tsn_inside_nr_map += (slide_from << 3); 2398ee94f0a2SMichael Tuexen } 2399f8829a4aSRandall Stewart asoc->mapping_array_base_tsn += (slide_from << 3); 2400b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2401f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, 2402f8829a4aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map, 2403f8829a4aSRandall Stewart SCTP_MAP_SLIDE_RESULT); 240480fefe0aSRandall Stewart } 2405830d754dSRandall Stewart } 2406830d754dSRandall Stewart } 2407b5c16493SMichael Tuexen } 2408b5c16493SMichael Tuexen 2409b5c16493SMichael Tuexen 2410b5c16493SMichael Tuexen void 2411b5c16493SMichael Tuexen sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap, int *abort_flag) 2412b5c16493SMichael Tuexen { 2413b5c16493SMichael Tuexen struct sctp_association *asoc; 2414b5c16493SMichael Tuexen uint32_t highest_tsn; 2415b5c16493SMichael Tuexen 2416b5c16493SMichael Tuexen asoc = &stcb->asoc; 2417b5c16493SMichael Tuexen if (compare_with_wrap(asoc->highest_tsn_inside_nr_map, 2418b5c16493SMichael Tuexen asoc->highest_tsn_inside_map, 2419b5c16493SMichael Tuexen MAX_TSN)) { 2420b5c16493SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_nr_map; 2421b5c16493SMichael Tuexen } else { 2422b5c16493SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_map; 2423b5c16493SMichael Tuexen } 2424b5c16493SMichael Tuexen 2425830d754dSRandall Stewart /* 2426f8829a4aSRandall Stewart * Now we need to see if we need to queue a sack or just start the 2427f8829a4aSRandall Stewart * timer (if allowed). 2428f8829a4aSRandall Stewart */ 2429f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 2430f8829a4aSRandall Stewart /* 2431b5c16493SMichael Tuexen * Ok special case, in SHUTDOWN-SENT case. here we maker 2432b5c16493SMichael Tuexen * sure SACK timer is off and instead send a SHUTDOWN and a 2433b5c16493SMichael Tuexen * SACK 2434f8829a4aSRandall Stewart */ 2435139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2436f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_RECV, 2437a5d547adSRandall Stewart stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_INDATA + SCTP_LOC_18); 2438f8829a4aSRandall Stewart } 2439f8829a4aSRandall Stewart sctp_send_shutdown(stcb, stcb->asoc.primary_destination); 2440f8829a4aSRandall Stewart sctp_send_sack(stcb); 2441f8829a4aSRandall Stewart } else { 2442f8829a4aSRandall Stewart int is_a_gap; 2443f8829a4aSRandall Stewart 2444f8829a4aSRandall Stewart /* is there a gap now ? */ 244577acdc25SRandall Stewart is_a_gap = compare_with_wrap(highest_tsn, stcb->asoc.cumulative_tsn, MAX_TSN); 2446f8829a4aSRandall Stewart 2447f8829a4aSRandall Stewart /* 2448b5c16493SMichael Tuexen * CMT DAC algorithm: increase number of packets received 2449b5c16493SMichael Tuexen * since last ack 2450f8829a4aSRandall Stewart */ 2451f8829a4aSRandall Stewart stcb->asoc.cmt_dac_pkts_rcvd++; 2452f8829a4aSRandall Stewart 245342551e99SRandall Stewart if ((stcb->asoc.send_sack == 1) || /* We need to send a 245442551e99SRandall Stewart * SACK */ 2455f8829a4aSRandall Stewart ((was_a_gap) && (is_a_gap == 0)) || /* was a gap, but no 2456f8829a4aSRandall Stewart * longer is one */ 2457f8829a4aSRandall Stewart (stcb->asoc.numduptsns) || /* we have dup's */ 2458f8829a4aSRandall Stewart (is_a_gap) || /* is still a gap */ 245942551e99SRandall Stewart (stcb->asoc.delayed_ack == 0) || /* Delayed sack disabled */ 246042551e99SRandall Stewart (stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) /* hit limit of pkts */ 2461f8829a4aSRandall Stewart ) { 2462f8829a4aSRandall Stewart 2463b3f1ea41SRandall Stewart if ((SCTP_BASE_SYSCTL(sctp_cmt_on_off)) && 2464b3f1ea41SRandall Stewart (SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) && 246542551e99SRandall Stewart (stcb->asoc.send_sack == 0) && 2466f8829a4aSRandall Stewart (stcb->asoc.numduptsns == 0) && 2467f8829a4aSRandall Stewart (stcb->asoc.delayed_ack) && 2468139bc87fSRandall Stewart (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer))) { 2469f8829a4aSRandall Stewart 2470f8829a4aSRandall Stewart /* 2471b5c16493SMichael Tuexen * CMT DAC algorithm: With CMT, delay acks 2472b5c16493SMichael Tuexen * even in the face of 2473f8829a4aSRandall Stewart * 2474b5c16493SMichael Tuexen * reordering. Therefore, if acks that do not 2475b5c16493SMichael Tuexen * have to be sent because of the above 2476b5c16493SMichael Tuexen * reasons, will be delayed. That is, acks 2477b5c16493SMichael Tuexen * that would have been sent due to gap 2478b5c16493SMichael Tuexen * reports will be delayed with DAC. Start 2479f8829a4aSRandall Stewart * the delayed ack timer. 2480f8829a4aSRandall Stewart */ 2481f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2482f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2483f8829a4aSRandall Stewart } else { 2484f8829a4aSRandall Stewart /* 2485b5c16493SMichael Tuexen * Ok we must build a SACK since the timer 2486b5c16493SMichael Tuexen * is pending, we got our first packet OR 2487b5c16493SMichael Tuexen * there are gaps or duplicates. 2488f8829a4aSRandall Stewart */ 2489ad81507eSRandall Stewart (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer); 2490f8829a4aSRandall Stewart sctp_send_sack(stcb); 2491f8829a4aSRandall Stewart } 2492f8829a4aSRandall Stewart } else { 249342551e99SRandall Stewart if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2494f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2495f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2496f8829a4aSRandall Stewart } 2497f8829a4aSRandall Stewart } 2498f8829a4aSRandall Stewart } 2499f8829a4aSRandall Stewart } 2500f8829a4aSRandall Stewart 2501f8829a4aSRandall Stewart void 2502f8829a4aSRandall Stewart sctp_service_queues(struct sctp_tcb *stcb, struct sctp_association *asoc) 2503f8829a4aSRandall Stewart { 2504f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 2505810ec536SMichael Tuexen uint32_t tsize, pd_point; 2506f8829a4aSRandall Stewart uint16_t nxt_todel; 2507f8829a4aSRandall Stewart 2508f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 2509f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 2510f8829a4aSRandall Stewart } 2511f8829a4aSRandall Stewart /* Can we proceed further, i.e. the PD-API is complete */ 2512f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 2513f8829a4aSRandall Stewart /* no */ 2514f8829a4aSRandall Stewart return; 2515f8829a4aSRandall Stewart } 2516f8829a4aSRandall Stewart /* 2517f8829a4aSRandall Stewart * Now is there some other chunk I can deliver from the reassembly 2518f8829a4aSRandall Stewart * queue. 2519f8829a4aSRandall Stewart */ 2520139bc87fSRandall Stewart doit_again: 2521f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 2522f8829a4aSRandall Stewart if (chk == NULL) { 2523f8829a4aSRandall Stewart asoc->size_on_reasm_queue = 0; 2524f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue = 0; 2525f8829a4aSRandall Stewart return; 2526f8829a4aSRandall Stewart } 2527f8829a4aSRandall Stewart nxt_todel = asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1; 2528f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) && 2529f8829a4aSRandall Stewart ((nxt_todel == chk->rec.data.stream_seq) || 2530f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) { 2531f8829a4aSRandall Stewart /* 2532f8829a4aSRandall Stewart * Yep the first one is here. We setup to start reception, 2533f8829a4aSRandall Stewart * by backing down the TSN just in case we can't deliver. 2534f8829a4aSRandall Stewart */ 2535f8829a4aSRandall Stewart 2536f8829a4aSRandall Stewart /* 2537f8829a4aSRandall Stewart * Before we start though either all of the message should 253824ae5c4aSMichael Tuexen * be here or the socket buffer max or nothing on the 2539f8829a4aSRandall Stewart * delivery queue and something can be delivered. 2540f8829a4aSRandall Stewart */ 2541810ec536SMichael Tuexen if (stcb->sctp_socket) { 254224ae5c4aSMichael Tuexen pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), 2543810ec536SMichael Tuexen stcb->sctp_ep->partial_delivery_point); 2544810ec536SMichael Tuexen } else { 2545810ec536SMichael Tuexen pd_point = stcb->sctp_ep->partial_delivery_point; 2546810ec536SMichael Tuexen } 2547810ec536SMichael Tuexen if (sctp_is_all_msg_on_reasm(asoc, &tsize) || (tsize >= pd_point)) { 2548f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 2549f8829a4aSRandall Stewart asoc->tsn_last_delivered = chk->rec.data.TSN_seq - 1; 2550f8829a4aSRandall Stewart asoc->str_of_pdapi = chk->rec.data.stream_number; 2551f8829a4aSRandall Stewart asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 2552f8829a4aSRandall Stewart asoc->pdapi_ppid = chk->rec.data.payloadtype; 2553f8829a4aSRandall Stewart asoc->fragment_flags = chk->rec.data.rcv_flags; 2554f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 2555139bc87fSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 2556139bc87fSRandall Stewart goto doit_again; 2557139bc87fSRandall Stewart } 2558f8829a4aSRandall Stewart } 2559f8829a4aSRandall Stewart } 2560f8829a4aSRandall Stewart } 2561f8829a4aSRandall Stewart 2562f8829a4aSRandall Stewart int 2563f8829a4aSRandall Stewart sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, 2564f8829a4aSRandall Stewart struct sctphdr *sh, struct sctp_inpcb *inp, struct sctp_tcb *stcb, 2565f8829a4aSRandall Stewart struct sctp_nets *net, uint32_t * high_tsn) 2566f8829a4aSRandall Stewart { 2567f8829a4aSRandall Stewart struct sctp_data_chunk *ch, chunk_buf; 2568f8829a4aSRandall Stewart struct sctp_association *asoc; 2569f8829a4aSRandall Stewart int num_chunks = 0; /* number of control chunks processed */ 2570f8829a4aSRandall Stewart int stop_proc = 0; 2571f8829a4aSRandall Stewart int chk_length, break_flag, last_chunk; 2572f8829a4aSRandall Stewart int abort_flag = 0, was_a_gap = 0; 2573f8829a4aSRandall Stewart struct mbuf *m; 2574f8829a4aSRandall Stewart 2575f8829a4aSRandall Stewart /* set the rwnd */ 2576f8829a4aSRandall Stewart sctp_set_rwnd(stcb, &stcb->asoc); 2577f8829a4aSRandall Stewart 2578f8829a4aSRandall Stewart m = *mm; 2579f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 2580f8829a4aSRandall Stewart asoc = &stcb->asoc; 2581f8829a4aSRandall Stewart if (compare_with_wrap(stcb->asoc.highest_tsn_inside_map, 2582f8829a4aSRandall Stewart stcb->asoc.cumulative_tsn, MAX_TSN)) { 2583f8829a4aSRandall Stewart /* there was a gap before this data was processed */ 2584f8829a4aSRandall Stewart was_a_gap = 1; 2585f8829a4aSRandall Stewart } 2586f8829a4aSRandall Stewart /* 2587f8829a4aSRandall Stewart * setup where we got the last DATA packet from for any SACK that 2588f8829a4aSRandall Stewart * may need to go out. Don't bump the net. This is done ONLY when a 2589f8829a4aSRandall Stewart * chunk is assigned. 2590f8829a4aSRandall Stewart */ 2591f8829a4aSRandall Stewart asoc->last_data_chunk_from = net; 2592f8829a4aSRandall Stewart 2593d06c82f1SRandall Stewart /*- 2594f8829a4aSRandall Stewart * Now before we proceed we must figure out if this is a wasted 2595f8829a4aSRandall Stewart * cluster... i.e. it is a small packet sent in and yet the driver 2596f8829a4aSRandall Stewart * underneath allocated a full cluster for it. If so we must copy it 2597f8829a4aSRandall Stewart * to a smaller mbuf and free up the cluster mbuf. This will help 2598d06c82f1SRandall Stewart * with cluster starvation. Note for __Panda__ we don't do this 2599d06c82f1SRandall Stewart * since it has clusters all the way down to 64 bytes. 2600f8829a4aSRandall Stewart */ 260144b7479bSRandall Stewart if (SCTP_BUF_LEN(m) < (long)MLEN && SCTP_BUF_NEXT(m) == NULL) { 2602f8829a4aSRandall Stewart /* we only handle mbufs that are singletons.. not chains */ 2603139bc87fSRandall Stewart m = sctp_get_mbuf_for_msg(SCTP_BUF_LEN(m), 0, M_DONTWAIT, 1, MT_DATA); 2604f8829a4aSRandall Stewart if (m) { 2605f8829a4aSRandall Stewart /* ok lets see if we can copy the data up */ 2606f8829a4aSRandall Stewart caddr_t *from, *to; 2607f8829a4aSRandall Stewart 2608f8829a4aSRandall Stewart /* get the pointers and copy */ 2609f8829a4aSRandall Stewart to = mtod(m, caddr_t *); 2610f8829a4aSRandall Stewart from = mtod((*mm), caddr_t *); 2611139bc87fSRandall Stewart memcpy(to, from, SCTP_BUF_LEN((*mm))); 2612f8829a4aSRandall Stewart /* copy the length and free up the old */ 2613139bc87fSRandall Stewart SCTP_BUF_LEN(m) = SCTP_BUF_LEN((*mm)); 2614f8829a4aSRandall Stewart sctp_m_freem(*mm); 2615f8829a4aSRandall Stewart /* sucess, back copy */ 2616f8829a4aSRandall Stewart *mm = m; 2617f8829a4aSRandall Stewart } else { 2618f8829a4aSRandall Stewart /* We are in trouble in the mbuf world .. yikes */ 2619f8829a4aSRandall Stewart m = *mm; 2620f8829a4aSRandall Stewart } 2621f8829a4aSRandall Stewart } 2622f8829a4aSRandall Stewart /* get pointer to the first chunk header */ 2623f8829a4aSRandall Stewart ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset, 2624f8829a4aSRandall Stewart sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); 2625f8829a4aSRandall Stewart if (ch == NULL) { 2626f8829a4aSRandall Stewart return (1); 2627f8829a4aSRandall Stewart } 2628f8829a4aSRandall Stewart /* 2629f8829a4aSRandall Stewart * process all DATA chunks... 2630f8829a4aSRandall Stewart */ 2631f8829a4aSRandall Stewart *high_tsn = asoc->cumulative_tsn; 2632f8829a4aSRandall Stewart break_flag = 0; 263342551e99SRandall Stewart asoc->data_pkts_seen++; 2634f8829a4aSRandall Stewart while (stop_proc == 0) { 2635f8829a4aSRandall Stewart /* validate chunk length */ 2636f8829a4aSRandall Stewart chk_length = ntohs(ch->ch.chunk_length); 2637f8829a4aSRandall Stewart if (length - *offset < chk_length) { 2638f8829a4aSRandall Stewart /* all done, mutulated chunk */ 2639f8829a4aSRandall Stewart stop_proc = 1; 2640f8829a4aSRandall Stewart break; 2641f8829a4aSRandall Stewart } 2642f8829a4aSRandall Stewart if (ch->ch.chunk_type == SCTP_DATA) { 2643f8829a4aSRandall Stewart if ((size_t)chk_length < sizeof(struct sctp_data_chunk) + 1) { 2644f8829a4aSRandall Stewart /* 2645f8829a4aSRandall Stewart * Need to send an abort since we had a 2646f8829a4aSRandall Stewart * invalid data chunk. 2647f8829a4aSRandall Stewart */ 2648f8829a4aSRandall Stewart struct mbuf *op_err; 2649f8829a4aSRandall Stewart 2650139bc87fSRandall Stewart op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 2 * sizeof(uint32_t)), 2651f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 2652f8829a4aSRandall Stewart 2653f8829a4aSRandall Stewart if (op_err) { 2654f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 2655f8829a4aSRandall Stewart uint32_t *ippp; 2656f8829a4aSRandall Stewart 2657139bc87fSRandall Stewart SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr) + 2658f8829a4aSRandall Stewart (2 * sizeof(uint32_t)); 2659f8829a4aSRandall Stewart ph = mtod(op_err, struct sctp_paramhdr *); 2660f8829a4aSRandall Stewart ph->param_type = 2661f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 2662139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(op_err)); 2663f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 2664a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_19); 2665f8829a4aSRandall Stewart ippp++; 2666f8829a4aSRandall Stewart *ippp = asoc->cumulative_tsn; 2667f8829a4aSRandall Stewart 2668f8829a4aSRandall Stewart } 2669a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_19; 2670f8829a4aSRandall Stewart sctp_abort_association(inp, stcb, m, iphlen, sh, 2671c54a18d2SRandall Stewart op_err, 0, net->port); 2672f8829a4aSRandall Stewart return (2); 2673f8829a4aSRandall Stewart } 2674f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 2675f8829a4aSRandall Stewart sctp_audit_log(0xB1, 0); 2676f8829a4aSRandall Stewart #endif 2677f8829a4aSRandall Stewart if (SCTP_SIZE32(chk_length) == (length - *offset)) { 2678f8829a4aSRandall Stewart last_chunk = 1; 2679f8829a4aSRandall Stewart } else { 2680f8829a4aSRandall Stewart last_chunk = 0; 2681f8829a4aSRandall Stewart } 2682f8829a4aSRandall Stewart if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset, ch, 2683f8829a4aSRandall Stewart chk_length, net, high_tsn, &abort_flag, &break_flag, 2684f8829a4aSRandall Stewart last_chunk)) { 2685f8829a4aSRandall Stewart num_chunks++; 2686f8829a4aSRandall Stewart } 2687f8829a4aSRandall Stewart if (abort_flag) 2688f8829a4aSRandall Stewart return (2); 2689f8829a4aSRandall Stewart 2690f8829a4aSRandall Stewart if (break_flag) { 2691f8829a4aSRandall Stewart /* 2692f8829a4aSRandall Stewart * Set because of out of rwnd space and no 2693f8829a4aSRandall Stewart * drop rep space left. 2694f8829a4aSRandall Stewart */ 2695f8829a4aSRandall Stewart stop_proc = 1; 2696f8829a4aSRandall Stewart break; 2697f8829a4aSRandall Stewart } 2698f8829a4aSRandall Stewart } else { 2699f8829a4aSRandall Stewart /* not a data chunk in the data region */ 2700f8829a4aSRandall Stewart switch (ch->ch.chunk_type) { 2701f8829a4aSRandall Stewart case SCTP_INITIATION: 2702f8829a4aSRandall Stewart case SCTP_INITIATION_ACK: 2703f8829a4aSRandall Stewart case SCTP_SELECTIVE_ACK: 2704830d754dSRandall Stewart case SCTP_NR_SELECTIVE_ACK: /* EY */ 2705f8829a4aSRandall Stewart case SCTP_HEARTBEAT_REQUEST: 2706f8829a4aSRandall Stewart case SCTP_HEARTBEAT_ACK: 2707f8829a4aSRandall Stewart case SCTP_ABORT_ASSOCIATION: 2708f8829a4aSRandall Stewart case SCTP_SHUTDOWN: 2709f8829a4aSRandall Stewart case SCTP_SHUTDOWN_ACK: 2710f8829a4aSRandall Stewart case SCTP_OPERATION_ERROR: 2711f8829a4aSRandall Stewart case SCTP_COOKIE_ECHO: 2712f8829a4aSRandall Stewart case SCTP_COOKIE_ACK: 2713f8829a4aSRandall Stewart case SCTP_ECN_ECHO: 2714f8829a4aSRandall Stewart case SCTP_ECN_CWR: 2715f8829a4aSRandall Stewart case SCTP_SHUTDOWN_COMPLETE: 2716f8829a4aSRandall Stewart case SCTP_AUTHENTICATION: 2717f8829a4aSRandall Stewart case SCTP_ASCONF_ACK: 2718f8829a4aSRandall Stewart case SCTP_PACKET_DROPPED: 2719f8829a4aSRandall Stewart case SCTP_STREAM_RESET: 2720f8829a4aSRandall Stewart case SCTP_FORWARD_CUM_TSN: 2721f8829a4aSRandall Stewart case SCTP_ASCONF: 2722f8829a4aSRandall Stewart /* 2723f8829a4aSRandall Stewart * Now, what do we do with KNOWN chunks that 2724f8829a4aSRandall Stewart * are NOT in the right place? 2725f8829a4aSRandall Stewart * 2726f8829a4aSRandall Stewart * For now, I do nothing but ignore them. We 2727f8829a4aSRandall Stewart * may later want to add sysctl stuff to 2728f8829a4aSRandall Stewart * switch out and do either an ABORT() or 2729f8829a4aSRandall Stewart * possibly process them. 2730f8829a4aSRandall Stewart */ 2731b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_data_order)) { 2732f8829a4aSRandall Stewart struct mbuf *op_err; 2733f8829a4aSRandall Stewart 2734f8829a4aSRandall Stewart op_err = sctp_generate_invmanparam(SCTP_CAUSE_PROTOCOL_VIOLATION); 2735c54a18d2SRandall Stewart sctp_abort_association(inp, stcb, m, iphlen, sh, op_err, 0, net->port); 2736f8829a4aSRandall Stewart return (2); 2737f8829a4aSRandall Stewart } 2738f8829a4aSRandall Stewart break; 2739f8829a4aSRandall Stewart default: 2740f8829a4aSRandall Stewart /* unknown chunk type, use bit rules */ 2741f8829a4aSRandall Stewart if (ch->ch.chunk_type & 0x40) { 2742f8829a4aSRandall Stewart /* Add a error report to the queue */ 2743d61a0ae0SRandall Stewart struct mbuf *merr; 2744f8829a4aSRandall Stewart struct sctp_paramhdr *phd; 2745f8829a4aSRandall Stewart 2746d61a0ae0SRandall Stewart merr = sctp_get_mbuf_for_msg(sizeof(*phd), 0, M_DONTWAIT, 1, MT_DATA); 2747d61a0ae0SRandall Stewart if (merr) { 2748d61a0ae0SRandall Stewart phd = mtod(merr, struct sctp_paramhdr *); 2749f8829a4aSRandall Stewart /* 2750f8829a4aSRandall Stewart * We cheat and use param 2751f8829a4aSRandall Stewart * type since we did not 2752f8829a4aSRandall Stewart * bother to define a error 2753f8829a4aSRandall Stewart * cause struct. They are 2754f8829a4aSRandall Stewart * the same basic format 2755f8829a4aSRandall Stewart * with different names. 2756f8829a4aSRandall Stewart */ 2757f8829a4aSRandall Stewart phd->param_type = 2758f8829a4aSRandall Stewart htons(SCTP_CAUSE_UNRECOG_CHUNK); 2759f8829a4aSRandall Stewart phd->param_length = 2760f8829a4aSRandall Stewart htons(chk_length + sizeof(*phd)); 2761d61a0ae0SRandall Stewart SCTP_BUF_LEN(merr) = sizeof(*phd); 2762d61a0ae0SRandall Stewart SCTP_BUF_NEXT(merr) = SCTP_M_COPYM(m, *offset, 2763f8829a4aSRandall Stewart SCTP_SIZE32(chk_length), 2764f8829a4aSRandall Stewart M_DONTWAIT); 2765d61a0ae0SRandall Stewart if (SCTP_BUF_NEXT(merr)) { 2766d61a0ae0SRandall Stewart sctp_queue_op_err(stcb, merr); 2767f8829a4aSRandall Stewart } else { 2768d61a0ae0SRandall Stewart sctp_m_freem(merr); 2769f8829a4aSRandall Stewart } 2770f8829a4aSRandall Stewart } 2771f8829a4aSRandall Stewart } 2772f8829a4aSRandall Stewart if ((ch->ch.chunk_type & 0x80) == 0) { 2773f8829a4aSRandall Stewart /* discard the rest of this packet */ 2774f8829a4aSRandall Stewart stop_proc = 1; 2775f8829a4aSRandall Stewart } /* else skip this bad chunk and 2776f8829a4aSRandall Stewart * continue... */ 2777f8829a4aSRandall Stewart break; 2778f8829a4aSRandall Stewart }; /* switch of chunk type */ 2779f8829a4aSRandall Stewart } 2780f8829a4aSRandall Stewart *offset += SCTP_SIZE32(chk_length); 2781f8829a4aSRandall Stewart if ((*offset >= length) || stop_proc) { 2782f8829a4aSRandall Stewart /* no more data left in the mbuf chain */ 2783f8829a4aSRandall Stewart stop_proc = 1; 2784f8829a4aSRandall Stewart continue; 2785f8829a4aSRandall Stewart } 2786f8829a4aSRandall Stewart ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset, 2787f8829a4aSRandall Stewart sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); 2788f8829a4aSRandall Stewart if (ch == NULL) { 2789f8829a4aSRandall Stewart *offset = length; 2790f8829a4aSRandall Stewart stop_proc = 1; 2791f8829a4aSRandall Stewart break; 2792f8829a4aSRandall Stewart 2793f8829a4aSRandall Stewart } 2794f8829a4aSRandall Stewart } /* while */ 2795f8829a4aSRandall Stewart if (break_flag) { 2796f8829a4aSRandall Stewart /* 2797f8829a4aSRandall Stewart * we need to report rwnd overrun drops. 2798f8829a4aSRandall Stewart */ 2799f8829a4aSRandall Stewart sctp_send_packet_dropped(stcb, net, *mm, iphlen, 0); 2800f8829a4aSRandall Stewart } 2801f8829a4aSRandall Stewart if (num_chunks) { 2802f8829a4aSRandall Stewart /* 2803ceaad40aSRandall Stewart * Did we get data, if so update the time for auto-close and 2804f8829a4aSRandall Stewart * give peer credit for being alive. 2805f8829a4aSRandall Stewart */ 2806f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvpktwithdata); 2807b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 2808c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 2809c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 2810c4739e2fSRandall Stewart 0, 2811c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 2812c4739e2fSRandall Stewart __LINE__); 2813c4739e2fSRandall Stewart } 2814f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 28156e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_last_rcvd); 2816f8829a4aSRandall Stewart } 2817f8829a4aSRandall Stewart /* now service all of the reassm queue if needed */ 2818f8829a4aSRandall Stewart if (!(TAILQ_EMPTY(&asoc->reasmqueue))) 2819f8829a4aSRandall Stewart sctp_service_queues(stcb, asoc); 2820f8829a4aSRandall Stewart 2821f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 282242551e99SRandall Stewart /* Assure that we ack right away */ 282342551e99SRandall Stewart stcb->asoc.send_sack = 1; 2824f8829a4aSRandall Stewart } 2825f8829a4aSRandall Stewart /* Start a sack timer or QUEUE a SACK for sending */ 2826b5c16493SMichael Tuexen sctp_sack_check(stcb, was_a_gap, &abort_flag); 2827f8829a4aSRandall Stewart if (abort_flag) 2828f8829a4aSRandall Stewart return (2); 2829f8829a4aSRandall Stewart 2830f8829a4aSRandall Stewart return (0); 2831f8829a4aSRandall Stewart } 2832f8829a4aSRandall Stewart 28330fa753b3SRandall Stewart static int 28340fa753b3SRandall Stewart sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1, uint32_t last_tsn, 28350fa753b3SRandall Stewart uint16_t frag_strt, uint16_t frag_end, int nr_sacking, 28360fa753b3SRandall Stewart int *num_frs, 28370fa753b3SRandall Stewart uint32_t * biggest_newly_acked_tsn, 28380fa753b3SRandall Stewart uint32_t * this_sack_lowest_newack, 28390fa753b3SRandall Stewart int *ecn_seg_sums) 28400fa753b3SRandall Stewart { 28410fa753b3SRandall Stewart struct sctp_tmit_chunk *tp1; 28420fa753b3SRandall Stewart unsigned int theTSN; 2843b5c16493SMichael Tuexen int j, wake_him = 0, circled = 0; 28440fa753b3SRandall Stewart 28450fa753b3SRandall Stewart /* Recover the tp1 we last saw */ 28460fa753b3SRandall Stewart tp1 = *p_tp1; 28470fa753b3SRandall Stewart if (tp1 == NULL) { 28480fa753b3SRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 28490fa753b3SRandall Stewart } 28500fa753b3SRandall Stewart for (j = frag_strt; j <= frag_end; j++) { 28510fa753b3SRandall Stewart theTSN = j + last_tsn; 28520fa753b3SRandall Stewart while (tp1) { 28530fa753b3SRandall Stewart if (tp1->rec.data.doing_fast_retransmit) 28540fa753b3SRandall Stewart (*num_frs) += 1; 28550fa753b3SRandall Stewart 28560fa753b3SRandall Stewart /*- 28570fa753b3SRandall Stewart * CMT: CUCv2 algorithm. For each TSN being 28580fa753b3SRandall Stewart * processed from the sent queue, track the 28590fa753b3SRandall Stewart * next expected pseudo-cumack, or 28600fa753b3SRandall Stewart * rtx_pseudo_cumack, if required. Separate 28610fa753b3SRandall Stewart * cumack trackers for first transmissions, 28620fa753b3SRandall Stewart * and retransmissions. 28630fa753b3SRandall Stewart */ 28640fa753b3SRandall Stewart if ((tp1->whoTo->find_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 28650fa753b3SRandall Stewart (tp1->snd_count == 1)) { 28660fa753b3SRandall Stewart tp1->whoTo->pseudo_cumack = tp1->rec.data.TSN_seq; 28670fa753b3SRandall Stewart tp1->whoTo->find_pseudo_cumack = 0; 28680fa753b3SRandall Stewart } 28690fa753b3SRandall Stewart if ((tp1->whoTo->find_rtx_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 28700fa753b3SRandall Stewart (tp1->snd_count > 1)) { 28710fa753b3SRandall Stewart tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.TSN_seq; 28720fa753b3SRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 0; 28730fa753b3SRandall Stewart } 28740fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == theTSN) { 28750fa753b3SRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 28760fa753b3SRandall Stewart /*- 28770fa753b3SRandall Stewart * must be held until 28780fa753b3SRandall Stewart * cum-ack passes 28790fa753b3SRandall Stewart */ 28800fa753b3SRandall Stewart /*- 28810fa753b3SRandall Stewart * ECN Nonce: Add the nonce 28820fa753b3SRandall Stewart * value to the sender's 28830fa753b3SRandall Stewart * nonce sum 28840fa753b3SRandall Stewart */ 28850fa753b3SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 28860fa753b3SRandall Stewart /*- 28870fa753b3SRandall Stewart * If it is less than RESEND, it is 28880fa753b3SRandall Stewart * now no-longer in flight. 28890fa753b3SRandall Stewart * Higher values may already be set 28900fa753b3SRandall Stewart * via previous Gap Ack Blocks... 28910fa753b3SRandall Stewart * i.e. ACKED or RESEND. 28920fa753b3SRandall Stewart */ 28930fa753b3SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 28940fa753b3SRandall Stewart *biggest_newly_acked_tsn, MAX_TSN)) { 28950fa753b3SRandall Stewart *biggest_newly_acked_tsn = tp1->rec.data.TSN_seq; 28960fa753b3SRandall Stewart } 28970fa753b3SRandall Stewart /*- 28980fa753b3SRandall Stewart * CMT: SFR algo (and HTNA) - set 28990fa753b3SRandall Stewart * saw_newack to 1 for dest being 29000fa753b3SRandall Stewart * newly acked. update 29010fa753b3SRandall Stewart * this_sack_highest_newack if 29020fa753b3SRandall Stewart * appropriate. 29030fa753b3SRandall Stewart */ 29040fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) 29050fa753b3SRandall Stewart tp1->whoTo->saw_newack = 1; 29060fa753b3SRandall Stewart 29070fa753b3SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 29080fa753b3SRandall Stewart tp1->whoTo->this_sack_highest_newack, 29090fa753b3SRandall Stewart MAX_TSN)) { 29100fa753b3SRandall Stewart tp1->whoTo->this_sack_highest_newack = 29110fa753b3SRandall Stewart tp1->rec.data.TSN_seq; 29120fa753b3SRandall Stewart } 29130fa753b3SRandall Stewart /*- 29140fa753b3SRandall Stewart * CMT DAC algo: also update 29150fa753b3SRandall Stewart * this_sack_lowest_newack 29160fa753b3SRandall Stewart */ 29170fa753b3SRandall Stewart if (*this_sack_lowest_newack == 0) { 29180fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 29190fa753b3SRandall Stewart sctp_log_sack(*this_sack_lowest_newack, 29200fa753b3SRandall Stewart last_tsn, 29210fa753b3SRandall Stewart tp1->rec.data.TSN_seq, 29220fa753b3SRandall Stewart 0, 29230fa753b3SRandall Stewart 0, 29240fa753b3SRandall Stewart SCTP_LOG_TSN_ACKED); 29250fa753b3SRandall Stewart } 29260fa753b3SRandall Stewart *this_sack_lowest_newack = tp1->rec.data.TSN_seq; 29270fa753b3SRandall Stewart } 29280fa753b3SRandall Stewart /*- 29290fa753b3SRandall Stewart * CMT: CUCv2 algorithm. If (rtx-)pseudo-cumack for corresp 29300fa753b3SRandall Stewart * dest is being acked, then we have a new (rtx-)pseudo-cumack. Set 29310fa753b3SRandall Stewart * new_(rtx_)pseudo_cumack to TRUE so that the cwnd for this dest can be 29320fa753b3SRandall Stewart * updated. Also trigger search for the next expected (rtx-)pseudo-cumack. 29330fa753b3SRandall Stewart * Separate pseudo_cumack trackers for first transmissions and 29340fa753b3SRandall Stewart * retransmissions. 29350fa753b3SRandall Stewart */ 29360fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->pseudo_cumack) { 29370fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 29380fa753b3SRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 29390fa753b3SRandall Stewart } 29400fa753b3SRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 29410fa753b3SRandall Stewart } 29420fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 29430fa753b3SRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 29440fa753b3SRandall Stewart } 29450fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->rtx_pseudo_cumack) { 29460fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 29470fa753b3SRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 29480fa753b3SRandall Stewart } 29490fa753b3SRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 29500fa753b3SRandall Stewart } 29510fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 29520fa753b3SRandall Stewart sctp_log_sack(*biggest_newly_acked_tsn, 29530fa753b3SRandall Stewart last_tsn, 29540fa753b3SRandall Stewart tp1->rec.data.TSN_seq, 29550fa753b3SRandall Stewart frag_strt, 29560fa753b3SRandall Stewart frag_end, 29570fa753b3SRandall Stewart SCTP_LOG_TSN_ACKED); 29580fa753b3SRandall Stewart } 29590fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 29600fa753b3SRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP, 29610fa753b3SRandall Stewart tp1->whoTo->flight_size, 29620fa753b3SRandall Stewart tp1->book_size, 29630fa753b3SRandall Stewart (uintptr_t) tp1->whoTo, 29640fa753b3SRandall Stewart tp1->rec.data.TSN_seq); 29650fa753b3SRandall Stewart } 29660fa753b3SRandall Stewart sctp_flight_size_decrease(tp1); 29670fa753b3SRandall Stewart sctp_total_flight_decrease(stcb, tp1); 29680fa753b3SRandall Stewart 29690fa753b3SRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 29700fa753b3SRandall Stewart if (tp1->snd_count < 2) { 29710fa753b3SRandall Stewart /*- 29720fa753b3SRandall Stewart * True non-retransmited chunk 29730fa753b3SRandall Stewart */ 29740fa753b3SRandall Stewart tp1->whoTo->net_ack2 += tp1->send_size; 29750fa753b3SRandall Stewart 29760fa753b3SRandall Stewart /*- 29770fa753b3SRandall Stewart * update RTO too ? 29780fa753b3SRandall Stewart */ 29790fa753b3SRandall Stewart if (tp1->do_rtt) { 29800fa753b3SRandall Stewart tp1->whoTo->RTO = 29810fa753b3SRandall Stewart sctp_calculate_rto(stcb, 29820fa753b3SRandall Stewart &stcb->asoc, 29830fa753b3SRandall Stewart tp1->whoTo, 29840fa753b3SRandall Stewart &tp1->sent_rcv_time, 29850fa753b3SRandall Stewart sctp_align_safe_nocopy); 29860fa753b3SRandall Stewart tp1->do_rtt = 0; 29870fa753b3SRandall Stewart } 29880fa753b3SRandall Stewart } 29890fa753b3SRandall Stewart } 29900fa753b3SRandall Stewart if (tp1->sent <= SCTP_DATAGRAM_RESEND) { 29910fa753b3SRandall Stewart (*ecn_seg_sums) += tp1->rec.data.ect_nonce; 29920fa753b3SRandall Stewart (*ecn_seg_sums) &= SCTP_SACK_NONCE_SUM; 29930fa753b3SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 29940fa753b3SRandall Stewart stcb->asoc.this_sack_highest_gap, 29950fa753b3SRandall Stewart MAX_TSN)) { 29960fa753b3SRandall Stewart stcb->asoc.this_sack_highest_gap = 29970fa753b3SRandall Stewart tp1->rec.data.TSN_seq; 29980fa753b3SRandall Stewart } 29990fa753b3SRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 30000fa753b3SRandall Stewart sctp_ucount_decr(stcb->asoc.sent_queue_retran_cnt); 30010fa753b3SRandall Stewart #ifdef SCTP_AUDITING_ENABLED 30020fa753b3SRandall Stewart sctp_audit_log(0xB2, 30030fa753b3SRandall Stewart (stcb->asoc.sent_queue_retran_cnt & 0x000000ff)); 30040fa753b3SRandall Stewart #endif 30050fa753b3SRandall Stewart } 30060fa753b3SRandall Stewart } 30070fa753b3SRandall Stewart /*- 30080fa753b3SRandall Stewart * All chunks NOT UNSENT fall through here and are marked 30090fa753b3SRandall Stewart * (leave PR-SCTP ones that are to skip alone though) 30100fa753b3SRandall Stewart */ 30110fa753b3SRandall Stewart if (tp1->sent != SCTP_FORWARD_TSN_SKIP) 30120fa753b3SRandall Stewart tp1->sent = SCTP_DATAGRAM_MARKED; 30130fa753b3SRandall Stewart 30140fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 30150fa753b3SRandall Stewart /* deflate the cwnd */ 30160fa753b3SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 30170fa753b3SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 30180fa753b3SRandall Stewart } 30190fa753b3SRandall Stewart /* NR Sack code here */ 30200fa753b3SRandall Stewart if (nr_sacking) { 30210fa753b3SRandall Stewart if (tp1->data) { 30220fa753b3SRandall Stewart /* 30230fa753b3SRandall Stewart * sa_ignore 30240fa753b3SRandall Stewart * NO_NULL_CHK 30250fa753b3SRandall Stewart */ 30260fa753b3SRandall Stewart sctp_free_bufspace(stcb, &stcb->asoc, tp1, 1); 30270fa753b3SRandall Stewart sctp_m_freem(tp1->data); 30280fa753b3SRandall Stewart tp1->data = NULL; 3029b5c16493SMichael Tuexen } 30300fa753b3SRandall Stewart wake_him++; 30310fa753b3SRandall Stewart } 30320fa753b3SRandall Stewart } 30330fa753b3SRandall Stewart break; 30340fa753b3SRandall Stewart } /* if (tp1->TSN_seq == theTSN) */ 30350fa753b3SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, theTSN, 30360fa753b3SRandall Stewart MAX_TSN)) 30370fa753b3SRandall Stewart break; 30380fa753b3SRandall Stewart 30390fa753b3SRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3040b5c16493SMichael Tuexen if ((tp1 == NULL) && (circled == 0)) { 3041b5c16493SMichael Tuexen circled++; 30420fa753b3SRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 30430fa753b3SRandall Stewart } 3044b5c16493SMichael Tuexen } /* end while (tp1) */ 3045b5c16493SMichael Tuexen if (tp1 == NULL) { 3046b5c16493SMichael Tuexen circled = 0; 3047b5c16493SMichael Tuexen tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 3048b5c16493SMichael Tuexen } 3049b5c16493SMichael Tuexen /* In case the fragments were not in order we must reset */ 30500fa753b3SRandall Stewart } /* end for (j = fragStart */ 30510fa753b3SRandall Stewart *p_tp1 = tp1; 30520fa753b3SRandall Stewart return (wake_him); /* Return value only used for nr-sack */ 30530fa753b3SRandall Stewart } 30540fa753b3SRandall Stewart 30550fa753b3SRandall Stewart 3056cd554309SMichael Tuexen static int 3057458303daSRandall Stewart sctp_handle_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct sctp_association *asoc, 3058cd554309SMichael Tuexen uint32_t last_tsn, uint32_t * biggest_tsn_acked, 3059139bc87fSRandall Stewart uint32_t * biggest_newly_acked_tsn, uint32_t * this_sack_lowest_newack, 3060cd554309SMichael Tuexen int num_seg, int num_nr_seg, int *ecn_seg_sums) 3061f8829a4aSRandall Stewart { 3062458303daSRandall Stewart struct sctp_gap_ack_block *frag, block; 3063f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 30640fa753b3SRandall Stewart int i; 3065f8829a4aSRandall Stewart int num_frs = 0; 3066cd554309SMichael Tuexen int chunk_freed; 3067cd554309SMichael Tuexen int non_revocable; 3068cd554309SMichael Tuexen uint16_t frag_strt, frag_end; 3069cd554309SMichael Tuexen uint32_t last_frag_high; 3070f8829a4aSRandall Stewart 3071cd554309SMichael Tuexen tp1 = NULL; 3072cd554309SMichael Tuexen last_frag_high = 0; 3073cd554309SMichael Tuexen chunk_freed = 0; 3074f8829a4aSRandall Stewart 3075cd554309SMichael Tuexen for (i = 0; i < (num_seg + num_nr_seg); i++) { 3076458303daSRandall Stewart frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, 3077458303daSRandall Stewart sizeof(struct sctp_gap_ack_block), (uint8_t *) & block); 3078458303daSRandall Stewart *offset += sizeof(block); 3079458303daSRandall Stewart if (frag == NULL) { 3080cd554309SMichael Tuexen return (chunk_freed); 3081458303daSRandall Stewart } 3082f8829a4aSRandall Stewart frag_strt = ntohs(frag->start); 3083f8829a4aSRandall Stewart frag_end = ntohs(frag->end); 3084830d754dSRandall Stewart /* some sanity checks on the fragment offsets */ 3085f8829a4aSRandall Stewart if (frag_strt > frag_end) { 3086f8829a4aSRandall Stewart /* this one is malformed, skip */ 3087f8829a4aSRandall Stewart continue; 3088f8829a4aSRandall Stewart } 3089f8829a4aSRandall Stewart if (compare_with_wrap((frag_end + last_tsn), *biggest_tsn_acked, 3090f8829a4aSRandall Stewart MAX_TSN)) 3091f8829a4aSRandall Stewart *biggest_tsn_acked = frag_end + last_tsn; 3092f8829a4aSRandall Stewart 3093f8829a4aSRandall Stewart /* mark acked dgs and find out the highestTSN being acked */ 3094f8829a4aSRandall Stewart if (tp1 == NULL) { 3095f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3096f8829a4aSRandall Stewart /* save the locations of the last frags */ 3097f8829a4aSRandall Stewart last_frag_high = frag_end + last_tsn; 3098f8829a4aSRandall Stewart } else { 3099f8829a4aSRandall Stewart /* 3100f8829a4aSRandall Stewart * now lets see if we need to reset the queue due to 3101f8829a4aSRandall Stewart * a out-of-order SACK fragment 3102f8829a4aSRandall Stewart */ 3103f8829a4aSRandall Stewart if (compare_with_wrap(frag_strt + last_tsn, 3104f8829a4aSRandall Stewart last_frag_high, MAX_TSN)) { 3105f8829a4aSRandall Stewart /* 3106f8829a4aSRandall Stewart * if the new frag starts after the last TSN 3107f8829a4aSRandall Stewart * frag covered, we are ok and this one is 3108f8829a4aSRandall Stewart * beyond the last one 3109f8829a4aSRandall Stewart */ 3110f8829a4aSRandall Stewart ; 3111f8829a4aSRandall Stewart } else { 3112f8829a4aSRandall Stewart /* 3113f8829a4aSRandall Stewart * ok, they have reset us, so we need to 3114f8829a4aSRandall Stewart * reset the queue this will cause extra 3115f8829a4aSRandall Stewart * hunting but hey, they chose the 3116f8829a4aSRandall Stewart * performance hit when they failed to order 3117830d754dSRandall Stewart * their gaps 3118f8829a4aSRandall Stewart */ 3119f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3120f8829a4aSRandall Stewart } 3121f8829a4aSRandall Stewart last_frag_high = frag_end + last_tsn; 3122f8829a4aSRandall Stewart } 3123cd554309SMichael Tuexen if (i < num_seg) { 3124cd554309SMichael Tuexen non_revocable = 0; 3125cd554309SMichael Tuexen } else { 3126cd554309SMichael Tuexen non_revocable = 1; 3127cd554309SMichael Tuexen } 3128b5c16493SMichael Tuexen if (i == num_seg) { 3129b5c16493SMichael Tuexen tp1 = NULL; 3130b5c16493SMichael Tuexen } 3131cd554309SMichael Tuexen if (sctp_process_segment_range(stcb, &tp1, last_tsn, frag_strt, frag_end, 3132cd554309SMichael Tuexen non_revocable, &num_frs, biggest_newly_acked_tsn, 3133cd554309SMichael Tuexen this_sack_lowest_newack, ecn_seg_sums)) { 3134cd554309SMichael Tuexen chunk_freed = 1; 3135458303daSRandall Stewart } 3136f8829a4aSRandall Stewart } 3137b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 313880fefe0aSRandall Stewart if (num_frs) 313980fefe0aSRandall Stewart sctp_log_fr(*biggest_tsn_acked, 314080fefe0aSRandall Stewart *biggest_newly_acked_tsn, 314180fefe0aSRandall Stewart last_tsn, SCTP_FR_LOG_BIGGEST_TSNS); 314280fefe0aSRandall Stewart } 3143cd554309SMichael Tuexen return (chunk_freed); 3144f8829a4aSRandall Stewart } 3145f8829a4aSRandall Stewart 3146f8829a4aSRandall Stewart static void 3147c105859eSRandall Stewart sctp_check_for_revoked(struct sctp_tcb *stcb, 3148c105859eSRandall Stewart struct sctp_association *asoc, uint32_t cumack, 314963eda93dSMichael Tuexen uint32_t biggest_tsn_acked) 3150f8829a4aSRandall Stewart { 3151f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3152f8829a4aSRandall Stewart int tot_revoked = 0; 3153f8829a4aSRandall Stewart 3154f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3155f8829a4aSRandall Stewart while (tp1) { 3156f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, cumack, 3157f8829a4aSRandall Stewart MAX_TSN)) { 3158f8829a4aSRandall Stewart /* 3159f8829a4aSRandall Stewart * ok this guy is either ACK or MARKED. If it is 3160f8829a4aSRandall Stewart * ACKED it has been previously acked but not this 3161f8829a4aSRandall Stewart * time i.e. revoked. If it is MARKED it was ACK'ed 3162f8829a4aSRandall Stewart * again. 3163f8829a4aSRandall Stewart */ 3164d06c82f1SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked, 3165d06c82f1SRandall Stewart MAX_TSN)) 3166d06c82f1SRandall Stewart break; 3167d06c82f1SRandall Stewart 3168d06c82f1SRandall Stewart 3169f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_ACKED) { 3170f8829a4aSRandall Stewart /* it has been revoked */ 3171f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 3172f8829a4aSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 3173a5d547adSRandall Stewart /* 317442551e99SRandall Stewart * We must add this stuff back in to assure 317542551e99SRandall Stewart * timers and such get started. 3176a5d547adSRandall Stewart */ 3177b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3178c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 3179c105859eSRandall Stewart tp1->whoTo->flight_size, 3180c105859eSRandall Stewart tp1->book_size, 3181c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3182c105859eSRandall Stewart tp1->rec.data.TSN_seq); 318380fefe0aSRandall Stewart } 3184c105859eSRandall Stewart sctp_flight_size_increase(tp1); 3185c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 318642551e99SRandall Stewart /* 318742551e99SRandall Stewart * We inflate the cwnd to compensate for our 318842551e99SRandall Stewart * artificial inflation of the flight_size. 318942551e99SRandall Stewart */ 319042551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 3191f8829a4aSRandall Stewart tot_revoked++; 3192b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 3193f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 3194f8829a4aSRandall Stewart cumack, 3195f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3196f8829a4aSRandall Stewart 0, 3197f8829a4aSRandall Stewart 0, 3198f8829a4aSRandall Stewart SCTP_LOG_TSN_REVOKED); 319980fefe0aSRandall Stewart } 3200f8829a4aSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_MARKED) { 3201f8829a4aSRandall Stewart /* it has been re-acked in this SACK */ 3202f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 3203f8829a4aSRandall Stewart } 3204f8829a4aSRandall Stewart } 3205f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) 3206f8829a4aSRandall Stewart break; 3207f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3208f8829a4aSRandall Stewart } 3209f8829a4aSRandall Stewart if (tot_revoked > 0) { 3210f8829a4aSRandall Stewart /* 3211f8829a4aSRandall Stewart * Setup the ecn nonce re-sync point. We do this since once 3212f8829a4aSRandall Stewart * data is revoked we begin to retransmit things, which do 3213f8829a4aSRandall Stewart * NOT have the ECN bits set. This means we are now out of 3214f8829a4aSRandall Stewart * sync and must wait until we get back in sync with the 3215f8829a4aSRandall Stewart * peer to check ECN bits. 3216f8829a4aSRandall Stewart */ 3217f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->send_queue); 3218f8829a4aSRandall Stewart if (tp1 == NULL) { 3219f8829a4aSRandall Stewart asoc->nonce_resync_tsn = asoc->sending_seq; 3220f8829a4aSRandall Stewart } else { 3221f8829a4aSRandall Stewart asoc->nonce_resync_tsn = tp1->rec.data.TSN_seq; 3222f8829a4aSRandall Stewart } 3223f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 0; 3224f8829a4aSRandall Stewart asoc->nonce_sum_check = 0; 3225f8829a4aSRandall Stewart } 3226f8829a4aSRandall Stewart } 3227f8829a4aSRandall Stewart 3228830d754dSRandall Stewart 3229f8829a4aSRandall Stewart static void 3230f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, 323163eda93dSMichael Tuexen uint32_t biggest_tsn_acked, uint32_t biggest_tsn_newly_acked, uint32_t this_sack_lowest_newack, int accum_moved) 3232f8829a4aSRandall Stewart { 3233f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3234f8829a4aSRandall Stewart int strike_flag = 0; 3235f8829a4aSRandall Stewart struct timeval now; 3236f8829a4aSRandall Stewart int tot_retrans = 0; 3237f8829a4aSRandall Stewart uint32_t sending_seq; 3238f8829a4aSRandall Stewart struct sctp_nets *net; 3239f8829a4aSRandall Stewart int num_dests_sacked = 0; 3240f8829a4aSRandall Stewart 3241f8829a4aSRandall Stewart /* 3242f8829a4aSRandall Stewart * select the sending_seq, this is either the next thing ready to be 3243f8829a4aSRandall Stewart * sent but not transmitted, OR, the next seq we assign. 3244f8829a4aSRandall Stewart */ 3245f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.send_queue); 3246f8829a4aSRandall Stewart if (tp1 == NULL) { 3247f8829a4aSRandall Stewart sending_seq = asoc->sending_seq; 3248f8829a4aSRandall Stewart } else { 3249f8829a4aSRandall Stewart sending_seq = tp1->rec.data.TSN_seq; 3250f8829a4aSRandall Stewart } 3251f8829a4aSRandall Stewart 3252f8829a4aSRandall Stewart /* CMT DAC algo: finding out if SACK is a mixed SACK */ 3253b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3254f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 3255f8829a4aSRandall Stewart if (net->saw_newack) 3256f8829a4aSRandall Stewart num_dests_sacked++; 3257f8829a4aSRandall Stewart } 3258f8829a4aSRandall Stewart } 3259f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_prsctp) { 32606e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 3261f8829a4aSRandall Stewart } 3262f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3263f8829a4aSRandall Stewart while (tp1) { 3264f8829a4aSRandall Stewart strike_flag = 0; 3265f8829a4aSRandall Stewart if (tp1->no_fr_allowed) { 3266f8829a4aSRandall Stewart /* this one had a timeout or something */ 3267f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3268f8829a4aSRandall Stewart continue; 3269f8829a4aSRandall Stewart } 3270b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3271f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) 3272f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3273f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3274f8829a4aSRandall Stewart tp1->sent, 3275f8829a4aSRandall Stewart SCTP_FR_LOG_CHECK_STRIKE); 327680fefe0aSRandall Stewart } 3277f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked, 3278f8829a4aSRandall Stewart MAX_TSN) || 3279f8829a4aSRandall Stewart tp1->sent == SCTP_DATAGRAM_UNSENT) { 3280f8829a4aSRandall Stewart /* done */ 3281f8829a4aSRandall Stewart break; 3282f8829a4aSRandall Stewart } 3283f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_prsctp) { 3284f8829a4aSRandall Stewart if ((PR_SCTP_TTL_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) { 3285f8829a4aSRandall Stewart /* Is it expired? */ 32865e54f665SRandall Stewart if ( 3287fc14de76SRandall Stewart /* 3288fc14de76SRandall Stewart * TODO sctp_constants.h needs alternative 3289fc14de76SRandall Stewart * time macros when _KERNEL is undefined. 3290fc14de76SRandall Stewart */ 32915e54f665SRandall Stewart (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) 32925e54f665SRandall Stewart ) { 3293f8829a4aSRandall Stewart /* Yes so drop it */ 3294f8829a4aSRandall Stewart if (tp1->data != NULL) { 3295ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3296f8829a4aSRandall Stewart (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 32970c0982b8SRandall Stewart SCTP_SO_NOT_LOCKED); 3298f8829a4aSRandall Stewart } 3299f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3300f8829a4aSRandall Stewart continue; 3301f8829a4aSRandall Stewart } 3302f8829a4aSRandall Stewart } 3303f8829a4aSRandall Stewart } 3304f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 3305f8829a4aSRandall Stewart asoc->this_sack_highest_gap, MAX_TSN)) { 3306f8829a4aSRandall Stewart /* we are beyond the tsn in the sack */ 3307f8829a4aSRandall Stewart break; 3308f8829a4aSRandall Stewart } 3309f8829a4aSRandall Stewart if (tp1->sent >= SCTP_DATAGRAM_RESEND) { 3310f8829a4aSRandall Stewart /* either a RESEND, ACKED, or MARKED */ 3311f8829a4aSRandall Stewart /* skip */ 3312f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3313f8829a4aSRandall Stewart continue; 3314f8829a4aSRandall Stewart } 3315f8829a4aSRandall Stewart /* 3316f8829a4aSRandall Stewart * CMT : SFR algo (covers part of DAC and HTNA as well) 3317f8829a4aSRandall Stewart */ 3318ad81507eSRandall Stewart if (tp1->whoTo && tp1->whoTo->saw_newack == 0) { 3319f8829a4aSRandall Stewart /* 3320f8829a4aSRandall Stewart * No new acks were receieved for data sent to this 3321f8829a4aSRandall Stewart * dest. Therefore, according to the SFR algo for 3322f8829a4aSRandall Stewart * CMT, no data sent to this dest can be marked for 3323c105859eSRandall Stewart * FR using this SACK. 3324f8829a4aSRandall Stewart */ 3325f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3326f8829a4aSRandall Stewart continue; 3327ad81507eSRandall Stewart } else if (tp1->whoTo && compare_with_wrap(tp1->rec.data.TSN_seq, 3328f8829a4aSRandall Stewart tp1->whoTo->this_sack_highest_newack, MAX_TSN)) { 3329f8829a4aSRandall Stewart /* 3330f8829a4aSRandall Stewart * CMT: New acks were receieved for data sent to 3331f8829a4aSRandall Stewart * this dest. But no new acks were seen for data 3332f8829a4aSRandall Stewart * sent after tp1. Therefore, according to the SFR 3333f8829a4aSRandall Stewart * algo for CMT, tp1 cannot be marked for FR using 3334f8829a4aSRandall Stewart * this SACK. This step covers part of the DAC algo 3335f8829a4aSRandall Stewart * and the HTNA algo as well. 3336f8829a4aSRandall Stewart */ 3337f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3338f8829a4aSRandall Stewart continue; 3339f8829a4aSRandall Stewart } 3340f8829a4aSRandall Stewart /* 3341f8829a4aSRandall Stewart * Here we check to see if we were have already done a FR 3342f8829a4aSRandall Stewart * and if so we see if the biggest TSN we saw in the sack is 3343f8829a4aSRandall Stewart * smaller than the recovery point. If so we don't strike 3344f8829a4aSRandall Stewart * the tsn... otherwise we CAN strike the TSN. 3345f8829a4aSRandall Stewart */ 3346f8829a4aSRandall Stewart /* 334742551e99SRandall Stewart * @@@ JRI: Check for CMT if (accum_moved && 334842551e99SRandall Stewart * asoc->fast_retran_loss_recovery && (sctp_cmt_on_off == 334942551e99SRandall Stewart * 0)) { 3350f8829a4aSRandall Stewart */ 335142551e99SRandall Stewart if (accum_moved && asoc->fast_retran_loss_recovery) { 3352f8829a4aSRandall Stewart /* 3353f8829a4aSRandall Stewart * Strike the TSN if in fast-recovery and cum-ack 3354f8829a4aSRandall Stewart * moved. 3355f8829a4aSRandall Stewart */ 3356b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3357f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3358f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3359f8829a4aSRandall Stewart tp1->sent, 3360f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 336180fefe0aSRandall Stewart } 33625e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3363f8829a4aSRandall Stewart tp1->sent++; 33645e54f665SRandall Stewart } 3365b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3366f8829a4aSRandall Stewart /* 3367f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK flag is set to 3368f8829a4aSRandall Stewart * 0, then lowest_newack test will not pass 3369f8829a4aSRandall Stewart * because it would have been set to the 3370f8829a4aSRandall Stewart * cumack earlier. If not already to be 3371f8829a4aSRandall Stewart * rtx'd, If not a mixed sack and if tp1 is 3372f8829a4aSRandall Stewart * not between two sacked TSNs, then mark by 3373c105859eSRandall Stewart * one more. NOTE that we are marking by one 3374c105859eSRandall Stewart * additional time since the SACK DAC flag 3375c105859eSRandall Stewart * indicates that two packets have been 3376c105859eSRandall Stewart * received after this missing TSN. 33775e54f665SRandall Stewart */ 33785e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && 3379f8829a4aSRandall Stewart compare_with_wrap(this_sack_lowest_newack, tp1->rec.data.TSN_seq, MAX_TSN)) { 3380b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3381f8829a4aSRandall Stewart sctp_log_fr(16 + num_dests_sacked, 3382f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3383f8829a4aSRandall Stewart tp1->sent, 3384f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 338580fefe0aSRandall Stewart } 3386f8829a4aSRandall Stewart tp1->sent++; 3387f8829a4aSRandall Stewart } 3388f8829a4aSRandall Stewart } 3389b3f1ea41SRandall Stewart } else if ((tp1->rec.data.doing_fast_retransmit) && (SCTP_BASE_SYSCTL(sctp_cmt_on_off) == 0)) { 3390f8829a4aSRandall Stewart /* 3391f8829a4aSRandall Stewart * For those that have done a FR we must take 3392f8829a4aSRandall Stewart * special consideration if we strike. I.e the 3393f8829a4aSRandall Stewart * biggest_newly_acked must be higher than the 3394f8829a4aSRandall Stewart * sending_seq at the time we did the FR. 3395f8829a4aSRandall Stewart */ 33965e54f665SRandall Stewart if ( 3397f8829a4aSRandall Stewart #ifdef SCTP_FR_TO_ALTERNATE 3398f8829a4aSRandall Stewart /* 3399f8829a4aSRandall Stewart * If FR's go to new networks, then we must only do 3400f8829a4aSRandall Stewart * this for singly homed asoc's. However if the FR's 3401f8829a4aSRandall Stewart * go to the same network (Armando's work) then its 3402f8829a4aSRandall Stewart * ok to FR multiple times. 3403f8829a4aSRandall Stewart */ 34045e54f665SRandall Stewart (asoc->numnets < 2) 3405f8829a4aSRandall Stewart #else 34065e54f665SRandall Stewart (1) 3407f8829a4aSRandall Stewart #endif 34085e54f665SRandall Stewart ) { 34095e54f665SRandall Stewart 3410f8829a4aSRandall Stewart if ((compare_with_wrap(biggest_tsn_newly_acked, 3411f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn, MAX_TSN)) || 3412f8829a4aSRandall Stewart (biggest_tsn_newly_acked == 3413f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn)) { 3414f8829a4aSRandall Stewart /* 3415f8829a4aSRandall Stewart * Strike the TSN, since this ack is 3416f8829a4aSRandall Stewart * beyond where things were when we 3417f8829a4aSRandall Stewart * did a FR. 3418f8829a4aSRandall Stewart */ 3419b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3420f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3421f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3422f8829a4aSRandall Stewart tp1->sent, 3423f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 342480fefe0aSRandall Stewart } 34255e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3426f8829a4aSRandall Stewart tp1->sent++; 34275e54f665SRandall Stewart } 3428f8829a4aSRandall Stewart strike_flag = 1; 3429b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3430f8829a4aSRandall Stewart /* 3431f8829a4aSRandall Stewart * CMT DAC algorithm: If 3432f8829a4aSRandall Stewart * SACK flag is set to 0, 3433f8829a4aSRandall Stewart * then lowest_newack test 3434f8829a4aSRandall Stewart * will not pass because it 3435f8829a4aSRandall Stewart * would have been set to 3436f8829a4aSRandall Stewart * the cumack earlier. If 3437f8829a4aSRandall Stewart * not already to be rtx'd, 3438f8829a4aSRandall Stewart * If not a mixed sack and 3439f8829a4aSRandall Stewart * if tp1 is not between two 3440f8829a4aSRandall Stewart * sacked TSNs, then mark by 3441c105859eSRandall Stewart * one more. NOTE that we 3442c105859eSRandall Stewart * are marking by one 3443c105859eSRandall Stewart * additional time since the 3444c105859eSRandall Stewart * SACK DAC flag indicates 3445c105859eSRandall Stewart * that two packets have 3446c105859eSRandall Stewart * been received after this 3447c105859eSRandall Stewart * missing TSN. 3448f8829a4aSRandall Stewart */ 34495e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && 34505e54f665SRandall Stewart (num_dests_sacked == 1) && 34515e54f665SRandall Stewart compare_with_wrap(this_sack_lowest_newack, 34525e54f665SRandall Stewart tp1->rec.data.TSN_seq, MAX_TSN)) { 3453b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3454f8829a4aSRandall Stewart sctp_log_fr(32 + num_dests_sacked, 3455f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3456f8829a4aSRandall Stewart tp1->sent, 3457f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 345880fefe0aSRandall Stewart } 34595e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3460f8829a4aSRandall Stewart tp1->sent++; 34615e54f665SRandall Stewart } 3462f8829a4aSRandall Stewart } 3463f8829a4aSRandall Stewart } 3464f8829a4aSRandall Stewart } 3465f8829a4aSRandall Stewart } 3466f8829a4aSRandall Stewart /* 346742551e99SRandall Stewart * JRI: TODO: remove code for HTNA algo. CMT's SFR 346842551e99SRandall Stewart * algo covers HTNA. 3469f8829a4aSRandall Stewart */ 3470f8829a4aSRandall Stewart } else if (compare_with_wrap(tp1->rec.data.TSN_seq, 3471f8829a4aSRandall Stewart biggest_tsn_newly_acked, MAX_TSN)) { 3472f8829a4aSRandall Stewart /* 3473f8829a4aSRandall Stewart * We don't strike these: This is the HTNA 3474f8829a4aSRandall Stewart * algorithm i.e. we don't strike If our TSN is 3475f8829a4aSRandall Stewart * larger than the Highest TSN Newly Acked. 3476f8829a4aSRandall Stewart */ 3477f8829a4aSRandall Stewart ; 3478f8829a4aSRandall Stewart } else { 3479f8829a4aSRandall Stewart /* Strike the TSN */ 3480b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3481f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3482f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3483f8829a4aSRandall Stewart tp1->sent, 3484f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 348580fefe0aSRandall Stewart } 34865e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3487f8829a4aSRandall Stewart tp1->sent++; 34885e54f665SRandall Stewart } 3489b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3490f8829a4aSRandall Stewart /* 3491f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK flag is set to 3492f8829a4aSRandall Stewart * 0, then lowest_newack test will not pass 3493f8829a4aSRandall Stewart * because it would have been set to the 3494f8829a4aSRandall Stewart * cumack earlier. If not already to be 3495f8829a4aSRandall Stewart * rtx'd, If not a mixed sack and if tp1 is 3496f8829a4aSRandall Stewart * not between two sacked TSNs, then mark by 3497c105859eSRandall Stewart * one more. NOTE that we are marking by one 3498c105859eSRandall Stewart * additional time since the SACK DAC flag 3499c105859eSRandall Stewart * indicates that two packets have been 3500c105859eSRandall Stewart * received after this missing TSN. 3501f8829a4aSRandall Stewart */ 35025e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && 3503f8829a4aSRandall Stewart compare_with_wrap(this_sack_lowest_newack, tp1->rec.data.TSN_seq, MAX_TSN)) { 3504b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3505f8829a4aSRandall Stewart sctp_log_fr(48 + num_dests_sacked, 3506f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3507f8829a4aSRandall Stewart tp1->sent, 3508f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 350980fefe0aSRandall Stewart } 3510f8829a4aSRandall Stewart tp1->sent++; 3511f8829a4aSRandall Stewart } 3512f8829a4aSRandall Stewart } 3513f8829a4aSRandall Stewart } 3514f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 3515f8829a4aSRandall Stewart struct sctp_nets *alt; 3516f8829a4aSRandall Stewart 3517544e35bdSRandall Stewart /* fix counts and things */ 3518544e35bdSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3519544e35bdSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND, 3520544e35bdSRandall Stewart (tp1->whoTo ? (tp1->whoTo->flight_size) : 0), 3521544e35bdSRandall Stewart tp1->book_size, 3522544e35bdSRandall Stewart (uintptr_t) tp1->whoTo, 3523544e35bdSRandall Stewart tp1->rec.data.TSN_seq); 3524544e35bdSRandall Stewart } 3525544e35bdSRandall Stewart if (tp1->whoTo) { 3526544e35bdSRandall Stewart tp1->whoTo->net_ack++; 3527544e35bdSRandall Stewart sctp_flight_size_decrease(tp1); 3528544e35bdSRandall Stewart } 3529544e35bdSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 3530544e35bdSRandall Stewart sctp_log_rwnd(SCTP_INCREASE_PEER_RWND, 3531544e35bdSRandall Stewart asoc->peers_rwnd, tp1->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 3532544e35bdSRandall Stewart } 3533544e35bdSRandall Stewart /* add back to the rwnd */ 3534544e35bdSRandall Stewart asoc->peers_rwnd += (tp1->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 3535544e35bdSRandall Stewart 3536544e35bdSRandall Stewart /* remove from the total flight */ 3537544e35bdSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 3538544e35bdSRandall Stewart 3539475d0674SMichael Tuexen if ((stcb->asoc.peer_supports_prsctp) && 3540475d0674SMichael Tuexen (PR_SCTP_RTX_ENABLED(tp1->flags))) { 3541475d0674SMichael Tuexen /* 3542475d0674SMichael Tuexen * Has it been retransmitted tv_sec times? - 3543475d0674SMichael Tuexen * we store the retran count there. 3544475d0674SMichael Tuexen */ 3545475d0674SMichael Tuexen if (tp1->snd_count > tp1->rec.data.timetodrop.tv_sec) { 3546475d0674SMichael Tuexen /* Yes, so drop it */ 3547475d0674SMichael Tuexen if (tp1->data != NULL) { 3548475d0674SMichael Tuexen (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3549475d0674SMichael Tuexen (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 3550475d0674SMichael Tuexen SCTP_SO_NOT_LOCKED); 3551475d0674SMichael Tuexen } 3552475d0674SMichael Tuexen /* Make sure to flag we had a FR */ 3553475d0674SMichael Tuexen tp1->whoTo->net_ack++; 3554475d0674SMichael Tuexen tp1 = TAILQ_NEXT(tp1, sctp_next); 3555475d0674SMichael Tuexen continue; 3556475d0674SMichael Tuexen } 3557475d0674SMichael Tuexen } 3558f8829a4aSRandall Stewart /* printf("OK, we are now ready to FR this guy\n"); */ 3559b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3560f8829a4aSRandall Stewart sctp_log_fr(tp1->rec.data.TSN_seq, tp1->snd_count, 3561f8829a4aSRandall Stewart 0, SCTP_FR_MARKED); 356280fefe0aSRandall Stewart } 3563f8829a4aSRandall Stewart if (strike_flag) { 3564f8829a4aSRandall Stewart /* This is a subsequent FR */ 3565f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_sendmultfastretrans); 3566f8829a4aSRandall Stewart } 35675e54f665SRandall Stewart sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); 3568b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) { 3569f8829a4aSRandall Stewart /* 3570f8829a4aSRandall Stewart * CMT: Using RTX_SSTHRESH policy for CMT. 3571f8829a4aSRandall Stewart * If CMT is being used, then pick dest with 3572f8829a4aSRandall Stewart * largest ssthresh for any retransmission. 3573f8829a4aSRandall Stewart */ 3574f8829a4aSRandall Stewart tp1->no_fr_allowed = 1; 3575f8829a4aSRandall Stewart alt = tp1->whoTo; 35763c503c28SRandall Stewart /* sa_ignore NO_NULL_CHK */ 3577b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_pf)) { 3578b54d3a6cSRandall Stewart /* 3579b54d3a6cSRandall Stewart * JRS 5/18/07 - If CMT PF is on, 3580b54d3a6cSRandall Stewart * use the PF version of 3581b54d3a6cSRandall Stewart * find_alt_net() 3582b54d3a6cSRandall Stewart */ 3583b54d3a6cSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 2); 3584b54d3a6cSRandall Stewart } else { 3585b54d3a6cSRandall Stewart /* 3586b54d3a6cSRandall Stewart * JRS 5/18/07 - If only CMT is on, 3587b54d3a6cSRandall Stewart * use the CMT version of 3588b54d3a6cSRandall Stewart * find_alt_net() 3589b54d3a6cSRandall Stewart */ 359052be287eSRandall Stewart /* sa_ignore NO_NULL_CHK */ 3591f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 1); 3592b54d3a6cSRandall Stewart } 3593ad81507eSRandall Stewart if (alt == NULL) { 3594ad81507eSRandall Stewart alt = tp1->whoTo; 3595ad81507eSRandall Stewart } 3596f8829a4aSRandall Stewart /* 3597f8829a4aSRandall Stewart * CUCv2: If a different dest is picked for 3598f8829a4aSRandall Stewart * the retransmission, then new 3599f8829a4aSRandall Stewart * (rtx-)pseudo_cumack needs to be tracked 3600f8829a4aSRandall Stewart * for orig dest. Let CUCv2 track new (rtx-) 3601f8829a4aSRandall Stewart * pseudo-cumack always. 3602f8829a4aSRandall Stewart */ 3603ad81507eSRandall Stewart if (tp1->whoTo) { 3604f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 3605f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 3606ad81507eSRandall Stewart } 3607f8829a4aSRandall Stewart } else {/* CMT is OFF */ 3608f8829a4aSRandall Stewart 3609f8829a4aSRandall Stewart #ifdef SCTP_FR_TO_ALTERNATE 3610f8829a4aSRandall Stewart /* Can we find an alternate? */ 3611f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, tp1->whoTo, 0); 3612f8829a4aSRandall Stewart #else 3613f8829a4aSRandall Stewart /* 3614f8829a4aSRandall Stewart * default behavior is to NOT retransmit 3615f8829a4aSRandall Stewart * FR's to an alternate. Armando Caro's 3616f8829a4aSRandall Stewart * paper details why. 3617f8829a4aSRandall Stewart */ 3618f8829a4aSRandall Stewart alt = tp1->whoTo; 3619f8829a4aSRandall Stewart #endif 3620f8829a4aSRandall Stewart } 3621f8829a4aSRandall Stewart 3622f8829a4aSRandall Stewart tp1->rec.data.doing_fast_retransmit = 1; 3623f8829a4aSRandall Stewart tot_retrans++; 3624f8829a4aSRandall Stewart /* mark the sending seq for possible subsequent FR's */ 3625f8829a4aSRandall Stewart /* 3626f8829a4aSRandall Stewart * printf("Marking TSN for FR new value %x\n", 3627f8829a4aSRandall Stewart * (uint32_t)tpi->rec.data.TSN_seq); 3628f8829a4aSRandall Stewart */ 3629f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue)) { 3630f8829a4aSRandall Stewart /* 3631f8829a4aSRandall Stewart * If the queue of send is empty then its 3632f8829a4aSRandall Stewart * the next sequence number that will be 3633f8829a4aSRandall Stewart * assigned so we subtract one from this to 3634f8829a4aSRandall Stewart * get the one we last sent. 3635f8829a4aSRandall Stewart */ 3636f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = sending_seq; 3637f8829a4aSRandall Stewart } else { 3638f8829a4aSRandall Stewart /* 3639f8829a4aSRandall Stewart * If there are chunks on the send queue 3640f8829a4aSRandall Stewart * (unsent data that has made it from the 3641f8829a4aSRandall Stewart * stream queues but not out the door, we 3642f8829a4aSRandall Stewart * take the first one (which will have the 3643f8829a4aSRandall Stewart * lowest TSN) and subtract one to get the 3644f8829a4aSRandall Stewart * one we last sent. 3645f8829a4aSRandall Stewart */ 3646f8829a4aSRandall Stewart struct sctp_tmit_chunk *ttt; 3647f8829a4aSRandall Stewart 3648f8829a4aSRandall Stewart ttt = TAILQ_FIRST(&asoc->send_queue); 3649f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = 3650f8829a4aSRandall Stewart ttt->rec.data.TSN_seq; 3651f8829a4aSRandall Stewart } 3652f8829a4aSRandall Stewart 3653f8829a4aSRandall Stewart if (tp1->do_rtt) { 3654f8829a4aSRandall Stewart /* 3655f8829a4aSRandall Stewart * this guy had a RTO calculation pending on 3656f8829a4aSRandall Stewart * it, cancel it 3657f8829a4aSRandall Stewart */ 3658f8829a4aSRandall Stewart tp1->do_rtt = 0; 3659f8829a4aSRandall Stewart } 3660f8829a4aSRandall Stewart if (alt != tp1->whoTo) { 3661f8829a4aSRandall Stewart /* yes, there is an alternate. */ 3662f8829a4aSRandall Stewart sctp_free_remote_addr(tp1->whoTo); 36633c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 3664f8829a4aSRandall Stewart tp1->whoTo = alt; 3665f8829a4aSRandall Stewart atomic_add_int(&alt->ref_count, 1); 3666f8829a4aSRandall Stewart } 3667f8829a4aSRandall Stewart } 3668f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3669f8829a4aSRandall Stewart } /* while (tp1) */ 3670f8829a4aSRandall Stewart 3671f8829a4aSRandall Stewart if (tot_retrans > 0) { 3672f8829a4aSRandall Stewart /* 3673f8829a4aSRandall Stewart * Setup the ecn nonce re-sync point. We do this since once 3674f8829a4aSRandall Stewart * we go to FR something we introduce a Karn's rule scenario 3675f8829a4aSRandall Stewart * and won't know the totals for the ECN bits. 3676f8829a4aSRandall Stewart */ 3677f8829a4aSRandall Stewart asoc->nonce_resync_tsn = sending_seq; 3678f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 0; 3679f8829a4aSRandall Stewart asoc->nonce_sum_check = 0; 3680f8829a4aSRandall Stewart } 3681f8829a4aSRandall Stewart } 3682f8829a4aSRandall Stewart 3683f8829a4aSRandall Stewart struct sctp_tmit_chunk * 3684f8829a4aSRandall Stewart sctp_try_advance_peer_ack_point(struct sctp_tcb *stcb, 3685f8829a4aSRandall Stewart struct sctp_association *asoc) 3686f8829a4aSRandall Stewart { 3687f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2, *a_adv = NULL; 3688f8829a4aSRandall Stewart struct timeval now; 3689f8829a4aSRandall Stewart int now_filled = 0; 3690f8829a4aSRandall Stewart 3691f8829a4aSRandall Stewart if (asoc->peer_supports_prsctp == 0) { 3692f8829a4aSRandall Stewart return (NULL); 3693f8829a4aSRandall Stewart } 3694f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3695f8829a4aSRandall Stewart while (tp1) { 3696f8829a4aSRandall Stewart if (tp1->sent != SCTP_FORWARD_TSN_SKIP && 36977898f408SRandall Stewart tp1->sent != SCTP_DATAGRAM_ACKED && 3698f8829a4aSRandall Stewart tp1->sent != SCTP_DATAGRAM_RESEND) { 3699f8829a4aSRandall Stewart /* no chance to advance, out of here */ 3700f8829a4aSRandall Stewart break; 3701f8829a4aSRandall Stewart } 37020c0982b8SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { 37030c0982b8SRandall Stewart if (tp1->sent == SCTP_FORWARD_TSN_SKIP) { 37040c0982b8SRandall Stewart sctp_misc_ints(SCTP_FWD_TSN_CHECK, 37050c0982b8SRandall Stewart asoc->advanced_peer_ack_point, 37060c0982b8SRandall Stewart tp1->rec.data.TSN_seq, 0, 0); 37070c0982b8SRandall Stewart } 37080c0982b8SRandall Stewart } 3709f8829a4aSRandall Stewart if (!PR_SCTP_ENABLED(tp1->flags)) { 3710f8829a4aSRandall Stewart /* 3711f8829a4aSRandall Stewart * We can't fwd-tsn past any that are reliable aka 3712f8829a4aSRandall Stewart * retransmitted until the asoc fails. 3713f8829a4aSRandall Stewart */ 3714f8829a4aSRandall Stewart break; 3715f8829a4aSRandall Stewart } 3716f8829a4aSRandall Stewart if (!now_filled) { 37176e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 3718f8829a4aSRandall Stewart now_filled = 1; 3719f8829a4aSRandall Stewart } 3720f8829a4aSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 3721f8829a4aSRandall Stewart /* 3722f8829a4aSRandall Stewart * now we got a chunk which is marked for another 3723f8829a4aSRandall Stewart * retransmission to a PR-stream but has run out its chances 3724f8829a4aSRandall Stewart * already maybe OR has been marked to skip now. Can we skip 3725f8829a4aSRandall Stewart * it if its a resend? 3726f8829a4aSRandall Stewart */ 3727f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND && 3728f8829a4aSRandall Stewart (PR_SCTP_TTL_ENABLED(tp1->flags))) { 3729f8829a4aSRandall Stewart /* 3730f8829a4aSRandall Stewart * Now is this one marked for resend and its time is 3731f8829a4aSRandall Stewart * now up? 3732f8829a4aSRandall Stewart */ 3733f8829a4aSRandall Stewart if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) { 3734f8829a4aSRandall Stewart /* Yes so drop it */ 3735f8829a4aSRandall Stewart if (tp1->data) { 3736ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3737f8829a4aSRandall Stewart (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 37380c0982b8SRandall Stewart SCTP_SO_NOT_LOCKED); 3739f8829a4aSRandall Stewart } 3740f8829a4aSRandall Stewart } else { 3741f8829a4aSRandall Stewart /* 3742f8829a4aSRandall Stewart * No, we are done when hit one for resend 3743f8829a4aSRandall Stewart * whos time as not expired. 3744f8829a4aSRandall Stewart */ 3745f8829a4aSRandall Stewart break; 3746f8829a4aSRandall Stewart } 3747f8829a4aSRandall Stewart } 3748f8829a4aSRandall Stewart /* 3749f8829a4aSRandall Stewart * Ok now if this chunk is marked to drop it we can clean up 3750f8829a4aSRandall Stewart * the chunk, advance our peer ack point and we can check 3751f8829a4aSRandall Stewart * the next chunk. 3752f8829a4aSRandall Stewart */ 375383128708SRandall Stewart if ((tp1->sent == SCTP_FORWARD_TSN_SKIP) || 375483128708SRandall Stewart (tp1->sent == SCTP_DATAGRAM_ACKED)) { 3755f8829a4aSRandall Stewart /* advance PeerAckPoint goes forward */ 37560c0982b8SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 37570c0982b8SRandall Stewart asoc->advanced_peer_ack_point, 37580c0982b8SRandall Stewart MAX_TSN)) { 37590c0982b8SRandall Stewart 3760f8829a4aSRandall Stewart asoc->advanced_peer_ack_point = tp1->rec.data.TSN_seq; 3761f8829a4aSRandall Stewart a_adv = tp1; 37620c0982b8SRandall Stewart } else if (tp1->rec.data.TSN_seq == asoc->advanced_peer_ack_point) { 37630c0982b8SRandall Stewart /* No update but we do save the chk */ 37640c0982b8SRandall Stewart a_adv = tp1; 37650c0982b8SRandall Stewart } 3766f8829a4aSRandall Stewart } else { 3767f8829a4aSRandall Stewart /* 3768f8829a4aSRandall Stewart * If it is still in RESEND we can advance no 3769f8829a4aSRandall Stewart * further 3770f8829a4aSRandall Stewart */ 3771f8829a4aSRandall Stewart break; 3772f8829a4aSRandall Stewart } 3773f8829a4aSRandall Stewart /* 3774f8829a4aSRandall Stewart * If we hit here we just dumped tp1, move to next tsn on 3775f8829a4aSRandall Stewart * sent queue. 3776f8829a4aSRandall Stewart */ 3777f8829a4aSRandall Stewart tp1 = tp2; 3778f8829a4aSRandall Stewart } 3779f8829a4aSRandall Stewart return (a_adv); 3780f8829a4aSRandall Stewart } 3781f8829a4aSRandall Stewart 37820c0982b8SRandall Stewart static int 3783c105859eSRandall Stewart sctp_fs_audit(struct sctp_association *asoc) 3784bff64a4dSRandall Stewart { 3785bff64a4dSRandall Stewart struct sctp_tmit_chunk *chk; 3786bff64a4dSRandall Stewart int inflight = 0, resend = 0, inbetween = 0, acked = 0, above = 0; 37870c0982b8SRandall Stewart int entry_flight, entry_cnt, ret; 37880c0982b8SRandall Stewart 37890c0982b8SRandall Stewart entry_flight = asoc->total_flight; 37900c0982b8SRandall Stewart entry_cnt = asoc->total_flight_count; 37910c0982b8SRandall Stewart ret = 0; 37920c0982b8SRandall Stewart 37930c0982b8SRandall Stewart if (asoc->pr_sctp_cnt >= asoc->sent_queue_cnt) 37940c0982b8SRandall Stewart return (0); 3795bff64a4dSRandall Stewart 3796bff64a4dSRandall Stewart TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { 3797bff64a4dSRandall Stewart if (chk->sent < SCTP_DATAGRAM_RESEND) { 37980c0982b8SRandall Stewart printf("Chk TSN:%u size:%d inflight cnt:%d\n", 37990c0982b8SRandall Stewart chk->rec.data.TSN_seq, 38000c0982b8SRandall Stewart chk->send_size, 38010c0982b8SRandall Stewart chk->snd_count 38020c0982b8SRandall Stewart ); 3803bff64a4dSRandall Stewart inflight++; 3804bff64a4dSRandall Stewart } else if (chk->sent == SCTP_DATAGRAM_RESEND) { 3805bff64a4dSRandall Stewart resend++; 3806bff64a4dSRandall Stewart } else if (chk->sent < SCTP_DATAGRAM_ACKED) { 3807bff64a4dSRandall Stewart inbetween++; 3808bff64a4dSRandall Stewart } else if (chk->sent > SCTP_DATAGRAM_ACKED) { 3809bff64a4dSRandall Stewart above++; 3810bff64a4dSRandall Stewart } else { 3811bff64a4dSRandall Stewart acked++; 3812bff64a4dSRandall Stewart } 3813bff64a4dSRandall Stewart } 3814f1f73e57SRandall Stewart 3815c105859eSRandall Stewart if ((inflight > 0) || (inbetween > 0)) { 3816f1f73e57SRandall Stewart #ifdef INVARIANTS 3817c105859eSRandall Stewart panic("Flight size-express incorrect? \n"); 3818f1f73e57SRandall Stewart #else 38190c0982b8SRandall Stewart printf("asoc->total_flight:%d cnt:%d\n", 38200c0982b8SRandall Stewart entry_flight, entry_cnt); 38210c0982b8SRandall Stewart 38220c0982b8SRandall Stewart SCTP_PRINTF("Flight size-express incorrect F:%d I:%d R:%d Ab:%d ACK:%d\n", 38230c0982b8SRandall Stewart inflight, inbetween, resend, above, acked); 38240c0982b8SRandall Stewart ret = 1; 3825f1f73e57SRandall Stewart #endif 3826bff64a4dSRandall Stewart } 38270c0982b8SRandall Stewart return (ret); 3828c105859eSRandall Stewart } 3829c105859eSRandall Stewart 3830c105859eSRandall Stewart 3831c105859eSRandall Stewart static void 3832c105859eSRandall Stewart sctp_window_probe_recovery(struct sctp_tcb *stcb, 3833c105859eSRandall Stewart struct sctp_association *asoc, 3834c105859eSRandall Stewart struct sctp_nets *net, 3835c105859eSRandall Stewart struct sctp_tmit_chunk *tp1) 3836c105859eSRandall Stewart { 3837dfb11ef8SRandall Stewart tp1->window_probe = 0; 38385171328bSRandall Stewart if ((tp1->sent >= SCTP_DATAGRAM_ACKED) || (tp1->data == NULL)) { 3839dfb11ef8SRandall Stewart /* TSN's skipped we do NOT move back. */ 3840dfb11ef8SRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DWN_WP_FWD, 3841dfb11ef8SRandall Stewart tp1->whoTo->flight_size, 3842dfb11ef8SRandall Stewart tp1->book_size, 3843dfb11ef8SRandall Stewart (uintptr_t) tp1->whoTo, 3844dfb11ef8SRandall Stewart tp1->rec.data.TSN_seq); 3845dfb11ef8SRandall Stewart return; 3846dfb11ef8SRandall Stewart } 38475171328bSRandall Stewart /* First setup this by shrinking flight */ 38485171328bSRandall Stewart sctp_flight_size_decrease(tp1); 38495171328bSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 38505171328bSRandall Stewart /* Now mark for resend */ 38515171328bSRandall Stewart tp1->sent = SCTP_DATAGRAM_RESEND; 3852*791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 3853*791437b5SRandall Stewart 3854b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3855c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_WP, 3856c105859eSRandall Stewart tp1->whoTo->flight_size, 3857c105859eSRandall Stewart tp1->book_size, 3858c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3859c105859eSRandall Stewart tp1->rec.data.TSN_seq); 386080fefe0aSRandall Stewart } 3861c105859eSRandall Stewart } 3862c105859eSRandall Stewart 3863f8829a4aSRandall Stewart void 3864f8829a4aSRandall Stewart sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, 3865f8829a4aSRandall Stewart uint32_t rwnd, int nonce_sum_flag, int *abort_now) 3866f8829a4aSRandall Stewart { 3867f8829a4aSRandall Stewart struct sctp_nets *net; 3868f8829a4aSRandall Stewart struct sctp_association *asoc; 3869f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 38705e54f665SRandall Stewart uint32_t old_rwnd; 38715e54f665SRandall Stewart int win_probe_recovery = 0; 3872c105859eSRandall Stewart int win_probe_recovered = 0; 3873d06c82f1SRandall Stewart int j, done_once = 0; 3874f8829a4aSRandall Stewart 3875b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 3876d06c82f1SRandall Stewart sctp_misc_ints(SCTP_SACK_LOG_EXPRESS, cumack, 3877d06c82f1SRandall Stewart rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 387880fefe0aSRandall Stewart } 3879f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 388018e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 388118e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cumack; 388218e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 388318e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 388418e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 388518e198d3SRandall Stewart } 388618e198d3SRandall Stewart #endif 3887f8829a4aSRandall Stewart asoc = &stcb->asoc; 3888d06c82f1SRandall Stewart old_rwnd = asoc->peers_rwnd; 38895e54f665SRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, cumack, MAX_TSN)) { 38905e54f665SRandall Stewart /* old ack */ 38915e54f665SRandall Stewart return; 3892d06c82f1SRandall Stewart } else if (asoc->last_acked_seq == cumack) { 3893d06c82f1SRandall Stewart /* Window update sack */ 3894d06c82f1SRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 3895b3f1ea41SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 3896d06c82f1SRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 3897d06c82f1SRandall Stewart /* SWS sender side engages */ 3898d06c82f1SRandall Stewart asoc->peers_rwnd = 0; 3899d06c82f1SRandall Stewart } 3900d06c82f1SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 3901d06c82f1SRandall Stewart goto again; 3902d06c82f1SRandall Stewart } 3903d06c82f1SRandall Stewart return; 39045e54f665SRandall Stewart } 3905f8829a4aSRandall Stewart /* First setup for CC stuff */ 3906f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 3907f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 3908f8829a4aSRandall Stewart net->net_ack = 0; 3909f8829a4aSRandall Stewart net->net_ack2 = 0; 3910132dea7dSRandall Stewart 3911132dea7dSRandall Stewart /* 3912132dea7dSRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 3913132dea7dSRandall Stewart * SACK processing 3914132dea7dSRandall Stewart */ 3915132dea7dSRandall Stewart net->new_pseudo_cumack = 0; 3916132dea7dSRandall Stewart net->will_exit_fast_recovery = 0; 3917f8829a4aSRandall Stewart } 3918b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 3919139bc87fSRandall Stewart uint32_t send_s; 3920139bc87fSRandall Stewart 3921c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 3922c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 3923c105859eSRandall Stewart sctpchunk_listhead); 3924c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 3925139bc87fSRandall Stewart } else { 3926c105859eSRandall Stewart send_s = asoc->sending_seq; 3927139bc87fSRandall Stewart } 3928139bc87fSRandall Stewart if ((cumack == send_s) || 3929139bc87fSRandall Stewart compare_with_wrap(cumack, send_s, MAX_TSN)) { 3930c105859eSRandall Stewart #ifndef INVARIANTS 3931139bc87fSRandall Stewart struct mbuf *oper; 3932139bc87fSRandall Stewart 3933c105859eSRandall Stewart #endif 3934c105859eSRandall Stewart #ifdef INVARIANTS 3935c105859eSRandall Stewart panic("Impossible sack 1"); 3936c105859eSRandall Stewart #else 3937b5c16493SMichael Tuexen 3938139bc87fSRandall Stewart *abort_now = 1; 3939139bc87fSRandall Stewart /* XXX */ 3940139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 3941139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 3942139bc87fSRandall Stewart if (oper) { 3943139bc87fSRandall Stewart struct sctp_paramhdr *ph; 3944139bc87fSRandall Stewart uint32_t *ippp; 3945139bc87fSRandall Stewart 3946139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 3947139bc87fSRandall Stewart sizeof(uint32_t); 3948139bc87fSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 3949139bc87fSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 3950139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 3951139bc87fSRandall Stewart ippp = (uint32_t *) (ph + 1); 3952139bc87fSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 3953139bc87fSRandall Stewart } 3954139bc87fSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 3955ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 3956139bc87fSRandall Stewart return; 3957139bc87fSRandall Stewart #endif 3958139bc87fSRandall Stewart } 3959139bc87fSRandall Stewart } 3960f8829a4aSRandall Stewart asoc->this_sack_highest_gap = cumack; 3961b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 3962c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 3963c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 3964c4739e2fSRandall Stewart 0, 3965c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 3966c4739e2fSRandall Stewart __LINE__); 3967c4739e2fSRandall Stewart } 3968f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 39695e54f665SRandall Stewart if (compare_with_wrap(cumack, asoc->last_acked_seq, MAX_TSN)) { 3970f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 3971f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3972f8829a4aSRandall Stewart while (tp1) { 3973f8829a4aSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 3974f8829a4aSRandall Stewart if (compare_with_wrap(cumack, tp1->rec.data.TSN_seq, 3975f8829a4aSRandall Stewart MAX_TSN) || 3976f8829a4aSRandall Stewart cumack == tp1->rec.data.TSN_seq) { 397718e198d3SRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 397818e198d3SRandall Stewart printf("Warning, an unsent is now acked?\n"); 397918e198d3SRandall Stewart } 3980f8829a4aSRandall Stewart /* 398118e198d3SRandall Stewart * ECN Nonce: Add the nonce to the sender's 398218e198d3SRandall Stewart * nonce sum 3983f8829a4aSRandall Stewart */ 3984f8829a4aSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 3985f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 3986f8829a4aSRandall Stewart /* 398718e198d3SRandall Stewart * If it is less than ACKED, it is 398818e198d3SRandall Stewart * now no-longer in flight. Higher 398918e198d3SRandall Stewart * values may occur during marking 3990f8829a4aSRandall Stewart */ 3991c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3992b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3993c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 3994a5d547adSRandall Stewart tp1->whoTo->flight_size, 3995a5d547adSRandall Stewart tp1->book_size, 3996c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3997a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 399880fefe0aSRandall Stewart } 3999c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 400004ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4001c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 4002f8829a4aSRandall Stewart } 4003f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 4004f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 4005f8829a4aSRandall Stewart /* 400618e198d3SRandall Stewart * True non-retransmited 4007f8829a4aSRandall Stewart * chunk 4008f8829a4aSRandall Stewart */ 4009f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 4010f8829a4aSRandall Stewart tp1->send_size; 4011f8829a4aSRandall Stewart 4012f8829a4aSRandall Stewart /* update RTO too? */ 401362c1ff9cSRandall Stewart if (tp1->do_rtt) { 4014f8829a4aSRandall Stewart tp1->whoTo->RTO = 401504ee05e8SRandall Stewart /* 401604ee05e8SRandall Stewart * sa_ignore 401704ee05e8SRandall Stewart * NO_NULL_CHK 401804ee05e8SRandall Stewart */ 4019f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 4020f8829a4aSRandall Stewart asoc, tp1->whoTo, 402118e198d3SRandall Stewart &tp1->sent_rcv_time, 402218e198d3SRandall Stewart sctp_align_safe_nocopy); 4023f8829a4aSRandall Stewart tp1->do_rtt = 0; 4024f8829a4aSRandall Stewart } 4025f8829a4aSRandall Stewart } 4026132dea7dSRandall Stewart /* 402718e198d3SRandall Stewart * CMT: CUCv2 algorithm. From the 402818e198d3SRandall Stewart * cumack'd TSNs, for each TSN being 402918e198d3SRandall Stewart * acked for the first time, set the 403018e198d3SRandall Stewart * following variables for the 403118e198d3SRandall Stewart * corresp destination. 403218e198d3SRandall Stewart * new_pseudo_cumack will trigger a 403318e198d3SRandall Stewart * cwnd update. 403418e198d3SRandall Stewart * find_(rtx_)pseudo_cumack will 403518e198d3SRandall Stewart * trigger search for the next 403618e198d3SRandall Stewart * expected (rtx-)pseudo-cumack. 4037132dea7dSRandall Stewart */ 4038132dea7dSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 4039132dea7dSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 4040132dea7dSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 4041132dea7dSRandall Stewart 4042b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 404304ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4044f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 404580fefe0aSRandall Stewart } 4046f8829a4aSRandall Stewart } 4047f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4048f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 4049f8829a4aSRandall Stewart } 405042551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 405142551e99SRandall Stewart /* deflate the cwnd */ 405242551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 405342551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 405442551e99SRandall Stewart } 4055f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 4056f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 4057f8829a4aSRandall Stewart if (tp1->data) { 405804ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4059f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 4060f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 4061f8829a4aSRandall Stewart } 4062b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4063f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4064f8829a4aSRandall Stewart cumack, 4065f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4066f8829a4aSRandall Stewart 0, 4067f8829a4aSRandall Stewart 0, 4068f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 406980fefe0aSRandall Stewart } 4070f8829a4aSRandall Stewart tp1->data = NULL; 4071f8829a4aSRandall Stewart asoc->sent_queue_cnt--; 4072f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, tp1); 4073f8829a4aSRandall Stewart tp1 = tp2; 407418e198d3SRandall Stewart } else { 407518e198d3SRandall Stewart break; 4076f8829a4aSRandall Stewart } 40775e54f665SRandall Stewart } 407818e198d3SRandall Stewart 407918e198d3SRandall Stewart } 408004ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4081f8829a4aSRandall Stewart if (stcb->sctp_socket) { 4082ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4083ceaad40aSRandall Stewart struct socket *so; 4084ceaad40aSRandall Stewart 4085ceaad40aSRandall Stewart #endif 4086f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 4087b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 408804ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4089f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_WAKESND_FROM_SACK); 409080fefe0aSRandall Stewart } 4091ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4092ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 4093ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 4094ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 4095ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 4096ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 4097ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 4098ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 4099ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 4100ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4101ceaad40aSRandall Stewart return; 4102ceaad40aSRandall Stewart } 4103ceaad40aSRandall Stewart #endif 4104f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 4105ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4106ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4107ceaad40aSRandall Stewart #endif 4108f8829a4aSRandall Stewart } else { 4109b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4110f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_NOWAKE_FROM_SACK); 411180fefe0aSRandall Stewart } 4112f8829a4aSRandall Stewart } 4113f8829a4aSRandall Stewart 4114b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4115f8829a4aSRandall Stewart if (asoc->last_acked_seq != cumack) 4116b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, 1, 0, 0); 41175e54f665SRandall Stewart 4118f8829a4aSRandall Stewart asoc->last_acked_seq = cumack; 41195e54f665SRandall Stewart 4120f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 4121f8829a4aSRandall Stewart /* nothing left in-flight */ 4122f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4123f8829a4aSRandall Stewart net->flight_size = 0; 4124f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4125f8829a4aSRandall Stewart } 4126f8829a4aSRandall Stewart asoc->total_flight = 0; 4127f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4128f8829a4aSRandall Stewart } 4129f8829a4aSRandall Stewart /* ECN Nonce updates */ 4130f8829a4aSRandall Stewart if (asoc->ecn_nonce_allowed) { 4131f8829a4aSRandall Stewart if (asoc->nonce_sum_check) { 4132f8829a4aSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base) & SCTP_SACK_NONCE_SUM)) { 4133f8829a4aSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 4134f8829a4aSRandall Stewart struct sctp_tmit_chunk *lchk; 4135f8829a4aSRandall Stewart 4136f8829a4aSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 4137f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 1; 4138f8829a4aSRandall Stewart if (lchk) { 4139f8829a4aSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 4140f8829a4aSRandall Stewart } else { 4141f8829a4aSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 4142f8829a4aSRandall Stewart } 4143f8829a4aSRandall Stewart } else { 4144f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) || 4145f8829a4aSRandall Stewart (asoc->last_acked_seq == asoc->nonce_wait_tsn)) { 4146f8829a4aSRandall Stewart /* 4147f8829a4aSRandall Stewart * Misbehaving peer. We need 4148f8829a4aSRandall Stewart * to react to this guy 4149f8829a4aSRandall Stewart */ 4150f8829a4aSRandall Stewart asoc->ecn_allowed = 0; 4151f8829a4aSRandall Stewart asoc->ecn_nonce_allowed = 0; 4152f8829a4aSRandall Stewart } 4153f8829a4aSRandall Stewart } 4154f8829a4aSRandall Stewart } 4155f8829a4aSRandall Stewart } else { 4156f8829a4aSRandall Stewart /* See if Resynchronization Possible */ 4157f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) { 4158f8829a4aSRandall Stewart asoc->nonce_sum_check = 1; 4159f8829a4aSRandall Stewart /* 4160cd554309SMichael Tuexen * Now we must calculate what the base is. 4161f8829a4aSRandall Stewart * We do this based on two things, we know 4162f8829a4aSRandall Stewart * the total's for all the segments 4163cd554309SMichael Tuexen * gap-acked in the SACK (none). We also 4164f8829a4aSRandall Stewart * know the SACK's nonce sum, its in 4165f8829a4aSRandall Stewart * nonce_sum_flag. So we can build a truth 4166f8829a4aSRandall Stewart * table to back-calculate the new value of 4167f8829a4aSRandall Stewart * asoc->nonce_sum_expect_base: 4168f8829a4aSRandall Stewart * 4169f8829a4aSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 4170f8829a4aSRandall Stewart * 1 0 1 0 1 1 1 4171f8829a4aSRandall Stewart * 1 0 4172f8829a4aSRandall Stewart */ 4173f8829a4aSRandall Stewart asoc->nonce_sum_expect_base = (0 ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 4174f8829a4aSRandall Stewart } 4175f8829a4aSRandall Stewart } 4176f8829a4aSRandall Stewart } 4177f8829a4aSRandall Stewart /* RWND update */ 4178f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 4179b3f1ea41SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 4180f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4181f8829a4aSRandall Stewart /* SWS sender side engages */ 4182f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4183f8829a4aSRandall Stewart } 41845e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 41855e54f665SRandall Stewart win_probe_recovery = 1; 41865e54f665SRandall Stewart } 4187f8829a4aSRandall Stewart /* Now assure a timer where data is queued at */ 4188a5d547adSRandall Stewart again: 4189a5d547adSRandall Stewart j = 0; 4190f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 41915171328bSRandall Stewart int to_ticks; 41925171328bSRandall Stewart 41935e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 4194c105859eSRandall Stewart win_probe_recovered = 1; 41955e54f665SRandall Stewart /* 41965e54f665SRandall Stewart * Find first chunk that was used with window probe 41975e54f665SRandall Stewart * and clear the sent 41985e54f665SRandall Stewart */ 41993c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 42005e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 42015e54f665SRandall Stewart if (tp1->window_probe) { 4202cd554309SMichael Tuexen /* move back to data send queue */ 4203c105859eSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 42045e54f665SRandall Stewart break; 42055e54f665SRandall Stewart } 42065e54f665SRandall Stewart } 42075e54f665SRandall Stewart } 4208f8829a4aSRandall Stewart if (net->RTO == 0) { 4209f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto); 4210f8829a4aSRandall Stewart } else { 4211f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(net->RTO); 4212f8829a4aSRandall Stewart } 42135171328bSRandall Stewart if (net->flight_size) { 4214a5d547adSRandall Stewart j++; 4215ad81507eSRandall Stewart (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 4216f8829a4aSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 42175171328bSRandall Stewart if (net->window_probe) { 42185171328bSRandall Stewart net->window_probe = 0; 42195171328bSRandall Stewart } 4220f8829a4aSRandall Stewart } else { 42215171328bSRandall Stewart if (net->window_probe) { 42225171328bSRandall Stewart /* 42235171328bSRandall Stewart * In window probes we must assure a timer 42245171328bSRandall Stewart * is still running there 42255171328bSRandall Stewart */ 42265171328bSRandall Stewart net->window_probe = 0; 42275171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 42285171328bSRandall Stewart SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 42295171328bSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 42305171328bSRandall Stewart } 42315171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 4232f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4233a5d547adSRandall Stewart stcb, net, 4234a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 4235f8829a4aSRandall Stewart } 4236b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4237139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4238f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 4239a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4240a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 4241f8829a4aSRandall Stewart } 4242f8829a4aSRandall Stewart } 4243f8829a4aSRandall Stewart } 4244f8829a4aSRandall Stewart } 4245bff64a4dSRandall Stewart if ((j == 0) && 4246bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 4247bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 4248c105859eSRandall Stewart (win_probe_recovered == 0) && 4249bff64a4dSRandall Stewart (done_once == 0)) { 42500c0982b8SRandall Stewart /* 42510c0982b8SRandall Stewart * huh, this should not happen unless all packets are 42520c0982b8SRandall Stewart * PR-SCTP and marked to skip of course. 42530c0982b8SRandall Stewart */ 42540c0982b8SRandall Stewart if (sctp_fs_audit(asoc)) { 4255a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4256a5d547adSRandall Stewart net->flight_size = 0; 4257a5d547adSRandall Stewart } 4258a5d547adSRandall Stewart asoc->total_flight = 0; 4259a5d547adSRandall Stewart asoc->total_flight_count = 0; 4260a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4261a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4262a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4263c105859eSRandall Stewart sctp_flight_size_increase(tp1); 4264c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 4265a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4266*791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 4267a5d547adSRandall Stewart } 4268a5d547adSRandall Stewart } 42690c0982b8SRandall Stewart } 4270bff64a4dSRandall Stewart done_once = 1; 4271a5d547adSRandall Stewart goto again; 4272a5d547adSRandall Stewart } 4273f8829a4aSRandall Stewart /**********************************/ 4274f8829a4aSRandall Stewart /* Now what about shutdown issues */ 4275f8829a4aSRandall Stewart /**********************************/ 4276f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 4277f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 4278f8829a4aSRandall Stewart /* clean up */ 4279f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 4280f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 4281f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 4282f8829a4aSRandall Stewart (asoc->locked_on_sending) 4283f8829a4aSRandall Stewart ) { 4284f8829a4aSRandall Stewart struct sctp_stream_queue_pending *sp; 4285f8829a4aSRandall Stewart 4286f8829a4aSRandall Stewart /* 4287f8829a4aSRandall Stewart * I may be in a state where we got all across.. but 4288f8829a4aSRandall Stewart * cannot write more due to a shutdown... we abort 4289f8829a4aSRandall Stewart * since the user did not indicate EOR in this case. 4290f8829a4aSRandall Stewart * The sp will be cleaned during free of the asoc. 4291f8829a4aSRandall Stewart */ 4292f8829a4aSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 4293f8829a4aSRandall Stewart sctp_streamhead); 42942afb3e84SRandall Stewart if ((sp) && (sp->length == 0)) { 42952afb3e84SRandall Stewart /* Let cleanup code purge it */ 42962afb3e84SRandall Stewart if (sp->msg_is_complete) { 42972afb3e84SRandall Stewart asoc->stream_queue_cnt--; 42982afb3e84SRandall Stewart } else { 4299f8829a4aSRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 4300f8829a4aSRandall Stewart asoc->locked_on_sending = NULL; 4301f8829a4aSRandall Stewart asoc->stream_queue_cnt--; 4302f8829a4aSRandall Stewart } 4303f8829a4aSRandall Stewart } 43042afb3e84SRandall Stewart } 4305f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 4306f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4307f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4308f8829a4aSRandall Stewart /* Need to abort here */ 4309f8829a4aSRandall Stewart struct mbuf *oper; 4310f8829a4aSRandall Stewart 4311f8829a4aSRandall Stewart abort_out_now: 4312f8829a4aSRandall Stewart *abort_now = 1; 4313f8829a4aSRandall Stewart /* XXX */ 4314f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4315f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4316f8829a4aSRandall Stewart if (oper) { 4317f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 4318f8829a4aSRandall Stewart uint32_t *ippp; 4319f8829a4aSRandall Stewart 4320139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4321f8829a4aSRandall Stewart sizeof(uint32_t); 4322f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4323f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 4324139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4325f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 4326a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_24); 4327f8829a4aSRandall Stewart } 4328a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24; 4329ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 4330f8829a4aSRandall Stewart } else { 4331f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 4332f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 4333f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4334f42a358aSRandall Stewart } 4335c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 4336b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4337f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 4338f8829a4aSRandall Stewart sctp_send_shutdown(stcb, 4339f8829a4aSRandall Stewart stcb->asoc.primary_destination); 4340f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 4341f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4342f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 4343f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4344f8829a4aSRandall Stewart } 4345f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 4346f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4347f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4348f8829a4aSRandall Stewart goto abort_out_now; 4349f8829a4aSRandall Stewart } 4350f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4351c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 4352b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4353f8829a4aSRandall Stewart sctp_send_shutdown_ack(stcb, 4354f8829a4aSRandall Stewart stcb->asoc.primary_destination); 4355f8829a4aSRandall Stewart 4356f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 4357f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4358f8829a4aSRandall Stewart } 4359f8829a4aSRandall Stewart } 4360dfb11ef8SRandall Stewart /*********************************************/ 4361dfb11ef8SRandall Stewart /* Here we perform PR-SCTP procedures */ 4362dfb11ef8SRandall Stewart /* (section 4.2) */ 4363dfb11ef8SRandall Stewart /*********************************************/ 4364dfb11ef8SRandall Stewart /* C1. update advancedPeerAckPoint */ 4365dfb11ef8SRandall Stewart if (compare_with_wrap(cumack, asoc->advanced_peer_ack_point, MAX_TSN)) { 4366dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cumack; 4367dfb11ef8SRandall Stewart } 4368830d754dSRandall Stewart /* PR-Sctp issues need to be addressed too */ 4369830d754dSRandall Stewart if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) { 4370830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 4371830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 4372830d754dSRandall Stewart 4373830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 4374830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 4375830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 4376830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, cumack, 4377830d754dSRandall Stewart MAX_TSN)) { 4378830d754dSRandall Stewart /* 4379830d754dSRandall Stewart * ISSUE with ECN, see FWD-TSN processing for notes 4380830d754dSRandall Stewart * on issues that will occur when the ECN NONCE 4381830d754dSRandall Stewart * stuff is put into SCTP for cross checking. 4382830d754dSRandall Stewart */ 4383830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, old_adv_peer_ack_point, 4384830d754dSRandall Stewart MAX_TSN)) { 4385830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 4386830d754dSRandall Stewart /* 4387830d754dSRandall Stewart * ECN Nonce: Disable Nonce Sum check when 4388830d754dSRandall Stewart * FWD TSN is sent and store resync tsn 4389830d754dSRandall Stewart */ 4390830d754dSRandall Stewart asoc->nonce_sum_check = 0; 4391830d754dSRandall Stewart asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point; 43920c0982b8SRandall Stewart } else if (lchk) { 43930c0982b8SRandall Stewart /* try to FR fwd-tsn's that get lost too */ 43940c0982b8SRandall Stewart lchk->rec.data.fwd_tsn_cnt++; 43950c0982b8SRandall Stewart if (lchk->rec.data.fwd_tsn_cnt > 3) { 43960c0982b8SRandall Stewart send_forward_tsn(stcb, asoc); 43970c0982b8SRandall Stewart lchk->rec.data.fwd_tsn_cnt = 0; 43980c0982b8SRandall Stewart } 4399830d754dSRandall Stewart } 4400830d754dSRandall Stewart } 4401830d754dSRandall Stewart if (lchk) { 4402830d754dSRandall Stewart /* Assure a timer is up */ 4403830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 4404830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 4405830d754dSRandall Stewart } 4406830d754dSRandall Stewart } 4407b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 4408f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 4409f8829a4aSRandall Stewart rwnd, 4410f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 4411f8829a4aSRandall Stewart stcb->asoc.total_flight, 4412f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 441380fefe0aSRandall Stewart } 4414f8829a4aSRandall Stewart } 4415f8829a4aSRandall Stewart 4416f8829a4aSRandall Stewart void 4417cd554309SMichael Tuexen sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup, 4418cd554309SMichael Tuexen struct sctp_tcb *stcb, struct sctp_nets *net_from, 4419cd554309SMichael Tuexen uint16_t num_seg, uint16_t num_nr_seg, uint16_t num_dup, 4420cd554309SMichael Tuexen int *abort_now, uint8_t flags, 4421cd554309SMichael Tuexen uint32_t cum_ack, uint32_t rwnd) 4422f8829a4aSRandall Stewart { 4423f8829a4aSRandall Stewart struct sctp_association *asoc; 4424f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 4425cd554309SMichael Tuexen uint32_t last_tsn, biggest_tsn_acked, biggest_tsn_newly_acked, this_sack_lowest_newack; 4426bff64a4dSRandall Stewart uint32_t sav_cum_ack; 4427f8829a4aSRandall Stewart uint16_t wake_him = 0; 4428c105859eSRandall Stewart uint32_t send_s = 0; 4429f8829a4aSRandall Stewart long j; 4430f8829a4aSRandall Stewart int accum_moved = 0; 4431f8829a4aSRandall Stewart int will_exit_fast_recovery = 0; 44325e54f665SRandall Stewart uint32_t a_rwnd, old_rwnd; 44335e54f665SRandall Stewart int win_probe_recovery = 0; 4434c105859eSRandall Stewart int win_probe_recovered = 0; 4435f8829a4aSRandall Stewart struct sctp_nets *net = NULL; 4436f8829a4aSRandall Stewart int nonce_sum_flag, ecn_seg_sums = 0; 4437bff64a4dSRandall Stewart int done_once; 4438f8829a4aSRandall Stewart uint8_t reneged_all = 0; 4439f8829a4aSRandall Stewart uint8_t cmt_dac_flag; 4440f8829a4aSRandall Stewart 4441f8829a4aSRandall Stewart /* 4442f8829a4aSRandall Stewart * we take any chance we can to service our queues since we cannot 4443f8829a4aSRandall Stewart * get awoken when the socket is read from :< 4444f8829a4aSRandall Stewart */ 4445f8829a4aSRandall Stewart /* 4446f8829a4aSRandall Stewart * Now perform the actual SACK handling: 1) Verify that it is not an 4447f8829a4aSRandall Stewart * old sack, if so discard. 2) If there is nothing left in the send 4448f8829a4aSRandall Stewart * queue (cum-ack is equal to last acked) then you have a duplicate 4449f8829a4aSRandall Stewart * too, update any rwnd change and verify no timers are running. 4450f8829a4aSRandall Stewart * then return. 3) Process any new consequtive data i.e. cum-ack 4451f8829a4aSRandall Stewart * moved process these first and note that it moved. 4) Process any 4452f8829a4aSRandall Stewart * sack blocks. 5) Drop any acked from the queue. 6) Check for any 4453f8829a4aSRandall Stewart * revoked blocks and mark. 7) Update the cwnd. 8) Nothing left, 4454f8829a4aSRandall Stewart * sync up flightsizes and things, stop all timers and also check 4455f8829a4aSRandall Stewart * for shutdown_pending state. If so then go ahead and send off the 4456f8829a4aSRandall Stewart * shutdown. If in shutdown recv, send off the shutdown-ack and 4457f8829a4aSRandall Stewart * start that timer, Ret. 9) Strike any non-acked things and do FR 4458f8829a4aSRandall Stewart * procedure if needed being sure to set the FR flag. 10) Do pr-sctp 4459f8829a4aSRandall Stewart * procedures. 11) Apply any FR penalties. 12) Assure we will SACK 4460f8829a4aSRandall Stewart * if in shutdown_recv state. 4461f8829a4aSRandall Stewart */ 4462f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 4463f8829a4aSRandall Stewart /* CMT DAC algo */ 4464f8829a4aSRandall Stewart this_sack_lowest_newack = 0; 4465f8829a4aSRandall Stewart j = 0; 4466f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_slowpath_sack); 4467cd554309SMichael Tuexen last_tsn = cum_ack; 4468cd554309SMichael Tuexen nonce_sum_flag = flags & SCTP_SACK_NONCE_SUM; 4469cd554309SMichael Tuexen cmt_dac_flag = flags & SCTP_SACK_CMT_DAC; 447018e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 447118e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cum_ack; 447218e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 447318e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 447418e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 447518e198d3SRandall Stewart } 447618e198d3SRandall Stewart #endif 4477d06c82f1SRandall Stewart a_rwnd = rwnd; 4478f8829a4aSRandall Stewart 4479cd554309SMichael Tuexen if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 4480cd554309SMichael Tuexen sctp_misc_ints(SCTP_SACK_LOG_NORMAL, cum_ack, 4481cd554309SMichael Tuexen rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 4482cd554309SMichael Tuexen } 44835e54f665SRandall Stewart old_rwnd = stcb->asoc.peers_rwnd; 4484b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 4485c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 4486c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 4487c4739e2fSRandall Stewart 0, 4488c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 4489c4739e2fSRandall Stewart __LINE__); 4490c4739e2fSRandall Stewart } 4491f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 4492f8829a4aSRandall Stewart asoc = &stcb->asoc; 4493b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4494f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4495f8829a4aSRandall Stewart cum_ack, 4496f8829a4aSRandall Stewart 0, 4497f8829a4aSRandall Stewart num_seg, 4498f8829a4aSRandall Stewart num_dup, 4499f8829a4aSRandall Stewart SCTP_LOG_NEW_SACK); 450080fefe0aSRandall Stewart } 4501b3f1ea41SRandall Stewart if ((num_dup) && (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_FR_LOGGING_ENABLE | SCTP_EARLYFR_LOGGING_ENABLE))) { 4502cd554309SMichael Tuexen uint16_t i; 4503458303daSRandall Stewart uint32_t *dupdata, dblock; 4504f8829a4aSRandall Stewart 4505cd554309SMichael Tuexen for (i = 0; i < num_dup; i++) { 4506cd554309SMichael Tuexen dupdata = (uint32_t *) sctp_m_getptr(m, offset_dup + i * sizeof(uint32_t), 4507458303daSRandall Stewart sizeof(uint32_t), (uint8_t *) & dblock); 4508cd554309SMichael Tuexen if (dupdata == NULL) { 4509458303daSRandall Stewart break; 4510458303daSRandall Stewart } 4511cd554309SMichael Tuexen sctp_log_fr(*dupdata, 0, 0, SCTP_FR_DUPED); 4512f8829a4aSRandall Stewart } 4513f8829a4aSRandall Stewart } 4514b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 4515c105859eSRandall Stewart /* reality check */ 4516c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 4517c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 4518c105859eSRandall Stewart sctpchunk_listhead); 4519c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 4520c105859eSRandall Stewart } else { 4521b5c16493SMichael Tuexen tp1 = NULL; 4522c105859eSRandall Stewart send_s = asoc->sending_seq; 4523c105859eSRandall Stewart } 4524f8829a4aSRandall Stewart if (cum_ack == send_s || 4525f8829a4aSRandall Stewart compare_with_wrap(cum_ack, send_s, MAX_TSN)) { 4526c105859eSRandall Stewart struct mbuf *oper; 4527c105859eSRandall Stewart 4528f8829a4aSRandall Stewart /* 4529f8829a4aSRandall Stewart * no way, we have not even sent this TSN out yet. 4530f8829a4aSRandall Stewart * Peer is hopelessly messed up with us. 4531f8829a4aSRandall Stewart */ 4532b5c16493SMichael Tuexen printf("NEW cum_ack:%x send_s:%x is smaller or equal\n", 4533b5c16493SMichael Tuexen cum_ack, send_s); 4534b5c16493SMichael Tuexen if (tp1) { 4535b5c16493SMichael Tuexen printf("Got send_s from tsn:%x + 1 of tp1:%p\n", 4536b5c16493SMichael Tuexen tp1->rec.data.TSN_seq, tp1); 4537b5c16493SMichael Tuexen } 4538f8829a4aSRandall Stewart hopeless_peer: 4539f8829a4aSRandall Stewart *abort_now = 1; 4540f8829a4aSRandall Stewart /* XXX */ 4541f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4542f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4543f8829a4aSRandall Stewart if (oper) { 4544f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 4545f8829a4aSRandall Stewart uint32_t *ippp; 4546f8829a4aSRandall Stewart 4547139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4548f8829a4aSRandall Stewart sizeof(uint32_t); 4549f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4550f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 4551139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4552f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 4553a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 4554f8829a4aSRandall Stewart } 4555a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 4556ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 4557f8829a4aSRandall Stewart return; 4558f8829a4aSRandall Stewart } 4559f8829a4aSRandall Stewart } 4560f8829a4aSRandall Stewart /**********************/ 4561f8829a4aSRandall Stewart /* 1) check the range */ 4562f8829a4aSRandall Stewart /**********************/ 4563f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, last_tsn, MAX_TSN)) { 4564f8829a4aSRandall Stewart /* acking something behind */ 4565f8829a4aSRandall Stewart return; 4566f8829a4aSRandall Stewart } 4567bff64a4dSRandall Stewart sav_cum_ack = asoc->last_acked_seq; 4568bff64a4dSRandall Stewart 4569f8829a4aSRandall Stewart /* update the Rwnd of the peer */ 4570f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue) && 4571f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->send_queue) && 4572cd554309SMichael Tuexen (asoc->stream_queue_cnt == 0)) { 4573f8829a4aSRandall Stewart /* nothing left on send/sent and strmq */ 4574b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4575f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 4576f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 457780fefe0aSRandall Stewart } 4578f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 4579f8829a4aSRandall Stewart if (asoc->sent_queue_retran_cnt) { 4580f8829a4aSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4581f8829a4aSRandall Stewart } 4582f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4583f8829a4aSRandall Stewart /* SWS sender side engages */ 4584f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4585f8829a4aSRandall Stewart } 4586f8829a4aSRandall Stewart /* stop any timers */ 4587f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4588f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4589a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 4590b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4591139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4592f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck1); 4593a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4594a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 4595f8829a4aSRandall Stewart } 4596f8829a4aSRandall Stewart } 4597f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4598f8829a4aSRandall Stewart net->flight_size = 0; 4599f8829a4aSRandall Stewart } 4600f8829a4aSRandall Stewart asoc->total_flight = 0; 4601f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4602f8829a4aSRandall Stewart return; 4603f8829a4aSRandall Stewart } 4604f8829a4aSRandall Stewart /* 4605f8829a4aSRandall Stewart * We init netAckSz and netAckSz2 to 0. These are used to track 2 4606f8829a4aSRandall Stewart * things. The total byte count acked is tracked in netAckSz AND 4607f8829a4aSRandall Stewart * netAck2 is used to track the total bytes acked that are un- 4608f8829a4aSRandall Stewart * amibguious and were never retransmitted. We track these on a per 4609f8829a4aSRandall Stewart * destination address basis. 4610f8829a4aSRandall Stewart */ 4611f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4612f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 4613f8829a4aSRandall Stewart net->net_ack = 0; 4614f8829a4aSRandall Stewart net->net_ack2 = 0; 4615f8829a4aSRandall Stewart 4616f8829a4aSRandall Stewart /* 461742551e99SRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 461842551e99SRandall Stewart * SACK processing 4619f8829a4aSRandall Stewart */ 4620f8829a4aSRandall Stewart net->new_pseudo_cumack = 0; 4621f8829a4aSRandall Stewart net->will_exit_fast_recovery = 0; 4622f8829a4aSRandall Stewart } 4623f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 4624f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 4625f8829a4aSRandall Stewart while (tp1) { 4626f8829a4aSRandall Stewart if (compare_with_wrap(last_tsn, tp1->rec.data.TSN_seq, 4627f8829a4aSRandall Stewart MAX_TSN) || 4628f8829a4aSRandall Stewart last_tsn == tp1->rec.data.TSN_seq) { 4629f8829a4aSRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 4630f8829a4aSRandall Stewart /* 4631f8829a4aSRandall Stewart * ECN Nonce: Add the nonce to the sender's 4632f8829a4aSRandall Stewart * nonce sum 4633f8829a4aSRandall Stewart */ 4634f8829a4aSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 4635f8829a4aSRandall Stewart accum_moved = 1; 4636f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 4637f8829a4aSRandall Stewart /* 4638f8829a4aSRandall Stewart * If it is less than ACKED, it is 4639f8829a4aSRandall Stewart * now no-longer in flight. Higher 4640f8829a4aSRandall Stewart * values may occur during marking 4641f8829a4aSRandall Stewart */ 4642f8829a4aSRandall Stewart if ((tp1->whoTo->dest_state & 4643f8829a4aSRandall Stewart SCTP_ADDR_UNCONFIRMED) && 4644f8829a4aSRandall Stewart (tp1->snd_count < 2)) { 4645f8829a4aSRandall Stewart /* 4646f8829a4aSRandall Stewart * If there was no retran 4647f8829a4aSRandall Stewart * and the address is 4648f8829a4aSRandall Stewart * un-confirmed and we sent 4649f8829a4aSRandall Stewart * there and are now 4650f8829a4aSRandall Stewart * sacked.. its confirmed, 4651f8829a4aSRandall Stewart * mark it so. 4652f8829a4aSRandall Stewart */ 4653f8829a4aSRandall Stewart tp1->whoTo->dest_state &= 4654f8829a4aSRandall Stewart ~SCTP_ADDR_UNCONFIRMED; 4655f8829a4aSRandall Stewart } 4656c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4657b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4658c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 4659a5d547adSRandall Stewart tp1->whoTo->flight_size, 4660a5d547adSRandall Stewart tp1->book_size, 4661c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4662a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 466380fefe0aSRandall Stewart } 4664c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 4665c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 4666f8829a4aSRandall Stewart } 4667f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 4668f8829a4aSRandall Stewart 4669f8829a4aSRandall Stewart /* CMT SFR and DAC algos */ 4670f8829a4aSRandall Stewart this_sack_lowest_newack = tp1->rec.data.TSN_seq; 4671f8829a4aSRandall Stewart tp1->whoTo->saw_newack = 1; 4672f8829a4aSRandall Stewart 4673f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 4674f8829a4aSRandall Stewart /* 4675f8829a4aSRandall Stewart * True non-retransmited 4676f8829a4aSRandall Stewart * chunk 4677f8829a4aSRandall Stewart */ 4678f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 4679f8829a4aSRandall Stewart tp1->send_size; 4680f8829a4aSRandall Stewart 4681f8829a4aSRandall Stewart /* update RTO too? */ 4682f8829a4aSRandall Stewart if (tp1->do_rtt) { 4683f8829a4aSRandall Stewart tp1->whoTo->RTO = 4684f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 4685f8829a4aSRandall Stewart asoc, tp1->whoTo, 468618e198d3SRandall Stewart &tp1->sent_rcv_time, 468718e198d3SRandall Stewart sctp_align_safe_nocopy); 4688f8829a4aSRandall Stewart tp1->do_rtt = 0; 4689f8829a4aSRandall Stewart } 4690f8829a4aSRandall Stewart } 4691f8829a4aSRandall Stewart /* 4692f8829a4aSRandall Stewart * CMT: CUCv2 algorithm. From the 4693f8829a4aSRandall Stewart * cumack'd TSNs, for each TSN being 4694f8829a4aSRandall Stewart * acked for the first time, set the 4695f8829a4aSRandall Stewart * following variables for the 4696f8829a4aSRandall Stewart * corresp destination. 4697f8829a4aSRandall Stewart * new_pseudo_cumack will trigger a 4698f8829a4aSRandall Stewart * cwnd update. 4699f8829a4aSRandall Stewart * find_(rtx_)pseudo_cumack will 4700f8829a4aSRandall Stewart * trigger search for the next 4701f8829a4aSRandall Stewart * expected (rtx-)pseudo-cumack. 4702f8829a4aSRandall Stewart */ 4703f8829a4aSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 4704f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 4705f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 4706f8829a4aSRandall Stewart 4707f8829a4aSRandall Stewart 4708b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4709f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4710f8829a4aSRandall Stewart cum_ack, 4711f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4712f8829a4aSRandall Stewart 0, 4713f8829a4aSRandall Stewart 0, 4714f8829a4aSRandall Stewart SCTP_LOG_TSN_ACKED); 471580fefe0aSRandall Stewart } 4716b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 4717f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 471880fefe0aSRandall Stewart } 4719f8829a4aSRandall Stewart } 4720f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4721f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 4722f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 4723f8829a4aSRandall Stewart sctp_audit_log(0xB3, 4724f8829a4aSRandall Stewart (asoc->sent_queue_retran_cnt & 0x000000ff)); 4725f8829a4aSRandall Stewart #endif 4726f8829a4aSRandall Stewart } 472742551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 472842551e99SRandall Stewart /* deflate the cwnd */ 472942551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 473042551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 473142551e99SRandall Stewart } 4732f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 4733f8829a4aSRandall Stewart } 4734f8829a4aSRandall Stewart } else { 4735f8829a4aSRandall Stewart break; 4736f8829a4aSRandall Stewart } 4737f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 4738f8829a4aSRandall Stewart } 4739f8829a4aSRandall Stewart biggest_tsn_newly_acked = biggest_tsn_acked = last_tsn; 4740f8829a4aSRandall Stewart /* always set this up to cum-ack */ 4741f8829a4aSRandall Stewart asoc->this_sack_highest_gap = last_tsn; 4742f8829a4aSRandall Stewart 4743cd554309SMichael Tuexen if ((num_seg > 0) || (num_nr_seg > 0)) { 4744f8829a4aSRandall Stewart 4745f8829a4aSRandall Stewart /* 4746f8829a4aSRandall Stewart * CMT: SFR algo (and HTNA) - this_sack_highest_newack has 4747f8829a4aSRandall Stewart * to be greater than the cumack. Also reset saw_newack to 0 4748f8829a4aSRandall Stewart * for all dests. 4749f8829a4aSRandall Stewart */ 4750f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4751f8829a4aSRandall Stewart net->saw_newack = 0; 4752f8829a4aSRandall Stewart net->this_sack_highest_newack = last_tsn; 4753f8829a4aSRandall Stewart } 4754f8829a4aSRandall Stewart 4755f8829a4aSRandall Stewart /* 4756f8829a4aSRandall Stewart * thisSackHighestGap will increase while handling NEW 4757f8829a4aSRandall Stewart * segments this_sack_highest_newack will increase while 4758f8829a4aSRandall Stewart * handling NEWLY ACKED chunks. this_sack_lowest_newack is 4759f8829a4aSRandall Stewart * used for CMT DAC algo. saw_newack will also change. 4760f8829a4aSRandall Stewart */ 4761cd554309SMichael Tuexen if (sctp_handle_segments(m, &offset_seg, stcb, asoc, last_tsn, &biggest_tsn_acked, 4762cd554309SMichael Tuexen &biggest_tsn_newly_acked, &this_sack_lowest_newack, 4763cd554309SMichael Tuexen num_seg, num_nr_seg, &ecn_seg_sums)) { 4764cd554309SMichael Tuexen wake_him++; 4765cd554309SMichael Tuexen } 4766b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 4767f8829a4aSRandall Stewart /* 4768f8829a4aSRandall Stewart * validate the biggest_tsn_acked in the gap acks if 4769f8829a4aSRandall Stewart * strict adherence is wanted. 4770f8829a4aSRandall Stewart */ 4771f8829a4aSRandall Stewart if ((biggest_tsn_acked == send_s) || 4772f8829a4aSRandall Stewart (compare_with_wrap(biggest_tsn_acked, send_s, MAX_TSN))) { 4773f8829a4aSRandall Stewart /* 4774f8829a4aSRandall Stewart * peer is either confused or we are under 4775f8829a4aSRandall Stewart * attack. We must abort. 4776f8829a4aSRandall Stewart */ 4777b5c16493SMichael Tuexen printf("Hopeless peer! biggest_tsn_acked:%x largest seq:%x\n", 4778b5c16493SMichael Tuexen biggest_tsn_acked, 4779b5c16493SMichael Tuexen send_s); 4780b5c16493SMichael Tuexen 4781f8829a4aSRandall Stewart goto hopeless_peer; 4782f8829a4aSRandall Stewart } 4783f8829a4aSRandall Stewart } 4784f8829a4aSRandall Stewart } 4785f8829a4aSRandall Stewart /*******************************************/ 4786f8829a4aSRandall Stewart /* cancel ALL T3-send timer if accum moved */ 4787f8829a4aSRandall Stewart /*******************************************/ 4788b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) { 4789f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4790f8829a4aSRandall Stewart if (net->new_pseudo_cumack) 4791f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4792a5d547adSRandall Stewart stcb, net, 4793a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_27); 4794f8829a4aSRandall Stewart 4795f8829a4aSRandall Stewart } 4796f8829a4aSRandall Stewart } else { 4797f8829a4aSRandall Stewart if (accum_moved) { 4798f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4799f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4800a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_28); 4801f8829a4aSRandall Stewart } 4802f8829a4aSRandall Stewart } 4803f8829a4aSRandall Stewart } 4804f8829a4aSRandall Stewart /********************************************/ 4805f8829a4aSRandall Stewart /* drop the acked chunks from the sendqueue */ 4806f8829a4aSRandall Stewart /********************************************/ 4807f8829a4aSRandall Stewart asoc->last_acked_seq = cum_ack; 4808f8829a4aSRandall Stewart 4809f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 4810f8829a4aSRandall Stewart if (tp1 == NULL) 4811f8829a4aSRandall Stewart goto done_with_it; 4812f8829a4aSRandall Stewart do { 4813f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, cum_ack, 4814f8829a4aSRandall Stewart MAX_TSN)) { 4815f8829a4aSRandall Stewart break; 4816f8829a4aSRandall Stewart } 4817f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 4818f8829a4aSRandall Stewart /* no more sent on list */ 481918e198d3SRandall Stewart printf("Warning, tp1->sent == %d and its now acked?\n", 482018e198d3SRandall Stewart tp1->sent); 4821f8829a4aSRandall Stewart } 4822f8829a4aSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 4823f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 4824f8829a4aSRandall Stewart if (tp1->pr_sctp_on) { 4825f8829a4aSRandall Stewart if (asoc->pr_sctp_cnt != 0) 4826f8829a4aSRandall Stewart asoc->pr_sctp_cnt--; 4827f8829a4aSRandall Stewart } 4828f8829a4aSRandall Stewart if ((TAILQ_FIRST(&asoc->sent_queue) == NULL) && 4829f8829a4aSRandall Stewart (asoc->total_flight > 0)) { 4830f1f73e57SRandall Stewart #ifdef INVARIANTS 4831c105859eSRandall Stewart panic("Warning flight size is postive and should be 0"); 4832f1f73e57SRandall Stewart #else 4833ad81507eSRandall Stewart SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n", 4834f8829a4aSRandall Stewart asoc->total_flight); 4835f1f73e57SRandall Stewart #endif 4836f8829a4aSRandall Stewart asoc->total_flight = 0; 4837f8829a4aSRandall Stewart } 4838f8829a4aSRandall Stewart if (tp1->data) { 483904ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4840f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 4841f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 4842810ec536SMichael Tuexen if (asoc->peer_supports_prsctp && PR_SCTP_BUF_ENABLED(tp1->flags)) { 4843f8829a4aSRandall Stewart asoc->sent_queue_cnt_removeable--; 4844f8829a4aSRandall Stewart } 4845f8829a4aSRandall Stewart } 4846b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4847f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4848f8829a4aSRandall Stewart cum_ack, 4849f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4850f8829a4aSRandall Stewart 0, 4851f8829a4aSRandall Stewart 0, 4852f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 485380fefe0aSRandall Stewart } 4854f8829a4aSRandall Stewart tp1->data = NULL; 4855f8829a4aSRandall Stewart asoc->sent_queue_cnt--; 4856f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, tp1); 4857f8829a4aSRandall Stewart wake_him++; 4858f8829a4aSRandall Stewart tp1 = tp2; 4859f8829a4aSRandall Stewart } while (tp1 != NULL); 4860f8829a4aSRandall Stewart 4861f8829a4aSRandall Stewart done_with_it: 486204ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4863f8829a4aSRandall Stewart if ((wake_him) && (stcb->sctp_socket)) { 4864ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4865ceaad40aSRandall Stewart struct socket *so; 4866ceaad40aSRandall Stewart 4867ceaad40aSRandall Stewart #endif 4868f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 4869b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4870f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_WAKESND_FROM_SACK); 487180fefe0aSRandall Stewart } 4872ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4873ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 4874ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 4875ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 4876ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 4877ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 4878ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 4879ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 4880ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 4881ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4882ceaad40aSRandall Stewart return; 4883ceaad40aSRandall Stewart } 4884ceaad40aSRandall Stewart #endif 4885f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 4886ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4887ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4888ceaad40aSRandall Stewart #endif 4889f8829a4aSRandall Stewart } else { 4890b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4891f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_NOWAKE_FROM_SACK); 489280fefe0aSRandall Stewart } 4893f8829a4aSRandall Stewart } 4894f8829a4aSRandall Stewart 489542551e99SRandall Stewart if (asoc->fast_retran_loss_recovery && accum_moved) { 4896f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, 4897f8829a4aSRandall Stewart asoc->fast_recovery_tsn, MAX_TSN) || 4898f8829a4aSRandall Stewart asoc->last_acked_seq == asoc->fast_recovery_tsn) { 4899f8829a4aSRandall Stewart /* Setup so we will exit RFC2582 fast recovery */ 4900f8829a4aSRandall Stewart will_exit_fast_recovery = 1; 4901f8829a4aSRandall Stewart } 4902f8829a4aSRandall Stewart } 4903f8829a4aSRandall Stewart /* 4904f8829a4aSRandall Stewart * Check for revoked fragments: 4905f8829a4aSRandall Stewart * 4906f8829a4aSRandall Stewart * if Previous sack - Had no frags then we can't have any revoked if 4907f8829a4aSRandall Stewart * Previous sack - Had frag's then - If we now have frags aka 4908f8829a4aSRandall Stewart * num_seg > 0 call sctp_check_for_revoked() to tell if peer revoked 4909f8829a4aSRandall Stewart * some of them. else - The peer revoked all ACKED fragments, since 4910f8829a4aSRandall Stewart * we had some before and now we have NONE. 4911f8829a4aSRandall Stewart */ 4912f8829a4aSRandall Stewart 4913f42a358aSRandall Stewart if (num_seg) 4914c105859eSRandall Stewart sctp_check_for_revoked(stcb, asoc, cum_ack, biggest_tsn_acked); 4915f8829a4aSRandall Stewart else if (asoc->saw_sack_with_frags) { 4916f8829a4aSRandall Stewart int cnt_revoked = 0; 4917f8829a4aSRandall Stewart 4918f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 4919f8829a4aSRandall Stewart if (tp1 != NULL) { 4920f8829a4aSRandall Stewart /* Peer revoked all dg's marked or acked */ 4921f8829a4aSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4922b5c16493SMichael Tuexen if (tp1->sent == SCTP_DATAGRAM_ACKED) { 4923f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 4924b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4925c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 4926c105859eSRandall Stewart tp1->whoTo->flight_size, 4927c105859eSRandall Stewart tp1->book_size, 4928c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4929c105859eSRandall Stewart tp1->rec.data.TSN_seq); 493080fefe0aSRandall Stewart } 4931c105859eSRandall Stewart sctp_flight_size_increase(tp1); 4932c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 4933a5d547adSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 493442551e99SRandall Stewart /* 493542551e99SRandall Stewart * To ensure that this increase in 493642551e99SRandall Stewart * flightsize, which is artificial, 493742551e99SRandall Stewart * does not throttle the sender, we 493842551e99SRandall Stewart * also increase the cwnd 493942551e99SRandall Stewart * artificially. 494042551e99SRandall Stewart */ 494142551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 4942f8829a4aSRandall Stewart cnt_revoked++; 4943f8829a4aSRandall Stewart } 4944f8829a4aSRandall Stewart } 4945f8829a4aSRandall Stewart if (cnt_revoked) { 4946f8829a4aSRandall Stewart reneged_all = 1; 4947f8829a4aSRandall Stewart } 4948f8829a4aSRandall Stewart } 4949f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 0; 4950f8829a4aSRandall Stewart } 4951b5c16493SMichael Tuexen if (num_seg || num_nr_seg) 4952f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 1; 4953f8829a4aSRandall Stewart else 4954f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 0; 4955f8829a4aSRandall Stewart 4956b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4957b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, accum_moved, reneged_all, will_exit_fast_recovery); 4958f8829a4aSRandall Stewart 4959f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 4960f8829a4aSRandall Stewart /* nothing left in-flight */ 4961f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4962f8829a4aSRandall Stewart /* stop all timers */ 4963b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4964139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4965f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 4966a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4967a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_29); 4968f8829a4aSRandall Stewart } 4969f8829a4aSRandall Stewart } 4970f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4971a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_30); 4972f8829a4aSRandall Stewart net->flight_size = 0; 4973f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4974f8829a4aSRandall Stewart } 4975f8829a4aSRandall Stewart asoc->total_flight = 0; 4976f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4977f8829a4aSRandall Stewart } 4978f8829a4aSRandall Stewart /**********************************/ 4979f8829a4aSRandall Stewart /* Now what about shutdown issues */ 4980f8829a4aSRandall Stewart /**********************************/ 4981f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 4982f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 4983b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4984f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 4985f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 498680fefe0aSRandall Stewart } 4987f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 4988f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4989f8829a4aSRandall Stewart /* SWS sender side engages */ 4990f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4991f8829a4aSRandall Stewart } 4992f8829a4aSRandall Stewart /* clean up */ 4993f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 4994f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 4995f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 4996f8829a4aSRandall Stewart (asoc->locked_on_sending) 4997f8829a4aSRandall Stewart ) { 4998f8829a4aSRandall Stewart struct sctp_stream_queue_pending *sp; 4999f8829a4aSRandall Stewart 5000f8829a4aSRandall Stewart /* 5001f8829a4aSRandall Stewart * I may be in a state where we got all across.. but 5002f8829a4aSRandall Stewart * cannot write more due to a shutdown... we abort 5003f8829a4aSRandall Stewart * since the user did not indicate EOR in this case. 5004f8829a4aSRandall Stewart */ 5005f8829a4aSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 5006f8829a4aSRandall Stewart sctp_streamhead); 50072afb3e84SRandall Stewart if ((sp) && (sp->length == 0)) { 5008f8829a4aSRandall Stewart asoc->locked_on_sending = NULL; 50092afb3e84SRandall Stewart if (sp->msg_is_complete) { 5010f8829a4aSRandall Stewart asoc->stream_queue_cnt--; 50112afb3e84SRandall Stewart } else { 50122afb3e84SRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 50132afb3e84SRandall Stewart asoc->stream_queue_cnt--; 50142afb3e84SRandall Stewart } 5015f8829a4aSRandall Stewart } 5016f8829a4aSRandall Stewart } 5017f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 5018f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 5019f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 5020f8829a4aSRandall Stewart /* Need to abort here */ 5021f8829a4aSRandall Stewart struct mbuf *oper; 5022f8829a4aSRandall Stewart 5023f8829a4aSRandall Stewart abort_out_now: 5024f8829a4aSRandall Stewart *abort_now = 1; 5025f8829a4aSRandall Stewart /* XXX */ 5026f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 5027f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 5028f8829a4aSRandall Stewart if (oper) { 5029f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 5030f8829a4aSRandall Stewart uint32_t *ippp; 5031f8829a4aSRandall Stewart 5032139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 5033f8829a4aSRandall Stewart sizeof(uint32_t); 5034f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 5035f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 5036139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 5037f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 5038a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_31); 5039f8829a4aSRandall Stewart } 5040a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_31; 5041ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 5042f8829a4aSRandall Stewart return; 5043f8829a4aSRandall Stewart } else { 5044f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 5045f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 5046f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 5047f42a358aSRandall Stewart } 5048c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 5049b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 5050f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 5051f8829a4aSRandall Stewart sctp_send_shutdown(stcb, 5052f8829a4aSRandall Stewart stcb->asoc.primary_destination); 5053f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 5054f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 5055f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 5056f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 5057f8829a4aSRandall Stewart } 5058f8829a4aSRandall Stewart return; 5059f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 5060f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 5061f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 5062f8829a4aSRandall Stewart goto abort_out_now; 5063f8829a4aSRandall Stewart } 5064f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 5065c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 5066b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 5067f8829a4aSRandall Stewart sctp_send_shutdown_ack(stcb, 5068f8829a4aSRandall Stewart stcb->asoc.primary_destination); 5069f8829a4aSRandall Stewart 5070f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 5071f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 5072f8829a4aSRandall Stewart return; 5073f8829a4aSRandall Stewart } 5074f8829a4aSRandall Stewart } 5075f8829a4aSRandall Stewart /* 5076f8829a4aSRandall Stewart * Now here we are going to recycle net_ack for a different use... 5077f8829a4aSRandall Stewart * HEADS UP. 5078f8829a4aSRandall Stewart */ 5079f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5080f8829a4aSRandall Stewart net->net_ack = 0; 5081f8829a4aSRandall Stewart } 5082f8829a4aSRandall Stewart 5083f8829a4aSRandall Stewart /* 5084f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK DAC flag was 0, then no extra marking 5085f8829a4aSRandall Stewart * to be done. Setting this_sack_lowest_newack to the cum_ack will 5086f8829a4aSRandall Stewart * automatically ensure that. 5087f8829a4aSRandall Stewart */ 5088b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac) && (cmt_dac_flag == 0)) { 5089f8829a4aSRandall Stewart this_sack_lowest_newack = cum_ack; 5090f8829a4aSRandall Stewart } 5091cd554309SMichael Tuexen if ((num_seg > 0) || (num_nr_seg > 0)) { 5092f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(stcb, asoc, biggest_tsn_acked, 5093f8829a4aSRandall Stewart biggest_tsn_newly_acked, this_sack_lowest_newack, accum_moved); 5094f8829a4aSRandall Stewart } 5095b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 5096b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_fr(stcb, asoc); 5097f8829a4aSRandall Stewart 5098f8829a4aSRandall Stewart /****************************************************************** 5099f8829a4aSRandall Stewart * Here we do the stuff with ECN Nonce checking. 5100f8829a4aSRandall Stewart * We basically check to see if the nonce sum flag was incorrect 5101f8829a4aSRandall Stewart * or if resynchronization needs to be done. Also if we catch a 5102f8829a4aSRandall Stewart * misbehaving receiver we give him the kick. 5103f8829a4aSRandall Stewart ******************************************************************/ 5104f8829a4aSRandall Stewart 5105f8829a4aSRandall Stewart if (asoc->ecn_nonce_allowed) { 5106f8829a4aSRandall Stewart if (asoc->nonce_sum_check) { 5107f8829a4aSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base + ecn_seg_sums) & SCTP_SACK_NONCE_SUM)) { 5108f8829a4aSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 5109f8829a4aSRandall Stewart struct sctp_tmit_chunk *lchk; 5110f8829a4aSRandall Stewart 5111f8829a4aSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 5112f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 1; 5113f8829a4aSRandall Stewart if (lchk) { 5114f8829a4aSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 5115f8829a4aSRandall Stewart } else { 5116f8829a4aSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 5117f8829a4aSRandall Stewart } 5118f8829a4aSRandall Stewart } else { 5119f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) || 5120f8829a4aSRandall Stewart (asoc->last_acked_seq == asoc->nonce_wait_tsn)) { 5121f8829a4aSRandall Stewart /* 5122f8829a4aSRandall Stewart * Misbehaving peer. We need 5123f8829a4aSRandall Stewart * to react to this guy 5124f8829a4aSRandall Stewart */ 5125f8829a4aSRandall Stewart asoc->ecn_allowed = 0; 5126f8829a4aSRandall Stewart asoc->ecn_nonce_allowed = 0; 5127f8829a4aSRandall Stewart } 5128f8829a4aSRandall Stewart } 5129f8829a4aSRandall Stewart } 5130f8829a4aSRandall Stewart } else { 5131f8829a4aSRandall Stewart /* See if Resynchronization Possible */ 5132f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) { 5133f8829a4aSRandall Stewart asoc->nonce_sum_check = 1; 5134f8829a4aSRandall Stewart /* 5135f8829a4aSRandall Stewart * now we must calculate what the base is. 5136f8829a4aSRandall Stewart * We do this based on two things, we know 5137f8829a4aSRandall Stewart * the total's for all the segments 5138f8829a4aSRandall Stewart * gap-acked in the SACK, its stored in 5139f8829a4aSRandall Stewart * ecn_seg_sums. We also know the SACK's 5140f8829a4aSRandall Stewart * nonce sum, its in nonce_sum_flag. So we 5141f8829a4aSRandall Stewart * can build a truth table to back-calculate 5142f8829a4aSRandall Stewart * the new value of 5143f8829a4aSRandall Stewart * asoc->nonce_sum_expect_base: 5144f8829a4aSRandall Stewart * 5145f8829a4aSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 5146f8829a4aSRandall Stewart * 1 0 1 0 1 1 1 5147f8829a4aSRandall Stewart * 1 0 5148f8829a4aSRandall Stewart */ 5149f8829a4aSRandall Stewart asoc->nonce_sum_expect_base = (ecn_seg_sums ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 5150f8829a4aSRandall Stewart } 5151f8829a4aSRandall Stewart } 5152f8829a4aSRandall Stewart } 5153f8829a4aSRandall Stewart /* Now are we exiting loss recovery ? */ 5154f8829a4aSRandall Stewart if (will_exit_fast_recovery) { 5155f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 5156f8829a4aSRandall Stewart asoc->fast_retran_loss_recovery = 0; 5157f8829a4aSRandall Stewart } 5158f8829a4aSRandall Stewart if ((asoc->sat_t3_loss_recovery) && 5159f8829a4aSRandall Stewart ((compare_with_wrap(asoc->last_acked_seq, asoc->sat_t3_recovery_tsn, 5160f8829a4aSRandall Stewart MAX_TSN) || 5161f8829a4aSRandall Stewart (asoc->last_acked_seq == asoc->sat_t3_recovery_tsn)))) { 5162f8829a4aSRandall Stewart /* end satellite t3 loss recovery */ 5163f8829a4aSRandall Stewart asoc->sat_t3_loss_recovery = 0; 5164f8829a4aSRandall Stewart } 516542551e99SRandall Stewart /* 516642551e99SRandall Stewart * CMT Fast recovery 516742551e99SRandall Stewart */ 5168f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5169f8829a4aSRandall Stewart if (net->will_exit_fast_recovery) { 5170f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 5171f8829a4aSRandall Stewart net->fast_retran_loss_recovery = 0; 5172f8829a4aSRandall Stewart } 5173f8829a4aSRandall Stewart } 5174f8829a4aSRandall Stewart 5175f8829a4aSRandall Stewart /* Adjust and set the new rwnd value */ 5176b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 5177f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 5178b3f1ea41SRandall Stewart asoc->peers_rwnd, asoc->total_flight, (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)), a_rwnd); 517980fefe0aSRandall Stewart } 5180f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd, 5181b3f1ea41SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 5182f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 5183f8829a4aSRandall Stewart /* SWS sender side engages */ 5184f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 5185f8829a4aSRandall Stewart } 51865e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 51875e54f665SRandall Stewart win_probe_recovery = 1; 51885e54f665SRandall Stewart } 5189f8829a4aSRandall Stewart /* 5190f8829a4aSRandall Stewart * Now we must setup so we have a timer up for anyone with 5191f8829a4aSRandall Stewart * outstanding data. 5192f8829a4aSRandall Stewart */ 5193bff64a4dSRandall Stewart done_once = 0; 5194a5d547adSRandall Stewart again: 5195a5d547adSRandall Stewart j = 0; 5196f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 51975e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 5198c105859eSRandall Stewart win_probe_recovered = 1; 51995e54f665SRandall Stewart /*- 52005e54f665SRandall Stewart * Find first chunk that was used with 52015e54f665SRandall Stewart * window probe and clear the event. Put 52025e54f665SRandall Stewart * it back into the send queue as if has 52035e54f665SRandall Stewart * not been sent. 52045e54f665SRandall Stewart */ 52055e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 52065e54f665SRandall Stewart if (tp1->window_probe) { 5207c105859eSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 52085e54f665SRandall Stewart break; 52095e54f665SRandall Stewart } 52105e54f665SRandall Stewart } 52115e54f665SRandall Stewart } 5212f8829a4aSRandall Stewart if (net->flight_size) { 5213a5d547adSRandall Stewart j++; 5214cd554309SMichael Tuexen if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 5215f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5216f8829a4aSRandall Stewart stcb->sctp_ep, stcb, net); 5217cd554309SMichael Tuexen } 52185171328bSRandall Stewart if (net->window_probe) { 5219cd554309SMichael Tuexen net->window_probe = 0; 52205171328bSRandall Stewart } 5221c105859eSRandall Stewart } else { 52225171328bSRandall Stewart if (net->window_probe) { 52235171328bSRandall Stewart /* 52245171328bSRandall Stewart * In window probes we must assure a timer 52255171328bSRandall Stewart * is still running there 52265171328bSRandall Stewart */ 52275171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 52285171328bSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 52295171328bSRandall Stewart stcb->sctp_ep, stcb, net); 52305171328bSRandall Stewart 52315171328bSRandall Stewart } 52325171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 5233c105859eSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 5234c105859eSRandall Stewart stcb, net, 5235c105859eSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 5236c105859eSRandall Stewart } 5237b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 5238c105859eSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 5239c105859eSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 5240c105859eSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 5241c105859eSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 5242c105859eSRandall Stewart } 5243c105859eSRandall Stewart } 5244f8829a4aSRandall Stewart } 5245f8829a4aSRandall Stewart } 5246bff64a4dSRandall Stewart if ((j == 0) && 5247bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 5248bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 5249c105859eSRandall Stewart (win_probe_recovered == 0) && 5250bff64a4dSRandall Stewart (done_once == 0)) { 52510c0982b8SRandall Stewart /* 52520c0982b8SRandall Stewart * huh, this should not happen unless all packets are 52530c0982b8SRandall Stewart * PR-SCTP and marked to skip of course. 52540c0982b8SRandall Stewart */ 52550c0982b8SRandall Stewart if (sctp_fs_audit(asoc)) { 5256a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5257a5d547adSRandall Stewart net->flight_size = 0; 5258a5d547adSRandall Stewart } 5259a5d547adSRandall Stewart asoc->total_flight = 0; 5260a5d547adSRandall Stewart asoc->total_flight_count = 0; 5261a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 5262a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 5263a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 5264c105859eSRandall Stewart sctp_flight_size_increase(tp1); 5265c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 5266a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 5267*791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 5268a5d547adSRandall Stewart } 5269a5d547adSRandall Stewart } 52700c0982b8SRandall Stewart } 5271bff64a4dSRandall Stewart done_once = 1; 5272a5d547adSRandall Stewart goto again; 5273a5d547adSRandall Stewart } 5274cd554309SMichael Tuexen /*********************************************/ 5275cd554309SMichael Tuexen /* Here we perform PR-SCTP procedures */ 5276cd554309SMichael Tuexen /* (section 4.2) */ 5277cd554309SMichael Tuexen /*********************************************/ 5278cd554309SMichael Tuexen /* C1. update advancedPeerAckPoint */ 5279dfb11ef8SRandall Stewart if (compare_with_wrap(cum_ack, asoc->advanced_peer_ack_point, MAX_TSN)) { 5280dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cum_ack; 5281dfb11ef8SRandall Stewart } 5282830d754dSRandall Stewart /* C2. try to further move advancedPeerAckPoint ahead */ 5283830d754dSRandall Stewart if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) { 5284830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 5285830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 5286830d754dSRandall Stewart 5287830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 5288830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 5289830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 5290830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, cum_ack, 5291830d754dSRandall Stewart MAX_TSN)) { 5292830d754dSRandall Stewart /* 5293830d754dSRandall Stewart * ISSUE with ECN, see FWD-TSN processing for notes 5294830d754dSRandall Stewart * on issues that will occur when the ECN NONCE 5295830d754dSRandall Stewart * stuff is put into SCTP for cross checking. 5296830d754dSRandall Stewart */ 52970c0982b8SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { 52980c0982b8SRandall Stewart sctp_misc_ints(SCTP_FWD_TSN_CHECK, 52990c0982b8SRandall Stewart 0xee, cum_ack, asoc->advanced_peer_ack_point, 53000c0982b8SRandall Stewart old_adv_peer_ack_point); 53010c0982b8SRandall Stewart } 5302830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, old_adv_peer_ack_point, 5303830d754dSRandall Stewart MAX_TSN)) { 5304830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 5305830d754dSRandall Stewart /* 5306830d754dSRandall Stewart * ECN Nonce: Disable Nonce Sum check when 5307830d754dSRandall Stewart * FWD TSN is sent and store resync tsn 5308830d754dSRandall Stewart */ 5309830d754dSRandall Stewart asoc->nonce_sum_check = 0; 5310830d754dSRandall Stewart asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point; 53110c0982b8SRandall Stewart } else if (lchk) { 53120c0982b8SRandall Stewart /* try to FR fwd-tsn's that get lost too */ 53130c0982b8SRandall Stewart lchk->rec.data.fwd_tsn_cnt++; 53140c0982b8SRandall Stewart if (lchk->rec.data.fwd_tsn_cnt > 3) { 53150c0982b8SRandall Stewart send_forward_tsn(stcb, asoc); 53160c0982b8SRandall Stewart lchk->rec.data.fwd_tsn_cnt = 0; 53170c0982b8SRandall Stewart } 5318830d754dSRandall Stewart } 5319830d754dSRandall Stewart } 5320830d754dSRandall Stewart if (lchk) { 5321830d754dSRandall Stewart /* Assure a timer is up */ 5322830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5323830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 5324830d754dSRandall Stewart } 5325830d754dSRandall Stewart } 5326b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 5327f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 5328f8829a4aSRandall Stewart a_rwnd, 5329f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 5330f8829a4aSRandall Stewart stcb->asoc.total_flight, 5331f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 533280fefe0aSRandall Stewart } 5333f8829a4aSRandall Stewart } 5334f8829a4aSRandall Stewart 5335f8829a4aSRandall Stewart void 5336f8829a4aSRandall Stewart sctp_update_acked(struct sctp_tcb *stcb, struct sctp_shutdown_chunk *cp, 5337f8829a4aSRandall Stewart struct sctp_nets *netp, int *abort_flag) 5338f8829a4aSRandall Stewart { 5339f8829a4aSRandall Stewart /* Copy cum-ack */ 5340f8829a4aSRandall Stewart uint32_t cum_ack, a_rwnd; 5341f8829a4aSRandall Stewart 5342f8829a4aSRandall Stewart cum_ack = ntohl(cp->cumulative_tsn_ack); 5343f8829a4aSRandall Stewart /* Arrange so a_rwnd does NOT change */ 5344f8829a4aSRandall Stewart a_rwnd = stcb->asoc.peers_rwnd + stcb->asoc.total_flight; 5345f8829a4aSRandall Stewart 5346f8829a4aSRandall Stewart /* Now call the express sack handling */ 5347f8829a4aSRandall Stewart sctp_express_handle_sack(stcb, cum_ack, a_rwnd, 0, abort_flag); 5348f8829a4aSRandall Stewart } 5349f8829a4aSRandall Stewart 5350f8829a4aSRandall Stewart static void 5351f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb, 5352f8829a4aSRandall Stewart struct sctp_stream_in *strmin) 5353f8829a4aSRandall Stewart { 5354f8829a4aSRandall Stewart struct sctp_queued_to_read *ctl, *nctl; 5355f8829a4aSRandall Stewart struct sctp_association *asoc; 535683128708SRandall Stewart uint16_t tt; 5357f8829a4aSRandall Stewart 5358f8829a4aSRandall Stewart asoc = &stcb->asoc; 5359f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered; 5360f8829a4aSRandall Stewart /* 5361f8829a4aSRandall Stewart * First deliver anything prior to and including the stream no that 5362f8829a4aSRandall Stewart * came in 5363f8829a4aSRandall Stewart */ 5364f8829a4aSRandall Stewart ctl = TAILQ_FIRST(&strmin->inqueue); 5365f8829a4aSRandall Stewart while (ctl) { 5366f8829a4aSRandall Stewart nctl = TAILQ_NEXT(ctl, next); 5367f8829a4aSRandall Stewart if (compare_with_wrap(tt, ctl->sinfo_ssn, MAX_SEQ) || 5368f8829a4aSRandall Stewart (tt == ctl->sinfo_ssn)) { 5369f8829a4aSRandall Stewart /* this is deliverable now */ 5370f8829a4aSRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next); 5371f8829a4aSRandall Stewart /* subtract pending on streams */ 5372f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5373f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5374f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5375f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5376b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 5377f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5378f8829a4aSRandall Stewart ctl, 5379cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED); 5380f8829a4aSRandall Stewart } 5381f8829a4aSRandall Stewart } else { 5382f8829a4aSRandall Stewart /* no more delivery now. */ 5383f8829a4aSRandall Stewart break; 5384f8829a4aSRandall Stewart } 5385f8829a4aSRandall Stewart ctl = nctl; 5386f8829a4aSRandall Stewart } 5387f8829a4aSRandall Stewart /* 5388f8829a4aSRandall Stewart * now we must deliver things in queue the normal way if any are 5389f8829a4aSRandall Stewart * now ready. 5390f8829a4aSRandall Stewart */ 5391f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 5392f8829a4aSRandall Stewart ctl = TAILQ_FIRST(&strmin->inqueue); 5393f8829a4aSRandall Stewart while (ctl) { 5394f8829a4aSRandall Stewart nctl = TAILQ_NEXT(ctl, next); 5395f8829a4aSRandall Stewart if (tt == ctl->sinfo_ssn) { 5396f8829a4aSRandall Stewart /* this is deliverable now */ 5397f8829a4aSRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next); 5398f8829a4aSRandall Stewart /* subtract pending on streams */ 5399f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5400f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5401f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5402f8829a4aSRandall Stewart strmin->last_sequence_delivered = ctl->sinfo_ssn; 5403f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5404b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 5405f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5406f8829a4aSRandall Stewart ctl, 5407cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED); 540877acdc25SRandall Stewart 5409f8829a4aSRandall Stewart } 5410f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 5411f8829a4aSRandall Stewart } else { 5412f8829a4aSRandall Stewart break; 5413f8829a4aSRandall Stewart } 5414f8829a4aSRandall Stewart ctl = nctl; 5415f8829a4aSRandall Stewart } 5416f8829a4aSRandall Stewart } 5417f8829a4aSRandall Stewart 54188933fa13SRandall Stewart static void 54198933fa13SRandall Stewart sctp_flush_reassm_for_str_seq(struct sctp_tcb *stcb, 54208933fa13SRandall Stewart struct sctp_association *asoc, 54218933fa13SRandall Stewart uint16_t stream, uint16_t seq) 54228933fa13SRandall Stewart { 54238933fa13SRandall Stewart struct sctp_tmit_chunk *chk, *at; 54248933fa13SRandall Stewart 54258933fa13SRandall Stewart if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 54268933fa13SRandall Stewart /* For each one on here see if we need to toss it */ 54278933fa13SRandall Stewart /* 54288933fa13SRandall Stewart * For now large messages held on the reasmqueue that are 54298933fa13SRandall Stewart * complete will be tossed too. We could in theory do more 54308933fa13SRandall Stewart * work to spin through and stop after dumping one msg aka 54318933fa13SRandall Stewart * seeing the start of a new msg at the head, and call the 54328933fa13SRandall Stewart * delivery function... to see if it can be delivered... But 54338933fa13SRandall Stewart * for now we just dump everything on the queue. 54348933fa13SRandall Stewart */ 54358933fa13SRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 54368933fa13SRandall Stewart while (chk) { 54378933fa13SRandall Stewart at = TAILQ_NEXT(chk, sctp_next); 54388e71b694SMichael Tuexen /* 54398e71b694SMichael Tuexen * Do not toss it if on a different stream or marked 54408e71b694SMichael Tuexen * for unordered delivery in which case the stream 54418e71b694SMichael Tuexen * sequence number has no meaning. 54428e71b694SMichael Tuexen */ 54438e71b694SMichael Tuexen if ((chk->rec.data.stream_number != stream) || 54448e71b694SMichael Tuexen ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == SCTP_DATA_UNORDERED)) { 54458933fa13SRandall Stewart chk = at; 54468933fa13SRandall Stewart continue; 54478933fa13SRandall Stewart } 54488933fa13SRandall Stewart if (chk->rec.data.stream_seq == seq) { 54498933fa13SRandall Stewart /* It needs to be tossed */ 54508933fa13SRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 54518933fa13SRandall Stewart if (compare_with_wrap(chk->rec.data.TSN_seq, 54528933fa13SRandall Stewart asoc->tsn_last_delivered, MAX_TSN)) { 54538933fa13SRandall Stewart asoc->tsn_last_delivered = 54548933fa13SRandall Stewart chk->rec.data.TSN_seq; 54558933fa13SRandall Stewart asoc->str_of_pdapi = 54568933fa13SRandall Stewart chk->rec.data.stream_number; 54578933fa13SRandall Stewart asoc->ssn_of_pdapi = 54588933fa13SRandall Stewart chk->rec.data.stream_seq; 54598933fa13SRandall Stewart asoc->fragment_flags = 54608933fa13SRandall Stewart chk->rec.data.rcv_flags; 54618933fa13SRandall Stewart } 54628933fa13SRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 54638933fa13SRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 54648933fa13SRandall Stewart 54658933fa13SRandall Stewart /* Clear up any stream problem */ 54668933fa13SRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) != 54678933fa13SRandall Stewart SCTP_DATA_UNORDERED && 54688933fa13SRandall Stewart (compare_with_wrap(chk->rec.data.stream_seq, 54698933fa13SRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered, 54708933fa13SRandall Stewart MAX_SEQ))) { 54718933fa13SRandall Stewart /* 54728933fa13SRandall Stewart * We must dump forward this streams 54738933fa13SRandall Stewart * sequence number if the chunk is 54748933fa13SRandall Stewart * not unordered that is being 54758933fa13SRandall Stewart * skipped. There is a chance that 54768933fa13SRandall Stewart * if the peer does not include the 54778933fa13SRandall Stewart * last fragment in its FWD-TSN we 54788933fa13SRandall Stewart * WILL have a problem here since 54798933fa13SRandall Stewart * you would have a partial chunk in 54808933fa13SRandall Stewart * queue that may not be 54818933fa13SRandall Stewart * deliverable. Also if a Partial 54828933fa13SRandall Stewart * delivery API as started the user 54838933fa13SRandall Stewart * may get a partial chunk. The next 54848933fa13SRandall Stewart * read returning a new chunk... 54858933fa13SRandall Stewart * really ugly but I see no way 54868933fa13SRandall Stewart * around it! Maybe a notify?? 54878933fa13SRandall Stewart */ 54888933fa13SRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered = 54898933fa13SRandall Stewart chk->rec.data.stream_seq; 54908933fa13SRandall Stewart } 54918933fa13SRandall Stewart if (chk->data) { 54928933fa13SRandall Stewart sctp_m_freem(chk->data); 54938933fa13SRandall Stewart chk->data = NULL; 54948933fa13SRandall Stewart } 54958933fa13SRandall Stewart sctp_free_a_chunk(stcb, chk); 54968933fa13SRandall Stewart } else if (compare_with_wrap(chk->rec.data.stream_seq, seq, MAX_SEQ)) { 54978933fa13SRandall Stewart /* 54988933fa13SRandall Stewart * If the stream_seq is > than the purging 54998933fa13SRandall Stewart * one, we are done 55008933fa13SRandall Stewart */ 55018933fa13SRandall Stewart break; 55028933fa13SRandall Stewart } 55038933fa13SRandall Stewart chk = at; 55048933fa13SRandall Stewart } 55058933fa13SRandall Stewart } 55068933fa13SRandall Stewart } 55078933fa13SRandall Stewart 55088933fa13SRandall Stewart 5509f8829a4aSRandall Stewart void 5510f8829a4aSRandall Stewart sctp_handle_forward_tsn(struct sctp_tcb *stcb, 5511b5c16493SMichael Tuexen struct sctp_forward_tsn_chunk *fwd, 5512b5c16493SMichael Tuexen int *abort_flag, struct mbuf *m, int offset) 5513f8829a4aSRandall Stewart { 5514f8829a4aSRandall Stewart /* 5515f8829a4aSRandall Stewart * ISSUES that MUST be fixed for ECN! When we are the sender of the 5516f8829a4aSRandall Stewart * forward TSN, when the SACK comes back that acknowledges the 5517f8829a4aSRandall Stewart * FWD-TSN we must reset the NONCE sum to match correctly. This will 5518f8829a4aSRandall Stewart * get quite tricky since we may have sent more data interveneing 5519f8829a4aSRandall Stewart * and must carefully account for what the SACK says on the nonce 5520f8829a4aSRandall Stewart * and any gaps that are reported. This work will NOT be done here, 5521f8829a4aSRandall Stewart * but I note it here since it is really related to PR-SCTP and 5522f8829a4aSRandall Stewart * FWD-TSN's 5523f8829a4aSRandall Stewart */ 5524f8829a4aSRandall Stewart 5525f8829a4aSRandall Stewart /* The pr-sctp fwd tsn */ 5526f8829a4aSRandall Stewart /* 5527f8829a4aSRandall Stewart * here we will perform all the data receiver side steps for 5528f8829a4aSRandall Stewart * processing FwdTSN, as required in by pr-sctp draft: 5529f8829a4aSRandall Stewart * 5530f8829a4aSRandall Stewart * Assume we get FwdTSN(x): 5531f8829a4aSRandall Stewart * 5532f8829a4aSRandall Stewart * 1) update local cumTSN to x 2) try to further advance cumTSN to x + 5533f8829a4aSRandall Stewart * others we have 3) examine and update re-ordering queue on 5534f8829a4aSRandall Stewart * pr-in-streams 4) clean up re-assembly queue 5) Send a sack to 5535f8829a4aSRandall Stewart * report where we are. 5536f8829a4aSRandall Stewart */ 5537f8829a4aSRandall Stewart struct sctp_association *asoc; 55387898f408SRandall Stewart uint32_t new_cum_tsn, gap; 55397898f408SRandall Stewart unsigned int i, fwd_sz, cumack_set_flag, m_size; 55408933fa13SRandall Stewart uint32_t str_seq; 5541f8829a4aSRandall Stewart struct sctp_stream_in *strm; 5542f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk, *at; 55438933fa13SRandall Stewart struct sctp_queued_to_read *ctl, *sv; 5544f8829a4aSRandall Stewart 5545f8829a4aSRandall Stewart cumack_set_flag = 0; 5546f8829a4aSRandall Stewart asoc = &stcb->asoc; 5547f8829a4aSRandall Stewart if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) { 5548ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, 5549ad81507eSRandall Stewart "Bad size too small/big fwd-tsn\n"); 5550f8829a4aSRandall Stewart return; 5551f8829a4aSRandall Stewart } 5552f8829a4aSRandall Stewart m_size = (stcb->asoc.mapping_array_size << 3); 5553f8829a4aSRandall Stewart /*************************************************************/ 5554f8829a4aSRandall Stewart /* 1. Here we update local cumTSN and shift the bitmap array */ 5555f8829a4aSRandall Stewart /*************************************************************/ 5556f8829a4aSRandall Stewart new_cum_tsn = ntohl(fwd->new_cumulative_tsn); 5557f8829a4aSRandall Stewart 5558f8829a4aSRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, new_cum_tsn, MAX_TSN) || 5559f8829a4aSRandall Stewart asoc->cumulative_tsn == new_cum_tsn) { 5560f8829a4aSRandall Stewart /* Already got there ... */ 5561f8829a4aSRandall Stewart return; 5562f8829a4aSRandall Stewart } 5563f8829a4aSRandall Stewart /* 5564f8829a4aSRandall Stewart * now we know the new TSN is more advanced, let's find the actual 5565f8829a4aSRandall Stewart * gap 5566f8829a4aSRandall Stewart */ 5567b5c16493SMichael Tuexen SCTP_CALC_TSN_TO_GAP(gap, new_cum_tsn, asoc->mapping_array_base_tsn); 556877acdc25SRandall Stewart asoc->cumulative_tsn = new_cum_tsn; 55692afb3e84SRandall Stewart if (gap >= m_size) { 5570f8829a4aSRandall Stewart if ((long)gap > sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv)) { 557117205eccSRandall Stewart struct mbuf *oper; 557217205eccSRandall Stewart 5573f8829a4aSRandall Stewart /* 5574f8829a4aSRandall Stewart * out of range (of single byte chunks in the rwnd I 557517205eccSRandall Stewart * give out). This must be an attacker. 5576f8829a4aSRandall Stewart */ 557717205eccSRandall Stewart *abort_flag = 1; 557817205eccSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 557917205eccSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 558017205eccSRandall Stewart if (oper) { 558117205eccSRandall Stewart struct sctp_paramhdr *ph; 558217205eccSRandall Stewart uint32_t *ippp; 558317205eccSRandall Stewart 558417205eccSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 558517205eccSRandall Stewart (sizeof(uint32_t) * 3); 558617205eccSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 558717205eccSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 558817205eccSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 558917205eccSRandall Stewart ippp = (uint32_t *) (ph + 1); 559017205eccSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_33); 559117205eccSRandall Stewart ippp++; 559217205eccSRandall Stewart *ippp = asoc->highest_tsn_inside_map; 559317205eccSRandall Stewart ippp++; 559417205eccSRandall Stewart *ippp = new_cum_tsn; 559517205eccSRandall Stewart } 559617205eccSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_33; 559717205eccSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 5598ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 5599f8829a4aSRandall Stewart return; 5600f8829a4aSRandall Stewart } 5601207304d4SRandall Stewart SCTP_STAT_INCR(sctps_fwdtsn_map_over); 560277acdc25SRandall Stewart 56032afb3e84SRandall Stewart memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size); 56042afb3e84SRandall Stewart asoc->mapping_array_base_tsn = new_cum_tsn + 1; 560577acdc25SRandall Stewart asoc->highest_tsn_inside_map = new_cum_tsn; 560677acdc25SRandall Stewart 5607b5c16493SMichael Tuexen memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.mapping_array_size); 5608830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = new_cum_tsn; 560977acdc25SRandall Stewart 5610b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 5611f8829a4aSRandall Stewart sctp_log_map(0, 3, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 561280fefe0aSRandall Stewart } 5613f8829a4aSRandall Stewart asoc->last_echo_tsn = asoc->highest_tsn_inside_map; 56142afb3e84SRandall Stewart } else { 56152afb3e84SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 56162afb3e84SRandall Stewart for (i = 0; i <= gap; i++) { 56177898f408SRandall Stewart if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, i) && 56187898f408SRandall Stewart !SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, i)) { 56198933fa13SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, i); 56207898f408SRandall Stewart if (compare_with_wrap(asoc->mapping_array_base_tsn + i, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 56217898f408SRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->mapping_array_base_tsn + i; 5622b5c16493SMichael Tuexen } 5623b5c16493SMichael Tuexen } 5624b5c16493SMichael Tuexen } 5625f8829a4aSRandall Stewart } 5626f8829a4aSRandall Stewart /*************************************************************/ 5627f8829a4aSRandall Stewart /* 2. Clear up re-assembly queue */ 5628f8829a4aSRandall Stewart /*************************************************************/ 5629f8829a4aSRandall Stewart /* 5630f8829a4aSRandall Stewart * First service it if pd-api is up, just in case we can progress it 5631f8829a4aSRandall Stewart * forward 5632f8829a4aSRandall Stewart */ 5633f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 5634f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 5635f8829a4aSRandall Stewart } 5636f8829a4aSRandall Stewart if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 5637f8829a4aSRandall Stewart /* For each one on here see if we need to toss it */ 5638f8829a4aSRandall Stewart /* 5639f8829a4aSRandall Stewart * For now large messages held on the reasmqueue that are 5640f8829a4aSRandall Stewart * complete will be tossed too. We could in theory do more 5641f8829a4aSRandall Stewart * work to spin through and stop after dumping one msg aka 5642f8829a4aSRandall Stewart * seeing the start of a new msg at the head, and call the 5643f8829a4aSRandall Stewart * delivery function... to see if it can be delivered... But 5644f8829a4aSRandall Stewart * for now we just dump everything on the queue. 5645f8829a4aSRandall Stewart */ 5646f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 5647f8829a4aSRandall Stewart while (chk) { 5648f8829a4aSRandall Stewart at = TAILQ_NEXT(chk, sctp_next); 56490c0982b8SRandall Stewart if ((compare_with_wrap(new_cum_tsn, 56500c0982b8SRandall Stewart chk->rec.data.TSN_seq, MAX_TSN)) || 56510c0982b8SRandall Stewart (new_cum_tsn == chk->rec.data.TSN_seq)) { 5652f8829a4aSRandall Stewart /* It needs to be tossed */ 5653f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 5654f8829a4aSRandall Stewart if (compare_with_wrap(chk->rec.data.TSN_seq, 5655f8829a4aSRandall Stewart asoc->tsn_last_delivered, MAX_TSN)) { 5656f8829a4aSRandall Stewart asoc->tsn_last_delivered = 5657f8829a4aSRandall Stewart chk->rec.data.TSN_seq; 5658f8829a4aSRandall Stewart asoc->str_of_pdapi = 5659f8829a4aSRandall Stewart chk->rec.data.stream_number; 5660f8829a4aSRandall Stewart asoc->ssn_of_pdapi = 5661f8829a4aSRandall Stewart chk->rec.data.stream_seq; 5662f8829a4aSRandall Stewart asoc->fragment_flags = 5663f8829a4aSRandall Stewart chk->rec.data.rcv_flags; 5664f8829a4aSRandall Stewart } 5665f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 5666f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 5667f8829a4aSRandall Stewart 5668f8829a4aSRandall Stewart /* Clear up any stream problem */ 5669f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) != 5670f8829a4aSRandall Stewart SCTP_DATA_UNORDERED && 5671f8829a4aSRandall Stewart (compare_with_wrap(chk->rec.data.stream_seq, 5672f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered, 5673f8829a4aSRandall Stewart MAX_SEQ))) { 5674f8829a4aSRandall Stewart /* 5675f8829a4aSRandall Stewart * We must dump forward this streams 5676f8829a4aSRandall Stewart * sequence number if the chunk is 5677f8829a4aSRandall Stewart * not unordered that is being 5678f8829a4aSRandall Stewart * skipped. There is a chance that 5679f8829a4aSRandall Stewart * if the peer does not include the 5680f8829a4aSRandall Stewart * last fragment in its FWD-TSN we 5681f8829a4aSRandall Stewart * WILL have a problem here since 5682f8829a4aSRandall Stewart * you would have a partial chunk in 5683f8829a4aSRandall Stewart * queue that may not be 5684f8829a4aSRandall Stewart * deliverable. Also if a Partial 5685f8829a4aSRandall Stewart * delivery API as started the user 5686f8829a4aSRandall Stewart * may get a partial chunk. The next 5687f8829a4aSRandall Stewart * read returning a new chunk... 5688f8829a4aSRandall Stewart * really ugly but I see no way 5689f8829a4aSRandall Stewart * around it! Maybe a notify?? 5690f8829a4aSRandall Stewart */ 5691f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered = 5692f8829a4aSRandall Stewart chk->rec.data.stream_seq; 5693f8829a4aSRandall Stewart } 5694f8829a4aSRandall Stewart if (chk->data) { 5695f8829a4aSRandall Stewart sctp_m_freem(chk->data); 5696f8829a4aSRandall Stewart chk->data = NULL; 5697f8829a4aSRandall Stewart } 5698f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 5699f8829a4aSRandall Stewart } else { 5700f8829a4aSRandall Stewart /* 5701f8829a4aSRandall Stewart * Ok we have gone beyond the end of the 57028933fa13SRandall Stewart * fwd-tsn's mark. 5703f8829a4aSRandall Stewart */ 5704f8829a4aSRandall Stewart break; 5705f8829a4aSRandall Stewart } 5706f8829a4aSRandall Stewart chk = at; 5707f8829a4aSRandall Stewart } 5708f8829a4aSRandall Stewart } 57098933fa13SRandall Stewart /*******************************************************/ 57108933fa13SRandall Stewart /* 3. Update the PR-stream re-ordering queues and fix */ 57118933fa13SRandall Stewart /* delivery issues as needed. */ 57128933fa13SRandall Stewart /*******************************************************/ 5713f8829a4aSRandall Stewart fwd_sz -= sizeof(*fwd); 5714671d309cSRandall Stewart if (m && fwd_sz) { 5715f8829a4aSRandall Stewart /* New method. */ 5716d61a0ae0SRandall Stewart unsigned int num_str; 5717671d309cSRandall Stewart struct sctp_strseq *stseq, strseqbuf; 5718671d309cSRandall Stewart 5719671d309cSRandall Stewart offset += sizeof(*fwd); 5720f8829a4aSRandall Stewart 57218933fa13SRandall Stewart SCTP_INP_READ_LOCK(stcb->sctp_ep); 5722f8829a4aSRandall Stewart num_str = fwd_sz / sizeof(struct sctp_strseq); 5723f8829a4aSRandall Stewart for (i = 0; i < num_str; i++) { 5724f8829a4aSRandall Stewart uint16_t st; 5725f8829a4aSRandall Stewart 5726671d309cSRandall Stewart stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset, 5727671d309cSRandall Stewart sizeof(struct sctp_strseq), 5728671d309cSRandall Stewart (uint8_t *) & strseqbuf); 5729671d309cSRandall Stewart offset += sizeof(struct sctp_strseq); 57302afb3e84SRandall Stewart if (stseq == NULL) { 5731671d309cSRandall Stewart break; 57322afb3e84SRandall Stewart } 5733f8829a4aSRandall Stewart /* Convert */ 5734851b7298SRandall Stewart st = ntohs(stseq->stream); 5735851b7298SRandall Stewart stseq->stream = st; 5736851b7298SRandall Stewart st = ntohs(stseq->sequence); 5737851b7298SRandall Stewart stseq->sequence = st; 57388933fa13SRandall Stewart 5739f8829a4aSRandall Stewart /* now process */ 57408933fa13SRandall Stewart 57418933fa13SRandall Stewart /* 57428933fa13SRandall Stewart * Ok we now look for the stream/seq on the read 57438933fa13SRandall Stewart * queue where its not all delivered. If we find it 57448933fa13SRandall Stewart * we transmute the read entry into a PDI_ABORTED. 57458933fa13SRandall Stewart */ 5746851b7298SRandall Stewart if (stseq->stream >= asoc->streamincnt) { 57472afb3e84SRandall Stewart /* screwed up streams, stop! */ 57482afb3e84SRandall Stewart break; 5749f8829a4aSRandall Stewart } 57508933fa13SRandall Stewart if ((asoc->str_of_pdapi == stseq->stream) && 57518933fa13SRandall Stewart (asoc->ssn_of_pdapi == stseq->sequence)) { 57528933fa13SRandall Stewart /* 57538933fa13SRandall Stewart * If this is the one we were partially 57548933fa13SRandall Stewart * delivering now then we no longer are. 57558933fa13SRandall Stewart * Note this will change with the reassembly 57568933fa13SRandall Stewart * re-write. 57578933fa13SRandall Stewart */ 57588933fa13SRandall Stewart asoc->fragmented_delivery_inprogress = 0; 57598933fa13SRandall Stewart } 57608933fa13SRandall Stewart sctp_flush_reassm_for_str_seq(stcb, asoc, stseq->stream, stseq->sequence); 57618933fa13SRandall Stewart TAILQ_FOREACH(ctl, &stcb->sctp_ep->read_queue, next) { 57628933fa13SRandall Stewart if ((ctl->sinfo_stream == stseq->stream) && 57638933fa13SRandall Stewart (ctl->sinfo_ssn == stseq->sequence)) { 57648933fa13SRandall Stewart str_seq = (stseq->stream << 16) | stseq->sequence; 57658933fa13SRandall Stewart ctl->end_added = 1; 57668933fa13SRandall Stewart ctl->pdapi_aborted = 1; 57678933fa13SRandall Stewart sv = stcb->asoc.control_pdapi; 57688933fa13SRandall Stewart stcb->asoc.control_pdapi = ctl; 5769810ec536SMichael Tuexen sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION, 5770810ec536SMichael Tuexen stcb, 57718933fa13SRandall Stewart SCTP_PARTIAL_DELIVERY_ABORTED, 5772810ec536SMichael Tuexen (void *)&str_seq, 5773810ec536SMichael Tuexen SCTP_SO_NOT_LOCKED); 57748933fa13SRandall Stewart stcb->asoc.control_pdapi = sv; 57758933fa13SRandall Stewart break; 57768933fa13SRandall Stewart } else if ((ctl->sinfo_stream == stseq->stream) && 57778933fa13SRandall Stewart (compare_with_wrap(ctl->sinfo_ssn, stseq->sequence, MAX_SEQ))) { 57788933fa13SRandall Stewart /* We are past our victim SSN */ 57798933fa13SRandall Stewart break; 57808933fa13SRandall Stewart } 57818933fa13SRandall Stewart } 5782851b7298SRandall Stewart strm = &asoc->strmin[stseq->stream]; 5783851b7298SRandall Stewart if (compare_with_wrap(stseq->sequence, 5784f8829a4aSRandall Stewart strm->last_sequence_delivered, MAX_SEQ)) { 5785f8829a4aSRandall Stewart /* Update the sequence number */ 5786f8829a4aSRandall Stewart strm->last_sequence_delivered = 5787851b7298SRandall Stewart stseq->sequence; 5788f8829a4aSRandall Stewart } 5789f8829a4aSRandall Stewart /* now kick the stream the new way */ 579004ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 5791f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(stcb, strm); 5792f8829a4aSRandall Stewart } 57938933fa13SRandall Stewart SCTP_INP_READ_UNLOCK(stcb->sctp_ep); 5794f8829a4aSRandall Stewart } 57957898f408SRandall Stewart /* 57967898f408SRandall Stewart * Now slide thing forward. 57977898f408SRandall Stewart */ 57987898f408SRandall Stewart sctp_slide_mapping_arrays(stcb); 57997898f408SRandall Stewart 5800139bc87fSRandall Stewart if (TAILQ_FIRST(&asoc->reasmqueue)) { 5801139bc87fSRandall Stewart /* now lets kick out and check for more fragmented delivery */ 580204ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 5803139bc87fSRandall Stewart sctp_deliver_reasm_check(stcb, &stcb->asoc); 5804139bc87fSRandall Stewart } 5805f8829a4aSRandall Stewart } 5806