1f8829a4aSRandall Stewart /*- 2b1006367SRandall Stewart * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 3807aad63SMichael Tuexen * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. 4807aad63SMichael Tuexen * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. 5f8829a4aSRandall Stewart * 6f8829a4aSRandall Stewart * Redistribution and use in source and binary forms, with or without 7f8829a4aSRandall Stewart * modification, are permitted provided that the following conditions are met: 8f8829a4aSRandall Stewart * 9f8829a4aSRandall Stewart * a) Redistributions of source code must retain the above copyright notice, 10f8829a4aSRandall Stewart * this list of conditions and the following disclaimer. 11f8829a4aSRandall Stewart * 12f8829a4aSRandall Stewart * b) Redistributions in binary form must reproduce the above copyright 13f8829a4aSRandall Stewart * notice, this list of conditions and the following disclaimer in 14f8829a4aSRandall Stewart * the documentation and/or other materials provided with the distribution. 15f8829a4aSRandall Stewart * 16f8829a4aSRandall Stewart * c) Neither the name of Cisco Systems, Inc. nor the names of its 17f8829a4aSRandall Stewart * contributors may be used to endorse or promote products derived 18f8829a4aSRandall Stewart * from this software without specific prior written permission. 19f8829a4aSRandall Stewart * 20f8829a4aSRandall Stewart * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21f8829a4aSRandall Stewart * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22f8829a4aSRandall Stewart * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23f8829a4aSRandall Stewart * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24f8829a4aSRandall Stewart * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25f8829a4aSRandall Stewart * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26f8829a4aSRandall Stewart * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27f8829a4aSRandall Stewart * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28f8829a4aSRandall Stewart * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29f8829a4aSRandall Stewart * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30f8829a4aSRandall Stewart * THE POSSIBILITY OF SUCH DAMAGE. 31f8829a4aSRandall Stewart */ 32f8829a4aSRandall Stewart 33f8829a4aSRandall Stewart #include <sys/cdefs.h> 34f8829a4aSRandall Stewart __FBSDID("$FreeBSD$"); 35f8829a4aSRandall Stewart 36f8829a4aSRandall Stewart #include <netinet/sctp_os.h> 3744249214SRandall Stewart #include <sys/proc.h> 38f8829a4aSRandall Stewart #include <netinet/sctp_var.h> 3942551e99SRandall Stewart #include <netinet/sctp_sysctl.h> 40f8829a4aSRandall Stewart #include <netinet/sctp_header.h> 4144249214SRandall Stewart #include <netinet/sctp_pcb.h> 42f8829a4aSRandall Stewart #include <netinet/sctputil.h> 43f8829a4aSRandall Stewart #include <netinet/sctp_output.h> 44f8829a4aSRandall Stewart #include <netinet/sctp_uio.h> 4544249214SRandall Stewart #include <netinet/sctp_auth.h> 46f8829a4aSRandall Stewart #include <netinet/sctp_timer.h> 4744249214SRandall Stewart #include <netinet/sctp_asconf.h> 4844249214SRandall Stewart #include <netinet/sctp_indata.h> 4944249214SRandall Stewart #include <netinet/sctp_bsd_addr.h> 5044249214SRandall Stewart #include <netinet/sctp_input.h> 5144249214SRandall Stewart #include <netinet/sctp_crc32.h> 5244249214SRandall Stewart #include <netinet/sctp_lock_bsd.h> 53f8829a4aSRandall Stewart /* 54f8829a4aSRandall Stewart * NOTES: On the outbound side of things I need to check the sack timer to 55f8829a4aSRandall Stewart * see if I should generate a sack into the chunk queue (if I have data to 56f8829a4aSRandall Stewart * send that is and will be sending it .. for bundling. 57f8829a4aSRandall Stewart * 58f8829a4aSRandall Stewart * The callback in sctp_usrreq.c will get called when the socket is read from. 59f8829a4aSRandall Stewart * This will cause sctp_service_queues() to get called on the top entry in 60f8829a4aSRandall Stewart * the list. 61f8829a4aSRandall Stewart */ 6244249214SRandall Stewart static void 6344249214SRandall Stewart sctp_add_chk_to_control(struct sctp_queued_to_read *control, 6444249214SRandall Stewart struct sctp_stream_in *strm, 6544249214SRandall Stewart struct sctp_tcb *stcb, 6644249214SRandall Stewart struct sctp_association *asoc, 67d1ea5fa9SMichael Tuexen struct sctp_tmit_chunk *chk, int lock_held); 6844249214SRandall Stewart 69f8829a4aSRandall Stewart 7072fb6fdbSRandall Stewart void 71f8829a4aSRandall Stewart sctp_set_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc) 72f8829a4aSRandall Stewart { 73b3f1ea41SRandall Stewart asoc->my_rwnd = sctp_calc_rwnd(stcb, asoc); 74f8829a4aSRandall Stewart } 75f8829a4aSRandall Stewart 76f8829a4aSRandall Stewart /* Calculate what the rwnd would be */ 7772fb6fdbSRandall Stewart uint32_t 78f8829a4aSRandall Stewart sctp_calc_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc) 79f8829a4aSRandall Stewart { 80b3f1ea41SRandall Stewart uint32_t calc = 0; 81f8829a4aSRandall Stewart 82f8829a4aSRandall Stewart /* 83f8829a4aSRandall Stewart * This is really set wrong with respect to a 1-2-m socket. Since 844e88d37aSMichael Tuexen * the sb_cc is the count that everyone as put up. When we re-write 85f8829a4aSRandall Stewart * sctp_soreceive then we will fix this so that ONLY this 86f8829a4aSRandall Stewart * associations data is taken into account. 87f8829a4aSRandall Stewart */ 8844249214SRandall Stewart if (stcb->sctp_socket == NULL) { 89f8829a4aSRandall Stewart return (calc); 9044249214SRandall Stewart } 914e88d37aSMichael Tuexen if (stcb->asoc.sb_cc == 0 && 92f8829a4aSRandall Stewart asoc->size_on_reasm_queue == 0 && 93f8829a4aSRandall Stewart asoc->size_on_all_streams == 0) { 94f8829a4aSRandall Stewart /* Full rwnd granted */ 95b3f1ea41SRandall Stewart calc = max(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), SCTP_MINIMAL_RWND); 96f8829a4aSRandall Stewart return (calc); 97f8829a4aSRandall Stewart } 98f8829a4aSRandall Stewart /* get actual space */ 99f8829a4aSRandall Stewart calc = (uint32_t) sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv); 100f8829a4aSRandall Stewart /* 101f8829a4aSRandall Stewart * take out what has NOT been put on socket queue and we yet hold 102f8829a4aSRandall Stewart * for putting up. 103f8829a4aSRandall Stewart */ 10444fbe462SRandall Stewart calc = sctp_sbspace_sub(calc, (uint32_t) (asoc->size_on_reasm_queue + 10544fbe462SRandall Stewart asoc->cnt_on_reasm_queue * MSIZE)); 10644fbe462SRandall Stewart calc = sctp_sbspace_sub(calc, (uint32_t) (asoc->size_on_all_streams + 10744fbe462SRandall Stewart asoc->cnt_on_all_streams * MSIZE)); 108f8829a4aSRandall Stewart if (calc == 0) { 109f8829a4aSRandall Stewart /* out of space */ 110f8829a4aSRandall Stewart return (calc); 111f8829a4aSRandall Stewart } 112f8829a4aSRandall Stewart /* what is the overhead of all these rwnd's */ 1132afb3e84SRandall Stewart calc = sctp_sbspace_sub(calc, stcb->asoc.my_rwnd_control_len); 114b3f1ea41SRandall Stewart /* 115b3f1ea41SRandall Stewart * If the window gets too small due to ctrl-stuff, reduce it to 1, 116b3f1ea41SRandall Stewart * even it is 0. SWS engaged 117f8829a4aSRandall Stewart */ 118b3f1ea41SRandall Stewart if (calc < stcb->asoc.my_rwnd_control_len) { 119b3f1ea41SRandall Stewart calc = 1; 1202afb3e84SRandall Stewart } 121b3f1ea41SRandall Stewart return (calc); 122f8829a4aSRandall Stewart } 123f8829a4aSRandall Stewart 124f8829a4aSRandall Stewart 125f8829a4aSRandall Stewart 126f8829a4aSRandall Stewart /* 127f8829a4aSRandall Stewart * Build out our readq entry based on the incoming packet. 128f8829a4aSRandall Stewart */ 129f8829a4aSRandall Stewart struct sctp_queued_to_read * 130f8829a4aSRandall Stewart sctp_build_readq_entry(struct sctp_tcb *stcb, 131f8829a4aSRandall Stewart struct sctp_nets *net, 132f8829a4aSRandall Stewart uint32_t tsn, uint32_t ppid, 133f8829a4aSRandall Stewart uint32_t context, uint16_t stream_no, 13444249214SRandall Stewart uint32_t stream_seq, uint8_t flags, 135f8829a4aSRandall Stewart struct mbuf *dm) 136f8829a4aSRandall Stewart { 137f8829a4aSRandall Stewart struct sctp_queued_to_read *read_queue_e = NULL; 138f8829a4aSRandall Stewart 139f8829a4aSRandall Stewart sctp_alloc_a_readq(stcb, read_queue_e); 140f8829a4aSRandall Stewart if (read_queue_e == NULL) { 141f8829a4aSRandall Stewart goto failed_build; 142f8829a4aSRandall Stewart } 14344249214SRandall Stewart memset(read_queue_e, 0, sizeof(struct sctp_queued_to_read)); 144f8829a4aSRandall Stewart read_queue_e->sinfo_stream = stream_no; 145f8829a4aSRandall Stewart read_queue_e->sinfo_ssn = stream_seq; 146f8829a4aSRandall Stewart read_queue_e->sinfo_flags = (flags << 8); 147f8829a4aSRandall Stewart read_queue_e->sinfo_ppid = ppid; 1487215cc1bSMichael Tuexen read_queue_e->sinfo_context = context; 149f8829a4aSRandall Stewart read_queue_e->sinfo_tsn = tsn; 150f8829a4aSRandall Stewart read_queue_e->sinfo_cumtsn = tsn; 151f8829a4aSRandall Stewart read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb); 15244249214SRandall Stewart read_queue_e->top_fsn = read_queue_e->fsn_included = 0xffffffff; 15344249214SRandall Stewart TAILQ_INIT(&read_queue_e->reasm); 154f8829a4aSRandall Stewart read_queue_e->whoFrom = net; 155f8829a4aSRandall Stewart atomic_add_int(&net->ref_count, 1); 156f8829a4aSRandall Stewart read_queue_e->data = dm; 157f8829a4aSRandall Stewart read_queue_e->stcb = stcb; 158f8829a4aSRandall Stewart read_queue_e->port_from = stcb->rport; 159f8829a4aSRandall Stewart failed_build: 160f8829a4aSRandall Stewart return (read_queue_e); 161f8829a4aSRandall Stewart } 162f8829a4aSRandall Stewart 163f8829a4aSRandall Stewart struct mbuf * 164e2e7c62eSMichael Tuexen sctp_build_ctl_nchunk(struct sctp_inpcb *inp, struct sctp_sndrcvinfo *sinfo) 165f8829a4aSRandall Stewart { 166e2e7c62eSMichael Tuexen struct sctp_extrcvinfo *seinfo; 167f8829a4aSRandall Stewart struct sctp_sndrcvinfo *outinfo; 168e2e7c62eSMichael Tuexen struct sctp_rcvinfo *rcvinfo; 169e2e7c62eSMichael Tuexen struct sctp_nxtinfo *nxtinfo; 170f8829a4aSRandall Stewart struct cmsghdr *cmh; 171f8829a4aSRandall Stewart struct mbuf *ret; 172f8829a4aSRandall Stewart int len; 173e2e7c62eSMichael Tuexen int use_extended; 174e2e7c62eSMichael Tuexen int provide_nxt; 175f8829a4aSRandall Stewart 176e2e7c62eSMichael Tuexen if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT) && 177e2e7c62eSMichael Tuexen sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO) && 178e2e7c62eSMichael Tuexen sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO)) { 179e2e7c62eSMichael Tuexen /* user does not want any ancillary data */ 180f8829a4aSRandall Stewart return (NULL); 181f8829a4aSRandall Stewart } 182e2e7c62eSMichael Tuexen len = 0; 183e2e7c62eSMichael Tuexen if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO)) { 184e2e7c62eSMichael Tuexen len += CMSG_SPACE(sizeof(struct sctp_rcvinfo)); 185e2e7c62eSMichael Tuexen } 186e2e7c62eSMichael Tuexen seinfo = (struct sctp_extrcvinfo *)sinfo; 187e2e7c62eSMichael Tuexen if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO) && 188b70b526dSMichael Tuexen (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_AVAIL)) { 189e2e7c62eSMichael Tuexen provide_nxt = 1; 1900bfc52beSMichael Tuexen len += CMSG_SPACE(sizeof(struct sctp_nxtinfo)); 191e2e7c62eSMichael Tuexen } else { 192e2e7c62eSMichael Tuexen provide_nxt = 0; 193e2e7c62eSMichael Tuexen } 194e2e7c62eSMichael Tuexen if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) { 195f8829a4aSRandall Stewart if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) { 196f8829a4aSRandall Stewart use_extended = 1; 197e2e7c62eSMichael Tuexen len += CMSG_SPACE(sizeof(struct sctp_extrcvinfo)); 198f8829a4aSRandall Stewart } else { 199e2e7c62eSMichael Tuexen use_extended = 0; 200e2e7c62eSMichael Tuexen len += CMSG_SPACE(sizeof(struct sctp_sndrcvinfo)); 201e2e7c62eSMichael Tuexen } 202e2e7c62eSMichael Tuexen } else { 203e2e7c62eSMichael Tuexen use_extended = 0; 204f8829a4aSRandall Stewart } 205f8829a4aSRandall Stewart 206eb1b1807SGleb Smirnoff ret = sctp_get_mbuf_for_msg(len, 0, M_NOWAIT, 1, MT_DATA); 207f8829a4aSRandall Stewart if (ret == NULL) { 208f8829a4aSRandall Stewart /* No space */ 209f8829a4aSRandall Stewart return (ret); 210f8829a4aSRandall Stewart } 211e2e7c62eSMichael Tuexen SCTP_BUF_LEN(ret) = 0; 212e2e7c62eSMichael Tuexen 213f8829a4aSRandall Stewart /* We need a CMSG header followed by the struct */ 214f8829a4aSRandall Stewart cmh = mtod(ret, struct cmsghdr *); 215e432298aSXin LI /* 216e432298aSXin LI * Make sure that there is no un-initialized padding between the 217e432298aSXin LI * cmsg header and cmsg data and after the cmsg data. 218e432298aSXin LI */ 219e432298aSXin LI memset(cmh, 0, len); 220e2e7c62eSMichael Tuexen if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO)) { 221f8829a4aSRandall Stewart cmh->cmsg_level = IPPROTO_SCTP; 222e2e7c62eSMichael Tuexen cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_rcvinfo)); 223e2e7c62eSMichael Tuexen cmh->cmsg_type = SCTP_RCVINFO; 224e2e7c62eSMichael Tuexen rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmh); 225e2e7c62eSMichael Tuexen rcvinfo->rcv_sid = sinfo->sinfo_stream; 226e2e7c62eSMichael Tuexen rcvinfo->rcv_ssn = sinfo->sinfo_ssn; 227e2e7c62eSMichael Tuexen rcvinfo->rcv_flags = sinfo->sinfo_flags; 228e2e7c62eSMichael Tuexen rcvinfo->rcv_ppid = sinfo->sinfo_ppid; 229e2e7c62eSMichael Tuexen rcvinfo->rcv_tsn = sinfo->sinfo_tsn; 230e2e7c62eSMichael Tuexen rcvinfo->rcv_cumtsn = sinfo->sinfo_cumtsn; 231e2e7c62eSMichael Tuexen rcvinfo->rcv_context = sinfo->sinfo_context; 232e2e7c62eSMichael Tuexen rcvinfo->rcv_assoc_id = sinfo->sinfo_assoc_id; 233e2e7c62eSMichael Tuexen cmh = (struct cmsghdr *)((caddr_t)cmh + CMSG_SPACE(sizeof(struct sctp_rcvinfo))); 234e2e7c62eSMichael Tuexen SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_rcvinfo)); 235f8829a4aSRandall Stewart } 236e2e7c62eSMichael Tuexen if (provide_nxt) { 237e2e7c62eSMichael Tuexen cmh->cmsg_level = IPPROTO_SCTP; 238e2e7c62eSMichael Tuexen cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_nxtinfo)); 239e2e7c62eSMichael Tuexen cmh->cmsg_type = SCTP_NXTINFO; 240e2e7c62eSMichael Tuexen nxtinfo = (struct sctp_nxtinfo *)CMSG_DATA(cmh); 241b70b526dSMichael Tuexen nxtinfo->nxt_sid = seinfo->serinfo_next_stream; 242e2e7c62eSMichael Tuexen nxtinfo->nxt_flags = 0; 243b70b526dSMichael Tuexen if (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_IS_UNORDERED) { 244e2e7c62eSMichael Tuexen nxtinfo->nxt_flags |= SCTP_UNORDERED; 245e2e7c62eSMichael Tuexen } 246b70b526dSMichael Tuexen if (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_IS_NOTIFICATION) { 247e2e7c62eSMichael Tuexen nxtinfo->nxt_flags |= SCTP_NOTIFICATION; 248e2e7c62eSMichael Tuexen } 249b70b526dSMichael Tuexen if (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_ISCOMPLETE) { 250e2e7c62eSMichael Tuexen nxtinfo->nxt_flags |= SCTP_COMPLETE; 251e2e7c62eSMichael Tuexen } 252b70b526dSMichael Tuexen nxtinfo->nxt_ppid = seinfo->serinfo_next_ppid; 253b70b526dSMichael Tuexen nxtinfo->nxt_length = seinfo->serinfo_next_length; 254b70b526dSMichael Tuexen nxtinfo->nxt_assoc_id = seinfo->serinfo_next_aid; 255e2e7c62eSMichael Tuexen cmh = (struct cmsghdr *)((caddr_t)cmh + CMSG_SPACE(sizeof(struct sctp_nxtinfo))); 256e2e7c62eSMichael Tuexen SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_nxtinfo)); 257e2e7c62eSMichael Tuexen } 258e2e7c62eSMichael Tuexen if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) { 259e2e7c62eSMichael Tuexen cmh->cmsg_level = IPPROTO_SCTP; 260e2e7c62eSMichael Tuexen outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh); 261e2e7c62eSMichael Tuexen if (use_extended) { 262e2e7c62eSMichael Tuexen cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_extrcvinfo)); 263e2e7c62eSMichael Tuexen cmh->cmsg_type = SCTP_EXTRCV; 264e2e7c62eSMichael Tuexen memcpy(outinfo, sinfo, sizeof(struct sctp_extrcvinfo)); 265e2e7c62eSMichael Tuexen SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_extrcvinfo)); 266e2e7c62eSMichael Tuexen } else { 267e2e7c62eSMichael Tuexen cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 268e2e7c62eSMichael Tuexen cmh->cmsg_type = SCTP_SNDRCV; 269e2e7c62eSMichael Tuexen *outinfo = *sinfo; 270e2e7c62eSMichael Tuexen SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_sndrcvinfo)); 271e2e7c62eSMichael Tuexen } 272e2e7c62eSMichael Tuexen } 273f8829a4aSRandall Stewart return (ret); 274f8829a4aSRandall Stewart } 275f8829a4aSRandall Stewart 276139bc87fSRandall Stewart 27777acdc25SRandall Stewart static void 27877acdc25SRandall Stewart sctp_mark_non_revokable(struct sctp_association *asoc, uint32_t tsn) 27977acdc25SRandall Stewart { 2809b2e0767SRandall Stewart uint32_t gap, i, cumackp1; 28177acdc25SRandall Stewart int fnd = 0; 28244249214SRandall Stewart int in_r = 0, in_nr = 0; 28377acdc25SRandall Stewart 28477acdc25SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) { 28577acdc25SRandall Stewart return; 28677acdc25SRandall Stewart } 2879b2e0767SRandall Stewart cumackp1 = asoc->cumulative_tsn + 1; 28820b07a4dSMichael Tuexen if (SCTP_TSN_GT(cumackp1, tsn)) { 2899b2e0767SRandall Stewart /* 2909b2e0767SRandall Stewart * this tsn is behind the cum ack and thus we don't need to 2919b2e0767SRandall Stewart * worry about it being moved from one to the other. 2929b2e0767SRandall Stewart */ 2939b2e0767SRandall Stewart return; 2949b2e0767SRandall Stewart } 29577acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn); 29644249214SRandall Stewart in_r = SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap); 29744249214SRandall Stewart in_nr = SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, gap); 29844249214SRandall Stewart if ((in_r == 0) && (in_nr == 0)) { 29944249214SRandall Stewart #ifdef INVARIANTS 30044249214SRandall Stewart panic("Things are really messed up now"); 30144249214SRandall Stewart #else 302cd3fd531SMichael Tuexen SCTP_PRINTF("gap:%x tsn:%x\n", gap, tsn); 30377acdc25SRandall Stewart sctp_print_mapping_array(asoc); 30477acdc25SRandall Stewart #endif 305b5c16493SMichael Tuexen } 30644249214SRandall Stewart if (in_nr == 0) 30777acdc25SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 30844249214SRandall Stewart if (in_r) 30977acdc25SRandall Stewart SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, gap); 31020b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 31177acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 31277acdc25SRandall Stewart } 31377acdc25SRandall Stewart if (tsn == asoc->highest_tsn_inside_map) { 31477acdc25SRandall Stewart /* We must back down to see what the new highest is */ 31520b07a4dSMichael Tuexen for (i = tsn - 1; SCTP_TSN_GE(i, asoc->mapping_array_base_tsn); i--) { 31677acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, i, asoc->mapping_array_base_tsn); 31777acdc25SRandall Stewart if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) { 31877acdc25SRandall Stewart asoc->highest_tsn_inside_map = i; 31977acdc25SRandall Stewart fnd = 1; 32077acdc25SRandall Stewart break; 32177acdc25SRandall Stewart } 32277acdc25SRandall Stewart } 32377acdc25SRandall Stewart if (!fnd) { 32477acdc25SRandall Stewart asoc->highest_tsn_inside_map = asoc->mapping_array_base_tsn - 1; 32577acdc25SRandall Stewart } 32677acdc25SRandall Stewart } 32777acdc25SRandall Stewart } 32877acdc25SRandall Stewart 32944249214SRandall Stewart static int 33044249214SRandall Stewart sctp_place_control_in_stream(struct sctp_stream_in *strm, 33144249214SRandall Stewart struct sctp_association *asoc, 33244249214SRandall Stewart struct sctp_queued_to_read *control) 333f8829a4aSRandall Stewart { 33444249214SRandall Stewart struct sctp_queued_to_read *at; 33544249214SRandall Stewart struct sctp_readhead *q; 33644249214SRandall Stewart uint8_t bits, unordered; 337f8829a4aSRandall Stewart 33844249214SRandall Stewart bits = (control->sinfo_flags >> 8); 33944249214SRandall Stewart unordered = bits & SCTP_DATA_UNORDERED; 34044249214SRandall Stewart if (unordered) { 34144249214SRandall Stewart q = &strm->uno_inqueue; 34244249214SRandall Stewart if (asoc->idata_supported == 0) { 34344249214SRandall Stewart if (!TAILQ_EMPTY(q)) { 344f8829a4aSRandall Stewart /* 34544249214SRandall Stewart * Only one stream can be here in old style 34644249214SRandall Stewart * -- abort 347f8829a4aSRandall Stewart */ 34844249214SRandall Stewart return (-1); 34944249214SRandall Stewart } 35044249214SRandall Stewart TAILQ_INSERT_TAIL(q, control, next_instrm); 35144249214SRandall Stewart control->on_strm_q = SCTP_ON_UNORDERED; 35244249214SRandall Stewart return (0); 35344249214SRandall Stewart } 35444249214SRandall Stewart } else { 35544249214SRandall Stewart q = &strm->inqueue; 35644249214SRandall Stewart } 35744249214SRandall Stewart if ((bits & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { 35844249214SRandall Stewart control->end_added = control->last_frag_seen = control->first_frag_seen = 1; 35944249214SRandall Stewart } 36044249214SRandall Stewart if (TAILQ_EMPTY(q)) { 36144249214SRandall Stewart /* Empty queue */ 36244249214SRandall Stewart TAILQ_INSERT_HEAD(q, control, next_instrm); 36344249214SRandall Stewart if (unordered) { 36444249214SRandall Stewart control->on_strm_q = SCTP_ON_UNORDERED; 36544249214SRandall Stewart } else { 36644249214SRandall Stewart control->on_strm_q = SCTP_ON_ORDERED; 36744249214SRandall Stewart } 36844249214SRandall Stewart return (0); 36944249214SRandall Stewart } else { 37044249214SRandall Stewart TAILQ_FOREACH(at, q, next_instrm) { 37144249214SRandall Stewart if (SCTP_TSN_GT(at->msg_id, control->msg_id)) { 37244249214SRandall Stewart /* 37344249214SRandall Stewart * one in queue is bigger than the new one, 37444249214SRandall Stewart * insert before this one 37544249214SRandall Stewart */ 37644249214SRandall Stewart TAILQ_INSERT_BEFORE(at, control, next_instrm); 37744249214SRandall Stewart if (unordered) { 37844249214SRandall Stewart control->on_strm_q = SCTP_ON_UNORDERED; 37944249214SRandall Stewart } else { 38044249214SRandall Stewart control->on_strm_q = SCTP_ON_ORDERED; 38144249214SRandall Stewart } 38244249214SRandall Stewart break; 38344249214SRandall Stewart } else if (at->msg_id == control->msg_id) { 38444249214SRandall Stewart /* 38544249214SRandall Stewart * Gak, He sent me a duplicate msg id 38644249214SRandall Stewart * number?? return -1 to abort. 38744249214SRandall Stewart */ 38844249214SRandall Stewart return (-1); 38944249214SRandall Stewart } else { 39044249214SRandall Stewart if (TAILQ_NEXT(at, next_instrm) == NULL) { 39144249214SRandall Stewart /* 39244249214SRandall Stewart * We are at the end, insert it 39344249214SRandall Stewart * after this one 39444249214SRandall Stewart */ 39544249214SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 39644249214SRandall Stewart sctp_log_strm_del(control, at, 39744249214SRandall Stewart SCTP_STR_LOG_FROM_INSERT_TL); 39844249214SRandall Stewart } 39944249214SRandall Stewart TAILQ_INSERT_AFTER(q, 40044249214SRandall Stewart at, control, next_instrm); 40144249214SRandall Stewart if (unordered) { 40244249214SRandall Stewart control->on_strm_q = SCTP_ON_UNORDERED; 40344249214SRandall Stewart } else { 40444249214SRandall Stewart control->on_strm_q = SCTP_ON_ORDERED; 40544249214SRandall Stewart } 40644249214SRandall Stewart break; 40744249214SRandall Stewart } 40844249214SRandall Stewart } 40944249214SRandall Stewart } 41044249214SRandall Stewart } 41144249214SRandall Stewart return (0); 41244249214SRandall Stewart } 41344249214SRandall Stewart 41444249214SRandall Stewart static void 41544249214SRandall Stewart sctp_abort_in_reasm(struct sctp_tcb *stcb, 41644249214SRandall Stewart struct sctp_queued_to_read *control, 41744249214SRandall Stewart struct sctp_tmit_chunk *chk, 41844249214SRandall Stewart int *abort_flag, int opspot) 41944249214SRandall Stewart { 42044249214SRandall Stewart char msg[SCTP_DIAG_INFO_LEN]; 42144249214SRandall Stewart struct mbuf *oper; 42244249214SRandall Stewart 42344249214SRandall Stewart if (stcb->asoc.idata_supported) { 42444249214SRandall Stewart snprintf(msg, sizeof(msg), 42544249214SRandall Stewart "Reass %x,CF:%x,TSN=%8.8x,SID=%4.4x,FSN=%8.8x,MID:%8.8x", 42644249214SRandall Stewart opspot, 42744249214SRandall Stewart control->fsn_included, 42844249214SRandall Stewart chk->rec.data.TSN_seq, 42944249214SRandall Stewart chk->rec.data.stream_number, 43044249214SRandall Stewart chk->rec.data.fsn_num, chk->rec.data.stream_seq); 43144249214SRandall Stewart } else { 43244249214SRandall Stewart snprintf(msg, sizeof(msg), 43344249214SRandall Stewart "Reass %x,CI:%x,TSN=%8.8x,SID=%4.4x,FSN=%4.4x,SSN:%4.4x", 43444249214SRandall Stewart opspot, 43544249214SRandall Stewart control->fsn_included, 43644249214SRandall Stewart chk->rec.data.TSN_seq, 43744249214SRandall Stewart chk->rec.data.stream_number, 43844249214SRandall Stewart chk->rec.data.fsn_num, 43944249214SRandall Stewart (uint16_t) chk->rec.data.stream_seq); 44044249214SRandall Stewart } 44144249214SRandall Stewart oper = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 442f8829a4aSRandall Stewart sctp_m_freem(chk->data); 443f8829a4aSRandall Stewart chk->data = NULL; 444689e6a5fSMichael Tuexen sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); 44544249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_1; 44644249214SRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, oper, SCTP_SO_NOT_LOCKED); 44744249214SRandall Stewart *abort_flag = 1; 448f8829a4aSRandall Stewart } 449f8829a4aSRandall Stewart 45044249214SRandall Stewart static void 451d1ea5fa9SMichael Tuexen sctp_clean_up_control(struct sctp_tcb *stcb, struct sctp_queued_to_read *control) 45244249214SRandall Stewart { 453f8829a4aSRandall Stewart /* 45444249214SRandall Stewart * The control could not be placed and must be cleaned. 455f8829a4aSRandall Stewart */ 45644249214SRandall Stewart struct sctp_tmit_chunk *chk, *nchk; 457df6e0cc3SRandall Stewart 45844249214SRandall Stewart TAILQ_FOREACH_SAFE(chk, &control->reasm, sctp_next, nchk) { 45944249214SRandall Stewart TAILQ_REMOVE(&control->reasm, chk, sctp_next); 46044249214SRandall Stewart if (chk->data) 46144249214SRandall Stewart sctp_m_freem(chk->data); 462f8829a4aSRandall Stewart chk->data = NULL; 463689e6a5fSMichael Tuexen sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); 464f8829a4aSRandall Stewart } 46544249214SRandall Stewart sctp_free_a_readq(stcb, control); 466f8829a4aSRandall Stewart } 467f8829a4aSRandall Stewart 468f8829a4aSRandall Stewart /* 469f8829a4aSRandall Stewart * Queue the chunk either right into the socket buffer if it is the next one 470f8829a4aSRandall Stewart * to go OR put it in the correct place in the delivery queue. If we do 47144249214SRandall Stewart * append to the so_buf, keep doing so until we are out of order as 47244249214SRandall Stewart * long as the control's entered are non-fragmented. 473f8829a4aSRandall Stewart */ 474f8829a4aSRandall Stewart static void 47544249214SRandall Stewart sctp_queue_data_to_stream(struct sctp_tcb *stcb, 47644249214SRandall Stewart struct sctp_stream_in *strm, 47744249214SRandall Stewart struct sctp_association *asoc, 47844249214SRandall Stewart struct sctp_queued_to_read *control, int *abort_flag, int *need_reasm) 479f8829a4aSRandall Stewart { 480f8829a4aSRandall Stewart /* 481f8829a4aSRandall Stewart * FIX-ME maybe? What happens when the ssn wraps? If we are getting 482f8829a4aSRandall Stewart * all the data in one stream this could happen quite rapidly. One 483f8829a4aSRandall Stewart * could use the TSN to keep track of things, but this scheme breaks 484cd0a4ff6SPedro F. Giffuni * down in the other type of stream usage that could occur. Send a 485f8829a4aSRandall Stewart * single msg to stream 0, send 4Billion messages to stream 1, now 486f8829a4aSRandall Stewart * send a message to stream 0. You have a situation where the TSN 487f8829a4aSRandall Stewart * has wrapped but not in the stream. Is this worth worrying about 488f8829a4aSRandall Stewart * or should we just change our queue sort at the bottom to be by 489f8829a4aSRandall Stewart * TSN. 490f8829a4aSRandall Stewart * 491f8829a4aSRandall Stewart * Could it also be legal for a peer to send ssn 1 with TSN 2 and ssn 2 492f8829a4aSRandall Stewart * with TSN 1? If the peer is doing some sort of funky TSN/SSN 493f8829a4aSRandall Stewart * assignment this could happen... and I don't see how this would be 494f8829a4aSRandall Stewart * a violation. So for now I am undecided an will leave the sort by 495f8829a4aSRandall Stewart * SSN alone. Maybe a hybred approach is the answer 496f8829a4aSRandall Stewart * 497f8829a4aSRandall Stewart */ 498f8829a4aSRandall Stewart struct sctp_queued_to_read *at; 499f8829a4aSRandall Stewart int queue_needed; 50044249214SRandall Stewart uint32_t nxt_todel; 501ff1ffd74SMichael Tuexen struct mbuf *op_err; 502ff1ffd74SMichael Tuexen char msg[SCTP_DIAG_INFO_LEN]; 503f8829a4aSRandall Stewart 504b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 505f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD); 50680fefe0aSRandall Stewart } 50744249214SRandall Stewart if (SCTP_MSGID_GT((!asoc->idata_supported), strm->last_sequence_delivered, control->sinfo_ssn)) { 508f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 509f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ: %u delivered: %u from peer, Abort association\n", 510ad81507eSRandall Stewart control->sinfo_ssn, strm->last_sequence_delivered); 511c40e9cf2SRandall Stewart protocol_error: 512f8829a4aSRandall Stewart /* 513f8829a4aSRandall Stewart * throw it in the stream so it gets cleaned up in 514f8829a4aSRandall Stewart * association destruction 515f8829a4aSRandall Stewart */ 51644249214SRandall Stewart TAILQ_INSERT_HEAD(&strm->inqueue, control, next_instrm); 517ff1ffd74SMichael Tuexen snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x", 518ff1ffd74SMichael Tuexen strm->last_sequence_delivered, control->sinfo_tsn, 519ff1ffd74SMichael Tuexen control->sinfo_stream, control->sinfo_ssn); 520ff1ffd74SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 52144249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2; 522ff1ffd74SMichael Tuexen sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 523f8829a4aSRandall Stewart *abort_flag = 1; 524f8829a4aSRandall Stewart return; 525f8829a4aSRandall Stewart 526f8829a4aSRandall Stewart } 52744249214SRandall Stewart if ((SCTP_TSN_GE(asoc->cumulative_tsn, control->sinfo_tsn)) && (asoc->idata_supported == 0)) { 52844249214SRandall Stewart goto protocol_error; 52944249214SRandall Stewart } 53044249214SRandall Stewart queue_needed = 1; 53144249214SRandall Stewart asoc->size_on_all_streams += control->length; 53244249214SRandall Stewart sctp_ucount_incr(asoc->cnt_on_all_streams); 53344249214SRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 53444249214SRandall Stewart if (nxt_todel == control->sinfo_ssn) { 535cf9e47b2SMichael Tuexen #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 536cf9e47b2SMichael Tuexen struct socket *so; 537cf9e47b2SMichael Tuexen 538cf9e47b2SMichael Tuexen so = SCTP_INP_SO(stcb->sctp_ep); 539cf9e47b2SMichael Tuexen atomic_add_int(&stcb->asoc.refcnt, 1); 540cf9e47b2SMichael Tuexen SCTP_TCB_UNLOCK(stcb); 541cf9e47b2SMichael Tuexen SCTP_SOCKET_LOCK(so, 1); 542cf9e47b2SMichael Tuexen SCTP_TCB_LOCK(stcb); 543cf9e47b2SMichael Tuexen atomic_subtract_int(&stcb->asoc.refcnt, 1); 544cf9e47b2SMichael Tuexen if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) { 545cf9e47b2SMichael Tuexen SCTP_SOCKET_UNLOCK(so, 1); 546cf9e47b2SMichael Tuexen return; 547cf9e47b2SMichael Tuexen } 548cf9e47b2SMichael Tuexen #endif 549f8829a4aSRandall Stewart /* can be delivered right away? */ 550b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 551f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_IMMED_DEL); 55280fefe0aSRandall Stewart } 553830d754dSRandall Stewart /* EY it wont be queued if it could be delivered directly */ 554f8829a4aSRandall Stewart queue_needed = 0; 555f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 556f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 557f8829a4aSRandall Stewart strm->last_sequence_delivered++; 558b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 559f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 560f8829a4aSRandall Stewart control, 561cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 562574679afSMichael Tuexen SCTP_READ_LOCK_NOT_HELD, SCTP_SO_LOCKED); 56344249214SRandall Stewart TAILQ_FOREACH_SAFE(control, &strm->inqueue, next_instrm, at) { 564f8829a4aSRandall Stewart /* all delivered */ 565f8829a4aSRandall Stewart nxt_todel = strm->last_sequence_delivered + 1; 56644249214SRandall Stewart if ((nxt_todel == control->sinfo_ssn) && 56744249214SRandall Stewart (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG)) { 568f8829a4aSRandall Stewart asoc->size_on_all_streams -= control->length; 569f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 57044249214SRandall Stewart if (control->on_strm_q == SCTP_ON_ORDERED) { 57144249214SRandall Stewart TAILQ_REMOVE(&strm->inqueue, control, next_instrm); 57298d5fd97SMichael Tuexen #ifdef INVARIANTS 57344249214SRandall Stewart } else { 57444249214SRandall Stewart panic("Huh control: %p is on_strm_q: %d", 57544249214SRandall Stewart control, control->on_strm_q); 57698d5fd97SMichael Tuexen #endif 57744249214SRandall Stewart } 57844249214SRandall Stewart control->on_strm_q = 0; 579f8829a4aSRandall Stewart strm->last_sequence_delivered++; 580f8829a4aSRandall Stewart /* 581f8829a4aSRandall Stewart * We ignore the return of deliver_data here 582f8829a4aSRandall Stewart * since we always can hold the chunk on the 583f8829a4aSRandall Stewart * d-queue. And we have a finite number that 584f8829a4aSRandall Stewart * can be delivered from the strq. 585f8829a4aSRandall Stewart */ 586b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 587f8829a4aSRandall Stewart sctp_log_strm_del(control, NULL, 588f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_IMMED_DEL); 58980fefe0aSRandall Stewart } 590b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, control->sinfo_tsn); 591f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 592f8829a4aSRandall Stewart control, 593cfde3ff7SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 594cfde3ff7SRandall Stewart SCTP_READ_LOCK_NOT_HELD, 595574679afSMichael Tuexen SCTP_SO_LOCKED); 596f8829a4aSRandall Stewart continue; 59744249214SRandall Stewart } else if (nxt_todel == control->sinfo_ssn) { 59844249214SRandall Stewart *need_reasm = 1; 599f8829a4aSRandall Stewart } 600f8829a4aSRandall Stewart break; 601f8829a4aSRandall Stewart } 60244249214SRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 60344249214SRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 60444249214SRandall Stewart #endif 605f8829a4aSRandall Stewart } 606f8829a4aSRandall Stewart if (queue_needed) { 607f8829a4aSRandall Stewart /* 608f8829a4aSRandall Stewart * Ok, we did not deliver this guy, find the correct place 609f8829a4aSRandall Stewart * to put it on the queue. 610f8829a4aSRandall Stewart */ 61144249214SRandall Stewart if (sctp_place_control_in_stream(strm, asoc, control)) { 61244249214SRandall Stewart snprintf(msg, sizeof(msg), 613f2ea2a2dSMichael Tuexen "Queue to str msg_id: %u duplicate", 61444249214SRandall Stewart control->msg_id); 615d1ea5fa9SMichael Tuexen sctp_clean_up_control(stcb, control); 616b1deed45SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 61744249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_3; 618b1deed45SMichael Tuexen sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 61944249214SRandall Stewart *abort_flag = 1; 620f8829a4aSRandall Stewart } 621f8829a4aSRandall Stewart } 622f8829a4aSRandall Stewart } 623f8829a4aSRandall Stewart 62444249214SRandall Stewart 62544249214SRandall Stewart static void 62644249214SRandall Stewart sctp_setup_tail_pointer(struct sctp_queued_to_read *control) 627f8829a4aSRandall Stewart { 62844249214SRandall Stewart struct mbuf *m, *prev = NULL; 62944249214SRandall Stewart struct sctp_tcb *stcb; 630f8829a4aSRandall Stewart 63144249214SRandall Stewart stcb = control->stcb; 63244249214SRandall Stewart control->held_length = 0; 63344249214SRandall Stewart control->length = 0; 63444249214SRandall Stewart m = control->data; 63544249214SRandall Stewart while (m) { 63644249214SRandall Stewart if (SCTP_BUF_LEN(m) == 0) { 63744249214SRandall Stewart /* Skip mbufs with NO length */ 63844249214SRandall Stewart if (prev == NULL) { 63944249214SRandall Stewart /* First one */ 64044249214SRandall Stewart control->data = sctp_m_free(m); 64144249214SRandall Stewart m = control->data; 64244249214SRandall Stewart } else { 64344249214SRandall Stewart SCTP_BUF_NEXT(prev) = sctp_m_free(m); 64444249214SRandall Stewart m = SCTP_BUF_NEXT(prev); 645f8829a4aSRandall Stewart } 64644249214SRandall Stewart if (m == NULL) { 64744249214SRandall Stewart control->tail_mbuf = prev; 648f8829a4aSRandall Stewart } 64944249214SRandall Stewart continue; 650f8829a4aSRandall Stewart } 65144249214SRandall Stewart prev = m; 65244249214SRandall Stewart atomic_add_int(&control->length, SCTP_BUF_LEN(m)); 65344249214SRandall Stewart if (control->on_read_q) { 65444249214SRandall Stewart /* 65544249214SRandall Stewart * On read queue so we must increment the SB stuff, 65644249214SRandall Stewart * we assume caller has done any locks of SB. 65744249214SRandall Stewart */ 65844249214SRandall Stewart sctp_sballoc(stcb, &stcb->sctp_socket->so_rcv, m); 659f8829a4aSRandall Stewart } 66044249214SRandall Stewart m = SCTP_BUF_NEXT(m); 661f8829a4aSRandall Stewart } 66244249214SRandall Stewart if (prev) { 66344249214SRandall Stewart control->tail_mbuf = prev; 66444249214SRandall Stewart } 665f8829a4aSRandall Stewart } 666f8829a4aSRandall Stewart 667f8829a4aSRandall Stewart static void 66844249214SRandall Stewart sctp_add_to_tail_pointer(struct sctp_queued_to_read *control, struct mbuf *m) 669f8829a4aSRandall Stewart { 67044249214SRandall Stewart struct mbuf *prev = NULL; 67144249214SRandall Stewart struct sctp_tcb *stcb; 672f8829a4aSRandall Stewart 67344249214SRandall Stewart stcb = control->stcb; 67444249214SRandall Stewart if (stcb == NULL) { 67598d5fd97SMichael Tuexen #ifdef INVARIANTS 67644249214SRandall Stewart panic("Control broken"); 67798d5fd97SMichael Tuexen #else 67898d5fd97SMichael Tuexen return; 67998d5fd97SMichael Tuexen #endif 68044249214SRandall Stewart } 68144249214SRandall Stewart if (control->tail_mbuf == NULL) { 68244249214SRandall Stewart /* TSNH */ 68344249214SRandall Stewart control->data = m; 68444249214SRandall Stewart sctp_setup_tail_pointer(control); 685f8829a4aSRandall Stewart return; 686f8829a4aSRandall Stewart } 68744249214SRandall Stewart control->tail_mbuf->m_next = m; 68844249214SRandall Stewart while (m) { 68944249214SRandall Stewart if (SCTP_BUF_LEN(m) == 0) { 69044249214SRandall Stewart /* Skip mbufs with NO length */ 69144249214SRandall Stewart if (prev == NULL) { 69244249214SRandall Stewart /* First one */ 69344249214SRandall Stewart control->tail_mbuf->m_next = sctp_m_free(m); 69444249214SRandall Stewart m = control->tail_mbuf->m_next; 69544249214SRandall Stewart } else { 69644249214SRandall Stewart SCTP_BUF_NEXT(prev) = sctp_m_free(m); 69744249214SRandall Stewart m = SCTP_BUF_NEXT(prev); 69844249214SRandall Stewart } 69944249214SRandall Stewart if (m == NULL) { 70044249214SRandall Stewart control->tail_mbuf = prev; 70144249214SRandall Stewart } 70244249214SRandall Stewart continue; 70344249214SRandall Stewart } 70444249214SRandall Stewart prev = m; 70544249214SRandall Stewart if (control->on_read_q) { 706f8829a4aSRandall Stewart /* 70744249214SRandall Stewart * On read queue so we must increment the SB stuff, 70844249214SRandall Stewart * we assume caller has done any locks of SB. 709f8829a4aSRandall Stewart */ 71044249214SRandall Stewart sctp_sballoc(stcb, &stcb->sctp_socket->so_rcv, m); 71144249214SRandall Stewart } 71244249214SRandall Stewart atomic_add_int(&control->length, SCTP_BUF_LEN(m)); 71344249214SRandall Stewart m = SCTP_BUF_NEXT(m); 71444249214SRandall Stewart } 71544249214SRandall Stewart if (prev) { 71644249214SRandall Stewart control->tail_mbuf = prev; 71744249214SRandall Stewart } 71844249214SRandall Stewart } 71944249214SRandall Stewart 72044249214SRandall Stewart static void 72144249214SRandall Stewart sctp_build_readq_entry_from_ctl(struct sctp_queued_to_read *nc, struct sctp_queued_to_read *control) 72244249214SRandall Stewart { 72344249214SRandall Stewart memset(nc, 0, sizeof(struct sctp_queued_to_read)); 72444249214SRandall Stewart nc->sinfo_stream = control->sinfo_stream; 72544249214SRandall Stewart nc->sinfo_ssn = control->sinfo_ssn; 72644249214SRandall Stewart TAILQ_INIT(&nc->reasm); 72744249214SRandall Stewart nc->top_fsn = control->top_fsn; 72844249214SRandall Stewart nc->msg_id = control->msg_id; 72944249214SRandall Stewart nc->sinfo_flags = control->sinfo_flags; 73044249214SRandall Stewart nc->sinfo_ppid = control->sinfo_ppid; 73144249214SRandall Stewart nc->sinfo_context = control->sinfo_context; 73244249214SRandall Stewart nc->fsn_included = 0xffffffff; 73344249214SRandall Stewart nc->sinfo_tsn = control->sinfo_tsn; 73444249214SRandall Stewart nc->sinfo_cumtsn = control->sinfo_cumtsn; 73544249214SRandall Stewart nc->sinfo_assoc_id = control->sinfo_assoc_id; 73644249214SRandall Stewart nc->whoFrom = control->whoFrom; 73744249214SRandall Stewart atomic_add_int(&nc->whoFrom->ref_count, 1); 73844249214SRandall Stewart nc->stcb = control->stcb; 73944249214SRandall Stewart nc->port_from = control->port_from; 74044249214SRandall Stewart } 74144249214SRandall Stewart 742d1ea5fa9SMichael Tuexen static void 743d1ea5fa9SMichael Tuexen sctp_reset_a_control(struct sctp_queued_to_read *control, 744d1ea5fa9SMichael Tuexen struct sctp_inpcb *inp, uint32_t tsn) 745d1ea5fa9SMichael Tuexen { 746d1ea5fa9SMichael Tuexen control->fsn_included = tsn; 747d1ea5fa9SMichael Tuexen if (control->on_read_q) { 748d1ea5fa9SMichael Tuexen /* 749d1ea5fa9SMichael Tuexen * We have to purge it from there, hopefully this will work 750d1ea5fa9SMichael Tuexen * :-) 751d1ea5fa9SMichael Tuexen */ 752d1ea5fa9SMichael Tuexen TAILQ_REMOVE(&inp->read_queue, control, next); 753d1ea5fa9SMichael Tuexen control->on_read_q = 0; 754d1ea5fa9SMichael Tuexen } 755d1ea5fa9SMichael Tuexen } 756d1ea5fa9SMichael Tuexen 75744249214SRandall Stewart static int 758d1ea5fa9SMichael Tuexen sctp_handle_old_unordered_data(struct sctp_tcb *stcb, 759d1ea5fa9SMichael Tuexen struct sctp_association *asoc, 760d1ea5fa9SMichael Tuexen struct sctp_stream_in *strm, 761d1ea5fa9SMichael Tuexen struct sctp_queued_to_read *control, 762d1ea5fa9SMichael Tuexen uint32_t pd_point, 763d1ea5fa9SMichael Tuexen int inp_read_lock_held) 76444249214SRandall Stewart { 76544249214SRandall Stewart /* 76644249214SRandall Stewart * Special handling for the old un-ordered data chunk. All the 76744249214SRandall Stewart * chunks/TSN's go to msg_id 0. So we have to do the old style 76844249214SRandall Stewart * watching to see if we have it all. If you return one, no other 76944249214SRandall Stewart * control entries on the un-ordered queue will be looked at. In 77044249214SRandall Stewart * theory there should be no others entries in reality, unless the 77144249214SRandall Stewart * guy is sending both unordered NDATA and unordered DATA... 77244249214SRandall Stewart */ 77344249214SRandall Stewart struct sctp_tmit_chunk *chk, *lchk, *tchk; 77444249214SRandall Stewart uint32_t fsn; 775643fd575SMichael Tuexen struct sctp_queued_to_read *nc; 77644249214SRandall Stewart int cnt_added; 77744249214SRandall Stewart 77844249214SRandall Stewart if (control->first_frag_seen == 0) { 77944249214SRandall Stewart /* Nothing we can do, we have not seen the first piece yet */ 78044249214SRandall Stewart return (1); 78144249214SRandall Stewart } 78244249214SRandall Stewart /* Collapse any we can */ 78344249214SRandall Stewart cnt_added = 0; 78444249214SRandall Stewart restart: 78544249214SRandall Stewart fsn = control->fsn_included + 1; 78644249214SRandall Stewart /* Now what can we add? */ 78744249214SRandall Stewart TAILQ_FOREACH_SAFE(chk, &control->reasm, sctp_next, lchk) { 78844249214SRandall Stewart if (chk->rec.data.fsn_num == fsn) { 78944249214SRandall Stewart /* Ok lets add it */ 790643fd575SMichael Tuexen sctp_alloc_a_readq(stcb, nc); 791643fd575SMichael Tuexen if (nc == NULL) { 792643fd575SMichael Tuexen break; 793643fd575SMichael Tuexen } 794643fd575SMichael Tuexen memset(nc, 0, sizeof(struct sctp_queued_to_read)); 79544249214SRandall Stewart TAILQ_REMOVE(&control->reasm, chk, sctp_next); 796d1ea5fa9SMichael Tuexen sctp_add_chk_to_control(control, strm, stcb, asoc, chk, SCTP_READ_LOCK_NOT_HELD); 79744249214SRandall Stewart fsn++; 79844249214SRandall Stewart cnt_added++; 79944249214SRandall Stewart chk = NULL; 80044249214SRandall Stewart if (control->end_added) { 80144249214SRandall Stewart /* We are done */ 80244249214SRandall Stewart if (!TAILQ_EMPTY(&control->reasm)) { 80344249214SRandall Stewart /* 80444249214SRandall Stewart * Ok we have to move anything left 80544249214SRandall Stewart * on the control queue to a new 80644249214SRandall Stewart * control. 80744249214SRandall Stewart */ 80844249214SRandall Stewart sctp_build_readq_entry_from_ctl(nc, control); 80944249214SRandall Stewart tchk = TAILQ_FIRST(&control->reasm); 81044249214SRandall Stewart if (tchk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 81144249214SRandall Stewart TAILQ_REMOVE(&control->reasm, tchk, sctp_next); 81244249214SRandall Stewart nc->first_frag_seen = 1; 81344249214SRandall Stewart nc->fsn_included = tchk->rec.data.fsn_num; 81444249214SRandall Stewart nc->data = tchk->data; 815d1ea5fa9SMichael Tuexen nc->sinfo_ppid = tchk->rec.data.payloadtype; 816d1ea5fa9SMichael Tuexen nc->sinfo_tsn = tchk->rec.data.TSN_seq; 81744249214SRandall Stewart sctp_mark_non_revokable(asoc, tchk->rec.data.TSN_seq); 81844249214SRandall Stewart tchk->data = NULL; 81944249214SRandall Stewart sctp_free_a_chunk(stcb, tchk, SCTP_SO_NOT_LOCKED); 82044249214SRandall Stewart sctp_setup_tail_pointer(nc); 82144249214SRandall Stewart tchk = TAILQ_FIRST(&control->reasm); 82244249214SRandall Stewart } 82344249214SRandall Stewart /* Spin the rest onto the queue */ 82444249214SRandall Stewart while (tchk) { 82544249214SRandall Stewart TAILQ_REMOVE(&control->reasm, tchk, sctp_next); 82644249214SRandall Stewart TAILQ_INSERT_TAIL(&nc->reasm, tchk, sctp_next); 82744249214SRandall Stewart tchk = TAILQ_FIRST(&control->reasm); 82844249214SRandall Stewart } 82944249214SRandall Stewart /* 83044249214SRandall Stewart * Now lets add it to the queue 83144249214SRandall Stewart * after removing control 83244249214SRandall Stewart */ 83344249214SRandall Stewart TAILQ_INSERT_TAIL(&strm->uno_inqueue, nc, next_instrm); 83444249214SRandall Stewart nc->on_strm_q = SCTP_ON_UNORDERED; 83544249214SRandall Stewart if (control->on_strm_q) { 83644249214SRandall Stewart TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); 83744249214SRandall Stewart control->on_strm_q = 0; 83844249214SRandall Stewart } 83944249214SRandall Stewart } 84044249214SRandall Stewart if (control->pdapi_started) { 84144249214SRandall Stewart strm->pd_api_started = 0; 84244249214SRandall Stewart control->pdapi_started = 0; 84344249214SRandall Stewart } 84444249214SRandall Stewart if (control->on_strm_q) { 84544249214SRandall Stewart TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); 84644249214SRandall Stewart control->on_strm_q = 0; 84726f0250aSMichael Tuexen SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); 84844249214SRandall Stewart } 849c09a1534SMichael Tuexen if (control->on_read_q == 0) { 850c09a1534SMichael Tuexen sctp_add_to_readq(stcb->sctp_ep, stcb, control, 851c09a1534SMichael Tuexen &stcb->sctp_socket->so_rcv, control->end_added, 852d1ea5fa9SMichael Tuexen inp_read_lock_held, SCTP_SO_NOT_LOCKED); 853c09a1534SMichael Tuexen } 854b1deed45SMichael Tuexen sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); 8550fa7377aSMichael Tuexen if ((nc->first_frag_seen) && !TAILQ_EMPTY(&nc->reasm)) { 85644249214SRandall Stewart /* 85744249214SRandall Stewart * Switch to the new guy and 85844249214SRandall Stewart * continue 85944249214SRandall Stewart */ 86044249214SRandall Stewart control = nc; 86144249214SRandall Stewart goto restart; 862643fd575SMichael Tuexen } else { 863d1ea5fa9SMichael Tuexen if (nc->on_strm_q == 0) { 864643fd575SMichael Tuexen sctp_free_a_readq(stcb, nc); 86544249214SRandall Stewart } 866d1ea5fa9SMichael Tuexen } 86744249214SRandall Stewart return (1); 868643fd575SMichael Tuexen } else { 869643fd575SMichael Tuexen sctp_free_a_readq(stcb, nc); 87044249214SRandall Stewart } 87144249214SRandall Stewart } else { 87244249214SRandall Stewart /* Can't add more */ 87344249214SRandall Stewart break; 87444249214SRandall Stewart } 87544249214SRandall Stewart } 87644249214SRandall Stewart if ((control->length > pd_point) && (strm->pd_api_started == 0)) { 877c09a1534SMichael Tuexen strm->pd_api_started = 1; 878c09a1534SMichael Tuexen control->pdapi_started = 1; 87944249214SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, control, 88044249214SRandall Stewart &stcb->sctp_socket->so_rcv, control->end_added, 881d1ea5fa9SMichael Tuexen inp_read_lock_held, SCTP_SO_NOT_LOCKED); 882b1deed45SMichael Tuexen sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); 88344249214SRandall Stewart return (0); 88444249214SRandall Stewart } else { 88544249214SRandall Stewart return (1); 88644249214SRandall Stewart } 88744249214SRandall Stewart } 88844249214SRandall Stewart 88944249214SRandall Stewart static void 890d1ea5fa9SMichael Tuexen sctp_inject_old_unordered_data(struct sctp_tcb *stcb, 891d1ea5fa9SMichael Tuexen struct sctp_association *asoc, 89244249214SRandall Stewart struct sctp_queued_to_read *control, 89344249214SRandall Stewart struct sctp_tmit_chunk *chk, 89444249214SRandall Stewart int *abort_flag) 89544249214SRandall Stewart { 89644249214SRandall Stewart struct sctp_tmit_chunk *at; 897d1ea5fa9SMichael Tuexen int inserted; 89844249214SRandall Stewart 89944249214SRandall Stewart /* 90044249214SRandall Stewart * Here we need to place the chunk into the control structure sorted 90144249214SRandall Stewart * in the correct order. 90244249214SRandall Stewart */ 90344249214SRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 90444249214SRandall Stewart /* Its the very first one. */ 90544249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 906f2ea2a2dSMichael Tuexen "chunk is a first fsn: %u becomes fsn_included\n", 90744249214SRandall Stewart chk->rec.data.fsn_num); 90844249214SRandall Stewart if (control->first_frag_seen) { 90944249214SRandall Stewart /* 91044249214SRandall Stewart * In old un-ordered we can reassembly on one 91144249214SRandall Stewart * control multiple messages. As long as the next 91244249214SRandall Stewart * FIRST is greater then the old first (TSN i.e. FSN 91344249214SRandall Stewart * wise) 91444249214SRandall Stewart */ 91544249214SRandall Stewart struct mbuf *tdata; 91644249214SRandall Stewart uint32_t tmp; 91744249214SRandall Stewart 91844249214SRandall Stewart if (SCTP_TSN_GT(chk->rec.data.fsn_num, control->fsn_included)) { 91944249214SRandall Stewart /* 92044249214SRandall Stewart * Easy way the start of a new guy beyond 92144249214SRandall Stewart * the lowest 92244249214SRandall Stewart */ 92344249214SRandall Stewart goto place_chunk; 92444249214SRandall Stewart } 92544249214SRandall Stewart if ((chk->rec.data.fsn_num == control->fsn_included) || 92644249214SRandall Stewart (control->pdapi_started)) { 92744249214SRandall Stewart /* 92844249214SRandall Stewart * Ok this should not happen, if it does we 92944249214SRandall Stewart * started the pd-api on the higher TSN 93044249214SRandall Stewart * (since the equals part is a TSN failure 93144249214SRandall Stewart * it must be that). 93244249214SRandall Stewart * 93344249214SRandall Stewart * We are completly hosed in that case since I 93444249214SRandall Stewart * have no way to recover. This really will 93544249214SRandall Stewart * only happen if we can get more TSN's 93644249214SRandall Stewart * higher before the pd-api-point. 93744249214SRandall Stewart */ 938b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, chk, 93944249214SRandall Stewart abort_flag, 94044249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_4); 94144249214SRandall Stewart 94244249214SRandall Stewart return; 94344249214SRandall Stewart } 94444249214SRandall Stewart /* 94544249214SRandall Stewart * Ok we have two firsts and the one we just got is 94644249214SRandall Stewart * smaller than the one we previously placed.. yuck! 94744249214SRandall Stewart * We must swap them out. 94844249214SRandall Stewart */ 94944249214SRandall Stewart /* swap the mbufs */ 95044249214SRandall Stewart tdata = control->data; 95144249214SRandall Stewart control->data = chk->data; 95244249214SRandall Stewart chk->data = tdata; 953d1ea5fa9SMichael Tuexen /* Save the lengths */ 954d1ea5fa9SMichael Tuexen chk->send_size = control->length; 955d1ea5fa9SMichael Tuexen /* Recompute length of control and tail pointer */ 956d1ea5fa9SMichael Tuexen sctp_setup_tail_pointer(control); 95744249214SRandall Stewart /* Fix the FSN included */ 95844249214SRandall Stewart tmp = control->fsn_included; 95944249214SRandall Stewart control->fsn_included = chk->rec.data.fsn_num; 96044249214SRandall Stewart chk->rec.data.fsn_num = tmp; 961d1ea5fa9SMichael Tuexen /* Fix the TSN included */ 962d1ea5fa9SMichael Tuexen tmp = control->sinfo_tsn; 963d1ea5fa9SMichael Tuexen control->sinfo_tsn = chk->rec.data.TSN_seq; 964d1ea5fa9SMichael Tuexen chk->rec.data.TSN_seq = tmp; 965d1ea5fa9SMichael Tuexen /* Fix the PPID included */ 966d1ea5fa9SMichael Tuexen tmp = control->sinfo_ppid; 967d1ea5fa9SMichael Tuexen control->sinfo_ppid = chk->rec.data.payloadtype; 968d1ea5fa9SMichael Tuexen chk->rec.data.payloadtype = tmp; 969d1ea5fa9SMichael Tuexen /* Fix tail pointer */ 97044249214SRandall Stewart goto place_chunk; 97144249214SRandall Stewart } 97244249214SRandall Stewart control->first_frag_seen = 1; 97344249214SRandall Stewart control->top_fsn = control->fsn_included = chk->rec.data.fsn_num; 974d1ea5fa9SMichael Tuexen control->sinfo_tsn = chk->rec.data.TSN_seq; 975d1ea5fa9SMichael Tuexen control->sinfo_ppid = chk->rec.data.payloadtype; 97644249214SRandall Stewart control->data = chk->data; 97744249214SRandall Stewart sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq); 97844249214SRandall Stewart chk->data = NULL; 97944249214SRandall Stewart sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); 98044249214SRandall Stewart sctp_setup_tail_pointer(control); 98144249214SRandall Stewart return; 98244249214SRandall Stewart } 98344249214SRandall Stewart place_chunk: 984d1ea5fa9SMichael Tuexen inserted = 0; 98544249214SRandall Stewart TAILQ_FOREACH(at, &control->reasm, sctp_next) { 98644249214SRandall Stewart if (SCTP_TSN_GT(at->rec.data.fsn_num, chk->rec.data.fsn_num)) { 98744249214SRandall Stewart /* 98844249214SRandall Stewart * This one in queue is bigger than the new one, 98944249214SRandall Stewart * insert the new one before at. 99044249214SRandall Stewart */ 99144249214SRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 99244249214SRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 99344249214SRandall Stewart inserted = 1; 99444249214SRandall Stewart TAILQ_INSERT_BEFORE(at, chk, sctp_next); 99544249214SRandall Stewart break; 99644249214SRandall Stewart } else if (at->rec.data.fsn_num == chk->rec.data.fsn_num) { 99744249214SRandall Stewart /* 99844249214SRandall Stewart * They sent a duplicate fsn number. This really 99944249214SRandall Stewart * should not happen since the FSN is a TSN and it 100044249214SRandall Stewart * should have been dropped earlier. 100144249214SRandall Stewart */ 1002b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, chk, 100344249214SRandall Stewart abort_flag, 100444249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_5); 100544249214SRandall Stewart return; 100644249214SRandall Stewart } 100744249214SRandall Stewart } 100844249214SRandall Stewart if (inserted == 0) { 100944249214SRandall Stewart /* Its at the end */ 101044249214SRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 101144249214SRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 101244249214SRandall Stewart control->top_fsn = chk->rec.data.fsn_num; 101344249214SRandall Stewart TAILQ_INSERT_TAIL(&control->reasm, chk, sctp_next); 101444249214SRandall Stewart } 101544249214SRandall Stewart } 101644249214SRandall Stewart 101744249214SRandall Stewart static int 1018d1ea5fa9SMichael Tuexen sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc, 1019d1ea5fa9SMichael Tuexen struct sctp_stream_in *strm, int inp_read_lock_held) 102044249214SRandall Stewart { 102144249214SRandall Stewart /* 102244249214SRandall Stewart * Given a stream, strm, see if any of the SSN's on it that are 102344249214SRandall Stewart * fragmented are ready to deliver. If so go ahead and place them on 102444249214SRandall Stewart * the read queue. In so placing if we have hit the end, then we 102544249214SRandall Stewart * need to remove them from the stream's queue. 102644249214SRandall Stewart */ 102744249214SRandall Stewart struct sctp_queued_to_read *control, *nctl = NULL; 102844249214SRandall Stewart uint32_t next_to_del; 102944249214SRandall Stewart uint32_t pd_point; 103044249214SRandall Stewart int ret = 0; 103144249214SRandall Stewart 1032810ec536SMichael Tuexen if (stcb->sctp_socket) { 1033d4d23375SMichael Tuexen pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket) >> SCTP_PARTIAL_DELIVERY_SHIFT, 1034810ec536SMichael Tuexen stcb->sctp_ep->partial_delivery_point); 1035810ec536SMichael Tuexen } else { 1036810ec536SMichael Tuexen pd_point = stcb->sctp_ep->partial_delivery_point; 1037810ec536SMichael Tuexen } 103844249214SRandall Stewart control = TAILQ_FIRST(&strm->uno_inqueue); 1039d1ea5fa9SMichael Tuexen 104044249214SRandall Stewart if ((control) && 104144249214SRandall Stewart (asoc->idata_supported == 0)) { 104244249214SRandall Stewart /* Special handling needed for "old" data format */ 1043d1ea5fa9SMichael Tuexen if (sctp_handle_old_unordered_data(stcb, asoc, strm, control, pd_point, inp_read_lock_held)) { 104444249214SRandall Stewart goto done_un; 1045f8829a4aSRandall Stewart } 1046f8829a4aSRandall Stewart } 104744249214SRandall Stewart if (strm->pd_api_started) { 104844249214SRandall Stewart /* Can't add more */ 104944249214SRandall Stewart return (0); 105044249214SRandall Stewart } 105144249214SRandall Stewart while (control) { 1052f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_XXX, "Looking at control: %p e(%d) ssn: %u top_fsn: %u inc_fsn: %u -uo\n", 105344249214SRandall Stewart control, control->end_added, control->sinfo_ssn, control->top_fsn, control->fsn_included); 105444249214SRandall Stewart nctl = TAILQ_NEXT(control, next_instrm); 105544249214SRandall Stewart if (control->end_added) { 105644249214SRandall Stewart /* We just put the last bit on */ 105744249214SRandall Stewart if (control->on_strm_q) { 105898d5fd97SMichael Tuexen #ifdef INVARIANTS 105944249214SRandall Stewart if (control->on_strm_q != SCTP_ON_UNORDERED) { 106044249214SRandall Stewart panic("Huh control: %p on_q: %d -- not unordered?", 106144249214SRandall Stewart control, control->on_strm_q); 106244249214SRandall Stewart } 106398d5fd97SMichael Tuexen #endif 106426f0250aSMichael Tuexen SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); 106544249214SRandall Stewart TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); 106644249214SRandall Stewart control->on_strm_q = 0; 106744249214SRandall Stewart } 106844249214SRandall Stewart if (control->on_read_q == 0) { 106944249214SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 107044249214SRandall Stewart control, 107144249214SRandall Stewart &stcb->sctp_socket->so_rcv, control->end_added, 1072d1ea5fa9SMichael Tuexen inp_read_lock_held, SCTP_SO_NOT_LOCKED); 107344249214SRandall Stewart } 1074f8829a4aSRandall Stewart } else { 107544249214SRandall Stewart /* Can we do a PD-API for this un-ordered guy? */ 107644249214SRandall Stewart if ((control->length >= pd_point) && (strm->pd_api_started == 0)) { 107744249214SRandall Stewart strm->pd_api_started = 1; 107844249214SRandall Stewart control->pdapi_started = 1; 107944249214SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 108044249214SRandall Stewart control, 108144249214SRandall Stewart &stcb->sctp_socket->so_rcv, control->end_added, 1082d1ea5fa9SMichael Tuexen inp_read_lock_held, SCTP_SO_NOT_LOCKED); 108344249214SRandall Stewart 108444249214SRandall Stewart break; 1085139bc87fSRandall Stewart } 1086f8829a4aSRandall Stewart } 108744249214SRandall Stewart control = nctl; 108844249214SRandall Stewart } 108944249214SRandall Stewart done_un: 109044249214SRandall Stewart control = TAILQ_FIRST(&strm->inqueue); 109144249214SRandall Stewart if (strm->pd_api_started) { 109244249214SRandall Stewart /* Can't add more */ 109344249214SRandall Stewart return (0); 109444249214SRandall Stewart } 109544249214SRandall Stewart if (control == NULL) { 109644249214SRandall Stewart return (ret); 109744249214SRandall Stewart } 109844249214SRandall Stewart if (strm->last_sequence_delivered == control->sinfo_ssn) { 109944249214SRandall Stewart /* 110044249214SRandall Stewart * Ok the guy at the top was being partially delivered 110144249214SRandall Stewart * completed, so we remove it. Note the pd_api flag was 110244249214SRandall Stewart * taken off when the chunk was merged on in 110344249214SRandall Stewart * sctp_queue_data_for_reasm below. 110444249214SRandall Stewart */ 110544249214SRandall Stewart nctl = TAILQ_NEXT(control, next_instrm); 110644249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1107f2ea2a2dSMichael Tuexen "Looking at control: %p e(%d) ssn: %u top_fsn: %u inc_fsn: %u (lastdel: %u)- o\n", 110844249214SRandall Stewart control, control->end_added, control->sinfo_ssn, 110944249214SRandall Stewart control->top_fsn, control->fsn_included, 111044249214SRandall Stewart strm->last_sequence_delivered); 111144249214SRandall Stewart if (control->end_added) { 111244249214SRandall Stewart if (control->on_strm_q) { 111398d5fd97SMichael Tuexen #ifdef INVARIANTS 111444249214SRandall Stewart if (control->on_strm_q != SCTP_ON_ORDERED) { 111544249214SRandall Stewart panic("Huh control: %p on_q: %d -- not ordered?", 111644249214SRandall Stewart control, control->on_strm_q); 111744249214SRandall Stewart } 111898d5fd97SMichael Tuexen #endif 111926f0250aSMichael Tuexen SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); 112044249214SRandall Stewart TAILQ_REMOVE(&strm->inqueue, control, next_instrm); 112144249214SRandall Stewart control->on_strm_q = 0; 112244249214SRandall Stewart } 1123c09a1534SMichael Tuexen if (strm->pd_api_started && control->pdapi_started) { 1124c09a1534SMichael Tuexen control->pdapi_started = 0; 1125c09a1534SMichael Tuexen strm->pd_api_started = 0; 1126c09a1534SMichael Tuexen } 112744249214SRandall Stewart if (control->on_read_q == 0) { 112844249214SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 112944249214SRandall Stewart control, 113044249214SRandall Stewart &stcb->sctp_socket->so_rcv, control->end_added, 1131d1ea5fa9SMichael Tuexen inp_read_lock_held, SCTP_SO_NOT_LOCKED); 113244249214SRandall Stewart } 113344249214SRandall Stewart control = nctl; 113444249214SRandall Stewart } 113544249214SRandall Stewart } 113644249214SRandall Stewart if (strm->pd_api_started) { 113744249214SRandall Stewart /* 113844249214SRandall Stewart * Can't add more must have gotten an un-ordered above being 113944249214SRandall Stewart * partially delivered. 114044249214SRandall Stewart */ 114144249214SRandall Stewart return (0); 114244249214SRandall Stewart } 114344249214SRandall Stewart deliver_more: 114444249214SRandall Stewart next_to_del = strm->last_sequence_delivered + 1; 114544249214SRandall Stewart if (control) { 114644249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1147f2ea2a2dSMichael Tuexen "Looking at control: %p e(%d) ssn: %u top_fsn: %u inc_fsn: %u (nxtdel: %u)- o\n", 114844249214SRandall Stewart control, control->end_added, control->sinfo_ssn, control->top_fsn, control->fsn_included, 114944249214SRandall Stewart next_to_del); 115044249214SRandall Stewart nctl = TAILQ_NEXT(control, next_instrm); 115144249214SRandall Stewart if ((control->sinfo_ssn == next_to_del) && 115244249214SRandall Stewart (control->first_frag_seen)) { 1153c09a1534SMichael Tuexen int done; 1154c09a1534SMichael Tuexen 115544249214SRandall Stewart /* Ok we can deliver it onto the stream. */ 115644249214SRandall Stewart if (control->end_added) { 115744249214SRandall Stewart /* We are done with it afterwards */ 115844249214SRandall Stewart if (control->on_strm_q) { 115998d5fd97SMichael Tuexen #ifdef INVARIANTS 116044249214SRandall Stewart if (control->on_strm_q != SCTP_ON_ORDERED) { 116144249214SRandall Stewart panic("Huh control: %p on_q: %d -- not ordered?", 116244249214SRandall Stewart control, control->on_strm_q); 116344249214SRandall Stewart } 116498d5fd97SMichael Tuexen #endif 116526f0250aSMichael Tuexen SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); 116644249214SRandall Stewart TAILQ_REMOVE(&strm->inqueue, control, next_instrm); 116744249214SRandall Stewart control->on_strm_q = 0; 116844249214SRandall Stewart } 116944249214SRandall Stewart ret++; 117044249214SRandall Stewart } 117144249214SRandall Stewart if (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { 117244249214SRandall Stewart /* 117344249214SRandall Stewart * A singleton now slipping through - mark 117444249214SRandall Stewart * it non-revokable too 117544249214SRandall Stewart */ 117644249214SRandall Stewart sctp_mark_non_revokable(asoc, control->sinfo_tsn); 117744249214SRandall Stewart } else if (control->end_added == 0) { 117844249214SRandall Stewart /* 117944249214SRandall Stewart * Check if we can defer adding until its 118044249214SRandall Stewart * all there 118144249214SRandall Stewart */ 118244249214SRandall Stewart if ((control->length < pd_point) || (strm->pd_api_started)) { 118344249214SRandall Stewart /* 118444249214SRandall Stewart * Don't need it or cannot add more 118544249214SRandall Stewart * (one being delivered that way) 118644249214SRandall Stewart */ 118744249214SRandall Stewart goto out; 118844249214SRandall Stewart } 118944249214SRandall Stewart } 1190c09a1534SMichael Tuexen done = (control->end_added) && (control->last_frag_seen); 119144249214SRandall Stewart if (control->on_read_q == 0) { 119244249214SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 119344249214SRandall Stewart control, 119444249214SRandall Stewart &stcb->sctp_socket->so_rcv, control->end_added, 1195d1ea5fa9SMichael Tuexen inp_read_lock_held, SCTP_SO_NOT_LOCKED); 119644249214SRandall Stewart } 119744249214SRandall Stewart strm->last_sequence_delivered = next_to_del; 1198c09a1534SMichael Tuexen if (done) { 119944249214SRandall Stewart control = nctl; 120044249214SRandall Stewart goto deliver_more; 120144249214SRandall Stewart } else { 120244249214SRandall Stewart /* We are now doing PD API */ 120344249214SRandall Stewart strm->pd_api_started = 1; 120444249214SRandall Stewart control->pdapi_started = 1; 120544249214SRandall Stewart } 120644249214SRandall Stewart } 120744249214SRandall Stewart } 120844249214SRandall Stewart out: 120944249214SRandall Stewart return (ret); 121044249214SRandall Stewart } 121144249214SRandall Stewart 1212d1ea5fa9SMichael Tuexen 121344249214SRandall Stewart void 121444249214SRandall Stewart sctp_add_chk_to_control(struct sctp_queued_to_read *control, 121544249214SRandall Stewart struct sctp_stream_in *strm, 121644249214SRandall Stewart struct sctp_tcb *stcb, struct sctp_association *asoc, 1217d1ea5fa9SMichael Tuexen struct sctp_tmit_chunk *chk, int hold_rlock) 121844249214SRandall Stewart { 121944249214SRandall Stewart /* 122044249214SRandall Stewart * Given a control and a chunk, merge the data from the chk onto the 122144249214SRandall Stewart * control and free up the chunk resources. 122244249214SRandall Stewart */ 122344249214SRandall Stewart int i_locked = 0; 122444249214SRandall Stewart 1225d1ea5fa9SMichael Tuexen if (control->on_read_q && (hold_rlock == 0)) { 122644249214SRandall Stewart /* 122744249214SRandall Stewart * Its being pd-api'd so we must do some locks. 122844249214SRandall Stewart */ 122944249214SRandall Stewart SCTP_INP_READ_LOCK(stcb->sctp_ep); 123044249214SRandall Stewart i_locked = 1; 123144249214SRandall Stewart } 123244249214SRandall Stewart if (control->data == NULL) { 123344249214SRandall Stewart control->data = chk->data; 123444249214SRandall Stewart sctp_setup_tail_pointer(control); 123544249214SRandall Stewart } else { 123644249214SRandall Stewart sctp_add_to_tail_pointer(control, chk->data); 123744249214SRandall Stewart } 123844249214SRandall Stewart control->fsn_included = chk->rec.data.fsn_num; 123944249214SRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 124044249214SRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 124144249214SRandall Stewart sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq); 124244249214SRandall Stewart chk->data = NULL; 124344249214SRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 124444249214SRandall Stewart control->first_frag_seen = 1; 124544249214SRandall Stewart } 124644249214SRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 124744249214SRandall Stewart /* Its complete */ 124844249214SRandall Stewart if ((control->on_strm_q) && (control->on_read_q)) { 124944249214SRandall Stewart if (control->pdapi_started) { 125044249214SRandall Stewart control->pdapi_started = 0; 125144249214SRandall Stewart strm->pd_api_started = 0; 125244249214SRandall Stewart } 125344249214SRandall Stewart if (control->on_strm_q == SCTP_ON_UNORDERED) { 125444249214SRandall Stewart /* Unordered */ 125544249214SRandall Stewart TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); 125644249214SRandall Stewart control->on_strm_q = 0; 125744249214SRandall Stewart } else if (control->on_strm_q == SCTP_ON_ORDERED) { 125844249214SRandall Stewart /* Ordered */ 125944249214SRandall Stewart TAILQ_REMOVE(&strm->inqueue, control, next_instrm); 126044249214SRandall Stewart control->on_strm_q = 0; 126198d5fd97SMichael Tuexen #ifdef INVARIANTS 126244249214SRandall Stewart } else if (control->on_strm_q) { 126344249214SRandall Stewart panic("Unknown state on ctrl: %p on_strm_q: %d", control, 126444249214SRandall Stewart control->on_strm_q); 126598d5fd97SMichael Tuexen #endif 126644249214SRandall Stewart } 126744249214SRandall Stewart } 126844249214SRandall Stewart control->end_added = 1; 126944249214SRandall Stewart control->last_frag_seen = 1; 127044249214SRandall Stewart } 127144249214SRandall Stewart if (i_locked) { 127244249214SRandall Stewart SCTP_INP_READ_UNLOCK(stcb->sctp_ep); 127344249214SRandall Stewart } 127444249214SRandall Stewart sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); 1275f8829a4aSRandall Stewart } 1276f8829a4aSRandall Stewart 1277f8829a4aSRandall Stewart /* 1278f8829a4aSRandall Stewart * Dump onto the re-assembly queue, in its proper place. After dumping on the 1279f8829a4aSRandall Stewart * queue, see if anthing can be delivered. If so pull it off (or as much as 1280f8829a4aSRandall Stewart * we can. If we run out of space then we must dump what we can and set the 1281f8829a4aSRandall Stewart * appropriate flag to say we queued what we could. 1282f8829a4aSRandall Stewart */ 1283f8829a4aSRandall Stewart static void 1284f8829a4aSRandall Stewart sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, 128544249214SRandall Stewart struct sctp_stream_in *strm, 128644249214SRandall Stewart struct sctp_queued_to_read *control, 128744249214SRandall Stewart struct sctp_tmit_chunk *chk, 128844249214SRandall Stewart int created_control, 128944249214SRandall Stewart int *abort_flag, uint32_t tsn) 1290f8829a4aSRandall Stewart { 129144249214SRandall Stewart uint32_t next_fsn; 129244249214SRandall Stewart struct sctp_tmit_chunk *at, *nat; 1293c09a1534SMichael Tuexen int do_wakeup, unordered; 1294f8829a4aSRandall Stewart 1295f8829a4aSRandall Stewart /* 129644249214SRandall Stewart * For old un-ordered data chunks. 1297f8829a4aSRandall Stewart */ 129844249214SRandall Stewart if ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) { 129944249214SRandall Stewart unordered = 1; 1300f8829a4aSRandall Stewart } else { 130144249214SRandall Stewart unordered = 0; 130244249214SRandall Stewart } 130344249214SRandall Stewart /* Must be added to the stream-in queue */ 130444249214SRandall Stewart if (created_control) { 130544249214SRandall Stewart if (sctp_place_control_in_stream(strm, asoc, control)) { 130644249214SRandall Stewart /* Duplicate SSN? */ 1307d1ea5fa9SMichael Tuexen sctp_clean_up_control(stcb, control); 1308b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, chk, 130944249214SRandall Stewart abort_flag, 131044249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_6); 131144249214SRandall Stewart return; 131244249214SRandall Stewart } 131344249214SRandall Stewart if ((tsn == (asoc->cumulative_tsn + 1) && (asoc->idata_supported == 0))) { 1314f8829a4aSRandall Stewart /* 131544249214SRandall Stewart * Ok we created this control and now lets validate 131644249214SRandall Stewart * that its legal i.e. there is a B bit set, if not 131744249214SRandall Stewart * and we have up to the cum-ack then its invalid. 131844249214SRandall Stewart */ 131944249214SRandall Stewart if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { 1320b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, chk, 132144249214SRandall Stewart abort_flag, 132244249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_7); 132344249214SRandall Stewart return; 132444249214SRandall Stewart } 132544249214SRandall Stewart } 132644249214SRandall Stewart } 1327a39ddef0SMichael Tuexen if ((asoc->idata_supported == 0) && (unordered == 1)) { 1328d1ea5fa9SMichael Tuexen sctp_inject_old_unordered_data(stcb, asoc, control, chk, abort_flag); 132944249214SRandall Stewart return; 133044249214SRandall Stewart } 133144249214SRandall Stewart /* 133244249214SRandall Stewart * Ok we must queue the chunk into the reasembly portion: o if its 133344249214SRandall Stewart * the first it goes to the control mbuf. o if its not first but the 133444249214SRandall Stewart * next in sequence it goes to the control, and each succeeding one 133544249214SRandall Stewart * in order also goes. o if its not in order we place it on the list 133644249214SRandall Stewart * in its place. 133744249214SRandall Stewart */ 133844249214SRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 133944249214SRandall Stewart /* Its the very first one. */ 134044249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1341f2ea2a2dSMichael Tuexen "chunk is a first fsn: %u becomes fsn_included\n", 134244249214SRandall Stewart chk->rec.data.fsn_num); 134344249214SRandall Stewart if (control->first_frag_seen) { 134444249214SRandall Stewart /* 134544249214SRandall Stewart * Error on senders part, they either sent us two 134644249214SRandall Stewart * data chunks with FIRST, or they sent two 134744249214SRandall Stewart * un-ordered chunks that were fragmented at the 134844249214SRandall Stewart * same time in the same stream. 134944249214SRandall Stewart */ 1350b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, chk, 135144249214SRandall Stewart abort_flag, 135244249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_8); 135344249214SRandall Stewart return; 135444249214SRandall Stewart } 135544249214SRandall Stewart control->first_frag_seen = 1; 135644249214SRandall Stewart control->fsn_included = chk->rec.data.fsn_num; 135744249214SRandall Stewart control->data = chk->data; 135844249214SRandall Stewart sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq); 135944249214SRandall Stewart chk->data = NULL; 136044249214SRandall Stewart sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); 136144249214SRandall Stewart sctp_setup_tail_pointer(control); 136244249214SRandall Stewart } else { 136344249214SRandall Stewart /* Place the chunk in our list */ 136444249214SRandall Stewart int inserted = 0; 136544249214SRandall Stewart 136644249214SRandall Stewart if (control->last_frag_seen == 0) { 136744249214SRandall Stewart /* Still willing to raise highest FSN seen */ 136844249214SRandall Stewart if (SCTP_TSN_GT(chk->rec.data.fsn_num, control->top_fsn)) { 136944249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1370f2ea2a2dSMichael Tuexen "We have a new top_fsn: %u\n", 137144249214SRandall Stewart chk->rec.data.fsn_num); 137244249214SRandall Stewart control->top_fsn = chk->rec.data.fsn_num; 137344249214SRandall Stewart } 137444249214SRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 137544249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1376f2ea2a2dSMichael Tuexen "The last fsn is now in place fsn: %u\n", 137744249214SRandall Stewart chk->rec.data.fsn_num); 137844249214SRandall Stewart control->last_frag_seen = 1; 137944249214SRandall Stewart } 138044249214SRandall Stewart if (asoc->idata_supported || control->first_frag_seen) { 138144249214SRandall Stewart /* 138244249214SRandall Stewart * For IDATA we always check since we know 138344249214SRandall Stewart * that the first fragment is 0. For old 138444249214SRandall Stewart * DATA we have to receive the first before 1385cd0a4ff6SPedro F. Giffuni * we know the first FSN (which is the TSN). 138644249214SRandall Stewart */ 138744249214SRandall Stewart if (SCTP_TSN_GE(control->fsn_included, chk->rec.data.fsn_num)) { 138844249214SRandall Stewart /* 138944249214SRandall Stewart * We have already delivered up to 139044249214SRandall Stewart * this so its a dup 139144249214SRandall Stewart */ 1392b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, chk, 139344249214SRandall Stewart abort_flag, 139444249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_9); 139544249214SRandall Stewart return; 139644249214SRandall Stewart } 139744249214SRandall Stewart } 139844249214SRandall Stewart } else { 139944249214SRandall Stewart if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { 140044249214SRandall Stewart /* Second last? huh? */ 140144249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1402f2ea2a2dSMichael Tuexen "Duplicate last fsn: %u (top: %u) -- abort\n", 140344249214SRandall Stewart chk->rec.data.fsn_num, control->top_fsn); 1404b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, 140544249214SRandall Stewart chk, abort_flag, 140644249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_10); 140744249214SRandall Stewart return; 140844249214SRandall Stewart } 140944249214SRandall Stewart if (asoc->idata_supported || control->first_frag_seen) { 141044249214SRandall Stewart /* 141144249214SRandall Stewart * For IDATA we always check since we know 141244249214SRandall Stewart * that the first fragment is 0. For old 141344249214SRandall Stewart * DATA we have to receive the first before 1414cd0a4ff6SPedro F. Giffuni * we know the first FSN (which is the TSN). 141544249214SRandall Stewart */ 141644249214SRandall Stewart 141744249214SRandall Stewart if (SCTP_TSN_GE(control->fsn_included, chk->rec.data.fsn_num)) { 141844249214SRandall Stewart /* 141944249214SRandall Stewart * We have already delivered up to 142044249214SRandall Stewart * this so its a dup 142144249214SRandall Stewart */ 142244249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1423f2ea2a2dSMichael Tuexen "New fsn: %u is already seen in included_fsn: %u -- abort\n", 142444249214SRandall Stewart chk->rec.data.fsn_num, control->fsn_included); 1425b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, chk, 142644249214SRandall Stewart abort_flag, 142744249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_11); 142844249214SRandall Stewart return; 142944249214SRandall Stewart } 143044249214SRandall Stewart } 143144249214SRandall Stewart /* 143244249214SRandall Stewart * validate not beyond top FSN if we have seen last 1433f8829a4aSRandall Stewart * one 1434f8829a4aSRandall Stewart */ 143544249214SRandall Stewart if (SCTP_TSN_GT(chk->rec.data.fsn_num, control->top_fsn)) { 143644249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1437f2ea2a2dSMichael Tuexen "New fsn: %u is beyond or at top_fsn: %u -- abort\n", 143844249214SRandall Stewart chk->rec.data.fsn_num, 143944249214SRandall Stewart control->top_fsn); 1440b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, chk, 144144249214SRandall Stewart abort_flag, 144244249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_12); 144344249214SRandall Stewart return; 144444249214SRandall Stewart } 144544249214SRandall Stewart } 144644249214SRandall Stewart /* 144744249214SRandall Stewart * If we reach here, we need to place the new chunk in the 144844249214SRandall Stewart * reassembly for this control. 144944249214SRandall Stewart */ 145044249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1451f2ea2a2dSMichael Tuexen "chunk is a not first fsn: %u needs to be inserted\n", 145244249214SRandall Stewart chk->rec.data.fsn_num); 145344249214SRandall Stewart TAILQ_FOREACH(at, &control->reasm, sctp_next) { 145444249214SRandall Stewart if (SCTP_TSN_GT(at->rec.data.fsn_num, chk->rec.data.fsn_num)) { 145544249214SRandall Stewart /* 145644249214SRandall Stewart * This one in queue is bigger than the new 145744249214SRandall Stewart * one, insert the new one before at. 145844249214SRandall Stewart */ 145944249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1460f2ea2a2dSMichael Tuexen "Insert it before fsn: %u\n", 146144249214SRandall Stewart at->rec.data.fsn_num); 1462f8829a4aSRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 1463f8829a4aSRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 146444249214SRandall Stewart TAILQ_INSERT_BEFORE(at, chk, sctp_next); 146544249214SRandall Stewart inserted = 1; 146644249214SRandall Stewart break; 146744249214SRandall Stewart } else if (at->rec.data.fsn_num == chk->rec.data.fsn_num) { 146844249214SRandall Stewart /* 146944249214SRandall Stewart * Gak, He sent me a duplicate str seq 147044249214SRandall Stewart * number 147144249214SRandall Stewart */ 147244249214SRandall Stewart /* 147344249214SRandall Stewart * foo bar, I guess I will just free this 147444249214SRandall Stewart * new guy, should we abort too? FIX ME 147544249214SRandall Stewart * MAYBE? Or it COULD be that the SSN's have 147644249214SRandall Stewart * wrapped. Maybe I should compare to TSN 147744249214SRandall Stewart * somehow... sigh for now just blow away 147844249214SRandall Stewart * the chunk! 147944249214SRandall Stewart */ 148044249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1481f2ea2a2dSMichael Tuexen "Duplicate to fsn: %u -- abort\n", 148244249214SRandall Stewart at->rec.data.fsn_num); 1483b1deed45SMichael Tuexen sctp_abort_in_reasm(stcb, control, 148444249214SRandall Stewart chk, abort_flag, 148544249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_13); 148644249214SRandall Stewart return; 148744249214SRandall Stewart } 148844249214SRandall Stewart } 148944249214SRandall Stewart if (inserted == 0) { 149044249214SRandall Stewart /* Goes on the end */ 1491f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_XXX, "Inserting at tail of list fsn: %u\n", 149244249214SRandall Stewart chk->rec.data.fsn_num); 149344249214SRandall Stewart asoc->size_on_reasm_queue += chk->send_size; 149444249214SRandall Stewart sctp_ucount_incr(asoc->cnt_on_reasm_queue); 149544249214SRandall Stewart TAILQ_INSERT_TAIL(&control->reasm, chk, sctp_next); 149644249214SRandall Stewart } 149744249214SRandall Stewart } 149844249214SRandall Stewart /* 149944249214SRandall Stewart * Ok lets see if we can suck any up into the control structure that 150044249214SRandall Stewart * are in seq if it makes sense. 150144249214SRandall Stewart */ 1502c09a1534SMichael Tuexen do_wakeup = 0; 150344249214SRandall Stewart /* 150444249214SRandall Stewart * If the first fragment has not been seen there is no sense in 150544249214SRandall Stewart * looking. 150644249214SRandall Stewart */ 150744249214SRandall Stewart if (control->first_frag_seen) { 150844249214SRandall Stewart next_fsn = control->fsn_included + 1; 150944249214SRandall Stewart TAILQ_FOREACH_SAFE(at, &control->reasm, sctp_next, nat) { 151044249214SRandall Stewart if (at->rec.data.fsn_num == next_fsn) { 151144249214SRandall Stewart /* We can add this one now to the control */ 151244249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 1513f2ea2a2dSMichael Tuexen "Adding more to control: %p at: %p fsn: %u next_fsn: %u included: %u\n", 151444249214SRandall Stewart control, at, 151544249214SRandall Stewart at->rec.data.fsn_num, 151644249214SRandall Stewart next_fsn, control->fsn_included); 151744249214SRandall Stewart TAILQ_REMOVE(&control->reasm, at, sctp_next); 1518d1ea5fa9SMichael Tuexen sctp_add_chk_to_control(control, strm, stcb, asoc, at, SCTP_READ_LOCK_NOT_HELD); 1519c09a1534SMichael Tuexen if (control->on_read_q) { 1520c09a1534SMichael Tuexen do_wakeup = 1; 1521c09a1534SMichael Tuexen } 152244249214SRandall Stewart next_fsn++; 152344249214SRandall Stewart if (control->end_added && control->pdapi_started) { 152444249214SRandall Stewart if (strm->pd_api_started) { 152544249214SRandall Stewart strm->pd_api_started = 0; 152644249214SRandall Stewart control->pdapi_started = 0; 152744249214SRandall Stewart } 152844249214SRandall Stewart if (control->on_read_q == 0) { 152944249214SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 153044249214SRandall Stewart control, 153144249214SRandall Stewart &stcb->sctp_socket->so_rcv, control->end_added, 153244249214SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 1533c09a1534SMichael Tuexen do_wakeup = 1; 153444249214SRandall Stewart } 153544249214SRandall Stewart break; 153644249214SRandall Stewart } 153744249214SRandall Stewart } else { 1538f8829a4aSRandall Stewart break; 1539f8829a4aSRandall Stewart } 1540f8829a4aSRandall Stewart } 1541f8829a4aSRandall Stewart } 1542c09a1534SMichael Tuexen if (do_wakeup) { 154344249214SRandall Stewart /* Need to wakeup the reader */ 1544b1deed45SMichael Tuexen sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); 1545f8829a4aSRandall Stewart } 1546f8829a4aSRandall Stewart } 1547f8829a4aSRandall Stewart 154844249214SRandall Stewart static struct sctp_queued_to_read * 1549d1ea5fa9SMichael Tuexen sctp_find_reasm_entry(struct sctp_stream_in *strm, uint32_t msg_id, int ordered, int old) 1550f8829a4aSRandall Stewart { 1551c09a1534SMichael Tuexen struct sctp_queued_to_read *control; 1552f8829a4aSRandall Stewart 155344249214SRandall Stewart if (ordered) { 1554c09a1534SMichael Tuexen TAILQ_FOREACH(control, &strm->inqueue, next_instrm) { 1555c09a1534SMichael Tuexen if (control->msg_id == msg_id) { 155644249214SRandall Stewart break; 155744249214SRandall Stewart } 155844249214SRandall Stewart } 1559f8829a4aSRandall Stewart } else { 156044249214SRandall Stewart if (old) { 1561c09a1534SMichael Tuexen control = TAILQ_FIRST(&strm->uno_inqueue); 1562c09a1534SMichael Tuexen return (control); 1563f8829a4aSRandall Stewart } 1564c09a1534SMichael Tuexen TAILQ_FOREACH(control, &strm->uno_inqueue, next_instrm) { 1565c09a1534SMichael Tuexen if (control->msg_id == msg_id) { 156644249214SRandall Stewart break; 1567f8829a4aSRandall Stewart } 1568f8829a4aSRandall Stewart } 1569f8829a4aSRandall Stewart } 1570c09a1534SMichael Tuexen return (control); 1571f8829a4aSRandall Stewart } 157244249214SRandall Stewart 1573f8829a4aSRandall Stewart static int 1574f8829a4aSRandall Stewart sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, 157544249214SRandall Stewart struct mbuf **m, int offset, int chk_length, 1576f8829a4aSRandall Stewart struct sctp_nets *net, uint32_t * high_tsn, int *abort_flag, 157744249214SRandall Stewart int *break_flag, int last_chunk, uint8_t chtype) 1578f8829a4aSRandall Stewart { 1579f8829a4aSRandall Stewart /* Process a data chunk */ 1580f8829a4aSRandall Stewart /* struct sctp_tmit_chunk *chk; */ 158144249214SRandall Stewart struct sctp_data_chunk *ch; 158244249214SRandall Stewart struct sctp_idata_chunk *nch, chunk_buf; 1583f8829a4aSRandall Stewart struct sctp_tmit_chunk *chk; 158444249214SRandall Stewart uint32_t tsn, fsn, gap, msg_id; 1585f8829a4aSRandall Stewart struct mbuf *dmbuf; 15867215cc1bSMichael Tuexen int the_len; 1587139bc87fSRandall Stewart int need_reasm_check = 0; 158844249214SRandall Stewart uint16_t strmno; 1589ff1ffd74SMichael Tuexen struct mbuf *op_err; 1590ff1ffd74SMichael Tuexen char msg[SCTP_DIAG_INFO_LEN]; 159144249214SRandall Stewart struct sctp_queued_to_read *control = NULL; 1592f42a358aSRandall Stewart uint32_t protocol_id; 1593f42a358aSRandall Stewart uint8_t chunk_flags; 159417205eccSRandall Stewart struct sctp_stream_reset_list *liste; 159544249214SRandall Stewart struct sctp_stream_in *strm; 159644249214SRandall Stewart int ordered; 159744249214SRandall Stewart size_t clen; 159844249214SRandall Stewart int created_control = 0; 159944249214SRandall Stewart uint8_t old_data; 1600f8829a4aSRandall Stewart 1601f8829a4aSRandall Stewart chk = NULL; 160244249214SRandall Stewart if (chtype == SCTP_IDATA) { 160344249214SRandall Stewart nch = (struct sctp_idata_chunk *)sctp_m_getptr(*m, offset, 160444249214SRandall Stewart sizeof(struct sctp_idata_chunk), (uint8_t *) & chunk_buf); 160544249214SRandall Stewart ch = (struct sctp_data_chunk *)nch; 160644249214SRandall Stewart clen = sizeof(struct sctp_idata_chunk); 1607f8829a4aSRandall Stewart tsn = ntohl(ch->dp.tsn); 160844249214SRandall Stewart msg_id = ntohl(nch->dp.msg_id); 1609d1ea5fa9SMichael Tuexen protocol_id = nch->dp.ppid_fsn.protocol_id; 161044249214SRandall Stewart if (ch->ch.chunk_flags & SCTP_DATA_FIRST_FRAG) 161144249214SRandall Stewart fsn = 0; 161244249214SRandall Stewart else 1613e187bac2SMichael Tuexen fsn = ntohl(nch->dp.ppid_fsn.fsn); 161444249214SRandall Stewart old_data = 0; 161544249214SRandall Stewart } else { 161644249214SRandall Stewart ch = (struct sctp_data_chunk *)sctp_m_getptr(*m, offset, 161744249214SRandall Stewart sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); 161844249214SRandall Stewart tsn = ntohl(ch->dp.tsn); 1619d1ea5fa9SMichael Tuexen protocol_id = ch->dp.protocol_id; 162044249214SRandall Stewart clen = sizeof(struct sctp_data_chunk); 162144249214SRandall Stewart fsn = tsn; 162244249214SRandall Stewart msg_id = (uint32_t) (ntohs(ch->dp.stream_sequence)); 162344249214SRandall Stewart nch = NULL; 162444249214SRandall Stewart old_data = 1; 162544249214SRandall Stewart } 1626f42a358aSRandall Stewart chunk_flags = ch->ch.chunk_flags; 162744249214SRandall Stewart if ((size_t)chk_length == clen) { 162844249214SRandall Stewart /* 162944249214SRandall Stewart * Need to send an abort since we had a empty data chunk. 163044249214SRandall Stewart */ 163144249214SRandall Stewart op_err = sctp_generate_no_user_data_cause(ch->dp.tsn); 163244249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_14; 163344249214SRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 163444249214SRandall Stewart *abort_flag = 1; 163544249214SRandall Stewart return (0); 163644249214SRandall Stewart } 1637b3f1ea41SRandall Stewart if ((chunk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) { 1638b3f1ea41SRandall Stewart asoc->send_sack = 1; 1639b3f1ea41SRandall Stewart } 164037f144ebSMichael Tuexen ordered = ((chunk_flags & SCTP_DATA_UNORDERED) == 0); 1641b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 1642c4739e2fSRandall Stewart sctp_log_map(tsn, asoc->cumulative_tsn, asoc->highest_tsn_inside_map, SCTP_MAP_TSN_ENTERS); 164380fefe0aSRandall Stewart } 1644ad81507eSRandall Stewart if (stcb == NULL) { 1645ad81507eSRandall Stewart return (0); 1646ad81507eSRandall Stewart } 164780fefe0aSRandall Stewart SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, ch->ch.chunk_type, tsn); 164820b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->cumulative_tsn, tsn)) { 1649f8829a4aSRandall Stewart /* It is a duplicate */ 1650f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1651f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1652f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1653f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1654f8829a4aSRandall Stewart asoc->numduptsns++; 1655f8829a4aSRandall Stewart } 1656b201f536SRandall Stewart asoc->send_sack = 1; 1657f8829a4aSRandall Stewart return (0); 1658f8829a4aSRandall Stewart } 1659f8829a4aSRandall Stewart /* Calculate the number of TSN's between the base and this TSN */ 1660d50c1d79SRandall Stewart SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn); 1661f8829a4aSRandall Stewart if (gap >= (SCTP_MAPPING_ARRAY << 3)) { 1662f8829a4aSRandall Stewart /* Can't hold the bit in the mapping at max array, toss it */ 1663f8829a4aSRandall Stewart return (0); 1664f8829a4aSRandall Stewart } 1665f8829a4aSRandall Stewart if (gap >= (uint32_t) (asoc->mapping_array_size << 3)) { 1666207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 16670696e120SRandall Stewart if (sctp_expand_mapping_array(asoc, gap)) { 1668f8829a4aSRandall Stewart /* Can't expand, drop it */ 1669f8829a4aSRandall Stewart return (0); 1670f8829a4aSRandall Stewart } 1671f8829a4aSRandall Stewart } 167220b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, *high_tsn)) { 1673f8829a4aSRandall Stewart *high_tsn = tsn; 1674f8829a4aSRandall Stewart } 1675f8829a4aSRandall Stewart /* See if we have received this one already */ 167677acdc25SRandall Stewart if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap) || 167777acdc25SRandall Stewart SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, gap)) { 1678f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdupdata); 1679f8829a4aSRandall Stewart if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { 1680f8829a4aSRandall Stewart /* Record a dup for the next outbound sack */ 1681f8829a4aSRandall Stewart asoc->dup_tsns[asoc->numduptsns] = tsn; 1682f8829a4aSRandall Stewart asoc->numduptsns++; 1683f8829a4aSRandall Stewart } 168442551e99SRandall Stewart asoc->send_sack = 1; 1685f8829a4aSRandall Stewart return (0); 1686f8829a4aSRandall Stewart } 1687f8829a4aSRandall Stewart /* 1688f8829a4aSRandall Stewart * Check to see about the GONE flag, duplicates would cause a sack 1689f8829a4aSRandall Stewart * to be sent up above 1690f8829a4aSRandall Stewart */ 1691ad81507eSRandall Stewart if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || 1692f8829a4aSRandall Stewart (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || 1693ff1ffd74SMichael Tuexen (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET))) { 1694f8829a4aSRandall Stewart /* 1695f8829a4aSRandall Stewart * wait a minute, this guy is gone, there is no longer a 1696f8829a4aSRandall Stewart * receiver. Send peer an ABORT! 1697f8829a4aSRandall Stewart */ 1698ff1ffd74SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_OUT_OF_RESC, ""); 1699a2b42326SMichael Tuexen sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 1700f8829a4aSRandall Stewart *abort_flag = 1; 1701f8829a4aSRandall Stewart return (0); 1702f8829a4aSRandall Stewart } 1703f8829a4aSRandall Stewart /* 1704f8829a4aSRandall Stewart * Now before going further we see if there is room. If NOT then we 1705f8829a4aSRandall Stewart * MAY let one through only IF this TSN is the one we are waiting 1706f8829a4aSRandall Stewart * for on a partial delivery API. 1707f8829a4aSRandall Stewart */ 1708f8829a4aSRandall Stewart 170944249214SRandall Stewart /* Is the stream valid? */ 1710f8829a4aSRandall Stewart strmno = ntohs(ch->dp.stream_id); 171144249214SRandall Stewart 1712f8829a4aSRandall Stewart if (strmno >= asoc->streamincnt) { 171386eda749SMichael Tuexen struct sctp_error_invalid_stream *cause; 1714f8829a4aSRandall Stewart 171586eda749SMichael Tuexen op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_error_invalid_stream), 1716eb1b1807SGleb Smirnoff 0, M_NOWAIT, 1, MT_DATA); 171786eda749SMichael Tuexen if (op_err != NULL) { 1718f8829a4aSRandall Stewart /* add some space up front so prepend will work well */ 171986eda749SMichael Tuexen SCTP_BUF_RESV_UF(op_err, sizeof(struct sctp_chunkhdr)); 172086eda749SMichael Tuexen cause = mtod(op_err, struct sctp_error_invalid_stream *); 1721f8829a4aSRandall Stewart /* 1722f8829a4aSRandall Stewart * Error causes are just param's and this one has 1723f8829a4aSRandall Stewart * two back to back phdr, one with the error type 1724f8829a4aSRandall Stewart * and size, the other with the streamid and a rsvd 1725f8829a4aSRandall Stewart */ 172686eda749SMichael Tuexen SCTP_BUF_LEN(op_err) = sizeof(struct sctp_error_invalid_stream); 172786eda749SMichael Tuexen cause->cause.code = htons(SCTP_CAUSE_INVALID_STREAM); 172886eda749SMichael Tuexen cause->cause.length = htons(sizeof(struct sctp_error_invalid_stream)); 172986eda749SMichael Tuexen cause->stream_id = ch->dp.stream_id; 173086eda749SMichael Tuexen cause->reserved = htons(0); 173186eda749SMichael Tuexen sctp_queue_op_err(stcb, op_err); 1732f8829a4aSRandall Stewart } 1733f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_badsid); 1734207304d4SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1735830d754dSRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 173620b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 1737830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 1738d06c82f1SRandall Stewart } 1739d06c82f1SRandall Stewart if (tsn == (asoc->cumulative_tsn + 1)) { 1740d06c82f1SRandall Stewart /* Update cum-ack */ 1741d06c82f1SRandall Stewart asoc->cumulative_tsn = tsn; 1742d06c82f1SRandall Stewart } 1743f8829a4aSRandall Stewart return (0); 1744f8829a4aSRandall Stewart } 174544249214SRandall Stewart strm = &asoc->strmin[strmno]; 1746f8829a4aSRandall Stewart /* 174744249214SRandall Stewart * If its a fragmented message, lets see if we can find the control 174844249214SRandall Stewart * on the reassembly queues. 1749f8829a4aSRandall Stewart */ 1750*be46a7c5SMichael Tuexen if ((chtype == SCTP_IDATA) && 1751*be46a7c5SMichael Tuexen ((chunk_flags & SCTP_DATA_FIRST_FRAG) == 0) && 1752*be46a7c5SMichael Tuexen (fsn == 0)) { 175344249214SRandall Stewart /* 175444249214SRandall Stewart * The first *must* be fsn 0, and other (middle/end) pieces 1755*be46a7c5SMichael Tuexen * can *not* be fsn 0. XXX: This can happen in case of a 1756*be46a7c5SMichael Tuexen * wrap around. Ignore is for now. 175744249214SRandall Stewart */ 1758*be46a7c5SMichael Tuexen snprintf(msg, sizeof(msg), "FSN zero for MID=%8.8x, but flags=%2.2x", 1759*be46a7c5SMichael Tuexen msg_id, chunk_flags); 176044249214SRandall Stewart goto err_out; 176144249214SRandall Stewart } 1762d1ea5fa9SMichael Tuexen control = sctp_find_reasm_entry(strm, msg_id, ordered, old_data); 176344249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags:0x%x look for control on queues %p\n", 176444249214SRandall Stewart chunk_flags, control); 1765*be46a7c5SMichael Tuexen if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { 1766*be46a7c5SMichael Tuexen /* See if we can find the re-assembly entity */ 1767*be46a7c5SMichael Tuexen if (control != NULL) { 176844249214SRandall Stewart /* We found something, does it belong? */ 176944249214SRandall Stewart if (ordered && (msg_id != control->sinfo_ssn)) { 1770*be46a7c5SMichael Tuexen snprintf(msg, sizeof(msg), "Reassembly problem (MID=%8.8x)", msg_id); 177144249214SRandall Stewart err_out: 177244249214SRandall Stewart op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 177344249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_15; 177444249214SRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 177544249214SRandall Stewart *abort_flag = 1; 177644249214SRandall Stewart return (0); 177744249214SRandall Stewart } 177844249214SRandall Stewart if (ordered && ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED)) { 177944249214SRandall Stewart /* 178044249214SRandall Stewart * We can't have a switched order with an 178144249214SRandall Stewart * unordered chunk 178244249214SRandall Stewart */ 1783*be46a7c5SMichael Tuexen snprintf(msg, sizeof(msg), "All fragments of a user message must be ordered or unordered (TSN=%8.8x)", 1784*be46a7c5SMichael Tuexen tsn); 178544249214SRandall Stewart goto err_out; 178644249214SRandall Stewart } 178744249214SRandall Stewart if (!ordered && (((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) == 0)) { 178844249214SRandall Stewart /* 178944249214SRandall Stewart * We can't have a switched unordered with a 179044249214SRandall Stewart * ordered chunk 179144249214SRandall Stewart */ 1792*be46a7c5SMichael Tuexen snprintf(msg, sizeof(msg), "All fragments of a user message must be ordered or unordered (TSN=%8.8x)", 1793*be46a7c5SMichael Tuexen tsn); 179444249214SRandall Stewart goto err_out; 179544249214SRandall Stewart } 179644249214SRandall Stewart } 179744249214SRandall Stewart } else { 179844249214SRandall Stewart /* 179944249214SRandall Stewart * Its a complete segment. Lets validate we don't have a 180044249214SRandall Stewart * re-assembly going on with the same Stream/Seq (for 180144249214SRandall Stewart * ordered) or in the same Stream for unordered. 180244249214SRandall Stewart */ 1803*be46a7c5SMichael Tuexen if (control != NULL) { 1804*be46a7c5SMichael Tuexen if (ordered || (old_data == 0)) { 1805f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags: 0x%x dup detected on msg_id: %u\n", 1806*be46a7c5SMichael Tuexen chunk_flags, msg_id); 1807*be46a7c5SMichael Tuexen snprintf(msg, sizeof(msg), "Duplicate MID=%8.8x detected.", msg_id); 180844249214SRandall Stewart goto err_out; 1809*be46a7c5SMichael Tuexen } else { 1810*be46a7c5SMichael Tuexen if ((tsn == control->fsn_included + 1) && 1811*be46a7c5SMichael Tuexen (control->end_added == 0)) { 1812*be46a7c5SMichael Tuexen snprintf(msg, sizeof(msg), "Illegal message sequence, missing end for MID: %8.8x", control->fsn_included); 1813*be46a7c5SMichael Tuexen goto err_out; 1814*be46a7c5SMichael Tuexen } else { 1815*be46a7c5SMichael Tuexen control = NULL; 1816*be46a7c5SMichael Tuexen } 1817*be46a7c5SMichael Tuexen } 181844249214SRandall Stewart } 181944249214SRandall Stewart } 182044249214SRandall Stewart /* now do the tests */ 182144249214SRandall Stewart if (((asoc->cnt_on_all_streams + 182244249214SRandall Stewart asoc->cnt_on_reasm_queue + 182344249214SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) || 182444249214SRandall Stewart (((int)asoc->my_rwnd) <= 0)) { 182544249214SRandall Stewart /* 182644249214SRandall Stewart * When we have NO room in the rwnd we check to make sure 182744249214SRandall Stewart * the reader is doing its job... 182844249214SRandall Stewart */ 182944249214SRandall Stewart if (stcb->sctp_socket->so_rcv.sb_cc) { 183044249214SRandall Stewart /* some to read, wake-up */ 183144249214SRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 183244249214SRandall Stewart struct socket *so; 183344249214SRandall Stewart 183444249214SRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 183544249214SRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 183644249214SRandall Stewart SCTP_TCB_UNLOCK(stcb); 183744249214SRandall Stewart SCTP_SOCKET_LOCK(so, 1); 183844249214SRandall Stewart SCTP_TCB_LOCK(stcb); 183944249214SRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 184044249214SRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 184144249214SRandall Stewart /* assoc was freed while we were unlocked */ 184244249214SRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 184344249214SRandall Stewart return (0); 184444249214SRandall Stewart } 184544249214SRandall Stewart #endif 184644249214SRandall Stewart sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket); 184744249214SRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 184844249214SRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 184944249214SRandall Stewart #endif 185044249214SRandall Stewart } 185144249214SRandall Stewart /* now is it in the mapping array of what we have accepted? */ 185244249214SRandall Stewart if (nch == NULL) { 185344249214SRandall Stewart if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map) && 185444249214SRandall Stewart SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 185544249214SRandall Stewart /* Nope not in the valid range dump it */ 185644249214SRandall Stewart dump_packet: 185744249214SRandall Stewart sctp_set_rwnd(stcb, asoc); 185844249214SRandall Stewart if ((asoc->cnt_on_all_streams + 185944249214SRandall Stewart asoc->cnt_on_reasm_queue + 186044249214SRandall Stewart asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) { 186144249214SRandall Stewart SCTP_STAT_INCR(sctps_datadropchklmt); 186244249214SRandall Stewart } else { 186344249214SRandall Stewart SCTP_STAT_INCR(sctps_datadroprwnd); 186444249214SRandall Stewart } 186544249214SRandall Stewart *break_flag = 1; 186644249214SRandall Stewart return (0); 186744249214SRandall Stewart } 186844249214SRandall Stewart } else { 186944249214SRandall Stewart if (control == NULL) { 187044249214SRandall Stewart goto dump_packet; 187144249214SRandall Stewart } 187244249214SRandall Stewart if (SCTP_TSN_GT(fsn, control->top_fsn)) { 187344249214SRandall Stewart goto dump_packet; 187444249214SRandall Stewart } 187544249214SRandall Stewart } 187644249214SRandall Stewart } 1877f42a358aSRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 187818e198d3SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 187918e198d3SRandall Stewart if (asoc->tsn_in_at >= SCTP_TSN_LOG_SIZE) { 188018e198d3SRandall Stewart asoc->tsn_in_at = 0; 188118e198d3SRandall Stewart asoc->tsn_in_wrapped = 1; 188218e198d3SRandall Stewart } 1883f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].tsn = tsn; 1884f42a358aSRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].strm = strmno; 188544249214SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].seq = msg_id; 1886f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].sz = chk_length; 1887f1f73e57SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].flgs = chunk_flags; 188818e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].stcb = (void *)stcb; 188918e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_pos = asoc->tsn_in_at; 189018e198d3SRandall Stewart asoc->in_tsnlog[asoc->tsn_in_at].in_out = 1; 1891f42a358aSRandall Stewart asoc->tsn_in_at++; 1892f42a358aSRandall Stewart #endif 189344249214SRandall Stewart /* 189444249214SRandall Stewart * Before we continue lets validate that we are not being fooled by 189544249214SRandall Stewart * an evil attacker. We can only have Nk chunks based on our TSN 189644249214SRandall Stewart * spread allowed by the mapping array N * 8 bits, so there is no 189744249214SRandall Stewart * way our stream sequence numbers could have wrapped. We of course 189844249214SRandall Stewart * only validate the FIRST fragment so the bit must be set. 189944249214SRandall Stewart */ 1900f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_FIRST_FRAG) && 1901d61a0ae0SRandall Stewart (TAILQ_EMPTY(&asoc->resetHead)) && 1902f42a358aSRandall Stewart (chunk_flags & SCTP_DATA_UNORDERED) == 0 && 190344249214SRandall Stewart SCTP_MSGID_GE(old_data, asoc->strmin[strmno].last_sequence_delivered, msg_id)) { 1904f8829a4aSRandall Stewart /* The incoming sseq is behind where we last delivered? */ 1905f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ: %u delivered: %u from peer, Abort!\n", 190644249214SRandall Stewart msg_id, asoc->strmin[strmno].last_sequence_delivered); 1907f8829a4aSRandall Stewart 1908ff1ffd74SMichael Tuexen snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x", 1909ff1ffd74SMichael Tuexen asoc->strmin[strmno].last_sequence_delivered, 191044249214SRandall Stewart tsn, strmno, msg_id); 1911ff1ffd74SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 1912b7d130beSMichael Tuexen stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16; 1913ff1ffd74SMichael Tuexen sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 1914f8829a4aSRandall Stewart *abort_flag = 1; 1915f8829a4aSRandall Stewart return (0); 1916f8829a4aSRandall Stewart } 1917f42a358aSRandall Stewart /************************************ 1918f42a358aSRandall Stewart * From here down we may find ch-> invalid 1919f42a358aSRandall Stewart * so its a good idea NOT to use it. 1920f42a358aSRandall Stewart *************************************/ 192144249214SRandall Stewart if (nch) { 192244249214SRandall Stewart the_len = (chk_length - sizeof(struct sctp_idata_chunk)); 192344249214SRandall Stewart } else { 1924f8829a4aSRandall Stewart the_len = (chk_length - sizeof(struct sctp_data_chunk)); 192544249214SRandall Stewart } 1926f8829a4aSRandall Stewart if (last_chunk == 0) { 192744249214SRandall Stewart if (nch) { 192844249214SRandall Stewart dmbuf = SCTP_M_COPYM(*m, 192944249214SRandall Stewart (offset + sizeof(struct sctp_idata_chunk)), 193044249214SRandall Stewart the_len, M_NOWAIT); 193144249214SRandall Stewart } else { 193244b7479bSRandall Stewart dmbuf = SCTP_M_COPYM(*m, 1933f8829a4aSRandall Stewart (offset + sizeof(struct sctp_data_chunk)), 1934eb1b1807SGleb Smirnoff the_len, M_NOWAIT); 193544249214SRandall Stewart } 1936f8829a4aSRandall Stewart #ifdef SCTP_MBUF_LOGGING 1937b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { 19384be807c4SMichael Tuexen sctp_log_mbc(dmbuf, SCTP_MBUF_ICOPY); 1939f8829a4aSRandall Stewart } 1940f8829a4aSRandall Stewart #endif 1941f8829a4aSRandall Stewart } else { 1942f8829a4aSRandall Stewart /* We can steal the last chunk */ 1943139bc87fSRandall Stewart int l_len; 1944139bc87fSRandall Stewart 1945f8829a4aSRandall Stewart dmbuf = *m; 1946f8829a4aSRandall Stewart /* lop off the top part */ 194744249214SRandall Stewart if (nch) { 194844249214SRandall Stewart m_adj(dmbuf, (offset + sizeof(struct sctp_idata_chunk))); 194944249214SRandall Stewart } else { 1950f8829a4aSRandall Stewart m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk))); 195144249214SRandall Stewart } 1952139bc87fSRandall Stewart if (SCTP_BUF_NEXT(dmbuf) == NULL) { 1953139bc87fSRandall Stewart l_len = SCTP_BUF_LEN(dmbuf); 1954139bc87fSRandall Stewart } else { 1955139bc87fSRandall Stewart /* 1956139bc87fSRandall Stewart * need to count up the size hopefully does not hit 1957139bc87fSRandall Stewart * this to often :-0 1958139bc87fSRandall Stewart */ 1959139bc87fSRandall Stewart struct mbuf *lat; 1960139bc87fSRandall Stewart 1961139bc87fSRandall Stewart l_len = 0; 196260990c0cSMichael Tuexen for (lat = dmbuf; lat; lat = SCTP_BUF_NEXT(lat)) { 1963139bc87fSRandall Stewart l_len += SCTP_BUF_LEN(lat); 1964139bc87fSRandall Stewart } 1965139bc87fSRandall Stewart } 1966139bc87fSRandall Stewart if (l_len > the_len) { 1967f8829a4aSRandall Stewart /* Trim the end round bytes off too */ 1968139bc87fSRandall Stewart m_adj(dmbuf, -(l_len - the_len)); 1969f8829a4aSRandall Stewart } 1970f8829a4aSRandall Stewart } 1971f8829a4aSRandall Stewart if (dmbuf == NULL) { 1972f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 1973f8829a4aSRandall Stewart return (0); 1974f8829a4aSRandall Stewart } 197544249214SRandall Stewart /* 197644249214SRandall Stewart * Now no matter what we need a control, get one if we don't have 197744249214SRandall Stewart * one (we may have gotten it above when we found the message was 197844249214SRandall Stewart * fragmented 197944249214SRandall Stewart */ 198044249214SRandall Stewart if (control == NULL) { 198144249214SRandall Stewart sctp_alloc_a_readq(stcb, control); 198244249214SRandall Stewart sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, 198344249214SRandall Stewart protocol_id, 198444249214SRandall Stewart strmno, msg_id, 198544249214SRandall Stewart chunk_flags, 198644249214SRandall Stewart NULL, fsn, msg_id); 198744249214SRandall Stewart if (control == NULL) { 198844249214SRandall Stewart SCTP_STAT_INCR(sctps_nomem); 198944249214SRandall Stewart return (0); 199044249214SRandall Stewart } 199144249214SRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { 199244249214SRandall Stewart control->data = dmbuf; 199344249214SRandall Stewart control->tail_mbuf = NULL; 199444249214SRandall Stewart control->end_added = control->last_frag_seen = control->first_frag_seen = 1; 199544249214SRandall Stewart control->top_fsn = control->fsn_included = fsn; 199644249214SRandall Stewart } 199744249214SRandall Stewart created_control = 1; 199844249214SRandall Stewart } 1999f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags: 0x%x ordered: %d msgid: %u control: %p\n", 200044249214SRandall Stewart chunk_flags, ordered, msg_id, control); 2001f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG && 2002f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->resetHead) && 2003f42a358aSRandall Stewart ((ordered == 0) || 200444249214SRandall Stewart ((uint16_t) (asoc->strmin[strmno].last_sequence_delivered + 1) == msg_id && 2005f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->strmin[strmno].inqueue)))) { 2006f8829a4aSRandall Stewart /* Candidate for express delivery */ 2007f8829a4aSRandall Stewart /* 2008f8829a4aSRandall Stewart * Its not fragmented, No PD-API is up, Nothing in the 2009f8829a4aSRandall Stewart * delivery queue, Its un-ordered OR ordered and the next to 2010f8829a4aSRandall Stewart * deliver AND nothing else is stuck on the stream queue, 2011f8829a4aSRandall Stewart * And there is room for it in the socket buffer. Lets just 2012f8829a4aSRandall Stewart * stuff it up the buffer.... 2013f8829a4aSRandall Stewart */ 20141ea735c8SMichael Tuexen SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 201520b07a4dSMichael Tuexen if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 20161ea735c8SMichael Tuexen asoc->highest_tsn_inside_nr_map = tsn; 20171ea735c8SMichael Tuexen } 2018f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_XXX, "Injecting control: %p to be read (msg_id: %u)\n", 201944249214SRandall Stewart control, msg_id); 202044249214SRandall Stewart 2021cfde3ff7SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 2022cfde3ff7SRandall Stewart control, &stcb->sctp_socket->so_rcv, 2023cfde3ff7SRandall Stewart 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 2024830d754dSRandall Stewart 2025f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { 2026f8829a4aSRandall Stewart /* for ordered, bump what we delivered */ 202744249214SRandall Stewart strm->last_sequence_delivered++; 2028f8829a4aSRandall Stewart } 2029f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvexpress); 2030b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 203144249214SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, msg_id, strmno, 2032f8829a4aSRandall Stewart SCTP_STR_LOG_FROM_EXPRS_DEL); 203380fefe0aSRandall Stewart } 2034f8829a4aSRandall Stewart control = NULL; 2035f8829a4aSRandall Stewart goto finish_express_del; 2036f8829a4aSRandall Stewart } 203744249214SRandall Stewart /* Now will we need a chunk too? */ 2038f42a358aSRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { 2039f8829a4aSRandall Stewart sctp_alloc_a_chunk(stcb, chk); 2040f8829a4aSRandall Stewart if (chk == NULL) { 2041f8829a4aSRandall Stewart /* No memory so we drop the chunk */ 2042f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_nomem); 2043f8829a4aSRandall Stewart if (last_chunk == 0) { 2044f8829a4aSRandall Stewart /* we copied it, free the copy */ 2045f8829a4aSRandall Stewart sctp_m_freem(dmbuf); 2046f8829a4aSRandall Stewart } 2047f8829a4aSRandall Stewart return (0); 2048f8829a4aSRandall Stewart } 2049f8829a4aSRandall Stewart chk->rec.data.TSN_seq = tsn; 2050f8829a4aSRandall Stewart chk->no_fr_allowed = 0; 205144249214SRandall Stewart chk->rec.data.fsn_num = fsn; 205244249214SRandall Stewart chk->rec.data.stream_seq = msg_id; 2053f8829a4aSRandall Stewart chk->rec.data.stream_number = strmno; 2054f42a358aSRandall Stewart chk->rec.data.payloadtype = protocol_id; 2055f8829a4aSRandall Stewart chk->rec.data.context = stcb->asoc.context; 2056f8829a4aSRandall Stewart chk->rec.data.doing_fast_retransmit = 0; 2057f42a358aSRandall Stewart chk->rec.data.rcv_flags = chunk_flags; 2058f8829a4aSRandall Stewart chk->asoc = asoc; 2059f8829a4aSRandall Stewart chk->send_size = the_len; 2060f8829a4aSRandall Stewart chk->whoTo = net; 2061f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_XXX, "Building ck: %p for control: %p to be read (msg_id: %u)\n", 206244249214SRandall Stewart chk, 206344249214SRandall Stewart control, msg_id); 2064f8829a4aSRandall Stewart atomic_add_int(&net->ref_count, 1); 2065f8829a4aSRandall Stewart chk->data = dmbuf; 206644249214SRandall Stewart } 206744249214SRandall Stewart /* Set the appropriate TSN mark */ 206844249214SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) { 206944249214SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); 207044249214SRandall Stewart if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { 207144249214SRandall Stewart asoc->highest_tsn_inside_nr_map = tsn; 207244249214SRandall Stewart } 2073f8829a4aSRandall Stewart } else { 207444249214SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap); 207544249214SRandall Stewart if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map)) { 207644249214SRandall Stewart asoc->highest_tsn_inside_map = tsn; 2077f8829a4aSRandall Stewart } 2078f8829a4aSRandall Stewart } 207944249214SRandall Stewart /* Now is it complete (i.e. not fragmented)? */ 208044249214SRandall Stewart if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { 2081f8829a4aSRandall Stewart /* 208244249214SRandall Stewart * Special check for when streams are resetting. We could be 208344249214SRandall Stewart * more smart about this and check the actual stream to see 208444249214SRandall Stewart * if it is not being reset.. that way we would not create a 208544249214SRandall Stewart * HOLB when amongst streams being reset and those not being 208644249214SRandall Stewart * reset. 2087f8829a4aSRandall Stewart * 2088f8829a4aSRandall Stewart */ 2089f8829a4aSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 209020b07a4dSMichael Tuexen SCTP_TSN_GT(tsn, liste->tsn)) { 2091f8829a4aSRandall Stewart /* 209244249214SRandall Stewart * yep its past where we need to reset... go ahead 209344249214SRandall Stewart * and queue it. 2094f8829a4aSRandall Stewart */ 2095f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->pending_reply_queue)) { 2096f8829a4aSRandall Stewart /* first one on */ 2097f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2098f8829a4aSRandall Stewart } else { 209944249214SRandall Stewart struct sctp_queued_to_read *ctlOn, *nctlOn; 2100f8829a4aSRandall Stewart unsigned char inserted = 0; 2101f8829a4aSRandall Stewart 21024a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ctlOn, &asoc->pending_reply_queue, next, nctlOn) { 210320b07a4dSMichael Tuexen if (SCTP_TSN_GT(control->sinfo_tsn, ctlOn->sinfo_tsn)) { 210444249214SRandall Stewart 21054a9ef3f8SMichael Tuexen continue; 2106f8829a4aSRandall Stewart } else { 2107f8829a4aSRandall Stewart /* found it */ 2108f8829a4aSRandall Stewart TAILQ_INSERT_BEFORE(ctlOn, control, next); 2109f8829a4aSRandall Stewart inserted = 1; 2110f8829a4aSRandall Stewart break; 2111f8829a4aSRandall Stewart } 2112f8829a4aSRandall Stewart } 2113f8829a4aSRandall Stewart if (inserted == 0) { 2114f8829a4aSRandall Stewart /* 211544249214SRandall Stewart * must be put at end, use prevP 211644249214SRandall Stewart * (all setup from loop) to setup 211744249214SRandall Stewart * nextP. 2118f8829a4aSRandall Stewart */ 2119f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); 2120f8829a4aSRandall Stewart } 2121f8829a4aSRandall Stewart } 212244249214SRandall Stewart goto finish_express_del; 212344249214SRandall Stewart } 212444249214SRandall Stewart if (chunk_flags & SCTP_DATA_UNORDERED) { 212544249214SRandall Stewart /* queue directly into socket buffer */ 2126f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_XXX, "Unordered data to be read control: %p msg_id: %u\n", 212744249214SRandall Stewart control, msg_id); 212844249214SRandall Stewart sctp_mark_non_revokable(asoc, control->sinfo_tsn); 212944249214SRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 213044249214SRandall Stewart control, 213144249214SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 213244249214SRandall Stewart SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); 213344249214SRandall Stewart 2134f8829a4aSRandall Stewart } else { 2135f2ea2a2dSMichael Tuexen SCTPDBG(SCTP_DEBUG_XXX, "Queue control: %p for reordering msg_id: %u\n", control, 213644249214SRandall Stewart msg_id); 213744249214SRandall Stewart sctp_queue_data_to_stream(stcb, strm, asoc, control, abort_flag, &need_reasm_check); 2138f8829a4aSRandall Stewart if (*abort_flag) { 21398be0fd55SMichael Tuexen if (last_chunk) { 21408be0fd55SMichael Tuexen *m = NULL; 21418be0fd55SMichael Tuexen } 2142f8829a4aSRandall Stewart return (0); 2143f8829a4aSRandall Stewart } 2144f8829a4aSRandall Stewart } 214544249214SRandall Stewart goto finish_express_del; 2146f8829a4aSRandall Stewart } 214744249214SRandall Stewart /* If we reach here its a reassembly */ 214844249214SRandall Stewart need_reasm_check = 1; 214944249214SRandall Stewart SCTPDBG(SCTP_DEBUG_XXX, 2150f2ea2a2dSMichael Tuexen "Queue data to stream for reasm control: %p msg_id: %u\n", 215144249214SRandall Stewart control, msg_id); 215244249214SRandall Stewart sctp_queue_data_for_reasm(stcb, asoc, strm, control, chk, created_control, abort_flag, tsn); 2153f8829a4aSRandall Stewart if (*abort_flag) { 2154a5d547adSRandall Stewart /* 215544249214SRandall Stewart * the assoc is now gone and chk was put onto the reasm 215644249214SRandall Stewart * queue, which has all been freed. 2157a5d547adSRandall Stewart */ 21588be0fd55SMichael Tuexen if (last_chunk) { 2159a5d547adSRandall Stewart *m = NULL; 21608be0fd55SMichael Tuexen } 2161f8829a4aSRandall Stewart return (0); 2162f8829a4aSRandall Stewart } 2163f8829a4aSRandall Stewart finish_express_del: 216444249214SRandall Stewart /* Here we tidy up things */ 2165307b49efSMichael Tuexen if (tsn == (asoc->cumulative_tsn + 1)) { 2166307b49efSMichael Tuexen /* Update cum-ack */ 2167307b49efSMichael Tuexen asoc->cumulative_tsn = tsn; 2168307b49efSMichael Tuexen } 2169f8829a4aSRandall Stewart if (last_chunk) { 2170f8829a4aSRandall Stewart *m = NULL; 2171f8829a4aSRandall Stewart } 2172f42a358aSRandall Stewart if (ordered) { 2173f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inorderchunks); 2174f8829a4aSRandall Stewart } else { 2175f8829a4aSRandall Stewart SCTP_STAT_INCR_COUNTER64(sctps_inunorderchunks); 2176f8829a4aSRandall Stewart } 2177f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvdata); 2178f8829a4aSRandall Stewart /* Set it present please */ 2179b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { 218044249214SRandall Stewart sctp_log_strm_del_alt(stcb, tsn, msg_id, strmno, SCTP_STR_LOG_FROM_MARK_TSN); 218180fefe0aSRandall Stewart } 2182b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2183f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, 2184f8829a4aSRandall Stewart asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE); 218580fefe0aSRandall Stewart } 218617205eccSRandall Stewart /* check the special flag for stream resets */ 218717205eccSRandall Stewart if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && 218820b07a4dSMichael Tuexen SCTP_TSN_GE(asoc->cumulative_tsn, liste->tsn)) { 218917205eccSRandall Stewart /* 219017205eccSRandall Stewart * we have finished working through the backlogged TSN's now 219117205eccSRandall Stewart * time to reset streams. 1: call reset function. 2: free 219217205eccSRandall Stewart * pending_reply space 3: distribute any chunks in 219317205eccSRandall Stewart * pending_reply_queue. 219417205eccSRandall Stewart */ 21954a9ef3f8SMichael Tuexen struct sctp_queued_to_read *ctl, *nctl; 219617205eccSRandall Stewart 2197a169d6ecSMichael Tuexen sctp_reset_in_stream(stcb, liste->number_entries, liste->list_of_streams); 219817205eccSRandall Stewart TAILQ_REMOVE(&asoc->resetHead, liste, next_resp); 21997cca1775SRandall Stewart sctp_send_deferred_reset_response(stcb, liste, SCTP_STREAM_RESET_RESULT_PERFORMED); 2200207304d4SRandall Stewart SCTP_FREE(liste, SCTP_M_STRESET); 22013c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 220217205eccSRandall Stewart liste = TAILQ_FIRST(&asoc->resetHead); 22034a9ef3f8SMichael Tuexen if (TAILQ_EMPTY(&asoc->resetHead)) { 220417205eccSRandall Stewart /* All can be removed */ 22054a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ctl, &asoc->pending_reply_queue, next, nctl) { 220617205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 220744249214SRandall Stewart sctp_queue_data_to_stream(stcb, strm, asoc, ctl, abort_flag, &need_reasm_check); 220817205eccSRandall Stewart if (*abort_flag) { 220917205eccSRandall Stewart return (0); 221017205eccSRandall Stewart } 221117205eccSRandall Stewart } 22124a9ef3f8SMichael Tuexen } else { 22134a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ctl, &asoc->pending_reply_queue, next, nctl) { 221420b07a4dSMichael Tuexen if (SCTP_TSN_GT(ctl->sinfo_tsn, liste->tsn)) { 22154a9ef3f8SMichael Tuexen break; 22164a9ef3f8SMichael Tuexen } 221717205eccSRandall Stewart /* 221817205eccSRandall Stewart * if ctl->sinfo_tsn is <= liste->tsn we can 221917205eccSRandall Stewart * process it which is the NOT of 222017205eccSRandall Stewart * ctl->sinfo_tsn > liste->tsn 222117205eccSRandall Stewart */ 222217205eccSRandall Stewart TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); 222344249214SRandall Stewart sctp_queue_data_to_stream(stcb, strm, asoc, ctl, abort_flag, &need_reasm_check); 222417205eccSRandall Stewart if (*abort_flag) { 222517205eccSRandall Stewart return (0); 222617205eccSRandall Stewart } 222717205eccSRandall Stewart } 222817205eccSRandall Stewart } 222917205eccSRandall Stewart /* 223017205eccSRandall Stewart * Now service re-assembly to pick up anything that has been 223117205eccSRandall Stewart * held on reassembly queue? 223217205eccSRandall Stewart */ 2233d1ea5fa9SMichael Tuexen (void)sctp_deliver_reasm_check(stcb, asoc, strm, SCTP_READ_LOCK_NOT_HELD); 223417205eccSRandall Stewart need_reasm_check = 0; 223517205eccSRandall Stewart } 2236139bc87fSRandall Stewart if (need_reasm_check) { 2237139bc87fSRandall Stewart /* Another one waits ? */ 2238d1ea5fa9SMichael Tuexen (void)sctp_deliver_reasm_check(stcb, asoc, strm, SCTP_READ_LOCK_NOT_HELD); 2239139bc87fSRandall Stewart } 2240f8829a4aSRandall Stewart return (1); 2241f8829a4aSRandall Stewart } 2242f8829a4aSRandall Stewart 2243ed654363SMichael Tuexen static const int8_t sctp_map_lookup_tab[256] = { 2244b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2245b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2246b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2247b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2248b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2249b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2250b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2251b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 6, 2252b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2253b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2254b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2255b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2256b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2257b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2258b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2259b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 7, 2260b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2261b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2262b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2263b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2264b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2265b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2266b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2267b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 6, 2268b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2269b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2270b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2271b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 5, 2272b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2273b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 4, 2274b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 3, 2275b5c16493SMichael Tuexen 0, 1, 0, 2, 0, 1, 0, 8 2276f8829a4aSRandall Stewart }; 2277f8829a4aSRandall Stewart 2278f8829a4aSRandall Stewart 2279f8829a4aSRandall Stewart void 2280b5c16493SMichael Tuexen sctp_slide_mapping_arrays(struct sctp_tcb *stcb) 2281f8829a4aSRandall Stewart { 2282f8829a4aSRandall Stewart /* 2283f8829a4aSRandall Stewart * Now we also need to check the mapping array in a couple of ways. 2284f8829a4aSRandall Stewart * 1) Did we move the cum-ack point? 228566bd30bdSRandall Stewart * 228666bd30bdSRandall Stewart * When you first glance at this you might think that all entries that 2287cd0a4ff6SPedro F. Giffuni * make up the position of the cum-ack would be in the nr-mapping 228866bd30bdSRandall Stewart * array only.. i.e. things up to the cum-ack are always 228966bd30bdSRandall Stewart * deliverable. Thats true with one exception, when its a fragmented 229066bd30bdSRandall Stewart * message we may not deliver the data until some threshold (or all 229166bd30bdSRandall Stewart * of it) is in place. So we must OR the nr_mapping_array and 229266bd30bdSRandall Stewart * mapping_array to get a true picture of the cum-ack. 2293f8829a4aSRandall Stewart */ 2294f8829a4aSRandall Stewart struct sctp_association *asoc; 2295b3f1ea41SRandall Stewart int at; 229666bd30bdSRandall Stewart uint8_t val; 2297f8829a4aSRandall Stewart int slide_from, slide_end, lgap, distance; 229877acdc25SRandall Stewart uint32_t old_cumack, old_base, old_highest, highest_tsn; 2299f8829a4aSRandall Stewart 2300f8829a4aSRandall Stewart asoc = &stcb->asoc; 2301f8829a4aSRandall Stewart 2302f8829a4aSRandall Stewart old_cumack = asoc->cumulative_tsn; 2303f8829a4aSRandall Stewart old_base = asoc->mapping_array_base_tsn; 2304f8829a4aSRandall Stewart old_highest = asoc->highest_tsn_inside_map; 2305f8829a4aSRandall Stewart /* 2306f8829a4aSRandall Stewart * We could probably improve this a small bit by calculating the 2307f8829a4aSRandall Stewart * offset of the current cum-ack as the starting point. 2308f8829a4aSRandall Stewart */ 2309f8829a4aSRandall Stewart at = 0; 2310b5c16493SMichael Tuexen for (slide_from = 0; slide_from < stcb->asoc.mapping_array_size; slide_from++) { 231166bd30bdSRandall Stewart val = asoc->nr_mapping_array[slide_from] | asoc->mapping_array[slide_from]; 231266bd30bdSRandall Stewart if (val == 0xff) { 2313f8829a4aSRandall Stewart at += 8; 2314f8829a4aSRandall Stewart } else { 2315f8829a4aSRandall Stewart /* there is a 0 bit */ 231666bd30bdSRandall Stewart at += sctp_map_lookup_tab[val]; 2317f8829a4aSRandall Stewart break; 2318f8829a4aSRandall Stewart } 2319f8829a4aSRandall Stewart } 2320b5c16493SMichael Tuexen asoc->cumulative_tsn = asoc->mapping_array_base_tsn + (at - 1); 2321f8829a4aSRandall Stewart 232220b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->cumulative_tsn, asoc->highest_tsn_inside_map) && 232320b07a4dSMichael Tuexen SCTP_TSN_GT(asoc->cumulative_tsn, asoc->highest_tsn_inside_nr_map)) { 2324a5d547adSRandall Stewart #ifdef INVARIANTS 2325ceaad40aSRandall Stewart panic("huh, cumack 0x%x greater than high-tsn 0x%x in map", 2326ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 2327f8829a4aSRandall Stewart #else 2328ceaad40aSRandall Stewart SCTP_PRINTF("huh, cumack 0x%x greater than high-tsn 0x%x in map - should panic?\n", 2329ceaad40aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map); 23300e13104dSRandall Stewart sctp_print_mapping_array(asoc); 2331b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2332b3f1ea41SRandall Stewart sctp_log_map(0, 6, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 2333b3f1ea41SRandall Stewart } 2334f8829a4aSRandall Stewart asoc->highest_tsn_inside_map = asoc->cumulative_tsn; 2335830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn; 2336f8829a4aSRandall Stewart #endif 2337f8829a4aSRandall Stewart } 233820b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { 233977acdc25SRandall Stewart highest_tsn = asoc->highest_tsn_inside_nr_map; 234077acdc25SRandall Stewart } else { 234177acdc25SRandall Stewart highest_tsn = asoc->highest_tsn_inside_map; 234277acdc25SRandall Stewart } 234377acdc25SRandall Stewart if ((asoc->cumulative_tsn == highest_tsn) && (at >= 8)) { 2344f8829a4aSRandall Stewart /* The complete array was completed by a single FR */ 234577acdc25SRandall Stewart /* highest becomes the cum-ack */ 234637f144ebSMichael Tuexen int clr; 234737f144ebSMichael Tuexen 234837f144ebSMichael Tuexen #ifdef INVARIANTS 234937f144ebSMichael Tuexen unsigned int i; 235037f144ebSMichael Tuexen 235137f144ebSMichael Tuexen #endif 2352f8829a4aSRandall Stewart 2353f8829a4aSRandall Stewart /* clear the array */ 2354b5c16493SMichael Tuexen clr = ((at + 7) >> 3); 2355c4739e2fSRandall Stewart if (clr > asoc->mapping_array_size) { 2356f8829a4aSRandall Stewart clr = asoc->mapping_array_size; 2357f8829a4aSRandall Stewart } 2358f8829a4aSRandall Stewart memset(asoc->mapping_array, 0, clr); 2359830d754dSRandall Stewart memset(asoc->nr_mapping_array, 0, clr); 236037f144ebSMichael Tuexen #ifdef INVARIANTS 2361b5c16493SMichael Tuexen for (i = 0; i < asoc->mapping_array_size; i++) { 2362b5c16493SMichael Tuexen if ((asoc->mapping_array[i]) || (asoc->nr_mapping_array[i])) { 2363cd3fd531SMichael Tuexen SCTP_PRINTF("Error Mapping array's not clean at clear\n"); 2364b5c16493SMichael Tuexen sctp_print_mapping_array(asoc); 2365b5c16493SMichael Tuexen } 2366b5c16493SMichael Tuexen } 236737f144ebSMichael Tuexen #endif 236877acdc25SRandall Stewart asoc->mapping_array_base_tsn = asoc->cumulative_tsn + 1; 236977acdc25SRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->highest_tsn_inside_map = asoc->cumulative_tsn; 2370f8829a4aSRandall Stewart } else if (at >= 8) { 2371f8829a4aSRandall Stewart /* we can slide the mapping array down */ 2372b3f1ea41SRandall Stewart /* slide_from holds where we hit the first NON 0xff byte */ 2373b3f1ea41SRandall Stewart 2374f8829a4aSRandall Stewart /* 2375f8829a4aSRandall Stewart * now calculate the ceiling of the move using our highest 2376f8829a4aSRandall Stewart * TSN value 2377f8829a4aSRandall Stewart */ 237877acdc25SRandall Stewart SCTP_CALC_TSN_TO_GAP(lgap, highest_tsn, asoc->mapping_array_base_tsn); 237977acdc25SRandall Stewart slide_end = (lgap >> 3); 2380f8829a4aSRandall Stewart if (slide_end < slide_from) { 238177acdc25SRandall Stewart sctp_print_mapping_array(asoc); 2382d55b0b1bSRandall Stewart #ifdef INVARIANTS 2383f8829a4aSRandall Stewart panic("impossible slide"); 2384d55b0b1bSRandall Stewart #else 2385cd3fd531SMichael Tuexen SCTP_PRINTF("impossible slide lgap: %x slide_end: %x slide_from: %x? at: %d\n", 238677acdc25SRandall Stewart lgap, slide_end, slide_from, at); 2387d55b0b1bSRandall Stewart return; 2388d55b0b1bSRandall Stewart #endif 2389f8829a4aSRandall Stewart } 2390b3f1ea41SRandall Stewart if (slide_end > asoc->mapping_array_size) { 2391b3f1ea41SRandall Stewart #ifdef INVARIANTS 2392b3f1ea41SRandall Stewart panic("would overrun buffer"); 2393b3f1ea41SRandall Stewart #else 2394cd3fd531SMichael Tuexen SCTP_PRINTF("Gak, would have overrun map end: %d slide_end: %d\n", 2395b3f1ea41SRandall Stewart asoc->mapping_array_size, slide_end); 2396b3f1ea41SRandall Stewart slide_end = asoc->mapping_array_size; 2397b3f1ea41SRandall Stewart #endif 2398b3f1ea41SRandall Stewart } 2399f8829a4aSRandall Stewart distance = (slide_end - slide_from) + 1; 2400b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2401f8829a4aSRandall Stewart sctp_log_map(old_base, old_cumack, old_highest, 2402f8829a4aSRandall Stewart SCTP_MAP_PREPARE_SLIDE); 2403f8829a4aSRandall Stewart sctp_log_map((uint32_t) slide_from, (uint32_t) slide_end, 2404f8829a4aSRandall Stewart (uint32_t) lgap, SCTP_MAP_SLIDE_FROM); 240580fefe0aSRandall Stewart } 2406f8829a4aSRandall Stewart if (distance + slide_from > asoc->mapping_array_size || 2407f8829a4aSRandall Stewart distance < 0) { 2408f8829a4aSRandall Stewart /* 2409f8829a4aSRandall Stewart * Here we do NOT slide forward the array so that 2410f8829a4aSRandall Stewart * hopefully when more data comes in to fill it up 2411f8829a4aSRandall Stewart * we will be able to slide it forward. Really I 2412f8829a4aSRandall Stewart * don't think this should happen :-0 2413f8829a4aSRandall Stewart */ 2414f8829a4aSRandall Stewart 2415b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2416f8829a4aSRandall Stewart sctp_log_map((uint32_t) distance, (uint32_t) slide_from, 2417f8829a4aSRandall Stewart (uint32_t) asoc->mapping_array_size, 2418f8829a4aSRandall Stewart SCTP_MAP_SLIDE_NONE); 241980fefe0aSRandall Stewart } 2420f8829a4aSRandall Stewart } else { 2421f8829a4aSRandall Stewart int ii; 2422f8829a4aSRandall Stewart 2423f8829a4aSRandall Stewart for (ii = 0; ii < distance; ii++) { 242437f144ebSMichael Tuexen asoc->mapping_array[ii] = asoc->mapping_array[slide_from + ii]; 242537f144ebSMichael Tuexen asoc->nr_mapping_array[ii] = asoc->nr_mapping_array[slide_from + ii]; 242677acdc25SRandall Stewart 2427f8829a4aSRandall Stewart } 2428aed5947cSMichael Tuexen for (ii = distance; ii < asoc->mapping_array_size; ii++) { 2429f8829a4aSRandall Stewart asoc->mapping_array[ii] = 0; 243077acdc25SRandall Stewart asoc->nr_mapping_array[ii] = 0; 2431f8829a4aSRandall Stewart } 2432ee94f0a2SMichael Tuexen if (asoc->highest_tsn_inside_map + 1 == asoc->mapping_array_base_tsn) { 2433ee94f0a2SMichael Tuexen asoc->highest_tsn_inside_map += (slide_from << 3); 2434ee94f0a2SMichael Tuexen } 2435ee94f0a2SMichael Tuexen if (asoc->highest_tsn_inside_nr_map + 1 == asoc->mapping_array_base_tsn) { 2436ee94f0a2SMichael Tuexen asoc->highest_tsn_inside_nr_map += (slide_from << 3); 2437ee94f0a2SMichael Tuexen } 2438f8829a4aSRandall Stewart asoc->mapping_array_base_tsn += (slide_from << 3); 2439b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 2440f8829a4aSRandall Stewart sctp_log_map(asoc->mapping_array_base_tsn, 2441f8829a4aSRandall Stewart asoc->cumulative_tsn, asoc->highest_tsn_inside_map, 2442f8829a4aSRandall Stewart SCTP_MAP_SLIDE_RESULT); 244380fefe0aSRandall Stewart } 2444830d754dSRandall Stewart } 2445830d754dSRandall Stewart } 2446b5c16493SMichael Tuexen } 2447b5c16493SMichael Tuexen 2448b5c16493SMichael Tuexen void 24497215cc1bSMichael Tuexen sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap) 2450b5c16493SMichael Tuexen { 2451b5c16493SMichael Tuexen struct sctp_association *asoc; 2452b5c16493SMichael Tuexen uint32_t highest_tsn; 2453b5c16493SMichael Tuexen 2454b5c16493SMichael Tuexen asoc = &stcb->asoc; 245520b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { 2456b5c16493SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_nr_map; 2457b5c16493SMichael Tuexen } else { 2458b5c16493SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_map; 2459b5c16493SMichael Tuexen } 2460b5c16493SMichael Tuexen 2461830d754dSRandall Stewart /* 2462f8829a4aSRandall Stewart * Now we need to see if we need to queue a sack or just start the 2463f8829a4aSRandall Stewart * timer (if allowed). 2464f8829a4aSRandall Stewart */ 2465f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 2466f8829a4aSRandall Stewart /* 2467b5c16493SMichael Tuexen * Ok special case, in SHUTDOWN-SENT case. here we maker 2468b5c16493SMichael Tuexen * sure SACK timer is off and instead send a SHUTDOWN and a 2469b5c16493SMichael Tuexen * SACK 2470f8829a4aSRandall Stewart */ 2471139bc87fSRandall Stewart if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2472f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_RECV, 2473b7d130beSMichael Tuexen stcb->sctp_ep, stcb, NULL, 247444249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_17); 2475f8829a4aSRandall Stewart } 2476ca85e948SMichael Tuexen sctp_send_shutdown(stcb, 2477ca85e948SMichael Tuexen ((stcb->asoc.alternate) ? stcb->asoc.alternate : stcb->asoc.primary_destination)); 2478689e6a5fSMichael Tuexen sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED); 2479f8829a4aSRandall Stewart } else { 2480f8829a4aSRandall Stewart int is_a_gap; 2481f8829a4aSRandall Stewart 2482f8829a4aSRandall Stewart /* is there a gap now ? */ 248320b07a4dSMichael Tuexen is_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn); 2484f8829a4aSRandall Stewart 2485f8829a4aSRandall Stewart /* 2486b5c16493SMichael Tuexen * CMT DAC algorithm: increase number of packets received 2487b5c16493SMichael Tuexen * since last ack 2488f8829a4aSRandall Stewart */ 2489f8829a4aSRandall Stewart stcb->asoc.cmt_dac_pkts_rcvd++; 2490f8829a4aSRandall Stewart 249142551e99SRandall Stewart if ((stcb->asoc.send_sack == 1) || /* We need to send a 249242551e99SRandall Stewart * SACK */ 2493f8829a4aSRandall Stewart ((was_a_gap) && (is_a_gap == 0)) || /* was a gap, but no 2494f8829a4aSRandall Stewart * longer is one */ 2495f8829a4aSRandall Stewart (stcb->asoc.numduptsns) || /* we have dup's */ 2496f8829a4aSRandall Stewart (is_a_gap) || /* is still a gap */ 249742551e99SRandall Stewart (stcb->asoc.delayed_ack == 0) || /* Delayed sack disabled */ 249842551e99SRandall Stewart (stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) /* hit limit of pkts */ 2499f8829a4aSRandall Stewart ) { 2500f8829a4aSRandall Stewart 25017c99d56fSMichael Tuexen if ((stcb->asoc.sctp_cmt_on_off > 0) && 2502b3f1ea41SRandall Stewart (SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) && 250342551e99SRandall Stewart (stcb->asoc.send_sack == 0) && 2504f8829a4aSRandall Stewart (stcb->asoc.numduptsns == 0) && 2505f8829a4aSRandall Stewart (stcb->asoc.delayed_ack) && 2506139bc87fSRandall Stewart (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer))) { 2507f8829a4aSRandall Stewart 2508f8829a4aSRandall Stewart /* 2509b5c16493SMichael Tuexen * CMT DAC algorithm: With CMT, delay acks 2510b5c16493SMichael Tuexen * even in the face of 2511f8829a4aSRandall Stewart * 2512b5c16493SMichael Tuexen * reordering. Therefore, if acks that do not 2513b5c16493SMichael Tuexen * have to be sent because of the above 2514b5c16493SMichael Tuexen * reasons, will be delayed. That is, acks 2515b5c16493SMichael Tuexen * that would have been sent due to gap 2516b5c16493SMichael Tuexen * reports will be delayed with DAC. Start 2517f8829a4aSRandall Stewart * the delayed ack timer. 2518f8829a4aSRandall Stewart */ 2519f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2520f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2521f8829a4aSRandall Stewart } else { 2522f8829a4aSRandall Stewart /* 2523b5c16493SMichael Tuexen * Ok we must build a SACK since the timer 2524b5c16493SMichael Tuexen * is pending, we got our first packet OR 2525b5c16493SMichael Tuexen * there are gaps or duplicates. 2526f8829a4aSRandall Stewart */ 2527ad81507eSRandall Stewart (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer); 2528689e6a5fSMichael Tuexen sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED); 2529f8829a4aSRandall Stewart } 2530f8829a4aSRandall Stewart } else { 253142551e99SRandall Stewart if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { 2532f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_RECV, 2533f8829a4aSRandall Stewart stcb->sctp_ep, stcb, NULL); 2534f8829a4aSRandall Stewart } 2535f8829a4aSRandall Stewart } 2536f8829a4aSRandall Stewart } 2537f8829a4aSRandall Stewart } 2538f8829a4aSRandall Stewart 2539f8829a4aSRandall Stewart int 2540f8829a4aSRandall Stewart sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, 2541e7e71dd7SMichael Tuexen struct sctp_inpcb *inp, struct sctp_tcb *stcb, 2542e7e71dd7SMichael Tuexen struct sctp_nets *net, uint32_t * high_tsn) 2543f8829a4aSRandall Stewart { 254444249214SRandall Stewart struct sctp_chunkhdr *ch, chunk_buf; 2545f8829a4aSRandall Stewart struct sctp_association *asoc; 2546f8829a4aSRandall Stewart int num_chunks = 0; /* number of control chunks processed */ 2547f8829a4aSRandall Stewart int stop_proc = 0; 2548f8829a4aSRandall Stewart int chk_length, break_flag, last_chunk; 25498f777478SMichael Tuexen int abort_flag = 0, was_a_gap; 2550f8829a4aSRandall Stewart struct mbuf *m; 25518f777478SMichael Tuexen uint32_t highest_tsn; 2552f8829a4aSRandall Stewart 2553f8829a4aSRandall Stewart /* set the rwnd */ 2554f8829a4aSRandall Stewart sctp_set_rwnd(stcb, &stcb->asoc); 2555f8829a4aSRandall Stewart 2556f8829a4aSRandall Stewart m = *mm; 2557f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 2558f8829a4aSRandall Stewart asoc = &stcb->asoc; 255920b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { 25608f777478SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_nr_map; 25618f777478SMichael Tuexen } else { 25628f777478SMichael Tuexen highest_tsn = asoc->highest_tsn_inside_map; 2563f8829a4aSRandall Stewart } 256420b07a4dSMichael Tuexen was_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn); 2565f8829a4aSRandall Stewart /* 2566f8829a4aSRandall Stewart * setup where we got the last DATA packet from for any SACK that 2567f8829a4aSRandall Stewart * may need to go out. Don't bump the net. This is done ONLY when a 2568f8829a4aSRandall Stewart * chunk is assigned. 2569f8829a4aSRandall Stewart */ 2570f8829a4aSRandall Stewart asoc->last_data_chunk_from = net; 2571f8829a4aSRandall Stewart 2572d06c82f1SRandall Stewart /*- 2573f8829a4aSRandall Stewart * Now before we proceed we must figure out if this is a wasted 2574f8829a4aSRandall Stewart * cluster... i.e. it is a small packet sent in and yet the driver 2575f8829a4aSRandall Stewart * underneath allocated a full cluster for it. If so we must copy it 2576f8829a4aSRandall Stewart * to a smaller mbuf and free up the cluster mbuf. This will help 2577d06c82f1SRandall Stewart * with cluster starvation. Note for __Panda__ we don't do this 2578d06c82f1SRandall Stewart * since it has clusters all the way down to 64 bytes. 2579f8829a4aSRandall Stewart */ 258044b7479bSRandall Stewart if (SCTP_BUF_LEN(m) < (long)MLEN && SCTP_BUF_NEXT(m) == NULL) { 2581f8829a4aSRandall Stewart /* we only handle mbufs that are singletons.. not chains */ 2582eb1b1807SGleb Smirnoff m = sctp_get_mbuf_for_msg(SCTP_BUF_LEN(m), 0, M_NOWAIT, 1, MT_DATA); 2583f8829a4aSRandall Stewart if (m) { 2584f8829a4aSRandall Stewart /* ok lets see if we can copy the data up */ 2585f8829a4aSRandall Stewart caddr_t *from, *to; 2586f8829a4aSRandall Stewart 2587f8829a4aSRandall Stewart /* get the pointers and copy */ 2588f8829a4aSRandall Stewart to = mtod(m, caddr_t *); 2589f8829a4aSRandall Stewart from = mtod((*mm), caddr_t *); 2590139bc87fSRandall Stewart memcpy(to, from, SCTP_BUF_LEN((*mm))); 2591f8829a4aSRandall Stewart /* copy the length and free up the old */ 2592139bc87fSRandall Stewart SCTP_BUF_LEN(m) = SCTP_BUF_LEN((*mm)); 2593f8829a4aSRandall Stewart sctp_m_freem(*mm); 2594cd0a4ff6SPedro F. Giffuni /* success, back copy */ 2595f8829a4aSRandall Stewart *mm = m; 2596f8829a4aSRandall Stewart } else { 2597f8829a4aSRandall Stewart /* We are in trouble in the mbuf world .. yikes */ 2598f8829a4aSRandall Stewart m = *mm; 2599f8829a4aSRandall Stewart } 2600f8829a4aSRandall Stewart } 2601f8829a4aSRandall Stewart /* get pointer to the first chunk header */ 260244249214SRandall Stewart ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset, 260344249214SRandall Stewart sizeof(struct sctp_chunkhdr), (uint8_t *) & chunk_buf); 2604f8829a4aSRandall Stewart if (ch == NULL) { 2605f8829a4aSRandall Stewart return (1); 2606f8829a4aSRandall Stewart } 2607f8829a4aSRandall Stewart /* 2608f8829a4aSRandall Stewart * process all DATA chunks... 2609f8829a4aSRandall Stewart */ 2610f8829a4aSRandall Stewart *high_tsn = asoc->cumulative_tsn; 2611f8829a4aSRandall Stewart break_flag = 0; 261242551e99SRandall Stewart asoc->data_pkts_seen++; 2613f8829a4aSRandall Stewart while (stop_proc == 0) { 2614f8829a4aSRandall Stewart /* validate chunk length */ 261544249214SRandall Stewart chk_length = ntohs(ch->chunk_length); 2616f8829a4aSRandall Stewart if (length - *offset < chk_length) { 2617f8829a4aSRandall Stewart /* all done, mutulated chunk */ 2618f8829a4aSRandall Stewart stop_proc = 1; 261960990c0cSMichael Tuexen continue; 2620f8829a4aSRandall Stewart } 262144249214SRandall Stewart if ((asoc->idata_supported == 1) && 262244249214SRandall Stewart (ch->chunk_type == SCTP_DATA)) { 262344249214SRandall Stewart struct mbuf *op_err; 262444249214SRandall Stewart char msg[SCTP_DIAG_INFO_LEN]; 262544249214SRandall Stewart 2626e7f232a0SMichael Tuexen snprintf(msg, sizeof(msg), "%s", "I-DATA chunk received when DATA was negotiated"); 262744249214SRandall Stewart op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 262844249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_18; 262944249214SRandall Stewart sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED); 263044249214SRandall Stewart return (2); 263144249214SRandall Stewart } 263244249214SRandall Stewart if ((asoc->idata_supported == 0) && 263344249214SRandall Stewart (ch->chunk_type == SCTP_IDATA)) { 263444249214SRandall Stewart struct mbuf *op_err; 263544249214SRandall Stewart char msg[SCTP_DIAG_INFO_LEN]; 263644249214SRandall Stewart 2637e7f232a0SMichael Tuexen snprintf(msg, sizeof(msg), "%s", "DATA chunk received when I-DATA was negotiated"); 263844249214SRandall Stewart op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 263944249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_19; 264044249214SRandall Stewart sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED); 264144249214SRandall Stewart return (2); 264244249214SRandall Stewart } 264344249214SRandall Stewart if ((ch->chunk_type == SCTP_DATA) || 264444249214SRandall Stewart (ch->chunk_type == SCTP_IDATA)) { 264544249214SRandall Stewart int clen; 264644249214SRandall Stewart 264744249214SRandall Stewart if (ch->chunk_type == SCTP_DATA) { 264844249214SRandall Stewart clen = sizeof(struct sctp_data_chunk); 264944249214SRandall Stewart } else { 265044249214SRandall Stewart clen = sizeof(struct sctp_idata_chunk); 265144249214SRandall Stewart } 2652f8ee69bfSMichael Tuexen if (chk_length < clen) { 2653f8829a4aSRandall Stewart /* 2654f8829a4aSRandall Stewart * Need to send an abort since we had a 2655f8829a4aSRandall Stewart * invalid data chunk. 2656f8829a4aSRandall Stewart */ 2657f8829a4aSRandall Stewart struct mbuf *op_err; 2658ff1ffd74SMichael Tuexen char msg[SCTP_DIAG_INFO_LEN]; 2659f8829a4aSRandall Stewart 2660ff1ffd74SMichael Tuexen snprintf(msg, sizeof(msg), "DATA chunk of length %d", 2661ff1ffd74SMichael Tuexen chk_length); 2662ff1ffd74SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 266344249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_20; 2664e7e71dd7SMichael Tuexen sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED); 266532451da4SMichael Tuexen return (2); 266632451da4SMichael Tuexen } 2667f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 2668f8829a4aSRandall Stewart sctp_audit_log(0xB1, 0); 2669f8829a4aSRandall Stewart #endif 2670f8829a4aSRandall Stewart if (SCTP_SIZE32(chk_length) == (length - *offset)) { 2671f8829a4aSRandall Stewart last_chunk = 1; 2672f8829a4aSRandall Stewart } else { 2673f8829a4aSRandall Stewart last_chunk = 0; 2674f8829a4aSRandall Stewart } 267544249214SRandall Stewart if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset, 2676f8829a4aSRandall Stewart chk_length, net, high_tsn, &abort_flag, &break_flag, 267744249214SRandall Stewart last_chunk, ch->chunk_type)) { 2678f8829a4aSRandall Stewart num_chunks++; 2679f8829a4aSRandall Stewart } 2680f8829a4aSRandall Stewart if (abort_flag) 2681f8829a4aSRandall Stewart return (2); 2682f8829a4aSRandall Stewart 2683f8829a4aSRandall Stewart if (break_flag) { 2684f8829a4aSRandall Stewart /* 2685f8829a4aSRandall Stewart * Set because of out of rwnd space and no 2686f8829a4aSRandall Stewart * drop rep space left. 2687f8829a4aSRandall Stewart */ 2688f8829a4aSRandall Stewart stop_proc = 1; 268960990c0cSMichael Tuexen continue; 2690f8829a4aSRandall Stewart } 2691f8829a4aSRandall Stewart } else { 2692f8829a4aSRandall Stewart /* not a data chunk in the data region */ 269344249214SRandall Stewart switch (ch->chunk_type) { 2694f8829a4aSRandall Stewart case SCTP_INITIATION: 2695f8829a4aSRandall Stewart case SCTP_INITIATION_ACK: 2696f8829a4aSRandall Stewart case SCTP_SELECTIVE_ACK: 269760990c0cSMichael Tuexen case SCTP_NR_SELECTIVE_ACK: 2698f8829a4aSRandall Stewart case SCTP_HEARTBEAT_REQUEST: 2699f8829a4aSRandall Stewart case SCTP_HEARTBEAT_ACK: 2700f8829a4aSRandall Stewart case SCTP_ABORT_ASSOCIATION: 2701f8829a4aSRandall Stewart case SCTP_SHUTDOWN: 2702f8829a4aSRandall Stewart case SCTP_SHUTDOWN_ACK: 2703f8829a4aSRandall Stewart case SCTP_OPERATION_ERROR: 2704f8829a4aSRandall Stewart case SCTP_COOKIE_ECHO: 2705f8829a4aSRandall Stewart case SCTP_COOKIE_ACK: 2706f8829a4aSRandall Stewart case SCTP_ECN_ECHO: 2707f8829a4aSRandall Stewart case SCTP_ECN_CWR: 2708f8829a4aSRandall Stewart case SCTP_SHUTDOWN_COMPLETE: 2709f8829a4aSRandall Stewart case SCTP_AUTHENTICATION: 2710f8829a4aSRandall Stewart case SCTP_ASCONF_ACK: 2711f8829a4aSRandall Stewart case SCTP_PACKET_DROPPED: 2712f8829a4aSRandall Stewart case SCTP_STREAM_RESET: 2713f8829a4aSRandall Stewart case SCTP_FORWARD_CUM_TSN: 2714f8829a4aSRandall Stewart case SCTP_ASCONF: 2715fd60718dSMichael Tuexen { 2716f8829a4aSRandall Stewart /* 2717fd60718dSMichael Tuexen * Now, what do we do with KNOWN 2718fd60718dSMichael Tuexen * chunks that are NOT in the right 2719fd60718dSMichael Tuexen * place? 2720f8829a4aSRandall Stewart * 2721fd60718dSMichael Tuexen * For now, I do nothing but ignore 2722fd60718dSMichael Tuexen * them. We may later want to add 2723fd60718dSMichael Tuexen * sysctl stuff to switch out and do 2724fd60718dSMichael Tuexen * either an ABORT() or possibly 2725fd60718dSMichael Tuexen * process them. 2726f8829a4aSRandall Stewart */ 2727f8829a4aSRandall Stewart struct mbuf *op_err; 2728267dbe63SMichael Tuexen char msg[SCTP_DIAG_INFO_LEN]; 2729f8829a4aSRandall Stewart 27309ae56375SMichael Tuexen snprintf(msg, sizeof(msg), "DATA chunk followed by chunk of type %2.2x", 273144249214SRandall Stewart ch->chunk_type); 2732267dbe63SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 2733e7e71dd7SMichael Tuexen sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED); 2734f8829a4aSRandall Stewart return (2); 2735f8829a4aSRandall Stewart } 2736f8829a4aSRandall Stewart default: 2737f8829a4aSRandall Stewart /* unknown chunk type, use bit rules */ 273844249214SRandall Stewart if (ch->chunk_type & 0x40) { 2739f8829a4aSRandall Stewart /* Add a error report to the queue */ 274086eda749SMichael Tuexen struct mbuf *op_err; 274186eda749SMichael Tuexen struct sctp_gen_error_cause *cause; 2742f8829a4aSRandall Stewart 274386eda749SMichael Tuexen op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_gen_error_cause), 274486eda749SMichael Tuexen 0, M_NOWAIT, 1, MT_DATA); 274586eda749SMichael Tuexen if (op_err != NULL) { 274686eda749SMichael Tuexen cause = mtod(op_err, struct sctp_gen_error_cause *); 274786eda749SMichael Tuexen cause->code = htons(SCTP_CAUSE_UNRECOG_CHUNK); 27489a8e3088SMichael Tuexen cause->length = htons((uint16_t) (chk_length + sizeof(struct sctp_gen_error_cause))); 274986eda749SMichael Tuexen SCTP_BUF_LEN(op_err) = sizeof(struct sctp_gen_error_cause); 275086eda749SMichael Tuexen SCTP_BUF_NEXT(op_err) = SCTP_M_COPYM(m, *offset, chk_length, M_NOWAIT); 275186eda749SMichael Tuexen if (SCTP_BUF_NEXT(op_err) != NULL) { 275286eda749SMichael Tuexen sctp_queue_op_err(stcb, op_err); 2753f8829a4aSRandall Stewart } else { 275486eda749SMichael Tuexen sctp_m_freem(op_err); 2755f8829a4aSRandall Stewart } 2756f8829a4aSRandall Stewart } 2757f8829a4aSRandall Stewart } 275844249214SRandall Stewart if ((ch->chunk_type & 0x80) == 0) { 2759f8829a4aSRandall Stewart /* discard the rest of this packet */ 2760f8829a4aSRandall Stewart stop_proc = 1; 2761f8829a4aSRandall Stewart } /* else skip this bad chunk and 2762f8829a4aSRandall Stewart * continue... */ 2763f8829a4aSRandall Stewart break; 276460990c0cSMichael Tuexen } /* switch of chunk type */ 2765f8829a4aSRandall Stewart } 2766f8829a4aSRandall Stewart *offset += SCTP_SIZE32(chk_length); 2767f8829a4aSRandall Stewart if ((*offset >= length) || stop_proc) { 2768f8829a4aSRandall Stewart /* no more data left in the mbuf chain */ 2769f8829a4aSRandall Stewart stop_proc = 1; 2770f8829a4aSRandall Stewart continue; 2771f8829a4aSRandall Stewart } 277244249214SRandall Stewart ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset, 277344249214SRandall Stewart sizeof(struct sctp_chunkhdr), (uint8_t *) & chunk_buf); 2774f8829a4aSRandall Stewart if (ch == NULL) { 2775f8829a4aSRandall Stewart *offset = length; 2776f8829a4aSRandall Stewart stop_proc = 1; 277760990c0cSMichael Tuexen continue; 2778f8829a4aSRandall Stewart } 277960990c0cSMichael Tuexen } 2780f8829a4aSRandall Stewart if (break_flag) { 2781f8829a4aSRandall Stewart /* 2782f8829a4aSRandall Stewart * we need to report rwnd overrun drops. 2783f8829a4aSRandall Stewart */ 278420cc2188SMichael Tuexen sctp_send_packet_dropped(stcb, net, *mm, length, iphlen, 0); 2785f8829a4aSRandall Stewart } 2786f8829a4aSRandall Stewart if (num_chunks) { 2787f8829a4aSRandall Stewart /* 2788ceaad40aSRandall Stewart * Did we get data, if so update the time for auto-close and 2789f8829a4aSRandall Stewart * give peer credit for being alive. 2790f8829a4aSRandall Stewart */ 2791f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_recvpktwithdata); 2792b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 2793c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 2794c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 2795c4739e2fSRandall Stewart 0, 2796c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 2797c4739e2fSRandall Stewart __LINE__); 2798c4739e2fSRandall Stewart } 2799f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 28006e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_last_rcvd); 2801f8829a4aSRandall Stewart } 2802f8829a4aSRandall Stewart /* now service all of the reassm queue if needed */ 2803f8829a4aSRandall Stewart if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) { 280442551e99SRandall Stewart /* Assure that we ack right away */ 280542551e99SRandall Stewart stcb->asoc.send_sack = 1; 2806f8829a4aSRandall Stewart } 2807f8829a4aSRandall Stewart /* Start a sack timer or QUEUE a SACK for sending */ 28087215cc1bSMichael Tuexen sctp_sack_check(stcb, was_a_gap); 2809f8829a4aSRandall Stewart return (0); 2810f8829a4aSRandall Stewart } 2811f8829a4aSRandall Stewart 28120fa753b3SRandall Stewart static int 28130fa753b3SRandall Stewart sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1, uint32_t last_tsn, 28140fa753b3SRandall Stewart uint16_t frag_strt, uint16_t frag_end, int nr_sacking, 28150fa753b3SRandall Stewart int *num_frs, 28160fa753b3SRandall Stewart uint32_t * biggest_newly_acked_tsn, 28170fa753b3SRandall Stewart uint32_t * this_sack_lowest_newack, 28187215cc1bSMichael Tuexen int *rto_ok) 28190fa753b3SRandall Stewart { 28200fa753b3SRandall Stewart struct sctp_tmit_chunk *tp1; 28210fa753b3SRandall Stewart unsigned int theTSN; 2822b5c16493SMichael Tuexen int j, wake_him = 0, circled = 0; 28230fa753b3SRandall Stewart 28240fa753b3SRandall Stewart /* Recover the tp1 we last saw */ 28250fa753b3SRandall Stewart tp1 = *p_tp1; 28260fa753b3SRandall Stewart if (tp1 == NULL) { 28270fa753b3SRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 28280fa753b3SRandall Stewart } 28290fa753b3SRandall Stewart for (j = frag_strt; j <= frag_end; j++) { 28300fa753b3SRandall Stewart theTSN = j + last_tsn; 28310fa753b3SRandall Stewart while (tp1) { 28320fa753b3SRandall Stewart if (tp1->rec.data.doing_fast_retransmit) 28330fa753b3SRandall Stewart (*num_frs) += 1; 28340fa753b3SRandall Stewart 28350fa753b3SRandall Stewart /*- 28360fa753b3SRandall Stewart * CMT: CUCv2 algorithm. For each TSN being 28370fa753b3SRandall Stewart * processed from the sent queue, track the 28380fa753b3SRandall Stewart * next expected pseudo-cumack, or 28390fa753b3SRandall Stewart * rtx_pseudo_cumack, if required. Separate 28400fa753b3SRandall Stewart * cumack trackers for first transmissions, 28410fa753b3SRandall Stewart * and retransmissions. 28420fa753b3SRandall Stewart */ 28438427b3fdSMichael Tuexen if ((tp1->sent < SCTP_DATAGRAM_RESEND) && 28448427b3fdSMichael Tuexen (tp1->whoTo->find_pseudo_cumack == 1) && 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 } 28498427b3fdSMichael Tuexen if ((tp1->sent < SCTP_DATAGRAM_RESEND) && 28508427b3fdSMichael Tuexen (tp1->whoTo->find_rtx_pseudo_cumack == 1) && 28510fa753b3SRandall Stewart (tp1->snd_count > 1)) { 28520fa753b3SRandall Stewart tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.TSN_seq; 28530fa753b3SRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 0; 28540fa753b3SRandall Stewart } 28550fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == theTSN) { 28560fa753b3SRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 28570fa753b3SRandall Stewart /*- 28580fa753b3SRandall Stewart * must be held until 28590fa753b3SRandall Stewart * cum-ack passes 28600fa753b3SRandall Stewart */ 28610fa753b3SRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 28620fa753b3SRandall Stewart /*- 28630fa753b3SRandall Stewart * If it is less than RESEND, it is 28640fa753b3SRandall Stewart * now no-longer in flight. 28650fa753b3SRandall Stewart * Higher values may already be set 28660fa753b3SRandall Stewart * via previous Gap Ack Blocks... 28670fa753b3SRandall Stewart * i.e. ACKED or RESEND. 28680fa753b3SRandall Stewart */ 286920b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, 287020b07a4dSMichael Tuexen *biggest_newly_acked_tsn)) { 28710fa753b3SRandall Stewart *biggest_newly_acked_tsn = tp1->rec.data.TSN_seq; 28720fa753b3SRandall Stewart } 28730fa753b3SRandall Stewart /*- 28740fa753b3SRandall Stewart * CMT: SFR algo (and HTNA) - set 28750fa753b3SRandall Stewart * saw_newack to 1 for dest being 28760fa753b3SRandall Stewart * newly acked. update 28770fa753b3SRandall Stewart * this_sack_highest_newack if 28780fa753b3SRandall Stewart * appropriate. 28790fa753b3SRandall Stewart */ 28800fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) 28810fa753b3SRandall Stewart tp1->whoTo->saw_newack = 1; 28820fa753b3SRandall Stewart 288320b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, 288420b07a4dSMichael Tuexen tp1->whoTo->this_sack_highest_newack)) { 28850fa753b3SRandall Stewart tp1->whoTo->this_sack_highest_newack = 28860fa753b3SRandall Stewart tp1->rec.data.TSN_seq; 28870fa753b3SRandall Stewart } 28880fa753b3SRandall Stewart /*- 28890fa753b3SRandall Stewart * CMT DAC algo: also update 28900fa753b3SRandall Stewart * this_sack_lowest_newack 28910fa753b3SRandall Stewart */ 28920fa753b3SRandall Stewart if (*this_sack_lowest_newack == 0) { 28930fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 28940fa753b3SRandall Stewart sctp_log_sack(*this_sack_lowest_newack, 28950fa753b3SRandall Stewart last_tsn, 28960fa753b3SRandall Stewart tp1->rec.data.TSN_seq, 28970fa753b3SRandall Stewart 0, 28980fa753b3SRandall Stewart 0, 28990fa753b3SRandall Stewart SCTP_LOG_TSN_ACKED); 29000fa753b3SRandall Stewart } 29010fa753b3SRandall Stewart *this_sack_lowest_newack = tp1->rec.data.TSN_seq; 29020fa753b3SRandall Stewart } 29030fa753b3SRandall Stewart /*- 29040fa753b3SRandall Stewart * CMT: CUCv2 algorithm. If (rtx-)pseudo-cumack for corresp 29050fa753b3SRandall Stewart * dest is being acked, then we have a new (rtx-)pseudo-cumack. Set 29060fa753b3SRandall Stewart * new_(rtx_)pseudo_cumack to TRUE so that the cwnd for this dest can be 29070fa753b3SRandall Stewart * updated. Also trigger search for the next expected (rtx-)pseudo-cumack. 29080fa753b3SRandall Stewart * Separate pseudo_cumack trackers for first transmissions and 29090fa753b3SRandall Stewart * retransmissions. 29100fa753b3SRandall Stewart */ 29110fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->pseudo_cumack) { 29120fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 29130fa753b3SRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 29140fa753b3SRandall Stewart } 29150fa753b3SRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 29160fa753b3SRandall Stewart } 29170fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 29180fa753b3SRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 29190fa753b3SRandall Stewart } 29200fa753b3SRandall Stewart if (tp1->rec.data.TSN_seq == tp1->whoTo->rtx_pseudo_cumack) { 29210fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked == 0) { 29220fa753b3SRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 29230fa753b3SRandall Stewart } 29240fa753b3SRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 29250fa753b3SRandall Stewart } 29260fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 29270fa753b3SRandall Stewart sctp_log_sack(*biggest_newly_acked_tsn, 29280fa753b3SRandall Stewart last_tsn, 29290fa753b3SRandall Stewart tp1->rec.data.TSN_seq, 29300fa753b3SRandall Stewart frag_strt, 29310fa753b3SRandall Stewart frag_end, 29320fa753b3SRandall Stewart SCTP_LOG_TSN_ACKED); 29330fa753b3SRandall Stewart } 29340fa753b3SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 29350fa753b3SRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP, 29360fa753b3SRandall Stewart tp1->whoTo->flight_size, 29370fa753b3SRandall Stewart tp1->book_size, 29389a8e3088SMichael Tuexen (uint32_t) (uintptr_t) tp1->whoTo, 29390fa753b3SRandall Stewart tp1->rec.data.TSN_seq); 29400fa753b3SRandall Stewart } 29410fa753b3SRandall Stewart sctp_flight_size_decrease(tp1); 2942299108c5SRandall Stewart if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { 2943299108c5SRandall Stewart (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) (tp1->whoTo, 2944299108c5SRandall Stewart tp1); 2945299108c5SRandall Stewart } 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) { 2959f79aab18SRandall Stewart if (*rto_ok) { 29600fa753b3SRandall Stewart tp1->whoTo->RTO = 29610fa753b3SRandall Stewart sctp_calculate_rto(stcb, 29620fa753b3SRandall Stewart &stcb->asoc, 29630fa753b3SRandall Stewart tp1->whoTo, 29640fa753b3SRandall Stewart &tp1->sent_rcv_time, 2965899288aeSRandall Stewart sctp_align_safe_nocopy, 2966f79aab18SRandall Stewart SCTP_RTT_FROM_DATA); 2967f79aab18SRandall Stewart *rto_ok = 0; 2968f79aab18SRandall Stewart } 2969f79aab18SRandall Stewart if (tp1->whoTo->rto_needed == 0) { 2970f79aab18SRandall Stewart tp1->whoTo->rto_needed = 1; 2971f79aab18SRandall Stewart } 29720fa753b3SRandall Stewart tp1->do_rtt = 0; 29730fa753b3SRandall Stewart } 29740fa753b3SRandall Stewart } 29750fa753b3SRandall Stewart } 29760fa753b3SRandall Stewart if (tp1->sent <= SCTP_DATAGRAM_RESEND) { 297720b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, 297820b07a4dSMichael Tuexen stcb->asoc.this_sack_highest_gap)) { 29790fa753b3SRandall Stewart stcb->asoc.this_sack_highest_gap = 29800fa753b3SRandall Stewart tp1->rec.data.TSN_seq; 29810fa753b3SRandall Stewart } 29820fa753b3SRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 29830fa753b3SRandall Stewart sctp_ucount_decr(stcb->asoc.sent_queue_retran_cnt); 29840fa753b3SRandall Stewart #ifdef SCTP_AUDITING_ENABLED 29850fa753b3SRandall Stewart sctp_audit_log(0xB2, 29860fa753b3SRandall Stewart (stcb->asoc.sent_queue_retran_cnt & 0x000000ff)); 29870fa753b3SRandall Stewart #endif 29880fa753b3SRandall Stewart } 29890fa753b3SRandall Stewart } 29900fa753b3SRandall Stewart /*- 29910fa753b3SRandall Stewart * All chunks NOT UNSENT fall through here and are marked 29920fa753b3SRandall Stewart * (leave PR-SCTP ones that are to skip alone though) 29930fa753b3SRandall Stewart */ 29942a498584SMichael Tuexen if ((tp1->sent != SCTP_FORWARD_TSN_SKIP) && 2995325c8c46SMichael Tuexen (tp1->sent != SCTP_DATAGRAM_NR_ACKED)) { 29960fa753b3SRandall Stewart tp1->sent = SCTP_DATAGRAM_MARKED; 29972a498584SMichael Tuexen } 29980fa753b3SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 29990fa753b3SRandall Stewart /* deflate the cwnd */ 30000fa753b3SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 30010fa753b3SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 30020fa753b3SRandall Stewart } 30030fa753b3SRandall Stewart /* NR Sack code here */ 3004325c8c46SMichael Tuexen if (nr_sacking && 3005325c8c46SMichael Tuexen (tp1->sent != SCTP_DATAGRAM_NR_ACKED)) { 3006325c8c46SMichael Tuexen if (stcb->asoc.strmout[tp1->rec.data.stream_number].chunks_on_queues > 0) { 3007325c8c46SMichael Tuexen stcb->asoc.strmout[tp1->rec.data.stream_number].chunks_on_queues--; 3008325c8c46SMichael Tuexen #ifdef INVARIANTS 3009325c8c46SMichael Tuexen } else { 3010325c8c46SMichael Tuexen panic("No chunks on the queues for sid %u.", tp1->rec.data.stream_number); 3011325c8c46SMichael Tuexen #endif 3012325c8c46SMichael Tuexen } 3013d96bef9cSMichael Tuexen if ((stcb->asoc.strmout[tp1->rec.data.stream_number].chunks_on_queues == 0) && 3014d96bef9cSMichael Tuexen (stcb->asoc.strmout[tp1->rec.data.stream_number].state == SCTP_STREAM_RESET_PENDING) && 3015d96bef9cSMichael Tuexen TAILQ_EMPTY(&stcb->asoc.strmout[tp1->rec.data.stream_number].outqueue)) { 3016d96bef9cSMichael Tuexen stcb->asoc.trigger_reset = 1; 3017d96bef9cSMichael Tuexen } 3018325c8c46SMichael Tuexen tp1->sent = SCTP_DATAGRAM_NR_ACKED; 30190fa753b3SRandall Stewart if (tp1->data) { 30200fa753b3SRandall Stewart /* 30210fa753b3SRandall Stewart * sa_ignore 30220fa753b3SRandall Stewart * NO_NULL_CHK 30230fa753b3SRandall Stewart */ 30240fa753b3SRandall Stewart sctp_free_bufspace(stcb, &stcb->asoc, tp1, 1); 30250fa753b3SRandall Stewart sctp_m_freem(tp1->data); 30260fa753b3SRandall Stewart tp1->data = NULL; 3027b5c16493SMichael Tuexen } 30280fa753b3SRandall Stewart wake_him++; 30290fa753b3SRandall Stewart } 30300fa753b3SRandall Stewart } 30310fa753b3SRandall Stewart break; 30320fa753b3SRandall Stewart } /* if (tp1->TSN_seq == theTSN) */ 303320b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, theTSN)) { 30340fa753b3SRandall Stewart break; 303520b07a4dSMichael Tuexen } 30360fa753b3SRandall Stewart tp1 = TAILQ_NEXT(tp1, sctp_next); 3037b5c16493SMichael Tuexen if ((tp1 == NULL) && (circled == 0)) { 3038b5c16493SMichael Tuexen circled++; 30390fa753b3SRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 30400fa753b3SRandall Stewart } 3041b5c16493SMichael Tuexen } /* end while (tp1) */ 3042b5c16493SMichael Tuexen if (tp1 == NULL) { 3043b5c16493SMichael Tuexen circled = 0; 3044b5c16493SMichael Tuexen tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); 3045b5c16493SMichael Tuexen } 3046b5c16493SMichael Tuexen /* In case the fragments were not in order we must reset */ 30470fa753b3SRandall Stewart } /* end for (j = fragStart */ 30480fa753b3SRandall Stewart *p_tp1 = tp1; 30490fa753b3SRandall Stewart return (wake_him); /* Return value only used for nr-sack */ 30500fa753b3SRandall Stewart } 30510fa753b3SRandall Stewart 30520fa753b3SRandall Stewart 3053cd554309SMichael Tuexen static int 3054458303daSRandall Stewart sctp_handle_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct sctp_association *asoc, 3055cd554309SMichael Tuexen uint32_t last_tsn, uint32_t * biggest_tsn_acked, 3056139bc87fSRandall Stewart uint32_t * biggest_newly_acked_tsn, uint32_t * this_sack_lowest_newack, 30577215cc1bSMichael Tuexen int num_seg, int num_nr_seg, int *rto_ok) 3058f8829a4aSRandall Stewart { 3059458303daSRandall Stewart struct sctp_gap_ack_block *frag, block; 3060f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 30610fa753b3SRandall Stewart int i; 3062f8829a4aSRandall Stewart int num_frs = 0; 3063cd554309SMichael Tuexen int chunk_freed; 3064cd554309SMichael Tuexen int non_revocable; 3065d9c5cfeaSMichael Tuexen uint16_t frag_strt, frag_end, prev_frag_end; 3066f8829a4aSRandall Stewart 3067d9c5cfeaSMichael Tuexen tp1 = TAILQ_FIRST(&asoc->sent_queue); 3068d9c5cfeaSMichael Tuexen prev_frag_end = 0; 3069cd554309SMichael Tuexen chunk_freed = 0; 3070f8829a4aSRandall Stewart 3071cd554309SMichael Tuexen for (i = 0; i < (num_seg + num_nr_seg); i++) { 3072d9c5cfeaSMichael Tuexen if (i == num_seg) { 3073d9c5cfeaSMichael Tuexen prev_frag_end = 0; 3074d9c5cfeaSMichael Tuexen tp1 = TAILQ_FIRST(&asoc->sent_queue); 3075d9c5cfeaSMichael Tuexen } 3076458303daSRandall Stewart frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, 3077458303daSRandall Stewart sizeof(struct sctp_gap_ack_block), (uint8_t *) & block); 3078458303daSRandall Stewart *offset += sizeof(block); 3079458303daSRandall Stewart if (frag == NULL) { 3080cd554309SMichael Tuexen return (chunk_freed); 3081458303daSRandall Stewart } 3082f8829a4aSRandall Stewart frag_strt = ntohs(frag->start); 3083f8829a4aSRandall Stewart frag_end = ntohs(frag->end); 3084d9c5cfeaSMichael Tuexen 3085f8829a4aSRandall Stewart if (frag_strt > frag_end) { 3086d9c5cfeaSMichael Tuexen /* This gap report is malformed, skip it. */ 3087f8829a4aSRandall Stewart continue; 3088f8829a4aSRandall Stewart } 3089d9c5cfeaSMichael Tuexen if (frag_strt <= prev_frag_end) { 3090d9c5cfeaSMichael Tuexen /* This gap report is not in order, so restart. */ 3091f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&asoc->sent_queue); 3092f8829a4aSRandall Stewart } 309320b07a4dSMichael Tuexen if (SCTP_TSN_GT((last_tsn + frag_end), *biggest_tsn_acked)) { 3094d9c5cfeaSMichael Tuexen *biggest_tsn_acked = last_tsn + frag_end; 3095f8829a4aSRandall Stewart } 3096cd554309SMichael Tuexen if (i < num_seg) { 3097cd554309SMichael Tuexen non_revocable = 0; 3098cd554309SMichael Tuexen } else { 3099cd554309SMichael Tuexen non_revocable = 1; 3100cd554309SMichael Tuexen } 3101cd554309SMichael Tuexen if (sctp_process_segment_range(stcb, &tp1, last_tsn, frag_strt, frag_end, 3102cd554309SMichael Tuexen non_revocable, &num_frs, biggest_newly_acked_tsn, 31037215cc1bSMichael Tuexen this_sack_lowest_newack, rto_ok)) { 3104cd554309SMichael Tuexen chunk_freed = 1; 3105458303daSRandall Stewart } 3106d9c5cfeaSMichael Tuexen prev_frag_end = frag_end; 3107f8829a4aSRandall Stewart } 3108b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 310980fefe0aSRandall Stewart if (num_frs) 311080fefe0aSRandall Stewart sctp_log_fr(*biggest_tsn_acked, 311180fefe0aSRandall Stewart *biggest_newly_acked_tsn, 311280fefe0aSRandall Stewart last_tsn, SCTP_FR_LOG_BIGGEST_TSNS); 311380fefe0aSRandall Stewart } 3114cd554309SMichael Tuexen return (chunk_freed); 3115f8829a4aSRandall Stewart } 3116f8829a4aSRandall Stewart 3117f8829a4aSRandall Stewart static void 3118c105859eSRandall Stewart sctp_check_for_revoked(struct sctp_tcb *stcb, 3119c105859eSRandall Stewart struct sctp_association *asoc, uint32_t cumack, 312063eda93dSMichael Tuexen uint32_t biggest_tsn_acked) 3121f8829a4aSRandall Stewart { 3122f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3123f8829a4aSRandall Stewart 31244a9ef3f8SMichael Tuexen TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 312520b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, cumack)) { 3126f8829a4aSRandall Stewart /* 3127f8829a4aSRandall Stewart * ok this guy is either ACK or MARKED. If it is 3128f8829a4aSRandall Stewart * ACKED it has been previously acked but not this 3129f8829a4aSRandall Stewart * time i.e. revoked. If it is MARKED it was ACK'ed 3130f8829a4aSRandall Stewart * again. 3131f8829a4aSRandall Stewart */ 313220b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, biggest_tsn_acked)) { 3133d06c82f1SRandall Stewart break; 313420b07a4dSMichael Tuexen } 3135f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_ACKED) { 3136f8829a4aSRandall Stewart /* it has been revoked */ 3137f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 3138f8829a4aSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 3139a5d547adSRandall Stewart /* 314042551e99SRandall Stewart * We must add this stuff back in to assure 314142551e99SRandall Stewart * timers and such get started. 3142a5d547adSRandall Stewart */ 3143b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3144c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 3145c105859eSRandall Stewart tp1->whoTo->flight_size, 3146c105859eSRandall Stewart tp1->book_size, 31479a8e3088SMichael Tuexen (uint32_t) (uintptr_t) tp1->whoTo, 3148c105859eSRandall Stewart tp1->rec.data.TSN_seq); 314980fefe0aSRandall Stewart } 3150c105859eSRandall Stewart sctp_flight_size_increase(tp1); 3151c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 315242551e99SRandall Stewart /* 315342551e99SRandall Stewart * We inflate the cwnd to compensate for our 315442551e99SRandall Stewart * artificial inflation of the flight_size. 315542551e99SRandall Stewart */ 315642551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 3157b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 3158f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 3159f8829a4aSRandall Stewart cumack, 3160f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3161f8829a4aSRandall Stewart 0, 3162f8829a4aSRandall Stewart 0, 3163f8829a4aSRandall Stewart SCTP_LOG_TSN_REVOKED); 316480fefe0aSRandall Stewart } 3165f8829a4aSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_MARKED) { 3166f8829a4aSRandall Stewart /* it has been re-acked in this SACK */ 3167f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 3168f8829a4aSRandall Stewart } 3169f8829a4aSRandall Stewart } 3170f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) 3171f8829a4aSRandall Stewart break; 3172f8829a4aSRandall Stewart } 3173f8829a4aSRandall Stewart } 3174f8829a4aSRandall Stewart 3175830d754dSRandall Stewart 3176f8829a4aSRandall Stewart static void 3177f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, 317863eda93dSMichael Tuexen uint32_t biggest_tsn_acked, uint32_t biggest_tsn_newly_acked, uint32_t this_sack_lowest_newack, int accum_moved) 3179f8829a4aSRandall Stewart { 3180f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1; 3181f8829a4aSRandall Stewart int strike_flag = 0; 3182f8829a4aSRandall Stewart struct timeval now; 3183f8829a4aSRandall Stewart int tot_retrans = 0; 3184f8829a4aSRandall Stewart uint32_t sending_seq; 3185f8829a4aSRandall Stewart struct sctp_nets *net; 3186f8829a4aSRandall Stewart int num_dests_sacked = 0; 3187f8829a4aSRandall Stewart 3188f8829a4aSRandall Stewart /* 3189f8829a4aSRandall Stewart * select the sending_seq, this is either the next thing ready to be 3190f8829a4aSRandall Stewart * sent but not transmitted, OR, the next seq we assign. 3191f8829a4aSRandall Stewart */ 3192f8829a4aSRandall Stewart tp1 = TAILQ_FIRST(&stcb->asoc.send_queue); 3193f8829a4aSRandall Stewart if (tp1 == NULL) { 3194f8829a4aSRandall Stewart sending_seq = asoc->sending_seq; 3195f8829a4aSRandall Stewart } else { 3196f8829a4aSRandall Stewart sending_seq = tp1->rec.data.TSN_seq; 3197f8829a4aSRandall Stewart } 3198f8829a4aSRandall Stewart 3199f8829a4aSRandall Stewart /* CMT DAC algo: finding out if SACK is a mixed SACK */ 32007c99d56fSMichael Tuexen if ((asoc->sctp_cmt_on_off > 0) && 320120083c2eSMichael Tuexen SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { 3202f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 3203f8829a4aSRandall Stewart if (net->saw_newack) 3204f8829a4aSRandall Stewart num_dests_sacked++; 3205f8829a4aSRandall Stewart } 3206f8829a4aSRandall Stewart } 3207dd973b0eSMichael Tuexen if (stcb->asoc.prsctp_supported) { 32086e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 3209f8829a4aSRandall Stewart } 32104a9ef3f8SMichael Tuexen TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 3211f8829a4aSRandall Stewart strike_flag = 0; 3212f8829a4aSRandall Stewart if (tp1->no_fr_allowed) { 3213f8829a4aSRandall Stewart /* this one had a timeout or something */ 3214f8829a4aSRandall Stewart continue; 3215f8829a4aSRandall Stewart } 3216b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3217f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) 3218f8829a4aSRandall Stewart sctp_log_fr(biggest_tsn_newly_acked, 3219f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 3220f8829a4aSRandall Stewart tp1->sent, 3221f8829a4aSRandall Stewart SCTP_FR_LOG_CHECK_STRIKE); 322280fefe0aSRandall Stewart } 322320b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, biggest_tsn_acked) || 3224f8829a4aSRandall Stewart tp1->sent == SCTP_DATAGRAM_UNSENT) { 3225f8829a4aSRandall Stewart /* done */ 3226f8829a4aSRandall Stewart break; 3227f8829a4aSRandall Stewart } 3228dd973b0eSMichael Tuexen if (stcb->asoc.prsctp_supported) { 3229f8829a4aSRandall Stewart if ((PR_SCTP_TTL_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) { 3230f8829a4aSRandall Stewart /* Is it expired? */ 323199ddc825SMichael Tuexen if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) { 3232f8829a4aSRandall Stewart /* Yes so drop it */ 3233f8829a4aSRandall Stewart if (tp1->data != NULL) { 32341edc9dbaSMichael Tuexen (void)sctp_release_pr_sctp_chunk(stcb, tp1, 1, 32350c0982b8SRandall Stewart SCTP_SO_NOT_LOCKED); 3236f8829a4aSRandall Stewart } 3237f8829a4aSRandall Stewart continue; 3238f8829a4aSRandall Stewart } 3239f8829a4aSRandall Stewart } 3240f8829a4aSRandall Stewart } 324120b07a4dSMichael 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; 326520b07a4dSMichael Tuexen } else if (tp1->whoTo && SCTP_TSN_GT(tp1->rec.data.TSN_seq, 326620b07a4dSMichael 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) && 331720b07a4dSMichael 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 334920b07a4dSMichael 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) && 338920b07a4dSMichael Tuexen SCTP_TSN_GT(this_sack_lowest_newack, 339020b07a4dSMichael 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 */ 340820b07a4dSMichael Tuexen } else if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, 340920b07a4dSMichael 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) && 344220b07a4dSMichael 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, 34619a8e3088SMichael Tuexen (uint32_t) (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); 3467299108c5SRandall Stewart if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { 3468299108c5SRandall Stewart (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) (tp1->whoTo, 3469299108c5SRandall Stewart tp1); 3470299108c5SRandall Stewart } 3471544e35bdSRandall Stewart } 3472544e35bdSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 3473544e35bdSRandall Stewart sctp_log_rwnd(SCTP_INCREASE_PEER_RWND, 3474544e35bdSRandall Stewart asoc->peers_rwnd, tp1->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 3475544e35bdSRandall Stewart } 3476544e35bdSRandall Stewart /* add back to the rwnd */ 3477544e35bdSRandall Stewart asoc->peers_rwnd += (tp1->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); 3478544e35bdSRandall Stewart 3479544e35bdSRandall Stewart /* remove from the total flight */ 3480544e35bdSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 3481544e35bdSRandall Stewart 3482dd973b0eSMichael Tuexen if ((stcb->asoc.prsctp_supported) && 3483475d0674SMichael Tuexen (PR_SCTP_RTX_ENABLED(tp1->flags))) { 3484475d0674SMichael Tuexen /* 3485475d0674SMichael Tuexen * Has it been retransmitted tv_sec times? - 3486475d0674SMichael Tuexen * we store the retran count there. 3487475d0674SMichael Tuexen */ 3488475d0674SMichael Tuexen if (tp1->snd_count > tp1->rec.data.timetodrop.tv_sec) { 3489475d0674SMichael Tuexen /* Yes, so drop it */ 3490475d0674SMichael Tuexen if (tp1->data != NULL) { 34911edc9dbaSMichael Tuexen (void)sctp_release_pr_sctp_chunk(stcb, tp1, 1, 3492475d0674SMichael Tuexen SCTP_SO_NOT_LOCKED); 3493475d0674SMichael Tuexen } 3494475d0674SMichael Tuexen /* Make sure to flag we had a FR */ 3495475d0674SMichael Tuexen tp1->whoTo->net_ack++; 3496475d0674SMichael Tuexen continue; 3497475d0674SMichael Tuexen } 3498475d0674SMichael Tuexen } 3499cd3fd531SMichael Tuexen /* 3500cd3fd531SMichael Tuexen * SCTP_PRINTF("OK, we are now ready to FR this 3501cd3fd531SMichael Tuexen * guy\n"); 3502cd3fd531SMichael Tuexen */ 3503b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { 3504f8829a4aSRandall Stewart sctp_log_fr(tp1->rec.data.TSN_seq, tp1->snd_count, 3505f8829a4aSRandall Stewart 0, SCTP_FR_MARKED); 350680fefe0aSRandall Stewart } 3507f8829a4aSRandall Stewart if (strike_flag) { 3508f8829a4aSRandall Stewart /* This is a subsequent FR */ 3509f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_sendmultfastretrans); 3510f8829a4aSRandall Stewart } 35115e54f665SRandall Stewart sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); 35127c99d56fSMichael Tuexen if (asoc->sctp_cmt_on_off > 0) { 3513f8829a4aSRandall Stewart /* 3514f8829a4aSRandall Stewart * CMT: Using RTX_SSTHRESH policy for CMT. 3515f8829a4aSRandall Stewart * If CMT is being used, then pick dest with 3516f8829a4aSRandall Stewart * largest ssthresh for any retransmission. 3517f8829a4aSRandall Stewart */ 3518f8829a4aSRandall Stewart tp1->no_fr_allowed = 1; 3519f8829a4aSRandall Stewart alt = tp1->whoTo; 35203c503c28SRandall Stewart /* sa_ignore NO_NULL_CHK */ 352120083c2eSMichael Tuexen if (asoc->sctp_cmt_pf > 0) { 3522b54d3a6cSRandall Stewart /* 3523b54d3a6cSRandall Stewart * JRS 5/18/07 - If CMT PF is on, 3524b54d3a6cSRandall Stewart * use the PF version of 3525b54d3a6cSRandall Stewart * find_alt_net() 3526b54d3a6cSRandall Stewart */ 3527b54d3a6cSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 2); 3528b54d3a6cSRandall Stewart } else { 3529b54d3a6cSRandall Stewart /* 3530b54d3a6cSRandall Stewart * JRS 5/18/07 - If only CMT is on, 3531b54d3a6cSRandall Stewart * use the CMT version of 3532b54d3a6cSRandall Stewart * find_alt_net() 3533b54d3a6cSRandall Stewart */ 353452be287eSRandall Stewart /* sa_ignore NO_NULL_CHK */ 3535f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, alt, 1); 3536b54d3a6cSRandall Stewart } 3537ad81507eSRandall Stewart if (alt == NULL) { 3538ad81507eSRandall Stewart alt = tp1->whoTo; 3539ad81507eSRandall Stewart } 3540f8829a4aSRandall Stewart /* 3541f8829a4aSRandall Stewart * CUCv2: If a different dest is picked for 3542f8829a4aSRandall Stewart * the retransmission, then new 3543f8829a4aSRandall Stewart * (rtx-)pseudo_cumack needs to be tracked 3544f8829a4aSRandall Stewart * for orig dest. Let CUCv2 track new (rtx-) 3545f8829a4aSRandall Stewart * pseudo-cumack always. 3546f8829a4aSRandall Stewart */ 3547ad81507eSRandall Stewart if (tp1->whoTo) { 3548f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 3549f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 3550ad81507eSRandall Stewart } 3551f8829a4aSRandall Stewart } else {/* CMT is OFF */ 3552f8829a4aSRandall Stewart 3553f8829a4aSRandall Stewart #ifdef SCTP_FR_TO_ALTERNATE 3554f8829a4aSRandall Stewart /* Can we find an alternate? */ 3555f8829a4aSRandall Stewart alt = sctp_find_alternate_net(stcb, tp1->whoTo, 0); 3556f8829a4aSRandall Stewart #else 3557f8829a4aSRandall Stewart /* 3558f8829a4aSRandall Stewart * default behavior is to NOT retransmit 3559f8829a4aSRandall Stewart * FR's to an alternate. Armando Caro's 3560f8829a4aSRandall Stewart * paper details why. 3561f8829a4aSRandall Stewart */ 3562f8829a4aSRandall Stewart alt = tp1->whoTo; 3563f8829a4aSRandall Stewart #endif 3564f8829a4aSRandall Stewart } 3565f8829a4aSRandall Stewart 3566f8829a4aSRandall Stewart tp1->rec.data.doing_fast_retransmit = 1; 3567f8829a4aSRandall Stewart tot_retrans++; 3568f8829a4aSRandall Stewart /* mark the sending seq for possible subsequent FR's */ 3569f8829a4aSRandall Stewart /* 3570cd3fd531SMichael Tuexen * SCTP_PRINTF("Marking TSN for FR new value %x\n", 3571f8829a4aSRandall Stewart * (uint32_t)tpi->rec.data.TSN_seq); 3572f8829a4aSRandall Stewart */ 3573f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue)) { 3574f8829a4aSRandall Stewart /* 3575f8829a4aSRandall Stewart * If the queue of send is empty then its 3576f8829a4aSRandall Stewart * the next sequence number that will be 3577f8829a4aSRandall Stewart * assigned so we subtract one from this to 3578f8829a4aSRandall Stewart * get the one we last sent. 3579f8829a4aSRandall Stewart */ 3580f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = sending_seq; 3581f8829a4aSRandall Stewart } else { 3582f8829a4aSRandall Stewart /* 3583f8829a4aSRandall Stewart * If there are chunks on the send queue 3584f8829a4aSRandall Stewart * (unsent data that has made it from the 3585f8829a4aSRandall Stewart * stream queues but not out the door, we 3586f8829a4aSRandall Stewart * take the first one (which will have the 3587f8829a4aSRandall Stewart * lowest TSN) and subtract one to get the 3588f8829a4aSRandall Stewart * one we last sent. 3589f8829a4aSRandall Stewart */ 3590f8829a4aSRandall Stewart struct sctp_tmit_chunk *ttt; 3591f8829a4aSRandall Stewart 3592f8829a4aSRandall Stewart ttt = TAILQ_FIRST(&asoc->send_queue); 3593f8829a4aSRandall Stewart tp1->rec.data.fast_retran_tsn = 3594f8829a4aSRandall Stewart ttt->rec.data.TSN_seq; 3595f8829a4aSRandall Stewart } 3596f8829a4aSRandall Stewart 3597f8829a4aSRandall Stewart if (tp1->do_rtt) { 3598f8829a4aSRandall Stewart /* 3599f8829a4aSRandall Stewart * this guy had a RTO calculation pending on 3600f8829a4aSRandall Stewart * it, cancel it 3601f8829a4aSRandall Stewart */ 360260990c0cSMichael Tuexen if ((tp1->whoTo != NULL) && 360360990c0cSMichael Tuexen (tp1->whoTo->rto_needed == 0)) { 3604f79aab18SRandall Stewart tp1->whoTo->rto_needed = 1; 3605f79aab18SRandall Stewart } 3606f8829a4aSRandall Stewart tp1->do_rtt = 0; 3607f8829a4aSRandall Stewart } 3608f8829a4aSRandall Stewart if (alt != tp1->whoTo) { 3609f8829a4aSRandall Stewart /* yes, there is an alternate. */ 3610f8829a4aSRandall Stewart sctp_free_remote_addr(tp1->whoTo); 36113c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 3612f8829a4aSRandall Stewart tp1->whoTo = alt; 3613f8829a4aSRandall Stewart atomic_add_int(&alt->ref_count, 1); 3614f8829a4aSRandall Stewart } 3615f8829a4aSRandall Stewart } 36164a9ef3f8SMichael Tuexen } 3617f8829a4aSRandall Stewart } 3618f8829a4aSRandall Stewart 3619f8829a4aSRandall Stewart struct sctp_tmit_chunk * 3620f8829a4aSRandall Stewart sctp_try_advance_peer_ack_point(struct sctp_tcb *stcb, 3621f8829a4aSRandall Stewart struct sctp_association *asoc) 3622f8829a4aSRandall Stewart { 3623f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2, *a_adv = NULL; 3624f8829a4aSRandall Stewart struct timeval now; 3625f8829a4aSRandall Stewart int now_filled = 0; 3626f8829a4aSRandall Stewart 3627dd973b0eSMichael Tuexen if (asoc->prsctp_supported == 0) { 3628f8829a4aSRandall Stewart return (NULL); 3629f8829a4aSRandall Stewart } 36304a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) { 3631f8829a4aSRandall Stewart if (tp1->sent != SCTP_FORWARD_TSN_SKIP && 363298f2956cSMichael Tuexen tp1->sent != SCTP_DATAGRAM_RESEND && 3633325c8c46SMichael Tuexen tp1->sent != SCTP_DATAGRAM_NR_ACKED) { 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) { 36382a498584SMichael Tuexen if ((tp1->sent == SCTP_FORWARD_TSN_SKIP) || 3639325c8c46SMichael Tuexen (tp1->sent == SCTP_DATAGRAM_NR_ACKED)) { 36400c0982b8SRandall Stewart sctp_misc_ints(SCTP_FWD_TSN_CHECK, 36410c0982b8SRandall Stewart asoc->advanced_peer_ack_point, 36420c0982b8SRandall Stewart tp1->rec.data.TSN_seq, 0, 0); 36430c0982b8SRandall Stewart } 36440c0982b8SRandall Stewart } 3645f8829a4aSRandall Stewart if (!PR_SCTP_ENABLED(tp1->flags)) { 3646f8829a4aSRandall Stewart /* 3647f8829a4aSRandall Stewart * We can't fwd-tsn past any that are reliable aka 3648f8829a4aSRandall Stewart * retransmitted until the asoc fails. 3649f8829a4aSRandall Stewart */ 3650f8829a4aSRandall Stewart break; 3651f8829a4aSRandall Stewart } 3652f8829a4aSRandall Stewart if (!now_filled) { 36536e55db54SRandall Stewart (void)SCTP_GETTIME_TIMEVAL(&now); 3654f8829a4aSRandall Stewart now_filled = 1; 3655f8829a4aSRandall Stewart } 3656f8829a4aSRandall Stewart /* 3657f8829a4aSRandall Stewart * now we got a chunk which is marked for another 3658f8829a4aSRandall Stewart * retransmission to a PR-stream but has run out its chances 3659f8829a4aSRandall Stewart * already maybe OR has been marked to skip now. Can we skip 3660f8829a4aSRandall Stewart * it if its a resend? 3661f8829a4aSRandall Stewart */ 3662f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND && 3663f8829a4aSRandall Stewart (PR_SCTP_TTL_ENABLED(tp1->flags))) { 3664f8829a4aSRandall Stewart /* 3665f8829a4aSRandall Stewart * Now is this one marked for resend and its time is 3666f8829a4aSRandall Stewart * now up? 3667f8829a4aSRandall Stewart */ 3668f8829a4aSRandall Stewart if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) { 3669f8829a4aSRandall Stewart /* Yes so drop it */ 3670f8829a4aSRandall Stewart if (tp1->data) { 3671ad81507eSRandall Stewart (void)sctp_release_pr_sctp_chunk(stcb, tp1, 36721edc9dbaSMichael Tuexen 1, 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 */ 368798f2956cSMichael Tuexen if ((tp1->sent == SCTP_FORWARD_TSN_SKIP) || 3688325c8c46SMichael Tuexen (tp1->sent == SCTP_DATAGRAM_NR_ACKED)) { 3689f8829a4aSRandall Stewart /* advance PeerAckPoint goes forward */ 369020b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, asoc->advanced_peer_ack_point)) { 3691f8829a4aSRandall Stewart asoc->advanced_peer_ack_point = tp1->rec.data.TSN_seq; 3692f8829a4aSRandall Stewart a_adv = tp1; 36930c0982b8SRandall Stewart } else if (tp1->rec.data.TSN_seq == asoc->advanced_peer_ack_point) { 36940c0982b8SRandall Stewart /* No update but we do save the chk */ 36950c0982b8SRandall Stewart a_adv = tp1; 36960c0982b8SRandall Stewart } 3697f8829a4aSRandall Stewart } else { 3698f8829a4aSRandall Stewart /* 3699f8829a4aSRandall Stewart * If it is still in RESEND we can advance no 3700f8829a4aSRandall Stewart * further 3701f8829a4aSRandall Stewart */ 3702f8829a4aSRandall Stewart break; 3703f8829a4aSRandall Stewart } 3704f8829a4aSRandall Stewart } 3705f8829a4aSRandall Stewart return (a_adv); 3706f8829a4aSRandall Stewart } 3707f8829a4aSRandall Stewart 37080c0982b8SRandall Stewart static int 3709c105859eSRandall Stewart sctp_fs_audit(struct sctp_association *asoc) 3710bff64a4dSRandall Stewart { 3711bff64a4dSRandall Stewart struct sctp_tmit_chunk *chk; 3712afd67482SMichael Tuexen int inflight = 0, resend = 0, inbetween = 0, acked = 0, above = 0; 3713548f47a8SMichael Tuexen int ret; 37140c0982b8SRandall Stewart 3715548f47a8SMichael Tuexen #ifndef INVARIANTS 3716548f47a8SMichael Tuexen int entry_flight, entry_cnt; 3717548f47a8SMichael Tuexen 3718548f47a8SMichael Tuexen #endif 3719548f47a8SMichael Tuexen 3720548f47a8SMichael Tuexen ret = 0; 3721548f47a8SMichael Tuexen #ifndef INVARIANTS 37220c0982b8SRandall Stewart entry_flight = asoc->total_flight; 37230c0982b8SRandall Stewart entry_cnt = asoc->total_flight_count; 3724548f47a8SMichael Tuexen #endif 37250c0982b8SRandall Stewart if (asoc->pr_sctp_cnt >= asoc->sent_queue_cnt) 37260c0982b8SRandall Stewart return (0); 3727bff64a4dSRandall Stewart 3728bff64a4dSRandall Stewart TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { 3729bff64a4dSRandall Stewart if (chk->sent < SCTP_DATAGRAM_RESEND) { 3730cd3fd531SMichael Tuexen SCTP_PRINTF("Chk TSN: %u size: %d inflight cnt: %d\n", 37310c0982b8SRandall Stewart chk->rec.data.TSN_seq, 37320c0982b8SRandall Stewart chk->send_size, 3733cd3fd531SMichael Tuexen chk->snd_count); 3734bff64a4dSRandall Stewart inflight++; 3735bff64a4dSRandall Stewart } else if (chk->sent == SCTP_DATAGRAM_RESEND) { 3736bff64a4dSRandall Stewart resend++; 3737bff64a4dSRandall Stewart } else if (chk->sent < SCTP_DATAGRAM_ACKED) { 3738bff64a4dSRandall Stewart inbetween++; 3739bff64a4dSRandall Stewart } else if (chk->sent > SCTP_DATAGRAM_ACKED) { 3740bff64a4dSRandall Stewart above++; 3741bff64a4dSRandall Stewart } else { 3742bff64a4dSRandall Stewart acked++; 3743bff64a4dSRandall Stewart } 3744bff64a4dSRandall Stewart } 3745f1f73e57SRandall Stewart 3746c105859eSRandall Stewart if ((inflight > 0) || (inbetween > 0)) { 3747f1f73e57SRandall Stewart #ifdef INVARIANTS 3748c105859eSRandall Stewart panic("Flight size-express incorrect? \n"); 3749f1f73e57SRandall Stewart #else 3750cd3fd531SMichael Tuexen SCTP_PRINTF("asoc->total_flight: %d cnt: %d\n", 37510c0982b8SRandall Stewart entry_flight, entry_cnt); 37520c0982b8SRandall Stewart 37530c0982b8SRandall Stewart SCTP_PRINTF("Flight size-express incorrect F: %d I: %d R: %d Ab: %d ACK: %d\n", 37540c0982b8SRandall Stewart inflight, inbetween, resend, above, acked); 37550c0982b8SRandall Stewart ret = 1; 3756f1f73e57SRandall Stewart #endif 3757bff64a4dSRandall Stewart } 37580c0982b8SRandall Stewart return (ret); 3759c105859eSRandall Stewart } 3760c105859eSRandall Stewart 3761c105859eSRandall Stewart 3762c105859eSRandall Stewart static void 3763c105859eSRandall Stewart sctp_window_probe_recovery(struct sctp_tcb *stcb, 3764c105859eSRandall Stewart struct sctp_association *asoc, 3765c105859eSRandall Stewart struct sctp_tmit_chunk *tp1) 3766c105859eSRandall Stewart { 3767dfb11ef8SRandall Stewart tp1->window_probe = 0; 37685171328bSRandall Stewart if ((tp1->sent >= SCTP_DATAGRAM_ACKED) || (tp1->data == NULL)) { 3769dfb11ef8SRandall Stewart /* TSN's skipped we do NOT move back. */ 3770dfb11ef8SRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DWN_WP_FWD, 37718427b3fdSMichael Tuexen tp1->whoTo ? tp1->whoTo->flight_size : 0, 3772dfb11ef8SRandall Stewart tp1->book_size, 37739a8e3088SMichael Tuexen (uint32_t) (uintptr_t) tp1->whoTo, 3774dfb11ef8SRandall Stewart tp1->rec.data.TSN_seq); 3775dfb11ef8SRandall Stewart return; 3776dfb11ef8SRandall Stewart } 37775171328bSRandall Stewart /* First setup this by shrinking flight */ 3778299108c5SRandall Stewart if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { 3779299108c5SRandall Stewart (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) (tp1->whoTo, 3780299108c5SRandall Stewart tp1); 3781299108c5SRandall Stewart } 37825171328bSRandall Stewart sctp_flight_size_decrease(tp1); 37835171328bSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 37845171328bSRandall Stewart /* Now mark for resend */ 37855171328bSRandall Stewart tp1->sent = SCTP_DATAGRAM_RESEND; 3786791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 3787791437b5SRandall Stewart 3788b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3789c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_WP, 3790c105859eSRandall Stewart tp1->whoTo->flight_size, 3791c105859eSRandall Stewart tp1->book_size, 37929a8e3088SMichael Tuexen (uint32_t) (uintptr_t) tp1->whoTo, 3793c105859eSRandall Stewart tp1->rec.data.TSN_seq); 379480fefe0aSRandall Stewart } 3795c105859eSRandall Stewart } 3796c105859eSRandall Stewart 3797f8829a4aSRandall Stewart void 3798f8829a4aSRandall Stewart sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, 3799899288aeSRandall Stewart uint32_t rwnd, int *abort_now, int ecne_seen) 3800f8829a4aSRandall Stewart { 3801f8829a4aSRandall Stewart struct sctp_nets *net; 3802f8829a4aSRandall Stewart struct sctp_association *asoc; 3803f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 38045e54f665SRandall Stewart uint32_t old_rwnd; 38055e54f665SRandall Stewart int win_probe_recovery = 0; 3806c105859eSRandall Stewart int win_probe_recovered = 0; 3807d06c82f1SRandall Stewart int j, done_once = 0; 3808f79aab18SRandall Stewart int rto_ok = 1; 3809fd60718dSMichael Tuexen uint32_t send_s; 3810f8829a4aSRandall Stewart 3811b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 3812d06c82f1SRandall Stewart sctp_misc_ints(SCTP_SACK_LOG_EXPRESS, cumack, 3813d06c82f1SRandall Stewart rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 381480fefe0aSRandall Stewart } 3815f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 381618e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 381718e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cumack; 381818e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 381918e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 382018e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 382118e198d3SRandall Stewart } 382218e198d3SRandall Stewart #endif 3823f8829a4aSRandall Stewart asoc = &stcb->asoc; 3824d06c82f1SRandall Stewart old_rwnd = asoc->peers_rwnd; 382520b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->last_acked_seq, cumack)) { 38265e54f665SRandall Stewart /* old ack */ 38275e54f665SRandall Stewart return; 3828d06c82f1SRandall Stewart } else if (asoc->last_acked_seq == cumack) { 3829d06c82f1SRandall Stewart /* Window update sack */ 3830d06c82f1SRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 383144fbe462SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 3832d06c82f1SRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 3833d06c82f1SRandall Stewart /* SWS sender side engages */ 3834d06c82f1SRandall Stewart asoc->peers_rwnd = 0; 3835d06c82f1SRandall Stewart } 3836d06c82f1SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 3837d06c82f1SRandall Stewart goto again; 3838d06c82f1SRandall Stewart } 3839d06c82f1SRandall Stewart return; 38405e54f665SRandall Stewart } 3841f8829a4aSRandall Stewart /* First setup for CC stuff */ 3842f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 3843a21779f0SRandall Stewart if (SCTP_TSN_GT(cumack, net->cwr_window_tsn)) { 3844a21779f0SRandall Stewart /* Drag along the window_tsn for cwr's */ 3845a21779f0SRandall Stewart net->cwr_window_tsn = cumack; 3846a21779f0SRandall Stewart } 3847f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 3848f8829a4aSRandall Stewart net->net_ack = 0; 3849f8829a4aSRandall Stewart net->net_ack2 = 0; 3850132dea7dSRandall Stewart 3851132dea7dSRandall Stewart /* 3852132dea7dSRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 3853132dea7dSRandall Stewart * SACK processing 3854132dea7dSRandall Stewart */ 3855132dea7dSRandall Stewart net->new_pseudo_cumack = 0; 3856132dea7dSRandall Stewart net->will_exit_fast_recovery = 0; 3857299108c5SRandall Stewart if (stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack) { 3858299108c5SRandall Stewart (*stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack) (stcb, net); 3859299108c5SRandall Stewart } 3860f8829a4aSRandall Stewart } 3861c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 3862c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 3863c105859eSRandall Stewart sctpchunk_listhead); 3864c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 3865139bc87fSRandall Stewart } else { 3866c105859eSRandall Stewart send_s = asoc->sending_seq; 3867139bc87fSRandall Stewart } 386820b07a4dSMichael Tuexen if (SCTP_TSN_GE(cumack, send_s)) { 3869ff1ffd74SMichael Tuexen struct mbuf *op_err; 3870ff1ffd74SMichael Tuexen char msg[SCTP_DIAG_INFO_LEN]; 3871139bc87fSRandall Stewart 3872139bc87fSRandall Stewart *abort_now = 1; 3873139bc87fSRandall Stewart /* XXX */ 387455f8a4bbSMichael Tuexen snprintf(msg, sizeof(msg), "Cum ack %8.8x greater or equal than TSN %8.8x", 3875ff1ffd74SMichael Tuexen cumack, send_s); 3876ff1ffd74SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 387744249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_21; 3878ff1ffd74SMichael Tuexen sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 3879139bc87fSRandall Stewart return; 3880139bc87fSRandall Stewart } 3881f8829a4aSRandall Stewart asoc->this_sack_highest_gap = cumack; 3882b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 3883c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 3884c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 3885c4739e2fSRandall Stewart 0, 3886c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 3887c4739e2fSRandall Stewart __LINE__); 3888c4739e2fSRandall Stewart } 3889f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 389020b07a4dSMichael Tuexen if (SCTP_TSN_GT(cumack, asoc->last_acked_seq)) { 3891f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 38924a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) { 389320b07a4dSMichael Tuexen if (SCTP_TSN_GE(cumack, tp1->rec.data.TSN_seq)) { 389418e198d3SRandall Stewart if (tp1->sent == SCTP_DATAGRAM_UNSENT) { 3895cd3fd531SMichael Tuexen SCTP_PRINTF("Warning, an unsent is now acked?\n"); 389618e198d3SRandall Stewart } 3897f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 3898f8829a4aSRandall Stewart /* 389918e198d3SRandall Stewart * If it is less than ACKED, it is 390018e198d3SRandall Stewart * now no-longer in flight. Higher 390118e198d3SRandall Stewart * values may occur during marking 3902f8829a4aSRandall Stewart */ 3903c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 3904b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 3905c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 3906a5d547adSRandall Stewart tp1->whoTo->flight_size, 3907a5d547adSRandall Stewart tp1->book_size, 39089a8e3088SMichael Tuexen (uint32_t) (uintptr_t) tp1->whoTo, 3909a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 391080fefe0aSRandall Stewart } 3911c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 3912299108c5SRandall Stewart if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { 3913299108c5SRandall Stewart (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) (tp1->whoTo, 3914299108c5SRandall Stewart tp1); 3915299108c5SRandall Stewart } 391604ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 3917c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 3918f8829a4aSRandall Stewart } 3919f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 3920f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 3921f8829a4aSRandall Stewart /* 392218e198d3SRandall Stewart * True non-retransmited 3923f8829a4aSRandall Stewart * chunk 3924f8829a4aSRandall Stewart */ 3925f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 3926f8829a4aSRandall Stewart tp1->send_size; 3927f8829a4aSRandall Stewart 3928f8829a4aSRandall Stewart /* update RTO too? */ 392962c1ff9cSRandall Stewart if (tp1->do_rtt) { 3930f79aab18SRandall Stewart if (rto_ok) { 3931f8829a4aSRandall Stewart tp1->whoTo->RTO = 393204ee05e8SRandall Stewart /* 393304ee05e8SRandall Stewart * sa_ignore 3934f79aab18SRandall Stewart * NO_NULL_CH 3935f79aab18SRandall Stewart * K 393604ee05e8SRandall Stewart */ 3937f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 3938f8829a4aSRandall Stewart asoc, tp1->whoTo, 393918e198d3SRandall Stewart &tp1->sent_rcv_time, 3940899288aeSRandall Stewart sctp_align_safe_nocopy, 3941f79aab18SRandall Stewart SCTP_RTT_FROM_DATA); 3942f79aab18SRandall Stewart rto_ok = 0; 3943f79aab18SRandall Stewart } 3944f79aab18SRandall Stewart if (tp1->whoTo->rto_needed == 0) { 3945f79aab18SRandall Stewart tp1->whoTo->rto_needed = 1; 3946f79aab18SRandall Stewart } 3947f8829a4aSRandall Stewart tp1->do_rtt = 0; 3948f8829a4aSRandall Stewart } 3949f8829a4aSRandall Stewart } 3950132dea7dSRandall Stewart /* 395118e198d3SRandall Stewart * CMT: CUCv2 algorithm. From the 395218e198d3SRandall Stewart * cumack'd TSNs, for each TSN being 395318e198d3SRandall Stewart * acked for the first time, set the 395418e198d3SRandall Stewart * following variables for the 395518e198d3SRandall Stewart * corresp destination. 395618e198d3SRandall Stewart * new_pseudo_cumack will trigger a 395718e198d3SRandall Stewart * cwnd update. 395818e198d3SRandall Stewart * find_(rtx_)pseudo_cumack will 395918e198d3SRandall Stewart * trigger search for the next 396018e198d3SRandall Stewart * expected (rtx-)pseudo-cumack. 3961132dea7dSRandall Stewart */ 3962132dea7dSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 3963132dea7dSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 3964132dea7dSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 3965132dea7dSRandall Stewart 3966b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 396704ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 3968f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 396980fefe0aSRandall Stewart } 3970f8829a4aSRandall Stewart } 3971f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 3972f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 3973f8829a4aSRandall Stewart } 397442551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 397542551e99SRandall Stewart /* deflate the cwnd */ 397642551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 397742551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 397842551e99SRandall Stewart } 3979325c8c46SMichael Tuexen if (tp1->sent != SCTP_DATAGRAM_NR_ACKED) { 3980a7ad6026SMichael Tuexen if (asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues > 0) { 3981a7ad6026SMichael Tuexen asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues--; 3982a7ad6026SMichael Tuexen #ifdef INVARIANTS 3983a7ad6026SMichael Tuexen } else { 3984a7ad6026SMichael Tuexen panic("No chunks on the queues for sid %u.", tp1->rec.data.stream_number); 3985a7ad6026SMichael Tuexen #endif 3986a7ad6026SMichael Tuexen } 3987a7ad6026SMichael Tuexen } 3988d96bef9cSMichael Tuexen if ((asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues == 0) && 3989d96bef9cSMichael Tuexen (asoc->strmout[tp1->rec.data.stream_number].state == SCTP_STREAM_RESET_PENDING) && 3990d96bef9cSMichael Tuexen TAILQ_EMPTY(&asoc->strmout[tp1->rec.data.stream_number].outqueue)) { 3991d96bef9cSMichael Tuexen asoc->trigger_reset = 1; 3992d96bef9cSMichael Tuexen } 3993f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 3994f8829a4aSRandall Stewart if (tp1->data) { 399504ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 3996f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 3997f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 39984a9ef3f8SMichael Tuexen tp1->data = NULL; 3999f8829a4aSRandall Stewart } 4000b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4001f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4002f8829a4aSRandall Stewart cumack, 4003f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4004f8829a4aSRandall Stewart 0, 4005f8829a4aSRandall Stewart 0, 4006f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 400780fefe0aSRandall Stewart } 4008f8829a4aSRandall Stewart asoc->sent_queue_cnt--; 4009689e6a5fSMichael Tuexen sctp_free_a_chunk(stcb, tp1, SCTP_SO_NOT_LOCKED); 401018e198d3SRandall Stewart } else { 401118e198d3SRandall Stewart break; 4012f8829a4aSRandall Stewart } 40135e54f665SRandall Stewart } 401418e198d3SRandall Stewart 401518e198d3SRandall Stewart } 401604ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4017f8829a4aSRandall Stewart if (stcb->sctp_socket) { 4018ceaad40aSRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4019ceaad40aSRandall Stewart struct socket *so; 4020ceaad40aSRandall Stewart 4021ceaad40aSRandall Stewart #endif 4022f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 4023b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 402404ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 40257215cc1bSMichael Tuexen sctp_wakeup_log(stcb, 1, SCTP_WAKESND_FROM_SACK); 402680fefe0aSRandall Stewart } 4027ceaad40aSRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4028ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 4029ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 4030ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 4031ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 4032ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 4033ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 4034ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 4035ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 4036ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4037ceaad40aSRandall Stewart return; 4038ceaad40aSRandall Stewart } 4039ceaad40aSRandall Stewart #endif 4040f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 4041ceaad40aSRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4042ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4043ceaad40aSRandall Stewart #endif 4044f8829a4aSRandall Stewart } else { 4045b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 40467215cc1bSMichael Tuexen sctp_wakeup_log(stcb, 1, SCTP_NOWAKE_FROM_SACK); 404780fefe0aSRandall Stewart } 4048f8829a4aSRandall Stewart } 4049f8829a4aSRandall Stewart 4050b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4051ca85e948SMichael Tuexen if ((asoc->last_acked_seq != cumack) && (ecne_seen == 0)) { 4052ca85e948SMichael Tuexen TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4053ca85e948SMichael Tuexen if (net->net_ack2 > 0) { 4054ca85e948SMichael Tuexen /* 4055ca85e948SMichael Tuexen * Karn's rule applies to clearing error 4056ca85e948SMichael Tuexen * count, this is optional. 4057ca85e948SMichael Tuexen */ 4058ca85e948SMichael Tuexen net->error_count = 0; 4059ca85e948SMichael Tuexen if (!(net->dest_state & SCTP_ADDR_REACHABLE)) { 4060ca85e948SMichael Tuexen /* addr came good */ 4061ca85e948SMichael Tuexen net->dest_state |= SCTP_ADDR_REACHABLE; 4062ca85e948SMichael Tuexen sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 40634b1f78e1SMichael Tuexen 0, (void *)net, SCTP_SO_NOT_LOCKED); 4064ca85e948SMichael Tuexen } 4065ca85e948SMichael Tuexen if (net == stcb->asoc.primary_destination) { 4066ca85e948SMichael Tuexen if (stcb->asoc.alternate) { 4067ca85e948SMichael Tuexen /* 4068ca85e948SMichael Tuexen * release the alternate, 4069ca85e948SMichael Tuexen * primary is good 4070ca85e948SMichael Tuexen */ 4071ca85e948SMichael Tuexen sctp_free_remote_addr(stcb->asoc.alternate); 4072ca85e948SMichael Tuexen stcb->asoc.alternate = NULL; 4073ca85e948SMichael Tuexen } 4074ca85e948SMichael Tuexen } 4075ca85e948SMichael Tuexen if (net->dest_state & SCTP_ADDR_PF) { 4076ca85e948SMichael Tuexen net->dest_state &= ~SCTP_ADDR_PF; 4077b7d130beSMichael Tuexen sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, 4078b7d130beSMichael Tuexen stcb->sctp_ep, stcb, net, 407944249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_22); 4080ca85e948SMichael Tuexen sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); 4081ca85e948SMichael Tuexen asoc->cc_functions.sctp_cwnd_update_exit_pf(stcb, net); 4082ca85e948SMichael Tuexen /* Done with this net */ 4083ca85e948SMichael Tuexen net->net_ack = 0; 4084ca85e948SMichael Tuexen } 4085ca85e948SMichael Tuexen /* restore any doubled timers */ 4086ca85e948SMichael Tuexen net->RTO = (net->lastsa >> SCTP_RTT_SHIFT) + net->lastsv; 4087ca85e948SMichael Tuexen if (net->RTO < stcb->asoc.minrto) { 4088ca85e948SMichael Tuexen net->RTO = stcb->asoc.minrto; 4089ca85e948SMichael Tuexen } 4090ca85e948SMichael Tuexen if (net->RTO > stcb->asoc.maxrto) { 4091ca85e948SMichael Tuexen net->RTO = stcb->asoc.maxrto; 4092ca85e948SMichael Tuexen } 4093ca85e948SMichael Tuexen } 4094ca85e948SMichael Tuexen } 4095b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, 1, 0, 0); 4096ca85e948SMichael Tuexen } 4097f8829a4aSRandall Stewart asoc->last_acked_seq = cumack; 40985e54f665SRandall Stewart 4099f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 4100f8829a4aSRandall Stewart /* nothing left in-flight */ 4101f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4102f8829a4aSRandall Stewart net->flight_size = 0; 4103f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4104f8829a4aSRandall Stewart } 4105f8829a4aSRandall Stewart asoc->total_flight = 0; 4106f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4107f8829a4aSRandall Stewart } 4108f8829a4aSRandall Stewart /* RWND update */ 4109f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(rwnd, 411044fbe462SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 4111f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4112f8829a4aSRandall Stewart /* SWS sender side engages */ 4113f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4114f8829a4aSRandall Stewart } 41155e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 41165e54f665SRandall Stewart win_probe_recovery = 1; 41175e54f665SRandall Stewart } 4118f8829a4aSRandall Stewart /* Now assure a timer where data is queued at */ 4119a5d547adSRandall Stewart again: 4120a5d547adSRandall Stewart j = 0; 4121f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 41225171328bSRandall Stewart int to_ticks; 41235171328bSRandall Stewart 41245e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 4125c105859eSRandall Stewart win_probe_recovered = 1; 41265e54f665SRandall Stewart /* 41275e54f665SRandall Stewart * Find first chunk that was used with window probe 41285e54f665SRandall Stewart * and clear the sent 41295e54f665SRandall Stewart */ 41303c503c28SRandall Stewart /* sa_ignore FREED_MEMORY */ 41315e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 41325e54f665SRandall Stewart if (tp1->window_probe) { 4133cd554309SMichael Tuexen /* move back to data send queue */ 41347215cc1bSMichael Tuexen sctp_window_probe_recovery(stcb, asoc, tp1); 41355e54f665SRandall Stewart break; 41365e54f665SRandall Stewart } 41375e54f665SRandall Stewart } 41385e54f665SRandall Stewart } 4139f8829a4aSRandall Stewart if (net->RTO == 0) { 4140f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto); 4141f8829a4aSRandall Stewart } else { 4142f8829a4aSRandall Stewart to_ticks = MSEC_TO_TICKS(net->RTO); 4143f8829a4aSRandall Stewart } 41445171328bSRandall Stewart if (net->flight_size) { 4145a5d547adSRandall Stewart j++; 4146ad81507eSRandall Stewart (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 4147f8829a4aSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 41485171328bSRandall Stewart if (net->window_probe) { 41495171328bSRandall Stewart net->window_probe = 0; 41505171328bSRandall Stewart } 4151f8829a4aSRandall Stewart } else { 41525171328bSRandall Stewart if (net->window_probe) { 41535171328bSRandall Stewart /* 41545171328bSRandall Stewart * In window probes we must assure a timer 41555171328bSRandall Stewart * is still running there 41565171328bSRandall Stewart */ 41575171328bSRandall Stewart net->window_probe = 0; 41585171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 41595171328bSRandall Stewart SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, 41605171328bSRandall Stewart sctp_timeout_handler, &net->rxt_timer); 41615171328bSRandall Stewart } 41625171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 4163f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4164a5d547adSRandall Stewart stcb, net, 416544249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_23); 4166f8829a4aSRandall Stewart } 4167f8829a4aSRandall Stewart } 4168f8829a4aSRandall Stewart } 4169bff64a4dSRandall Stewart if ((j == 0) && 4170bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 4171bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 4172c105859eSRandall Stewart (win_probe_recovered == 0) && 4173bff64a4dSRandall Stewart (done_once == 0)) { 41740c0982b8SRandall Stewart /* 41750c0982b8SRandall Stewart * huh, this should not happen unless all packets are 41760c0982b8SRandall Stewart * PR-SCTP and marked to skip of course. 41770c0982b8SRandall Stewart */ 41780c0982b8SRandall Stewart if (sctp_fs_audit(asoc)) { 4179a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4180a5d547adSRandall Stewart net->flight_size = 0; 4181a5d547adSRandall Stewart } 4182a5d547adSRandall Stewart asoc->total_flight = 0; 4183a5d547adSRandall Stewart asoc->total_flight_count = 0; 4184a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4185a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4186a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4187c105859eSRandall Stewart sctp_flight_size_increase(tp1); 4188c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 4189a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4190791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 4191a5d547adSRandall Stewart } 4192a5d547adSRandall Stewart } 41930c0982b8SRandall Stewart } 4194bff64a4dSRandall Stewart done_once = 1; 4195a5d547adSRandall Stewart goto again; 4196a5d547adSRandall Stewart } 4197f8829a4aSRandall Stewart /**********************************/ 4198f8829a4aSRandall Stewart /* Now what about shutdown issues */ 4199f8829a4aSRandall Stewart /**********************************/ 4200f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 4201f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 4202f8829a4aSRandall Stewart /* clean up */ 4203f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 4204f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 4205f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 4206d1ea5fa9SMichael Tuexen ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc))) { 4207f8829a4aSRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 42082afb3e84SRandall Stewart } 4209f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 4210f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4211f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4212f8829a4aSRandall Stewart /* Need to abort here */ 4213ff1ffd74SMichael Tuexen struct mbuf *op_err; 4214f8829a4aSRandall Stewart 4215f8829a4aSRandall Stewart abort_out_now: 4216f8829a4aSRandall Stewart *abort_now = 1; 4217f8829a4aSRandall Stewart /* XXX */ 4218ff1ffd74SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, ""); 421944249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24; 4220ff1ffd74SMichael Tuexen sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 4221fe4a59b3SMichael Tuexen return; 4222f8829a4aSRandall Stewart } else { 4223ca85e948SMichael Tuexen struct sctp_nets *netp; 4224ca85e948SMichael Tuexen 4225f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 4226f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 4227f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4228f42a358aSRandall Stewart } 4229c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 4230b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4231f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 4232ca85e948SMichael Tuexen if (asoc->alternate) { 4233ca85e948SMichael Tuexen netp = asoc->alternate; 4234ca85e948SMichael Tuexen } else { 4235ca85e948SMichael Tuexen netp = asoc->primary_destination; 4236ca85e948SMichael Tuexen } 4237ca85e948SMichael Tuexen sctp_send_shutdown(stcb, netp); 4238f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 4239ca85e948SMichael Tuexen stcb->sctp_ep, stcb, netp); 4240f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 4241ca85e948SMichael Tuexen stcb->sctp_ep, stcb, netp); 4242f8829a4aSRandall Stewart } 4243f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 4244f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4245ca85e948SMichael Tuexen struct sctp_nets *netp; 4246ca85e948SMichael Tuexen 4247f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4248f8829a4aSRandall Stewart goto abort_out_now; 4249f8829a4aSRandall Stewart } 4250f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4251c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 4252b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 425312af6654SMichael Tuexen sctp_stop_timers_for_shutdown(stcb); 4254c39cfa1fSMichael Tuexen if (asoc->alternate) { 4255c39cfa1fSMichael Tuexen netp = asoc->alternate; 4256c39cfa1fSMichael Tuexen } else { 4257c39cfa1fSMichael Tuexen netp = asoc->primary_destination; 4258c39cfa1fSMichael Tuexen } 4259c39cfa1fSMichael Tuexen sctp_send_shutdown_ack(stcb, netp); 4260f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 4261ca85e948SMichael Tuexen stcb->sctp_ep, stcb, netp); 4262f8829a4aSRandall Stewart } 4263f8829a4aSRandall Stewart } 4264dfb11ef8SRandall Stewart /*********************************************/ 4265dfb11ef8SRandall Stewart /* Here we perform PR-SCTP procedures */ 4266dfb11ef8SRandall Stewart /* (section 4.2) */ 4267dfb11ef8SRandall Stewart /*********************************************/ 4268dfb11ef8SRandall Stewart /* C1. update advancedPeerAckPoint */ 426920b07a4dSMichael Tuexen if (SCTP_TSN_GT(cumack, asoc->advanced_peer_ack_point)) { 4270dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cumack; 4271dfb11ef8SRandall Stewart } 4272830d754dSRandall Stewart /* PR-Sctp issues need to be addressed too */ 4273dd973b0eSMichael Tuexen if ((asoc->prsctp_supported) && (asoc->pr_sctp_cnt > 0)) { 4274830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 4275830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 4276830d754dSRandall Stewart 4277830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 4278830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 4279830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 428020b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, cumack)) { 4281830d754dSRandall Stewart /* 4282493d8e5aSRandall Stewart * ISSUE with ECN, see FWD-TSN processing. 4283830d754dSRandall Stewart */ 428420b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, old_adv_peer_ack_point)) { 4285830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 42860c0982b8SRandall Stewart } else if (lchk) { 42870c0982b8SRandall Stewart /* try to FR fwd-tsn's that get lost too */ 428844fbe462SRandall Stewart if (lchk->rec.data.fwd_tsn_cnt >= 3) { 42890c0982b8SRandall Stewart send_forward_tsn(stcb, asoc); 42900c0982b8SRandall Stewart } 4291830d754dSRandall Stewart } 4292830d754dSRandall Stewart } 4293830d754dSRandall Stewart if (lchk) { 4294830d754dSRandall Stewart /* Assure a timer is up */ 4295830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 4296830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 4297830d754dSRandall Stewart } 4298830d754dSRandall Stewart } 4299b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 4300f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 4301f8829a4aSRandall Stewart rwnd, 4302f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 4303f8829a4aSRandall Stewart stcb->asoc.total_flight, 4304f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 430580fefe0aSRandall Stewart } 4306f8829a4aSRandall Stewart } 4307f8829a4aSRandall Stewart 4308f8829a4aSRandall Stewart void 4309cd554309SMichael Tuexen sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup, 43107215cc1bSMichael Tuexen struct sctp_tcb *stcb, 4311cd554309SMichael Tuexen uint16_t num_seg, uint16_t num_nr_seg, uint16_t num_dup, 4312cd554309SMichael Tuexen int *abort_now, uint8_t flags, 4313899288aeSRandall Stewart uint32_t cum_ack, uint32_t rwnd, int ecne_seen) 4314f8829a4aSRandall Stewart { 4315f8829a4aSRandall Stewart struct sctp_association *asoc; 4316f8829a4aSRandall Stewart struct sctp_tmit_chunk *tp1, *tp2; 4317cd554309SMichael Tuexen uint32_t last_tsn, biggest_tsn_acked, biggest_tsn_newly_acked, this_sack_lowest_newack; 4318f8829a4aSRandall Stewart uint16_t wake_him = 0; 4319c105859eSRandall Stewart uint32_t send_s = 0; 4320f8829a4aSRandall Stewart long j; 4321f8829a4aSRandall Stewart int accum_moved = 0; 4322f8829a4aSRandall Stewart int will_exit_fast_recovery = 0; 43235e54f665SRandall Stewart uint32_t a_rwnd, old_rwnd; 43245e54f665SRandall Stewart int win_probe_recovery = 0; 4325c105859eSRandall Stewart int win_probe_recovered = 0; 4326f8829a4aSRandall Stewart struct sctp_nets *net = NULL; 4327bff64a4dSRandall Stewart int done_once; 4328f79aab18SRandall Stewart int rto_ok = 1; 4329f8829a4aSRandall Stewart uint8_t reneged_all = 0; 4330f8829a4aSRandall Stewart uint8_t cmt_dac_flag; 4331f8829a4aSRandall Stewart 4332f8829a4aSRandall Stewart /* 4333f8829a4aSRandall Stewart * we take any chance we can to service our queues since we cannot 4334f8829a4aSRandall Stewart * get awoken when the socket is read from :< 4335f8829a4aSRandall Stewart */ 4336f8829a4aSRandall Stewart /* 4337f8829a4aSRandall Stewart * Now perform the actual SACK handling: 1) Verify that it is not an 4338f8829a4aSRandall Stewart * old sack, if so discard. 2) If there is nothing left in the send 4339f8829a4aSRandall Stewart * queue (cum-ack is equal to last acked) then you have a duplicate 4340f8829a4aSRandall Stewart * too, update any rwnd change and verify no timers are running. 4341f8829a4aSRandall Stewart * then return. 3) Process any new consequtive data i.e. cum-ack 4342f8829a4aSRandall Stewart * moved process these first and note that it moved. 4) Process any 4343f8829a4aSRandall Stewart * sack blocks. 5) Drop any acked from the queue. 6) Check for any 4344f8829a4aSRandall Stewart * revoked blocks and mark. 7) Update the cwnd. 8) Nothing left, 4345f8829a4aSRandall Stewart * sync up flightsizes and things, stop all timers and also check 4346f8829a4aSRandall Stewart * for shutdown_pending state. If so then go ahead and send off the 4347f8829a4aSRandall Stewart * shutdown. If in shutdown recv, send off the shutdown-ack and 4348f8829a4aSRandall Stewart * start that timer, Ret. 9) Strike any non-acked things and do FR 4349f8829a4aSRandall Stewart * procedure if needed being sure to set the FR flag. 10) Do pr-sctp 4350f8829a4aSRandall Stewart * procedures. 11) Apply any FR penalties. 12) Assure we will SACK 4351f8829a4aSRandall Stewart * if in shutdown_recv state. 4352f8829a4aSRandall Stewart */ 4353f8829a4aSRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 4354f8829a4aSRandall Stewart /* CMT DAC algo */ 4355f8829a4aSRandall Stewart this_sack_lowest_newack = 0; 4356f8829a4aSRandall Stewart SCTP_STAT_INCR(sctps_slowpath_sack); 4357cd554309SMichael Tuexen last_tsn = cum_ack; 4358cd554309SMichael Tuexen cmt_dac_flag = flags & SCTP_SACK_CMT_DAC; 435918e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS 436018e198d3SRandall Stewart stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cum_ack; 436118e198d3SRandall Stewart stcb->asoc.cumack_log_at++; 436218e198d3SRandall Stewart if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { 436318e198d3SRandall Stewart stcb->asoc.cumack_log_at = 0; 436418e198d3SRandall Stewart } 436518e198d3SRandall Stewart #endif 4366d06c82f1SRandall Stewart a_rwnd = rwnd; 4367f8829a4aSRandall Stewart 4368cd554309SMichael Tuexen if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { 4369cd554309SMichael Tuexen sctp_misc_ints(SCTP_SACK_LOG_NORMAL, cum_ack, 4370cd554309SMichael Tuexen rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); 4371cd554309SMichael Tuexen } 43725e54f665SRandall Stewart old_rwnd = stcb->asoc.peers_rwnd; 4373b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 4374c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 4375c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 4376c4739e2fSRandall Stewart 0, 4377c4739e2fSRandall Stewart SCTP_FROM_SCTP_INDATA, 4378c4739e2fSRandall Stewart __LINE__); 4379c4739e2fSRandall Stewart } 4380f8829a4aSRandall Stewart stcb->asoc.overall_error_count = 0; 4381f8829a4aSRandall Stewart asoc = &stcb->asoc; 4382b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4383f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4384f8829a4aSRandall Stewart cum_ack, 4385f8829a4aSRandall Stewart 0, 4386f8829a4aSRandall Stewart num_seg, 4387f8829a4aSRandall Stewart num_dup, 4388f8829a4aSRandall Stewart SCTP_LOG_NEW_SACK); 438980fefe0aSRandall Stewart } 4390ca85e948SMichael Tuexen if ((num_dup) && (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE)) { 4391cd554309SMichael Tuexen uint16_t i; 4392458303daSRandall Stewart uint32_t *dupdata, dblock; 4393f8829a4aSRandall Stewart 4394cd554309SMichael Tuexen for (i = 0; i < num_dup; i++) { 4395cd554309SMichael Tuexen dupdata = (uint32_t *) sctp_m_getptr(m, offset_dup + i * sizeof(uint32_t), 4396458303daSRandall Stewart sizeof(uint32_t), (uint8_t *) & dblock); 4397cd554309SMichael Tuexen if (dupdata == NULL) { 4398458303daSRandall Stewart break; 4399458303daSRandall Stewart } 4400cd554309SMichael Tuexen sctp_log_fr(*dupdata, 0, 0, SCTP_FR_DUPED); 4401f8829a4aSRandall Stewart } 4402f8829a4aSRandall Stewart } 4403c105859eSRandall Stewart /* reality check */ 4404c105859eSRandall Stewart if (!TAILQ_EMPTY(&asoc->sent_queue)) { 4405c105859eSRandall Stewart tp1 = TAILQ_LAST(&asoc->sent_queue, 4406c105859eSRandall Stewart sctpchunk_listhead); 4407c105859eSRandall Stewart send_s = tp1->rec.data.TSN_seq + 1; 4408c105859eSRandall Stewart } else { 4409b5c16493SMichael Tuexen tp1 = NULL; 4410c105859eSRandall Stewart send_s = asoc->sending_seq; 4411c105859eSRandall Stewart } 441220b07a4dSMichael Tuexen if (SCTP_TSN_GE(cum_ack, send_s)) { 4413ff1ffd74SMichael Tuexen struct mbuf *op_err; 4414ff1ffd74SMichael Tuexen char msg[SCTP_DIAG_INFO_LEN]; 4415c105859eSRandall Stewart 4416f8829a4aSRandall Stewart /* 4417fd60718dSMichael Tuexen * no way, we have not even sent this TSN out yet. Peer is 4418fd60718dSMichael Tuexen * hopelessly messed up with us. 4419f8829a4aSRandall Stewart */ 4420cd3fd531SMichael Tuexen SCTP_PRINTF("NEW cum_ack:%x send_s:%x is smaller or equal\n", 4421b5c16493SMichael Tuexen cum_ack, send_s); 4422b5c16493SMichael Tuexen if (tp1) { 4423cd3fd531SMichael Tuexen SCTP_PRINTF("Got send_s from tsn:%x + 1 of tp1: %p\n", 4424dd294dceSMichael Tuexen tp1->rec.data.TSN_seq, (void *)tp1); 4425b5c16493SMichael Tuexen } 4426f8829a4aSRandall Stewart hopeless_peer: 4427f8829a4aSRandall Stewart *abort_now = 1; 4428f8829a4aSRandall Stewart /* XXX */ 442955f8a4bbSMichael Tuexen snprintf(msg, sizeof(msg), "Cum ack %8.8x greater or equal than TSN %8.8x", 4430ff1ffd74SMichael Tuexen cum_ack, send_s); 4431ff1ffd74SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 443244249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; 4433ff1ffd74SMichael Tuexen sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 4434f8829a4aSRandall Stewart return; 4435f8829a4aSRandall Stewart } 4436f8829a4aSRandall Stewart /**********************/ 4437f8829a4aSRandall Stewart /* 1) check the range */ 4438f8829a4aSRandall Stewart /**********************/ 443920b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->last_acked_seq, last_tsn)) { 4440f8829a4aSRandall Stewart /* acking something behind */ 4441f8829a4aSRandall Stewart return; 4442f8829a4aSRandall Stewart } 4443f8829a4aSRandall Stewart /* update the Rwnd of the peer */ 4444f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue) && 4445f8829a4aSRandall Stewart TAILQ_EMPTY(&asoc->send_queue) && 4446cd554309SMichael Tuexen (asoc->stream_queue_cnt == 0)) { 4447f8829a4aSRandall Stewart /* nothing left on send/sent and strmq */ 4448b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4449f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 4450f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 445180fefe0aSRandall Stewart } 4452f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 4453f8829a4aSRandall Stewart if (asoc->sent_queue_retran_cnt) { 4454f8829a4aSRandall Stewart asoc->sent_queue_retran_cnt = 0; 4455f8829a4aSRandall Stewart } 4456f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4457f8829a4aSRandall Stewart /* SWS sender side engages */ 4458f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4459f8829a4aSRandall Stewart } 4460f8829a4aSRandall Stewart /* stop any timers */ 4461f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4462f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 446344249214SRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); 4464f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4465f8829a4aSRandall Stewart net->flight_size = 0; 4466f8829a4aSRandall Stewart } 4467f8829a4aSRandall Stewart asoc->total_flight = 0; 4468f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4469f8829a4aSRandall Stewart return; 4470f8829a4aSRandall Stewart } 4471f8829a4aSRandall Stewart /* 4472f8829a4aSRandall Stewart * We init netAckSz and netAckSz2 to 0. These are used to track 2 4473f8829a4aSRandall Stewart * things. The total byte count acked is tracked in netAckSz AND 4474f8829a4aSRandall Stewart * netAck2 is used to track the total bytes acked that are un- 4475f8829a4aSRandall Stewart * amibguious and were never retransmitted. We track these on a per 4476f8829a4aSRandall Stewart * destination address basis. 4477f8829a4aSRandall Stewart */ 4478f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4479a21779f0SRandall Stewart if (SCTP_TSN_GT(cum_ack, net->cwr_window_tsn)) { 4480a21779f0SRandall Stewart /* Drag along the window_tsn for cwr's */ 4481a21779f0SRandall Stewart net->cwr_window_tsn = cum_ack; 4482a21779f0SRandall Stewart } 4483f8829a4aSRandall Stewart net->prev_cwnd = net->cwnd; 4484f8829a4aSRandall Stewart net->net_ack = 0; 4485f8829a4aSRandall Stewart net->net_ack2 = 0; 4486f8829a4aSRandall Stewart 4487f8829a4aSRandall Stewart /* 448842551e99SRandall Stewart * CMT: Reset CUC and Fast recovery algo variables before 448942551e99SRandall Stewart * SACK processing 4490f8829a4aSRandall Stewart */ 4491f8829a4aSRandall Stewart net->new_pseudo_cumack = 0; 4492f8829a4aSRandall Stewart net->will_exit_fast_recovery = 0; 4493299108c5SRandall Stewart if (stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack) { 4494299108c5SRandall Stewart (*stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack) (stcb, net); 4495299108c5SRandall Stewart } 4496f8829a4aSRandall Stewart } 4497f8829a4aSRandall Stewart /* process the new consecutive TSN first */ 44984a9ef3f8SMichael Tuexen TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 449920b07a4dSMichael Tuexen if (SCTP_TSN_GE(last_tsn, tp1->rec.data.TSN_seq)) { 4500f8829a4aSRandall Stewart if (tp1->sent != SCTP_DATAGRAM_UNSENT) { 4501f8829a4aSRandall Stewart accum_moved = 1; 4502f8829a4aSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_ACKED) { 4503f8829a4aSRandall Stewart /* 4504f8829a4aSRandall Stewart * If it is less than ACKED, it is 4505f8829a4aSRandall Stewart * now no-longer in flight. Higher 4506f8829a4aSRandall Stewart * values may occur during marking 4507f8829a4aSRandall Stewart */ 4508f8829a4aSRandall Stewart if ((tp1->whoTo->dest_state & 4509f8829a4aSRandall Stewart SCTP_ADDR_UNCONFIRMED) && 4510f8829a4aSRandall Stewart (tp1->snd_count < 2)) { 4511f8829a4aSRandall Stewart /* 4512f8829a4aSRandall Stewart * If there was no retran 4513f8829a4aSRandall Stewart * and the address is 4514f8829a4aSRandall Stewart * un-confirmed and we sent 4515f8829a4aSRandall Stewart * there and are now 4516f8829a4aSRandall Stewart * sacked.. its confirmed, 4517f8829a4aSRandall Stewart * mark it so. 4518f8829a4aSRandall Stewart */ 4519f8829a4aSRandall Stewart tp1->whoTo->dest_state &= 4520f8829a4aSRandall Stewart ~SCTP_ADDR_UNCONFIRMED; 4521f8829a4aSRandall Stewart } 4522c105859eSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 4523b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4524c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, 4525a5d547adSRandall Stewart tp1->whoTo->flight_size, 4526a5d547adSRandall Stewart tp1->book_size, 45279a8e3088SMichael Tuexen (uint32_t) (uintptr_t) tp1->whoTo, 4528a5d547adSRandall Stewart tp1->rec.data.TSN_seq); 452980fefe0aSRandall Stewart } 4530c105859eSRandall Stewart sctp_flight_size_decrease(tp1); 4531c105859eSRandall Stewart sctp_total_flight_decrease(stcb, tp1); 4532299108c5SRandall Stewart if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { 4533299108c5SRandall Stewart (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) (tp1->whoTo, 4534299108c5SRandall Stewart tp1); 4535299108c5SRandall Stewart } 4536f8829a4aSRandall Stewart } 4537f8829a4aSRandall Stewart tp1->whoTo->net_ack += tp1->send_size; 4538f8829a4aSRandall Stewart 4539f8829a4aSRandall Stewart /* CMT SFR and DAC algos */ 4540f8829a4aSRandall Stewart this_sack_lowest_newack = tp1->rec.data.TSN_seq; 4541f8829a4aSRandall Stewart tp1->whoTo->saw_newack = 1; 4542f8829a4aSRandall Stewart 4543f8829a4aSRandall Stewart if (tp1->snd_count < 2) { 4544f8829a4aSRandall Stewart /* 4545f8829a4aSRandall Stewart * True non-retransmited 4546f8829a4aSRandall Stewart * chunk 4547f8829a4aSRandall Stewart */ 4548f8829a4aSRandall Stewart tp1->whoTo->net_ack2 += 4549f8829a4aSRandall Stewart tp1->send_size; 4550f8829a4aSRandall Stewart 4551f8829a4aSRandall Stewart /* update RTO too? */ 4552f8829a4aSRandall Stewart if (tp1->do_rtt) { 4553f79aab18SRandall Stewart if (rto_ok) { 4554f8829a4aSRandall Stewart tp1->whoTo->RTO = 4555f8829a4aSRandall Stewart sctp_calculate_rto(stcb, 4556f8829a4aSRandall Stewart asoc, tp1->whoTo, 455718e198d3SRandall Stewart &tp1->sent_rcv_time, 4558899288aeSRandall Stewart sctp_align_safe_nocopy, 4559f79aab18SRandall Stewart SCTP_RTT_FROM_DATA); 4560f79aab18SRandall Stewart rto_ok = 0; 4561f79aab18SRandall Stewart } 4562f79aab18SRandall Stewart if (tp1->whoTo->rto_needed == 0) { 4563f79aab18SRandall Stewart tp1->whoTo->rto_needed = 1; 4564f79aab18SRandall Stewart } 4565f8829a4aSRandall Stewart tp1->do_rtt = 0; 4566f8829a4aSRandall Stewart } 4567f8829a4aSRandall Stewart } 4568f8829a4aSRandall Stewart /* 4569f8829a4aSRandall Stewart * CMT: CUCv2 algorithm. From the 4570f8829a4aSRandall Stewart * cumack'd TSNs, for each TSN being 4571f8829a4aSRandall Stewart * acked for the first time, set the 4572f8829a4aSRandall Stewart * following variables for the 4573f8829a4aSRandall Stewart * corresp destination. 4574f8829a4aSRandall Stewart * new_pseudo_cumack will trigger a 4575f8829a4aSRandall Stewart * cwnd update. 4576f8829a4aSRandall Stewart * find_(rtx_)pseudo_cumack will 4577f8829a4aSRandall Stewart * trigger search for the next 4578f8829a4aSRandall Stewart * expected (rtx-)pseudo-cumack. 4579f8829a4aSRandall Stewart */ 4580f8829a4aSRandall Stewart tp1->whoTo->new_pseudo_cumack = 1; 4581f8829a4aSRandall Stewart tp1->whoTo->find_pseudo_cumack = 1; 4582f8829a4aSRandall Stewart tp1->whoTo->find_rtx_pseudo_cumack = 1; 4583f8829a4aSRandall Stewart 4584f8829a4aSRandall Stewart 4585b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4586f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4587f8829a4aSRandall Stewart cum_ack, 4588f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4589f8829a4aSRandall Stewart 0, 4590f8829a4aSRandall Stewart 0, 4591f8829a4aSRandall Stewart SCTP_LOG_TSN_ACKED); 459280fefe0aSRandall Stewart } 4593b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 4594f8829a4aSRandall Stewart sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK); 459580fefe0aSRandall Stewart } 4596f8829a4aSRandall Stewart } 4597f8829a4aSRandall Stewart if (tp1->sent == SCTP_DATAGRAM_RESEND) { 4598f8829a4aSRandall Stewart sctp_ucount_decr(asoc->sent_queue_retran_cnt); 4599f8829a4aSRandall Stewart #ifdef SCTP_AUDITING_ENABLED 4600f8829a4aSRandall Stewart sctp_audit_log(0xB3, 4601f8829a4aSRandall Stewart (asoc->sent_queue_retran_cnt & 0x000000ff)); 4602f8829a4aSRandall Stewart #endif 4603f8829a4aSRandall Stewart } 460442551e99SRandall Stewart if (tp1->rec.data.chunk_was_revoked) { 460542551e99SRandall Stewart /* deflate the cwnd */ 460642551e99SRandall Stewart tp1->whoTo->cwnd -= tp1->book_size; 460742551e99SRandall Stewart tp1->rec.data.chunk_was_revoked = 0; 460842551e99SRandall Stewart } 4609325c8c46SMichael Tuexen if (tp1->sent != SCTP_DATAGRAM_NR_ACKED) { 4610f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_ACKED; 4611f8829a4aSRandall Stewart } 4612325c8c46SMichael Tuexen } 4613f8829a4aSRandall Stewart } else { 4614f8829a4aSRandall Stewart break; 4615f8829a4aSRandall Stewart } 4616f8829a4aSRandall Stewart } 4617f8829a4aSRandall Stewart biggest_tsn_newly_acked = biggest_tsn_acked = last_tsn; 4618f8829a4aSRandall Stewart /* always set this up to cum-ack */ 4619f8829a4aSRandall Stewart asoc->this_sack_highest_gap = last_tsn; 4620f8829a4aSRandall Stewart 4621cd554309SMichael Tuexen if ((num_seg > 0) || (num_nr_seg > 0)) { 4622f8829a4aSRandall Stewart 4623f8829a4aSRandall Stewart /* 4624f8829a4aSRandall Stewart * CMT: SFR algo (and HTNA) - this_sack_highest_newack has 4625f8829a4aSRandall Stewart * to be greater than the cumack. Also reset saw_newack to 0 4626f8829a4aSRandall Stewart * for all dests. 4627f8829a4aSRandall Stewart */ 4628f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4629f8829a4aSRandall Stewart net->saw_newack = 0; 4630f8829a4aSRandall Stewart net->this_sack_highest_newack = last_tsn; 4631f8829a4aSRandall Stewart } 4632f8829a4aSRandall Stewart 4633f8829a4aSRandall Stewart /* 4634f8829a4aSRandall Stewart * thisSackHighestGap will increase while handling NEW 4635f8829a4aSRandall Stewart * segments this_sack_highest_newack will increase while 4636f8829a4aSRandall Stewart * handling NEWLY ACKED chunks. this_sack_lowest_newack is 4637f8829a4aSRandall Stewart * used for CMT DAC algo. saw_newack will also change. 4638f8829a4aSRandall Stewart */ 4639cd554309SMichael Tuexen if (sctp_handle_segments(m, &offset_seg, stcb, asoc, last_tsn, &biggest_tsn_acked, 4640cd554309SMichael Tuexen &biggest_tsn_newly_acked, &this_sack_lowest_newack, 46417215cc1bSMichael Tuexen num_seg, num_nr_seg, &rto_ok)) { 4642cd554309SMichael Tuexen wake_him++; 4643cd554309SMichael Tuexen } 4644f8829a4aSRandall Stewart /* 4645fd60718dSMichael Tuexen * validate the biggest_tsn_acked in the gap acks if strict 4646fd60718dSMichael Tuexen * adherence is wanted. 4647f8829a4aSRandall Stewart */ 464820b07a4dSMichael Tuexen if (SCTP_TSN_GE(biggest_tsn_acked, send_s)) { 4649f8829a4aSRandall Stewart /* 4650fd60718dSMichael Tuexen * peer is either confused or we are under attack. 4651fd60718dSMichael Tuexen * We must abort. 4652f8829a4aSRandall Stewart */ 4653cd3fd531SMichael Tuexen SCTP_PRINTF("Hopeless peer! biggest_tsn_acked:%x largest seq:%x\n", 4654cd3fd531SMichael Tuexen biggest_tsn_acked, send_s); 4655f8829a4aSRandall Stewart goto hopeless_peer; 4656f8829a4aSRandall Stewart } 4657f8829a4aSRandall Stewart } 4658f8829a4aSRandall Stewart /*******************************************/ 4659f8829a4aSRandall Stewart /* cancel ALL T3-send timer if accum moved */ 4660f8829a4aSRandall Stewart /*******************************************/ 46617c99d56fSMichael Tuexen if (asoc->sctp_cmt_on_off > 0) { 4662f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4663f8829a4aSRandall Stewart if (net->new_pseudo_cumack) 4664f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4665a5d547adSRandall Stewart stcb, net, 466644249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_27); 4667f8829a4aSRandall Stewart 4668f8829a4aSRandall Stewart } 4669f8829a4aSRandall Stewart } else { 4670f8829a4aSRandall Stewart if (accum_moved) { 4671f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4672f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 467344249214SRandall Stewart stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_28); 4674f8829a4aSRandall Stewart } 4675f8829a4aSRandall Stewart } 4676f8829a4aSRandall Stewart } 4677f8829a4aSRandall Stewart /********************************************/ 4678d9c5cfeaSMichael Tuexen /* drop the acked chunks from the sentqueue */ 4679f8829a4aSRandall Stewart /********************************************/ 4680f8829a4aSRandall Stewart asoc->last_acked_seq = cum_ack; 4681f8829a4aSRandall Stewart 46827c99d56fSMichael Tuexen TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) { 468320b07a4dSMichael Tuexen if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, cum_ack)) { 4684f8829a4aSRandall Stewart break; 4685f8829a4aSRandall Stewart } 4686325c8c46SMichael Tuexen if (tp1->sent != SCTP_DATAGRAM_NR_ACKED) { 4687a7ad6026SMichael Tuexen if (asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues > 0) { 4688a7ad6026SMichael Tuexen asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues--; 4689a7ad6026SMichael Tuexen #ifdef INVARIANTS 4690a7ad6026SMichael Tuexen } else { 4691a7ad6026SMichael Tuexen panic("No chunks on the queues for sid %u.", tp1->rec.data.stream_number); 4692a7ad6026SMichael Tuexen #endif 4693a7ad6026SMichael Tuexen } 4694f8829a4aSRandall Stewart } 4695d96bef9cSMichael Tuexen if ((asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues == 0) && 4696d96bef9cSMichael Tuexen (asoc->strmout[tp1->rec.data.stream_number].state == SCTP_STREAM_RESET_PENDING) && 4697d96bef9cSMichael Tuexen TAILQ_EMPTY(&asoc->strmout[tp1->rec.data.stream_number].outqueue)) { 4698d96bef9cSMichael Tuexen asoc->trigger_reset = 1; 4699d96bef9cSMichael Tuexen } 4700f8829a4aSRandall Stewart TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); 47010ddb4299SMichael Tuexen if (PR_SCTP_ENABLED(tp1->flags)) { 4702f8829a4aSRandall Stewart if (asoc->pr_sctp_cnt != 0) 4703f8829a4aSRandall Stewart asoc->pr_sctp_cnt--; 4704f8829a4aSRandall Stewart } 47057c99d56fSMichael Tuexen asoc->sent_queue_cnt--; 4706f8829a4aSRandall Stewart if (tp1->data) { 470704ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4708f8829a4aSRandall Stewart sctp_free_bufspace(stcb, asoc, tp1, 1); 4709f8829a4aSRandall Stewart sctp_m_freem(tp1->data); 47107c99d56fSMichael Tuexen tp1->data = NULL; 4711dd973b0eSMichael Tuexen if (asoc->prsctp_supported && PR_SCTP_BUF_ENABLED(tp1->flags)) { 4712f8829a4aSRandall Stewart asoc->sent_queue_cnt_removeable--; 4713f8829a4aSRandall Stewart } 4714f8829a4aSRandall Stewart } 4715b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { 4716f8829a4aSRandall Stewart sctp_log_sack(asoc->last_acked_seq, 4717f8829a4aSRandall Stewart cum_ack, 4718f8829a4aSRandall Stewart tp1->rec.data.TSN_seq, 4719f8829a4aSRandall Stewart 0, 4720f8829a4aSRandall Stewart 0, 4721f8829a4aSRandall Stewart SCTP_LOG_FREE_SENT); 472280fefe0aSRandall Stewart } 4723689e6a5fSMichael Tuexen sctp_free_a_chunk(stcb, tp1, SCTP_SO_NOT_LOCKED); 4724f8829a4aSRandall Stewart wake_him++; 47257c99d56fSMichael Tuexen } 47267c99d56fSMichael Tuexen if (TAILQ_EMPTY(&asoc->sent_queue) && (asoc->total_flight > 0)) { 47277c99d56fSMichael Tuexen #ifdef INVARIANTS 4728cd0a4ff6SPedro F. Giffuni panic("Warning flight size is positive and should be 0"); 47297c99d56fSMichael Tuexen #else 47307c99d56fSMichael Tuexen SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n", 47317c99d56fSMichael Tuexen asoc->total_flight); 47327c99d56fSMichael Tuexen #endif 47337c99d56fSMichael Tuexen asoc->total_flight = 0; 47347c99d56fSMichael Tuexen } 473504ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 4736f8829a4aSRandall Stewart if ((wake_him) && (stcb->sctp_socket)) { 4737ceaad40aSRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4738ceaad40aSRandall Stewart struct socket *so; 4739ceaad40aSRandall Stewart 4740ceaad40aSRandall Stewart #endif 4741f8829a4aSRandall Stewart SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); 4742b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 47437215cc1bSMichael Tuexen sctp_wakeup_log(stcb, wake_him, SCTP_WAKESND_FROM_SACK); 474480fefe0aSRandall Stewart } 4745ceaad40aSRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4746ceaad40aSRandall Stewart so = SCTP_INP_SO(stcb->sctp_ep); 4747ceaad40aSRandall Stewart atomic_add_int(&stcb->asoc.refcnt, 1); 4748ceaad40aSRandall Stewart SCTP_TCB_UNLOCK(stcb); 4749ceaad40aSRandall Stewart SCTP_SOCKET_LOCK(so, 1); 4750ceaad40aSRandall Stewart SCTP_TCB_LOCK(stcb); 4751ceaad40aSRandall Stewart atomic_subtract_int(&stcb->asoc.refcnt, 1); 4752ceaad40aSRandall Stewart if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { 4753ceaad40aSRandall Stewart /* assoc was freed while we were unlocked */ 4754ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4755ceaad40aSRandall Stewart return; 4756ceaad40aSRandall Stewart } 4757ceaad40aSRandall Stewart #endif 4758f8829a4aSRandall Stewart sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); 4759ceaad40aSRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) 4760ceaad40aSRandall Stewart SCTP_SOCKET_UNLOCK(so, 1); 4761ceaad40aSRandall Stewart #endif 4762f8829a4aSRandall Stewart } else { 4763b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { 47647215cc1bSMichael Tuexen sctp_wakeup_log(stcb, wake_him, SCTP_NOWAKE_FROM_SACK); 476580fefe0aSRandall Stewart } 4766f8829a4aSRandall Stewart } 4767f8829a4aSRandall Stewart 476842551e99SRandall Stewart if (asoc->fast_retran_loss_recovery && accum_moved) { 476920b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->last_acked_seq, asoc->fast_recovery_tsn)) { 4770f8829a4aSRandall Stewart /* Setup so we will exit RFC2582 fast recovery */ 4771f8829a4aSRandall Stewart will_exit_fast_recovery = 1; 4772f8829a4aSRandall Stewart } 4773f8829a4aSRandall Stewart } 4774f8829a4aSRandall Stewart /* 4775f8829a4aSRandall Stewart * Check for revoked fragments: 4776f8829a4aSRandall Stewart * 4777f8829a4aSRandall Stewart * if Previous sack - Had no frags then we can't have any revoked if 4778f8829a4aSRandall Stewart * Previous sack - Had frag's then - If we now have frags aka 4779f8829a4aSRandall Stewart * num_seg > 0 call sctp_check_for_revoked() to tell if peer revoked 4780f8829a4aSRandall Stewart * some of them. else - The peer revoked all ACKED fragments, since 4781f8829a4aSRandall Stewart * we had some before and now we have NONE. 4782f8829a4aSRandall Stewart */ 4783f8829a4aSRandall Stewart 4784d9c5cfeaSMichael Tuexen if (num_seg) { 4785c105859eSRandall Stewart sctp_check_for_revoked(stcb, asoc, cum_ack, biggest_tsn_acked); 4786d9c5cfeaSMichael Tuexen asoc->saw_sack_with_frags = 1; 4787d9c5cfeaSMichael Tuexen } else if (asoc->saw_sack_with_frags) { 4788f8829a4aSRandall Stewart int cnt_revoked = 0; 4789f8829a4aSRandall Stewart 4790f8829a4aSRandall Stewart /* Peer revoked all dg's marked or acked */ 4791f8829a4aSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 4792b5c16493SMichael Tuexen if (tp1->sent == SCTP_DATAGRAM_ACKED) { 4793f8829a4aSRandall Stewart tp1->sent = SCTP_DATAGRAM_SENT; 4794b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { 4795c105859eSRandall Stewart sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, 4796c105859eSRandall Stewart tp1->whoTo->flight_size, 4797c105859eSRandall Stewart tp1->book_size, 47989a8e3088SMichael Tuexen (uint32_t) (uintptr_t) tp1->whoTo, 4799c105859eSRandall Stewart tp1->rec.data.TSN_seq); 480080fefe0aSRandall Stewart } 4801c105859eSRandall Stewart sctp_flight_size_increase(tp1); 4802c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 4803a5d547adSRandall Stewart tp1->rec.data.chunk_was_revoked = 1; 480442551e99SRandall Stewart /* 480542551e99SRandall Stewart * To ensure that this increase in 48064a9ef3f8SMichael Tuexen * flightsize, which is artificial, does not 48074a9ef3f8SMichael Tuexen * throttle the sender, we also increase the 48084a9ef3f8SMichael Tuexen * cwnd artificially. 480942551e99SRandall Stewart */ 481042551e99SRandall Stewart tp1->whoTo->cwnd += tp1->book_size; 4811f8829a4aSRandall Stewart cnt_revoked++; 4812f8829a4aSRandall Stewart } 4813f8829a4aSRandall Stewart } 4814f8829a4aSRandall Stewart if (cnt_revoked) { 4815f8829a4aSRandall Stewart reneged_all = 1; 4816f8829a4aSRandall Stewart } 4817f8829a4aSRandall Stewart asoc->saw_sack_with_frags = 0; 4818f8829a4aSRandall Stewart } 4819d9c5cfeaSMichael Tuexen if (num_nr_seg > 0) 4820d9c5cfeaSMichael Tuexen asoc->saw_sack_with_nr_frags = 1; 4821f8829a4aSRandall Stewart else 4822d9c5cfeaSMichael Tuexen asoc->saw_sack_with_nr_frags = 0; 4823f8829a4aSRandall Stewart 4824b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4825ca85e948SMichael Tuexen if (ecne_seen == 0) { 4826ca85e948SMichael Tuexen TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4827ca85e948SMichael Tuexen if (net->net_ack2 > 0) { 4828ca85e948SMichael Tuexen /* 4829ca85e948SMichael Tuexen * Karn's rule applies to clearing error 4830ca85e948SMichael Tuexen * count, this is optional. 4831ca85e948SMichael Tuexen */ 4832ca85e948SMichael Tuexen net->error_count = 0; 4833ca85e948SMichael Tuexen if (!(net->dest_state & SCTP_ADDR_REACHABLE)) { 4834ca85e948SMichael Tuexen /* addr came good */ 4835ca85e948SMichael Tuexen net->dest_state |= SCTP_ADDR_REACHABLE; 4836ca85e948SMichael Tuexen sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 48374b1f78e1SMichael Tuexen 0, (void *)net, SCTP_SO_NOT_LOCKED); 4838ca85e948SMichael Tuexen } 4839ca85e948SMichael Tuexen if (net == stcb->asoc.primary_destination) { 4840ca85e948SMichael Tuexen if (stcb->asoc.alternate) { 4841ca85e948SMichael Tuexen /* 4842ca85e948SMichael Tuexen * release the alternate, 4843ca85e948SMichael Tuexen * primary is good 4844ca85e948SMichael Tuexen */ 4845ca85e948SMichael Tuexen sctp_free_remote_addr(stcb->asoc.alternate); 4846ca85e948SMichael Tuexen stcb->asoc.alternate = NULL; 4847ca85e948SMichael Tuexen } 4848ca85e948SMichael Tuexen } 4849ca85e948SMichael Tuexen if (net->dest_state & SCTP_ADDR_PF) { 4850ca85e948SMichael Tuexen net->dest_state &= ~SCTP_ADDR_PF; 4851b7d130beSMichael Tuexen sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, 4852b7d130beSMichael Tuexen stcb->sctp_ep, stcb, net, 485344249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_29); 4854ca85e948SMichael Tuexen sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); 4855ca85e948SMichael Tuexen asoc->cc_functions.sctp_cwnd_update_exit_pf(stcb, net); 4856ca85e948SMichael Tuexen /* Done with this net */ 4857ca85e948SMichael Tuexen net->net_ack = 0; 4858ca85e948SMichael Tuexen } 4859ca85e948SMichael Tuexen /* restore any doubled timers */ 4860ca85e948SMichael Tuexen net->RTO = (net->lastsa >> SCTP_RTT_SHIFT) + net->lastsv; 4861ca85e948SMichael Tuexen if (net->RTO < stcb->asoc.minrto) { 4862ca85e948SMichael Tuexen net->RTO = stcb->asoc.minrto; 4863ca85e948SMichael Tuexen } 4864ca85e948SMichael Tuexen if (net->RTO > stcb->asoc.maxrto) { 4865ca85e948SMichael Tuexen net->RTO = stcb->asoc.maxrto; 4866ca85e948SMichael Tuexen } 4867ca85e948SMichael Tuexen } 4868ca85e948SMichael Tuexen } 4869b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, accum_moved, reneged_all, will_exit_fast_recovery); 4870ca85e948SMichael Tuexen } 4871f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->sent_queue)) { 4872f8829a4aSRandall Stewart /* nothing left in-flight */ 4873f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4874f8829a4aSRandall Stewart /* stop all timers */ 4875f8829a4aSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 4876b7d130beSMichael Tuexen stcb, net, 487744249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_30); 4878f8829a4aSRandall Stewart net->flight_size = 0; 4879f8829a4aSRandall Stewart net->partial_bytes_acked = 0; 4880f8829a4aSRandall Stewart } 4881f8829a4aSRandall Stewart asoc->total_flight = 0; 4882f8829a4aSRandall Stewart asoc->total_flight_count = 0; 4883f8829a4aSRandall Stewart } 4884f8829a4aSRandall Stewart /**********************************/ 4885f8829a4aSRandall Stewart /* Now what about shutdown issues */ 4886f8829a4aSRandall Stewart /**********************************/ 4887f8829a4aSRandall Stewart if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { 4888f8829a4aSRandall Stewart /* nothing left on sendqueue.. consider done */ 4889b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 4890f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 4891f8829a4aSRandall Stewart asoc->peers_rwnd, 0, 0, a_rwnd); 489280fefe0aSRandall Stewart } 4893f8829a4aSRandall Stewart asoc->peers_rwnd = a_rwnd; 4894f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 4895f8829a4aSRandall Stewart /* SWS sender side engages */ 4896f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 4897f8829a4aSRandall Stewart } 4898f8829a4aSRandall Stewart /* clean up */ 4899f8829a4aSRandall Stewart if ((asoc->stream_queue_cnt == 1) && 4900f8829a4aSRandall Stewart ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || 4901f8829a4aSRandall Stewart (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) && 4902d1ea5fa9SMichael Tuexen ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc))) { 49032afb3e84SRandall Stewart asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; 4904f8829a4aSRandall Stewart } 4905f8829a4aSRandall Stewart if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && 4906f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4907f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4908f8829a4aSRandall Stewart /* Need to abort here */ 4909ff1ffd74SMichael Tuexen struct mbuf *op_err; 4910f8829a4aSRandall Stewart 4911f8829a4aSRandall Stewart abort_out_now: 4912f8829a4aSRandall Stewart *abort_now = 1; 4913f8829a4aSRandall Stewart /* XXX */ 4914ff1ffd74SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, ""); 491544249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_31; 4916ff1ffd74SMichael Tuexen sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 4917f8829a4aSRandall Stewart return; 4918f8829a4aSRandall Stewart } else { 4919ca85e948SMichael Tuexen struct sctp_nets *netp; 4920ca85e948SMichael Tuexen 4921f42a358aSRandall Stewart if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || 4922f42a358aSRandall Stewart (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 4923f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4924f42a358aSRandall Stewart } 4925c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); 4926b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 4927f8829a4aSRandall Stewart sctp_stop_timers_for_shutdown(stcb); 4928c39cfa1fSMichael Tuexen if (asoc->alternate) { 4929c39cfa1fSMichael Tuexen netp = asoc->alternate; 4930c39cfa1fSMichael Tuexen } else { 4931c39cfa1fSMichael Tuexen netp = asoc->primary_destination; 4932c39cfa1fSMichael Tuexen } 4933ca85e948SMichael Tuexen sctp_send_shutdown(stcb, netp); 4934f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 4935ca85e948SMichael Tuexen stcb->sctp_ep, stcb, netp); 4936f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 4937ca85e948SMichael Tuexen stcb->sctp_ep, stcb, netp); 4938f8829a4aSRandall Stewart } 4939f8829a4aSRandall Stewart return; 4940f8829a4aSRandall Stewart } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) && 4941f8829a4aSRandall Stewart (asoc->stream_queue_cnt == 0)) { 4942ca85e948SMichael Tuexen struct sctp_nets *netp; 4943ca85e948SMichael Tuexen 4944f8829a4aSRandall Stewart if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) { 4945f8829a4aSRandall Stewart goto abort_out_now; 4946f8829a4aSRandall Stewart } 4947f8829a4aSRandall Stewart SCTP_STAT_DECR_GAUGE32(sctps_currestab); 4948c4739e2fSRandall Stewart SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT); 4949b201f536SRandall Stewart SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); 495012af6654SMichael Tuexen sctp_stop_timers_for_shutdown(stcb); 4951c39cfa1fSMichael Tuexen if (asoc->alternate) { 4952c39cfa1fSMichael Tuexen netp = asoc->alternate; 4953c39cfa1fSMichael Tuexen } else { 4954c39cfa1fSMichael Tuexen netp = asoc->primary_destination; 4955c39cfa1fSMichael Tuexen } 4956c39cfa1fSMichael Tuexen sctp_send_shutdown_ack(stcb, netp); 4957f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, 4958ca85e948SMichael Tuexen stcb->sctp_ep, stcb, netp); 4959f8829a4aSRandall Stewart return; 4960f8829a4aSRandall Stewart } 4961f8829a4aSRandall Stewart } 4962f8829a4aSRandall Stewart /* 4963f8829a4aSRandall Stewart * Now here we are going to recycle net_ack for a different use... 4964f8829a4aSRandall Stewart * HEADS UP. 4965f8829a4aSRandall Stewart */ 4966f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 4967f8829a4aSRandall Stewart net->net_ack = 0; 4968f8829a4aSRandall Stewart } 4969f8829a4aSRandall Stewart 4970f8829a4aSRandall Stewart /* 4971f8829a4aSRandall Stewart * CMT DAC algorithm: If SACK DAC flag was 0, then no extra marking 4972f8829a4aSRandall Stewart * to be done. Setting this_sack_lowest_newack to the cum_ack will 4973f8829a4aSRandall Stewart * automatically ensure that. 4974f8829a4aSRandall Stewart */ 49757c99d56fSMichael Tuexen if ((asoc->sctp_cmt_on_off > 0) && 497620083c2eSMichael Tuexen SCTP_BASE_SYSCTL(sctp_cmt_use_dac) && 497720083c2eSMichael Tuexen (cmt_dac_flag == 0)) { 4978f8829a4aSRandall Stewart this_sack_lowest_newack = cum_ack; 4979f8829a4aSRandall Stewart } 4980cd554309SMichael Tuexen if ((num_seg > 0) || (num_nr_seg > 0)) { 4981f8829a4aSRandall Stewart sctp_strike_gap_ack_chunks(stcb, asoc, biggest_tsn_acked, 4982f8829a4aSRandall Stewart biggest_tsn_newly_acked, this_sack_lowest_newack, accum_moved); 4983f8829a4aSRandall Stewart } 4984b54d3a6cSRandall Stewart /* JRS - Use the congestion control given in the CC module */ 4985b54d3a6cSRandall Stewart asoc->cc_functions.sctp_cwnd_update_after_fr(stcb, asoc); 4986f8829a4aSRandall Stewart 4987f8829a4aSRandall Stewart /* Now are we exiting loss recovery ? */ 4988f8829a4aSRandall Stewart if (will_exit_fast_recovery) { 4989f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 4990f8829a4aSRandall Stewart asoc->fast_retran_loss_recovery = 0; 4991f8829a4aSRandall Stewart } 4992f8829a4aSRandall Stewart if ((asoc->sat_t3_loss_recovery) && 499320b07a4dSMichael Tuexen SCTP_TSN_GE(asoc->last_acked_seq, asoc->sat_t3_recovery_tsn)) { 4994f8829a4aSRandall Stewart /* end satellite t3 loss recovery */ 4995f8829a4aSRandall Stewart asoc->sat_t3_loss_recovery = 0; 4996f8829a4aSRandall Stewart } 499742551e99SRandall Stewart /* 499842551e99SRandall Stewart * CMT Fast recovery 499942551e99SRandall Stewart */ 5000f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5001f8829a4aSRandall Stewart if (net->will_exit_fast_recovery) { 5002f8829a4aSRandall Stewart /* Ok, we must exit fast recovery */ 5003f8829a4aSRandall Stewart net->fast_retran_loss_recovery = 0; 5004f8829a4aSRandall Stewart } 5005f8829a4aSRandall Stewart } 5006f8829a4aSRandall Stewart 5007f8829a4aSRandall Stewart /* Adjust and set the new rwnd value */ 5008b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { 5009f8829a4aSRandall Stewart sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, 501044fbe462SRandall Stewart asoc->peers_rwnd, asoc->total_flight, (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)), a_rwnd); 501180fefe0aSRandall Stewart } 5012f8829a4aSRandall Stewart asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd, 501344fbe462SRandall Stewart (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); 5014f8829a4aSRandall Stewart if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { 5015f8829a4aSRandall Stewart /* SWS sender side engages */ 5016f8829a4aSRandall Stewart asoc->peers_rwnd = 0; 5017f8829a4aSRandall Stewart } 50185e54f665SRandall Stewart if (asoc->peers_rwnd > old_rwnd) { 50195e54f665SRandall Stewart win_probe_recovery = 1; 50205e54f665SRandall Stewart } 5021f8829a4aSRandall Stewart /* 5022f8829a4aSRandall Stewart * Now we must setup so we have a timer up for anyone with 5023f8829a4aSRandall Stewart * outstanding data. 5024f8829a4aSRandall Stewart */ 5025bff64a4dSRandall Stewart done_once = 0; 5026a5d547adSRandall Stewart again: 5027a5d547adSRandall Stewart j = 0; 5028f8829a4aSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 50295e54f665SRandall Stewart if (win_probe_recovery && (net->window_probe)) { 5030c105859eSRandall Stewart win_probe_recovered = 1; 50315e54f665SRandall Stewart /*- 50325e54f665SRandall Stewart * Find first chunk that was used with 50335e54f665SRandall Stewart * window probe and clear the event. Put 50345e54f665SRandall Stewart * it back into the send queue as if has 50355e54f665SRandall Stewart * not been sent. 50365e54f665SRandall Stewart */ 50375e54f665SRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 50385e54f665SRandall Stewart if (tp1->window_probe) { 50397215cc1bSMichael Tuexen sctp_window_probe_recovery(stcb, asoc, tp1); 50405e54f665SRandall Stewart break; 50415e54f665SRandall Stewart } 50425e54f665SRandall Stewart } 50435e54f665SRandall Stewart } 5044f8829a4aSRandall Stewart if (net->flight_size) { 5045a5d547adSRandall Stewart j++; 5046cd554309SMichael Tuexen if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 5047f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5048f8829a4aSRandall Stewart stcb->sctp_ep, stcb, net); 5049cd554309SMichael Tuexen } 50505171328bSRandall Stewart if (net->window_probe) { 5051cd554309SMichael Tuexen net->window_probe = 0; 50525171328bSRandall Stewart } 5053c105859eSRandall Stewart } else { 50545171328bSRandall Stewart if (net->window_probe) { 50555171328bSRandall Stewart /* 50565171328bSRandall Stewart * In window probes we must assure a timer 50575171328bSRandall Stewart * is still running there 50585171328bSRandall Stewart */ 50595171328bSRandall Stewart if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 50605171328bSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 50615171328bSRandall Stewart stcb->sctp_ep, stcb, net); 50625171328bSRandall Stewart 50635171328bSRandall Stewart } 50645171328bSRandall Stewart } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { 5065c105859eSRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 5066c105859eSRandall Stewart stcb, net, 506744249214SRandall Stewart SCTP_FROM_SCTP_INDATA + SCTP_LOC_32); 5068c105859eSRandall Stewart } 5069f8829a4aSRandall Stewart } 5070f8829a4aSRandall Stewart } 5071bff64a4dSRandall Stewart if ((j == 0) && 5072bff64a4dSRandall Stewart (!TAILQ_EMPTY(&asoc->sent_queue)) && 5073bff64a4dSRandall Stewart (asoc->sent_queue_retran_cnt == 0) && 5074c105859eSRandall Stewart (win_probe_recovered == 0) && 5075bff64a4dSRandall Stewart (done_once == 0)) { 50760c0982b8SRandall Stewart /* 50770c0982b8SRandall Stewart * huh, this should not happen unless all packets are 50780c0982b8SRandall Stewart * PR-SCTP and marked to skip of course. 50790c0982b8SRandall Stewart */ 50800c0982b8SRandall Stewart if (sctp_fs_audit(asoc)) { 5081a5d547adSRandall Stewart TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 5082a5d547adSRandall Stewart net->flight_size = 0; 5083a5d547adSRandall Stewart } 5084a5d547adSRandall Stewart asoc->total_flight = 0; 5085a5d547adSRandall Stewart asoc->total_flight_count = 0; 5086a5d547adSRandall Stewart asoc->sent_queue_retran_cnt = 0; 5087a5d547adSRandall Stewart TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { 5088a5d547adSRandall Stewart if (tp1->sent < SCTP_DATAGRAM_RESEND) { 5089c105859eSRandall Stewart sctp_flight_size_increase(tp1); 5090c105859eSRandall Stewart sctp_total_flight_increase(stcb, tp1); 5091a5d547adSRandall Stewart } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { 5092791437b5SRandall Stewart sctp_ucount_incr(asoc->sent_queue_retran_cnt); 5093a5d547adSRandall Stewart } 5094a5d547adSRandall Stewart } 50950c0982b8SRandall Stewart } 5096bff64a4dSRandall Stewart done_once = 1; 5097a5d547adSRandall Stewart goto again; 5098a5d547adSRandall Stewart } 5099cd554309SMichael Tuexen /*********************************************/ 5100cd554309SMichael Tuexen /* Here we perform PR-SCTP procedures */ 5101cd554309SMichael Tuexen /* (section 4.2) */ 5102cd554309SMichael Tuexen /*********************************************/ 5103cd554309SMichael Tuexen /* C1. update advancedPeerAckPoint */ 510420b07a4dSMichael Tuexen if (SCTP_TSN_GT(cum_ack, asoc->advanced_peer_ack_point)) { 5105dfb11ef8SRandall Stewart asoc->advanced_peer_ack_point = cum_ack; 5106dfb11ef8SRandall Stewart } 5107830d754dSRandall Stewart /* C2. try to further move advancedPeerAckPoint ahead */ 5108dd973b0eSMichael Tuexen if ((asoc->prsctp_supported) && (asoc->pr_sctp_cnt > 0)) { 5109830d754dSRandall Stewart struct sctp_tmit_chunk *lchk; 5110830d754dSRandall Stewart uint32_t old_adv_peer_ack_point; 5111830d754dSRandall Stewart 5112830d754dSRandall Stewart old_adv_peer_ack_point = asoc->advanced_peer_ack_point; 5113830d754dSRandall Stewart lchk = sctp_try_advance_peer_ack_point(stcb, asoc); 5114830d754dSRandall Stewart /* C3. See if we need to send a Fwd-TSN */ 511520b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, cum_ack)) { 5116830d754dSRandall Stewart /* 5117493d8e5aSRandall Stewart * ISSUE with ECN, see FWD-TSN processing. 5118830d754dSRandall Stewart */ 51190c0982b8SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { 51200c0982b8SRandall Stewart sctp_misc_ints(SCTP_FWD_TSN_CHECK, 51210c0982b8SRandall Stewart 0xee, cum_ack, asoc->advanced_peer_ack_point, 51220c0982b8SRandall Stewart old_adv_peer_ack_point); 51230c0982b8SRandall Stewart } 512420b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, old_adv_peer_ack_point)) { 5125830d754dSRandall Stewart send_forward_tsn(stcb, asoc); 51260c0982b8SRandall Stewart } else if (lchk) { 51270c0982b8SRandall Stewart /* try to FR fwd-tsn's that get lost too */ 512844fbe462SRandall Stewart if (lchk->rec.data.fwd_tsn_cnt >= 3) { 51290c0982b8SRandall Stewart send_forward_tsn(stcb, asoc); 51300c0982b8SRandall Stewart } 5131830d754dSRandall Stewart } 5132830d754dSRandall Stewart } 5133830d754dSRandall Stewart if (lchk) { 5134830d754dSRandall Stewart /* Assure a timer is up */ 5135830d754dSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, 5136830d754dSRandall Stewart stcb->sctp_ep, stcb, lchk->whoTo); 5137830d754dSRandall Stewart } 5138830d754dSRandall Stewart } 5139b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { 5140f8829a4aSRandall Stewart sctp_misc_ints(SCTP_SACK_RWND_UPDATE, 5141f8829a4aSRandall Stewart a_rwnd, 5142f8829a4aSRandall Stewart stcb->asoc.peers_rwnd, 5143f8829a4aSRandall Stewart stcb->asoc.total_flight, 5144f8829a4aSRandall Stewart stcb->asoc.total_output_queue_size); 514580fefe0aSRandall Stewart } 5146f8829a4aSRandall Stewart } 5147f8829a4aSRandall Stewart 5148f8829a4aSRandall Stewart void 51497215cc1bSMichael Tuexen sctp_update_acked(struct sctp_tcb *stcb, struct sctp_shutdown_chunk *cp, int *abort_flag) 5150f8829a4aSRandall Stewart { 5151f8829a4aSRandall Stewart /* Copy cum-ack */ 5152f8829a4aSRandall Stewart uint32_t cum_ack, a_rwnd; 5153f8829a4aSRandall Stewart 5154f8829a4aSRandall Stewart cum_ack = ntohl(cp->cumulative_tsn_ack); 5155f8829a4aSRandall Stewart /* Arrange so a_rwnd does NOT change */ 5156f8829a4aSRandall Stewart a_rwnd = stcb->asoc.peers_rwnd + stcb->asoc.total_flight; 5157f8829a4aSRandall Stewart 5158f8829a4aSRandall Stewart /* Now call the express sack handling */ 5159899288aeSRandall Stewart sctp_express_handle_sack(stcb, cum_ack, a_rwnd, abort_flag, 0); 5160f8829a4aSRandall Stewart } 5161f8829a4aSRandall Stewart 5162f8829a4aSRandall Stewart static void 5163f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb, 5164f8829a4aSRandall Stewart struct sctp_stream_in *strmin) 5165f8829a4aSRandall Stewart { 5166f8829a4aSRandall Stewart struct sctp_queued_to_read *ctl, *nctl; 5167f8829a4aSRandall Stewart struct sctp_association *asoc; 516844249214SRandall Stewart uint32_t tt; 516944249214SRandall Stewart int need_reasm_check = 0, old; 5170f8829a4aSRandall Stewart 5171f8829a4aSRandall Stewart asoc = &stcb->asoc; 5172f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered; 517344249214SRandall Stewart if (asoc->idata_supported) { 517444249214SRandall Stewart old = 0; 517544249214SRandall Stewart } else { 517644249214SRandall Stewart old = 1; 517744249214SRandall Stewart } 5178f8829a4aSRandall Stewart /* 5179f8829a4aSRandall Stewart * First deliver anything prior to and including the stream no that 518044249214SRandall Stewart * came in. 5181f8829a4aSRandall Stewart */ 518244249214SRandall Stewart TAILQ_FOREACH_SAFE(ctl, &strmin->inqueue, next_instrm, nctl) { 518344249214SRandall Stewart if (SCTP_MSGID_GE(old, tt, ctl->sinfo_ssn)) { 5184f8829a4aSRandall Stewart /* this is deliverable now */ 518544249214SRandall Stewart if (((ctl->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { 518644249214SRandall Stewart if (ctl->on_strm_q) { 518744249214SRandall Stewart if (ctl->on_strm_q == SCTP_ON_ORDERED) { 518844249214SRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next_instrm); 518944249214SRandall Stewart } else if (ctl->on_strm_q == SCTP_ON_UNORDERED) { 519044249214SRandall Stewart TAILQ_REMOVE(&strmin->uno_inqueue, ctl, next_instrm); 519198d5fd97SMichael Tuexen #ifdef INVARIANTS 519244249214SRandall Stewart } else { 519344249214SRandall Stewart panic("strmin: %p ctl: %p unknown %d", 519444249214SRandall Stewart strmin, ctl, ctl->on_strm_q); 519598d5fd97SMichael Tuexen #endif 519644249214SRandall Stewart } 519744249214SRandall Stewart ctl->on_strm_q = 0; 519844249214SRandall Stewart } 5199f8829a4aSRandall Stewart /* subtract pending on streams */ 5200f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5201f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5202f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5203f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5204b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 5205f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5206f8829a4aSRandall Stewart ctl, 520744249214SRandall Stewart &stcb->sctp_socket->so_rcv, 520844249214SRandall Stewart 1, SCTP_READ_LOCK_HELD, 520944249214SRandall Stewart SCTP_SO_NOT_LOCKED); 521044249214SRandall Stewart } 521144249214SRandall Stewart } else { 521244249214SRandall Stewart /* Its a fragmented message */ 521344249214SRandall Stewart if (ctl->first_frag_seen) { 521444249214SRandall Stewart /* 521544249214SRandall Stewart * Make it so this is next to 521644249214SRandall Stewart * deliver, we restore later 521744249214SRandall Stewart */ 521844249214SRandall Stewart strmin->last_sequence_delivered = ctl->sinfo_ssn - 1; 521944249214SRandall Stewart need_reasm_check = 1; 522044249214SRandall Stewart break; 522144249214SRandall Stewart } 5222f8829a4aSRandall Stewart } 5223f8829a4aSRandall Stewart } else { 5224f8829a4aSRandall Stewart /* no more delivery now. */ 5225f8829a4aSRandall Stewart break; 5226f8829a4aSRandall Stewart } 5227f8829a4aSRandall Stewart } 522844249214SRandall Stewart if (need_reasm_check) { 522944249214SRandall Stewart int ret; 523044249214SRandall Stewart 5231d1ea5fa9SMichael Tuexen ret = sctp_deliver_reasm_check(stcb, &stcb->asoc, strmin, SCTP_READ_LOCK_HELD); 523244249214SRandall Stewart if (SCTP_MSGID_GT(old, tt, strmin->last_sequence_delivered)) { 523344249214SRandall Stewart /* Restore the next to deliver unless we are ahead */ 523444249214SRandall Stewart strmin->last_sequence_delivered = tt; 523544249214SRandall Stewart } 523644249214SRandall Stewart if (ret == 0) { 523744249214SRandall Stewart /* Left the front Partial one on */ 523844249214SRandall Stewart return; 523944249214SRandall Stewart } 524044249214SRandall Stewart need_reasm_check = 0; 524144249214SRandall Stewart } 5242f8829a4aSRandall Stewart /* 5243f8829a4aSRandall Stewart * now we must deliver things in queue the normal way if any are 5244f8829a4aSRandall Stewart * now ready. 5245f8829a4aSRandall Stewart */ 5246f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 524744249214SRandall Stewart TAILQ_FOREACH_SAFE(ctl, &strmin->inqueue, next_instrm, nctl) { 5248f8829a4aSRandall Stewart if (tt == ctl->sinfo_ssn) { 524944249214SRandall Stewart if (((ctl->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { 5250f8829a4aSRandall Stewart /* this is deliverable now */ 525144249214SRandall Stewart if (ctl->on_strm_q) { 525244249214SRandall Stewart if (ctl->on_strm_q == SCTP_ON_ORDERED) { 525344249214SRandall Stewart TAILQ_REMOVE(&strmin->inqueue, ctl, next_instrm); 525444249214SRandall Stewart } else if (ctl->on_strm_q == SCTP_ON_UNORDERED) { 525544249214SRandall Stewart TAILQ_REMOVE(&strmin->uno_inqueue, ctl, next_instrm); 525698d5fd97SMichael Tuexen #ifdef INVARIANTS 525744249214SRandall Stewart } else { 525844249214SRandall Stewart panic("strmin: %p ctl: %p unknown %d", 525944249214SRandall Stewart strmin, ctl, ctl->on_strm_q); 526098d5fd97SMichael Tuexen #endif 526144249214SRandall Stewart } 526244249214SRandall Stewart ctl->on_strm_q = 0; 526344249214SRandall Stewart } 5264f8829a4aSRandall Stewart /* subtract pending on streams */ 5265f8829a4aSRandall Stewart asoc->size_on_all_streams -= ctl->length; 5266f8829a4aSRandall Stewart sctp_ucount_decr(asoc->cnt_on_all_streams); 5267f8829a4aSRandall Stewart /* deliver it to at least the delivery-q */ 5268f8829a4aSRandall Stewart strmin->last_sequence_delivered = ctl->sinfo_ssn; 5269f8829a4aSRandall Stewart if (stcb->sctp_socket) { 5270b5c16493SMichael Tuexen sctp_mark_non_revokable(asoc, ctl->sinfo_tsn); 5271f8829a4aSRandall Stewart sctp_add_to_readq(stcb->sctp_ep, stcb, 5272f8829a4aSRandall Stewart ctl, 527344249214SRandall Stewart &stcb->sctp_socket->so_rcv, 1, 527444249214SRandall Stewart SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED); 527577acdc25SRandall Stewart 5276f8829a4aSRandall Stewart } 5277f8829a4aSRandall Stewart tt = strmin->last_sequence_delivered + 1; 5278f8829a4aSRandall Stewart } else { 527944249214SRandall Stewart /* Its a fragmented message */ 528044249214SRandall Stewart if (ctl->first_frag_seen) { 528144249214SRandall Stewart /* 528244249214SRandall Stewart * Make it so this is next to 528344249214SRandall Stewart * deliver 528444249214SRandall Stewart */ 528544249214SRandall Stewart strmin->last_sequence_delivered = ctl->sinfo_ssn - 1; 528644249214SRandall Stewart need_reasm_check = 1; 5287f8829a4aSRandall Stewart break; 5288f8829a4aSRandall Stewart } 5289f8829a4aSRandall Stewart } 529044249214SRandall Stewart } else { 529144249214SRandall Stewart break; 529244249214SRandall Stewart } 529344249214SRandall Stewart } 529444249214SRandall Stewart if (need_reasm_check) { 5295d1ea5fa9SMichael Tuexen (void)sctp_deliver_reasm_check(stcb, &stcb->asoc, strmin, SCTP_READ_LOCK_HELD); 529644249214SRandall Stewart } 5297f8829a4aSRandall Stewart } 5298f8829a4aSRandall Stewart 52998e1b295fSMichael Tuexen 5300d1ea5fa9SMichael Tuexen 53018933fa13SRandall Stewart static void 53028933fa13SRandall Stewart sctp_flush_reassm_for_str_seq(struct sctp_tcb *stcb, 53038933fa13SRandall Stewart struct sctp_association *asoc, 5304d1ea5fa9SMichael Tuexen uint16_t stream, uint32_t seq, int ordered, int old, uint32_t cumtsn) 53058933fa13SRandall Stewart { 530644249214SRandall Stewart struct sctp_queued_to_read *control; 530744249214SRandall Stewart struct sctp_stream_in *strm; 53084a9ef3f8SMichael Tuexen struct sctp_tmit_chunk *chk, *nchk; 5309d1ea5fa9SMichael Tuexen int cnt_removed = 0; 53108933fa13SRandall Stewart 53118933fa13SRandall Stewart /* 531244249214SRandall Stewart * For now large messages held on the stream reasm that are complete 53134a9ef3f8SMichael Tuexen * will be tossed too. We could in theory do more work to spin 53144a9ef3f8SMichael Tuexen * through and stop after dumping one msg aka seeing the start of a 53154a9ef3f8SMichael Tuexen * new msg at the head, and call the delivery function... to see if 53164a9ef3f8SMichael Tuexen * it can be delivered... But for now we just dump everything on the 53174a9ef3f8SMichael Tuexen * queue. 53188933fa13SRandall Stewart */ 531944249214SRandall Stewart strm = &asoc->strmin[stream]; 5320d1ea5fa9SMichael Tuexen control = sctp_find_reasm_entry(strm, (uint32_t) seq, ordered, old); 532144249214SRandall Stewart if (control == NULL) { 532244249214SRandall Stewart /* Not found */ 532344249214SRandall Stewart return; 53248933fa13SRandall Stewart } 532544249214SRandall Stewart TAILQ_FOREACH_SAFE(chk, &control->reasm, sctp_next, nchk) { 532644249214SRandall Stewart /* Purge hanging chunks */ 5327d1ea5fa9SMichael Tuexen if (old && (ordered == 0)) { 5328d1ea5fa9SMichael Tuexen if (SCTP_TSN_GT(chk->rec.data.TSN_seq, cumtsn)) { 5329d1ea5fa9SMichael Tuexen break; 5330d1ea5fa9SMichael Tuexen } 5331d1ea5fa9SMichael Tuexen } 5332d1ea5fa9SMichael Tuexen cnt_removed++; 533344249214SRandall Stewart TAILQ_REMOVE(&control->reasm, chk, sctp_next); 53348933fa13SRandall Stewart asoc->size_on_reasm_queue -= chk->send_size; 53358933fa13SRandall Stewart sctp_ucount_decr(asoc->cnt_on_reasm_queue); 53368933fa13SRandall Stewart if (chk->data) { 53378933fa13SRandall Stewart sctp_m_freem(chk->data); 53388933fa13SRandall Stewart chk->data = NULL; 53398933fa13SRandall Stewart } 5340689e6a5fSMichael Tuexen sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); 53418933fa13SRandall Stewart } 5342d1ea5fa9SMichael Tuexen if (!TAILQ_EMPTY(&control->reasm)) { 5343d1ea5fa9SMichael Tuexen /* This has to be old data, unordered */ 5344d1ea5fa9SMichael Tuexen if (control->data) { 5345d1ea5fa9SMichael Tuexen sctp_m_freem(control->data); 5346d1ea5fa9SMichael Tuexen control->data = NULL; 5347d1ea5fa9SMichael Tuexen } 5348d1ea5fa9SMichael Tuexen sctp_reset_a_control(control, stcb->sctp_ep, cumtsn); 5349d1ea5fa9SMichael Tuexen chk = TAILQ_FIRST(&control->reasm); 5350d1ea5fa9SMichael Tuexen if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { 5351d1ea5fa9SMichael Tuexen TAILQ_REMOVE(&control->reasm, chk, sctp_next); 5352d1ea5fa9SMichael Tuexen sctp_add_chk_to_control(control, strm, stcb, asoc, 5353d1ea5fa9SMichael Tuexen chk, SCTP_READ_LOCK_HELD); 5354d1ea5fa9SMichael Tuexen } 5355d1ea5fa9SMichael Tuexen sctp_deliver_reasm_check(stcb, asoc, strm, SCTP_READ_LOCK_HELD); 5356d1ea5fa9SMichael Tuexen return; 5357d1ea5fa9SMichael Tuexen } 5358d1ea5fa9SMichael Tuexen if (control->on_strm_q == SCTP_ON_ORDERED) { 535944249214SRandall Stewart TAILQ_REMOVE(&strm->inqueue, control, next_instrm); 5360d1ea5fa9SMichael Tuexen control->on_strm_q = 0; 5361d1ea5fa9SMichael Tuexen } else if (control->on_strm_q == SCTP_ON_UNORDERED) { 5362d1ea5fa9SMichael Tuexen TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); 5363d1ea5fa9SMichael Tuexen control->on_strm_q = 0; 5364d1ea5fa9SMichael Tuexen #ifdef INVARIANTS 5365d1ea5fa9SMichael Tuexen } else if (control->on_strm_q) { 5366d1ea5fa9SMichael Tuexen panic("strm: %p ctl: %p unknown %d", 5367d1ea5fa9SMichael Tuexen strm, control, control->on_strm_q); 5368d1ea5fa9SMichael Tuexen #endif 5369d1ea5fa9SMichael Tuexen } 5370d1ea5fa9SMichael Tuexen control->on_strm_q = 0; 537144249214SRandall Stewart if (control->on_read_q == 0) { 537244249214SRandall Stewart sctp_free_remote_addr(control->whoFrom); 537344249214SRandall Stewart if (control->data) { 537444249214SRandall Stewart sctp_m_freem(control->data); 537544249214SRandall Stewart control->data = NULL; 537644249214SRandall Stewart } 537744249214SRandall Stewart sctp_free_a_readq(stcb, control); 53788933fa13SRandall Stewart } 53798933fa13SRandall Stewart } 53808933fa13SRandall Stewart 5381f8829a4aSRandall Stewart void 5382f8829a4aSRandall Stewart sctp_handle_forward_tsn(struct sctp_tcb *stcb, 5383b5c16493SMichael Tuexen struct sctp_forward_tsn_chunk *fwd, 5384b5c16493SMichael Tuexen int *abort_flag, struct mbuf *m, int offset) 5385f8829a4aSRandall Stewart { 5386f8829a4aSRandall Stewart /* The pr-sctp fwd tsn */ 5387f8829a4aSRandall Stewart /* 5388f8829a4aSRandall Stewart * here we will perform all the data receiver side steps for 5389f8829a4aSRandall Stewart * processing FwdTSN, as required in by pr-sctp draft: 5390f8829a4aSRandall Stewart * 5391f8829a4aSRandall Stewart * Assume we get FwdTSN(x): 5392f8829a4aSRandall Stewart * 5393f8829a4aSRandall Stewart * 1) update local cumTSN to x 2) try to further advance cumTSN to x + 5394f8829a4aSRandall Stewart * others we have 3) examine and update re-ordering queue on 5395f8829a4aSRandall Stewart * pr-in-streams 4) clean up re-assembly queue 5) Send a sack to 5396f8829a4aSRandall Stewart * report where we are. 5397f8829a4aSRandall Stewart */ 5398f8829a4aSRandall Stewart struct sctp_association *asoc; 53997898f408SRandall Stewart uint32_t new_cum_tsn, gap; 54007215cc1bSMichael Tuexen unsigned int i, fwd_sz, m_size; 54018933fa13SRandall Stewart uint32_t str_seq; 5402f8829a4aSRandall Stewart struct sctp_stream_in *strm; 54038933fa13SRandall Stewart struct sctp_queued_to_read *ctl, *sv; 5404f8829a4aSRandall Stewart 5405f8829a4aSRandall Stewart asoc = &stcb->asoc; 5406f8829a4aSRandall Stewart if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) { 5407ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_INDATA1, 5408ad81507eSRandall Stewart "Bad size too small/big fwd-tsn\n"); 5409f8829a4aSRandall Stewart return; 5410f8829a4aSRandall Stewart } 5411f8829a4aSRandall Stewart m_size = (stcb->asoc.mapping_array_size << 3); 5412f8829a4aSRandall Stewart /*************************************************************/ 5413f8829a4aSRandall Stewart /* 1. Here we update local cumTSN and shift the bitmap array */ 5414f8829a4aSRandall Stewart /*************************************************************/ 5415f8829a4aSRandall Stewart new_cum_tsn = ntohl(fwd->new_cumulative_tsn); 5416f8829a4aSRandall Stewart 541720b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->cumulative_tsn, new_cum_tsn)) { 5418f8829a4aSRandall Stewart /* Already got there ... */ 5419f8829a4aSRandall Stewart return; 5420f8829a4aSRandall Stewart } 5421f8829a4aSRandall Stewart /* 5422f8829a4aSRandall Stewart * now we know the new TSN is more advanced, let's find the actual 5423f8829a4aSRandall Stewart * gap 5424f8829a4aSRandall Stewart */ 5425b5c16493SMichael Tuexen SCTP_CALC_TSN_TO_GAP(gap, new_cum_tsn, asoc->mapping_array_base_tsn); 542677acdc25SRandall Stewart asoc->cumulative_tsn = new_cum_tsn; 54272afb3e84SRandall Stewart if (gap >= m_size) { 5428f8829a4aSRandall Stewart if ((long)gap > sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv)) { 5429ff1ffd74SMichael Tuexen struct mbuf *op_err; 5430ff1ffd74SMichael Tuexen char msg[SCTP_DIAG_INFO_LEN]; 543117205eccSRandall Stewart 5432f8829a4aSRandall Stewart /* 5433f8829a4aSRandall Stewart * out of range (of single byte chunks in the rwnd I 543417205eccSRandall Stewart * give out). This must be an attacker. 5435f8829a4aSRandall Stewart */ 543617205eccSRandall Stewart *abort_flag = 1; 5437ff1ffd74SMichael Tuexen snprintf(msg, sizeof(msg), 5438ff1ffd74SMichael Tuexen "New cum ack %8.8x too high, highest TSN %8.8x", 5439ff1ffd74SMichael Tuexen new_cum_tsn, asoc->highest_tsn_inside_map); 5440ff1ffd74SMichael Tuexen op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 544144249214SRandall Stewart stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_33; 5442ff1ffd74SMichael Tuexen sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 5443f8829a4aSRandall Stewart return; 5444f8829a4aSRandall Stewart } 5445207304d4SRandall Stewart SCTP_STAT_INCR(sctps_fwdtsn_map_over); 544677acdc25SRandall Stewart 54472afb3e84SRandall Stewart memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size); 54482afb3e84SRandall Stewart asoc->mapping_array_base_tsn = new_cum_tsn + 1; 544977acdc25SRandall Stewart asoc->highest_tsn_inside_map = new_cum_tsn; 545077acdc25SRandall Stewart 5451b5c16493SMichael Tuexen memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.mapping_array_size); 5452830d754dSRandall Stewart asoc->highest_tsn_inside_nr_map = new_cum_tsn; 545377acdc25SRandall Stewart 5454b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { 5455f8829a4aSRandall Stewart sctp_log_map(0, 3, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); 545680fefe0aSRandall Stewart } 54572afb3e84SRandall Stewart } else { 54582afb3e84SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 54592afb3e84SRandall Stewart for (i = 0; i <= gap; i++) { 54607898f408SRandall Stewart if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, i) && 54617898f408SRandall Stewart !SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, i)) { 54628933fa13SRandall Stewart SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, i); 546320b07a4dSMichael Tuexen if (SCTP_TSN_GT(asoc->mapping_array_base_tsn + i, asoc->highest_tsn_inside_nr_map)) { 54647898f408SRandall Stewart asoc->highest_tsn_inside_nr_map = asoc->mapping_array_base_tsn + i; 5465b5c16493SMichael Tuexen } 5466b5c16493SMichael Tuexen } 5467b5c16493SMichael Tuexen } 5468f8829a4aSRandall Stewart } 5469f8829a4aSRandall Stewart /*************************************************************/ 5470f8829a4aSRandall Stewart /* 2. Clear up re-assembly queue */ 5471f8829a4aSRandall Stewart /*************************************************************/ 5472f8829a4aSRandall Stewart 547344249214SRandall Stewart /* This is now done as part of clearing up the stream/seq */ 5474d1ea5fa9SMichael Tuexen if (asoc->idata_supported == 0) { 5475d1ea5fa9SMichael Tuexen uint16_t sid; 547644249214SRandall Stewart 5477d1ea5fa9SMichael Tuexen /* Flush all the un-ordered data based on cum-tsn */ 5478d1ea5fa9SMichael Tuexen SCTP_INP_READ_LOCK(stcb->sctp_ep); 5479d1ea5fa9SMichael Tuexen for (sid = 0; sid < asoc->streamincnt; sid++) { 5480d1ea5fa9SMichael Tuexen sctp_flush_reassm_for_str_seq(stcb, asoc, sid, 0, 0, 1, new_cum_tsn); 5481d1ea5fa9SMichael Tuexen } 5482d1ea5fa9SMichael Tuexen SCTP_INP_READ_UNLOCK(stcb->sctp_ep); 5483d1ea5fa9SMichael Tuexen } 54848933fa13SRandall Stewart /*******************************************************/ 54858933fa13SRandall Stewart /* 3. Update the PR-stream re-ordering queues and fix */ 54868933fa13SRandall Stewart /* delivery issues as needed. */ 54878933fa13SRandall Stewart /*******************************************************/ 5488f8829a4aSRandall Stewart fwd_sz -= sizeof(*fwd); 5489671d309cSRandall Stewart if (m && fwd_sz) { 5490f8829a4aSRandall Stewart /* New method. */ 5491d61a0ae0SRandall Stewart unsigned int num_str; 549244249214SRandall Stewart uint32_t sequence; 549344249214SRandall Stewart uint16_t stream; 54948e1b295fSMichael Tuexen uint16_t ordered, flags; 549544249214SRandall Stewart int old; 5496671d309cSRandall Stewart struct sctp_strseq *stseq, strseqbuf; 549744249214SRandall Stewart struct sctp_strseq_mid *stseq_m, strseqbuf_m; 5498671d309cSRandall Stewart 5499671d309cSRandall Stewart offset += sizeof(*fwd); 5500f8829a4aSRandall Stewart 55018933fa13SRandall Stewart SCTP_INP_READ_LOCK(stcb->sctp_ep); 550244249214SRandall Stewart if (asoc->idata_supported) { 550344249214SRandall Stewart num_str = fwd_sz / sizeof(struct sctp_strseq_mid); 550444249214SRandall Stewart old = 0; 550544249214SRandall Stewart } else { 5506f8829a4aSRandall Stewart num_str = fwd_sz / sizeof(struct sctp_strseq); 550744249214SRandall Stewart old = 1; 550844249214SRandall Stewart } 5509f8829a4aSRandall Stewart for (i = 0; i < num_str; i++) { 551044249214SRandall Stewart if (asoc->idata_supported) { 551144249214SRandall Stewart stseq_m = (struct sctp_strseq_mid *)sctp_m_getptr(m, offset, 551244249214SRandall Stewart sizeof(struct sctp_strseq_mid), 551344249214SRandall Stewart (uint8_t *) & strseqbuf_m); 551444249214SRandall Stewart offset += sizeof(struct sctp_strseq_mid); 551544249214SRandall Stewart if (stseq_m == NULL) { 551644249214SRandall Stewart break; 551744249214SRandall Stewart } 551844249214SRandall Stewart stream = ntohs(stseq_m->stream); 551944249214SRandall Stewart sequence = ntohl(stseq_m->msg_id); 55208e1b295fSMichael Tuexen flags = ntohs(stseq_m->flags); 55218e1b295fSMichael Tuexen if (flags & PR_SCTP_UNORDERED_FLAG) { 55228e1b295fSMichael Tuexen ordered = 0; 55238e1b295fSMichael Tuexen } else { 55248e1b295fSMichael Tuexen ordered = 1; 55258e1b295fSMichael Tuexen } 552644249214SRandall Stewart } else { 5527671d309cSRandall Stewart stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset, 5528671d309cSRandall Stewart sizeof(struct sctp_strseq), 5529671d309cSRandall Stewart (uint8_t *) & strseqbuf); 5530671d309cSRandall Stewart offset += sizeof(struct sctp_strseq); 55312afb3e84SRandall Stewart if (stseq == NULL) { 5532671d309cSRandall Stewart break; 55332afb3e84SRandall Stewart } 553444249214SRandall Stewart stream = ntohs(stseq->stream); 553544249214SRandall Stewart sequence = (uint32_t) ntohs(stseq->sequence); 55368e1b295fSMichael Tuexen ordered = 1; 553744249214SRandall Stewart } 5538f8829a4aSRandall Stewart /* Convert */ 55398933fa13SRandall Stewart 5540f8829a4aSRandall Stewart /* now process */ 55418933fa13SRandall Stewart 55428933fa13SRandall Stewart /* 55438933fa13SRandall Stewart * Ok we now look for the stream/seq on the read 55448933fa13SRandall Stewart * queue where its not all delivered. If we find it 55458933fa13SRandall Stewart * we transmute the read entry into a PDI_ABORTED. 55468933fa13SRandall Stewart */ 554744249214SRandall Stewart if (stream >= asoc->streamincnt) { 55482afb3e84SRandall Stewart /* screwed up streams, stop! */ 55492afb3e84SRandall Stewart break; 5550f8829a4aSRandall Stewart } 555144249214SRandall Stewart if ((asoc->str_of_pdapi == stream) && 555244249214SRandall Stewart (asoc->ssn_of_pdapi == sequence)) { 55538933fa13SRandall Stewart /* 55548933fa13SRandall Stewart * If this is the one we were partially 55558933fa13SRandall Stewart * delivering now then we no longer are. 55568933fa13SRandall Stewart * Note this will change with the reassembly 55578933fa13SRandall Stewart * re-write. 55588933fa13SRandall Stewart */ 55598933fa13SRandall Stewart asoc->fragmented_delivery_inprogress = 0; 55608933fa13SRandall Stewart } 556144249214SRandall Stewart strm = &asoc->strmin[stream]; 5562d1ea5fa9SMichael Tuexen if (asoc->idata_supported == 0) { 5563d1ea5fa9SMichael Tuexen uint16_t strm_at; 5564d1ea5fa9SMichael Tuexen 5565d1ea5fa9SMichael Tuexen for (strm_at = strm->last_sequence_delivered; SCTP_MSGID_GE(1, sequence, strm_at); strm_at++) { 5566d1ea5fa9SMichael Tuexen sctp_flush_reassm_for_str_seq(stcb, asoc, stream, strm_at, ordered, old, new_cum_tsn); 5567d1ea5fa9SMichael Tuexen } 5568d1ea5fa9SMichael Tuexen } else { 5569d1ea5fa9SMichael Tuexen uint32_t strm_at; 5570d1ea5fa9SMichael Tuexen 5571d1ea5fa9SMichael Tuexen for (strm_at = strm->last_sequence_delivered; SCTP_MSGID_GE(0, sequence, strm_at); strm_at++) { 5572d1ea5fa9SMichael Tuexen sctp_flush_reassm_for_str_seq(stcb, asoc, stream, strm_at, ordered, old, new_cum_tsn); 5573d1ea5fa9SMichael Tuexen } 5574d1ea5fa9SMichael Tuexen } 55758933fa13SRandall Stewart TAILQ_FOREACH(ctl, &stcb->sctp_ep->read_queue, next) { 557644249214SRandall Stewart if ((ctl->sinfo_stream == stream) && 557744249214SRandall Stewart (ctl->sinfo_ssn == sequence)) { 557844249214SRandall Stewart str_seq = (stream << 16) | (0x0000ffff & sequence); 55798933fa13SRandall Stewart ctl->pdapi_aborted = 1; 55808933fa13SRandall Stewart sv = stcb->asoc.control_pdapi; 558144249214SRandall Stewart ctl->end_added = 1; 558244249214SRandall Stewart if (ctl->on_strm_q == SCTP_ON_ORDERED) { 558344249214SRandall Stewart TAILQ_REMOVE(&strm->inqueue, ctl, next_instrm); 558444249214SRandall Stewart } else if (ctl->on_strm_q == SCTP_ON_UNORDERED) { 558544249214SRandall Stewart TAILQ_REMOVE(&strm->uno_inqueue, ctl, next_instrm); 558698d5fd97SMichael Tuexen #ifdef INVARIANTS 558744249214SRandall Stewart } else if (ctl->on_strm_q) { 558844249214SRandall Stewart panic("strm: %p ctl: %p unknown %d", 558944249214SRandall Stewart strm, ctl, ctl->on_strm_q); 559098d5fd97SMichael Tuexen #endif 559144249214SRandall Stewart } 559244249214SRandall Stewart ctl->on_strm_q = 0; 55938933fa13SRandall Stewart stcb->asoc.control_pdapi = ctl; 5594810ec536SMichael Tuexen sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION, 5595810ec536SMichael Tuexen stcb, 55968933fa13SRandall Stewart SCTP_PARTIAL_DELIVERY_ABORTED, 5597810ec536SMichael Tuexen (void *)&str_seq, 5598810ec536SMichael Tuexen SCTP_SO_NOT_LOCKED); 55998933fa13SRandall Stewart stcb->asoc.control_pdapi = sv; 56008933fa13SRandall Stewart break; 560144249214SRandall Stewart } else if ((ctl->sinfo_stream == stream) && 560244249214SRandall Stewart SCTP_MSGID_GT(old, ctl->sinfo_ssn, sequence)) { 56038933fa13SRandall Stewart /* We are past our victim SSN */ 56048933fa13SRandall Stewart break; 56058933fa13SRandall Stewart } 56068933fa13SRandall Stewart } 560744249214SRandall Stewart if (SCTP_MSGID_GT(old, sequence, strm->last_sequence_delivered)) { 5608f8829a4aSRandall Stewart /* Update the sequence number */ 560944249214SRandall Stewart strm->last_sequence_delivered = sequence; 5610f8829a4aSRandall Stewart } 5611f8829a4aSRandall Stewart /* now kick the stream the new way */ 561204ee05e8SRandall Stewart /* sa_ignore NO_NULL_CHK */ 5613f8829a4aSRandall Stewart sctp_kick_prsctp_reorder_queue(stcb, strm); 5614f8829a4aSRandall Stewart } 56158933fa13SRandall Stewart SCTP_INP_READ_UNLOCK(stcb->sctp_ep); 5616f8829a4aSRandall Stewart } 56177898f408SRandall Stewart /* 56187898f408SRandall Stewart * Now slide thing forward. 56197898f408SRandall Stewart */ 56207898f408SRandall Stewart sctp_slide_mapping_arrays(stcb); 5621f8829a4aSRandall Stewart } 5622