tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1 | /*- |
Michael Tuexen | 866a731 | 2017-11-24 12:44:05 +0100 | [diff] [blame] | 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4 | * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. |
tuexen | 194eae1 | 2012-05-23 12:03:48 +0000 | [diff] [blame] | 5 | * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. |
| 6 | * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 11 | * a) Redistributions of source code must retain the above copyright notice, |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 12 | * this list of conditions and the following disclaimer. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 13 | * |
| 14 | * b) Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 16 | * the documentation and/or other materials provided with the distribution. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 17 | * |
| 18 | * c) Neither the name of Cisco Systems, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 32 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 35 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 36 | #include <sys/cdefs.h> |
Michael Tuexen | b882f26 | 2021-01-31 10:07:47 +0100 | [diff] [blame] | 37 | __FBSDID("$FreeBSD$"); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
| 40 | #include <netinet/sctp_os.h> |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 41 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 42 | #include <sys/proc.h> |
| 43 | #endif |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 44 | #include <netinet/sctp_var.h> |
| 45 | #include <netinet/sctp_sysctl.h> |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 46 | #include <netinet/sctp_header.h> |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 47 | #include <netinet/sctp_pcb.h> |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 48 | #include <netinet/sctputil.h> |
| 49 | #include <netinet/sctp_output.h> |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 50 | #include <netinet/sctp_uio.h> |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 51 | #include <netinet/sctp_auth.h> |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 52 | #include <netinet/sctp_timer.h> |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 53 | #include <netinet/sctp_asconf.h> |
| 54 | #include <netinet/sctp_indata.h> |
| 55 | #include <netinet/sctp_bsd_addr.h> |
| 56 | #include <netinet/sctp_input.h> |
| 57 | #include <netinet/sctp_crc32.h> |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 58 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 59 | #include <netinet/sctp_lock_bsd.h> |
| 60 | #endif |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 61 | /* |
| 62 | * NOTES: On the outbound side of things I need to check the sack timer to |
| 63 | * see if I should generate a sack into the chunk queue (if I have data to |
| 64 | * send that is and will be sending it .. for bundling. |
| 65 | * |
| 66 | * The callback in sctp_usrreq.c will get called when the socket is read from. |
| 67 | * This will cause sctp_service_queues() to get called on the top entry in |
| 68 | * the list. |
| 69 | */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 70 | static uint32_t |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 71 | sctp_add_chk_to_control(struct sctp_queued_to_read *control, |
| 72 | struct sctp_stream_in *strm, |
| 73 | struct sctp_tcb *stcb, |
| 74 | struct sctp_association *asoc, |
Michael Tuexen | eddbc5b | 2020-06-14 11:56:24 +0200 | [diff] [blame] | 75 | struct sctp_tmit_chunk *chk, int hold_rlock); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 76 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 77 | void |
| 78 | sctp_set_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc) |
| 79 | { |
| 80 | asoc->my_rwnd = sctp_calc_rwnd(stcb, asoc); |
| 81 | } |
| 82 | |
| 83 | /* Calculate what the rwnd would be */ |
| 84 | uint32_t |
| 85 | sctp_calc_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc) |
| 86 | { |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 87 | uint32_t calc = 0; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 88 | |
| 89 | /* |
| 90 | * This is really set wrong with respect to a 1-2-m socket. Since |
| 91 | * the sb_cc is the count that everyone as put up. When we re-write |
| 92 | * sctp_soreceive then we will fix this so that ONLY this |
| 93 | * associations data is taken into account. |
| 94 | */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 95 | if (stcb->sctp_socket == NULL) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 96 | return (calc); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 97 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 98 | |
Michael Tuexen | cdba126 | 2017-11-05 13:05:10 +0100 | [diff] [blame] | 99 | KASSERT(asoc->cnt_on_reasm_queue > 0 || asoc->size_on_reasm_queue == 0, |
| 100 | ("size_on_reasm_queue is %u", asoc->size_on_reasm_queue)); |
| 101 | KASSERT(asoc->cnt_on_all_streams > 0 || asoc->size_on_all_streams == 0, |
| 102 | ("size_on_all_streams is %u", asoc->size_on_all_streams)); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 103 | if (stcb->asoc.sb_cc == 0 && |
Michael Tuexen | cdba126 | 2017-11-05 13:05:10 +0100 | [diff] [blame] | 104 | asoc->cnt_on_reasm_queue == 0 && |
| 105 | asoc->cnt_on_all_streams == 0) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 106 | /* Full rwnd granted */ |
| 107 | calc = max(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), SCTP_MINIMAL_RWND); |
| 108 | return (calc); |
| 109 | } |
| 110 | /* get actual space */ |
| 111 | calc = (uint32_t) sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 112 | /* |
| 113 | * take out what has NOT been put on socket queue and we yet hold |
| 114 | * for putting up. |
| 115 | */ |
| 116 | calc = sctp_sbspace_sub(calc, (uint32_t)(asoc->size_on_reasm_queue + |
| 117 | asoc->cnt_on_reasm_queue * MSIZE)); |
| 118 | calc = sctp_sbspace_sub(calc, (uint32_t)(asoc->size_on_all_streams + |
| 119 | asoc->cnt_on_all_streams * MSIZE)); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 120 | if (calc == 0) { |
| 121 | /* out of space */ |
| 122 | return (calc); |
| 123 | } |
| 124 | |
| 125 | /* what is the overhead of all these rwnd's */ |
| 126 | calc = sctp_sbspace_sub(calc, stcb->asoc.my_rwnd_control_len); |
| 127 | /* If the window gets too small due to ctrl-stuff, reduce it |
| 128 | * to 1, even it is 0. SWS engaged |
| 129 | */ |
| 130 | if (calc < stcb->asoc.my_rwnd_control_len) { |
| 131 | calc = 1; |
| 132 | } |
| 133 | return (calc); |
| 134 | } |
| 135 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 136 | /* |
| 137 | * Build out our readq entry based on the incoming packet. |
| 138 | */ |
| 139 | struct sctp_queued_to_read * |
| 140 | sctp_build_readq_entry(struct sctp_tcb *stcb, |
| 141 | struct sctp_nets *net, |
| 142 | uint32_t tsn, uint32_t ppid, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 143 | uint32_t context, uint16_t sid, |
| 144 | uint32_t mid, uint8_t flags, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 145 | struct mbuf *dm) |
| 146 | { |
| 147 | struct sctp_queued_to_read *read_queue_e = NULL; |
| 148 | |
| 149 | sctp_alloc_a_readq(stcb, read_queue_e); |
| 150 | if (read_queue_e == NULL) { |
| 151 | goto failed_build; |
| 152 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 153 | memset(read_queue_e, 0, sizeof(struct sctp_queued_to_read)); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 154 | read_queue_e->sinfo_stream = sid; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 155 | read_queue_e->sinfo_flags = (flags << 8); |
| 156 | read_queue_e->sinfo_ppid = ppid; |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 157 | read_queue_e->sinfo_context = context; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 158 | read_queue_e->sinfo_tsn = tsn; |
| 159 | read_queue_e->sinfo_cumtsn = tsn; |
| 160 | read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 161 | read_queue_e->mid = mid; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 162 | read_queue_e->top_fsn = read_queue_e->fsn_included = 0xffffffff; |
| 163 | TAILQ_INIT(&read_queue_e->reasm); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 164 | read_queue_e->whoFrom = net; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 165 | atomic_add_int(&net->ref_count, 1); |
| 166 | read_queue_e->data = dm; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 167 | read_queue_e->stcb = stcb; |
| 168 | read_queue_e->port_from = stcb->rport; |
Michael Tuexen | d98d2c4 | 2020-05-18 14:09:04 +0200 | [diff] [blame] | 169 | if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
| 170 | read_queue_e->do_not_ref_stcb = 1; |
| 171 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 172 | failed_build: |
| 173 | return (read_queue_e); |
| 174 | } |
| 175 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 176 | struct mbuf * |
| 177 | sctp_build_ctl_nchunk(struct sctp_inpcb *inp, struct sctp_sndrcvinfo *sinfo) |
| 178 | { |
| 179 | struct sctp_extrcvinfo *seinfo; |
| 180 | struct sctp_sndrcvinfo *outinfo; |
| 181 | struct sctp_rcvinfo *rcvinfo; |
| 182 | struct sctp_nxtinfo *nxtinfo; |
Michael Tuexen | eb61157 | 2020-06-13 17:27:02 +0200 | [diff] [blame] | 183 | #if defined(_WIN32) |
t00fcxen | 8d8ec79 | 2012-09-04 22:31:29 +0000 | [diff] [blame] | 184 | WSACMSGHDR *cmh; |
| 185 | #else |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 186 | struct cmsghdr *cmh; |
t00fcxen | 8d8ec79 | 2012-09-04 22:31:29 +0000 | [diff] [blame] | 187 | #endif |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 188 | struct mbuf *ret; |
| 189 | int len; |
| 190 | int use_extended; |
| 191 | int provide_nxt; |
| 192 | |
| 193 | if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT) && |
| 194 | sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO) && |
| 195 | sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO)) { |
| 196 | /* user does not want any ancillary data */ |
| 197 | return (NULL); |
| 198 | } |
| 199 | |
| 200 | len = 0; |
| 201 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO)) { |
| 202 | len += CMSG_SPACE(sizeof(struct sctp_rcvinfo)); |
| 203 | } |
| 204 | seinfo = (struct sctp_extrcvinfo *)sinfo; |
| 205 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO) && |
Michael Tuexen | e818552 | 2015-11-06 14:17:33 +0100 | [diff] [blame] | 206 | (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_AVAIL)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 207 | provide_nxt = 1; |
Michael Tuexen | 9465650 | 2015-11-06 23:14:32 +0100 | [diff] [blame] | 208 | len += CMSG_SPACE(sizeof(struct sctp_nxtinfo)); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 209 | } else { |
| 210 | provide_nxt = 0; |
| 211 | } |
| 212 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) { |
| 213 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) { |
| 214 | use_extended = 1; |
| 215 | len += CMSG_SPACE(sizeof(struct sctp_extrcvinfo)); |
| 216 | } else { |
| 217 | use_extended = 0; |
| 218 | len += CMSG_SPACE(sizeof(struct sctp_sndrcvinfo)); |
| 219 | } |
| 220 | } else { |
| 221 | use_extended = 0; |
| 222 | } |
| 223 | |
t00fcxen | 23c2b8f | 2012-12-10 20:15:50 +0000 | [diff] [blame] | 224 | ret = sctp_get_mbuf_for_msg(len, 0, M_NOWAIT, 1, MT_DATA); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 225 | if (ret == NULL) { |
| 226 | /* No space */ |
| 227 | return (ret); |
| 228 | } |
| 229 | SCTP_BUF_LEN(ret) = 0; |
| 230 | |
| 231 | /* We need a CMSG header followed by the struct */ |
Michael Tuexen | eb61157 | 2020-06-13 17:27:02 +0200 | [diff] [blame] | 232 | #if defined(_WIN32) |
t00fcxen | 8d8ec79 | 2012-09-04 22:31:29 +0000 | [diff] [blame] | 233 | cmh = mtod(ret, WSACMSGHDR *); |
| 234 | #else |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 235 | cmh = mtod(ret, struct cmsghdr *); |
t00fcxen | 8d8ec79 | 2012-09-04 22:31:29 +0000 | [diff] [blame] | 236 | #endif |
t00fcxen | 6b2685d | 2014-07-11 06:33:20 +0000 | [diff] [blame] | 237 | /* |
| 238 | * Make sure that there is no un-initialized padding between |
| 239 | * the cmsg header and cmsg data and after the cmsg data. |
| 240 | */ |
| 241 | memset(cmh, 0, len); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 242 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO)) { |
| 243 | cmh->cmsg_level = IPPROTO_SCTP; |
| 244 | cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_rcvinfo)); |
| 245 | cmh->cmsg_type = SCTP_RCVINFO; |
| 246 | rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmh); |
| 247 | rcvinfo->rcv_sid = sinfo->sinfo_stream; |
| 248 | rcvinfo->rcv_ssn = sinfo->sinfo_ssn; |
| 249 | rcvinfo->rcv_flags = sinfo->sinfo_flags; |
| 250 | rcvinfo->rcv_ppid = sinfo->sinfo_ppid; |
| 251 | rcvinfo->rcv_tsn = sinfo->sinfo_tsn; |
| 252 | rcvinfo->rcv_cumtsn = sinfo->sinfo_cumtsn; |
| 253 | rcvinfo->rcv_context = sinfo->sinfo_context; |
| 254 | rcvinfo->rcv_assoc_id = sinfo->sinfo_assoc_id; |
Michael Tuexen | eb61157 | 2020-06-13 17:27:02 +0200 | [diff] [blame] | 255 | #if defined(_WIN32) |
t00fcxen | 8d8ec79 | 2012-09-04 22:31:29 +0000 | [diff] [blame] | 256 | cmh = (WSACMSGHDR *)((caddr_t)cmh + CMSG_SPACE(sizeof(struct sctp_rcvinfo))); |
| 257 | #else |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 258 | cmh = (struct cmsghdr *)((caddr_t)cmh + CMSG_SPACE(sizeof(struct sctp_rcvinfo))); |
t00fcxen | 8d8ec79 | 2012-09-04 22:31:29 +0000 | [diff] [blame] | 259 | #endif |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 260 | SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_rcvinfo)); |
| 261 | } |
| 262 | if (provide_nxt) { |
| 263 | cmh->cmsg_level = IPPROTO_SCTP; |
| 264 | cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_nxtinfo)); |
| 265 | cmh->cmsg_type = SCTP_NXTINFO; |
| 266 | nxtinfo = (struct sctp_nxtinfo *)CMSG_DATA(cmh); |
Michael Tuexen | e818552 | 2015-11-06 14:17:33 +0100 | [diff] [blame] | 267 | nxtinfo->nxt_sid = seinfo->serinfo_next_stream; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 268 | nxtinfo->nxt_flags = 0; |
Michael Tuexen | e818552 | 2015-11-06 14:17:33 +0100 | [diff] [blame] | 269 | if (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_IS_UNORDERED) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 270 | nxtinfo->nxt_flags |= SCTP_UNORDERED; |
| 271 | } |
Michael Tuexen | e818552 | 2015-11-06 14:17:33 +0100 | [diff] [blame] | 272 | if (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_IS_NOTIFICATION) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 273 | nxtinfo->nxt_flags |= SCTP_NOTIFICATION; |
| 274 | } |
Michael Tuexen | e818552 | 2015-11-06 14:17:33 +0100 | [diff] [blame] | 275 | if (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_ISCOMPLETE) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 276 | nxtinfo->nxt_flags |= SCTP_COMPLETE; |
| 277 | } |
Michael Tuexen | e818552 | 2015-11-06 14:17:33 +0100 | [diff] [blame] | 278 | nxtinfo->nxt_ppid = seinfo->serinfo_next_ppid; |
| 279 | nxtinfo->nxt_length = seinfo->serinfo_next_length; |
| 280 | nxtinfo->nxt_assoc_id = seinfo->serinfo_next_aid; |
Michael Tuexen | eb61157 | 2020-06-13 17:27:02 +0200 | [diff] [blame] | 281 | #if defined(_WIN32) |
t00fcxen | 8d8ec79 | 2012-09-04 22:31:29 +0000 | [diff] [blame] | 282 | cmh = (WSACMSGHDR *)((caddr_t)cmh + CMSG_SPACE(sizeof(struct sctp_nxtinfo))); |
| 283 | #else |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 284 | cmh = (struct cmsghdr *)((caddr_t)cmh + CMSG_SPACE(sizeof(struct sctp_nxtinfo))); |
t00fcxen | 8d8ec79 | 2012-09-04 22:31:29 +0000 | [diff] [blame] | 285 | #endif |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 286 | SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_nxtinfo)); |
| 287 | } |
| 288 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) { |
| 289 | cmh->cmsg_level = IPPROTO_SCTP; |
| 290 | outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh); |
| 291 | if (use_extended) { |
| 292 | cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_extrcvinfo)); |
| 293 | cmh->cmsg_type = SCTP_EXTRCV; |
| 294 | memcpy(outinfo, sinfo, sizeof(struct sctp_extrcvinfo)); |
| 295 | SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_extrcvinfo)); |
| 296 | } else { |
| 297 | cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); |
| 298 | cmh->cmsg_type = SCTP_SNDRCV; |
| 299 | *outinfo = *sinfo; |
| 300 | SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_sndrcvinfo)); |
| 301 | } |
| 302 | } |
| 303 | return (ret); |
| 304 | } |
| 305 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 306 | static void |
| 307 | sctp_mark_non_revokable(struct sctp_association *asoc, uint32_t tsn) |
| 308 | { |
Michael Tuexen | fd9f4fd | 2020-10-04 17:26:24 +0200 | [diff] [blame] | 309 | uint32_t gap, i; |
| 310 | int in_r, in_nr; |
| 311 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 312 | if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) { |
| 313 | return; |
| 314 | } |
Michael Tuexen | fd9f4fd | 2020-10-04 17:26:24 +0200 | [diff] [blame] | 315 | if (SCTP_TSN_GE(asoc->cumulative_tsn, tsn)) { |
| 316 | /* |
| 317 | * This tsn is behind the cum ack and thus we don't |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 318 | * need to worry about it being moved from one to the other. |
| 319 | */ |
| 320 | return; |
| 321 | } |
| 322 | SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 323 | in_r = SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap); |
| 324 | in_nr = SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, gap); |
Michael Tuexen | ab7bbd9 | 2020-10-04 18:45:50 +0200 | [diff] [blame] | 325 | KASSERT(in_r || in_nr, ("%s: Things are really messed up now", __func__)); |
Michael Tuexen | fd9f4fd | 2020-10-04 17:26:24 +0200 | [diff] [blame] | 326 | if (!in_nr) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 327 | SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); |
Michael Tuexen | fd9f4fd | 2020-10-04 17:26:24 +0200 | [diff] [blame] | 328 | if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { |
| 329 | asoc->highest_tsn_inside_nr_map = tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 330 | } |
Michael Tuexen | fd9f4fd | 2020-10-04 17:26:24 +0200 | [diff] [blame] | 331 | } |
| 332 | if (in_r) { |
| 333 | SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, gap); |
| 334 | if (tsn == asoc->highest_tsn_inside_map) { |
| 335 | /* We must back down to see what the new highest is. */ |
| 336 | for (i = tsn - 1; SCTP_TSN_GE(i, asoc->mapping_array_base_tsn); i--) { |
| 337 | SCTP_CALC_TSN_TO_GAP(gap, i, asoc->mapping_array_base_tsn); |
| 338 | if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) { |
| 339 | asoc->highest_tsn_inside_map = i; |
| 340 | break; |
| 341 | } |
| 342 | } |
| 343 | if (!SCTP_TSN_GE(i, asoc->mapping_array_base_tsn)) { |
| 344 | asoc->highest_tsn_inside_map = asoc->mapping_array_base_tsn - 1; |
| 345 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 350 | static int |
| 351 | sctp_place_control_in_stream(struct sctp_stream_in *strm, |
| 352 | struct sctp_association *asoc, |
| 353 | struct sctp_queued_to_read *control) |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 354 | { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 355 | struct sctp_queued_to_read *at; |
| 356 | struct sctp_readhead *q; |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 357 | uint8_t flags, unordered; |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 358 | |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 359 | flags = (control->sinfo_flags >> 8); |
| 360 | unordered = flags & SCTP_DATA_UNORDERED; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 361 | if (unordered) { |
| 362 | q = &strm->uno_inqueue; |
| 363 | if (asoc->idata_supported == 0) { |
| 364 | if (!TAILQ_EMPTY(q)) { |
| 365 | /* Only one stream can be here in old style -- abort */ |
| 366 | return (-1); |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 367 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 368 | TAILQ_INSERT_TAIL(q, control, next_instrm); |
| 369 | control->on_strm_q = SCTP_ON_UNORDERED; |
| 370 | return (0); |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 371 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 372 | } else { |
| 373 | q = &strm->inqueue; |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 374 | } |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 375 | if ((flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { |
| 376 | control->end_added = 1; |
| 377 | control->first_frag_seen = 1; |
| 378 | control->last_frag_seen = 1; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 379 | } |
| 380 | if (TAILQ_EMPTY(q)) { |
| 381 | /* Empty queue */ |
| 382 | TAILQ_INSERT_HEAD(q, control, next_instrm); |
| 383 | if (unordered) { |
| 384 | control->on_strm_q = SCTP_ON_UNORDERED; |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 385 | } else { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 386 | control->on_strm_q = SCTP_ON_ORDERED; |
| 387 | } |
| 388 | return (0); |
| 389 | } else { |
| 390 | TAILQ_FOREACH(at, q, next_instrm) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 391 | if (SCTP_MID_GT(asoc->idata_supported, at->mid, control->mid)) { |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 392 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 393 | * one in queue is bigger than the |
| 394 | * new one, insert before this one |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 395 | */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 396 | TAILQ_INSERT_BEFORE(at, control, next_instrm); |
| 397 | if (unordered) { |
| 398 | control->on_strm_q = SCTP_ON_UNORDERED; |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 399 | } else { |
Michael Tuexen | 196fbbe | 2020-09-28 17:04:25 +0200 | [diff] [blame] | 400 | control->on_strm_q = SCTP_ON_ORDERED; |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 401 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 402 | break; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 403 | } else if (SCTP_MID_EQ(asoc->idata_supported, at->mid, control->mid)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 404 | /* |
| 405 | * Gak, He sent me a duplicate msg |
| 406 | * id number?? return -1 to abort. |
| 407 | */ |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 408 | return (-1); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 409 | } else { |
| 410 | if (TAILQ_NEXT(at, next_instrm) == NULL) { |
| 411 | /* |
| 412 | * We are at the end, insert |
| 413 | * it after this one |
| 414 | */ |
| 415 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { |
| 416 | sctp_log_strm_del(control, at, |
| 417 | SCTP_STR_LOG_FROM_INSERT_TL); |
| 418 | } |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 419 | TAILQ_INSERT_AFTER(q, at, control, next_instrm); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 420 | if (unordered) { |
Michael Tuexen | 196fbbe | 2020-09-28 17:04:25 +0200 | [diff] [blame] | 421 | control->on_strm_q = SCTP_ON_UNORDERED; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 422 | } else { |
Michael Tuexen | 196fbbe | 2020-09-28 17:04:25 +0200 | [diff] [blame] | 423 | control->on_strm_q = SCTP_ON_ORDERED; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 424 | } |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 425 | break; |
| 426 | } |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 427 | } |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 428 | } |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 429 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 430 | return (0); |
| 431 | } |
| 432 | |
| 433 | static void |
| 434 | sctp_abort_in_reasm(struct sctp_tcb *stcb, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 435 | struct sctp_queued_to_read *control, |
| 436 | struct sctp_tmit_chunk *chk, |
| 437 | int *abort_flag, int opspot) |
| 438 | { |
| 439 | char msg[SCTP_DIAG_INFO_LEN]; |
| 440 | struct mbuf *oper; |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 441 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 442 | if (stcb->asoc.idata_supported) { |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 443 | SCTP_SNPRINTF(msg, sizeof(msg), |
| 444 | "Reass %x,CF:%x,TSN=%8.8x,SID=%4.4x,FSN=%8.8x,MID:%8.8x", |
| 445 | opspot, |
| 446 | control->fsn_included, |
| 447 | chk->rec.data.tsn, |
| 448 | chk->rec.data.sid, |
| 449 | chk->rec.data.fsn, chk->rec.data.mid); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 450 | } else { |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 451 | SCTP_SNPRINTF(msg, sizeof(msg), |
| 452 | "Reass %x,CI:%x,TSN=%8.8x,SID=%4.4x,FSN=%4.4x,SSN:%4.4x", |
| 453 | opspot, |
| 454 | control->fsn_included, |
| 455 | chk->rec.data.tsn, |
| 456 | chk->rec.data.sid, |
| 457 | chk->rec.data.fsn, |
| 458 | (uint16_t)chk->rec.data.mid); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 459 | } |
| 460 | oper = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
| 461 | sctp_m_freem(chk->data); |
| 462 | chk->data = NULL; |
| 463 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
| 464 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_1; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 465 | sctp_abort_an_association(stcb->sctp_ep, stcb, oper, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 466 | *abort_flag = 1; |
| 467 | } |
| 468 | |
| 469 | static void |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 470 | sctp_clean_up_control(struct sctp_tcb *stcb, struct sctp_queued_to_read *control) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 471 | { |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 472 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 473 | * The control could not be placed and must be cleaned. |
| 474 | */ |
| 475 | struct sctp_tmit_chunk *chk, *nchk; |
| 476 | TAILQ_FOREACH_SAFE(chk, &control->reasm, sctp_next, nchk) { |
| 477 | TAILQ_REMOVE(&control->reasm, chk, sctp_next); |
| 478 | if (chk->data) |
| 479 | sctp_m_freem(chk->data); |
| 480 | chk->data = NULL; |
| 481 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
| 482 | } |
Michael Tuexen | b07df88 | 2019-09-24 15:21:23 +0200 | [diff] [blame] | 483 | sctp_free_remote_addr(control->whoFrom); |
| 484 | if (control->data) { |
| 485 | sctp_m_freem(control->data); |
| 486 | control->data = NULL; |
| 487 | } |
| 488 | sctp_free_a_readq(stcb, control); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /* |
| 492 | * Queue the chunk either right into the socket buffer if it is the next one |
| 493 | * to go OR put it in the correct place in the delivery queue. If we do |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 494 | * append to the so_buf, keep doing so until we are out of order as |
| 495 | * long as the control's entered are non-fragmented. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 496 | */ |
| 497 | static void |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 498 | sctp_queue_data_to_stream(struct sctp_tcb *stcb, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 499 | struct sctp_association *asoc, |
| 500 | struct sctp_queued_to_read *control, int *abort_flag, int *need_reasm) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 501 | { |
| 502 | /* |
| 503 | * FIX-ME maybe? What happens when the ssn wraps? If we are getting |
| 504 | * all the data in one stream this could happen quite rapidly. One |
| 505 | * could use the TSN to keep track of things, but this scheme breaks |
Michael Tuexen | 34488e7 | 2016-05-03 22:11:59 +0200 | [diff] [blame] | 506 | * down in the other type of stream usage that could occur. Send a |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 507 | * single msg to stream 0, send 4Billion messages to stream 1, now |
| 508 | * send a message to stream 0. You have a situation where the TSN |
| 509 | * has wrapped but not in the stream. Is this worth worrying about |
| 510 | * or should we just change our queue sort at the bottom to be by |
| 511 | * TSN. |
| 512 | * |
| 513 | * Could it also be legal for a peer to send ssn 1 with TSN 2 and ssn 2 |
| 514 | * with TSN 1? If the peer is doing some sort of funky TSN/SSN |
| 515 | * assignment this could happen... and I don't see how this would be |
| 516 | * a violation. So for now I am undecided an will leave the sort by |
David Sanders | b519f51 | 2022-03-29 13:55:16 -0700 | [diff] [blame] | 517 | * SSN alone. Maybe a hybrid approach is the answer |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 518 | * |
| 519 | */ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 520 | struct sctp_queued_to_read *at; |
| 521 | int queue_needed; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 522 | uint32_t nxt_todel; |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 523 | struct mbuf *op_err; |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 524 | struct sctp_stream_in *strm; |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 525 | char msg[SCTP_DIAG_INFO_LEN]; |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 526 | |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 527 | strm = &asoc->strmin[control->sinfo_stream]; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 528 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { |
| 529 | sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD); |
| 530 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 531 | if (SCTP_MID_GT((asoc->idata_supported), strm->last_mid_delivered, control->mid)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 532 | /* The incoming sseq is behind where we last delivered? */ |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 533 | SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ: %u delivered: %u from peer, Abort association\n", |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 534 | strm->last_mid_delivered, control->mid); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 535 | /* |
| 536 | * throw it in the stream so it gets cleaned up in |
| 537 | * association destruction |
| 538 | */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 539 | TAILQ_INSERT_HEAD(&strm->inqueue, control, next_instrm); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 540 | if (asoc->idata_supported) { |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 541 | SCTP_SNPRINTF(msg, sizeof(msg), "Delivered MID=%8.8x, got TSN=%8.8x, SID=%4.4x, MID=%8.8x", |
| 542 | strm->last_mid_delivered, control->sinfo_tsn, |
| 543 | control->sinfo_stream, control->mid); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 544 | } else { |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 545 | SCTP_SNPRINTF(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x", |
| 546 | (uint16_t)strm->last_mid_delivered, |
| 547 | control->sinfo_tsn, |
| 548 | control->sinfo_stream, |
| 549 | (uint16_t)control->mid); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 550 | } |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 551 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 552 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 553 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 554 | *abort_flag = 1; |
| 555 | return; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 556 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 557 | queue_needed = 1; |
| 558 | asoc->size_on_all_streams += control->length; |
| 559 | sctp_ucount_incr(asoc->cnt_on_all_streams); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 560 | nxt_todel = strm->last_mid_delivered + 1; |
| 561 | if (SCTP_MID_EQ(asoc->idata_supported, nxt_todel, control->mid)) { |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 562 | #if defined(__APPLE__) && !defined(__Userspace__) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 563 | struct socket *so; |
| 564 | |
| 565 | so = SCTP_INP_SO(stcb->sctp_ep); |
| 566 | atomic_add_int(&stcb->asoc.refcnt, 1); |
| 567 | SCTP_TCB_UNLOCK(stcb); |
| 568 | SCTP_SOCKET_LOCK(so, 1); |
| 569 | SCTP_TCB_LOCK(stcb); |
| 570 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
| 571 | if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) { |
| 572 | SCTP_SOCKET_UNLOCK(so, 1); |
| 573 | return; |
| 574 | } |
| 575 | #endif |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 576 | /* can be delivered right away? */ |
| 577 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { |
| 578 | sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_IMMED_DEL); |
| 579 | } |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 580 | /* EY it wont be queued if it could be delivered directly */ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 581 | queue_needed = 0; |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 582 | if (asoc->size_on_all_streams >= control->length) { |
| 583 | asoc->size_on_all_streams -= control->length; |
| 584 | } else { |
| 585 | #ifdef INVARIANTS |
| 586 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 587 | #else |
| 588 | asoc->size_on_all_streams = 0; |
| 589 | #endif |
| 590 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 591 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 592 | strm->last_mid_delivered++; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 593 | sctp_mark_non_revokable(asoc, control->sinfo_tsn); |
| 594 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
| 595 | control, |
| 596 | &stcb->sctp_socket->so_rcv, 1, |
Michael Tuexen | 6ecb9e4 | 2016-05-14 15:47:51 +0200 | [diff] [blame] | 597 | SCTP_READ_LOCK_NOT_HELD, SCTP_SO_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 598 | TAILQ_FOREACH_SAFE(control, &strm->inqueue, next_instrm, at) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 599 | /* all delivered */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 600 | nxt_todel = strm->last_mid_delivered + 1; |
| 601 | if (SCTP_MID_EQ(asoc->idata_supported, nxt_todel, control->mid) && |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 602 | (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 603 | if (control->on_strm_q == SCTP_ON_ORDERED) { |
| 604 | TAILQ_REMOVE(&strm->inqueue, control, next_instrm); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 605 | if (asoc->size_on_all_streams >= control->length) { |
| 606 | asoc->size_on_all_streams -= control->length; |
| 607 | } else { |
| 608 | #ifdef INVARIANTS |
| 609 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 610 | #else |
| 611 | asoc->size_on_all_streams = 0; |
| 612 | #endif |
| 613 | } |
| 614 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 615 | #ifdef INVARIANTS |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 616 | } else { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 617 | panic("Huh control: %p is on_strm_q: %d", |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 618 | control, control->on_strm_q); |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 619 | #endif |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 620 | } |
| 621 | control->on_strm_q = 0; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 622 | strm->last_mid_delivered++; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 623 | /* |
| 624 | * We ignore the return of deliver_data here |
| 625 | * since we always can hold the chunk on the |
| 626 | * d-queue. And we have a finite number that |
| 627 | * can be delivered from the strq. |
| 628 | */ |
| 629 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { |
| 630 | sctp_log_strm_del(control, NULL, |
| 631 | SCTP_STR_LOG_FROM_IMMED_DEL); |
| 632 | } |
| 633 | sctp_mark_non_revokable(asoc, control->sinfo_tsn); |
| 634 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
| 635 | control, |
| 636 | &stcb->sctp_socket->so_rcv, 1, |
| 637 | SCTP_READ_LOCK_NOT_HELD, |
Michael Tuexen | 6ecb9e4 | 2016-05-14 15:47:51 +0200 | [diff] [blame] | 638 | SCTP_SO_LOCKED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 639 | continue; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 640 | } else if (SCTP_MID_EQ(asoc->idata_supported, nxt_todel, control->mid)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 641 | *need_reasm = 1; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 642 | } |
| 643 | break; |
| 644 | } |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 645 | #if defined(__APPLE__) && !defined(__Userspace__) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 646 | SCTP_SOCKET_UNLOCK(so, 1); |
| 647 | #endif |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 648 | } |
| 649 | if (queue_needed) { |
| 650 | /* |
| 651 | * Ok, we did not deliver this guy, find the correct place |
| 652 | * to put it on the queue. |
| 653 | */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 654 | if (sctp_place_control_in_stream(strm, asoc, control)) { |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 655 | SCTP_SNPRINTF(msg, sizeof(msg), |
| 656 | "Queue to str MID: %u duplicate", control->mid); |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 657 | sctp_clean_up_control(stcb, control); |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 658 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 659 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_3; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 660 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 661 | *abort_flag = 1; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 662 | } |
| 663 | } |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 664 | } |
| 665 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 666 | static void |
| 667 | sctp_setup_tail_pointer(struct sctp_queued_to_read *control) |
| 668 | { |
| 669 | struct mbuf *m, *prev = NULL; |
| 670 | struct sctp_tcb *stcb; |
| 671 | |
| 672 | stcb = control->stcb; |
| 673 | control->held_length = 0; |
| 674 | control->length = 0; |
| 675 | m = control->data; |
| 676 | while (m) { |
| 677 | if (SCTP_BUF_LEN(m) == 0) { |
| 678 | /* Skip mbufs with NO length */ |
| 679 | if (prev == NULL) { |
| 680 | /* First one */ |
| 681 | control->data = sctp_m_free(m); |
| 682 | m = control->data; |
| 683 | } else { |
| 684 | SCTP_BUF_NEXT(prev) = sctp_m_free(m); |
| 685 | m = SCTP_BUF_NEXT(prev); |
| 686 | } |
| 687 | if (m == NULL) { |
| 688 | control->tail_mbuf = prev; |
| 689 | } |
| 690 | continue; |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 691 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 692 | prev = m; |
| 693 | atomic_add_int(&control->length, SCTP_BUF_LEN(m)); |
| 694 | if (control->on_read_q) { |
| 695 | /* |
| 696 | * On read queue so we must increment the |
| 697 | * SB stuff, we assume caller has done any locks of SB. |
| 698 | */ |
| 699 | sctp_sballoc(stcb, &stcb->sctp_socket->so_rcv, m); |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 700 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 701 | m = SCTP_BUF_NEXT(m); |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 702 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 703 | if (prev) { |
| 704 | control->tail_mbuf = prev; |
| 705 | } |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | static void |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 709 | sctp_add_to_tail_pointer(struct sctp_queued_to_read *control, struct mbuf *m, uint32_t *added) |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 710 | { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 711 | struct mbuf *prev=NULL; |
| 712 | struct sctp_tcb *stcb; |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 713 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 714 | stcb = control->stcb; |
| 715 | if (stcb == NULL) { |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 716 | #ifdef INVARIANTS |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 717 | panic("Control broken"); |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 718 | #else |
| 719 | return; |
| 720 | #endif |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 721 | } |
| 722 | if (control->tail_mbuf == NULL) { |
| 723 | /* TSNH */ |
Michael Tuexen | c38740e | 2019-10-06 10:52:55 +0200 | [diff] [blame] | 724 | sctp_m_freem(control->data); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 725 | control->data = m; |
| 726 | sctp_setup_tail_pointer(control); |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 727 | return; |
| 728 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 729 | control->tail_mbuf->m_next = m; |
| 730 | while (m) { |
| 731 | if (SCTP_BUF_LEN(m) == 0) { |
| 732 | /* Skip mbufs with NO length */ |
| 733 | if (prev == NULL) { |
| 734 | /* First one */ |
| 735 | control->tail_mbuf->m_next = sctp_m_free(m); |
| 736 | m = control->tail_mbuf->m_next; |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 737 | } else { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 738 | SCTP_BUF_NEXT(prev) = sctp_m_free(m); |
| 739 | m = SCTP_BUF_NEXT(prev); |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 740 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 741 | if (m == NULL) { |
| 742 | control->tail_mbuf = prev; |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 743 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 744 | continue; |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 745 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 746 | prev = m; |
| 747 | if (control->on_read_q) { |
| 748 | /* |
| 749 | * On read queue so we must increment the |
| 750 | * SB stuff, we assume caller has done any locks of SB. |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 751 | */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 752 | sctp_sballoc(stcb, &stcb->sctp_socket->so_rcv, m); |
| 753 | } |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 754 | *added += SCTP_BUF_LEN(m); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 755 | atomic_add_int(&control->length, SCTP_BUF_LEN(m)); |
| 756 | m = SCTP_BUF_NEXT(m); |
| 757 | } |
| 758 | if (prev) { |
| 759 | control->tail_mbuf = prev; |
| 760 | } |
| 761 | } |
| 762 | |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 763 | static void |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 764 | sctp_build_readq_entry_from_ctl(struct sctp_queued_to_read *nc, struct sctp_queued_to_read *control) |
| 765 | { |
| 766 | memset(nc, 0, sizeof(struct sctp_queued_to_read)); |
| 767 | nc->sinfo_stream = control->sinfo_stream; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 768 | nc->mid = control->mid; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 769 | TAILQ_INIT(&nc->reasm); |
| 770 | nc->top_fsn = control->top_fsn; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 771 | nc->mid = control->mid; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 772 | nc->sinfo_flags = control->sinfo_flags; |
| 773 | nc->sinfo_ppid = control->sinfo_ppid; |
| 774 | nc->sinfo_context = control->sinfo_context; |
| 775 | nc->fsn_included = 0xffffffff; |
| 776 | nc->sinfo_tsn = control->sinfo_tsn; |
| 777 | nc->sinfo_cumtsn = control->sinfo_cumtsn; |
| 778 | nc->sinfo_assoc_id = control->sinfo_assoc_id; |
| 779 | nc->whoFrom = control->whoFrom; |
| 780 | atomic_add_int(&nc->whoFrom->ref_count, 1); |
| 781 | nc->stcb = control->stcb; |
| 782 | nc->port_from = control->port_from; |
Michael Tuexen | d98d2c4 | 2020-05-18 14:09:04 +0200 | [diff] [blame] | 783 | nc->do_not_ref_stcb = control->do_not_ref_stcb; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 784 | } |
| 785 | |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 786 | static void |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 787 | sctp_reset_a_control(struct sctp_queued_to_read *control, |
| 788 | struct sctp_inpcb *inp, uint32_t tsn) |
| 789 | { |
| 790 | control->fsn_included = tsn; |
| 791 | if (control->on_read_q) { |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 792 | /* |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 793 | * We have to purge it from there, |
| 794 | * hopefully this will work :-) |
| 795 | */ |
| 796 | TAILQ_REMOVE(&inp->read_queue, control, next); |
| 797 | control->on_read_q = 0; |
| 798 | } |
| 799 | } |
| 800 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 801 | static int |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 802 | sctp_handle_old_unordered_data(struct sctp_tcb *stcb, |
| 803 | struct sctp_association *asoc, |
| 804 | struct sctp_stream_in *strm, |
| 805 | struct sctp_queued_to_read *control, |
| 806 | uint32_t pd_point, |
| 807 | int inp_read_lock_held) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 808 | { |
| 809 | /* Special handling for the old un-ordered data chunk. |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 810 | * All the chunks/TSN's go to mid 0. So |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 811 | * we have to do the old style watching to see |
| 812 | * if we have it all. If you return one, no other |
| 813 | * control entries on the un-ordered queue will |
| 814 | * be looked at. In theory there should be no others |
| 815 | * entries in reality, unless the guy is sending both |
| 816 | * unordered NDATA and unordered DATA... |
| 817 | */ |
| 818 | struct sctp_tmit_chunk *chk, *lchk, *tchk; |
| 819 | uint32_t fsn; |
Michael Tuexen | c0d26d9 | 2016-07-16 12:22:25 +0200 | [diff] [blame] | 820 | struct sctp_queued_to_read *nc; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 821 | int cnt_added; |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 822 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 823 | if (control->first_frag_seen == 0) { |
| 824 | /* Nothing we can do, we have not seen the first piece yet */ |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 825 | return (1); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 826 | } |
| 827 | /* Collapse any we can */ |
| 828 | cnt_added = 0; |
| 829 | restart: |
| 830 | fsn = control->fsn_included + 1; |
| 831 | /* Now what can we add? */ |
| 832 | TAILQ_FOREACH_SAFE(chk, &control->reasm, sctp_next, lchk) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 833 | if (chk->rec.data.fsn == fsn) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 834 | /* Ok lets add it */ |
Michael Tuexen | c0d26d9 | 2016-07-16 12:22:25 +0200 | [diff] [blame] | 835 | sctp_alloc_a_readq(stcb, nc); |
| 836 | if (nc == NULL) { |
| 837 | break; |
| 838 | } |
Michael Tuexen | 2b62a39 | 2016-07-16 13:59:54 +0200 | [diff] [blame] | 839 | memset(nc, 0, sizeof(struct sctp_queued_to_read)); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 840 | TAILQ_REMOVE(&control->reasm, chk, sctp_next); |
Michael Tuexen | b882f26 | 2021-01-31 10:07:47 +0100 | [diff] [blame] | 841 | sctp_add_chk_to_control(control, strm, stcb, asoc, chk, inp_read_lock_held); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 842 | fsn++; |
| 843 | cnt_added++; |
| 844 | chk = NULL; |
| 845 | if (control->end_added) { |
| 846 | /* We are done */ |
| 847 | if (!TAILQ_EMPTY(&control->reasm)) { |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 848 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 849 | * Ok we have to move anything left on |
| 850 | * the control queue to a new control. |
| 851 | */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 852 | sctp_build_readq_entry_from_ctl(nc, control); |
| 853 | tchk = TAILQ_FIRST(&control->reasm); |
| 854 | if (tchk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { |
| 855 | TAILQ_REMOVE(&control->reasm, tchk, sctp_next); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 856 | if (asoc->size_on_reasm_queue >= tchk->send_size) { |
| 857 | asoc->size_on_reasm_queue -= tchk->send_size; |
| 858 | } else { |
| 859 | #ifdef INVARIANTS |
| 860 | panic("size_on_reasm_queue = %u smaller than chunk length %u", asoc->size_on_reasm_queue, tchk->send_size); |
| 861 | #else |
| 862 | asoc->size_on_reasm_queue = 0; |
| 863 | #endif |
| 864 | } |
Michael Tuexen | 93e6e55 | 2016-09-22 16:25:12 +0200 | [diff] [blame] | 865 | sctp_ucount_decr(asoc->cnt_on_reasm_queue); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 866 | nc->first_frag_seen = 1; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 867 | nc->fsn_included = tchk->rec.data.fsn; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 868 | nc->data = tchk->data; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 869 | nc->sinfo_ppid = tchk->rec.data.ppid; |
| 870 | nc->sinfo_tsn = tchk->rec.data.tsn; |
| 871 | sctp_mark_non_revokable(asoc, tchk->rec.data.tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 872 | tchk->data = NULL; |
| 873 | sctp_free_a_chunk(stcb, tchk, SCTP_SO_NOT_LOCKED); |
| 874 | sctp_setup_tail_pointer(nc); |
| 875 | tchk = TAILQ_FIRST(&control->reasm); |
| 876 | } |
| 877 | /* Spin the rest onto the queue */ |
| 878 | while (tchk) { |
| 879 | TAILQ_REMOVE(&control->reasm, tchk, sctp_next); |
| 880 | TAILQ_INSERT_TAIL(&nc->reasm, tchk, sctp_next); |
| 881 | tchk = TAILQ_FIRST(&control->reasm); |
| 882 | } |
| 883 | /* Now lets add it to the queue after removing control */ |
| 884 | TAILQ_INSERT_TAIL(&strm->uno_inqueue, nc, next_instrm); |
| 885 | nc->on_strm_q = SCTP_ON_UNORDERED; |
| 886 | if (control->on_strm_q) { |
| 887 | TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); |
| 888 | control->on_strm_q = 0; |
| 889 | } |
| 890 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 891 | if (control->pdapi_started) { |
| 892 | strm->pd_api_started = 0; |
| 893 | control->pdapi_started = 0; |
| 894 | } |
| 895 | if (control->on_strm_q) { |
| 896 | TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); |
| 897 | control->on_strm_q = 0; |
Michael Tuexen | 07cc2ed | 2016-07-17 10:33:57 +0200 | [diff] [blame] | 898 | SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 899 | } |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 900 | if (control->on_read_q == 0) { |
| 901 | sctp_add_to_readq(stcb->sctp_ep, stcb, control, |
| 902 | &stcb->sctp_socket->so_rcv, control->end_added, |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 903 | inp_read_lock_held, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | 6539426 | 2016-05-09 08:17:54 +0200 | [diff] [blame] | 904 | #if defined(__Userspace__) |
| 905 | } else { |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 906 | sctp_invoke_recv_callback(stcb->sctp_ep, stcb, control, inp_read_lock_held); |
Michael Tuexen | 6539426 | 2016-05-09 08:17:54 +0200 | [diff] [blame] | 907 | #endif |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 908 | } |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 909 | sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | 2a74c79 | 2016-07-19 13:20:24 +0200 | [diff] [blame] | 910 | if ((nc->first_frag_seen) && !TAILQ_EMPTY(&nc->reasm)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 911 | /* Switch to the new guy and continue */ |
| 912 | control = nc; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 913 | goto restart; |
Michael Tuexen | c0d26d9 | 2016-07-16 12:22:25 +0200 | [diff] [blame] | 914 | } else { |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 915 | if (nc->on_strm_q == 0) { |
| 916 | sctp_free_a_readq(stcb, nc); |
| 917 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 918 | } |
| 919 | return (1); |
Michael Tuexen | c0d26d9 | 2016-07-16 12:22:25 +0200 | [diff] [blame] | 920 | } else { |
| 921 | sctp_free_a_readq(stcb, nc); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 922 | } |
| 923 | } else { |
| 924 | /* Can't add more */ |
| 925 | break; |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 926 | } |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 927 | } |
Michael Tüxen | 703ca42 | 2019-07-22 14:13:53 -0400 | [diff] [blame] | 928 | if (cnt_added && strm->pd_api_started) { |
| 929 | #if defined(__Userspace__) |
Michael Tuexen | b882f26 | 2021-01-31 10:07:47 +0100 | [diff] [blame] | 930 | sctp_invoke_recv_callback(stcb->sctp_ep, stcb, control, inp_read_lock_held); |
Michael Tüxen | 703ca42 | 2019-07-22 14:13:53 -0400 | [diff] [blame] | 931 | #endif |
| 932 | sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); |
| 933 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 934 | if ((control->length > pd_point) && (strm->pd_api_started == 0)) { |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 935 | strm->pd_api_started = 1; |
| 936 | control->pdapi_started = 1; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 937 | sctp_add_to_readq(stcb->sctp_ep, stcb, control, |
| 938 | &stcb->sctp_socket->so_rcv, control->end_added, |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 939 | inp_read_lock_held, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 940 | sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 941 | return (0); |
| 942 | } else { |
| 943 | return (1); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | static void |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 948 | sctp_inject_old_unordered_data(struct sctp_tcb *stcb, |
| 949 | struct sctp_association *asoc, |
| 950 | struct sctp_queued_to_read *control, |
| 951 | struct sctp_tmit_chunk *chk, |
| 952 | int *abort_flag) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 953 | { |
| 954 | struct sctp_tmit_chunk *at; |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 955 | int inserted; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 956 | /* |
| 957 | * Here we need to place the chunk into the control structure |
| 958 | * sorted in the correct order. |
| 959 | */ |
| 960 | if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { |
| 961 | /* Its the very first one. */ |
| 962 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 963 | "chunk is a first fsn: %u becomes fsn_included\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 964 | chk->rec.data.fsn); |
Michael Tuexen | 6dcb0e0 | 2019-03-26 14:08:49 +0100 | [diff] [blame] | 965 | at = TAILQ_FIRST(&control->reasm); |
| 966 | if (at && SCTP_TSN_GT(chk->rec.data.fsn, at->rec.data.fsn)) { |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 967 | /* |
Michael Tuexen | 6dcb0e0 | 2019-03-26 14:08:49 +0100 | [diff] [blame] | 968 | * The first chunk in the reassembly is |
| 969 | * a smaller TSN than this one, even though |
| 970 | * this has a first, it must be from a subsequent |
| 971 | * msg. |
| 972 | */ |
| 973 | goto place_chunk; |
| 974 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 975 | if (control->first_frag_seen) { |
| 976 | /* |
| 977 | * In old un-ordered we can reassembly on |
| 978 | * one control multiple messages. As long |
| 979 | * as the next FIRST is greater then the old |
| 980 | * first (TSN i.e. FSN wise) |
| 981 | */ |
| 982 | struct mbuf *tdata; |
| 983 | uint32_t tmp; |
| 984 | |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 985 | if (SCTP_TSN_GT(chk->rec.data.fsn, control->fsn_included)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 986 | /* Easy way the start of a new guy beyond the lowest */ |
| 987 | goto place_chunk; |
| 988 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 989 | if ((chk->rec.data.fsn == control->fsn_included) || |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 990 | (control->pdapi_started)) { |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 991 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 992 | * Ok this should not happen, if it does |
| 993 | * we started the pd-api on the higher TSN (since |
| 994 | * the equals part is a TSN failure it must be that). |
| 995 | * |
David Sanders | b519f51 | 2022-03-29 13:55:16 -0700 | [diff] [blame] | 996 | * We are completely hosed in that case since I have |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 997 | * no way to recover. This really will only happen |
| 998 | * if we can get more TSN's higher before the pd-api-point. |
| 999 | */ |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1000 | sctp_abort_in_reasm(stcb, control, chk, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1001 | abort_flag, |
| 1002 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_4); |
| 1003 | |
| 1004 | return; |
| 1005 | } |
| 1006 | /* |
| 1007 | * Ok we have two firsts and the one we just got |
| 1008 | * is smaller than the one we previously placed.. yuck! |
| 1009 | * We must swap them out. |
| 1010 | */ |
| 1011 | /* swap the mbufs */ |
| 1012 | tdata = control->data; |
| 1013 | control->data = chk->data; |
| 1014 | chk->data = tdata; |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1015 | /* Save the lengths */ |
| 1016 | chk->send_size = control->length; |
| 1017 | /* Recompute length of control and tail pointer */ |
| 1018 | sctp_setup_tail_pointer(control); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1019 | /* Fix the FSN included */ |
| 1020 | tmp = control->fsn_included; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1021 | control->fsn_included = chk->rec.data.fsn; |
| 1022 | chk->rec.data.fsn = tmp; |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1023 | /* Fix the TSN included */ |
| 1024 | tmp = control->sinfo_tsn; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1025 | control->sinfo_tsn = chk->rec.data.tsn; |
| 1026 | chk->rec.data.tsn = tmp; |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1027 | /* Fix the PPID included */ |
| 1028 | tmp = control->sinfo_ppid; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1029 | control->sinfo_ppid = chk->rec.data.ppid; |
| 1030 | chk->rec.data.ppid = tmp; |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1031 | /* Fix tail pointer */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1032 | goto place_chunk; |
| 1033 | } |
| 1034 | control->first_frag_seen = 1; |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1035 | control->fsn_included = chk->rec.data.fsn; |
| 1036 | control->top_fsn = chk->rec.data.fsn; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1037 | control->sinfo_tsn = chk->rec.data.tsn; |
| 1038 | control->sinfo_ppid = chk->rec.data.ppid; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1039 | control->data = chk->data; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1040 | sctp_mark_non_revokable(asoc, chk->rec.data.tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1041 | chk->data = NULL; |
| 1042 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
| 1043 | sctp_setup_tail_pointer(control); |
| 1044 | return; |
| 1045 | } |
| 1046 | place_chunk: |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1047 | inserted = 0; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1048 | TAILQ_FOREACH(at, &control->reasm, sctp_next) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1049 | if (SCTP_TSN_GT(at->rec.data.fsn, chk->rec.data.fsn)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1050 | /* |
| 1051 | * This one in queue is bigger than the new one, insert |
| 1052 | * the new one before at. |
| 1053 | */ |
| 1054 | asoc->size_on_reasm_queue += chk->send_size; |
| 1055 | sctp_ucount_incr(asoc->cnt_on_reasm_queue); |
| 1056 | inserted = 1; |
| 1057 | TAILQ_INSERT_BEFORE(at, chk, sctp_next); |
| 1058 | break; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1059 | } else if (at->rec.data.fsn == chk->rec.data.fsn) { |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 1060 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1061 | * They sent a duplicate fsn number. This |
| 1062 | * really should not happen since the FSN is |
| 1063 | * a TSN and it should have been dropped earlier. |
| 1064 | */ |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1065 | sctp_abort_in_reasm(stcb, control, chk, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1066 | abort_flag, |
| 1067 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_5); |
| 1068 | return; |
| 1069 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1070 | } |
| 1071 | if (inserted == 0) { |
| 1072 | /* Its at the end */ |
| 1073 | asoc->size_on_reasm_queue += chk->send_size; |
| 1074 | sctp_ucount_incr(asoc->cnt_on_reasm_queue); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1075 | control->top_fsn = chk->rec.data.fsn; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1076 | TAILQ_INSERT_TAIL(&control->reasm, chk, sctp_next); |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | static int |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1081 | sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc, |
| 1082 | struct sctp_stream_in *strm, int inp_read_lock_held) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1083 | { |
| 1084 | /* |
| 1085 | * Given a stream, strm, see if any of |
| 1086 | * the SSN's on it that are fragmented |
| 1087 | * are ready to deliver. If so go ahead |
| 1088 | * and place them on the read queue. In |
| 1089 | * so placing if we have hit the end, then |
| 1090 | * we need to remove them from the stream's queue. |
| 1091 | */ |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 1092 | struct sctp_queued_to_read *control, *nctl = NULL; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1093 | uint32_t next_to_del; |
| 1094 | uint32_t pd_point; |
| 1095 | int ret = 0; |
| 1096 | |
| 1097 | if (stcb->sctp_socket) { |
| 1098 | pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket) >> SCTP_PARTIAL_DELIVERY_SHIFT, |
| 1099 | stcb->sctp_ep->partial_delivery_point); |
| 1100 | } else { |
| 1101 | pd_point = stcb->sctp_ep->partial_delivery_point; |
| 1102 | } |
| 1103 | control = TAILQ_FIRST(&strm->uno_inqueue); |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1104 | |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 1105 | if ((control != NULL) && |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1106 | (asoc->idata_supported == 0)) { |
| 1107 | /* Special handling needed for "old" data format */ |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1108 | if (sctp_handle_old_unordered_data(stcb, asoc, strm, control, pd_point, inp_read_lock_held)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1109 | goto done_un; |
| 1110 | } |
| 1111 | } |
| 1112 | if (strm->pd_api_started) { |
| 1113 | /* Can't add more */ |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1114 | return (0); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1115 | } |
| 1116 | while (control) { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1117 | SCTPDBG(SCTP_DEBUG_XXX, "Looking at control: %p e(%d) ssn: %u top_fsn: %u inc_fsn: %u -uo\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1118 | control, control->end_added, control->mid, control->top_fsn, control->fsn_included); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1119 | nctl = TAILQ_NEXT(control, next_instrm); |
| 1120 | if (control->end_added) { |
| 1121 | /* We just put the last bit on */ |
| 1122 | if (control->on_strm_q) { |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 1123 | #ifdef INVARIANTS |
Michael Tuexen | 53579be | 2020-10-07 17:39:17 +0200 | [diff] [blame] | 1124 | if (control->on_strm_q != SCTP_ON_UNORDERED) { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1125 | panic("Huh control: %p on_q: %d -- not unordered?", |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1126 | control, control->on_strm_q); |
| 1127 | } |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 1128 | #endif |
Michael Tuexen | 07cc2ed | 2016-07-17 10:33:57 +0200 | [diff] [blame] | 1129 | SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1130 | TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); |
Michael Tuexen | 4f5d962 | 2020-06-24 16:49:59 +0200 | [diff] [blame] | 1131 | if (asoc->size_on_all_streams >= control->length) { |
| 1132 | asoc->size_on_all_streams -= control->length; |
| 1133 | } else { |
| 1134 | #ifdef INVARIANTS |
| 1135 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 1136 | #else |
| 1137 | asoc->size_on_all_streams = 0; |
| 1138 | #endif |
| 1139 | } |
| 1140 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1141 | control->on_strm_q = 0; |
| 1142 | } |
| 1143 | if (control->on_read_q == 0) { |
| 1144 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
| 1145 | control, |
| 1146 | &stcb->sctp_socket->so_rcv, control->end_added, |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1147 | inp_read_lock_held, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1148 | } |
| 1149 | } else { |
| 1150 | /* Can we do a PD-API for this un-ordered guy? */ |
| 1151 | if ((control->length >= pd_point) && (strm->pd_api_started == 0)) { |
| 1152 | strm->pd_api_started = 1; |
| 1153 | control->pdapi_started = 1; |
| 1154 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
| 1155 | control, |
| 1156 | &stcb->sctp_socket->so_rcv, control->end_added, |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1157 | inp_read_lock_held, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | ea37a47 | 2017-12-08 00:07:41 +0100 | [diff] [blame] | 1158 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1159 | break; |
| 1160 | } |
| 1161 | } |
| 1162 | control = nctl; |
| 1163 | } |
| 1164 | done_un: |
| 1165 | control = TAILQ_FIRST(&strm->inqueue); |
| 1166 | if (strm->pd_api_started) { |
| 1167 | /* Can't add more */ |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1168 | return (0); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1169 | } |
| 1170 | if (control == NULL) { |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1171 | return (ret); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1172 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1173 | if (SCTP_MID_EQ(asoc->idata_supported, strm->last_mid_delivered, control->mid)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1174 | /* Ok the guy at the top was being partially delivered |
| 1175 | * completed, so we remove it. Note |
| 1176 | * the pd_api flag was taken off when the |
| 1177 | * chunk was merged on in sctp_queue_data_for_reasm below. |
| 1178 | */ |
| 1179 | nctl = TAILQ_NEXT(control, next_instrm); |
| 1180 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1181 | "Looking at control: %p e(%d) ssn: %u top_fsn: %u inc_fsn: %u (lastdel: %u)- o\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1182 | control, control->end_added, control->mid, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1183 | control->top_fsn, control->fsn_included, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1184 | strm->last_mid_delivered); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1185 | if (control->end_added) { |
| 1186 | if (control->on_strm_q) { |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 1187 | #ifdef INVARIANTS |
Michael Tuexen | 53579be | 2020-10-07 17:39:17 +0200 | [diff] [blame] | 1188 | if (control->on_strm_q != SCTP_ON_ORDERED) { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1189 | panic("Huh control: %p on_q: %d -- not ordered?", |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1190 | control, control->on_strm_q); |
| 1191 | } |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 1192 | #endif |
Michael Tuexen | 07cc2ed | 2016-07-17 10:33:57 +0200 | [diff] [blame] | 1193 | SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1194 | TAILQ_REMOVE(&strm->inqueue, control, next_instrm); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1195 | if (asoc->size_on_all_streams >= control->length) { |
| 1196 | asoc->size_on_all_streams -= control->length; |
| 1197 | } else { |
| 1198 | #ifdef INVARIANTS |
| 1199 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 1200 | #else |
| 1201 | asoc->size_on_all_streams = 0; |
| 1202 | #endif |
| 1203 | } |
| 1204 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1205 | control->on_strm_q = 0; |
| 1206 | } |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1207 | if (strm->pd_api_started && control->pdapi_started) { |
| 1208 | control->pdapi_started = 0; |
| 1209 | strm->pd_api_started = 0; |
| 1210 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1211 | if (control->on_read_q == 0) { |
| 1212 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
| 1213 | control, |
| 1214 | &stcb->sctp_socket->so_rcv, control->end_added, |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1215 | inp_read_lock_held, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1216 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1217 | control = nctl; |
| 1218 | } |
| 1219 | } |
| 1220 | if (strm->pd_api_started) { |
| 1221 | /* Can't add more must have gotten an un-ordered above being partially delivered. */ |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1222 | return (0); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1223 | } |
| 1224 | deliver_more: |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1225 | next_to_del = strm->last_mid_delivered + 1; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1226 | if (control) { |
| 1227 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1228 | "Looking at control: %p e(%d) ssn: %u top_fsn: %u inc_fsn: %u (nxtdel: %u)- o\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1229 | control, control->end_added, control->mid, control->top_fsn, control->fsn_included, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1230 | next_to_del); |
| 1231 | nctl = TAILQ_NEXT(control, next_instrm); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1232 | if (SCTP_MID_EQ(asoc->idata_supported, control->mid, next_to_del) && |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1233 | (control->first_frag_seen)) { |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1234 | int done; |
| 1235 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1236 | /* Ok we can deliver it onto the stream. */ |
| 1237 | if (control->end_added) { |
| 1238 | /* We are done with it afterwards */ |
| 1239 | if (control->on_strm_q) { |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 1240 | #ifdef INVARIANTS |
Michael Tuexen | 53579be | 2020-10-07 17:39:17 +0200 | [diff] [blame] | 1241 | if (control->on_strm_q != SCTP_ON_ORDERED) { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1242 | panic("Huh control: %p on_q: %d -- not ordered?", |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1243 | control, control->on_strm_q); |
| 1244 | } |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 1245 | #endif |
Michael Tuexen | 07cc2ed | 2016-07-17 10:33:57 +0200 | [diff] [blame] | 1246 | SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1247 | TAILQ_REMOVE(&strm->inqueue, control, next_instrm); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1248 | if (asoc->size_on_all_streams >= control->length) { |
| 1249 | asoc->size_on_all_streams -= control->length; |
| 1250 | } else { |
| 1251 | #ifdef INVARIANTS |
| 1252 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 1253 | #else |
| 1254 | asoc->size_on_all_streams = 0; |
| 1255 | #endif |
| 1256 | } |
| 1257 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1258 | control->on_strm_q = 0; |
| 1259 | } |
| 1260 | ret++; |
| 1261 | } |
| 1262 | if (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { |
| 1263 | /* A singleton now slipping through - mark it non-revokable too */ |
| 1264 | sctp_mark_non_revokable(asoc, control->sinfo_tsn); |
| 1265 | } else if (control->end_added == 0) { |
| 1266 | /* Check if we can defer adding until its all there */ |
| 1267 | if ((control->length < pd_point) || (strm->pd_api_started)) { |
| 1268 | /* Don't need it or cannot add more (one being delivered that way) */ |
| 1269 | goto out; |
| 1270 | } |
| 1271 | } |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1272 | done = (control->end_added) && (control->last_frag_seen); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1273 | if (control->on_read_q == 0) { |
Michael Tuexen | cdba126 | 2017-11-05 13:05:10 +0100 | [diff] [blame] | 1274 | if (!done) { |
| 1275 | if (asoc->size_on_all_streams >= control->length) { |
| 1276 | asoc->size_on_all_streams -= control->length; |
| 1277 | } else { |
| 1278 | #ifdef INVARIANTS |
| 1279 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 1280 | #else |
| 1281 | asoc->size_on_all_streams = 0; |
| 1282 | #endif |
| 1283 | } |
| 1284 | strm->pd_api_started = 1; |
| 1285 | control->pdapi_started = 1; |
| 1286 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1287 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
| 1288 | control, |
| 1289 | &stcb->sctp_socket->so_rcv, control->end_added, |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1290 | inp_read_lock_held, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1291 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1292 | strm->last_mid_delivered = next_to_del; |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1293 | if (done) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1294 | control = nctl; |
| 1295 | goto deliver_more; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | } |
| 1299 | out: |
| 1300 | return (ret); |
| 1301 | } |
| 1302 | |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1303 | uint32_t |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1304 | sctp_add_chk_to_control(struct sctp_queued_to_read *control, |
| 1305 | struct sctp_stream_in *strm, |
| 1306 | struct sctp_tcb *stcb, struct sctp_association *asoc, |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1307 | struct sctp_tmit_chunk *chk, int hold_rlock) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1308 | { |
| 1309 | /* |
| 1310 | * Given a control and a chunk, merge the |
| 1311 | * data from the chk onto the control and free |
| 1312 | * up the chunk resources. |
| 1313 | */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1314 | uint32_t added=0; |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1315 | int i_locked = 0; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1316 | |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1317 | if (control->on_read_q && (hold_rlock == 0)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1318 | /* |
| 1319 | * Its being pd-api'd so we must |
| 1320 | * do some locks. |
| 1321 | */ |
| 1322 | SCTP_INP_READ_LOCK(stcb->sctp_ep); |
| 1323 | i_locked = 1; |
| 1324 | } |
| 1325 | if (control->data == NULL) { |
| 1326 | control->data = chk->data; |
| 1327 | sctp_setup_tail_pointer(control); |
| 1328 | } else { |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1329 | sctp_add_to_tail_pointer(control, chk->data, &added); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1330 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1331 | control->fsn_included = chk->rec.data.fsn; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1332 | asoc->size_on_reasm_queue -= chk->send_size; |
| 1333 | sctp_ucount_decr(asoc->cnt_on_reasm_queue); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1334 | sctp_mark_non_revokable(asoc, chk->rec.data.tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1335 | chk->data = NULL; |
| 1336 | if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { |
| 1337 | control->first_frag_seen = 1; |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1338 | control->sinfo_tsn = chk->rec.data.tsn; |
| 1339 | control->sinfo_ppid = chk->rec.data.ppid; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1340 | } |
| 1341 | if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { |
| 1342 | /* Its complete */ |
| 1343 | if ((control->on_strm_q) && (control->on_read_q)) { |
| 1344 | if (control->pdapi_started) { |
| 1345 | control->pdapi_started = 0; |
| 1346 | strm->pd_api_started = 0; |
| 1347 | } |
| 1348 | if (control->on_strm_q == SCTP_ON_UNORDERED) { |
| 1349 | /* Unordered */ |
| 1350 | TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); |
| 1351 | control->on_strm_q = 0; |
| 1352 | } else if (control->on_strm_q == SCTP_ON_ORDERED) { |
| 1353 | /* Ordered */ |
| 1354 | TAILQ_REMOVE(&strm->inqueue, control, next_instrm); |
Michael Tuexen | cdba126 | 2017-11-05 13:05:10 +0100 | [diff] [blame] | 1355 | /* |
| 1356 | * Don't need to decrement size_on_all_streams, |
| 1357 | * since control is on the read queue. |
| 1358 | */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1359 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1360 | control->on_strm_q = 0; |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 1361 | #ifdef INVARIANTS |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1362 | } else if (control->on_strm_q) { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1363 | panic("Unknown state on ctrl: %p on_strm_q: %d", control, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1364 | control->on_strm_q); |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 1365 | #endif |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | control->end_added = 1; |
| 1369 | control->last_frag_seen = 1; |
| 1370 | } |
| 1371 | if (i_locked) { |
| 1372 | SCTP_INP_READ_UNLOCK(stcb->sctp_ep); |
| 1373 | } |
Michael Tuexen | 98b7455 | 2016-05-09 17:41:56 +0200 | [diff] [blame] | 1374 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1375 | return (added); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /* |
| 1379 | * Dump onto the re-assembly queue, in its proper place. After dumping on the |
| 1380 | * queue, see if anthing can be delivered. If so pull it off (or as much as |
| 1381 | * we can. If we run out of space then we must dump what we can and set the |
| 1382 | * appropriate flag to say we queued what we could. |
| 1383 | */ |
| 1384 | static void |
| 1385 | sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1386 | struct sctp_queued_to_read *control, |
| 1387 | struct sctp_tmit_chunk *chk, |
| 1388 | int created_control, |
| 1389 | int *abort_flag, uint32_t tsn) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1390 | { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1391 | uint32_t next_fsn; |
| 1392 | struct sctp_tmit_chunk *at, *nat; |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 1393 | struct sctp_stream_in *strm; |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1394 | int do_wakeup, unordered; |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1395 | uint32_t lenadded; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1396 | |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 1397 | strm = &asoc->strmin[control->sinfo_stream]; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1398 | /* |
| 1399 | * For old un-ordered data chunks. |
| 1400 | */ |
| 1401 | if ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) { |
| 1402 | unordered = 1; |
| 1403 | } else { |
| 1404 | unordered = 0; |
| 1405 | } |
| 1406 | /* Must be added to the stream-in queue */ |
| 1407 | if (created_control) { |
Michael Tuexen | 4f5d962 | 2020-06-24 16:49:59 +0200 | [diff] [blame] | 1408 | if ((unordered == 0) || (asoc->idata_supported)) { |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1409 | sctp_ucount_incr(asoc->cnt_on_all_streams); |
| 1410 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1411 | if (sctp_place_control_in_stream(strm, asoc, control)) { |
| 1412 | /* Duplicate SSN? */ |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1413 | sctp_abort_in_reasm(stcb, control, chk, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1414 | abort_flag, |
| 1415 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_6); |
Michael Tuexen | 663a17e | 2017-09-21 11:49:43 +0200 | [diff] [blame] | 1416 | sctp_clean_up_control(stcb, control); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1417 | return; |
| 1418 | } |
| 1419 | if ((tsn == (asoc->cumulative_tsn + 1) && (asoc->idata_supported == 0))) { |
| 1420 | /* Ok we created this control and now |
| 1421 | * lets validate that its legal i.e. there |
| 1422 | * is a B bit set, if not and we have |
| 1423 | * up to the cum-ack then its invalid. |
| 1424 | */ |
| 1425 | if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) { |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1426 | sctp_abort_in_reasm(stcb, control, chk, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1427 | abort_flag, |
| 1428 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_7); |
| 1429 | return; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1430 | } |
| 1431 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1432 | } |
Michael Tuexen | 34a90e2 | 2016-04-18 11:35:26 +0200 | [diff] [blame] | 1433 | if ((asoc->idata_supported == 0) && (unordered == 1)) { |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 1434 | sctp_inject_old_unordered_data(stcb, asoc, control, chk, abort_flag); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1435 | return; |
| 1436 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1437 | /* |
| 1438 | * Ok we must queue the chunk into the reasembly portion: |
| 1439 | * o if its the first it goes to the control mbuf. |
| 1440 | * o if its not first but the next in sequence it goes to the control, |
| 1441 | * and each succeeding one in order also goes. |
| 1442 | * o if its not in order we place it on the list in its place. |
| 1443 | */ |
| 1444 | if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { |
| 1445 | /* Its the very first one. */ |
| 1446 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1447 | "chunk is a first fsn: %u becomes fsn_included\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1448 | chk->rec.data.fsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1449 | if (control->first_frag_seen) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1450 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1451 | * Error on senders part, they either |
| 1452 | * sent us two data chunks with FIRST, |
| 1453 | * or they sent two un-ordered chunks that |
| 1454 | * were fragmented at the same time in the same stream. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1455 | */ |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1456 | sctp_abort_in_reasm(stcb, control, chk, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1457 | abort_flag, |
| 1458 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_8); |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 1459 | return; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1460 | } |
| 1461 | control->first_frag_seen = 1; |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1462 | control->sinfo_ppid = chk->rec.data.ppid; |
| 1463 | control->sinfo_tsn = chk->rec.data.tsn; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1464 | control->fsn_included = chk->rec.data.fsn; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1465 | control->data = chk->data; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1466 | sctp_mark_non_revokable(asoc, chk->rec.data.tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1467 | chk->data = NULL; |
| 1468 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
| 1469 | sctp_setup_tail_pointer(control); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1470 | asoc->size_on_all_streams += control->length; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1471 | } else { |
| 1472 | /* Place the chunk in our list */ |
| 1473 | int inserted=0; |
Michael Tuexen | 34a90e2 | 2016-04-18 11:35:26 +0200 | [diff] [blame] | 1474 | if (control->last_frag_seen == 0) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1475 | /* Still willing to raise highest FSN seen */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1476 | if (SCTP_TSN_GT(chk->rec.data.fsn, control->top_fsn)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1477 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1478 | "We have a new top_fsn: %u\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1479 | chk->rec.data.fsn); |
| 1480 | control->top_fsn = chk->rec.data.fsn; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1481 | } |
| 1482 | if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { |
| 1483 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1484 | "The last fsn is now in place fsn: %u\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1485 | chk->rec.data.fsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1486 | control->last_frag_seen = 1; |
Michael Tuexen | 4687803 | 2019-08-31 10:22:19 +0200 | [diff] [blame] | 1487 | if (SCTP_TSN_GT(control->top_fsn, chk->rec.data.fsn)) { |
| 1488 | SCTPDBG(SCTP_DEBUG_XXX, |
| 1489 | "New fsn: %u is not at top_fsn: %u -- abort\n", |
| 1490 | chk->rec.data.fsn, |
| 1491 | control->top_fsn); |
| 1492 | sctp_abort_in_reasm(stcb, control, chk, |
| 1493 | abort_flag, |
| 1494 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_9); |
| 1495 | return; |
| 1496 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1497 | } |
| 1498 | if (asoc->idata_supported || control->first_frag_seen) { |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 1499 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1500 | * For IDATA we always check since we know that |
| 1501 | * the first fragment is 0. For old DATA we have |
Michael Tuexen | 34488e7 | 2016-05-03 22:11:59 +0200 | [diff] [blame] | 1502 | * to receive the first before we know the first FSN |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1503 | * (which is the TSN). |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 1504 | */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1505 | if (SCTP_TSN_GE(control->fsn_included, chk->rec.data.fsn)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1506 | /* We have already delivered up to this so its a dup */ |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1507 | sctp_abort_in_reasm(stcb, control, chk, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1508 | abort_flag, |
Michael Tuexen | 4687803 | 2019-08-31 10:22:19 +0200 | [diff] [blame] | 1509 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_10); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1510 | return; |
| 1511 | } |
| 1512 | } |
| 1513 | } else { |
| 1514 | if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { |
| 1515 | /* Second last? huh? */ |
| 1516 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1517 | "Duplicate last fsn: %u (top: %u) -- abort\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1518 | chk->rec.data.fsn, control->top_fsn); |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1519 | sctp_abort_in_reasm(stcb, control, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1520 | chk, abort_flag, |
Michael Tuexen | 4687803 | 2019-08-31 10:22:19 +0200 | [diff] [blame] | 1521 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_11); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1522 | return; |
| 1523 | } |
| 1524 | if (asoc->idata_supported || control->first_frag_seen) { |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 1525 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1526 | * For IDATA we always check since we know that |
| 1527 | * the first fragment is 0. For old DATA we have |
Michael Tuexen | 34488e7 | 2016-05-03 22:11:59 +0200 | [diff] [blame] | 1528 | * to receive the first before we know the first FSN |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1529 | * (which is the TSN). |
| 1530 | */ |
| 1531 | |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1532 | if (SCTP_TSN_GE(control->fsn_included, chk->rec.data.fsn)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1533 | /* We have already delivered up to this so its a dup */ |
| 1534 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1535 | "New fsn: %u is already seen in included_fsn: %u -- abort\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1536 | chk->rec.data.fsn, control->fsn_included); |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1537 | sctp_abort_in_reasm(stcb, control, chk, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1538 | abort_flag, |
Michael Tuexen | 4687803 | 2019-08-31 10:22:19 +0200 | [diff] [blame] | 1539 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_12); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1540 | return; |
| 1541 | } |
| 1542 | } |
| 1543 | /* validate not beyond top FSN if we have seen last one */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1544 | if (SCTP_TSN_GT(chk->rec.data.fsn, control->top_fsn)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1545 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1546 | "New fsn: %u is beyond or at top_fsn: %u -- abort\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1547 | chk->rec.data.fsn, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1548 | control->top_fsn); |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1549 | sctp_abort_in_reasm(stcb, control, chk, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1550 | abort_flag, |
Michael Tuexen | 4687803 | 2019-08-31 10:22:19 +0200 | [diff] [blame] | 1551 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_13); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1552 | return; |
| 1553 | } |
| 1554 | } |
| 1555 | /* |
| 1556 | * If we reach here, we need to place the |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 1557 | * new chunk in the reassembly for this |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1558 | * control. |
| 1559 | */ |
| 1560 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1561 | "chunk is a not first fsn: %u needs to be inserted\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1562 | chk->rec.data.fsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1563 | TAILQ_FOREACH(at, &control->reasm, sctp_next) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1564 | if (SCTP_TSN_GT(at->rec.data.fsn, chk->rec.data.fsn)) { |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 1565 | if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { |
| 1566 | /* Last not at the end? huh? */ |
| 1567 | SCTPDBG(SCTP_DEBUG_XXX, |
| 1568 | "Last fragment not last in list: -- abort\n"); |
| 1569 | sctp_abort_in_reasm(stcb, control, |
| 1570 | chk, abort_flag, |
| 1571 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_14); |
| 1572 | return; |
| 1573 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1574 | /* |
| 1575 | * This one in queue is bigger than the new one, insert |
| 1576 | * the new one before at. |
| 1577 | */ |
| 1578 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1579 | "Insert it before fsn: %u\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1580 | at->rec.data.fsn); |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 1581 | asoc->size_on_reasm_queue += chk->send_size; |
| 1582 | sctp_ucount_incr(asoc->cnt_on_reasm_queue); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1583 | TAILQ_INSERT_BEFORE(at, chk, sctp_next); |
| 1584 | inserted = 1; |
| 1585 | break; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1586 | } else if (at->rec.data.fsn == chk->rec.data.fsn) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1587 | /* Gak, He sent me a duplicate str seq number */ |
| 1588 | /* |
| 1589 | * foo bar, I guess I will just free this new guy, |
| 1590 | * should we abort too? FIX ME MAYBE? Or it COULD be |
| 1591 | * that the SSN's have wrapped. Maybe I should |
| 1592 | * compare to TSN somehow... sigh for now just blow |
| 1593 | * away the chunk! |
| 1594 | */ |
| 1595 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1596 | "Duplicate to fsn: %u -- abort\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1597 | at->rec.data.fsn); |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1598 | sctp_abort_in_reasm(stcb, control, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1599 | chk, abort_flag, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 1600 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_15); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1601 | return; |
| 1602 | } |
| 1603 | } |
| 1604 | if (inserted == 0) { |
| 1605 | /* Goes on the end */ |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1606 | SCTPDBG(SCTP_DEBUG_XXX, "Inserting at tail of list fsn: %u\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1607 | chk->rec.data.fsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1608 | asoc->size_on_reasm_queue += chk->send_size; |
| 1609 | sctp_ucount_incr(asoc->cnt_on_reasm_queue); |
| 1610 | TAILQ_INSERT_TAIL(&control->reasm, chk, sctp_next); |
| 1611 | } |
| 1612 | } |
| 1613 | /* |
| 1614 | * Ok lets see if we can suck any up into the control |
| 1615 | * structure that are in seq if it makes sense. |
| 1616 | */ |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1617 | do_wakeup = 0; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1618 | /* |
| 1619 | * If the first fragment has not been |
| 1620 | * seen there is no sense in looking. |
| 1621 | */ |
| 1622 | if (control->first_frag_seen) { |
| 1623 | next_fsn = control->fsn_included + 1; |
| 1624 | TAILQ_FOREACH_SAFE(at, &control->reasm, sctp_next, nat) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1625 | if (at->rec.data.fsn == next_fsn) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1626 | /* We can add this one now to the control */ |
| 1627 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 1628 | "Adding more to control: %p at: %p fsn: %u next_fsn: %u included: %u\n", |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1629 | control, at, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1630 | at->rec.data.fsn, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1631 | next_fsn, control->fsn_included); |
| 1632 | TAILQ_REMOVE(&control->reasm, at, sctp_next); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1633 | lenadded = sctp_add_chk_to_control(control, strm, stcb, asoc, at, SCTP_READ_LOCK_NOT_HELD); |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1634 | if (control->on_read_q) { |
| 1635 | do_wakeup = 1; |
Michael Tuexen | a7360a1 | 2017-09-17 11:30:34 +0200 | [diff] [blame] | 1636 | } else { |
| 1637 | /* |
| 1638 | * We only add to the size-on-all-streams |
| 1639 | * if its not on the read q. The read q |
| 1640 | * flag will cause a sballoc so its accounted |
| 1641 | * for there. |
| 1642 | */ |
| 1643 | asoc->size_on_all_streams += lenadded; |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1644 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1645 | next_fsn++; |
| 1646 | if (control->end_added && control->pdapi_started) { |
| 1647 | if (strm->pd_api_started) { |
| 1648 | strm->pd_api_started = 0; |
| 1649 | control->pdapi_started = 0; |
| 1650 | } |
| 1651 | if (control->on_read_q == 0) { |
| 1652 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
| 1653 | control, |
| 1654 | &stcb->sctp_socket->so_rcv, control->end_added, |
| 1655 | SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); |
| 1656 | } |
| 1657 | break; |
| 1658 | } |
| 1659 | } else { |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 1660 | break; |
| 1661 | } |
Michael Tuexen | 48ebe5e | 2016-04-10 23:10:14 +0200 | [diff] [blame] | 1662 | } |
| 1663 | } |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1664 | if (do_wakeup) { |
Michael Tuexen | 6539426 | 2016-05-09 08:17:54 +0200 | [diff] [blame] | 1665 | #if defined(__Userspace__) |
| 1666 | sctp_invoke_recv_callback(stcb->sctp_ep, stcb, control, SCTP_READ_LOCK_NOT_HELD); |
| 1667 | #endif |
Michael Tuexen | 98b7455 | 2016-05-09 17:41:56 +0200 | [diff] [blame] | 1668 | /* Need to wakeup the reader */ |
Michael Tuexen | a9d8c47 | 2016-04-18 22:22:59 +0200 | [diff] [blame] | 1669 | sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1670 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1673 | static struct sctp_queued_to_read * |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1674 | sctp_find_reasm_entry(struct sctp_stream_in *strm, uint32_t mid, int ordered, int idata_supported) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1675 | { |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1676 | struct sctp_queued_to_read *control; |
| 1677 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1678 | if (ordered) { |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1679 | TAILQ_FOREACH(control, &strm->inqueue, next_instrm) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1680 | if (SCTP_MID_EQ(idata_supported, control->mid, mid)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1681 | break; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1682 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1683 | } |
| 1684 | } else { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1685 | if (idata_supported) { |
| 1686 | TAILQ_FOREACH(control, &strm->uno_inqueue, next_instrm) { |
| 1687 | if (SCTP_MID_EQ(idata_supported, control->mid, mid)) { |
| 1688 | break; |
| 1689 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1690 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1691 | } else { |
| 1692 | control = TAILQ_FIRST(&strm->uno_inqueue); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1693 | } |
| 1694 | } |
Michael Tuexen | b0298bf | 2016-04-27 21:01:33 +0200 | [diff] [blame] | 1695 | return (control); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1698 | static int |
| 1699 | sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1700 | struct mbuf **m, int offset, int chk_length, |
| 1701 | struct sctp_nets *net, uint32_t *high_tsn, int *abort_flag, |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1702 | int *break_flag, int last_chunk, uint8_t chk_type) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1703 | { |
Michael Tuexen | 022ef44 | 2018-05-21 17:04:54 +0200 | [diff] [blame] | 1704 | struct sctp_tmit_chunk *chk = NULL; /* make gcc happy */ |
Michael Tuexen | ffed092 | 2020-07-10 13:24:15 +0200 | [diff] [blame] | 1705 | struct sctp_stream_in *strm; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1706 | uint32_t tsn, fsn, gap, mid; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1707 | struct mbuf *dmbuf; |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 1708 | int the_len; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1709 | int need_reasm_check = 0; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1710 | uint16_t sid; |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 1711 | struct mbuf *op_err; |
| 1712 | char msg[SCTP_DIAG_INFO_LEN]; |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 1713 | struct sctp_queued_to_read *control, *ncontrol; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1714 | uint32_t ppid; |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1715 | uint8_t chk_flags; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1716 | struct sctp_stream_reset_list *liste; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1717 | int ordered; |
| 1718 | size_t clen; |
| 1719 | int created_control = 0; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1720 | |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1721 | if (chk_type == SCTP_IDATA) { |
| 1722 | struct sctp_idata_chunk *chunk, chunk_buf; |
| 1723 | |
| 1724 | chunk = (struct sctp_idata_chunk *)sctp_m_getptr(*m, offset, |
| 1725 | sizeof(struct sctp_idata_chunk), (uint8_t *)&chunk_buf); |
| 1726 | chk_flags = chunk->ch.chunk_flags; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1727 | clen = sizeof(struct sctp_idata_chunk); |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1728 | tsn = ntohl(chunk->dp.tsn); |
| 1729 | sid = ntohs(chunk->dp.sid); |
| 1730 | mid = ntohl(chunk->dp.mid); |
| 1731 | if (chk_flags & SCTP_DATA_FIRST_FRAG) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1732 | fsn = 0; |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1733 | ppid = chunk->dp.ppid_fsn.ppid; |
| 1734 | } else { |
| 1735 | fsn = ntohl(chunk->dp.ppid_fsn.fsn); |
| 1736 | ppid = 0xffffffff; /* Use as an invalid value. */ |
| 1737 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1738 | } else { |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1739 | struct sctp_data_chunk *chunk, chunk_buf; |
| 1740 | |
| 1741 | chunk = (struct sctp_data_chunk *)sctp_m_getptr(*m, offset, |
| 1742 | sizeof(struct sctp_data_chunk), (uint8_t *)&chunk_buf); |
| 1743 | chk_flags = chunk->ch.chunk_flags; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1744 | clen = sizeof(struct sctp_data_chunk); |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1745 | tsn = ntohl(chunk->dp.tsn); |
| 1746 | sid = ntohs(chunk->dp.sid); |
| 1747 | mid = (uint32_t)(ntohs(chunk->dp.ssn)); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1748 | fsn = tsn; |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1749 | ppid = chunk->dp.ppid; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1750 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1751 | if ((size_t)chk_length == clen) { |
| 1752 | /* |
| 1753 | * Need to send an abort since we had a |
| 1754 | * empty data chunk. |
| 1755 | */ |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1756 | op_err = sctp_generate_no_user_data_cause(tsn); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 1757 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 1758 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1759 | *abort_flag = 1; |
| 1760 | return (0); |
| 1761 | } |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1762 | if ((chk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1763 | asoc->send_sack = 1; |
| 1764 | } |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1765 | ordered = ((chk_flags & SCTP_DATA_UNORDERED) == 0); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1766 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { |
| 1767 | sctp_log_map(tsn, asoc->cumulative_tsn, asoc->highest_tsn_inside_map, SCTP_MAP_TSN_ENTERS); |
| 1768 | } |
| 1769 | if (stcb == NULL) { |
| 1770 | return (0); |
| 1771 | } |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1772 | SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, chk_type, tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1773 | if (SCTP_TSN_GE(asoc->cumulative_tsn, tsn)) { |
| 1774 | /* It is a duplicate */ |
| 1775 | SCTP_STAT_INCR(sctps_recvdupdata); |
| 1776 | if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { |
| 1777 | /* Record a dup for the next outbound sack */ |
| 1778 | asoc->dup_tsns[asoc->numduptsns] = tsn; |
| 1779 | asoc->numduptsns++; |
| 1780 | } |
| 1781 | asoc->send_sack = 1; |
| 1782 | return (0); |
| 1783 | } |
| 1784 | /* Calculate the number of TSN's between the base and this TSN */ |
| 1785 | SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn); |
| 1786 | if (gap >= (SCTP_MAPPING_ARRAY << 3)) { |
| 1787 | /* Can't hold the bit in the mapping at max array, toss it */ |
| 1788 | return (0); |
| 1789 | } |
| 1790 | if (gap >= (uint32_t) (asoc->mapping_array_size << 3)) { |
| 1791 | SCTP_TCB_LOCK_ASSERT(stcb); |
| 1792 | if (sctp_expand_mapping_array(asoc, gap)) { |
| 1793 | /* Can't expand, drop it */ |
| 1794 | return (0); |
| 1795 | } |
| 1796 | } |
| 1797 | if (SCTP_TSN_GT(tsn, *high_tsn)) { |
| 1798 | *high_tsn = tsn; |
| 1799 | } |
| 1800 | /* See if we have received this one already */ |
| 1801 | if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap) || |
| 1802 | SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, gap)) { |
| 1803 | SCTP_STAT_INCR(sctps_recvdupdata); |
| 1804 | if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) { |
| 1805 | /* Record a dup for the next outbound sack */ |
| 1806 | asoc->dup_tsns[asoc->numduptsns] = tsn; |
| 1807 | asoc->numduptsns++; |
| 1808 | } |
| 1809 | asoc->send_sack = 1; |
| 1810 | return (0); |
| 1811 | } |
| 1812 | /* |
| 1813 | * Check to see about the GONE flag, duplicates would cause a sack |
| 1814 | * to be sent up above |
| 1815 | */ |
| 1816 | if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || |
| 1817 | (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 1818 | (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET))) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1819 | /* |
| 1820 | * wait a minute, this guy is gone, there is no longer a |
| 1821 | * receiver. Send peer an ABORT! |
| 1822 | */ |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 1823 | op_err = sctp_generate_cause(SCTP_CAUSE_OUT_OF_RESC, ""); |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 1824 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1825 | *abort_flag = 1; |
| 1826 | return (0); |
| 1827 | } |
| 1828 | /* |
| 1829 | * Now before going further we see if there is room. If NOT then we |
| 1830 | * MAY let one through only IF this TSN is the one we are waiting |
| 1831 | * for on a partial delivery API. |
| 1832 | */ |
| 1833 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1834 | /* Is the stream valid? */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1835 | if (sid >= asoc->streamincnt) { |
Michael Tuexen | f39c429 | 2015-09-12 19:39:48 +0200 | [diff] [blame] | 1836 | struct sctp_error_invalid_stream *cause; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1837 | |
Michael Tuexen | f39c429 | 2015-09-12 19:39:48 +0200 | [diff] [blame] | 1838 | op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_error_invalid_stream), |
| 1839 | 0, M_NOWAIT, 1, MT_DATA); |
| 1840 | if (op_err != NULL) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1841 | /* add some space up front so prepend will work well */ |
Michael Tuexen | f39c429 | 2015-09-12 19:39:48 +0200 | [diff] [blame] | 1842 | SCTP_BUF_RESV_UF(op_err, sizeof(struct sctp_chunkhdr)); |
| 1843 | cause = mtod(op_err, struct sctp_error_invalid_stream *); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1844 | /* |
| 1845 | * Error causes are just param's and this one has |
| 1846 | * two back to back phdr, one with the error type |
| 1847 | * and size, the other with the streamid and a rsvd |
| 1848 | */ |
Michael Tuexen | f39c429 | 2015-09-12 19:39:48 +0200 | [diff] [blame] | 1849 | SCTP_BUF_LEN(op_err) = sizeof(struct sctp_error_invalid_stream); |
| 1850 | cause->cause.code = htons(SCTP_CAUSE_INVALID_STREAM); |
| 1851 | cause->cause.length = htons(sizeof(struct sctp_error_invalid_stream)); |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1852 | cause->stream_id = htons(sid); |
Michael Tuexen | f39c429 | 2015-09-12 19:39:48 +0200 | [diff] [blame] | 1853 | cause->reserved = htons(0); |
| 1854 | sctp_queue_op_err(stcb, op_err); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1855 | } |
| 1856 | SCTP_STAT_INCR(sctps_badsid); |
| 1857 | SCTP_TCB_LOCK_ASSERT(stcb); |
| 1858 | SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); |
| 1859 | if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { |
| 1860 | asoc->highest_tsn_inside_nr_map = tsn; |
| 1861 | } |
| 1862 | if (tsn == (asoc->cumulative_tsn + 1)) { |
| 1863 | /* Update cum-ack */ |
| 1864 | asoc->cumulative_tsn = tsn; |
| 1865 | } |
| 1866 | return (0); |
| 1867 | } |
| 1868 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1869 | * If its a fragmented message, lets see if we can |
| 1870 | * find the control on the reassembly queues. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1871 | */ |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1872 | if ((chk_type == SCTP_IDATA) && |
| 1873 | ((chk_flags & SCTP_DATA_FIRST_FRAG) == 0) && |
Michael Tuexen | 4ce5bad | 2016-08-10 19:24:19 +0200 | [diff] [blame] | 1874 | (fsn == 0)) { |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 1875 | /* |
| 1876 | * The first *must* be fsn 0, and other |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1877 | * (middle/end) pieces can *not* be fsn 0. |
Michael Tuexen | 4ce5bad | 2016-08-10 19:24:19 +0200 | [diff] [blame] | 1878 | * XXX: This can happen in case of a wrap around. |
| 1879 | * Ignore is for now. |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1880 | */ |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 1881 | SCTP_SNPRINTF(msg, sizeof(msg), "FSN zero for MID=%8.8x, but flags=%2.2x", mid, chk_flags); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1882 | goto err_out; |
| 1883 | } |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 1884 | control = sctp_find_reasm_entry(&asoc->strmin[sid], mid, ordered, asoc->idata_supported); |
Michael Tuexen | 4ce5bad | 2016-08-10 19:24:19 +0200 | [diff] [blame] | 1885 | SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags:0x%x look for control on queues %p\n", |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1886 | chk_flags, control); |
| 1887 | if ((chk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1888 | /* See if we can find the re-assembly entity */ |
Michael Tuexen | 4ce5bad | 2016-08-10 19:24:19 +0200 | [diff] [blame] | 1889 | if (control != NULL) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1890 | /* We found something, does it belong? */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1891 | if (ordered && (mid != control->mid)) { |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 1892 | SCTP_SNPRINTF(msg, sizeof(msg), "Reassembly problem (MID=%8.8x)", mid); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1893 | err_out: |
| 1894 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 1895 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_17; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 1896 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1897 | *abort_flag = 1; |
| 1898 | return (0); |
| 1899 | } |
| 1900 | if (ordered && ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED)) { |
| 1901 | /* We can't have a switched order with an unordered chunk */ |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 1902 | SCTP_SNPRINTF(msg, sizeof(msg), |
| 1903 | "All fragments of a user message must be ordered or unordered (TSN=%8.8x)", |
| 1904 | tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1905 | goto err_out; |
| 1906 | } |
| 1907 | if (!ordered && (((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) == 0)) { |
| 1908 | /* We can't have a switched unordered with a ordered chunk */ |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 1909 | SCTP_SNPRINTF(msg, sizeof(msg), |
Michael Tuexen | d98d2c4 | 2020-05-18 14:09:04 +0200 | [diff] [blame] | 1910 | "All fragments of a user message must be ordered or unordered (TSN=%8.8x)", |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 1911 | tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1912 | goto err_out; |
| 1913 | } |
| 1914 | } |
| 1915 | } else { |
| 1916 | /* Its a complete segment. Lets validate we |
| 1917 | * don't have a re-assembly going on with |
| 1918 | * the same Stream/Seq (for ordered) or in |
| 1919 | * the same Stream for unordered. |
| 1920 | */ |
Michael Tuexen | 4ce5bad | 2016-08-10 19:24:19 +0200 | [diff] [blame] | 1921 | if (control != NULL) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 1922 | if (ordered || asoc->idata_supported) { |
| 1923 | SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags: 0x%x dup detected on MID: %u\n", |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1924 | chk_flags, mid); |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 1925 | SCTP_SNPRINTF(msg, sizeof(msg), "Duplicate MID=%8.8x detected.", mid); |
Michael Tuexen | 4ce5bad | 2016-08-10 19:24:19 +0200 | [diff] [blame] | 1926 | goto err_out; |
| 1927 | } else { |
| 1928 | if ((tsn == control->fsn_included + 1) && |
| 1929 | (control->end_added == 0)) { |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 1930 | SCTP_SNPRINTF(msg, sizeof(msg), |
| 1931 | "Illegal message sequence, missing end for MID: %8.8x", |
| 1932 | control->fsn_included); |
Michael Tuexen | 4ce5bad | 2016-08-10 19:24:19 +0200 | [diff] [blame] | 1933 | goto err_out; |
| 1934 | } else { |
| 1935 | control = NULL; |
| 1936 | } |
| 1937 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | /* now do the tests */ |
| 1941 | if (((asoc->cnt_on_all_streams + |
| 1942 | asoc->cnt_on_reasm_queue + |
| 1943 | asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) || |
| 1944 | (((int)asoc->my_rwnd) <= 0)) { |
| 1945 | /* |
| 1946 | * When we have NO room in the rwnd we check to make sure |
| 1947 | * the reader is doing its job... |
| 1948 | */ |
Michael Tuexen | 13a3b53 | 2022-05-15 22:51:57 +0200 | [diff] [blame] | 1949 | if (SCTP_SBAVAIL(&stcb->sctp_socket->so_rcv) > 0) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1950 | /* some to read, wake-up */ |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 1951 | #if defined(__APPLE__) && !defined(__Userspace__) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1952 | struct socket *so; |
| 1953 | |
| 1954 | so = SCTP_INP_SO(stcb->sctp_ep); |
| 1955 | atomic_add_int(&stcb->asoc.refcnt, 1); |
| 1956 | SCTP_TCB_UNLOCK(stcb); |
| 1957 | SCTP_SOCKET_LOCK(so, 1); |
| 1958 | SCTP_TCB_LOCK(stcb); |
| 1959 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
| 1960 | if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { |
| 1961 | /* assoc was freed while we were unlocked */ |
| 1962 | SCTP_SOCKET_UNLOCK(so, 1); |
| 1963 | return (0); |
| 1964 | } |
| 1965 | #endif |
| 1966 | sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket); |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 1967 | #if defined(__APPLE__) && !defined(__Userspace__) |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1968 | SCTP_SOCKET_UNLOCK(so, 1); |
| 1969 | #endif |
| 1970 | } |
| 1971 | /* now is it in the mapping array of what we have accepted? */ |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 1972 | if (chk_type == SCTP_DATA) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 1973 | if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map) && |
| 1974 | SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { |
| 1975 | /* Nope not in the valid range dump it */ |
| 1976 | dump_packet: |
| 1977 | sctp_set_rwnd(stcb, asoc); |
| 1978 | if ((asoc->cnt_on_all_streams + |
| 1979 | asoc->cnt_on_reasm_queue + |
| 1980 | asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) { |
| 1981 | SCTP_STAT_INCR(sctps_datadropchklmt); |
| 1982 | } else { |
| 1983 | SCTP_STAT_INCR(sctps_datadroprwnd); |
| 1984 | } |
| 1985 | *break_flag = 1; |
| 1986 | return (0); |
| 1987 | } |
| 1988 | } else { |
| 1989 | if (control == NULL) { |
| 1990 | goto dump_packet; |
| 1991 | } |
| 1992 | if (SCTP_TSN_GT(fsn, control->top_fsn)) { |
| 1993 | goto dump_packet; |
| 1994 | } |
| 1995 | } |
| 1996 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 1997 | #ifdef SCTP_ASOCLOG_OF_TSNS |
| 1998 | SCTP_TCB_LOCK_ASSERT(stcb); |
| 1999 | if (asoc->tsn_in_at >= SCTP_TSN_LOG_SIZE) { |
| 2000 | asoc->tsn_in_at = 0; |
| 2001 | asoc->tsn_in_wrapped = 1; |
| 2002 | } |
| 2003 | asoc->in_tsnlog[asoc->tsn_in_at].tsn = tsn; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2004 | asoc->in_tsnlog[asoc->tsn_in_at].strm = sid; |
| 2005 | asoc->in_tsnlog[asoc->tsn_in_at].seq = mid; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2006 | asoc->in_tsnlog[asoc->tsn_in_at].sz = chk_length; |
| 2007 | asoc->in_tsnlog[asoc->tsn_in_at].flgs = chunk_flags; |
| 2008 | asoc->in_tsnlog[asoc->tsn_in_at].stcb = (void *)stcb; |
| 2009 | asoc->in_tsnlog[asoc->tsn_in_at].in_pos = asoc->tsn_in_at; |
| 2010 | asoc->in_tsnlog[asoc->tsn_in_at].in_out = 1; |
| 2011 | asoc->tsn_in_at++; |
| 2012 | #endif |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2013 | /* |
| 2014 | * Before we continue lets validate that we are not being fooled by |
| 2015 | * an evil attacker. We can only have Nk chunks based on our TSN |
| 2016 | * spread allowed by the mapping array N * 8 bits, so there is no |
| 2017 | * way our stream sequence numbers could have wrapped. We of course |
| 2018 | * only validate the FIRST fragment so the bit must be set. |
| 2019 | */ |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2020 | if ((chk_flags & SCTP_DATA_FIRST_FRAG) && |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2021 | (TAILQ_EMPTY(&asoc->resetHead)) && |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2022 | (chk_flags & SCTP_DATA_UNORDERED) == 0 && |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2023 | SCTP_MID_GE(asoc->idata_supported, asoc->strmin[sid].last_mid_delivered, mid)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2024 | /* The incoming sseq is behind where we last delivered? */ |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 2025 | SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ: %u delivered: %u from peer, Abort!\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2026 | mid, asoc->strmin[sid].last_mid_delivered); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2027 | |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2028 | if (asoc->idata_supported) { |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 2029 | SCTP_SNPRINTF(msg, sizeof(msg), "Delivered MID=%8.8x, got TSN=%8.8x, SID=%4.4x, MID=%8.8x", |
| 2030 | asoc->strmin[sid].last_mid_delivered, |
| 2031 | tsn, |
| 2032 | sid, |
| 2033 | mid); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2034 | } else { |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 2035 | SCTP_SNPRINTF(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x", |
| 2036 | (uint16_t)asoc->strmin[sid].last_mid_delivered, |
| 2037 | tsn, |
| 2038 | sid, |
| 2039 | (uint16_t)mid); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2040 | } |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 2041 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 2042 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_18; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 2043 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2044 | *abort_flag = 1; |
| 2045 | return (0); |
| 2046 | } |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2047 | if (chk_type == SCTP_IDATA) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2048 | the_len = (chk_length - sizeof(struct sctp_idata_chunk)); |
| 2049 | } else { |
| 2050 | the_len = (chk_length - sizeof(struct sctp_data_chunk)); |
| 2051 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2052 | if (last_chunk == 0) { |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2053 | if (chk_type == SCTP_IDATA) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2054 | dmbuf = SCTP_M_COPYM(*m, |
| 2055 | (offset + sizeof(struct sctp_idata_chunk)), |
| 2056 | the_len, M_NOWAIT); |
| 2057 | } else { |
| 2058 | dmbuf = SCTP_M_COPYM(*m, |
| 2059 | (offset + sizeof(struct sctp_data_chunk)), |
| 2060 | the_len, M_NOWAIT); |
| 2061 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2062 | #ifdef SCTP_MBUF_LOGGING |
| 2063 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
t00fcxen | 8285bce | 2015-01-10 21:09:55 +0000 | [diff] [blame] | 2064 | sctp_log_mbc(dmbuf, SCTP_MBUF_ICOPY); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2065 | } |
| 2066 | #endif |
| 2067 | } else { |
| 2068 | /* We can steal the last chunk */ |
| 2069 | int l_len; |
| 2070 | dmbuf = *m; |
| 2071 | /* lop off the top part */ |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2072 | if (chk_type == SCTP_IDATA) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2073 | m_adj(dmbuf, (offset + sizeof(struct sctp_idata_chunk))); |
| 2074 | } else { |
| 2075 | m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk))); |
| 2076 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2077 | if (SCTP_BUF_NEXT(dmbuf) == NULL) { |
| 2078 | l_len = SCTP_BUF_LEN(dmbuf); |
| 2079 | } else { |
| 2080 | /* need to count up the size hopefully |
| 2081 | * does not hit this to often :-0 |
| 2082 | */ |
| 2083 | struct mbuf *lat; |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2084 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2085 | l_len = 0; |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2086 | for (lat = dmbuf; lat; lat = SCTP_BUF_NEXT(lat)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2087 | l_len += SCTP_BUF_LEN(lat); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | if (l_len > the_len) { |
| 2091 | /* Trim the end round bytes off too */ |
| 2092 | m_adj(dmbuf, -(l_len - the_len)); |
| 2093 | } |
| 2094 | } |
| 2095 | if (dmbuf == NULL) { |
| 2096 | SCTP_STAT_INCR(sctps_nomem); |
| 2097 | return (0); |
| 2098 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2099 | /* |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2100 | * Now no matter what, we need a control, get one |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2101 | * if we don't have one (we may have gotten it |
| 2102 | * above when we found the message was fragmented |
| 2103 | */ |
| 2104 | if (control == NULL) { |
| 2105 | sctp_alloc_a_readq(stcb, control); |
| 2106 | sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2107 | ppid, |
| 2108 | sid, |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2109 | chk_flags, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2110 | NULL, fsn, mid); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2111 | if (control == NULL) { |
| 2112 | SCTP_STAT_INCR(sctps_nomem); |
| 2113 | return (0); |
| 2114 | } |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2115 | if ((chk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { |
Michael Tuexen | 3381e77 | 2017-07-19 17:14:51 +0200 | [diff] [blame] | 2116 | struct mbuf *mm; |
| 2117 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2118 | control->data = dmbuf; |
Michael Tuexen | c38740e | 2019-10-06 10:52:55 +0200 | [diff] [blame] | 2119 | control->tail_mbuf = NULL; |
Michael Tuexen | 3381e77 | 2017-07-19 17:14:51 +0200 | [diff] [blame] | 2120 | for (mm = control->data; mm; mm = mm->m_next) { |
| 2121 | control->length += SCTP_BUF_LEN(mm); |
Michael Tuexen | c38740e | 2019-10-06 10:52:55 +0200 | [diff] [blame] | 2122 | if (SCTP_BUF_NEXT(mm) == NULL) { |
| 2123 | control->tail_mbuf = mm; |
| 2124 | } |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2125 | } |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2126 | control->end_added = 1; |
| 2127 | control->last_frag_seen = 1; |
| 2128 | control->first_frag_seen = 1; |
| 2129 | control->fsn_included = fsn; |
| 2130 | control->top_fsn = fsn; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2131 | } |
| 2132 | created_control = 1; |
| 2133 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2134 | SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags: 0x%x ordered: %d MID: %u control: %p\n", |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2135 | chk_flags, ordered, mid, control); |
| 2136 | if ((chk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG && |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2137 | TAILQ_EMPTY(&asoc->resetHead) && |
| 2138 | ((ordered == 0) || |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2139 | (SCTP_MID_EQ(asoc->idata_supported, asoc->strmin[sid].last_mid_delivered + 1, mid) && |
| 2140 | TAILQ_EMPTY(&asoc->strmin[sid].inqueue)))) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2141 | /* Candidate for express delivery */ |
| 2142 | /* |
| 2143 | * Its not fragmented, No PD-API is up, Nothing in the |
| 2144 | * delivery queue, Its un-ordered OR ordered and the next to |
| 2145 | * deliver AND nothing else is stuck on the stream queue, |
| 2146 | * And there is room for it in the socket buffer. Lets just |
| 2147 | * stuff it up the buffer.... |
| 2148 | */ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2149 | SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); |
| 2150 | if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { |
| 2151 | asoc->highest_tsn_inside_nr_map = tsn; |
| 2152 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2153 | SCTPDBG(SCTP_DEBUG_XXX, "Injecting control: %p to be read (MID: %u)\n", |
| 2154 | control, mid); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2155 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2156 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
| 2157 | control, &stcb->sctp_socket->so_rcv, |
| 2158 | 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); |
| 2159 | |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2160 | if ((chk_flags & SCTP_DATA_UNORDERED) == 0) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2161 | /* for ordered, bump what we delivered */ |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 2162 | asoc->strmin[sid].last_mid_delivered++; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2163 | } |
| 2164 | SCTP_STAT_INCR(sctps_recvexpress); |
| 2165 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2166 | sctp_log_strm_del_alt(stcb, tsn, mid, sid, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2167 | SCTP_STR_LOG_FROM_EXPRS_DEL); |
| 2168 | } |
| 2169 | control = NULL; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2170 | goto finish_express_del; |
| 2171 | } |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2172 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2173 | /* Now will we need a chunk too? */ |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2174 | if ((chk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2175 | sctp_alloc_a_chunk(stcb, chk); |
| 2176 | if (chk == NULL) { |
| 2177 | /* No memory so we drop the chunk */ |
| 2178 | SCTP_STAT_INCR(sctps_nomem); |
| 2179 | if (last_chunk == 0) { |
| 2180 | /* we copied it, free the copy */ |
| 2181 | sctp_m_freem(dmbuf); |
| 2182 | } |
| 2183 | return (0); |
| 2184 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2185 | chk->rec.data.tsn = tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2186 | chk->no_fr_allowed = 0; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2187 | chk->rec.data.fsn = fsn; |
| 2188 | chk->rec.data.mid = mid; |
| 2189 | chk->rec.data.sid = sid; |
| 2190 | chk->rec.data.ppid = ppid; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2191 | chk->rec.data.context = stcb->asoc.context; |
| 2192 | chk->rec.data.doing_fast_retransmit = 0; |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2193 | chk->rec.data.rcv_flags = chk_flags; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2194 | chk->asoc = asoc; |
| 2195 | chk->send_size = the_len; |
| 2196 | chk->whoTo = net; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2197 | SCTPDBG(SCTP_DEBUG_XXX, "Building ck: %p for control: %p to be read (MID: %u)\n", |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2198 | chk, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2199 | control, mid); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2200 | atomic_add_int(&net->ref_count, 1); |
| 2201 | chk->data = dmbuf; |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 2202 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2203 | /* Set the appropriate TSN mark */ |
| 2204 | if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) { |
| 2205 | SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap); |
| 2206 | if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { |
| 2207 | asoc->highest_tsn_inside_nr_map = tsn; |
| 2208 | } |
| 2209 | } else { |
| 2210 | SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap); |
| 2211 | if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map)) { |
| 2212 | asoc->highest_tsn_inside_map = tsn; |
| 2213 | } |
| 2214 | } |
| 2215 | /* Now is it complete (i.e. not fragmented)? */ |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2216 | if ((chk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2217 | /* |
| 2218 | * Special check for when streams are resetting. We |
| 2219 | * could be more smart about this and check the |
| 2220 | * actual stream to see if it is not being reset.. |
| 2221 | * that way we would not create a HOLB when amongst |
| 2222 | * streams being reset and those not being reset. |
| 2223 | * |
| 2224 | */ |
| 2225 | if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && |
| 2226 | SCTP_TSN_GT(tsn, liste->tsn)) { |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 2227 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2228 | * yep its past where we need to reset... go |
| 2229 | * ahead and queue it. |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 2230 | */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2231 | if (TAILQ_EMPTY(&asoc->pending_reply_queue)) { |
| 2232 | /* first one on */ |
| 2233 | TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); |
| 2234 | } else { |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2235 | struct sctp_queued_to_read *lcontrol, *nlcontrol; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2236 | unsigned char inserted = 0; |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2237 | TAILQ_FOREACH_SAFE(lcontrol, &asoc->pending_reply_queue, next, nlcontrol) { |
| 2238 | if (SCTP_TSN_GT(control->sinfo_tsn, lcontrol->sinfo_tsn)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2239 | continue; |
| 2240 | } else { |
| 2241 | /* found it */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2242 | TAILQ_INSERT_BEFORE(lcontrol, control, next); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2243 | inserted = 1; |
| 2244 | break; |
| 2245 | } |
Michael Tuexen | 3121b80 | 2016-04-10 23:28:19 +0200 | [diff] [blame] | 2246 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2247 | if (inserted == 0) { |
| 2248 | /* |
| 2249 | * must be put at end, use |
| 2250 | * prevP (all setup from |
| 2251 | * loop) to setup nextP. |
| 2252 | */ |
| 2253 | TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next); |
| 2254 | } |
| 2255 | } |
| 2256 | goto finish_express_del; |
| 2257 | } |
Michael Tuexen | dbfc1b8 | 2016-12-11 14:57:19 +0100 | [diff] [blame] | 2258 | if (chk_flags & SCTP_DATA_UNORDERED) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2259 | /* queue directly into socket buffer */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2260 | SCTPDBG(SCTP_DEBUG_XXX, "Unordered data to be read control: %p MID: %u\n", |
| 2261 | control, mid); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2262 | sctp_mark_non_revokable(asoc, control->sinfo_tsn); |
| 2263 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
| 2264 | control, |
| 2265 | &stcb->sctp_socket->so_rcv, 1, |
| 2266 | SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); |
| 2267 | |
| 2268 | } else { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2269 | SCTPDBG(SCTP_DEBUG_XXX, "Queue control: %p for reordering MID: %u\n", control, |
| 2270 | mid); |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 2271 | sctp_queue_data_to_stream(stcb, asoc, control, abort_flag, &need_reasm_check); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2272 | if (*abort_flag) { |
t00fcxen | 2ed8f3d | 2014-04-23 21:28:37 +0000 | [diff] [blame] | 2273 | if (last_chunk) { |
| 2274 | *m = NULL; |
| 2275 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2276 | return (0); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2277 | } |
| 2278 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2279 | goto finish_express_del; |
| 2280 | } |
| 2281 | /* If we reach here its a reassembly */ |
| 2282 | need_reasm_check = 1; |
| 2283 | SCTPDBG(SCTP_DEBUG_XXX, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2284 | "Queue data to stream for reasm control: %p MID: %u\n", |
| 2285 | control, mid); |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 2286 | sctp_queue_data_for_reasm(stcb, asoc, control, chk, created_control, abort_flag, tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2287 | if (*abort_flag) { |
| 2288 | /* |
| 2289 | * the assoc is now gone and chk was put onto the |
| 2290 | * reasm queue, which has all been freed. |
| 2291 | */ |
| 2292 | if (last_chunk) { |
| 2293 | *m = NULL; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2294 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2295 | return (0); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2296 | } |
| 2297 | finish_express_del: |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2298 | /* Here we tidy up things */ |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 2299 | if (tsn == (asoc->cumulative_tsn + 1)) { |
| 2300 | /* Update cum-ack */ |
| 2301 | asoc->cumulative_tsn = tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2302 | } |
| 2303 | if (last_chunk) { |
| 2304 | *m = NULL; |
| 2305 | } |
| 2306 | if (ordered) { |
| 2307 | SCTP_STAT_INCR_COUNTER64(sctps_inorderchunks); |
| 2308 | } else { |
| 2309 | SCTP_STAT_INCR_COUNTER64(sctps_inunorderchunks); |
| 2310 | } |
| 2311 | SCTP_STAT_INCR(sctps_recvdata); |
| 2312 | /* Set it present please */ |
| 2313 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2314 | sctp_log_strm_del_alt(stcb, tsn, mid, sid, SCTP_STR_LOG_FROM_MARK_TSN); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2315 | } |
| 2316 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { |
| 2317 | sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, |
| 2318 | asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE); |
| 2319 | } |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 2320 | if (need_reasm_check) { |
| 2321 | (void)sctp_deliver_reasm_check(stcb, asoc, &asoc->strmin[sid], SCTP_READ_LOCK_NOT_HELD); |
| 2322 | need_reasm_check = 0; |
| 2323 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2324 | /* check the special flag for stream resets */ |
| 2325 | if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && |
| 2326 | SCTP_TSN_GE(asoc->cumulative_tsn, liste->tsn)) { |
| 2327 | /* |
| 2328 | * we have finished working through the backlogged TSN's now |
| 2329 | * time to reset streams. 1: call reset function. 2: free |
| 2330 | * pending_reply space 3: distribute any chunks in |
| 2331 | * pending_reply_queue. |
| 2332 | */ |
t00fcxen | 0f0d87f | 2012-09-07 13:42:20 +0000 | [diff] [blame] | 2333 | sctp_reset_in_stream(stcb, liste->number_entries, liste->list_of_streams); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2334 | TAILQ_REMOVE(&asoc->resetHead, liste, next_resp); |
Michael Tüxen | 6b4d292 | 2015-07-22 13:55:48 +0200 | [diff] [blame] | 2335 | sctp_send_deferred_reset_response(stcb, liste, SCTP_STREAM_RESET_RESULT_PERFORMED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2336 | SCTP_FREE(liste, SCTP_M_STRESET); |
| 2337 | /*sa_ignore FREED_MEMORY*/ |
| 2338 | liste = TAILQ_FIRST(&asoc->resetHead); |
| 2339 | if (TAILQ_EMPTY(&asoc->resetHead)) { |
| 2340 | /* All can be removed */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2341 | TAILQ_FOREACH_SAFE(control, &asoc->pending_reply_queue, next, ncontrol) { |
| 2342 | TAILQ_REMOVE(&asoc->pending_reply_queue, control, next); |
Michael Tuexen | ffed092 | 2020-07-10 13:24:15 +0200 | [diff] [blame] | 2343 | strm = &asoc->strmin[control->sinfo_stream]; |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2344 | sctp_queue_data_to_stream(stcb, asoc, control, abort_flag, &need_reasm_check); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2345 | if (*abort_flag) { |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2346 | return (0); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2347 | } |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 2348 | if (need_reasm_check) { |
Michael Tuexen | ffed092 | 2020-07-10 13:24:15 +0200 | [diff] [blame] | 2349 | (void)sctp_deliver_reasm_check(stcb, asoc, strm, SCTP_READ_LOCK_NOT_HELD); |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 2350 | need_reasm_check = 0; |
| 2351 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2352 | } |
| 2353 | } else { |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2354 | TAILQ_FOREACH_SAFE(control, &asoc->pending_reply_queue, next, ncontrol) { |
| 2355 | if (SCTP_TSN_GT(control->sinfo_tsn, liste->tsn)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2356 | break; |
| 2357 | } |
| 2358 | /* |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2359 | * if control->sinfo_tsn is <= liste->tsn we can |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2360 | * process it which is the NOT of |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2361 | * control->sinfo_tsn > liste->tsn |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2362 | */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2363 | TAILQ_REMOVE(&asoc->pending_reply_queue, control, next); |
Michael Tuexen | ffed092 | 2020-07-10 13:24:15 +0200 | [diff] [blame] | 2364 | strm = &asoc->strmin[control->sinfo_stream]; |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 2365 | sctp_queue_data_to_stream(stcb, asoc, control, abort_flag, &need_reasm_check); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2366 | if (*abort_flag) { |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2367 | return (0); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2368 | } |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 2369 | if (need_reasm_check) { |
Michael Tuexen | ffed092 | 2020-07-10 13:24:15 +0200 | [diff] [blame] | 2370 | (void)sctp_deliver_reasm_check(stcb, asoc, strm, SCTP_READ_LOCK_NOT_HELD); |
Michael Tuexen | e411f66 | 2016-12-17 23:36:21 +0100 | [diff] [blame] | 2371 | need_reasm_check = 0; |
| 2372 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2373 | } |
| 2374 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2375 | } |
| 2376 | return (1); |
| 2377 | } |
| 2378 | |
Michael Tuexen | 8105522 | 2016-03-23 14:40:10 +0100 | [diff] [blame] | 2379 | static const int8_t sctp_map_lookup_tab[256] = { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2380 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2381 | 0, 1, 0, 2, 0, 1, 0, 4, |
| 2382 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2383 | 0, 1, 0, 2, 0, 1, 0, 5, |
| 2384 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2385 | 0, 1, 0, 2, 0, 1, 0, 4, |
| 2386 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2387 | 0, 1, 0, 2, 0, 1, 0, 6, |
| 2388 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2389 | 0, 1, 0, 2, 0, 1, 0, 4, |
| 2390 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2391 | 0, 1, 0, 2, 0, 1, 0, 5, |
| 2392 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2393 | 0, 1, 0, 2, 0, 1, 0, 4, |
| 2394 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2395 | 0, 1, 0, 2, 0, 1, 0, 7, |
| 2396 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2397 | 0, 1, 0, 2, 0, 1, 0, 4, |
| 2398 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2399 | 0, 1, 0, 2, 0, 1, 0, 5, |
| 2400 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2401 | 0, 1, 0, 2, 0, 1, 0, 4, |
| 2402 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2403 | 0, 1, 0, 2, 0, 1, 0, 6, |
| 2404 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2405 | 0, 1, 0, 2, 0, 1, 0, 4, |
| 2406 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2407 | 0, 1, 0, 2, 0, 1, 0, 5, |
| 2408 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2409 | 0, 1, 0, 2, 0, 1, 0, 4, |
| 2410 | 0, 1, 0, 2, 0, 1, 0, 3, |
| 2411 | 0, 1, 0, 2, 0, 1, 0, 8 |
| 2412 | }; |
| 2413 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2414 | void |
| 2415 | sctp_slide_mapping_arrays(struct sctp_tcb *stcb) |
| 2416 | { |
| 2417 | /* |
| 2418 | * Now we also need to check the mapping array in a couple of ways. |
| 2419 | * 1) Did we move the cum-ack point? |
| 2420 | * |
| 2421 | * When you first glance at this you might think |
Michael Tuexen | 34488e7 | 2016-05-03 22:11:59 +0200 | [diff] [blame] | 2422 | * that all entries that make up the position |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2423 | * of the cum-ack would be in the nr-mapping array |
| 2424 | * only.. i.e. things up to the cum-ack are always |
| 2425 | * deliverable. Thats true with one exception, when |
| 2426 | * its a fragmented message we may not deliver the data |
| 2427 | * until some threshold (or all of it) is in place. So |
| 2428 | * we must OR the nr_mapping_array and mapping_array to |
| 2429 | * get a true picture of the cum-ack. |
| 2430 | */ |
| 2431 | struct sctp_association *asoc; |
| 2432 | int at; |
| 2433 | uint8_t val; |
| 2434 | int slide_from, slide_end, lgap, distance; |
| 2435 | uint32_t old_cumack, old_base, old_highest, highest_tsn; |
| 2436 | |
| 2437 | asoc = &stcb->asoc; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2438 | |
| 2439 | old_cumack = asoc->cumulative_tsn; |
| 2440 | old_base = asoc->mapping_array_base_tsn; |
| 2441 | old_highest = asoc->highest_tsn_inside_map; |
| 2442 | /* |
| 2443 | * We could probably improve this a small bit by calculating the |
| 2444 | * offset of the current cum-ack as the starting point. |
| 2445 | */ |
| 2446 | at = 0; |
| 2447 | for (slide_from = 0; slide_from < stcb->asoc.mapping_array_size; slide_from++) { |
| 2448 | val = asoc->nr_mapping_array[slide_from] | asoc->mapping_array[slide_from]; |
| 2449 | if (val == 0xff) { |
| 2450 | at += 8; |
| 2451 | } else { |
| 2452 | /* there is a 0 bit */ |
| 2453 | at += sctp_map_lookup_tab[val]; |
| 2454 | break; |
| 2455 | } |
| 2456 | } |
| 2457 | asoc->cumulative_tsn = asoc->mapping_array_base_tsn + (at-1); |
| 2458 | |
| 2459 | if (SCTP_TSN_GT(asoc->cumulative_tsn, asoc->highest_tsn_inside_map) && |
| 2460 | SCTP_TSN_GT(asoc->cumulative_tsn, asoc->highest_tsn_inside_nr_map)) { |
| 2461 | #ifdef INVARIANTS |
| 2462 | panic("huh, cumack 0x%x greater than high-tsn 0x%x in map", |
| 2463 | asoc->cumulative_tsn, asoc->highest_tsn_inside_map); |
| 2464 | #else |
| 2465 | SCTP_PRINTF("huh, cumack 0x%x greater than high-tsn 0x%x in map - should panic?\n", |
| 2466 | asoc->cumulative_tsn, asoc->highest_tsn_inside_map); |
| 2467 | sctp_print_mapping_array(asoc); |
| 2468 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { |
| 2469 | sctp_log_map(0, 6, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); |
| 2470 | } |
| 2471 | asoc->highest_tsn_inside_map = asoc->cumulative_tsn; |
| 2472 | asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn; |
| 2473 | #endif |
| 2474 | } |
| 2475 | if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { |
| 2476 | highest_tsn = asoc->highest_tsn_inside_nr_map; |
| 2477 | } else { |
| 2478 | highest_tsn = asoc->highest_tsn_inside_map; |
| 2479 | } |
| 2480 | if ((asoc->cumulative_tsn == highest_tsn) && (at >= 8)) { |
| 2481 | /* The complete array was completed by a single FR */ |
| 2482 | /* highest becomes the cum-ack */ |
| 2483 | int clr; |
| 2484 | #ifdef INVARIANTS |
| 2485 | unsigned int i; |
| 2486 | #endif |
| 2487 | |
| 2488 | /* clear the array */ |
| 2489 | clr = ((at+7) >> 3); |
| 2490 | if (clr > asoc->mapping_array_size) { |
| 2491 | clr = asoc->mapping_array_size; |
| 2492 | } |
| 2493 | memset(asoc->mapping_array, 0, clr); |
| 2494 | memset(asoc->nr_mapping_array, 0, clr); |
| 2495 | #ifdef INVARIANTS |
| 2496 | for (i = 0; i < asoc->mapping_array_size; i++) { |
| 2497 | if ((asoc->mapping_array[i]) || (asoc->nr_mapping_array[i])) { |
tuexen | cb5fe8d | 2012-05-04 09:50:27 +0000 | [diff] [blame] | 2498 | SCTP_PRINTF("Error Mapping array's not clean at clear\n"); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2499 | sctp_print_mapping_array(asoc); |
| 2500 | } |
| 2501 | } |
| 2502 | #endif |
| 2503 | asoc->mapping_array_base_tsn = asoc->cumulative_tsn + 1; |
| 2504 | asoc->highest_tsn_inside_nr_map = asoc->highest_tsn_inside_map = asoc->cumulative_tsn; |
| 2505 | } else if (at >= 8) { |
| 2506 | /* we can slide the mapping array down */ |
| 2507 | /* slide_from holds where we hit the first NON 0xff byte */ |
| 2508 | |
| 2509 | /* |
| 2510 | * now calculate the ceiling of the move using our highest |
| 2511 | * TSN value |
| 2512 | */ |
| 2513 | SCTP_CALC_TSN_TO_GAP(lgap, highest_tsn, asoc->mapping_array_base_tsn); |
| 2514 | slide_end = (lgap >> 3); |
| 2515 | if (slide_end < slide_from) { |
| 2516 | sctp_print_mapping_array(asoc); |
| 2517 | #ifdef INVARIANTS |
| 2518 | panic("impossible slide"); |
| 2519 | #else |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 2520 | SCTP_PRINTF("impossible slide lgap: %x slide_end: %x slide_from: %x? at: %d\n", |
tuexen | cb5fe8d | 2012-05-04 09:50:27 +0000 | [diff] [blame] | 2521 | lgap, slide_end, slide_from, at); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2522 | return; |
| 2523 | #endif |
| 2524 | } |
| 2525 | if (slide_end > asoc->mapping_array_size) { |
| 2526 | #ifdef INVARIANTS |
| 2527 | panic("would overrun buffer"); |
| 2528 | #else |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 2529 | SCTP_PRINTF("Gak, would have overrun map end: %d slide_end: %d\n", |
tuexen | cb5fe8d | 2012-05-04 09:50:27 +0000 | [diff] [blame] | 2530 | asoc->mapping_array_size, slide_end); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2531 | slide_end = asoc->mapping_array_size; |
| 2532 | #endif |
| 2533 | } |
| 2534 | distance = (slide_end - slide_from) + 1; |
| 2535 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { |
| 2536 | sctp_log_map(old_base, old_cumack, old_highest, |
| 2537 | SCTP_MAP_PREPARE_SLIDE); |
| 2538 | sctp_log_map((uint32_t) slide_from, (uint32_t) slide_end, |
| 2539 | (uint32_t) lgap, SCTP_MAP_SLIDE_FROM); |
| 2540 | } |
| 2541 | if (distance + slide_from > asoc->mapping_array_size || |
| 2542 | distance < 0) { |
| 2543 | /* |
| 2544 | * Here we do NOT slide forward the array so that |
| 2545 | * hopefully when more data comes in to fill it up |
| 2546 | * we will be able to slide it forward. Really I |
| 2547 | * don't think this should happen :-0 |
| 2548 | */ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2549 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { |
| 2550 | sctp_log_map((uint32_t) distance, (uint32_t) slide_from, |
| 2551 | (uint32_t) asoc->mapping_array_size, |
| 2552 | SCTP_MAP_SLIDE_NONE); |
| 2553 | } |
| 2554 | } else { |
| 2555 | int ii; |
| 2556 | |
| 2557 | for (ii = 0; ii < distance; ii++) { |
| 2558 | asoc->mapping_array[ii] = asoc->mapping_array[slide_from + ii]; |
| 2559 | asoc->nr_mapping_array[ii] = asoc->nr_mapping_array[slide_from + ii]; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2560 | } |
| 2561 | for (ii = distance; ii < asoc->mapping_array_size; ii++) { |
| 2562 | asoc->mapping_array[ii] = 0; |
| 2563 | asoc->nr_mapping_array[ii] = 0; |
| 2564 | } |
| 2565 | if (asoc->highest_tsn_inside_map + 1 == asoc->mapping_array_base_tsn) { |
| 2566 | asoc->highest_tsn_inside_map += (slide_from << 3); |
| 2567 | } |
| 2568 | if (asoc->highest_tsn_inside_nr_map + 1 == asoc->mapping_array_base_tsn) { |
| 2569 | asoc->highest_tsn_inside_nr_map += (slide_from << 3); |
| 2570 | } |
| 2571 | asoc->mapping_array_base_tsn += (slide_from << 3); |
| 2572 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { |
| 2573 | sctp_log_map(asoc->mapping_array_base_tsn, |
| 2574 | asoc->cumulative_tsn, asoc->highest_tsn_inside_map, |
| 2575 | SCTP_MAP_SLIDE_RESULT); |
| 2576 | } |
| 2577 | } |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | void |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 2582 | sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2583 | { |
| 2584 | struct sctp_association *asoc; |
| 2585 | uint32_t highest_tsn; |
Michael Tuexen | 753e445 | 2016-12-09 19:20:11 +0100 | [diff] [blame] | 2586 | int is_a_gap; |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 2587 | |
Michael Tuexen | 753e445 | 2016-12-09 19:20:11 +0100 | [diff] [blame] | 2588 | sctp_slide_mapping_arrays(stcb); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2589 | asoc = &stcb->asoc; |
| 2590 | if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { |
| 2591 | highest_tsn = asoc->highest_tsn_inside_nr_map; |
| 2592 | } else { |
| 2593 | highest_tsn = asoc->highest_tsn_inside_map; |
| 2594 | } |
Michael Tuexen | 753e445 | 2016-12-09 19:20:11 +0100 | [diff] [blame] | 2595 | /* Is there a gap now? */ |
| 2596 | is_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2597 | |
| 2598 | /* |
| 2599 | * Now we need to see if we need to queue a sack or just start the |
| 2600 | * timer (if allowed). |
| 2601 | */ |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 2602 | if (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_SENT) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2603 | /* |
| 2604 | * Ok special case, in SHUTDOWN-SENT case. here we |
| 2605 | * maker sure SACK timer is off and instead send a |
| 2606 | * SHUTDOWN and a SACK |
| 2607 | */ |
| 2608 | if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { |
| 2609 | sctp_timer_stop(SCTP_TIMER_TYPE_RECV, |
t00fcxen | 0057a6d | 2015-05-28 16:42:49 +0000 | [diff] [blame] | 2610 | stcb->sctp_ep, stcb, NULL, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 2611 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_19); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2612 | } |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 2613 | sctp_send_shutdown(stcb, |
Michael Tuexen | 753e445 | 2016-12-09 19:20:11 +0100 | [diff] [blame] | 2614 | ((stcb->asoc.alternate) ? stcb->asoc.alternate : stcb->asoc.primary_destination)); |
| 2615 | if (is_a_gap) { |
| 2616 | sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED); |
| 2617 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2618 | } else { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2619 | /* |
| 2620 | * CMT DAC algorithm: increase number of packets |
| 2621 | * received since last ack |
| 2622 | */ |
| 2623 | stcb->asoc.cmt_dac_pkts_rcvd++; |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 2624 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2625 | if ((stcb->asoc.send_sack == 1) || /* We need to send a SACK */ |
| 2626 | ((was_a_gap) && (is_a_gap == 0)) || /* was a gap, but no |
| 2627 | * longer is one */ |
| 2628 | (stcb->asoc.numduptsns) || /* we have dup's */ |
| 2629 | (is_a_gap) || /* is still a gap */ |
| 2630 | (stcb->asoc.delayed_ack == 0) || /* Delayed sack disabled */ |
Michael Tuexen | f7f9cd8 | 2020-09-24 15:14:13 +0200 | [diff] [blame] | 2631 | (stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq)) { /* hit limit of pkts */ |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2632 | if ((stcb->asoc.sctp_cmt_on_off > 0) && |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2633 | (SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) && |
| 2634 | (stcb->asoc.send_sack == 0) && |
| 2635 | (stcb->asoc.numduptsns == 0) && |
| 2636 | (stcb->asoc.delayed_ack) && |
| 2637 | (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer))) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2638 | /* |
| 2639 | * CMT DAC algorithm: With CMT, |
| 2640 | * delay acks even in the face of |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2641 | * reordering. Therefore, if acks |
| 2642 | * that do not have to be sent |
| 2643 | * because of the above reasons, |
| 2644 | * will be delayed. That is, acks |
| 2645 | * that would have been sent due to |
| 2646 | * gap reports will be delayed with |
| 2647 | * DAC. Start the delayed ack timer. |
| 2648 | */ |
| 2649 | sctp_timer_start(SCTP_TIMER_TYPE_RECV, |
| 2650 | stcb->sctp_ep, stcb, NULL); |
| 2651 | } else { |
| 2652 | /* |
| 2653 | * Ok we must build a SACK since the |
| 2654 | * timer is pending, we got our |
| 2655 | * first packet OR there are gaps or |
| 2656 | * duplicates. |
| 2657 | */ |
Michael Tuexen | 61f6683 | 2020-02-09 23:15:19 +0100 | [diff] [blame] | 2658 | sctp_timer_stop(SCTP_TIMER_TYPE_RECV, stcb->sctp_ep, stcb, NULL, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 2659 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_20); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2660 | sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED); |
| 2661 | } |
| 2662 | } else { |
| 2663 | if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { |
| 2664 | sctp_timer_start(SCTP_TIMER_TYPE_RECV, |
| 2665 | stcb->sctp_ep, stcb, NULL); |
| 2666 | } |
| 2667 | } |
| 2668 | } |
| 2669 | } |
| 2670 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2671 | int |
| 2672 | sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, |
Michael Tüxen | 9843e06 | 2015-08-02 18:10:36 +0200 | [diff] [blame] | 2673 | struct sctp_inpcb *inp, struct sctp_tcb *stcb, |
| 2674 | struct sctp_nets *net, uint32_t *high_tsn) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2675 | { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2676 | struct sctp_chunkhdr *ch, chunk_buf; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2677 | struct sctp_association *asoc; |
| 2678 | int num_chunks = 0; /* number of control chunks processed */ |
| 2679 | int stop_proc = 0; |
Michael Tuexen | 48b9802 | 2017-10-18 23:12:24 +0200 | [diff] [blame] | 2680 | int break_flag, last_chunk; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2681 | int abort_flag = 0, was_a_gap; |
| 2682 | struct mbuf *m; |
| 2683 | uint32_t highest_tsn; |
Michael Tuexen | 48b9802 | 2017-10-18 23:12:24 +0200 | [diff] [blame] | 2684 | uint16_t chk_length; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2685 | |
| 2686 | /* set the rwnd */ |
| 2687 | sctp_set_rwnd(stcb, &stcb->asoc); |
| 2688 | |
| 2689 | m = *mm; |
| 2690 | SCTP_TCB_LOCK_ASSERT(stcb); |
| 2691 | asoc = &stcb->asoc; |
| 2692 | if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { |
| 2693 | highest_tsn = asoc->highest_tsn_inside_nr_map; |
| 2694 | } else { |
| 2695 | highest_tsn = asoc->highest_tsn_inside_map; |
| 2696 | } |
| 2697 | was_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn); |
| 2698 | /* |
| 2699 | * setup where we got the last DATA packet from for any SACK that |
| 2700 | * may need to go out. Don't bump the net. This is done ONLY when a |
| 2701 | * chunk is assigned. |
| 2702 | */ |
| 2703 | asoc->last_data_chunk_from = net; |
| 2704 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2705 | /*- |
| 2706 | * Now before we proceed we must figure out if this is a wasted |
| 2707 | * cluster... i.e. it is a small packet sent in and yet the driver |
| 2708 | * underneath allocated a full cluster for it. If so we must copy it |
| 2709 | * to a smaller mbuf and free up the cluster mbuf. This will help |
Michael Tuexen | 3b4263d | 2020-06-06 19:52:50 +0200 | [diff] [blame] | 2710 | * with cluster starvation. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2711 | */ |
| 2712 | if (SCTP_BUF_LEN(m) < (long)MLEN && SCTP_BUF_NEXT(m) == NULL) { |
| 2713 | /* we only handle mbufs that are singletons.. not chains */ |
t00fcxen | 23c2b8f | 2012-12-10 20:15:50 +0000 | [diff] [blame] | 2714 | m = sctp_get_mbuf_for_msg(SCTP_BUF_LEN(m), 0, M_NOWAIT, 1, MT_DATA); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2715 | if (m) { |
| 2716 | /* ok lets see if we can copy the data up */ |
| 2717 | caddr_t *from, *to; |
| 2718 | /* get the pointers and copy */ |
| 2719 | to = mtod(m, caddr_t *); |
| 2720 | from = mtod((*mm), caddr_t *); |
| 2721 | memcpy(to, from, SCTP_BUF_LEN((*mm))); |
| 2722 | /* copy the length and free up the old */ |
| 2723 | SCTP_BUF_LEN(m) = SCTP_BUF_LEN((*mm)); |
| 2724 | sctp_m_freem(*mm); |
Michael Tuexen | 34488e7 | 2016-05-03 22:11:59 +0200 | [diff] [blame] | 2725 | /* success, back copy */ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2726 | *mm = m; |
| 2727 | } else { |
| 2728 | /* We are in trouble in the mbuf world .. yikes */ |
| 2729 | m = *mm; |
| 2730 | } |
| 2731 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2732 | /* get pointer to the first chunk header */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2733 | ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset, |
Michael Tuexen | 97aebbe | 2017-10-18 22:22:05 +0200 | [diff] [blame] | 2734 | sizeof(struct sctp_chunkhdr), |
| 2735 | (uint8_t *)&chunk_buf); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2736 | if (ch == NULL) { |
| 2737 | return (1); |
| 2738 | } |
| 2739 | /* |
| 2740 | * process all DATA chunks... |
| 2741 | */ |
| 2742 | *high_tsn = asoc->cumulative_tsn; |
| 2743 | break_flag = 0; |
| 2744 | asoc->data_pkts_seen++; |
| 2745 | while (stop_proc == 0) { |
| 2746 | /* validate chunk length */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2747 | chk_length = ntohs(ch->chunk_length); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2748 | if (length - *offset < chk_length) { |
| 2749 | /* all done, mutulated chunk */ |
| 2750 | stop_proc = 1; |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2751 | continue; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2752 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2753 | if ((asoc->idata_supported == 1) && |
| 2754 | (ch->chunk_type == SCTP_DATA)) { |
| 2755 | struct mbuf *op_err; |
| 2756 | char msg[SCTP_DIAG_INFO_LEN]; |
| 2757 | |
Michael Tuexen | 50db0d7 | 2020-07-08 18:11:47 +0200 | [diff] [blame] | 2758 | SCTP_SNPRINTF(msg, sizeof(msg), "%s", "DATA chunk received when I-DATA was negotiated"); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2759 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 2760 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_21; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 2761 | sctp_abort_an_association(inp, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2762 | return (2); |
| 2763 | } |
| 2764 | if ((asoc->idata_supported == 0) && |
| 2765 | (ch->chunk_type == SCTP_IDATA)) { |
| 2766 | struct mbuf *op_err; |
| 2767 | char msg[SCTP_DIAG_INFO_LEN]; |
| 2768 | |
Michael Tuexen | 50db0d7 | 2020-07-08 18:11:47 +0200 | [diff] [blame] | 2769 | SCTP_SNPRINTF(msg, sizeof(msg), "%s", "I-DATA chunk received when DATA was negotiated"); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2770 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 2771 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_22; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 2772 | sctp_abort_an_association(inp, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2773 | return (2); |
| 2774 | } |
| 2775 | if ((ch->chunk_type == SCTP_DATA) || |
| 2776 | (ch->chunk_type == SCTP_IDATA)) { |
Michael Tuexen | 48b9802 | 2017-10-18 23:12:24 +0200 | [diff] [blame] | 2777 | uint16_t clen; |
Michael Tuexen | 66c8493 | 2016-04-18 11:42:41 +0200 | [diff] [blame] | 2778 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2779 | if (ch->chunk_type == SCTP_DATA) { |
| 2780 | clen = sizeof(struct sctp_data_chunk); |
| 2781 | } else { |
| 2782 | clen = sizeof(struct sctp_idata_chunk); |
| 2783 | } |
Michael Tuexen | 66c8493 | 2016-04-18 11:42:41 +0200 | [diff] [blame] | 2784 | if (chk_length < clen) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2785 | /* |
| 2786 | * Need to send an abort since we had a |
| 2787 | * invalid data chunk. |
| 2788 | */ |
| 2789 | struct mbuf *op_err; |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 2790 | char msg[SCTP_DIAG_INFO_LEN]; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2791 | |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 2792 | SCTP_SNPRINTF(msg, sizeof(msg), "%s chunk of length %u", |
| 2793 | ch->chunk_type == SCTP_DATA ? "DATA" : "I-DATA", |
| 2794 | chk_length); |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 2795 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 2796 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_23; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 2797 | sctp_abort_an_association(inp, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
t00fcxen | 227f8db | 2014-04-19 19:44:25 +0000 | [diff] [blame] | 2798 | return (2); |
| 2799 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2800 | #ifdef SCTP_AUDITING_ENABLED |
| 2801 | sctp_audit_log(0xB1, 0); |
| 2802 | #endif |
| 2803 | if (SCTP_SIZE32(chk_length) == (length - *offset)) { |
| 2804 | last_chunk = 1; |
| 2805 | } else { |
| 2806 | last_chunk = 0; |
| 2807 | } |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 2808 | if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2809 | chk_length, net, high_tsn, &abort_flag, &break_flag, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2810 | last_chunk, ch->chunk_type)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2811 | num_chunks++; |
| 2812 | } |
| 2813 | if (abort_flag) |
| 2814 | return (2); |
| 2815 | |
| 2816 | if (break_flag) { |
| 2817 | /* |
| 2818 | * Set because of out of rwnd space and no |
| 2819 | * drop rep space left. |
| 2820 | */ |
| 2821 | stop_proc = 1; |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2822 | continue; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2823 | } |
| 2824 | } else { |
| 2825 | /* not a data chunk in the data region */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2826 | switch (ch->chunk_type) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2827 | case SCTP_INITIATION: |
| 2828 | case SCTP_INITIATION_ACK: |
| 2829 | case SCTP_SELECTIVE_ACK: |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2830 | case SCTP_NR_SELECTIVE_ACK: |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2831 | case SCTP_HEARTBEAT_REQUEST: |
| 2832 | case SCTP_HEARTBEAT_ACK: |
| 2833 | case SCTP_ABORT_ASSOCIATION: |
| 2834 | case SCTP_SHUTDOWN: |
| 2835 | case SCTP_SHUTDOWN_ACK: |
| 2836 | case SCTP_OPERATION_ERROR: |
| 2837 | case SCTP_COOKIE_ECHO: |
| 2838 | case SCTP_COOKIE_ACK: |
| 2839 | case SCTP_ECN_ECHO: |
| 2840 | case SCTP_ECN_CWR: |
| 2841 | case SCTP_SHUTDOWN_COMPLETE: |
| 2842 | case SCTP_AUTHENTICATION: |
| 2843 | case SCTP_ASCONF_ACK: |
| 2844 | case SCTP_PACKET_DROPPED: |
| 2845 | case SCTP_STREAM_RESET: |
| 2846 | case SCTP_FORWARD_CUM_TSN: |
| 2847 | case SCTP_ASCONF: |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 2848 | { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2849 | /* |
| 2850 | * Now, what do we do with KNOWN chunks that |
| 2851 | * are NOT in the right place? |
| 2852 | * |
| 2853 | * For now, I do nothing but ignore them. We |
| 2854 | * may later want to add sysctl stuff to |
| 2855 | * switch out and do either an ABORT() or |
| 2856 | * possibly process them. |
| 2857 | */ |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 2858 | struct mbuf *op_err; |
| 2859 | char msg[SCTP_DIAG_INFO_LEN]; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2860 | |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 2861 | SCTP_SNPRINTF(msg, sizeof(msg), "DATA chunk followed by chunk of type %2.2x", |
| 2862 | ch->chunk_type); |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 2863 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 2864 | sctp_abort_an_association(inp, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 2865 | return (2); |
| 2866 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2867 | default: |
Michael Tuexen | 97aebbe | 2017-10-18 22:22:05 +0200 | [diff] [blame] | 2868 | /* |
| 2869 | * Unknown chunk type: use bit rules after |
| 2870 | * checking length |
| 2871 | */ |
| 2872 | if (chk_length < sizeof(struct sctp_chunkhdr)) { |
| 2873 | /* |
| 2874 | * Need to send an abort since we had a |
| 2875 | * invalid chunk. |
| 2876 | */ |
| 2877 | struct mbuf *op_err; |
| 2878 | char msg[SCTP_DIAG_INFO_LEN]; |
| 2879 | |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 2880 | SCTP_SNPRINTF(msg, sizeof(msg), "Chunk of length %u", chk_length); |
Michael Tuexen | 97aebbe | 2017-10-18 22:22:05 +0200 | [diff] [blame] | 2881 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 2882 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 2883 | sctp_abort_an_association(inp, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | 97aebbe | 2017-10-18 22:22:05 +0200 | [diff] [blame] | 2884 | return (2); |
| 2885 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2886 | if (ch->chunk_type & 0x40) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2887 | /* Add a error report to the queue */ |
Michael Tuexen | f39c429 | 2015-09-12 19:39:48 +0200 | [diff] [blame] | 2888 | struct mbuf *op_err; |
| 2889 | struct sctp_gen_error_cause *cause; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2890 | |
Michael Tuexen | f39c429 | 2015-09-12 19:39:48 +0200 | [diff] [blame] | 2891 | op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_gen_error_cause), |
| 2892 | 0, M_NOWAIT, 1, MT_DATA); |
| 2893 | if (op_err != NULL) { |
| 2894 | cause = mtod(op_err, struct sctp_gen_error_cause *); |
| 2895 | cause->code = htons(SCTP_CAUSE_UNRECOG_CHUNK); |
Michael Tuexen | 1ce9b13 | 2016-03-25 15:03:49 +0100 | [diff] [blame] | 2896 | cause->length = htons((uint16_t)(chk_length + sizeof(struct sctp_gen_error_cause))); |
Michael Tuexen | f39c429 | 2015-09-12 19:39:48 +0200 | [diff] [blame] | 2897 | SCTP_BUF_LEN(op_err) = sizeof(struct sctp_gen_error_cause); |
| 2898 | SCTP_BUF_NEXT(op_err) = SCTP_M_COPYM(m, *offset, chk_length, M_NOWAIT); |
| 2899 | if (SCTP_BUF_NEXT(op_err) != NULL) { |
| 2900 | sctp_queue_op_err(stcb, op_err); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2901 | } else { |
Michael Tuexen | f39c429 | 2015-09-12 19:39:48 +0200 | [diff] [blame] | 2902 | sctp_m_freem(op_err); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2903 | } |
| 2904 | } |
| 2905 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2906 | if ((ch->chunk_type & 0x80) == 0) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2907 | /* discard the rest of this packet */ |
| 2908 | stop_proc = 1; |
| 2909 | } /* else skip this bad chunk and |
| 2910 | * continue... */ |
| 2911 | break; |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2912 | } /* switch of chunk type */ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2913 | } |
| 2914 | *offset += SCTP_SIZE32(chk_length); |
| 2915 | if ((*offset >= length) || stop_proc) { |
| 2916 | /* no more data left in the mbuf chain */ |
| 2917 | stop_proc = 1; |
| 2918 | continue; |
| 2919 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 2920 | ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset, |
Michael Tuexen | 97aebbe | 2017-10-18 22:22:05 +0200 | [diff] [blame] | 2921 | sizeof(struct sctp_chunkhdr), |
| 2922 | (uint8_t *)&chunk_buf); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2923 | if (ch == NULL) { |
| 2924 | *offset = length; |
| 2925 | stop_proc = 1; |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2926 | continue; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2927 | } |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 2928 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2929 | if (break_flag) { |
| 2930 | /* |
| 2931 | * we need to report rwnd overrun drops. |
| 2932 | */ |
tuexen | 3caef19 | 2012-06-24 23:24:06 +0000 | [diff] [blame] | 2933 | sctp_send_packet_dropped(stcb, net, *mm, length, iphlen, 0); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2934 | } |
| 2935 | if (num_chunks) { |
| 2936 | /* |
| 2937 | * Did we get data, if so update the time for auto-close and |
| 2938 | * give peer credit for being alive. |
| 2939 | */ |
| 2940 | SCTP_STAT_INCR(sctps_recvpktwithdata); |
| 2941 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { |
| 2942 | sctp_misc_ints(SCTP_THRESHOLD_CLEAR, |
| 2943 | stcb->asoc.overall_error_count, |
| 2944 | 0, |
| 2945 | SCTP_FROM_SCTP_INDATA, |
| 2946 | __LINE__); |
| 2947 | } |
| 2948 | stcb->asoc.overall_error_count = 0; |
| 2949 | (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_last_rcvd); |
| 2950 | } |
| 2951 | /* now service all of the reassm queue if needed */ |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 2952 | if (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_SENT) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2953 | /* Assure that we ack right away */ |
| 2954 | stcb->asoc.send_sack = 1; |
| 2955 | } |
| 2956 | /* Start a sack timer or QUEUE a SACK for sending */ |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 2957 | sctp_sack_check(stcb, was_a_gap); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2958 | return (0); |
| 2959 | } |
| 2960 | |
| 2961 | static int |
| 2962 | sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1, uint32_t last_tsn, |
| 2963 | uint16_t frag_strt, uint16_t frag_end, int nr_sacking, |
| 2964 | int *num_frs, |
| 2965 | uint32_t *biggest_newly_acked_tsn, |
| 2966 | uint32_t *this_sack_lowest_newack, |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 2967 | int *rto_ok) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2968 | { |
| 2969 | struct sctp_tmit_chunk *tp1; |
| 2970 | unsigned int theTSN; |
| 2971 | int j, wake_him = 0, circled = 0; |
| 2972 | |
| 2973 | /* Recover the tp1 we last saw */ |
| 2974 | tp1 = *p_tp1; |
| 2975 | if (tp1 == NULL) { |
| 2976 | tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); |
| 2977 | } |
| 2978 | for (j = frag_strt; j <= frag_end; j++) { |
| 2979 | theTSN = j + last_tsn; |
| 2980 | while (tp1) { |
| 2981 | if (tp1->rec.data.doing_fast_retransmit) |
| 2982 | (*num_frs) += 1; |
| 2983 | |
| 2984 | /*- |
| 2985 | * CMT: CUCv2 algorithm. For each TSN being |
| 2986 | * processed from the sent queue, track the |
| 2987 | * next expected pseudo-cumack, or |
| 2988 | * rtx_pseudo_cumack, if required. Separate |
| 2989 | * cumack trackers for first transmissions, |
| 2990 | * and retransmissions. |
| 2991 | */ |
t00fcxen | f95cdf4 | 2015-03-24 15:12:04 +0000 | [diff] [blame] | 2992 | if ((tp1->sent < SCTP_DATAGRAM_RESEND) && |
| 2993 | (tp1->whoTo->find_pseudo_cumack == 1) && |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2994 | (tp1->snd_count == 1)) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 2995 | tp1->whoTo->pseudo_cumack = tp1->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 2996 | tp1->whoTo->find_pseudo_cumack = 0; |
| 2997 | } |
t00fcxen | f95cdf4 | 2015-03-24 15:12:04 +0000 | [diff] [blame] | 2998 | if ((tp1->sent < SCTP_DATAGRAM_RESEND) && |
| 2999 | (tp1->whoTo->find_rtx_pseudo_cumack == 1) && |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3000 | (tp1->snd_count > 1)) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3001 | tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3002 | tp1->whoTo->find_rtx_pseudo_cumack = 0; |
| 3003 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3004 | if (tp1->rec.data.tsn == theTSN) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3005 | if (tp1->sent != SCTP_DATAGRAM_UNSENT) { |
| 3006 | /*- |
| 3007 | * must be held until |
| 3008 | * cum-ack passes |
| 3009 | */ |
| 3010 | if (tp1->sent < SCTP_DATAGRAM_RESEND) { |
| 3011 | /*- |
| 3012 | * If it is less than RESEND, it is |
| 3013 | * now no-longer in flight. |
| 3014 | * Higher values may already be set |
| 3015 | * via previous Gap Ack Blocks... |
| 3016 | * i.e. ACKED or RESEND. |
| 3017 | */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3018 | if (SCTP_TSN_GT(tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3019 | *biggest_newly_acked_tsn)) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3020 | *biggest_newly_acked_tsn = tp1->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3021 | } |
| 3022 | /*- |
| 3023 | * CMT: SFR algo (and HTNA) - set |
| 3024 | * saw_newack to 1 for dest being |
| 3025 | * newly acked. update |
| 3026 | * this_sack_highest_newack if |
| 3027 | * appropriate. |
| 3028 | */ |
| 3029 | if (tp1->rec.data.chunk_was_revoked == 0) |
| 3030 | tp1->whoTo->saw_newack = 1; |
| 3031 | |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3032 | if (SCTP_TSN_GT(tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3033 | tp1->whoTo->this_sack_highest_newack)) { |
| 3034 | tp1->whoTo->this_sack_highest_newack = |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3035 | tp1->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3036 | } |
| 3037 | /*- |
| 3038 | * CMT DAC algo: also update |
| 3039 | * this_sack_lowest_newack |
| 3040 | */ |
| 3041 | if (*this_sack_lowest_newack == 0) { |
| 3042 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { |
| 3043 | sctp_log_sack(*this_sack_lowest_newack, |
| 3044 | last_tsn, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3045 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3046 | 0, |
| 3047 | 0, |
| 3048 | SCTP_LOG_TSN_ACKED); |
| 3049 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3050 | *this_sack_lowest_newack = tp1->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3051 | } |
| 3052 | /*- |
| 3053 | * CMT: CUCv2 algorithm. If (rtx-)pseudo-cumack for corresp |
| 3054 | * dest is being acked, then we have a new (rtx-)pseudo-cumack. Set |
| 3055 | * new_(rtx_)pseudo_cumack to TRUE so that the cwnd for this dest can be |
| 3056 | * updated. Also trigger search for the next expected (rtx-)pseudo-cumack. |
| 3057 | * Separate pseudo_cumack trackers for first transmissions and |
| 3058 | * retransmissions. |
| 3059 | */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3060 | if (tp1->rec.data.tsn == tp1->whoTo->pseudo_cumack) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3061 | if (tp1->rec.data.chunk_was_revoked == 0) { |
| 3062 | tp1->whoTo->new_pseudo_cumack = 1; |
| 3063 | } |
| 3064 | tp1->whoTo->find_pseudo_cumack = 1; |
| 3065 | } |
| 3066 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3067 | sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.tsn, SCTP_CWND_LOG_FROM_SACK); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3068 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3069 | if (tp1->rec.data.tsn == tp1->whoTo->rtx_pseudo_cumack) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3070 | if (tp1->rec.data.chunk_was_revoked == 0) { |
| 3071 | tp1->whoTo->new_pseudo_cumack = 1; |
| 3072 | } |
| 3073 | tp1->whoTo->find_rtx_pseudo_cumack = 1; |
| 3074 | } |
| 3075 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { |
| 3076 | sctp_log_sack(*biggest_newly_acked_tsn, |
| 3077 | last_tsn, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3078 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3079 | frag_strt, |
| 3080 | frag_end, |
| 3081 | SCTP_LOG_TSN_ACKED); |
| 3082 | } |
| 3083 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
| 3084 | sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP, |
| 3085 | tp1->whoTo->flight_size, |
| 3086 | tp1->book_size, |
Michael Tuexen | 95da8e5 | 2016-03-25 12:29:52 +0100 | [diff] [blame] | 3087 | (uint32_t)(uintptr_t)tp1->whoTo, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3088 | tp1->rec.data.tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3089 | } |
| 3090 | sctp_flight_size_decrease(tp1); |
| 3091 | if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { |
| 3092 | (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo, |
| 3093 | tp1); |
| 3094 | } |
| 3095 | sctp_total_flight_decrease(stcb, tp1); |
| 3096 | |
| 3097 | tp1->whoTo->net_ack += tp1->send_size; |
| 3098 | if (tp1->snd_count < 2) { |
| 3099 | /*- |
Michael Tuexen | c51af97 | 2018-08-12 15:32:55 +0200 | [diff] [blame] | 3100 | * True non-retransmitted chunk |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3101 | */ |
| 3102 | tp1->whoTo->net_ack2 += tp1->send_size; |
| 3103 | |
| 3104 | /*- |
| 3105 | * update RTO too ? |
| 3106 | */ |
| 3107 | if (tp1->do_rtt) { |
Michael Tuexen | b7ed78b | 2019-09-22 12:48:36 +0200 | [diff] [blame] | 3108 | if (*rto_ok && |
| 3109 | sctp_calculate_rto(stcb, |
| 3110 | &stcb->asoc, |
| 3111 | tp1->whoTo, |
| 3112 | &tp1->sent_rcv_time, |
| 3113 | SCTP_RTT_FROM_DATA)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3114 | *rto_ok = 0; |
| 3115 | } |
| 3116 | if (tp1->whoTo->rto_needed == 0) { |
| 3117 | tp1->whoTo->rto_needed = 1; |
| 3118 | } |
| 3119 | tp1->do_rtt = 0; |
| 3120 | } |
| 3121 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3122 | } |
| 3123 | if (tp1->sent <= SCTP_DATAGRAM_RESEND) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3124 | if (SCTP_TSN_GT(tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3125 | stcb->asoc.this_sack_highest_gap)) { |
| 3126 | stcb->asoc.this_sack_highest_gap = |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3127 | tp1->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3128 | } |
| 3129 | if (tp1->sent == SCTP_DATAGRAM_RESEND) { |
| 3130 | sctp_ucount_decr(stcb->asoc.sent_queue_retran_cnt); |
| 3131 | #ifdef SCTP_AUDITING_ENABLED |
| 3132 | sctp_audit_log(0xB2, |
| 3133 | (stcb->asoc.sent_queue_retran_cnt & 0x000000ff)); |
| 3134 | #endif |
| 3135 | } |
| 3136 | } |
| 3137 | /*- |
| 3138 | * All chunks NOT UNSENT fall through here and are marked |
| 3139 | * (leave PR-SCTP ones that are to skip alone though) |
| 3140 | */ |
t00fcxen | 9ad9077 | 2012-11-07 22:19:57 +0000 | [diff] [blame] | 3141 | if ((tp1->sent != SCTP_FORWARD_TSN_SKIP) && |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 3142 | (tp1->sent != SCTP_DATAGRAM_NR_ACKED)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3143 | tp1->sent = SCTP_DATAGRAM_MARKED; |
t00fcxen | 9ad9077 | 2012-11-07 22:19:57 +0000 | [diff] [blame] | 3144 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3145 | if (tp1->rec.data.chunk_was_revoked) { |
| 3146 | /* deflate the cwnd */ |
| 3147 | tp1->whoTo->cwnd -= tp1->book_size; |
| 3148 | tp1->rec.data.chunk_was_revoked = 0; |
| 3149 | } |
| 3150 | /* NR Sack code here */ |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 3151 | if (nr_sacking && |
| 3152 | (tp1->sent != SCTP_DATAGRAM_NR_ACKED)) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3153 | if (stcb->asoc.strmout[tp1->rec.data.sid].chunks_on_queues > 0) { |
| 3154 | stcb->asoc.strmout[tp1->rec.data.sid].chunks_on_queues--; |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 3155 | #ifdef INVARIANTS |
| 3156 | } else { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3157 | panic("No chunks on the queues for sid %u.", tp1->rec.data.sid); |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 3158 | #endif |
| 3159 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3160 | if ((stcb->asoc.strmout[tp1->rec.data.sid].chunks_on_queues == 0) && |
| 3161 | (stcb->asoc.strmout[tp1->rec.data.sid].state == SCTP_STREAM_RESET_PENDING) && |
| 3162 | TAILQ_EMPTY(&stcb->asoc.strmout[tp1->rec.data.sid].outqueue)) { |
Michael Tuexen | c0a12d1 | 2015-12-03 16:30:24 +0100 | [diff] [blame] | 3163 | stcb->asoc.trigger_reset = 1; |
| 3164 | } |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 3165 | tp1->sent = SCTP_DATAGRAM_NR_ACKED; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3166 | if (tp1->data) { |
| 3167 | /* sa_ignore NO_NULL_CHK */ |
| 3168 | sctp_free_bufspace(stcb, &stcb->asoc, tp1, 1); |
| 3169 | sctp_m_freem(tp1->data); |
| 3170 | tp1->data = NULL; |
| 3171 | } |
| 3172 | wake_him++; |
| 3173 | } |
| 3174 | } |
| 3175 | break; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3176 | } /* if (tp1->tsn == theTSN) */ |
| 3177 | if (SCTP_TSN_GT(tp1->rec.data.tsn, theTSN)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3178 | break; |
| 3179 | } |
| 3180 | tp1 = TAILQ_NEXT(tp1, sctp_next); |
| 3181 | if ((tp1 == NULL) && (circled == 0)) { |
| 3182 | circled++; |
| 3183 | tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); |
| 3184 | } |
| 3185 | } /* end while (tp1) */ |
| 3186 | if (tp1 == NULL) { |
| 3187 | circled = 0; |
| 3188 | tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue); |
| 3189 | } |
| 3190 | /* In case the fragments were not in order we must reset */ |
| 3191 | } /* end for (j = fragStart */ |
| 3192 | *p_tp1 = tp1; |
| 3193 | return (wake_him); /* Return value only used for nr-sack */ |
| 3194 | } |
| 3195 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3196 | static int |
| 3197 | sctp_handle_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct sctp_association *asoc, |
| 3198 | uint32_t last_tsn, uint32_t *biggest_tsn_acked, |
| 3199 | uint32_t *biggest_newly_acked_tsn, uint32_t *this_sack_lowest_newack, |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 3200 | int num_seg, int num_nr_seg, int *rto_ok) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3201 | { |
| 3202 | struct sctp_gap_ack_block *frag, block; |
| 3203 | struct sctp_tmit_chunk *tp1; |
| 3204 | int i; |
| 3205 | int num_frs = 0; |
| 3206 | int chunk_freed; |
| 3207 | int non_revocable; |
| 3208 | uint16_t frag_strt, frag_end, prev_frag_end; |
| 3209 | |
| 3210 | tp1 = TAILQ_FIRST(&asoc->sent_queue); |
| 3211 | prev_frag_end = 0; |
| 3212 | chunk_freed = 0; |
| 3213 | |
| 3214 | for (i = 0; i < (num_seg + num_nr_seg); i++) { |
| 3215 | if (i == num_seg) { |
| 3216 | prev_frag_end = 0; |
| 3217 | tp1 = TAILQ_FIRST(&asoc->sent_queue); |
| 3218 | } |
| 3219 | frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, |
| 3220 | sizeof(struct sctp_gap_ack_block), (uint8_t *) &block); |
| 3221 | *offset += sizeof(block); |
| 3222 | if (frag == NULL) { |
| 3223 | return (chunk_freed); |
| 3224 | } |
| 3225 | frag_strt = ntohs(frag->start); |
| 3226 | frag_end = ntohs(frag->end); |
| 3227 | |
| 3228 | if (frag_strt > frag_end) { |
| 3229 | /* This gap report is malformed, skip it. */ |
| 3230 | continue; |
| 3231 | } |
| 3232 | if (frag_strt <= prev_frag_end) { |
| 3233 | /* This gap report is not in order, so restart. */ |
| 3234 | tp1 = TAILQ_FIRST(&asoc->sent_queue); |
| 3235 | } |
| 3236 | if (SCTP_TSN_GT((last_tsn + frag_end), *biggest_tsn_acked)) { |
| 3237 | *biggest_tsn_acked = last_tsn + frag_end; |
| 3238 | } |
| 3239 | if (i < num_seg) { |
| 3240 | non_revocable = 0; |
| 3241 | } else { |
| 3242 | non_revocable = 1; |
| 3243 | } |
| 3244 | if (sctp_process_segment_range(stcb, &tp1, last_tsn, frag_strt, frag_end, |
| 3245 | non_revocable, &num_frs, biggest_newly_acked_tsn, |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 3246 | this_sack_lowest_newack, rto_ok)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3247 | chunk_freed = 1; |
| 3248 | } |
| 3249 | prev_frag_end = frag_end; |
| 3250 | } |
| 3251 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { |
| 3252 | if (num_frs) |
| 3253 | sctp_log_fr(*biggest_tsn_acked, |
| 3254 | *biggest_newly_acked_tsn, |
| 3255 | last_tsn, SCTP_FR_LOG_BIGGEST_TSNS); |
| 3256 | } |
| 3257 | return (chunk_freed); |
| 3258 | } |
| 3259 | |
| 3260 | static void |
| 3261 | sctp_check_for_revoked(struct sctp_tcb *stcb, |
| 3262 | struct sctp_association *asoc, uint32_t cumack, |
| 3263 | uint32_t biggest_tsn_acked) |
| 3264 | { |
| 3265 | struct sctp_tmit_chunk *tp1; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3266 | |
| 3267 | TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3268 | if (SCTP_TSN_GT(tp1->rec.data.tsn, cumack)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3269 | /* |
| 3270 | * ok this guy is either ACK or MARKED. If it is |
| 3271 | * ACKED it has been previously acked but not this |
| 3272 | * time i.e. revoked. If it is MARKED it was ACK'ed |
| 3273 | * again. |
| 3274 | */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3275 | if (SCTP_TSN_GT(tp1->rec.data.tsn, biggest_tsn_acked)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3276 | break; |
| 3277 | } |
| 3278 | if (tp1->sent == SCTP_DATAGRAM_ACKED) { |
| 3279 | /* it has been revoked */ |
| 3280 | tp1->sent = SCTP_DATAGRAM_SENT; |
| 3281 | tp1->rec.data.chunk_was_revoked = 1; |
| 3282 | /* We must add this stuff back in to |
| 3283 | * assure timers and such get started. |
| 3284 | */ |
| 3285 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
| 3286 | sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, |
| 3287 | tp1->whoTo->flight_size, |
| 3288 | tp1->book_size, |
Michael Tuexen | 95da8e5 | 2016-03-25 12:29:52 +0100 | [diff] [blame] | 3289 | (uint32_t)(uintptr_t)tp1->whoTo, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3290 | tp1->rec.data.tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3291 | } |
| 3292 | sctp_flight_size_increase(tp1); |
| 3293 | sctp_total_flight_increase(stcb, tp1); |
| 3294 | /* We inflate the cwnd to compensate for our |
| 3295 | * artificial inflation of the flight_size. |
| 3296 | */ |
| 3297 | tp1->whoTo->cwnd += tp1->book_size; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3298 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { |
| 3299 | sctp_log_sack(asoc->last_acked_seq, |
| 3300 | cumack, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3301 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3302 | 0, |
| 3303 | 0, |
| 3304 | SCTP_LOG_TSN_REVOKED); |
| 3305 | } |
| 3306 | } else if (tp1->sent == SCTP_DATAGRAM_MARKED) { |
| 3307 | /* it has been re-acked in this SACK */ |
| 3308 | tp1->sent = SCTP_DATAGRAM_ACKED; |
| 3309 | } |
| 3310 | } |
| 3311 | if (tp1->sent == SCTP_DATAGRAM_UNSENT) |
| 3312 | break; |
| 3313 | } |
| 3314 | } |
| 3315 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3316 | static void |
| 3317 | sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, |
| 3318 | uint32_t biggest_tsn_acked, uint32_t biggest_tsn_newly_acked, uint32_t this_sack_lowest_newack, int accum_moved) |
| 3319 | { |
| 3320 | struct sctp_tmit_chunk *tp1; |
| 3321 | int strike_flag = 0; |
| 3322 | struct timeval now; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3323 | uint32_t sending_seq; |
| 3324 | struct sctp_nets *net; |
| 3325 | int num_dests_sacked = 0; |
| 3326 | |
| 3327 | /* |
| 3328 | * select the sending_seq, this is either the next thing ready to be |
| 3329 | * sent but not transmitted, OR, the next seq we assign. |
| 3330 | */ |
| 3331 | tp1 = TAILQ_FIRST(&stcb->asoc.send_queue); |
| 3332 | if (tp1 == NULL) { |
| 3333 | sending_seq = asoc->sending_seq; |
| 3334 | } else { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3335 | sending_seq = tp1->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | /* CMT DAC algo: finding out if SACK is a mixed SACK */ |
| 3339 | if ((asoc->sctp_cmt_on_off > 0) && |
| 3340 | SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { |
| 3341 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 3342 | if (net->saw_newack) |
| 3343 | num_dests_sacked++; |
| 3344 | } |
| 3345 | } |
t00fcxen | 0e78cef | 2014-08-02 22:05:33 +0000 | [diff] [blame] | 3346 | if (stcb->asoc.prsctp_supported) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3347 | (void)SCTP_GETTIME_TIMEVAL(&now); |
| 3348 | } |
| 3349 | TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { |
| 3350 | strike_flag = 0; |
| 3351 | if (tp1->no_fr_allowed) { |
| 3352 | /* this one had a timeout or something */ |
| 3353 | continue; |
| 3354 | } |
| 3355 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { |
| 3356 | if (tp1->sent < SCTP_DATAGRAM_RESEND) |
| 3357 | sctp_log_fr(biggest_tsn_newly_acked, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3358 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3359 | tp1->sent, |
| 3360 | SCTP_FR_LOG_CHECK_STRIKE); |
| 3361 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3362 | if (SCTP_TSN_GT(tp1->rec.data.tsn, biggest_tsn_acked) || |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3363 | tp1->sent == SCTP_DATAGRAM_UNSENT) { |
| 3364 | /* done */ |
| 3365 | break; |
| 3366 | } |
t00fcxen | 0e78cef | 2014-08-02 22:05:33 +0000 | [diff] [blame] | 3367 | if (stcb->asoc.prsctp_supported) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3368 | if ((PR_SCTP_TTL_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) { |
| 3369 | /* Is it expired? */ |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 3370 | #if !(defined(__FreeBSD__) && !defined(__Userspace__)) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3371 | if (timercmp(&now, &tp1->rec.data.timetodrop, >)) { |
| 3372 | #else |
| 3373 | if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) { |
| 3374 | #endif |
| 3375 | /* Yes so drop it */ |
| 3376 | if (tp1->data != NULL) { |
tuexen | da53ff0 | 2012-05-14 09:00:59 +0000 | [diff] [blame] | 3377 | (void)sctp_release_pr_sctp_chunk(stcb, tp1, 1, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3378 | SCTP_SO_NOT_LOCKED); |
| 3379 | } |
| 3380 | continue; |
| 3381 | } |
| 3382 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3383 | } |
Michael Tuexen | 83714a8 | 2018-01-16 23:02:09 +0100 | [diff] [blame] | 3384 | if (SCTP_TSN_GT(tp1->rec.data.tsn, asoc->this_sack_highest_gap) && |
| 3385 | !(accum_moved && asoc->fast_retran_loss_recovery)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3386 | /* we are beyond the tsn in the sack */ |
| 3387 | break; |
| 3388 | } |
| 3389 | if (tp1->sent >= SCTP_DATAGRAM_RESEND) { |
| 3390 | /* either a RESEND, ACKED, or MARKED */ |
| 3391 | /* skip */ |
| 3392 | if (tp1->sent == SCTP_FORWARD_TSN_SKIP) { |
| 3393 | /* Continue strikin FWD-TSN chunks */ |
| 3394 | tp1->rec.data.fwd_tsn_cnt++; |
| 3395 | } |
| 3396 | continue; |
| 3397 | } |
| 3398 | /* |
| 3399 | * CMT : SFR algo (covers part of DAC and HTNA as well) |
| 3400 | */ |
| 3401 | if (tp1->whoTo && tp1->whoTo->saw_newack == 0) { |
| 3402 | /* |
David Sanders | b519f51 | 2022-03-29 13:55:16 -0700 | [diff] [blame] | 3403 | * No new acks were received for data sent to this |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3404 | * dest. Therefore, according to the SFR algo for |
| 3405 | * CMT, no data sent to this dest can be marked for |
| 3406 | * FR using this SACK. |
| 3407 | */ |
| 3408 | continue; |
Michael Tuexen | 83714a8 | 2018-01-16 23:02:09 +0100 | [diff] [blame] | 3409 | } else if (tp1->whoTo && |
| 3410 | SCTP_TSN_GT(tp1->rec.data.tsn, |
| 3411 | tp1->whoTo->this_sack_highest_newack) && |
| 3412 | !(accum_moved && asoc->fast_retran_loss_recovery)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3413 | /* |
David Sanders | b519f51 | 2022-03-29 13:55:16 -0700 | [diff] [blame] | 3414 | * CMT: New acks were received for data sent to |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3415 | * this dest. But no new acks were seen for data |
| 3416 | * sent after tp1. Therefore, according to the SFR |
| 3417 | * algo for CMT, tp1 cannot be marked for FR using |
| 3418 | * this SACK. This step covers part of the DAC algo |
| 3419 | * and the HTNA algo as well. |
| 3420 | */ |
| 3421 | continue; |
| 3422 | } |
| 3423 | /* |
| 3424 | * Here we check to see if we were have already done a FR |
| 3425 | * and if so we see if the biggest TSN we saw in the sack is |
| 3426 | * smaller than the recovery point. If so we don't strike |
| 3427 | * the tsn... otherwise we CAN strike the TSN. |
| 3428 | */ |
| 3429 | /* |
| 3430 | * @@@ JRI: Check for CMT |
| 3431 | * if (accum_moved && asoc->fast_retran_loss_recovery && (sctp_cmt_on_off == 0)) { |
| 3432 | */ |
| 3433 | if (accum_moved && asoc->fast_retran_loss_recovery) { |
| 3434 | /* |
| 3435 | * Strike the TSN if in fast-recovery and cum-ack |
| 3436 | * moved. |
| 3437 | */ |
| 3438 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { |
| 3439 | sctp_log_fr(biggest_tsn_newly_acked, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3440 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3441 | tp1->sent, |
| 3442 | SCTP_FR_LOG_STRIKE_CHUNK); |
| 3443 | } |
| 3444 | if (tp1->sent < SCTP_DATAGRAM_RESEND) { |
| 3445 | tp1->sent++; |
| 3446 | } |
| 3447 | if ((asoc->sctp_cmt_on_off > 0) && |
| 3448 | SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { |
| 3449 | /* |
| 3450 | * CMT DAC algorithm: If SACK flag is set to |
| 3451 | * 0, then lowest_newack test will not pass |
| 3452 | * because it would have been set to the |
| 3453 | * cumack earlier. If not already to be |
| 3454 | * rtx'd, If not a mixed sack and if tp1 is |
| 3455 | * not between two sacked TSNs, then mark by |
| 3456 | * one more. |
| 3457 | * NOTE that we are marking by one additional time since the SACK DAC flag indicates that |
| 3458 | * two packets have been received after this missing TSN. |
| 3459 | */ |
| 3460 | if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3461 | SCTP_TSN_GT(this_sack_lowest_newack, tp1->rec.data.tsn)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3462 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { |
| 3463 | sctp_log_fr(16 + num_dests_sacked, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3464 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3465 | tp1->sent, |
| 3466 | SCTP_FR_LOG_STRIKE_CHUNK); |
| 3467 | } |
| 3468 | tp1->sent++; |
| 3469 | } |
| 3470 | } |
| 3471 | } else if ((tp1->rec.data.doing_fast_retransmit) && |
| 3472 | (asoc->sctp_cmt_on_off == 0)) { |
| 3473 | /* |
| 3474 | * For those that have done a FR we must take |
| 3475 | * special consideration if we strike. I.e the |
| 3476 | * biggest_newly_acked must be higher than the |
| 3477 | * sending_seq at the time we did the FR. |
| 3478 | */ |
| 3479 | if ( |
| 3480 | #ifdef SCTP_FR_TO_ALTERNATE |
| 3481 | /* |
| 3482 | * If FR's go to new networks, then we must only do |
| 3483 | * this for singly homed asoc's. However if the FR's |
| 3484 | * go to the same network (Armando's work) then its |
| 3485 | * ok to FR multiple times. |
| 3486 | */ |
| 3487 | (asoc->numnets < 2) |
| 3488 | #else |
| 3489 | (1) |
| 3490 | #endif |
| 3491 | ) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3492 | if (SCTP_TSN_GE(biggest_tsn_newly_acked, |
| 3493 | tp1->rec.data.fast_retran_tsn)) { |
| 3494 | /* |
| 3495 | * Strike the TSN, since this ack is |
| 3496 | * beyond where things were when we |
| 3497 | * did a FR. |
| 3498 | */ |
| 3499 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { |
| 3500 | sctp_log_fr(biggest_tsn_newly_acked, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3501 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3502 | tp1->sent, |
| 3503 | SCTP_FR_LOG_STRIKE_CHUNK); |
| 3504 | } |
| 3505 | if (tp1->sent < SCTP_DATAGRAM_RESEND) { |
| 3506 | tp1->sent++; |
| 3507 | } |
| 3508 | strike_flag = 1; |
| 3509 | if ((asoc->sctp_cmt_on_off > 0) && |
| 3510 | SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { |
| 3511 | /* |
| 3512 | * CMT DAC algorithm: If |
| 3513 | * SACK flag is set to 0, |
| 3514 | * then lowest_newack test |
| 3515 | * will not pass because it |
| 3516 | * would have been set to |
| 3517 | * the cumack earlier. If |
| 3518 | * not already to be rtx'd, |
| 3519 | * If not a mixed sack and |
| 3520 | * if tp1 is not between two |
| 3521 | * sacked TSNs, then mark by |
| 3522 | * one more. |
| 3523 | * NOTE that we are marking by one additional time since the SACK DAC flag indicates that |
| 3524 | * two packets have been received after this missing TSN. |
| 3525 | */ |
| 3526 | if ((tp1->sent < SCTP_DATAGRAM_RESEND) && |
| 3527 | (num_dests_sacked == 1) && |
| 3528 | SCTP_TSN_GT(this_sack_lowest_newack, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3529 | tp1->rec.data.tsn)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3530 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { |
| 3531 | sctp_log_fr(32 + num_dests_sacked, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3532 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3533 | tp1->sent, |
| 3534 | SCTP_FR_LOG_STRIKE_CHUNK); |
| 3535 | } |
| 3536 | if (tp1->sent < SCTP_DATAGRAM_RESEND) { |
| 3537 | tp1->sent++; |
| 3538 | } |
| 3539 | } |
| 3540 | } |
| 3541 | } |
| 3542 | } |
| 3543 | /* |
| 3544 | * JRI: TODO: remove code for HTNA algo. CMT's |
| 3545 | * SFR algo covers HTNA. |
| 3546 | */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3547 | } else if (SCTP_TSN_GT(tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3548 | biggest_tsn_newly_acked)) { |
| 3549 | /* |
| 3550 | * We don't strike these: This is the HTNA |
| 3551 | * algorithm i.e. we don't strike If our TSN is |
| 3552 | * larger than the Highest TSN Newly Acked. |
| 3553 | */ |
| 3554 | ; |
| 3555 | } else { |
| 3556 | /* Strike the TSN */ |
| 3557 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { |
| 3558 | sctp_log_fr(biggest_tsn_newly_acked, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3559 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3560 | tp1->sent, |
| 3561 | SCTP_FR_LOG_STRIKE_CHUNK); |
| 3562 | } |
| 3563 | if (tp1->sent < SCTP_DATAGRAM_RESEND) { |
| 3564 | tp1->sent++; |
| 3565 | } |
| 3566 | if ((asoc->sctp_cmt_on_off > 0) && |
| 3567 | SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { |
| 3568 | /* |
| 3569 | * CMT DAC algorithm: If SACK flag is set to |
| 3570 | * 0, then lowest_newack test will not pass |
| 3571 | * because it would have been set to the |
| 3572 | * cumack earlier. If not already to be |
| 3573 | * rtx'd, If not a mixed sack and if tp1 is |
| 3574 | * not between two sacked TSNs, then mark by |
| 3575 | * one more. |
| 3576 | * NOTE that we are marking by one additional time since the SACK DAC flag indicates that |
| 3577 | * two packets have been received after this missing TSN. |
| 3578 | */ |
| 3579 | if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) && |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3580 | SCTP_TSN_GT(this_sack_lowest_newack, tp1->rec.data.tsn)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3581 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { |
| 3582 | sctp_log_fr(48 + num_dests_sacked, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3583 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3584 | tp1->sent, |
| 3585 | SCTP_FR_LOG_STRIKE_CHUNK); |
| 3586 | } |
| 3587 | tp1->sent++; |
| 3588 | } |
| 3589 | } |
| 3590 | } |
| 3591 | if (tp1->sent == SCTP_DATAGRAM_RESEND) { |
| 3592 | struct sctp_nets *alt; |
| 3593 | |
| 3594 | /* fix counts and things */ |
| 3595 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
| 3596 | sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND, |
| 3597 | (tp1->whoTo ? (tp1->whoTo->flight_size) : 0), |
| 3598 | tp1->book_size, |
Michael Tuexen | 95da8e5 | 2016-03-25 12:29:52 +0100 | [diff] [blame] | 3599 | (uint32_t)(uintptr_t)tp1->whoTo, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3600 | tp1->rec.data.tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3601 | } |
| 3602 | if (tp1->whoTo) { |
| 3603 | tp1->whoTo->net_ack++; |
| 3604 | sctp_flight_size_decrease(tp1); |
| 3605 | if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { |
| 3606 | (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo, |
| 3607 | tp1); |
| 3608 | } |
| 3609 | } |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 3610 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3611 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { |
| 3612 | sctp_log_rwnd(SCTP_INCREASE_PEER_RWND, |
| 3613 | asoc->peers_rwnd, tp1->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); |
| 3614 | } |
| 3615 | /* add back to the rwnd */ |
| 3616 | asoc->peers_rwnd += (tp1->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 3617 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3618 | /* remove from the total flight */ |
| 3619 | sctp_total_flight_decrease(stcb, tp1); |
| 3620 | |
t00fcxen | 0e78cef | 2014-08-02 22:05:33 +0000 | [diff] [blame] | 3621 | if ((stcb->asoc.prsctp_supported) && |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3622 | (PR_SCTP_RTX_ENABLED(tp1->flags))) { |
| 3623 | /* Has it been retransmitted tv_sec times? - we store the retran count there. */ |
| 3624 | if (tp1->snd_count > tp1->rec.data.timetodrop.tv_sec) { |
| 3625 | /* Yes, so drop it */ |
| 3626 | if (tp1->data != NULL) { |
tuexen | da53ff0 | 2012-05-14 09:00:59 +0000 | [diff] [blame] | 3627 | (void)sctp_release_pr_sctp_chunk(stcb, tp1, 1, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3628 | SCTP_SO_NOT_LOCKED); |
| 3629 | } |
| 3630 | /* Make sure to flag we had a FR */ |
Michael Tuexen | 4d93360 | 2018-05-06 16:23:44 +0200 | [diff] [blame] | 3631 | if (tp1->whoTo != NULL) { |
| 3632 | tp1->whoTo->net_ack++; |
| 3633 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3634 | continue; |
| 3635 | } |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 3636 | } |
tuexen | cb5fe8d | 2012-05-04 09:50:27 +0000 | [diff] [blame] | 3637 | /* SCTP_PRINTF("OK, we are now ready to FR this guy\n"); */ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3638 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3639 | sctp_log_fr(tp1->rec.data.tsn, tp1->snd_count, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3640 | 0, SCTP_FR_MARKED); |
| 3641 | } |
| 3642 | if (strike_flag) { |
| 3643 | /* This is a subsequent FR */ |
| 3644 | SCTP_STAT_INCR(sctps_sendmultfastretrans); |
| 3645 | } |
| 3646 | sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); |
| 3647 | if (asoc->sctp_cmt_on_off > 0) { |
| 3648 | /* |
| 3649 | * CMT: Using RTX_SSTHRESH policy for CMT. |
| 3650 | * If CMT is being used, then pick dest with |
| 3651 | * largest ssthresh for any retransmission. |
| 3652 | */ |
| 3653 | tp1->no_fr_allowed = 1; |
| 3654 | alt = tp1->whoTo; |
| 3655 | /*sa_ignore NO_NULL_CHK*/ |
| 3656 | if (asoc->sctp_cmt_pf > 0) { |
| 3657 | /* JRS 5/18/07 - If CMT PF is on, use the PF version of find_alt_net() */ |
| 3658 | alt = sctp_find_alternate_net(stcb, alt, 2); |
| 3659 | } else { |
| 3660 | /* JRS 5/18/07 - If only CMT is on, use the CMT version of find_alt_net() */ |
| 3661 | /*sa_ignore NO_NULL_CHK*/ |
| 3662 | alt = sctp_find_alternate_net(stcb, alt, 1); |
| 3663 | } |
| 3664 | if (alt == NULL) { |
| 3665 | alt = tp1->whoTo; |
| 3666 | } |
| 3667 | /* |
| 3668 | * CUCv2: If a different dest is picked for |
| 3669 | * the retransmission, then new |
| 3670 | * (rtx-)pseudo_cumack needs to be tracked |
| 3671 | * for orig dest. Let CUCv2 track new (rtx-) |
| 3672 | * pseudo-cumack always. |
| 3673 | */ |
| 3674 | if (tp1->whoTo) { |
| 3675 | tp1->whoTo->find_pseudo_cumack = 1; |
| 3676 | tp1->whoTo->find_rtx_pseudo_cumack = 1; |
| 3677 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3678 | } else {/* CMT is OFF */ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3679 | #ifdef SCTP_FR_TO_ALTERNATE |
| 3680 | /* Can we find an alternate? */ |
| 3681 | alt = sctp_find_alternate_net(stcb, tp1->whoTo, 0); |
| 3682 | #else |
| 3683 | /* |
| 3684 | * default behavior is to NOT retransmit |
| 3685 | * FR's to an alternate. Armando Caro's |
| 3686 | * paper details why. |
| 3687 | */ |
| 3688 | alt = tp1->whoTo; |
| 3689 | #endif |
| 3690 | } |
| 3691 | |
| 3692 | tp1->rec.data.doing_fast_retransmit = 1; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3693 | /* mark the sending seq for possible subsequent FR's */ |
| 3694 | /* |
tuexen | cb5fe8d | 2012-05-04 09:50:27 +0000 | [diff] [blame] | 3695 | * SCTP_PRINTF("Marking TSN for FR new value %x\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3696 | * (uint32_t)tpi->rec.data.tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3697 | */ |
| 3698 | if (TAILQ_EMPTY(&asoc->send_queue)) { |
| 3699 | /* |
| 3700 | * If the queue of send is empty then its |
| 3701 | * the next sequence number that will be |
| 3702 | * assigned so we subtract one from this to |
| 3703 | * get the one we last sent. |
| 3704 | */ |
| 3705 | tp1->rec.data.fast_retran_tsn = sending_seq; |
| 3706 | } else { |
| 3707 | /* |
| 3708 | * If there are chunks on the send queue |
| 3709 | * (unsent data that has made it from the |
| 3710 | * stream queues but not out the door, we |
| 3711 | * take the first one (which will have the |
| 3712 | * lowest TSN) and subtract one to get the |
| 3713 | * one we last sent. |
| 3714 | */ |
| 3715 | struct sctp_tmit_chunk *ttt; |
| 3716 | |
| 3717 | ttt = TAILQ_FIRST(&asoc->send_queue); |
| 3718 | tp1->rec.data.fast_retran_tsn = |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3719 | ttt->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | if (tp1->do_rtt) { |
| 3723 | /* |
| 3724 | * this guy had a RTO calculation pending on |
| 3725 | * it, cancel it |
| 3726 | */ |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 3727 | if ((tp1->whoTo != NULL) && |
| 3728 | (tp1->whoTo->rto_needed == 0)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3729 | tp1->whoTo->rto_needed = 1; |
| 3730 | } |
| 3731 | tp1->do_rtt = 0; |
| 3732 | } |
| 3733 | if (alt != tp1->whoTo) { |
| 3734 | /* yes, there is an alternate. */ |
| 3735 | sctp_free_remote_addr(tp1->whoTo); |
| 3736 | /*sa_ignore FREED_MEMORY*/ |
| 3737 | tp1->whoTo = alt; |
| 3738 | atomic_add_int(&alt->ref_count, 1); |
| 3739 | } |
| 3740 | } |
| 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | struct sctp_tmit_chunk * |
| 3745 | sctp_try_advance_peer_ack_point(struct sctp_tcb *stcb, |
| 3746 | struct sctp_association *asoc) |
| 3747 | { |
| 3748 | struct sctp_tmit_chunk *tp1, *tp2, *a_adv = NULL; |
| 3749 | struct timeval now; |
| 3750 | int now_filled = 0; |
| 3751 | |
t00fcxen | 0e78cef | 2014-08-02 22:05:33 +0000 | [diff] [blame] | 3752 | if (asoc->prsctp_supported == 0) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3753 | return (NULL); |
| 3754 | } |
| 3755 | TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) { |
| 3756 | if (tp1->sent != SCTP_FORWARD_TSN_SKIP && |
t00fcxen | 06a2a53 | 2012-11-07 21:03:47 +0000 | [diff] [blame] | 3757 | tp1->sent != SCTP_DATAGRAM_RESEND && |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 3758 | tp1->sent != SCTP_DATAGRAM_NR_ACKED) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3759 | /* no chance to advance, out of here */ |
| 3760 | break; |
| 3761 | } |
| 3762 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { |
t00fcxen | 9ad9077 | 2012-11-07 22:19:57 +0000 | [diff] [blame] | 3763 | if ((tp1->sent == SCTP_FORWARD_TSN_SKIP) || |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 3764 | (tp1->sent == SCTP_DATAGRAM_NR_ACKED)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3765 | sctp_misc_ints(SCTP_FWD_TSN_CHECK, |
| 3766 | asoc->advanced_peer_ack_point, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3767 | tp1->rec.data.tsn, 0, 0); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3768 | } |
| 3769 | } |
| 3770 | if (!PR_SCTP_ENABLED(tp1->flags)) { |
| 3771 | /* |
| 3772 | * We can't fwd-tsn past any that are reliable aka |
| 3773 | * retransmitted until the asoc fails. |
| 3774 | */ |
| 3775 | break; |
| 3776 | } |
| 3777 | if (!now_filled) { |
| 3778 | (void)SCTP_GETTIME_TIMEVAL(&now); |
| 3779 | now_filled = 1; |
| 3780 | } |
| 3781 | /* |
| 3782 | * now we got a chunk which is marked for another |
| 3783 | * retransmission to a PR-stream but has run out its chances |
| 3784 | * already maybe OR has been marked to skip now. Can we skip |
| 3785 | * it if its a resend? |
| 3786 | */ |
| 3787 | if (tp1->sent == SCTP_DATAGRAM_RESEND && |
| 3788 | (PR_SCTP_TTL_ENABLED(tp1->flags))) { |
| 3789 | /* |
| 3790 | * Now is this one marked for resend and its time is |
| 3791 | * now up? |
| 3792 | */ |
Michael Tuexen | 8d6935d | 2022-05-15 01:51:24 +0200 | [diff] [blame] | 3793 | #if !(defined(__FreeBSD__) && !defined(__Userspace__)) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3794 | if (timercmp(&now, &tp1->rec.data.timetodrop, >)) { |
| 3795 | #else |
| 3796 | if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) { |
| 3797 | #endif |
| 3798 | /* Yes so drop it */ |
| 3799 | if (tp1->data) { |
| 3800 | (void)sctp_release_pr_sctp_chunk(stcb, tp1, |
tuexen | da53ff0 | 2012-05-14 09:00:59 +0000 | [diff] [blame] | 3801 | 1, SCTP_SO_NOT_LOCKED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3802 | } |
| 3803 | } else { |
| 3804 | /* |
| 3805 | * No, we are done when hit one for resend |
| 3806 | * whos time as not expired. |
| 3807 | */ |
| 3808 | break; |
| 3809 | } |
| 3810 | } |
| 3811 | /* |
| 3812 | * Ok now if this chunk is marked to drop it we can clean up |
| 3813 | * the chunk, advance our peer ack point and we can check |
| 3814 | * the next chunk. |
| 3815 | */ |
t00fcxen | 06a2a53 | 2012-11-07 21:03:47 +0000 | [diff] [blame] | 3816 | if ((tp1->sent == SCTP_FORWARD_TSN_SKIP) || |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 3817 | (tp1->sent == SCTP_DATAGRAM_NR_ACKED)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3818 | /* advance PeerAckPoint goes forward */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3819 | if (SCTP_TSN_GT(tp1->rec.data.tsn, asoc->advanced_peer_ack_point)) { |
| 3820 | asoc->advanced_peer_ack_point = tp1->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3821 | a_adv = tp1; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3822 | } else if (tp1->rec.data.tsn == asoc->advanced_peer_ack_point) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3823 | /* No update but we do save the chk */ |
| 3824 | a_adv = tp1; |
| 3825 | } |
| 3826 | } else { |
| 3827 | /* |
| 3828 | * If it is still in RESEND we can advance no |
| 3829 | * further |
| 3830 | */ |
| 3831 | break; |
| 3832 | } |
| 3833 | } |
| 3834 | return (a_adv); |
| 3835 | } |
| 3836 | |
| 3837 | static int |
| 3838 | sctp_fs_audit(struct sctp_association *asoc) |
| 3839 | { |
| 3840 | struct sctp_tmit_chunk *chk; |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 3841 | int inflight = 0, resend = 0, inbetween = 0, acked = 0, above = 0; |
t00fcxen | 006c3bc | 2015-05-28 14:33:28 +0000 | [diff] [blame] | 3842 | int ret; |
| 3843 | #ifndef INVARIANTS |
| 3844 | int entry_flight, entry_cnt; |
| 3845 | #endif |
t00fcxen | 2ea88ad | 2014-02-20 20:24:25 +0000 | [diff] [blame] | 3846 | |
t00fcxen | 006c3bc | 2015-05-28 14:33:28 +0000 | [diff] [blame] | 3847 | ret = 0; |
| 3848 | #ifndef INVARIANTS |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3849 | entry_flight = asoc->total_flight; |
| 3850 | entry_cnt = asoc->total_flight_count; |
t00fcxen | 006c3bc | 2015-05-28 14:33:28 +0000 | [diff] [blame] | 3851 | #endif |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3852 | if (asoc->pr_sctp_cnt >= asoc->sent_queue_cnt) |
| 3853 | return (0); |
| 3854 | |
| 3855 | TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { |
| 3856 | if (chk->sent < SCTP_DATAGRAM_RESEND) { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 3857 | SCTP_PRINTF("Chk TSN: %u size: %d inflight cnt: %d\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3858 | chk->rec.data.tsn, |
tuexen | cb5fe8d | 2012-05-04 09:50:27 +0000 | [diff] [blame] | 3859 | chk->send_size, |
| 3860 | chk->snd_count); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3861 | inflight++; |
| 3862 | } else if (chk->sent == SCTP_DATAGRAM_RESEND) { |
| 3863 | resend++; |
| 3864 | } else if (chk->sent < SCTP_DATAGRAM_ACKED) { |
| 3865 | inbetween++; |
| 3866 | } else if (chk->sent > SCTP_DATAGRAM_ACKED) { |
| 3867 | above++; |
| 3868 | } else { |
| 3869 | acked++; |
| 3870 | } |
| 3871 | } |
| 3872 | |
| 3873 | if ((inflight > 0) || (inbetween > 0)) { |
| 3874 | #ifdef INVARIANTS |
Michael Tuexen | e19d122 | 2022-08-03 17:35:14 +0200 | [diff] [blame^] | 3875 | panic("Flight size-express incorrect F: %d I: %d R: %d Ab: %d ACK: %d", |
| 3876 | inflight, inbetween, resend, above, acked); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3877 | #else |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 3878 | SCTP_PRINTF("asoc->total_flight: %d cnt: %d\n", |
tuexen | cb5fe8d | 2012-05-04 09:50:27 +0000 | [diff] [blame] | 3879 | entry_flight, entry_cnt); |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 3880 | SCTP_PRINTF("Flight size-express incorrect F: %d I: %d R: %d Ab: %d ACK: %d\n", |
Michael Tuexen | e19d122 | 2022-08-03 17:35:14 +0200 | [diff] [blame^] | 3881 | inflight, inbetween, resend, above, acked); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3882 | ret = 1; |
| 3883 | #endif |
| 3884 | } |
| 3885 | return (ret); |
| 3886 | } |
| 3887 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3888 | static void |
| 3889 | sctp_window_probe_recovery(struct sctp_tcb *stcb, |
Michael Tuexen | f7f9cd8 | 2020-09-24 15:14:13 +0200 | [diff] [blame] | 3890 | struct sctp_association *asoc, |
| 3891 | struct sctp_tmit_chunk *tp1) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3892 | { |
| 3893 | tp1->window_probe = 0; |
| 3894 | if ((tp1->sent >= SCTP_DATAGRAM_ACKED) || (tp1->data == NULL)) { |
| 3895 | /* TSN's skipped we do NOT move back. */ |
| 3896 | sctp_misc_ints(SCTP_FLIGHT_LOG_DWN_WP_FWD, |
t00fcxen | f95cdf4 | 2015-03-24 15:12:04 +0000 | [diff] [blame] | 3897 | tp1->whoTo ? tp1->whoTo->flight_size : 0, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3898 | tp1->book_size, |
Michael Tuexen | 95da8e5 | 2016-03-25 12:29:52 +0100 | [diff] [blame] | 3899 | (uint32_t)(uintptr_t)tp1->whoTo, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3900 | tp1->rec.data.tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3901 | return; |
| 3902 | } |
| 3903 | /* First setup this by shrinking flight */ |
| 3904 | if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { |
| 3905 | (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo, |
| 3906 | tp1); |
| 3907 | } |
| 3908 | sctp_flight_size_decrease(tp1); |
| 3909 | sctp_total_flight_decrease(stcb, tp1); |
| 3910 | /* Now mark for resend */ |
| 3911 | tp1->sent = SCTP_DATAGRAM_RESEND; |
| 3912 | sctp_ucount_incr(asoc->sent_queue_retran_cnt); |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 3913 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3914 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
| 3915 | sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_WP, |
| 3916 | tp1->whoTo->flight_size, |
| 3917 | tp1->book_size, |
Michael Tuexen | 95da8e5 | 2016-03-25 12:29:52 +0100 | [diff] [blame] | 3918 | (uint32_t)(uintptr_t)tp1->whoTo, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3919 | tp1->rec.data.tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | void |
| 3924 | sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, |
| 3925 | uint32_t rwnd, int *abort_now, int ecne_seen) |
| 3926 | { |
| 3927 | struct sctp_nets *net; |
| 3928 | struct sctp_association *asoc; |
| 3929 | struct sctp_tmit_chunk *tp1, *tp2; |
| 3930 | uint32_t old_rwnd; |
| 3931 | int win_probe_recovery = 0; |
| 3932 | int win_probe_recovered = 0; |
| 3933 | int j, done_once = 0; |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 3934 | int rto_ok = 1; |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 3935 | uint32_t send_s; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3936 | |
| 3937 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { |
| 3938 | sctp_misc_ints(SCTP_SACK_LOG_EXPRESS, cumack, |
| 3939 | rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); |
| 3940 | } |
| 3941 | SCTP_TCB_LOCK_ASSERT(stcb); |
| 3942 | #ifdef SCTP_ASOCLOG_OF_TSNS |
| 3943 | stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cumack; |
| 3944 | stcb->asoc.cumack_log_at++; |
| 3945 | if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { |
| 3946 | stcb->asoc.cumack_log_at = 0; |
| 3947 | } |
| 3948 | #endif |
| 3949 | asoc = &stcb->asoc; |
| 3950 | old_rwnd = asoc->peers_rwnd; |
| 3951 | if (SCTP_TSN_GT(asoc->last_acked_seq, cumack)) { |
| 3952 | /* old ack */ |
| 3953 | return; |
| 3954 | } else if (asoc->last_acked_seq == cumack) { |
| 3955 | /* Window update sack */ |
| 3956 | asoc->peers_rwnd = sctp_sbspace_sub(rwnd, |
| 3957 | (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); |
| 3958 | if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { |
| 3959 | /* SWS sender side engages */ |
| 3960 | asoc->peers_rwnd = 0; |
| 3961 | } |
| 3962 | if (asoc->peers_rwnd > old_rwnd) { |
| 3963 | goto again; |
| 3964 | } |
| 3965 | return; |
| 3966 | } |
| 3967 | |
| 3968 | /* First setup for CC stuff */ |
| 3969 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 3970 | if (SCTP_TSN_GT(cumack, net->cwr_window_tsn)) { |
| 3971 | /* Drag along the window_tsn for cwr's */ |
| 3972 | net->cwr_window_tsn = cumack; |
| 3973 | } |
| 3974 | net->prev_cwnd = net->cwnd; |
| 3975 | net->net_ack = 0; |
| 3976 | net->net_ack2 = 0; |
| 3977 | |
| 3978 | /* |
| 3979 | * CMT: Reset CUC and Fast recovery algo variables before |
| 3980 | * SACK processing |
| 3981 | */ |
| 3982 | net->new_pseudo_cumack = 0; |
| 3983 | net->will_exit_fast_recovery = 0; |
| 3984 | if (stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack) { |
| 3985 | (*stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack)(stcb, net); |
| 3986 | } |
| 3987 | } |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 3988 | if (!TAILQ_EMPTY(&asoc->sent_queue)) { |
| 3989 | tp1 = TAILQ_LAST(&asoc->sent_queue, |
| 3990 | sctpchunk_listhead); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 3991 | send_s = tp1->rec.data.tsn + 1; |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 3992 | } else { |
| 3993 | send_s = asoc->sending_seq; |
| 3994 | } |
| 3995 | if (SCTP_TSN_GE(cumack, send_s)) { |
| 3996 | struct mbuf *op_err; |
| 3997 | char msg[SCTP_DIAG_INFO_LEN]; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 3998 | |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 3999 | *abort_now = 1; |
| 4000 | /* XXX */ |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 4001 | SCTP_SNPRINTF(msg, sizeof(msg), |
| 4002 | "Cum ack %8.8x greater or equal than TSN %8.8x", |
| 4003 | cumack, send_s); |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4004 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 4005 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 4006 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4007 | return; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4008 | } |
| 4009 | asoc->this_sack_highest_gap = cumack; |
| 4010 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { |
| 4011 | sctp_misc_ints(SCTP_THRESHOLD_CLEAR, |
| 4012 | stcb->asoc.overall_error_count, |
| 4013 | 0, |
| 4014 | SCTP_FROM_SCTP_INDATA, |
| 4015 | __LINE__); |
| 4016 | } |
| 4017 | stcb->asoc.overall_error_count = 0; |
| 4018 | if (SCTP_TSN_GT(cumack, asoc->last_acked_seq)) { |
| 4019 | /* process the new consecutive TSN first */ |
| 4020 | TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4021 | if (SCTP_TSN_GE(cumack, tp1->rec.data.tsn)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4022 | if (tp1->sent == SCTP_DATAGRAM_UNSENT) { |
tuexen | cb5fe8d | 2012-05-04 09:50:27 +0000 | [diff] [blame] | 4023 | SCTP_PRINTF("Warning, an unsent is now acked?\n"); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4024 | } |
| 4025 | if (tp1->sent < SCTP_DATAGRAM_ACKED) { |
| 4026 | /* |
| 4027 | * If it is less than ACKED, it is |
| 4028 | * now no-longer in flight. Higher |
| 4029 | * values may occur during marking |
| 4030 | */ |
| 4031 | if (tp1->sent < SCTP_DATAGRAM_RESEND) { |
| 4032 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
| 4033 | sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, |
| 4034 | tp1->whoTo->flight_size, |
| 4035 | tp1->book_size, |
Michael Tuexen | 95da8e5 | 2016-03-25 12:29:52 +0100 | [diff] [blame] | 4036 | (uint32_t)(uintptr_t)tp1->whoTo, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4037 | tp1->rec.data.tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4038 | } |
| 4039 | sctp_flight_size_decrease(tp1); |
| 4040 | if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { |
| 4041 | (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo, |
| 4042 | tp1); |
| 4043 | } |
| 4044 | /* sa_ignore NO_NULL_CHK */ |
| 4045 | sctp_total_flight_decrease(stcb, tp1); |
| 4046 | } |
| 4047 | tp1->whoTo->net_ack += tp1->send_size; |
| 4048 | if (tp1->snd_count < 2) { |
| 4049 | /* |
Michael Tuexen | c51af97 | 2018-08-12 15:32:55 +0200 | [diff] [blame] | 4050 | * True non-retransmitted |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4051 | * chunk |
| 4052 | */ |
| 4053 | tp1->whoTo->net_ack2 += |
| 4054 | tp1->send_size; |
| 4055 | |
| 4056 | /* update RTO too? */ |
| 4057 | if (tp1->do_rtt) { |
Michael Tuexen | b7ed78b | 2019-09-22 12:48:36 +0200 | [diff] [blame] | 4058 | if (rto_ok && |
| 4059 | sctp_calculate_rto(stcb, |
| 4060 | &stcb->asoc, |
| 4061 | tp1->whoTo, |
| 4062 | &tp1->sent_rcv_time, |
| 4063 | SCTP_RTT_FROM_DATA)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4064 | rto_ok = 0; |
| 4065 | } |
| 4066 | if (tp1->whoTo->rto_needed == 0) { |
| 4067 | tp1->whoTo->rto_needed = 1; |
| 4068 | } |
| 4069 | tp1->do_rtt = 0; |
| 4070 | } |
| 4071 | } |
| 4072 | /* |
| 4073 | * CMT: CUCv2 algorithm. From the |
| 4074 | * cumack'd TSNs, for each TSN being |
| 4075 | * acked for the first time, set the |
| 4076 | * following variables for the |
| 4077 | * corresp destination. |
| 4078 | * new_pseudo_cumack will trigger a |
| 4079 | * cwnd update. |
| 4080 | * find_(rtx_)pseudo_cumack will |
| 4081 | * trigger search for the next |
| 4082 | * expected (rtx-)pseudo-cumack. |
| 4083 | */ |
| 4084 | tp1->whoTo->new_pseudo_cumack = 1; |
| 4085 | tp1->whoTo->find_pseudo_cumack = 1; |
| 4086 | tp1->whoTo->find_rtx_pseudo_cumack = 1; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4087 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
| 4088 | /* sa_ignore NO_NULL_CHK */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4089 | sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.tsn, SCTP_CWND_LOG_FROM_SACK); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4090 | } |
| 4091 | } |
| 4092 | if (tp1->sent == SCTP_DATAGRAM_RESEND) { |
| 4093 | sctp_ucount_decr(asoc->sent_queue_retran_cnt); |
| 4094 | } |
| 4095 | if (tp1->rec.data.chunk_was_revoked) { |
| 4096 | /* deflate the cwnd */ |
| 4097 | tp1->whoTo->cwnd -= tp1->book_size; |
| 4098 | tp1->rec.data.chunk_was_revoked = 0; |
| 4099 | } |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 4100 | if (tp1->sent != SCTP_DATAGRAM_NR_ACKED) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4101 | if (asoc->strmout[tp1->rec.data.sid].chunks_on_queues > 0) { |
| 4102 | asoc->strmout[tp1->rec.data.sid].chunks_on_queues--; |
t00fcxen | 9ad9077 | 2012-11-07 22:19:57 +0000 | [diff] [blame] | 4103 | #ifdef INVARIANTS |
| 4104 | } else { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4105 | panic("No chunks on the queues for sid %u.", tp1->rec.data.sid); |
t00fcxen | 9ad9077 | 2012-11-07 22:19:57 +0000 | [diff] [blame] | 4106 | #endif |
| 4107 | } |
| 4108 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4109 | if ((asoc->strmout[tp1->rec.data.sid].chunks_on_queues == 0) && |
| 4110 | (asoc->strmout[tp1->rec.data.sid].state == SCTP_STREAM_RESET_PENDING) && |
| 4111 | TAILQ_EMPTY(&asoc->strmout[tp1->rec.data.sid].outqueue)) { |
Michael Tuexen | c0a12d1 | 2015-12-03 16:30:24 +0100 | [diff] [blame] | 4112 | asoc->trigger_reset = 1; |
| 4113 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4114 | TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); |
| 4115 | if (tp1->data) { |
| 4116 | /* sa_ignore NO_NULL_CHK */ |
| 4117 | sctp_free_bufspace(stcb, asoc, tp1, 1); |
| 4118 | sctp_m_freem(tp1->data); |
| 4119 | tp1->data = NULL; |
| 4120 | } |
| 4121 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { |
| 4122 | sctp_log_sack(asoc->last_acked_seq, |
| 4123 | cumack, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4124 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4125 | 0, |
| 4126 | 0, |
| 4127 | SCTP_LOG_FREE_SENT); |
| 4128 | } |
| 4129 | asoc->sent_queue_cnt--; |
| 4130 | sctp_free_a_chunk(stcb, tp1, SCTP_SO_NOT_LOCKED); |
| 4131 | } else { |
| 4132 | break; |
| 4133 | } |
| 4134 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4135 | } |
tuexen | 6bffa9a | 2012-06-25 17:40:03 +0000 | [diff] [blame] | 4136 | #if defined(__Userspace__) |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4137 | if (stcb->sctp_ep->recv_callback) { |
| 4138 | if (stcb->sctp_socket) { |
| 4139 | uint32_t inqueue_bytes, sb_free_now; |
| 4140 | struct sctp_inpcb *inp; |
tuexen | 749d856 | 2011-11-13 13:41:49 +0000 | [diff] [blame] | 4141 | |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4142 | inp = stcb->sctp_ep; |
tuexen | 749d856 | 2011-11-13 13:41:49 +0000 | [diff] [blame] | 4143 | inqueue_bytes = stcb->asoc.total_output_queue_size - (stcb->asoc.chunks_on_out_queue * sizeof(struct sctp_data_chunk)); |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4144 | sb_free_now = SCTP_SB_LIMIT_SND(stcb->sctp_socket) - (inqueue_bytes + stcb->asoc.sb_send_resv); |
| 4145 | |
| 4146 | /* check if the amount free in the send socket buffer crossed the threshold */ |
| 4147 | if (inp->send_callback && |
| 4148 | (((inp->send_sb_threshold > 0) && |
| 4149 | (sb_free_now >= inp->send_sb_threshold) && |
| 4150 | (stcb->asoc.chunks_on_out_queue <= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue))) || |
| 4151 | (inp->send_sb_threshold == 0))) { |
| 4152 | atomic_add_int(&stcb->asoc.refcnt, 1); |
| 4153 | SCTP_TCB_UNLOCK(stcb); |
José Luis Millán | 3df8f52 | 2020-08-01 12:34:40 +0200 | [diff] [blame] | 4154 | inp->send_callback(stcb->sctp_socket, sb_free_now, inp->ulp_info); |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4155 | SCTP_TCB_LOCK(stcb); |
| 4156 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
| 4157 | } |
tuexen | 749d856 | 2011-11-13 13:41:49 +0000 | [diff] [blame] | 4158 | } |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4159 | } else if (stcb->sctp_socket) { |
tuexen | 749d856 | 2011-11-13 13:41:49 +0000 | [diff] [blame] | 4160 | #else |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4161 | /* sa_ignore NO_NULL_CHK */ |
| 4162 | if (stcb->sctp_socket) { |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4163 | #endif |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 4164 | #if defined(__APPLE__) && !defined(__Userspace__) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4165 | struct socket *so; |
| 4166 | |
| 4167 | #endif |
| 4168 | SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); |
| 4169 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { |
| 4170 | /* sa_ignore NO_NULL_CHK */ |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 4171 | sctp_wakeup_log(stcb, 1, SCTP_WAKESND_FROM_SACK); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4172 | } |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 4173 | #if defined(__APPLE__) && !defined(__Userspace__) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4174 | so = SCTP_INP_SO(stcb->sctp_ep); |
| 4175 | atomic_add_int(&stcb->asoc.refcnt, 1); |
| 4176 | SCTP_TCB_UNLOCK(stcb); |
| 4177 | SCTP_SOCKET_LOCK(so, 1); |
| 4178 | SCTP_TCB_LOCK(stcb); |
| 4179 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
| 4180 | if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { |
| 4181 | /* assoc was freed while we were unlocked */ |
| 4182 | SCTP_SOCKET_UNLOCK(so, 1); |
| 4183 | return; |
| 4184 | } |
| 4185 | #endif |
| 4186 | sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 4187 | #if defined(__APPLE__) && !defined(__Userspace__) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4188 | SCTP_SOCKET_UNLOCK(so, 1); |
| 4189 | #endif |
| 4190 | } else { |
| 4191 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 4192 | sctp_wakeup_log(stcb, 1, SCTP_NOWAKE_FROM_SACK); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | /* JRS - Use the congestion control given in the CC module */ |
| 4197 | if ((asoc->last_acked_seq != cumack) && (ecne_seen == 0)) { |
| 4198 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 4199 | if (net->net_ack2 > 0) { |
| 4200 | /* |
| 4201 | * Karn's rule applies to clearing error count, this |
| 4202 | * is optional. |
| 4203 | */ |
| 4204 | net->error_count = 0; |
Michael Tuexen | 8d6935d | 2022-05-15 01:51:24 +0200 | [diff] [blame] | 4205 | if ((net->dest_state & SCTP_ADDR_REACHABLE) == 0) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4206 | /* addr came good */ |
| 4207 | net->dest_state |= SCTP_ADDR_REACHABLE; |
| 4208 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, |
tuexen | da53ff0 | 2012-05-14 09:00:59 +0000 | [diff] [blame] | 4209 | 0, (void *)net, SCTP_SO_NOT_LOCKED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4210 | } |
| 4211 | if (net == stcb->asoc.primary_destination) { |
| 4212 | if (stcb->asoc.alternate) { |
| 4213 | /* release the alternate, primary is good */ |
| 4214 | sctp_free_remote_addr(stcb->asoc.alternate); |
| 4215 | stcb->asoc.alternate = NULL; |
| 4216 | } |
| 4217 | } |
| 4218 | if (net->dest_state & SCTP_ADDR_PF) { |
| 4219 | net->dest_state &= ~SCTP_ADDR_PF; |
t00fcxen | 0057a6d | 2015-05-28 16:42:49 +0000 | [diff] [blame] | 4220 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, |
| 4221 | stcb->sctp_ep, stcb, net, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 4222 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_26); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4223 | sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); |
| 4224 | asoc->cc_functions.sctp_cwnd_update_exit_pf(stcb, net); |
| 4225 | /* Done with this net */ |
| 4226 | net->net_ack = 0; |
| 4227 | } |
| 4228 | /* restore any doubled timers */ |
| 4229 | net->RTO = (net->lastsa >> SCTP_RTT_SHIFT) + net->lastsv; |
| 4230 | if (net->RTO < stcb->asoc.minrto) { |
| 4231 | net->RTO = stcb->asoc.minrto; |
| 4232 | } |
| 4233 | if (net->RTO > stcb->asoc.maxrto) { |
| 4234 | net->RTO = stcb->asoc.maxrto; |
| 4235 | } |
| 4236 | } |
| 4237 | } |
| 4238 | asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, 1, 0, 0); |
| 4239 | } |
| 4240 | asoc->last_acked_seq = cumack; |
| 4241 | |
| 4242 | if (TAILQ_EMPTY(&asoc->sent_queue)) { |
| 4243 | /* nothing left in-flight */ |
| 4244 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 4245 | net->flight_size = 0; |
| 4246 | net->partial_bytes_acked = 0; |
| 4247 | } |
| 4248 | asoc->total_flight = 0; |
| 4249 | asoc->total_flight_count = 0; |
| 4250 | } |
| 4251 | |
| 4252 | /* RWND update */ |
| 4253 | asoc->peers_rwnd = sctp_sbspace_sub(rwnd, |
| 4254 | (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); |
| 4255 | if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { |
| 4256 | /* SWS sender side engages */ |
| 4257 | asoc->peers_rwnd = 0; |
| 4258 | } |
| 4259 | if (asoc->peers_rwnd > old_rwnd) { |
| 4260 | win_probe_recovery = 1; |
| 4261 | } |
| 4262 | /* Now assure a timer where data is queued at */ |
| 4263 | again: |
| 4264 | j = 0; |
| 4265 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4266 | if (win_probe_recovery && (net->window_probe)) { |
| 4267 | win_probe_recovered = 1; |
| 4268 | /* |
| 4269 | * Find first chunk that was used with window probe |
| 4270 | * and clear the sent |
| 4271 | */ |
| 4272 | /* sa_ignore FREED_MEMORY */ |
| 4273 | TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { |
| 4274 | if (tp1->window_probe) { |
| 4275 | /* move back to data send queue */ |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 4276 | sctp_window_probe_recovery(stcb, asoc, tp1); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4277 | break; |
| 4278 | } |
| 4279 | } |
| 4280 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4281 | if (net->flight_size) { |
| 4282 | j++; |
Michael Tuexen | a7360a1 | 2017-09-17 11:30:34 +0200 | [diff] [blame] | 4283 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4284 | if (net->window_probe) { |
| 4285 | net->window_probe = 0; |
| 4286 | } |
| 4287 | } else { |
| 4288 | if (net->window_probe) { |
| 4289 | /* In window probes we must assure a timer is still running there */ |
| 4290 | net->window_probe = 0; |
| 4291 | if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { |
Michael Tuexen | a7360a1 | 2017-09-17 11:30:34 +0200 | [diff] [blame] | 4292 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4293 | } |
| 4294 | } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { |
| 4295 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, |
| 4296 | stcb, net, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 4297 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_27); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4298 | } |
| 4299 | } |
| 4300 | } |
| 4301 | if ((j == 0) && |
| 4302 | (!TAILQ_EMPTY(&asoc->sent_queue)) && |
| 4303 | (asoc->sent_queue_retran_cnt == 0) && |
| 4304 | (win_probe_recovered == 0) && |
| 4305 | (done_once == 0)) { |
| 4306 | /* huh, this should not happen unless all packets |
| 4307 | * are PR-SCTP and marked to skip of course. |
| 4308 | */ |
| 4309 | if (sctp_fs_audit(asoc)) { |
| 4310 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 4311 | net->flight_size = 0; |
| 4312 | } |
| 4313 | asoc->total_flight = 0; |
| 4314 | asoc->total_flight_count = 0; |
| 4315 | asoc->sent_queue_retran_cnt = 0; |
| 4316 | TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { |
| 4317 | if (tp1->sent < SCTP_DATAGRAM_RESEND) { |
| 4318 | sctp_flight_size_increase(tp1); |
| 4319 | sctp_total_flight_increase(stcb, tp1); |
| 4320 | } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { |
| 4321 | sctp_ucount_incr(asoc->sent_queue_retran_cnt); |
| 4322 | } |
| 4323 | } |
| 4324 | } |
| 4325 | done_once = 1; |
| 4326 | goto again; |
| 4327 | } |
| 4328 | /**********************************/ |
| 4329 | /* Now what about shutdown issues */ |
| 4330 | /**********************************/ |
| 4331 | if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { |
| 4332 | /* nothing left on sendqueue.. consider done */ |
| 4333 | /* clean up */ |
| 4334 | if ((asoc->stream_queue_cnt == 1) && |
| 4335 | ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 4336 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) && |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 4337 | ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete)(stcb, asoc))) { |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 4338 | SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4339 | } |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 4340 | if (((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 4341 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) && |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 4342 | (asoc->stream_queue_cnt == 1) && |
| 4343 | (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { |
| 4344 | struct mbuf *op_err; |
| 4345 | |
| 4346 | *abort_now = 1; |
| 4347 | /* XXX */ |
| 4348 | op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, ""); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 4349 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_28; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 4350 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 4351 | return; |
| 4352 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4353 | if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && |
| 4354 | (asoc->stream_queue_cnt == 0)) { |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 4355 | struct sctp_nets *netp; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4356 | |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 4357 | if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) || |
| 4358 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) { |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 4359 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4360 | } |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 4361 | SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT); |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 4362 | sctp_stop_timers_for_shutdown(stcb); |
| 4363 | if (asoc->alternate) { |
| 4364 | netp = asoc->alternate; |
| 4365 | } else { |
| 4366 | netp = asoc->primary_destination; |
| 4367 | } |
| 4368 | sctp_send_shutdown(stcb, netp); |
| 4369 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, |
| 4370 | stcb->sctp_ep, stcb, netp); |
| 4371 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, |
Michael Tuexen | d07a5f2 | 2020-03-19 23:34:46 +0100 | [diff] [blame] | 4372 | stcb->sctp_ep, stcb, NULL); |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 4373 | } else if ((SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED) && |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4374 | (asoc->stream_queue_cnt == 0)) { |
| 4375 | struct sctp_nets *netp; |
t00fcxen | d0ad16b | 2013-02-09 18:34:24 +0000 | [diff] [blame] | 4376 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4377 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 4378 | SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_ACK_SENT); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4379 | sctp_stop_timers_for_shutdown(stcb); |
t00fcxen | d0ad16b | 2013-02-09 18:34:24 +0000 | [diff] [blame] | 4380 | if (asoc->alternate) { |
| 4381 | netp = asoc->alternate; |
| 4382 | } else { |
| 4383 | netp = asoc->primary_destination; |
| 4384 | } |
| 4385 | sctp_send_shutdown_ack(stcb, netp); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4386 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, |
| 4387 | stcb->sctp_ep, stcb, netp); |
| 4388 | } |
| 4389 | } |
| 4390 | /*********************************************/ |
| 4391 | /* Here we perform PR-SCTP procedures */ |
| 4392 | /* (section 4.2) */ |
| 4393 | /*********************************************/ |
| 4394 | /* C1. update advancedPeerAckPoint */ |
| 4395 | if (SCTP_TSN_GT(cumack, asoc->advanced_peer_ack_point)) { |
| 4396 | asoc->advanced_peer_ack_point = cumack; |
| 4397 | } |
| 4398 | /* PR-Sctp issues need to be addressed too */ |
t00fcxen | 0e78cef | 2014-08-02 22:05:33 +0000 | [diff] [blame] | 4399 | if ((asoc->prsctp_supported) && (asoc->pr_sctp_cnt > 0)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4400 | struct sctp_tmit_chunk *lchk; |
| 4401 | uint32_t old_adv_peer_ack_point; |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 4402 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4403 | old_adv_peer_ack_point = asoc->advanced_peer_ack_point; |
| 4404 | lchk = sctp_try_advance_peer_ack_point(stcb, asoc); |
| 4405 | /* C3. See if we need to send a Fwd-TSN */ |
| 4406 | if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, cumack)) { |
| 4407 | /* |
| 4408 | * ISSUE with ECN, see FWD-TSN processing. |
| 4409 | */ |
| 4410 | if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, old_adv_peer_ack_point)) { |
| 4411 | send_forward_tsn(stcb, asoc); |
| 4412 | } else if (lchk) { |
| 4413 | /* try to FR fwd-tsn's that get lost too */ |
| 4414 | if (lchk->rec.data.fwd_tsn_cnt >= 3) { |
| 4415 | send_forward_tsn(stcb, asoc); |
| 4416 | } |
| 4417 | } |
| 4418 | } |
Michael Tuexen | a8f3d9d | 2020-05-10 19:35:08 +0200 | [diff] [blame] | 4419 | for (; lchk != NULL; lchk = TAILQ_NEXT(lchk, sctp_next)) { |
| 4420 | if (lchk->whoTo != NULL) { |
| 4421 | break; |
| 4422 | } |
| 4423 | } |
| 4424 | if (lchk != NULL) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4425 | /* Assure a timer is up */ |
| 4426 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, |
Michael Tuexen | a8f3d9d | 2020-05-10 19:35:08 +0200 | [diff] [blame] | 4427 | stcb->sctp_ep, stcb, lchk->whoTo); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4428 | } |
| 4429 | } |
| 4430 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { |
| 4431 | sctp_misc_ints(SCTP_SACK_RWND_UPDATE, |
| 4432 | rwnd, |
| 4433 | stcb->asoc.peers_rwnd, |
| 4434 | stcb->asoc.total_flight, |
| 4435 | stcb->asoc.total_output_queue_size); |
| 4436 | } |
| 4437 | } |
| 4438 | |
| 4439 | void |
| 4440 | sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup, |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 4441 | struct sctp_tcb *stcb, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4442 | uint16_t num_seg, uint16_t num_nr_seg, uint16_t num_dup, |
| 4443 | int *abort_now, uint8_t flags, |
| 4444 | uint32_t cum_ack, uint32_t rwnd, int ecne_seen) |
| 4445 | { |
| 4446 | struct sctp_association *asoc; |
| 4447 | struct sctp_tmit_chunk *tp1, *tp2; |
| 4448 | uint32_t last_tsn, biggest_tsn_acked, biggest_tsn_newly_acked, this_sack_lowest_newack; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4449 | uint16_t wake_him = 0; |
| 4450 | uint32_t send_s = 0; |
| 4451 | long j; |
| 4452 | int accum_moved = 0; |
| 4453 | int will_exit_fast_recovery = 0; |
| 4454 | uint32_t a_rwnd, old_rwnd; |
| 4455 | int win_probe_recovery = 0; |
| 4456 | int win_probe_recovered = 0; |
| 4457 | struct sctp_nets *net = NULL; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4458 | int done_once; |
tuexen | 63fc0bb | 2011-12-27 12:24:52 +0000 | [diff] [blame] | 4459 | int rto_ok = 1; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4460 | uint8_t reneged_all = 0; |
| 4461 | uint8_t cmt_dac_flag; |
| 4462 | /* |
| 4463 | * we take any chance we can to service our queues since we cannot |
| 4464 | * get awoken when the socket is read from :< |
| 4465 | */ |
| 4466 | /* |
| 4467 | * Now perform the actual SACK handling: 1) Verify that it is not an |
| 4468 | * old sack, if so discard. 2) If there is nothing left in the send |
| 4469 | * queue (cum-ack is equal to last acked) then you have a duplicate |
| 4470 | * too, update any rwnd change and verify no timers are running. |
David Sanders | b519f51 | 2022-03-29 13:55:16 -0700 | [diff] [blame] | 4471 | * then return. 3) Process any new consecutive data i.e. cum-ack |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4472 | * moved process these first and note that it moved. 4) Process any |
| 4473 | * sack blocks. 5) Drop any acked from the queue. 6) Check for any |
| 4474 | * revoked blocks and mark. 7) Update the cwnd. 8) Nothing left, |
| 4475 | * sync up flightsizes and things, stop all timers and also check |
| 4476 | * for shutdown_pending state. If so then go ahead and send off the |
| 4477 | * shutdown. If in shutdown recv, send off the shutdown-ack and |
| 4478 | * start that timer, Ret. 9) Strike any non-acked things and do FR |
| 4479 | * procedure if needed being sure to set the FR flag. 10) Do pr-sctp |
| 4480 | * procedures. 11) Apply any FR penalties. 12) Assure we will SACK |
| 4481 | * if in shutdown_recv state. |
| 4482 | */ |
| 4483 | SCTP_TCB_LOCK_ASSERT(stcb); |
| 4484 | /* CMT DAC algo */ |
| 4485 | this_sack_lowest_newack = 0; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4486 | SCTP_STAT_INCR(sctps_slowpath_sack); |
| 4487 | last_tsn = cum_ack; |
| 4488 | cmt_dac_flag = flags & SCTP_SACK_CMT_DAC; |
| 4489 | #ifdef SCTP_ASOCLOG_OF_TSNS |
| 4490 | stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cum_ack; |
| 4491 | stcb->asoc.cumack_log_at++; |
| 4492 | if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) { |
| 4493 | stcb->asoc.cumack_log_at = 0; |
| 4494 | } |
| 4495 | #endif |
| 4496 | a_rwnd = rwnd; |
| 4497 | |
| 4498 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) { |
| 4499 | sctp_misc_ints(SCTP_SACK_LOG_NORMAL, cum_ack, |
| 4500 | rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd); |
| 4501 | } |
| 4502 | |
| 4503 | old_rwnd = stcb->asoc.peers_rwnd; |
| 4504 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { |
| 4505 | sctp_misc_ints(SCTP_THRESHOLD_CLEAR, |
| 4506 | stcb->asoc.overall_error_count, |
| 4507 | 0, |
| 4508 | SCTP_FROM_SCTP_INDATA, |
| 4509 | __LINE__); |
| 4510 | } |
| 4511 | stcb->asoc.overall_error_count = 0; |
| 4512 | asoc = &stcb->asoc; |
| 4513 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { |
| 4514 | sctp_log_sack(asoc->last_acked_seq, |
| 4515 | cum_ack, |
| 4516 | 0, |
| 4517 | num_seg, |
| 4518 | num_dup, |
| 4519 | SCTP_LOG_NEW_SACK); |
| 4520 | } |
| 4521 | if ((num_dup) && (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE)) { |
| 4522 | uint16_t i; |
| 4523 | uint32_t *dupdata, dblock; |
| 4524 | |
| 4525 | for (i = 0; i < num_dup; i++) { |
| 4526 | dupdata = (uint32_t *)sctp_m_getptr(m, offset_dup + i * sizeof(uint32_t), |
| 4527 | sizeof(uint32_t), (uint8_t *)&dblock); |
| 4528 | if (dupdata == NULL) { |
| 4529 | break; |
| 4530 | } |
| 4531 | sctp_log_fr(*dupdata, 0, 0, SCTP_FR_DUPED); |
| 4532 | } |
| 4533 | } |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4534 | /* reality check */ |
| 4535 | if (!TAILQ_EMPTY(&asoc->sent_queue)) { |
| 4536 | tp1 = TAILQ_LAST(&asoc->sent_queue, |
| 4537 | sctpchunk_listhead); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4538 | send_s = tp1->rec.data.tsn + 1; |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4539 | } else { |
| 4540 | tp1 = NULL; |
| 4541 | send_s = asoc->sending_seq; |
| 4542 | } |
| 4543 | if (SCTP_TSN_GE(cum_ack, send_s)) { |
| 4544 | struct mbuf *op_err; |
| 4545 | char msg[SCTP_DIAG_INFO_LEN]; |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 4546 | |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4547 | /* |
| 4548 | * no way, we have not even sent this TSN out yet. |
| 4549 | * Peer is hopelessly messed up with us. |
| 4550 | */ |
| 4551 | SCTP_PRINTF("NEW cum_ack:%x send_s:%x is smaller or equal\n", |
| 4552 | cum_ack, send_s); |
| 4553 | if (tp1) { |
| 4554 | SCTP_PRINTF("Got send_s from tsn:%x + 1 of tp1: %p\n", |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4555 | tp1->rec.data.tsn, (void *)tp1); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4556 | } |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4557 | hopeless_peer: |
| 4558 | *abort_now = 1; |
| 4559 | /* XXX */ |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 4560 | SCTP_SNPRINTF(msg, sizeof(msg), |
| 4561 | "Cum ack %8.8x greater or equal than TSN %8.8x", |
| 4562 | cum_ack, send_s); |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4563 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 4564 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_29; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 4565 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4566 | return; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4567 | } |
| 4568 | /**********************/ |
| 4569 | /* 1) check the range */ |
| 4570 | /**********************/ |
| 4571 | if (SCTP_TSN_GT(asoc->last_acked_seq, last_tsn)) { |
| 4572 | /* acking something behind */ |
| 4573 | return; |
| 4574 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4575 | |
| 4576 | /* update the Rwnd of the peer */ |
| 4577 | if (TAILQ_EMPTY(&asoc->sent_queue) && |
| 4578 | TAILQ_EMPTY(&asoc->send_queue) && |
| 4579 | (asoc->stream_queue_cnt == 0)) { |
| 4580 | /* nothing left on send/sent and strmq */ |
| 4581 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { |
| 4582 | sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, |
| 4583 | asoc->peers_rwnd, 0, 0, a_rwnd); |
| 4584 | } |
| 4585 | asoc->peers_rwnd = a_rwnd; |
| 4586 | if (asoc->sent_queue_retran_cnt) { |
| 4587 | asoc->sent_queue_retran_cnt = 0; |
| 4588 | } |
| 4589 | if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { |
| 4590 | /* SWS sender side engages */ |
| 4591 | asoc->peers_rwnd = 0; |
| 4592 | } |
| 4593 | /* stop any timers */ |
| 4594 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 4595 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 4596 | stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_30); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4597 | net->partial_bytes_acked = 0; |
| 4598 | net->flight_size = 0; |
| 4599 | } |
| 4600 | asoc->total_flight = 0; |
| 4601 | asoc->total_flight_count = 0; |
| 4602 | return; |
| 4603 | } |
| 4604 | /* |
| 4605 | * We init netAckSz and netAckSz2 to 0. These are used to track 2 |
| 4606 | * things. The total byte count acked is tracked in netAckSz AND |
| 4607 | * netAck2 is used to track the total bytes acked that are un- |
David Sanders | b519f51 | 2022-03-29 13:55:16 -0700 | [diff] [blame] | 4608 | * ambiguous and were never retransmitted. We track these on a per |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4609 | * destination address basis. |
| 4610 | */ |
| 4611 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 4612 | if (SCTP_TSN_GT(cum_ack, net->cwr_window_tsn)) { |
| 4613 | /* Drag along the window_tsn for cwr's */ |
| 4614 | net->cwr_window_tsn = cum_ack; |
| 4615 | } |
| 4616 | net->prev_cwnd = net->cwnd; |
| 4617 | net->net_ack = 0; |
| 4618 | net->net_ack2 = 0; |
| 4619 | |
| 4620 | /* |
| 4621 | * CMT: Reset CUC and Fast recovery algo variables before |
| 4622 | * SACK processing |
| 4623 | */ |
| 4624 | net->new_pseudo_cumack = 0; |
| 4625 | net->will_exit_fast_recovery = 0; |
| 4626 | if (stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack) { |
| 4627 | (*stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack)(stcb, net); |
| 4628 | } |
Michael Tuexen | 83714a8 | 2018-01-16 23:02:09 +0100 | [diff] [blame] | 4629 | |
| 4630 | /* |
| 4631 | * CMT: SFR algo (and HTNA) - this_sack_highest_newack has |
| 4632 | * to be greater than the cumack. Also reset saw_newack to 0 |
| 4633 | * for all dests. |
| 4634 | */ |
| 4635 | net->saw_newack = 0; |
| 4636 | net->this_sack_highest_newack = last_tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4637 | } |
| 4638 | /* process the new consecutive TSN first */ |
| 4639 | TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4640 | if (SCTP_TSN_GE(last_tsn, tp1->rec.data.tsn)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4641 | if (tp1->sent != SCTP_DATAGRAM_UNSENT) { |
| 4642 | accum_moved = 1; |
| 4643 | if (tp1->sent < SCTP_DATAGRAM_ACKED) { |
| 4644 | /* |
| 4645 | * If it is less than ACKED, it is |
| 4646 | * now no-longer in flight. Higher |
| 4647 | * values may occur during marking |
| 4648 | */ |
| 4649 | if ((tp1->whoTo->dest_state & |
| 4650 | SCTP_ADDR_UNCONFIRMED) && |
| 4651 | (tp1->snd_count < 2)) { |
| 4652 | /* |
| 4653 | * If there was no retran |
| 4654 | * and the address is |
| 4655 | * un-confirmed and we sent |
| 4656 | * there and are now |
| 4657 | * sacked.. its confirmed, |
| 4658 | * mark it so. |
| 4659 | */ |
| 4660 | tp1->whoTo->dest_state &= |
| 4661 | ~SCTP_ADDR_UNCONFIRMED; |
| 4662 | } |
| 4663 | if (tp1->sent < SCTP_DATAGRAM_RESEND) { |
| 4664 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
| 4665 | sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, |
| 4666 | tp1->whoTo->flight_size, |
| 4667 | tp1->book_size, |
Michael Tuexen | 95da8e5 | 2016-03-25 12:29:52 +0100 | [diff] [blame] | 4668 | (uint32_t)(uintptr_t)tp1->whoTo, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4669 | tp1->rec.data.tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4670 | } |
| 4671 | sctp_flight_size_decrease(tp1); |
| 4672 | sctp_total_flight_decrease(stcb, tp1); |
| 4673 | if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) { |
| 4674 | (*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo, |
| 4675 | tp1); |
| 4676 | } |
| 4677 | } |
| 4678 | tp1->whoTo->net_ack += tp1->send_size; |
| 4679 | |
| 4680 | /* CMT SFR and DAC algos */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4681 | this_sack_lowest_newack = tp1->rec.data.tsn; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4682 | tp1->whoTo->saw_newack = 1; |
| 4683 | |
| 4684 | if (tp1->snd_count < 2) { |
| 4685 | /* |
Michael Tuexen | c51af97 | 2018-08-12 15:32:55 +0200 | [diff] [blame] | 4686 | * True non-retransmitted |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4687 | * chunk |
| 4688 | */ |
| 4689 | tp1->whoTo->net_ack2 += |
| 4690 | tp1->send_size; |
| 4691 | |
| 4692 | /* update RTO too? */ |
| 4693 | if (tp1->do_rtt) { |
Michael Tuexen | b7ed78b | 2019-09-22 12:48:36 +0200 | [diff] [blame] | 4694 | if (rto_ok && |
| 4695 | sctp_calculate_rto(stcb, |
| 4696 | &stcb->asoc, |
| 4697 | tp1->whoTo, |
| 4698 | &tp1->sent_rcv_time, |
| 4699 | SCTP_RTT_FROM_DATA)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4700 | rto_ok = 0; |
| 4701 | } |
| 4702 | if (tp1->whoTo->rto_needed == 0) { |
| 4703 | tp1->whoTo->rto_needed = 1; |
| 4704 | } |
| 4705 | tp1->do_rtt = 0; |
| 4706 | } |
| 4707 | } |
| 4708 | /* |
| 4709 | * CMT: CUCv2 algorithm. From the |
| 4710 | * cumack'd TSNs, for each TSN being |
| 4711 | * acked for the first time, set the |
| 4712 | * following variables for the |
| 4713 | * corresp destination. |
| 4714 | * new_pseudo_cumack will trigger a |
| 4715 | * cwnd update. |
| 4716 | * find_(rtx_)pseudo_cumack will |
| 4717 | * trigger search for the next |
| 4718 | * expected (rtx-)pseudo-cumack. |
| 4719 | */ |
| 4720 | tp1->whoTo->new_pseudo_cumack = 1; |
| 4721 | tp1->whoTo->find_pseudo_cumack = 1; |
| 4722 | tp1->whoTo->find_rtx_pseudo_cumack = 1; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4723 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { |
| 4724 | sctp_log_sack(asoc->last_acked_seq, |
| 4725 | cum_ack, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4726 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4727 | 0, |
| 4728 | 0, |
| 4729 | SCTP_LOG_TSN_ACKED); |
| 4730 | } |
| 4731 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4732 | sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.tsn, SCTP_CWND_LOG_FROM_SACK); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4733 | } |
| 4734 | } |
| 4735 | if (tp1->sent == SCTP_DATAGRAM_RESEND) { |
| 4736 | sctp_ucount_decr(asoc->sent_queue_retran_cnt); |
| 4737 | #ifdef SCTP_AUDITING_ENABLED |
| 4738 | sctp_audit_log(0xB3, |
| 4739 | (asoc->sent_queue_retran_cnt & 0x000000ff)); |
| 4740 | #endif |
| 4741 | } |
| 4742 | if (tp1->rec.data.chunk_was_revoked) { |
| 4743 | /* deflate the cwnd */ |
| 4744 | tp1->whoTo->cwnd -= tp1->book_size; |
| 4745 | tp1->rec.data.chunk_was_revoked = 0; |
| 4746 | } |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 4747 | if (tp1->sent != SCTP_DATAGRAM_NR_ACKED) { |
| 4748 | tp1->sent = SCTP_DATAGRAM_ACKED; |
| 4749 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4750 | } |
| 4751 | } else { |
| 4752 | break; |
| 4753 | } |
| 4754 | } |
| 4755 | biggest_tsn_newly_acked = biggest_tsn_acked = last_tsn; |
| 4756 | /* always set this up to cum-ack */ |
| 4757 | asoc->this_sack_highest_gap = last_tsn; |
| 4758 | |
| 4759 | if ((num_seg > 0) || (num_nr_seg > 0)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4760 | /* |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4761 | * thisSackHighestGap will increase while handling NEW |
| 4762 | * segments this_sack_highest_newack will increase while |
| 4763 | * handling NEWLY ACKED chunks. this_sack_lowest_newack is |
| 4764 | * used for CMT DAC algo. saw_newack will also change. |
| 4765 | */ |
| 4766 | if (sctp_handle_segments(m, &offset_seg, stcb, asoc, last_tsn, &biggest_tsn_acked, |
| 4767 | &biggest_tsn_newly_acked, &this_sack_lowest_newack, |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 4768 | num_seg, num_nr_seg, &rto_ok)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4769 | wake_him++; |
| 4770 | } |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4771 | /* |
| 4772 | * validate the biggest_tsn_acked in the gap acks if |
| 4773 | * strict adherence is wanted. |
| 4774 | */ |
| 4775 | if (SCTP_TSN_GE(biggest_tsn_acked, send_s)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4776 | /* |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4777 | * peer is either confused or we are under |
| 4778 | * attack. We must abort. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4779 | */ |
Michael Tuexen | 0ec2150 | 2016-05-12 18:39:01 +0200 | [diff] [blame] | 4780 | SCTP_PRINTF("Hopeless peer! biggest_tsn_acked:%x largest seq:%x\n", |
| 4781 | biggest_tsn_acked, send_s); |
| 4782 | goto hopeless_peer; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | /*******************************************/ |
| 4786 | /* cancel ALL T3-send timer if accum moved */ |
| 4787 | /*******************************************/ |
| 4788 | if (asoc->sctp_cmt_on_off > 0) { |
| 4789 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 4790 | if (net->new_pseudo_cumack) |
| 4791 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, |
| 4792 | stcb, net, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 4793 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_31); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4794 | } |
| 4795 | } else { |
| 4796 | if (accum_moved) { |
| 4797 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 4798 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 4799 | stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4800 | } |
| 4801 | } |
| 4802 | } |
| 4803 | /********************************************/ |
| 4804 | /* drop the acked chunks from the sentqueue */ |
| 4805 | /********************************************/ |
| 4806 | asoc->last_acked_seq = cum_ack; |
| 4807 | |
| 4808 | TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4809 | if (SCTP_TSN_GT(tp1->rec.data.tsn, cum_ack)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4810 | break; |
| 4811 | } |
t00fcxen | 8fcc514 | 2012-11-16 19:46:12 +0000 | [diff] [blame] | 4812 | if (tp1->sent != SCTP_DATAGRAM_NR_ACKED) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4813 | if (asoc->strmout[tp1->rec.data.sid].chunks_on_queues > 0) { |
| 4814 | asoc->strmout[tp1->rec.data.sid].chunks_on_queues--; |
t00fcxen | 9ad9077 | 2012-11-07 22:19:57 +0000 | [diff] [blame] | 4815 | #ifdef INVARIANTS |
| 4816 | } else { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4817 | panic("No chunks on the queues for sid %u.", tp1->rec.data.sid); |
t00fcxen | 9ad9077 | 2012-11-07 22:19:57 +0000 | [diff] [blame] | 4818 | #endif |
| 4819 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4820 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4821 | if ((asoc->strmout[tp1->rec.data.sid].chunks_on_queues == 0) && |
| 4822 | (asoc->strmout[tp1->rec.data.sid].state == SCTP_STREAM_RESET_PENDING) && |
| 4823 | TAILQ_EMPTY(&asoc->strmout[tp1->rec.data.sid].outqueue)) { |
Michael Tuexen | c0a12d1 | 2015-12-03 16:30:24 +0100 | [diff] [blame] | 4824 | asoc->trigger_reset = 1; |
| 4825 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4826 | TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next); |
t00fcxen | 91ceb73 | 2013-09-03 19:40:11 +0000 | [diff] [blame] | 4827 | if (PR_SCTP_ENABLED(tp1->flags)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4828 | if (asoc->pr_sctp_cnt != 0) |
| 4829 | asoc->pr_sctp_cnt--; |
| 4830 | } |
| 4831 | asoc->sent_queue_cnt--; |
| 4832 | if (tp1->data) { |
| 4833 | /* sa_ignore NO_NULL_CHK */ |
| 4834 | sctp_free_bufspace(stcb, asoc, tp1, 1); |
| 4835 | sctp_m_freem(tp1->data); |
| 4836 | tp1->data = NULL; |
t00fcxen | 0e78cef | 2014-08-02 22:05:33 +0000 | [diff] [blame] | 4837 | if (asoc->prsctp_supported && PR_SCTP_BUF_ENABLED(tp1->flags)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4838 | asoc->sent_queue_cnt_removeable--; |
| 4839 | } |
| 4840 | } |
| 4841 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) { |
| 4842 | sctp_log_sack(asoc->last_acked_seq, |
| 4843 | cum_ack, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4844 | tp1->rec.data.tsn, |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4845 | 0, |
| 4846 | 0, |
| 4847 | SCTP_LOG_FREE_SENT); |
| 4848 | } |
| 4849 | sctp_free_a_chunk(stcb, tp1, SCTP_SO_NOT_LOCKED); |
| 4850 | wake_him++; |
| 4851 | } |
| 4852 | if (TAILQ_EMPTY(&asoc->sent_queue) && (asoc->total_flight > 0)) { |
| 4853 | #ifdef INVARIANTS |
Michael Tuexen | 34488e7 | 2016-05-03 22:11:59 +0200 | [diff] [blame] | 4854 | panic("Warning flight size is positive and should be 0"); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4855 | #else |
| 4856 | SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n", |
| 4857 | asoc->total_flight); |
| 4858 | #endif |
| 4859 | asoc->total_flight = 0; |
| 4860 | } |
| 4861 | |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4862 | #if defined(__Userspace__) |
| 4863 | if (stcb->sctp_ep->recv_callback) { |
| 4864 | if (stcb->sctp_socket) { |
| 4865 | uint32_t inqueue_bytes, sb_free_now; |
| 4866 | struct sctp_inpcb *inp; |
tuexen | 749d856 | 2011-11-13 13:41:49 +0000 | [diff] [blame] | 4867 | |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4868 | inp = stcb->sctp_ep; |
tuexen | 749d856 | 2011-11-13 13:41:49 +0000 | [diff] [blame] | 4869 | inqueue_bytes = stcb->asoc.total_output_queue_size - (stcb->asoc.chunks_on_out_queue * sizeof(struct sctp_data_chunk)); |
tuexen | 1ee04c8 | 2012-04-19 16:35:13 +0000 | [diff] [blame] | 4870 | sb_free_now = SCTP_SB_LIMIT_SND(stcb->sctp_socket) - (inqueue_bytes + stcb->asoc.sb_send_resv); |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4871 | |
| 4872 | /* check if the amount free in the send socket buffer crossed the threshold */ |
| 4873 | if (inp->send_callback && |
| 4874 | (((inp->send_sb_threshold > 0) && (sb_free_now >= inp->send_sb_threshold)) || |
| 4875 | (inp->send_sb_threshold == 0))) { |
| 4876 | atomic_add_int(&stcb->asoc.refcnt, 1); |
| 4877 | SCTP_TCB_UNLOCK(stcb); |
José Luis Millán | 3df8f52 | 2020-08-01 12:34:40 +0200 | [diff] [blame] | 4878 | inp->send_callback(stcb->sctp_socket, sb_free_now, inp->ulp_info); |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4879 | SCTP_TCB_LOCK(stcb); |
| 4880 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
| 4881 | } |
tuexen | 749d856 | 2011-11-13 13:41:49 +0000 | [diff] [blame] | 4882 | } |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4883 | } else if ((wake_him) && (stcb->sctp_socket)) { |
tuexen | 749d856 | 2011-11-13 13:41:49 +0000 | [diff] [blame] | 4884 | #else |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4885 | /* sa_ignore NO_NULL_CHK */ |
| 4886 | if ((wake_him) && (stcb->sctp_socket)) { |
tuexen | 98456cf | 2012-04-19 15:37:07 +0000 | [diff] [blame] | 4887 | #endif |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 4888 | #if defined(__APPLE__) && !defined(__Userspace__) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4889 | struct socket *so; |
| 4890 | |
| 4891 | #endif |
| 4892 | SOCKBUF_LOCK(&stcb->sctp_socket->so_snd); |
| 4893 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 4894 | sctp_wakeup_log(stcb, wake_him, SCTP_WAKESND_FROM_SACK); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4895 | } |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 4896 | #if defined(__APPLE__) && !defined(__Userspace__) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4897 | so = SCTP_INP_SO(stcb->sctp_ep); |
| 4898 | atomic_add_int(&stcb->asoc.refcnt, 1); |
| 4899 | SCTP_TCB_UNLOCK(stcb); |
| 4900 | SCTP_SOCKET_LOCK(so, 1); |
| 4901 | SCTP_TCB_LOCK(stcb); |
| 4902 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
| 4903 | if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { |
| 4904 | /* assoc was freed while we were unlocked */ |
| 4905 | SCTP_SOCKET_UNLOCK(so, 1); |
| 4906 | return; |
| 4907 | } |
| 4908 | #endif |
| 4909 | sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket); |
Michael Tuexen | 5be0c25 | 2020-06-13 00:53:56 +0200 | [diff] [blame] | 4910 | #if defined(__APPLE__) && !defined(__Userspace__) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4911 | SCTP_SOCKET_UNLOCK(so, 1); |
| 4912 | #endif |
| 4913 | } else { |
| 4914 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_WAKE_LOGGING_ENABLE) { |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 4915 | sctp_wakeup_log(stcb, wake_him, SCTP_NOWAKE_FROM_SACK); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4916 | } |
| 4917 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4918 | |
| 4919 | if (asoc->fast_retran_loss_recovery && accum_moved) { |
| 4920 | if (SCTP_TSN_GE(asoc->last_acked_seq, asoc->fast_recovery_tsn)) { |
| 4921 | /* Setup so we will exit RFC2582 fast recovery */ |
| 4922 | will_exit_fast_recovery = 1; |
| 4923 | } |
| 4924 | } |
| 4925 | /* |
| 4926 | * Check for revoked fragments: |
| 4927 | * |
| 4928 | * if Previous sack - Had no frags then we can't have any revoked if |
| 4929 | * Previous sack - Had frag's then - If we now have frags aka |
| 4930 | * num_seg > 0 call sctp_check_for_revoked() to tell if peer revoked |
| 4931 | * some of them. else - The peer revoked all ACKED fragments, since |
| 4932 | * we had some before and now we have NONE. |
| 4933 | */ |
| 4934 | |
| 4935 | if (num_seg) { |
| 4936 | sctp_check_for_revoked(stcb, asoc, cum_ack, biggest_tsn_acked); |
| 4937 | asoc->saw_sack_with_frags = 1; |
| 4938 | } else if (asoc->saw_sack_with_frags) { |
| 4939 | int cnt_revoked = 0; |
| 4940 | |
| 4941 | /* Peer revoked all dg's marked or acked */ |
| 4942 | TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { |
| 4943 | if (tp1->sent == SCTP_DATAGRAM_ACKED) { |
| 4944 | tp1->sent = SCTP_DATAGRAM_SENT; |
| 4945 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
| 4946 | sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, |
| 4947 | tp1->whoTo->flight_size, |
| 4948 | tp1->book_size, |
Michael Tuexen | 95da8e5 | 2016-03-25 12:29:52 +0100 | [diff] [blame] | 4949 | (uint32_t)(uintptr_t)tp1->whoTo, |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 4950 | tp1->rec.data.tsn); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4951 | } |
| 4952 | sctp_flight_size_increase(tp1); |
| 4953 | sctp_total_flight_increase(stcb, tp1); |
| 4954 | tp1->rec.data.chunk_was_revoked = 1; |
| 4955 | /* |
| 4956 | * To ensure that this increase in |
| 4957 | * flightsize, which is artificial, |
| 4958 | * does not throttle the sender, we |
| 4959 | * also increase the cwnd |
| 4960 | * artificially. |
| 4961 | */ |
| 4962 | tp1->whoTo->cwnd += tp1->book_size; |
| 4963 | cnt_revoked++; |
| 4964 | } |
| 4965 | } |
| 4966 | if (cnt_revoked) { |
| 4967 | reneged_all = 1; |
| 4968 | } |
| 4969 | asoc->saw_sack_with_frags = 0; |
| 4970 | } |
| 4971 | if (num_nr_seg > 0) |
| 4972 | asoc->saw_sack_with_nr_frags = 1; |
| 4973 | else |
| 4974 | asoc->saw_sack_with_nr_frags = 0; |
| 4975 | |
| 4976 | /* JRS - Use the congestion control given in the CC module */ |
| 4977 | if (ecne_seen == 0) { |
| 4978 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 4979 | if (net->net_ack2 > 0) { |
| 4980 | /* |
| 4981 | * Karn's rule applies to clearing error count, this |
| 4982 | * is optional. |
| 4983 | */ |
| 4984 | net->error_count = 0; |
Michael Tuexen | 8d6935d | 2022-05-15 01:51:24 +0200 | [diff] [blame] | 4985 | if ((net->dest_state & SCTP_ADDR_REACHABLE) == 0) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4986 | /* addr came good */ |
| 4987 | net->dest_state |= SCTP_ADDR_REACHABLE; |
| 4988 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, |
tuexen | da53ff0 | 2012-05-14 09:00:59 +0000 | [diff] [blame] | 4989 | 0, (void *)net, SCTP_SO_NOT_LOCKED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | if (net == stcb->asoc.primary_destination) { |
| 4993 | if (stcb->asoc.alternate) { |
| 4994 | /* release the alternate, primary is good */ |
| 4995 | sctp_free_remote_addr(stcb->asoc.alternate); |
| 4996 | stcb->asoc.alternate = NULL; |
| 4997 | } |
| 4998 | } |
| 4999 | |
| 5000 | if (net->dest_state & SCTP_ADDR_PF) { |
| 5001 | net->dest_state &= ~SCTP_ADDR_PF; |
t00fcxen | 0057a6d | 2015-05-28 16:42:49 +0000 | [diff] [blame] | 5002 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, |
| 5003 | stcb->sctp_ep, stcb, net, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 5004 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_33); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5005 | sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); |
| 5006 | asoc->cc_functions.sctp_cwnd_update_exit_pf(stcb, net); |
| 5007 | /* Done with this net */ |
| 5008 | net->net_ack = 0; |
| 5009 | } |
| 5010 | /* restore any doubled timers */ |
| 5011 | net->RTO = (net->lastsa >> SCTP_RTT_SHIFT) + net->lastsv; |
| 5012 | if (net->RTO < stcb->asoc.minrto) { |
| 5013 | net->RTO = stcb->asoc.minrto; |
| 5014 | } |
| 5015 | if (net->RTO > stcb->asoc.maxrto) { |
| 5016 | net->RTO = stcb->asoc.maxrto; |
| 5017 | } |
| 5018 | } |
| 5019 | } |
| 5020 | asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, accum_moved, reneged_all, will_exit_fast_recovery); |
| 5021 | } |
| 5022 | |
| 5023 | if (TAILQ_EMPTY(&asoc->sent_queue)) { |
| 5024 | /* nothing left in-flight */ |
| 5025 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 5026 | /* stop all timers */ |
| 5027 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, |
t00fcxen | 0057a6d | 2015-05-28 16:42:49 +0000 | [diff] [blame] | 5028 | stcb, net, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 5029 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_34); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5030 | net->flight_size = 0; |
| 5031 | net->partial_bytes_acked = 0; |
| 5032 | } |
| 5033 | asoc->total_flight = 0; |
| 5034 | asoc->total_flight_count = 0; |
| 5035 | } |
| 5036 | |
| 5037 | /**********************************/ |
| 5038 | /* Now what about shutdown issues */ |
| 5039 | /**********************************/ |
| 5040 | if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) { |
| 5041 | /* nothing left on sendqueue.. consider done */ |
| 5042 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { |
| 5043 | sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, |
| 5044 | asoc->peers_rwnd, 0, 0, a_rwnd); |
| 5045 | } |
| 5046 | asoc->peers_rwnd = a_rwnd; |
| 5047 | if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { |
| 5048 | /* SWS sender side engages */ |
| 5049 | asoc->peers_rwnd = 0; |
| 5050 | } |
| 5051 | /* clean up */ |
| 5052 | if ((asoc->stream_queue_cnt == 1) && |
| 5053 | ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 5054 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) && |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5055 | ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete)(stcb, asoc))) { |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 5056 | SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5057 | } |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 5058 | if (((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 5059 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) && |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 5060 | (asoc->stream_queue_cnt == 1) && |
| 5061 | (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { |
| 5062 | struct mbuf *op_err; |
| 5063 | |
| 5064 | *abort_now = 1; |
| 5065 | /* XXX */ |
| 5066 | op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, ""); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 5067 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_35; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 5068 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 5069 | return; |
| 5070 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5071 | if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) && |
| 5072 | (asoc->stream_queue_cnt == 0)) { |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 5073 | struct sctp_nets *netp; |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 5074 | |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 5075 | if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) || |
| 5076 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) { |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 5077 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5078 | } |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 5079 | SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT); |
Michael Tuexen | 74842cb | 2017-07-20 13:15:46 +0200 | [diff] [blame] | 5080 | sctp_stop_timers_for_shutdown(stcb); |
| 5081 | if (asoc->alternate) { |
| 5082 | netp = asoc->alternate; |
| 5083 | } else { |
| 5084 | netp = asoc->primary_destination; |
| 5085 | } |
| 5086 | sctp_send_shutdown(stcb, netp); |
| 5087 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, |
| 5088 | stcb->sctp_ep, stcb, netp); |
| 5089 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, |
Michael Tuexen | d07a5f2 | 2020-03-19 23:34:46 +0100 | [diff] [blame] | 5090 | stcb->sctp_ep, stcb, NULL); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5091 | return; |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 5092 | } else if ((SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED) && |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5093 | (asoc->stream_queue_cnt == 0)) { |
| 5094 | struct sctp_nets *netp; |
t00fcxen | d0ad16b | 2013-02-09 18:34:24 +0000 | [diff] [blame] | 5095 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5096 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
Michael Tuexen | 348a36c | 2018-08-13 16:24:47 +0200 | [diff] [blame] | 5097 | SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_ACK_SENT); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5098 | sctp_stop_timers_for_shutdown(stcb); |
t00fcxen | d0ad16b | 2013-02-09 18:34:24 +0000 | [diff] [blame] | 5099 | if (asoc->alternate) { |
| 5100 | netp = asoc->alternate; |
| 5101 | } else { |
| 5102 | netp = asoc->primary_destination; |
| 5103 | } |
| 5104 | sctp_send_shutdown_ack(stcb, netp); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5105 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, |
| 5106 | stcb->sctp_ep, stcb, netp); |
| 5107 | return; |
| 5108 | } |
| 5109 | } |
| 5110 | /* |
| 5111 | * Now here we are going to recycle net_ack for a different use... |
| 5112 | * HEADS UP. |
| 5113 | */ |
| 5114 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 5115 | net->net_ack = 0; |
| 5116 | } |
| 5117 | |
| 5118 | /* |
| 5119 | * CMT DAC algorithm: If SACK DAC flag was 0, then no extra marking |
| 5120 | * to be done. Setting this_sack_lowest_newack to the cum_ack will |
| 5121 | * automatically ensure that. |
| 5122 | */ |
| 5123 | if ((asoc->sctp_cmt_on_off > 0) && |
| 5124 | SCTP_BASE_SYSCTL(sctp_cmt_use_dac) && |
| 5125 | (cmt_dac_flag == 0)) { |
| 5126 | this_sack_lowest_newack = cum_ack; |
| 5127 | } |
| 5128 | if ((num_seg > 0) || (num_nr_seg > 0)) { |
| 5129 | sctp_strike_gap_ack_chunks(stcb, asoc, biggest_tsn_acked, |
| 5130 | biggest_tsn_newly_acked, this_sack_lowest_newack, accum_moved); |
| 5131 | } |
| 5132 | /* JRS - Use the congestion control given in the CC module */ |
| 5133 | asoc->cc_functions.sctp_cwnd_update_after_fr(stcb, asoc); |
| 5134 | |
| 5135 | /* Now are we exiting loss recovery ? */ |
| 5136 | if (will_exit_fast_recovery) { |
| 5137 | /* Ok, we must exit fast recovery */ |
| 5138 | asoc->fast_retran_loss_recovery = 0; |
| 5139 | } |
| 5140 | if ((asoc->sat_t3_loss_recovery) && |
| 5141 | SCTP_TSN_GE(asoc->last_acked_seq, asoc->sat_t3_recovery_tsn)) { |
| 5142 | /* end satellite t3 loss recovery */ |
| 5143 | asoc->sat_t3_loss_recovery = 0; |
| 5144 | } |
| 5145 | /* |
| 5146 | * CMT Fast recovery |
| 5147 | */ |
| 5148 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 5149 | if (net->will_exit_fast_recovery) { |
| 5150 | /* Ok, we must exit fast recovery */ |
| 5151 | net->fast_retran_loss_recovery = 0; |
| 5152 | } |
| 5153 | } |
| 5154 | |
| 5155 | /* Adjust and set the new rwnd value */ |
| 5156 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { |
| 5157 | sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK, |
| 5158 | asoc->peers_rwnd, asoc->total_flight, (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)), a_rwnd); |
| 5159 | } |
| 5160 | asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd, |
| 5161 | (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); |
| 5162 | if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { |
| 5163 | /* SWS sender side engages */ |
| 5164 | asoc->peers_rwnd = 0; |
| 5165 | } |
| 5166 | if (asoc->peers_rwnd > old_rwnd) { |
| 5167 | win_probe_recovery = 1; |
| 5168 | } |
| 5169 | |
| 5170 | /* |
| 5171 | * Now we must setup so we have a timer up for anyone with |
| 5172 | * outstanding data. |
| 5173 | */ |
| 5174 | done_once = 0; |
| 5175 | again: |
| 5176 | j = 0; |
| 5177 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 5178 | if (win_probe_recovery && (net->window_probe)) { |
| 5179 | win_probe_recovered = 1; |
| 5180 | /*- |
| 5181 | * Find first chunk that was used with |
| 5182 | * window probe and clear the event. Put |
| 5183 | * it back into the send queue as if has |
| 5184 | * not been sent. |
| 5185 | */ |
| 5186 | TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { |
| 5187 | if (tp1->window_probe) { |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 5188 | sctp_window_probe_recovery(stcb, asoc, tp1); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5189 | break; |
| 5190 | } |
| 5191 | } |
| 5192 | } |
| 5193 | if (net->flight_size) { |
| 5194 | j++; |
| 5195 | if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { |
| 5196 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, |
| 5197 | stcb->sctp_ep, stcb, net); |
| 5198 | } |
| 5199 | if (net->window_probe) { |
| 5200 | net->window_probe = 0; |
| 5201 | } |
| 5202 | } else { |
| 5203 | if (net->window_probe) { |
| 5204 | /* In window probes we must assure a timer is still running there */ |
| 5205 | if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { |
| 5206 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, |
| 5207 | stcb->sctp_ep, stcb, net); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5208 | } |
| 5209 | } else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { |
| 5210 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, |
| 5211 | stcb, net, |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 5212 | SCTP_FROM_SCTP_INDATA + SCTP_LOC_36); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5213 | } |
| 5214 | } |
| 5215 | } |
| 5216 | if ((j == 0) && |
| 5217 | (!TAILQ_EMPTY(&asoc->sent_queue)) && |
| 5218 | (asoc->sent_queue_retran_cnt == 0) && |
| 5219 | (win_probe_recovered == 0) && |
| 5220 | (done_once == 0)) { |
| 5221 | /* huh, this should not happen unless all packets |
| 5222 | * are PR-SCTP and marked to skip of course. |
| 5223 | */ |
| 5224 | if (sctp_fs_audit(asoc)) { |
| 5225 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
| 5226 | net->flight_size = 0; |
| 5227 | } |
| 5228 | asoc->total_flight = 0; |
| 5229 | asoc->total_flight_count = 0; |
| 5230 | asoc->sent_queue_retran_cnt = 0; |
| 5231 | TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) { |
| 5232 | if (tp1->sent < SCTP_DATAGRAM_RESEND) { |
| 5233 | sctp_flight_size_increase(tp1); |
| 5234 | sctp_total_flight_increase(stcb, tp1); |
| 5235 | } else if (tp1->sent == SCTP_DATAGRAM_RESEND) { |
| 5236 | sctp_ucount_incr(asoc->sent_queue_retran_cnt); |
| 5237 | } |
| 5238 | } |
| 5239 | } |
| 5240 | done_once = 1; |
| 5241 | goto again; |
| 5242 | } |
| 5243 | /*********************************************/ |
| 5244 | /* Here we perform PR-SCTP procedures */ |
| 5245 | /* (section 4.2) */ |
| 5246 | /*********************************************/ |
| 5247 | /* C1. update advancedPeerAckPoint */ |
| 5248 | if (SCTP_TSN_GT(cum_ack, asoc->advanced_peer_ack_point)) { |
| 5249 | asoc->advanced_peer_ack_point = cum_ack; |
| 5250 | } |
| 5251 | /* C2. try to further move advancedPeerAckPoint ahead */ |
t00fcxen | 0e78cef | 2014-08-02 22:05:33 +0000 | [diff] [blame] | 5252 | if ((asoc->prsctp_supported) && (asoc->pr_sctp_cnt > 0)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5253 | struct sctp_tmit_chunk *lchk; |
| 5254 | uint32_t old_adv_peer_ack_point; |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 5255 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5256 | old_adv_peer_ack_point = asoc->advanced_peer_ack_point; |
| 5257 | lchk = sctp_try_advance_peer_ack_point(stcb, asoc); |
| 5258 | /* C3. See if we need to send a Fwd-TSN */ |
| 5259 | if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, cum_ack)) { |
| 5260 | /* |
| 5261 | * ISSUE with ECN, see FWD-TSN processing. |
| 5262 | */ |
| 5263 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { |
| 5264 | sctp_misc_ints(SCTP_FWD_TSN_CHECK, |
| 5265 | 0xee, cum_ack, asoc->advanced_peer_ack_point, |
| 5266 | old_adv_peer_ack_point); |
| 5267 | } |
| 5268 | if (SCTP_TSN_GT(asoc->advanced_peer_ack_point, old_adv_peer_ack_point)) { |
| 5269 | send_forward_tsn(stcb, asoc); |
| 5270 | } else if (lchk) { |
| 5271 | /* try to FR fwd-tsn's that get lost too */ |
| 5272 | if (lchk->rec.data.fwd_tsn_cnt >= 3) { |
| 5273 | send_forward_tsn(stcb, asoc); |
| 5274 | } |
| 5275 | } |
| 5276 | } |
Michael Tuexen | a8f3d9d | 2020-05-10 19:35:08 +0200 | [diff] [blame] | 5277 | for (; lchk != NULL; lchk = TAILQ_NEXT(lchk, sctp_next)) { |
| 5278 | if (lchk->whoTo != NULL) { |
| 5279 | break; |
| 5280 | } |
| 5281 | } |
| 5282 | if (lchk != NULL) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5283 | /* Assure a timer is up */ |
| 5284 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, |
| 5285 | stcb->sctp_ep, stcb, lchk->whoTo); |
| 5286 | } |
| 5287 | } |
| 5288 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_RWND_LOGGING_ENABLE) { |
| 5289 | sctp_misc_ints(SCTP_SACK_RWND_UPDATE, |
| 5290 | a_rwnd, |
| 5291 | stcb->asoc.peers_rwnd, |
| 5292 | stcb->asoc.total_flight, |
| 5293 | stcb->asoc.total_output_queue_size); |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | void |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 5298 | sctp_update_acked(struct sctp_tcb *stcb, struct sctp_shutdown_chunk *cp, int *abort_flag) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5299 | { |
| 5300 | /* Copy cum-ack */ |
| 5301 | uint32_t cum_ack, a_rwnd; |
| 5302 | |
| 5303 | cum_ack = ntohl(cp->cumulative_tsn_ack); |
| 5304 | /* Arrange so a_rwnd does NOT change */ |
| 5305 | a_rwnd = stcb->asoc.peers_rwnd + stcb->asoc.total_flight; |
| 5306 | |
| 5307 | /* Now call the express sack handling */ |
| 5308 | sctp_express_handle_sack(stcb, cum_ack, a_rwnd, abort_flag, 0); |
| 5309 | } |
| 5310 | |
| 5311 | static void |
| 5312 | sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5313 | struct sctp_stream_in *strmin) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5314 | { |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5315 | struct sctp_queued_to_read *control, *ncontrol; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5316 | struct sctp_association *asoc; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5317 | uint32_t mid; |
| 5318 | int need_reasm_check = 0; |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 5319 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5320 | asoc = &stcb->asoc; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5321 | mid = strmin->last_mid_delivered; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5322 | /* |
| 5323 | * First deliver anything prior to and including the stream no that |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5324 | * came in. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5325 | */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5326 | TAILQ_FOREACH_SAFE(control, &strmin->inqueue, next_instrm, ncontrol) { |
| 5327 | if (SCTP_MID_GE(asoc->idata_supported, mid, control->mid)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5328 | /* this is deliverable now */ |
Michael Tuexen | 8d6935d | 2022-05-15 01:51:24 +0200 | [diff] [blame] | 5329 | if (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5330 | if (control->on_strm_q) { |
| 5331 | if (control->on_strm_q == SCTP_ON_ORDERED) { |
| 5332 | TAILQ_REMOVE(&strmin->inqueue, control, next_instrm); |
| 5333 | } else if (control->on_strm_q == SCTP_ON_UNORDERED) { |
| 5334 | TAILQ_REMOVE(&strmin->uno_inqueue, control, next_instrm); |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 5335 | #ifdef INVARIANTS |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5336 | } else { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 5337 | panic("strmin: %p ctl: %p unknown %d", |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5338 | strmin, control, control->on_strm_q); |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 5339 | #endif |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5340 | } |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5341 | control->on_strm_q = 0; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5342 | } |
| 5343 | /* subtract pending on streams */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5344 | if (asoc->size_on_all_streams >= control->length) { |
| 5345 | asoc->size_on_all_streams -= control->length; |
| 5346 | } else { |
| 5347 | #ifdef INVARIANTS |
| 5348 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 5349 | #else |
| 5350 | asoc->size_on_all_streams = 0; |
| 5351 | #endif |
| 5352 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5353 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
| 5354 | /* deliver it to at least the delivery-q */ |
| 5355 | if (stcb->sctp_socket) { |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5356 | sctp_mark_non_revokable(asoc, control->sinfo_tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5357 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5358 | control, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5359 | &stcb->sctp_socket->so_rcv, |
| 5360 | 1, SCTP_READ_LOCK_HELD, |
| 5361 | SCTP_SO_NOT_LOCKED); |
| 5362 | } |
| 5363 | } else { |
| 5364 | /* Its a fragmented message */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5365 | if (control->first_frag_seen) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5366 | /* Make it so this is next to deliver, we restore later */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5367 | strmin->last_mid_delivered = control->mid - 1; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5368 | need_reasm_check = 1; |
| 5369 | break; |
| 5370 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5371 | } |
| 5372 | } else { |
| 5373 | /* no more delivery now. */ |
| 5374 | break; |
| 5375 | } |
| 5376 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5377 | if (need_reasm_check) { |
| 5378 | int ret; |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5379 | ret = sctp_deliver_reasm_check(stcb, &stcb->asoc, strmin, SCTP_READ_LOCK_HELD); |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5380 | if (SCTP_MID_GT(asoc->idata_supported, mid, strmin->last_mid_delivered)) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5381 | /* Restore the next to deliver unless we are ahead */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5382 | strmin->last_mid_delivered = mid; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5383 | } |
| 5384 | if (ret == 0) { |
| 5385 | /* Left the front Partial one on */ |
| 5386 | return; |
| 5387 | } |
| 5388 | need_reasm_check = 0; |
| 5389 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5390 | /* |
| 5391 | * now we must deliver things in queue the normal way if any are |
| 5392 | * now ready. |
| 5393 | */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5394 | mid = strmin->last_mid_delivered + 1; |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5395 | TAILQ_FOREACH_SAFE(control, &strmin->inqueue, next_instrm, ncontrol) { |
| 5396 | if (SCTP_MID_EQ(asoc->idata_supported, mid, control->mid)) { |
| 5397 | if (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5398 | /* this is deliverable now */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5399 | if (control->on_strm_q) { |
| 5400 | if (control->on_strm_q == SCTP_ON_ORDERED) { |
| 5401 | TAILQ_REMOVE(&strmin->inqueue, control, next_instrm); |
| 5402 | } else if (control->on_strm_q == SCTP_ON_UNORDERED) { |
| 5403 | TAILQ_REMOVE(&strmin->uno_inqueue, control, next_instrm); |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 5404 | #ifdef INVARIANTS |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5405 | } else { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 5406 | panic("strmin: %p ctl: %p unknown %d", |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5407 | strmin, control, control->on_strm_q); |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 5408 | #endif |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5409 | } |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5410 | control->on_strm_q = 0; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5411 | } |
| 5412 | /* subtract pending on streams */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5413 | if (asoc->size_on_all_streams >= control->length) { |
| 5414 | asoc->size_on_all_streams -= control->length; |
| 5415 | } else { |
| 5416 | #ifdef INVARIANTS |
| 5417 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 5418 | #else |
| 5419 | asoc->size_on_all_streams = 0; |
| 5420 | #endif |
| 5421 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5422 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
| 5423 | /* deliver it to at least the delivery-q */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5424 | strmin->last_mid_delivered = control->mid; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5425 | if (stcb->sctp_socket) { |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5426 | sctp_mark_non_revokable(asoc, control->sinfo_tsn); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5427 | sctp_add_to_readq(stcb->sctp_ep, stcb, |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5428 | control, |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5429 | &stcb->sctp_socket->so_rcv, 1, |
| 5430 | SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5431 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5432 | mid = strmin->last_mid_delivered + 1; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5433 | } else { |
| 5434 | /* Its a fragmented message */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5435 | if (control->first_frag_seen) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5436 | /* Make it so this is next to deliver */ |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5437 | strmin->last_mid_delivered = control->mid - 1; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5438 | need_reasm_check = 1; |
| 5439 | break; |
| 5440 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5441 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5442 | } else { |
| 5443 | break; |
| 5444 | } |
| 5445 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5446 | if (need_reasm_check) { |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5447 | (void)sctp_deliver_reasm_check(stcb, &stcb->asoc, strmin, SCTP_READ_LOCK_HELD); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5448 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | static void |
| 5452 | sctp_flush_reassm_for_str_seq(struct sctp_tcb *stcb, |
Michael Tuexen | b10a5d3 | 2020-07-09 18:25:16 +0200 | [diff] [blame] | 5453 | struct sctp_association *asoc, struct sctp_stream_in *strm, |
| 5454 | struct sctp_queued_to_read *control, int ordered, uint32_t cumtsn) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5455 | { |
| 5456 | struct sctp_tmit_chunk *chk, *nchk; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5457 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5458 | /* |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5459 | * For now large messages held on the stream reasm that are |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5460 | * complete will be tossed too. We could in theory do more |
| 5461 | * work to spin through and stop after dumping one msg aka |
| 5462 | * seeing the start of a new msg at the head, and call the |
| 5463 | * delivery function... to see if it can be delivered... But |
| 5464 | * for now we just dump everything on the queue. |
| 5465 | */ |
Michael Tuexen | 7d6d4c2 | 2020-09-27 15:40:33 +0200 | [diff] [blame] | 5466 | if (!asoc->idata_supported && !ordered && |
| 5467 | control->first_frag_seen && |
| 5468 | SCTP_TSN_GT(control->fsn_included, cumtsn)) { |
Michael Tuexen | 93e6e55 | 2016-09-22 16:25:12 +0200 | [diff] [blame] | 5469 | return; |
| 5470 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5471 | TAILQ_FOREACH_SAFE(chk, &control->reasm, sctp_next, nchk) { |
| 5472 | /* Purge hanging chunks */ |
Michael Tuexen | 7d6d4c2 | 2020-09-27 15:40:33 +0200 | [diff] [blame] | 5473 | if (!asoc->idata_supported && !ordered) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5474 | if (SCTP_TSN_GT(chk->rec.data.tsn, cumtsn)) { |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5475 | break; |
| 5476 | } |
| 5477 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5478 | TAILQ_REMOVE(&control->reasm, chk, sctp_next); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5479 | if (asoc->size_on_reasm_queue >= chk->send_size) { |
| 5480 | asoc->size_on_reasm_queue -= chk->send_size; |
| 5481 | } else { |
| 5482 | #ifdef INVARIANTS |
| 5483 | panic("size_on_reasm_queue = %u smaller than chunk length %u", asoc->size_on_reasm_queue, chk->send_size); |
| 5484 | #else |
| 5485 | asoc->size_on_reasm_queue = 0; |
| 5486 | #endif |
| 5487 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5488 | sctp_ucount_decr(asoc->cnt_on_reasm_queue); |
| 5489 | if (chk->data) { |
| 5490 | sctp_m_freem(chk->data); |
| 5491 | chk->data = NULL; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5492 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5493 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
| 5494 | } |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5495 | if (!TAILQ_EMPTY(&control->reasm)) { |
| 5496 | /* This has to be old data, unordered */ |
| 5497 | if (control->data) { |
| 5498 | sctp_m_freem(control->data); |
| 5499 | control->data = NULL; |
| 5500 | } |
| 5501 | sctp_reset_a_control(control, stcb->sctp_ep, cumtsn); |
| 5502 | chk = TAILQ_FIRST(&control->reasm); |
| 5503 | if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { |
| 5504 | TAILQ_REMOVE(&control->reasm, chk, sctp_next); |
| 5505 | sctp_add_chk_to_control(control, strm, stcb, asoc, |
| 5506 | chk, SCTP_READ_LOCK_HELD); |
| 5507 | } |
| 5508 | sctp_deliver_reasm_check(stcb, asoc, strm, SCTP_READ_LOCK_HELD); |
| 5509 | return; |
| 5510 | } |
| 5511 | if (control->on_strm_q == SCTP_ON_ORDERED) { |
| 5512 | TAILQ_REMOVE(&strm->inqueue, control, next_instrm); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5513 | if (asoc->size_on_all_streams >= control->length) { |
| 5514 | asoc->size_on_all_streams -= control->length; |
| 5515 | } else { |
| 5516 | #ifdef INVARIANTS |
| 5517 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 5518 | #else |
| 5519 | asoc->size_on_all_streams = 0; |
| 5520 | #endif |
| 5521 | } |
| 5522 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5523 | control->on_strm_q = 0; |
| 5524 | } else if (control->on_strm_q == SCTP_ON_UNORDERED) { |
| 5525 | TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); |
| 5526 | control->on_strm_q = 0; |
| 5527 | #ifdef INVARIANTS |
| 5528 | } else if (control->on_strm_q) { |
| 5529 | panic("strm: %p ctl: %p unknown %d", |
| 5530 | strm, control, control->on_strm_q); |
| 5531 | #endif |
| 5532 | } |
| 5533 | control->on_strm_q = 0; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5534 | if (control->on_read_q == 0) { |
| 5535 | sctp_free_remote_addr(control->whoFrom); |
| 5536 | if (control->data) { |
| 5537 | sctp_m_freem(control->data); |
| 5538 | control->data = NULL; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5539 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5540 | sctp_free_a_readq(stcb, control); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5541 | } |
| 5542 | } |
| 5543 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5544 | void |
| 5545 | sctp_handle_forward_tsn(struct sctp_tcb *stcb, |
| 5546 | struct sctp_forward_tsn_chunk *fwd, |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5547 | int *abort_flag, struct mbuf *m , int offset) |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5548 | { |
| 5549 | /* The pr-sctp fwd tsn */ |
| 5550 | /* |
| 5551 | * here we will perform all the data receiver side steps for |
| 5552 | * processing FwdTSN, as required in by pr-sctp draft: |
| 5553 | * |
| 5554 | * Assume we get FwdTSN(x): |
| 5555 | * |
Michael Tuexen | d333128 | 2020-02-03 23:14:00 +0100 | [diff] [blame] | 5556 | * 1) update local cumTSN to x |
| 5557 | * 2) try to further advance cumTSN to x + others we have |
| 5558 | * 3) examine and update re-ordering queue on pr-in-streams |
| 5559 | * 4) clean up re-assembly queue |
Michael Tuexen | e64d773 | 2016-07-17 15:21:06 +0200 | [diff] [blame] | 5560 | * 5) Send a sack to report where we are. |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5561 | */ |
| 5562 | struct sctp_association *asoc; |
| 5563 | uint32_t new_cum_tsn, gap; |
tuexen | 9784e9a | 2011-12-18 13:04:23 +0000 | [diff] [blame] | 5564 | unsigned int i, fwd_sz, m_size; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5565 | uint32_t str_seq; |
| 5566 | struct sctp_stream_in *strm; |
Michael Tuexen | 9140950 | 2020-11-09 14:23:07 +0100 | [diff] [blame] | 5567 | struct sctp_queued_to_read *control, *ncontrol, *sv; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5568 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5569 | asoc = &stcb->asoc; |
| 5570 | if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) { |
| 5571 | SCTPDBG(SCTP_DEBUG_INDATA1, |
| 5572 | "Bad size too small/big fwd-tsn\n"); |
| 5573 | return; |
| 5574 | } |
| 5575 | m_size = (stcb->asoc.mapping_array_size << 3); |
| 5576 | /*************************************************************/ |
| 5577 | /* 1. Here we update local cumTSN and shift the bitmap array */ |
| 5578 | /*************************************************************/ |
| 5579 | new_cum_tsn = ntohl(fwd->new_cumulative_tsn); |
| 5580 | |
| 5581 | if (SCTP_TSN_GE(asoc->cumulative_tsn, new_cum_tsn)) { |
| 5582 | /* Already got there ... */ |
| 5583 | return; |
| 5584 | } |
| 5585 | /* |
| 5586 | * now we know the new TSN is more advanced, let's find the actual |
| 5587 | * gap |
| 5588 | */ |
| 5589 | SCTP_CALC_TSN_TO_GAP(gap, new_cum_tsn, asoc->mapping_array_base_tsn); |
| 5590 | asoc->cumulative_tsn = new_cum_tsn; |
| 5591 | if (gap >= m_size) { |
| 5592 | if ((long)gap > sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv)) { |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 5593 | struct mbuf *op_err; |
| 5594 | char msg[SCTP_DIAG_INFO_LEN]; |
| 5595 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5596 | /* |
| 5597 | * out of range (of single byte chunks in the rwnd I |
| 5598 | * give out). This must be an attacker. |
| 5599 | */ |
| 5600 | *abort_flag = 1; |
Michael Tuexen | edd369d | 2020-05-19 09:42:15 +0200 | [diff] [blame] | 5601 | SCTP_SNPRINTF(msg, sizeof(msg), |
| 5602 | "New cum ack %8.8x too high, highest TSN %8.8x", |
| 5603 | new_cum_tsn, asoc->highest_tsn_inside_map); |
t00fcxen | 08f9ff9 | 2014-03-16 13:38:54 +0000 | [diff] [blame] | 5604 | op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); |
Michael Tuexen | 555c8e8 | 2020-07-23 03:43:26 +0200 | [diff] [blame] | 5605 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_37; |
Michael Tuexen | 1ade45c | 2021-07-09 23:32:42 +0200 | [diff] [blame] | 5606 | sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5607 | return; |
| 5608 | } |
| 5609 | SCTP_STAT_INCR(sctps_fwdtsn_map_over); |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 5610 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5611 | memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size); |
| 5612 | asoc->mapping_array_base_tsn = new_cum_tsn + 1; |
| 5613 | asoc->highest_tsn_inside_map = new_cum_tsn; |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 5614 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5615 | memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.mapping_array_size); |
| 5616 | asoc->highest_tsn_inside_nr_map = new_cum_tsn; |
tuexen | 15f99d8 | 2012-04-19 16:08:38 +0000 | [diff] [blame] | 5617 | |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5618 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { |
| 5619 | sctp_log_map(0, 3, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT); |
| 5620 | } |
| 5621 | } else { |
| 5622 | SCTP_TCB_LOCK_ASSERT(stcb); |
| 5623 | for (i = 0; i <= gap; i++) { |
| 5624 | if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, i) && |
| 5625 | !SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, i)) { |
| 5626 | SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, i); |
| 5627 | if (SCTP_TSN_GT(asoc->mapping_array_base_tsn + i, asoc->highest_tsn_inside_nr_map)) { |
| 5628 | asoc->highest_tsn_inside_nr_map = asoc->mapping_array_base_tsn + i; |
| 5629 | } |
| 5630 | } |
| 5631 | } |
| 5632 | } |
| 5633 | /*************************************************************/ |
| 5634 | /* 2. Clear up re-assembly queue */ |
| 5635 | /*************************************************************/ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5636 | |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5637 | /* This is now done as part of clearing up the stream/seq */ |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5638 | if (asoc->idata_supported == 0) { |
| 5639 | uint16_t sid; |
Michael Tuexen | b10a5d3 | 2020-07-09 18:25:16 +0200 | [diff] [blame] | 5640 | |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5641 | /* Flush all the un-ordered data based on cum-tsn */ |
| 5642 | SCTP_INP_READ_LOCK(stcb->sctp_ep); |
Michael Tuexen | 196fbbe | 2020-09-28 17:04:25 +0200 | [diff] [blame] | 5643 | for (sid = 0; sid < asoc->streamincnt; sid++) { |
Michael Tuexen | b10a5d3 | 2020-07-09 18:25:16 +0200 | [diff] [blame] | 5644 | strm = &asoc->strmin[sid]; |
| 5645 | if (!TAILQ_EMPTY(&strm->uno_inqueue)) { |
| 5646 | sctp_flush_reassm_for_str_seq(stcb, asoc, strm, TAILQ_FIRST(&strm->uno_inqueue), 0, new_cum_tsn); |
| 5647 | } |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5648 | } |
| 5649 | SCTP_INP_READ_UNLOCK(stcb->sctp_ep); |
| 5650 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5651 | /*******************************************************/ |
| 5652 | /* 3. Update the PR-stream re-ordering queues and fix */ |
| 5653 | /* delivery issues as needed. */ |
| 5654 | /*******************************************************/ |
| 5655 | fwd_sz -= sizeof(*fwd); |
| 5656 | if (m && fwd_sz) { |
| 5657 | /* New method. */ |
| 5658 | unsigned int num_str; |
Michael Tuexen | b10a5d3 | 2020-07-09 18:25:16 +0200 | [diff] [blame] | 5659 | uint32_t mid; |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5660 | uint16_t sid; |
Michael Tuexen | e64d773 | 2016-07-17 15:21:06 +0200 | [diff] [blame] | 5661 | uint16_t ordered, flags; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5662 | struct sctp_strseq *stseq, strseqbuf; |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5663 | struct sctp_strseq_mid *stseq_m, strseqbuf_m; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5664 | offset += sizeof(*fwd); |
| 5665 | |
| 5666 | SCTP_INP_READ_LOCK(stcb->sctp_ep); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5667 | if (asoc->idata_supported) { |
| 5668 | num_str = fwd_sz / sizeof(struct sctp_strseq_mid); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5669 | } else { |
| 5670 | num_str = fwd_sz / sizeof(struct sctp_strseq); |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5671 | } |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5672 | for (i = 0; i < num_str; i++) { |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5673 | if (asoc->idata_supported) { |
| 5674 | stseq_m = (struct sctp_strseq_mid *)sctp_m_getptr(m, offset, |
| 5675 | sizeof(struct sctp_strseq_mid), |
| 5676 | (uint8_t *)&strseqbuf_m); |
| 5677 | offset += sizeof(struct sctp_strseq_mid); |
| 5678 | if (stseq_m == NULL) { |
| 5679 | break; |
| 5680 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5681 | sid = ntohs(stseq_m->sid); |
| 5682 | mid = ntohl(stseq_m->mid); |
Michael Tuexen | e64d773 | 2016-07-17 15:21:06 +0200 | [diff] [blame] | 5683 | flags = ntohs(stseq_m->flags); |
| 5684 | if (flags & PR_SCTP_UNORDERED_FLAG) { |
| 5685 | ordered = 0; |
| 5686 | } else { |
| 5687 | ordered = 1; |
| 5688 | } |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5689 | } else { |
| 5690 | stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset, |
| 5691 | sizeof(struct sctp_strseq), |
| 5692 | (uint8_t *)&strseqbuf); |
| 5693 | offset += sizeof(struct sctp_strseq); |
| 5694 | if (stseq == NULL) { |
| 5695 | break; |
| 5696 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5697 | sid = ntohs(stseq->sid); |
| 5698 | mid = (uint32_t)ntohs(stseq->ssn); |
Michael Tuexen | e64d773 | 2016-07-17 15:21:06 +0200 | [diff] [blame] | 5699 | ordered = 1; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5700 | } |
| 5701 | /* Convert */ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5702 | |
| 5703 | /* now process */ |
| 5704 | |
| 5705 | /* |
| 5706 | * Ok we now look for the stream/seq on the read queue |
| 5707 | * where its not all delivered. If we find it we transmute the |
| 5708 | * read entry into a PDI_ABORTED. |
| 5709 | */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5710 | if (sid >= asoc->streamincnt) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5711 | /* screwed up streams, stop! */ |
| 5712 | break; |
| 5713 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5714 | if ((asoc->str_of_pdapi == sid) && |
| 5715 | (asoc->ssn_of_pdapi == mid)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5716 | /* If this is the one we were partially delivering |
| 5717 | * now then we no longer are. Note this will change |
| 5718 | * with the reassembly re-write. |
| 5719 | */ |
| 5720 | asoc->fragmented_delivery_inprogress = 0; |
| 5721 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5722 | strm = &asoc->strmin[sid]; |
Michael Tuexen | b10a5d3 | 2020-07-09 18:25:16 +0200 | [diff] [blame] | 5723 | if (ordered) { |
Michael Tuexen | 9140950 | 2020-11-09 14:23:07 +0100 | [diff] [blame] | 5724 | TAILQ_FOREACH_SAFE(control, &strm->inqueue, next_instrm, ncontrol) { |
Michael Tuexen | b10a5d3 | 2020-07-09 18:25:16 +0200 | [diff] [blame] | 5725 | if (SCTP_MID_GE(asoc->idata_supported, mid, control->mid)) { |
| 5726 | sctp_flush_reassm_for_str_seq(stcb, asoc, strm, control, ordered, new_cum_tsn); |
| 5727 | } |
| 5728 | } |
| 5729 | } else { |
| 5730 | if (asoc->idata_supported) { |
Michael Tuexen | 9140950 | 2020-11-09 14:23:07 +0100 | [diff] [blame] | 5731 | TAILQ_FOREACH_SAFE(control, &strm->uno_inqueue, next_instrm, ncontrol) { |
Michael Tuexen | b10a5d3 | 2020-07-09 18:25:16 +0200 | [diff] [blame] | 5732 | if (SCTP_MID_GE(asoc->idata_supported, mid, control->mid)) { |
| 5733 | sctp_flush_reassm_for_str_seq(stcb, asoc, strm, control, ordered, new_cum_tsn); |
| 5734 | } |
| 5735 | } |
| 5736 | } else { |
| 5737 | if (!TAILQ_EMPTY(&strm->uno_inqueue)) { |
| 5738 | sctp_flush_reassm_for_str_seq(stcb, asoc, strm, TAILQ_FIRST(&strm->uno_inqueue), ordered, new_cum_tsn); |
| 5739 | } |
| 5740 | } |
Michael Tuexen | fdcf790 | 2016-08-06 14:39:31 +0200 | [diff] [blame] | 5741 | } |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5742 | TAILQ_FOREACH(control, &stcb->sctp_ep->read_queue, next) { |
| 5743 | if ((control->sinfo_stream == sid) && |
| 5744 | (SCTP_MID_EQ(asoc->idata_supported, control->mid, mid))) { |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5745 | str_seq = (sid << 16) | (0x0000ffff & mid); |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5746 | control->pdapi_aborted = 1; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5747 | sv = stcb->asoc.control_pdapi; |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5748 | control->end_added = 1; |
| 5749 | if (control->on_strm_q == SCTP_ON_ORDERED) { |
| 5750 | TAILQ_REMOVE(&strm->inqueue, control, next_instrm); |
| 5751 | if (asoc->size_on_all_streams >= control->length) { |
| 5752 | asoc->size_on_all_streams -= control->length; |
| 5753 | } else { |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 5754 | #ifdef INVARIANTS |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5755 | panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length); |
| 5756 | #else |
| 5757 | asoc->size_on_all_streams = 0; |
| 5758 | #endif |
| 5759 | } |
| 5760 | sctp_ucount_decr(asoc->cnt_on_all_streams); |
| 5761 | } else if (control->on_strm_q == SCTP_ON_UNORDERED) { |
| 5762 | TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm); |
| 5763 | #ifdef INVARIANTS |
| 5764 | } else if (control->on_strm_q) { |
Michael Tuexen | eccb4be | 2016-04-18 08:58:59 +0200 | [diff] [blame] | 5765 | panic("strm: %p ctl: %p unknown %d", |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5766 | strm, control, control->on_strm_q); |
Michael Tuexen | f6d20c5 | 2016-04-18 11:31:05 +0200 | [diff] [blame] | 5767 | #endif |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5768 | } |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5769 | control->on_strm_q = 0; |
| 5770 | stcb->asoc.control_pdapi = control; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5771 | sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION, |
| 5772 | stcb, |
| 5773 | SCTP_PARTIAL_DELIVERY_ABORTED, |
| 5774 | (void *)&str_seq, |
| 5775 | SCTP_SO_NOT_LOCKED); |
| 5776 | stcb->asoc.control_pdapi = sv; |
| 5777 | break; |
Michael Tuexen | be5e3e7 | 2017-07-19 14:44:48 +0200 | [diff] [blame] | 5778 | } else if ((control->sinfo_stream == sid) && |
| 5779 | SCTP_MID_GT(asoc->idata_supported, control->mid, mid)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5780 | /* We are past our victim SSN */ |
| 5781 | break; |
| 5782 | } |
| 5783 | } |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5784 | if (SCTP_MID_GT(asoc->idata_supported, mid, strm->last_mid_delivered)) { |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5785 | /* Update the sequence number */ |
Michael Tuexen | 00657ac | 2016-12-07 21:53:26 +0100 | [diff] [blame] | 5786 | strm->last_mid_delivered = mid; |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5787 | } |
| 5788 | /* now kick the stream the new way */ |
Michael Tuexen | e500195 | 2016-04-17 19:25:27 +0200 | [diff] [blame] | 5789 | /*sa_ignore NO_NULL_CHK*/ |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5790 | sctp_kick_prsctp_reorder_queue(stcb, strm); |
| 5791 | } |
| 5792 | SCTP_INP_READ_UNLOCK(stcb->sctp_ep); |
| 5793 | } |
| 5794 | /* |
| 5795 | * Now slide thing forward. |
| 5796 | */ |
| 5797 | sctp_slide_mapping_arrays(stcb); |
tuexen | dd72923 | 2011-11-01 23:04:43 +0000 | [diff] [blame] | 5798 | } |