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 */ 94*44fbe462SRandall Stewart calc = sctp_sbspace_sub(calc, (uint32_t) (asoc->size_on_reasm_queue + 95*44fbe462SRandall Stewart asoc->cnt_on_reasm_queue * MSIZE)); 96*44fbe462SRandall Stewart calc = sctp_sbspace_sub(calc, (uint32_t) (asoc->size_on_all_streams + 97*44fbe462SRandall Stewart asoc->cnt_on_all_streams * MSIZE)); 98f8829a4aSRandall Stewart 99f8829a4aSRandall Stewart if (calc == 0) { 100f8829a4aSRandall Stewart /* out of space */ 101f8829a4aSRandall Stewart return (calc); 102f8829a4aSRandall Stewart } 103f8829a4aSRandall Stewart /* what is the overhead of all these rwnd's */ 1042afb3e84SRandall Stewart calc = sctp_sbspace_sub(calc, stcb->asoc.my_rwnd_control_len); 105b3f1ea41SRandall Stewart /* 106b3f1ea41SRandall Stewart * If the window gets too small due to ctrl-stuff, reduce it to 1, 107b3f1ea41SRandall Stewart * even it is 0. SWS engaged 108f8829a4aSRandall Stewart */ 109b3f1ea41SRandall Stewart if (calc < stcb->asoc.my_rwnd_control_len) { 110b3f1ea41SRandall Stewart calc = 1; 1112afb3e84SRandall Stewart } 112b3f1ea41SRandall Stewart return (calc); 113f8829a4aSRandall Stewart } 114f8829a4aSRandall Stewart 115f8829a4aSRandall Stewart 116f8829a4aSRandall Stewart 117f8829a4aSRandall Stewart /* 118f8829a4aSRandall Stewart * Build out our readq entry based on the incoming packet. 119f8829a4aSRandall Stewart */ 120f8829a4aSRandall Stewart struct sctp_queued_to_read * 121f8829a4aSRandall Stewart sctp_build_readq_entry(struct sctp_tcb *stcb, 122f8829a4aSRandall Stewart struct sctp_nets *net, 123f8829a4aSRandall Stewart uint32_t tsn, uint32_t ppid, 124f8829a4aSRandall Stewart uint32_t context, uint16_t stream_no, 125f8829a4aSRandall Stewart uint16_t stream_seq, uint8_t flags, 126f8829a4aSRandall Stewart struct mbuf *dm) 127f8829a4aSRandall Stewart { 128f8829a4aSRandall Stewart struct sctp_queued_to_read *read_queue_e = NULL; 129f8829a4aSRandall Stewart 130f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, read_queue_e); 131f8829a4aSRandall Stewart if (read_queue_e == NULL) { 132f8829a4aSRandall Stewart goto failed_build; 133f8829a4aSRandall Stewart } 134f8829a4aSRandall Stewart read_queue_e->sinfo_stream = stream_no; 135f8829a4aSRandall Stewart read_queue_e->sinfo_ssn = stream_seq; 136f8829a4aSRandall Stewart read_queue_e->sinfo_flags = (flags << 8); 137f8829a4aSRandall Stewart read_queue_e->sinfo_ppid = ppid; 138f8829a4aSRandall Stewart read_queue_e->sinfo_context = stcb->asoc.context; 139f8829a4aSRandall Stewart read_queue_e->sinfo_timetolive = 0; 140f8829a4aSRandall Stewart read_queue_e->sinfo_tsn = tsn; 141f8829a4aSRandall Stewart read_queue_e->sinfo_cumtsn = tsn; 142f8829a4aSRandall Stewart read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb); 143f8829a4aSRandall Stewart read_queue_e->whoFrom = net; 144f8829a4aSRandall Stewart read_queue_e->length = 0; 145f8829a4aSRandall Stewart atomic_add_int(&net->ref_count, 1); 146f8829a4aSRandall Stewart read_queue_e->data = dm; 147139bc87fSRandall Stewart read_queue_e->spec_flags = 0; 148f8829a4aSRandall Stewart read_queue_e->tail_mbuf = NULL; 14917205eccSRandall Stewart read_queue_e->aux_data = NULL; 150f8829a4aSRandall Stewart read_queue_e->stcb = stcb; 151f8829a4aSRandall Stewart read_queue_e->port_from = stcb->rport; 152f8829a4aSRandall Stewart read_queue_e->do_not_ref_stcb = 0; 153f8829a4aSRandall Stewart read_queue_e->end_added = 0; 1549a6142d8SRandall Stewart read_queue_e->some_taken = 0; 15503b0b021SRandall Stewart read_queue_e->pdapi_aborted = 0; 156f8829a4aSRandall Stewart failed_build: 157f8829a4aSRandall Stewart return (read_queue_e); 158f8829a4aSRandall Stewart } 159f8829a4aSRandall Stewart 160f8829a4aSRandall Stewart 161f8829a4aSRandall Stewart /* 162f8829a4aSRandall Stewart * Build out our readq entry based on the incoming packet. 163f8829a4aSRandall Stewart */ 164f8829a4aSRandall Stewart static struct sctp_queued_to_read * 165f8829a4aSRandall Stewart sctp_build_readq_entry_chk(struct sctp_tcb *stcb, 166f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk) 167f8829a4aSRandall Stewart { 168f8829a4aSRandall Stewart struct sctp_queued_to_read *read_queue_e = NULL; 169f8829a4aSRandall Stewart 170f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, read_queue_e); 171f8829a4aSRandall Stewart if (read_queue_e == NULL) { 172f8829a4aSRandall Stewart goto failed_build; 173f8829a4aSRandall Stewart } 174f8829a4aSRandall Stewart read_queue_e->sinfo_stream = chk->rec.data.stream_number; 175f8829a4aSRandall Stewart read_queue_e->sinfo_ssn = chk->rec.data.stream_seq; 176f8829a4aSRandall Stewart read_queue_e->sinfo_flags = (chk->rec.data.rcv_flags << 8); 177f8829a4aSRandall Stewart read_queue_e->sinfo_ppid = chk->rec.data.payloadtype; 178f8829a4aSRandall Stewart read_queue_e->sinfo_context = stcb->asoc.context; 179f8829a4aSRandall Stewart read_queue_e->sinfo_timetolive = 0; 180f8829a4aSRandall Stewart read_queue_e->sinfo_tsn = chk->rec.data.TSN_seq; 181f8829a4aSRandall Stewart read_queue_e->sinfo_cumtsn = chk->rec.data.TSN_seq; 182f8829a4aSRandall Stewart read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb); 183f8829a4aSRandall Stewart read_queue_e->whoFrom = chk->whoTo; 18417205eccSRandall Stewart read_queue_e->aux_data = NULL; 185f8829a4aSRandall Stewart read_queue_e->length = 0; 186f8829a4aSRandall Stewart atomic_add_int(&chk->whoTo->ref_count, 1); 187f8829a4aSRandall Stewart read_queue_e->data = chk->data; 188f8829a4aSRandall Stewart read_queue_e->tail_mbuf = NULL; 189f8829a4aSRandall Stewart read_queue_e->stcb = stcb; 190f8829a4aSRandall Stewart read_queue_e->port_from = stcb->rport; 191139bc87fSRandall Stewart read_queue_e->spec_flags = 0; 192f8829a4aSRandall Stewart read_queue_e->do_not_ref_stcb = 0; 193f8829a4aSRandall Stewart read_queue_e->end_added = 0; 1949a6142d8SRandall Stewart read_queue_e->some_taken = 0; 19503b0b021SRandall Stewart read_queue_e->pdapi_aborted = 0; 196f8829a4aSRandall Stewart failed_build: 197f8829a4aSRandall Stewart return (read_queue_e); 198f8829a4aSRandall Stewart } 199f8829a4aSRandall Stewart 200f8829a4aSRandall Stewart 201f8829a4aSRandall Stewart struct mbuf * 202f8829a4aSRandall Stewart sctp_build_ctl_nchunk(struct sctp_inpcb *inp, 203f8829a4aSRandall Stewart struct sctp_sndrcvinfo *sinfo) 204f8829a4aSRandall Stewart { 205f8829a4aSRandall Stewart struct sctp_sndrcvinfo *outinfo; 206f8829a4aSRandall Stewart struct cmsghdr *cmh; 207f8829a4aSRandall Stewart struct mbuf *ret; 208f8829a4aSRandall Stewart int len; 209f8829a4aSRandall Stewart int use_extended = 0; 210f8829a4aSRandall Stewart 211f8829a4aSRandall Stewart if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) { 212f8829a4aSRandall Stewart /* user does not want the sndrcv ctl */ 213f8829a4aSRandall Stewart return (NULL); 214f8829a4aSRandall Stewart } 215f8829a4aSRandall Stewart if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) { 216f8829a4aSRandall Stewart use_extended = 1; 217f8829a4aSRandall Stewart len = CMSG_LEN(sizeof(struct sctp_extrcvinfo)); 218f8829a4aSRandall Stewart } else { 219f8829a4aSRandall Stewart len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 220f8829a4aSRandall Stewart } 221f8829a4aSRandall Stewart 222f8829a4aSRandall Stewart 223f8829a4aSRandall Stewart ret = sctp_get_mbuf_for_msg(len, 224139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 225f8829a4aSRandall Stewart 226f8829a4aSRandall Stewart if (ret == NULL) { 227f8829a4aSRandall Stewart /* No space */ 228f8829a4aSRandall Stewart return (ret); 229f8829a4aSRandall Stewart } 230f8829a4aSRandall Stewart /* We need a CMSG header followed by the struct */ 231f8829a4aSRandall Stewart cmh = mtod(ret, struct cmsghdr *); 232f8829a4aSRandall Stewart outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh); 233f8829a4aSRandall Stewart cmh->cmsg_level = IPPROTO_SCTP; 234f8829a4aSRandall Stewart if (use_extended) { 235f8829a4aSRandall Stewart cmh->cmsg_type = SCTP_EXTRCV; 236f8829a4aSRandall Stewart cmh->cmsg_len = len; 237f8829a4aSRandall Stewart memcpy(outinfo, sinfo, len); 238f8829a4aSRandall Stewart } else { 239f8829a4aSRandall Stewart cmh->cmsg_type = SCTP_SNDRCV; 240f8829a4aSRandall Stewart cmh->cmsg_len = len; 241f8829a4aSRandall Stewart *outinfo = *sinfo; 242f8829a4aSRandall Stewart } 243139bc87fSRandall Stewart SCTP_BUF_LEN(ret) = cmh->cmsg_len; 244f8829a4aSRandall Stewart return (ret); 245f8829a4aSRandall Stewart } 246f8829a4aSRandall Stewart 247139bc87fSRandall Stewart 24817205eccSRandall Stewart char * 24917205eccSRandall Stewart sctp_build_ctl_cchunk(struct sctp_inpcb *inp, 25017205eccSRandall Stewart int *control_len, 25117205eccSRandall Stewart struct sctp_sndrcvinfo *sinfo) 25217205eccSRandall Stewart { 25317205eccSRandall Stewart struct sctp_sndrcvinfo *outinfo; 25417205eccSRandall Stewart struct cmsghdr *cmh; 25517205eccSRandall Stewart char *buf; 25617205eccSRandall Stewart int len; 25717205eccSRandall Stewart int use_extended = 0; 25817205eccSRandall Stewart 25917205eccSRandall Stewart if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) { 26017205eccSRandall Stewart /* user does not want the sndrcv ctl */ 26117205eccSRandall Stewart return (NULL); 26217205eccSRandall Stewart } 26317205eccSRandall Stewart if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) { 26417205eccSRandall Stewart use_extended = 1; 26517205eccSRandall Stewart len = CMSG_LEN(sizeof(struct sctp_extrcvinfo)); 26617205eccSRandall Stewart } else { 26717205eccSRandall Stewart len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 26817205eccSRandall Stewart } 269207304d4SRandall Stewart SCTP_MALLOC(buf, char *, len, SCTP_M_CMSG); 27017205eccSRandall Stewart if (buf == NULL) { 27117205eccSRandall Stewart /* No space */ 27217205eccSRandall Stewart return (buf); 27317205eccSRandall Stewart } 27417205eccSRandall Stewart /* We need a CMSG header followed by the struct */ 27517205eccSRandall Stewart cmh = (struct cmsghdr *)buf; 27617205eccSRandall Stewart outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh); 27717205eccSRandall Stewart cmh->cmsg_level = IPPROTO_SCTP; 27817205eccSRandall Stewart if (use_extended) { 27917205eccSRandall Stewart cmh->cmsg_type = SCTP_EXTRCV; 28017205eccSRandall Stewart cmh->cmsg_len = len; 28117205eccSRandall Stewart memcpy(outinfo, sinfo, len); 28217205eccSRandall Stewart } else { 28317205eccSRandall Stewart cmh->cmsg_type = SCTP_SNDRCV; 28417205eccSRandall Stewart cmh->cmsg_len = len; 28517205eccSRandall Stewart *outinfo = *sinfo; 28617205eccSRandall Stewart } 28717205eccSRandall Stewart *control_len = len; 28817205eccSRandall Stewart return (buf); 28917205eccSRandall Stewart } 29017205eccSRandall Stewart 29177acdc25SRandall Stewart static void 29277acdc25SRandall Stewart sctp_mark_non_revokable(struct sctp_association *asoc, uint32_t tsn) 29377acdc25SRandall Stewart { 2949b2e0767SRandall Stewart uint32_t gap, i, cumackp1; 29577acdc25SRandall Stewart int fnd = 0; 29677acdc25SRandall Stewart 29777acdc25SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) { 29877acdc25SRandall Stewart return; 29977acdc25SRandall Stewart } 3009b2e0767SRandall Stewart cumackp1 = asoc->cumulative_tsn + 1; 3019b2e0767SRandall Stewart if (compare_with_wrap(cumackp1, tsn, MAX_TSN)) { 3029b2e0767SRandall Stewart /* 3039b2e0767SRandall Stewart * this tsn is behind the cum ack and thus we don't need to 3049b2e0767SRandall Stewart * worry about it being moved from one to the other. 3059b2e0767SRandall Stewart */ 3069b2e0767SRandall Stewart return; 3079b2e0767SRandall Stewart } 30877acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn); 30977acdc25SRandall Stewart if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) { 31077acdc25SRandall Stewart printf("gap:%x tsn:%x\n", gap, tsn); 31177acdc25SRandall Stewart sctp_print_mapping_array(asoc); 312b5c16493SMichael Tuexen #ifdef INVARIANTS 31377acdc25SRandall Stewart panic("Things are really messed up now!!"); 31477acdc25SRandall Stewart #endif 315b5c16493SMichael Tuexen } 31677acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 31777acdc25SRandall Stewart SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, gap); 31877acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 31977acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 32077acdc25SRandall Stewart } 32177acdc25SRandall Stewart if (tsn == asoc->highest_tsn_inside_map) { 32277acdc25SRandall Stewart /* We must back down to see what the new highest is */ 323b5c16493SMichael Tuexen for (i = tsn - 1; (compare_with_wrap(i, asoc->mapping_array_base_tsn, MAX_TSN) || 324b5c16493SMichael Tuexen (i == asoc->mapping_array_base_tsn)); i--) { 32577acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, i, asoc->mapping_array_base_tsn); 32677acdc25SRandall Stewart if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) { 32777acdc25SRandall Stewart asoc->highest_tsn_inside_map = i; 32877acdc25SRandall Stewart fnd = 1; 32977acdc25SRandall Stewart break; 33077acdc25SRandall Stewart } 33177acdc25SRandall Stewart } 33277acdc25SRandall Stewart if (!fnd) { 33377acdc25SRandall Stewart asoc->highest_tsn_inside_map = asoc->mapping_array_base_tsn - 1; 33477acdc25SRandall Stewart } 33577acdc25SRandall Stewart } 33677acdc25SRandall Stewart } 33777acdc25SRandall Stewart 33817205eccSRandall Stewart 339f8829a4aSRandall Stewart /* 340f8829a4aSRandall Stewart * We are delivering currently from the reassembly queue. We must continue to 341f8829a4aSRandall Stewart * deliver until we either: 1) run out of space. 2) run out of sequential 342f8829a4aSRandall Stewart * TSN's 3) hit the SCTP_DATA_LAST_FRAG flag. 343f8829a4aSRandall Stewart */ 344f8829a4aSRandall Stewart static void 345f8829a4aSRandall Stewart sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc) 346f8829a4aSRandall Stewart { 347f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 348f8829a4aSRandall Stewart uint16_t nxt_todel; 349f8829a4aSRandall Stewart uint16_t stream_no; 350f8829a4aSRandall Stewart int end = 0; 351f8829a4aSRandall Stewart int cntDel; 352830d754dSRandall Stewart 353f8829a4aSRandall Stewart struct sctp_queued_to_read *control, *ctl, *ctlat; 354f8829a4aSRandall Stewart 355ad81507eSRandall Stewart if (stcb == NULL) 356ad81507eSRandall Stewart return; 357ad81507eSRandall Stewart 358f42a358aSRandall Stewart cntDel = stream_no = 0; 359ad81507eSRandall Stewart if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || 360851b7298SRandall Stewart (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) || 361ad81507eSRandall Stewart (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) { 362851b7298SRandall Stewart /* socket above is long gone or going.. */ 363851b7298SRandall Stewart abandon: 364f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 365f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 366f8829a4aSRandall Stewart while (chk) { 367f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 368f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 369f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 370f8829a4aSRandall Stewart /* 371f8829a4aSRandall Stewart * Lose the data pointer, since its in the socket 372f8829a4aSRandall Stewart * buffer 373f8829a4aSRandall Stewart */ 374f8829a4aSRandall Stewart if (chk->data) { 375f8829a4aSRandall Stewart sctp_m_freem(chk->data); 376f8829a4aSRandall Stewart chk->data = NULL; 377f8829a4aSRandall Stewart } 378f8829a4aSRandall Stewart /* Now free the address and data */ 379f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 3803c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 381f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 382f8829a4aSRandall Stewart } 383f8829a4aSRandall Stewart return; 384f8829a4aSRandall Stewart } 385f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 386f8829a4aSRandall Stewart do { 387f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 388f8829a4aSRandall Stewart if (chk == NULL) { 389f8829a4aSRandall Stewart return; 390f8829a4aSRandall Stewart } 391f8829a4aSRandall Stewart if (chk->rec.data.TSN_seq != (asoc->tsn_last_delivered + 1)) { 392f8829a4aSRandall Stewart /* Can't deliver more :< */ 393f8829a4aSRandall Stewart return; 394f8829a4aSRandall Stewart } 395f8829a4aSRandall Stewart stream_no = chk->rec.data.stream_number; 396f8829a4aSRandall Stewart nxt_todel = asoc->strmin[stream_no].last_sequence_delivered + 1; 397f8829a4aSRandall Stewart if (nxt_todel != chk->rec.data.stream_seq && 398f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { 399f8829a4aSRandall Stewart /* 400f8829a4aSRandall Stewart * Not the next sequence to deliver in its stream OR 401f8829a4aSRandall Stewart * unordered 402f8829a4aSRandall Stewart */ 403f8829a4aSRandall Stewart return; 404f8829a4aSRandall Stewart } 405f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 406f8829a4aSRandall Stewart 407f8829a4aSRandall Stewart control = sctp_build_readq_entry_chk(stcb, chk); 408f8829a4aSRandall Stewart if (control == NULL) { 409f8829a4aSRandall Stewart /* out of memory? */ 410f8829a4aSRandall Stewart return; 411f8829a4aSRandall Stewart } 412f8829a4aSRandall Stewart /* save it off for our future deliveries */ 413f8829a4aSRandall Stewart stcb->asoc.control_pdapi = control; 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 sctp_add_to_readq(stcb->sctp_ep, 420cfde3ff7SRandall Stewart stcb, control, &stcb->sctp_socket->so_rcv, end, 421cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 422f8829a4aSRandall Stewart cntDel++; 423f8829a4aSRandall Stewart } else { 424f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) 425f8829a4aSRandall Stewart end = 1; 426f8829a4aSRandall Stewart else 427f8829a4aSRandall Stewart end = 0; 428b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq); 429f8829a4aSRandall Stewart if (sctp_append_to_readq(stcb->sctp_ep, stcb, 430f8829a4aSRandall Stewart stcb->asoc.control_pdapi, 431f8829a4aSRandall Stewart chk->data, end, chk->rec.data.TSN_seq, 432f8829a4aSRandall Stewart &stcb->sctp_socket->so_rcv)) { 433f8829a4aSRandall Stewart /* 434f8829a4aSRandall Stewart * something is very wrong, either 435f8829a4aSRandall Stewart * control_pdapi is NULL, or the tail_mbuf 436f8829a4aSRandall Stewart * is corrupt, or there is a EOM already on 437f8829a4aSRandall Stewart * the mbuf chain. 438f8829a4aSRandall Stewart */ 439851b7298SRandall Stewart if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { 440851b7298SRandall Stewart goto abandon; 441851b7298SRandall Stewart } else { 442df6e0cc3SRandall Stewart #ifdef INVARIANTS 443ad81507eSRandall Stewart if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) { 444f8829a4aSRandall Stewart panic("This should not happen control_pdapi NULL?"); 445f8829a4aSRandall Stewart } 446f8829a4aSRandall Stewart /* if we did not panic, it was a EOM */ 447f8829a4aSRandall Stewart panic("Bad chunking ??"); 448df6e0cc3SRandall Stewart #else 449df6e0cc3SRandall Stewart if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) { 450df6e0cc3SRandall Stewart SCTP_PRINTF("This should not happen control_pdapi NULL?\n"); 451df6e0cc3SRandall Stewart } 452df6e0cc3SRandall Stewart SCTP_PRINTF("Bad chunking ??\n"); 453df6e0cc3SRandall Stewart SCTP_PRINTF("Dumping re-assembly queue this will probably hose the association\n"); 454df6e0cc3SRandall Stewart 455df6e0cc3SRandall Stewart #endif 456df6e0cc3SRandall Stewart goto abandon; 457f8829a4aSRandall Stewart } 458851b7298SRandall Stewart } 459f8829a4aSRandall Stewart cntDel++; 460f8829a4aSRandall Stewart } 461f8829a4aSRandall Stewart /* pull it we did it */ 462f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 463f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 464f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 465f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { 466f8829a4aSRandall Stewart asoc->strmin[stream_no].last_sequence_delivered++; 467f8829a4aSRandall Stewart } 468f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { 469f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); 470f8829a4aSRandall Stewart } 471f8829a4aSRandall Stewart } else if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 472f8829a4aSRandall Stewart /* 473f8829a4aSRandall Stewart * turn the flag back on since we just delivered 474f8829a4aSRandall Stewart * yet another one. 475f8829a4aSRandall Stewart */ 476f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 477f8829a4aSRandall Stewart } 478f8829a4aSRandall Stewart asoc->tsn_of_pdapi_last_delivered = chk->rec.data.TSN_seq; 479f8829a4aSRandall Stewart asoc->last_flags_delivered = chk->rec.data.rcv_flags; 480f8829a4aSRandall Stewart asoc->last_strm_seq_delivered = chk->rec.data.stream_seq; 481f8829a4aSRandall Stewart asoc->last_strm_no_delivered = chk->rec.data.stream_number; 482f8829a4aSRandall Stewart 483f8829a4aSRandall Stewart asoc->tsn_last_delivered = chk->rec.data.TSN_seq; 484f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 485f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 486f8829a4aSRandall Stewart /* free up the chk */ 487f8829a4aSRandall Stewart chk->data = NULL; 488f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 489f8829a4aSRandall Stewart 490f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 491f8829a4aSRandall Stewart /* 492f8829a4aSRandall Stewart * Now lets see if we can deliver the next one on 493f8829a4aSRandall Stewart * the stream 494f8829a4aSRandall Stewart */ 495f8829a4aSRandall Stewart struct sctp_stream_in *strm; 496f8829a4aSRandall Stewart 497f8829a4aSRandall Stewart strm = &asoc->strmin[stream_no]; 498f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 499f8829a4aSRandall Stewart ctl = TAILQ_FIRST(&strm->inqueue); 500f8829a4aSRandall Stewart if (ctl && (nxt_todel == ctl->sinfo_ssn)) { 501f8829a4aSRandall Stewart while (ctl != NULL) { 502f8829a4aSRandall Stewart /* Deliver more if we can. */ 503f8829a4aSRandall Stewart if (nxt_todel == ctl->sinfo_ssn) { 504f8829a4aSRandall Stewart ctlat = TAILQ_NEXT(ctl, next); 505f8829a4aSRandall Stewart TAILQ_REMOVE(&strm->inqueue, ctl, next); 506f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 507f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 508f8829a4aSRandall Stewart strm->last_sequence_delivered++; 509b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 510f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 511f8829a4aSRandall Stewart ctl, 512cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 513cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 514f8829a4aSRandall Stewart ctl = ctlat; 515f8829a4aSRandall Stewart } else { 516f8829a4aSRandall Stewart break; 517f8829a4aSRandall Stewart } 518f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 519f8829a4aSRandall Stewart } 520f8829a4aSRandall Stewart } 521139bc87fSRandall Stewart break; 522f8829a4aSRandall Stewart } 5233c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 524f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 525f8829a4aSRandall Stewart } while (chk); 526f8829a4aSRandall Stewart } 527f8829a4aSRandall Stewart 528f8829a4aSRandall Stewart /* 529f8829a4aSRandall Stewart * Queue the chunk either right into the socket buffer if it is the next one 530f8829a4aSRandall Stewart * to go OR put it in the correct place in the delivery queue. If we do 531f8829a4aSRandall Stewart * append to the so_buf, keep doing so until we are out of order. One big 532f8829a4aSRandall Stewart * question still remains, what to do when the socket buffer is FULL?? 533f8829a4aSRandall Stewart */ 534f8829a4aSRandall Stewart static void 535f8829a4aSRandall Stewart sctp_queue_data_to_stream(struct sctp_tcb *stcb, struct sctp_association *asoc, 536f8829a4aSRandall Stewart struct sctp_queued_to_read *control, int *abort_flag) 537f8829a4aSRandall Stewart { 538f8829a4aSRandall Stewart /* 539f8829a4aSRandall Stewart * FIX-ME maybe? What happens when the ssn wraps? If we are getting 540f8829a4aSRandall Stewart * all the data in one stream this could happen quite rapidly. One 541f8829a4aSRandall Stewart * could use the TSN to keep track of things, but this scheme breaks 542f8829a4aSRandall Stewart * down in the other type of stream useage that could occur. Send a 543f8829a4aSRandall Stewart * single msg to stream 0, send 4Billion messages to stream 1, now 544f8829a4aSRandall Stewart * send a message to stream 0. You have a situation where the TSN 545f8829a4aSRandall Stewart * has wrapped but not in the stream. Is this worth worrying about 546f8829a4aSRandall Stewart * or should we just change our queue sort at the bottom to be by 547f8829a4aSRandall Stewart * TSN. 548f8829a4aSRandall Stewart * 549f8829a4aSRandall Stewart * Could it also be legal for a peer to send ssn 1 with TSN 2 and ssn 2 550f8829a4aSRandall Stewart * with TSN 1? If the peer is doing some sort of funky TSN/SSN 551f8829a4aSRandall Stewart * assignment this could happen... and I don't see how this would be 552f8829a4aSRandall Stewart * a violation. So for now I am undecided an will leave the sort by 553f8829a4aSRandall Stewart * SSN alone. Maybe a hybred approach is the answer 554f8829a4aSRandall Stewart * 555f8829a4aSRandall Stewart */ 556f8829a4aSRandall Stewart struct sctp_stream_in *strm; 557f8829a4aSRandall Stewart struct sctp_queued_to_read *at; 558f8829a4aSRandall Stewart int queue_needed; 559f8829a4aSRandall Stewart uint16_t nxt_todel; 560f8829a4aSRandall Stewart struct mbuf *oper; 561f8829a4aSRandall Stewart 562f8829a4aSRandall Stewart queue_needed = 1; 563f8829a4aSRandall Stewart asoc->size_on_all_streams += control->length; 564f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_all_streams); 565f8829a4aSRandall Stewart strm = &asoc->strmin[control->sinfo_stream]; 566f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 567b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 568f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD); 56980fefe0aSRandall Stewart } 570ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, 571ad81507eSRandall Stewart "queue to stream called for ssn:%u lastdel:%u nxt:%u\n", 572f8829a4aSRandall Stewart (uint32_t) control->sinfo_stream, 573ad81507eSRandall Stewart (uint32_t) strm->last_sequence_delivered, 574ad81507eSRandall Stewart (uint32_t) nxt_todel); 575f8829a4aSRandall Stewart if (compare_with_wrap(strm->last_sequence_delivered, 576f8829a4aSRandall Stewart control->sinfo_ssn, MAX_SEQ) || 577f8829a4aSRandall Stewart (strm->last_sequence_delivered == control->sinfo_ssn)) { 578f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 579ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ:%d delivered:%d from peer, Abort association\n", 580ad81507eSRandall Stewart control->sinfo_ssn, strm->last_sequence_delivered); 581c40e9cf2SRandall Stewart protocol_error: 582f8829a4aSRandall Stewart /* 583f8829a4aSRandall Stewart * throw it in the stream so it gets cleaned up in 584f8829a4aSRandall Stewart * association destruction 585f8829a4aSRandall Stewart */ 586f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&strm->inqueue, control, next); 587139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 588f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 589f8829a4aSRandall Stewart if (oper) { 590f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 591f8829a4aSRandall Stewart uint32_t *ippp; 592f8829a4aSRandall Stewart 593139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 594f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 595f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 596f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 597139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 598f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 599a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_1); 600f8829a4aSRandall Stewart ippp++; 601f8829a4aSRandall Stewart *ippp = control->sinfo_tsn; 602f8829a4aSRandall Stewart ippp++; 603f8829a4aSRandall Stewart *ippp = ((control->sinfo_stream << 16) | control->sinfo_ssn); 604f8829a4aSRandall Stewart } 605a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_1; 606f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 607ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 608f8829a4aSRandall Stewart 609f8829a4aSRandall Stewart *abort_flag = 1; 610f8829a4aSRandall Stewart return; 611f8829a4aSRandall Stewart 612f8829a4aSRandall Stewart } 613f8829a4aSRandall Stewart if (nxt_todel == control->sinfo_ssn) { 614f8829a4aSRandall Stewart /* can be delivered right away? */ 615b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 616f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_IMMED_DEL); 61780fefe0aSRandall Stewart } 618830d754dSRandall Stewart /* EY it wont be queued if it could be delivered directly */ 619f8829a4aSRandall Stewart queue_needed = 0; 620f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 621f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 622f8829a4aSRandall Stewart strm->last_sequence_delivered++; 62377acdc25SRandall Stewart 624b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 625f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 626f8829a4aSRandall Stewart control, 627cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 628cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 629f8829a4aSRandall Stewart control = TAILQ_FIRST(&strm->inqueue); 630f8829a4aSRandall Stewart while (control != NULL) { 631f8829a4aSRandall Stewart /* all delivered */ 632f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 633f8829a4aSRandall Stewart if (nxt_todel == control->sinfo_ssn) { 634f8829a4aSRandall Stewart at = TAILQ_NEXT(control, next); 635f8829a4aSRandall Stewart TAILQ_REMOVE(&strm->inqueue, control, next); 636f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 637f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 638f8829a4aSRandall Stewart strm->last_sequence_delivered++; 639f8829a4aSRandall Stewart /* 640f8829a4aSRandall Stewart * We ignore the return of deliver_data here 641f8829a4aSRandall Stewart * since we always can hold the chunk on the 642f8829a4aSRandall Stewart * d-queue. And we have a finite number that 643f8829a4aSRandall Stewart * can be delivered from the strq. 644f8829a4aSRandall Stewart */ 645b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 646f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, 647f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_IMMED_DEL); 64880fefe0aSRandall Stewart } 649b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 650f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 651f8829a4aSRandall Stewart control, 652cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 653cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, 654cfde3ff7SRandall Stewart SCTP_SO_NOT_LOCKED); 655f8829a4aSRandall Stewart control = at; 656f8829a4aSRandall Stewart continue; 657f8829a4aSRandall Stewart } 658f8829a4aSRandall Stewart break; 659f8829a4aSRandall Stewart } 660f8829a4aSRandall Stewart } 661f8829a4aSRandall Stewart if (queue_needed) { 662f8829a4aSRandall Stewart /* 663f8829a4aSRandall Stewart * Ok, we did not deliver this guy, find the correct place 664f8829a4aSRandall Stewart * to put it on the queue. 665f8829a4aSRandall Stewart */ 666c40e9cf2SRandall Stewart if ((compare_with_wrap(asoc->cumulative_tsn, 667c40e9cf2SRandall Stewart control->sinfo_tsn, MAX_TSN)) || 668c40e9cf2SRandall Stewart (control->sinfo_tsn == asoc->cumulative_tsn)) { 669c40e9cf2SRandall Stewart goto protocol_error; 670c40e9cf2SRandall Stewart } 671f8829a4aSRandall Stewart if (TAILQ_EMPTY(&strm->inqueue)) { 672f8829a4aSRandall Stewart /* Empty queue */ 673b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 674f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INSERT_HD); 67580fefe0aSRandall Stewart } 676f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&strm->inqueue, control, next); 677f8829a4aSRandall Stewart } else { 678f8829a4aSRandall Stewart TAILQ_FOREACH(at, &strm->inqueue, next) { 679f8829a4aSRandall Stewart if (compare_with_wrap(at->sinfo_ssn, 680f8829a4aSRandall Stewart control->sinfo_ssn, MAX_SEQ)) { 681f8829a4aSRandall Stewart /* 682f8829a4aSRandall Stewart * one in queue is bigger than the 683f8829a4aSRandall Stewart * new one, insert before this one 684f8829a4aSRandall Stewart */ 685b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 686f8829a4aSRandall Stewart sctp_log_strm_del(control, at, 687f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_INSERT_MD); 68880fefe0aSRandall Stewart } 689f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(at, control, next); 690f8829a4aSRandall Stewart break; 691f8829a4aSRandall Stewart } else if (at->sinfo_ssn == control->sinfo_ssn) { 692f8829a4aSRandall Stewart /* 693f8829a4aSRandall Stewart * Gak, He sent me a duplicate str 694f8829a4aSRandall Stewart * seq number 695f8829a4aSRandall Stewart */ 696f8829a4aSRandall Stewart /* 697f8829a4aSRandall Stewart * foo bar, I guess I will just free 698f8829a4aSRandall Stewart * this new guy, should we abort 699f8829a4aSRandall Stewart * too? FIX ME MAYBE? Or it COULD be 700f8829a4aSRandall Stewart * that the SSN's have wrapped. 701f8829a4aSRandall Stewart * Maybe I should compare to TSN 702f8829a4aSRandall Stewart * somehow... sigh for now just blow 703f8829a4aSRandall Stewart * away the chunk! 704f8829a4aSRandall Stewart */ 705f8829a4aSRandall Stewart 706f8829a4aSRandall Stewart if (control->data) 707f8829a4aSRandall Stewart sctp_m_freem(control->data); 708f8829a4aSRandall Stewart control->data = NULL; 709f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 710f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 7115bead436SRandall Stewart if (control->whoFrom) 712f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 7135bead436SRandall Stewart control->whoFrom = NULL; 714f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 715f8829a4aSRandall Stewart return; 716f8829a4aSRandall Stewart } else { 717f8829a4aSRandall Stewart if (TAILQ_NEXT(at, next) == NULL) { 718f8829a4aSRandall Stewart /* 719f8829a4aSRandall Stewart * We are at the end, insert 720f8829a4aSRandall Stewart * it after this one 721f8829a4aSRandall Stewart */ 722b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 723f8829a4aSRandall Stewart sctp_log_strm_del(control, at, 724f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_INSERT_TL); 72580fefe0aSRandall Stewart } 726f8829a4aSRandall Stewart TAILQ_INSERT_AFTER(&strm->inqueue, 727f8829a4aSRandall Stewart at, control, next); 728f8829a4aSRandall Stewart break; 729f8829a4aSRandall Stewart } 730f8829a4aSRandall Stewart } 731f8829a4aSRandall Stewart } 732f8829a4aSRandall Stewart } 733f8829a4aSRandall Stewart } 734f8829a4aSRandall Stewart } 735f8829a4aSRandall Stewart 736f8829a4aSRandall Stewart /* 737f8829a4aSRandall Stewart * Returns two things: You get the total size of the deliverable parts of the 738f8829a4aSRandall Stewart * first fragmented message on the reassembly queue. And you get a 1 back if 739f8829a4aSRandall Stewart * all of the message is ready or a 0 back if the message is still incomplete 740f8829a4aSRandall Stewart */ 741f8829a4aSRandall Stewart static int 742f8829a4aSRandall Stewart sctp_is_all_msg_on_reasm(struct sctp_association *asoc, uint32_t * t_size) 743f8829a4aSRandall Stewart { 744f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 745f8829a4aSRandall Stewart uint32_t tsn; 746f8829a4aSRandall Stewart 747f8829a4aSRandall Stewart *t_size = 0; 748f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 749f8829a4aSRandall Stewart if (chk == NULL) { 750f8829a4aSRandall Stewart /* nothing on the queue */ 751f8829a4aSRandall Stewart return (0); 752f8829a4aSRandall Stewart } 753f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { 754f8829a4aSRandall Stewart /* Not a first on the queue */ 755f8829a4aSRandall Stewart return (0); 756f8829a4aSRandall Stewart } 757f8829a4aSRandall Stewart tsn = chk->rec.data.TSN_seq; 758f8829a4aSRandall Stewart while (chk) { 759f8829a4aSRandall Stewart if (tsn != chk->rec.data.TSN_seq) { 760f8829a4aSRandall Stewart return (0); 761f8829a4aSRandall Stewart } 762f8829a4aSRandall Stewart *t_size += chk->send_size; 763f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 764f8829a4aSRandall Stewart return (1); 765f8829a4aSRandall Stewart } 766f8829a4aSRandall Stewart tsn++; 767f8829a4aSRandall Stewart chk = TAILQ_NEXT(chk, sctp_next); 768f8829a4aSRandall Stewart } 769f8829a4aSRandall Stewart return (0); 770f8829a4aSRandall Stewart } 771f8829a4aSRandall Stewart 772f8829a4aSRandall Stewart static void 773f8829a4aSRandall Stewart sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc) 774f8829a4aSRandall Stewart { 775f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 776f8829a4aSRandall Stewart uint16_t nxt_todel; 777810ec536SMichael Tuexen uint32_t tsize, pd_point; 778f8829a4aSRandall Stewart 779139bc87fSRandall Stewart doit_again: 780f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 781f8829a4aSRandall Stewart if (chk == NULL) { 782f8829a4aSRandall Stewart /* Huh? */ 783f8829a4aSRandall Stewart asoc->size_on_reasm_queue = 0; 784f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue = 0; 785f8829a4aSRandall Stewart return; 786f8829a4aSRandall Stewart } 787f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 788f8829a4aSRandall Stewart nxt_todel = 789f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1; 790f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) && 791f8829a4aSRandall Stewart (nxt_todel == chk->rec.data.stream_seq || 792f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) { 793f8829a4aSRandall Stewart /* 794f8829a4aSRandall Stewart * Yep the first one is here and its ok to deliver 795f8829a4aSRandall Stewart * but should we? 796f8829a4aSRandall Stewart */ 797810ec536SMichael Tuexen if (stcb->sctp_socket) { 79824ae5c4aSMichael Tuexen pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), 799810ec536SMichael Tuexen stcb->sctp_ep->partial_delivery_point); 800810ec536SMichael Tuexen } else { 801810ec536SMichael Tuexen pd_point = stcb->sctp_ep->partial_delivery_point; 802810ec536SMichael Tuexen } 803810ec536SMichael Tuexen if (sctp_is_all_msg_on_reasm(asoc, &tsize) || (tsize >= pd_point)) { 804f8829a4aSRandall Stewart 805f8829a4aSRandall Stewart /* 806f8829a4aSRandall Stewart * Yes, we setup to start reception, by 807f8829a4aSRandall Stewart * backing down the TSN just in case we 808f8829a4aSRandall Stewart * can't deliver. If we 809f8829a4aSRandall Stewart */ 810f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 811f8829a4aSRandall Stewart asoc->tsn_last_delivered = 812f8829a4aSRandall Stewart chk->rec.data.TSN_seq - 1; 813f8829a4aSRandall Stewart asoc->str_of_pdapi = 814f8829a4aSRandall Stewart chk->rec.data.stream_number; 815f8829a4aSRandall Stewart asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 816f8829a4aSRandall Stewart asoc->pdapi_ppid = chk->rec.data.payloadtype; 817f8829a4aSRandall Stewart asoc->fragment_flags = chk->rec.data.rcv_flags; 818f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 819f8829a4aSRandall Stewart } 820f8829a4aSRandall Stewart } 821f8829a4aSRandall Stewart } else { 822139bc87fSRandall Stewart /* 823139bc87fSRandall Stewart * Service re-assembly will deliver stream data queued at 824139bc87fSRandall Stewart * the end of fragmented delivery.. but it wont know to go 825139bc87fSRandall Stewart * back and call itself again... we do that here with the 826139bc87fSRandall Stewart * got doit_again 827139bc87fSRandall Stewart */ 828f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 829139bc87fSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 830139bc87fSRandall Stewart /* 831139bc87fSRandall Stewart * finished our Fragmented delivery, could be more 832139bc87fSRandall Stewart * waiting? 833139bc87fSRandall Stewart */ 834139bc87fSRandall Stewart goto doit_again; 835139bc87fSRandall Stewart } 836f8829a4aSRandall Stewart } 837f8829a4aSRandall Stewart } 838f8829a4aSRandall Stewart 839f8829a4aSRandall Stewart /* 840f8829a4aSRandall Stewart * Dump onto the re-assembly queue, in its proper place. After dumping on the 841f8829a4aSRandall Stewart * queue, see if anthing can be delivered. If so pull it off (or as much as 842f8829a4aSRandall Stewart * we can. If we run out of space then we must dump what we can and set the 843f8829a4aSRandall Stewart * appropriate flag to say we queued what we could. 844f8829a4aSRandall Stewart */ 845f8829a4aSRandall Stewart static void 846f8829a4aSRandall Stewart sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, 847f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk, int *abort_flag) 848f8829a4aSRandall Stewart { 849f8829a4aSRandall Stewart struct mbuf *oper; 850f8829a4aSRandall Stewart uint32_t cum_ackp1, last_tsn, prev_tsn, post_tsn; 851f8829a4aSRandall Stewart u_char last_flags; 852f8829a4aSRandall Stewart struct sctp_tmit_chunk *at, *prev, *next; 853f8829a4aSRandall Stewart 854f8829a4aSRandall Stewart prev = next = NULL; 855f8829a4aSRandall Stewart cum_ackp1 = asoc->tsn_last_delivered + 1; 856f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue)) { 857f8829a4aSRandall Stewart /* This is the first one on the queue */ 858f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&asoc->reasmqueue, chk, sctp_next); 859f8829a4aSRandall Stewart /* 860f8829a4aSRandall Stewart * we do not check for delivery of anything when only one 861f8829a4aSRandall Stewart * fragment is here 862f8829a4aSRandall Stewart */ 863f8829a4aSRandall Stewart asoc->size_on_reasm_queue = chk->send_size; 864f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 865f8829a4aSRandall Stewart if (chk->rec.data.TSN_seq == cum_ackp1) { 866f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0 && 867f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) != 868f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 869f8829a4aSRandall Stewart /* 870f8829a4aSRandall Stewart * An empty queue, no delivery inprogress, 871f8829a4aSRandall Stewart * we hit the next one and it does NOT have 872f8829a4aSRandall Stewart * a FIRST fragment mark. 873f8829a4aSRandall Stewart */ 874ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not first, no fragmented delivery in progress\n"); 875139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 876f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 877f8829a4aSRandall Stewart 878f8829a4aSRandall Stewart if (oper) { 879f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 880f8829a4aSRandall Stewart uint32_t *ippp; 881f8829a4aSRandall Stewart 882139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 883f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 884f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 885f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 886f8829a4aSRandall Stewart ph->param_type = 887f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 888139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 889f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 890a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_2); 891f8829a4aSRandall Stewart ippp++; 892f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 893f8829a4aSRandall Stewart ippp++; 894f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 895f8829a4aSRandall Stewart 896f8829a4aSRandall Stewart } 897a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2; 898f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 899ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 900f8829a4aSRandall Stewart *abort_flag = 1; 901f8829a4aSRandall Stewart } else if (asoc->fragmented_delivery_inprogress && 902f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) { 903f8829a4aSRandall Stewart /* 904f8829a4aSRandall Stewart * We are doing a partial delivery and the 905f8829a4aSRandall Stewart * NEXT chunk MUST be either the LAST or 906f8829a4aSRandall Stewart * MIDDLE fragment NOT a FIRST 907f8829a4aSRandall Stewart */ 908ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS a first and fragmented delivery in progress\n"); 909139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 910f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 911f8829a4aSRandall Stewart if (oper) { 912f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 913f8829a4aSRandall Stewart uint32_t *ippp; 914f8829a4aSRandall Stewart 915139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 916f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 917f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 918f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 919f8829a4aSRandall Stewart ph->param_type = 920f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 921139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 922f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 923a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_3); 924f8829a4aSRandall Stewart ippp++; 925f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 926f8829a4aSRandall Stewart ippp++; 927f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 928f8829a4aSRandall Stewart } 929a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_3; 930f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 931ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 932f8829a4aSRandall Stewart *abort_flag = 1; 933f8829a4aSRandall Stewart } else if (asoc->fragmented_delivery_inprogress) { 934f8829a4aSRandall Stewart /* 935f8829a4aSRandall Stewart * Here we are ok with a MIDDLE or LAST 936f8829a4aSRandall Stewart * piece 937f8829a4aSRandall Stewart */ 938f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 939f8829a4aSRandall Stewart asoc->str_of_pdapi) { 940f8829a4aSRandall Stewart /* Got to be the right STR No */ 941ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream number %d vs %d\n", 942f8829a4aSRandall Stewart chk->rec.data.stream_number, 943f8829a4aSRandall Stewart asoc->str_of_pdapi); 944139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 945f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 946f8829a4aSRandall Stewart if (oper) { 947f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 948f8829a4aSRandall Stewart uint32_t *ippp; 949f8829a4aSRandall Stewart 950139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 951f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 952f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 953f8829a4aSRandall Stewart ph = mtod(oper, 954f8829a4aSRandall Stewart struct sctp_paramhdr *); 955f8829a4aSRandall Stewart ph->param_type = 956f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 957f8829a4aSRandall Stewart ph->param_length = 958139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 959f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 960a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_4); 961f8829a4aSRandall Stewart ippp++; 962f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 963f8829a4aSRandall Stewart ippp++; 964f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 965f8829a4aSRandall Stewart } 966a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_4; 967f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 968ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 969f8829a4aSRandall Stewart *abort_flag = 1; 970f8829a4aSRandall Stewart } else if ((asoc->fragment_flags & SCTP_DATA_UNORDERED) != 971f8829a4aSRandall Stewart SCTP_DATA_UNORDERED && 972b5c16493SMichael Tuexen chk->rec.data.stream_seq != asoc->ssn_of_pdapi) { 973f8829a4aSRandall Stewart /* Got to be the right STR Seq */ 974ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream seq %d vs %d\n", 975f8829a4aSRandall Stewart chk->rec.data.stream_seq, 976f8829a4aSRandall Stewart asoc->ssn_of_pdapi); 977139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 978f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 979f8829a4aSRandall Stewart if (oper) { 980f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 981f8829a4aSRandall Stewart uint32_t *ippp; 982f8829a4aSRandall Stewart 983139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 984f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 985f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 986f8829a4aSRandall Stewart ph = mtod(oper, 987f8829a4aSRandall Stewart struct sctp_paramhdr *); 988f8829a4aSRandall Stewart ph->param_type = 989f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 990f8829a4aSRandall Stewart ph->param_length = 991139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 992f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 993a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_5); 994f8829a4aSRandall Stewart ippp++; 995f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 996f8829a4aSRandall Stewart ippp++; 997f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 998f8829a4aSRandall Stewart 999f8829a4aSRandall Stewart } 1000a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_5; 1001f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1002ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1003f8829a4aSRandall Stewart *abort_flag = 1; 1004f8829a4aSRandall Stewart } 1005f8829a4aSRandall Stewart } 1006f8829a4aSRandall Stewart } 1007f8829a4aSRandall Stewart return; 1008f8829a4aSRandall Stewart } 1009f8829a4aSRandall Stewart /* Find its place */ 1010f8829a4aSRandall Stewart TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) { 1011f8829a4aSRandall Stewart if (compare_with_wrap(at->rec.data.TSN_seq, 1012f8829a4aSRandall Stewart chk->rec.data.TSN_seq, MAX_TSN)) { 1013f8829a4aSRandall Stewart /* 1014f8829a4aSRandall Stewart * one in queue is bigger than the new one, insert 1015f8829a4aSRandall Stewart * before this one 1016f8829a4aSRandall Stewart */ 1017f8829a4aSRandall Stewart /* A check */ 1018f8829a4aSRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 1019f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 1020f8829a4aSRandall Stewart next = at; 1021f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(at, chk, sctp_next); 1022f8829a4aSRandall Stewart break; 1023f8829a4aSRandall Stewart } else if (at->rec.data.TSN_seq == chk->rec.data.TSN_seq) { 1024f8829a4aSRandall Stewart /* Gak, He sent me a duplicate str seq number */ 1025f8829a4aSRandall Stewart /* 1026f8829a4aSRandall Stewart * foo bar, I guess I will just free this new guy, 1027f8829a4aSRandall Stewart * should we abort too? FIX ME MAYBE? Or it COULD be 1028f8829a4aSRandall Stewart * that the SSN's have wrapped. Maybe I should 1029f8829a4aSRandall Stewart * compare to TSN somehow... sigh for now just blow 1030f8829a4aSRandall Stewart * away the chunk! 1031f8829a4aSRandall Stewart */ 1032f8829a4aSRandall Stewart if (chk->data) { 1033f8829a4aSRandall Stewart sctp_m_freem(chk->data); 1034f8829a4aSRandall Stewart chk->data = NULL; 1035f8829a4aSRandall Stewart } 1036f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 1037f8829a4aSRandall Stewart return; 1038f8829a4aSRandall Stewart } else { 1039f8829a4aSRandall Stewart last_flags = at->rec.data.rcv_flags; 1040f8829a4aSRandall Stewart last_tsn = at->rec.data.TSN_seq; 1041f8829a4aSRandall Stewart prev = at; 1042f8829a4aSRandall Stewart if (TAILQ_NEXT(at, sctp_next) == NULL) { 1043f8829a4aSRandall Stewart /* 1044f8829a4aSRandall Stewart * We are at the end, insert it after this 1045f8829a4aSRandall Stewart * one 1046f8829a4aSRandall Stewart */ 1047f8829a4aSRandall Stewart /* check it first */ 1048f8829a4aSRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 1049f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 1050f8829a4aSRandall Stewart TAILQ_INSERT_AFTER(&asoc->reasmqueue, at, chk, sctp_next); 1051f8829a4aSRandall Stewart break; 1052f8829a4aSRandall Stewart } 1053f8829a4aSRandall Stewart } 1054f8829a4aSRandall Stewart } 1055f8829a4aSRandall Stewart /* Now the audits */ 1056f8829a4aSRandall Stewart if (prev) { 1057f8829a4aSRandall Stewart prev_tsn = chk->rec.data.TSN_seq - 1; 1058f8829a4aSRandall Stewart if (prev_tsn == prev->rec.data.TSN_seq) { 1059f8829a4aSRandall Stewart /* 1060f8829a4aSRandall Stewart * Ok the one I am dropping onto the end is the 1061f8829a4aSRandall Stewart * NEXT. A bit of valdiation here. 1062f8829a4aSRandall Stewart */ 1063f8829a4aSRandall Stewart if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1064f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG || 1065f8829a4aSRandall Stewart (prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1066f8829a4aSRandall Stewart SCTP_DATA_MIDDLE_FRAG) { 1067f8829a4aSRandall Stewart /* 1068f8829a4aSRandall Stewart * Insert chk MUST be a MIDDLE or LAST 1069f8829a4aSRandall Stewart * fragment 1070f8829a4aSRandall Stewart */ 1071f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1072f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1073ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - It can be a midlle or last but not a first\n"); 1074ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it's a FIRST!\n"); 1075139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1076f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1077f8829a4aSRandall Stewart if (oper) { 1078f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1079f8829a4aSRandall Stewart uint32_t *ippp; 1080f8829a4aSRandall Stewart 1081139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1082f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1083f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1084f8829a4aSRandall Stewart ph = mtod(oper, 1085f8829a4aSRandall Stewart struct sctp_paramhdr *); 1086f8829a4aSRandall Stewart ph->param_type = 1087f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1088f8829a4aSRandall Stewart ph->param_length = 1089139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1090f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1091a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_6); 1092f8829a4aSRandall Stewart ippp++; 1093f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1094f8829a4aSRandall Stewart ippp++; 1095f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1096f8829a4aSRandall Stewart 1097f8829a4aSRandall Stewart } 1098a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_6; 1099f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1100ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1101f8829a4aSRandall Stewart *abort_flag = 1; 1102f8829a4aSRandall Stewart return; 1103f8829a4aSRandall Stewart } 1104f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 1105f8829a4aSRandall Stewart prev->rec.data.stream_number) { 1106f8829a4aSRandall Stewart /* 1107f8829a4aSRandall Stewart * Huh, need the correct STR here, 1108f8829a4aSRandall Stewart * they must be the same. 1109f8829a4aSRandall Stewart */ 1110ad81507eSRandall Stewart SCTP_PRINTF("Prev check - Gak, Evil plot, ssn:%d not the same as at:%d\n", 1111f8829a4aSRandall Stewart chk->rec.data.stream_number, 1112f8829a4aSRandall Stewart prev->rec.data.stream_number); 1113139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1114f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1115f8829a4aSRandall Stewart if (oper) { 1116f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1117f8829a4aSRandall Stewart uint32_t *ippp; 1118f8829a4aSRandall Stewart 1119139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1120f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1121f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1122f8829a4aSRandall Stewart ph = mtod(oper, 1123f8829a4aSRandall Stewart struct sctp_paramhdr *); 1124f8829a4aSRandall Stewart ph->param_type = 1125f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1126f8829a4aSRandall Stewart ph->param_length = 1127139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1128f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1129a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_7); 1130f8829a4aSRandall Stewart ippp++; 1131f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1132f8829a4aSRandall Stewart ippp++; 1133f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1134f8829a4aSRandall Stewart } 1135a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_7; 1136f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1137ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1138f8829a4aSRandall Stewart 1139f8829a4aSRandall Stewart *abort_flag = 1; 1140f8829a4aSRandall Stewart return; 1141f8829a4aSRandall Stewart } 1142f8829a4aSRandall Stewart if ((prev->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 && 1143f8829a4aSRandall Stewart chk->rec.data.stream_seq != 1144f8829a4aSRandall Stewart prev->rec.data.stream_seq) { 1145f8829a4aSRandall Stewart /* 1146f8829a4aSRandall Stewart * Huh, need the correct STR here, 1147f8829a4aSRandall Stewart * they must be the same. 1148f8829a4aSRandall Stewart */ 1149ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, Evil plot, sseq:%d not the same as at:%d\n", 1150f8829a4aSRandall Stewart chk->rec.data.stream_seq, 1151f8829a4aSRandall Stewart prev->rec.data.stream_seq); 1152139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1153f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1154f8829a4aSRandall Stewart if (oper) { 1155f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1156f8829a4aSRandall Stewart uint32_t *ippp; 1157f8829a4aSRandall Stewart 1158139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1159f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1160f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1161f8829a4aSRandall Stewart ph = mtod(oper, 1162f8829a4aSRandall Stewart struct sctp_paramhdr *); 1163f8829a4aSRandall Stewart ph->param_type = 1164f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1165f8829a4aSRandall Stewart ph->param_length = 1166139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1167f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1168a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_8); 1169f8829a4aSRandall Stewart ippp++; 1170f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1171f8829a4aSRandall Stewart ippp++; 1172f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1173f8829a4aSRandall Stewart } 1174a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_8; 1175f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1176ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1177f8829a4aSRandall Stewart 1178f8829a4aSRandall Stewart *abort_flag = 1; 1179f8829a4aSRandall Stewart return; 1180f8829a4aSRandall Stewart } 1181f8829a4aSRandall Stewart } else if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1182f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1183f8829a4aSRandall Stewart /* Insert chk MUST be a FIRST */ 1184f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1185f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1186ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, evil plot, its not FIRST and it must be!\n"); 1187139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1188f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1189f8829a4aSRandall Stewart if (oper) { 1190f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1191f8829a4aSRandall Stewart uint32_t *ippp; 1192f8829a4aSRandall Stewart 1193139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1194f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1195f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1196f8829a4aSRandall Stewart ph = mtod(oper, 1197f8829a4aSRandall Stewart struct sctp_paramhdr *); 1198f8829a4aSRandall Stewart ph->param_type = 1199f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1200f8829a4aSRandall Stewart ph->param_length = 1201139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1202f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1203a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_9); 1204f8829a4aSRandall Stewart ippp++; 1205f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1206f8829a4aSRandall Stewart ippp++; 1207f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1208f8829a4aSRandall Stewart 1209f8829a4aSRandall Stewart } 1210a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_9; 1211f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1212ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1213f8829a4aSRandall Stewart 1214f8829a4aSRandall Stewart *abort_flag = 1; 1215f8829a4aSRandall Stewart return; 1216f8829a4aSRandall Stewart } 1217f8829a4aSRandall Stewart } 1218f8829a4aSRandall Stewart } 1219f8829a4aSRandall Stewart } 1220f8829a4aSRandall Stewart if (next) { 1221f8829a4aSRandall Stewart post_tsn = chk->rec.data.TSN_seq + 1; 1222f8829a4aSRandall Stewart if (post_tsn == next->rec.data.TSN_seq) { 1223f8829a4aSRandall Stewart /* 1224f8829a4aSRandall Stewart * Ok the one I am inserting ahead of is my NEXT 1225f8829a4aSRandall Stewart * one. A bit of valdiation here. 1226f8829a4aSRandall Stewart */ 1227f8829a4aSRandall Stewart if (next->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 1228f8829a4aSRandall Stewart /* Insert chk MUST be a last fragment */ 1229f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) 1230f8829a4aSRandall Stewart != SCTP_DATA_LAST_FRAG) { 1231ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is FIRST, we must be LAST\n"); 1232ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not a last!\n"); 1233139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1234f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1235f8829a4aSRandall Stewart if (oper) { 1236f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1237f8829a4aSRandall Stewart uint32_t *ippp; 1238f8829a4aSRandall Stewart 1239139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1240f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1241f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1242f8829a4aSRandall Stewart ph = mtod(oper, 1243f8829a4aSRandall Stewart struct sctp_paramhdr *); 1244f8829a4aSRandall Stewart ph->param_type = 1245f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1246f8829a4aSRandall Stewart ph->param_length = 1247139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1248f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1249a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_10); 1250f8829a4aSRandall Stewart ippp++; 1251f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1252f8829a4aSRandall Stewart ippp++; 1253f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1254f8829a4aSRandall Stewart } 1255a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_10; 1256f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1257ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1258f8829a4aSRandall Stewart 1259f8829a4aSRandall Stewart *abort_flag = 1; 1260f8829a4aSRandall Stewart return; 1261f8829a4aSRandall Stewart } 1262f8829a4aSRandall Stewart } else if ((next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1263f8829a4aSRandall Stewart SCTP_DATA_MIDDLE_FRAG || 1264f8829a4aSRandall Stewart (next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1265f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1266f8829a4aSRandall Stewart /* 1267f8829a4aSRandall Stewart * Insert chk CAN be MIDDLE or FIRST NOT 1268f8829a4aSRandall Stewart * LAST 1269f8829a4aSRandall Stewart */ 1270f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1271f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1272ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is a MIDDLE/LAST\n"); 1273ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, new prev chunk is a LAST\n"); 1274139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1275f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1276f8829a4aSRandall Stewart if (oper) { 1277f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1278f8829a4aSRandall Stewart uint32_t *ippp; 1279f8829a4aSRandall Stewart 1280139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1281f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1282f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1283f8829a4aSRandall Stewart ph = mtod(oper, 1284f8829a4aSRandall Stewart struct sctp_paramhdr *); 1285f8829a4aSRandall Stewart ph->param_type = 1286f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1287f8829a4aSRandall Stewart ph->param_length = 1288139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1289f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1290a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_11); 1291f8829a4aSRandall Stewart ippp++; 1292f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1293f8829a4aSRandall Stewart ippp++; 1294f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1295f8829a4aSRandall Stewart 1296f8829a4aSRandall Stewart } 1297a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_11; 1298f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1299ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1300f8829a4aSRandall Stewart 1301f8829a4aSRandall Stewart *abort_flag = 1; 1302f8829a4aSRandall Stewart return; 1303f8829a4aSRandall Stewart } 1304f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 1305f8829a4aSRandall Stewart next->rec.data.stream_number) { 1306f8829a4aSRandall Stewart /* 1307f8829a4aSRandall Stewart * Huh, need the correct STR here, 1308f8829a4aSRandall Stewart * they must be the same. 1309f8829a4aSRandall Stewart */ 1310ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, ssn:%d not the same as at:%d\n", 1311f8829a4aSRandall Stewart chk->rec.data.stream_number, 1312f8829a4aSRandall Stewart next->rec.data.stream_number); 1313139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1314f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1315f8829a4aSRandall Stewart if (oper) { 1316f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1317f8829a4aSRandall Stewart uint32_t *ippp; 1318f8829a4aSRandall Stewart 1319139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1320f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1321f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1322f8829a4aSRandall Stewart ph = mtod(oper, 1323f8829a4aSRandall Stewart struct sctp_paramhdr *); 1324f8829a4aSRandall Stewart ph->param_type = 1325f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1326f8829a4aSRandall Stewart ph->param_length = 1327139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1328f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1329a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_12); 1330f8829a4aSRandall Stewart ippp++; 1331f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1332f8829a4aSRandall Stewart ippp++; 1333f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1334f8829a4aSRandall Stewart 1335f8829a4aSRandall Stewart } 1336a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_12; 1337f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1338ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1339f8829a4aSRandall Stewart 1340f8829a4aSRandall Stewart *abort_flag = 1; 1341f8829a4aSRandall Stewart return; 1342f8829a4aSRandall Stewart } 1343f8829a4aSRandall Stewart if ((next->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 && 1344f8829a4aSRandall Stewart chk->rec.data.stream_seq != 1345f8829a4aSRandall Stewart next->rec.data.stream_seq) { 1346f8829a4aSRandall Stewart /* 1347f8829a4aSRandall Stewart * Huh, need the correct STR here, 1348f8829a4aSRandall Stewart * they must be the same. 1349f8829a4aSRandall Stewart */ 1350ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, sseq:%d not the same as at:%d\n", 1351f8829a4aSRandall Stewart chk->rec.data.stream_seq, 1352f8829a4aSRandall Stewart next->rec.data.stream_seq); 1353139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1354f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1355f8829a4aSRandall Stewart if (oper) { 1356f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1357f8829a4aSRandall Stewart uint32_t *ippp; 1358f8829a4aSRandall Stewart 1359139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1360f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1361f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1362f8829a4aSRandall Stewart ph = mtod(oper, 1363f8829a4aSRandall Stewart struct sctp_paramhdr *); 1364f8829a4aSRandall Stewart ph->param_type = 1365f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1366f8829a4aSRandall Stewart ph->param_length = 1367139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1368f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1369a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_13); 1370f8829a4aSRandall Stewart ippp++; 1371f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1372f8829a4aSRandall Stewart ippp++; 1373f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1374f8829a4aSRandall Stewart } 1375a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_13; 1376f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1377ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1378f8829a4aSRandall Stewart 1379f8829a4aSRandall Stewart *abort_flag = 1; 1380f8829a4aSRandall Stewart return; 1381f8829a4aSRandall Stewart } 1382f8829a4aSRandall Stewart } 1383f8829a4aSRandall Stewart } 1384f8829a4aSRandall Stewart } 1385f8829a4aSRandall Stewart /* Do we need to do some delivery? check */ 1386f8829a4aSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 1387f8829a4aSRandall Stewart } 1388f8829a4aSRandall Stewart 1389f8829a4aSRandall Stewart /* 1390f8829a4aSRandall Stewart * This is an unfortunate routine. It checks to make sure a evil guy is not 1391f8829a4aSRandall Stewart * stuffing us full of bad packet fragments. A broken peer could also do this 1392f8829a4aSRandall Stewart * but this is doubtful. It is to bad I must worry about evil crackers sigh 1393f8829a4aSRandall Stewart * :< more cycles. 1394f8829a4aSRandall Stewart */ 1395f8829a4aSRandall Stewart static int 1396f8829a4aSRandall Stewart sctp_does_tsn_belong_to_reasm(struct sctp_association *asoc, 1397f8829a4aSRandall Stewart uint32_t TSN_seq) 1398f8829a4aSRandall Stewart { 1399f8829a4aSRandall Stewart struct sctp_tmit_chunk *at; 1400f8829a4aSRandall Stewart uint32_t tsn_est; 1401f8829a4aSRandall Stewart 1402f8829a4aSRandall Stewart TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) { 1403f8829a4aSRandall Stewart if (compare_with_wrap(TSN_seq, 1404f8829a4aSRandall Stewart at->rec.data.TSN_seq, MAX_TSN)) { 1405f8829a4aSRandall Stewart /* is it one bigger? */ 1406f8829a4aSRandall Stewart tsn_est = at->rec.data.TSN_seq + 1; 1407f8829a4aSRandall Stewart if (tsn_est == TSN_seq) { 1408f8829a4aSRandall Stewart /* yep. It better be a last then */ 1409f8829a4aSRandall Stewart if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1410f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1411f8829a4aSRandall Stewart /* 1412f8829a4aSRandall Stewart * Ok this guy belongs next to a guy 1413f8829a4aSRandall Stewart * that is NOT last, it should be a 1414f8829a4aSRandall Stewart * middle/last, not a complete 1415f8829a4aSRandall Stewart * chunk. 1416f8829a4aSRandall Stewart */ 1417f8829a4aSRandall Stewart return (1); 1418f8829a4aSRandall Stewart } else { 1419f8829a4aSRandall Stewart /* 1420f8829a4aSRandall Stewart * This guy is ok since its a LAST 1421f8829a4aSRandall Stewart * and the new chunk is a fully 1422f8829a4aSRandall Stewart * self- contained one. 1423f8829a4aSRandall Stewart */ 1424f8829a4aSRandall Stewart return (0); 1425f8829a4aSRandall Stewart } 1426f8829a4aSRandall Stewart } 1427f8829a4aSRandall Stewart } else if (TSN_seq == at->rec.data.TSN_seq) { 1428f8829a4aSRandall Stewart /* Software error since I have a dup? */ 1429f8829a4aSRandall Stewart return (1); 1430f8829a4aSRandall Stewart } else { 1431f8829a4aSRandall Stewart /* 1432f8829a4aSRandall Stewart * Ok, 'at' is larger than new chunk but does it 1433f8829a4aSRandall Stewart * need to be right before it. 1434f8829a4aSRandall Stewart */ 1435f8829a4aSRandall Stewart tsn_est = TSN_seq + 1; 1436f8829a4aSRandall Stewart if (tsn_est == at->rec.data.TSN_seq) { 1437f8829a4aSRandall Stewart /* Yep, It better be a first */ 1438f8829a4aSRandall Stewart if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1439f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1440f8829a4aSRandall Stewart return (1); 1441f8829a4aSRandall Stewart } else { 1442f8829a4aSRandall Stewart return (0); 1443f8829a4aSRandall Stewart } 1444f8829a4aSRandall Stewart } 1445f8829a4aSRandall Stewart } 1446f8829a4aSRandall Stewart } 1447f8829a4aSRandall Stewart return (0); 1448f8829a4aSRandall Stewart } 1449f8829a4aSRandall Stewart 1450f8829a4aSRandall Stewart 1451f8829a4aSRandall Stewart static int 1452f8829a4aSRandall Stewart sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, 1453f8829a4aSRandall Stewart struct mbuf **m, int offset, struct sctp_data_chunk *ch, int chk_length, 1454f8829a4aSRandall Stewart struct sctp_nets *net, uint32_t * high_tsn, int *abort_flag, 1455f8829a4aSRandall Stewart int *break_flag, int last_chunk) 1456f8829a4aSRandall Stewart { 1457f8829a4aSRandall Stewart /* Process a data chunk */ 1458f8829a4aSRandall Stewart /* struct sctp_tmit_chunk *chk; */ 1459f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 1460f8829a4aSRandall Stewart uint32_t tsn, gap; 1461f8829a4aSRandall Stewart struct mbuf *dmbuf; 1462f8829a4aSRandall Stewart int indx, the_len; 1463139bc87fSRandall Stewart int need_reasm_check = 0; 1464f8829a4aSRandall Stewart uint16_t strmno, strmseq; 1465f8829a4aSRandall Stewart struct mbuf *oper; 1466f8829a4aSRandall Stewart struct sctp_queued_to_read *control; 1467f42a358aSRandall Stewart int ordered; 1468f42a358aSRandall Stewart uint32_t protocol_id; 1469f42a358aSRandall Stewart uint8_t chunk_flags; 147017205eccSRandall Stewart struct sctp_stream_reset_list *liste; 1471f8829a4aSRandall Stewart 1472f8829a4aSRandall Stewart chk = NULL; 1473f8829a4aSRandall Stewart tsn = ntohl(ch->dp.tsn); 1474f42a358aSRandall Stewart chunk_flags = ch->ch.chunk_flags; 1475b3f1ea41SRandall Stewart if ((chunk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) { 1476b3f1ea41SRandall Stewart asoc->send_sack = 1; 1477b3f1ea41SRandall Stewart } 1478f42a358aSRandall Stewart protocol_id = ch->dp.protocol_id; 147937f144ebSMichael Tuexen ordered = ((chunk_flags & SCTP_DATA_UNORDERED) == 0); 1480b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 1481c4739e2fSRandall Stewart sctp_log_map(tsn, asoc->cumulative_tsn, asoc->highest_tsn_inside_map, SCTP_MAP_TSN_ENTERS); 148280fefe0aSRandall Stewart } 1483ad81507eSRandall Stewart if (stcb == NULL) { 1484ad81507eSRandall Stewart return (0); 1485ad81507eSRandall Stewart } 148680fefe0aSRandall Stewart SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, ch->ch.chunk_type, tsn); 1487f8829a4aSRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, tsn, MAX_TSN) || 1488f8829a4aSRandall Stewart asoc->cumulative_tsn == tsn) { 1489f8829a4aSRandall Stewart /* It is a duplicate */ 1490f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1491f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1492f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1493f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1494f8829a4aSRandall Stewart asoc->numduptsns++; 1495f8829a4aSRandall Stewart } 1496b201f536SRandall Stewart asoc->send_sack = 1; 1497f8829a4aSRandall Stewart return (0); 1498f8829a4aSRandall Stewart } 1499f8829a4aSRandall Stewart /* Calculate the number of TSN's between the base and this TSN */ 1500d50c1d79SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn); 1501f8829a4aSRandall Stewart if (gap >= (SCTP_MAPPING_ARRAY << 3)) { 1502f8829a4aSRandall Stewart /* Can't hold the bit in the mapping at max array, toss it */ 1503f8829a4aSRandall Stewart return (0); 1504f8829a4aSRandall Stewart } 1505f8829a4aSRandall Stewart if (gap >= (uint32_t) (asoc->mapping_array_size << 3)) { 1506207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 15070696e120SRandall Stewart if (sctp_expand_mapping_array(asoc, gap)) { 1508f8829a4aSRandall Stewart /* Can't expand, drop it */ 1509f8829a4aSRandall Stewart return (0); 1510f8829a4aSRandall Stewart } 1511f8829a4aSRandall Stewart } 1512f8829a4aSRandall Stewart if (compare_with_wrap(tsn, *high_tsn, MAX_TSN)) { 1513f8829a4aSRandall Stewart *high_tsn = tsn; 1514f8829a4aSRandall Stewart } 1515f8829a4aSRandall Stewart /* See if we have received this one already */ 151677acdc25SRandall Stewart if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap) || 151777acdc25SRandall Stewart SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, gap)) { 1518f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1519f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1520f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1521f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1522f8829a4aSRandall Stewart asoc->numduptsns++; 1523f8829a4aSRandall Stewart } 152442551e99SRandall Stewart asoc->send_sack = 1; 1525f8829a4aSRandall Stewart return (0); 1526f8829a4aSRandall Stewart } 1527f8829a4aSRandall Stewart /* 1528f8829a4aSRandall Stewart * Check to see about the GONE flag, duplicates would cause a sack 1529f8829a4aSRandall Stewart * to be sent up above 1530f8829a4aSRandall Stewart */ 1531ad81507eSRandall Stewart if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || 1532f8829a4aSRandall Stewart (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || 1533f8829a4aSRandall Stewart (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) 1534f8829a4aSRandall Stewart ) { 1535f8829a4aSRandall Stewart /* 1536f8829a4aSRandall Stewart * wait a minute, this guy is gone, there is no longer a 1537f8829a4aSRandall Stewart * receiver. Send peer an ABORT! 1538f8829a4aSRandall Stewart */ 1539f8829a4aSRandall Stewart struct mbuf *op_err; 1540f8829a4aSRandall Stewart 1541f8829a4aSRandall Stewart op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC); 1542ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 0, op_err, SCTP_SO_NOT_LOCKED); 1543f8829a4aSRandall Stewart *abort_flag = 1; 1544f8829a4aSRandall Stewart return (0); 1545f8829a4aSRandall Stewart } 1546f8829a4aSRandall Stewart /* 1547f8829a4aSRandall Stewart * Now before going further we see if there is room. If NOT then we 1548f8829a4aSRandall Stewart * MAY let one through only IF this TSN is the one we are waiting 1549f8829a4aSRandall Stewart * for on a partial delivery API. 1550f8829a4aSRandall Stewart */ 1551f8829a4aSRandall Stewart 1552f8829a4aSRandall Stewart /* now do the tests */ 1553f8829a4aSRandall Stewart if (((asoc->cnt_on_all_streams + 1554f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue + 1555b3f1ea41SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) || 1556f8829a4aSRandall Stewart (((int)asoc->my_rwnd) <= 0)) { 1557f8829a4aSRandall Stewart /* 1558f8829a4aSRandall Stewart * When we have NO room in the rwnd we check to make sure 1559f8829a4aSRandall Stewart * the reader is doing its job... 1560f8829a4aSRandall Stewart */ 1561f8829a4aSRandall Stewart if (stcb->sctp_socket->so_rcv.sb_cc) { 1562f8829a4aSRandall Stewart /* some to read, wake-up */ 1563ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 1564ceaad40aSRandall Stewart struct socket *so; 1565ceaad40aSRandall Stewart 1566ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 1567ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 1568ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 1569ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 1570ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 1571ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 1572ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 1573ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 1574ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 1575ceaad40aSRandall Stewart return (0); 1576ceaad40aSRandall Stewart } 1577ceaad40aSRandall Stewart #endif 1578f8829a4aSRandall Stewart sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket); 1579ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 1580ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 1581ceaad40aSRandall Stewart #endif 1582f8829a4aSRandall Stewart } 1583f8829a4aSRandall Stewart /* now is it in the mapping array of what we have accepted? */ 158477acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN) && 158577acdc25SRandall Stewart compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 1586f8829a4aSRandall Stewart /* Nope not in the valid range dump it */ 1587f8829a4aSRandall Stewart sctp_set_rwnd(stcb, asoc); 1588f8829a4aSRandall Stewart if ((asoc->cnt_on_all_streams + 1589f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue + 1590b3f1ea41SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) { 1591f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_datadropchklmt); 1592f8829a4aSRandall Stewart } else { 1593f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_datadroprwnd); 1594f8829a4aSRandall Stewart } 1595f8829a4aSRandall Stewart indx = *break_flag; 1596f8829a4aSRandall Stewart *break_flag = 1; 1597f8829a4aSRandall Stewart return (0); 1598f8829a4aSRandall Stewart } 1599f8829a4aSRandall Stewart } 1600f8829a4aSRandall Stewart strmno = ntohs(ch->dp.stream_id); 1601f8829a4aSRandall Stewart if (strmno >= asoc->streamincnt) { 1602f8829a4aSRandall Stewart struct sctp_paramhdr *phdr; 1603f8829a4aSRandall Stewart struct mbuf *mb; 1604f8829a4aSRandall Stewart 1605f8829a4aSRandall Stewart mb = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) * 2), 1606139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1607f8829a4aSRandall Stewart if (mb != NULL) { 1608f8829a4aSRandall Stewart /* add some space up front so prepend will work well */ 1609139bc87fSRandall Stewart SCTP_BUF_RESV_UF(mb, sizeof(struct sctp_chunkhdr)); 1610f8829a4aSRandall Stewart phdr = mtod(mb, struct sctp_paramhdr *); 1611f8829a4aSRandall Stewart /* 1612f8829a4aSRandall Stewart * Error causes are just param's and this one has 1613f8829a4aSRandall Stewart * two back to back phdr, one with the error type 1614f8829a4aSRandall Stewart * and size, the other with the streamid and a rsvd 1615f8829a4aSRandall Stewart */ 1616139bc87fSRandall Stewart SCTP_BUF_LEN(mb) = (sizeof(struct sctp_paramhdr) * 2); 1617f8829a4aSRandall Stewart phdr->param_type = htons(SCTP_CAUSE_INVALID_STREAM); 1618f8829a4aSRandall Stewart phdr->param_length = 1619f8829a4aSRandall Stewart htons(sizeof(struct sctp_paramhdr) * 2); 1620f8829a4aSRandall Stewart phdr++; 1621f8829a4aSRandall Stewart /* We insert the stream in the type field */ 1622f8829a4aSRandall Stewart phdr->param_type = ch->dp.stream_id; 1623f8829a4aSRandall Stewart /* And set the length to 0 for the rsvd field */ 1624f8829a4aSRandall Stewart phdr->param_length = 0; 1625f8829a4aSRandall Stewart sctp_queue_op_err(stcb, mb); 1626f8829a4aSRandall Stewart } 1627f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_badsid); 1628207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1629830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 163077acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 1631830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 1632d06c82f1SRandall Stewart } 1633d06c82f1SRandall Stewart if (tsn == (asoc->cumulative_tsn + 1)) { 1634d06c82f1SRandall Stewart /* Update cum-ack */ 1635d06c82f1SRandall Stewart asoc->cumulative_tsn = tsn; 1636d06c82f1SRandall Stewart } 1637f8829a4aSRandall Stewart return (0); 1638f8829a4aSRandall Stewart } 1639f8829a4aSRandall Stewart /* 1640f8829a4aSRandall Stewart * Before we continue lets validate that we are not being fooled by 1641f8829a4aSRandall Stewart * an evil attacker. We can only have 4k chunks based on our TSN 1642f8829a4aSRandall Stewart * spread allowed by the mapping array 512 * 8 bits, so there is no 1643f8829a4aSRandall Stewart * way our stream sequence numbers could have wrapped. We of course 1644f8829a4aSRandall Stewart * only validate the FIRST fragment so the bit must be set. 1645f8829a4aSRandall Stewart */ 1646f8829a4aSRandall Stewart strmseq = ntohs(ch->dp.stream_sequence); 1647f42a358aSRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 164818e198d3SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 164918e198d3SRandall Stewart if (asoc->tsn_in_at >= SCTP_TSN_LOG_SIZE) { 165018e198d3SRandall Stewart asoc->tsn_in_at = 0; 165118e198d3SRandall Stewart asoc->tsn_in_wrapped = 1; 165218e198d3SRandall Stewart } 1653f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].tsn = tsn; 1654f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].strm = strmno; 1655f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].seq = strmseq; 1656f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].sz = chk_length; 1657f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].flgs = chunk_flags; 165818e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].stcb = (void *)stcb; 165918e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_pos = asoc->tsn_in_at; 166018e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_out = 1; 1661f42a358aSRandall Stewart asoc->tsn_in_at++; 1662f42a358aSRandall Stewart #endif 1663f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_FIRST_FRAG) && 1664d61a0ae0SRandall Stewart (TAILQ_EMPTY(&asoc->resetHead)) && 1665f42a358aSRandall Stewart (chunk_flags & SCTP_DATA_UNORDERED) == 0 && 1666f8829a4aSRandall Stewart (compare_with_wrap(asoc->strmin[strmno].last_sequence_delivered, 1667f8829a4aSRandall Stewart strmseq, MAX_SEQ) || 1668f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered == strmseq)) { 1669f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 1670ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ:%d delivered:%d from peer, Abort!\n", 1671ad81507eSRandall Stewart strmseq, asoc->strmin[strmno].last_sequence_delivered); 1672139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1673f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1674f8829a4aSRandall Stewart if (oper) { 1675f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1676f8829a4aSRandall Stewart uint32_t *ippp; 1677f8829a4aSRandall Stewart 1678139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 1679f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1680f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 1681f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1682139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 1683f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1684a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_14); 1685f8829a4aSRandall Stewart ippp++; 1686f8829a4aSRandall Stewart *ippp = tsn; 1687f8829a4aSRandall Stewart ippp++; 1688f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 1689f8829a4aSRandall Stewart 1690f8829a4aSRandall Stewart } 1691a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_14; 1692f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1693ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1694f8829a4aSRandall Stewart *abort_flag = 1; 1695f8829a4aSRandall Stewart return (0); 1696f8829a4aSRandall Stewart } 1697f42a358aSRandall Stewart /************************************ 1698f42a358aSRandall Stewart * From here down we may find ch-> invalid 1699f42a358aSRandall Stewart * so its a good idea NOT to use it. 1700f42a358aSRandall Stewart *************************************/ 1701f42a358aSRandall Stewart 1702f8829a4aSRandall Stewart the_len = (chk_length - sizeof(struct sctp_data_chunk)); 1703f8829a4aSRandall Stewart if (last_chunk == 0) { 170444b7479bSRandall Stewart dmbuf = SCTP_M_COPYM(*m, 1705f8829a4aSRandall Stewart (offset + sizeof(struct sctp_data_chunk)), 1706f8829a4aSRandall Stewart the_len, M_DONTWAIT); 1707f8829a4aSRandall Stewart #ifdef SCTP_MBUF_LOGGING 1708b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { 1709f8829a4aSRandall Stewart struct mbuf *mat; 1710f8829a4aSRandall Stewart 1711f8829a4aSRandall Stewart mat = dmbuf; 1712f8829a4aSRandall Stewart while (mat) { 1713139bc87fSRandall Stewart if (SCTP_BUF_IS_EXTENDED(mat)) { 1714f8829a4aSRandall Stewart sctp_log_mb(mat, SCTP_MBUF_ICOPY); 1715f8829a4aSRandall Stewart } 1716139bc87fSRandall Stewart mat = SCTP_BUF_NEXT(mat); 1717f8829a4aSRandall Stewart } 1718f8829a4aSRandall Stewart } 1719f8829a4aSRandall Stewart #endif 1720f8829a4aSRandall Stewart } else { 1721f8829a4aSRandall Stewart /* We can steal the last chunk */ 1722139bc87fSRandall Stewart int l_len; 1723139bc87fSRandall Stewart 1724f8829a4aSRandall Stewart dmbuf = *m; 1725f8829a4aSRandall Stewart /* lop off the top part */ 1726f8829a4aSRandall Stewart m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk))); 1727139bc87fSRandall Stewart if (SCTP_BUF_NEXT(dmbuf) == NULL) { 1728139bc87fSRandall Stewart l_len = SCTP_BUF_LEN(dmbuf); 1729139bc87fSRandall Stewart } else { 1730139bc87fSRandall Stewart /* 1731139bc87fSRandall Stewart * need to count up the size hopefully does not hit 1732139bc87fSRandall Stewart * this to often :-0 1733139bc87fSRandall Stewart */ 1734139bc87fSRandall Stewart struct mbuf *lat; 1735139bc87fSRandall Stewart 1736139bc87fSRandall Stewart l_len = 0; 1737139bc87fSRandall Stewart lat = dmbuf; 1738139bc87fSRandall Stewart while (lat) { 1739139bc87fSRandall Stewart l_len += SCTP_BUF_LEN(lat); 1740139bc87fSRandall Stewart lat = SCTP_BUF_NEXT(lat); 1741139bc87fSRandall Stewart } 1742139bc87fSRandall Stewart } 1743139bc87fSRandall Stewart if (l_len > the_len) { 1744f8829a4aSRandall Stewart /* Trim the end round bytes off too */ 1745139bc87fSRandall Stewart m_adj(dmbuf, -(l_len - the_len)); 1746f8829a4aSRandall Stewart } 1747f8829a4aSRandall Stewart } 1748f8829a4aSRandall Stewart if (dmbuf == NULL) { 1749f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1750f8829a4aSRandall Stewart return (0); 1751f8829a4aSRandall Stewart } 1752f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG && 1753f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress == 0 && 1754f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->resetHead) && 1755f42a358aSRandall Stewart ((ordered == 0) || 1756f8829a4aSRandall Stewart ((asoc->strmin[strmno].last_sequence_delivered + 1) == strmseq && 1757f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->strmin[strmno].inqueue)))) { 1758f8829a4aSRandall Stewart /* Candidate for express delivery */ 1759f8829a4aSRandall Stewart /* 1760f8829a4aSRandall Stewart * Its not fragmented, No PD-API is up, Nothing in the 1761f8829a4aSRandall Stewart * delivery queue, Its un-ordered OR ordered and the next to 1762f8829a4aSRandall Stewart * deliver AND nothing else is stuck on the stream queue, 1763f8829a4aSRandall Stewart * And there is room for it in the socket buffer. Lets just 1764f8829a4aSRandall Stewart * stuff it up the buffer.... 1765f8829a4aSRandall Stewart */ 1766f8829a4aSRandall Stewart 1767f8829a4aSRandall Stewart /* It would be nice to avoid this copy if we could :< */ 1768f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, control); 1769f8829a4aSRandall Stewart sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, 1770f42a358aSRandall Stewart protocol_id, 1771f8829a4aSRandall Stewart stcb->asoc.context, 1772f8829a4aSRandall Stewart strmno, strmseq, 1773f42a358aSRandall Stewart chunk_flags, 1774f8829a4aSRandall Stewart dmbuf); 1775f8829a4aSRandall Stewart if (control == NULL) { 1776f8829a4aSRandall Stewart goto failed_express_del; 1777f8829a4aSRandall Stewart } 1778cfde3ff7SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 1779cfde3ff7SRandall Stewart control, &stcb->sctp_socket->so_rcv, 1780cfde3ff7SRandall Stewart 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 1781830d754dSRandall Stewart 1782f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { 1783f8829a4aSRandall Stewart /* for ordered, bump what we delivered */ 1784f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered++; 1785f8829a4aSRandall Stewart } 1786f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvexpress); 1787b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 17886a91f103SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, 1789f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_EXPRS_DEL); 179080fefe0aSRandall Stewart } 1791f8829a4aSRandall Stewart control = NULL; 1792b5c16493SMichael Tuexen 179377acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 179477acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 179577acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 179677acdc25SRandall Stewart } 1797f8829a4aSRandall Stewart goto finish_express_del; 1798f8829a4aSRandall Stewart } 1799f8829a4aSRandall Stewart failed_express_del: 1800f8829a4aSRandall Stewart /* If we reach here this is a new chunk */ 1801f8829a4aSRandall Stewart chk = NULL; 1802f8829a4aSRandall Stewart control = NULL; 1803f8829a4aSRandall Stewart /* Express for fragmented delivery? */ 1804f8829a4aSRandall Stewart if ((asoc->fragmented_delivery_inprogress) && 1805f8829a4aSRandall Stewart (stcb->asoc.control_pdapi) && 1806f8829a4aSRandall Stewart (asoc->str_of_pdapi == strmno) && 1807f8829a4aSRandall Stewart (asoc->ssn_of_pdapi == strmseq) 1808f8829a4aSRandall Stewart ) { 1809f8829a4aSRandall Stewart control = stcb->asoc.control_pdapi; 1810f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) { 1811f8829a4aSRandall Stewart /* Can't be another first? */ 1812f8829a4aSRandall Stewart goto failed_pdapi_express_del; 1813f8829a4aSRandall Stewart } 1814f8829a4aSRandall Stewart if (tsn == (control->sinfo_tsn + 1)) { 1815f8829a4aSRandall Stewart /* Yep, we can add it on */ 1816f8829a4aSRandall Stewart int end = 0; 1817f8829a4aSRandall Stewart uint32_t cumack; 1818f8829a4aSRandall Stewart 1819f42a358aSRandall Stewart if (chunk_flags & SCTP_DATA_LAST_FRAG) { 1820f8829a4aSRandall Stewart end = 1; 1821f8829a4aSRandall Stewart } 1822f8829a4aSRandall Stewart cumack = asoc->cumulative_tsn; 1823f8829a4aSRandall Stewart if ((cumack + 1) == tsn) 1824f8829a4aSRandall Stewart cumack = tsn; 1825f8829a4aSRandall Stewart 1826f8829a4aSRandall Stewart if (sctp_append_to_readq(stcb->sctp_ep, stcb, control, dmbuf, end, 1827f8829a4aSRandall Stewart tsn, 1828f8829a4aSRandall Stewart &stcb->sctp_socket->so_rcv)) { 1829ad81507eSRandall Stewart SCTP_PRINTF("Append fails end:%d\n", end); 1830f8829a4aSRandall Stewart goto failed_pdapi_express_del; 1831f8829a4aSRandall Stewart } 183277acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 183377acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 1834830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 1835830d754dSRandall Stewart } 1836f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvexpressm); 1837f8829a4aSRandall Stewart control->sinfo_tsn = tsn; 1838f8829a4aSRandall Stewart asoc->tsn_last_delivered = tsn; 1839f42a358aSRandall Stewart asoc->fragment_flags = chunk_flags; 1840f8829a4aSRandall Stewart asoc->tsn_of_pdapi_last_delivered = tsn; 1841f42a358aSRandall Stewart asoc->last_flags_delivered = chunk_flags; 1842f8829a4aSRandall Stewart asoc->last_strm_seq_delivered = strmseq; 1843f8829a4aSRandall Stewart asoc->last_strm_no_delivered = strmno; 1844f8829a4aSRandall Stewart if (end) { 1845f8829a4aSRandall Stewart /* clean up the flags and such */ 1846f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 1847f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { 1848f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered++; 1849a5d547adSRandall Stewart } 1850f8829a4aSRandall Stewart stcb->asoc.control_pdapi = NULL; 1851139bc87fSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue) == 0) { 1852139bc87fSRandall Stewart /* 1853139bc87fSRandall Stewart * There could be another message 1854139bc87fSRandall Stewart * ready 1855139bc87fSRandall Stewart */ 1856139bc87fSRandall Stewart need_reasm_check = 1; 1857139bc87fSRandall Stewart } 1858f8829a4aSRandall Stewart } 1859f8829a4aSRandall Stewart control = NULL; 1860f8829a4aSRandall Stewart goto finish_express_del; 1861f8829a4aSRandall Stewart } 1862f8829a4aSRandall Stewart } 1863f8829a4aSRandall Stewart failed_pdapi_express_del: 1864f8829a4aSRandall Stewart control = NULL; 186577acdc25SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) { 186677acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 186777acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 186877acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 186977acdc25SRandall Stewart } 187077acdc25SRandall Stewart } else { 187177acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap); 187277acdc25SRandall Stewart if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) { 187377acdc25SRandall Stewart asoc->highest_tsn_inside_map = tsn; 187477acdc25SRandall Stewart } 187577acdc25SRandall Stewart } 1876f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { 1877f8829a4aSRandall Stewart sctp_alloc_a_chunk(stcb, chk); 1878f8829a4aSRandall Stewart if (chk == NULL) { 1879f8829a4aSRandall Stewart /* No memory so we drop the chunk */ 1880f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1881f8829a4aSRandall Stewart if (last_chunk == 0) { 1882f8829a4aSRandall Stewart /* we copied it, free the copy */ 1883f8829a4aSRandall Stewart sctp_m_freem(dmbuf); 1884f8829a4aSRandall Stewart } 1885f8829a4aSRandall Stewart return (0); 1886f8829a4aSRandall Stewart } 1887f8829a4aSRandall Stewart chk->rec.data.TSN_seq = tsn; 1888f8829a4aSRandall Stewart chk->no_fr_allowed = 0; 1889f8829a4aSRandall Stewart chk->rec.data.stream_seq = strmseq; 1890f8829a4aSRandall Stewart chk->rec.data.stream_number = strmno; 1891f42a358aSRandall Stewart chk->rec.data.payloadtype = protocol_id; 1892f8829a4aSRandall Stewart chk->rec.data.context = stcb->asoc.context; 1893f8829a4aSRandall Stewart chk->rec.data.doing_fast_retransmit = 0; 1894f42a358aSRandall Stewart chk->rec.data.rcv_flags = chunk_flags; 1895f8829a4aSRandall Stewart chk->asoc = asoc; 1896f8829a4aSRandall Stewart chk->send_size = the_len; 1897f8829a4aSRandall Stewart chk->whoTo = net; 1898f8829a4aSRandall Stewart atomic_add_int(&net->ref_count, 1); 1899f8829a4aSRandall Stewart chk->data = dmbuf; 1900f8829a4aSRandall Stewart } else { 1901f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, control); 1902f8829a4aSRandall Stewart sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, 1903f42a358aSRandall Stewart protocol_id, 1904f8829a4aSRandall Stewart stcb->asoc.context, 1905f8829a4aSRandall Stewart strmno, strmseq, 1906f42a358aSRandall Stewart chunk_flags, 1907f8829a4aSRandall Stewart dmbuf); 1908f8829a4aSRandall Stewart if (control == NULL) { 1909f8829a4aSRandall Stewart /* No memory so we drop the chunk */ 1910f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1911f8829a4aSRandall Stewart if (last_chunk == 0) { 1912f8829a4aSRandall Stewart /* we copied it, free the copy */ 1913f8829a4aSRandall Stewart sctp_m_freem(dmbuf); 1914f8829a4aSRandall Stewart } 1915f8829a4aSRandall Stewart return (0); 1916f8829a4aSRandall Stewart } 1917f8829a4aSRandall Stewart control->length = the_len; 1918f8829a4aSRandall Stewart } 1919f8829a4aSRandall Stewart 1920f8829a4aSRandall Stewart /* Mark it as received */ 1921f8829a4aSRandall Stewart /* Now queue it where it belongs */ 1922f8829a4aSRandall Stewart if (control != NULL) { 1923f8829a4aSRandall Stewart /* First a sanity check */ 1924f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 1925f8829a4aSRandall Stewart /* 1926f8829a4aSRandall Stewart * Ok, we have a fragmented delivery in progress if 1927f8829a4aSRandall Stewart * this chunk is next to deliver OR belongs in our 1928f8829a4aSRandall Stewart * view to the reassembly, the peer is evil or 1929f8829a4aSRandall Stewart * broken. 1930f8829a4aSRandall Stewart */ 1931f8829a4aSRandall Stewart uint32_t estimate_tsn; 1932f8829a4aSRandall Stewart 1933f8829a4aSRandall Stewart estimate_tsn = asoc->tsn_last_delivered + 1; 1934f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue) && 1935f8829a4aSRandall Stewart (estimate_tsn == control->sinfo_tsn)) { 1936f8829a4aSRandall Stewart /* Evil/Broke peer */ 1937f8829a4aSRandall Stewart sctp_m_freem(control->data); 1938f8829a4aSRandall Stewart control->data = NULL; 19395bead436SRandall Stewart if (control->whoFrom) { 1940f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 19415bead436SRandall Stewart control->whoFrom = NULL; 19425bead436SRandall Stewart } 1943f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 1944139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1945f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1946f8829a4aSRandall Stewart if (oper) { 1947f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1948f8829a4aSRandall Stewart uint32_t *ippp; 1949f8829a4aSRandall Stewart 1950139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1951f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1952f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1953f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 1954f8829a4aSRandall Stewart ph->param_type = 1955f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1956139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 1957f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1958a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_15); 1959f8829a4aSRandall Stewart ippp++; 1960f8829a4aSRandall Stewart *ippp = tsn; 1961f8829a4aSRandall Stewart ippp++; 1962f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 1963f8829a4aSRandall Stewart } 1964a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_15; 1965f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1966ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1967f8829a4aSRandall Stewart 1968f8829a4aSRandall Stewart *abort_flag = 1; 1969f8829a4aSRandall Stewart return (0); 1970f8829a4aSRandall Stewart } else { 1971f8829a4aSRandall Stewart if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) { 1972f8829a4aSRandall Stewart sctp_m_freem(control->data); 1973f8829a4aSRandall Stewart control->data = NULL; 19745bead436SRandall Stewart if (control->whoFrom) { 1975f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 19765bead436SRandall Stewart control->whoFrom = NULL; 19775bead436SRandall Stewart } 1978f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 1979f8829a4aSRandall Stewart 1980139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1981f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1982f8829a4aSRandall Stewart if (oper) { 1983f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1984f8829a4aSRandall Stewart uint32_t *ippp; 1985f8829a4aSRandall Stewart 1986139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1987f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1988f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1989f8829a4aSRandall Stewart ph = mtod(oper, 1990f8829a4aSRandall Stewart struct sctp_paramhdr *); 1991f8829a4aSRandall Stewart ph->param_type = 1992f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1993f8829a4aSRandall Stewart ph->param_length = 1994139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1995f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1996a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_16); 1997f8829a4aSRandall Stewart ippp++; 1998f8829a4aSRandall Stewart *ippp = tsn; 1999f8829a4aSRandall Stewart ippp++; 2000f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 2001f8829a4aSRandall Stewart } 2002a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16; 2003f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 2004ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 2005f8829a4aSRandall Stewart 2006f8829a4aSRandall Stewart *abort_flag = 1; 2007f8829a4aSRandall Stewart return (0); 2008f8829a4aSRandall Stewart } 2009f8829a4aSRandall Stewart } 2010f8829a4aSRandall Stewart } else { 2011f8829a4aSRandall Stewart /* No PDAPI running */ 2012f8829a4aSRandall Stewart if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 2013f8829a4aSRandall Stewart /* 2014f8829a4aSRandall Stewart * Reassembly queue is NOT empty validate 2015f8829a4aSRandall Stewart * that this tsn does not need to be in 2016f8829a4aSRandall Stewart * reasembly queue. If it does then our peer 2017f8829a4aSRandall Stewart * is broken or evil. 2018f8829a4aSRandall Stewart */ 2019f8829a4aSRandall Stewart if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) { 2020f8829a4aSRandall Stewart sctp_m_freem(control->data); 2021f8829a4aSRandall Stewart control->data = NULL; 20225bead436SRandall Stewart if (control->whoFrom) { 2023f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 20245bead436SRandall Stewart control->whoFrom = NULL; 20255bead436SRandall Stewart } 2026f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 2027139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 2028f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 2029f8829a4aSRandall Stewart if (oper) { 2030f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 2031f8829a4aSRandall Stewart uint32_t *ippp; 2032f8829a4aSRandall Stewart 2033139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 2034f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 2035f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 2036f8829a4aSRandall Stewart ph = mtod(oper, 2037f8829a4aSRandall Stewart struct sctp_paramhdr *); 2038f8829a4aSRandall Stewart ph->param_type = 2039f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 2040f8829a4aSRandall Stewart ph->param_length = 2041139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 2042f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 2043a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_17); 2044f8829a4aSRandall Stewart ippp++; 2045f8829a4aSRandall Stewart *ippp = tsn; 2046f8829a4aSRandall Stewart ippp++; 2047f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 2048f8829a4aSRandall Stewart } 2049a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_17; 2050f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 2051ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 2052f8829a4aSRandall Stewart 2053f8829a4aSRandall Stewart *abort_flag = 1; 2054f8829a4aSRandall Stewart return (0); 2055f8829a4aSRandall Stewart } 2056f8829a4aSRandall Stewart } 2057f8829a4aSRandall Stewart } 2058f8829a4aSRandall Stewart /* ok, if we reach here we have passed the sanity checks */ 2059f42a358aSRandall Stewart if (chunk_flags & SCTP_DATA_UNORDERED) { 2060f8829a4aSRandall Stewart /* queue directly into socket buffer */ 2061b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 2062f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 2063f8829a4aSRandall Stewart control, 2064cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 2065f8829a4aSRandall Stewart } else { 2066f8829a4aSRandall Stewart /* 2067f8829a4aSRandall Stewart * Special check for when streams are resetting. We 2068f8829a4aSRandall Stewart * could be more smart about this and check the 2069f8829a4aSRandall Stewart * actual stream to see if it is not being reset.. 2070f8829a4aSRandall Stewart * that way we would not create a HOLB when amongst 2071f8829a4aSRandall Stewart * streams being reset and those not being reset. 2072f8829a4aSRandall Stewart * 2073f8829a4aSRandall Stewart * We take complete messages that have a stream reset 2074f8829a4aSRandall Stewart * intervening (aka the TSN is after where our 2075f8829a4aSRandall Stewart * cum-ack needs to be) off and put them on a 2076f8829a4aSRandall Stewart * pending_reply_queue. The reassembly ones we do 2077f8829a4aSRandall Stewart * not have to worry about since they are all sorted 2078f8829a4aSRandall Stewart * and proceessed by TSN order. It is only the 2079f8829a4aSRandall Stewart * singletons I must worry about. 2080f8829a4aSRandall Stewart */ 2081f8829a4aSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 2082d61a0ae0SRandall Stewart ((compare_with_wrap(tsn, liste->tsn, MAX_TSN))) 2083f8829a4aSRandall Stewart ) { 2084f8829a4aSRandall Stewart /* 2085f8829a4aSRandall Stewart * yep its past where we need to reset... go 2086f8829a4aSRandall Stewart * ahead and queue it. 2087f8829a4aSRandall Stewart */ 2088f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->pending_reply_queue)) { 2089f8829a4aSRandall Stewart /* first one on */ 2090f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2091f8829a4aSRandall Stewart } else { 2092f8829a4aSRandall Stewart struct sctp_queued_to_read *ctlOn; 2093f8829a4aSRandall Stewart unsigned char inserted = 0; 2094f8829a4aSRandall Stewart 2095f8829a4aSRandall Stewart ctlOn = TAILQ_FIRST(&asoc->pending_reply_queue); 2096f8829a4aSRandall Stewart while (ctlOn) { 2097f8829a4aSRandall Stewart if (compare_with_wrap(control->sinfo_tsn, 2098f8829a4aSRandall Stewart ctlOn->sinfo_tsn, MAX_TSN)) { 2099f8829a4aSRandall Stewart ctlOn = TAILQ_NEXT(ctlOn, next); 2100f8829a4aSRandall Stewart } else { 2101f8829a4aSRandall Stewart /* found it */ 2102f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(ctlOn, control, next); 2103f8829a4aSRandall Stewart inserted = 1; 2104f8829a4aSRandall Stewart break; 2105f8829a4aSRandall Stewart } 2106f8829a4aSRandall Stewart } 2107f8829a4aSRandall Stewart if (inserted == 0) { 2108f8829a4aSRandall Stewart /* 2109f8829a4aSRandall Stewart * must be put at end, use 2110f8829a4aSRandall Stewart * prevP (all setup from 2111f8829a4aSRandall Stewart * loop) to setup nextP. 2112f8829a4aSRandall Stewart */ 2113f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2114f8829a4aSRandall Stewart } 2115f8829a4aSRandall Stewart } 2116f8829a4aSRandall Stewart } else { 2117f8829a4aSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, control, abort_flag); 2118f8829a4aSRandall Stewart if (*abort_flag) { 2119f8829a4aSRandall Stewart return (0); 2120f8829a4aSRandall Stewart } 2121f8829a4aSRandall Stewart } 2122f8829a4aSRandall Stewart } 2123f8829a4aSRandall Stewart } else { 2124f8829a4aSRandall Stewart /* Into the re-assembly queue */ 2125f8829a4aSRandall Stewart sctp_queue_data_for_reasm(stcb, asoc, chk, abort_flag); 2126f8829a4aSRandall Stewart if (*abort_flag) { 2127a5d547adSRandall Stewart /* 2128a5d547adSRandall Stewart * the assoc is now gone and chk was put onto the 2129a5d547adSRandall Stewart * reasm queue, which has all been freed. 2130a5d547adSRandall Stewart */ 2131a5d547adSRandall Stewart *m = NULL; 2132f8829a4aSRandall Stewart return (0); 2133f8829a4aSRandall Stewart } 2134f8829a4aSRandall Stewart } 2135f8829a4aSRandall Stewart finish_express_del: 2136307b49efSMichael Tuexen if (tsn == (asoc->cumulative_tsn + 1)) { 2137307b49efSMichael Tuexen /* Update cum-ack */ 2138307b49efSMichael Tuexen asoc->cumulative_tsn = tsn; 2139307b49efSMichael Tuexen } 2140f8829a4aSRandall Stewart if (last_chunk) { 2141f8829a4aSRandall Stewart *m = NULL; 2142f8829a4aSRandall Stewart } 2143f42a358aSRandall Stewart if (ordered) { 2144f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inorderchunks); 2145f8829a4aSRandall Stewart } else { 2146f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inunorderchunks); 2147f8829a4aSRandall Stewart } 2148f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdata); 2149f8829a4aSRandall Stewart /* Set it present please */ 2150b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 21516a91f103SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, SCTP_STR_LOG_FROM_MARK_TSN); 215280fefe0aSRandall Stewart } 2153b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2154f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, 2155f8829a4aSRandall Stewart asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE); 215680fefe0aSRandall Stewart } 215717205eccSRandall Stewart /* check the special flag for stream resets */ 215817205eccSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 2159d61a0ae0SRandall Stewart ((compare_with_wrap(asoc->cumulative_tsn, liste->tsn, MAX_TSN)) || 2160d61a0ae0SRandall Stewart (asoc->cumulative_tsn == liste->tsn)) 216117205eccSRandall Stewart ) { 216217205eccSRandall Stewart /* 216317205eccSRandall Stewart * we have finished working through the backlogged TSN's now 216417205eccSRandall Stewart * time to reset streams. 1: call reset function. 2: free 216517205eccSRandall Stewart * pending_reply space 3: distribute any chunks in 216617205eccSRandall Stewart * pending_reply_queue. 216717205eccSRandall Stewart */ 216817205eccSRandall Stewart struct sctp_queued_to_read *ctl; 216917205eccSRandall Stewart 217017205eccSRandall Stewart sctp_reset_in_stream(stcb, liste->number_entries, liste->req.list_of_streams); 217117205eccSRandall Stewart TAILQ_REMOVE(&asoc->resetHead, liste, next_resp); 2172207304d4SRandall Stewart SCTP_FREE(liste, SCTP_M_STRESET); 21733c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 217417205eccSRandall Stewart liste = TAILQ_FIRST(&asoc->resetHead); 217517205eccSRandall Stewart ctl = TAILQ_FIRST(&asoc->pending_reply_queue); 217617205eccSRandall Stewart if (ctl && (liste == NULL)) { 217717205eccSRandall Stewart /* All can be removed */ 217817205eccSRandall Stewart while (ctl) { 217917205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 218017205eccSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag); 218117205eccSRandall Stewart if (*abort_flag) { 218217205eccSRandall Stewart return (0); 218317205eccSRandall Stewart } 218417205eccSRandall Stewart ctl = TAILQ_FIRST(&asoc->pending_reply_queue); 218517205eccSRandall Stewart } 218617205eccSRandall Stewart } else if (ctl) { 218717205eccSRandall Stewart /* more than one in queue */ 2188d61a0ae0SRandall Stewart while (!compare_with_wrap(ctl->sinfo_tsn, liste->tsn, MAX_TSN)) { 218917205eccSRandall Stewart /* 219017205eccSRandall Stewart * if ctl->sinfo_tsn is <= liste->tsn we can 219117205eccSRandall Stewart * process it which is the NOT of 219217205eccSRandall Stewart * ctl->sinfo_tsn > liste->tsn 219317205eccSRandall Stewart */ 219417205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 219517205eccSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag); 219617205eccSRandall Stewart if (*abort_flag) { 219717205eccSRandall Stewart return (0); 219817205eccSRandall Stewart } 219917205eccSRandall Stewart ctl = TAILQ_FIRST(&asoc->pending_reply_queue); 220017205eccSRandall Stewart } 220117205eccSRandall Stewart } 220217205eccSRandall Stewart /* 220317205eccSRandall Stewart * Now service re-assembly to pick up anything that has been 220417205eccSRandall Stewart * held on reassembly queue? 220517205eccSRandall Stewart */ 220617205eccSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 220717205eccSRandall Stewart need_reasm_check = 0; 220817205eccSRandall Stewart } 2209139bc87fSRandall Stewart if (need_reasm_check) { 2210139bc87fSRandall Stewart /* Another one waits ? */ 2211139bc87fSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 2212139bc87fSRandall Stewart } 2213f8829a4aSRandall Stewart return (1); 2214f8829a4aSRandall Stewart } 2215f8829a4aSRandall Stewart 2216f8829a4aSRandall Stewart int8_t sctp_map_lookup_tab[256] = { 2217b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2218b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2219b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2220b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2221b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2222b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2223b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2224b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 6, 2225b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2226b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2227b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2228b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2229b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2230b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2231b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2232b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 7, 2233b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2234b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2235b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2236b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2237b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2238b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2239b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2240b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 6, 2241b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2242b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2243b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2244b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2245b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2246b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2247b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2248b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 8 2249f8829a4aSRandall Stewart }; 2250f8829a4aSRandall Stewart 2251f8829a4aSRandall Stewart 2252f8829a4aSRandall Stewart void 2253b5c16493SMichael Tuexen sctp_slide_mapping_arrays(struct sctp_tcb *stcb) 2254f8829a4aSRandall Stewart { 2255f8829a4aSRandall Stewart /* 2256f8829a4aSRandall Stewart * Now we also need to check the mapping array in a couple of ways. 2257f8829a4aSRandall Stewart * 1) Did we move the cum-ack point? 225866bd30bdSRandall Stewart * 225966bd30bdSRandall Stewart * When you first glance at this you might think that all entries that 226066bd30bdSRandall Stewart * make up the postion of the cum-ack would be in the nr-mapping 226166bd30bdSRandall Stewart * array only.. i.e. things up to the cum-ack are always 226266bd30bdSRandall Stewart * deliverable. Thats true with one exception, when its a fragmented 226366bd30bdSRandall Stewart * message we may not deliver the data until some threshold (or all 226466bd30bdSRandall Stewart * of it) is in place. So we must OR the nr_mapping_array and 226566bd30bdSRandall Stewart * mapping_array to get a true picture of the cum-ack. 2266f8829a4aSRandall Stewart */ 2267f8829a4aSRandall Stewart struct sctp_association *asoc; 2268b3f1ea41SRandall Stewart int at; 226966bd30bdSRandall Stewart uint8_t val; 2270f8829a4aSRandall Stewart int slide_from, slide_end, lgap, distance; 227177acdc25SRandall Stewart uint32_t old_cumack, old_base, old_highest, highest_tsn; 2272f8829a4aSRandall Stewart 2273f8829a4aSRandall Stewart asoc = &stcb->asoc; 2274f8829a4aSRandall Stewart at = 0; 2275f8829a4aSRandall Stewart 2276f8829a4aSRandall Stewart old_cumack = asoc->cumulative_tsn; 2277f8829a4aSRandall Stewart old_base = asoc->mapping_array_base_tsn; 2278f8829a4aSRandall Stewart old_highest = asoc->highest_tsn_inside_map; 2279f8829a4aSRandall Stewart /* 2280f8829a4aSRandall Stewart * We could probably improve this a small bit by calculating the 2281f8829a4aSRandall Stewart * offset of the current cum-ack as the starting point. 2282f8829a4aSRandall Stewart */ 2283f8829a4aSRandall Stewart at = 0; 2284b5c16493SMichael Tuexen for (slide_from = 0; slide_from < stcb->asoc.mapping_array_size; slide_from++) { 228566bd30bdSRandall Stewart val = asoc->nr_mapping_array[slide_from] | asoc->mapping_array[slide_from]; 228666bd30bdSRandall Stewart if (val == 0xff) { 2287f8829a4aSRandall Stewart at += 8; 2288f8829a4aSRandall Stewart } else { 2289f8829a4aSRandall Stewart /* there is a 0 bit */ 229066bd30bdSRandall Stewart at += sctp_map_lookup_tab[val]; 2291f8829a4aSRandall Stewart break; 2292f8829a4aSRandall Stewart } 2293f8829a4aSRandall Stewart } 2294b5c16493SMichael Tuexen asoc->cumulative_tsn = asoc->mapping_array_base_tsn + (at - 1); 2295f8829a4aSRandall Stewart 229677acdc25SRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, asoc->highest_tsn_inside_map, MAX_TSN) && 2297aed5947cSMichael Tuexen compare_with_wrap(asoc->cumulative_tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 2298a5d547adSRandall Stewart #ifdef INVARIANTS 2299ceaad40aSRandall Stewart panic("huh, cumack 0x%x greater than high-tsn 0x%x in map", 2300ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 2301f8829a4aSRandall Stewart #else 2302ceaad40aSRandall Stewart SCTP_PRINTF("huh, cumack 0x%x greater than high-tsn 0x%x in map - should panic?\n", 2303ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 23040e13104dSRandall Stewart sctp_print_mapping_array(asoc); 2305b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2306b3f1ea41SRandall Stewart sctp_log_map(0, 6, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 2307b3f1ea41SRandall Stewart } 2308f8829a4aSRandall Stewart asoc->highest_tsn_inside_map = asoc->cumulative_tsn; 2309830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn; 2310f8829a4aSRandall Stewart #endif 2311f8829a4aSRandall Stewart } 231277acdc25SRandall Stewart if (compare_with_wrap(asoc->highest_tsn_inside_nr_map, 231377acdc25SRandall Stewart asoc->highest_tsn_inside_map, 231477acdc25SRandall Stewart MAX_TSN)) { 231577acdc25SRandall Stewart highest_tsn = asoc->highest_tsn_inside_nr_map; 231677acdc25SRandall Stewart } else { 231777acdc25SRandall Stewart highest_tsn = asoc->highest_tsn_inside_map; 231877acdc25SRandall Stewart } 231977acdc25SRandall Stewart if ((asoc->cumulative_tsn == highest_tsn) && (at >= 8)) { 2320f8829a4aSRandall Stewart /* The complete array was completed by a single FR */ 232177acdc25SRandall Stewart /* highest becomes the cum-ack */ 232237f144ebSMichael Tuexen int clr; 232337f144ebSMichael Tuexen 232437f144ebSMichael Tuexen #ifdef INVARIANTS 232537f144ebSMichael Tuexen unsigned int i; 232637f144ebSMichael Tuexen 232737f144ebSMichael Tuexen #endif 2328f8829a4aSRandall Stewart 2329f8829a4aSRandall Stewart /* clear the array */ 2330b5c16493SMichael Tuexen clr = ((at + 7) >> 3); 2331c4739e2fSRandall Stewart if (clr > asoc->mapping_array_size) { 2332f8829a4aSRandall Stewart clr = asoc->mapping_array_size; 2333f8829a4aSRandall Stewart } 2334f8829a4aSRandall Stewart memset(asoc->mapping_array, 0, clr); 2335830d754dSRandall Stewart memset(asoc->nr_mapping_array, 0, clr); 233637f144ebSMichael Tuexen #ifdef INVARIANTS 2337b5c16493SMichael Tuexen for (i = 0; i < asoc->mapping_array_size; i++) { 2338b5c16493SMichael Tuexen if ((asoc->mapping_array[i]) || (asoc->nr_mapping_array[i])) { 2339b5c16493SMichael Tuexen printf("Error Mapping array's not clean at clear\n"); 2340b5c16493SMichael Tuexen sctp_print_mapping_array(asoc); 2341b5c16493SMichael Tuexen } 2342b5c16493SMichael Tuexen } 234337f144ebSMichael Tuexen #endif 234477acdc25SRandall Stewart asoc->mapping_array_base_tsn = asoc->cumulative_tsn + 1; 234577acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->highest_tsn_inside_map = asoc->cumulative_tsn; 2346f8829a4aSRandall Stewart } else if (at >= 8) { 2347f8829a4aSRandall Stewart /* we can slide the mapping array down */ 2348b3f1ea41SRandall Stewart /* slide_from holds where we hit the first NON 0xff byte */ 2349b3f1ea41SRandall Stewart 2350f8829a4aSRandall Stewart /* 2351f8829a4aSRandall Stewart * now calculate the ceiling of the move using our highest 2352f8829a4aSRandall Stewart * TSN value 2353f8829a4aSRandall Stewart */ 235477acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(lgap, highest_tsn, asoc->mapping_array_base_tsn); 235577acdc25SRandall Stewart slide_end = (lgap >> 3); 2356f8829a4aSRandall Stewart if (slide_end < slide_from) { 235777acdc25SRandall Stewart sctp_print_mapping_array(asoc); 2358d55b0b1bSRandall Stewart #ifdef INVARIANTS 2359f8829a4aSRandall Stewart panic("impossible slide"); 2360d55b0b1bSRandall Stewart #else 236177acdc25SRandall Stewart printf("impossible slide lgap:%x slide_end:%x slide_from:%x? at:%d\n", 236277acdc25SRandall Stewart lgap, slide_end, slide_from, at); 2363d55b0b1bSRandall Stewart return; 2364d55b0b1bSRandall Stewart #endif 2365f8829a4aSRandall Stewart } 2366b3f1ea41SRandall Stewart if (slide_end > asoc->mapping_array_size) { 2367b3f1ea41SRandall Stewart #ifdef INVARIANTS 2368b3f1ea41SRandall Stewart panic("would overrun buffer"); 2369b3f1ea41SRandall Stewart #else 2370b3f1ea41SRandall Stewart printf("Gak, would have overrun map end:%d slide_end:%d\n", 2371b3f1ea41SRandall Stewart asoc->mapping_array_size, slide_end); 2372b3f1ea41SRandall Stewart slide_end = asoc->mapping_array_size; 2373b3f1ea41SRandall Stewart #endif 2374b3f1ea41SRandall Stewart } 2375f8829a4aSRandall Stewart distance = (slide_end - slide_from) + 1; 2376b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2377f8829a4aSRandall Stewart sctp_log_map(old_base, old_cumack, old_highest, 2378f8829a4aSRandall Stewart SCTP_MAP_PREPARE_SLIDE); 2379f8829a4aSRandall Stewart sctp_log_map((uint32_t) slide_from, (uint32_t) slide_end, 2380f8829a4aSRandall Stewart (uint32_t) lgap, SCTP_MAP_SLIDE_FROM); 238180fefe0aSRandall Stewart } 2382f8829a4aSRandall Stewart if (distance + slide_from > asoc->mapping_array_size || 2383f8829a4aSRandall Stewart distance < 0) { 2384f8829a4aSRandall Stewart /* 2385f8829a4aSRandall Stewart * Here we do NOT slide forward the array so that 2386f8829a4aSRandall Stewart * hopefully when more data comes in to fill it up 2387f8829a4aSRandall Stewart * we will be able to slide it forward. Really I 2388f8829a4aSRandall Stewart * don't think this should happen :-0 2389f8829a4aSRandall Stewart */ 2390f8829a4aSRandall Stewart 2391b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2392f8829a4aSRandall Stewart sctp_log_map((uint32_t) distance, (uint32_t) slide_from, 2393f8829a4aSRandall Stewart (uint32_t) asoc->mapping_array_size, 2394f8829a4aSRandall Stewart SCTP_MAP_SLIDE_NONE); 239580fefe0aSRandall Stewart } 2396f8829a4aSRandall Stewart } else { 2397f8829a4aSRandall Stewart int ii; 2398f8829a4aSRandall Stewart 2399f8829a4aSRandall Stewart for (ii = 0; ii < distance; ii++) { 240037f144ebSMichael Tuexen asoc->mapping_array[ii] = asoc->mapping_array[slide_from + ii]; 240137f144ebSMichael Tuexen asoc->nr_mapping_array[ii] = asoc->nr_mapping_array[slide_from + ii]; 240277acdc25SRandall Stewart 2403f8829a4aSRandall Stewart } 2404aed5947cSMichael Tuexen for (ii = distance; ii < asoc->mapping_array_size; ii++) { 2405f8829a4aSRandall Stewart asoc->mapping_array[ii] = 0; 240677acdc25SRandall Stewart asoc->nr_mapping_array[ii] = 0; 2407f8829a4aSRandall Stewart } 2408ee94f0a2SMichael Tuexen if (asoc->highest_tsn_inside_map + 1 == asoc->mapping_array_base_tsn) { 2409ee94f0a2SMichael Tuexen asoc->highest_tsn_inside_map += (slide_from << 3); 2410ee94f0a2SMichael Tuexen } 2411ee94f0a2SMichael Tuexen if (asoc->highest_tsn_inside_nr_map + 1 == asoc->mapping_array_base_tsn) { 2412ee94f0a2SMichael Tuexen asoc->highest_tsn_inside_nr_map += (slide_from << 3); 2413ee94f0a2SMichael Tuexen } 2414f8829a4aSRandall Stewart asoc->mapping_array_base_tsn += (slide_from << 3); 2415b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2416f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, 2417f8829a4aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map, 2418f8829a4aSRandall Stewart SCTP_MAP_SLIDE_RESULT); 241980fefe0aSRandall Stewart } 2420830d754dSRandall Stewart } 2421830d754dSRandall Stewart } 2422b5c16493SMichael Tuexen } 2423b5c16493SMichael Tuexen 2424b5c16493SMichael Tuexen 2425b5c16493SMichael Tuexen void 2426b5c16493SMichael Tuexen sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap, int *abort_flag) 2427b5c16493SMichael Tuexen { 2428b5c16493SMichael Tuexen struct sctp_association *asoc; 2429b5c16493SMichael Tuexen uint32_t highest_tsn; 2430b5c16493SMichael Tuexen 2431b5c16493SMichael Tuexen asoc = &stcb->asoc; 2432b5c16493SMichael Tuexen if (compare_with_wrap(asoc->highest_tsn_inside_nr_map, 2433b5c16493SMichael Tuexen asoc->highest_tsn_inside_map, 2434b5c16493SMichael Tuexen MAX_TSN)) { 2435b5c16493SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_nr_map; 2436b5c16493SMichael Tuexen } else { 2437b5c16493SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_map; 2438b5c16493SMichael Tuexen } 2439b5c16493SMichael Tuexen 2440830d754dSRandall Stewart /* 2441f8829a4aSRandall Stewart * Now we need to see if we need to queue a sack or just start the 2442f8829a4aSRandall Stewart * timer (if allowed). 2443f8829a4aSRandall Stewart */ 2444f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 2445f8829a4aSRandall Stewart /* 2446b5c16493SMichael Tuexen * Ok special case, in SHUTDOWN-SENT case. here we maker 2447b5c16493SMichael Tuexen * sure SACK timer is off and instead send a SHUTDOWN and a 2448b5c16493SMichael Tuexen * SACK 2449f8829a4aSRandall Stewart */ 2450139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2451f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_RECV, 2452a5d547adSRandall Stewart stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_INDATA + SCTP_LOC_18); 2453f8829a4aSRandall Stewart } 2454f8829a4aSRandall Stewart sctp_send_shutdown(stcb, stcb->asoc.primary_destination); 2455f8829a4aSRandall Stewart sctp_send_sack(stcb); 2456f8829a4aSRandall Stewart } else { 2457f8829a4aSRandall Stewart int is_a_gap; 2458f8829a4aSRandall Stewart 2459f8829a4aSRandall Stewart /* is there a gap now ? */ 246077acdc25SRandall Stewart is_a_gap = compare_with_wrap(highest_tsn, stcb->asoc.cumulative_tsn, MAX_TSN); 2461f8829a4aSRandall Stewart 2462f8829a4aSRandall Stewart /* 2463b5c16493SMichael Tuexen * CMT DAC algorithm: increase number of packets received 2464b5c16493SMichael Tuexen * since last ack 2465f8829a4aSRandall Stewart */ 2466f8829a4aSRandall Stewart stcb->asoc.cmt_dac_pkts_rcvd++; 2467f8829a4aSRandall Stewart 246842551e99SRandall Stewart if ((stcb->asoc.send_sack == 1) || /* We need to send a 246942551e99SRandall Stewart * SACK */ 2470f8829a4aSRandall Stewart ((was_a_gap) && (is_a_gap == 0)) || /* was a gap, but no 2471f8829a4aSRandall Stewart * longer is one */ 2472f8829a4aSRandall Stewart (stcb->asoc.numduptsns) || /* we have dup's */ 2473f8829a4aSRandall Stewart (is_a_gap) || /* is still a gap */ 247442551e99SRandall Stewart (stcb->asoc.delayed_ack == 0) || /* Delayed sack disabled */ 247542551e99SRandall Stewart (stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) /* hit limit of pkts */ 2476f8829a4aSRandall Stewart ) { 2477f8829a4aSRandall Stewart 2478b3f1ea41SRandall Stewart if ((SCTP_BASE_SYSCTL(sctp_cmt_on_off)) && 2479b3f1ea41SRandall Stewart (SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) && 248042551e99SRandall Stewart (stcb->asoc.send_sack == 0) && 2481f8829a4aSRandall Stewart (stcb->asoc.numduptsns == 0) && 2482f8829a4aSRandall Stewart (stcb->asoc.delayed_ack) && 2483139bc87fSRandall Stewart (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer))) { 2484f8829a4aSRandall Stewart 2485f8829a4aSRandall Stewart /* 2486b5c16493SMichael Tuexen * CMT DAC algorithm: With CMT, delay acks 2487b5c16493SMichael Tuexen * even in the face of 2488f8829a4aSRandall Stewart * 2489b5c16493SMichael Tuexen * reordering. Therefore, if acks that do not 2490b5c16493SMichael Tuexen * have to be sent because of the above 2491b5c16493SMichael Tuexen * reasons, will be delayed. That is, acks 2492b5c16493SMichael Tuexen * that would have been sent due to gap 2493b5c16493SMichael Tuexen * reports will be delayed with DAC. Start 2494f8829a4aSRandall Stewart * the delayed ack timer. 2495f8829a4aSRandall Stewart */ 2496f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2497f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2498f8829a4aSRandall Stewart } else { 2499f8829a4aSRandall Stewart /* 2500b5c16493SMichael Tuexen * Ok we must build a SACK since the timer 2501b5c16493SMichael Tuexen * is pending, we got our first packet OR 2502b5c16493SMichael Tuexen * there are gaps or duplicates. 2503f8829a4aSRandall Stewart */ 2504ad81507eSRandall Stewart (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer); 2505f8829a4aSRandall Stewart sctp_send_sack(stcb); 2506f8829a4aSRandall Stewart } 2507f8829a4aSRandall Stewart } else { 250842551e99SRandall Stewart if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2509f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2510f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2511f8829a4aSRandall Stewart } 2512f8829a4aSRandall Stewart } 2513f8829a4aSRandall Stewart } 2514f8829a4aSRandall Stewart } 2515f8829a4aSRandall Stewart 2516f8829a4aSRandall Stewart void 2517f8829a4aSRandall Stewart sctp_service_queues(struct sctp_tcb *stcb, struct sctp_association *asoc) 2518f8829a4aSRandall Stewart { 2519f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 2520810ec536SMichael Tuexen uint32_t tsize, pd_point; 2521f8829a4aSRandall Stewart uint16_t nxt_todel; 2522f8829a4aSRandall Stewart 2523f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 2524f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 2525f8829a4aSRandall Stewart } 2526f8829a4aSRandall Stewart /* Can we proceed further, i.e. the PD-API is complete */ 2527f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 2528f8829a4aSRandall Stewart /* no */ 2529f8829a4aSRandall Stewart return; 2530f8829a4aSRandall Stewart } 2531f8829a4aSRandall Stewart /* 2532f8829a4aSRandall Stewart * Now is there some other chunk I can deliver from the reassembly 2533f8829a4aSRandall Stewart * queue. 2534f8829a4aSRandall Stewart */ 2535139bc87fSRandall Stewart doit_again: 2536f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 2537f8829a4aSRandall Stewart if (chk == NULL) { 2538f8829a4aSRandall Stewart asoc->size_on_reasm_queue = 0; 2539f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue = 0; 2540f8829a4aSRandall Stewart return; 2541f8829a4aSRandall Stewart } 2542f8829a4aSRandall Stewart nxt_todel = asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1; 2543f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) && 2544f8829a4aSRandall Stewart ((nxt_todel == chk->rec.data.stream_seq) || 2545f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) { 2546f8829a4aSRandall Stewart /* 2547f8829a4aSRandall Stewart * Yep the first one is here. We setup to start reception, 2548f8829a4aSRandall Stewart * by backing down the TSN just in case we can't deliver. 2549f8829a4aSRandall Stewart */ 2550f8829a4aSRandall Stewart 2551f8829a4aSRandall Stewart /* 2552f8829a4aSRandall Stewart * Before we start though either all of the message should 255324ae5c4aSMichael Tuexen * be here or the socket buffer max or nothing on the 2554f8829a4aSRandall Stewart * delivery queue and something can be delivered. 2555f8829a4aSRandall Stewart */ 2556810ec536SMichael Tuexen if (stcb->sctp_socket) { 255724ae5c4aSMichael Tuexen pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), 2558810ec536SMichael Tuexen stcb->sctp_ep->partial_delivery_point); 2559810ec536SMichael Tuexen } else { 2560810ec536SMichael Tuexen pd_point = stcb->sctp_ep->partial_delivery_point; 2561810ec536SMichael Tuexen } 2562810ec536SMichael Tuexen if (sctp_is_all_msg_on_reasm(asoc, &tsize) || (tsize >= pd_point)) { 2563f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 2564f8829a4aSRandall Stewart asoc->tsn_last_delivered = chk->rec.data.TSN_seq - 1; 2565f8829a4aSRandall Stewart asoc->str_of_pdapi = chk->rec.data.stream_number; 2566f8829a4aSRandall Stewart asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 2567f8829a4aSRandall Stewart asoc->pdapi_ppid = chk->rec.data.payloadtype; 2568f8829a4aSRandall Stewart asoc->fragment_flags = chk->rec.data.rcv_flags; 2569f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 2570139bc87fSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 2571139bc87fSRandall Stewart goto doit_again; 2572139bc87fSRandall Stewart } 2573f8829a4aSRandall Stewart } 2574f8829a4aSRandall Stewart } 2575f8829a4aSRandall Stewart } 2576f8829a4aSRandall Stewart 2577f8829a4aSRandall Stewart int 2578f8829a4aSRandall Stewart sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, 2579f8829a4aSRandall Stewart struct sctphdr *sh, struct sctp_inpcb *inp, struct sctp_tcb *stcb, 2580f8829a4aSRandall Stewart struct sctp_nets *net, uint32_t * high_tsn) 2581f8829a4aSRandall Stewart { 2582f8829a4aSRandall Stewart struct sctp_data_chunk *ch, chunk_buf; 2583f8829a4aSRandall Stewart struct sctp_association *asoc; 2584f8829a4aSRandall Stewart int num_chunks = 0; /* number of control chunks processed */ 2585f8829a4aSRandall Stewart int stop_proc = 0; 2586f8829a4aSRandall Stewart int chk_length, break_flag, last_chunk; 2587f8829a4aSRandall Stewart int abort_flag = 0, was_a_gap = 0; 2588f8829a4aSRandall Stewart struct mbuf *m; 2589f8829a4aSRandall Stewart 2590f8829a4aSRandall Stewart /* set the rwnd */ 2591f8829a4aSRandall Stewart sctp_set_rwnd(stcb, &stcb->asoc); 2592f8829a4aSRandall Stewart 2593f8829a4aSRandall Stewart m = *mm; 2594f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 2595f8829a4aSRandall Stewart asoc = &stcb->asoc; 2596f8829a4aSRandall Stewart if (compare_with_wrap(stcb->asoc.highest_tsn_inside_map, 2597f8829a4aSRandall Stewart stcb->asoc.cumulative_tsn, MAX_TSN)) { 2598f8829a4aSRandall Stewart /* there was a gap before this data was processed */ 2599f8829a4aSRandall Stewart was_a_gap = 1; 2600f8829a4aSRandall Stewart } 2601f8829a4aSRandall Stewart /* 2602f8829a4aSRandall Stewart * setup where we got the last DATA packet from for any SACK that 2603f8829a4aSRandall Stewart * may need to go out. Don't bump the net. This is done ONLY when a 2604f8829a4aSRandall Stewart * chunk is assigned. 2605f8829a4aSRandall Stewart */ 2606f8829a4aSRandall Stewart asoc->last_data_chunk_from = net; 2607f8829a4aSRandall Stewart 2608d06c82f1SRandall Stewart /*- 2609f8829a4aSRandall Stewart * Now before we proceed we must figure out if this is a wasted 2610f8829a4aSRandall Stewart * cluster... i.e. it is a small packet sent in and yet the driver 2611f8829a4aSRandall Stewart * underneath allocated a full cluster for it. If so we must copy it 2612f8829a4aSRandall Stewart * to a smaller mbuf and free up the cluster mbuf. This will help 2613d06c82f1SRandall Stewart * with cluster starvation. Note for __Panda__ we don't do this 2614d06c82f1SRandall Stewart * since it has clusters all the way down to 64 bytes. 2615f8829a4aSRandall Stewart */ 261644b7479bSRandall Stewart if (SCTP_BUF_LEN(m) < (long)MLEN && SCTP_BUF_NEXT(m) == NULL) { 2617f8829a4aSRandall Stewart /* we only handle mbufs that are singletons.. not chains */ 2618139bc87fSRandall Stewart m = sctp_get_mbuf_for_msg(SCTP_BUF_LEN(m), 0, M_DONTWAIT, 1, MT_DATA); 2619f8829a4aSRandall Stewart if (m) { 2620f8829a4aSRandall Stewart /* ok lets see if we can copy the data up */ 2621f8829a4aSRandall Stewart caddr_t *from, *to; 2622f8829a4aSRandall Stewart 2623f8829a4aSRandall Stewart /* get the pointers and copy */ 2624f8829a4aSRandall Stewart to = mtod(m, caddr_t *); 2625f8829a4aSRandall Stewart from = mtod((*mm), caddr_t *); 2626139bc87fSRandall Stewart memcpy(to, from, SCTP_BUF_LEN((*mm))); 2627f8829a4aSRandall Stewart /* copy the length and free up the old */ 2628139bc87fSRandall Stewart SCTP_BUF_LEN(m) = SCTP_BUF_LEN((*mm)); 2629f8829a4aSRandall Stewart sctp_m_freem(*mm); 2630f8829a4aSRandall Stewart /* sucess, back copy */ 2631f8829a4aSRandall Stewart *mm = m; 2632f8829a4aSRandall Stewart } else { 2633f8829a4aSRandall Stewart /* We are in trouble in the mbuf world .. yikes */ 2634f8829a4aSRandall Stewart m = *mm; 2635f8829a4aSRandall Stewart } 2636f8829a4aSRandall Stewart } 2637f8829a4aSRandall Stewart /* get pointer to the first chunk header */ 2638f8829a4aSRandall Stewart ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset, 2639f8829a4aSRandall Stewart sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); 2640f8829a4aSRandall Stewart if (ch == NULL) { 2641f8829a4aSRandall Stewart return (1); 2642f8829a4aSRandall Stewart } 2643f8829a4aSRandall Stewart /* 2644f8829a4aSRandall Stewart * process all DATA chunks... 2645f8829a4aSRandall Stewart */ 2646f8829a4aSRandall Stewart *high_tsn = asoc->cumulative_tsn; 2647f8829a4aSRandall Stewart break_flag = 0; 264842551e99SRandall Stewart asoc->data_pkts_seen++; 2649f8829a4aSRandall Stewart while (stop_proc == 0) { 2650f8829a4aSRandall Stewart /* validate chunk length */ 2651f8829a4aSRandall Stewart chk_length = ntohs(ch->ch.chunk_length); 2652f8829a4aSRandall Stewart if (length - *offset < chk_length) { 2653f8829a4aSRandall Stewart /* all done, mutulated chunk */ 2654f8829a4aSRandall Stewart stop_proc = 1; 2655f8829a4aSRandall Stewart break; 2656f8829a4aSRandall Stewart } 2657f8829a4aSRandall Stewart if (ch->ch.chunk_type == SCTP_DATA) { 2658f8829a4aSRandall Stewart if ((size_t)chk_length < sizeof(struct sctp_data_chunk) + 1) { 2659f8829a4aSRandall Stewart /* 2660f8829a4aSRandall Stewart * Need to send an abort since we had a 2661f8829a4aSRandall Stewart * invalid data chunk. 2662f8829a4aSRandall Stewart */ 2663f8829a4aSRandall Stewart struct mbuf *op_err; 2664f8829a4aSRandall Stewart 2665139bc87fSRandall Stewart op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 2 * sizeof(uint32_t)), 2666f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 2667f8829a4aSRandall Stewart 2668f8829a4aSRandall Stewart if (op_err) { 2669f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 2670f8829a4aSRandall Stewart uint32_t *ippp; 2671f8829a4aSRandall Stewart 2672139bc87fSRandall Stewart SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr) + 2673f8829a4aSRandall Stewart (2 * sizeof(uint32_t)); 2674f8829a4aSRandall Stewart ph = mtod(op_err, struct sctp_paramhdr *); 2675f8829a4aSRandall Stewart ph->param_type = 2676f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 2677139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(op_err)); 2678f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 2679a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_19); 2680f8829a4aSRandall Stewart ippp++; 2681f8829a4aSRandall Stewart *ippp = asoc->cumulative_tsn; 2682f8829a4aSRandall Stewart 2683f8829a4aSRandall Stewart } 2684a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_19; 2685f8829a4aSRandall Stewart sctp_abort_association(inp, stcb, m, iphlen, sh, 2686c54a18d2SRandall Stewart op_err, 0, net->port); 2687f8829a4aSRandall Stewart return (2); 2688f8829a4aSRandall Stewart } 2689f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 2690f8829a4aSRandall Stewart sctp_audit_log(0xB1, 0); 2691f8829a4aSRandall Stewart #endif 2692f8829a4aSRandall Stewart if (SCTP_SIZE32(chk_length) == (length - *offset)) { 2693f8829a4aSRandall Stewart last_chunk = 1; 2694f8829a4aSRandall Stewart } else { 2695f8829a4aSRandall Stewart last_chunk = 0; 2696f8829a4aSRandall Stewart } 2697f8829a4aSRandall Stewart if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset, ch, 2698f8829a4aSRandall Stewart chk_length, net, high_tsn, &abort_flag, &break_flag, 2699f8829a4aSRandall Stewart last_chunk)) { 2700f8829a4aSRandall Stewart num_chunks++; 2701f8829a4aSRandall Stewart } 2702f8829a4aSRandall Stewart if (abort_flag) 2703f8829a4aSRandall Stewart return (2); 2704f8829a4aSRandall Stewart 2705f8829a4aSRandall Stewart if (break_flag) { 2706f8829a4aSRandall Stewart /* 2707f8829a4aSRandall Stewart * Set because of out of rwnd space and no 2708f8829a4aSRandall Stewart * drop rep space left. 2709f8829a4aSRandall Stewart */ 2710f8829a4aSRandall Stewart stop_proc = 1; 2711f8829a4aSRandall Stewart break; 2712f8829a4aSRandall Stewart } 2713f8829a4aSRandall Stewart } else { 2714f8829a4aSRandall Stewart /* not a data chunk in the data region */ 2715f8829a4aSRandall Stewart switch (ch->ch.chunk_type) { 2716f8829a4aSRandall Stewart case SCTP_INITIATION: 2717f8829a4aSRandall Stewart case SCTP_INITIATION_ACK: 2718f8829a4aSRandall Stewart case SCTP_SELECTIVE_ACK: 2719830d754dSRandall Stewart case SCTP_NR_SELECTIVE_ACK: /* EY */ 2720f8829a4aSRandall Stewart case SCTP_HEARTBEAT_REQUEST: 2721f8829a4aSRandall Stewart case SCTP_HEARTBEAT_ACK: 2722f8829a4aSRandall Stewart case SCTP_ABORT_ASSOCIATION: 2723f8829a4aSRandall Stewart case SCTP_SHUTDOWN: 2724f8829a4aSRandall Stewart case SCTP_SHUTDOWN_ACK: 2725f8829a4aSRandall Stewart case SCTP_OPERATION_ERROR: 2726f8829a4aSRandall Stewart case SCTP_COOKIE_ECHO: 2727f8829a4aSRandall Stewart case SCTP_COOKIE_ACK: 2728f8829a4aSRandall Stewart case SCTP_ECN_ECHO: 2729f8829a4aSRandall Stewart case SCTP_ECN_CWR: 2730f8829a4aSRandall Stewart case SCTP_SHUTDOWN_COMPLETE: 2731f8829a4aSRandall Stewart case SCTP_AUTHENTICATION: 2732f8829a4aSRandall Stewart case SCTP_ASCONF_ACK: 2733f8829a4aSRandall Stewart case SCTP_PACKET_DROPPED: 2734f8829a4aSRandall Stewart case SCTP_STREAM_RESET: 2735f8829a4aSRandall Stewart case SCTP_FORWARD_CUM_TSN: 2736f8829a4aSRandall Stewart case SCTP_ASCONF: 2737f8829a4aSRandall Stewart /* 2738f8829a4aSRandall Stewart * Now, what do we do with KNOWN chunks that 2739f8829a4aSRandall Stewart * are NOT in the right place? 2740f8829a4aSRandall Stewart * 2741f8829a4aSRandall Stewart * For now, I do nothing but ignore them. We 2742f8829a4aSRandall Stewart * may later want to add sysctl stuff to 2743f8829a4aSRandall Stewart * switch out and do either an ABORT() or 2744f8829a4aSRandall Stewart * possibly process them. 2745f8829a4aSRandall Stewart */ 2746b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_data_order)) { 2747f8829a4aSRandall Stewart struct mbuf *op_err; 2748f8829a4aSRandall Stewart 2749f8829a4aSRandall Stewart op_err = sctp_generate_invmanparam(SCTP_CAUSE_PROTOCOL_VIOLATION); 2750c54a18d2SRandall Stewart sctp_abort_association(inp, stcb, m, iphlen, sh, op_err, 0, net->port); 2751f8829a4aSRandall Stewart return (2); 2752f8829a4aSRandall Stewart } 2753f8829a4aSRandall Stewart break; 2754f8829a4aSRandall Stewart default: 2755f8829a4aSRandall Stewart /* unknown chunk type, use bit rules */ 2756f8829a4aSRandall Stewart if (ch->ch.chunk_type & 0x40) { 2757f8829a4aSRandall Stewart /* Add a error report to the queue */ 2758d61a0ae0SRandall Stewart struct mbuf *merr; 2759f8829a4aSRandall Stewart struct sctp_paramhdr *phd; 2760f8829a4aSRandall Stewart 2761d61a0ae0SRandall Stewart merr = sctp_get_mbuf_for_msg(sizeof(*phd), 0, M_DONTWAIT, 1, MT_DATA); 2762d61a0ae0SRandall Stewart if (merr) { 2763d61a0ae0SRandall Stewart phd = mtod(merr, struct sctp_paramhdr *); 2764f8829a4aSRandall Stewart /* 2765f8829a4aSRandall Stewart * We cheat and use param 2766f8829a4aSRandall Stewart * type since we did not 2767f8829a4aSRandall Stewart * bother to define a error 2768f8829a4aSRandall Stewart * cause struct. They are 2769f8829a4aSRandall Stewart * the same basic format 2770f8829a4aSRandall Stewart * with different names. 2771f8829a4aSRandall Stewart */ 2772f8829a4aSRandall Stewart phd->param_type = 2773f8829a4aSRandall Stewart htons(SCTP_CAUSE_UNRECOG_CHUNK); 2774f8829a4aSRandall Stewart phd->param_length = 2775f8829a4aSRandall Stewart htons(chk_length + sizeof(*phd)); 2776d61a0ae0SRandall Stewart SCTP_BUF_LEN(merr) = sizeof(*phd); 2777d61a0ae0SRandall Stewart SCTP_BUF_NEXT(merr) = SCTP_M_COPYM(m, *offset, 2778f8829a4aSRandall Stewart SCTP_SIZE32(chk_length), 2779f8829a4aSRandall Stewart M_DONTWAIT); 2780d61a0ae0SRandall Stewart if (SCTP_BUF_NEXT(merr)) { 2781d61a0ae0SRandall Stewart sctp_queue_op_err(stcb, merr); 2782f8829a4aSRandall Stewart } else { 2783d61a0ae0SRandall Stewart sctp_m_freem(merr); 2784f8829a4aSRandall Stewart } 2785f8829a4aSRandall Stewart } 2786f8829a4aSRandall Stewart } 2787f8829a4aSRandall Stewart if ((ch->ch.chunk_type & 0x80) == 0) { 2788f8829a4aSRandall Stewart /* discard the rest of this packet */ 2789f8829a4aSRandall Stewart stop_proc = 1; 2790f8829a4aSRandall Stewart } /* else skip this bad chunk and 2791f8829a4aSRandall Stewart * continue... */ 2792f8829a4aSRandall Stewart break; 2793f8829a4aSRandall Stewart }; /* switch of chunk type */ 2794f8829a4aSRandall Stewart } 2795f8829a4aSRandall Stewart *offset += SCTP_SIZE32(chk_length); 2796f8829a4aSRandall Stewart if ((*offset >= length) || stop_proc) { 2797f8829a4aSRandall Stewart /* no more data left in the mbuf chain */ 2798f8829a4aSRandall Stewart stop_proc = 1; 2799f8829a4aSRandall Stewart continue; 2800f8829a4aSRandall Stewart } 2801f8829a4aSRandall Stewart ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset, 2802f8829a4aSRandall Stewart sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); 2803f8829a4aSRandall Stewart if (ch == NULL) { 2804f8829a4aSRandall Stewart *offset = length; 2805f8829a4aSRandall Stewart stop_proc = 1; 2806f8829a4aSRandall Stewart break; 2807f8829a4aSRandall Stewart 2808f8829a4aSRandall Stewart } 2809f8829a4aSRandall Stewart } /* while */ 2810f8829a4aSRandall Stewart if (break_flag) { 2811f8829a4aSRandall Stewart /* 2812f8829a4aSRandall Stewart * we need to report rwnd overrun drops. 2813f8829a4aSRandall Stewart */ 2814f8829a4aSRandall Stewart sctp_send_packet_dropped(stcb, net, *mm, iphlen, 0); 2815f8829a4aSRandall Stewart } 2816f8829a4aSRandall Stewart if (num_chunks) { 2817f8829a4aSRandall Stewart /* 2818ceaad40aSRandall Stewart * Did we get data, if so update the time for auto-close and 2819f8829a4aSRandall Stewart * give peer credit for being alive. 2820f8829a4aSRandall Stewart */ 2821f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvpktwithdata); 2822b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 2823c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 2824c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 2825c4739e2fSRandall Stewart 0, 2826c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 2827c4739e2fSRandall Stewart __LINE__); 2828c4739e2fSRandall Stewart } 2829f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 28306e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_last_rcvd); 2831f8829a4aSRandall Stewart } 2832f8829a4aSRandall Stewart /* now service all of the reassm queue if needed */ 2833f8829a4aSRandall Stewart if (!(TAILQ_EMPTY(&asoc->reasmqueue))) 2834f8829a4aSRandall Stewart sctp_service_queues(stcb, asoc); 2835f8829a4aSRandall Stewart 2836f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 283742551e99SRandall Stewart /* Assure that we ack right away */ 283842551e99SRandall Stewart stcb->asoc.send_sack = 1; 2839f8829a4aSRandall Stewart } 2840f8829a4aSRandall Stewart /* Start a sack timer or QUEUE a SACK for sending */ 2841b5c16493SMichael Tuexen sctp_sack_check(stcb, was_a_gap, &abort_flag); 2842f8829a4aSRandall Stewart if (abort_flag) 2843f8829a4aSRandall Stewart return (2); 2844f8829a4aSRandall Stewart 2845f8829a4aSRandall Stewart return (0); 2846f8829a4aSRandall Stewart } 2847f8829a4aSRandall Stewart 28480fa753b3SRandall Stewart static int 28490fa753b3SRandall Stewart sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1, uint32_t last_tsn, 28500fa753b3SRandall Stewart uint16_t frag_strt, uint16_t frag_end, int nr_sacking, 28510fa753b3SRandall Stewart int *num_frs, 28520fa753b3SRandall Stewart uint32_t * biggest_newly_acked_tsn, 28530fa753b3SRandall Stewart uint32_t * this_sack_lowest_newack, 28540fa753b3SRandall Stewart int *ecn_seg_sums) 28550fa753b3SRandall Stewart { 28560fa753b3SRandall Stewart struct sctp_tmit_chunk *tp1; 28570fa753b3SRandall Stewart unsigned int theTSN; 2858b5c16493SMichael Tuexen int j, wake_him = 0, circled = 0; 28590fa753b3SRandall Stewart 28600fa753b3SRandall Stewart /* Recover the tp1 we last saw */ 28610fa753b3SRandall Stewart tp1 = *p_tp1; 28620fa753b3SRandall Stewart if (tp1 == NULL) { 28630fa753b3SRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 28640fa753b3SRandall Stewart } 28650fa753b3SRandall Stewart for (j = frag_strt; j <= frag_end; j++) { 28660fa753b3SRandall Stewart theTSN = j + last_tsn; 28670fa753b3SRandall Stewart while (tp1) { 28680fa753b3SRandall Stewart if (tp1->rec.data.doing_fast_retransmit) 28690fa753b3SRandall Stewart (*num_frs) += 1; 28700fa753b3SRandall Stewart 28710fa753b3SRandall Stewart /*- 28720fa753b3SRandall Stewart * CMT: CUCv2 algorithm. For each TSN being 28730fa753b3SRandall Stewart * processed from the sent queue, track the 28740fa753b3SRandall Stewart * next expected pseudo-cumack, or 28750fa753b3SRandall Stewart * rtx_pseudo_cumack, if required. Separate 28760fa753b3SRandall Stewart * cumack trackers for first transmissions, 28770fa753b3SRandall Stewart * and retransmissions. 28780fa753b3SRandall Stewart */ 28790fa753b3SRandall Stewart if ((tp1->whoTo->find_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 28800fa753b3SRandall Stewart (tp1->snd_count == 1)) { 28810fa753b3SRandall Stewart tp1->whoTo->pseudo_cumack = tp1->rec.data.TSN_seq; 28820fa753b3SRandall Stewart tp1->whoTo->find_pseudo_cumack = 0; 28830fa753b3SRandall Stewart } 28840fa753b3SRandall Stewart if ((tp1->whoTo->find_rtx_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 28850fa753b3SRandall Stewart (tp1->snd_count > 1)) { 28860fa753b3SRandall Stewart tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.TSN_seq; 28870fa753b3SRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 0; 28880fa753b3SRandall Stewart } 28890fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == theTSN) { 28900fa753b3SRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 28910fa753b3SRandall Stewart /*- 28920fa753b3SRandall Stewart * must be held until 28930fa753b3SRandall Stewart * cum-ack passes 28940fa753b3SRandall Stewart */ 28950fa753b3SRandall Stewart /*- 28960fa753b3SRandall Stewart * ECN Nonce: Add the nonce 28970fa753b3SRandall Stewart * value to the sender's 28980fa753b3SRandall Stewart * nonce sum 28990fa753b3SRandall Stewart */ 29000fa753b3SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 29010fa753b3SRandall Stewart /*- 29020fa753b3SRandall Stewart * If it is less than RESEND, it is 29030fa753b3SRandall Stewart * now no-longer in flight. 29040fa753b3SRandall Stewart * Higher values may already be set 29050fa753b3SRandall Stewart * via previous Gap Ack Blocks... 29060fa753b3SRandall Stewart * i.e. ACKED or RESEND. 29070fa753b3SRandall Stewart */ 29080fa753b3SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 29090fa753b3SRandall Stewart *biggest_newly_acked_tsn, MAX_TSN)) { 29100fa753b3SRandall Stewart *biggest_newly_acked_tsn = tp1->rec.data.TSN_seq; 29110fa753b3SRandall Stewart } 29120fa753b3SRandall Stewart /*- 29130fa753b3SRandall Stewart * CMT: SFR algo (and HTNA) - set 29140fa753b3SRandall Stewart * saw_newack to 1 for dest being 29150fa753b3SRandall Stewart * newly acked. update 29160fa753b3SRandall Stewart * this_sack_highest_newack if 29170fa753b3SRandall Stewart * appropriate. 29180fa753b3SRandall Stewart */ 29190fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) 29200fa753b3SRandall Stewart tp1->whoTo->saw_newack = 1; 29210fa753b3SRandall Stewart 29220fa753b3SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 29230fa753b3SRandall Stewart tp1->whoTo->this_sack_highest_newack, 29240fa753b3SRandall Stewart MAX_TSN)) { 29250fa753b3SRandall Stewart tp1->whoTo->this_sack_highest_newack = 29260fa753b3SRandall Stewart tp1->rec.data.TSN_seq; 29270fa753b3SRandall Stewart } 29280fa753b3SRandall Stewart /*- 29290fa753b3SRandall Stewart * CMT DAC algo: also update 29300fa753b3SRandall Stewart * this_sack_lowest_newack 29310fa753b3SRandall Stewart */ 29320fa753b3SRandall Stewart if (*this_sack_lowest_newack == 0) { 29330fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 29340fa753b3SRandall Stewart sctp_log_sack(*this_sack_lowest_newack, 29350fa753b3SRandall Stewart last_tsn, 29360fa753b3SRandall Stewart tp1->rec.data.TSN_seq, 29370fa753b3SRandall Stewart 0, 29380fa753b3SRandall Stewart 0, 29390fa753b3SRandall Stewart SCTP_LOG_TSN_ACKED); 29400fa753b3SRandall Stewart } 29410fa753b3SRandall Stewart *this_sack_lowest_newack = tp1->rec.data.TSN_seq; 29420fa753b3SRandall Stewart } 29430fa753b3SRandall Stewart /*- 29440fa753b3SRandall Stewart * CMT: CUCv2 algorithm. If (rtx-)pseudo-cumack for corresp 29450fa753b3SRandall Stewart * dest is being acked, then we have a new (rtx-)pseudo-cumack. Set 29460fa753b3SRandall Stewart * new_(rtx_)pseudo_cumack to TRUE so that the cwnd for this dest can be 29470fa753b3SRandall Stewart * updated. Also trigger search for the next expected (rtx-)pseudo-cumack. 29480fa753b3SRandall Stewart * Separate pseudo_cumack trackers for first transmissions and 29490fa753b3SRandall Stewart * retransmissions. 29500fa753b3SRandall Stewart */ 29510fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->pseudo_cumack) { 29520fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 29530fa753b3SRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 29540fa753b3SRandall Stewart } 29550fa753b3SRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 29560fa753b3SRandall Stewart } 29570fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 29580fa753b3SRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 29590fa753b3SRandall Stewart } 29600fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->rtx_pseudo_cumack) { 29610fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 29620fa753b3SRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 29630fa753b3SRandall Stewart } 29640fa753b3SRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 29650fa753b3SRandall Stewart } 29660fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 29670fa753b3SRandall Stewart sctp_log_sack(*biggest_newly_acked_tsn, 29680fa753b3SRandall Stewart last_tsn, 29690fa753b3SRandall Stewart tp1->rec.data.TSN_seq, 29700fa753b3SRandall Stewart frag_strt, 29710fa753b3SRandall Stewart frag_end, 29720fa753b3SRandall Stewart SCTP_LOG_TSN_ACKED); 29730fa753b3SRandall Stewart } 29740fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 29750fa753b3SRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP, 29760fa753b3SRandall Stewart tp1->whoTo->flight_size, 29770fa753b3SRandall Stewart tp1->book_size, 29780fa753b3SRandall Stewart (uintptr_t) tp1->whoTo, 29790fa753b3SRandall Stewart tp1->rec.data.TSN_seq); 29800fa753b3SRandall Stewart } 29810fa753b3SRandall Stewart sctp_flight_size_decrease(tp1); 29820fa753b3SRandall Stewart sctp_total_flight_decrease(stcb, tp1); 29830fa753b3SRandall Stewart 29840fa753b3SRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 29850fa753b3SRandall Stewart if (tp1->snd_count < 2) { 29860fa753b3SRandall Stewart /*- 29870fa753b3SRandall Stewart * True non-retransmited chunk 29880fa753b3SRandall Stewart */ 29890fa753b3SRandall Stewart tp1->whoTo->net_ack2 += tp1->send_size; 29900fa753b3SRandall Stewart 29910fa753b3SRandall Stewart /*- 29920fa753b3SRandall Stewart * update RTO too ? 29930fa753b3SRandall Stewart */ 29940fa753b3SRandall Stewart if (tp1->do_rtt) { 29950fa753b3SRandall Stewart tp1->whoTo->RTO = 29960fa753b3SRandall Stewart sctp_calculate_rto(stcb, 29970fa753b3SRandall Stewart &stcb->asoc, 29980fa753b3SRandall Stewart tp1->whoTo, 29990fa753b3SRandall Stewart &tp1->sent_rcv_time, 30000fa753b3SRandall Stewart sctp_align_safe_nocopy); 30010fa753b3SRandall Stewart tp1->do_rtt = 0; 30020fa753b3SRandall Stewart } 30030fa753b3SRandall Stewart } 30040fa753b3SRandall Stewart } 30050fa753b3SRandall Stewart if (tp1->sent <= SCTP_DATAGRAM_RESEND) { 30060fa753b3SRandall Stewart (*ecn_seg_sums) += tp1->rec.data.ect_nonce; 30070fa753b3SRandall Stewart (*ecn_seg_sums) &= SCTP_SACK_NONCE_SUM; 30080fa753b3SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 30090fa753b3SRandall Stewart stcb->asoc.this_sack_highest_gap, 30100fa753b3SRandall Stewart MAX_TSN)) { 30110fa753b3SRandall Stewart stcb->asoc.this_sack_highest_gap = 30120fa753b3SRandall Stewart tp1->rec.data.TSN_seq; 30130fa753b3SRandall Stewart } 30140fa753b3SRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 30150fa753b3SRandall Stewart sctp_ucount_decr(stcb->asoc.sent_queue_retran_cnt); 30160fa753b3SRandall Stewart #ifdef SCTP_AUDITING_ENABLED 30170fa753b3SRandall Stewart sctp_audit_log(0xB2, 30180fa753b3SRandall Stewart (stcb->asoc.sent_queue_retran_cnt & 0x000000ff)); 30190fa753b3SRandall Stewart #endif 30200fa753b3SRandall Stewart } 30210fa753b3SRandall Stewart } 30220fa753b3SRandall Stewart /*- 30230fa753b3SRandall Stewart * All chunks NOT UNSENT fall through here and are marked 30240fa753b3SRandall Stewart * (leave PR-SCTP ones that are to skip alone though) 30250fa753b3SRandall Stewart */ 30260fa753b3SRandall Stewart if (tp1->sent != SCTP_FORWARD_TSN_SKIP) 30270fa753b3SRandall Stewart tp1->sent = SCTP_DATAGRAM_MARKED; 30280fa753b3SRandall Stewart 30290fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 30300fa753b3SRandall Stewart /* deflate the cwnd */ 30310fa753b3SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 30320fa753b3SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 30330fa753b3SRandall Stewart } 30340fa753b3SRandall Stewart /* NR Sack code here */ 30350fa753b3SRandall Stewart if (nr_sacking) { 30360fa753b3SRandall Stewart if (tp1->data) { 30370fa753b3SRandall Stewart /* 30380fa753b3SRandall Stewart * sa_ignore 30390fa753b3SRandall Stewart * NO_NULL_CHK 30400fa753b3SRandall Stewart */ 30410fa753b3SRandall Stewart sctp_free_bufspace(stcb, &stcb->asoc, tp1, 1); 30420fa753b3SRandall Stewart sctp_m_freem(tp1->data); 30430fa753b3SRandall Stewart tp1->data = NULL; 3044b5c16493SMichael Tuexen } 30450fa753b3SRandall Stewart wake_him++; 30460fa753b3SRandall Stewart } 30470fa753b3SRandall Stewart } 30480fa753b3SRandall Stewart break; 30490fa753b3SRandall Stewart } /* if (tp1->TSN_seq == theTSN) */ 30500fa753b3SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, theTSN, 30510fa753b3SRandall Stewart MAX_TSN)) 30520fa753b3SRandall Stewart break; 30530fa753b3SRandall Stewart 30540fa753b3SRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3055b5c16493SMichael Tuexen if ((tp1 == NULL) && (circled == 0)) { 3056b5c16493SMichael Tuexen circled++; 30570fa753b3SRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 30580fa753b3SRandall Stewart } 3059b5c16493SMichael Tuexen } /* end while (tp1) */ 3060b5c16493SMichael Tuexen if (tp1 == NULL) { 3061b5c16493SMichael Tuexen circled = 0; 3062b5c16493SMichael Tuexen tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 3063b5c16493SMichael Tuexen } 3064b5c16493SMichael Tuexen /* In case the fragments were not in order we must reset */ 30650fa753b3SRandall Stewart } /* end for (j = fragStart */ 30660fa753b3SRandall Stewart *p_tp1 = tp1; 30670fa753b3SRandall Stewart return (wake_him); /* Return value only used for nr-sack */ 30680fa753b3SRandall Stewart } 30690fa753b3SRandall Stewart 30700fa753b3SRandall Stewart 3071cd554309SMichael Tuexen static int 3072458303daSRandall Stewart sctp_handle_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct sctp_association *asoc, 3073cd554309SMichael Tuexen uint32_t last_tsn, uint32_t * biggest_tsn_acked, 3074139bc87fSRandall Stewart uint32_t * biggest_newly_acked_tsn, uint32_t * this_sack_lowest_newack, 3075cd554309SMichael Tuexen int num_seg, int num_nr_seg, int *ecn_seg_sums) 3076f8829a4aSRandall Stewart { 3077458303daSRandall Stewart struct sctp_gap_ack_block *frag, block; 3078f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 30790fa753b3SRandall Stewart int i; 3080f8829a4aSRandall Stewart int num_frs = 0; 3081cd554309SMichael Tuexen int chunk_freed; 3082cd554309SMichael Tuexen int non_revocable; 3083cd554309SMichael Tuexen uint16_t frag_strt, frag_end; 3084cd554309SMichael Tuexen uint32_t last_frag_high; 3085f8829a4aSRandall Stewart 3086cd554309SMichael Tuexen tp1 = NULL; 3087cd554309SMichael Tuexen last_frag_high = 0; 3088cd554309SMichael Tuexen chunk_freed = 0; 3089f8829a4aSRandall Stewart 3090cd554309SMichael Tuexen for (i = 0; i < (num_seg + num_nr_seg); i++) { 3091458303daSRandall Stewart frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, 3092458303daSRandall Stewart sizeof(struct sctp_gap_ack_block), (uint8_t *) & block); 3093458303daSRandall Stewart *offset += sizeof(block); 3094458303daSRandall Stewart if (frag == NULL) { 3095cd554309SMichael Tuexen return (chunk_freed); 3096458303daSRandall Stewart } 3097f8829a4aSRandall Stewart frag_strt = ntohs(frag->start); 3098f8829a4aSRandall Stewart frag_end = ntohs(frag->end); 3099830d754dSRandall Stewart /* some sanity checks on the fragment offsets */ 3100f8829a4aSRandall Stewart if (frag_strt > frag_end) { 3101f8829a4aSRandall Stewart /* this one is malformed, skip */ 3102f8829a4aSRandall Stewart continue; 3103f8829a4aSRandall Stewart } 3104f8829a4aSRandall Stewart if (compare_with_wrap((frag_end + last_tsn), *biggest_tsn_acked, 3105f8829a4aSRandall Stewart MAX_TSN)) 3106f8829a4aSRandall Stewart *biggest_tsn_acked = frag_end + last_tsn; 3107f8829a4aSRandall Stewart 3108f8829a4aSRandall Stewart /* mark acked dgs and find out the highestTSN being acked */ 3109f8829a4aSRandall Stewart if (tp1 == NULL) { 3110f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3111f8829a4aSRandall Stewart /* save the locations of the last frags */ 3112f8829a4aSRandall Stewart last_frag_high = frag_end + last_tsn; 3113f8829a4aSRandall Stewart } else { 3114f8829a4aSRandall Stewart /* 3115f8829a4aSRandall Stewart * now lets see if we need to reset the queue due to 3116f8829a4aSRandall Stewart * a out-of-order SACK fragment 3117f8829a4aSRandall Stewart */ 3118f8829a4aSRandall Stewart if (compare_with_wrap(frag_strt + last_tsn, 3119f8829a4aSRandall Stewart last_frag_high, MAX_TSN)) { 3120f8829a4aSRandall Stewart /* 3121f8829a4aSRandall Stewart * if the new frag starts after the last TSN 3122f8829a4aSRandall Stewart * frag covered, we are ok and this one is 3123f8829a4aSRandall Stewart * beyond the last one 3124f8829a4aSRandall Stewart */ 3125f8829a4aSRandall Stewart ; 3126f8829a4aSRandall Stewart } else { 3127f8829a4aSRandall Stewart /* 3128f8829a4aSRandall Stewart * ok, they have reset us, so we need to 3129f8829a4aSRandall Stewart * reset the queue this will cause extra 3130f8829a4aSRandall Stewart * hunting but hey, they chose the 3131f8829a4aSRandall Stewart * performance hit when they failed to order 3132830d754dSRandall Stewart * their gaps 3133f8829a4aSRandall Stewart */ 3134f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3135f8829a4aSRandall Stewart } 3136f8829a4aSRandall Stewart last_frag_high = frag_end + last_tsn; 3137f8829a4aSRandall Stewart } 3138cd554309SMichael Tuexen if (i < num_seg) { 3139cd554309SMichael Tuexen non_revocable = 0; 3140cd554309SMichael Tuexen } else { 3141cd554309SMichael Tuexen non_revocable = 1; 3142cd554309SMichael Tuexen } 3143b5c16493SMichael Tuexen if (i == num_seg) { 3144b5c16493SMichael Tuexen tp1 = NULL; 3145b5c16493SMichael Tuexen } 3146cd554309SMichael Tuexen if (sctp_process_segment_range(stcb, &tp1, last_tsn, frag_strt, frag_end, 3147cd554309SMichael Tuexen non_revocable, &num_frs, biggest_newly_acked_tsn, 3148cd554309SMichael Tuexen this_sack_lowest_newack, ecn_seg_sums)) { 3149cd554309SMichael Tuexen chunk_freed = 1; 3150458303daSRandall Stewart } 3151f8829a4aSRandall Stewart } 3152b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 315380fefe0aSRandall Stewart if (num_frs) 315480fefe0aSRandall Stewart sctp_log_fr(*biggest_tsn_acked, 315580fefe0aSRandall Stewart *biggest_newly_acked_tsn, 315680fefe0aSRandall Stewart last_tsn, SCTP_FR_LOG_BIGGEST_TSNS); 315780fefe0aSRandall Stewart } 3158cd554309SMichael Tuexen return (chunk_freed); 3159f8829a4aSRandall Stewart } 3160f8829a4aSRandall Stewart 3161f8829a4aSRandall Stewart static void 3162c105859eSRandall Stewart sctp_check_for_revoked(struct sctp_tcb *stcb, 3163c105859eSRandall Stewart struct sctp_association *asoc, uint32_t cumack, 316463eda93dSMichael Tuexen uint32_t biggest_tsn_acked) 3165f8829a4aSRandall Stewart { 3166f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3167f8829a4aSRandall Stewart int tot_revoked = 0; 3168f8829a4aSRandall Stewart 3169f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3170f8829a4aSRandall Stewart while (tp1) { 3171f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, cumack, 3172f8829a4aSRandall Stewart MAX_TSN)) { 3173f8829a4aSRandall Stewart /* 3174f8829a4aSRandall Stewart * ok this guy is either ACK or MARKED. If it is 3175f8829a4aSRandall Stewart * ACKED it has been previously acked but not this 3176f8829a4aSRandall Stewart * time i.e. revoked. If it is MARKED it was ACK'ed 3177f8829a4aSRandall Stewart * again. 3178f8829a4aSRandall Stewart */ 3179d06c82f1SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked, 3180d06c82f1SRandall Stewart MAX_TSN)) 3181d06c82f1SRandall Stewart break; 3182d06c82f1SRandall Stewart 3183d06c82f1SRandall Stewart 3184f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_ACKED) { 3185f8829a4aSRandall Stewart /* it has been revoked */ 3186f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 3187f8829a4aSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 3188a5d547adSRandall Stewart /* 318942551e99SRandall Stewart * We must add this stuff back in to assure 319042551e99SRandall Stewart * timers and such get started. 3191a5d547adSRandall Stewart */ 3192b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3193c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 3194c105859eSRandall Stewart tp1->whoTo->flight_size, 3195c105859eSRandall Stewart tp1->book_size, 3196c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3197c105859eSRandall Stewart tp1->rec.data.TSN_seq); 319880fefe0aSRandall Stewart } 3199c105859eSRandall Stewart sctp_flight_size_increase(tp1); 3200c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 320142551e99SRandall Stewart /* 320242551e99SRandall Stewart * We inflate the cwnd to compensate for our 320342551e99SRandall Stewart * artificial inflation of the flight_size. 320442551e99SRandall Stewart */ 320542551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 3206f8829a4aSRandall Stewart tot_revoked++; 3207b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 3208f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 3209f8829a4aSRandall Stewart cumack, 3210f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3211f8829a4aSRandall Stewart 0, 3212f8829a4aSRandall Stewart 0, 3213f8829a4aSRandall Stewart SCTP_LOG_TSN_REVOKED); 321480fefe0aSRandall Stewart } 3215f8829a4aSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_MARKED) { 3216f8829a4aSRandall Stewart /* it has been re-acked in this SACK */ 3217f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 3218f8829a4aSRandall Stewart } 3219f8829a4aSRandall Stewart } 3220f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) 3221f8829a4aSRandall Stewart break; 3222f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3223f8829a4aSRandall Stewart } 3224f8829a4aSRandall Stewart if (tot_revoked > 0) { 3225f8829a4aSRandall Stewart /* 3226f8829a4aSRandall Stewart * Setup the ecn nonce re-sync point. We do this since once 3227f8829a4aSRandall Stewart * data is revoked we begin to retransmit things, which do 3228f8829a4aSRandall Stewart * NOT have the ECN bits set. This means we are now out of 3229f8829a4aSRandall Stewart * sync and must wait until we get back in sync with the 3230f8829a4aSRandall Stewart * peer to check ECN bits. 3231f8829a4aSRandall Stewart */ 3232f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->send_queue); 3233f8829a4aSRandall Stewart if (tp1 == NULL) { 3234f8829a4aSRandall Stewart asoc->nonce_resync_tsn = asoc->sending_seq; 3235f8829a4aSRandall Stewart } else { 3236f8829a4aSRandall Stewart asoc->nonce_resync_tsn = tp1->rec.data.TSN_seq; 3237f8829a4aSRandall Stewart } 3238f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 0; 3239f8829a4aSRandall Stewart asoc->nonce_sum_check = 0; 3240f8829a4aSRandall Stewart } 3241f8829a4aSRandall Stewart } 3242f8829a4aSRandall Stewart 3243830d754dSRandall Stewart 3244f8829a4aSRandall Stewart static void 3245f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, 324663eda93dSMichael Tuexen uint32_t biggest_tsn_acked, uint32_t biggest_tsn_newly_acked, uint32_t this_sack_lowest_newack, int accum_moved) 3247f8829a4aSRandall Stewart { 3248f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3249f8829a4aSRandall Stewart int strike_flag = 0; 3250f8829a4aSRandall Stewart struct timeval now; 3251f8829a4aSRandall Stewart int tot_retrans = 0; 3252f8829a4aSRandall Stewart uint32_t sending_seq; 3253f8829a4aSRandall Stewart struct sctp_nets *net; 3254f8829a4aSRandall Stewart int num_dests_sacked = 0; 3255f8829a4aSRandall Stewart 3256f8829a4aSRandall Stewart /* 3257f8829a4aSRandall Stewart * select the sending_seq, this is either the next thing ready to be 3258f8829a4aSRandall Stewart * sent but not transmitted, OR, the next seq we assign. 3259f8829a4aSRandall Stewart */ 3260f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.send_queue); 3261f8829a4aSRandall Stewart if (tp1 == NULL) { 3262f8829a4aSRandall Stewart sending_seq = asoc->sending_seq; 3263f8829a4aSRandall Stewart } else { 3264f8829a4aSRandall Stewart sending_seq = tp1->rec.data.TSN_seq; 3265f8829a4aSRandall Stewart } 3266f8829a4aSRandall Stewart 3267f8829a4aSRandall Stewart /* CMT DAC algo: finding out if SACK is a mixed SACK */ 3268b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3269f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 3270f8829a4aSRandall Stewart if (net->saw_newack) 3271f8829a4aSRandall Stewart num_dests_sacked++; 3272f8829a4aSRandall Stewart } 3273f8829a4aSRandall Stewart } 3274f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_prsctp) { 32756e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 3276f8829a4aSRandall Stewart } 3277f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3278f8829a4aSRandall Stewart while (tp1) { 3279f8829a4aSRandall Stewart strike_flag = 0; 3280f8829a4aSRandall Stewart if (tp1->no_fr_allowed) { 3281f8829a4aSRandall Stewart /* this one had a timeout or something */ 3282f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3283f8829a4aSRandall Stewart continue; 3284f8829a4aSRandall Stewart } 3285b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3286f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) 3287f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3288f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3289f8829a4aSRandall Stewart tp1->sent, 3290f8829a4aSRandall Stewart SCTP_FR_LOG_CHECK_STRIKE); 329180fefe0aSRandall Stewart } 3292f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked, 3293f8829a4aSRandall Stewart MAX_TSN) || 3294f8829a4aSRandall Stewart tp1->sent == SCTP_DATAGRAM_UNSENT) { 3295f8829a4aSRandall Stewart /* done */ 3296f8829a4aSRandall Stewart break; 3297f8829a4aSRandall Stewart } 3298f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_prsctp) { 3299f8829a4aSRandall Stewart if ((PR_SCTP_TTL_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) { 3300f8829a4aSRandall Stewart /* Is it expired? */ 33015e54f665SRandall Stewart if ( 3302fc14de76SRandall Stewart /* 3303fc14de76SRandall Stewart * TODO sctp_constants.h needs alternative 3304fc14de76SRandall Stewart * time macros when _KERNEL is undefined. 3305fc14de76SRandall Stewart */ 33065e54f665SRandall Stewart (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) 33075e54f665SRandall Stewart ) { 3308f8829a4aSRandall Stewart /* Yes so drop it */ 3309f8829a4aSRandall Stewart if (tp1->data != NULL) { 3310ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3311f8829a4aSRandall Stewart (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 33120c0982b8SRandall Stewart SCTP_SO_NOT_LOCKED); 3313f8829a4aSRandall Stewart } 3314f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3315f8829a4aSRandall Stewart continue; 3316f8829a4aSRandall Stewart } 3317f8829a4aSRandall Stewart } 3318f8829a4aSRandall Stewart } 3319f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 3320f8829a4aSRandall Stewart asoc->this_sack_highest_gap, MAX_TSN)) { 3321f8829a4aSRandall Stewart /* we are beyond the tsn in the sack */ 3322f8829a4aSRandall Stewart break; 3323f8829a4aSRandall Stewart } 3324f8829a4aSRandall Stewart if (tp1->sent >= SCTP_DATAGRAM_RESEND) { 3325f8829a4aSRandall Stewart /* either a RESEND, ACKED, or MARKED */ 3326f8829a4aSRandall Stewart /* skip */ 3327*44fbe462SRandall Stewart if (tp1->sent == SCTP_FORWARD_TSN_SKIP) { 3328*44fbe462SRandall Stewart /* Continue strikin FWD-TSN chunks */ 3329*44fbe462SRandall Stewart tp1->rec.data.fwd_tsn_cnt++; 3330*44fbe462SRandall Stewart } 3331f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3332f8829a4aSRandall Stewart continue; 3333f8829a4aSRandall Stewart } 3334f8829a4aSRandall Stewart /* 3335f8829a4aSRandall Stewart * CMT : SFR algo (covers part of DAC and HTNA as well) 3336f8829a4aSRandall Stewart */ 3337ad81507eSRandall Stewart if (tp1->whoTo && tp1->whoTo->saw_newack == 0) { 3338f8829a4aSRandall Stewart /* 3339f8829a4aSRandall Stewart * No new acks were receieved for data sent to this 3340f8829a4aSRandall Stewart * dest. Therefore, according to the SFR algo for 3341f8829a4aSRandall Stewart * CMT, no data sent to this dest can be marked for 3342c105859eSRandall Stewart * FR using this SACK. 3343f8829a4aSRandall Stewart */ 3344f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3345f8829a4aSRandall Stewart continue; 3346ad81507eSRandall Stewart } else if (tp1->whoTo && compare_with_wrap(tp1->rec.data.TSN_seq, 3347f8829a4aSRandall Stewart tp1->whoTo->this_sack_highest_newack, MAX_TSN)) { 3348f8829a4aSRandall Stewart /* 3349f8829a4aSRandall Stewart * CMT: New acks were receieved for data sent to 3350f8829a4aSRandall Stewart * this dest. But no new acks were seen for data 3351f8829a4aSRandall Stewart * sent after tp1. Therefore, according to the SFR 3352f8829a4aSRandall Stewart * algo for CMT, tp1 cannot be marked for FR using 3353f8829a4aSRandall Stewart * this SACK. This step covers part of the DAC algo 3354f8829a4aSRandall Stewart * and the HTNA algo as well. 3355f8829a4aSRandall Stewart */ 3356f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3357f8829a4aSRandall Stewart continue; 3358f8829a4aSRandall Stewart } 3359f8829a4aSRandall Stewart /* 3360f8829a4aSRandall Stewart * Here we check to see if we were have already done a FR 3361f8829a4aSRandall Stewart * and if so we see if the biggest TSN we saw in the sack is 3362f8829a4aSRandall Stewart * smaller than the recovery point. If so we don't strike 3363f8829a4aSRandall Stewart * the tsn... otherwise we CAN strike the TSN. 3364f8829a4aSRandall Stewart */ 3365f8829a4aSRandall Stewart /* 336642551e99SRandall Stewart * @@@ JRI: Check for CMT if (accum_moved && 336742551e99SRandall Stewart * asoc->fast_retran_loss_recovery && (sctp_cmt_on_off == 336842551e99SRandall Stewart * 0)) { 3369f8829a4aSRandall Stewart */ 337042551e99SRandall Stewart if (accum_moved && asoc->fast_retran_loss_recovery) { 3371f8829a4aSRandall Stewart /* 3372f8829a4aSRandall Stewart * Strike the TSN if in fast-recovery and cum-ack 3373f8829a4aSRandall Stewart * moved. 3374f8829a4aSRandall Stewart */ 3375b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3376f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3377f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3378f8829a4aSRandall Stewart tp1->sent, 3379f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 338080fefe0aSRandall Stewart } 33815e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3382f8829a4aSRandall Stewart tp1->sent++; 33835e54f665SRandall Stewart } 3384b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3385f8829a4aSRandall Stewart /* 3386f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK flag is set to 3387f8829a4aSRandall Stewart * 0, then lowest_newack test will not pass 3388f8829a4aSRandall Stewart * because it would have been set to the 3389f8829a4aSRandall Stewart * cumack earlier. If not already to be 3390f8829a4aSRandall Stewart * rtx'd, If not a mixed sack and if tp1 is 3391f8829a4aSRandall Stewart * not between two sacked TSNs, then mark by 3392c105859eSRandall Stewart * one more. NOTE that we are marking by one 3393c105859eSRandall Stewart * additional time since the SACK DAC flag 3394c105859eSRandall Stewart * indicates that two packets have been 3395c105859eSRandall Stewart * received after this missing TSN. 33965e54f665SRandall Stewart */ 33975e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && 3398f8829a4aSRandall Stewart compare_with_wrap(this_sack_lowest_newack, tp1->rec.data.TSN_seq, MAX_TSN)) { 3399b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3400f8829a4aSRandall Stewart sctp_log_fr(16 + num_dests_sacked, 3401f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3402f8829a4aSRandall Stewart tp1->sent, 3403f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 340480fefe0aSRandall Stewart } 3405f8829a4aSRandall Stewart tp1->sent++; 3406f8829a4aSRandall Stewart } 3407f8829a4aSRandall Stewart } 3408b3f1ea41SRandall Stewart } else if ((tp1->rec.data.doing_fast_retransmit) && (SCTP_BASE_SYSCTL(sctp_cmt_on_off) == 0)) { 3409f8829a4aSRandall Stewart /* 3410f8829a4aSRandall Stewart * For those that have done a FR we must take 3411f8829a4aSRandall Stewart * special consideration if we strike. I.e the 3412f8829a4aSRandall Stewart * biggest_newly_acked must be higher than the 3413f8829a4aSRandall Stewart * sending_seq at the time we did the FR. 3414f8829a4aSRandall Stewart */ 34155e54f665SRandall Stewart if ( 3416f8829a4aSRandall Stewart #ifdef SCTP_FR_TO_ALTERNATE 3417f8829a4aSRandall Stewart /* 3418f8829a4aSRandall Stewart * If FR's go to new networks, then we must only do 3419f8829a4aSRandall Stewart * this for singly homed asoc's. However if the FR's 3420f8829a4aSRandall Stewart * go to the same network (Armando's work) then its 3421f8829a4aSRandall Stewart * ok to FR multiple times. 3422f8829a4aSRandall Stewart */ 34235e54f665SRandall Stewart (asoc->numnets < 2) 3424f8829a4aSRandall Stewart #else 34255e54f665SRandall Stewart (1) 3426f8829a4aSRandall Stewart #endif 34275e54f665SRandall Stewart ) { 34285e54f665SRandall Stewart 3429f8829a4aSRandall Stewart if ((compare_with_wrap(biggest_tsn_newly_acked, 3430f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn, MAX_TSN)) || 3431f8829a4aSRandall Stewart (biggest_tsn_newly_acked == 3432f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn)) { 3433f8829a4aSRandall Stewart /* 3434f8829a4aSRandall Stewart * Strike the TSN, since this ack is 3435f8829a4aSRandall Stewart * beyond where things were when we 3436f8829a4aSRandall Stewart * did a FR. 3437f8829a4aSRandall Stewart */ 3438b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3439f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3440f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3441f8829a4aSRandall Stewart tp1->sent, 3442f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 344380fefe0aSRandall Stewart } 34445e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3445f8829a4aSRandall Stewart tp1->sent++; 34465e54f665SRandall Stewart } 3447f8829a4aSRandall Stewart strike_flag = 1; 3448b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3449f8829a4aSRandall Stewart /* 3450f8829a4aSRandall Stewart * CMT DAC algorithm: If 3451f8829a4aSRandall Stewart * SACK flag is set to 0, 3452f8829a4aSRandall Stewart * then lowest_newack test 3453f8829a4aSRandall Stewart * will not pass because it 3454f8829a4aSRandall Stewart * would have been set to 3455f8829a4aSRandall Stewart * the cumack earlier. If 3456f8829a4aSRandall Stewart * not already to be rtx'd, 3457f8829a4aSRandall Stewart * If not a mixed sack and 3458f8829a4aSRandall Stewart * if tp1 is not between two 3459f8829a4aSRandall Stewart * sacked TSNs, then mark by 3460c105859eSRandall Stewart * one more. NOTE that we 3461c105859eSRandall Stewart * are marking by one 3462c105859eSRandall Stewart * additional time since the 3463c105859eSRandall Stewart * SACK DAC flag indicates 3464c105859eSRandall Stewart * that two packets have 3465c105859eSRandall Stewart * been received after this 3466c105859eSRandall Stewart * missing TSN. 3467f8829a4aSRandall Stewart */ 34685e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && 34695e54f665SRandall Stewart (num_dests_sacked == 1) && 34705e54f665SRandall Stewart compare_with_wrap(this_sack_lowest_newack, 34715e54f665SRandall Stewart tp1->rec.data.TSN_seq, MAX_TSN)) { 3472b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3473f8829a4aSRandall Stewart sctp_log_fr(32 + num_dests_sacked, 3474f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3475f8829a4aSRandall Stewart tp1->sent, 3476f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 347780fefe0aSRandall Stewart } 34785e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3479f8829a4aSRandall Stewart tp1->sent++; 34805e54f665SRandall Stewart } 3481f8829a4aSRandall Stewart } 3482f8829a4aSRandall Stewart } 3483f8829a4aSRandall Stewart } 3484f8829a4aSRandall Stewart } 3485f8829a4aSRandall Stewart /* 348642551e99SRandall Stewart * JRI: TODO: remove code for HTNA algo. CMT's SFR 348742551e99SRandall Stewart * algo covers HTNA. 3488f8829a4aSRandall Stewart */ 3489f8829a4aSRandall Stewart } else if (compare_with_wrap(tp1->rec.data.TSN_seq, 3490f8829a4aSRandall Stewart biggest_tsn_newly_acked, MAX_TSN)) { 3491f8829a4aSRandall Stewart /* 3492f8829a4aSRandall Stewart * We don't strike these: This is the HTNA 3493f8829a4aSRandall Stewart * algorithm i.e. we don't strike If our TSN is 3494f8829a4aSRandall Stewart * larger than the Highest TSN Newly Acked. 3495f8829a4aSRandall Stewart */ 3496f8829a4aSRandall Stewart ; 3497f8829a4aSRandall Stewart } else { 3498f8829a4aSRandall Stewart /* Strike the TSN */ 3499b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3500f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3501f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3502f8829a4aSRandall Stewart tp1->sent, 3503f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 350480fefe0aSRandall Stewart } 35055e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3506f8829a4aSRandall Stewart tp1->sent++; 35075e54f665SRandall Stewart } 3508b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3509f8829a4aSRandall Stewart /* 3510f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK flag is set to 3511f8829a4aSRandall Stewart * 0, then lowest_newack test will not pass 3512f8829a4aSRandall Stewart * because it would have been set to the 3513f8829a4aSRandall Stewart * cumack earlier. If not already to be 3514f8829a4aSRandall Stewart * rtx'd, If not a mixed sack and if tp1 is 3515f8829a4aSRandall Stewart * not between two sacked TSNs, then mark by 3516c105859eSRandall Stewart * one more. NOTE that we are marking by one 3517c105859eSRandall Stewart * additional time since the SACK DAC flag 3518c105859eSRandall Stewart * indicates that two packets have been 3519c105859eSRandall Stewart * received after this missing TSN. 3520f8829a4aSRandall Stewart */ 35215e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && 3522f8829a4aSRandall Stewart compare_with_wrap(this_sack_lowest_newack, tp1->rec.data.TSN_seq, MAX_TSN)) { 3523b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3524f8829a4aSRandall Stewart sctp_log_fr(48 + num_dests_sacked, 3525f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3526f8829a4aSRandall Stewart tp1->sent, 3527f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 352880fefe0aSRandall Stewart } 3529f8829a4aSRandall Stewart tp1->sent++; 3530f8829a4aSRandall Stewart } 3531f8829a4aSRandall Stewart } 3532f8829a4aSRandall Stewart } 3533f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 3534f8829a4aSRandall Stewart struct sctp_nets *alt; 3535f8829a4aSRandall Stewart 3536544e35bdSRandall Stewart /* fix counts and things */ 3537544e35bdSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3538544e35bdSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND, 3539544e35bdSRandall Stewart (tp1->whoTo ? (tp1->whoTo->flight_size) : 0), 3540544e35bdSRandall Stewart tp1->book_size, 3541544e35bdSRandall Stewart (uintptr_t) tp1->whoTo, 3542544e35bdSRandall Stewart tp1->rec.data.TSN_seq); 3543544e35bdSRandall Stewart } 3544544e35bdSRandall Stewart if (tp1->whoTo) { 3545544e35bdSRandall Stewart tp1->whoTo->net_ack++; 3546544e35bdSRandall Stewart sctp_flight_size_decrease(tp1); 3547544e35bdSRandall Stewart } 3548544e35bdSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 3549544e35bdSRandall Stewart sctp_log_rwnd(SCTP_INCREASE_PEER_RWND, 3550544e35bdSRandall Stewart asoc->peers_rwnd, tp1->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 3551544e35bdSRandall Stewart } 3552544e35bdSRandall Stewart /* add back to the rwnd */ 3553544e35bdSRandall Stewart asoc->peers_rwnd += (tp1->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 3554544e35bdSRandall Stewart 3555544e35bdSRandall Stewart /* remove from the total flight */ 3556544e35bdSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 3557544e35bdSRandall Stewart 3558475d0674SMichael Tuexen if ((stcb->asoc.peer_supports_prsctp) && 3559475d0674SMichael Tuexen (PR_SCTP_RTX_ENABLED(tp1->flags))) { 3560475d0674SMichael Tuexen /* 3561475d0674SMichael Tuexen * Has it been retransmitted tv_sec times? - 3562475d0674SMichael Tuexen * we store the retran count there. 3563475d0674SMichael Tuexen */ 3564475d0674SMichael Tuexen if (tp1->snd_count > tp1->rec.data.timetodrop.tv_sec) { 3565475d0674SMichael Tuexen /* Yes, so drop it */ 3566475d0674SMichael Tuexen if (tp1->data != NULL) { 3567475d0674SMichael Tuexen (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3568475d0674SMichael Tuexen (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 3569475d0674SMichael Tuexen SCTP_SO_NOT_LOCKED); 3570475d0674SMichael Tuexen } 3571475d0674SMichael Tuexen /* Make sure to flag we had a FR */ 3572475d0674SMichael Tuexen tp1->whoTo->net_ack++; 3573475d0674SMichael Tuexen tp1 = TAILQ_NEXT(tp1, sctp_next); 3574475d0674SMichael Tuexen continue; 3575475d0674SMichael Tuexen } 3576475d0674SMichael Tuexen } 3577f8829a4aSRandall Stewart /* printf("OK, we are now ready to FR this guy\n"); */ 3578b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3579f8829a4aSRandall Stewart sctp_log_fr(tp1->rec.data.TSN_seq, tp1->snd_count, 3580f8829a4aSRandall Stewart 0, SCTP_FR_MARKED); 358180fefe0aSRandall Stewart } 3582f8829a4aSRandall Stewart if (strike_flag) { 3583f8829a4aSRandall Stewart /* This is a subsequent FR */ 3584f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_sendmultfastretrans); 3585f8829a4aSRandall Stewart } 35865e54f665SRandall Stewart sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); 3587b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) { 3588f8829a4aSRandall Stewart /* 3589f8829a4aSRandall Stewart * CMT: Using RTX_SSTHRESH policy for CMT. 3590f8829a4aSRandall Stewart * If CMT is being used, then pick dest with 3591f8829a4aSRandall Stewart * largest ssthresh for any retransmission. 3592f8829a4aSRandall Stewart */ 3593f8829a4aSRandall Stewart tp1->no_fr_allowed = 1; 3594f8829a4aSRandall Stewart alt = tp1->whoTo; 35953c503c28SRandall Stewart /* sa_ignore NO_NULL_CHK */ 3596b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_pf)) { 3597b54d3a6cSRandall Stewart /* 3598b54d3a6cSRandall Stewart * JRS 5/18/07 - If CMT PF is on, 3599b54d3a6cSRandall Stewart * use the PF version of 3600b54d3a6cSRandall Stewart * find_alt_net() 3601b54d3a6cSRandall Stewart */ 3602b54d3a6cSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 2); 3603b54d3a6cSRandall Stewart } else { 3604b54d3a6cSRandall Stewart /* 3605b54d3a6cSRandall Stewart * JRS 5/18/07 - If only CMT is on, 3606b54d3a6cSRandall Stewart * use the CMT version of 3607b54d3a6cSRandall Stewart * find_alt_net() 3608b54d3a6cSRandall Stewart */ 360952be287eSRandall Stewart /* sa_ignore NO_NULL_CHK */ 3610f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 1); 3611b54d3a6cSRandall Stewart } 3612ad81507eSRandall Stewart if (alt == NULL) { 3613ad81507eSRandall Stewart alt = tp1->whoTo; 3614ad81507eSRandall Stewart } 3615f8829a4aSRandall Stewart /* 3616f8829a4aSRandall Stewart * CUCv2: If a different dest is picked for 3617f8829a4aSRandall Stewart * the retransmission, then new 3618f8829a4aSRandall Stewart * (rtx-)pseudo_cumack needs to be tracked 3619f8829a4aSRandall Stewart * for orig dest. Let CUCv2 track new (rtx-) 3620f8829a4aSRandall Stewart * pseudo-cumack always. 3621f8829a4aSRandall Stewart */ 3622ad81507eSRandall Stewart if (tp1->whoTo) { 3623f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 3624f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 3625ad81507eSRandall Stewart } 3626f8829a4aSRandall Stewart } else {/* CMT is OFF */ 3627f8829a4aSRandall Stewart 3628f8829a4aSRandall Stewart #ifdef SCTP_FR_TO_ALTERNATE 3629f8829a4aSRandall Stewart /* Can we find an alternate? */ 3630f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, tp1->whoTo, 0); 3631f8829a4aSRandall Stewart #else 3632f8829a4aSRandall Stewart /* 3633f8829a4aSRandall Stewart * default behavior is to NOT retransmit 3634f8829a4aSRandall Stewart * FR's to an alternate. Armando Caro's 3635f8829a4aSRandall Stewart * paper details why. 3636f8829a4aSRandall Stewart */ 3637f8829a4aSRandall Stewart alt = tp1->whoTo; 3638f8829a4aSRandall Stewart #endif 3639f8829a4aSRandall Stewart } 3640f8829a4aSRandall Stewart 3641f8829a4aSRandall Stewart tp1->rec.data.doing_fast_retransmit = 1; 3642f8829a4aSRandall Stewart tot_retrans++; 3643f8829a4aSRandall Stewart /* mark the sending seq for possible subsequent FR's */ 3644f8829a4aSRandall Stewart /* 3645f8829a4aSRandall Stewart * printf("Marking TSN for FR new value %x\n", 3646f8829a4aSRandall Stewart * (uint32_t)tpi->rec.data.TSN_seq); 3647f8829a4aSRandall Stewart */ 3648f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue)) { 3649f8829a4aSRandall Stewart /* 3650f8829a4aSRandall Stewart * If the queue of send is empty then its 3651f8829a4aSRandall Stewart * the next sequence number that will be 3652f8829a4aSRandall Stewart * assigned so we subtract one from this to 3653f8829a4aSRandall Stewart * get the one we last sent. 3654f8829a4aSRandall Stewart */ 3655f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = sending_seq; 3656f8829a4aSRandall Stewart } else { 3657f8829a4aSRandall Stewart /* 3658f8829a4aSRandall Stewart * If there are chunks on the send queue 3659f8829a4aSRandall Stewart * (unsent data that has made it from the 3660f8829a4aSRandall Stewart * stream queues but not out the door, we 3661f8829a4aSRandall Stewart * take the first one (which will have the 3662f8829a4aSRandall Stewart * lowest TSN) and subtract one to get the 3663f8829a4aSRandall Stewart * one we last sent. 3664f8829a4aSRandall Stewart */ 3665f8829a4aSRandall Stewart struct sctp_tmit_chunk *ttt; 3666f8829a4aSRandall Stewart 3667f8829a4aSRandall Stewart ttt = TAILQ_FIRST(&asoc->send_queue); 3668f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = 3669f8829a4aSRandall Stewart ttt->rec.data.TSN_seq; 3670f8829a4aSRandall Stewart } 3671f8829a4aSRandall Stewart 3672f8829a4aSRandall Stewart if (tp1->do_rtt) { 3673f8829a4aSRandall Stewart /* 3674f8829a4aSRandall Stewart * this guy had a RTO calculation pending on 3675f8829a4aSRandall Stewart * it, cancel it 3676f8829a4aSRandall Stewart */ 3677f8829a4aSRandall Stewart tp1->do_rtt = 0; 3678f8829a4aSRandall Stewart } 3679f8829a4aSRandall Stewart if (alt != tp1->whoTo) { 3680f8829a4aSRandall Stewart /* yes, there is an alternate. */ 3681f8829a4aSRandall Stewart sctp_free_remote_addr(tp1->whoTo); 36823c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 3683f8829a4aSRandall Stewart tp1->whoTo = alt; 3684f8829a4aSRandall Stewart atomic_add_int(&alt->ref_count, 1); 3685f8829a4aSRandall Stewart } 3686f8829a4aSRandall Stewart } 3687f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3688f8829a4aSRandall Stewart } /* while (tp1) */ 3689f8829a4aSRandall Stewart 3690f8829a4aSRandall Stewart if (tot_retrans > 0) { 3691f8829a4aSRandall Stewart /* 3692f8829a4aSRandall Stewart * Setup the ecn nonce re-sync point. We do this since once 3693f8829a4aSRandall Stewart * we go to FR something we introduce a Karn's rule scenario 3694f8829a4aSRandall Stewart * and won't know the totals for the ECN bits. 3695f8829a4aSRandall Stewart */ 3696f8829a4aSRandall Stewart asoc->nonce_resync_tsn = sending_seq; 3697f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 0; 3698f8829a4aSRandall Stewart asoc->nonce_sum_check = 0; 3699f8829a4aSRandall Stewart } 3700f8829a4aSRandall Stewart } 3701f8829a4aSRandall Stewart 3702f8829a4aSRandall Stewart struct sctp_tmit_chunk * 3703f8829a4aSRandall Stewart sctp_try_advance_peer_ack_point(struct sctp_tcb *stcb, 3704f8829a4aSRandall Stewart struct sctp_association *asoc) 3705f8829a4aSRandall Stewart { 3706f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2, *a_adv = NULL; 3707f8829a4aSRandall Stewart struct timeval now; 3708f8829a4aSRandall Stewart int now_filled = 0; 3709f8829a4aSRandall Stewart 3710f8829a4aSRandall Stewart if (asoc->peer_supports_prsctp == 0) { 3711f8829a4aSRandall Stewart return (NULL); 3712f8829a4aSRandall Stewart } 3713f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3714f8829a4aSRandall Stewart while (tp1) { 3715f8829a4aSRandall Stewart if (tp1->sent != SCTP_FORWARD_TSN_SKIP && 3716f8829a4aSRandall Stewart tp1->sent != SCTP_DATAGRAM_RESEND) { 3717f8829a4aSRandall Stewart /* no chance to advance, out of here */ 3718f8829a4aSRandall Stewart break; 3719f8829a4aSRandall Stewart } 37200c0982b8SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { 37210c0982b8SRandall Stewart if (tp1->sent == SCTP_FORWARD_TSN_SKIP) { 37220c0982b8SRandall Stewart sctp_misc_ints(SCTP_FWD_TSN_CHECK, 37230c0982b8SRandall Stewart asoc->advanced_peer_ack_point, 37240c0982b8SRandall Stewart tp1->rec.data.TSN_seq, 0, 0); 37250c0982b8SRandall Stewart } 37260c0982b8SRandall Stewart } 3727f8829a4aSRandall Stewart if (!PR_SCTP_ENABLED(tp1->flags)) { 3728f8829a4aSRandall Stewart /* 3729f8829a4aSRandall Stewart * We can't fwd-tsn past any that are reliable aka 3730f8829a4aSRandall Stewart * retransmitted until the asoc fails. 3731f8829a4aSRandall Stewart */ 3732f8829a4aSRandall Stewart break; 3733f8829a4aSRandall Stewart } 3734f8829a4aSRandall Stewart if (!now_filled) { 37356e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 3736f8829a4aSRandall Stewart now_filled = 1; 3737f8829a4aSRandall Stewart } 3738f8829a4aSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 3739f8829a4aSRandall Stewart /* 3740f8829a4aSRandall Stewart * now we got a chunk which is marked for another 3741f8829a4aSRandall Stewart * retransmission to a PR-stream but has run out its chances 3742f8829a4aSRandall Stewart * already maybe OR has been marked to skip now. Can we skip 3743f8829a4aSRandall Stewart * it if its a resend? 3744f8829a4aSRandall Stewart */ 3745f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND && 3746f8829a4aSRandall Stewart (PR_SCTP_TTL_ENABLED(tp1->flags))) { 3747f8829a4aSRandall Stewart /* 3748f8829a4aSRandall Stewart * Now is this one marked for resend and its time is 3749f8829a4aSRandall Stewart * now up? 3750f8829a4aSRandall Stewart */ 3751f8829a4aSRandall Stewart if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) { 3752f8829a4aSRandall Stewart /* Yes so drop it */ 3753f8829a4aSRandall Stewart if (tp1->data) { 3754ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3755f8829a4aSRandall Stewart (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 37560c0982b8SRandall Stewart SCTP_SO_NOT_LOCKED); 3757f8829a4aSRandall Stewart } 3758f8829a4aSRandall Stewart } else { 3759f8829a4aSRandall Stewart /* 3760f8829a4aSRandall Stewart * No, we are done when hit one for resend 3761f8829a4aSRandall Stewart * whos time as not expired. 3762f8829a4aSRandall Stewart */ 3763f8829a4aSRandall Stewart break; 3764f8829a4aSRandall Stewart } 3765f8829a4aSRandall Stewart } 3766f8829a4aSRandall Stewart /* 3767f8829a4aSRandall Stewart * Ok now if this chunk is marked to drop it we can clean up 3768f8829a4aSRandall Stewart * the chunk, advance our peer ack point and we can check 3769f8829a4aSRandall Stewart * the next chunk. 3770f8829a4aSRandall Stewart */ 3771*44fbe462SRandall Stewart if (tp1->sent == SCTP_FORWARD_TSN_SKIP) { 3772f8829a4aSRandall Stewart /* advance PeerAckPoint goes forward */ 37730c0982b8SRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, 37740c0982b8SRandall Stewart asoc->advanced_peer_ack_point, 37750c0982b8SRandall Stewart MAX_TSN)) { 37760c0982b8SRandall Stewart 3777f8829a4aSRandall Stewart asoc->advanced_peer_ack_point = tp1->rec.data.TSN_seq; 3778f8829a4aSRandall Stewart a_adv = tp1; 37790c0982b8SRandall Stewart } else if (tp1->rec.data.TSN_seq == asoc->advanced_peer_ack_point) { 37800c0982b8SRandall Stewart /* No update but we do save the chk */ 37810c0982b8SRandall Stewart a_adv = tp1; 37820c0982b8SRandall Stewart } 3783f8829a4aSRandall Stewart } else { 3784f8829a4aSRandall Stewart /* 3785f8829a4aSRandall Stewart * If it is still in RESEND we can advance no 3786f8829a4aSRandall Stewart * further 3787f8829a4aSRandall Stewart */ 3788f8829a4aSRandall Stewart break; 3789f8829a4aSRandall Stewart } 3790f8829a4aSRandall Stewart /* 3791f8829a4aSRandall Stewart * If we hit here we just dumped tp1, move to next tsn on 3792f8829a4aSRandall Stewart * sent queue. 3793f8829a4aSRandall Stewart */ 3794f8829a4aSRandall Stewart tp1 = tp2; 3795f8829a4aSRandall Stewart } 3796f8829a4aSRandall Stewart return (a_adv); 3797f8829a4aSRandall Stewart } 3798f8829a4aSRandall Stewart 37990c0982b8SRandall Stewart static int 3800c105859eSRandall Stewart sctp_fs_audit(struct sctp_association *asoc) 3801bff64a4dSRandall Stewart { 3802bff64a4dSRandall Stewart struct sctp_tmit_chunk *chk; 3803bff64a4dSRandall Stewart int inflight = 0, resend = 0, inbetween = 0, acked = 0, above = 0; 38040c0982b8SRandall Stewart int entry_flight, entry_cnt, ret; 38050c0982b8SRandall Stewart 38060c0982b8SRandall Stewart entry_flight = asoc->total_flight; 38070c0982b8SRandall Stewart entry_cnt = asoc->total_flight_count; 38080c0982b8SRandall Stewart ret = 0; 38090c0982b8SRandall Stewart 38100c0982b8SRandall Stewart if (asoc->pr_sctp_cnt >= asoc->sent_queue_cnt) 38110c0982b8SRandall Stewart return (0); 3812bff64a4dSRandall Stewart 3813bff64a4dSRandall Stewart TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { 3814bff64a4dSRandall Stewart if (chk->sent < SCTP_DATAGRAM_RESEND) { 38150c0982b8SRandall Stewart printf("Chk TSN:%u size:%d inflight cnt:%d\n", 38160c0982b8SRandall Stewart chk->rec.data.TSN_seq, 38170c0982b8SRandall Stewart chk->send_size, 38180c0982b8SRandall Stewart chk->snd_count 38190c0982b8SRandall Stewart ); 3820bff64a4dSRandall Stewart inflight++; 3821bff64a4dSRandall Stewart } else if (chk->sent == SCTP_DATAGRAM_RESEND) { 3822bff64a4dSRandall Stewart resend++; 3823bff64a4dSRandall Stewart } else if (chk->sent < SCTP_DATAGRAM_ACKED) { 3824bff64a4dSRandall Stewart inbetween++; 3825bff64a4dSRandall Stewart } else if (chk->sent > SCTP_DATAGRAM_ACKED) { 3826bff64a4dSRandall Stewart above++; 3827bff64a4dSRandall Stewart } else { 3828bff64a4dSRandall Stewart acked++; 3829bff64a4dSRandall Stewart } 3830bff64a4dSRandall Stewart } 3831f1f73e57SRandall Stewart 3832c105859eSRandall Stewart if ((inflight > 0) || (inbetween > 0)) { 3833f1f73e57SRandall Stewart #ifdef INVARIANTS 3834c105859eSRandall Stewart panic("Flight size-express incorrect? \n"); 3835f1f73e57SRandall Stewart #else 38360c0982b8SRandall Stewart printf("asoc->total_flight:%d cnt:%d\n", 38370c0982b8SRandall Stewart entry_flight, entry_cnt); 38380c0982b8SRandall Stewart 38390c0982b8SRandall Stewart SCTP_PRINTF("Flight size-express incorrect F:%d I:%d R:%d Ab:%d ACK:%d\n", 38400c0982b8SRandall Stewart inflight, inbetween, resend, above, acked); 38410c0982b8SRandall Stewart ret = 1; 3842f1f73e57SRandall Stewart #endif 3843bff64a4dSRandall Stewart } 38440c0982b8SRandall Stewart return (ret); 3845c105859eSRandall Stewart } 3846c105859eSRandall Stewart 3847c105859eSRandall Stewart 3848c105859eSRandall Stewart static void 3849c105859eSRandall Stewart sctp_window_probe_recovery(struct sctp_tcb *stcb, 3850c105859eSRandall Stewart struct sctp_association *asoc, 3851c105859eSRandall Stewart struct sctp_nets *net, 3852c105859eSRandall Stewart struct sctp_tmit_chunk *tp1) 3853c105859eSRandall Stewart { 3854dfb11ef8SRandall Stewart tp1->window_probe = 0; 38555171328bSRandall Stewart if ((tp1->sent >= SCTP_DATAGRAM_ACKED) || (tp1->data == NULL)) { 3856dfb11ef8SRandall Stewart /* TSN's skipped we do NOT move back. */ 3857dfb11ef8SRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DWN_WP_FWD, 3858dfb11ef8SRandall Stewart tp1->whoTo->flight_size, 3859dfb11ef8SRandall Stewart tp1->book_size, 3860dfb11ef8SRandall Stewart (uintptr_t) tp1->whoTo, 3861dfb11ef8SRandall Stewart tp1->rec.data.TSN_seq); 3862dfb11ef8SRandall Stewart return; 3863dfb11ef8SRandall Stewart } 38645171328bSRandall Stewart /* First setup this by shrinking flight */ 38655171328bSRandall Stewart sctp_flight_size_decrease(tp1); 38665171328bSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 38675171328bSRandall Stewart /* Now mark for resend */ 38685171328bSRandall Stewart tp1->sent = SCTP_DATAGRAM_RESEND; 3869791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 3870791437b5SRandall Stewart 3871b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3872c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_WP, 3873c105859eSRandall Stewart tp1->whoTo->flight_size, 3874c105859eSRandall Stewart tp1->book_size, 3875c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3876c105859eSRandall Stewart tp1->rec.data.TSN_seq); 387780fefe0aSRandall Stewart } 3878c105859eSRandall Stewart } 3879c105859eSRandall Stewart 3880f8829a4aSRandall Stewart void 3881f8829a4aSRandall Stewart sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, 3882f8829a4aSRandall Stewart uint32_t rwnd, int nonce_sum_flag, int *abort_now) 3883f8829a4aSRandall Stewart { 3884f8829a4aSRandall Stewart struct sctp_nets *net; 3885f8829a4aSRandall Stewart struct sctp_association *asoc; 3886f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 38875e54f665SRandall Stewart uint32_t old_rwnd; 38885e54f665SRandall Stewart int win_probe_recovery = 0; 3889c105859eSRandall Stewart int win_probe_recovered = 0; 3890d06c82f1SRandall Stewart int j, done_once = 0; 3891f8829a4aSRandall Stewart 3892b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 3893d06c82f1SRandall Stewart sctp_misc_ints(SCTP_SACK_LOG_EXPRESS, cumack, 3894d06c82f1SRandall Stewart rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 389580fefe0aSRandall Stewart } 3896f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 389718e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 389818e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cumack; 389918e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 390018e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 390118e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 390218e198d3SRandall Stewart } 390318e198d3SRandall Stewart #endif 3904f8829a4aSRandall Stewart asoc = &stcb->asoc; 3905d06c82f1SRandall Stewart old_rwnd = asoc->peers_rwnd; 39065e54f665SRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, cumack, MAX_TSN)) { 39075e54f665SRandall Stewart /* old ack */ 39085e54f665SRandall Stewart return; 3909d06c82f1SRandall Stewart } else if (asoc->last_acked_seq == cumack) { 3910d06c82f1SRandall Stewart /* Window update sack */ 3911d06c82f1SRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 3912*44fbe462SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 3913d06c82f1SRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 3914d06c82f1SRandall Stewart /* SWS sender side engages */ 3915d06c82f1SRandall Stewart asoc->peers_rwnd = 0; 3916d06c82f1SRandall Stewart } 3917d06c82f1SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 3918d06c82f1SRandall Stewart goto again; 3919d06c82f1SRandall Stewart } 3920d06c82f1SRandall Stewart return; 39215e54f665SRandall Stewart } 3922f8829a4aSRandall Stewart /* First setup for CC stuff */ 3923f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 3924f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 3925f8829a4aSRandall Stewart net->net_ack = 0; 3926f8829a4aSRandall Stewart net->net_ack2 = 0; 3927132dea7dSRandall Stewart 3928132dea7dSRandall Stewart /* 3929132dea7dSRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 3930132dea7dSRandall Stewart * SACK processing 3931132dea7dSRandall Stewart */ 3932132dea7dSRandall Stewart net->new_pseudo_cumack = 0; 3933132dea7dSRandall Stewart net->will_exit_fast_recovery = 0; 3934f8829a4aSRandall Stewart } 3935b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 3936139bc87fSRandall Stewart uint32_t send_s; 3937139bc87fSRandall Stewart 3938c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 3939c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 3940c105859eSRandall Stewart sctpchunk_listhead); 3941c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 3942139bc87fSRandall Stewart } else { 3943c105859eSRandall Stewart send_s = asoc->sending_seq; 3944139bc87fSRandall Stewart } 3945139bc87fSRandall Stewart if ((cumack == send_s) || 3946139bc87fSRandall Stewart compare_with_wrap(cumack, send_s, MAX_TSN)) { 3947c105859eSRandall Stewart #ifndef INVARIANTS 3948139bc87fSRandall Stewart struct mbuf *oper; 3949139bc87fSRandall Stewart 3950c105859eSRandall Stewart #endif 3951c105859eSRandall Stewart #ifdef INVARIANTS 3952c105859eSRandall Stewart panic("Impossible sack 1"); 3953c105859eSRandall Stewart #else 3954b5c16493SMichael Tuexen 3955139bc87fSRandall Stewart *abort_now = 1; 3956139bc87fSRandall Stewart /* XXX */ 3957139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 3958139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 3959139bc87fSRandall Stewart if (oper) { 3960139bc87fSRandall Stewart struct sctp_paramhdr *ph; 3961139bc87fSRandall Stewart uint32_t *ippp; 3962139bc87fSRandall Stewart 3963139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 3964139bc87fSRandall Stewart sizeof(uint32_t); 3965139bc87fSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 3966139bc87fSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 3967139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 3968139bc87fSRandall Stewart ippp = (uint32_t *) (ph + 1); 3969139bc87fSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 3970139bc87fSRandall Stewart } 3971139bc87fSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 3972ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 3973139bc87fSRandall Stewart return; 3974139bc87fSRandall Stewart #endif 3975139bc87fSRandall Stewart } 3976139bc87fSRandall Stewart } 3977f8829a4aSRandall Stewart asoc->this_sack_highest_gap = cumack; 3978b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 3979c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 3980c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 3981c4739e2fSRandall Stewart 0, 3982c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 3983c4739e2fSRandall Stewart __LINE__); 3984c4739e2fSRandall Stewart } 3985f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 39865e54f665SRandall Stewart if (compare_with_wrap(cumack, asoc->last_acked_seq, MAX_TSN)) { 3987f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 3988f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3989f8829a4aSRandall Stewart while (tp1) { 3990f8829a4aSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 3991f8829a4aSRandall Stewart if (compare_with_wrap(cumack, tp1->rec.data.TSN_seq, 3992f8829a4aSRandall Stewart MAX_TSN) || 3993f8829a4aSRandall Stewart cumack == tp1->rec.data.TSN_seq) { 399418e198d3SRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 399518e198d3SRandall Stewart printf("Warning, an unsent is now acked?\n"); 399618e198d3SRandall Stewart } 3997f8829a4aSRandall Stewart /* 399818e198d3SRandall Stewart * ECN Nonce: Add the nonce to the sender's 399918e198d3SRandall Stewart * nonce sum 4000f8829a4aSRandall Stewart */ 4001f8829a4aSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 4002f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 4003f8829a4aSRandall Stewart /* 400418e198d3SRandall Stewart * If it is less than ACKED, it is 400518e198d3SRandall Stewart * now no-longer in flight. Higher 400618e198d3SRandall Stewart * values may occur during marking 4007f8829a4aSRandall Stewart */ 4008c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4009b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4010c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 4011a5d547adSRandall Stewart tp1->whoTo->flight_size, 4012a5d547adSRandall Stewart tp1->book_size, 4013c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4014a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 401580fefe0aSRandall Stewart } 4016c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 401704ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4018c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 4019f8829a4aSRandall Stewart } 4020f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 4021f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 4022f8829a4aSRandall Stewart /* 402318e198d3SRandall Stewart * True non-retransmited 4024f8829a4aSRandall Stewart * chunk 4025f8829a4aSRandall Stewart */ 4026f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 4027f8829a4aSRandall Stewart tp1->send_size; 4028f8829a4aSRandall Stewart 4029f8829a4aSRandall Stewart /* update RTO too? */ 403062c1ff9cSRandall Stewart if (tp1->do_rtt) { 4031f8829a4aSRandall Stewart tp1->whoTo->RTO = 403204ee05e8SRandall Stewart /* 403304ee05e8SRandall Stewart * sa_ignore 403404ee05e8SRandall Stewart * NO_NULL_CHK 403504ee05e8SRandall Stewart */ 4036f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 4037f8829a4aSRandall Stewart asoc, tp1->whoTo, 403818e198d3SRandall Stewart &tp1->sent_rcv_time, 403918e198d3SRandall Stewart sctp_align_safe_nocopy); 4040f8829a4aSRandall Stewart tp1->do_rtt = 0; 4041f8829a4aSRandall Stewart } 4042f8829a4aSRandall Stewart } 4043132dea7dSRandall Stewart /* 404418e198d3SRandall Stewart * CMT: CUCv2 algorithm. From the 404518e198d3SRandall Stewart * cumack'd TSNs, for each TSN being 404618e198d3SRandall Stewart * acked for the first time, set the 404718e198d3SRandall Stewart * following variables for the 404818e198d3SRandall Stewart * corresp destination. 404918e198d3SRandall Stewart * new_pseudo_cumack will trigger a 405018e198d3SRandall Stewart * cwnd update. 405118e198d3SRandall Stewart * find_(rtx_)pseudo_cumack will 405218e198d3SRandall Stewart * trigger search for the next 405318e198d3SRandall Stewart * expected (rtx-)pseudo-cumack. 4054132dea7dSRandall Stewart */ 4055132dea7dSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 4056132dea7dSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 4057132dea7dSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 4058132dea7dSRandall Stewart 4059b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 406004ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4061f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 406280fefe0aSRandall Stewart } 4063f8829a4aSRandall Stewart } 4064f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4065f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 4066f8829a4aSRandall Stewart } 406742551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 406842551e99SRandall Stewart /* deflate the cwnd */ 406942551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 407042551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 407142551e99SRandall Stewart } 4072f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 4073f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 4074f8829a4aSRandall Stewart if (tp1->data) { 407504ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4076f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 4077f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 4078f8829a4aSRandall Stewart } 4079b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4080f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4081f8829a4aSRandall Stewart cumack, 4082f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4083f8829a4aSRandall Stewart 0, 4084f8829a4aSRandall Stewart 0, 4085f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 408680fefe0aSRandall Stewart } 4087f8829a4aSRandall Stewart tp1->data = NULL; 4088f8829a4aSRandall Stewart asoc->sent_queue_cnt--; 4089f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, tp1); 4090f8829a4aSRandall Stewart tp1 = tp2; 409118e198d3SRandall Stewart } else { 409218e198d3SRandall Stewart break; 4093f8829a4aSRandall Stewart } 40945e54f665SRandall Stewart } 409518e198d3SRandall Stewart 409618e198d3SRandall Stewart } 409704ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4098f8829a4aSRandall Stewart if (stcb->sctp_socket) { 4099ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4100ceaad40aSRandall Stewart struct socket *so; 4101ceaad40aSRandall Stewart 4102ceaad40aSRandall Stewart #endif 4103f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 4104b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 410504ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4106f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_WAKESND_FROM_SACK); 410780fefe0aSRandall Stewart } 4108ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4109ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 4110ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 4111ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 4112ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 4113ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 4114ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 4115ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 4116ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 4117ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4118ceaad40aSRandall Stewart return; 4119ceaad40aSRandall Stewart } 4120ceaad40aSRandall Stewart #endif 4121f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 4122ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4123ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4124ceaad40aSRandall Stewart #endif 4125f8829a4aSRandall Stewart } else { 4126b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4127f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_NOWAKE_FROM_SACK); 412880fefe0aSRandall Stewart } 4129f8829a4aSRandall Stewart } 4130f8829a4aSRandall Stewart 4131b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4132f8829a4aSRandall Stewart if (asoc->last_acked_seq != cumack) 4133b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, 1, 0, 0); 41345e54f665SRandall Stewart 4135f8829a4aSRandall Stewart asoc->last_acked_seq = cumack; 41365e54f665SRandall Stewart 4137f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 4138f8829a4aSRandall Stewart /* nothing left in-flight */ 4139f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4140f8829a4aSRandall Stewart net->flight_size = 0; 4141f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4142f8829a4aSRandall Stewart } 4143f8829a4aSRandall Stewart asoc->total_flight = 0; 4144f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4145f8829a4aSRandall Stewart } 4146f8829a4aSRandall Stewart /* ECN Nonce updates */ 4147f8829a4aSRandall Stewart if (asoc->ecn_nonce_allowed) { 4148f8829a4aSRandall Stewart if (asoc->nonce_sum_check) { 4149f8829a4aSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base) & SCTP_SACK_NONCE_SUM)) { 4150f8829a4aSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 4151f8829a4aSRandall Stewart struct sctp_tmit_chunk *lchk; 4152f8829a4aSRandall Stewart 4153f8829a4aSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 4154f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 1; 4155f8829a4aSRandall Stewart if (lchk) { 4156f8829a4aSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 4157f8829a4aSRandall Stewart } else { 4158f8829a4aSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 4159f8829a4aSRandall Stewart } 4160f8829a4aSRandall Stewart } else { 4161f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) || 4162f8829a4aSRandall Stewart (asoc->last_acked_seq == asoc->nonce_wait_tsn)) { 4163f8829a4aSRandall Stewart /* 4164f8829a4aSRandall Stewart * Misbehaving peer. We need 4165f8829a4aSRandall Stewart * to react to this guy 4166f8829a4aSRandall Stewart */ 4167f8829a4aSRandall Stewart asoc->ecn_allowed = 0; 4168f8829a4aSRandall Stewart asoc->ecn_nonce_allowed = 0; 4169f8829a4aSRandall Stewart } 4170f8829a4aSRandall Stewart } 4171f8829a4aSRandall Stewart } 4172f8829a4aSRandall Stewart } else { 4173f8829a4aSRandall Stewart /* See if Resynchronization Possible */ 4174f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) { 4175f8829a4aSRandall Stewart asoc->nonce_sum_check = 1; 4176f8829a4aSRandall Stewart /* 4177cd554309SMichael Tuexen * Now we must calculate what the base is. 4178f8829a4aSRandall Stewart * We do this based on two things, we know 4179f8829a4aSRandall Stewart * the total's for all the segments 4180cd554309SMichael Tuexen * gap-acked in the SACK (none). We also 4181f8829a4aSRandall Stewart * know the SACK's nonce sum, its in 4182f8829a4aSRandall Stewart * nonce_sum_flag. So we can build a truth 4183f8829a4aSRandall Stewart * table to back-calculate the new value of 4184f8829a4aSRandall Stewart * asoc->nonce_sum_expect_base: 4185f8829a4aSRandall Stewart * 4186f8829a4aSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 4187f8829a4aSRandall Stewart * 1 0 1 0 1 1 1 4188f8829a4aSRandall Stewart * 1 0 4189f8829a4aSRandall Stewart */ 4190f8829a4aSRandall Stewart asoc->nonce_sum_expect_base = (0 ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 4191f8829a4aSRandall Stewart } 4192f8829a4aSRandall Stewart } 4193f8829a4aSRandall Stewart } 4194f8829a4aSRandall Stewart /* RWND update */ 4195f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 4196*44fbe462SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 4197f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4198f8829a4aSRandall Stewart /* SWS sender side engages */ 4199f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4200f8829a4aSRandall Stewart } 42015e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 42025e54f665SRandall Stewart win_probe_recovery = 1; 42035e54f665SRandall Stewart } 4204f8829a4aSRandall Stewart /* Now assure a timer where data is queued at */ 4205a5d547adSRandall Stewart again: 4206a5d547adSRandall Stewart j = 0; 4207f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 42085171328bSRandall Stewart int to_ticks; 42095171328bSRandall Stewart 42105e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 4211c105859eSRandall Stewart win_probe_recovered = 1; 42125e54f665SRandall Stewart /* 42135e54f665SRandall Stewart * Find first chunk that was used with window probe 42145e54f665SRandall Stewart * and clear the sent 42155e54f665SRandall Stewart */ 42163c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 42175e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 42185e54f665SRandall Stewart if (tp1->window_probe) { 4219cd554309SMichael Tuexen /* move back to data send queue */ 4220c105859eSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 42215e54f665SRandall Stewart break; 42225e54f665SRandall Stewart } 42235e54f665SRandall Stewart } 42245e54f665SRandall Stewart } 4225f8829a4aSRandall Stewart if (net->RTO == 0) { 4226f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto); 4227f8829a4aSRandall Stewart } else { 4228f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(net->RTO); 4229f8829a4aSRandall Stewart } 42305171328bSRandall Stewart if (net->flight_size) { 4231a5d547adSRandall Stewart j++; 4232ad81507eSRandall Stewart (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 4233f8829a4aSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 42345171328bSRandall Stewart if (net->window_probe) { 42355171328bSRandall Stewart net->window_probe = 0; 42365171328bSRandall Stewart } 4237f8829a4aSRandall Stewart } else { 42385171328bSRandall Stewart if (net->window_probe) { 42395171328bSRandall Stewart /* 42405171328bSRandall Stewart * In window probes we must assure a timer 42415171328bSRandall Stewart * is still running there 42425171328bSRandall Stewart */ 42435171328bSRandall Stewart net->window_probe = 0; 42445171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 42455171328bSRandall Stewart SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 42465171328bSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 42475171328bSRandall Stewart } 42485171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 4249f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4250a5d547adSRandall Stewart stcb, net, 4251a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 4252f8829a4aSRandall Stewart } 4253b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4254139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4255f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 4256a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4257a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 4258f8829a4aSRandall Stewart } 4259f8829a4aSRandall Stewart } 4260f8829a4aSRandall Stewart } 4261f8829a4aSRandall Stewart } 4262bff64a4dSRandall Stewart if ((j == 0) && 4263bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 4264bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 4265c105859eSRandall Stewart (win_probe_recovered == 0) && 4266bff64a4dSRandall Stewart (done_once == 0)) { 42670c0982b8SRandall Stewart /* 42680c0982b8SRandall Stewart * huh, this should not happen unless all packets are 42690c0982b8SRandall Stewart * PR-SCTP and marked to skip of course. 42700c0982b8SRandall Stewart */ 42710c0982b8SRandall Stewart if (sctp_fs_audit(asoc)) { 4272a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4273a5d547adSRandall Stewart net->flight_size = 0; 4274a5d547adSRandall Stewart } 4275a5d547adSRandall Stewart asoc->total_flight = 0; 4276a5d547adSRandall Stewart asoc->total_flight_count = 0; 4277a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4278a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4279a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4280c105859eSRandall Stewart sctp_flight_size_increase(tp1); 4281c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 4282a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4283791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 4284a5d547adSRandall Stewart } 4285a5d547adSRandall Stewart } 42860c0982b8SRandall Stewart } 4287bff64a4dSRandall Stewart done_once = 1; 4288a5d547adSRandall Stewart goto again; 4289a5d547adSRandall Stewart } 4290f8829a4aSRandall Stewart /**********************************/ 4291f8829a4aSRandall Stewart /* Now what about shutdown issues */ 4292f8829a4aSRandall Stewart /**********************************/ 4293f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 4294f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 4295f8829a4aSRandall Stewart /* clean up */ 4296f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 4297f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 4298f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 4299f8829a4aSRandall Stewart (asoc->locked_on_sending) 4300f8829a4aSRandall Stewart ) { 4301f8829a4aSRandall Stewart struct sctp_stream_queue_pending *sp; 4302f8829a4aSRandall Stewart 4303f8829a4aSRandall Stewart /* 4304f8829a4aSRandall Stewart * I may be in a state where we got all across.. but 4305f8829a4aSRandall Stewart * cannot write more due to a shutdown... we abort 4306f8829a4aSRandall Stewart * since the user did not indicate EOR in this case. 4307f8829a4aSRandall Stewart * The sp will be cleaned during free of the asoc. 4308f8829a4aSRandall Stewart */ 4309f8829a4aSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 4310f8829a4aSRandall Stewart sctp_streamhead); 43112afb3e84SRandall Stewart if ((sp) && (sp->length == 0)) { 43122afb3e84SRandall Stewart /* Let cleanup code purge it */ 43132afb3e84SRandall Stewart if (sp->msg_is_complete) { 43142afb3e84SRandall Stewart asoc->stream_queue_cnt--; 43152afb3e84SRandall Stewart } else { 4316f8829a4aSRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 4317f8829a4aSRandall Stewart asoc->locked_on_sending = NULL; 4318f8829a4aSRandall Stewart asoc->stream_queue_cnt--; 4319f8829a4aSRandall Stewart } 4320f8829a4aSRandall Stewart } 43212afb3e84SRandall Stewart } 4322f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 4323f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4324f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4325f8829a4aSRandall Stewart /* Need to abort here */ 4326f8829a4aSRandall Stewart struct mbuf *oper; 4327f8829a4aSRandall Stewart 4328f8829a4aSRandall Stewart abort_out_now: 4329f8829a4aSRandall Stewart *abort_now = 1; 4330f8829a4aSRandall Stewart /* XXX */ 4331f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4332f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4333f8829a4aSRandall Stewart if (oper) { 4334f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 4335f8829a4aSRandall Stewart uint32_t *ippp; 4336f8829a4aSRandall Stewart 4337139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4338f8829a4aSRandall Stewart sizeof(uint32_t); 4339f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4340f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 4341139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4342f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 4343a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_24); 4344f8829a4aSRandall Stewart } 4345a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24; 4346ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 4347f8829a4aSRandall Stewart } else { 4348f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 4349f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 4350f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4351f42a358aSRandall Stewart } 4352c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 4353b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4354f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 4355f8829a4aSRandall Stewart sctp_send_shutdown(stcb, 4356f8829a4aSRandall Stewart stcb->asoc.primary_destination); 4357f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 4358f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4359f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 4360f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4361f8829a4aSRandall Stewart } 4362f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 4363f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4364f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4365f8829a4aSRandall Stewart goto abort_out_now; 4366f8829a4aSRandall Stewart } 4367f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4368c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 4369b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4370f8829a4aSRandall Stewart sctp_send_shutdown_ack(stcb, 4371f8829a4aSRandall Stewart stcb->asoc.primary_destination); 4372f8829a4aSRandall Stewart 4373f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 4374f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4375f8829a4aSRandall Stewart } 4376f8829a4aSRandall Stewart } 4377dfb11ef8SRandall Stewart /*********************************************/ 4378dfb11ef8SRandall Stewart /* Here we perform PR-SCTP procedures */ 4379dfb11ef8SRandall Stewart /* (section 4.2) */ 4380dfb11ef8SRandall Stewart /*********************************************/ 4381dfb11ef8SRandall Stewart /* C1. update advancedPeerAckPoint */ 4382dfb11ef8SRandall Stewart if (compare_with_wrap(cumack, asoc->advanced_peer_ack_point, MAX_TSN)) { 4383dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cumack; 4384dfb11ef8SRandall Stewart } 4385830d754dSRandall Stewart /* PR-Sctp issues need to be addressed too */ 4386830d754dSRandall Stewart if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) { 4387830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 4388830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 4389830d754dSRandall Stewart 4390830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 4391830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 4392830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 4393830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, cumack, 4394830d754dSRandall Stewart MAX_TSN)) { 4395830d754dSRandall Stewart /* 4396830d754dSRandall Stewart * ISSUE with ECN, see FWD-TSN processing for notes 4397830d754dSRandall Stewart * on issues that will occur when the ECN NONCE 4398830d754dSRandall Stewart * stuff is put into SCTP for cross checking. 4399830d754dSRandall Stewart */ 4400830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, old_adv_peer_ack_point, 4401830d754dSRandall Stewart MAX_TSN)) { 4402830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 4403830d754dSRandall Stewart /* 4404830d754dSRandall Stewart * ECN Nonce: Disable Nonce Sum check when 4405830d754dSRandall Stewart * FWD TSN is sent and store resync tsn 4406830d754dSRandall Stewart */ 4407830d754dSRandall Stewart asoc->nonce_sum_check = 0; 4408830d754dSRandall Stewart asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point; 44090c0982b8SRandall Stewart } else if (lchk) { 44100c0982b8SRandall Stewart /* try to FR fwd-tsn's that get lost too */ 4411*44fbe462SRandall Stewart if (lchk->rec.data.fwd_tsn_cnt >= 3) { 44120c0982b8SRandall Stewart send_forward_tsn(stcb, asoc); 44130c0982b8SRandall Stewart } 4414830d754dSRandall Stewart } 4415830d754dSRandall Stewart } 4416830d754dSRandall Stewart if (lchk) { 4417830d754dSRandall Stewart /* Assure a timer is up */ 4418830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 4419830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 4420830d754dSRandall Stewart } 4421830d754dSRandall Stewart } 4422b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 4423f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 4424f8829a4aSRandall Stewart rwnd, 4425f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 4426f8829a4aSRandall Stewart stcb->asoc.total_flight, 4427f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 442880fefe0aSRandall Stewart } 4429f8829a4aSRandall Stewart } 4430f8829a4aSRandall Stewart 4431f8829a4aSRandall Stewart void 4432cd554309SMichael Tuexen sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup, 4433cd554309SMichael Tuexen struct sctp_tcb *stcb, struct sctp_nets *net_from, 4434cd554309SMichael Tuexen uint16_t num_seg, uint16_t num_nr_seg, uint16_t num_dup, 4435cd554309SMichael Tuexen int *abort_now, uint8_t flags, 4436cd554309SMichael Tuexen uint32_t cum_ack, uint32_t rwnd) 4437f8829a4aSRandall Stewart { 4438f8829a4aSRandall Stewart struct sctp_association *asoc; 4439f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 4440cd554309SMichael Tuexen uint32_t last_tsn, biggest_tsn_acked, biggest_tsn_newly_acked, this_sack_lowest_newack; 4441bff64a4dSRandall Stewart uint32_t sav_cum_ack; 4442f8829a4aSRandall Stewart uint16_t wake_him = 0; 4443c105859eSRandall Stewart uint32_t send_s = 0; 4444f8829a4aSRandall Stewart long j; 4445f8829a4aSRandall Stewart int accum_moved = 0; 4446f8829a4aSRandall Stewart int will_exit_fast_recovery = 0; 44475e54f665SRandall Stewart uint32_t a_rwnd, old_rwnd; 44485e54f665SRandall Stewart int win_probe_recovery = 0; 4449c105859eSRandall Stewart int win_probe_recovered = 0; 4450f8829a4aSRandall Stewart struct sctp_nets *net = NULL; 4451f8829a4aSRandall Stewart int nonce_sum_flag, ecn_seg_sums = 0; 4452bff64a4dSRandall Stewart int done_once; 4453f8829a4aSRandall Stewart uint8_t reneged_all = 0; 4454f8829a4aSRandall Stewart uint8_t cmt_dac_flag; 4455f8829a4aSRandall Stewart 4456f8829a4aSRandall Stewart /* 4457f8829a4aSRandall Stewart * we take any chance we can to service our queues since we cannot 4458f8829a4aSRandall Stewart * get awoken when the socket is read from :< 4459f8829a4aSRandall Stewart */ 4460f8829a4aSRandall Stewart /* 4461f8829a4aSRandall Stewart * Now perform the actual SACK handling: 1) Verify that it is not an 4462f8829a4aSRandall Stewart * old sack, if so discard. 2) If there is nothing left in the send 4463f8829a4aSRandall Stewart * queue (cum-ack is equal to last acked) then you have a duplicate 4464f8829a4aSRandall Stewart * too, update any rwnd change and verify no timers are running. 4465f8829a4aSRandall Stewart * then return. 3) Process any new consequtive data i.e. cum-ack 4466f8829a4aSRandall Stewart * moved process these first and note that it moved. 4) Process any 4467f8829a4aSRandall Stewart * sack blocks. 5) Drop any acked from the queue. 6) Check for any 4468f8829a4aSRandall Stewart * revoked blocks and mark. 7) Update the cwnd. 8) Nothing left, 4469f8829a4aSRandall Stewart * sync up flightsizes and things, stop all timers and also check 4470f8829a4aSRandall Stewart * for shutdown_pending state. If so then go ahead and send off the 4471f8829a4aSRandall Stewart * shutdown. If in shutdown recv, send off the shutdown-ack and 4472f8829a4aSRandall Stewart * start that timer, Ret. 9) Strike any non-acked things and do FR 4473f8829a4aSRandall Stewart * procedure if needed being sure to set the FR flag. 10) Do pr-sctp 4474f8829a4aSRandall Stewart * procedures. 11) Apply any FR penalties. 12) Assure we will SACK 4475f8829a4aSRandall Stewart * if in shutdown_recv state. 4476f8829a4aSRandall Stewart */ 4477f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 4478f8829a4aSRandall Stewart /* CMT DAC algo */ 4479f8829a4aSRandall Stewart this_sack_lowest_newack = 0; 4480f8829a4aSRandall Stewart j = 0; 4481f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_slowpath_sack); 4482cd554309SMichael Tuexen last_tsn = cum_ack; 4483cd554309SMichael Tuexen nonce_sum_flag = flags & SCTP_SACK_NONCE_SUM; 4484cd554309SMichael Tuexen cmt_dac_flag = flags & SCTP_SACK_CMT_DAC; 448518e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 448618e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cum_ack; 448718e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 448818e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 448918e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 449018e198d3SRandall Stewart } 449118e198d3SRandall Stewart #endif 4492d06c82f1SRandall Stewart a_rwnd = rwnd; 4493f8829a4aSRandall Stewart 4494cd554309SMichael Tuexen if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 4495cd554309SMichael Tuexen sctp_misc_ints(SCTP_SACK_LOG_NORMAL, cum_ack, 4496cd554309SMichael Tuexen rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 4497cd554309SMichael Tuexen } 44985e54f665SRandall Stewart old_rwnd = stcb->asoc.peers_rwnd; 4499b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 4500c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 4501c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 4502c4739e2fSRandall Stewart 0, 4503c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 4504c4739e2fSRandall Stewart __LINE__); 4505c4739e2fSRandall Stewart } 4506f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 4507f8829a4aSRandall Stewart asoc = &stcb->asoc; 4508b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4509f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4510f8829a4aSRandall Stewart cum_ack, 4511f8829a4aSRandall Stewart 0, 4512f8829a4aSRandall Stewart num_seg, 4513f8829a4aSRandall Stewart num_dup, 4514f8829a4aSRandall Stewart SCTP_LOG_NEW_SACK); 451580fefe0aSRandall Stewart } 4516b3f1ea41SRandall Stewart if ((num_dup) && (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_FR_LOGGING_ENABLE | SCTP_EARLYFR_LOGGING_ENABLE))) { 4517cd554309SMichael Tuexen uint16_t i; 4518458303daSRandall Stewart uint32_t *dupdata, dblock; 4519f8829a4aSRandall Stewart 4520cd554309SMichael Tuexen for (i = 0; i < num_dup; i++) { 4521cd554309SMichael Tuexen dupdata = (uint32_t *) sctp_m_getptr(m, offset_dup + i * sizeof(uint32_t), 4522458303daSRandall Stewart sizeof(uint32_t), (uint8_t *) & dblock); 4523cd554309SMichael Tuexen if (dupdata == NULL) { 4524458303daSRandall Stewart break; 4525458303daSRandall Stewart } 4526cd554309SMichael Tuexen sctp_log_fr(*dupdata, 0, 0, SCTP_FR_DUPED); 4527f8829a4aSRandall Stewart } 4528f8829a4aSRandall Stewart } 4529b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 4530c105859eSRandall Stewart /* reality check */ 4531c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 4532c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 4533c105859eSRandall Stewart sctpchunk_listhead); 4534c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 4535c105859eSRandall Stewart } else { 4536b5c16493SMichael Tuexen tp1 = NULL; 4537c105859eSRandall Stewart send_s = asoc->sending_seq; 4538c105859eSRandall Stewart } 4539f8829a4aSRandall Stewart if (cum_ack == send_s || 4540f8829a4aSRandall Stewart compare_with_wrap(cum_ack, send_s, MAX_TSN)) { 4541c105859eSRandall Stewart struct mbuf *oper; 4542c105859eSRandall Stewart 4543f8829a4aSRandall Stewart /* 4544f8829a4aSRandall Stewart * no way, we have not even sent this TSN out yet. 4545f8829a4aSRandall Stewart * Peer is hopelessly messed up with us. 4546f8829a4aSRandall Stewart */ 4547b5c16493SMichael Tuexen printf("NEW cum_ack:%x send_s:%x is smaller or equal\n", 4548b5c16493SMichael Tuexen cum_ack, send_s); 4549b5c16493SMichael Tuexen if (tp1) { 4550b5c16493SMichael Tuexen printf("Got send_s from tsn:%x + 1 of tp1:%p\n", 4551b5c16493SMichael Tuexen tp1->rec.data.TSN_seq, tp1); 4552b5c16493SMichael Tuexen } 4553f8829a4aSRandall Stewart hopeless_peer: 4554f8829a4aSRandall Stewart *abort_now = 1; 4555f8829a4aSRandall Stewart /* XXX */ 4556f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4557f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4558f8829a4aSRandall Stewart if (oper) { 4559f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 4560f8829a4aSRandall Stewart uint32_t *ippp; 4561f8829a4aSRandall Stewart 4562139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4563f8829a4aSRandall Stewart sizeof(uint32_t); 4564f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4565f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 4566139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4567f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 4568a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 4569f8829a4aSRandall Stewart } 4570a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 4571ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 4572f8829a4aSRandall Stewart return; 4573f8829a4aSRandall Stewart } 4574f8829a4aSRandall Stewart } 4575f8829a4aSRandall Stewart /**********************/ 4576f8829a4aSRandall Stewart /* 1) check the range */ 4577f8829a4aSRandall Stewart /**********************/ 4578f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, last_tsn, MAX_TSN)) { 4579f8829a4aSRandall Stewart /* acking something behind */ 4580f8829a4aSRandall Stewart return; 4581f8829a4aSRandall Stewart } 4582bff64a4dSRandall Stewart sav_cum_ack = asoc->last_acked_seq; 4583bff64a4dSRandall Stewart 4584f8829a4aSRandall Stewart /* update the Rwnd of the peer */ 4585f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue) && 4586f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->send_queue) && 4587cd554309SMichael Tuexen (asoc->stream_queue_cnt == 0)) { 4588f8829a4aSRandall Stewart /* nothing left on send/sent and strmq */ 4589b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4590f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 4591f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 459280fefe0aSRandall Stewart } 4593f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 4594f8829a4aSRandall Stewart if (asoc->sent_queue_retran_cnt) { 4595f8829a4aSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4596f8829a4aSRandall Stewart } 4597f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4598f8829a4aSRandall Stewart /* SWS sender side engages */ 4599f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4600f8829a4aSRandall Stewart } 4601f8829a4aSRandall Stewart /* stop any timers */ 4602f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4603f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4604a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 4605b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4606139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4607f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck1); 4608a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4609a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 4610f8829a4aSRandall Stewart } 4611f8829a4aSRandall Stewart } 4612f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4613f8829a4aSRandall Stewart net->flight_size = 0; 4614f8829a4aSRandall Stewart } 4615f8829a4aSRandall Stewart asoc->total_flight = 0; 4616f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4617f8829a4aSRandall Stewart return; 4618f8829a4aSRandall Stewart } 4619f8829a4aSRandall Stewart /* 4620f8829a4aSRandall Stewart * We init netAckSz and netAckSz2 to 0. These are used to track 2 4621f8829a4aSRandall Stewart * things. The total byte count acked is tracked in netAckSz AND 4622f8829a4aSRandall Stewart * netAck2 is used to track the total bytes acked that are un- 4623f8829a4aSRandall Stewart * amibguious and were never retransmitted. We track these on a per 4624f8829a4aSRandall Stewart * destination address basis. 4625f8829a4aSRandall Stewart */ 4626f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4627f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 4628f8829a4aSRandall Stewart net->net_ack = 0; 4629f8829a4aSRandall Stewart net->net_ack2 = 0; 4630f8829a4aSRandall Stewart 4631f8829a4aSRandall Stewart /* 463242551e99SRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 463342551e99SRandall Stewart * SACK processing 4634f8829a4aSRandall Stewart */ 4635f8829a4aSRandall Stewart net->new_pseudo_cumack = 0; 4636f8829a4aSRandall Stewart net->will_exit_fast_recovery = 0; 4637f8829a4aSRandall Stewart } 4638f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 4639f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 4640f8829a4aSRandall Stewart while (tp1) { 4641f8829a4aSRandall Stewart if (compare_with_wrap(last_tsn, tp1->rec.data.TSN_seq, 4642f8829a4aSRandall Stewart MAX_TSN) || 4643f8829a4aSRandall Stewart last_tsn == tp1->rec.data.TSN_seq) { 4644f8829a4aSRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 4645f8829a4aSRandall Stewart /* 4646f8829a4aSRandall Stewart * ECN Nonce: Add the nonce to the sender's 4647f8829a4aSRandall Stewart * nonce sum 4648f8829a4aSRandall Stewart */ 4649f8829a4aSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 4650f8829a4aSRandall Stewart accum_moved = 1; 4651f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 4652f8829a4aSRandall Stewart /* 4653f8829a4aSRandall Stewart * If it is less than ACKED, it is 4654f8829a4aSRandall Stewart * now no-longer in flight. Higher 4655f8829a4aSRandall Stewart * values may occur during marking 4656f8829a4aSRandall Stewart */ 4657f8829a4aSRandall Stewart if ((tp1->whoTo->dest_state & 4658f8829a4aSRandall Stewart SCTP_ADDR_UNCONFIRMED) && 4659f8829a4aSRandall Stewart (tp1->snd_count < 2)) { 4660f8829a4aSRandall Stewart /* 4661f8829a4aSRandall Stewart * If there was no retran 4662f8829a4aSRandall Stewart * and the address is 4663f8829a4aSRandall Stewart * un-confirmed and we sent 4664f8829a4aSRandall Stewart * there and are now 4665f8829a4aSRandall Stewart * sacked.. its confirmed, 4666f8829a4aSRandall Stewart * mark it so. 4667f8829a4aSRandall Stewart */ 4668f8829a4aSRandall Stewart tp1->whoTo->dest_state &= 4669f8829a4aSRandall Stewart ~SCTP_ADDR_UNCONFIRMED; 4670f8829a4aSRandall Stewart } 4671c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4672b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4673c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 4674a5d547adSRandall Stewart tp1->whoTo->flight_size, 4675a5d547adSRandall Stewart tp1->book_size, 4676c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4677a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 467880fefe0aSRandall Stewart } 4679c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 4680c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 4681f8829a4aSRandall Stewart } 4682f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 4683f8829a4aSRandall Stewart 4684f8829a4aSRandall Stewart /* CMT SFR and DAC algos */ 4685f8829a4aSRandall Stewart this_sack_lowest_newack = tp1->rec.data.TSN_seq; 4686f8829a4aSRandall Stewart tp1->whoTo->saw_newack = 1; 4687f8829a4aSRandall Stewart 4688f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 4689f8829a4aSRandall Stewart /* 4690f8829a4aSRandall Stewart * True non-retransmited 4691f8829a4aSRandall Stewart * chunk 4692f8829a4aSRandall Stewart */ 4693f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 4694f8829a4aSRandall Stewart tp1->send_size; 4695f8829a4aSRandall Stewart 4696f8829a4aSRandall Stewart /* update RTO too? */ 4697f8829a4aSRandall Stewart if (tp1->do_rtt) { 4698f8829a4aSRandall Stewart tp1->whoTo->RTO = 4699f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 4700f8829a4aSRandall Stewart asoc, tp1->whoTo, 470118e198d3SRandall Stewart &tp1->sent_rcv_time, 470218e198d3SRandall Stewart sctp_align_safe_nocopy); 4703f8829a4aSRandall Stewart tp1->do_rtt = 0; 4704f8829a4aSRandall Stewart } 4705f8829a4aSRandall Stewart } 4706f8829a4aSRandall Stewart /* 4707f8829a4aSRandall Stewart * CMT: CUCv2 algorithm. From the 4708f8829a4aSRandall Stewart * cumack'd TSNs, for each TSN being 4709f8829a4aSRandall Stewart * acked for the first time, set the 4710f8829a4aSRandall Stewart * following variables for the 4711f8829a4aSRandall Stewart * corresp destination. 4712f8829a4aSRandall Stewart * new_pseudo_cumack will trigger a 4713f8829a4aSRandall Stewart * cwnd update. 4714f8829a4aSRandall Stewart * find_(rtx_)pseudo_cumack will 4715f8829a4aSRandall Stewart * trigger search for the next 4716f8829a4aSRandall Stewart * expected (rtx-)pseudo-cumack. 4717f8829a4aSRandall Stewart */ 4718f8829a4aSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 4719f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 4720f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 4721f8829a4aSRandall Stewart 4722f8829a4aSRandall Stewart 4723b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4724f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4725f8829a4aSRandall Stewart cum_ack, 4726f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4727f8829a4aSRandall Stewart 0, 4728f8829a4aSRandall Stewart 0, 4729f8829a4aSRandall Stewart SCTP_LOG_TSN_ACKED); 473080fefe0aSRandall Stewart } 4731b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 4732f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 473380fefe0aSRandall Stewart } 4734f8829a4aSRandall Stewart } 4735f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4736f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 4737f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 4738f8829a4aSRandall Stewart sctp_audit_log(0xB3, 4739f8829a4aSRandall Stewart (asoc->sent_queue_retran_cnt & 0x000000ff)); 4740f8829a4aSRandall Stewart #endif 4741f8829a4aSRandall Stewart } 474242551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 474342551e99SRandall Stewart /* deflate the cwnd */ 474442551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 474542551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 474642551e99SRandall Stewart } 4747f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 4748f8829a4aSRandall Stewart } 4749f8829a4aSRandall Stewart } else { 4750f8829a4aSRandall Stewart break; 4751f8829a4aSRandall Stewart } 4752f8829a4aSRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 4753f8829a4aSRandall Stewart } 4754f8829a4aSRandall Stewart biggest_tsn_newly_acked = biggest_tsn_acked = last_tsn; 4755f8829a4aSRandall Stewart /* always set this up to cum-ack */ 4756f8829a4aSRandall Stewart asoc->this_sack_highest_gap = last_tsn; 4757f8829a4aSRandall Stewart 4758cd554309SMichael Tuexen if ((num_seg > 0) || (num_nr_seg > 0)) { 4759f8829a4aSRandall Stewart 4760f8829a4aSRandall Stewart /* 4761f8829a4aSRandall Stewart * CMT: SFR algo (and HTNA) - this_sack_highest_newack has 4762f8829a4aSRandall Stewart * to be greater than the cumack. Also reset saw_newack to 0 4763f8829a4aSRandall Stewart * for all dests. 4764f8829a4aSRandall Stewart */ 4765f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4766f8829a4aSRandall Stewart net->saw_newack = 0; 4767f8829a4aSRandall Stewart net->this_sack_highest_newack = last_tsn; 4768f8829a4aSRandall Stewart } 4769f8829a4aSRandall Stewart 4770f8829a4aSRandall Stewart /* 4771f8829a4aSRandall Stewart * thisSackHighestGap will increase while handling NEW 4772f8829a4aSRandall Stewart * segments this_sack_highest_newack will increase while 4773f8829a4aSRandall Stewart * handling NEWLY ACKED chunks. this_sack_lowest_newack is 4774f8829a4aSRandall Stewart * used for CMT DAC algo. saw_newack will also change. 4775f8829a4aSRandall Stewart */ 4776cd554309SMichael Tuexen if (sctp_handle_segments(m, &offset_seg, stcb, asoc, last_tsn, &biggest_tsn_acked, 4777cd554309SMichael Tuexen &biggest_tsn_newly_acked, &this_sack_lowest_newack, 4778cd554309SMichael Tuexen num_seg, num_nr_seg, &ecn_seg_sums)) { 4779cd554309SMichael Tuexen wake_him++; 4780cd554309SMichael Tuexen } 4781b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 4782f8829a4aSRandall Stewart /* 4783f8829a4aSRandall Stewart * validate the biggest_tsn_acked in the gap acks if 4784f8829a4aSRandall Stewart * strict adherence is wanted. 4785f8829a4aSRandall Stewart */ 4786f8829a4aSRandall Stewart if ((biggest_tsn_acked == send_s) || 4787f8829a4aSRandall Stewart (compare_with_wrap(biggest_tsn_acked, send_s, MAX_TSN))) { 4788f8829a4aSRandall Stewart /* 4789f8829a4aSRandall Stewart * peer is either confused or we are under 4790f8829a4aSRandall Stewart * attack. We must abort. 4791f8829a4aSRandall Stewart */ 4792b5c16493SMichael Tuexen printf("Hopeless peer! biggest_tsn_acked:%x largest seq:%x\n", 4793b5c16493SMichael Tuexen biggest_tsn_acked, 4794b5c16493SMichael Tuexen send_s); 4795b5c16493SMichael Tuexen 4796f8829a4aSRandall Stewart goto hopeless_peer; 4797f8829a4aSRandall Stewart } 4798f8829a4aSRandall Stewart } 4799f8829a4aSRandall Stewart } 4800f8829a4aSRandall Stewart /*******************************************/ 4801f8829a4aSRandall Stewart /* cancel ALL T3-send timer if accum moved */ 4802f8829a4aSRandall Stewart /*******************************************/ 4803b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) { 4804f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4805f8829a4aSRandall Stewart if (net->new_pseudo_cumack) 4806f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4807a5d547adSRandall Stewart stcb, net, 4808a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_27); 4809f8829a4aSRandall Stewart 4810f8829a4aSRandall Stewart } 4811f8829a4aSRandall Stewart } else { 4812f8829a4aSRandall Stewart if (accum_moved) { 4813f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4814f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4815a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_28); 4816f8829a4aSRandall Stewart } 4817f8829a4aSRandall Stewart } 4818f8829a4aSRandall Stewart } 4819f8829a4aSRandall Stewart /********************************************/ 4820f8829a4aSRandall Stewart /* drop the acked chunks from the sendqueue */ 4821f8829a4aSRandall Stewart /********************************************/ 4822f8829a4aSRandall Stewart asoc->last_acked_seq = cum_ack; 4823f8829a4aSRandall Stewart 4824f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 4825f8829a4aSRandall Stewart if (tp1 == NULL) 4826f8829a4aSRandall Stewart goto done_with_it; 4827f8829a4aSRandall Stewart do { 4828f8829a4aSRandall Stewart if (compare_with_wrap(tp1->rec.data.TSN_seq, cum_ack, 4829f8829a4aSRandall Stewart MAX_TSN)) { 4830f8829a4aSRandall Stewart break; 4831f8829a4aSRandall Stewart } 4832f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 4833f8829a4aSRandall Stewart /* no more sent on list */ 483418e198d3SRandall Stewart printf("Warning, tp1->sent == %d and its now acked?\n", 483518e198d3SRandall Stewart tp1->sent); 4836f8829a4aSRandall Stewart } 4837f8829a4aSRandall Stewart tp2 = TAILQ_NEXT(tp1, sctp_next); 4838f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 4839f8829a4aSRandall Stewart if (tp1->pr_sctp_on) { 4840f8829a4aSRandall Stewart if (asoc->pr_sctp_cnt != 0) 4841f8829a4aSRandall Stewart asoc->pr_sctp_cnt--; 4842f8829a4aSRandall Stewart } 4843f8829a4aSRandall Stewart if ((TAILQ_FIRST(&asoc->sent_queue) == NULL) && 4844f8829a4aSRandall Stewart (asoc->total_flight > 0)) { 4845f1f73e57SRandall Stewart #ifdef INVARIANTS 4846c105859eSRandall Stewart panic("Warning flight size is postive and should be 0"); 4847f1f73e57SRandall Stewart #else 4848ad81507eSRandall Stewart SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n", 4849f8829a4aSRandall Stewart asoc->total_flight); 4850f1f73e57SRandall Stewart #endif 4851f8829a4aSRandall Stewart asoc->total_flight = 0; 4852f8829a4aSRandall Stewart } 4853f8829a4aSRandall Stewart if (tp1->data) { 485404ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4855f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 4856f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 4857810ec536SMichael Tuexen if (asoc->peer_supports_prsctp && PR_SCTP_BUF_ENABLED(tp1->flags)) { 4858f8829a4aSRandall Stewart asoc->sent_queue_cnt_removeable--; 4859f8829a4aSRandall Stewart } 4860f8829a4aSRandall Stewart } 4861b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4862f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4863f8829a4aSRandall Stewart cum_ack, 4864f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4865f8829a4aSRandall Stewart 0, 4866f8829a4aSRandall Stewart 0, 4867f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 486880fefe0aSRandall Stewart } 4869f8829a4aSRandall Stewart tp1->data = NULL; 4870f8829a4aSRandall Stewart asoc->sent_queue_cnt--; 4871f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, tp1); 4872f8829a4aSRandall Stewart wake_him++; 4873f8829a4aSRandall Stewart tp1 = tp2; 4874f8829a4aSRandall Stewart } while (tp1 != NULL); 4875f8829a4aSRandall Stewart 4876f8829a4aSRandall Stewart done_with_it: 487704ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4878f8829a4aSRandall Stewart if ((wake_him) && (stcb->sctp_socket)) { 4879ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4880ceaad40aSRandall Stewart struct socket *so; 4881ceaad40aSRandall Stewart 4882ceaad40aSRandall Stewart #endif 4883f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 4884b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4885f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_WAKESND_FROM_SACK); 488680fefe0aSRandall Stewart } 4887ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4888ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 4889ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 4890ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 4891ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 4892ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 4893ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 4894ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 4895ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 4896ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4897ceaad40aSRandall Stewart return; 4898ceaad40aSRandall Stewart } 4899ceaad40aSRandall Stewart #endif 4900f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 4901ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4902ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4903ceaad40aSRandall Stewart #endif 4904f8829a4aSRandall Stewart } else { 4905b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4906f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_NOWAKE_FROM_SACK); 490780fefe0aSRandall Stewart } 4908f8829a4aSRandall Stewart } 4909f8829a4aSRandall Stewart 491042551e99SRandall Stewart if (asoc->fast_retran_loss_recovery && accum_moved) { 4911f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, 4912f8829a4aSRandall Stewart asoc->fast_recovery_tsn, MAX_TSN) || 4913f8829a4aSRandall Stewart asoc->last_acked_seq == asoc->fast_recovery_tsn) { 4914f8829a4aSRandall Stewart /* Setup so we will exit RFC2582 fast recovery */ 4915f8829a4aSRandall Stewart will_exit_fast_recovery = 1; 4916f8829a4aSRandall Stewart } 4917f8829a4aSRandall Stewart } 4918f8829a4aSRandall Stewart /* 4919f8829a4aSRandall Stewart * Check for revoked fragments: 4920f8829a4aSRandall Stewart * 4921f8829a4aSRandall Stewart * if Previous sack - Had no frags then we can't have any revoked if 4922f8829a4aSRandall Stewart * Previous sack - Had frag's then - If we now have frags aka 4923f8829a4aSRandall Stewart * num_seg > 0 call sctp_check_for_revoked() to tell if peer revoked 4924f8829a4aSRandall Stewart * some of them. else - The peer revoked all ACKED fragments, since 4925f8829a4aSRandall Stewart * we had some before and now we have NONE. 4926f8829a4aSRandall Stewart */ 4927f8829a4aSRandall Stewart 4928f42a358aSRandall Stewart if (num_seg) 4929c105859eSRandall Stewart sctp_check_for_revoked(stcb, asoc, cum_ack, biggest_tsn_acked); 4930f8829a4aSRandall Stewart else if (asoc->saw_sack_with_frags) { 4931f8829a4aSRandall Stewart int cnt_revoked = 0; 4932f8829a4aSRandall Stewart 4933f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 4934f8829a4aSRandall Stewart if (tp1 != NULL) { 4935f8829a4aSRandall Stewart /* Peer revoked all dg's marked or acked */ 4936f8829a4aSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4937b5c16493SMichael Tuexen if (tp1->sent == SCTP_DATAGRAM_ACKED) { 4938f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 4939b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4940c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 4941c105859eSRandall Stewart tp1->whoTo->flight_size, 4942c105859eSRandall Stewart tp1->book_size, 4943c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4944c105859eSRandall Stewart tp1->rec.data.TSN_seq); 494580fefe0aSRandall Stewart } 4946c105859eSRandall Stewart sctp_flight_size_increase(tp1); 4947c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 4948a5d547adSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 494942551e99SRandall Stewart /* 495042551e99SRandall Stewart * To ensure that this increase in 495142551e99SRandall Stewart * flightsize, which is artificial, 495242551e99SRandall Stewart * does not throttle the sender, we 495342551e99SRandall Stewart * also increase the cwnd 495442551e99SRandall Stewart * artificially. 495542551e99SRandall Stewart */ 495642551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 4957f8829a4aSRandall Stewart cnt_revoked++; 4958f8829a4aSRandall Stewart } 4959f8829a4aSRandall Stewart } 4960f8829a4aSRandall Stewart if (cnt_revoked) { 4961f8829a4aSRandall Stewart reneged_all = 1; 4962f8829a4aSRandall Stewart } 4963f8829a4aSRandall Stewart } 4964f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 0; 4965f8829a4aSRandall Stewart } 4966b5c16493SMichael Tuexen if (num_seg || num_nr_seg) 4967f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 1; 4968f8829a4aSRandall Stewart else 4969f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 0; 4970f8829a4aSRandall Stewart 4971b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4972b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, accum_moved, reneged_all, will_exit_fast_recovery); 4973f8829a4aSRandall Stewart 4974f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 4975f8829a4aSRandall Stewart /* nothing left in-flight */ 4976f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4977f8829a4aSRandall Stewart /* stop all timers */ 4978b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4979139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4980f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 4981a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4982a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_29); 4983f8829a4aSRandall Stewart } 4984f8829a4aSRandall Stewart } 4985f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4986a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_30); 4987f8829a4aSRandall Stewart net->flight_size = 0; 4988f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4989f8829a4aSRandall Stewart } 4990f8829a4aSRandall Stewart asoc->total_flight = 0; 4991f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4992f8829a4aSRandall Stewart } 4993f8829a4aSRandall Stewart /**********************************/ 4994f8829a4aSRandall Stewart /* Now what about shutdown issues */ 4995f8829a4aSRandall Stewart /**********************************/ 4996f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 4997f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 4998b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4999f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 5000f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 500180fefe0aSRandall Stewart } 5002f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 5003f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 5004f8829a4aSRandall Stewart /* SWS sender side engages */ 5005f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 5006f8829a4aSRandall Stewart } 5007f8829a4aSRandall Stewart /* clean up */ 5008f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 5009f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 5010f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 5011f8829a4aSRandall Stewart (asoc->locked_on_sending) 5012f8829a4aSRandall Stewart ) { 5013f8829a4aSRandall Stewart struct sctp_stream_queue_pending *sp; 5014f8829a4aSRandall Stewart 5015f8829a4aSRandall Stewart /* 5016f8829a4aSRandall Stewart * I may be in a state where we got all across.. but 5017f8829a4aSRandall Stewart * cannot write more due to a shutdown... we abort 5018f8829a4aSRandall Stewart * since the user did not indicate EOR in this case. 5019f8829a4aSRandall Stewart */ 5020f8829a4aSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 5021f8829a4aSRandall Stewart sctp_streamhead); 50222afb3e84SRandall Stewart if ((sp) && (sp->length == 0)) { 5023f8829a4aSRandall Stewart asoc->locked_on_sending = NULL; 50242afb3e84SRandall Stewart if (sp->msg_is_complete) { 5025f8829a4aSRandall Stewart asoc->stream_queue_cnt--; 50262afb3e84SRandall Stewart } else { 50272afb3e84SRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 50282afb3e84SRandall Stewart asoc->stream_queue_cnt--; 50292afb3e84SRandall Stewart } 5030f8829a4aSRandall Stewart } 5031f8829a4aSRandall Stewart } 5032f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 5033f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 5034f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 5035f8829a4aSRandall Stewart /* Need to abort here */ 5036f8829a4aSRandall Stewart struct mbuf *oper; 5037f8829a4aSRandall Stewart 5038f8829a4aSRandall Stewart abort_out_now: 5039f8829a4aSRandall Stewart *abort_now = 1; 5040f8829a4aSRandall Stewart /* XXX */ 5041f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 5042f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 5043f8829a4aSRandall Stewart if (oper) { 5044f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 5045f8829a4aSRandall Stewart uint32_t *ippp; 5046f8829a4aSRandall Stewart 5047139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 5048f8829a4aSRandall Stewart sizeof(uint32_t); 5049f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 5050f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 5051139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 5052f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 5053a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_31); 5054f8829a4aSRandall Stewart } 5055a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_31; 5056ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 5057f8829a4aSRandall Stewart return; 5058f8829a4aSRandall Stewart } else { 5059f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 5060f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 5061f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 5062f42a358aSRandall Stewart } 5063c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 5064b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 5065f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 5066f8829a4aSRandall Stewart sctp_send_shutdown(stcb, 5067f8829a4aSRandall Stewart stcb->asoc.primary_destination); 5068f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 5069f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 5070f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 5071f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 5072f8829a4aSRandall Stewart } 5073f8829a4aSRandall Stewart return; 5074f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 5075f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 5076f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 5077f8829a4aSRandall Stewart goto abort_out_now; 5078f8829a4aSRandall Stewart } 5079f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 5080c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 5081b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 5082f8829a4aSRandall Stewart sctp_send_shutdown_ack(stcb, 5083f8829a4aSRandall Stewart stcb->asoc.primary_destination); 5084f8829a4aSRandall Stewart 5085f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 5086f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 5087f8829a4aSRandall Stewart return; 5088f8829a4aSRandall Stewart } 5089f8829a4aSRandall Stewart } 5090f8829a4aSRandall Stewart /* 5091f8829a4aSRandall Stewart * Now here we are going to recycle net_ack for a different use... 5092f8829a4aSRandall Stewart * HEADS UP. 5093f8829a4aSRandall Stewart */ 5094f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5095f8829a4aSRandall Stewart net->net_ack = 0; 5096f8829a4aSRandall Stewart } 5097f8829a4aSRandall Stewart 5098f8829a4aSRandall Stewart /* 5099f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK DAC flag was 0, then no extra marking 5100f8829a4aSRandall Stewart * to be done. Setting this_sack_lowest_newack to the cum_ack will 5101f8829a4aSRandall Stewart * automatically ensure that. 5102f8829a4aSRandall Stewart */ 5103b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_use_dac) && (cmt_dac_flag == 0)) { 5104f8829a4aSRandall Stewart this_sack_lowest_newack = cum_ack; 5105f8829a4aSRandall Stewart } 5106cd554309SMichael Tuexen if ((num_seg > 0) || (num_nr_seg > 0)) { 5107f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(stcb, asoc, biggest_tsn_acked, 5108f8829a4aSRandall Stewart biggest_tsn_newly_acked, this_sack_lowest_newack, accum_moved); 5109f8829a4aSRandall Stewart } 5110b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 5111b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_fr(stcb, asoc); 5112f8829a4aSRandall Stewart 5113f8829a4aSRandall Stewart /****************************************************************** 5114f8829a4aSRandall Stewart * Here we do the stuff with ECN Nonce checking. 5115f8829a4aSRandall Stewart * We basically check to see if the nonce sum flag was incorrect 5116f8829a4aSRandall Stewart * or if resynchronization needs to be done. Also if we catch a 5117f8829a4aSRandall Stewart * misbehaving receiver we give him the kick. 5118f8829a4aSRandall Stewart ******************************************************************/ 5119f8829a4aSRandall Stewart 5120f8829a4aSRandall Stewart if (asoc->ecn_nonce_allowed) { 5121f8829a4aSRandall Stewart if (asoc->nonce_sum_check) { 5122f8829a4aSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base + ecn_seg_sums) & SCTP_SACK_NONCE_SUM)) { 5123f8829a4aSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 5124f8829a4aSRandall Stewart struct sctp_tmit_chunk *lchk; 5125f8829a4aSRandall Stewart 5126f8829a4aSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 5127f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 1; 5128f8829a4aSRandall Stewart if (lchk) { 5129f8829a4aSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 5130f8829a4aSRandall Stewart } else { 5131f8829a4aSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 5132f8829a4aSRandall Stewart } 5133f8829a4aSRandall Stewart } else { 5134f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) || 5135f8829a4aSRandall Stewart (asoc->last_acked_seq == asoc->nonce_wait_tsn)) { 5136f8829a4aSRandall Stewart /* 5137f8829a4aSRandall Stewart * Misbehaving peer. We need 5138f8829a4aSRandall Stewart * to react to this guy 5139f8829a4aSRandall Stewart */ 5140f8829a4aSRandall Stewart asoc->ecn_allowed = 0; 5141f8829a4aSRandall Stewart asoc->ecn_nonce_allowed = 0; 5142f8829a4aSRandall Stewart } 5143f8829a4aSRandall Stewart } 5144f8829a4aSRandall Stewart } 5145f8829a4aSRandall Stewart } else { 5146f8829a4aSRandall Stewart /* See if Resynchronization Possible */ 5147f8829a4aSRandall Stewart if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) { 5148f8829a4aSRandall Stewart asoc->nonce_sum_check = 1; 5149f8829a4aSRandall Stewart /* 5150f8829a4aSRandall Stewart * now we must calculate what the base is. 5151f8829a4aSRandall Stewart * We do this based on two things, we know 5152f8829a4aSRandall Stewart * the total's for all the segments 5153f8829a4aSRandall Stewart * gap-acked in the SACK, its stored in 5154f8829a4aSRandall Stewart * ecn_seg_sums. We also know the SACK's 5155f8829a4aSRandall Stewart * nonce sum, its in nonce_sum_flag. So we 5156f8829a4aSRandall Stewart * can build a truth table to back-calculate 5157f8829a4aSRandall Stewart * the new value of 5158f8829a4aSRandall Stewart * asoc->nonce_sum_expect_base: 5159f8829a4aSRandall Stewart * 5160f8829a4aSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 5161f8829a4aSRandall Stewart * 1 0 1 0 1 1 1 5162f8829a4aSRandall Stewart * 1 0 5163f8829a4aSRandall Stewart */ 5164f8829a4aSRandall Stewart asoc->nonce_sum_expect_base = (ecn_seg_sums ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 5165f8829a4aSRandall Stewart } 5166f8829a4aSRandall Stewart } 5167f8829a4aSRandall Stewart } 5168f8829a4aSRandall Stewart /* Now are we exiting loss recovery ? */ 5169f8829a4aSRandall Stewart if (will_exit_fast_recovery) { 5170f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 5171f8829a4aSRandall Stewart asoc->fast_retran_loss_recovery = 0; 5172f8829a4aSRandall Stewart } 5173f8829a4aSRandall Stewart if ((asoc->sat_t3_loss_recovery) && 5174f8829a4aSRandall Stewart ((compare_with_wrap(asoc->last_acked_seq, asoc->sat_t3_recovery_tsn, 5175f8829a4aSRandall Stewart MAX_TSN) || 5176f8829a4aSRandall Stewart (asoc->last_acked_seq == asoc->sat_t3_recovery_tsn)))) { 5177f8829a4aSRandall Stewart /* end satellite t3 loss recovery */ 5178f8829a4aSRandall Stewart asoc->sat_t3_loss_recovery = 0; 5179f8829a4aSRandall Stewart } 518042551e99SRandall Stewart /* 518142551e99SRandall Stewart * CMT Fast recovery 518242551e99SRandall Stewart */ 5183f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5184f8829a4aSRandall Stewart if (net->will_exit_fast_recovery) { 5185f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 5186f8829a4aSRandall Stewart net->fast_retran_loss_recovery = 0; 5187f8829a4aSRandall Stewart } 5188f8829a4aSRandall Stewart } 5189f8829a4aSRandall Stewart 5190f8829a4aSRandall Stewart /* Adjust and set the new rwnd value */ 5191b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 5192f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 5193*44fbe462SRandall Stewart asoc->peers_rwnd, asoc->total_flight, (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)), a_rwnd); 519480fefe0aSRandall Stewart } 5195f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd, 5196*44fbe462SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 5197f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 5198f8829a4aSRandall Stewart /* SWS sender side engages */ 5199f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 5200f8829a4aSRandall Stewart } 52015e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 52025e54f665SRandall Stewart win_probe_recovery = 1; 52035e54f665SRandall Stewart } 5204f8829a4aSRandall Stewart /* 5205f8829a4aSRandall Stewart * Now we must setup so we have a timer up for anyone with 5206f8829a4aSRandall Stewart * outstanding data. 5207f8829a4aSRandall Stewart */ 5208bff64a4dSRandall Stewart done_once = 0; 5209a5d547adSRandall Stewart again: 5210a5d547adSRandall Stewart j = 0; 5211f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 52125e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 5213c105859eSRandall Stewart win_probe_recovered = 1; 52145e54f665SRandall Stewart /*- 52155e54f665SRandall Stewart * Find first chunk that was used with 52165e54f665SRandall Stewart * window probe and clear the event. Put 52175e54f665SRandall Stewart * it back into the send queue as if has 52185e54f665SRandall Stewart * not been sent. 52195e54f665SRandall Stewart */ 52205e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 52215e54f665SRandall Stewart if (tp1->window_probe) { 5222c105859eSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 52235e54f665SRandall Stewart break; 52245e54f665SRandall Stewart } 52255e54f665SRandall Stewart } 52265e54f665SRandall Stewart } 5227f8829a4aSRandall Stewart if (net->flight_size) { 5228a5d547adSRandall Stewart j++; 5229cd554309SMichael Tuexen if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 5230f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5231f8829a4aSRandall Stewart stcb->sctp_ep, stcb, net); 5232cd554309SMichael Tuexen } 52335171328bSRandall Stewart if (net->window_probe) { 5234cd554309SMichael Tuexen net->window_probe = 0; 52355171328bSRandall Stewart } 5236c105859eSRandall Stewart } else { 52375171328bSRandall Stewart if (net->window_probe) { 52385171328bSRandall Stewart /* 52395171328bSRandall Stewart * In window probes we must assure a timer 52405171328bSRandall Stewart * is still running there 52415171328bSRandall Stewart */ 52425171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 52435171328bSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 52445171328bSRandall Stewart stcb->sctp_ep, stcb, net); 52455171328bSRandall Stewart 52465171328bSRandall Stewart } 52475171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 5248c105859eSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 5249c105859eSRandall Stewart stcb, net, 5250c105859eSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 5251c105859eSRandall Stewart } 5252b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 5253c105859eSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 5254c105859eSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 5255c105859eSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 5256c105859eSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 5257c105859eSRandall Stewart } 5258c105859eSRandall Stewart } 5259f8829a4aSRandall Stewart } 5260f8829a4aSRandall Stewart } 5261bff64a4dSRandall Stewart if ((j == 0) && 5262bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 5263bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 5264c105859eSRandall Stewart (win_probe_recovered == 0) && 5265bff64a4dSRandall Stewart (done_once == 0)) { 52660c0982b8SRandall Stewart /* 52670c0982b8SRandall Stewart * huh, this should not happen unless all packets are 52680c0982b8SRandall Stewart * PR-SCTP and marked to skip of course. 52690c0982b8SRandall Stewart */ 52700c0982b8SRandall Stewart if (sctp_fs_audit(asoc)) { 5271a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5272a5d547adSRandall Stewart net->flight_size = 0; 5273a5d547adSRandall Stewart } 5274a5d547adSRandall Stewart asoc->total_flight = 0; 5275a5d547adSRandall Stewart asoc->total_flight_count = 0; 5276a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 5277a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 5278a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 5279c105859eSRandall Stewart sctp_flight_size_increase(tp1); 5280c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 5281a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 5282791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 5283a5d547adSRandall Stewart } 5284a5d547adSRandall Stewart } 52850c0982b8SRandall Stewart } 5286bff64a4dSRandall Stewart done_once = 1; 5287a5d547adSRandall Stewart goto again; 5288a5d547adSRandall Stewart } 5289cd554309SMichael Tuexen /*********************************************/ 5290cd554309SMichael Tuexen /* Here we perform PR-SCTP procedures */ 5291cd554309SMichael Tuexen /* (section 4.2) */ 5292cd554309SMichael Tuexen /*********************************************/ 5293cd554309SMichael Tuexen /* C1. update advancedPeerAckPoint */ 5294dfb11ef8SRandall Stewart if (compare_with_wrap(cum_ack, asoc->advanced_peer_ack_point, MAX_TSN)) { 5295dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cum_ack; 5296dfb11ef8SRandall Stewart } 5297830d754dSRandall Stewart /* C2. try to further move advancedPeerAckPoint ahead */ 5298830d754dSRandall Stewart if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) { 5299830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 5300830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 5301830d754dSRandall Stewart 5302830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 5303830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 5304830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 5305830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, cum_ack, 5306830d754dSRandall Stewart MAX_TSN)) { 5307830d754dSRandall Stewart /* 5308830d754dSRandall Stewart * ISSUE with ECN, see FWD-TSN processing for notes 5309830d754dSRandall Stewart * on issues that will occur when the ECN NONCE 5310830d754dSRandall Stewart * stuff is put into SCTP for cross checking. 5311830d754dSRandall Stewart */ 53120c0982b8SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { 53130c0982b8SRandall Stewart sctp_misc_ints(SCTP_FWD_TSN_CHECK, 53140c0982b8SRandall Stewart 0xee, cum_ack, asoc->advanced_peer_ack_point, 53150c0982b8SRandall Stewart old_adv_peer_ack_point); 53160c0982b8SRandall Stewart } 5317830d754dSRandall Stewart if (compare_with_wrap(asoc->advanced_peer_ack_point, old_adv_peer_ack_point, 5318830d754dSRandall Stewart MAX_TSN)) { 5319*44fbe462SRandall Stewart 5320830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 5321830d754dSRandall Stewart /* 5322830d754dSRandall Stewart * ECN Nonce: Disable Nonce Sum check when 5323830d754dSRandall Stewart * FWD TSN is sent and store resync tsn 5324830d754dSRandall Stewart */ 5325830d754dSRandall Stewart asoc->nonce_sum_check = 0; 5326830d754dSRandall Stewart asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point; 53270c0982b8SRandall Stewart } else if (lchk) { 53280c0982b8SRandall Stewart /* try to FR fwd-tsn's that get lost too */ 5329*44fbe462SRandall Stewart if (lchk->rec.data.fwd_tsn_cnt >= 3) { 53300c0982b8SRandall Stewart send_forward_tsn(stcb, asoc); 53310c0982b8SRandall Stewart } 5332830d754dSRandall Stewart } 5333830d754dSRandall Stewart } 5334830d754dSRandall Stewart if (lchk) { 5335830d754dSRandall Stewart /* Assure a timer is up */ 5336830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5337830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 5338830d754dSRandall Stewart } 5339830d754dSRandall Stewart } 5340b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 5341f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 5342f8829a4aSRandall Stewart a_rwnd, 5343f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 5344f8829a4aSRandall Stewart stcb->asoc.total_flight, 5345f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 534680fefe0aSRandall Stewart } 5347f8829a4aSRandall Stewart } 5348f8829a4aSRandall Stewart 5349f8829a4aSRandall Stewart void 5350f8829a4aSRandall Stewart sctp_update_acked(struct sctp_tcb *stcb, struct sctp_shutdown_chunk *cp, 5351f8829a4aSRandall Stewart struct sctp_nets *netp, int *abort_flag) 5352f8829a4aSRandall Stewart { 5353f8829a4aSRandall Stewart /* Copy cum-ack */ 5354f8829a4aSRandall Stewart uint32_t cum_ack, a_rwnd; 5355f8829a4aSRandall Stewart 5356f8829a4aSRandall Stewart cum_ack = ntohl(cp->cumulative_tsn_ack); 5357f8829a4aSRandall Stewart /* Arrange so a_rwnd does NOT change */ 5358f8829a4aSRandall Stewart a_rwnd = stcb->asoc.peers_rwnd + stcb->asoc.total_flight; 5359f8829a4aSRandall Stewart 5360f8829a4aSRandall Stewart /* Now call the express sack handling */ 5361f8829a4aSRandall Stewart sctp_express_handle_sack(stcb, cum_ack, a_rwnd, 0, abort_flag); 5362f8829a4aSRandall Stewart } 5363f8829a4aSRandall Stewart 5364f8829a4aSRandall Stewart static void 5365f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb, 5366f8829a4aSRandall Stewart struct sctp_stream_in *strmin) 5367f8829a4aSRandall Stewart { 5368f8829a4aSRandall Stewart struct sctp_queued_to_read *ctl, *nctl; 5369f8829a4aSRandall Stewart struct sctp_association *asoc; 537083128708SRandall Stewart uint16_t tt; 5371f8829a4aSRandall Stewart 5372f8829a4aSRandall Stewart asoc = &stcb->asoc; 5373f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered; 5374f8829a4aSRandall Stewart /* 5375f8829a4aSRandall Stewart * First deliver anything prior to and including the stream no that 5376f8829a4aSRandall Stewart * came in 5377f8829a4aSRandall Stewart */ 5378f8829a4aSRandall Stewart ctl = TAILQ_FIRST(&strmin->inqueue); 5379f8829a4aSRandall Stewart while (ctl) { 5380f8829a4aSRandall Stewart nctl = TAILQ_NEXT(ctl, next); 5381f8829a4aSRandall Stewart if (compare_with_wrap(tt, ctl->sinfo_ssn, MAX_SEQ) || 5382f8829a4aSRandall Stewart (tt == ctl->sinfo_ssn)) { 5383f8829a4aSRandall Stewart /* this is deliverable now */ 5384f8829a4aSRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next); 5385f8829a4aSRandall Stewart /* subtract pending on streams */ 5386f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5387f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5388f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5389f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5390b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 5391f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5392f8829a4aSRandall Stewart ctl, 5393cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED); 5394f8829a4aSRandall Stewart } 5395f8829a4aSRandall Stewart } else { 5396f8829a4aSRandall Stewart /* no more delivery now. */ 5397f8829a4aSRandall Stewart break; 5398f8829a4aSRandall Stewart } 5399f8829a4aSRandall Stewart ctl = nctl; 5400f8829a4aSRandall Stewart } 5401f8829a4aSRandall Stewart /* 5402f8829a4aSRandall Stewart * now we must deliver things in queue the normal way if any are 5403f8829a4aSRandall Stewart * now ready. 5404f8829a4aSRandall Stewart */ 5405f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 5406f8829a4aSRandall Stewart ctl = TAILQ_FIRST(&strmin->inqueue); 5407f8829a4aSRandall Stewart while (ctl) { 5408f8829a4aSRandall Stewart nctl = TAILQ_NEXT(ctl, next); 5409f8829a4aSRandall Stewart if (tt == ctl->sinfo_ssn) { 5410f8829a4aSRandall Stewart /* this is deliverable now */ 5411f8829a4aSRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next); 5412f8829a4aSRandall Stewart /* subtract pending on streams */ 5413f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5414f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5415f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5416f8829a4aSRandall Stewart strmin->last_sequence_delivered = ctl->sinfo_ssn; 5417f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5418b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 5419f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5420f8829a4aSRandall Stewart ctl, 5421cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED); 542277acdc25SRandall Stewart 5423f8829a4aSRandall Stewart } 5424f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 5425f8829a4aSRandall Stewart } else { 5426f8829a4aSRandall Stewart break; 5427f8829a4aSRandall Stewart } 5428f8829a4aSRandall Stewart ctl = nctl; 5429f8829a4aSRandall Stewart } 5430f8829a4aSRandall Stewart } 5431f8829a4aSRandall Stewart 54328933fa13SRandall Stewart static void 54338933fa13SRandall Stewart sctp_flush_reassm_for_str_seq(struct sctp_tcb *stcb, 54348933fa13SRandall Stewart struct sctp_association *asoc, 54358933fa13SRandall Stewart uint16_t stream, uint16_t seq) 54368933fa13SRandall Stewart { 54378933fa13SRandall Stewart struct sctp_tmit_chunk *chk, *at; 54388933fa13SRandall Stewart 54398933fa13SRandall Stewart if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 54408933fa13SRandall Stewart /* For each one on here see if we need to toss it */ 54418933fa13SRandall Stewart /* 54428933fa13SRandall Stewart * For now large messages held on the reasmqueue that are 54438933fa13SRandall Stewart * complete will be tossed too. We could in theory do more 54448933fa13SRandall Stewart * work to spin through and stop after dumping one msg aka 54458933fa13SRandall Stewart * seeing the start of a new msg at the head, and call the 54468933fa13SRandall Stewart * delivery function... to see if it can be delivered... But 54478933fa13SRandall Stewart * for now we just dump everything on the queue. 54488933fa13SRandall Stewart */ 54498933fa13SRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 54508933fa13SRandall Stewart while (chk) { 54518933fa13SRandall Stewart at = TAILQ_NEXT(chk, sctp_next); 54528e71b694SMichael Tuexen /* 54538e71b694SMichael Tuexen * Do not toss it if on a different stream or marked 54548e71b694SMichael Tuexen * for unordered delivery in which case the stream 54558e71b694SMichael Tuexen * sequence number has no meaning. 54568e71b694SMichael Tuexen */ 54578e71b694SMichael Tuexen if ((chk->rec.data.stream_number != stream) || 54588e71b694SMichael Tuexen ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == SCTP_DATA_UNORDERED)) { 54598933fa13SRandall Stewart chk = at; 54608933fa13SRandall Stewart continue; 54618933fa13SRandall Stewart } 54628933fa13SRandall Stewart if (chk->rec.data.stream_seq == seq) { 54638933fa13SRandall Stewart /* It needs to be tossed */ 54648933fa13SRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 54658933fa13SRandall Stewart if (compare_with_wrap(chk->rec.data.TSN_seq, 54668933fa13SRandall Stewart asoc->tsn_last_delivered, MAX_TSN)) { 54678933fa13SRandall Stewart asoc->tsn_last_delivered = 54688933fa13SRandall Stewart chk->rec.data.TSN_seq; 54698933fa13SRandall Stewart asoc->str_of_pdapi = 54708933fa13SRandall Stewart chk->rec.data.stream_number; 54718933fa13SRandall Stewart asoc->ssn_of_pdapi = 54728933fa13SRandall Stewart chk->rec.data.stream_seq; 54738933fa13SRandall Stewart asoc->fragment_flags = 54748933fa13SRandall Stewart chk->rec.data.rcv_flags; 54758933fa13SRandall Stewart } 54768933fa13SRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 54778933fa13SRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 54788933fa13SRandall Stewart 54798933fa13SRandall Stewart /* Clear up any stream problem */ 54808933fa13SRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) != 54818933fa13SRandall Stewart SCTP_DATA_UNORDERED && 54828933fa13SRandall Stewart (compare_with_wrap(chk->rec.data.stream_seq, 54838933fa13SRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered, 54848933fa13SRandall Stewart MAX_SEQ))) { 54858933fa13SRandall Stewart /* 54868933fa13SRandall Stewart * We must dump forward this streams 54878933fa13SRandall Stewart * sequence number if the chunk is 54888933fa13SRandall Stewart * not unordered that is being 54898933fa13SRandall Stewart * skipped. There is a chance that 54908933fa13SRandall Stewart * if the peer does not include the 54918933fa13SRandall Stewart * last fragment in its FWD-TSN we 54928933fa13SRandall Stewart * WILL have a problem here since 54938933fa13SRandall Stewart * you would have a partial chunk in 54948933fa13SRandall Stewart * queue that may not be 54958933fa13SRandall Stewart * deliverable. Also if a Partial 54968933fa13SRandall Stewart * delivery API as started the user 54978933fa13SRandall Stewart * may get a partial chunk. The next 54988933fa13SRandall Stewart * read returning a new chunk... 54998933fa13SRandall Stewart * really ugly but I see no way 55008933fa13SRandall Stewart * around it! Maybe a notify?? 55018933fa13SRandall Stewart */ 55028933fa13SRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered = 55038933fa13SRandall Stewart chk->rec.data.stream_seq; 55048933fa13SRandall Stewart } 55058933fa13SRandall Stewart if (chk->data) { 55068933fa13SRandall Stewart sctp_m_freem(chk->data); 55078933fa13SRandall Stewart chk->data = NULL; 55088933fa13SRandall Stewart } 55098933fa13SRandall Stewart sctp_free_a_chunk(stcb, chk); 55108933fa13SRandall Stewart } else if (compare_with_wrap(chk->rec.data.stream_seq, seq, MAX_SEQ)) { 55118933fa13SRandall Stewart /* 55128933fa13SRandall Stewart * If the stream_seq is > than the purging 55138933fa13SRandall Stewart * one, we are done 55148933fa13SRandall Stewart */ 55158933fa13SRandall Stewart break; 55168933fa13SRandall Stewart } 55178933fa13SRandall Stewart chk = at; 55188933fa13SRandall Stewart } 55198933fa13SRandall Stewart } 55208933fa13SRandall Stewart } 55218933fa13SRandall Stewart 55228933fa13SRandall Stewart 5523f8829a4aSRandall Stewart void 5524f8829a4aSRandall Stewart sctp_handle_forward_tsn(struct sctp_tcb *stcb, 5525b5c16493SMichael Tuexen struct sctp_forward_tsn_chunk *fwd, 5526b5c16493SMichael Tuexen int *abort_flag, struct mbuf *m, int offset) 5527f8829a4aSRandall Stewart { 5528f8829a4aSRandall Stewart /* 5529f8829a4aSRandall Stewart * ISSUES that MUST be fixed for ECN! When we are the sender of the 5530f8829a4aSRandall Stewart * forward TSN, when the SACK comes back that acknowledges the 5531f8829a4aSRandall Stewart * FWD-TSN we must reset the NONCE sum to match correctly. This will 5532f8829a4aSRandall Stewart * get quite tricky since we may have sent more data interveneing 5533f8829a4aSRandall Stewart * and must carefully account for what the SACK says on the nonce 5534f8829a4aSRandall Stewart * and any gaps that are reported. This work will NOT be done here, 5535f8829a4aSRandall Stewart * but I note it here since it is really related to PR-SCTP and 5536f8829a4aSRandall Stewart * FWD-TSN's 5537f8829a4aSRandall Stewart */ 5538f8829a4aSRandall Stewart 5539f8829a4aSRandall Stewart /* The pr-sctp fwd tsn */ 5540f8829a4aSRandall Stewart /* 5541f8829a4aSRandall Stewart * here we will perform all the data receiver side steps for 5542f8829a4aSRandall Stewart * processing FwdTSN, as required in by pr-sctp draft: 5543f8829a4aSRandall Stewart * 5544f8829a4aSRandall Stewart * Assume we get FwdTSN(x): 5545f8829a4aSRandall Stewart * 5546f8829a4aSRandall Stewart * 1) update local cumTSN to x 2) try to further advance cumTSN to x + 5547f8829a4aSRandall Stewart * others we have 3) examine and update re-ordering queue on 5548f8829a4aSRandall Stewart * pr-in-streams 4) clean up re-assembly queue 5) Send a sack to 5549f8829a4aSRandall Stewart * report where we are. 5550f8829a4aSRandall Stewart */ 5551f8829a4aSRandall Stewart struct sctp_association *asoc; 55527898f408SRandall Stewart uint32_t new_cum_tsn, gap; 55537898f408SRandall Stewart unsigned int i, fwd_sz, cumack_set_flag, m_size; 55548933fa13SRandall Stewart uint32_t str_seq; 5555f8829a4aSRandall Stewart struct sctp_stream_in *strm; 5556f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk, *at; 55578933fa13SRandall Stewart struct sctp_queued_to_read *ctl, *sv; 5558f8829a4aSRandall Stewart 5559f8829a4aSRandall Stewart cumack_set_flag = 0; 5560f8829a4aSRandall Stewart asoc = &stcb->asoc; 5561f8829a4aSRandall Stewart if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) { 5562ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, 5563ad81507eSRandall Stewart "Bad size too small/big fwd-tsn\n"); 5564f8829a4aSRandall Stewart return; 5565f8829a4aSRandall Stewart } 5566f8829a4aSRandall Stewart m_size = (stcb->asoc.mapping_array_size << 3); 5567f8829a4aSRandall Stewart /*************************************************************/ 5568f8829a4aSRandall Stewart /* 1. Here we update local cumTSN and shift the bitmap array */ 5569f8829a4aSRandall Stewart /*************************************************************/ 5570f8829a4aSRandall Stewart new_cum_tsn = ntohl(fwd->new_cumulative_tsn); 5571f8829a4aSRandall Stewart 5572f8829a4aSRandall Stewart if (compare_with_wrap(asoc->cumulative_tsn, new_cum_tsn, MAX_TSN) || 5573f8829a4aSRandall Stewart asoc->cumulative_tsn == new_cum_tsn) { 5574f8829a4aSRandall Stewart /* Already got there ... */ 5575f8829a4aSRandall Stewart return; 5576f8829a4aSRandall Stewart } 5577f8829a4aSRandall Stewart /* 5578f8829a4aSRandall Stewart * now we know the new TSN is more advanced, let's find the actual 5579f8829a4aSRandall Stewart * gap 5580f8829a4aSRandall Stewart */ 5581b5c16493SMichael Tuexen SCTP_CALC_TSN_TO_GAP(gap, new_cum_tsn, asoc->mapping_array_base_tsn); 558277acdc25SRandall Stewart asoc->cumulative_tsn = new_cum_tsn; 55832afb3e84SRandall Stewart if (gap >= m_size) { 5584f8829a4aSRandall Stewart if ((long)gap > sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv)) { 558517205eccSRandall Stewart struct mbuf *oper; 558617205eccSRandall Stewart 5587f8829a4aSRandall Stewart /* 5588f8829a4aSRandall Stewart * out of range (of single byte chunks in the rwnd I 558917205eccSRandall Stewart * give out). This must be an attacker. 5590f8829a4aSRandall Stewart */ 559117205eccSRandall Stewart *abort_flag = 1; 559217205eccSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 559317205eccSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 559417205eccSRandall Stewart if (oper) { 559517205eccSRandall Stewart struct sctp_paramhdr *ph; 559617205eccSRandall Stewart uint32_t *ippp; 559717205eccSRandall Stewart 559817205eccSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 559917205eccSRandall Stewart (sizeof(uint32_t) * 3); 560017205eccSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 560117205eccSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 560217205eccSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 560317205eccSRandall Stewart ippp = (uint32_t *) (ph + 1); 560417205eccSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_33); 560517205eccSRandall Stewart ippp++; 560617205eccSRandall Stewart *ippp = asoc->highest_tsn_inside_map; 560717205eccSRandall Stewart ippp++; 560817205eccSRandall Stewart *ippp = new_cum_tsn; 560917205eccSRandall Stewart } 561017205eccSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_33; 561117205eccSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 5612ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 5613f8829a4aSRandall Stewart return; 5614f8829a4aSRandall Stewart } 5615207304d4SRandall Stewart SCTP_STAT_INCR(sctps_fwdtsn_map_over); 561677acdc25SRandall Stewart 56172afb3e84SRandall Stewart memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size); 56182afb3e84SRandall Stewart asoc->mapping_array_base_tsn = new_cum_tsn + 1; 561977acdc25SRandall Stewart asoc->highest_tsn_inside_map = new_cum_tsn; 562077acdc25SRandall Stewart 5621b5c16493SMichael Tuexen memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.mapping_array_size); 5622830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = new_cum_tsn; 562377acdc25SRandall Stewart 5624b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 5625f8829a4aSRandall Stewart sctp_log_map(0, 3, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 562680fefe0aSRandall Stewart } 5627f8829a4aSRandall Stewart asoc->last_echo_tsn = asoc->highest_tsn_inside_map; 56282afb3e84SRandall Stewart } else { 56292afb3e84SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 56302afb3e84SRandall Stewart for (i = 0; i <= gap; i++) { 56317898f408SRandall Stewart if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, i) && 56327898f408SRandall Stewart !SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, i)) { 56338933fa13SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, i); 56347898f408SRandall Stewart if (compare_with_wrap(asoc->mapping_array_base_tsn + i, asoc->highest_tsn_inside_nr_map, MAX_TSN)) { 56357898f408SRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->mapping_array_base_tsn + i; 5636b5c16493SMichael Tuexen } 5637b5c16493SMichael Tuexen } 5638b5c16493SMichael Tuexen } 5639f8829a4aSRandall Stewart } 5640f8829a4aSRandall Stewart /*************************************************************/ 5641f8829a4aSRandall Stewart /* 2. Clear up re-assembly queue */ 5642f8829a4aSRandall Stewart /*************************************************************/ 5643f8829a4aSRandall Stewart /* 5644f8829a4aSRandall Stewart * First service it if pd-api is up, just in case we can progress it 5645f8829a4aSRandall Stewart * forward 5646f8829a4aSRandall Stewart */ 5647f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 5648f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 5649f8829a4aSRandall Stewart } 5650f8829a4aSRandall Stewart if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 5651f8829a4aSRandall Stewart /* For each one on here see if we need to toss it */ 5652f8829a4aSRandall Stewart /* 5653f8829a4aSRandall Stewart * For now large messages held on the reasmqueue that are 5654f8829a4aSRandall Stewart * complete will be tossed too. We could in theory do more 5655f8829a4aSRandall Stewart * work to spin through and stop after dumping one msg aka 5656f8829a4aSRandall Stewart * seeing the start of a new msg at the head, and call the 5657f8829a4aSRandall Stewart * delivery function... to see if it can be delivered... But 5658f8829a4aSRandall Stewart * for now we just dump everything on the queue. 5659f8829a4aSRandall Stewart */ 5660f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 5661f8829a4aSRandall Stewart while (chk) { 5662f8829a4aSRandall Stewart at = TAILQ_NEXT(chk, sctp_next); 56630c0982b8SRandall Stewart if ((compare_with_wrap(new_cum_tsn, 56640c0982b8SRandall Stewart chk->rec.data.TSN_seq, MAX_TSN)) || 56650c0982b8SRandall Stewart (new_cum_tsn == chk->rec.data.TSN_seq)) { 5666f8829a4aSRandall Stewart /* It needs to be tossed */ 5667f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 5668f8829a4aSRandall Stewart if (compare_with_wrap(chk->rec.data.TSN_seq, 5669f8829a4aSRandall Stewart asoc->tsn_last_delivered, MAX_TSN)) { 5670f8829a4aSRandall Stewart asoc->tsn_last_delivered = 5671f8829a4aSRandall Stewart chk->rec.data.TSN_seq; 5672f8829a4aSRandall Stewart asoc->str_of_pdapi = 5673f8829a4aSRandall Stewart chk->rec.data.stream_number; 5674f8829a4aSRandall Stewart asoc->ssn_of_pdapi = 5675f8829a4aSRandall Stewart chk->rec.data.stream_seq; 5676f8829a4aSRandall Stewart asoc->fragment_flags = 5677f8829a4aSRandall Stewart chk->rec.data.rcv_flags; 5678f8829a4aSRandall Stewart } 5679f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 5680f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 5681f8829a4aSRandall Stewart 5682f8829a4aSRandall Stewart /* Clear up any stream problem */ 5683f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) != 5684f8829a4aSRandall Stewart SCTP_DATA_UNORDERED && 5685f8829a4aSRandall Stewart (compare_with_wrap(chk->rec.data.stream_seq, 5686f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered, 5687f8829a4aSRandall Stewart MAX_SEQ))) { 5688f8829a4aSRandall Stewart /* 5689f8829a4aSRandall Stewart * We must dump forward this streams 5690f8829a4aSRandall Stewart * sequence number if the chunk is 5691f8829a4aSRandall Stewart * not unordered that is being 5692f8829a4aSRandall Stewart * skipped. There is a chance that 5693f8829a4aSRandall Stewart * if the peer does not include the 5694f8829a4aSRandall Stewart * last fragment in its FWD-TSN we 5695f8829a4aSRandall Stewart * WILL have a problem here since 5696f8829a4aSRandall Stewart * you would have a partial chunk in 5697f8829a4aSRandall Stewart * queue that may not be 5698f8829a4aSRandall Stewart * deliverable. Also if a Partial 5699f8829a4aSRandall Stewart * delivery API as started the user 5700f8829a4aSRandall Stewart * may get a partial chunk. The next 5701f8829a4aSRandall Stewart * read returning a new chunk... 5702f8829a4aSRandall Stewart * really ugly but I see no way 5703f8829a4aSRandall Stewart * around it! Maybe a notify?? 5704f8829a4aSRandall Stewart */ 5705f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered = 5706f8829a4aSRandall Stewart chk->rec.data.stream_seq; 5707f8829a4aSRandall Stewart } 5708f8829a4aSRandall Stewart if (chk->data) { 5709f8829a4aSRandall Stewart sctp_m_freem(chk->data); 5710f8829a4aSRandall Stewart chk->data = NULL; 5711f8829a4aSRandall Stewart } 5712f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 5713f8829a4aSRandall Stewart } else { 5714f8829a4aSRandall Stewart /* 5715f8829a4aSRandall Stewart * Ok we have gone beyond the end of the 57168933fa13SRandall Stewart * fwd-tsn's mark. 5717f8829a4aSRandall Stewart */ 5718f8829a4aSRandall Stewart break; 5719f8829a4aSRandall Stewart } 5720f8829a4aSRandall Stewart chk = at; 5721f8829a4aSRandall Stewart } 5722f8829a4aSRandall Stewart } 57238933fa13SRandall Stewart /*******************************************************/ 57248933fa13SRandall Stewart /* 3. Update the PR-stream re-ordering queues and fix */ 57258933fa13SRandall Stewart /* delivery issues as needed. */ 57268933fa13SRandall Stewart /*******************************************************/ 5727f8829a4aSRandall Stewart fwd_sz -= sizeof(*fwd); 5728671d309cSRandall Stewart if (m && fwd_sz) { 5729f8829a4aSRandall Stewart /* New method. */ 5730d61a0ae0SRandall Stewart unsigned int num_str; 5731671d309cSRandall Stewart struct sctp_strseq *stseq, strseqbuf; 5732671d309cSRandall Stewart 5733671d309cSRandall Stewart offset += sizeof(*fwd); 5734f8829a4aSRandall Stewart 57358933fa13SRandall Stewart SCTP_INP_READ_LOCK(stcb->sctp_ep); 5736f8829a4aSRandall Stewart num_str = fwd_sz / sizeof(struct sctp_strseq); 5737f8829a4aSRandall Stewart for (i = 0; i < num_str; i++) { 5738f8829a4aSRandall Stewart uint16_t st; 5739f8829a4aSRandall Stewart 5740671d309cSRandall Stewart stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset, 5741671d309cSRandall Stewart sizeof(struct sctp_strseq), 5742671d309cSRandall Stewart (uint8_t *) & strseqbuf); 5743671d309cSRandall Stewart offset += sizeof(struct sctp_strseq); 57442afb3e84SRandall Stewart if (stseq == NULL) { 5745671d309cSRandall Stewart break; 57462afb3e84SRandall Stewart } 5747f8829a4aSRandall Stewart /* Convert */ 5748851b7298SRandall Stewart st = ntohs(stseq->stream); 5749851b7298SRandall Stewart stseq->stream = st; 5750851b7298SRandall Stewart st = ntohs(stseq->sequence); 5751851b7298SRandall Stewart stseq->sequence = st; 57528933fa13SRandall Stewart 5753f8829a4aSRandall Stewart /* now process */ 57548933fa13SRandall Stewart 57558933fa13SRandall Stewart /* 57568933fa13SRandall Stewart * Ok we now look for the stream/seq on the read 57578933fa13SRandall Stewart * queue where its not all delivered. If we find it 57588933fa13SRandall Stewart * we transmute the read entry into a PDI_ABORTED. 57598933fa13SRandall Stewart */ 5760851b7298SRandall Stewart if (stseq->stream >= asoc->streamincnt) { 57612afb3e84SRandall Stewart /* screwed up streams, stop! */ 57622afb3e84SRandall Stewart break; 5763f8829a4aSRandall Stewart } 57648933fa13SRandall Stewart if ((asoc->str_of_pdapi == stseq->stream) && 57658933fa13SRandall Stewart (asoc->ssn_of_pdapi == stseq->sequence)) { 57668933fa13SRandall Stewart /* 57678933fa13SRandall Stewart * If this is the one we were partially 57688933fa13SRandall Stewart * delivering now then we no longer are. 57698933fa13SRandall Stewart * Note this will change with the reassembly 57708933fa13SRandall Stewart * re-write. 57718933fa13SRandall Stewart */ 57728933fa13SRandall Stewart asoc->fragmented_delivery_inprogress = 0; 57738933fa13SRandall Stewart } 57748933fa13SRandall Stewart sctp_flush_reassm_for_str_seq(stcb, asoc, stseq->stream, stseq->sequence); 57758933fa13SRandall Stewart TAILQ_FOREACH(ctl, &stcb->sctp_ep->read_queue, next) { 57768933fa13SRandall Stewart if ((ctl->sinfo_stream == stseq->stream) && 57778933fa13SRandall Stewart (ctl->sinfo_ssn == stseq->sequence)) { 57788933fa13SRandall Stewart str_seq = (stseq->stream << 16) | stseq->sequence; 57798933fa13SRandall Stewart ctl->end_added = 1; 57808933fa13SRandall Stewart ctl->pdapi_aborted = 1; 57818933fa13SRandall Stewart sv = stcb->asoc.control_pdapi; 57828933fa13SRandall Stewart stcb->asoc.control_pdapi = ctl; 5783810ec536SMichael Tuexen sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION, 5784810ec536SMichael Tuexen stcb, 57858933fa13SRandall Stewart SCTP_PARTIAL_DELIVERY_ABORTED, 5786810ec536SMichael Tuexen (void *)&str_seq, 5787810ec536SMichael Tuexen SCTP_SO_NOT_LOCKED); 57888933fa13SRandall Stewart stcb->asoc.control_pdapi = sv; 57898933fa13SRandall Stewart break; 57908933fa13SRandall Stewart } else if ((ctl->sinfo_stream == stseq->stream) && 57918933fa13SRandall Stewart (compare_with_wrap(ctl->sinfo_ssn, stseq->sequence, MAX_SEQ))) { 57928933fa13SRandall Stewart /* We are past our victim SSN */ 57938933fa13SRandall Stewart break; 57948933fa13SRandall Stewart } 57958933fa13SRandall Stewart } 5796851b7298SRandall Stewart strm = &asoc->strmin[stseq->stream]; 5797851b7298SRandall Stewart if (compare_with_wrap(stseq->sequence, 5798f8829a4aSRandall Stewart strm->last_sequence_delivered, MAX_SEQ)) { 5799f8829a4aSRandall Stewart /* Update the sequence number */ 5800f8829a4aSRandall Stewart strm->last_sequence_delivered = 5801851b7298SRandall Stewart stseq->sequence; 5802f8829a4aSRandall Stewart } 5803f8829a4aSRandall Stewart /* now kick the stream the new way */ 580404ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 5805f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(stcb, strm); 5806f8829a4aSRandall Stewart } 58078933fa13SRandall Stewart SCTP_INP_READ_UNLOCK(stcb->sctp_ep); 5808f8829a4aSRandall Stewart } 58097898f408SRandall Stewart /* 58107898f408SRandall Stewart * Now slide thing forward. 58117898f408SRandall Stewart */ 58127898f408SRandall Stewart sctp_slide_mapping_arrays(stcb); 58137898f408SRandall Stewart 5814139bc87fSRandall Stewart if (TAILQ_FIRST(&asoc->reasmqueue)) { 5815139bc87fSRandall Stewart /* now lets kick out and check for more fragmented delivery */ 581604ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 5817139bc87fSRandall Stewart sctp_deliver_reasm_check(stcb, &stcb->asoc); 5818139bc87fSRandall Stewart } 5819f8829a4aSRandall Stewart } 5820