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 */ 9444fbe462SRandall Stewart calc = sctp_sbspace_sub(calc, (uint32_t) (asoc->size_on_reasm_queue + 9544fbe462SRandall Stewart asoc->cnt_on_reasm_queue * MSIZE)); 9644fbe462SRandall Stewart calc = sctp_sbspace_sub(calc, (uint32_t) (asoc->size_on_all_streams + 9744fbe462SRandall 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; 301*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(cumackp1, 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); 318*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 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 */ 323*20b07a4dSMichael Tuexen for (i = tsn - 1; SCTP_TSN_GE(i, asoc->mapping_array_base_tsn); i--) { 32477acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, i, asoc->mapping_array_base_tsn); 32577acdc25SRandall Stewart if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) { 32677acdc25SRandall Stewart asoc->highest_tsn_inside_map = i; 32777acdc25SRandall Stewart fnd = 1; 32877acdc25SRandall Stewart break; 32977acdc25SRandall Stewart } 33077acdc25SRandall Stewart } 33177acdc25SRandall Stewart if (!fnd) { 33277acdc25SRandall Stewart asoc->highest_tsn_inside_map = asoc->mapping_array_base_tsn - 1; 33377acdc25SRandall Stewart } 33477acdc25SRandall Stewart } 33577acdc25SRandall Stewart } 33677acdc25SRandall Stewart 33717205eccSRandall Stewart 338f8829a4aSRandall Stewart /* 339f8829a4aSRandall Stewart * We are delivering currently from the reassembly queue. We must continue to 340f8829a4aSRandall Stewart * deliver until we either: 1) run out of space. 2) run out of sequential 341f8829a4aSRandall Stewart * TSN's 3) hit the SCTP_DATA_LAST_FRAG flag. 342f8829a4aSRandall Stewart */ 343f8829a4aSRandall Stewart static void 344f8829a4aSRandall Stewart sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc) 345f8829a4aSRandall Stewart { 3464a9ef3f8SMichael Tuexen struct sctp_tmit_chunk *chk, *nchk; 347f8829a4aSRandall Stewart uint16_t nxt_todel; 348f8829a4aSRandall Stewart uint16_t stream_no; 349f8829a4aSRandall Stewart int end = 0; 350f8829a4aSRandall Stewart int cntDel; 3514a9ef3f8SMichael Tuexen struct sctp_queued_to_read *control, *ctl, *nctl; 352f8829a4aSRandall Stewart 353ad81507eSRandall Stewart if (stcb == NULL) 354ad81507eSRandall Stewart return; 355ad81507eSRandall Stewart 356f42a358aSRandall Stewart cntDel = stream_no = 0; 357ad81507eSRandall Stewart if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || 358851b7298SRandall Stewart (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) || 359ad81507eSRandall Stewart (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) { 360851b7298SRandall Stewart /* socket above is long gone or going.. */ 361851b7298SRandall Stewart abandon: 362f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 3634a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) { 364f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 365f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 366f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 367f8829a4aSRandall Stewart /* 368f8829a4aSRandall Stewart * Lose the data pointer, since its in the socket 369f8829a4aSRandall Stewart * buffer 370f8829a4aSRandall Stewart */ 371f8829a4aSRandall Stewart if (chk->data) { 372f8829a4aSRandall Stewart sctp_m_freem(chk->data); 373f8829a4aSRandall Stewart chk->data = NULL; 374f8829a4aSRandall Stewart } 375f8829a4aSRandall Stewart /* Now free the address and data */ 376f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 3773c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 378f8829a4aSRandall Stewart } 379f8829a4aSRandall Stewart return; 380f8829a4aSRandall Stewart } 381f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 3824a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) { 383f8829a4aSRandall Stewart if (chk->rec.data.TSN_seq != (asoc->tsn_last_delivered + 1)) { 384f8829a4aSRandall Stewart /* Can't deliver more :< */ 385f8829a4aSRandall Stewart return; 386f8829a4aSRandall Stewart } 387f8829a4aSRandall Stewart stream_no = chk->rec.data.stream_number; 388f8829a4aSRandall Stewart nxt_todel = asoc->strmin[stream_no].last_sequence_delivered + 1; 389f8829a4aSRandall Stewart if (nxt_todel != chk->rec.data.stream_seq && 390f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { 391f8829a4aSRandall Stewart /* 392f8829a4aSRandall Stewart * Not the next sequence to deliver in its stream OR 393f8829a4aSRandall Stewart * unordered 394f8829a4aSRandall Stewart */ 395f8829a4aSRandall Stewart return; 396f8829a4aSRandall Stewart } 397f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 398f8829a4aSRandall Stewart 399f8829a4aSRandall Stewart control = sctp_build_readq_entry_chk(stcb, chk); 400f8829a4aSRandall Stewart if (control == NULL) { 401f8829a4aSRandall Stewart /* out of memory? */ 402f8829a4aSRandall Stewart return; 403f8829a4aSRandall Stewart } 404f8829a4aSRandall Stewart /* save it off for our future deliveries */ 405f8829a4aSRandall Stewart stcb->asoc.control_pdapi = control; 406f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) 407f8829a4aSRandall Stewart end = 1; 408f8829a4aSRandall Stewart else 409f8829a4aSRandall Stewart end = 0; 410b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq); 411f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, 412cfde3ff7SRandall Stewart stcb, control, &stcb->sctp_socket->so_rcv, end, 413cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 414f8829a4aSRandall Stewart cntDel++; 415f8829a4aSRandall Stewart } else { 416f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) 417f8829a4aSRandall Stewart end = 1; 418f8829a4aSRandall Stewart else 419f8829a4aSRandall Stewart end = 0; 420b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq); 421f8829a4aSRandall Stewart if (sctp_append_to_readq(stcb->sctp_ep, stcb, 422f8829a4aSRandall Stewart stcb->asoc.control_pdapi, 423f8829a4aSRandall Stewart chk->data, end, chk->rec.data.TSN_seq, 424f8829a4aSRandall Stewart &stcb->sctp_socket->so_rcv)) { 425f8829a4aSRandall Stewart /* 426f8829a4aSRandall Stewart * something is very wrong, either 427f8829a4aSRandall Stewart * control_pdapi is NULL, or the tail_mbuf 428f8829a4aSRandall Stewart * is corrupt, or there is a EOM already on 429f8829a4aSRandall Stewart * the mbuf chain. 430f8829a4aSRandall Stewart */ 431851b7298SRandall Stewart if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { 432851b7298SRandall Stewart goto abandon; 433851b7298SRandall Stewart } else { 434df6e0cc3SRandall Stewart #ifdef INVARIANTS 435ad81507eSRandall Stewart if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) { 436f8829a4aSRandall Stewart panic("This should not happen control_pdapi NULL?"); 437f8829a4aSRandall Stewart } 438f8829a4aSRandall Stewart /* if we did not panic, it was a EOM */ 439f8829a4aSRandall Stewart panic("Bad chunking ??"); 440df6e0cc3SRandall Stewart #else 441df6e0cc3SRandall Stewart if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) { 442df6e0cc3SRandall Stewart SCTP_PRINTF("This should not happen control_pdapi NULL?\n"); 443df6e0cc3SRandall Stewart } 444df6e0cc3SRandall Stewart SCTP_PRINTF("Bad chunking ??\n"); 445df6e0cc3SRandall Stewart SCTP_PRINTF("Dumping re-assembly queue this will probably hose the association\n"); 446df6e0cc3SRandall Stewart 447df6e0cc3SRandall Stewart #endif 448df6e0cc3SRandall Stewart goto abandon; 449f8829a4aSRandall Stewart } 450851b7298SRandall Stewart } 451f8829a4aSRandall Stewart cntDel++; 452f8829a4aSRandall Stewart } 453f8829a4aSRandall Stewart /* pull it we did it */ 454f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 455f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 456f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 457f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { 458f8829a4aSRandall Stewart asoc->strmin[stream_no].last_sequence_delivered++; 459f8829a4aSRandall Stewart } 460f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { 461f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); 462f8829a4aSRandall Stewart } 463f8829a4aSRandall Stewart } else if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 464f8829a4aSRandall Stewart /* 465f8829a4aSRandall Stewart * turn the flag back on since we just delivered 466f8829a4aSRandall Stewart * yet another one. 467f8829a4aSRandall Stewart */ 468f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 469f8829a4aSRandall Stewart } 470f8829a4aSRandall Stewart asoc->tsn_of_pdapi_last_delivered = chk->rec.data.TSN_seq; 471f8829a4aSRandall Stewart asoc->last_flags_delivered = chk->rec.data.rcv_flags; 472f8829a4aSRandall Stewart asoc->last_strm_seq_delivered = chk->rec.data.stream_seq; 473f8829a4aSRandall Stewart asoc->last_strm_no_delivered = chk->rec.data.stream_number; 474f8829a4aSRandall Stewart 475f8829a4aSRandall Stewart asoc->tsn_last_delivered = chk->rec.data.TSN_seq; 476f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 477f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 478f8829a4aSRandall Stewart /* free up the chk */ 479f8829a4aSRandall Stewart chk->data = NULL; 480f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 481f8829a4aSRandall Stewart 482f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 483f8829a4aSRandall Stewart /* 484f8829a4aSRandall Stewart * Now lets see if we can deliver the next one on 485f8829a4aSRandall Stewart * the stream 486f8829a4aSRandall Stewart */ 487f8829a4aSRandall Stewart struct sctp_stream_in *strm; 488f8829a4aSRandall Stewart 489f8829a4aSRandall Stewart strm = &asoc->strmin[stream_no]; 490f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 4914a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ctl, &strm->inqueue, next, nctl) { 492f8829a4aSRandall Stewart /* Deliver more if we can. */ 493f8829a4aSRandall Stewart if (nxt_todel == ctl->sinfo_ssn) { 494f8829a4aSRandall Stewart TAILQ_REMOVE(&strm->inqueue, ctl, next); 495f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 496f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 497f8829a4aSRandall Stewart strm->last_sequence_delivered++; 498b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 499f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 500f8829a4aSRandall Stewart ctl, 501cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 502cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 503f8829a4aSRandall Stewart } else { 504f8829a4aSRandall Stewart break; 505f8829a4aSRandall Stewart } 506f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 507f8829a4aSRandall Stewart } 508139bc87fSRandall Stewart break; 509f8829a4aSRandall Stewart } 5104a9ef3f8SMichael Tuexen } 511f8829a4aSRandall Stewart } 512f8829a4aSRandall Stewart 513f8829a4aSRandall Stewart /* 514f8829a4aSRandall Stewart * Queue the chunk either right into the socket buffer if it is the next one 515f8829a4aSRandall Stewart * to go OR put it in the correct place in the delivery queue. If we do 516f8829a4aSRandall Stewart * append to the so_buf, keep doing so until we are out of order. One big 517f8829a4aSRandall Stewart * question still remains, what to do when the socket buffer is FULL?? 518f8829a4aSRandall Stewart */ 519f8829a4aSRandall Stewart static void 520f8829a4aSRandall Stewart sctp_queue_data_to_stream(struct sctp_tcb *stcb, struct sctp_association *asoc, 521f8829a4aSRandall Stewart struct sctp_queued_to_read *control, int *abort_flag) 522f8829a4aSRandall Stewart { 523f8829a4aSRandall Stewart /* 524f8829a4aSRandall Stewart * FIX-ME maybe? What happens when the ssn wraps? If we are getting 525f8829a4aSRandall Stewart * all the data in one stream this could happen quite rapidly. One 526f8829a4aSRandall Stewart * could use the TSN to keep track of things, but this scheme breaks 527f8829a4aSRandall Stewart * down in the other type of stream useage that could occur. Send a 528f8829a4aSRandall Stewart * single msg to stream 0, send 4Billion messages to stream 1, now 529f8829a4aSRandall Stewart * send a message to stream 0. You have a situation where the TSN 530f8829a4aSRandall Stewart * has wrapped but not in the stream. Is this worth worrying about 531f8829a4aSRandall Stewart * or should we just change our queue sort at the bottom to be by 532f8829a4aSRandall Stewart * TSN. 533f8829a4aSRandall Stewart * 534f8829a4aSRandall Stewart * Could it also be legal for a peer to send ssn 1 with TSN 2 and ssn 2 535f8829a4aSRandall Stewart * with TSN 1? If the peer is doing some sort of funky TSN/SSN 536f8829a4aSRandall Stewart * assignment this could happen... and I don't see how this would be 537f8829a4aSRandall Stewart * a violation. So for now I am undecided an will leave the sort by 538f8829a4aSRandall Stewart * SSN alone. Maybe a hybred approach is the answer 539f8829a4aSRandall Stewart * 540f8829a4aSRandall Stewart */ 541f8829a4aSRandall Stewart struct sctp_stream_in *strm; 542f8829a4aSRandall Stewart struct sctp_queued_to_read *at; 543f8829a4aSRandall Stewart int queue_needed; 544f8829a4aSRandall Stewart uint16_t nxt_todel; 545f8829a4aSRandall Stewart struct mbuf *oper; 546f8829a4aSRandall Stewart 547f8829a4aSRandall Stewart queue_needed = 1; 548f8829a4aSRandall Stewart asoc->size_on_all_streams += control->length; 549f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_all_streams); 550f8829a4aSRandall Stewart strm = &asoc->strmin[control->sinfo_stream]; 551f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 552b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 553f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD); 55480fefe0aSRandall Stewart } 555ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, 556ad81507eSRandall Stewart "queue to stream called for ssn:%u lastdel:%u nxt:%u\n", 557f8829a4aSRandall Stewart (uint32_t) control->sinfo_stream, 558ad81507eSRandall Stewart (uint32_t) strm->last_sequence_delivered, 559ad81507eSRandall Stewart (uint32_t) nxt_todel); 560*20b07a4dSMichael Tuexen if (SCTP_SSN_GE(strm->last_sequence_delivered, control->sinfo_ssn)) { 561f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 562ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ:%d delivered:%d from peer, Abort association\n", 563ad81507eSRandall Stewart control->sinfo_ssn, strm->last_sequence_delivered); 564c40e9cf2SRandall Stewart protocol_error: 565f8829a4aSRandall Stewart /* 566f8829a4aSRandall Stewart * throw it in the stream so it gets cleaned up in 567f8829a4aSRandall Stewart * association destruction 568f8829a4aSRandall Stewart */ 569f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&strm->inqueue, control, next); 570139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 571f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 572f8829a4aSRandall Stewart if (oper) { 573f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 574f8829a4aSRandall Stewart uint32_t *ippp; 575f8829a4aSRandall Stewart 576139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 577f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 578f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 579f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 580139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 581f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 582a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_1); 583f8829a4aSRandall Stewart ippp++; 584f8829a4aSRandall Stewart *ippp = control->sinfo_tsn; 585f8829a4aSRandall Stewart ippp++; 586f8829a4aSRandall Stewart *ippp = ((control->sinfo_stream << 16) | control->sinfo_ssn); 587f8829a4aSRandall Stewart } 588a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_1; 589f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 590ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 591f8829a4aSRandall Stewart 592f8829a4aSRandall Stewart *abort_flag = 1; 593f8829a4aSRandall Stewart return; 594f8829a4aSRandall Stewart 595f8829a4aSRandall Stewart } 596f8829a4aSRandall Stewart if (nxt_todel == control->sinfo_ssn) { 597f8829a4aSRandall Stewart /* can be delivered right away? */ 598b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 599f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_IMMED_DEL); 60080fefe0aSRandall Stewart } 601830d754dSRandall Stewart /* EY it wont be queued if it could be delivered directly */ 602f8829a4aSRandall Stewart queue_needed = 0; 603f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 604f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 605f8829a4aSRandall Stewart strm->last_sequence_delivered++; 60677acdc25SRandall Stewart 607b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 608f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 609f8829a4aSRandall Stewart control, 610cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 611cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 6124a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(control, &strm->inqueue, next, at) { 613f8829a4aSRandall Stewart /* all delivered */ 614f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 615f8829a4aSRandall Stewart if (nxt_todel == control->sinfo_ssn) { 616f8829a4aSRandall Stewart TAILQ_REMOVE(&strm->inqueue, control, next); 617f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 618f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 619f8829a4aSRandall Stewart strm->last_sequence_delivered++; 620f8829a4aSRandall Stewart /* 621f8829a4aSRandall Stewart * We ignore the return of deliver_data here 622f8829a4aSRandall Stewart * since we always can hold the chunk on the 623f8829a4aSRandall Stewart * d-queue. And we have a finite number that 624f8829a4aSRandall Stewart * can be delivered from the strq. 625f8829a4aSRandall Stewart */ 626b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 627f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, 628f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_IMMED_DEL); 62980fefe0aSRandall Stewart } 630b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 631f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 632f8829a4aSRandall Stewart control, 633cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 634cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, 635cfde3ff7SRandall Stewart SCTP_SO_NOT_LOCKED); 636f8829a4aSRandall Stewart continue; 637f8829a4aSRandall Stewart } 638f8829a4aSRandall Stewart break; 639f8829a4aSRandall Stewart } 640f8829a4aSRandall Stewart } 641f8829a4aSRandall Stewart if (queue_needed) { 642f8829a4aSRandall Stewart /* 643f8829a4aSRandall Stewart * Ok, we did not deliver this guy, find the correct place 644f8829a4aSRandall Stewart * to put it on the queue. 645f8829a4aSRandall Stewart */ 646*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->cumulative_tsn, control->sinfo_tsn)) { 647c40e9cf2SRandall Stewart goto protocol_error; 648c40e9cf2SRandall Stewart } 649f8829a4aSRandall Stewart if (TAILQ_EMPTY(&strm->inqueue)) { 650f8829a4aSRandall Stewart /* Empty queue */ 651b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 652f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INSERT_HD); 65380fefe0aSRandall Stewart } 654f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&strm->inqueue, control, next); 655f8829a4aSRandall Stewart } else { 656f8829a4aSRandall Stewart TAILQ_FOREACH(at, &strm->inqueue, next) { 657*20b07a4dSMichael Tuexen if (SCTP_SSN_GT(at->sinfo_ssn, control->sinfo_ssn)) { 658f8829a4aSRandall Stewart /* 659f8829a4aSRandall Stewart * one in queue is bigger than the 660f8829a4aSRandall Stewart * new one, insert before this one 661f8829a4aSRandall Stewart */ 662b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 663f8829a4aSRandall Stewart sctp_log_strm_del(control, at, 664f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_INSERT_MD); 66580fefe0aSRandall Stewart } 666f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(at, control, next); 667f8829a4aSRandall Stewart break; 668f8829a4aSRandall Stewart } else if (at->sinfo_ssn == control->sinfo_ssn) { 669f8829a4aSRandall Stewart /* 670f8829a4aSRandall Stewart * Gak, He sent me a duplicate str 671f8829a4aSRandall Stewart * seq number 672f8829a4aSRandall Stewart */ 673f8829a4aSRandall Stewart /* 674f8829a4aSRandall Stewart * foo bar, I guess I will just free 675f8829a4aSRandall Stewart * this new guy, should we abort 676f8829a4aSRandall Stewart * too? FIX ME MAYBE? Or it COULD be 677f8829a4aSRandall Stewart * that the SSN's have wrapped. 678f8829a4aSRandall Stewart * Maybe I should compare to TSN 679f8829a4aSRandall Stewart * somehow... sigh for now just blow 680f8829a4aSRandall Stewart * away the chunk! 681f8829a4aSRandall Stewart */ 682f8829a4aSRandall Stewart 683f8829a4aSRandall Stewart if (control->data) 684f8829a4aSRandall Stewart sctp_m_freem(control->data); 685f8829a4aSRandall Stewart control->data = NULL; 686f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 687f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 68824f52bbdSMichael Tuexen if (control->whoFrom) { 689f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 6905bead436SRandall Stewart control->whoFrom = NULL; 69124f52bbdSMichael Tuexen } 692f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 693f8829a4aSRandall Stewart return; 694f8829a4aSRandall Stewart } else { 695f8829a4aSRandall Stewart if (TAILQ_NEXT(at, next) == NULL) { 696f8829a4aSRandall Stewart /* 697f8829a4aSRandall Stewart * We are at the end, insert 698f8829a4aSRandall Stewart * it after this one 699f8829a4aSRandall Stewart */ 700b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 701f8829a4aSRandall Stewart sctp_log_strm_del(control, at, 702f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_INSERT_TL); 70380fefe0aSRandall Stewart } 704f8829a4aSRandall Stewart TAILQ_INSERT_AFTER(&strm->inqueue, 705f8829a4aSRandall Stewart at, control, next); 706f8829a4aSRandall Stewart break; 707f8829a4aSRandall Stewart } 708f8829a4aSRandall Stewart } 709f8829a4aSRandall Stewart } 710f8829a4aSRandall Stewart } 711f8829a4aSRandall Stewart } 712f8829a4aSRandall Stewart } 713f8829a4aSRandall Stewart 714f8829a4aSRandall Stewart /* 715f8829a4aSRandall Stewart * Returns two things: You get the total size of the deliverable parts of the 716f8829a4aSRandall Stewart * first fragmented message on the reassembly queue. And you get a 1 back if 717f8829a4aSRandall Stewart * all of the message is ready or a 0 back if the message is still incomplete 718f8829a4aSRandall Stewart */ 719f8829a4aSRandall Stewart static int 720f8829a4aSRandall Stewart sctp_is_all_msg_on_reasm(struct sctp_association *asoc, uint32_t * t_size) 721f8829a4aSRandall Stewart { 722f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 723f8829a4aSRandall Stewart uint32_t tsn; 724f8829a4aSRandall Stewart 725f8829a4aSRandall Stewart *t_size = 0; 726f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 727f8829a4aSRandall Stewart if (chk == NULL) { 728f8829a4aSRandall Stewart /* nothing on the queue */ 729f8829a4aSRandall Stewart return (0); 730f8829a4aSRandall Stewart } 731f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { 732f8829a4aSRandall Stewart /* Not a first on the queue */ 733f8829a4aSRandall Stewart return (0); 734f8829a4aSRandall Stewart } 735f8829a4aSRandall Stewart tsn = chk->rec.data.TSN_seq; 7364a9ef3f8SMichael Tuexen TAILQ_FOREACH(chk, &asoc->reasmqueue, sctp_next) { 737f8829a4aSRandall Stewart if (tsn != chk->rec.data.TSN_seq) { 738f8829a4aSRandall Stewart return (0); 739f8829a4aSRandall Stewart } 740f8829a4aSRandall Stewart *t_size += chk->send_size; 741f8829a4aSRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 742f8829a4aSRandall Stewart return (1); 743f8829a4aSRandall Stewart } 744f8829a4aSRandall Stewart tsn++; 745f8829a4aSRandall Stewart } 746f8829a4aSRandall Stewart return (0); 747f8829a4aSRandall Stewart } 748f8829a4aSRandall Stewart 749f8829a4aSRandall Stewart static void 750f8829a4aSRandall Stewart sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc) 751f8829a4aSRandall Stewart { 752f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 753f8829a4aSRandall Stewart uint16_t nxt_todel; 754810ec536SMichael Tuexen uint32_t tsize, pd_point; 755f8829a4aSRandall Stewart 756139bc87fSRandall Stewart doit_again: 757f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 758f8829a4aSRandall Stewart if (chk == NULL) { 759f8829a4aSRandall Stewart /* Huh? */ 760f8829a4aSRandall Stewart asoc->size_on_reasm_queue = 0; 761f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue = 0; 762f8829a4aSRandall Stewart return; 763f8829a4aSRandall Stewart } 764f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 765f8829a4aSRandall Stewart nxt_todel = 766f8829a4aSRandall Stewart asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1; 767f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) && 768f8829a4aSRandall Stewart (nxt_todel == chk->rec.data.stream_seq || 769f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) { 770f8829a4aSRandall Stewart /* 771f8829a4aSRandall Stewart * Yep the first one is here and its ok to deliver 772f8829a4aSRandall Stewart * but should we? 773f8829a4aSRandall Stewart */ 774810ec536SMichael Tuexen if (stcb->sctp_socket) { 77524ae5c4aSMichael Tuexen pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), 776810ec536SMichael Tuexen stcb->sctp_ep->partial_delivery_point); 777810ec536SMichael Tuexen } else { 778810ec536SMichael Tuexen pd_point = stcb->sctp_ep->partial_delivery_point; 779810ec536SMichael Tuexen } 780810ec536SMichael Tuexen if (sctp_is_all_msg_on_reasm(asoc, &tsize) || (tsize >= pd_point)) { 781f8829a4aSRandall Stewart 782f8829a4aSRandall Stewart /* 783f8829a4aSRandall Stewart * Yes, we setup to start reception, by 784f8829a4aSRandall Stewart * backing down the TSN just in case we 785f8829a4aSRandall Stewart * can't deliver. If we 786f8829a4aSRandall Stewart */ 787f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 788f8829a4aSRandall Stewart asoc->tsn_last_delivered = 789f8829a4aSRandall Stewart chk->rec.data.TSN_seq - 1; 790f8829a4aSRandall Stewart asoc->str_of_pdapi = 791f8829a4aSRandall Stewart chk->rec.data.stream_number; 792f8829a4aSRandall Stewart asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 793f8829a4aSRandall Stewart asoc->pdapi_ppid = chk->rec.data.payloadtype; 794f8829a4aSRandall Stewart asoc->fragment_flags = chk->rec.data.rcv_flags; 795f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 796f8829a4aSRandall Stewart } 797f8829a4aSRandall Stewart } 798f8829a4aSRandall Stewart } else { 799139bc87fSRandall Stewart /* 800139bc87fSRandall Stewart * Service re-assembly will deliver stream data queued at 801139bc87fSRandall Stewart * the end of fragmented delivery.. but it wont know to go 802139bc87fSRandall Stewart * back and call itself again... we do that here with the 803139bc87fSRandall Stewart * got doit_again 804139bc87fSRandall Stewart */ 805f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 806139bc87fSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 807139bc87fSRandall Stewart /* 808139bc87fSRandall Stewart * finished our Fragmented delivery, could be more 809139bc87fSRandall Stewart * waiting? 810139bc87fSRandall Stewart */ 811139bc87fSRandall Stewart goto doit_again; 812139bc87fSRandall Stewart } 813f8829a4aSRandall Stewart } 814f8829a4aSRandall Stewart } 815f8829a4aSRandall Stewart 816f8829a4aSRandall Stewart /* 817f8829a4aSRandall Stewart * Dump onto the re-assembly queue, in its proper place. After dumping on the 818f8829a4aSRandall Stewart * queue, see if anthing can be delivered. If so pull it off (or as much as 819f8829a4aSRandall Stewart * we can. If we run out of space then we must dump what we can and set the 820f8829a4aSRandall Stewart * appropriate flag to say we queued what we could. 821f8829a4aSRandall Stewart */ 822f8829a4aSRandall Stewart static void 823f8829a4aSRandall Stewart sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, 824f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk, int *abort_flag) 825f8829a4aSRandall Stewart { 826f8829a4aSRandall Stewart struct mbuf *oper; 827f8829a4aSRandall Stewart uint32_t cum_ackp1, last_tsn, prev_tsn, post_tsn; 828f8829a4aSRandall Stewart u_char last_flags; 829f8829a4aSRandall Stewart struct sctp_tmit_chunk *at, *prev, *next; 830f8829a4aSRandall Stewart 831f8829a4aSRandall Stewart prev = next = NULL; 832f8829a4aSRandall Stewart cum_ackp1 = asoc->tsn_last_delivered + 1; 833f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue)) { 834f8829a4aSRandall Stewart /* This is the first one on the queue */ 835f8829a4aSRandall Stewart TAILQ_INSERT_HEAD(&asoc->reasmqueue, chk, sctp_next); 836f8829a4aSRandall Stewart /* 837f8829a4aSRandall Stewart * we do not check for delivery of anything when only one 838f8829a4aSRandall Stewart * fragment is here 839f8829a4aSRandall Stewart */ 840f8829a4aSRandall Stewart asoc->size_on_reasm_queue = chk->send_size; 841f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 842f8829a4aSRandall Stewart if (chk->rec.data.TSN_seq == cum_ackp1) { 843f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0 && 844f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) != 845f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 846f8829a4aSRandall Stewart /* 847f8829a4aSRandall Stewart * An empty queue, no delivery inprogress, 848f8829a4aSRandall Stewart * we hit the next one and it does NOT have 849f8829a4aSRandall Stewart * a FIRST fragment mark. 850f8829a4aSRandall Stewart */ 851ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not first, no fragmented delivery in progress\n"); 852139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 853f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 854f8829a4aSRandall Stewart 855f8829a4aSRandall Stewart if (oper) { 856f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 857f8829a4aSRandall Stewart uint32_t *ippp; 858f8829a4aSRandall Stewart 859139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 860f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 861f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 862f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 863f8829a4aSRandall Stewart ph->param_type = 864f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 865139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 866f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 867a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_2); 868f8829a4aSRandall Stewart ippp++; 869f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 870f8829a4aSRandall Stewart ippp++; 871f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 872f8829a4aSRandall Stewart 873f8829a4aSRandall Stewart } 874a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2; 875f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 876ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 877f8829a4aSRandall Stewart *abort_flag = 1; 878f8829a4aSRandall Stewart } else if (asoc->fragmented_delivery_inprogress && 879f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) { 880f8829a4aSRandall Stewart /* 881f8829a4aSRandall Stewart * We are doing a partial delivery and the 882f8829a4aSRandall Stewart * NEXT chunk MUST be either the LAST or 883f8829a4aSRandall Stewart * MIDDLE fragment NOT a FIRST 884f8829a4aSRandall Stewart */ 885ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS a first and fragmented delivery in progress\n"); 886139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 887f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 888f8829a4aSRandall Stewart if (oper) { 889f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 890f8829a4aSRandall Stewart uint32_t *ippp; 891f8829a4aSRandall Stewart 892139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 893f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 894f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 895f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 896f8829a4aSRandall Stewart ph->param_type = 897f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 898139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 899f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 900a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_3); 901f8829a4aSRandall Stewart ippp++; 902f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 903f8829a4aSRandall Stewart ippp++; 904f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 905f8829a4aSRandall Stewart } 906a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_3; 907f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 908ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 909f8829a4aSRandall Stewart *abort_flag = 1; 910f8829a4aSRandall Stewart } else if (asoc->fragmented_delivery_inprogress) { 911f8829a4aSRandall Stewart /* 912f8829a4aSRandall Stewart * Here we are ok with a MIDDLE or LAST 913f8829a4aSRandall Stewart * piece 914f8829a4aSRandall Stewart */ 915f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 916f8829a4aSRandall Stewart asoc->str_of_pdapi) { 917f8829a4aSRandall Stewart /* Got to be the right STR No */ 918ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream number %d vs %d\n", 919f8829a4aSRandall Stewart chk->rec.data.stream_number, 920f8829a4aSRandall Stewart asoc->str_of_pdapi); 921139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 922f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 923f8829a4aSRandall Stewart if (oper) { 924f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 925f8829a4aSRandall Stewart uint32_t *ippp; 926f8829a4aSRandall Stewart 927139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 928f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 929f8829a4aSRandall Stewart (sizeof(uint32_t) * 3); 930f8829a4aSRandall Stewart ph = mtod(oper, 931f8829a4aSRandall Stewart struct sctp_paramhdr *); 932f8829a4aSRandall Stewart ph->param_type = 933f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 934f8829a4aSRandall Stewart ph->param_length = 935139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 936f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 937a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_4); 938f8829a4aSRandall Stewart ippp++; 939f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 940f8829a4aSRandall Stewart ippp++; 941f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 942f8829a4aSRandall Stewart } 943a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_4; 944f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 945ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 946f8829a4aSRandall Stewart *abort_flag = 1; 947f8829a4aSRandall Stewart } else if ((asoc->fragment_flags & SCTP_DATA_UNORDERED) != 948f8829a4aSRandall Stewart SCTP_DATA_UNORDERED && 949b5c16493SMichael Tuexen chk->rec.data.stream_seq != asoc->ssn_of_pdapi) { 950f8829a4aSRandall Stewart /* Got to be the right STR Seq */ 951ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream seq %d vs %d\n", 952f8829a4aSRandall Stewart chk->rec.data.stream_seq, 953f8829a4aSRandall Stewart asoc->ssn_of_pdapi); 954139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 955f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 956f8829a4aSRandall Stewart if (oper) { 957f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 958f8829a4aSRandall Stewart uint32_t *ippp; 959f8829a4aSRandall Stewart 960139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 961f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 962f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 963f8829a4aSRandall Stewart ph = mtod(oper, 964f8829a4aSRandall Stewart struct sctp_paramhdr *); 965f8829a4aSRandall Stewart ph->param_type = 966f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 967f8829a4aSRandall Stewart ph->param_length = 968139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 969f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 970a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_5); 971f8829a4aSRandall Stewart ippp++; 972f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 973f8829a4aSRandall Stewart ippp++; 974f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 975f8829a4aSRandall Stewart 976f8829a4aSRandall Stewart } 977a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_5; 978f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 979ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 980f8829a4aSRandall Stewart *abort_flag = 1; 981f8829a4aSRandall Stewart } 982f8829a4aSRandall Stewart } 983f8829a4aSRandall Stewart } 984f8829a4aSRandall Stewart return; 985f8829a4aSRandall Stewart } 986f8829a4aSRandall Stewart /* Find its place */ 987f8829a4aSRandall Stewart TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) { 988*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(at->rec.data.TSN_seq, chk->rec.data.TSN_seq)) { 989f8829a4aSRandall Stewart /* 990f8829a4aSRandall Stewart * one in queue is bigger than the new one, insert 991f8829a4aSRandall Stewart * before this one 992f8829a4aSRandall Stewart */ 993f8829a4aSRandall Stewart /* A check */ 994f8829a4aSRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 995f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 996f8829a4aSRandall Stewart next = at; 997f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(at, chk, sctp_next); 998f8829a4aSRandall Stewart break; 999f8829a4aSRandall Stewart } else if (at->rec.data.TSN_seq == chk->rec.data.TSN_seq) { 1000f8829a4aSRandall Stewart /* Gak, He sent me a duplicate str seq number */ 1001f8829a4aSRandall Stewart /* 1002f8829a4aSRandall Stewart * foo bar, I guess I will just free this new guy, 1003f8829a4aSRandall Stewart * should we abort too? FIX ME MAYBE? Or it COULD be 1004f8829a4aSRandall Stewart * that the SSN's have wrapped. Maybe I should 1005f8829a4aSRandall Stewart * compare to TSN somehow... sigh for now just blow 1006f8829a4aSRandall Stewart * away the chunk! 1007f8829a4aSRandall Stewart */ 1008f8829a4aSRandall Stewart if (chk->data) { 1009f8829a4aSRandall Stewart sctp_m_freem(chk->data); 1010f8829a4aSRandall Stewart chk->data = NULL; 1011f8829a4aSRandall Stewart } 1012f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 1013f8829a4aSRandall Stewart return; 1014f8829a4aSRandall Stewart } else { 1015f8829a4aSRandall Stewart last_flags = at->rec.data.rcv_flags; 1016f8829a4aSRandall Stewart last_tsn = at->rec.data.TSN_seq; 1017f8829a4aSRandall Stewart prev = at; 1018f8829a4aSRandall Stewart if (TAILQ_NEXT(at, sctp_next) == NULL) { 1019f8829a4aSRandall Stewart /* 1020f8829a4aSRandall Stewart * We are at the end, insert it after this 1021f8829a4aSRandall Stewart * one 1022f8829a4aSRandall Stewart */ 1023f8829a4aSRandall Stewart /* check it first */ 1024f8829a4aSRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 1025f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 1026f8829a4aSRandall Stewart TAILQ_INSERT_AFTER(&asoc->reasmqueue, at, chk, sctp_next); 1027f8829a4aSRandall Stewart break; 1028f8829a4aSRandall Stewart } 1029f8829a4aSRandall Stewart } 1030f8829a4aSRandall Stewart } 1031f8829a4aSRandall Stewart /* Now the audits */ 1032f8829a4aSRandall Stewart if (prev) { 1033f8829a4aSRandall Stewart prev_tsn = chk->rec.data.TSN_seq - 1; 1034f8829a4aSRandall Stewart if (prev_tsn == prev->rec.data.TSN_seq) { 1035f8829a4aSRandall Stewart /* 1036f8829a4aSRandall Stewart * Ok the one I am dropping onto the end is the 1037f8829a4aSRandall Stewart * NEXT. A bit of valdiation here. 1038f8829a4aSRandall Stewart */ 1039f8829a4aSRandall Stewart if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1040f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG || 1041f8829a4aSRandall Stewart (prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1042f8829a4aSRandall Stewart SCTP_DATA_MIDDLE_FRAG) { 1043f8829a4aSRandall Stewart /* 1044f8829a4aSRandall Stewart * Insert chk MUST be a MIDDLE or LAST 1045f8829a4aSRandall Stewart * fragment 1046f8829a4aSRandall Stewart */ 1047f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1048f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1049ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - It can be a midlle or last but not a first\n"); 1050ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it's a FIRST!\n"); 1051139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1052f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1053f8829a4aSRandall Stewart if (oper) { 1054f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1055f8829a4aSRandall Stewart uint32_t *ippp; 1056f8829a4aSRandall Stewart 1057139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1058f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1059f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1060f8829a4aSRandall Stewart ph = mtod(oper, 1061f8829a4aSRandall Stewart struct sctp_paramhdr *); 1062f8829a4aSRandall Stewart ph->param_type = 1063f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1064f8829a4aSRandall Stewart ph->param_length = 1065139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1066f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1067a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_6); 1068f8829a4aSRandall Stewart ippp++; 1069f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1070f8829a4aSRandall Stewart ippp++; 1071f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1072f8829a4aSRandall Stewart 1073f8829a4aSRandall Stewart } 1074a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_6; 1075f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1076ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1077f8829a4aSRandall Stewart *abort_flag = 1; 1078f8829a4aSRandall Stewart return; 1079f8829a4aSRandall Stewart } 1080f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 1081f8829a4aSRandall Stewart prev->rec.data.stream_number) { 1082f8829a4aSRandall Stewart /* 1083f8829a4aSRandall Stewart * Huh, need the correct STR here, 1084f8829a4aSRandall Stewart * they must be the same. 1085f8829a4aSRandall Stewart */ 1086ad81507eSRandall Stewart SCTP_PRINTF("Prev check - Gak, Evil plot, ssn:%d not the same as at:%d\n", 1087f8829a4aSRandall Stewart chk->rec.data.stream_number, 1088f8829a4aSRandall Stewart prev->rec.data.stream_number); 1089139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1090f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1091f8829a4aSRandall Stewart if (oper) { 1092f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1093f8829a4aSRandall Stewart uint32_t *ippp; 1094f8829a4aSRandall Stewart 1095139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1096f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1097f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1098f8829a4aSRandall Stewart ph = mtod(oper, 1099f8829a4aSRandall Stewart struct sctp_paramhdr *); 1100f8829a4aSRandall Stewart ph->param_type = 1101f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1102f8829a4aSRandall Stewart ph->param_length = 1103139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1104f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1105a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_7); 1106f8829a4aSRandall Stewart ippp++; 1107f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1108f8829a4aSRandall Stewart ippp++; 1109f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1110f8829a4aSRandall Stewart } 1111a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_7; 1112f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1113ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1114f8829a4aSRandall Stewart 1115f8829a4aSRandall Stewart *abort_flag = 1; 1116f8829a4aSRandall Stewart return; 1117f8829a4aSRandall Stewart } 1118f8829a4aSRandall Stewart if ((prev->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 && 1119f8829a4aSRandall Stewart chk->rec.data.stream_seq != 1120f8829a4aSRandall Stewart prev->rec.data.stream_seq) { 1121f8829a4aSRandall Stewart /* 1122f8829a4aSRandall Stewart * Huh, need the correct STR here, 1123f8829a4aSRandall Stewart * they must be the same. 1124f8829a4aSRandall Stewart */ 1125ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, Evil plot, sseq:%d not the same as at:%d\n", 1126f8829a4aSRandall Stewart chk->rec.data.stream_seq, 1127f8829a4aSRandall Stewart prev->rec.data.stream_seq); 1128139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1129f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1130f8829a4aSRandall Stewart if (oper) { 1131f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1132f8829a4aSRandall Stewart uint32_t *ippp; 1133f8829a4aSRandall Stewart 1134139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1135f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1136f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1137f8829a4aSRandall Stewart ph = mtod(oper, 1138f8829a4aSRandall Stewart struct sctp_paramhdr *); 1139f8829a4aSRandall Stewart ph->param_type = 1140f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1141f8829a4aSRandall Stewart ph->param_length = 1142139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1143f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1144a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_8); 1145f8829a4aSRandall Stewart ippp++; 1146f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1147f8829a4aSRandall Stewart ippp++; 1148f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1149f8829a4aSRandall Stewart } 1150a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_8; 1151f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1152ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1153f8829a4aSRandall Stewart 1154f8829a4aSRandall Stewart *abort_flag = 1; 1155f8829a4aSRandall Stewart return; 1156f8829a4aSRandall Stewart } 1157f8829a4aSRandall Stewart } else if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1158f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1159f8829a4aSRandall Stewart /* Insert chk MUST be a FIRST */ 1160f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1161f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1162ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, evil plot, its not FIRST and it must be!\n"); 1163139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1164f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1165f8829a4aSRandall Stewart if (oper) { 1166f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1167f8829a4aSRandall Stewart uint32_t *ippp; 1168f8829a4aSRandall Stewart 1169139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1170f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1171f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1172f8829a4aSRandall Stewart ph = mtod(oper, 1173f8829a4aSRandall Stewart struct sctp_paramhdr *); 1174f8829a4aSRandall Stewart ph->param_type = 1175f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1176f8829a4aSRandall Stewart ph->param_length = 1177139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1178f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1179a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_9); 1180f8829a4aSRandall Stewart ippp++; 1181f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1182f8829a4aSRandall Stewart ippp++; 1183f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1184f8829a4aSRandall Stewart 1185f8829a4aSRandall Stewart } 1186a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_9; 1187f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1188ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1189f8829a4aSRandall Stewart 1190f8829a4aSRandall Stewart *abort_flag = 1; 1191f8829a4aSRandall Stewart return; 1192f8829a4aSRandall Stewart } 1193f8829a4aSRandall Stewart } 1194f8829a4aSRandall Stewart } 1195f8829a4aSRandall Stewart } 1196f8829a4aSRandall Stewart if (next) { 1197f8829a4aSRandall Stewart post_tsn = chk->rec.data.TSN_seq + 1; 1198f8829a4aSRandall Stewart if (post_tsn == next->rec.data.TSN_seq) { 1199f8829a4aSRandall Stewart /* 1200f8829a4aSRandall Stewart * Ok the one I am inserting ahead of is my NEXT 1201f8829a4aSRandall Stewart * one. A bit of valdiation here. 1202f8829a4aSRandall Stewart */ 1203f8829a4aSRandall Stewart if (next->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 1204f8829a4aSRandall Stewart /* Insert chk MUST be a last fragment */ 1205f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) 1206f8829a4aSRandall Stewart != SCTP_DATA_LAST_FRAG) { 1207ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is FIRST, we must be LAST\n"); 1208ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not a last!\n"); 1209139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1210f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1211f8829a4aSRandall Stewart if (oper) { 1212f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1213f8829a4aSRandall Stewart uint32_t *ippp; 1214f8829a4aSRandall Stewart 1215139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1216f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1217f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1218f8829a4aSRandall Stewart ph = mtod(oper, 1219f8829a4aSRandall Stewart struct sctp_paramhdr *); 1220f8829a4aSRandall Stewart ph->param_type = 1221f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1222f8829a4aSRandall Stewart ph->param_length = 1223139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1224f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1225a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_10); 1226f8829a4aSRandall Stewart ippp++; 1227f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1228f8829a4aSRandall Stewart ippp++; 1229f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1230f8829a4aSRandall Stewart } 1231a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_10; 1232f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1233ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1234f8829a4aSRandall Stewart 1235f8829a4aSRandall Stewart *abort_flag = 1; 1236f8829a4aSRandall Stewart return; 1237f8829a4aSRandall Stewart } 1238f8829a4aSRandall Stewart } else if ((next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1239f8829a4aSRandall Stewart SCTP_DATA_MIDDLE_FRAG || 1240f8829a4aSRandall Stewart (next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1241f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1242f8829a4aSRandall Stewart /* 1243f8829a4aSRandall Stewart * Insert chk CAN be MIDDLE or FIRST NOT 1244f8829a4aSRandall Stewart * LAST 1245f8829a4aSRandall Stewart */ 1246f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) == 1247f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1248ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is a MIDDLE/LAST\n"); 1249ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, new prev chunk is a LAST\n"); 1250139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1251f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1252f8829a4aSRandall Stewart if (oper) { 1253f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1254f8829a4aSRandall Stewart uint32_t *ippp; 1255f8829a4aSRandall Stewart 1256139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1257f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1258f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1259f8829a4aSRandall Stewart ph = mtod(oper, 1260f8829a4aSRandall Stewart struct sctp_paramhdr *); 1261f8829a4aSRandall Stewart ph->param_type = 1262f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1263f8829a4aSRandall Stewart ph->param_length = 1264139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1265f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1266a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_11); 1267f8829a4aSRandall Stewart ippp++; 1268f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1269f8829a4aSRandall Stewart ippp++; 1270f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1271f8829a4aSRandall Stewart 1272f8829a4aSRandall Stewart } 1273a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_11; 1274f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1275ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1276f8829a4aSRandall Stewart 1277f8829a4aSRandall Stewart *abort_flag = 1; 1278f8829a4aSRandall Stewart return; 1279f8829a4aSRandall Stewart } 1280f8829a4aSRandall Stewart if (chk->rec.data.stream_number != 1281f8829a4aSRandall Stewart next->rec.data.stream_number) { 1282f8829a4aSRandall Stewart /* 1283f8829a4aSRandall Stewart * Huh, need the correct STR here, 1284f8829a4aSRandall Stewart * they must be the same. 1285f8829a4aSRandall Stewart */ 1286ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, ssn:%d not the same as at:%d\n", 1287f8829a4aSRandall Stewart chk->rec.data.stream_number, 1288f8829a4aSRandall Stewart next->rec.data.stream_number); 1289139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1290f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1291f8829a4aSRandall Stewart if (oper) { 1292f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1293f8829a4aSRandall Stewart uint32_t *ippp; 1294f8829a4aSRandall Stewart 1295139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1296f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1297f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1298f8829a4aSRandall Stewart ph = mtod(oper, 1299f8829a4aSRandall Stewart struct sctp_paramhdr *); 1300f8829a4aSRandall Stewart ph->param_type = 1301f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1302f8829a4aSRandall Stewart ph->param_length = 1303139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1304f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1305a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_12); 1306f8829a4aSRandall Stewart ippp++; 1307f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1308f8829a4aSRandall Stewart ippp++; 1309f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1310f8829a4aSRandall Stewart 1311f8829a4aSRandall Stewart } 1312a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_12; 1313f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1314ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1315f8829a4aSRandall Stewart 1316f8829a4aSRandall Stewart *abort_flag = 1; 1317f8829a4aSRandall Stewart return; 1318f8829a4aSRandall Stewart } 1319f8829a4aSRandall Stewart if ((next->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 && 1320f8829a4aSRandall Stewart chk->rec.data.stream_seq != 1321f8829a4aSRandall Stewart next->rec.data.stream_seq) { 1322f8829a4aSRandall Stewart /* 1323f8829a4aSRandall Stewart * Huh, need the correct STR here, 1324f8829a4aSRandall Stewart * they must be the same. 1325f8829a4aSRandall Stewart */ 1326ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, sseq:%d not the same as at:%d\n", 1327f8829a4aSRandall Stewart chk->rec.data.stream_seq, 1328f8829a4aSRandall Stewart next->rec.data.stream_seq); 1329139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1330f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1331f8829a4aSRandall Stewart if (oper) { 1332f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1333f8829a4aSRandall Stewart uint32_t *ippp; 1334f8829a4aSRandall Stewart 1335139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1336f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1337f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1338f8829a4aSRandall Stewart ph = mtod(oper, 1339f8829a4aSRandall Stewart struct sctp_paramhdr *); 1340f8829a4aSRandall Stewart ph->param_type = 1341f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1342f8829a4aSRandall Stewart ph->param_length = 1343139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1344f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1345a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_13); 1346f8829a4aSRandall Stewart ippp++; 1347f8829a4aSRandall Stewart *ippp = chk->rec.data.TSN_seq; 1348f8829a4aSRandall Stewart ippp++; 1349f8829a4aSRandall Stewart *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq); 1350f8829a4aSRandall Stewart } 1351a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_13; 1352f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1353ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1354f8829a4aSRandall Stewart 1355f8829a4aSRandall Stewart *abort_flag = 1; 1356f8829a4aSRandall Stewart return; 1357f8829a4aSRandall Stewart } 1358f8829a4aSRandall Stewart } 1359f8829a4aSRandall Stewart } 1360f8829a4aSRandall Stewart } 1361f8829a4aSRandall Stewart /* Do we need to do some delivery? check */ 1362f8829a4aSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 1363f8829a4aSRandall Stewart } 1364f8829a4aSRandall Stewart 1365f8829a4aSRandall Stewart /* 1366f8829a4aSRandall Stewart * This is an unfortunate routine. It checks to make sure a evil guy is not 1367f8829a4aSRandall Stewart * stuffing us full of bad packet fragments. A broken peer could also do this 1368f8829a4aSRandall Stewart * but this is doubtful. It is to bad I must worry about evil crackers sigh 1369f8829a4aSRandall Stewart * :< more cycles. 1370f8829a4aSRandall Stewart */ 1371f8829a4aSRandall Stewart static int 1372f8829a4aSRandall Stewart sctp_does_tsn_belong_to_reasm(struct sctp_association *asoc, 1373f8829a4aSRandall Stewart uint32_t TSN_seq) 1374f8829a4aSRandall Stewart { 1375f8829a4aSRandall Stewart struct sctp_tmit_chunk *at; 1376f8829a4aSRandall Stewart uint32_t tsn_est; 1377f8829a4aSRandall Stewart 1378f8829a4aSRandall Stewart TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) { 1379*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(TSN_seq, at->rec.data.TSN_seq)) { 1380f8829a4aSRandall Stewart /* is it one bigger? */ 1381f8829a4aSRandall Stewart tsn_est = at->rec.data.TSN_seq + 1; 1382f8829a4aSRandall Stewart if (tsn_est == TSN_seq) { 1383f8829a4aSRandall Stewart /* yep. It better be a last then */ 1384f8829a4aSRandall Stewart if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1385f8829a4aSRandall Stewart SCTP_DATA_LAST_FRAG) { 1386f8829a4aSRandall Stewart /* 1387f8829a4aSRandall Stewart * Ok this guy belongs next to a guy 1388f8829a4aSRandall Stewart * that is NOT last, it should be a 1389f8829a4aSRandall Stewart * middle/last, not a complete 1390f8829a4aSRandall Stewart * chunk. 1391f8829a4aSRandall Stewart */ 1392f8829a4aSRandall Stewart return (1); 1393f8829a4aSRandall Stewart } else { 1394f8829a4aSRandall Stewart /* 1395f8829a4aSRandall Stewart * This guy is ok since its a LAST 1396f8829a4aSRandall Stewart * and the new chunk is a fully 1397f8829a4aSRandall Stewart * self- contained one. 1398f8829a4aSRandall Stewart */ 1399f8829a4aSRandall Stewart return (0); 1400f8829a4aSRandall Stewart } 1401f8829a4aSRandall Stewart } 1402f8829a4aSRandall Stewart } else if (TSN_seq == at->rec.data.TSN_seq) { 1403f8829a4aSRandall Stewart /* Software error since I have a dup? */ 1404f8829a4aSRandall Stewart return (1); 1405f8829a4aSRandall Stewart } else { 1406f8829a4aSRandall Stewart /* 1407f8829a4aSRandall Stewart * Ok, 'at' is larger than new chunk but does it 1408f8829a4aSRandall Stewart * need to be right before it. 1409f8829a4aSRandall Stewart */ 1410f8829a4aSRandall Stewart tsn_est = TSN_seq + 1; 1411f8829a4aSRandall Stewart if (tsn_est == at->rec.data.TSN_seq) { 1412f8829a4aSRandall Stewart /* Yep, It better be a first */ 1413f8829a4aSRandall Stewart if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) != 1414f8829a4aSRandall Stewart SCTP_DATA_FIRST_FRAG) { 1415f8829a4aSRandall Stewart return (1); 1416f8829a4aSRandall Stewart } else { 1417f8829a4aSRandall Stewart return (0); 1418f8829a4aSRandall Stewart } 1419f8829a4aSRandall Stewart } 1420f8829a4aSRandall Stewart } 1421f8829a4aSRandall Stewart } 1422f8829a4aSRandall Stewart return (0); 1423f8829a4aSRandall Stewart } 1424f8829a4aSRandall Stewart 1425f8829a4aSRandall Stewart 1426f8829a4aSRandall Stewart static int 1427f8829a4aSRandall Stewart sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, 1428f8829a4aSRandall Stewart struct mbuf **m, int offset, struct sctp_data_chunk *ch, int chk_length, 1429f8829a4aSRandall Stewart struct sctp_nets *net, uint32_t * high_tsn, int *abort_flag, 1430f8829a4aSRandall Stewart int *break_flag, int last_chunk) 1431f8829a4aSRandall Stewart { 1432f8829a4aSRandall Stewart /* Process a data chunk */ 1433f8829a4aSRandall Stewart /* struct sctp_tmit_chunk *chk; */ 1434f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 1435f8829a4aSRandall Stewart uint32_t tsn, gap; 1436f8829a4aSRandall Stewart struct mbuf *dmbuf; 1437f8829a4aSRandall Stewart int indx, the_len; 1438139bc87fSRandall Stewart int need_reasm_check = 0; 1439f8829a4aSRandall Stewart uint16_t strmno, strmseq; 1440f8829a4aSRandall Stewart struct mbuf *oper; 1441f8829a4aSRandall Stewart struct sctp_queued_to_read *control; 1442f42a358aSRandall Stewart int ordered; 1443f42a358aSRandall Stewart uint32_t protocol_id; 1444f42a358aSRandall Stewart uint8_t chunk_flags; 144517205eccSRandall Stewart struct sctp_stream_reset_list *liste; 1446f8829a4aSRandall Stewart 1447f8829a4aSRandall Stewart chk = NULL; 1448f8829a4aSRandall Stewart tsn = ntohl(ch->dp.tsn); 1449f42a358aSRandall Stewart chunk_flags = ch->ch.chunk_flags; 1450b3f1ea41SRandall Stewart if ((chunk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) { 1451b3f1ea41SRandall Stewart asoc->send_sack = 1; 1452b3f1ea41SRandall Stewart } 1453f42a358aSRandall Stewart protocol_id = ch->dp.protocol_id; 145437f144ebSMichael Tuexen ordered = ((chunk_flags & SCTP_DATA_UNORDERED) == 0); 1455b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 1456c4739e2fSRandall Stewart sctp_log_map(tsn, asoc->cumulative_tsn, asoc->highest_tsn_inside_map, SCTP_MAP_TSN_ENTERS); 145780fefe0aSRandall Stewart } 1458ad81507eSRandall Stewart if (stcb == NULL) { 1459ad81507eSRandall Stewart return (0); 1460ad81507eSRandall Stewart } 146180fefe0aSRandall Stewart SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, ch->ch.chunk_type, tsn); 1462*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->cumulative_tsn, tsn)) { 1463f8829a4aSRandall Stewart /* It is a duplicate */ 1464f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1465f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1466f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1467f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1468f8829a4aSRandall Stewart asoc->numduptsns++; 1469f8829a4aSRandall Stewart } 1470b201f536SRandall Stewart asoc->send_sack = 1; 1471f8829a4aSRandall Stewart return (0); 1472f8829a4aSRandall Stewart } 1473f8829a4aSRandall Stewart /* Calculate the number of TSN's between the base and this TSN */ 1474d50c1d79SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn); 1475f8829a4aSRandall Stewart if (gap >= (SCTP_MAPPING_ARRAY << 3)) { 1476f8829a4aSRandall Stewart /* Can't hold the bit in the mapping at max array, toss it */ 1477f8829a4aSRandall Stewart return (0); 1478f8829a4aSRandall Stewart } 1479f8829a4aSRandall Stewart if (gap >= (uint32_t) (asoc->mapping_array_size << 3)) { 1480207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 14810696e120SRandall Stewart if (sctp_expand_mapping_array(asoc, gap)) { 1482f8829a4aSRandall Stewart /* Can't expand, drop it */ 1483f8829a4aSRandall Stewart return (0); 1484f8829a4aSRandall Stewart } 1485f8829a4aSRandall Stewart } 1486*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, *high_tsn)) { 1487f8829a4aSRandall Stewart *high_tsn = tsn; 1488f8829a4aSRandall Stewart } 1489f8829a4aSRandall Stewart /* See if we have received this one already */ 149077acdc25SRandall Stewart if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap) || 149177acdc25SRandall Stewart SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, gap)) { 1492f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1493f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1494f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1495f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1496f8829a4aSRandall Stewart asoc->numduptsns++; 1497f8829a4aSRandall Stewart } 149842551e99SRandall Stewart asoc->send_sack = 1; 1499f8829a4aSRandall Stewart return (0); 1500f8829a4aSRandall Stewart } 1501f8829a4aSRandall Stewart /* 1502f8829a4aSRandall Stewart * Check to see about the GONE flag, duplicates would cause a sack 1503f8829a4aSRandall Stewart * to be sent up above 1504f8829a4aSRandall Stewart */ 1505ad81507eSRandall Stewart if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || 1506f8829a4aSRandall Stewart (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || 1507f8829a4aSRandall Stewart (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) 1508f8829a4aSRandall Stewart ) { 1509f8829a4aSRandall Stewart /* 1510f8829a4aSRandall Stewart * wait a minute, this guy is gone, there is no longer a 1511f8829a4aSRandall Stewart * receiver. Send peer an ABORT! 1512f8829a4aSRandall Stewart */ 1513f8829a4aSRandall Stewart struct mbuf *op_err; 1514f8829a4aSRandall Stewart 1515f8829a4aSRandall Stewart op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC); 1516ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 0, op_err, SCTP_SO_NOT_LOCKED); 1517f8829a4aSRandall Stewart *abort_flag = 1; 1518f8829a4aSRandall Stewart return (0); 1519f8829a4aSRandall Stewart } 1520f8829a4aSRandall Stewart /* 1521f8829a4aSRandall Stewart * Now before going further we see if there is room. If NOT then we 1522f8829a4aSRandall Stewart * MAY let one through only IF this TSN is the one we are waiting 1523f8829a4aSRandall Stewart * for on a partial delivery API. 1524f8829a4aSRandall Stewart */ 1525f8829a4aSRandall Stewart 1526f8829a4aSRandall Stewart /* now do the tests */ 1527f8829a4aSRandall Stewart if (((asoc->cnt_on_all_streams + 1528f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue + 1529b3f1ea41SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) || 1530f8829a4aSRandall Stewart (((int)asoc->my_rwnd) <= 0)) { 1531f8829a4aSRandall Stewart /* 1532f8829a4aSRandall Stewart * When we have NO room in the rwnd we check to make sure 1533f8829a4aSRandall Stewart * the reader is doing its job... 1534f8829a4aSRandall Stewart */ 1535f8829a4aSRandall Stewart if (stcb->sctp_socket->so_rcv.sb_cc) { 1536f8829a4aSRandall Stewart /* some to read, wake-up */ 1537ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 1538ceaad40aSRandall Stewart struct socket *so; 1539ceaad40aSRandall Stewart 1540ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 1541ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 1542ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 1543ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 1544ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 1545ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 1546ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 1547ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 1548ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 1549ceaad40aSRandall Stewart return (0); 1550ceaad40aSRandall Stewart } 1551ceaad40aSRandall Stewart #endif 1552f8829a4aSRandall Stewart sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket); 1553ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 1554ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 1555ceaad40aSRandall Stewart #endif 1556f8829a4aSRandall Stewart } 1557f8829a4aSRandall Stewart /* now is it in the mapping array of what we have accepted? */ 1558*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map) && 1559*20b07a4dSMichael Tuexen SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 1560f8829a4aSRandall Stewart /* Nope not in the valid range dump it */ 1561f8829a4aSRandall Stewart sctp_set_rwnd(stcb, asoc); 1562f8829a4aSRandall Stewart if ((asoc->cnt_on_all_streams + 1563f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue + 1564b3f1ea41SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) { 1565f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_datadropchklmt); 1566f8829a4aSRandall Stewart } else { 1567f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_datadroprwnd); 1568f8829a4aSRandall Stewart } 1569f8829a4aSRandall Stewart indx = *break_flag; 1570f8829a4aSRandall Stewart *break_flag = 1; 1571f8829a4aSRandall Stewart return (0); 1572f8829a4aSRandall Stewart } 1573f8829a4aSRandall Stewart } 1574f8829a4aSRandall Stewart strmno = ntohs(ch->dp.stream_id); 1575f8829a4aSRandall Stewart if (strmno >= asoc->streamincnt) { 1576f8829a4aSRandall Stewart struct sctp_paramhdr *phdr; 1577f8829a4aSRandall Stewart struct mbuf *mb; 1578f8829a4aSRandall Stewart 1579f8829a4aSRandall Stewart mb = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) * 2), 1580139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1581f8829a4aSRandall Stewart if (mb != NULL) { 1582f8829a4aSRandall Stewart /* add some space up front so prepend will work well */ 1583139bc87fSRandall Stewart SCTP_BUF_RESV_UF(mb, sizeof(struct sctp_chunkhdr)); 1584f8829a4aSRandall Stewart phdr = mtod(mb, struct sctp_paramhdr *); 1585f8829a4aSRandall Stewart /* 1586f8829a4aSRandall Stewart * Error causes are just param's and this one has 1587f8829a4aSRandall Stewart * two back to back phdr, one with the error type 1588f8829a4aSRandall Stewart * and size, the other with the streamid and a rsvd 1589f8829a4aSRandall Stewart */ 1590139bc87fSRandall Stewart SCTP_BUF_LEN(mb) = (sizeof(struct sctp_paramhdr) * 2); 1591f8829a4aSRandall Stewart phdr->param_type = htons(SCTP_CAUSE_INVALID_STREAM); 1592f8829a4aSRandall Stewart phdr->param_length = 1593f8829a4aSRandall Stewart htons(sizeof(struct sctp_paramhdr) * 2); 1594f8829a4aSRandall Stewart phdr++; 1595f8829a4aSRandall Stewart /* We insert the stream in the type field */ 1596f8829a4aSRandall Stewart phdr->param_type = ch->dp.stream_id; 1597f8829a4aSRandall Stewart /* And set the length to 0 for the rsvd field */ 1598f8829a4aSRandall Stewart phdr->param_length = 0; 1599f8829a4aSRandall Stewart sctp_queue_op_err(stcb, mb); 1600f8829a4aSRandall Stewart } 1601f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_badsid); 1602207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1603830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 1604*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 1605830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 1606d06c82f1SRandall Stewart } 1607d06c82f1SRandall Stewart if (tsn == (asoc->cumulative_tsn + 1)) { 1608d06c82f1SRandall Stewart /* Update cum-ack */ 1609d06c82f1SRandall Stewart asoc->cumulative_tsn = tsn; 1610d06c82f1SRandall Stewart } 1611f8829a4aSRandall Stewart return (0); 1612f8829a4aSRandall Stewart } 1613f8829a4aSRandall Stewart /* 1614f8829a4aSRandall Stewart * Before we continue lets validate that we are not being fooled by 1615f8829a4aSRandall Stewart * an evil attacker. We can only have 4k chunks based on our TSN 1616f8829a4aSRandall Stewart * spread allowed by the mapping array 512 * 8 bits, so there is no 1617f8829a4aSRandall Stewart * way our stream sequence numbers could have wrapped. We of course 1618f8829a4aSRandall Stewart * only validate the FIRST fragment so the bit must be set. 1619f8829a4aSRandall Stewart */ 1620f8829a4aSRandall Stewart strmseq = ntohs(ch->dp.stream_sequence); 1621f42a358aSRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 162218e198d3SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 162318e198d3SRandall Stewart if (asoc->tsn_in_at >= SCTP_TSN_LOG_SIZE) { 162418e198d3SRandall Stewart asoc->tsn_in_at = 0; 162518e198d3SRandall Stewart asoc->tsn_in_wrapped = 1; 162618e198d3SRandall Stewart } 1627f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].tsn = tsn; 1628f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].strm = strmno; 1629f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].seq = strmseq; 1630f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].sz = chk_length; 1631f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].flgs = chunk_flags; 163218e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].stcb = (void *)stcb; 163318e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_pos = asoc->tsn_in_at; 163418e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_out = 1; 1635f42a358aSRandall Stewart asoc->tsn_in_at++; 1636f42a358aSRandall Stewart #endif 1637f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_FIRST_FRAG) && 1638d61a0ae0SRandall Stewart (TAILQ_EMPTY(&asoc->resetHead)) && 1639f42a358aSRandall Stewart (chunk_flags & SCTP_DATA_UNORDERED) == 0 && 1640*20b07a4dSMichael Tuexen SCTP_SSN_GE(asoc->strmin[strmno].last_sequence_delivered, strmseq)) { 1641f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 1642ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ:%d delivered:%d from peer, Abort!\n", 1643ad81507eSRandall Stewart strmseq, asoc->strmin[strmno].last_sequence_delivered); 1644139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1645f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1646f8829a4aSRandall Stewart if (oper) { 1647f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1648f8829a4aSRandall Stewart uint32_t *ippp; 1649f8829a4aSRandall Stewart 1650139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 1651f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1652f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 1653f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1654139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 1655f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1656a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_14); 1657f8829a4aSRandall Stewart ippp++; 1658f8829a4aSRandall Stewart *ippp = tsn; 1659f8829a4aSRandall Stewart ippp++; 1660f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 1661f8829a4aSRandall Stewart 1662f8829a4aSRandall Stewart } 1663a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_14; 1664f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1665ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1666f8829a4aSRandall Stewart *abort_flag = 1; 1667f8829a4aSRandall Stewart return (0); 1668f8829a4aSRandall Stewart } 1669f42a358aSRandall Stewart /************************************ 1670f42a358aSRandall Stewart * From here down we may find ch-> invalid 1671f42a358aSRandall Stewart * so its a good idea NOT to use it. 1672f42a358aSRandall Stewart *************************************/ 1673f42a358aSRandall Stewart 1674f8829a4aSRandall Stewart the_len = (chk_length - sizeof(struct sctp_data_chunk)); 1675f8829a4aSRandall Stewart if (last_chunk == 0) { 167644b7479bSRandall Stewart dmbuf = SCTP_M_COPYM(*m, 1677f8829a4aSRandall Stewart (offset + sizeof(struct sctp_data_chunk)), 1678f8829a4aSRandall Stewart the_len, M_DONTWAIT); 1679f8829a4aSRandall Stewart #ifdef SCTP_MBUF_LOGGING 1680b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { 1681f8829a4aSRandall Stewart struct mbuf *mat; 1682f8829a4aSRandall Stewart 1683f8829a4aSRandall Stewart mat = dmbuf; 1684f8829a4aSRandall Stewart while (mat) { 1685139bc87fSRandall Stewart if (SCTP_BUF_IS_EXTENDED(mat)) { 1686f8829a4aSRandall Stewart sctp_log_mb(mat, SCTP_MBUF_ICOPY); 1687f8829a4aSRandall Stewart } 1688139bc87fSRandall Stewart mat = SCTP_BUF_NEXT(mat); 1689f8829a4aSRandall Stewart } 1690f8829a4aSRandall Stewart } 1691f8829a4aSRandall Stewart #endif 1692f8829a4aSRandall Stewart } else { 1693f8829a4aSRandall Stewart /* We can steal the last chunk */ 1694139bc87fSRandall Stewart int l_len; 1695139bc87fSRandall Stewart 1696f8829a4aSRandall Stewart dmbuf = *m; 1697f8829a4aSRandall Stewart /* lop off the top part */ 1698f8829a4aSRandall Stewart m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk))); 1699139bc87fSRandall Stewart if (SCTP_BUF_NEXT(dmbuf) == NULL) { 1700139bc87fSRandall Stewart l_len = SCTP_BUF_LEN(dmbuf); 1701139bc87fSRandall Stewart } else { 1702139bc87fSRandall Stewart /* 1703139bc87fSRandall Stewart * need to count up the size hopefully does not hit 1704139bc87fSRandall Stewart * this to often :-0 1705139bc87fSRandall Stewart */ 1706139bc87fSRandall Stewart struct mbuf *lat; 1707139bc87fSRandall Stewart 1708139bc87fSRandall Stewart l_len = 0; 1709139bc87fSRandall Stewart lat = dmbuf; 1710139bc87fSRandall Stewart while (lat) { 1711139bc87fSRandall Stewart l_len += SCTP_BUF_LEN(lat); 1712139bc87fSRandall Stewart lat = SCTP_BUF_NEXT(lat); 1713139bc87fSRandall Stewart } 1714139bc87fSRandall Stewart } 1715139bc87fSRandall Stewart if (l_len > the_len) { 1716f8829a4aSRandall Stewart /* Trim the end round bytes off too */ 1717139bc87fSRandall Stewart m_adj(dmbuf, -(l_len - the_len)); 1718f8829a4aSRandall Stewart } 1719f8829a4aSRandall Stewart } 1720f8829a4aSRandall Stewart if (dmbuf == NULL) { 1721f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1722f8829a4aSRandall Stewart return (0); 1723f8829a4aSRandall Stewart } 1724f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG && 1725f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress == 0 && 1726f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->resetHead) && 1727f42a358aSRandall Stewart ((ordered == 0) || 172836ec9f81SMichael Tuexen ((uint16_t) (asoc->strmin[strmno].last_sequence_delivered + 1) == strmseq && 1729f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->strmin[strmno].inqueue)))) { 1730f8829a4aSRandall Stewart /* Candidate for express delivery */ 1731f8829a4aSRandall Stewart /* 1732f8829a4aSRandall Stewart * Its not fragmented, No PD-API is up, Nothing in the 1733f8829a4aSRandall Stewart * delivery queue, Its un-ordered OR ordered and the next to 1734f8829a4aSRandall Stewart * deliver AND nothing else is stuck on the stream queue, 1735f8829a4aSRandall Stewart * And there is room for it in the socket buffer. Lets just 1736f8829a4aSRandall Stewart * stuff it up the buffer.... 1737f8829a4aSRandall Stewart */ 1738f8829a4aSRandall Stewart 1739f8829a4aSRandall Stewart /* It would be nice to avoid this copy if we could :< */ 1740f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, control); 1741f8829a4aSRandall Stewart sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, 1742f42a358aSRandall Stewart protocol_id, 1743f8829a4aSRandall Stewart stcb->asoc.context, 1744f8829a4aSRandall Stewart strmno, strmseq, 1745f42a358aSRandall Stewart chunk_flags, 1746f8829a4aSRandall Stewart dmbuf); 1747f8829a4aSRandall Stewart if (control == NULL) { 1748f8829a4aSRandall Stewart goto failed_express_del; 1749f8829a4aSRandall Stewart } 17501ea735c8SMichael Tuexen SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 1751*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 17521ea735c8SMichael Tuexen asoc->highest_tsn_inside_nr_map = tsn; 17531ea735c8SMichael Tuexen } 1754cfde3ff7SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 1755cfde3ff7SRandall Stewart control, &stcb->sctp_socket->so_rcv, 1756cfde3ff7SRandall Stewart 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 1757830d754dSRandall Stewart 1758f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { 1759f8829a4aSRandall Stewart /* for ordered, bump what we delivered */ 1760f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered++; 1761f8829a4aSRandall Stewart } 1762f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvexpress); 1763b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 17646a91f103SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, 1765f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_EXPRS_DEL); 176680fefe0aSRandall Stewart } 1767f8829a4aSRandall Stewart control = NULL; 1768b5c16493SMichael Tuexen 1769f8829a4aSRandall Stewart goto finish_express_del; 1770f8829a4aSRandall Stewart } 1771f8829a4aSRandall Stewart failed_express_del: 1772f8829a4aSRandall Stewart /* If we reach here this is a new chunk */ 1773f8829a4aSRandall Stewart chk = NULL; 1774f8829a4aSRandall Stewart control = NULL; 1775f8829a4aSRandall Stewart /* Express for fragmented delivery? */ 1776f8829a4aSRandall Stewart if ((asoc->fragmented_delivery_inprogress) && 1777f8829a4aSRandall Stewart (stcb->asoc.control_pdapi) && 1778f8829a4aSRandall Stewart (asoc->str_of_pdapi == strmno) && 1779f8829a4aSRandall Stewart (asoc->ssn_of_pdapi == strmseq) 1780f8829a4aSRandall Stewart ) { 1781f8829a4aSRandall Stewart control = stcb->asoc.control_pdapi; 1782f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) { 1783f8829a4aSRandall Stewart /* Can't be another first? */ 1784f8829a4aSRandall Stewart goto failed_pdapi_express_del; 1785f8829a4aSRandall Stewart } 1786f8829a4aSRandall Stewart if (tsn == (control->sinfo_tsn + 1)) { 1787f8829a4aSRandall Stewart /* Yep, we can add it on */ 1788f8829a4aSRandall Stewart int end = 0; 1789f8829a4aSRandall Stewart uint32_t cumack; 1790f8829a4aSRandall Stewart 1791f42a358aSRandall Stewart if (chunk_flags & SCTP_DATA_LAST_FRAG) { 1792f8829a4aSRandall Stewart end = 1; 1793f8829a4aSRandall Stewart } 1794f8829a4aSRandall Stewart cumack = asoc->cumulative_tsn; 1795f8829a4aSRandall Stewart if ((cumack + 1) == tsn) 1796f8829a4aSRandall Stewart cumack = tsn; 1797f8829a4aSRandall Stewart 1798f8829a4aSRandall Stewart if (sctp_append_to_readq(stcb->sctp_ep, stcb, control, dmbuf, end, 1799f8829a4aSRandall Stewart tsn, 1800f8829a4aSRandall Stewart &stcb->sctp_socket->so_rcv)) { 1801ad81507eSRandall Stewart SCTP_PRINTF("Append fails end:%d\n", end); 1802f8829a4aSRandall Stewart goto failed_pdapi_express_del; 1803f8829a4aSRandall Stewart } 180477acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 1805*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 1806830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 1807830d754dSRandall Stewart } 1808f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvexpressm); 1809f8829a4aSRandall Stewart control->sinfo_tsn = tsn; 1810f8829a4aSRandall Stewart asoc->tsn_last_delivered = tsn; 1811f42a358aSRandall Stewart asoc->fragment_flags = chunk_flags; 1812f8829a4aSRandall Stewart asoc->tsn_of_pdapi_last_delivered = tsn; 1813f42a358aSRandall Stewart asoc->last_flags_delivered = chunk_flags; 1814f8829a4aSRandall Stewart asoc->last_strm_seq_delivered = strmseq; 1815f8829a4aSRandall Stewart asoc->last_strm_no_delivered = strmno; 1816f8829a4aSRandall Stewart if (end) { 1817f8829a4aSRandall Stewart /* clean up the flags and such */ 1818f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 0; 1819f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { 1820f8829a4aSRandall Stewart asoc->strmin[strmno].last_sequence_delivered++; 1821a5d547adSRandall Stewart } 1822f8829a4aSRandall Stewart stcb->asoc.control_pdapi = NULL; 1823139bc87fSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue) == 0) { 1824139bc87fSRandall Stewart /* 1825139bc87fSRandall Stewart * There could be another message 1826139bc87fSRandall Stewart * ready 1827139bc87fSRandall Stewart */ 1828139bc87fSRandall Stewart need_reasm_check = 1; 1829139bc87fSRandall Stewart } 1830f8829a4aSRandall Stewart } 1831f8829a4aSRandall Stewart control = NULL; 1832f8829a4aSRandall Stewart goto finish_express_del; 1833f8829a4aSRandall Stewart } 1834f8829a4aSRandall Stewart } 1835f8829a4aSRandall Stewart failed_pdapi_express_del: 1836f8829a4aSRandall Stewart control = NULL; 183777acdc25SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) { 183877acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 1839*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 184077acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 184177acdc25SRandall Stewart } 184277acdc25SRandall Stewart } else { 184377acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap); 1844*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map)) { 184577acdc25SRandall Stewart asoc->highest_tsn_inside_map = tsn; 184677acdc25SRandall Stewart } 184777acdc25SRandall Stewart } 1848f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { 1849f8829a4aSRandall Stewart sctp_alloc_a_chunk(stcb, chk); 1850f8829a4aSRandall Stewart if (chk == NULL) { 1851f8829a4aSRandall Stewart /* No memory so we drop the chunk */ 1852f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1853f8829a4aSRandall Stewart if (last_chunk == 0) { 1854f8829a4aSRandall Stewart /* we copied it, free the copy */ 1855f8829a4aSRandall Stewart sctp_m_freem(dmbuf); 1856f8829a4aSRandall Stewart } 1857f8829a4aSRandall Stewart return (0); 1858f8829a4aSRandall Stewart } 1859f8829a4aSRandall Stewart chk->rec.data.TSN_seq = tsn; 1860f8829a4aSRandall Stewart chk->no_fr_allowed = 0; 1861f8829a4aSRandall Stewart chk->rec.data.stream_seq = strmseq; 1862f8829a4aSRandall Stewart chk->rec.data.stream_number = strmno; 1863f42a358aSRandall Stewart chk->rec.data.payloadtype = protocol_id; 1864f8829a4aSRandall Stewart chk->rec.data.context = stcb->asoc.context; 1865f8829a4aSRandall Stewart chk->rec.data.doing_fast_retransmit = 0; 1866f42a358aSRandall Stewart chk->rec.data.rcv_flags = chunk_flags; 1867f8829a4aSRandall Stewart chk->asoc = asoc; 1868f8829a4aSRandall Stewart chk->send_size = the_len; 1869f8829a4aSRandall Stewart chk->whoTo = net; 1870f8829a4aSRandall Stewart atomic_add_int(&net->ref_count, 1); 1871f8829a4aSRandall Stewart chk->data = dmbuf; 1872f8829a4aSRandall Stewart } else { 1873f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, control); 1874f8829a4aSRandall Stewart sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, 1875f42a358aSRandall Stewart protocol_id, 1876f8829a4aSRandall Stewart stcb->asoc.context, 1877f8829a4aSRandall Stewart strmno, strmseq, 1878f42a358aSRandall Stewart chunk_flags, 1879f8829a4aSRandall Stewart dmbuf); 1880f8829a4aSRandall Stewart if (control == NULL) { 1881f8829a4aSRandall Stewart /* No memory so we drop the chunk */ 1882f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1883f8829a4aSRandall Stewart if (last_chunk == 0) { 1884f8829a4aSRandall Stewart /* we copied it, free the copy */ 1885f8829a4aSRandall Stewart sctp_m_freem(dmbuf); 1886f8829a4aSRandall Stewart } 1887f8829a4aSRandall Stewart return (0); 1888f8829a4aSRandall Stewart } 1889f8829a4aSRandall Stewart control->length = the_len; 1890f8829a4aSRandall Stewart } 1891f8829a4aSRandall Stewart 1892f8829a4aSRandall Stewart /* Mark it as received */ 1893f8829a4aSRandall Stewart /* Now queue it where it belongs */ 1894f8829a4aSRandall Stewart if (control != NULL) { 1895f8829a4aSRandall Stewart /* First a sanity check */ 1896f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 1897f8829a4aSRandall Stewart /* 1898f8829a4aSRandall Stewart * Ok, we have a fragmented delivery in progress if 1899f8829a4aSRandall Stewart * this chunk is next to deliver OR belongs in our 1900f8829a4aSRandall Stewart * view to the reassembly, the peer is evil or 1901f8829a4aSRandall Stewart * broken. 1902f8829a4aSRandall Stewart */ 1903f8829a4aSRandall Stewart uint32_t estimate_tsn; 1904f8829a4aSRandall Stewart 1905f8829a4aSRandall Stewart estimate_tsn = asoc->tsn_last_delivered + 1; 1906f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->reasmqueue) && 1907f8829a4aSRandall Stewart (estimate_tsn == control->sinfo_tsn)) { 1908f8829a4aSRandall Stewart /* Evil/Broke peer */ 1909f8829a4aSRandall Stewart sctp_m_freem(control->data); 1910f8829a4aSRandall Stewart control->data = NULL; 19115bead436SRandall Stewart if (control->whoFrom) { 1912f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 19135bead436SRandall Stewart control->whoFrom = NULL; 19145bead436SRandall Stewart } 1915f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 1916139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1917f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1918f8829a4aSRandall Stewart if (oper) { 1919f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1920f8829a4aSRandall Stewart uint32_t *ippp; 1921f8829a4aSRandall Stewart 1922139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1923f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1924f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1925f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 1926f8829a4aSRandall Stewart ph->param_type = 1927f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1928139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 1929f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1930a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_15); 1931f8829a4aSRandall Stewart ippp++; 1932f8829a4aSRandall Stewart *ippp = tsn; 1933f8829a4aSRandall Stewart ippp++; 1934f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 1935f8829a4aSRandall Stewart } 1936a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_15; 1937f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1938ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1939f8829a4aSRandall Stewart 1940f8829a4aSRandall Stewart *abort_flag = 1; 1941f8829a4aSRandall Stewart return (0); 1942f8829a4aSRandall Stewart } else { 1943f8829a4aSRandall Stewart if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) { 1944f8829a4aSRandall Stewart sctp_m_freem(control->data); 1945f8829a4aSRandall Stewart control->data = NULL; 19465bead436SRandall Stewart if (control->whoFrom) { 1947f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 19485bead436SRandall Stewart control->whoFrom = NULL; 19495bead436SRandall Stewart } 1950f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 1951f8829a4aSRandall Stewart 1952139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 1953f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 1954f8829a4aSRandall Stewart if (oper) { 1955f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1956f8829a4aSRandall Stewart uint32_t *ippp; 1957f8829a4aSRandall Stewart 1958139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 1959f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 1960f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 1961f8829a4aSRandall Stewart ph = mtod(oper, 1962f8829a4aSRandall Stewart struct sctp_paramhdr *); 1963f8829a4aSRandall Stewart ph->param_type = 1964f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 1965f8829a4aSRandall Stewart ph->param_length = 1966139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 1967f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 1968a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_16); 1969f8829a4aSRandall Stewart ippp++; 1970f8829a4aSRandall Stewart *ippp = tsn; 1971f8829a4aSRandall Stewart ippp++; 1972f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 1973f8829a4aSRandall Stewart } 1974a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16; 1975f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 1976ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 1977f8829a4aSRandall Stewart 1978f8829a4aSRandall Stewart *abort_flag = 1; 1979f8829a4aSRandall Stewart return (0); 1980f8829a4aSRandall Stewart } 1981f8829a4aSRandall Stewart } 1982f8829a4aSRandall Stewart } else { 1983f8829a4aSRandall Stewart /* No PDAPI running */ 1984f8829a4aSRandall Stewart if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 1985f8829a4aSRandall Stewart /* 1986f8829a4aSRandall Stewart * Reassembly queue is NOT empty validate 1987f8829a4aSRandall Stewart * that this tsn does not need to be in 1988f8829a4aSRandall Stewart * reasembly queue. If it does then our peer 1989f8829a4aSRandall Stewart * is broken or evil. 1990f8829a4aSRandall Stewart */ 1991f8829a4aSRandall Stewart if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) { 1992f8829a4aSRandall Stewart sctp_m_freem(control->data); 1993f8829a4aSRandall Stewart control->data = NULL; 19945bead436SRandall Stewart if (control->whoFrom) { 1995f8829a4aSRandall Stewart sctp_free_remote_addr(control->whoFrom); 19965bead436SRandall Stewart control->whoFrom = NULL; 19975bead436SRandall Stewart } 1998f8829a4aSRandall Stewart sctp_free_a_readq(stcb, control); 1999139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 2000f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 2001f8829a4aSRandall Stewart if (oper) { 2002f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 2003f8829a4aSRandall Stewart uint32_t *ippp; 2004f8829a4aSRandall Stewart 2005139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = 2006f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr) + 2007f8829a4aSRandall Stewart (3 * sizeof(uint32_t)); 2008f8829a4aSRandall Stewart ph = mtod(oper, 2009f8829a4aSRandall Stewart struct sctp_paramhdr *); 2010f8829a4aSRandall Stewart ph->param_type = 2011f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 2012f8829a4aSRandall Stewart ph->param_length = 2013139bc87fSRandall Stewart htons(SCTP_BUF_LEN(oper)); 2014f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 2015a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_17); 2016f8829a4aSRandall Stewart ippp++; 2017f8829a4aSRandall Stewart *ippp = tsn; 2018f8829a4aSRandall Stewart ippp++; 2019f8829a4aSRandall Stewart *ippp = ((strmno << 16) | strmseq); 2020f8829a4aSRandall Stewart } 2021a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_17; 2022f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, 2023ceaad40aSRandall Stewart stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 2024f8829a4aSRandall Stewart 2025f8829a4aSRandall Stewart *abort_flag = 1; 2026f8829a4aSRandall Stewart return (0); 2027f8829a4aSRandall Stewart } 2028f8829a4aSRandall Stewart } 2029f8829a4aSRandall Stewart } 2030f8829a4aSRandall Stewart /* ok, if we reach here we have passed the sanity checks */ 2031f42a358aSRandall Stewart if (chunk_flags & SCTP_DATA_UNORDERED) { 2032f8829a4aSRandall Stewart /* queue directly into socket buffer */ 2033b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 2034f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 2035f8829a4aSRandall Stewart control, 2036cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 2037f8829a4aSRandall Stewart } else { 2038f8829a4aSRandall Stewart /* 2039f8829a4aSRandall Stewart * Special check for when streams are resetting. We 2040f8829a4aSRandall Stewart * could be more smart about this and check the 2041f8829a4aSRandall Stewart * actual stream to see if it is not being reset.. 2042f8829a4aSRandall Stewart * that way we would not create a HOLB when amongst 2043f8829a4aSRandall Stewart * streams being reset and those not being reset. 2044f8829a4aSRandall Stewart * 2045f8829a4aSRandall Stewart * We take complete messages that have a stream reset 2046f8829a4aSRandall Stewart * intervening (aka the TSN is after where our 2047f8829a4aSRandall Stewart * cum-ack needs to be) off and put them on a 2048f8829a4aSRandall Stewart * pending_reply_queue. The reassembly ones we do 2049f8829a4aSRandall Stewart * not have to worry about since they are all sorted 2050f8829a4aSRandall Stewart * and proceessed by TSN order. It is only the 2051f8829a4aSRandall Stewart * singletons I must worry about. 2052f8829a4aSRandall Stewart */ 2053f8829a4aSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 2054*20b07a4dSMichael Tuexen SCTP_TSN_GT(tsn, liste->tsn)) { 2055f8829a4aSRandall Stewart /* 2056f8829a4aSRandall Stewart * yep its past where we need to reset... go 2057f8829a4aSRandall Stewart * ahead and queue it. 2058f8829a4aSRandall Stewart */ 2059f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->pending_reply_queue)) { 2060f8829a4aSRandall Stewart /* first one on */ 2061f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2062f8829a4aSRandall Stewart } else { 20634a9ef3f8SMichael Tuexen struct sctp_queued_to_read *ctlOn, 20644a9ef3f8SMichael Tuexen *nctlOn; 2065f8829a4aSRandall Stewart unsigned char inserted = 0; 2066f8829a4aSRandall Stewart 20674a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ctlOn, &asoc->pending_reply_queue, next, nctlOn) { 2068*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(control->sinfo_tsn, ctlOn->sinfo_tsn)) { 20694a9ef3f8SMichael Tuexen continue; 2070f8829a4aSRandall Stewart } else { 2071f8829a4aSRandall Stewart /* found it */ 2072f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(ctlOn, control, next); 2073f8829a4aSRandall Stewart inserted = 1; 2074f8829a4aSRandall Stewart break; 2075f8829a4aSRandall Stewart } 2076f8829a4aSRandall Stewart } 2077f8829a4aSRandall Stewart if (inserted == 0) { 2078f8829a4aSRandall Stewart /* 2079f8829a4aSRandall Stewart * must be put at end, use 2080f8829a4aSRandall Stewart * prevP (all setup from 2081f8829a4aSRandall Stewart * loop) to setup nextP. 2082f8829a4aSRandall Stewart */ 2083f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2084f8829a4aSRandall Stewart } 2085f8829a4aSRandall Stewart } 2086f8829a4aSRandall Stewart } else { 2087f8829a4aSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, control, abort_flag); 2088f8829a4aSRandall Stewart if (*abort_flag) { 2089f8829a4aSRandall Stewart return (0); 2090f8829a4aSRandall Stewart } 2091f8829a4aSRandall Stewart } 2092f8829a4aSRandall Stewart } 2093f8829a4aSRandall Stewart } else { 2094f8829a4aSRandall Stewart /* Into the re-assembly queue */ 2095f8829a4aSRandall Stewart sctp_queue_data_for_reasm(stcb, asoc, chk, abort_flag); 2096f8829a4aSRandall Stewart if (*abort_flag) { 2097a5d547adSRandall Stewart /* 2098a5d547adSRandall Stewart * the assoc is now gone and chk was put onto the 2099a5d547adSRandall Stewart * reasm queue, which has all been freed. 2100a5d547adSRandall Stewart */ 2101a5d547adSRandall Stewart *m = NULL; 2102f8829a4aSRandall Stewart return (0); 2103f8829a4aSRandall Stewart } 2104f8829a4aSRandall Stewart } 2105f8829a4aSRandall Stewart finish_express_del: 2106307b49efSMichael Tuexen if (tsn == (asoc->cumulative_tsn + 1)) { 2107307b49efSMichael Tuexen /* Update cum-ack */ 2108307b49efSMichael Tuexen asoc->cumulative_tsn = tsn; 2109307b49efSMichael Tuexen } 2110f8829a4aSRandall Stewart if (last_chunk) { 2111f8829a4aSRandall Stewart *m = NULL; 2112f8829a4aSRandall Stewart } 2113f42a358aSRandall Stewart if (ordered) { 2114f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inorderchunks); 2115f8829a4aSRandall Stewart } else { 2116f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inunorderchunks); 2117f8829a4aSRandall Stewart } 2118f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdata); 2119f8829a4aSRandall Stewart /* Set it present please */ 2120b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 21216a91f103SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, SCTP_STR_LOG_FROM_MARK_TSN); 212280fefe0aSRandall Stewart } 2123b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2124f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, 2125f8829a4aSRandall Stewart asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE); 212680fefe0aSRandall Stewart } 212717205eccSRandall Stewart /* check the special flag for stream resets */ 212817205eccSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 2129*20b07a4dSMichael Tuexen SCTP_TSN_GE(asoc->cumulative_tsn, liste->tsn)) { 213017205eccSRandall Stewart /* 213117205eccSRandall Stewart * we have finished working through the backlogged TSN's now 213217205eccSRandall Stewart * time to reset streams. 1: call reset function. 2: free 213317205eccSRandall Stewart * pending_reply space 3: distribute any chunks in 213417205eccSRandall Stewart * pending_reply_queue. 213517205eccSRandall Stewart */ 21364a9ef3f8SMichael Tuexen struct sctp_queued_to_read *ctl, *nctl; 213717205eccSRandall Stewart 213817205eccSRandall Stewart sctp_reset_in_stream(stcb, liste->number_entries, liste->req.list_of_streams); 213917205eccSRandall Stewart TAILQ_REMOVE(&asoc->resetHead, liste, next_resp); 2140207304d4SRandall Stewart SCTP_FREE(liste, SCTP_M_STRESET); 21413c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 214217205eccSRandall Stewart liste = TAILQ_FIRST(&asoc->resetHead); 21434a9ef3f8SMichael Tuexen if (TAILQ_EMPTY(&asoc->resetHead)) { 214417205eccSRandall Stewart /* All can be removed */ 21454a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ctl, &asoc->pending_reply_queue, next, nctl) { 214617205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 214717205eccSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag); 214817205eccSRandall Stewart if (*abort_flag) { 214917205eccSRandall Stewart return (0); 215017205eccSRandall Stewart } 215117205eccSRandall Stewart } 21524a9ef3f8SMichael Tuexen } else { 21534a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ctl, &asoc->pending_reply_queue, next, nctl) { 2154*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(ctl->sinfo_tsn, liste->tsn)) { 21554a9ef3f8SMichael Tuexen break; 21564a9ef3f8SMichael Tuexen } 215717205eccSRandall Stewart /* 215817205eccSRandall Stewart * if ctl->sinfo_tsn is <= liste->tsn we can 215917205eccSRandall Stewart * process it which is the NOT of 216017205eccSRandall Stewart * ctl->sinfo_tsn > liste->tsn 216117205eccSRandall Stewart */ 216217205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 216317205eccSRandall Stewart sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag); 216417205eccSRandall Stewart if (*abort_flag) { 216517205eccSRandall Stewart return (0); 216617205eccSRandall Stewart } 216717205eccSRandall Stewart } 216817205eccSRandall Stewart } 216917205eccSRandall Stewart /* 217017205eccSRandall Stewart * Now service re-assembly to pick up anything that has been 217117205eccSRandall Stewart * held on reassembly queue? 217217205eccSRandall Stewart */ 217317205eccSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 217417205eccSRandall Stewart need_reasm_check = 0; 217517205eccSRandall Stewart } 2176139bc87fSRandall Stewart if (need_reasm_check) { 2177139bc87fSRandall Stewart /* Another one waits ? */ 2178139bc87fSRandall Stewart sctp_deliver_reasm_check(stcb, asoc); 2179139bc87fSRandall Stewart } 2180f8829a4aSRandall Stewart return (1); 2181f8829a4aSRandall Stewart } 2182f8829a4aSRandall Stewart 2183f8829a4aSRandall Stewart int8_t sctp_map_lookup_tab[256] = { 2184b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2185b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2186b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2187b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2188b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2189b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2190b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2191b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 6, 2192b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2193b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2194b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2195b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2196b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2197b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2198b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2199b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 7, 2200b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2201b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2202b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2203b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2204b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2205b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2206b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2207b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 6, 2208b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2209b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2210b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2211b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2212b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2213b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2214b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2215b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 8 2216f8829a4aSRandall Stewart }; 2217f8829a4aSRandall Stewart 2218f8829a4aSRandall Stewart 2219f8829a4aSRandall Stewart void 2220b5c16493SMichael Tuexen sctp_slide_mapping_arrays(struct sctp_tcb *stcb) 2221f8829a4aSRandall Stewart { 2222f8829a4aSRandall Stewart /* 2223f8829a4aSRandall Stewart * Now we also need to check the mapping array in a couple of ways. 2224f8829a4aSRandall Stewart * 1) Did we move the cum-ack point? 222566bd30bdSRandall Stewart * 222666bd30bdSRandall Stewart * When you first glance at this you might think that all entries that 222766bd30bdSRandall Stewart * make up the postion of the cum-ack would be in the nr-mapping 222866bd30bdSRandall Stewart * array only.. i.e. things up to the cum-ack are always 222966bd30bdSRandall Stewart * deliverable. Thats true with one exception, when its a fragmented 223066bd30bdSRandall Stewart * message we may not deliver the data until some threshold (or all 223166bd30bdSRandall Stewart * of it) is in place. So we must OR the nr_mapping_array and 223266bd30bdSRandall Stewart * mapping_array to get a true picture of the cum-ack. 2233f8829a4aSRandall Stewart */ 2234f8829a4aSRandall Stewart struct sctp_association *asoc; 2235b3f1ea41SRandall Stewart int at; 223666bd30bdSRandall Stewart uint8_t val; 2237f8829a4aSRandall Stewart int slide_from, slide_end, lgap, distance; 223877acdc25SRandall Stewart uint32_t old_cumack, old_base, old_highest, highest_tsn; 2239f8829a4aSRandall Stewart 2240f8829a4aSRandall Stewart asoc = &stcb->asoc; 2241f8829a4aSRandall Stewart at = 0; 2242f8829a4aSRandall Stewart 2243f8829a4aSRandall Stewart old_cumack = asoc->cumulative_tsn; 2244f8829a4aSRandall Stewart old_base = asoc->mapping_array_base_tsn; 2245f8829a4aSRandall Stewart old_highest = asoc->highest_tsn_inside_map; 2246f8829a4aSRandall Stewart /* 2247f8829a4aSRandall Stewart * We could probably improve this a small bit by calculating the 2248f8829a4aSRandall Stewart * offset of the current cum-ack as the starting point. 2249f8829a4aSRandall Stewart */ 2250f8829a4aSRandall Stewart at = 0; 2251b5c16493SMichael Tuexen for (slide_from = 0; slide_from < stcb->asoc.mapping_array_size; slide_from++) { 225266bd30bdSRandall Stewart val = asoc->nr_mapping_array[slide_from] | asoc->mapping_array[slide_from]; 225366bd30bdSRandall Stewart if (val == 0xff) { 2254f8829a4aSRandall Stewart at += 8; 2255f8829a4aSRandall Stewart } else { 2256f8829a4aSRandall Stewart /* there is a 0 bit */ 225766bd30bdSRandall Stewart at += sctp_map_lookup_tab[val]; 2258f8829a4aSRandall Stewart break; 2259f8829a4aSRandall Stewart } 2260f8829a4aSRandall Stewart } 2261b5c16493SMichael Tuexen asoc->cumulative_tsn = asoc->mapping_array_base_tsn + (at - 1); 2262f8829a4aSRandall Stewart 2263*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->cumulative_tsn, asoc->highest_tsn_inside_map) && 2264*20b07a4dSMichael Tuexen SCTP_TSN_GT(asoc->cumulative_tsn, asoc->highest_tsn_inside_nr_map)) { 2265a5d547adSRandall Stewart #ifdef INVARIANTS 2266ceaad40aSRandall Stewart panic("huh, cumack 0x%x greater than high-tsn 0x%x in map", 2267ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 2268f8829a4aSRandall Stewart #else 2269ceaad40aSRandall Stewart SCTP_PRINTF("huh, cumack 0x%x greater than high-tsn 0x%x in map - should panic?\n", 2270ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 22710e13104dSRandall Stewart sctp_print_mapping_array(asoc); 2272b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2273b3f1ea41SRandall Stewart sctp_log_map(0, 6, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 2274b3f1ea41SRandall Stewart } 2275f8829a4aSRandall Stewart asoc->highest_tsn_inside_map = asoc->cumulative_tsn; 2276830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn; 2277f8829a4aSRandall Stewart #endif 2278f8829a4aSRandall Stewart } 2279*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { 228077acdc25SRandall Stewart highest_tsn = asoc->highest_tsn_inside_nr_map; 228177acdc25SRandall Stewart } else { 228277acdc25SRandall Stewart highest_tsn = asoc->highest_tsn_inside_map; 228377acdc25SRandall Stewart } 228477acdc25SRandall Stewart if ((asoc->cumulative_tsn == highest_tsn) && (at >= 8)) { 2285f8829a4aSRandall Stewart /* The complete array was completed by a single FR */ 228677acdc25SRandall Stewart /* highest becomes the cum-ack */ 228737f144ebSMichael Tuexen int clr; 228837f144ebSMichael Tuexen 228937f144ebSMichael Tuexen #ifdef INVARIANTS 229037f144ebSMichael Tuexen unsigned int i; 229137f144ebSMichael Tuexen 229237f144ebSMichael Tuexen #endif 2293f8829a4aSRandall Stewart 2294f8829a4aSRandall Stewart /* clear the array */ 2295b5c16493SMichael Tuexen clr = ((at + 7) >> 3); 2296c4739e2fSRandall Stewart if (clr > asoc->mapping_array_size) { 2297f8829a4aSRandall Stewart clr = asoc->mapping_array_size; 2298f8829a4aSRandall Stewart } 2299f8829a4aSRandall Stewart memset(asoc->mapping_array, 0, clr); 2300830d754dSRandall Stewart memset(asoc->nr_mapping_array, 0, clr); 230137f144ebSMichael Tuexen #ifdef INVARIANTS 2302b5c16493SMichael Tuexen for (i = 0; i < asoc->mapping_array_size; i++) { 2303b5c16493SMichael Tuexen if ((asoc->mapping_array[i]) || (asoc->nr_mapping_array[i])) { 2304b5c16493SMichael Tuexen printf("Error Mapping array's not clean at clear\n"); 2305b5c16493SMichael Tuexen sctp_print_mapping_array(asoc); 2306b5c16493SMichael Tuexen } 2307b5c16493SMichael Tuexen } 230837f144ebSMichael Tuexen #endif 230977acdc25SRandall Stewart asoc->mapping_array_base_tsn = asoc->cumulative_tsn + 1; 231077acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->highest_tsn_inside_map = asoc->cumulative_tsn; 2311f8829a4aSRandall Stewart } else if (at >= 8) { 2312f8829a4aSRandall Stewart /* we can slide the mapping array down */ 2313b3f1ea41SRandall Stewart /* slide_from holds where we hit the first NON 0xff byte */ 2314b3f1ea41SRandall Stewart 2315f8829a4aSRandall Stewart /* 2316f8829a4aSRandall Stewart * now calculate the ceiling of the move using our highest 2317f8829a4aSRandall Stewart * TSN value 2318f8829a4aSRandall Stewart */ 231977acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(lgap, highest_tsn, asoc->mapping_array_base_tsn); 232077acdc25SRandall Stewart slide_end = (lgap >> 3); 2321f8829a4aSRandall Stewart if (slide_end < slide_from) { 232277acdc25SRandall Stewart sctp_print_mapping_array(asoc); 2323d55b0b1bSRandall Stewart #ifdef INVARIANTS 2324f8829a4aSRandall Stewart panic("impossible slide"); 2325d55b0b1bSRandall Stewart #else 232677acdc25SRandall Stewart printf("impossible slide lgap:%x slide_end:%x slide_from:%x? at:%d\n", 232777acdc25SRandall Stewart lgap, slide_end, slide_from, at); 2328d55b0b1bSRandall Stewart return; 2329d55b0b1bSRandall Stewart #endif 2330f8829a4aSRandall Stewart } 2331b3f1ea41SRandall Stewart if (slide_end > asoc->mapping_array_size) { 2332b3f1ea41SRandall Stewart #ifdef INVARIANTS 2333b3f1ea41SRandall Stewart panic("would overrun buffer"); 2334b3f1ea41SRandall Stewart #else 2335b3f1ea41SRandall Stewart printf("Gak, would have overrun map end:%d slide_end:%d\n", 2336b3f1ea41SRandall Stewart asoc->mapping_array_size, slide_end); 2337b3f1ea41SRandall Stewart slide_end = asoc->mapping_array_size; 2338b3f1ea41SRandall Stewart #endif 2339b3f1ea41SRandall Stewart } 2340f8829a4aSRandall Stewart distance = (slide_end - slide_from) + 1; 2341b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2342f8829a4aSRandall Stewart sctp_log_map(old_base, old_cumack, old_highest, 2343f8829a4aSRandall Stewart SCTP_MAP_PREPARE_SLIDE); 2344f8829a4aSRandall Stewart sctp_log_map((uint32_t) slide_from, (uint32_t) slide_end, 2345f8829a4aSRandall Stewart (uint32_t) lgap, SCTP_MAP_SLIDE_FROM); 234680fefe0aSRandall Stewart } 2347f8829a4aSRandall Stewart if (distance + slide_from > asoc->mapping_array_size || 2348f8829a4aSRandall Stewart distance < 0) { 2349f8829a4aSRandall Stewart /* 2350f8829a4aSRandall Stewart * Here we do NOT slide forward the array so that 2351f8829a4aSRandall Stewart * hopefully when more data comes in to fill it up 2352f8829a4aSRandall Stewart * we will be able to slide it forward. Really I 2353f8829a4aSRandall Stewart * don't think this should happen :-0 2354f8829a4aSRandall Stewart */ 2355f8829a4aSRandall Stewart 2356b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2357f8829a4aSRandall Stewart sctp_log_map((uint32_t) distance, (uint32_t) slide_from, 2358f8829a4aSRandall Stewart (uint32_t) asoc->mapping_array_size, 2359f8829a4aSRandall Stewart SCTP_MAP_SLIDE_NONE); 236080fefe0aSRandall Stewart } 2361f8829a4aSRandall Stewart } else { 2362f8829a4aSRandall Stewart int ii; 2363f8829a4aSRandall Stewart 2364f8829a4aSRandall Stewart for (ii = 0; ii < distance; ii++) { 236537f144ebSMichael Tuexen asoc->mapping_array[ii] = asoc->mapping_array[slide_from + ii]; 236637f144ebSMichael Tuexen asoc->nr_mapping_array[ii] = asoc->nr_mapping_array[slide_from + ii]; 236777acdc25SRandall Stewart 2368f8829a4aSRandall Stewart } 2369aed5947cSMichael Tuexen for (ii = distance; ii < asoc->mapping_array_size; ii++) { 2370f8829a4aSRandall Stewart asoc->mapping_array[ii] = 0; 237177acdc25SRandall Stewart asoc->nr_mapping_array[ii] = 0; 2372f8829a4aSRandall Stewart } 2373ee94f0a2SMichael Tuexen if (asoc->highest_tsn_inside_map + 1 == asoc->mapping_array_base_tsn) { 2374ee94f0a2SMichael Tuexen asoc->highest_tsn_inside_map += (slide_from << 3); 2375ee94f0a2SMichael Tuexen } 2376ee94f0a2SMichael Tuexen if (asoc->highest_tsn_inside_nr_map + 1 == asoc->mapping_array_base_tsn) { 2377ee94f0a2SMichael Tuexen asoc->highest_tsn_inside_nr_map += (slide_from << 3); 2378ee94f0a2SMichael Tuexen } 2379f8829a4aSRandall Stewart asoc->mapping_array_base_tsn += (slide_from << 3); 2380b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2381f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, 2382f8829a4aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map, 2383f8829a4aSRandall Stewart SCTP_MAP_SLIDE_RESULT); 238480fefe0aSRandall Stewart } 2385830d754dSRandall Stewart } 2386830d754dSRandall Stewart } 2387b5c16493SMichael Tuexen } 2388b5c16493SMichael Tuexen 2389b5c16493SMichael Tuexen 2390b5c16493SMichael Tuexen void 2391b5c16493SMichael Tuexen sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap, int *abort_flag) 2392b5c16493SMichael Tuexen { 2393b5c16493SMichael Tuexen struct sctp_association *asoc; 2394b5c16493SMichael Tuexen uint32_t highest_tsn; 2395b5c16493SMichael Tuexen 2396b5c16493SMichael Tuexen asoc = &stcb->asoc; 2397*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { 2398b5c16493SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_nr_map; 2399b5c16493SMichael Tuexen } else { 2400b5c16493SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_map; 2401b5c16493SMichael Tuexen } 2402b5c16493SMichael Tuexen 2403830d754dSRandall Stewart /* 2404f8829a4aSRandall Stewart * Now we need to see if we need to queue a sack or just start the 2405f8829a4aSRandall Stewart * timer (if allowed). 2406f8829a4aSRandall Stewart */ 2407f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 2408f8829a4aSRandall Stewart /* 2409b5c16493SMichael Tuexen * Ok special case, in SHUTDOWN-SENT case. here we maker 2410b5c16493SMichael Tuexen * sure SACK timer is off and instead send a SHUTDOWN and a 2411b5c16493SMichael Tuexen * SACK 2412f8829a4aSRandall Stewart */ 2413139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2414f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_RECV, 2415a5d547adSRandall Stewart stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_INDATA + SCTP_LOC_18); 2416f8829a4aSRandall Stewart } 2417f8829a4aSRandall Stewart sctp_send_shutdown(stcb, stcb->asoc.primary_destination); 2418f8829a4aSRandall Stewart sctp_send_sack(stcb); 2419f8829a4aSRandall Stewart } else { 2420f8829a4aSRandall Stewart int is_a_gap; 2421f8829a4aSRandall Stewart 2422f8829a4aSRandall Stewart /* is there a gap now ? */ 2423*20b07a4dSMichael Tuexen is_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn); 2424f8829a4aSRandall Stewart 2425f8829a4aSRandall Stewart /* 2426b5c16493SMichael Tuexen * CMT DAC algorithm: increase number of packets received 2427b5c16493SMichael Tuexen * since last ack 2428f8829a4aSRandall Stewart */ 2429f8829a4aSRandall Stewart stcb->asoc.cmt_dac_pkts_rcvd++; 2430f8829a4aSRandall Stewart 243142551e99SRandall Stewart if ((stcb->asoc.send_sack == 1) || /* We need to send a 243242551e99SRandall Stewart * SACK */ 2433f8829a4aSRandall Stewart ((was_a_gap) && (is_a_gap == 0)) || /* was a gap, but no 2434f8829a4aSRandall Stewart * longer is one */ 2435f8829a4aSRandall Stewart (stcb->asoc.numduptsns) || /* we have dup's */ 2436f8829a4aSRandall Stewart (is_a_gap) || /* is still a gap */ 243742551e99SRandall Stewart (stcb->asoc.delayed_ack == 0) || /* Delayed sack disabled */ 243842551e99SRandall Stewart (stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) /* hit limit of pkts */ 2439f8829a4aSRandall Stewart ) { 2440f8829a4aSRandall Stewart 24417c99d56fSMichael Tuexen if ((stcb->asoc.sctp_cmt_on_off > 0) && 2442b3f1ea41SRandall Stewart (SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) && 244342551e99SRandall Stewart (stcb->asoc.send_sack == 0) && 2444f8829a4aSRandall Stewart (stcb->asoc.numduptsns == 0) && 2445f8829a4aSRandall Stewart (stcb->asoc.delayed_ack) && 2446139bc87fSRandall Stewart (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer))) { 2447f8829a4aSRandall Stewart 2448f8829a4aSRandall Stewart /* 2449b5c16493SMichael Tuexen * CMT DAC algorithm: With CMT, delay acks 2450b5c16493SMichael Tuexen * even in the face of 2451f8829a4aSRandall Stewart * 2452b5c16493SMichael Tuexen * reordering. Therefore, if acks that do not 2453b5c16493SMichael Tuexen * have to be sent because of the above 2454b5c16493SMichael Tuexen * reasons, will be delayed. That is, acks 2455b5c16493SMichael Tuexen * that would have been sent due to gap 2456b5c16493SMichael Tuexen * reports will be delayed with DAC. Start 2457f8829a4aSRandall Stewart * the delayed ack timer. 2458f8829a4aSRandall Stewart */ 2459f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2460f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2461f8829a4aSRandall Stewart } else { 2462f8829a4aSRandall Stewart /* 2463b5c16493SMichael Tuexen * Ok we must build a SACK since the timer 2464b5c16493SMichael Tuexen * is pending, we got our first packet OR 2465b5c16493SMichael Tuexen * there are gaps or duplicates. 2466f8829a4aSRandall Stewart */ 2467ad81507eSRandall Stewart (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer); 2468f8829a4aSRandall Stewart sctp_send_sack(stcb); 2469f8829a4aSRandall Stewart } 2470f8829a4aSRandall Stewart } else { 247142551e99SRandall Stewart if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2472f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2473f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2474f8829a4aSRandall Stewart } 2475f8829a4aSRandall Stewart } 2476f8829a4aSRandall Stewart } 2477f8829a4aSRandall Stewart } 2478f8829a4aSRandall Stewart 2479f8829a4aSRandall Stewart void 2480f8829a4aSRandall Stewart sctp_service_queues(struct sctp_tcb *stcb, struct sctp_association *asoc) 2481f8829a4aSRandall Stewart { 2482f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 2483810ec536SMichael Tuexen uint32_t tsize, pd_point; 2484f8829a4aSRandall Stewart uint16_t nxt_todel; 2485f8829a4aSRandall Stewart 2486f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 2487f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 2488f8829a4aSRandall Stewart } 2489f8829a4aSRandall Stewart /* Can we proceed further, i.e. the PD-API is complete */ 2490f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 2491f8829a4aSRandall Stewart /* no */ 2492f8829a4aSRandall Stewart return; 2493f8829a4aSRandall Stewart } 2494f8829a4aSRandall Stewart /* 2495f8829a4aSRandall Stewart * Now is there some other chunk I can deliver from the reassembly 2496f8829a4aSRandall Stewart * queue. 2497f8829a4aSRandall Stewart */ 2498139bc87fSRandall Stewart doit_again: 2499f8829a4aSRandall Stewart chk = TAILQ_FIRST(&asoc->reasmqueue); 2500f8829a4aSRandall Stewart if (chk == NULL) { 2501f8829a4aSRandall Stewart asoc->size_on_reasm_queue = 0; 2502f8829a4aSRandall Stewart asoc->cnt_on_reasm_queue = 0; 2503f8829a4aSRandall Stewart return; 2504f8829a4aSRandall Stewart } 2505f8829a4aSRandall Stewart nxt_todel = asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1; 2506f8829a4aSRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) && 2507f8829a4aSRandall Stewart ((nxt_todel == chk->rec.data.stream_seq) || 2508f8829a4aSRandall Stewart (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) { 2509f8829a4aSRandall Stewart /* 2510f8829a4aSRandall Stewart * Yep the first one is here. We setup to start reception, 2511f8829a4aSRandall Stewart * by backing down the TSN just in case we can't deliver. 2512f8829a4aSRandall Stewart */ 2513f8829a4aSRandall Stewart 2514f8829a4aSRandall Stewart /* 2515f8829a4aSRandall Stewart * Before we start though either all of the message should 251624ae5c4aSMichael Tuexen * be here or the socket buffer max or nothing on the 2517f8829a4aSRandall Stewart * delivery queue and something can be delivered. 2518f8829a4aSRandall Stewart */ 2519810ec536SMichael Tuexen if (stcb->sctp_socket) { 252024ae5c4aSMichael Tuexen pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), 2521810ec536SMichael Tuexen stcb->sctp_ep->partial_delivery_point); 2522810ec536SMichael Tuexen } else { 2523810ec536SMichael Tuexen pd_point = stcb->sctp_ep->partial_delivery_point; 2524810ec536SMichael Tuexen } 2525810ec536SMichael Tuexen if (sctp_is_all_msg_on_reasm(asoc, &tsize) || (tsize >= pd_point)) { 2526f8829a4aSRandall Stewart asoc->fragmented_delivery_inprogress = 1; 2527f8829a4aSRandall Stewart asoc->tsn_last_delivered = chk->rec.data.TSN_seq - 1; 2528f8829a4aSRandall Stewart asoc->str_of_pdapi = chk->rec.data.stream_number; 2529f8829a4aSRandall Stewart asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 2530f8829a4aSRandall Stewart asoc->pdapi_ppid = chk->rec.data.payloadtype; 2531f8829a4aSRandall Stewart asoc->fragment_flags = chk->rec.data.rcv_flags; 2532f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 2533139bc87fSRandall Stewart if (asoc->fragmented_delivery_inprogress == 0) { 2534139bc87fSRandall Stewart goto doit_again; 2535139bc87fSRandall Stewart } 2536f8829a4aSRandall Stewart } 2537f8829a4aSRandall Stewart } 2538f8829a4aSRandall Stewart } 2539f8829a4aSRandall Stewart 2540f8829a4aSRandall Stewart int 2541f8829a4aSRandall Stewart sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, 2542f8829a4aSRandall Stewart struct sctphdr *sh, struct sctp_inpcb *inp, struct sctp_tcb *stcb, 2543f8829a4aSRandall Stewart struct sctp_nets *net, uint32_t * high_tsn) 2544f8829a4aSRandall Stewart { 2545f8829a4aSRandall Stewart struct sctp_data_chunk *ch, chunk_buf; 2546f8829a4aSRandall Stewart struct sctp_association *asoc; 2547f8829a4aSRandall Stewart int num_chunks = 0; /* number of control chunks processed */ 2548f8829a4aSRandall Stewart int stop_proc = 0; 2549f8829a4aSRandall Stewart int chk_length, break_flag, last_chunk; 25508f777478SMichael Tuexen int abort_flag = 0, was_a_gap; 2551f8829a4aSRandall Stewart struct mbuf *m; 25528f777478SMichael Tuexen uint32_t highest_tsn; 2553f8829a4aSRandall Stewart 2554f8829a4aSRandall Stewart /* set the rwnd */ 2555f8829a4aSRandall Stewart sctp_set_rwnd(stcb, &stcb->asoc); 2556f8829a4aSRandall Stewart 2557f8829a4aSRandall Stewart m = *mm; 2558f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 2559f8829a4aSRandall Stewart asoc = &stcb->asoc; 2560*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { 25618f777478SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_nr_map; 25628f777478SMichael Tuexen } else { 25638f777478SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_map; 2564f8829a4aSRandall Stewart } 2565*20b07a4dSMichael Tuexen was_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn); 2566f8829a4aSRandall Stewart /* 2567f8829a4aSRandall Stewart * setup where we got the last DATA packet from for any SACK that 2568f8829a4aSRandall Stewart * may need to go out. Don't bump the net. This is done ONLY when a 2569f8829a4aSRandall Stewart * chunk is assigned. 2570f8829a4aSRandall Stewart */ 2571f8829a4aSRandall Stewart asoc->last_data_chunk_from = net; 2572f8829a4aSRandall Stewart 2573d06c82f1SRandall Stewart /*- 2574f8829a4aSRandall Stewart * Now before we proceed we must figure out if this is a wasted 2575f8829a4aSRandall Stewart * cluster... i.e. it is a small packet sent in and yet the driver 2576f8829a4aSRandall Stewart * underneath allocated a full cluster for it. If so we must copy it 2577f8829a4aSRandall Stewart * to a smaller mbuf and free up the cluster mbuf. This will help 2578d06c82f1SRandall Stewart * with cluster starvation. Note for __Panda__ we don't do this 2579d06c82f1SRandall Stewart * since it has clusters all the way down to 64 bytes. 2580f8829a4aSRandall Stewart */ 258144b7479bSRandall Stewart if (SCTP_BUF_LEN(m) < (long)MLEN && SCTP_BUF_NEXT(m) == NULL) { 2582f8829a4aSRandall Stewart /* we only handle mbufs that are singletons.. not chains */ 2583139bc87fSRandall Stewart m = sctp_get_mbuf_for_msg(SCTP_BUF_LEN(m), 0, M_DONTWAIT, 1, MT_DATA); 2584f8829a4aSRandall Stewart if (m) { 2585f8829a4aSRandall Stewart /* ok lets see if we can copy the data up */ 2586f8829a4aSRandall Stewart caddr_t *from, *to; 2587f8829a4aSRandall Stewart 2588f8829a4aSRandall Stewart /* get the pointers and copy */ 2589f8829a4aSRandall Stewart to = mtod(m, caddr_t *); 2590f8829a4aSRandall Stewart from = mtod((*mm), caddr_t *); 2591139bc87fSRandall Stewart memcpy(to, from, SCTP_BUF_LEN((*mm))); 2592f8829a4aSRandall Stewart /* copy the length and free up the old */ 2593139bc87fSRandall Stewart SCTP_BUF_LEN(m) = SCTP_BUF_LEN((*mm)); 2594f8829a4aSRandall Stewart sctp_m_freem(*mm); 2595f8829a4aSRandall Stewart /* sucess, back copy */ 2596f8829a4aSRandall Stewart *mm = m; 2597f8829a4aSRandall Stewart } else { 2598f8829a4aSRandall Stewart /* We are in trouble in the mbuf world .. yikes */ 2599f8829a4aSRandall Stewart m = *mm; 2600f8829a4aSRandall Stewart } 2601f8829a4aSRandall Stewart } 2602f8829a4aSRandall Stewart /* get pointer to the first chunk header */ 2603f8829a4aSRandall Stewart ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset, 2604f8829a4aSRandall Stewart sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); 2605f8829a4aSRandall Stewart if (ch == NULL) { 2606f8829a4aSRandall Stewart return (1); 2607f8829a4aSRandall Stewart } 2608f8829a4aSRandall Stewart /* 2609f8829a4aSRandall Stewart * process all DATA chunks... 2610f8829a4aSRandall Stewart */ 2611f8829a4aSRandall Stewart *high_tsn = asoc->cumulative_tsn; 2612f8829a4aSRandall Stewart break_flag = 0; 261342551e99SRandall Stewart asoc->data_pkts_seen++; 2614f8829a4aSRandall Stewart while (stop_proc == 0) { 2615f8829a4aSRandall Stewart /* validate chunk length */ 2616f8829a4aSRandall Stewart chk_length = ntohs(ch->ch.chunk_length); 2617f8829a4aSRandall Stewart if (length - *offset < chk_length) { 2618f8829a4aSRandall Stewart /* all done, mutulated chunk */ 2619f8829a4aSRandall Stewart stop_proc = 1; 2620f8829a4aSRandall Stewart break; 2621f8829a4aSRandall Stewart } 2622f8829a4aSRandall Stewart if (ch->ch.chunk_type == SCTP_DATA) { 2623f8829a4aSRandall Stewart if ((size_t)chk_length < sizeof(struct sctp_data_chunk) + 1) { 2624f8829a4aSRandall Stewart /* 2625f8829a4aSRandall Stewart * Need to send an abort since we had a 2626f8829a4aSRandall Stewart * invalid data chunk. 2627f8829a4aSRandall Stewart */ 2628f8829a4aSRandall Stewart struct mbuf *op_err; 2629f8829a4aSRandall Stewart 2630139bc87fSRandall Stewart op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 2 * sizeof(uint32_t)), 2631f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 2632f8829a4aSRandall Stewart 2633f8829a4aSRandall Stewart if (op_err) { 2634f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 2635f8829a4aSRandall Stewart uint32_t *ippp; 2636f8829a4aSRandall Stewart 2637139bc87fSRandall Stewart SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr) + 2638f8829a4aSRandall Stewart (2 * sizeof(uint32_t)); 2639f8829a4aSRandall Stewart ph = mtod(op_err, struct sctp_paramhdr *); 2640f8829a4aSRandall Stewart ph->param_type = 2641f8829a4aSRandall Stewart htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 2642139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(op_err)); 2643f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 2644a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_19); 2645f8829a4aSRandall Stewart ippp++; 2646f8829a4aSRandall Stewart *ippp = asoc->cumulative_tsn; 2647f8829a4aSRandall Stewart 2648f8829a4aSRandall Stewart } 2649a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_19; 2650f8829a4aSRandall Stewart sctp_abort_association(inp, stcb, m, iphlen, sh, 2651c54a18d2SRandall Stewart op_err, 0, net->port); 2652f8829a4aSRandall Stewart return (2); 2653f8829a4aSRandall Stewart } 2654f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 2655f8829a4aSRandall Stewart sctp_audit_log(0xB1, 0); 2656f8829a4aSRandall Stewart #endif 2657f8829a4aSRandall Stewart if (SCTP_SIZE32(chk_length) == (length - *offset)) { 2658f8829a4aSRandall Stewart last_chunk = 1; 2659f8829a4aSRandall Stewart } else { 2660f8829a4aSRandall Stewart last_chunk = 0; 2661f8829a4aSRandall Stewart } 2662f8829a4aSRandall Stewart if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset, ch, 2663f8829a4aSRandall Stewart chk_length, net, high_tsn, &abort_flag, &break_flag, 2664f8829a4aSRandall Stewart last_chunk)) { 2665f8829a4aSRandall Stewart num_chunks++; 2666f8829a4aSRandall Stewart } 2667f8829a4aSRandall Stewart if (abort_flag) 2668f8829a4aSRandall Stewart return (2); 2669f8829a4aSRandall Stewart 2670f8829a4aSRandall Stewart if (break_flag) { 2671f8829a4aSRandall Stewart /* 2672f8829a4aSRandall Stewart * Set because of out of rwnd space and no 2673f8829a4aSRandall Stewart * drop rep space left. 2674f8829a4aSRandall Stewart */ 2675f8829a4aSRandall Stewart stop_proc = 1; 2676f8829a4aSRandall Stewart break; 2677f8829a4aSRandall Stewart } 2678f8829a4aSRandall Stewart } else { 2679f8829a4aSRandall Stewart /* not a data chunk in the data region */ 2680f8829a4aSRandall Stewart switch (ch->ch.chunk_type) { 2681f8829a4aSRandall Stewart case SCTP_INITIATION: 2682f8829a4aSRandall Stewart case SCTP_INITIATION_ACK: 2683f8829a4aSRandall Stewart case SCTP_SELECTIVE_ACK: 2684830d754dSRandall Stewart case SCTP_NR_SELECTIVE_ACK: /* EY */ 2685f8829a4aSRandall Stewart case SCTP_HEARTBEAT_REQUEST: 2686f8829a4aSRandall Stewart case SCTP_HEARTBEAT_ACK: 2687f8829a4aSRandall Stewart case SCTP_ABORT_ASSOCIATION: 2688f8829a4aSRandall Stewart case SCTP_SHUTDOWN: 2689f8829a4aSRandall Stewart case SCTP_SHUTDOWN_ACK: 2690f8829a4aSRandall Stewart case SCTP_OPERATION_ERROR: 2691f8829a4aSRandall Stewart case SCTP_COOKIE_ECHO: 2692f8829a4aSRandall Stewart case SCTP_COOKIE_ACK: 2693f8829a4aSRandall Stewart case SCTP_ECN_ECHO: 2694f8829a4aSRandall Stewart case SCTP_ECN_CWR: 2695f8829a4aSRandall Stewart case SCTP_SHUTDOWN_COMPLETE: 2696f8829a4aSRandall Stewart case SCTP_AUTHENTICATION: 2697f8829a4aSRandall Stewart case SCTP_ASCONF_ACK: 2698f8829a4aSRandall Stewart case SCTP_PACKET_DROPPED: 2699f8829a4aSRandall Stewart case SCTP_STREAM_RESET: 2700f8829a4aSRandall Stewart case SCTP_FORWARD_CUM_TSN: 2701f8829a4aSRandall Stewart case SCTP_ASCONF: 2702f8829a4aSRandall Stewart /* 2703f8829a4aSRandall Stewart * Now, what do we do with KNOWN chunks that 2704f8829a4aSRandall Stewart * are NOT in the right place? 2705f8829a4aSRandall Stewart * 2706f8829a4aSRandall Stewart * For now, I do nothing but ignore them. We 2707f8829a4aSRandall Stewart * may later want to add sysctl stuff to 2708f8829a4aSRandall Stewart * switch out and do either an ABORT() or 2709f8829a4aSRandall Stewart * possibly process them. 2710f8829a4aSRandall Stewart */ 2711b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_data_order)) { 2712f8829a4aSRandall Stewart struct mbuf *op_err; 2713f8829a4aSRandall Stewart 2714f8829a4aSRandall Stewart op_err = sctp_generate_invmanparam(SCTP_CAUSE_PROTOCOL_VIOLATION); 2715c54a18d2SRandall Stewart sctp_abort_association(inp, stcb, m, iphlen, sh, op_err, 0, net->port); 2716f8829a4aSRandall Stewart return (2); 2717f8829a4aSRandall Stewart } 2718f8829a4aSRandall Stewart break; 2719f8829a4aSRandall Stewart default: 2720f8829a4aSRandall Stewart /* unknown chunk type, use bit rules */ 2721f8829a4aSRandall Stewart if (ch->ch.chunk_type & 0x40) { 2722f8829a4aSRandall Stewart /* Add a error report to the queue */ 2723d61a0ae0SRandall Stewart struct mbuf *merr; 2724f8829a4aSRandall Stewart struct sctp_paramhdr *phd; 2725f8829a4aSRandall Stewart 2726d61a0ae0SRandall Stewart merr = sctp_get_mbuf_for_msg(sizeof(*phd), 0, M_DONTWAIT, 1, MT_DATA); 2727d61a0ae0SRandall Stewart if (merr) { 2728d61a0ae0SRandall Stewart phd = mtod(merr, struct sctp_paramhdr *); 2729f8829a4aSRandall Stewart /* 2730f8829a4aSRandall Stewart * We cheat and use param 2731f8829a4aSRandall Stewart * type since we did not 2732f8829a4aSRandall Stewart * bother to define a error 2733f8829a4aSRandall Stewart * cause struct. They are 2734f8829a4aSRandall Stewart * the same basic format 2735f8829a4aSRandall Stewart * with different names. 2736f8829a4aSRandall Stewart */ 2737f8829a4aSRandall Stewart phd->param_type = 2738f8829a4aSRandall Stewart htons(SCTP_CAUSE_UNRECOG_CHUNK); 2739f8829a4aSRandall Stewart phd->param_length = 2740f8829a4aSRandall Stewart htons(chk_length + sizeof(*phd)); 2741d61a0ae0SRandall Stewart SCTP_BUF_LEN(merr) = sizeof(*phd); 2742d61a0ae0SRandall Stewart SCTP_BUF_NEXT(merr) = SCTP_M_COPYM(m, *offset, 2743f8829a4aSRandall Stewart SCTP_SIZE32(chk_length), 2744f8829a4aSRandall Stewart M_DONTWAIT); 2745d61a0ae0SRandall Stewart if (SCTP_BUF_NEXT(merr)) { 2746d61a0ae0SRandall Stewart sctp_queue_op_err(stcb, merr); 2747f8829a4aSRandall Stewart } else { 2748d61a0ae0SRandall Stewart sctp_m_freem(merr); 2749f8829a4aSRandall Stewart } 2750f8829a4aSRandall Stewart } 2751f8829a4aSRandall Stewart } 2752f8829a4aSRandall Stewart if ((ch->ch.chunk_type & 0x80) == 0) { 2753f8829a4aSRandall Stewart /* discard the rest of this packet */ 2754f8829a4aSRandall Stewart stop_proc = 1; 2755f8829a4aSRandall Stewart } /* else skip this bad chunk and 2756f8829a4aSRandall Stewart * continue... */ 2757f8829a4aSRandall Stewart break; 2758f8829a4aSRandall Stewart }; /* switch of chunk type */ 2759f8829a4aSRandall Stewart } 2760f8829a4aSRandall Stewart *offset += SCTP_SIZE32(chk_length); 2761f8829a4aSRandall Stewart if ((*offset >= length) || stop_proc) { 2762f8829a4aSRandall Stewart /* no more data left in the mbuf chain */ 2763f8829a4aSRandall Stewart stop_proc = 1; 2764f8829a4aSRandall Stewart continue; 2765f8829a4aSRandall Stewart } 2766f8829a4aSRandall Stewart ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset, 2767f8829a4aSRandall Stewart sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); 2768f8829a4aSRandall Stewart if (ch == NULL) { 2769f8829a4aSRandall Stewart *offset = length; 2770f8829a4aSRandall Stewart stop_proc = 1; 2771f8829a4aSRandall Stewart break; 2772f8829a4aSRandall Stewart 2773f8829a4aSRandall Stewart } 2774f8829a4aSRandall Stewart } /* while */ 2775f8829a4aSRandall Stewart if (break_flag) { 2776f8829a4aSRandall Stewart /* 2777f8829a4aSRandall Stewart * we need to report rwnd overrun drops. 2778f8829a4aSRandall Stewart */ 2779f8829a4aSRandall Stewart sctp_send_packet_dropped(stcb, net, *mm, iphlen, 0); 2780f8829a4aSRandall Stewart } 2781f8829a4aSRandall Stewart if (num_chunks) { 2782f8829a4aSRandall Stewart /* 2783ceaad40aSRandall Stewart * Did we get data, if so update the time for auto-close and 2784f8829a4aSRandall Stewart * give peer credit for being alive. 2785f8829a4aSRandall Stewart */ 2786f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvpktwithdata); 2787b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 2788c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 2789c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 2790c4739e2fSRandall Stewart 0, 2791c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 2792c4739e2fSRandall Stewart __LINE__); 2793c4739e2fSRandall Stewart } 2794f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 27956e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_last_rcvd); 2796f8829a4aSRandall Stewart } 2797f8829a4aSRandall Stewart /* now service all of the reassm queue if needed */ 2798f8829a4aSRandall Stewart if (!(TAILQ_EMPTY(&asoc->reasmqueue))) 2799f8829a4aSRandall Stewart sctp_service_queues(stcb, asoc); 2800f8829a4aSRandall Stewart 2801f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 280242551e99SRandall Stewart /* Assure that we ack right away */ 280342551e99SRandall Stewart stcb->asoc.send_sack = 1; 2804f8829a4aSRandall Stewart } 2805f8829a4aSRandall Stewart /* Start a sack timer or QUEUE a SACK for sending */ 2806b5c16493SMichael Tuexen sctp_sack_check(stcb, was_a_gap, &abort_flag); 2807f8829a4aSRandall Stewart if (abort_flag) 2808f8829a4aSRandall Stewart return (2); 2809f8829a4aSRandall Stewart 2810f8829a4aSRandall Stewart return (0); 2811f8829a4aSRandall Stewart } 2812f8829a4aSRandall Stewart 28130fa753b3SRandall Stewart static int 28140fa753b3SRandall Stewart sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1, uint32_t last_tsn, 28150fa753b3SRandall Stewart uint16_t frag_strt, uint16_t frag_end, int nr_sacking, 28160fa753b3SRandall Stewart int *num_frs, 28170fa753b3SRandall Stewart uint32_t * biggest_newly_acked_tsn, 28180fa753b3SRandall Stewart uint32_t * this_sack_lowest_newack, 28190fa753b3SRandall Stewart int *ecn_seg_sums) 28200fa753b3SRandall Stewart { 28210fa753b3SRandall Stewart struct sctp_tmit_chunk *tp1; 28220fa753b3SRandall Stewart unsigned int theTSN; 2823b5c16493SMichael Tuexen int j, wake_him = 0, circled = 0; 28240fa753b3SRandall Stewart 28250fa753b3SRandall Stewart /* Recover the tp1 we last saw */ 28260fa753b3SRandall Stewart tp1 = *p_tp1; 28270fa753b3SRandall Stewart if (tp1 == NULL) { 28280fa753b3SRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 28290fa753b3SRandall Stewart } 28300fa753b3SRandall Stewart for (j = frag_strt; j <= frag_end; j++) { 28310fa753b3SRandall Stewart theTSN = j + last_tsn; 28320fa753b3SRandall Stewart while (tp1) { 28330fa753b3SRandall Stewart if (tp1->rec.data.doing_fast_retransmit) 28340fa753b3SRandall Stewart (*num_frs) += 1; 28350fa753b3SRandall Stewart 28360fa753b3SRandall Stewart /*- 28370fa753b3SRandall Stewart * CMT: CUCv2 algorithm. For each TSN being 28380fa753b3SRandall Stewart * processed from the sent queue, track the 28390fa753b3SRandall Stewart * next expected pseudo-cumack, or 28400fa753b3SRandall Stewart * rtx_pseudo_cumack, if required. Separate 28410fa753b3SRandall Stewart * cumack trackers for first transmissions, 28420fa753b3SRandall Stewart * and retransmissions. 28430fa753b3SRandall Stewart */ 28440fa753b3SRandall Stewart if ((tp1->whoTo->find_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 28450fa753b3SRandall Stewart (tp1->snd_count == 1)) { 28460fa753b3SRandall Stewart tp1->whoTo->pseudo_cumack = tp1->rec.data.TSN_seq; 28470fa753b3SRandall Stewart tp1->whoTo->find_pseudo_cumack = 0; 28480fa753b3SRandall Stewart } 28490fa753b3SRandall Stewart if ((tp1->whoTo->find_rtx_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) && 28500fa753b3SRandall Stewart (tp1->snd_count > 1)) { 28510fa753b3SRandall Stewart tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.TSN_seq; 28520fa753b3SRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 0; 28530fa753b3SRandall Stewart } 28540fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == theTSN) { 28550fa753b3SRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 28560fa753b3SRandall Stewart /*- 28570fa753b3SRandall Stewart * must be held until 28580fa753b3SRandall Stewart * cum-ack passes 28590fa753b3SRandall Stewart */ 28600fa753b3SRandall Stewart /*- 28610fa753b3SRandall Stewart * ECN Nonce: Add the nonce 28620fa753b3SRandall Stewart * value to the sender's 28630fa753b3SRandall Stewart * nonce sum 28640fa753b3SRandall Stewart */ 28650fa753b3SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 28660fa753b3SRandall Stewart /*- 28670fa753b3SRandall Stewart * If it is less than RESEND, it is 28680fa753b3SRandall Stewart * now no-longer in flight. 28690fa753b3SRandall Stewart * Higher values may already be set 28700fa753b3SRandall Stewart * via previous Gap Ack Blocks... 28710fa753b3SRandall Stewart * i.e. ACKED or RESEND. 28720fa753b3SRandall Stewart */ 2873*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, 2874*20b07a4dSMichael Tuexen *biggest_newly_acked_tsn)) { 28750fa753b3SRandall Stewart *biggest_newly_acked_tsn = tp1->rec.data.TSN_seq; 28760fa753b3SRandall Stewart } 28770fa753b3SRandall Stewart /*- 28780fa753b3SRandall Stewart * CMT: SFR algo (and HTNA) - set 28790fa753b3SRandall Stewart * saw_newack to 1 for dest being 28800fa753b3SRandall Stewart * newly acked. update 28810fa753b3SRandall Stewart * this_sack_highest_newack if 28820fa753b3SRandall Stewart * appropriate. 28830fa753b3SRandall Stewart */ 28840fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) 28850fa753b3SRandall Stewart tp1->whoTo->saw_newack = 1; 28860fa753b3SRandall Stewart 2887*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, 2888*20b07a4dSMichael Tuexen tp1->whoTo->this_sack_highest_newack)) { 28890fa753b3SRandall Stewart tp1->whoTo->this_sack_highest_newack = 28900fa753b3SRandall Stewart tp1->rec.data.TSN_seq; 28910fa753b3SRandall Stewart } 28920fa753b3SRandall Stewart /*- 28930fa753b3SRandall Stewart * CMT DAC algo: also update 28940fa753b3SRandall Stewart * this_sack_lowest_newack 28950fa753b3SRandall Stewart */ 28960fa753b3SRandall Stewart if (*this_sack_lowest_newack == 0) { 28970fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 28980fa753b3SRandall Stewart sctp_log_sack(*this_sack_lowest_newack, 28990fa753b3SRandall Stewart last_tsn, 29000fa753b3SRandall Stewart tp1->rec.data.TSN_seq, 29010fa753b3SRandall Stewart 0, 29020fa753b3SRandall Stewart 0, 29030fa753b3SRandall Stewart SCTP_LOG_TSN_ACKED); 29040fa753b3SRandall Stewart } 29050fa753b3SRandall Stewart *this_sack_lowest_newack = tp1->rec.data.TSN_seq; 29060fa753b3SRandall Stewart } 29070fa753b3SRandall Stewart /*- 29080fa753b3SRandall Stewart * CMT: CUCv2 algorithm. If (rtx-)pseudo-cumack for corresp 29090fa753b3SRandall Stewart * dest is being acked, then we have a new (rtx-)pseudo-cumack. Set 29100fa753b3SRandall Stewart * new_(rtx_)pseudo_cumack to TRUE so that the cwnd for this dest can be 29110fa753b3SRandall Stewart * updated. Also trigger search for the next expected (rtx-)pseudo-cumack. 29120fa753b3SRandall Stewart * Separate pseudo_cumack trackers for first transmissions and 29130fa753b3SRandall Stewart * retransmissions. 29140fa753b3SRandall Stewart */ 29150fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->pseudo_cumack) { 29160fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 29170fa753b3SRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 29180fa753b3SRandall Stewart } 29190fa753b3SRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 29200fa753b3SRandall Stewart } 29210fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 29220fa753b3SRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 29230fa753b3SRandall Stewart } 29240fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->rtx_pseudo_cumack) { 29250fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 29260fa753b3SRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 29270fa753b3SRandall Stewart } 29280fa753b3SRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 29290fa753b3SRandall Stewart } 29300fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 29310fa753b3SRandall Stewart sctp_log_sack(*biggest_newly_acked_tsn, 29320fa753b3SRandall Stewart last_tsn, 29330fa753b3SRandall Stewart tp1->rec.data.TSN_seq, 29340fa753b3SRandall Stewart frag_strt, 29350fa753b3SRandall Stewart frag_end, 29360fa753b3SRandall Stewart SCTP_LOG_TSN_ACKED); 29370fa753b3SRandall Stewart } 29380fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 29390fa753b3SRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP, 29400fa753b3SRandall Stewart tp1->whoTo->flight_size, 29410fa753b3SRandall Stewart tp1->book_size, 29420fa753b3SRandall Stewart (uintptr_t) tp1->whoTo, 29430fa753b3SRandall Stewart tp1->rec.data.TSN_seq); 29440fa753b3SRandall Stewart } 29450fa753b3SRandall Stewart sctp_flight_size_decrease(tp1); 29460fa753b3SRandall Stewart sctp_total_flight_decrease(stcb, tp1); 29470fa753b3SRandall Stewart 29480fa753b3SRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 29490fa753b3SRandall Stewart if (tp1->snd_count < 2) { 29500fa753b3SRandall Stewart /*- 29510fa753b3SRandall Stewart * True non-retransmited chunk 29520fa753b3SRandall Stewart */ 29530fa753b3SRandall Stewart tp1->whoTo->net_ack2 += tp1->send_size; 29540fa753b3SRandall Stewart 29550fa753b3SRandall Stewart /*- 29560fa753b3SRandall Stewart * update RTO too ? 29570fa753b3SRandall Stewart */ 29580fa753b3SRandall Stewart if (tp1->do_rtt) { 29590fa753b3SRandall Stewart tp1->whoTo->RTO = 29600fa753b3SRandall Stewart sctp_calculate_rto(stcb, 29610fa753b3SRandall Stewart &stcb->asoc, 29620fa753b3SRandall Stewart tp1->whoTo, 29630fa753b3SRandall Stewart &tp1->sent_rcv_time, 29640fa753b3SRandall Stewart sctp_align_safe_nocopy); 29650fa753b3SRandall Stewart tp1->do_rtt = 0; 29660fa753b3SRandall Stewart } 29670fa753b3SRandall Stewart } 29680fa753b3SRandall Stewart } 29690fa753b3SRandall Stewart if (tp1->sent <= SCTP_DATAGRAM_RESEND) { 29700fa753b3SRandall Stewart (*ecn_seg_sums) += tp1->rec.data.ect_nonce; 29710fa753b3SRandall Stewart (*ecn_seg_sums) &= SCTP_SACK_NONCE_SUM; 2972*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, 2973*20b07a4dSMichael Tuexen stcb->asoc.this_sack_highest_gap)) { 29740fa753b3SRandall Stewart stcb->asoc.this_sack_highest_gap = 29750fa753b3SRandall Stewart tp1->rec.data.TSN_seq; 29760fa753b3SRandall Stewart } 29770fa753b3SRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 29780fa753b3SRandall Stewart sctp_ucount_decr(stcb->asoc.sent_queue_retran_cnt); 29790fa753b3SRandall Stewart #ifdef SCTP_AUDITING_ENABLED 29800fa753b3SRandall Stewart sctp_audit_log(0xB2, 29810fa753b3SRandall Stewart (stcb->asoc.sent_queue_retran_cnt & 0x000000ff)); 29820fa753b3SRandall Stewart #endif 29830fa753b3SRandall Stewart } 29840fa753b3SRandall Stewart } 29850fa753b3SRandall Stewart /*- 29860fa753b3SRandall Stewart * All chunks NOT UNSENT fall through here and are marked 29870fa753b3SRandall Stewart * (leave PR-SCTP ones that are to skip alone though) 29880fa753b3SRandall Stewart */ 29890fa753b3SRandall Stewart if (tp1->sent != SCTP_FORWARD_TSN_SKIP) 29900fa753b3SRandall Stewart tp1->sent = SCTP_DATAGRAM_MARKED; 29910fa753b3SRandall Stewart 29920fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 29930fa753b3SRandall Stewart /* deflate the cwnd */ 29940fa753b3SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 29950fa753b3SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 29960fa753b3SRandall Stewart } 29970fa753b3SRandall Stewart /* NR Sack code here */ 29980fa753b3SRandall Stewart if (nr_sacking) { 29990fa753b3SRandall Stewart if (tp1->data) { 30000fa753b3SRandall Stewart /* 30010fa753b3SRandall Stewart * sa_ignore 30020fa753b3SRandall Stewart * NO_NULL_CHK 30030fa753b3SRandall Stewart */ 30040fa753b3SRandall Stewart sctp_free_bufspace(stcb, &stcb->asoc, tp1, 1); 30050fa753b3SRandall Stewart sctp_m_freem(tp1->data); 30060fa753b3SRandall Stewart tp1->data = NULL; 3007b5c16493SMichael Tuexen } 30080fa753b3SRandall Stewart wake_him++; 30090fa753b3SRandall Stewart } 30100fa753b3SRandall Stewart } 30110fa753b3SRandall Stewart break; 30120fa753b3SRandall Stewart } /* if (tp1->TSN_seq == theTSN) */ 3013*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, theTSN)) { 30140fa753b3SRandall Stewart break; 3015*20b07a4dSMichael Tuexen } 30160fa753b3SRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3017b5c16493SMichael Tuexen if ((tp1 == NULL) && (circled == 0)) { 3018b5c16493SMichael Tuexen circled++; 30190fa753b3SRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 30200fa753b3SRandall Stewart } 3021b5c16493SMichael Tuexen } /* end while (tp1) */ 3022b5c16493SMichael Tuexen if (tp1 == NULL) { 3023b5c16493SMichael Tuexen circled = 0; 3024b5c16493SMichael Tuexen tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 3025b5c16493SMichael Tuexen } 3026b5c16493SMichael Tuexen /* In case the fragments were not in order we must reset */ 30270fa753b3SRandall Stewart } /* end for (j = fragStart */ 30280fa753b3SRandall Stewart *p_tp1 = tp1; 30290fa753b3SRandall Stewart return (wake_him); /* Return value only used for nr-sack */ 30300fa753b3SRandall Stewart } 30310fa753b3SRandall Stewart 30320fa753b3SRandall Stewart 3033cd554309SMichael Tuexen static int 3034458303daSRandall Stewart sctp_handle_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct sctp_association *asoc, 3035cd554309SMichael Tuexen uint32_t last_tsn, uint32_t * biggest_tsn_acked, 3036139bc87fSRandall Stewart uint32_t * biggest_newly_acked_tsn, uint32_t * this_sack_lowest_newack, 3037cd554309SMichael Tuexen int num_seg, int num_nr_seg, int *ecn_seg_sums) 3038f8829a4aSRandall Stewart { 3039458303daSRandall Stewart struct sctp_gap_ack_block *frag, block; 3040f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 30410fa753b3SRandall Stewart int i; 3042f8829a4aSRandall Stewart int num_frs = 0; 3043cd554309SMichael Tuexen int chunk_freed; 3044cd554309SMichael Tuexen int non_revocable; 3045d9c5cfeaSMichael Tuexen uint16_t frag_strt, frag_end, prev_frag_end; 3046f8829a4aSRandall Stewart 3047d9c5cfeaSMichael Tuexen tp1 = TAILQ_FIRST(&asoc->sent_queue); 3048d9c5cfeaSMichael Tuexen prev_frag_end = 0; 3049cd554309SMichael Tuexen chunk_freed = 0; 3050f8829a4aSRandall Stewart 3051cd554309SMichael Tuexen for (i = 0; i < (num_seg + num_nr_seg); i++) { 3052d9c5cfeaSMichael Tuexen if (i == num_seg) { 3053d9c5cfeaSMichael Tuexen prev_frag_end = 0; 3054d9c5cfeaSMichael Tuexen tp1 = TAILQ_FIRST(&asoc->sent_queue); 3055d9c5cfeaSMichael Tuexen } 3056458303daSRandall Stewart frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, 3057458303daSRandall Stewart sizeof(struct sctp_gap_ack_block), (uint8_t *) & block); 3058458303daSRandall Stewart *offset += sizeof(block); 3059458303daSRandall Stewart if (frag == NULL) { 3060cd554309SMichael Tuexen return (chunk_freed); 3061458303daSRandall Stewart } 3062f8829a4aSRandall Stewart frag_strt = ntohs(frag->start); 3063f8829a4aSRandall Stewart frag_end = ntohs(frag->end); 3064d9c5cfeaSMichael Tuexen 3065f8829a4aSRandall Stewart if (frag_strt > frag_end) { 3066d9c5cfeaSMichael Tuexen /* This gap report is malformed, skip it. */ 3067f8829a4aSRandall Stewart continue; 3068f8829a4aSRandall Stewart } 3069d9c5cfeaSMichael Tuexen if (frag_strt <= prev_frag_end) { 3070d9c5cfeaSMichael Tuexen /* This gap report is not in order, so restart. */ 3071f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3072f8829a4aSRandall Stewart } 3073*20b07a4dSMichael Tuexen if (SCTP_TSN_GT((last_tsn + frag_end), *biggest_tsn_acked)) { 3074d9c5cfeaSMichael Tuexen *biggest_tsn_acked = last_tsn + frag_end; 3075f8829a4aSRandall Stewart } 3076cd554309SMichael Tuexen if (i < num_seg) { 3077cd554309SMichael Tuexen non_revocable = 0; 3078cd554309SMichael Tuexen } else { 3079cd554309SMichael Tuexen non_revocable = 1; 3080cd554309SMichael Tuexen } 3081cd554309SMichael Tuexen if (sctp_process_segment_range(stcb, &tp1, last_tsn, frag_strt, frag_end, 3082cd554309SMichael Tuexen non_revocable, &num_frs, biggest_newly_acked_tsn, 3083cd554309SMichael Tuexen this_sack_lowest_newack, ecn_seg_sums)) { 3084cd554309SMichael Tuexen chunk_freed = 1; 3085458303daSRandall Stewart } 3086d9c5cfeaSMichael Tuexen prev_frag_end = frag_end; 3087f8829a4aSRandall Stewart } 3088b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 308980fefe0aSRandall Stewart if (num_frs) 309080fefe0aSRandall Stewart sctp_log_fr(*biggest_tsn_acked, 309180fefe0aSRandall Stewart *biggest_newly_acked_tsn, 309280fefe0aSRandall Stewart last_tsn, SCTP_FR_LOG_BIGGEST_TSNS); 309380fefe0aSRandall Stewart } 3094cd554309SMichael Tuexen return (chunk_freed); 3095f8829a4aSRandall Stewart } 3096f8829a4aSRandall Stewart 3097f8829a4aSRandall Stewart static void 3098c105859eSRandall Stewart sctp_check_for_revoked(struct sctp_tcb *stcb, 3099c105859eSRandall Stewart struct sctp_association *asoc, uint32_t cumack, 310063eda93dSMichael Tuexen uint32_t biggest_tsn_acked) 3101f8829a4aSRandall Stewart { 3102f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3103f8829a4aSRandall Stewart int tot_revoked = 0; 3104f8829a4aSRandall Stewart 31054a9ef3f8SMichael Tuexen TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 3106*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, cumack)) { 3107f8829a4aSRandall Stewart /* 3108f8829a4aSRandall Stewart * ok this guy is either ACK or MARKED. If it is 3109f8829a4aSRandall Stewart * ACKED it has been previously acked but not this 3110f8829a4aSRandall Stewart * time i.e. revoked. If it is MARKED it was ACK'ed 3111f8829a4aSRandall Stewart * again. 3112f8829a4aSRandall Stewart */ 3113*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, biggest_tsn_acked)) { 3114d06c82f1SRandall Stewart break; 3115*20b07a4dSMichael Tuexen } 3116f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_ACKED) { 3117f8829a4aSRandall Stewart /* it has been revoked */ 3118f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 3119f8829a4aSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 3120a5d547adSRandall Stewart /* 312142551e99SRandall Stewart * We must add this stuff back in to assure 312242551e99SRandall Stewart * timers and such get started. 3123a5d547adSRandall Stewart */ 3124b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3125c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 3126c105859eSRandall Stewart tp1->whoTo->flight_size, 3127c105859eSRandall Stewart tp1->book_size, 3128c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3129c105859eSRandall Stewart tp1->rec.data.TSN_seq); 313080fefe0aSRandall Stewart } 3131c105859eSRandall Stewart sctp_flight_size_increase(tp1); 3132c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 313342551e99SRandall Stewart /* 313442551e99SRandall Stewart * We inflate the cwnd to compensate for our 313542551e99SRandall Stewart * artificial inflation of the flight_size. 313642551e99SRandall Stewart */ 313742551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 3138f8829a4aSRandall Stewart tot_revoked++; 3139b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 3140f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 3141f8829a4aSRandall Stewart cumack, 3142f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3143f8829a4aSRandall Stewart 0, 3144f8829a4aSRandall Stewart 0, 3145f8829a4aSRandall Stewart SCTP_LOG_TSN_REVOKED); 314680fefe0aSRandall Stewart } 3147f8829a4aSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_MARKED) { 3148f8829a4aSRandall Stewart /* it has been re-acked in this SACK */ 3149f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 3150f8829a4aSRandall Stewart } 3151f8829a4aSRandall Stewart } 3152f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) 3153f8829a4aSRandall Stewart break; 3154f8829a4aSRandall Stewart } 3155f8829a4aSRandall Stewart if (tot_revoked > 0) { 3156f8829a4aSRandall Stewart /* 3157f8829a4aSRandall Stewart * Setup the ecn nonce re-sync point. We do this since once 3158f8829a4aSRandall Stewart * data is revoked we begin to retransmit things, which do 3159f8829a4aSRandall Stewart * NOT have the ECN bits set. This means we are now out of 3160f8829a4aSRandall Stewart * sync and must wait until we get back in sync with the 3161f8829a4aSRandall Stewart * peer to check ECN bits. 3162f8829a4aSRandall Stewart */ 3163f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->send_queue); 3164f8829a4aSRandall Stewart if (tp1 == NULL) { 3165f8829a4aSRandall Stewart asoc->nonce_resync_tsn = asoc->sending_seq; 3166f8829a4aSRandall Stewart } else { 3167f8829a4aSRandall Stewart asoc->nonce_resync_tsn = tp1->rec.data.TSN_seq; 3168f8829a4aSRandall Stewart } 3169f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 0; 3170f8829a4aSRandall Stewart asoc->nonce_sum_check = 0; 3171f8829a4aSRandall Stewart } 3172f8829a4aSRandall Stewart } 3173f8829a4aSRandall Stewart 3174830d754dSRandall Stewart 3175f8829a4aSRandall Stewart static void 3176f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, 317763eda93dSMichael Tuexen uint32_t biggest_tsn_acked, uint32_t biggest_tsn_newly_acked, uint32_t this_sack_lowest_newack, int accum_moved) 3178f8829a4aSRandall Stewart { 3179f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3180f8829a4aSRandall Stewart int strike_flag = 0; 3181f8829a4aSRandall Stewart struct timeval now; 3182f8829a4aSRandall Stewart int tot_retrans = 0; 3183f8829a4aSRandall Stewart uint32_t sending_seq; 3184f8829a4aSRandall Stewart struct sctp_nets *net; 3185f8829a4aSRandall Stewart int num_dests_sacked = 0; 3186f8829a4aSRandall Stewart 3187f8829a4aSRandall Stewart /* 3188f8829a4aSRandall Stewart * select the sending_seq, this is either the next thing ready to be 3189f8829a4aSRandall Stewart * sent but not transmitted, OR, the next seq we assign. 3190f8829a4aSRandall Stewart */ 3191f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.send_queue); 3192f8829a4aSRandall Stewart if (tp1 == NULL) { 3193f8829a4aSRandall Stewart sending_seq = asoc->sending_seq; 3194f8829a4aSRandall Stewart } else { 3195f8829a4aSRandall Stewart sending_seq = tp1->rec.data.TSN_seq; 3196f8829a4aSRandall Stewart } 3197f8829a4aSRandall Stewart 3198f8829a4aSRandall Stewart /* CMT DAC algo: finding out if SACK is a mixed SACK */ 31997c99d56fSMichael Tuexen if ((asoc->sctp_cmt_on_off > 0) && 320020083c2eSMichael Tuexen SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3201f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 3202f8829a4aSRandall Stewart if (net->saw_newack) 3203f8829a4aSRandall Stewart num_dests_sacked++; 3204f8829a4aSRandall Stewart } 3205f8829a4aSRandall Stewart } 3206f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_prsctp) { 32076e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 3208f8829a4aSRandall Stewart } 32094a9ef3f8SMichael Tuexen TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 3210f8829a4aSRandall Stewart strike_flag = 0; 3211f8829a4aSRandall Stewart if (tp1->no_fr_allowed) { 3212f8829a4aSRandall Stewart /* this one had a timeout or something */ 3213f8829a4aSRandall Stewart continue; 3214f8829a4aSRandall Stewart } 3215b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3216f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) 3217f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3218f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3219f8829a4aSRandall Stewart tp1->sent, 3220f8829a4aSRandall Stewart SCTP_FR_LOG_CHECK_STRIKE); 322180fefe0aSRandall Stewart } 3222*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, biggest_tsn_acked) || 3223f8829a4aSRandall Stewart tp1->sent == SCTP_DATAGRAM_UNSENT) { 3224f8829a4aSRandall Stewart /* done */ 3225f8829a4aSRandall Stewart break; 3226f8829a4aSRandall Stewart } 3227f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_prsctp) { 3228f8829a4aSRandall Stewart if ((PR_SCTP_TTL_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) { 3229f8829a4aSRandall Stewart /* Is it expired? */ 323099ddc825SMichael Tuexen if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) { 3231f8829a4aSRandall Stewart /* Yes so drop it */ 3232f8829a4aSRandall Stewart if (tp1->data != NULL) { 3233ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3234f8829a4aSRandall Stewart (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 32350c0982b8SRandall Stewart SCTP_SO_NOT_LOCKED); 3236f8829a4aSRandall Stewart } 3237f8829a4aSRandall Stewart continue; 3238f8829a4aSRandall Stewart } 3239f8829a4aSRandall Stewart } 3240f8829a4aSRandall Stewart } 3241*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, asoc->this_sack_highest_gap)) { 3242f8829a4aSRandall Stewart /* we are beyond the tsn in the sack */ 3243f8829a4aSRandall Stewart break; 3244f8829a4aSRandall Stewart } 3245f8829a4aSRandall Stewart if (tp1->sent >= SCTP_DATAGRAM_RESEND) { 3246f8829a4aSRandall Stewart /* either a RESEND, ACKED, or MARKED */ 3247f8829a4aSRandall Stewart /* skip */ 324844fbe462SRandall Stewart if (tp1->sent == SCTP_FORWARD_TSN_SKIP) { 324944fbe462SRandall Stewart /* Continue strikin FWD-TSN chunks */ 325044fbe462SRandall Stewart tp1->rec.data.fwd_tsn_cnt++; 325144fbe462SRandall Stewart } 3252f8829a4aSRandall Stewart continue; 3253f8829a4aSRandall Stewart } 3254f8829a4aSRandall Stewart /* 3255f8829a4aSRandall Stewart * CMT : SFR algo (covers part of DAC and HTNA as well) 3256f8829a4aSRandall Stewart */ 3257ad81507eSRandall Stewart if (tp1->whoTo && tp1->whoTo->saw_newack == 0) { 3258f8829a4aSRandall Stewart /* 3259f8829a4aSRandall Stewart * No new acks were receieved for data sent to this 3260f8829a4aSRandall Stewart * dest. Therefore, according to the SFR algo for 3261f8829a4aSRandall Stewart * CMT, no data sent to this dest can be marked for 3262c105859eSRandall Stewart * FR using this SACK. 3263f8829a4aSRandall Stewart */ 3264f8829a4aSRandall Stewart continue; 3265*20b07a4dSMichael Tuexen } else if (tp1->whoTo && SCTP_TSN_GT(tp1->rec.data.TSN_seq, 3266*20b07a4dSMichael Tuexen tp1->whoTo->this_sack_highest_newack)) { 3267f8829a4aSRandall Stewart /* 3268f8829a4aSRandall Stewart * CMT: New acks were receieved for data sent to 3269f8829a4aSRandall Stewart * this dest. But no new acks were seen for data 3270f8829a4aSRandall Stewart * sent after tp1. Therefore, according to the SFR 3271f8829a4aSRandall Stewart * algo for CMT, tp1 cannot be marked for FR using 3272f8829a4aSRandall Stewart * this SACK. This step covers part of the DAC algo 3273f8829a4aSRandall Stewart * and the HTNA algo as well. 3274f8829a4aSRandall Stewart */ 3275f8829a4aSRandall Stewart continue; 3276f8829a4aSRandall Stewart } 3277f8829a4aSRandall Stewart /* 3278f8829a4aSRandall Stewart * Here we check to see if we were have already done a FR 3279f8829a4aSRandall Stewart * and if so we see if the biggest TSN we saw in the sack is 3280f8829a4aSRandall Stewart * smaller than the recovery point. If so we don't strike 3281f8829a4aSRandall Stewart * the tsn... otherwise we CAN strike the TSN. 3282f8829a4aSRandall Stewart */ 3283f8829a4aSRandall Stewart /* 328442551e99SRandall Stewart * @@@ JRI: Check for CMT if (accum_moved && 328542551e99SRandall Stewart * asoc->fast_retran_loss_recovery && (sctp_cmt_on_off == 328642551e99SRandall Stewart * 0)) { 3287f8829a4aSRandall Stewart */ 328842551e99SRandall Stewart if (accum_moved && asoc->fast_retran_loss_recovery) { 3289f8829a4aSRandall Stewart /* 3290f8829a4aSRandall Stewart * Strike the TSN if in fast-recovery and cum-ack 3291f8829a4aSRandall Stewart * moved. 3292f8829a4aSRandall Stewart */ 3293b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3294f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3295f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3296f8829a4aSRandall Stewart tp1->sent, 3297f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 329880fefe0aSRandall Stewart } 32995e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3300f8829a4aSRandall Stewart tp1->sent++; 33015e54f665SRandall Stewart } 33027c99d56fSMichael Tuexen if ((asoc->sctp_cmt_on_off > 0) && 330320083c2eSMichael Tuexen SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3304f8829a4aSRandall Stewart /* 3305f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK flag is set to 3306f8829a4aSRandall Stewart * 0, then lowest_newack test will not pass 3307f8829a4aSRandall Stewart * because it would have been set to the 3308f8829a4aSRandall Stewart * cumack earlier. If not already to be 3309f8829a4aSRandall Stewart * rtx'd, If not a mixed sack and if tp1 is 3310f8829a4aSRandall Stewart * not between two sacked TSNs, then mark by 3311c105859eSRandall Stewart * one more. NOTE that we are marking by one 3312c105859eSRandall Stewart * additional time since the SACK DAC flag 3313c105859eSRandall Stewart * indicates that two packets have been 3314c105859eSRandall Stewart * received after this missing TSN. 33155e54f665SRandall Stewart */ 33165e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && 3317*20b07a4dSMichael Tuexen SCTP_TSN_GT(this_sack_lowest_newack, tp1->rec.data.TSN_seq)) { 3318b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3319f8829a4aSRandall Stewart sctp_log_fr(16 + num_dests_sacked, 3320f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3321f8829a4aSRandall Stewart tp1->sent, 3322f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 332380fefe0aSRandall Stewart } 3324f8829a4aSRandall Stewart tp1->sent++; 3325f8829a4aSRandall Stewart } 3326f8829a4aSRandall Stewart } 332720083c2eSMichael Tuexen } else if ((tp1->rec.data.doing_fast_retransmit) && 332820083c2eSMichael Tuexen (asoc->sctp_cmt_on_off == 0)) { 3329f8829a4aSRandall Stewart /* 3330f8829a4aSRandall Stewart * For those that have done a FR we must take 3331f8829a4aSRandall Stewart * special consideration if we strike. I.e the 3332f8829a4aSRandall Stewart * biggest_newly_acked must be higher than the 3333f8829a4aSRandall Stewart * sending_seq at the time we did the FR. 3334f8829a4aSRandall Stewart */ 33355e54f665SRandall Stewart if ( 3336f8829a4aSRandall Stewart #ifdef SCTP_FR_TO_ALTERNATE 3337f8829a4aSRandall Stewart /* 3338f8829a4aSRandall Stewart * If FR's go to new networks, then we must only do 3339f8829a4aSRandall Stewart * this for singly homed asoc's. However if the FR's 3340f8829a4aSRandall Stewart * go to the same network (Armando's work) then its 3341f8829a4aSRandall Stewart * ok to FR multiple times. 3342f8829a4aSRandall Stewart */ 33435e54f665SRandall Stewart (asoc->numnets < 2) 3344f8829a4aSRandall Stewart #else 33455e54f665SRandall Stewart (1) 3346f8829a4aSRandall Stewart #endif 33475e54f665SRandall Stewart ) { 33485e54f665SRandall Stewart 3349*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(biggest_tsn_newly_acked, 3350f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn)) { 3351f8829a4aSRandall Stewart /* 3352f8829a4aSRandall Stewart * Strike the TSN, since this ack is 3353f8829a4aSRandall Stewart * beyond where things were when we 3354f8829a4aSRandall Stewart * did a FR. 3355f8829a4aSRandall Stewart */ 3356b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3357f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3358f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3359f8829a4aSRandall Stewart tp1->sent, 3360f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 336180fefe0aSRandall Stewart } 33625e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3363f8829a4aSRandall Stewart tp1->sent++; 33645e54f665SRandall Stewart } 3365f8829a4aSRandall Stewart strike_flag = 1; 33667c99d56fSMichael Tuexen if ((asoc->sctp_cmt_on_off > 0) && 336720083c2eSMichael Tuexen SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3368f8829a4aSRandall Stewart /* 3369f8829a4aSRandall Stewart * CMT DAC algorithm: If 3370f8829a4aSRandall Stewart * SACK flag is set to 0, 3371f8829a4aSRandall Stewart * then lowest_newack test 3372f8829a4aSRandall Stewart * will not pass because it 3373f8829a4aSRandall Stewart * would have been set to 3374f8829a4aSRandall Stewart * the cumack earlier. If 3375f8829a4aSRandall Stewart * not already to be rtx'd, 3376f8829a4aSRandall Stewart * If not a mixed sack and 3377f8829a4aSRandall Stewart * if tp1 is not between two 3378f8829a4aSRandall Stewart * sacked TSNs, then mark by 3379c105859eSRandall Stewart * one more. NOTE that we 3380c105859eSRandall Stewart * are marking by one 3381c105859eSRandall Stewart * additional time since the 3382c105859eSRandall Stewart * SACK DAC flag indicates 3383c105859eSRandall Stewart * that two packets have 3384c105859eSRandall Stewart * been received after this 3385c105859eSRandall Stewart * missing TSN. 3386f8829a4aSRandall Stewart */ 33875e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && 33885e54f665SRandall Stewart (num_dests_sacked == 1) && 3389*20b07a4dSMichael Tuexen SCTP_TSN_GT(this_sack_lowest_newack, 3390*20b07a4dSMichael Tuexen tp1->rec.data.TSN_seq)) { 3391b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3392f8829a4aSRandall Stewart sctp_log_fr(32 + num_dests_sacked, 3393f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3394f8829a4aSRandall Stewart tp1->sent, 3395f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 339680fefe0aSRandall Stewart } 33975e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3398f8829a4aSRandall Stewart tp1->sent++; 33995e54f665SRandall Stewart } 3400f8829a4aSRandall Stewart } 3401f8829a4aSRandall Stewart } 3402f8829a4aSRandall Stewart } 3403f8829a4aSRandall Stewart } 3404f8829a4aSRandall Stewart /* 340542551e99SRandall Stewart * JRI: TODO: remove code for HTNA algo. CMT's SFR 340642551e99SRandall Stewart * algo covers HTNA. 3407f8829a4aSRandall Stewart */ 3408*20b07a4dSMichael Tuexen } else if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, 3409*20b07a4dSMichael Tuexen biggest_tsn_newly_acked)) { 3410f8829a4aSRandall Stewart /* 3411f8829a4aSRandall Stewart * We don't strike these: This is the HTNA 3412f8829a4aSRandall Stewart * algorithm i.e. we don't strike If our TSN is 3413f8829a4aSRandall Stewart * larger than the Highest TSN Newly Acked. 3414f8829a4aSRandall Stewart */ 3415f8829a4aSRandall Stewart ; 3416f8829a4aSRandall Stewart } else { 3417f8829a4aSRandall Stewart /* Strike the TSN */ 3418b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3419f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3420f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3421f8829a4aSRandall Stewart tp1->sent, 3422f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 342380fefe0aSRandall Stewart } 34245e54f665SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3425f8829a4aSRandall Stewart tp1->sent++; 34265e54f665SRandall Stewart } 34277c99d56fSMichael Tuexen if ((asoc->sctp_cmt_on_off > 0) && 342820083c2eSMichael Tuexen SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3429f8829a4aSRandall Stewart /* 3430f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK flag is set to 3431f8829a4aSRandall Stewart * 0, then lowest_newack test will not pass 3432f8829a4aSRandall Stewart * because it would have been set to the 3433f8829a4aSRandall Stewart * cumack earlier. If not already to be 3434f8829a4aSRandall Stewart * rtx'd, If not a mixed sack and if tp1 is 3435f8829a4aSRandall Stewart * not between two sacked TSNs, then mark by 3436c105859eSRandall Stewart * one more. NOTE that we are marking by one 3437c105859eSRandall Stewart * additional time since the SACK DAC flag 3438c105859eSRandall Stewart * indicates that two packets have been 3439c105859eSRandall Stewart * received after this missing TSN. 3440f8829a4aSRandall Stewart */ 34415e54f665SRandall Stewart if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && 3442*20b07a4dSMichael Tuexen SCTP_TSN_GT(this_sack_lowest_newack, tp1->rec.data.TSN_seq)) { 3443b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3444f8829a4aSRandall Stewart sctp_log_fr(48 + num_dests_sacked, 3445f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3446f8829a4aSRandall Stewart tp1->sent, 3447f8829a4aSRandall Stewart SCTP_FR_LOG_STRIKE_CHUNK); 344880fefe0aSRandall Stewart } 3449f8829a4aSRandall Stewart tp1->sent++; 3450f8829a4aSRandall Stewart } 3451f8829a4aSRandall Stewart } 3452f8829a4aSRandall Stewart } 3453f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 3454f8829a4aSRandall Stewart struct sctp_nets *alt; 3455f8829a4aSRandall Stewart 3456544e35bdSRandall Stewart /* fix counts and things */ 3457544e35bdSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3458544e35bdSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND, 3459544e35bdSRandall Stewart (tp1->whoTo ? (tp1->whoTo->flight_size) : 0), 3460544e35bdSRandall Stewart tp1->book_size, 3461544e35bdSRandall Stewart (uintptr_t) tp1->whoTo, 3462544e35bdSRandall Stewart tp1->rec.data.TSN_seq); 3463544e35bdSRandall Stewart } 3464544e35bdSRandall Stewart if (tp1->whoTo) { 3465544e35bdSRandall Stewart tp1->whoTo->net_ack++; 3466544e35bdSRandall Stewart sctp_flight_size_decrease(tp1); 3467544e35bdSRandall Stewart } 3468544e35bdSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 3469544e35bdSRandall Stewart sctp_log_rwnd(SCTP_INCREASE_PEER_RWND, 3470544e35bdSRandall Stewart asoc->peers_rwnd, tp1->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 3471544e35bdSRandall Stewart } 3472544e35bdSRandall Stewart /* add back to the rwnd */ 3473544e35bdSRandall Stewart asoc->peers_rwnd += (tp1->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 3474544e35bdSRandall Stewart 3475544e35bdSRandall Stewart /* remove from the total flight */ 3476544e35bdSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 3477544e35bdSRandall Stewart 3478475d0674SMichael Tuexen if ((stcb->asoc.peer_supports_prsctp) && 3479475d0674SMichael Tuexen (PR_SCTP_RTX_ENABLED(tp1->flags))) { 3480475d0674SMichael Tuexen /* 3481475d0674SMichael Tuexen * Has it been retransmitted tv_sec times? - 3482475d0674SMichael Tuexen * we store the retran count there. 3483475d0674SMichael Tuexen */ 3484475d0674SMichael Tuexen if (tp1->snd_count > tp1->rec.data.timetodrop.tv_sec) { 3485475d0674SMichael Tuexen /* Yes, so drop it */ 3486475d0674SMichael Tuexen if (tp1->data != NULL) { 3487475d0674SMichael Tuexen (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3488475d0674SMichael Tuexen (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 3489475d0674SMichael Tuexen SCTP_SO_NOT_LOCKED); 3490475d0674SMichael Tuexen } 3491475d0674SMichael Tuexen /* Make sure to flag we had a FR */ 3492475d0674SMichael Tuexen tp1->whoTo->net_ack++; 3493475d0674SMichael Tuexen continue; 3494475d0674SMichael Tuexen } 3495475d0674SMichael Tuexen } 3496f8829a4aSRandall Stewart /* printf("OK, we are now ready to FR this guy\n"); */ 3497b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3498f8829a4aSRandall Stewart sctp_log_fr(tp1->rec.data.TSN_seq, tp1->snd_count, 3499f8829a4aSRandall Stewart 0, SCTP_FR_MARKED); 350080fefe0aSRandall Stewart } 3501f8829a4aSRandall Stewart if (strike_flag) { 3502f8829a4aSRandall Stewart /* This is a subsequent FR */ 3503f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_sendmultfastretrans); 3504f8829a4aSRandall Stewart } 35055e54f665SRandall Stewart sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); 35067c99d56fSMichael Tuexen if (asoc->sctp_cmt_on_off > 0) { 3507f8829a4aSRandall Stewart /* 3508f8829a4aSRandall Stewart * CMT: Using RTX_SSTHRESH policy for CMT. 3509f8829a4aSRandall Stewart * If CMT is being used, then pick dest with 3510f8829a4aSRandall Stewart * largest ssthresh for any retransmission. 3511f8829a4aSRandall Stewart */ 3512f8829a4aSRandall Stewart tp1->no_fr_allowed = 1; 3513f8829a4aSRandall Stewart alt = tp1->whoTo; 35143c503c28SRandall Stewart /* sa_ignore NO_NULL_CHK */ 351520083c2eSMichael Tuexen if (asoc->sctp_cmt_pf > 0) { 3516b54d3a6cSRandall Stewart /* 3517b54d3a6cSRandall Stewart * JRS 5/18/07 - If CMT PF is on, 3518b54d3a6cSRandall Stewart * use the PF version of 3519b54d3a6cSRandall Stewart * find_alt_net() 3520b54d3a6cSRandall Stewart */ 3521b54d3a6cSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 2); 3522b54d3a6cSRandall Stewart } else { 3523b54d3a6cSRandall Stewart /* 3524b54d3a6cSRandall Stewart * JRS 5/18/07 - If only CMT is on, 3525b54d3a6cSRandall Stewart * use the CMT version of 3526b54d3a6cSRandall Stewart * find_alt_net() 3527b54d3a6cSRandall Stewart */ 352852be287eSRandall Stewart /* sa_ignore NO_NULL_CHK */ 3529f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 1); 3530b54d3a6cSRandall Stewart } 3531ad81507eSRandall Stewart if (alt == NULL) { 3532ad81507eSRandall Stewart alt = tp1->whoTo; 3533ad81507eSRandall Stewart } 3534f8829a4aSRandall Stewart /* 3535f8829a4aSRandall Stewart * CUCv2: If a different dest is picked for 3536f8829a4aSRandall Stewart * the retransmission, then new 3537f8829a4aSRandall Stewart * (rtx-)pseudo_cumack needs to be tracked 3538f8829a4aSRandall Stewart * for orig dest. Let CUCv2 track new (rtx-) 3539f8829a4aSRandall Stewart * pseudo-cumack always. 3540f8829a4aSRandall Stewart */ 3541ad81507eSRandall Stewart if (tp1->whoTo) { 3542f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 3543f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 3544ad81507eSRandall Stewart } 3545f8829a4aSRandall Stewart } else {/* CMT is OFF */ 3546f8829a4aSRandall Stewart 3547f8829a4aSRandall Stewart #ifdef SCTP_FR_TO_ALTERNATE 3548f8829a4aSRandall Stewart /* Can we find an alternate? */ 3549f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, tp1->whoTo, 0); 3550f8829a4aSRandall Stewart #else 3551f8829a4aSRandall Stewart /* 3552f8829a4aSRandall Stewart * default behavior is to NOT retransmit 3553f8829a4aSRandall Stewart * FR's to an alternate. Armando Caro's 3554f8829a4aSRandall Stewart * paper details why. 3555f8829a4aSRandall Stewart */ 3556f8829a4aSRandall Stewart alt = tp1->whoTo; 3557f8829a4aSRandall Stewart #endif 3558f8829a4aSRandall Stewart } 3559f8829a4aSRandall Stewart 3560f8829a4aSRandall Stewart tp1->rec.data.doing_fast_retransmit = 1; 3561f8829a4aSRandall Stewart tot_retrans++; 3562f8829a4aSRandall Stewart /* mark the sending seq for possible subsequent FR's */ 3563f8829a4aSRandall Stewart /* 3564f8829a4aSRandall Stewart * printf("Marking TSN for FR new value %x\n", 3565f8829a4aSRandall Stewart * (uint32_t)tpi->rec.data.TSN_seq); 3566f8829a4aSRandall Stewart */ 3567f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue)) { 3568f8829a4aSRandall Stewart /* 3569f8829a4aSRandall Stewart * If the queue of send is empty then its 3570f8829a4aSRandall Stewart * the next sequence number that will be 3571f8829a4aSRandall Stewart * assigned so we subtract one from this to 3572f8829a4aSRandall Stewart * get the one we last sent. 3573f8829a4aSRandall Stewart */ 3574f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = sending_seq; 3575f8829a4aSRandall Stewart } else { 3576f8829a4aSRandall Stewart /* 3577f8829a4aSRandall Stewart * If there are chunks on the send queue 3578f8829a4aSRandall Stewart * (unsent data that has made it from the 3579f8829a4aSRandall Stewart * stream queues but not out the door, we 3580f8829a4aSRandall Stewart * take the first one (which will have the 3581f8829a4aSRandall Stewart * lowest TSN) and subtract one to get the 3582f8829a4aSRandall Stewart * one we last sent. 3583f8829a4aSRandall Stewart */ 3584f8829a4aSRandall Stewart struct sctp_tmit_chunk *ttt; 3585f8829a4aSRandall Stewart 3586f8829a4aSRandall Stewart ttt = TAILQ_FIRST(&asoc->send_queue); 3587f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = 3588f8829a4aSRandall Stewart ttt->rec.data.TSN_seq; 3589f8829a4aSRandall Stewart } 3590f8829a4aSRandall Stewart 3591f8829a4aSRandall Stewart if (tp1->do_rtt) { 3592f8829a4aSRandall Stewart /* 3593f8829a4aSRandall Stewart * this guy had a RTO calculation pending on 3594f8829a4aSRandall Stewart * it, cancel it 3595f8829a4aSRandall Stewart */ 3596f8829a4aSRandall Stewart tp1->do_rtt = 0; 3597f8829a4aSRandall Stewart } 3598f8829a4aSRandall Stewart if (alt != tp1->whoTo) { 3599f8829a4aSRandall Stewart /* yes, there is an alternate. */ 3600f8829a4aSRandall Stewart sctp_free_remote_addr(tp1->whoTo); 36013c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 3602f8829a4aSRandall Stewart tp1->whoTo = alt; 3603f8829a4aSRandall Stewart atomic_add_int(&alt->ref_count, 1); 3604f8829a4aSRandall Stewart } 3605f8829a4aSRandall Stewart } 36064a9ef3f8SMichael Tuexen } 3607f8829a4aSRandall Stewart 3608f8829a4aSRandall Stewart if (tot_retrans > 0) { 3609f8829a4aSRandall Stewart /* 3610f8829a4aSRandall Stewart * Setup the ecn nonce re-sync point. We do this since once 3611f8829a4aSRandall Stewart * we go to FR something we introduce a Karn's rule scenario 3612f8829a4aSRandall Stewart * and won't know the totals for the ECN bits. 3613f8829a4aSRandall Stewart */ 3614f8829a4aSRandall Stewart asoc->nonce_resync_tsn = sending_seq; 3615f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 0; 3616f8829a4aSRandall Stewart asoc->nonce_sum_check = 0; 3617f8829a4aSRandall Stewart } 3618f8829a4aSRandall Stewart } 3619f8829a4aSRandall Stewart 3620f8829a4aSRandall Stewart struct sctp_tmit_chunk * 3621f8829a4aSRandall Stewart sctp_try_advance_peer_ack_point(struct sctp_tcb *stcb, 3622f8829a4aSRandall Stewart struct sctp_association *asoc) 3623f8829a4aSRandall Stewart { 3624f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2, *a_adv = NULL; 3625f8829a4aSRandall Stewart struct timeval now; 3626f8829a4aSRandall Stewart int now_filled = 0; 3627f8829a4aSRandall Stewart 3628f8829a4aSRandall Stewart if (asoc->peer_supports_prsctp == 0) { 3629f8829a4aSRandall Stewart return (NULL); 3630f8829a4aSRandall Stewart } 36314a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) { 3632f8829a4aSRandall Stewart if (tp1->sent != SCTP_FORWARD_TSN_SKIP && 3633f8829a4aSRandall Stewart tp1->sent != SCTP_DATAGRAM_RESEND) { 3634f8829a4aSRandall Stewart /* no chance to advance, out of here */ 3635f8829a4aSRandall Stewart break; 3636f8829a4aSRandall Stewart } 36370c0982b8SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { 36380c0982b8SRandall Stewart if (tp1->sent == SCTP_FORWARD_TSN_SKIP) { 36390c0982b8SRandall Stewart sctp_misc_ints(SCTP_FWD_TSN_CHECK, 36400c0982b8SRandall Stewart asoc->advanced_peer_ack_point, 36410c0982b8SRandall Stewart tp1->rec.data.TSN_seq, 0, 0); 36420c0982b8SRandall Stewart } 36430c0982b8SRandall Stewart } 3644f8829a4aSRandall Stewart if (!PR_SCTP_ENABLED(tp1->flags)) { 3645f8829a4aSRandall Stewart /* 3646f8829a4aSRandall Stewart * We can't fwd-tsn past any that are reliable aka 3647f8829a4aSRandall Stewart * retransmitted until the asoc fails. 3648f8829a4aSRandall Stewart */ 3649f8829a4aSRandall Stewart break; 3650f8829a4aSRandall Stewart } 3651f8829a4aSRandall Stewart if (!now_filled) { 36526e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 3653f8829a4aSRandall Stewart now_filled = 1; 3654f8829a4aSRandall Stewart } 3655f8829a4aSRandall Stewart /* 3656f8829a4aSRandall Stewart * now we got a chunk which is marked for another 3657f8829a4aSRandall Stewart * retransmission to a PR-stream but has run out its chances 3658f8829a4aSRandall Stewart * already maybe OR has been marked to skip now. Can we skip 3659f8829a4aSRandall Stewart * it if its a resend? 3660f8829a4aSRandall Stewart */ 3661f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND && 3662f8829a4aSRandall Stewart (PR_SCTP_TTL_ENABLED(tp1->flags))) { 3663f8829a4aSRandall Stewart /* 3664f8829a4aSRandall Stewart * Now is this one marked for resend and its time is 3665f8829a4aSRandall Stewart * now up? 3666f8829a4aSRandall Stewart */ 3667f8829a4aSRandall Stewart if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) { 3668f8829a4aSRandall Stewart /* Yes so drop it */ 3669f8829a4aSRandall Stewart if (tp1->data) { 3670ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 3671f8829a4aSRandall Stewart (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT), 36720c0982b8SRandall Stewart SCTP_SO_NOT_LOCKED); 3673f8829a4aSRandall Stewart } 3674f8829a4aSRandall Stewart } else { 3675f8829a4aSRandall Stewart /* 3676f8829a4aSRandall Stewart * No, we are done when hit one for resend 3677f8829a4aSRandall Stewart * whos time as not expired. 3678f8829a4aSRandall Stewart */ 3679f8829a4aSRandall Stewart break; 3680f8829a4aSRandall Stewart } 3681f8829a4aSRandall Stewart } 3682f8829a4aSRandall Stewart /* 3683f8829a4aSRandall Stewart * Ok now if this chunk is marked to drop it we can clean up 3684f8829a4aSRandall Stewart * the chunk, advance our peer ack point and we can check 3685f8829a4aSRandall Stewart * the next chunk. 3686f8829a4aSRandall Stewart */ 368744fbe462SRandall Stewart if (tp1->sent == SCTP_FORWARD_TSN_SKIP) { 3688f8829a4aSRandall Stewart /* advance PeerAckPoint goes forward */ 3689*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, asoc->advanced_peer_ack_point)) { 3690f8829a4aSRandall Stewart asoc->advanced_peer_ack_point = tp1->rec.data.TSN_seq; 3691f8829a4aSRandall Stewart a_adv = tp1; 36920c0982b8SRandall Stewart } else if (tp1->rec.data.TSN_seq == asoc->advanced_peer_ack_point) { 36930c0982b8SRandall Stewart /* No update but we do save the chk */ 36940c0982b8SRandall Stewart a_adv = tp1; 36950c0982b8SRandall Stewart } 3696f8829a4aSRandall Stewart } else { 3697f8829a4aSRandall Stewart /* 3698f8829a4aSRandall Stewart * If it is still in RESEND we can advance no 3699f8829a4aSRandall Stewart * further 3700f8829a4aSRandall Stewart */ 3701f8829a4aSRandall Stewart break; 3702f8829a4aSRandall Stewart } 3703f8829a4aSRandall Stewart } 3704f8829a4aSRandall Stewart return (a_adv); 3705f8829a4aSRandall Stewart } 3706f8829a4aSRandall Stewart 37070c0982b8SRandall Stewart static int 3708c105859eSRandall Stewart sctp_fs_audit(struct sctp_association *asoc) 3709bff64a4dSRandall Stewart { 3710bff64a4dSRandall Stewart struct sctp_tmit_chunk *chk; 3711bff64a4dSRandall Stewart int inflight = 0, resend = 0, inbetween = 0, acked = 0, above = 0; 37120c0982b8SRandall Stewart int entry_flight, entry_cnt, ret; 37130c0982b8SRandall Stewart 37140c0982b8SRandall Stewart entry_flight = asoc->total_flight; 37150c0982b8SRandall Stewart entry_cnt = asoc->total_flight_count; 37160c0982b8SRandall Stewart ret = 0; 37170c0982b8SRandall Stewart 37180c0982b8SRandall Stewart if (asoc->pr_sctp_cnt >= asoc->sent_queue_cnt) 37190c0982b8SRandall Stewart return (0); 3720bff64a4dSRandall Stewart 3721bff64a4dSRandall Stewart TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { 3722bff64a4dSRandall Stewart if (chk->sent < SCTP_DATAGRAM_RESEND) { 37230c0982b8SRandall Stewart printf("Chk TSN:%u size:%d inflight cnt:%d\n", 37240c0982b8SRandall Stewart chk->rec.data.TSN_seq, 37250c0982b8SRandall Stewart chk->send_size, 37260c0982b8SRandall Stewart chk->snd_count 37270c0982b8SRandall Stewart ); 3728bff64a4dSRandall Stewart inflight++; 3729bff64a4dSRandall Stewart } else if (chk->sent == SCTP_DATAGRAM_RESEND) { 3730bff64a4dSRandall Stewart resend++; 3731bff64a4dSRandall Stewart } else if (chk->sent < SCTP_DATAGRAM_ACKED) { 3732bff64a4dSRandall Stewart inbetween++; 3733bff64a4dSRandall Stewart } else if (chk->sent > SCTP_DATAGRAM_ACKED) { 3734bff64a4dSRandall Stewart above++; 3735bff64a4dSRandall Stewart } else { 3736bff64a4dSRandall Stewart acked++; 3737bff64a4dSRandall Stewart } 3738bff64a4dSRandall Stewart } 3739f1f73e57SRandall Stewart 3740c105859eSRandall Stewart if ((inflight > 0) || (inbetween > 0)) { 3741f1f73e57SRandall Stewart #ifdef INVARIANTS 3742c105859eSRandall Stewart panic("Flight size-express incorrect? \n"); 3743f1f73e57SRandall Stewart #else 37440c0982b8SRandall Stewart printf("asoc->total_flight:%d cnt:%d\n", 37450c0982b8SRandall Stewart entry_flight, entry_cnt); 37460c0982b8SRandall Stewart 37470c0982b8SRandall Stewart SCTP_PRINTF("Flight size-express incorrect F:%d I:%d R:%d Ab:%d ACK:%d\n", 37480c0982b8SRandall Stewart inflight, inbetween, resend, above, acked); 37490c0982b8SRandall Stewart ret = 1; 3750f1f73e57SRandall Stewart #endif 3751bff64a4dSRandall Stewart } 37520c0982b8SRandall Stewart return (ret); 3753c105859eSRandall Stewart } 3754c105859eSRandall Stewart 3755c105859eSRandall Stewart 3756c105859eSRandall Stewart static void 3757c105859eSRandall Stewart sctp_window_probe_recovery(struct sctp_tcb *stcb, 3758c105859eSRandall Stewart struct sctp_association *asoc, 3759c105859eSRandall Stewart struct sctp_nets *net, 3760c105859eSRandall Stewart struct sctp_tmit_chunk *tp1) 3761c105859eSRandall Stewart { 3762dfb11ef8SRandall Stewart tp1->window_probe = 0; 37635171328bSRandall Stewart if ((tp1->sent >= SCTP_DATAGRAM_ACKED) || (tp1->data == NULL)) { 3764dfb11ef8SRandall Stewart /* TSN's skipped we do NOT move back. */ 3765dfb11ef8SRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DWN_WP_FWD, 3766dfb11ef8SRandall Stewart tp1->whoTo->flight_size, 3767dfb11ef8SRandall Stewart tp1->book_size, 3768dfb11ef8SRandall Stewart (uintptr_t) tp1->whoTo, 3769dfb11ef8SRandall Stewart tp1->rec.data.TSN_seq); 3770dfb11ef8SRandall Stewart return; 3771dfb11ef8SRandall Stewart } 37725171328bSRandall Stewart /* First setup this by shrinking flight */ 37735171328bSRandall Stewart sctp_flight_size_decrease(tp1); 37745171328bSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 37755171328bSRandall Stewart /* Now mark for resend */ 37765171328bSRandall Stewart tp1->sent = SCTP_DATAGRAM_RESEND; 3777791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 3778791437b5SRandall Stewart 3779b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3780c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_WP, 3781c105859eSRandall Stewart tp1->whoTo->flight_size, 3782c105859eSRandall Stewart tp1->book_size, 3783c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3784c105859eSRandall Stewart tp1->rec.data.TSN_seq); 378580fefe0aSRandall Stewart } 3786c105859eSRandall Stewart } 3787c105859eSRandall Stewart 3788f8829a4aSRandall Stewart void 3789f8829a4aSRandall Stewart sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, 3790f8829a4aSRandall Stewart uint32_t rwnd, int nonce_sum_flag, int *abort_now) 3791f8829a4aSRandall Stewart { 3792f8829a4aSRandall Stewart struct sctp_nets *net; 3793f8829a4aSRandall Stewart struct sctp_association *asoc; 3794f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 37955e54f665SRandall Stewart uint32_t old_rwnd; 37965e54f665SRandall Stewart int win_probe_recovery = 0; 3797c105859eSRandall Stewart int win_probe_recovered = 0; 3798d06c82f1SRandall Stewart int j, done_once = 0; 3799f8829a4aSRandall Stewart 3800b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 3801d06c82f1SRandall Stewart sctp_misc_ints(SCTP_SACK_LOG_EXPRESS, cumack, 3802d06c82f1SRandall Stewart rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 380380fefe0aSRandall Stewart } 3804f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 380518e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 380618e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cumack; 380718e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 380818e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 380918e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 381018e198d3SRandall Stewart } 381118e198d3SRandall Stewart #endif 3812f8829a4aSRandall Stewart asoc = &stcb->asoc; 3813d06c82f1SRandall Stewart old_rwnd = asoc->peers_rwnd; 3814*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->last_acked_seq, cumack)) { 38155e54f665SRandall Stewart /* old ack */ 38165e54f665SRandall Stewart return; 3817d06c82f1SRandall Stewart } else if (asoc->last_acked_seq == cumack) { 3818d06c82f1SRandall Stewart /* Window update sack */ 3819d06c82f1SRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 382044fbe462SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 3821d06c82f1SRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 3822d06c82f1SRandall Stewart /* SWS sender side engages */ 3823d06c82f1SRandall Stewart asoc->peers_rwnd = 0; 3824d06c82f1SRandall Stewart } 3825d06c82f1SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 3826d06c82f1SRandall Stewart goto again; 3827d06c82f1SRandall Stewart } 3828d06c82f1SRandall Stewart return; 38295e54f665SRandall Stewart } 3830f8829a4aSRandall Stewart /* First setup for CC stuff */ 3831f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 3832f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 3833f8829a4aSRandall Stewart net->net_ack = 0; 3834f8829a4aSRandall Stewart net->net_ack2 = 0; 3835132dea7dSRandall Stewart 3836132dea7dSRandall Stewart /* 3837132dea7dSRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 3838132dea7dSRandall Stewart * SACK processing 3839132dea7dSRandall Stewart */ 3840132dea7dSRandall Stewart net->new_pseudo_cumack = 0; 3841132dea7dSRandall Stewart net->will_exit_fast_recovery = 0; 3842f8829a4aSRandall Stewart } 3843b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 3844139bc87fSRandall Stewart uint32_t send_s; 3845139bc87fSRandall Stewart 3846c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 3847c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 3848c105859eSRandall Stewart sctpchunk_listhead); 3849c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 3850139bc87fSRandall Stewart } else { 3851c105859eSRandall Stewart send_s = asoc->sending_seq; 3852139bc87fSRandall Stewart } 3853*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(cumack, send_s)) { 3854c105859eSRandall Stewart #ifndef INVARIANTS 3855139bc87fSRandall Stewart struct mbuf *oper; 3856139bc87fSRandall Stewart 3857c105859eSRandall Stewart #endif 3858c105859eSRandall Stewart #ifdef INVARIANTS 3859c105859eSRandall Stewart panic("Impossible sack 1"); 3860c105859eSRandall Stewart #else 3861b5c16493SMichael Tuexen 3862139bc87fSRandall Stewart *abort_now = 1; 3863139bc87fSRandall Stewart /* XXX */ 3864139bc87fSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 3865139bc87fSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 3866139bc87fSRandall Stewart if (oper) { 3867139bc87fSRandall Stewart struct sctp_paramhdr *ph; 3868139bc87fSRandall Stewart uint32_t *ippp; 3869139bc87fSRandall Stewart 3870139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 3871139bc87fSRandall Stewart sizeof(uint32_t); 3872139bc87fSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 3873139bc87fSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 3874139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 3875139bc87fSRandall Stewart ippp = (uint32_t *) (ph + 1); 3876139bc87fSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 3877139bc87fSRandall Stewart } 3878139bc87fSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 3879ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 3880139bc87fSRandall Stewart return; 3881139bc87fSRandall Stewart #endif 3882139bc87fSRandall Stewart } 3883139bc87fSRandall Stewart } 3884f8829a4aSRandall Stewart asoc->this_sack_highest_gap = cumack; 3885b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 3886c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 3887c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 3888c4739e2fSRandall Stewart 0, 3889c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 3890c4739e2fSRandall Stewart __LINE__); 3891c4739e2fSRandall Stewart } 3892f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 3893*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(cumack, asoc->last_acked_seq)) { 3894f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 38954a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) { 3896*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(cumack, tp1->rec.data.TSN_seq)) { 389718e198d3SRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 389818e198d3SRandall Stewart printf("Warning, an unsent is now acked?\n"); 389918e198d3SRandall Stewart } 3900f8829a4aSRandall Stewart /* 390118e198d3SRandall Stewart * ECN Nonce: Add the nonce to the sender's 390218e198d3SRandall Stewart * nonce sum 3903f8829a4aSRandall Stewart */ 3904f8829a4aSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 3905f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 3906f8829a4aSRandall Stewart /* 390718e198d3SRandall Stewart * If it is less than ACKED, it is 390818e198d3SRandall Stewart * now no-longer in flight. Higher 390918e198d3SRandall Stewart * values may occur during marking 3910f8829a4aSRandall Stewart */ 3911c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3912b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3913c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 3914a5d547adSRandall Stewart tp1->whoTo->flight_size, 3915a5d547adSRandall Stewart tp1->book_size, 3916c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 3917a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 391880fefe0aSRandall Stewart } 3919c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 392004ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 3921c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 3922f8829a4aSRandall Stewart } 3923f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 3924f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 3925f8829a4aSRandall Stewart /* 392618e198d3SRandall Stewart * True non-retransmited 3927f8829a4aSRandall Stewart * chunk 3928f8829a4aSRandall Stewart */ 3929f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 3930f8829a4aSRandall Stewart tp1->send_size; 3931f8829a4aSRandall Stewart 3932f8829a4aSRandall Stewart /* update RTO too? */ 393362c1ff9cSRandall Stewart if (tp1->do_rtt) { 3934f8829a4aSRandall Stewart tp1->whoTo->RTO = 393504ee05e8SRandall Stewart /* 393604ee05e8SRandall Stewart * sa_ignore 393704ee05e8SRandall Stewart * NO_NULL_CHK 393804ee05e8SRandall Stewart */ 3939f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 3940f8829a4aSRandall Stewart asoc, tp1->whoTo, 394118e198d3SRandall Stewart &tp1->sent_rcv_time, 394218e198d3SRandall Stewart sctp_align_safe_nocopy); 3943f8829a4aSRandall Stewart tp1->do_rtt = 0; 3944f8829a4aSRandall Stewart } 3945f8829a4aSRandall Stewart } 3946132dea7dSRandall Stewart /* 394718e198d3SRandall Stewart * CMT: CUCv2 algorithm. From the 394818e198d3SRandall Stewart * cumack'd TSNs, for each TSN being 394918e198d3SRandall Stewart * acked for the first time, set the 395018e198d3SRandall Stewart * following variables for the 395118e198d3SRandall Stewart * corresp destination. 395218e198d3SRandall Stewart * new_pseudo_cumack will trigger a 395318e198d3SRandall Stewart * cwnd update. 395418e198d3SRandall Stewart * find_(rtx_)pseudo_cumack will 395518e198d3SRandall Stewart * trigger search for the next 395618e198d3SRandall Stewart * expected (rtx-)pseudo-cumack. 3957132dea7dSRandall Stewart */ 3958132dea7dSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 3959132dea7dSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 3960132dea7dSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 3961132dea7dSRandall Stewart 3962b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 396304ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 3964f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 396580fefe0aSRandall Stewart } 3966f8829a4aSRandall Stewart } 3967f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 3968f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 3969f8829a4aSRandall Stewart } 397042551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 397142551e99SRandall Stewart /* deflate the cwnd */ 397242551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 397342551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 397442551e99SRandall Stewart } 3975f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 3976f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 3977f8829a4aSRandall Stewart if (tp1->data) { 397804ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 3979f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 3980f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 39814a9ef3f8SMichael Tuexen tp1->data = NULL; 3982f8829a4aSRandall Stewart } 3983b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 3984f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 3985f8829a4aSRandall Stewart cumack, 3986f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3987f8829a4aSRandall Stewart 0, 3988f8829a4aSRandall Stewart 0, 3989f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 399080fefe0aSRandall Stewart } 3991f8829a4aSRandall Stewart asoc->sent_queue_cnt--; 3992f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, tp1); 399318e198d3SRandall Stewart } else { 399418e198d3SRandall Stewart break; 3995f8829a4aSRandall Stewart } 39965e54f665SRandall Stewart } 399718e198d3SRandall Stewart 399818e198d3SRandall Stewart } 399904ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4000f8829a4aSRandall Stewart if (stcb->sctp_socket) { 4001ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4002ceaad40aSRandall Stewart struct socket *so; 4003ceaad40aSRandall Stewart 4004ceaad40aSRandall Stewart #endif 4005f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 4006b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 400704ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4008f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_WAKESND_FROM_SACK); 400980fefe0aSRandall Stewart } 4010ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4011ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 4012ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 4013ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 4014ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 4015ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 4016ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 4017ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 4018ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 4019ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4020ceaad40aSRandall Stewart return; 4021ceaad40aSRandall Stewart } 4022ceaad40aSRandall Stewart #endif 4023f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 4024ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4025ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4026ceaad40aSRandall Stewart #endif 4027f8829a4aSRandall Stewart } else { 4028b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4029f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cumack, 1, SCTP_NOWAKE_FROM_SACK); 403080fefe0aSRandall Stewart } 4031f8829a4aSRandall Stewart } 4032f8829a4aSRandall Stewart 4033b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4034f8829a4aSRandall Stewart if (asoc->last_acked_seq != cumack) 4035b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, 1, 0, 0); 40365e54f665SRandall Stewart 4037f8829a4aSRandall Stewart asoc->last_acked_seq = cumack; 40385e54f665SRandall Stewart 4039f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 4040f8829a4aSRandall Stewart /* nothing left in-flight */ 4041f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4042f8829a4aSRandall Stewart net->flight_size = 0; 4043f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4044f8829a4aSRandall Stewart } 4045f8829a4aSRandall Stewart asoc->total_flight = 0; 4046f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4047f8829a4aSRandall Stewart } 4048f8829a4aSRandall Stewart /* ECN Nonce updates */ 4049f8829a4aSRandall Stewart if (asoc->ecn_nonce_allowed) { 4050f8829a4aSRandall Stewart if (asoc->nonce_sum_check) { 4051f8829a4aSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base) & SCTP_SACK_NONCE_SUM)) { 4052f8829a4aSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 4053f8829a4aSRandall Stewart struct sctp_tmit_chunk *lchk; 4054f8829a4aSRandall Stewart 4055f8829a4aSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 4056f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 1; 4057f8829a4aSRandall Stewart if (lchk) { 4058f8829a4aSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 4059f8829a4aSRandall Stewart } else { 4060f8829a4aSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 4061f8829a4aSRandall Stewart } 4062f8829a4aSRandall Stewart } else { 4063*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->last_acked_seq, asoc->nonce_wait_tsn)) { 4064f8829a4aSRandall Stewart /* 4065f8829a4aSRandall Stewart * Misbehaving peer. We need 4066f8829a4aSRandall Stewart * to react to this guy 4067f8829a4aSRandall Stewart */ 4068f8829a4aSRandall Stewart asoc->ecn_allowed = 0; 4069f8829a4aSRandall Stewart asoc->ecn_nonce_allowed = 0; 4070f8829a4aSRandall Stewart } 4071f8829a4aSRandall Stewart } 4072f8829a4aSRandall Stewart } 4073f8829a4aSRandall Stewart } else { 4074f8829a4aSRandall Stewart /* See if Resynchronization Possible */ 4075*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->last_acked_seq, asoc->nonce_resync_tsn)) { 4076f8829a4aSRandall Stewart asoc->nonce_sum_check = 1; 4077f8829a4aSRandall Stewart /* 4078cd554309SMichael Tuexen * Now we must calculate what the base is. 4079f8829a4aSRandall Stewart * We do this based on two things, we know 4080f8829a4aSRandall Stewart * the total's for all the segments 4081cd554309SMichael Tuexen * gap-acked in the SACK (none). We also 4082f8829a4aSRandall Stewart * know the SACK's nonce sum, its in 4083f8829a4aSRandall Stewart * nonce_sum_flag. So we can build a truth 4084f8829a4aSRandall Stewart * table to back-calculate the new value of 4085f8829a4aSRandall Stewart * asoc->nonce_sum_expect_base: 4086f8829a4aSRandall Stewart * 4087f8829a4aSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 4088f8829a4aSRandall Stewart * 1 0 1 0 1 1 1 4089f8829a4aSRandall Stewart * 1 0 4090f8829a4aSRandall Stewart */ 4091f8829a4aSRandall Stewart asoc->nonce_sum_expect_base = (0 ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 4092f8829a4aSRandall Stewart } 4093f8829a4aSRandall Stewart } 4094f8829a4aSRandall Stewart } 4095f8829a4aSRandall Stewart /* RWND update */ 4096f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 409744fbe462SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 4098f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4099f8829a4aSRandall Stewart /* SWS sender side engages */ 4100f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4101f8829a4aSRandall Stewart } 41025e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 41035e54f665SRandall Stewart win_probe_recovery = 1; 41045e54f665SRandall Stewart } 4105f8829a4aSRandall Stewart /* Now assure a timer where data is queued at */ 4106a5d547adSRandall Stewart again: 4107a5d547adSRandall Stewart j = 0; 4108f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 41095171328bSRandall Stewart int to_ticks; 41105171328bSRandall Stewart 41115e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 4112c105859eSRandall Stewart win_probe_recovered = 1; 41135e54f665SRandall Stewart /* 41145e54f665SRandall Stewart * Find first chunk that was used with window probe 41155e54f665SRandall Stewart * and clear the sent 41165e54f665SRandall Stewart */ 41173c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 41185e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 41195e54f665SRandall Stewart if (tp1->window_probe) { 4120cd554309SMichael Tuexen /* move back to data send queue */ 4121c105859eSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 41225e54f665SRandall Stewart break; 41235e54f665SRandall Stewart } 41245e54f665SRandall Stewart } 41255e54f665SRandall Stewart } 4126f8829a4aSRandall Stewart if (net->RTO == 0) { 4127f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto); 4128f8829a4aSRandall Stewart } else { 4129f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(net->RTO); 4130f8829a4aSRandall Stewart } 41315171328bSRandall Stewart if (net->flight_size) { 4132a5d547adSRandall Stewart j++; 4133ad81507eSRandall Stewart (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 4134f8829a4aSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 41355171328bSRandall Stewart if (net->window_probe) { 41365171328bSRandall Stewart net->window_probe = 0; 41375171328bSRandall Stewart } 4138f8829a4aSRandall Stewart } else { 41395171328bSRandall Stewart if (net->window_probe) { 41405171328bSRandall Stewart /* 41415171328bSRandall Stewart * In window probes we must assure a timer 41425171328bSRandall Stewart * is still running there 41435171328bSRandall Stewart */ 41445171328bSRandall Stewart net->window_probe = 0; 41455171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 41465171328bSRandall Stewart SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 41475171328bSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 41485171328bSRandall Stewart } 41495171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 4150f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4151a5d547adSRandall Stewart stcb, net, 4152a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 4153f8829a4aSRandall Stewart } 4154b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4155139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4156f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 4157a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4158a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 4159f8829a4aSRandall Stewart } 4160f8829a4aSRandall Stewart } 4161f8829a4aSRandall Stewart } 4162f8829a4aSRandall Stewart } 4163bff64a4dSRandall Stewart if ((j == 0) && 4164bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 4165bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 4166c105859eSRandall Stewart (win_probe_recovered == 0) && 4167bff64a4dSRandall Stewart (done_once == 0)) { 41680c0982b8SRandall Stewart /* 41690c0982b8SRandall Stewart * huh, this should not happen unless all packets are 41700c0982b8SRandall Stewart * PR-SCTP and marked to skip of course. 41710c0982b8SRandall Stewart */ 41720c0982b8SRandall Stewart if (sctp_fs_audit(asoc)) { 4173a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4174a5d547adSRandall Stewart net->flight_size = 0; 4175a5d547adSRandall Stewart } 4176a5d547adSRandall Stewart asoc->total_flight = 0; 4177a5d547adSRandall Stewart asoc->total_flight_count = 0; 4178a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4179a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4180a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4181c105859eSRandall Stewart sctp_flight_size_increase(tp1); 4182c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 4183a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4184791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 4185a5d547adSRandall Stewart } 4186a5d547adSRandall Stewart } 41870c0982b8SRandall Stewart } 4188bff64a4dSRandall Stewart done_once = 1; 4189a5d547adSRandall Stewart goto again; 4190a5d547adSRandall Stewart } 4191f8829a4aSRandall Stewart /**********************************/ 4192f8829a4aSRandall Stewart /* Now what about shutdown issues */ 4193f8829a4aSRandall Stewart /**********************************/ 4194f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 4195f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 4196f8829a4aSRandall Stewart /* clean up */ 4197f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 4198f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 4199f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 4200f8829a4aSRandall Stewart (asoc->locked_on_sending) 4201f8829a4aSRandall Stewart ) { 4202f8829a4aSRandall Stewart struct sctp_stream_queue_pending *sp; 4203f8829a4aSRandall Stewart 4204f8829a4aSRandall Stewart /* 4205f8829a4aSRandall Stewart * I may be in a state where we got all across.. but 4206f8829a4aSRandall Stewart * cannot write more due to a shutdown... we abort 4207f8829a4aSRandall Stewart * since the user did not indicate EOR in this case. 4208f8829a4aSRandall Stewart * The sp will be cleaned during free of the asoc. 4209f8829a4aSRandall Stewart */ 4210f8829a4aSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 4211f8829a4aSRandall Stewart sctp_streamhead); 42122afb3e84SRandall Stewart if ((sp) && (sp->length == 0)) { 42132afb3e84SRandall Stewart /* Let cleanup code purge it */ 42142afb3e84SRandall Stewart if (sp->msg_is_complete) { 42152afb3e84SRandall Stewart asoc->stream_queue_cnt--; 42162afb3e84SRandall Stewart } else { 4217f8829a4aSRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 4218f8829a4aSRandall Stewart asoc->locked_on_sending = NULL; 4219f8829a4aSRandall Stewart asoc->stream_queue_cnt--; 4220f8829a4aSRandall Stewart } 4221f8829a4aSRandall Stewart } 42222afb3e84SRandall Stewart } 4223f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 4224f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4225f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4226f8829a4aSRandall Stewart /* Need to abort here */ 4227f8829a4aSRandall Stewart struct mbuf *oper; 4228f8829a4aSRandall Stewart 4229f8829a4aSRandall Stewart abort_out_now: 4230f8829a4aSRandall Stewart *abort_now = 1; 4231f8829a4aSRandall Stewart /* XXX */ 4232f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4233f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4234f8829a4aSRandall Stewart if (oper) { 4235f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 4236f8829a4aSRandall Stewart uint32_t *ippp; 4237f8829a4aSRandall Stewart 4238139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4239f8829a4aSRandall Stewart sizeof(uint32_t); 4240f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4241f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 4242139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4243f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 4244a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_24); 4245f8829a4aSRandall Stewart } 4246a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24; 4247ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 4248f8829a4aSRandall Stewart } else { 4249f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 4250f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 4251f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4252f42a358aSRandall Stewart } 4253c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 4254b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4255f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 4256f8829a4aSRandall Stewart sctp_send_shutdown(stcb, 4257f8829a4aSRandall Stewart stcb->asoc.primary_destination); 4258f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 4259f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4260f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 4261f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4262f8829a4aSRandall Stewart } 4263f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 4264f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4265f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4266f8829a4aSRandall Stewart goto abort_out_now; 4267f8829a4aSRandall Stewart } 4268f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4269c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 4270b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4271f8829a4aSRandall Stewart sctp_send_shutdown_ack(stcb, 4272f8829a4aSRandall Stewart stcb->asoc.primary_destination); 427312af6654SMichael Tuexen sctp_stop_timers_for_shutdown(stcb); 4274f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 4275f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4276f8829a4aSRandall Stewart } 4277f8829a4aSRandall Stewart } 4278dfb11ef8SRandall Stewart /*********************************************/ 4279dfb11ef8SRandall Stewart /* Here we perform PR-SCTP procedures */ 4280dfb11ef8SRandall Stewart /* (section 4.2) */ 4281dfb11ef8SRandall Stewart /*********************************************/ 4282dfb11ef8SRandall Stewart /* C1. update advancedPeerAckPoint */ 4283*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(cumack, asoc->advanced_peer_ack_point)) { 4284dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cumack; 4285dfb11ef8SRandall Stewart } 4286830d754dSRandall Stewart /* PR-Sctp issues need to be addressed too */ 4287830d754dSRandall Stewart if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) { 4288830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 4289830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 4290830d754dSRandall Stewart 4291830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 4292830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 4293830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 4294*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, cumack)) { 4295830d754dSRandall Stewart /* 4296830d754dSRandall Stewart * ISSUE with ECN, see FWD-TSN processing for notes 4297830d754dSRandall Stewart * on issues that will occur when the ECN NONCE 4298830d754dSRandall Stewart * stuff is put into SCTP for cross checking. 4299830d754dSRandall Stewart */ 4300*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, old_adv_peer_ack_point)) { 4301830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 4302830d754dSRandall Stewart /* 4303830d754dSRandall Stewart * ECN Nonce: Disable Nonce Sum check when 4304830d754dSRandall Stewart * FWD TSN is sent and store resync tsn 4305830d754dSRandall Stewart */ 4306830d754dSRandall Stewart asoc->nonce_sum_check = 0; 4307830d754dSRandall Stewart asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point; 43080c0982b8SRandall Stewart } else if (lchk) { 43090c0982b8SRandall Stewart /* try to FR fwd-tsn's that get lost too */ 431044fbe462SRandall Stewart if (lchk->rec.data.fwd_tsn_cnt >= 3) { 43110c0982b8SRandall Stewart send_forward_tsn(stcb, asoc); 43120c0982b8SRandall Stewart } 4313830d754dSRandall Stewart } 4314830d754dSRandall Stewart } 4315830d754dSRandall Stewart if (lchk) { 4316830d754dSRandall Stewart /* Assure a timer is up */ 4317830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 4318830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 4319830d754dSRandall Stewart } 4320830d754dSRandall Stewart } 4321b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 4322f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 4323f8829a4aSRandall Stewart rwnd, 4324f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 4325f8829a4aSRandall Stewart stcb->asoc.total_flight, 4326f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 432780fefe0aSRandall Stewart } 4328f8829a4aSRandall Stewart } 4329f8829a4aSRandall Stewart 4330f8829a4aSRandall Stewart void 4331cd554309SMichael Tuexen sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup, 4332cd554309SMichael Tuexen struct sctp_tcb *stcb, struct sctp_nets *net_from, 4333cd554309SMichael Tuexen uint16_t num_seg, uint16_t num_nr_seg, uint16_t num_dup, 4334cd554309SMichael Tuexen int *abort_now, uint8_t flags, 4335cd554309SMichael Tuexen uint32_t cum_ack, uint32_t rwnd) 4336f8829a4aSRandall Stewart { 4337f8829a4aSRandall Stewart struct sctp_association *asoc; 4338f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 4339cd554309SMichael Tuexen uint32_t last_tsn, biggest_tsn_acked, biggest_tsn_newly_acked, this_sack_lowest_newack; 4340bff64a4dSRandall Stewart uint32_t sav_cum_ack; 4341f8829a4aSRandall Stewart uint16_t wake_him = 0; 4342c105859eSRandall Stewart uint32_t send_s = 0; 4343f8829a4aSRandall Stewart long j; 4344f8829a4aSRandall Stewart int accum_moved = 0; 4345f8829a4aSRandall Stewart int will_exit_fast_recovery = 0; 43465e54f665SRandall Stewart uint32_t a_rwnd, old_rwnd; 43475e54f665SRandall Stewart int win_probe_recovery = 0; 4348c105859eSRandall Stewart int win_probe_recovered = 0; 4349f8829a4aSRandall Stewart struct sctp_nets *net = NULL; 4350f8829a4aSRandall Stewart int nonce_sum_flag, ecn_seg_sums = 0; 4351bff64a4dSRandall Stewart int done_once; 4352f8829a4aSRandall Stewart uint8_t reneged_all = 0; 4353f8829a4aSRandall Stewart uint8_t cmt_dac_flag; 4354f8829a4aSRandall Stewart 4355f8829a4aSRandall Stewart /* 4356f8829a4aSRandall Stewart * we take any chance we can to service our queues since we cannot 4357f8829a4aSRandall Stewart * get awoken when the socket is read from :< 4358f8829a4aSRandall Stewart */ 4359f8829a4aSRandall Stewart /* 4360f8829a4aSRandall Stewart * Now perform the actual SACK handling: 1) Verify that it is not an 4361f8829a4aSRandall Stewart * old sack, if so discard. 2) If there is nothing left in the send 4362f8829a4aSRandall Stewart * queue (cum-ack is equal to last acked) then you have a duplicate 4363f8829a4aSRandall Stewart * too, update any rwnd change and verify no timers are running. 4364f8829a4aSRandall Stewart * then return. 3) Process any new consequtive data i.e. cum-ack 4365f8829a4aSRandall Stewart * moved process these first and note that it moved. 4) Process any 4366f8829a4aSRandall Stewart * sack blocks. 5) Drop any acked from the queue. 6) Check for any 4367f8829a4aSRandall Stewart * revoked blocks and mark. 7) Update the cwnd. 8) Nothing left, 4368f8829a4aSRandall Stewart * sync up flightsizes and things, stop all timers and also check 4369f8829a4aSRandall Stewart * for shutdown_pending state. If so then go ahead and send off the 4370f8829a4aSRandall Stewart * shutdown. If in shutdown recv, send off the shutdown-ack and 4371f8829a4aSRandall Stewart * start that timer, Ret. 9) Strike any non-acked things and do FR 4372f8829a4aSRandall Stewart * procedure if needed being sure to set the FR flag. 10) Do pr-sctp 4373f8829a4aSRandall Stewart * procedures. 11) Apply any FR penalties. 12) Assure we will SACK 4374f8829a4aSRandall Stewart * if in shutdown_recv state. 4375f8829a4aSRandall Stewart */ 4376f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 4377f8829a4aSRandall Stewart /* CMT DAC algo */ 4378f8829a4aSRandall Stewart this_sack_lowest_newack = 0; 4379f8829a4aSRandall Stewart j = 0; 4380f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_slowpath_sack); 4381cd554309SMichael Tuexen last_tsn = cum_ack; 4382cd554309SMichael Tuexen nonce_sum_flag = flags & SCTP_SACK_NONCE_SUM; 4383cd554309SMichael Tuexen cmt_dac_flag = flags & SCTP_SACK_CMT_DAC; 438418e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 438518e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cum_ack; 438618e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 438718e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 438818e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 438918e198d3SRandall Stewart } 439018e198d3SRandall Stewart #endif 4391d06c82f1SRandall Stewart a_rwnd = rwnd; 4392f8829a4aSRandall Stewart 4393cd554309SMichael Tuexen if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 4394cd554309SMichael Tuexen sctp_misc_ints(SCTP_SACK_LOG_NORMAL, cum_ack, 4395cd554309SMichael Tuexen rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 4396cd554309SMichael Tuexen } 43975e54f665SRandall Stewart old_rwnd = stcb->asoc.peers_rwnd; 4398b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 4399c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 4400c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 4401c4739e2fSRandall Stewart 0, 4402c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 4403c4739e2fSRandall Stewart __LINE__); 4404c4739e2fSRandall Stewart } 4405f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 4406f8829a4aSRandall Stewart asoc = &stcb->asoc; 4407b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4408f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4409f8829a4aSRandall Stewart cum_ack, 4410f8829a4aSRandall Stewart 0, 4411f8829a4aSRandall Stewart num_seg, 4412f8829a4aSRandall Stewart num_dup, 4413f8829a4aSRandall Stewart SCTP_LOG_NEW_SACK); 441480fefe0aSRandall Stewart } 4415b3f1ea41SRandall Stewart if ((num_dup) && (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_FR_LOGGING_ENABLE | SCTP_EARLYFR_LOGGING_ENABLE))) { 4416cd554309SMichael Tuexen uint16_t i; 4417458303daSRandall Stewart uint32_t *dupdata, dblock; 4418f8829a4aSRandall Stewart 4419cd554309SMichael Tuexen for (i = 0; i < num_dup; i++) { 4420cd554309SMichael Tuexen dupdata = (uint32_t *) sctp_m_getptr(m, offset_dup + i * sizeof(uint32_t), 4421458303daSRandall Stewart sizeof(uint32_t), (uint8_t *) & dblock); 4422cd554309SMichael Tuexen if (dupdata == NULL) { 4423458303daSRandall Stewart break; 4424458303daSRandall Stewart } 4425cd554309SMichael Tuexen sctp_log_fr(*dupdata, 0, 0, SCTP_FR_DUPED); 4426f8829a4aSRandall Stewart } 4427f8829a4aSRandall Stewart } 4428b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 4429c105859eSRandall Stewart /* reality check */ 4430c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 4431c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 4432c105859eSRandall Stewart sctpchunk_listhead); 4433c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 4434c105859eSRandall Stewart } else { 4435b5c16493SMichael Tuexen tp1 = NULL; 4436c105859eSRandall Stewart send_s = asoc->sending_seq; 4437c105859eSRandall Stewart } 4438*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(cum_ack, send_s)) { 4439c105859eSRandall Stewart struct mbuf *oper; 4440c105859eSRandall Stewart 4441f8829a4aSRandall Stewart /* 4442f8829a4aSRandall Stewart * no way, we have not even sent this TSN out yet. 4443f8829a4aSRandall Stewart * Peer is hopelessly messed up with us. 4444f8829a4aSRandall Stewart */ 4445b5c16493SMichael Tuexen printf("NEW cum_ack:%x send_s:%x is smaller or equal\n", 4446b5c16493SMichael Tuexen cum_ack, send_s); 4447b5c16493SMichael Tuexen if (tp1) { 4448b5c16493SMichael Tuexen printf("Got send_s from tsn:%x + 1 of tp1:%p\n", 4449b5c16493SMichael Tuexen tp1->rec.data.TSN_seq, tp1); 4450b5c16493SMichael Tuexen } 4451f8829a4aSRandall Stewart hopeless_peer: 4452f8829a4aSRandall Stewart *abort_now = 1; 4453f8829a4aSRandall Stewart /* XXX */ 4454f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4455f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4456f8829a4aSRandall Stewart if (oper) { 4457f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 4458f8829a4aSRandall Stewart uint32_t *ippp; 4459f8829a4aSRandall Stewart 4460139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4461f8829a4aSRandall Stewart sizeof(uint32_t); 4462f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4463f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 4464139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4465f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 4466a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25); 4467f8829a4aSRandall Stewart } 4468a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 4469ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 4470f8829a4aSRandall Stewart return; 4471f8829a4aSRandall Stewart } 4472f8829a4aSRandall Stewart } 4473f8829a4aSRandall Stewart /**********************/ 4474f8829a4aSRandall Stewart /* 1) check the range */ 4475f8829a4aSRandall Stewart /**********************/ 4476*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->last_acked_seq, last_tsn)) { 4477f8829a4aSRandall Stewart /* acking something behind */ 4478f8829a4aSRandall Stewart return; 4479f8829a4aSRandall Stewart } 4480bff64a4dSRandall Stewart sav_cum_ack = asoc->last_acked_seq; 4481bff64a4dSRandall Stewart 4482f8829a4aSRandall Stewart /* update the Rwnd of the peer */ 4483f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue) && 4484f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->send_queue) && 4485cd554309SMichael Tuexen (asoc->stream_queue_cnt == 0)) { 4486f8829a4aSRandall Stewart /* nothing left on send/sent and strmq */ 4487b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4488f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 4489f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 449080fefe0aSRandall Stewart } 4491f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 4492f8829a4aSRandall Stewart if (asoc->sent_queue_retran_cnt) { 4493f8829a4aSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4494f8829a4aSRandall Stewart } 4495f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4496f8829a4aSRandall Stewart /* SWS sender side engages */ 4497f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4498f8829a4aSRandall Stewart } 4499f8829a4aSRandall Stewart /* stop any timers */ 4500f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4501f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4502a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 4503b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4504139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4505f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck1); 4506a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4507a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 4508f8829a4aSRandall Stewart } 4509f8829a4aSRandall Stewart } 4510f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4511f8829a4aSRandall Stewart net->flight_size = 0; 4512f8829a4aSRandall Stewart } 4513f8829a4aSRandall Stewart asoc->total_flight = 0; 4514f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4515f8829a4aSRandall Stewart return; 4516f8829a4aSRandall Stewart } 4517f8829a4aSRandall Stewart /* 4518f8829a4aSRandall Stewart * We init netAckSz and netAckSz2 to 0. These are used to track 2 4519f8829a4aSRandall Stewart * things. The total byte count acked is tracked in netAckSz AND 4520f8829a4aSRandall Stewart * netAck2 is used to track the total bytes acked that are un- 4521f8829a4aSRandall Stewart * amibguious and were never retransmitted. We track these on a per 4522f8829a4aSRandall Stewart * destination address basis. 4523f8829a4aSRandall Stewart */ 4524f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4525f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 4526f8829a4aSRandall Stewart net->net_ack = 0; 4527f8829a4aSRandall Stewart net->net_ack2 = 0; 4528f8829a4aSRandall Stewart 4529f8829a4aSRandall Stewart /* 453042551e99SRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 453142551e99SRandall Stewart * SACK processing 4532f8829a4aSRandall Stewart */ 4533f8829a4aSRandall Stewart net->new_pseudo_cumack = 0; 4534f8829a4aSRandall Stewart net->will_exit_fast_recovery = 0; 4535f8829a4aSRandall Stewart } 4536f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 45374a9ef3f8SMichael Tuexen TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4538*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(last_tsn, tp1->rec.data.TSN_seq)) { 4539f8829a4aSRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 4540f8829a4aSRandall Stewart /* 4541f8829a4aSRandall Stewart * ECN Nonce: Add the nonce to the sender's 4542f8829a4aSRandall Stewart * nonce sum 4543f8829a4aSRandall Stewart */ 4544f8829a4aSRandall Stewart asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce; 4545f8829a4aSRandall Stewart accum_moved = 1; 4546f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 4547f8829a4aSRandall Stewart /* 4548f8829a4aSRandall Stewart * If it is less than ACKED, it is 4549f8829a4aSRandall Stewart * now no-longer in flight. Higher 4550f8829a4aSRandall Stewart * values may occur during marking 4551f8829a4aSRandall Stewart */ 4552f8829a4aSRandall Stewart if ((tp1->whoTo->dest_state & 4553f8829a4aSRandall Stewart SCTP_ADDR_UNCONFIRMED) && 4554f8829a4aSRandall Stewart (tp1->snd_count < 2)) { 4555f8829a4aSRandall Stewart /* 4556f8829a4aSRandall Stewart * If there was no retran 4557f8829a4aSRandall Stewart * and the address is 4558f8829a4aSRandall Stewart * un-confirmed and we sent 4559f8829a4aSRandall Stewart * there and are now 4560f8829a4aSRandall Stewart * sacked.. its confirmed, 4561f8829a4aSRandall Stewart * mark it so. 4562f8829a4aSRandall Stewart */ 4563f8829a4aSRandall Stewart tp1->whoTo->dest_state &= 4564f8829a4aSRandall Stewart ~SCTP_ADDR_UNCONFIRMED; 4565f8829a4aSRandall Stewart } 4566c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4567b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4568c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 4569a5d547adSRandall Stewart tp1->whoTo->flight_size, 4570a5d547adSRandall Stewart tp1->book_size, 4571c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4572a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 457380fefe0aSRandall Stewart } 4574c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 4575c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 4576f8829a4aSRandall Stewart } 4577f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 4578f8829a4aSRandall Stewart 4579f8829a4aSRandall Stewart /* CMT SFR and DAC algos */ 4580f8829a4aSRandall Stewart this_sack_lowest_newack = tp1->rec.data.TSN_seq; 4581f8829a4aSRandall Stewart tp1->whoTo->saw_newack = 1; 4582f8829a4aSRandall Stewart 4583f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 4584f8829a4aSRandall Stewart /* 4585f8829a4aSRandall Stewart * True non-retransmited 4586f8829a4aSRandall Stewart * chunk 4587f8829a4aSRandall Stewart */ 4588f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 4589f8829a4aSRandall Stewart tp1->send_size; 4590f8829a4aSRandall Stewart 4591f8829a4aSRandall Stewart /* update RTO too? */ 4592f8829a4aSRandall Stewart if (tp1->do_rtt) { 4593f8829a4aSRandall Stewart tp1->whoTo->RTO = 4594f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 4595f8829a4aSRandall Stewart asoc, tp1->whoTo, 459618e198d3SRandall Stewart &tp1->sent_rcv_time, 459718e198d3SRandall Stewart sctp_align_safe_nocopy); 4598f8829a4aSRandall Stewart tp1->do_rtt = 0; 4599f8829a4aSRandall Stewart } 4600f8829a4aSRandall Stewart } 4601f8829a4aSRandall Stewart /* 4602f8829a4aSRandall Stewart * CMT: CUCv2 algorithm. From the 4603f8829a4aSRandall Stewart * cumack'd TSNs, for each TSN being 4604f8829a4aSRandall Stewart * acked for the first time, set the 4605f8829a4aSRandall Stewart * following variables for the 4606f8829a4aSRandall Stewart * corresp destination. 4607f8829a4aSRandall Stewart * new_pseudo_cumack will trigger a 4608f8829a4aSRandall Stewart * cwnd update. 4609f8829a4aSRandall Stewart * find_(rtx_)pseudo_cumack will 4610f8829a4aSRandall Stewart * trigger search for the next 4611f8829a4aSRandall Stewart * expected (rtx-)pseudo-cumack. 4612f8829a4aSRandall Stewart */ 4613f8829a4aSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 4614f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 4615f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 4616f8829a4aSRandall Stewart 4617f8829a4aSRandall Stewart 4618b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4619f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4620f8829a4aSRandall Stewart cum_ack, 4621f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4622f8829a4aSRandall Stewart 0, 4623f8829a4aSRandall Stewart 0, 4624f8829a4aSRandall Stewart SCTP_LOG_TSN_ACKED); 462580fefe0aSRandall Stewart } 4626b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 4627f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 462880fefe0aSRandall Stewart } 4629f8829a4aSRandall Stewart } 4630f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4631f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 4632f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 4633f8829a4aSRandall Stewart sctp_audit_log(0xB3, 4634f8829a4aSRandall Stewart (asoc->sent_queue_retran_cnt & 0x000000ff)); 4635f8829a4aSRandall Stewart #endif 4636f8829a4aSRandall Stewart } 463742551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 463842551e99SRandall Stewart /* deflate the cwnd */ 463942551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 464042551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 464142551e99SRandall Stewart } 4642f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 4643f8829a4aSRandall Stewart } 4644f8829a4aSRandall Stewart } else { 4645f8829a4aSRandall Stewart break; 4646f8829a4aSRandall Stewart } 4647f8829a4aSRandall Stewart } 4648f8829a4aSRandall Stewart biggest_tsn_newly_acked = biggest_tsn_acked = last_tsn; 4649f8829a4aSRandall Stewart /* always set this up to cum-ack */ 4650f8829a4aSRandall Stewart asoc->this_sack_highest_gap = last_tsn; 4651f8829a4aSRandall Stewart 4652cd554309SMichael Tuexen if ((num_seg > 0) || (num_nr_seg > 0)) { 4653f8829a4aSRandall Stewart 4654f8829a4aSRandall Stewart /* 4655f8829a4aSRandall Stewart * CMT: SFR algo (and HTNA) - this_sack_highest_newack has 4656f8829a4aSRandall Stewart * to be greater than the cumack. Also reset saw_newack to 0 4657f8829a4aSRandall Stewart * for all dests. 4658f8829a4aSRandall Stewart */ 4659f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4660f8829a4aSRandall Stewart net->saw_newack = 0; 4661f8829a4aSRandall Stewart net->this_sack_highest_newack = last_tsn; 4662f8829a4aSRandall Stewart } 4663f8829a4aSRandall Stewart 4664f8829a4aSRandall Stewart /* 4665f8829a4aSRandall Stewart * thisSackHighestGap will increase while handling NEW 4666f8829a4aSRandall Stewart * segments this_sack_highest_newack will increase while 4667f8829a4aSRandall Stewart * handling NEWLY ACKED chunks. this_sack_lowest_newack is 4668f8829a4aSRandall Stewart * used for CMT DAC algo. saw_newack will also change. 4669f8829a4aSRandall Stewart */ 4670cd554309SMichael Tuexen if (sctp_handle_segments(m, &offset_seg, stcb, asoc, last_tsn, &biggest_tsn_acked, 4671cd554309SMichael Tuexen &biggest_tsn_newly_acked, &this_sack_lowest_newack, 4672cd554309SMichael Tuexen num_seg, num_nr_seg, &ecn_seg_sums)) { 4673cd554309SMichael Tuexen wake_him++; 4674cd554309SMichael Tuexen } 4675b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) { 4676f8829a4aSRandall Stewart /* 4677f8829a4aSRandall Stewart * validate the biggest_tsn_acked in the gap acks if 4678f8829a4aSRandall Stewart * strict adherence is wanted. 4679f8829a4aSRandall Stewart */ 4680*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(biggest_tsn_acked, send_s)) { 4681f8829a4aSRandall Stewart /* 4682f8829a4aSRandall Stewart * peer is either confused or we are under 4683f8829a4aSRandall Stewart * attack. We must abort. 4684f8829a4aSRandall Stewart */ 4685b5c16493SMichael Tuexen printf("Hopeless peer! biggest_tsn_acked:%x largest seq:%x\n", 4686b5c16493SMichael Tuexen biggest_tsn_acked, 4687b5c16493SMichael Tuexen send_s); 4688b5c16493SMichael Tuexen 4689f8829a4aSRandall Stewart goto hopeless_peer; 4690f8829a4aSRandall Stewart } 4691f8829a4aSRandall Stewart } 4692f8829a4aSRandall Stewart } 4693f8829a4aSRandall Stewart /*******************************************/ 4694f8829a4aSRandall Stewart /* cancel ALL T3-send timer if accum moved */ 4695f8829a4aSRandall Stewart /*******************************************/ 46967c99d56fSMichael Tuexen if (asoc->sctp_cmt_on_off > 0) { 4697f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4698f8829a4aSRandall Stewart if (net->new_pseudo_cumack) 4699f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4700a5d547adSRandall Stewart stcb, net, 4701a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_27); 4702f8829a4aSRandall Stewart 4703f8829a4aSRandall Stewart } 4704f8829a4aSRandall Stewart } else { 4705f8829a4aSRandall Stewart if (accum_moved) { 4706f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4707f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4708a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_28); 4709f8829a4aSRandall Stewart } 4710f8829a4aSRandall Stewart } 4711f8829a4aSRandall Stewart } 4712f8829a4aSRandall Stewart /********************************************/ 4713d9c5cfeaSMichael Tuexen /* drop the acked chunks from the sentqueue */ 4714f8829a4aSRandall Stewart /********************************************/ 4715f8829a4aSRandall Stewart asoc->last_acked_seq = cum_ack; 4716f8829a4aSRandall Stewart 47177c99d56fSMichael Tuexen TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) { 4718*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, cum_ack)) { 4719f8829a4aSRandall Stewart break; 4720f8829a4aSRandall Stewart } 4721f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 4722f8829a4aSRandall Stewart /* no more sent on list */ 472318e198d3SRandall Stewart printf("Warning, tp1->sent == %d and its now acked?\n", 472418e198d3SRandall Stewart tp1->sent); 4725f8829a4aSRandall Stewart } 4726f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 4727f8829a4aSRandall Stewart if (tp1->pr_sctp_on) { 4728f8829a4aSRandall Stewart if (asoc->pr_sctp_cnt != 0) 4729f8829a4aSRandall Stewart asoc->pr_sctp_cnt--; 4730f8829a4aSRandall Stewart } 47317c99d56fSMichael Tuexen asoc->sent_queue_cnt--; 4732f8829a4aSRandall Stewart if (tp1->data) { 473304ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4734f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 4735f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 47367c99d56fSMichael Tuexen tp1->data = NULL; 4737810ec536SMichael Tuexen if (asoc->peer_supports_prsctp && PR_SCTP_BUF_ENABLED(tp1->flags)) { 4738f8829a4aSRandall Stewart asoc->sent_queue_cnt_removeable--; 4739f8829a4aSRandall Stewart } 4740f8829a4aSRandall Stewart } 4741b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4742f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4743f8829a4aSRandall Stewart cum_ack, 4744f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4745f8829a4aSRandall Stewart 0, 4746f8829a4aSRandall Stewart 0, 4747f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 474880fefe0aSRandall Stewart } 4749f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, tp1); 4750f8829a4aSRandall Stewart wake_him++; 47517c99d56fSMichael Tuexen } 47527c99d56fSMichael Tuexen if (TAILQ_EMPTY(&asoc->sent_queue) && (asoc->total_flight > 0)) { 47537c99d56fSMichael Tuexen #ifdef INVARIANTS 47547c99d56fSMichael Tuexen panic("Warning flight size is postive and should be 0"); 47557c99d56fSMichael Tuexen #else 47567c99d56fSMichael Tuexen SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n", 47577c99d56fSMichael Tuexen asoc->total_flight); 47587c99d56fSMichael Tuexen #endif 47597c99d56fSMichael Tuexen asoc->total_flight = 0; 47607c99d56fSMichael Tuexen } 476104ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4762f8829a4aSRandall Stewart if ((wake_him) && (stcb->sctp_socket)) { 4763ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4764ceaad40aSRandall Stewart struct socket *so; 4765ceaad40aSRandall Stewart 4766ceaad40aSRandall Stewart #endif 4767f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 4768b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4769f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_WAKESND_FROM_SACK); 477080fefe0aSRandall Stewart } 4771ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4772ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 4773ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 4774ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 4775ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 4776ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 4777ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 4778ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 4779ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 4780ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4781ceaad40aSRandall Stewart return; 4782ceaad40aSRandall Stewart } 4783ceaad40aSRandall Stewart #endif 4784f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 4785ceaad40aSRandall Stewart #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4786ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4787ceaad40aSRandall Stewart #endif 4788f8829a4aSRandall Stewart } else { 4789b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 4790f8829a4aSRandall Stewart sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_NOWAKE_FROM_SACK); 479180fefe0aSRandall Stewart } 4792f8829a4aSRandall Stewart } 4793f8829a4aSRandall Stewart 479442551e99SRandall Stewart if (asoc->fast_retran_loss_recovery && accum_moved) { 4795*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->last_acked_seq, asoc->fast_recovery_tsn)) { 4796f8829a4aSRandall Stewart /* Setup so we will exit RFC2582 fast recovery */ 4797f8829a4aSRandall Stewart will_exit_fast_recovery = 1; 4798f8829a4aSRandall Stewart } 4799f8829a4aSRandall Stewart } 4800f8829a4aSRandall Stewart /* 4801f8829a4aSRandall Stewart * Check for revoked fragments: 4802f8829a4aSRandall Stewart * 4803f8829a4aSRandall Stewart * if Previous sack - Had no frags then we can't have any revoked if 4804f8829a4aSRandall Stewart * Previous sack - Had frag's then - If we now have frags aka 4805f8829a4aSRandall Stewart * num_seg > 0 call sctp_check_for_revoked() to tell if peer revoked 4806f8829a4aSRandall Stewart * some of them. else - The peer revoked all ACKED fragments, since 4807f8829a4aSRandall Stewart * we had some before and now we have NONE. 4808f8829a4aSRandall Stewart */ 4809f8829a4aSRandall Stewart 4810d9c5cfeaSMichael Tuexen if (num_seg) { 4811c105859eSRandall Stewart sctp_check_for_revoked(stcb, asoc, cum_ack, biggest_tsn_acked); 4812d9c5cfeaSMichael Tuexen asoc->saw_sack_with_frags = 1; 4813d9c5cfeaSMichael Tuexen } else if (asoc->saw_sack_with_frags) { 4814f8829a4aSRandall Stewart int cnt_revoked = 0; 4815f8829a4aSRandall Stewart 4816f8829a4aSRandall Stewart /* Peer revoked all dg's marked or acked */ 4817f8829a4aSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4818b5c16493SMichael Tuexen if (tp1->sent == SCTP_DATAGRAM_ACKED) { 4819f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 4820b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4821c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 4822c105859eSRandall Stewart tp1->whoTo->flight_size, 4823c105859eSRandall Stewart tp1->book_size, 4824c105859eSRandall Stewart (uintptr_t) tp1->whoTo, 4825c105859eSRandall Stewart tp1->rec.data.TSN_seq); 482680fefe0aSRandall Stewart } 4827c105859eSRandall Stewart sctp_flight_size_increase(tp1); 4828c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 4829a5d547adSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 483042551e99SRandall Stewart /* 483142551e99SRandall Stewart * To ensure that this increase in 48324a9ef3f8SMichael Tuexen * flightsize, which is artificial, does not 48334a9ef3f8SMichael Tuexen * throttle the sender, we also increase the 48344a9ef3f8SMichael Tuexen * cwnd artificially. 483542551e99SRandall Stewart */ 483642551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 4837f8829a4aSRandall Stewart cnt_revoked++; 4838f8829a4aSRandall Stewart } 4839f8829a4aSRandall Stewart } 4840f8829a4aSRandall Stewart if (cnt_revoked) { 4841f8829a4aSRandall Stewart reneged_all = 1; 4842f8829a4aSRandall Stewart } 4843f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 0; 4844f8829a4aSRandall Stewart } 4845d9c5cfeaSMichael Tuexen if (num_nr_seg > 0) 4846d9c5cfeaSMichael Tuexen asoc->saw_sack_with_nr_frags = 1; 4847f8829a4aSRandall Stewart else 4848d9c5cfeaSMichael Tuexen asoc->saw_sack_with_nr_frags = 0; 4849f8829a4aSRandall Stewart 4850b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4851b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, accum_moved, reneged_all, will_exit_fast_recovery); 4852f8829a4aSRandall Stewart 4853f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 4854f8829a4aSRandall Stewart /* nothing left in-flight */ 4855f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4856f8829a4aSRandall Stewart /* stop all timers */ 4857b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 4858139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 4859f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 4860a5d547adSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 4861a5d547adSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_29); 4862f8829a4aSRandall Stewart } 4863f8829a4aSRandall Stewart } 4864f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4865a5d547adSRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_30); 4866f8829a4aSRandall Stewart net->flight_size = 0; 4867f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4868f8829a4aSRandall Stewart } 4869f8829a4aSRandall Stewart asoc->total_flight = 0; 4870f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4871f8829a4aSRandall Stewart } 4872f8829a4aSRandall Stewart /**********************************/ 4873f8829a4aSRandall Stewart /* Now what about shutdown issues */ 4874f8829a4aSRandall Stewart /**********************************/ 4875f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 4876f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 4877b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4878f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 4879f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 488080fefe0aSRandall Stewart } 4881f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 4882f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4883f8829a4aSRandall Stewart /* SWS sender side engages */ 4884f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4885f8829a4aSRandall Stewart } 4886f8829a4aSRandall Stewart /* clean up */ 4887f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 4888f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 4889f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 4890f8829a4aSRandall Stewart (asoc->locked_on_sending) 4891f8829a4aSRandall Stewart ) { 4892f8829a4aSRandall Stewart struct sctp_stream_queue_pending *sp; 4893f8829a4aSRandall Stewart 4894f8829a4aSRandall Stewart /* 4895f8829a4aSRandall Stewart * I may be in a state where we got all across.. but 4896f8829a4aSRandall Stewart * cannot write more due to a shutdown... we abort 4897f8829a4aSRandall Stewart * since the user did not indicate EOR in this case. 4898f8829a4aSRandall Stewart */ 4899f8829a4aSRandall Stewart sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue), 4900f8829a4aSRandall Stewart sctp_streamhead); 49012afb3e84SRandall Stewart if ((sp) && (sp->length == 0)) { 4902f8829a4aSRandall Stewart asoc->locked_on_sending = NULL; 49032afb3e84SRandall Stewart if (sp->msg_is_complete) { 4904f8829a4aSRandall Stewart asoc->stream_queue_cnt--; 49052afb3e84SRandall Stewart } else { 49062afb3e84SRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 49072afb3e84SRandall Stewart asoc->stream_queue_cnt--; 49082afb3e84SRandall Stewart } 4909f8829a4aSRandall Stewart } 4910f8829a4aSRandall Stewart } 4911f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 4912f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4913f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4914f8829a4aSRandall Stewart /* Need to abort here */ 4915f8829a4aSRandall Stewart struct mbuf *oper; 4916f8829a4aSRandall Stewart 4917f8829a4aSRandall Stewart abort_out_now: 4918f8829a4aSRandall Stewart *abort_now = 1; 4919f8829a4aSRandall Stewart /* XXX */ 4920f8829a4aSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), 4921f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 4922f8829a4aSRandall Stewart if (oper) { 4923f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 4924f8829a4aSRandall Stewart uint32_t *ippp; 4925f8829a4aSRandall Stewart 4926139bc87fSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 4927f8829a4aSRandall Stewart sizeof(uint32_t); 4928f8829a4aSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 4929f8829a4aSRandall Stewart ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 4930139bc87fSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 4931f8829a4aSRandall Stewart ippp = (uint32_t *) (ph + 1); 4932a5d547adSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_31); 4933f8829a4aSRandall Stewart } 4934a5d547adSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_31; 4935ceaad40aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper, SCTP_SO_NOT_LOCKED); 4936f8829a4aSRandall Stewart return; 4937f8829a4aSRandall Stewart } else { 4938f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 4939f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 4940f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4941f42a358aSRandall Stewart } 4942c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 4943b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4944f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 4945f8829a4aSRandall Stewart sctp_send_shutdown(stcb, 4946f8829a4aSRandall Stewart stcb->asoc.primary_destination); 4947f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 4948f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4949f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 4950f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4951f8829a4aSRandall Stewart } 4952f8829a4aSRandall Stewart return; 4953f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 4954f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4955f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4956f8829a4aSRandall Stewart goto abort_out_now; 4957f8829a4aSRandall Stewart } 4958f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4959c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 4960b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4961f8829a4aSRandall Stewart sctp_send_shutdown_ack(stcb, 4962f8829a4aSRandall Stewart stcb->asoc.primary_destination); 496312af6654SMichael Tuexen sctp_stop_timers_for_shutdown(stcb); 4964f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 4965f8829a4aSRandall Stewart stcb->sctp_ep, stcb, asoc->primary_destination); 4966f8829a4aSRandall Stewart return; 4967f8829a4aSRandall Stewart } 4968f8829a4aSRandall Stewart } 4969f8829a4aSRandall Stewart /* 4970f8829a4aSRandall Stewart * Now here we are going to recycle net_ack for a different use... 4971f8829a4aSRandall Stewart * HEADS UP. 4972f8829a4aSRandall Stewart */ 4973f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4974f8829a4aSRandall Stewart net->net_ack = 0; 4975f8829a4aSRandall Stewart } 4976f8829a4aSRandall Stewart 4977f8829a4aSRandall Stewart /* 4978f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK DAC flag was 0, then no extra marking 4979f8829a4aSRandall Stewart * to be done. Setting this_sack_lowest_newack to the cum_ack will 4980f8829a4aSRandall Stewart * automatically ensure that. 4981f8829a4aSRandall Stewart */ 49827c99d56fSMichael Tuexen if ((asoc->sctp_cmt_on_off > 0) && 498320083c2eSMichael Tuexen SCTP_BASE_SYSCTL(sctp_cmt_use_dac) && 498420083c2eSMichael Tuexen (cmt_dac_flag == 0)) { 4985f8829a4aSRandall Stewart this_sack_lowest_newack = cum_ack; 4986f8829a4aSRandall Stewart } 4987cd554309SMichael Tuexen if ((num_seg > 0) || (num_nr_seg > 0)) { 4988f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(stcb, asoc, biggest_tsn_acked, 4989f8829a4aSRandall Stewart biggest_tsn_newly_acked, this_sack_lowest_newack, accum_moved); 4990f8829a4aSRandall Stewart } 4991b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4992b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_fr(stcb, asoc); 4993f8829a4aSRandall Stewart 4994f8829a4aSRandall Stewart /****************************************************************** 4995f8829a4aSRandall Stewart * Here we do the stuff with ECN Nonce checking. 4996f8829a4aSRandall Stewart * We basically check to see if the nonce sum flag was incorrect 4997f8829a4aSRandall Stewart * or if resynchronization needs to be done. Also if we catch a 4998f8829a4aSRandall Stewart * misbehaving receiver we give him the kick. 4999f8829a4aSRandall Stewart ******************************************************************/ 5000f8829a4aSRandall Stewart 5001f8829a4aSRandall Stewart if (asoc->ecn_nonce_allowed) { 5002f8829a4aSRandall Stewart if (asoc->nonce_sum_check) { 5003f8829a4aSRandall Stewart if (nonce_sum_flag != ((asoc->nonce_sum_expect_base + ecn_seg_sums) & SCTP_SACK_NONCE_SUM)) { 5004f8829a4aSRandall Stewart if (asoc->nonce_wait_for_ecne == 0) { 5005f8829a4aSRandall Stewart struct sctp_tmit_chunk *lchk; 5006f8829a4aSRandall Stewart 5007f8829a4aSRandall Stewart lchk = TAILQ_FIRST(&asoc->send_queue); 5008f8829a4aSRandall Stewart asoc->nonce_wait_for_ecne = 1; 5009f8829a4aSRandall Stewart if (lchk) { 5010f8829a4aSRandall Stewart asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq; 5011f8829a4aSRandall Stewart } else { 5012f8829a4aSRandall Stewart asoc->nonce_wait_tsn = asoc->sending_seq; 5013f8829a4aSRandall Stewart } 5014f8829a4aSRandall Stewart } else { 5015*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->last_acked_seq, asoc->nonce_wait_tsn)) { 5016f8829a4aSRandall Stewart /* 5017f8829a4aSRandall Stewart * Misbehaving peer. We need 5018f8829a4aSRandall Stewart * to react to this guy 5019f8829a4aSRandall Stewart */ 5020f8829a4aSRandall Stewart asoc->ecn_allowed = 0; 5021f8829a4aSRandall Stewart asoc->ecn_nonce_allowed = 0; 5022f8829a4aSRandall Stewart } 5023f8829a4aSRandall Stewart } 5024f8829a4aSRandall Stewart } 5025f8829a4aSRandall Stewart } else { 5026f8829a4aSRandall Stewart /* See if Resynchronization Possible */ 5027*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->last_acked_seq, asoc->nonce_resync_tsn)) { 5028f8829a4aSRandall Stewart asoc->nonce_sum_check = 1; 5029f8829a4aSRandall Stewart /* 5030f8829a4aSRandall Stewart * now we must calculate what the base is. 5031f8829a4aSRandall Stewart * We do this based on two things, we know 5032f8829a4aSRandall Stewart * the total's for all the segments 5033f8829a4aSRandall Stewart * gap-acked in the SACK, its stored in 5034f8829a4aSRandall Stewart * ecn_seg_sums. We also know the SACK's 5035f8829a4aSRandall Stewart * nonce sum, its in nonce_sum_flag. So we 5036f8829a4aSRandall Stewart * can build a truth table to back-calculate 5037f8829a4aSRandall Stewart * the new value of 5038f8829a4aSRandall Stewart * asoc->nonce_sum_expect_base: 5039f8829a4aSRandall Stewart * 5040f8829a4aSRandall Stewart * SACK-flag-Value Seg-Sums Base 0 0 0 5041f8829a4aSRandall Stewart * 1 0 1 0 1 1 1 5042f8829a4aSRandall Stewart * 1 0 5043f8829a4aSRandall Stewart */ 5044f8829a4aSRandall Stewart asoc->nonce_sum_expect_base = (ecn_seg_sums ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM; 5045f8829a4aSRandall Stewart } 5046f8829a4aSRandall Stewart } 5047f8829a4aSRandall Stewart } 5048f8829a4aSRandall Stewart /* Now are we exiting loss recovery ? */ 5049f8829a4aSRandall Stewart if (will_exit_fast_recovery) { 5050f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 5051f8829a4aSRandall Stewart asoc->fast_retran_loss_recovery = 0; 5052f8829a4aSRandall Stewart } 5053f8829a4aSRandall Stewart if ((asoc->sat_t3_loss_recovery) && 5054*20b07a4dSMichael Tuexen SCTP_TSN_GE(asoc->last_acked_seq, asoc->sat_t3_recovery_tsn)) { 5055f8829a4aSRandall Stewart /* end satellite t3 loss recovery */ 5056f8829a4aSRandall Stewart asoc->sat_t3_loss_recovery = 0; 5057f8829a4aSRandall Stewart } 505842551e99SRandall Stewart /* 505942551e99SRandall Stewart * CMT Fast recovery 506042551e99SRandall Stewart */ 5061f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5062f8829a4aSRandall Stewart if (net->will_exit_fast_recovery) { 5063f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 5064f8829a4aSRandall Stewart net->fast_retran_loss_recovery = 0; 5065f8829a4aSRandall Stewart } 5066f8829a4aSRandall Stewart } 5067f8829a4aSRandall Stewart 5068f8829a4aSRandall Stewart /* Adjust and set the new rwnd value */ 5069b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 5070f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 507144fbe462SRandall Stewart asoc->peers_rwnd, asoc->total_flight, (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)), a_rwnd); 507280fefe0aSRandall Stewart } 5073f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd, 507444fbe462SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 5075f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 5076f8829a4aSRandall Stewart /* SWS sender side engages */ 5077f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 5078f8829a4aSRandall Stewart } 50795e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 50805e54f665SRandall Stewart win_probe_recovery = 1; 50815e54f665SRandall Stewart } 5082f8829a4aSRandall Stewart /* 5083f8829a4aSRandall Stewart * Now we must setup so we have a timer up for anyone with 5084f8829a4aSRandall Stewart * outstanding data. 5085f8829a4aSRandall Stewart */ 5086bff64a4dSRandall Stewart done_once = 0; 5087a5d547adSRandall Stewart again: 5088a5d547adSRandall Stewart j = 0; 5089f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 50905e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 5091c105859eSRandall Stewart win_probe_recovered = 1; 50925e54f665SRandall Stewart /*- 50935e54f665SRandall Stewart * Find first chunk that was used with 50945e54f665SRandall Stewart * window probe and clear the event. Put 50955e54f665SRandall Stewart * it back into the send queue as if has 50965e54f665SRandall Stewart * not been sent. 50975e54f665SRandall Stewart */ 50985e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 50995e54f665SRandall Stewart if (tp1->window_probe) { 5100c105859eSRandall Stewart sctp_window_probe_recovery(stcb, asoc, net, tp1); 51015e54f665SRandall Stewart break; 51025e54f665SRandall Stewart } 51035e54f665SRandall Stewart } 51045e54f665SRandall Stewart } 5105f8829a4aSRandall Stewart if (net->flight_size) { 5106a5d547adSRandall Stewart j++; 5107cd554309SMichael Tuexen if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 5108f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5109f8829a4aSRandall Stewart stcb->sctp_ep, stcb, net); 5110cd554309SMichael Tuexen } 51115171328bSRandall Stewart if (net->window_probe) { 5112cd554309SMichael Tuexen net->window_probe = 0; 51135171328bSRandall Stewart } 5114c105859eSRandall Stewart } else { 51155171328bSRandall Stewart if (net->window_probe) { 51165171328bSRandall Stewart /* 51175171328bSRandall Stewart * In window probes we must assure a timer 51185171328bSRandall Stewart * is still running there 51195171328bSRandall Stewart */ 51205171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 51215171328bSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 51225171328bSRandall Stewart stcb->sctp_ep, stcb, net); 51235171328bSRandall Stewart 51245171328bSRandall Stewart } 51255171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 5126c105859eSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 5127c105859eSRandall Stewart stcb, net, 5128c105859eSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 5129c105859eSRandall Stewart } 5130b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_early_fr)) { 5131c105859eSRandall Stewart if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) { 5132c105859eSRandall Stewart SCTP_STAT_INCR(sctps_earlyfrstpidsck4); 5133c105859eSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net, 5134c105859eSRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 5135c105859eSRandall Stewart } 5136c105859eSRandall Stewart } 5137f8829a4aSRandall Stewart } 5138f8829a4aSRandall Stewart } 5139bff64a4dSRandall Stewart if ((j == 0) && 5140bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 5141bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 5142c105859eSRandall Stewart (win_probe_recovered == 0) && 5143bff64a4dSRandall Stewart (done_once == 0)) { 51440c0982b8SRandall Stewart /* 51450c0982b8SRandall Stewart * huh, this should not happen unless all packets are 51460c0982b8SRandall Stewart * PR-SCTP and marked to skip of course. 51470c0982b8SRandall Stewart */ 51480c0982b8SRandall Stewart if (sctp_fs_audit(asoc)) { 5149a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5150a5d547adSRandall Stewart net->flight_size = 0; 5151a5d547adSRandall Stewart } 5152a5d547adSRandall Stewart asoc->total_flight = 0; 5153a5d547adSRandall Stewart asoc->total_flight_count = 0; 5154a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 5155a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 5156a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 5157c105859eSRandall Stewart sctp_flight_size_increase(tp1); 5158c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 5159a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 5160791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 5161a5d547adSRandall Stewart } 5162a5d547adSRandall Stewart } 51630c0982b8SRandall Stewart } 5164bff64a4dSRandall Stewart done_once = 1; 5165a5d547adSRandall Stewart goto again; 5166a5d547adSRandall Stewart } 5167cd554309SMichael Tuexen /*********************************************/ 5168cd554309SMichael Tuexen /* Here we perform PR-SCTP procedures */ 5169cd554309SMichael Tuexen /* (section 4.2) */ 5170cd554309SMichael Tuexen /*********************************************/ 5171cd554309SMichael Tuexen /* C1. update advancedPeerAckPoint */ 5172*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(cum_ack, asoc->advanced_peer_ack_point)) { 5173dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cum_ack; 5174dfb11ef8SRandall Stewart } 5175830d754dSRandall Stewart /* C2. try to further move advancedPeerAckPoint ahead */ 5176830d754dSRandall Stewart if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) { 5177830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 5178830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 5179830d754dSRandall Stewart 5180830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 5181830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 5182830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 5183*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, cum_ack)) { 5184830d754dSRandall Stewart /* 5185830d754dSRandall Stewart * ISSUE with ECN, see FWD-TSN processing for notes 5186830d754dSRandall Stewart * on issues that will occur when the ECN NONCE 5187830d754dSRandall Stewart * stuff is put into SCTP for cross checking. 5188830d754dSRandall Stewart */ 51890c0982b8SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { 51900c0982b8SRandall Stewart sctp_misc_ints(SCTP_FWD_TSN_CHECK, 51910c0982b8SRandall Stewart 0xee, cum_ack, asoc->advanced_peer_ack_point, 51920c0982b8SRandall Stewart old_adv_peer_ack_point); 51930c0982b8SRandall Stewart } 5194*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, old_adv_peer_ack_point)) { 519544fbe462SRandall Stewart 5196830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 5197830d754dSRandall Stewart /* 5198830d754dSRandall Stewart * ECN Nonce: Disable Nonce Sum check when 5199830d754dSRandall Stewart * FWD TSN is sent and store resync tsn 5200830d754dSRandall Stewart */ 5201830d754dSRandall Stewart asoc->nonce_sum_check = 0; 5202830d754dSRandall Stewart asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point; 52030c0982b8SRandall Stewart } else if (lchk) { 52040c0982b8SRandall Stewart /* try to FR fwd-tsn's that get lost too */ 520544fbe462SRandall Stewart if (lchk->rec.data.fwd_tsn_cnt >= 3) { 52060c0982b8SRandall Stewart send_forward_tsn(stcb, asoc); 52070c0982b8SRandall Stewart } 5208830d754dSRandall Stewart } 5209830d754dSRandall Stewart } 5210830d754dSRandall Stewart if (lchk) { 5211830d754dSRandall Stewart /* Assure a timer is up */ 5212830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5213830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 5214830d754dSRandall Stewart } 5215830d754dSRandall Stewart } 5216b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 5217f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 5218f8829a4aSRandall Stewart a_rwnd, 5219f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 5220f8829a4aSRandall Stewart stcb->asoc.total_flight, 5221f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 522280fefe0aSRandall Stewart } 5223f8829a4aSRandall Stewart } 5224f8829a4aSRandall Stewart 5225f8829a4aSRandall Stewart void 5226f8829a4aSRandall Stewart sctp_update_acked(struct sctp_tcb *stcb, struct sctp_shutdown_chunk *cp, 5227f8829a4aSRandall Stewart struct sctp_nets *netp, int *abort_flag) 5228f8829a4aSRandall Stewart { 5229f8829a4aSRandall Stewart /* Copy cum-ack */ 5230f8829a4aSRandall Stewart uint32_t cum_ack, a_rwnd; 5231f8829a4aSRandall Stewart 5232f8829a4aSRandall Stewart cum_ack = ntohl(cp->cumulative_tsn_ack); 5233f8829a4aSRandall Stewart /* Arrange so a_rwnd does NOT change */ 5234f8829a4aSRandall Stewart a_rwnd = stcb->asoc.peers_rwnd + stcb->asoc.total_flight; 5235f8829a4aSRandall Stewart 5236f8829a4aSRandall Stewart /* Now call the express sack handling */ 5237f8829a4aSRandall Stewart sctp_express_handle_sack(stcb, cum_ack, a_rwnd, 0, abort_flag); 5238f8829a4aSRandall Stewart } 5239f8829a4aSRandall Stewart 5240f8829a4aSRandall Stewart static void 5241f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb, 5242f8829a4aSRandall Stewart struct sctp_stream_in *strmin) 5243f8829a4aSRandall Stewart { 5244f8829a4aSRandall Stewart struct sctp_queued_to_read *ctl, *nctl; 5245f8829a4aSRandall Stewart struct sctp_association *asoc; 524683128708SRandall Stewart uint16_t tt; 5247f8829a4aSRandall Stewart 5248f8829a4aSRandall Stewart asoc = &stcb->asoc; 5249f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered; 5250f8829a4aSRandall Stewart /* 5251f8829a4aSRandall Stewart * First deliver anything prior to and including the stream no that 5252f8829a4aSRandall Stewart * came in 5253f8829a4aSRandall Stewart */ 52544a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ctl, &strmin->inqueue, next, nctl) { 5255*20b07a4dSMichael Tuexen if (SCTP_SSN_GE(tt, ctl->sinfo_ssn)) { 5256f8829a4aSRandall Stewart /* this is deliverable now */ 5257f8829a4aSRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next); 5258f8829a4aSRandall Stewart /* subtract pending on streams */ 5259f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5260f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5261f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5262f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5263b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 5264f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5265f8829a4aSRandall Stewart ctl, 5266cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED); 5267f8829a4aSRandall Stewart } 5268f8829a4aSRandall Stewart } else { 5269f8829a4aSRandall Stewart /* no more delivery now. */ 5270f8829a4aSRandall Stewart break; 5271f8829a4aSRandall Stewart } 5272f8829a4aSRandall Stewart } 5273f8829a4aSRandall Stewart /* 5274f8829a4aSRandall Stewart * now we must deliver things in queue the normal way if any are 5275f8829a4aSRandall Stewart * now ready. 5276f8829a4aSRandall Stewart */ 5277f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 52784a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ctl, &strmin->inqueue, next, nctl) { 5279f8829a4aSRandall Stewart if (tt == ctl->sinfo_ssn) { 5280f8829a4aSRandall Stewart /* this is deliverable now */ 5281f8829a4aSRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next); 5282f8829a4aSRandall Stewart /* subtract pending on streams */ 5283f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5284f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5285f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5286f8829a4aSRandall Stewart strmin->last_sequence_delivered = ctl->sinfo_ssn; 5287f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5288b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 5289f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5290f8829a4aSRandall Stewart ctl, 5291cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED); 529277acdc25SRandall Stewart 5293f8829a4aSRandall Stewart } 5294f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 5295f8829a4aSRandall Stewart } else { 5296f8829a4aSRandall Stewart break; 5297f8829a4aSRandall Stewart } 5298f8829a4aSRandall Stewart } 5299f8829a4aSRandall Stewart } 5300f8829a4aSRandall Stewart 53018933fa13SRandall Stewart static void 53028933fa13SRandall Stewart sctp_flush_reassm_for_str_seq(struct sctp_tcb *stcb, 53038933fa13SRandall Stewart struct sctp_association *asoc, 53048933fa13SRandall Stewart uint16_t stream, uint16_t seq) 53058933fa13SRandall Stewart { 53064a9ef3f8SMichael Tuexen struct sctp_tmit_chunk *chk, *nchk; 53078933fa13SRandall Stewart 53088933fa13SRandall Stewart /* For each one on here see if we need to toss it */ 53098933fa13SRandall Stewart /* 53104a9ef3f8SMichael Tuexen * For now large messages held on the reasmqueue that are complete 53114a9ef3f8SMichael Tuexen * will be tossed too. We could in theory do more work to spin 53124a9ef3f8SMichael Tuexen * through and stop after dumping one msg aka seeing the start of a 53134a9ef3f8SMichael Tuexen * new msg at the head, and call the delivery function... to see if 53144a9ef3f8SMichael Tuexen * it can be delivered... But for now we just dump everything on the 53154a9ef3f8SMichael Tuexen * queue. 53168933fa13SRandall Stewart */ 53174a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) { 53188e71b694SMichael Tuexen /* 53194a9ef3f8SMichael Tuexen * Do not toss it if on a different stream or marked for 53204a9ef3f8SMichael Tuexen * unordered delivery in which case the stream sequence 53214a9ef3f8SMichael Tuexen * number has no meaning. 53228e71b694SMichael Tuexen */ 53238e71b694SMichael Tuexen if ((chk->rec.data.stream_number != stream) || 53248e71b694SMichael Tuexen ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == SCTP_DATA_UNORDERED)) { 53258933fa13SRandall Stewart continue; 53268933fa13SRandall Stewart } 53278933fa13SRandall Stewart if (chk->rec.data.stream_seq == seq) { 53288933fa13SRandall Stewart /* It needs to be tossed */ 53298933fa13SRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 5330*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(chk->rec.data.TSN_seq, asoc->tsn_last_delivered)) { 53314a9ef3f8SMichael Tuexen asoc->tsn_last_delivered = chk->rec.data.TSN_seq; 53324a9ef3f8SMichael Tuexen asoc->str_of_pdapi = chk->rec.data.stream_number; 53334a9ef3f8SMichael Tuexen asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 53344a9ef3f8SMichael Tuexen asoc->fragment_flags = chk->rec.data.rcv_flags; 53358933fa13SRandall Stewart } 53368933fa13SRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 53378933fa13SRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 53388933fa13SRandall Stewart 53398933fa13SRandall Stewart /* Clear up any stream problem */ 5340*20b07a4dSMichael Tuexen if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) != SCTP_DATA_UNORDERED && 5341*20b07a4dSMichael Tuexen SCTP_SSN_GT(chk->rec.data.stream_seq, asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered)) { 53428933fa13SRandall Stewart /* 53438933fa13SRandall Stewart * We must dump forward this streams 53444a9ef3f8SMichael Tuexen * sequence number if the chunk is not 53454a9ef3f8SMichael Tuexen * unordered that is being skipped. There is 53464a9ef3f8SMichael Tuexen * a chance that if the peer does not 53474a9ef3f8SMichael Tuexen * include the last fragment in its FWD-TSN 53484a9ef3f8SMichael Tuexen * we WILL have a problem here since you 53494a9ef3f8SMichael Tuexen * would have a partial chunk in queue that 53504a9ef3f8SMichael Tuexen * may not be deliverable. Also if a Partial 53514a9ef3f8SMichael Tuexen * delivery API as started the user may get 53524a9ef3f8SMichael Tuexen * a partial chunk. The next read returning 53534a9ef3f8SMichael Tuexen * a new chunk... really ugly but I see no 53544a9ef3f8SMichael Tuexen * way around it! Maybe a notify?? 53558933fa13SRandall Stewart */ 53564a9ef3f8SMichael Tuexen asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered = chk->rec.data.stream_seq; 53578933fa13SRandall Stewart } 53588933fa13SRandall Stewart if (chk->data) { 53598933fa13SRandall Stewart sctp_m_freem(chk->data); 53608933fa13SRandall Stewart chk->data = NULL; 53618933fa13SRandall Stewart } 53628933fa13SRandall Stewart sctp_free_a_chunk(stcb, chk); 5363*20b07a4dSMichael Tuexen } else if (SCTP_SSN_GT(chk->rec.data.stream_seq, seq)) { 53648933fa13SRandall Stewart /* 53654a9ef3f8SMichael Tuexen * If the stream_seq is > than the purging one, we 53664a9ef3f8SMichael Tuexen * are done 53678933fa13SRandall Stewart */ 53688933fa13SRandall Stewart break; 53698933fa13SRandall Stewart } 53708933fa13SRandall Stewart } 53718933fa13SRandall Stewart } 53728933fa13SRandall Stewart 53738933fa13SRandall Stewart 5374f8829a4aSRandall Stewart void 5375f8829a4aSRandall Stewart sctp_handle_forward_tsn(struct sctp_tcb *stcb, 5376b5c16493SMichael Tuexen struct sctp_forward_tsn_chunk *fwd, 5377b5c16493SMichael Tuexen int *abort_flag, struct mbuf *m, int offset) 5378f8829a4aSRandall Stewart { 5379f8829a4aSRandall Stewart /* 5380f8829a4aSRandall Stewart * ISSUES that MUST be fixed for ECN! When we are the sender of the 5381f8829a4aSRandall Stewart * forward TSN, when the SACK comes back that acknowledges the 5382f8829a4aSRandall Stewart * FWD-TSN we must reset the NONCE sum to match correctly. This will 5383f8829a4aSRandall Stewart * get quite tricky since we may have sent more data interveneing 5384f8829a4aSRandall Stewart * and must carefully account for what the SACK says on the nonce 5385f8829a4aSRandall Stewart * and any gaps that are reported. This work will NOT be done here, 5386f8829a4aSRandall Stewart * but I note it here since it is really related to PR-SCTP and 5387f8829a4aSRandall Stewart * FWD-TSN's 5388f8829a4aSRandall Stewart */ 5389f8829a4aSRandall Stewart 5390f8829a4aSRandall Stewart /* The pr-sctp fwd tsn */ 5391f8829a4aSRandall Stewart /* 5392f8829a4aSRandall Stewart * here we will perform all the data receiver side steps for 5393f8829a4aSRandall Stewart * processing FwdTSN, as required in by pr-sctp draft: 5394f8829a4aSRandall Stewart * 5395f8829a4aSRandall Stewart * Assume we get FwdTSN(x): 5396f8829a4aSRandall Stewart * 5397f8829a4aSRandall Stewart * 1) update local cumTSN to x 2) try to further advance cumTSN to x + 5398f8829a4aSRandall Stewart * others we have 3) examine and update re-ordering queue on 5399f8829a4aSRandall Stewart * pr-in-streams 4) clean up re-assembly queue 5) Send a sack to 5400f8829a4aSRandall Stewart * report where we are. 5401f8829a4aSRandall Stewart */ 5402f8829a4aSRandall Stewart struct sctp_association *asoc; 54037898f408SRandall Stewart uint32_t new_cum_tsn, gap; 54047898f408SRandall Stewart unsigned int i, fwd_sz, cumack_set_flag, m_size; 54058933fa13SRandall Stewart uint32_t str_seq; 5406f8829a4aSRandall Stewart struct sctp_stream_in *strm; 54074a9ef3f8SMichael Tuexen struct sctp_tmit_chunk *chk, *nchk; 54088933fa13SRandall Stewart struct sctp_queued_to_read *ctl, *sv; 5409f8829a4aSRandall Stewart 5410f8829a4aSRandall Stewart cumack_set_flag = 0; 5411f8829a4aSRandall Stewart asoc = &stcb->asoc; 5412f8829a4aSRandall Stewart if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) { 5413ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, 5414ad81507eSRandall Stewart "Bad size too small/big fwd-tsn\n"); 5415f8829a4aSRandall Stewart return; 5416f8829a4aSRandall Stewart } 5417f8829a4aSRandall Stewart m_size = (stcb->asoc.mapping_array_size << 3); 5418f8829a4aSRandall Stewart /*************************************************************/ 5419f8829a4aSRandall Stewart /* 1. Here we update local cumTSN and shift the bitmap array */ 5420f8829a4aSRandall Stewart /*************************************************************/ 5421f8829a4aSRandall Stewart new_cum_tsn = ntohl(fwd->new_cumulative_tsn); 5422f8829a4aSRandall Stewart 5423*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->cumulative_tsn, new_cum_tsn)) { 5424f8829a4aSRandall Stewart /* Already got there ... */ 5425f8829a4aSRandall Stewart return; 5426f8829a4aSRandall Stewart } 5427f8829a4aSRandall Stewart /* 5428f8829a4aSRandall Stewart * now we know the new TSN is more advanced, let's find the actual 5429f8829a4aSRandall Stewart * gap 5430f8829a4aSRandall Stewart */ 5431b5c16493SMichael Tuexen SCTP_CALC_TSN_TO_GAP(gap, new_cum_tsn, asoc->mapping_array_base_tsn); 543277acdc25SRandall Stewart asoc->cumulative_tsn = new_cum_tsn; 54332afb3e84SRandall Stewart if (gap >= m_size) { 5434f8829a4aSRandall Stewart if ((long)gap > sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv)) { 543517205eccSRandall Stewart struct mbuf *oper; 543617205eccSRandall Stewart 5437f8829a4aSRandall Stewart /* 5438f8829a4aSRandall Stewart * out of range (of single byte chunks in the rwnd I 543917205eccSRandall Stewart * give out). This must be an attacker. 5440f8829a4aSRandall Stewart */ 544117205eccSRandall Stewart *abort_flag = 1; 544217205eccSRandall Stewart oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)), 544317205eccSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 544417205eccSRandall Stewart if (oper) { 544517205eccSRandall Stewart struct sctp_paramhdr *ph; 544617205eccSRandall Stewart uint32_t *ippp; 544717205eccSRandall Stewart 544817205eccSRandall Stewart SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + 544917205eccSRandall Stewart (sizeof(uint32_t) * 3); 545017205eccSRandall Stewart ph = mtod(oper, struct sctp_paramhdr *); 545117205eccSRandall Stewart ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); 545217205eccSRandall Stewart ph->param_length = htons(SCTP_BUF_LEN(oper)); 545317205eccSRandall Stewart ippp = (uint32_t *) (ph + 1); 545417205eccSRandall Stewart *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_33); 545517205eccSRandall Stewart ippp++; 545617205eccSRandall Stewart *ippp = asoc->highest_tsn_inside_map; 545717205eccSRandall Stewart ippp++; 545817205eccSRandall Stewart *ippp = new_cum_tsn; 545917205eccSRandall Stewart } 546017205eccSRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_33; 546117205eccSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 5462ceaad40aSRandall Stewart SCTP_PEER_FAULTY, oper, SCTP_SO_NOT_LOCKED); 5463f8829a4aSRandall Stewart return; 5464f8829a4aSRandall Stewart } 5465207304d4SRandall Stewart SCTP_STAT_INCR(sctps_fwdtsn_map_over); 546677acdc25SRandall Stewart 54672afb3e84SRandall Stewart memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size); 54682afb3e84SRandall Stewart asoc->mapping_array_base_tsn = new_cum_tsn + 1; 546977acdc25SRandall Stewart asoc->highest_tsn_inside_map = new_cum_tsn; 547077acdc25SRandall Stewart 5471b5c16493SMichael Tuexen memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.mapping_array_size); 5472830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = new_cum_tsn; 547377acdc25SRandall Stewart 5474b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 5475f8829a4aSRandall Stewart sctp_log_map(0, 3, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 547680fefe0aSRandall Stewart } 5477f8829a4aSRandall Stewart asoc->last_echo_tsn = asoc->highest_tsn_inside_map; 54782afb3e84SRandall Stewart } else { 54792afb3e84SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 54802afb3e84SRandall Stewart for (i = 0; i <= gap; i++) { 54817898f408SRandall Stewart if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, i) && 54827898f408SRandall Stewart !SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, i)) { 54838933fa13SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, i); 5484*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->mapping_array_base_tsn + i, asoc->highest_tsn_inside_nr_map)) { 54857898f408SRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->mapping_array_base_tsn + i; 5486b5c16493SMichael Tuexen } 5487b5c16493SMichael Tuexen } 5488b5c16493SMichael Tuexen } 5489f8829a4aSRandall Stewart } 5490f8829a4aSRandall Stewart /*************************************************************/ 5491f8829a4aSRandall Stewart /* 2. Clear up re-assembly queue */ 5492f8829a4aSRandall Stewart /*************************************************************/ 5493f8829a4aSRandall Stewart /* 5494f8829a4aSRandall Stewart * First service it if pd-api is up, just in case we can progress it 5495f8829a4aSRandall Stewart * forward 5496f8829a4aSRandall Stewart */ 5497f8829a4aSRandall Stewart if (asoc->fragmented_delivery_inprogress) { 5498f8829a4aSRandall Stewart sctp_service_reassembly(stcb, asoc); 5499f8829a4aSRandall Stewart } 5500f8829a4aSRandall Stewart /* For each one on here see if we need to toss it */ 5501f8829a4aSRandall Stewart /* 55024a9ef3f8SMichael Tuexen * For now large messages held on the reasmqueue that are complete 55034a9ef3f8SMichael Tuexen * will be tossed too. We could in theory do more work to spin 55044a9ef3f8SMichael Tuexen * through and stop after dumping one msg aka seeing the start of a 55054a9ef3f8SMichael Tuexen * new msg at the head, and call the delivery function... to see if 55064a9ef3f8SMichael Tuexen * it can be delivered... But for now we just dump everything on the 55074a9ef3f8SMichael Tuexen * queue. 5508f8829a4aSRandall Stewart */ 55094a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) { 5510*20b07a4dSMichael Tuexen if (SCTP_TSN_GE(new_cum_tsn, chk->rec.data.TSN_seq)) { 5511f8829a4aSRandall Stewart /* It needs to be tossed */ 5512f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next); 5513*20b07a4dSMichael Tuexen if (SCTP_TSN_GT(chk->rec.data.TSN_seq, asoc->tsn_last_delivered)) { 55144a9ef3f8SMichael Tuexen asoc->tsn_last_delivered = chk->rec.data.TSN_seq; 55154a9ef3f8SMichael Tuexen asoc->str_of_pdapi = chk->rec.data.stream_number; 55164a9ef3f8SMichael Tuexen asoc->ssn_of_pdapi = chk->rec.data.stream_seq; 55174a9ef3f8SMichael Tuexen asoc->fragment_flags = chk->rec.data.rcv_flags; 5518f8829a4aSRandall Stewart } 5519f8829a4aSRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 5520f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 5521f8829a4aSRandall Stewart 5522f8829a4aSRandall Stewart /* Clear up any stream problem */ 5523*20b07a4dSMichael Tuexen if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) != SCTP_DATA_UNORDERED && 5524*20b07a4dSMichael Tuexen SCTP_SSN_GT(chk->rec.data.stream_seq, asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered)) { 5525f8829a4aSRandall Stewart /* 5526f8829a4aSRandall Stewart * We must dump forward this streams 55274a9ef3f8SMichael Tuexen * sequence number if the chunk is not 55284a9ef3f8SMichael Tuexen * unordered that is being skipped. There is 55294a9ef3f8SMichael Tuexen * a chance that if the peer does not 55304a9ef3f8SMichael Tuexen * include the last fragment in its FWD-TSN 55314a9ef3f8SMichael Tuexen * we WILL have a problem here since you 55324a9ef3f8SMichael Tuexen * would have a partial chunk in queue that 55334a9ef3f8SMichael Tuexen * may not be deliverable. Also if a Partial 55344a9ef3f8SMichael Tuexen * delivery API as started the user may get 55354a9ef3f8SMichael Tuexen * a partial chunk. The next read returning 55364a9ef3f8SMichael Tuexen * a new chunk... really ugly but I see no 55374a9ef3f8SMichael Tuexen * way around it! Maybe a notify?? 5538f8829a4aSRandall Stewart */ 55394a9ef3f8SMichael Tuexen asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered = chk->rec.data.stream_seq; 5540f8829a4aSRandall Stewart } 5541f8829a4aSRandall Stewart if (chk->data) { 5542f8829a4aSRandall Stewart sctp_m_freem(chk->data); 5543f8829a4aSRandall Stewart chk->data = NULL; 5544f8829a4aSRandall Stewart } 5545f8829a4aSRandall Stewart sctp_free_a_chunk(stcb, chk); 5546f8829a4aSRandall Stewart } else { 5547f8829a4aSRandall Stewart /* 55484a9ef3f8SMichael Tuexen * Ok we have gone beyond the end of the fwd-tsn's 55494a9ef3f8SMichael Tuexen * mark. 5550f8829a4aSRandall Stewart */ 5551f8829a4aSRandall Stewart break; 5552f8829a4aSRandall Stewart } 5553f8829a4aSRandall Stewart } 55548933fa13SRandall Stewart /*******************************************************/ 55558933fa13SRandall Stewart /* 3. Update the PR-stream re-ordering queues and fix */ 55568933fa13SRandall Stewart /* delivery issues as needed. */ 55578933fa13SRandall Stewart /*******************************************************/ 5558f8829a4aSRandall Stewart fwd_sz -= sizeof(*fwd); 5559671d309cSRandall Stewart if (m && fwd_sz) { 5560f8829a4aSRandall Stewart /* New method. */ 5561d61a0ae0SRandall Stewart unsigned int num_str; 5562671d309cSRandall Stewart struct sctp_strseq *stseq, strseqbuf; 5563671d309cSRandall Stewart 5564671d309cSRandall Stewart offset += sizeof(*fwd); 5565f8829a4aSRandall Stewart 55668933fa13SRandall Stewart SCTP_INP_READ_LOCK(stcb->sctp_ep); 5567f8829a4aSRandall Stewart num_str = fwd_sz / sizeof(struct sctp_strseq); 5568f8829a4aSRandall Stewart for (i = 0; i < num_str; i++) { 5569f8829a4aSRandall Stewart uint16_t st; 5570f8829a4aSRandall Stewart 5571671d309cSRandall Stewart stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset, 5572671d309cSRandall Stewart sizeof(struct sctp_strseq), 5573671d309cSRandall Stewart (uint8_t *) & strseqbuf); 5574671d309cSRandall Stewart offset += sizeof(struct sctp_strseq); 55752afb3e84SRandall Stewart if (stseq == NULL) { 5576671d309cSRandall Stewart break; 55772afb3e84SRandall Stewart } 5578f8829a4aSRandall Stewart /* Convert */ 5579851b7298SRandall Stewart st = ntohs(stseq->stream); 5580851b7298SRandall Stewart stseq->stream = st; 5581851b7298SRandall Stewart st = ntohs(stseq->sequence); 5582851b7298SRandall Stewart stseq->sequence = st; 55838933fa13SRandall Stewart 5584f8829a4aSRandall Stewart /* now process */ 55858933fa13SRandall Stewart 55868933fa13SRandall Stewart /* 55878933fa13SRandall Stewart * Ok we now look for the stream/seq on the read 55888933fa13SRandall Stewart * queue where its not all delivered. If we find it 55898933fa13SRandall Stewart * we transmute the read entry into a PDI_ABORTED. 55908933fa13SRandall Stewart */ 5591851b7298SRandall Stewart if (stseq->stream >= asoc->streamincnt) { 55922afb3e84SRandall Stewart /* screwed up streams, stop! */ 55932afb3e84SRandall Stewart break; 5594f8829a4aSRandall Stewart } 55958933fa13SRandall Stewart if ((asoc->str_of_pdapi == stseq->stream) && 55968933fa13SRandall Stewart (asoc->ssn_of_pdapi == stseq->sequence)) { 55978933fa13SRandall Stewart /* 55988933fa13SRandall Stewart * If this is the one we were partially 55998933fa13SRandall Stewart * delivering now then we no longer are. 56008933fa13SRandall Stewart * Note this will change with the reassembly 56018933fa13SRandall Stewart * re-write. 56028933fa13SRandall Stewart */ 56038933fa13SRandall Stewart asoc->fragmented_delivery_inprogress = 0; 56048933fa13SRandall Stewart } 56058933fa13SRandall Stewart sctp_flush_reassm_for_str_seq(stcb, asoc, stseq->stream, stseq->sequence); 56068933fa13SRandall Stewart TAILQ_FOREACH(ctl, &stcb->sctp_ep->read_queue, next) { 56078933fa13SRandall Stewart if ((ctl->sinfo_stream == stseq->stream) && 56088933fa13SRandall Stewart (ctl->sinfo_ssn == stseq->sequence)) { 56098933fa13SRandall Stewart str_seq = (stseq->stream << 16) | stseq->sequence; 56108933fa13SRandall Stewart ctl->end_added = 1; 56118933fa13SRandall Stewart ctl->pdapi_aborted = 1; 56128933fa13SRandall Stewart sv = stcb->asoc.control_pdapi; 56138933fa13SRandall Stewart stcb->asoc.control_pdapi = ctl; 5614810ec536SMichael Tuexen sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION, 5615810ec536SMichael Tuexen stcb, 56168933fa13SRandall Stewart SCTP_PARTIAL_DELIVERY_ABORTED, 5617810ec536SMichael Tuexen (void *)&str_seq, 5618810ec536SMichael Tuexen SCTP_SO_NOT_LOCKED); 56198933fa13SRandall Stewart stcb->asoc.control_pdapi = sv; 56208933fa13SRandall Stewart break; 56218933fa13SRandall Stewart } else if ((ctl->sinfo_stream == stseq->stream) && 5622*20b07a4dSMichael Tuexen SCTP_SSN_GT(ctl->sinfo_ssn, stseq->sequence)) { 56238933fa13SRandall Stewart /* We are past our victim SSN */ 56248933fa13SRandall Stewart break; 56258933fa13SRandall Stewart } 56268933fa13SRandall Stewart } 5627851b7298SRandall Stewart strm = &asoc->strmin[stseq->stream]; 5628*20b07a4dSMichael Tuexen if (SCTP_SSN_GT(stseq->sequence, strm->last_sequence_delivered)) { 5629f8829a4aSRandall Stewart /* Update the sequence number */ 5630*20b07a4dSMichael Tuexen strm->last_sequence_delivered = stseq->sequence; 5631f8829a4aSRandall Stewart } 5632f8829a4aSRandall Stewart /* now kick the stream the new way */ 563304ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 5634f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(stcb, strm); 5635f8829a4aSRandall Stewart } 56368933fa13SRandall Stewart SCTP_INP_READ_UNLOCK(stcb->sctp_ep); 5637f8829a4aSRandall Stewart } 56387898f408SRandall Stewart /* 56397898f408SRandall Stewart * Now slide thing forward. 56407898f408SRandall Stewart */ 56417898f408SRandall Stewart sctp_slide_mapping_arrays(stcb); 56427898f408SRandall Stewart 564324f52bbdSMichael Tuexen if (!TAILQ_EMPTY(&asoc->reasmqueue)) { 5644139bc87fSRandall Stewart /* now lets kick out and check for more fragmented delivery */ 564504ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 5646139bc87fSRandall Stewart sctp_deliver_reasm_check(stcb, &stcb->asoc); 5647139bc87fSRandall Stewart } 5648f8829a4aSRandall Stewart } 5649