sctp_indata.c revision 1.1 1 1.1 rjs /* $NetBSD: sctp_indata.c,v 1.1 2015/10/13 21:28:35 rjs Exp $ */
2 1.1 rjs /* $KAME: sctp_indata.c,v 1.36 2005/03/06 16:04:17 itojun Exp $ */
3 1.1 rjs
4 1.1 rjs /*
5 1.1 rjs * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc,
6 1.1 rjs * All rights reserved.
7 1.1 rjs *
8 1.1 rjs * Redistribution and use in source and binary forms, with or without
9 1.1 rjs * modification, are permitted provided that the following conditions
10 1.1 rjs * are met:
11 1.1 rjs * 1. Redistributions of source code must retain the above copyright
12 1.1 rjs * notice, this list of conditions and the following disclaimer.
13 1.1 rjs * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 rjs * notice, this list of conditions and the following disclaimer in the
15 1.1 rjs * documentation and/or other materials provided with the distribution.
16 1.1 rjs * 3. Neither the name of the project nor the names of its contributors
17 1.1 rjs * may be used to endorse or promote products derived from this software
18 1.1 rjs * without specific prior written permission.
19 1.1 rjs *
20 1.1 rjs * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 1.1 rjs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.1 rjs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.1 rjs * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 1.1 rjs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.1 rjs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.1 rjs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.1 rjs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.1 rjs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.1 rjs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.1 rjs * SUCH DAMAGE.
31 1.1 rjs */
32 1.1 rjs
33 1.1 rjs #include <sys/cdefs.h>
34 1.1 rjs __KERNEL_RCSID(0, "$NetBSD: sctp_indata.c,v 1.1 2015/10/13 21:28:35 rjs Exp $");
35 1.1 rjs
36 1.1 rjs #ifdef _KERNEL_OPT
37 1.1 rjs #include "opt_ipsec.h"
38 1.1 rjs #include "opt_inet.h"
39 1.1 rjs #include "opt_sctp.h"
40 1.1 rjs #endif /* _KERNEL_OPT */
41 1.1 rjs
42 1.1 rjs #include <sys/param.h>
43 1.1 rjs #include <sys/systm.h>
44 1.1 rjs #include <sys/mbuf.h>
45 1.1 rjs #include <sys/malloc.h>
46 1.1 rjs #include <sys/socket.h>
47 1.1 rjs #include <sys/socketvar.h>
48 1.1 rjs #include <sys/sysctl.h>
49 1.1 rjs
50 1.1 rjs #include <net/if.h>
51 1.1 rjs #include <net/route.h>
52 1.1 rjs
53 1.1 rjs
54 1.1 rjs #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
55 1.1 rjs #include <sys/limits.h>
56 1.1 rjs #else
57 1.1 rjs #include <machine/limits.h>
58 1.1 rjs #endif
59 1.1 rjs #include <machine/cpu.h>
60 1.1 rjs
61 1.1 rjs #include <netinet/in.h>
62 1.1 rjs #include <netinet/in_systm.h>
63 1.1 rjs #include <netinet/ip.h>
64 1.1 rjs #ifdef INET6
65 1.1 rjs #include <netinet/ip6.h>
66 1.1 rjs #endif /* INET6 */
67 1.1 rjs #include <netinet/in_pcb.h>
68 1.1 rjs #include <netinet/in_var.h>
69 1.1 rjs #include <netinet/ip_var.h>
70 1.1 rjs #ifdef INET6
71 1.1 rjs #include <netinet6/ip6_var.h>
72 1.1 rjs #endif /* INET6 */
73 1.1 rjs #include <netinet/ip_icmp.h>
74 1.1 rjs #include <netinet/icmp_var.h>
75 1.1 rjs #include <netinet/sctp_var.h>
76 1.1 rjs #include <netinet/sctp_pcb.h>
77 1.1 rjs #include <netinet/sctp_header.h>
78 1.1 rjs #include <netinet/sctputil.h>
79 1.1 rjs #include <netinet/sctp_output.h>
80 1.1 rjs #include <netinet/sctp_input.h>
81 1.1 rjs #include <netinet/sctp_hashdriver.h>
82 1.1 rjs #include <netinet/sctp_indata.h>
83 1.1 rjs #include <netinet/sctp_uio.h>
84 1.1 rjs #include <netinet/sctp_timer.h>
85 1.1 rjs #ifdef IPSEC
86 1.1 rjs #include <netinet6/ipsec.h>
87 1.1 rjs #include <netkey/key.h>
88 1.1 rjs #endif /*IPSEC*/
89 1.1 rjs
90 1.1 rjs #include <net/net_osdep.h>
91 1.1 rjs
92 1.1 rjs #ifdef SCTP_DEBUG
93 1.1 rjs extern u_int32_t sctp_debug_on;
94 1.1 rjs #endif
95 1.1 rjs
96 1.1 rjs /*
97 1.1 rjs * NOTES: On the outbound side of things I need to check the sack timer to
98 1.1 rjs * see if I should generate a sack into the chunk queue (if I have data to
99 1.1 rjs * send that is and will be sending it .. for bundling.
100 1.1 rjs *
101 1.1 rjs * The callback in sctp_usrreq.c will get called when the socket is read
102 1.1 rjs * from. This will cause sctp_service_queues() to get called on the top
103 1.1 rjs * entry in the list.
104 1.1 rjs */
105 1.1 rjs
106 1.1 rjs extern int sctp_strict_sacks;
107 1.1 rjs
108 1.1 rjs void
109 1.1 rjs sctp_set_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc)
110 1.1 rjs {
111 1.1 rjs u_int32_t calc, calc_w_oh;
112 1.1 rjs
113 1.1 rjs #ifdef SCTP_DEBUG
114 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA4) {
115 1.1 rjs printf("cc:%lu hiwat:%lu lowat:%lu mbcnt:%lu mbmax:%lu\n",
116 1.1 rjs (u_long)stcb->sctp_socket->so_rcv.sb_cc,
117 1.1 rjs (u_long)stcb->sctp_socket->so_rcv.sb_hiwat,
118 1.1 rjs (u_long)stcb->sctp_socket->so_rcv.sb_lowat,
119 1.1 rjs (u_long)stcb->sctp_socket->so_rcv.sb_mbcnt,
120 1.1 rjs (u_long)stcb->sctp_socket->so_rcv.sb_mbmax);
121 1.1 rjs printf("Setting rwnd to: sb:%ld - (del:%d + reasm:%d str:%d)\n",
122 1.1 rjs sctp_sbspace(&stcb->sctp_socket->so_rcv),
123 1.1 rjs asoc->size_on_delivery_queue,
124 1.1 rjs asoc->size_on_reasm_queue,
125 1.1 rjs asoc->size_on_all_streams);
126 1.1 rjs }
127 1.1 rjs #endif
128 1.1 rjs if (stcb->sctp_socket->so_rcv.sb_cc == 0 &&
129 1.1 rjs asoc->size_on_delivery_queue == 0 &&
130 1.1 rjs asoc->size_on_reasm_queue == 0 &&
131 1.1 rjs asoc->size_on_all_streams == 0) {
132 1.1 rjs /* Full rwnd granted */
133 1.1 rjs asoc->my_rwnd = max(stcb->sctp_socket->so_rcv.sb_hiwat,
134 1.1 rjs SCTP_MINIMAL_RWND);
135 1.1 rjs return;
136 1.1 rjs }
137 1.1 rjs /* get actual space */
138 1.1 rjs calc = (u_int32_t)sctp_sbspace(&stcb->sctp_socket->so_rcv);
139 1.1 rjs
140 1.1 rjs /* take out what has NOT been put on socket queue and
141 1.1 rjs * we yet hold for putting up.
142 1.1 rjs */
143 1.1 rjs calc = sctp_sbspace_sub(calc, (u_int32_t)asoc->size_on_delivery_queue);
144 1.1 rjs calc = sctp_sbspace_sub(calc, (u_int32_t)asoc->size_on_reasm_queue);
145 1.1 rjs calc = sctp_sbspace_sub(calc, (u_int32_t)asoc->size_on_all_streams);
146 1.1 rjs
147 1.1 rjs /* what is the overhead of all these rwnd's */
148 1.1 rjs calc_w_oh = sctp_sbspace_sub(calc, stcb->asoc.my_rwnd_control_len);
149 1.1 rjs
150 1.1 rjs asoc->my_rwnd = calc;
151 1.1 rjs if (calc_w_oh == 0) {
152 1.1 rjs /* If our overhead is greater than the advertised
153 1.1 rjs * rwnd, we clamp the rwnd to 1. This lets us
154 1.1 rjs * still accept inbound segments, but hopefully will
155 1.1 rjs * shut the sender down when he finally gets the message.
156 1.1 rjs */
157 1.1 rjs asoc->my_rwnd = 1;
158 1.1 rjs } else {
159 1.1 rjs /* SWS threshold */
160 1.1 rjs if (asoc->my_rwnd &&
161 1.1 rjs (asoc->my_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_receiver)) {
162 1.1 rjs /* SWS engaged, tell peer none left */
163 1.1 rjs asoc->my_rwnd = 1;
164 1.1 rjs #ifdef SCTP_DEBUG
165 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA4) {
166 1.1 rjs printf(" - SWS zeros\n");
167 1.1 rjs }
168 1.1 rjs } else {
169 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA4) {
170 1.1 rjs printf("\n");
171 1.1 rjs }
172 1.1 rjs #endif
173 1.1 rjs }
174 1.1 rjs }
175 1.1 rjs }
176 1.1 rjs
177 1.1 rjs /*
178 1.1 rjs * Take a chk structure and build it into an mbuf. Hmm should we change things
179 1.1 rjs * so that instead we store the data side in a chunk?
180 1.1 rjs */
181 1.1 rjs static struct mbuf *
182 1.1 rjs sctp_build_ctl_nchunk(struct sctp_tcb *stcb, uint32_t tsn, uint32_t ppid,
183 1.1 rjs uint32_t context, uint16_t stream_no, uint16_t stream_seq, uint8_t flags)
184 1.1 rjs {
185 1.1 rjs struct sctp_sndrcvinfo *outinfo;
186 1.1 rjs struct cmsghdr *cmh;
187 1.1 rjs struct mbuf *ret;
188 1.1 rjs
189 1.1 rjs if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_RECVDATAIOEVNT) == 0) {
190 1.1 rjs /* user does not want the sndrcv ctl */
191 1.1 rjs return (NULL);
192 1.1 rjs }
193 1.1 rjs
194 1.1 rjs MGETHDR(ret, M_DONTWAIT, MT_CONTROL);
195 1.1 rjs if (ret == NULL) {
196 1.1 rjs /* No space */
197 1.1 rjs return (ret);
198 1.1 rjs }
199 1.1 rjs /* We need a CMSG header followed by the struct */
200 1.1 rjs cmh = mtod(ret, struct cmsghdr *);
201 1.1 rjs outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh);
202 1.1 rjs cmh->cmsg_level = IPPROTO_SCTP;
203 1.1 rjs cmh->cmsg_type = SCTP_SNDRCV;
204 1.1 rjs cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
205 1.1 rjs outinfo->sinfo_stream = stream_no;
206 1.1 rjs outinfo->sinfo_ssn = stream_seq;
207 1.1 rjs if (flags & SCTP_DATA_UNORDERED) {
208 1.1 rjs outinfo->sinfo_flags = MSG_UNORDERED;
209 1.1 rjs } else {
210 1.1 rjs outinfo->sinfo_flags = 0;
211 1.1 rjs }
212 1.1 rjs outinfo->sinfo_ppid = ppid;
213 1.1 rjs outinfo->sinfo_context = context;
214 1.1 rjs outinfo->sinfo_assoc_id = sctp_get_associd(stcb);
215 1.1 rjs outinfo->sinfo_tsn = tsn;
216 1.1 rjs outinfo->sinfo_cumtsn = stcb->asoc.cumulative_tsn;
217 1.1 rjs ret->m_len = cmh->cmsg_len;
218 1.1 rjs ret->m_pkthdr.len = ret->m_len;
219 1.1 rjs /*
220 1.1 rjs * We track how many control len's have gone upon the sb
221 1.1 rjs * and do not count these in the rwnd calculation.
222 1.1 rjs */
223 1.1 rjs stcb->asoc.my_rwnd_control_len +=
224 1.1 rjs CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
225 1.1 rjs
226 1.1 rjs return (ret);
227 1.1 rjs }
228 1.1 rjs
229 1.1 rjs /*
230 1.1 rjs * Take a chk structure and build it into an mbuf. Should we change things
231 1.1 rjs * so that instead we store the data side in a chunk?
232 1.1 rjs */
233 1.1 rjs static
234 1.1 rjs struct mbuf *
235 1.1 rjs sctp_build_ctl(struct sctp_tcb *stcb, struct sctp_tmit_chunk *chk)
236 1.1 rjs {
237 1.1 rjs struct sctp_sndrcvinfo *outinfo;
238 1.1 rjs struct cmsghdr *cmh;
239 1.1 rjs struct mbuf *ret;
240 1.1 rjs if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_RECVDATAIOEVNT) == 0) {
241 1.1 rjs /* user does not want the sndrcv ctl */
242 1.1 rjs return (NULL);
243 1.1 rjs }
244 1.1 rjs MGET(ret, M_DONTWAIT, MT_CONTROL);
245 1.1 rjs if (ret == NULL) {
246 1.1 rjs /* No space */
247 1.1 rjs return (ret);
248 1.1 rjs }
249 1.1 rjs
250 1.1 rjs /* We need a CMSG header followed by the struct */
251 1.1 rjs cmh = mtod(ret, struct cmsghdr *);
252 1.1 rjs outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh);
253 1.1 rjs cmh->cmsg_level = IPPROTO_SCTP;
254 1.1 rjs cmh->cmsg_type = SCTP_SNDRCV;
255 1.1 rjs cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
256 1.1 rjs outinfo->sinfo_stream = chk->rec.data.stream_number;
257 1.1 rjs outinfo->sinfo_ssn = chk->rec.data.stream_seq;
258 1.1 rjs if (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) {
259 1.1 rjs outinfo->sinfo_flags = MSG_UNORDERED;
260 1.1 rjs } else {
261 1.1 rjs outinfo->sinfo_flags = 0;
262 1.1 rjs }
263 1.1 rjs outinfo->sinfo_ppid = chk->rec.data.payloadtype;
264 1.1 rjs outinfo->sinfo_context = chk->rec.data.context;
265 1.1 rjs outinfo->sinfo_assoc_id = sctp_get_associd(stcb);
266 1.1 rjs outinfo->sinfo_tsn = chk->rec.data.TSN_seq;
267 1.1 rjs outinfo->sinfo_cumtsn = stcb->asoc.cumulative_tsn;
268 1.1 rjs ret->m_len = cmh->cmsg_len;
269 1.1 rjs stcb->asoc.my_rwnd_control_len +=
270 1.1 rjs CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
271 1.1 rjs
272 1.1 rjs return (ret);
273 1.1 rjs }
274 1.1 rjs
275 1.1 rjs int
276 1.1 rjs sctp_deliver_data(struct sctp_tcb *stcb, struct sctp_association *asoc,
277 1.1 rjs struct sctp_tmit_chunk *chk, int hold_locks)
278 1.1 rjs {
279 1.1 rjs struct mbuf *control, *m;
280 1.1 rjs int free_it;
281 1.1 rjs struct sockaddr_in6 sin6;
282 1.1 rjs const struct sockaddr *to;
283 1.1 rjs
284 1.1 rjs #ifdef SCTP_DEBUG
285 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
286 1.1 rjs printf("I am now in Deliver data! (%p)\n", chk);
287 1.1 rjs }
288 1.1 rjs #endif
289 1.1 rjs /* get a write lock on the inp if not already */
290 1.1 rjs if (hold_locks == 0) {
291 1.1 rjs SCTP_TCB_UNLOCK(stcb);
292 1.1 rjs SCTP_INP_WLOCK(stcb->sctp_ep);
293 1.1 rjs SCTP_TCB_LOCK(stcb);
294 1.1 rjs }
295 1.1 rjs free_it = 0;
296 1.1 rjs /* We always add it to the queue */
297 1.1 rjs if (stcb && (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
298 1.1 rjs /* socket above is long gone */
299 1.1 rjs #ifdef SCTP_DEBUG
300 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
301 1.1 rjs printf("gone is gone!\n");
302 1.1 rjs }
303 1.1 rjs #endif
304 1.1 rjs if (chk != NULL) {
305 1.1 rjs if (chk->data)
306 1.1 rjs sctp_m_freem(chk->data);
307 1.1 rjs chk->data = NULL;
308 1.1 rjs sctp_free_remote_addr(chk->whoTo);
309 1.1 rjs SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
310 1.1 rjs sctppcbinfo.ipi_count_chunk--;
311 1.1 rjs if ((int)sctppcbinfo.ipi_count_chunk < 0) {
312 1.1 rjs panic("Chunk count is negative");
313 1.1 rjs }
314 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
315 1.1 rjs }
316 1.1 rjs TAILQ_FOREACH(chk, &asoc->delivery_queue, sctp_next) {
317 1.1 rjs asoc->size_on_delivery_queue -= chk->send_size;
318 1.1 rjs asoc->cnt_on_delivery_queue--;
319 1.1 rjs /*
320 1.1 rjs * Lose the data pointer, since its in the socket buffer
321 1.1 rjs */
322 1.1 rjs if (chk->data)
323 1.1 rjs sctp_m_freem(chk->data);
324 1.1 rjs chk->data = NULL;
325 1.1 rjs /* Now free the address and data */
326 1.1 rjs sctp_free_remote_addr(chk->whoTo);
327 1.1 rjs SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
328 1.1 rjs sctppcbinfo.ipi_count_chunk--;
329 1.1 rjs if ((int)sctppcbinfo.ipi_count_chunk < 0) {
330 1.1 rjs panic("Chunk count is negative");
331 1.1 rjs }
332 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
333 1.1 rjs }
334 1.1 rjs if (hold_locks == 0) {
335 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
336 1.1 rjs }
337 1.1 rjs return (0);
338 1.1 rjs }
339 1.1 rjs if (chk != NULL) {
340 1.1 rjs TAILQ_INSERT_TAIL(&asoc->delivery_queue, chk, sctp_next);
341 1.1 rjs asoc->size_on_delivery_queue += chk->send_size;
342 1.1 rjs asoc->cnt_on_delivery_queue++;
343 1.1 rjs }
344 1.1 rjs if (asoc->fragmented_delivery_inprogress) {
345 1.1 rjs /*
346 1.1 rjs * oh oh, fragmented delivery in progress
347 1.1 rjs * return out of here.
348 1.1 rjs */
349 1.1 rjs #ifdef SCTP_DEBUG
350 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
351 1.1 rjs printf("Fragmented delivery in progress?\n");
352 1.1 rjs }
353 1.1 rjs #endif
354 1.1 rjs if (hold_locks == 0) {
355 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
356 1.1 rjs }
357 1.1 rjs return (0);
358 1.1 rjs }
359 1.1 rjs /* Now grab the first one */
360 1.1 rjs chk = TAILQ_FIRST(&asoc->delivery_queue);
361 1.1 rjs if (chk == NULL) {
362 1.1 rjs /* Nothing in queue */
363 1.1 rjs #ifdef SCTP_DEBUG
364 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
365 1.1 rjs printf("Nothing in queue?\n");
366 1.1 rjs }
367 1.1 rjs #endif
368 1.1 rjs asoc->size_on_delivery_queue = 0;
369 1.1 rjs asoc->cnt_on_delivery_queue = 0;
370 1.1 rjs if (hold_locks == 0) {
371 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
372 1.1 rjs }
373 1.1 rjs return (0);
374 1.1 rjs }
375 1.1 rjs
376 1.1 rjs if (stcb->sctp_socket->so_rcv.sb_cc >= stcb->sctp_socket->so_rcv.sb_hiwat) {
377 1.1 rjs /* Boy, there really is NO room */
378 1.1 rjs if (hold_locks == 0) {
379 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
380 1.1 rjs }
381 1.1 rjs return (0);
382 1.1 rjs }
383 1.1 rjs #ifdef SCTP_DEBUG
384 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
385 1.1 rjs printf("Now to the delivery with chk(%p)!\n", chk);
386 1.1 rjs }
387 1.1 rjs #endif
388 1.1 rjs /* XXX need to append PKTHDR to the socket buffer first */
389 1.1 rjs if ((chk->data->m_flags & M_PKTHDR) == 0) {
390 1.1 rjs MGETHDR(m, M_DONTWAIT, MT_DATA);
391 1.1 rjs if (m == NULL) {
392 1.1 rjs /* no room! */
393 1.1 rjs if (hold_locks == 0) {
394 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
395 1.1 rjs }
396 1.1 rjs return (0);
397 1.1 rjs }
398 1.1 rjs m->m_pkthdr.len = chk->send_size;
399 1.1 rjs m->m_len = 0;
400 1.1 rjs m->m_next = chk->data;
401 1.1 rjs chk->data = m;
402 1.1 rjs }
403 1.1 rjs if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
404 1.1 rjs if (chk->data->m_next == NULL) {
405 1.1 rjs /* hopefully we hit here most of the time */
406 1.1 rjs chk->data->m_flags |= M_EOR;
407 1.1 rjs } else {
408 1.1 rjs /* Add the flag to the LAST mbuf in the chain */
409 1.1 rjs m = chk->data;
410 1.1 rjs while (m->m_next != NULL) {
411 1.1 rjs m = m->m_next;
412 1.1 rjs }
413 1.1 rjs m->m_flags |= M_EOR;
414 1.1 rjs }
415 1.1 rjs }
416 1.1 rjs
417 1.1 rjs if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
418 1.1 rjs struct sockaddr_in6 lsa6;
419 1.1 rjs
420 1.1 rjs control = sctp_build_ctl(stcb, chk);
421 1.1 rjs to = rtcache_getdst(&chk->whoTo->ro);
422 1.1 rjs if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) &&
423 1.1 rjs to->sa_family == AF_INET) {
424 1.1 rjs const struct sockaddr_in *sin;
425 1.1 rjs
426 1.1 rjs sin = (const struct sockaddr_in *)to;
427 1.1 rjs memset(&sin6, 0, sizeof(sin6));
428 1.1 rjs sin6.sin6_family = AF_INET6;
429 1.1 rjs sin6.sin6_len = sizeof(struct sockaddr_in6);
430 1.1 rjs sin6.sin6_addr.s6_addr16[2] = 0xffff;
431 1.1 rjs bcopy(&sin->sin_addr, &sin6.sin6_addr.s6_addr16[3],
432 1.1 rjs sizeof(sin6.sin6_addr.s6_addr16[3]));
433 1.1 rjs sin6.sin6_port = sin->sin_port;
434 1.1 rjs to = (struct sockaddr *)&sin6;
435 1.1 rjs }
436 1.1 rjs /* check and strip embedded scope junk */
437 1.1 rjs to = (const struct sockaddr *)sctp_recover_scope((const struct sockaddr_in6 *)to,
438 1.1 rjs &lsa6);
439 1.1 rjs if (((const struct sockaddr_in *)to)->sin_port == 0) {
440 1.1 rjs printf("Huh a, port is %d not net:%p %d?\n",
441 1.1 rjs ((const struct sockaddr_in *)to)->sin_port,
442 1.1 rjs chk->whoTo,
443 1.1 rjs (int)(ntohs(stcb->rport)));
444 1.1 rjs /*((struct sockaddr_in *)to)->sin_port = stcb->rport;*/
445 1.1 rjs /* XXX */
446 1.1 rjs }
447 1.1 rjs if (sctp_sbspace(&stcb->sctp_socket->so_rcv) < (long)chk->send_size) {
448 1.1 rjs /* Gak not enough room */
449 1.1 rjs if (control) {
450 1.1 rjs sctp_m_freem(control);
451 1.1 rjs stcb->asoc.my_rwnd_control_len -=
452 1.1 rjs CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
453 1.1 rjs }
454 1.1 rjs goto skip;
455 1.1 rjs }
456 1.1 rjs if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv,
457 1.1 rjs to, chk->data, control, stcb->asoc.my_vtag,
458 1.1 rjs stcb->sctp_ep)) {
459 1.1 rjs /* Gak not enough room */
460 1.1 rjs if (control) {
461 1.1 rjs sctp_m_freem(control);
462 1.1 rjs stcb->asoc.my_rwnd_control_len -=
463 1.1 rjs CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
464 1.1 rjs }
465 1.1 rjs } else {
466 1.1 rjs if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) {
467 1.1 rjs if (sctp_add_to_socket_q(stcb->sctp_ep, stcb)) {
468 1.1 rjs stcb->asoc.my_rwnd_control_len +=
469 1.1 rjs sizeof(struct mbuf);
470 1.1 rjs }
471 1.1 rjs } else {
472 1.1 rjs stcb->asoc.my_rwnd_control_len += sizeof(struct mbuf);
473 1.1 rjs }
474 1.1 rjs free_it = 1;
475 1.1 rjs }
476 1.1 rjs } else {
477 1.1 rjs /* append to a already started message. */
478 1.1 rjs if (sctp_sbspace(&stcb->sctp_socket->so_rcv) >=
479 1.1 rjs (long)chk->send_size) {
480 1.1 rjs sbappend(&stcb->sctp_socket->so_rcv, chk->data);
481 1.1 rjs free_it = 1;
482 1.1 rjs }
483 1.1 rjs }
484 1.1 rjs skip:
485 1.1 rjs if (hold_locks == 0) {
486 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
487 1.1 rjs }
488 1.1 rjs /* free up the one we inserted */
489 1.1 rjs if (free_it) {
490 1.1 rjs /* Pull it off the queue */
491 1.1 rjs #ifdef SCTP_DEBUG
492 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
493 1.1 rjs printf("Free_it true, doing tickle wakeup\n");
494 1.1 rjs }
495 1.1 rjs #endif
496 1.1 rjs sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
497 1.1 rjs TAILQ_REMOVE(&asoc->delivery_queue, chk, sctp_next);
498 1.1 rjs asoc->size_on_delivery_queue -= chk->send_size;
499 1.1 rjs asoc->cnt_on_delivery_queue--;
500 1.1 rjs /* Lose the data pointer, since its in the socket buffer */
501 1.1 rjs chk->data = NULL;
502 1.1 rjs /* Now free the address and data */
503 1.1 rjs sctp_free_remote_addr(chk->whoTo);
504 1.1 rjs SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
505 1.1 rjs sctppcbinfo.ipi_count_chunk--;
506 1.1 rjs if ((int)sctppcbinfo.ipi_count_chunk < 0) {
507 1.1 rjs panic("Chunk count is negative");
508 1.1 rjs }
509 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
510 1.1 rjs }
511 1.1 rjs return (free_it);
512 1.1 rjs }
513 1.1 rjs
514 1.1 rjs /*
515 1.1 rjs * We are delivering currently from the reassembly queue. We must continue to
516 1.1 rjs * deliver until we either:
517 1.1 rjs * 1) run out of space.
518 1.1 rjs * 2) run out of sequential TSN's
519 1.1 rjs * 3) hit the SCTP_DATA_LAST_FRAG flag.
520 1.1 rjs */
521 1.1 rjs static void
522 1.1 rjs sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc, int hold_locks)
523 1.1 rjs {
524 1.1 rjs const struct sockaddr *to;
525 1.1 rjs struct sockaddr_in6 sin6;
526 1.1 rjs struct sctp_tmit_chunk *chk, *at;
527 1.1 rjs struct mbuf *control, *m;
528 1.1 rjs u_int16_t nxt_todel;
529 1.1 rjs u_int16_t stream_no;
530 1.1 rjs int cntDel;
531 1.1 rjs cntDel = stream_no = 0;
532 1.1 rjs if (hold_locks == 0) {
533 1.1 rjs /*
534 1.1 rjs * you always have the TCB lock, we need
535 1.1 rjs * to have the inp write lock as well.
536 1.1 rjs */
537 1.1 rjs SCTP_TCB_UNLOCK(stcb);
538 1.1 rjs SCTP_INP_WLOCK(stcb->sctp_ep);
539 1.1 rjs SCTP_TCB_LOCK(stcb);
540 1.1 rjs }
541 1.1 rjs if (stcb && (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
542 1.1 rjs /* socket above is long gone */
543 1.1 rjs asoc->fragmented_delivery_inprogress = 0;
544 1.1 rjs TAILQ_FOREACH(chk, &asoc->reasmqueue, sctp_next) {
545 1.1 rjs asoc->size_on_delivery_queue -= chk->send_size;
546 1.1 rjs asoc->cnt_on_delivery_queue--;
547 1.1 rjs /*
548 1.1 rjs * Lose the data pointer, since its in the socket buffer
549 1.1 rjs */
550 1.1 rjs if (chk->data)
551 1.1 rjs sctp_m_freem(chk->data);
552 1.1 rjs chk->data = NULL;
553 1.1 rjs /* Now free the address and data */
554 1.1 rjs sctp_free_remote_addr(chk->whoTo);
555 1.1 rjs SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
556 1.1 rjs sctppcbinfo.ipi_count_chunk--;
557 1.1 rjs if ((int)sctppcbinfo.ipi_count_chunk < 0) {
558 1.1 rjs panic("Chunk count is negative");
559 1.1 rjs }
560 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
561 1.1 rjs }
562 1.1 rjs if (hold_locks == 0) {
563 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
564 1.1 rjs }
565 1.1 rjs return;
566 1.1 rjs }
567 1.1 rjs do {
568 1.1 rjs if (stcb->sctp_socket->so_rcv.sb_cc >=
569 1.1 rjs stcb->sctp_socket->so_rcv.sb_hiwat) {
570 1.1 rjs if (cntDel) {
571 1.1 rjs sctp_sorwakeup(stcb->sctp_ep,
572 1.1 rjs stcb->sctp_socket);
573 1.1 rjs }
574 1.1 rjs if (hold_locks == 0) {
575 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
576 1.1 rjs }
577 1.1 rjs return;
578 1.1 rjs }
579 1.1 rjs chk = TAILQ_FIRST(&asoc->reasmqueue);
580 1.1 rjs if (chk == NULL) {
581 1.1 rjs if (cntDel) {
582 1.1 rjs sctp_sorwakeup(stcb->sctp_ep,
583 1.1 rjs stcb->sctp_socket);
584 1.1 rjs }
585 1.1 rjs if (hold_locks == 0) {
586 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
587 1.1 rjs }
588 1.1 rjs return;
589 1.1 rjs }
590 1.1 rjs if (chk->rec.data.TSN_seq != (asoc->tsn_last_delivered + 1)) {
591 1.1 rjs /* Can't deliver more :< */
592 1.1 rjs if (cntDel) {
593 1.1 rjs sctp_sorwakeup(stcb->sctp_ep,
594 1.1 rjs stcb->sctp_socket);
595 1.1 rjs }
596 1.1 rjs if (hold_locks == 0) {
597 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
598 1.1 rjs }
599 1.1 rjs return;
600 1.1 rjs }
601 1.1 rjs stream_no = chk->rec.data.stream_number;
602 1.1 rjs nxt_todel = asoc->strmin[stream_no].last_sequence_delivered + 1;
603 1.1 rjs if (nxt_todel != chk->rec.data.stream_seq &&
604 1.1 rjs (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) {
605 1.1 rjs /*
606 1.1 rjs * Not the next sequence to deliver in its stream OR
607 1.1 rjs * unordered
608 1.1 rjs */
609 1.1 rjs if (cntDel) {
610 1.1 rjs sctp_sorwakeup(stcb->sctp_ep,
611 1.1 rjs stcb->sctp_socket);
612 1.1 rjs }
613 1.1 rjs if (hold_locks == 0) {
614 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
615 1.1 rjs }
616 1.1 rjs return;
617 1.1 rjs }
618 1.1 rjs
619 1.1 rjs if ((chk->data->m_flags & M_PKTHDR) == 0) {
620 1.1 rjs MGETHDR(m, M_DONTWAIT, MT_DATA);
621 1.1 rjs if (m == NULL) {
622 1.1 rjs /* no room! */
623 1.1 rjs if (hold_locks == 0) {
624 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
625 1.1 rjs }
626 1.1 rjs return;
627 1.1 rjs }
628 1.1 rjs m->m_pkthdr.len = chk->send_size;
629 1.1 rjs m->m_len = 0;
630 1.1 rjs m->m_next = chk->data;
631 1.1 rjs chk->data = m;
632 1.1 rjs }
633 1.1 rjs if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
634 1.1 rjs if (chk->data->m_next == NULL) {
635 1.1 rjs /* hopefully we hit here most of the time */
636 1.1 rjs chk->data->m_flags |= M_EOR;
637 1.1 rjs } else {
638 1.1 rjs /* Add the flag to the LAST mbuf in the chain */
639 1.1 rjs m = chk->data;
640 1.1 rjs while (m->m_next != NULL) {
641 1.1 rjs m = m->m_next;
642 1.1 rjs }
643 1.1 rjs m->m_flags |= M_EOR;
644 1.1 rjs }
645 1.1 rjs }
646 1.1 rjs if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
647 1.1 rjs struct sockaddr_in6 lsa6;
648 1.1 rjs
649 1.1 rjs control = sctp_build_ctl(stcb, chk);
650 1.1 rjs to = rtcache_getdst(&chk->whoTo->ro);
651 1.1 rjs if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) &&
652 1.1 rjs to->sa_family == AF_INET) {
653 1.1 rjs const struct sockaddr_in *sin;
654 1.1 rjs
655 1.1 rjs sin = satocsin(to);
656 1.1 rjs memset(&sin6, 0, sizeof(sin6));
657 1.1 rjs sin6.sin6_family = AF_INET6;
658 1.1 rjs sin6.sin6_len = sizeof(struct sockaddr_in6);
659 1.1 rjs sin6.sin6_addr.s6_addr16[2] = 0xffff;
660 1.1 rjs bcopy(&sin->sin_addr,
661 1.1 rjs &sin6.sin6_addr.s6_addr16[3],
662 1.1 rjs sizeof(sin6.sin6_addr.s6_addr16[3]));
663 1.1 rjs sin6.sin6_port = sin->sin_port;
664 1.1 rjs to = (struct sockaddr *)&sin6;
665 1.1 rjs }
666 1.1 rjs /* check and strip embedded scope junk */
667 1.1 rjs to = (const struct sockaddr *)sctp_recover_scope((const struct sockaddr_in6 *)to,
668 1.1 rjs &lsa6);
669 1.1 rjs if (((const struct sockaddr_in *)to)->sin_port == 0) {
670 1.1 rjs printf("Huh b, port is %d not net:%p %d?\n",
671 1.1 rjs ((const struct sockaddr_in *)to)->sin_port,
672 1.1 rjs chk->whoTo,
673 1.1 rjs (int)(ntohs(stcb->rport)));
674 1.1 rjs /*((struct sockaddr_in *)to)->sin_port = stcb->rport;*/
675 1.1 rjs /* XXX */
676 1.1 rjs }
677 1.1 rjs if (sctp_sbspace(&stcb->sctp_socket->so_rcv) <
678 1.1 rjs (long)chk->send_size) {
679 1.1 rjs if (control) {
680 1.1 rjs sctp_m_freem(control);
681 1.1 rjs stcb->asoc.my_rwnd_control_len -=
682 1.1 rjs CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
683 1.1 rjs }
684 1.1 rjs sctp_sorwakeup(stcb->sctp_ep,
685 1.1 rjs stcb->sctp_socket);
686 1.1 rjs if (hold_locks == 0) {
687 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
688 1.1 rjs }
689 1.1 rjs return;
690 1.1 rjs }
691 1.1 rjs if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv,
692 1.1 rjs to, chk->data, control, stcb->asoc.my_vtag,
693 1.1 rjs stcb->sctp_ep)) {
694 1.1 rjs /* Gak not enough room */
695 1.1 rjs if (control) {
696 1.1 rjs sctp_m_freem(control);
697 1.1 rjs stcb->asoc.my_rwnd_control_len -=
698 1.1 rjs CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
699 1.1 rjs }
700 1.1 rjs sctp_sorwakeup(stcb->sctp_ep,
701 1.1 rjs stcb->sctp_socket);
702 1.1 rjs if (hold_locks == 0) {
703 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
704 1.1 rjs }
705 1.1 rjs return;
706 1.1 rjs }
707 1.1 rjs if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) {
708 1.1 rjs if (sctp_add_to_socket_q(stcb->sctp_ep, stcb)) {
709 1.1 rjs stcb->asoc.my_rwnd_control_len +=
710 1.1 rjs sizeof(struct mbuf);
711 1.1 rjs }
712 1.1 rjs } else {
713 1.1 rjs stcb->asoc.my_rwnd_control_len += sizeof(struct mbuf);
714 1.1 rjs }
715 1.1 rjs cntDel++;
716 1.1 rjs } else {
717 1.1 rjs if (sctp_sbspace(&stcb->sctp_socket->so_rcv) >=
718 1.1 rjs (long)chk->send_size) {
719 1.1 rjs sbappend(&stcb->sctp_socket->so_rcv, chk->data);
720 1.1 rjs cntDel++;
721 1.1 rjs } else {
722 1.1 rjs /* out of space in the sb */
723 1.1 rjs sctp_sorwakeup(stcb->sctp_ep,
724 1.1 rjs stcb->sctp_socket);
725 1.1 rjs if (hold_locks == 0) {
726 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
727 1.1 rjs }
728 1.1 rjs return;
729 1.1 rjs }
730 1.1 rjs }
731 1.1 rjs /* pull it we did it */
732 1.1 rjs TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
733 1.1 rjs if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
734 1.1 rjs asoc->fragmented_delivery_inprogress = 0;
735 1.1 rjs if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) {
736 1.1 rjs asoc->strmin[stream_no].last_sequence_delivered++;
737 1.1 rjs }
738 1.1 rjs }
739 1.1 rjs asoc->tsn_last_delivered = chk->rec.data.TSN_seq;
740 1.1 rjs asoc->size_on_reasm_queue -= chk->send_size;
741 1.1 rjs asoc->cnt_on_reasm_queue--;
742 1.1 rjs /* free up the chk */
743 1.1 rjs sctp_free_remote_addr(chk->whoTo);
744 1.1 rjs chk->data = NULL;
745 1.1 rjs SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
746 1.1 rjs sctppcbinfo.ipi_count_chunk--;
747 1.1 rjs if ((int)sctppcbinfo.ipi_count_chunk < 0) {
748 1.1 rjs panic("Chunk count is negative");
749 1.1 rjs }
750 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
751 1.1 rjs if (asoc->fragmented_delivery_inprogress == 0) {
752 1.1 rjs /*
753 1.1 rjs * Now lets see if we can deliver the next one on the
754 1.1 rjs * stream
755 1.1 rjs */
756 1.1 rjs /*u_int16_t nxt_todel;*/
757 1.1 rjs struct sctp_stream_in *strm;
758 1.1 rjs
759 1.1 rjs strm = &asoc->strmin[stream_no];
760 1.1 rjs nxt_todel = strm->last_sequence_delivered + 1;
761 1.1 rjs chk = TAILQ_FIRST(&strm->inqueue);
762 1.1 rjs if (chk && (nxt_todel == chk->rec.data.stream_seq)) {
763 1.1 rjs while (chk != NULL) {
764 1.1 rjs /* all delivered */
765 1.1 rjs if (nxt_todel ==
766 1.1 rjs chk->rec.data.stream_seq) {
767 1.1 rjs at = TAILQ_NEXT(chk, sctp_next);
768 1.1 rjs TAILQ_REMOVE(&strm->inqueue,
769 1.1 rjs chk, sctp_next);
770 1.1 rjs asoc->size_on_all_streams -=
771 1.1 rjs chk->send_size;
772 1.1 rjs asoc->cnt_on_all_streams--;
773 1.1 rjs strm->last_sequence_delivered++;
774 1.1 rjs /*
775 1.1 rjs * We ignore the return of
776 1.1 rjs * deliver_data here since we
777 1.1 rjs * always can hold the chunk on
778 1.1 rjs * the d-queue. And we have a
779 1.1 rjs * finite number that can be
780 1.1 rjs * delivered from the strq.
781 1.1 rjs */
782 1.1 rjs sctp_deliver_data(stcb, asoc, chk, 1);
783 1.1 rjs chk = at;
784 1.1 rjs } else {
785 1.1 rjs break;
786 1.1 rjs }
787 1.1 rjs nxt_todel =
788 1.1 rjs strm->last_sequence_delivered + 1;
789 1.1 rjs }
790 1.1 rjs }
791 1.1 rjs if (!TAILQ_EMPTY(&asoc->delivery_queue)) {
792 1.1 rjs /* Here if deliver_data fails, we must break */
793 1.1 rjs if (sctp_deliver_data(stcb, asoc, NULL, 1) == 0)
794 1.1 rjs break;
795 1.1 rjs }
796 1.1 rjs sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
797 1.1 rjs if (hold_locks == 0) {
798 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
799 1.1 rjs }
800 1.1 rjs return;
801 1.1 rjs }
802 1.1 rjs chk = TAILQ_FIRST(&asoc->reasmqueue);
803 1.1 rjs } while (chk);
804 1.1 rjs if (cntDel) {
805 1.1 rjs sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
806 1.1 rjs }
807 1.1 rjs if (hold_locks == 0) {
808 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
809 1.1 rjs }
810 1.1 rjs }
811 1.1 rjs
812 1.1 rjs /*
813 1.1 rjs * Queue the chunk either right into the socket buffer if it is the next one
814 1.1 rjs * to go OR put it in the correct place in the delivery queue. If we do
815 1.1 rjs * append to the so_buf, keep doing so until we are out of order.
816 1.1 rjs * One big question still remains, what to do when the socket buffer is FULL??
817 1.1 rjs */
818 1.1 rjs static void
819 1.1 rjs sctp_queue_data_to_stream(struct sctp_tcb *stcb, struct sctp_association *asoc,
820 1.1 rjs struct sctp_tmit_chunk *chk, int *abort_flag)
821 1.1 rjs {
822 1.1 rjs struct sctp_stream_in *strm;
823 1.1 rjs struct sctp_tmit_chunk *at;
824 1.1 rjs int queue_needed;
825 1.1 rjs u_int16_t nxt_todel;
826 1.1 rjs struct mbuf *oper;
827 1.1 rjs
828 1.1 rjs /*** FIX FIX FIX ???
829 1.1 rjs * Need to add code to deal with 16 bit seq wrap
830 1.1 rjs * without a TSN wrap for ordered delivery (maybe).
831 1.1 rjs * FIX FIX FIX ???
832 1.1 rjs */
833 1.1 rjs queue_needed = 1;
834 1.1 rjs asoc->size_on_all_streams += chk->send_size;
835 1.1 rjs asoc->cnt_on_all_streams++;
836 1.1 rjs strm = &asoc->strmin[chk->rec.data.stream_number];
837 1.1 rjs nxt_todel = strm->last_sequence_delivered + 1;
838 1.1 rjs #ifdef SCTP_STR_LOGGING
839 1.1 rjs sctp_log_strm_del(chk, NULL, SCTP_STR_LOG_FROM_INTO_STRD);
840 1.1 rjs #endif
841 1.1 rjs #ifdef SCTP_DEBUG
842 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
843 1.1 rjs printf("queue to stream called for ssn:%u lastdel:%u nxt:%u\n",
844 1.1 rjs (u_int)chk->rec.data.stream_seq,
845 1.1 rjs (u_int)strm->last_sequence_delivered, (u_int)nxt_todel);
846 1.1 rjs }
847 1.1 rjs #endif
848 1.1 rjs if (compare_with_wrap(strm->last_sequence_delivered,
849 1.1 rjs chk->rec.data.stream_seq, MAX_SEQ) ||
850 1.1 rjs (strm->last_sequence_delivered == chk->rec.data.stream_seq)) {
851 1.1 rjs /* The incoming sseq is behind where we last delivered? */
852 1.1 rjs #ifdef SCTP_DEBUG
853 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
854 1.1 rjs printf("Duplicate S-SEQ:%d delivered:%d from peer, Abort association\n",
855 1.1 rjs chk->rec.data.stream_seq,
856 1.1 rjs strm->last_sequence_delivered);
857 1.1 rjs }
858 1.1 rjs #endif
859 1.1 rjs /*
860 1.1 rjs * throw it in the stream so it gets cleaned up in
861 1.1 rjs * association destruction
862 1.1 rjs */
863 1.1 rjs TAILQ_INSERT_HEAD(&strm->inqueue, chk, sctp_next);
864 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
865 1.1 rjs if (oper) {
866 1.1 rjs struct sctp_paramhdr *ph;
867 1.1 rjs u_int32_t *ippp;
868 1.1 rjs
869 1.1 rjs oper->m_len = sizeof(struct sctp_paramhdr) +
870 1.1 rjs sizeof(*ippp);
871 1.1 rjs ph = mtod(oper, struct sctp_paramhdr *);
872 1.1 rjs ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
873 1.1 rjs ph->param_length = htons(oper->m_len);
874 1.1 rjs ippp = (u_int32_t *)(ph + 1);
875 1.1 rjs *ippp = htonl(0x00000001);
876 1.1 rjs }
877 1.1 rjs sctp_abort_an_association(stcb->sctp_ep, stcb,
878 1.1 rjs SCTP_PEER_FAULTY, oper);
879 1.1 rjs
880 1.1 rjs *abort_flag = 1;
881 1.1 rjs return;
882 1.1 rjs
883 1.1 rjs }
884 1.1 rjs if (nxt_todel == chk->rec.data.stream_seq) {
885 1.1 rjs /* can be delivered right away */
886 1.1 rjs #ifdef SCTP_DEBUG
887 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
888 1.1 rjs printf("It's NEXT!\n");
889 1.1 rjs }
890 1.1 rjs #endif
891 1.1 rjs #ifdef SCTP_STR_LOGGING
892 1.1 rjs sctp_log_strm_del(chk, NULL, SCTP_STR_LOG_FROM_IMMED_DEL);
893 1.1 rjs #endif
894 1.1 rjs queue_needed = 0;
895 1.1 rjs asoc->size_on_all_streams -= chk->send_size;
896 1.1 rjs asoc->cnt_on_all_streams--;
897 1.1 rjs strm->last_sequence_delivered++;
898 1.1 rjs sctp_deliver_data(stcb, asoc, chk, 0);
899 1.1 rjs chk = TAILQ_FIRST(&strm->inqueue);
900 1.1 rjs while (chk != NULL) {
901 1.1 rjs /* all delivered */
902 1.1 rjs nxt_todel = strm->last_sequence_delivered + 1;
903 1.1 rjs if (nxt_todel == chk->rec.data.stream_seq) {
904 1.1 rjs at = TAILQ_NEXT(chk, sctp_next);
905 1.1 rjs TAILQ_REMOVE(&strm->inqueue, chk, sctp_next);
906 1.1 rjs asoc->size_on_all_streams -= chk->send_size;
907 1.1 rjs asoc->cnt_on_all_streams--;
908 1.1 rjs strm->last_sequence_delivered++;
909 1.1 rjs /*
910 1.1 rjs * We ignore the return of deliver_data here
911 1.1 rjs * since we always can hold the chunk on the
912 1.1 rjs * d-queue. And we have a finite number that
913 1.1 rjs * can be delivered from the strq.
914 1.1 rjs */
915 1.1 rjs #ifdef SCTP_STR_LOGGING
916 1.1 rjs sctp_log_strm_del(chk, NULL,
917 1.1 rjs SCTP_STR_LOG_FROM_IMMED_DEL);
918 1.1 rjs #endif
919 1.1 rjs sctp_deliver_data(stcb, asoc, chk, 0);
920 1.1 rjs chk = at;
921 1.1 rjs continue;
922 1.1 rjs }
923 1.1 rjs break;
924 1.1 rjs }
925 1.1 rjs }
926 1.1 rjs if (queue_needed) {
927 1.1 rjs /*
928 1.1 rjs * Ok, we did not deliver this guy, find
929 1.1 rjs * the correct place to put it on the queue.
930 1.1 rjs */
931 1.1 rjs #ifdef SCTP_DEBUG
932 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
933 1.1 rjs printf("Queue Needed!\n");
934 1.1 rjs }
935 1.1 rjs #endif
936 1.1 rjs if (TAILQ_EMPTY(&strm->inqueue)) {
937 1.1 rjs /* Empty queue */
938 1.1 rjs #ifdef SCTP_STR_LOGGING
939 1.1 rjs sctp_log_strm_del(chk, NULL, SCTP_STR_LOG_FROM_INSERT_HD);
940 1.1 rjs #endif
941 1.1 rjs TAILQ_INSERT_HEAD(&strm->inqueue, chk, sctp_next);
942 1.1 rjs } else {
943 1.1 rjs TAILQ_FOREACH(at, &strm->inqueue, sctp_next) {
944 1.1 rjs if (compare_with_wrap(at->rec.data.stream_seq,
945 1.1 rjs chk->rec.data.stream_seq, MAX_SEQ)) {
946 1.1 rjs /*
947 1.1 rjs * one in queue is bigger than the new
948 1.1 rjs * one, insert before this one
949 1.1 rjs */
950 1.1 rjs #ifdef SCTP_STR_LOGGING
951 1.1 rjs sctp_log_strm_del(chk, at,
952 1.1 rjs SCTP_STR_LOG_FROM_INSERT_MD);
953 1.1 rjs #endif
954 1.1 rjs TAILQ_INSERT_BEFORE(at, chk, sctp_next);
955 1.1 rjs break;
956 1.1 rjs } else if (at->rec.data.stream_seq ==
957 1.1 rjs chk->rec.data.stream_seq) {
958 1.1 rjs /*
959 1.1 rjs * Gak, He sent me a duplicate str seq
960 1.1 rjs * number
961 1.1 rjs */
962 1.1 rjs /*
963 1.1 rjs * foo bar, I guess I will just free
964 1.1 rjs * this new guy, should we abort too?
965 1.1 rjs * FIX ME MAYBE? Or it COULD be that
966 1.1 rjs * the SSN's have wrapped. Maybe I
967 1.1 rjs * should compare to TSN somehow...
968 1.1 rjs * sigh for now just blow away the
969 1.1 rjs * chunk!
970 1.1 rjs */
971 1.1 rjs
972 1.1 rjs if (chk->data)
973 1.1 rjs sctp_m_freem(chk->data);
974 1.1 rjs chk->data = NULL;
975 1.1 rjs asoc->size_on_all_streams -= chk->send_size;
976 1.1 rjs asoc->cnt_on_all_streams--;
977 1.1 rjs sctp_pegs[SCTP_DUP_SSN_RCVD]++;
978 1.1 rjs sctp_free_remote_addr(chk->whoTo);
979 1.1 rjs SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
980 1.1 rjs sctppcbinfo.ipi_count_chunk--;
981 1.1 rjs if ((int)sctppcbinfo.ipi_count_chunk <
982 1.1 rjs 0) {
983 1.1 rjs panic("Chunk count is negative");
984 1.1 rjs }
985 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
986 1.1 rjs return;
987 1.1 rjs } else {
988 1.1 rjs if (TAILQ_NEXT(at, sctp_next) == NULL) {
989 1.1 rjs /*
990 1.1 rjs * We are at the end, insert it
991 1.1 rjs * after this one
992 1.1 rjs */
993 1.1 rjs #ifdef SCTP_STR_LOGGING
994 1.1 rjs sctp_log_strm_del(chk, at,
995 1.1 rjs SCTP_STR_LOG_FROM_INSERT_TL);
996 1.1 rjs #endif
997 1.1 rjs TAILQ_INSERT_AFTER(&strm->inqueue,
998 1.1 rjs at, chk, sctp_next);
999 1.1 rjs break;
1000 1.1 rjs }
1001 1.1 rjs }
1002 1.1 rjs }
1003 1.1 rjs }
1004 1.1 rjs } else {
1005 1.1 rjs /* We delivered some chunks, wake them up */
1006 1.1 rjs
1007 1.1 rjs #ifdef SCTP_DEBUG
1008 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1009 1.1 rjs printf("Doing WAKEUP!\n");
1010 1.1 rjs }
1011 1.1 rjs #endif
1012 1.1 rjs sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
1013 1.1 rjs }
1014 1.1 rjs }
1015 1.1 rjs
1016 1.1 rjs /*
1017 1.1 rjs * Returns two things: You get the total size of the deliverable parts of the
1018 1.1 rjs * first fragmented message on the reassembly queue. And you get a 1 back if
1019 1.1 rjs * all of the message is ready or a 0 back if the message is still incomplete
1020 1.1 rjs */
1021 1.1 rjs static int
1022 1.1 rjs sctp_is_all_msg_on_reasm(struct sctp_association *asoc, int *t_size)
1023 1.1 rjs {
1024 1.1 rjs struct sctp_tmit_chunk *chk;
1025 1.1 rjs u_int32_t tsn;
1026 1.1 rjs
1027 1.1 rjs *t_size = 0;
1028 1.1 rjs chk = TAILQ_FIRST(&asoc->reasmqueue);
1029 1.1 rjs if (chk == NULL) {
1030 1.1 rjs /* nothing on the queue */
1031 1.1 rjs return (0);
1032 1.1 rjs }
1033 1.1 rjs if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) {
1034 1.1 rjs /* Not a first on the queue */
1035 1.1 rjs return (0);
1036 1.1 rjs }
1037 1.1 rjs tsn = chk->rec.data.TSN_seq;
1038 1.1 rjs while (chk) {
1039 1.1 rjs if (tsn != chk->rec.data.TSN_seq) {
1040 1.1 rjs return (0);
1041 1.1 rjs }
1042 1.1 rjs *t_size += chk->send_size;
1043 1.1 rjs if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
1044 1.1 rjs return (1);
1045 1.1 rjs }
1046 1.1 rjs tsn++;
1047 1.1 rjs chk = TAILQ_NEXT(chk, sctp_next);
1048 1.1 rjs }
1049 1.1 rjs return (0);
1050 1.1 rjs }
1051 1.1 rjs
1052 1.1 rjs /*
1053 1.1 rjs * Dump onto the re-assembly queue, in its proper place. After dumping on
1054 1.1 rjs * the queue, see if anthing can be delivered. If so pull it off (or as much
1055 1.1 rjs * as we can. If we run out of space then we must dump what we can and set
1056 1.1 rjs * the appropriate flag to say we queued what we could.
1057 1.1 rjs */
1058 1.1 rjs static void
1059 1.1 rjs sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
1060 1.1 rjs struct sctp_tmit_chunk *chk, int *abort_flag)
1061 1.1 rjs {
1062 1.1 rjs struct mbuf *oper;
1063 1.1 rjs u_int16_t nxt_todel;
1064 1.1 rjs u_int32_t cum_ackp1, prev_tsn, post_tsn;
1065 1.1 rjs int tsize;
1066 1.1 rjs struct sctp_tmit_chunk *at, *prev, *next;
1067 1.1 rjs
1068 1.1 rjs prev = next = NULL;
1069 1.1 rjs cum_ackp1 = asoc->tsn_last_delivered + 1;
1070 1.1 rjs
1071 1.1 rjs if (TAILQ_EMPTY(&asoc->reasmqueue)) {
1072 1.1 rjs /* This is the first one on the queue */
1073 1.1 rjs TAILQ_INSERT_HEAD(&asoc->reasmqueue, chk, sctp_next);
1074 1.1 rjs /*
1075 1.1 rjs * we do not check for delivery of anything when
1076 1.1 rjs * only one fragment is here
1077 1.1 rjs */
1078 1.1 rjs asoc->size_on_reasm_queue = chk->send_size;
1079 1.1 rjs asoc->cnt_on_reasm_queue++;
1080 1.1 rjs if (chk->rec.data.TSN_seq == cum_ackp1) {
1081 1.1 rjs if (asoc->fragmented_delivery_inprogress == 0 &&
1082 1.1 rjs (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) !=
1083 1.1 rjs SCTP_DATA_FIRST_FRAG) {
1084 1.1 rjs /*
1085 1.1 rjs * An empty queue, no delivery inprogress, we
1086 1.1 rjs * hit the next one and it does NOT have a
1087 1.1 rjs * FIRST fragment mark.
1088 1.1 rjs */
1089 1.1 rjs #ifdef SCTP_DEBUG
1090 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1091 1.1 rjs printf("Gak, Evil plot, its not first, no fragmented delivery in progress\n");
1092 1.1 rjs }
1093 1.1 rjs #endif
1094 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1095 1.1 rjs if (oper) {
1096 1.1 rjs struct sctp_paramhdr *ph;
1097 1.1 rjs u_int32_t *ippp;
1098 1.1 rjs
1099 1.1 rjs oper->m_len =
1100 1.1 rjs sizeof(struct sctp_paramhdr) +
1101 1.1 rjs sizeof(*ippp);
1102 1.1 rjs ph = mtod(oper, struct sctp_paramhdr *);
1103 1.1 rjs ph->param_type =
1104 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1105 1.1 rjs ph->param_length = htons(oper->m_len);
1106 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1107 1.1 rjs *ippp = htonl(0x10000001);
1108 1.1 rjs }
1109 1.1 rjs sctp_abort_an_association(stcb->sctp_ep, stcb,
1110 1.1 rjs SCTP_PEER_FAULTY, oper);
1111 1.1 rjs *abort_flag = 1;
1112 1.1 rjs } else if (asoc->fragmented_delivery_inprogress &&
1113 1.1 rjs (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) {
1114 1.1 rjs /*
1115 1.1 rjs * We are doing a partial delivery and the NEXT
1116 1.1 rjs * chunk MUST be either the LAST or MIDDLE
1117 1.1 rjs * fragment NOT a FIRST
1118 1.1 rjs */
1119 1.1 rjs #ifdef SCTP_DEBUG
1120 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1121 1.1 rjs printf("Gak, Evil plot, it IS a first and fragmented delivery in progress\n");
1122 1.1 rjs }
1123 1.1 rjs #endif
1124 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1125 1.1 rjs if (oper) {
1126 1.1 rjs struct sctp_paramhdr *ph;
1127 1.1 rjs u_int32_t *ippp;
1128 1.1 rjs
1129 1.1 rjs oper->m_len =
1130 1.1 rjs sizeof(struct sctp_paramhdr) +
1131 1.1 rjs sizeof(*ippp);
1132 1.1 rjs ph = mtod(oper, struct sctp_paramhdr *);
1133 1.1 rjs ph->param_type =
1134 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1135 1.1 rjs ph->param_length = htons(oper->m_len);
1136 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1137 1.1 rjs *ippp = htonl(0x10000002);
1138 1.1 rjs }
1139 1.1 rjs sctp_abort_an_association(stcb->sctp_ep, stcb,
1140 1.1 rjs SCTP_PEER_FAULTY, oper);
1141 1.1 rjs *abort_flag = 1;
1142 1.1 rjs } else if (asoc->fragmented_delivery_inprogress) {
1143 1.1 rjs /* Here we are ok with a MIDDLE or LAST piece */
1144 1.1 rjs if (chk->rec.data.stream_number !=
1145 1.1 rjs asoc->str_of_pdapi) {
1146 1.1 rjs /* Got to be the right STR No */
1147 1.1 rjs #ifdef SCTP_DEBUG
1148 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1149 1.1 rjs printf("Gak, Evil plot, it IS not same stream number %d vs %d\n",
1150 1.1 rjs chk->rec.data.stream_number,
1151 1.1 rjs asoc->str_of_pdapi);
1152 1.1 rjs }
1153 1.1 rjs #endif
1154 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1155 1.1 rjs if (oper) {
1156 1.1 rjs struct sctp_paramhdr *ph;
1157 1.1 rjs u_int32_t *ippp;
1158 1.1 rjs oper->m_len =
1159 1.1 rjs sizeof(struct sctp_paramhdr) +
1160 1.1 rjs sizeof(*ippp);
1161 1.1 rjs ph = mtod(oper,
1162 1.1 rjs struct sctp_paramhdr *);
1163 1.1 rjs ph->param_type =
1164 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1165 1.1 rjs ph->param_length =
1166 1.1 rjs htons(oper->m_len);
1167 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1168 1.1 rjs *ippp = htonl(0x10000003);
1169 1.1 rjs }
1170 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1171 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1172 1.1 rjs *abort_flag = 1;
1173 1.1 rjs } else if ((asoc->fragment_flags & SCTP_DATA_UNORDERED) !=
1174 1.1 rjs SCTP_DATA_UNORDERED &&
1175 1.1 rjs chk->rec.data.stream_seq !=
1176 1.1 rjs asoc->ssn_of_pdapi) {
1177 1.1 rjs /* Got to be the right STR Seq */
1178 1.1 rjs #ifdef SCTP_DEBUG
1179 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1180 1.1 rjs printf("Gak, Evil plot, it IS not same stream seq %d vs %d\n",
1181 1.1 rjs chk->rec.data.stream_seq,
1182 1.1 rjs asoc->ssn_of_pdapi);
1183 1.1 rjs }
1184 1.1 rjs #endif
1185 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1186 1.1 rjs if (oper) {
1187 1.1 rjs struct sctp_paramhdr *ph;
1188 1.1 rjs u_int32_t *ippp;
1189 1.1 rjs oper->m_len =
1190 1.1 rjs sizeof(struct sctp_paramhdr) +
1191 1.1 rjs sizeof(*ippp);
1192 1.1 rjs ph = mtod(oper,
1193 1.1 rjs struct sctp_paramhdr *);
1194 1.1 rjs ph->param_type =
1195 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1196 1.1 rjs ph->param_length =
1197 1.1 rjs htons(oper->m_len);
1198 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1199 1.1 rjs *ippp = htonl(0x10000004);
1200 1.1 rjs }
1201 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1202 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1203 1.1 rjs *abort_flag = 1;
1204 1.1 rjs }
1205 1.1 rjs }
1206 1.1 rjs }
1207 1.1 rjs return;
1208 1.1 rjs }
1209 1.1 rjs /* Find its place */
1210 1.1 rjs at = TAILQ_FIRST(&asoc->reasmqueue);
1211 1.1 rjs
1212 1.1 rjs /* Grab the top flags */
1213 1.1 rjs TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) {
1214 1.1 rjs if (compare_with_wrap(at->rec.data.TSN_seq,
1215 1.1 rjs chk->rec.data.TSN_seq, MAX_TSN)) {
1216 1.1 rjs /*
1217 1.1 rjs * one in queue is bigger than the new one, insert
1218 1.1 rjs * before this one
1219 1.1 rjs */
1220 1.1 rjs /* A check */
1221 1.1 rjs asoc->size_on_reasm_queue += chk->send_size;
1222 1.1 rjs asoc->cnt_on_reasm_queue++;
1223 1.1 rjs next = at;
1224 1.1 rjs TAILQ_INSERT_BEFORE(at, chk, sctp_next);
1225 1.1 rjs break;
1226 1.1 rjs } else if (at->rec.data.TSN_seq == chk->rec.data.TSN_seq) {
1227 1.1 rjs /* Gak, He sent me a duplicate str seq number */
1228 1.1 rjs /*
1229 1.1 rjs * foo bar, I guess I will just free this new guy,
1230 1.1 rjs * should we abort too? FIX ME MAYBE? Or it COULD be
1231 1.1 rjs * that the SSN's have wrapped. Maybe I should compare
1232 1.1 rjs * to TSN somehow... sigh for now just blow away the
1233 1.1 rjs * chunk!
1234 1.1 rjs */
1235 1.1 rjs if (chk->data)
1236 1.1 rjs sctp_m_freem(chk->data);
1237 1.1 rjs chk->data = NULL;
1238 1.1 rjs sctp_free_remote_addr(chk->whoTo);
1239 1.1 rjs SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
1240 1.1 rjs sctppcbinfo.ipi_count_chunk--;
1241 1.1 rjs if ((int)sctppcbinfo.ipi_count_chunk < 0) {
1242 1.1 rjs panic("Chunk count is negative");
1243 1.1 rjs }
1244 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
1245 1.1 rjs return;
1246 1.1 rjs } else {
1247 1.1 rjs prev = at;
1248 1.1 rjs if (TAILQ_NEXT(at, sctp_next) == NULL) {
1249 1.1 rjs /*
1250 1.1 rjs * We are at the end, insert it after this one
1251 1.1 rjs */
1252 1.1 rjs /* check it first */
1253 1.1 rjs asoc->size_on_reasm_queue += chk->send_size;
1254 1.1 rjs asoc->cnt_on_reasm_queue++;
1255 1.1 rjs TAILQ_INSERT_AFTER(&asoc->reasmqueue, at, chk, sctp_next);
1256 1.1 rjs break;
1257 1.1 rjs }
1258 1.1 rjs }
1259 1.1 rjs }
1260 1.1 rjs /* Now the audits */
1261 1.1 rjs if (prev) {
1262 1.1 rjs prev_tsn = chk->rec.data.TSN_seq - 1;
1263 1.1 rjs if (prev_tsn == prev->rec.data.TSN_seq) {
1264 1.1 rjs /*
1265 1.1 rjs * Ok the one I am dropping onto the end
1266 1.1 rjs * is the NEXT. A bit of valdiation here.
1267 1.1 rjs */
1268 1.1 rjs if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1269 1.1 rjs SCTP_DATA_FIRST_FRAG ||
1270 1.1 rjs (prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1271 1.1 rjs SCTP_DATA_MIDDLE_FRAG) {
1272 1.1 rjs /*
1273 1.1 rjs * Insert chk MUST be a MIDDLE or LAST fragment
1274 1.1 rjs */
1275 1.1 rjs if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1276 1.1 rjs SCTP_DATA_FIRST_FRAG) {
1277 1.1 rjs #ifdef SCTP_DEBUG
1278 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1279 1.1 rjs printf("Prev check - It can be a midlle or last but not a first\n");
1280 1.1 rjs printf("Gak, Evil plot, it's a FIRST!\n");
1281 1.1 rjs }
1282 1.1 rjs #endif
1283 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1284 1.1 rjs if (oper) {
1285 1.1 rjs struct sctp_paramhdr *ph;
1286 1.1 rjs u_int32_t *ippp;
1287 1.1 rjs
1288 1.1 rjs oper->m_len =
1289 1.1 rjs sizeof(struct sctp_paramhdr) +
1290 1.1 rjs sizeof(*ippp);
1291 1.1 rjs ph = mtod(oper,
1292 1.1 rjs struct sctp_paramhdr *);
1293 1.1 rjs ph->param_type =
1294 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1295 1.1 rjs ph->param_length =
1296 1.1 rjs htons(oper->m_len);
1297 1.1 rjs
1298 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1299 1.1 rjs *ippp = htonl(0x10000005);
1300 1.1 rjs }
1301 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1302 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1303 1.1 rjs *abort_flag = 1;
1304 1.1 rjs return;
1305 1.1 rjs }
1306 1.1 rjs if (chk->rec.data.stream_number !=
1307 1.1 rjs prev->rec.data.stream_number) {
1308 1.1 rjs /*
1309 1.1 rjs * Huh, need the correct STR here, they
1310 1.1 rjs * must be the same.
1311 1.1 rjs */
1312 1.1 rjs #ifdef SCTP_DEBUG
1313 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1314 1.1 rjs printf("Prev check - Gak, Evil plot, ssn:%d not the same as at:%d\n",
1315 1.1 rjs chk->rec.data.stream_number,
1316 1.1 rjs prev->rec.data.stream_number);
1317 1.1 rjs }
1318 1.1 rjs #endif
1319 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1320 1.1 rjs if (oper) {
1321 1.1 rjs struct sctp_paramhdr *ph;
1322 1.1 rjs u_int32_t *ippp;
1323 1.1 rjs
1324 1.1 rjs oper->m_len =
1325 1.1 rjs sizeof(struct sctp_paramhdr) +
1326 1.1 rjs sizeof(*ippp);
1327 1.1 rjs ph = mtod(oper,
1328 1.1 rjs struct sctp_paramhdr *);
1329 1.1 rjs ph->param_type =
1330 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1331 1.1 rjs ph->param_length =
1332 1.1 rjs htons(oper->m_len);
1333 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1334 1.1 rjs *ippp = htonl(0x10000006);
1335 1.1 rjs }
1336 1.1 rjs
1337 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1338 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1339 1.1 rjs
1340 1.1 rjs *abort_flag = 1;
1341 1.1 rjs return;
1342 1.1 rjs }
1343 1.1 rjs if ((prev->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 &&
1344 1.1 rjs chk->rec.data.stream_seq !=
1345 1.1 rjs prev->rec.data.stream_seq) {
1346 1.1 rjs /*
1347 1.1 rjs * Huh, need the correct STR here, they
1348 1.1 rjs * must be the same.
1349 1.1 rjs */
1350 1.1 rjs #ifdef SCTP_DEBUG
1351 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1352 1.1 rjs printf("Prev check - Gak, Evil plot, sseq:%d not the same as at:%d\n",
1353 1.1 rjs chk->rec.data.stream_seq,
1354 1.1 rjs prev->rec.data.stream_seq);
1355 1.1 rjs }
1356 1.1 rjs #endif
1357 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1358 1.1 rjs if (oper) {
1359 1.1 rjs struct sctp_paramhdr *ph;
1360 1.1 rjs u_int32_t *ippp;
1361 1.1 rjs
1362 1.1 rjs oper->m_len =
1363 1.1 rjs sizeof(struct sctp_paramhdr) +
1364 1.1 rjs sizeof(*ippp);
1365 1.1 rjs ph = mtod(oper,
1366 1.1 rjs struct sctp_paramhdr *);
1367 1.1 rjs ph->param_type =
1368 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1369 1.1 rjs ph->param_length =
1370 1.1 rjs htons(oper->m_len);
1371 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1372 1.1 rjs *ippp = htonl(0x10000007);
1373 1.1 rjs }
1374 1.1 rjs
1375 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1376 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1377 1.1 rjs
1378 1.1 rjs *abort_flag = 1;
1379 1.1 rjs return;
1380 1.1 rjs }
1381 1.1 rjs } else if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1382 1.1 rjs SCTP_DATA_LAST_FRAG) {
1383 1.1 rjs /* Insert chk MUST be a FIRST */
1384 1.1 rjs if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
1385 1.1 rjs SCTP_DATA_FIRST_FRAG) {
1386 1.1 rjs #ifdef SCTP_DEBUG
1387 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1388 1.1 rjs printf("Prev check - Gak, evil plot, its not FIRST and it must be!\n");
1389 1.1 rjs }
1390 1.1 rjs #endif
1391 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1392 1.1 rjs if (oper) {
1393 1.1 rjs struct sctp_paramhdr *ph;
1394 1.1 rjs u_int32_t *ippp;
1395 1.1 rjs
1396 1.1 rjs oper->m_len =
1397 1.1 rjs sizeof(struct sctp_paramhdr) +
1398 1.1 rjs sizeof(*ippp);
1399 1.1 rjs ph = mtod(oper,
1400 1.1 rjs struct sctp_paramhdr *);
1401 1.1 rjs ph->param_type =
1402 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1403 1.1 rjs ph->param_length =
1404 1.1 rjs htons(oper->m_len);
1405 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1406 1.1 rjs *ippp = htonl(0x10000008);
1407 1.1 rjs }
1408 1.1 rjs
1409 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1410 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1411 1.1 rjs
1412 1.1 rjs *abort_flag = 1;
1413 1.1 rjs return;
1414 1.1 rjs }
1415 1.1 rjs }
1416 1.1 rjs }
1417 1.1 rjs }
1418 1.1 rjs
1419 1.1 rjs if (next) {
1420 1.1 rjs post_tsn = chk->rec.data.TSN_seq + 1;
1421 1.1 rjs if (post_tsn == next->rec.data.TSN_seq) {
1422 1.1 rjs /*
1423 1.1 rjs * Ok the one I am inserting ahead of
1424 1.1 rjs * is my NEXT one. A bit of valdiation here.
1425 1.1 rjs */
1426 1.1 rjs if (next->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
1427 1.1 rjs /* Insert chk MUST be a last fragment */
1428 1.1 rjs if ((chk->rec.data.rcv_flags&SCTP_DATA_FRAG_MASK)
1429 1.1 rjs != SCTP_DATA_LAST_FRAG) {
1430 1.1 rjs #ifdef SCTP_DEBUG
1431 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1432 1.1 rjs printf("Next chk - Next is FIRST, we must be LAST\n");
1433 1.1 rjs printf("Gak, Evil plot, its not a last!\n");
1434 1.1 rjs }
1435 1.1 rjs #endif
1436 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1437 1.1 rjs if (oper) {
1438 1.1 rjs struct sctp_paramhdr *ph;
1439 1.1 rjs u_int32_t *ippp;
1440 1.1 rjs
1441 1.1 rjs oper->m_len =
1442 1.1 rjs sizeof(struct sctp_paramhdr) +
1443 1.1 rjs sizeof(*ippp);
1444 1.1 rjs ph = mtod(oper,
1445 1.1 rjs struct sctp_paramhdr *);
1446 1.1 rjs ph->param_type =
1447 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1448 1.1 rjs ph->param_length =
1449 1.1 rjs htons(oper->m_len);
1450 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1451 1.1 rjs *ippp = htonl(0x10000009);
1452 1.1 rjs }
1453 1.1 rjs
1454 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1455 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1456 1.1 rjs
1457 1.1 rjs *abort_flag = 1;
1458 1.1 rjs return;
1459 1.1 rjs }
1460 1.1 rjs } else if ((next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1461 1.1 rjs SCTP_DATA_MIDDLE_FRAG ||
1462 1.1 rjs (next->rec.data.rcv_flags&SCTP_DATA_FRAG_MASK) ==
1463 1.1 rjs SCTP_DATA_LAST_FRAG) {
1464 1.1 rjs /* Insert chk CAN be MIDDLE or FIRST NOT LAST */
1465 1.1 rjs if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1466 1.1 rjs SCTP_DATA_LAST_FRAG) {
1467 1.1 rjs #ifdef SCTP_DEBUG
1468 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1469 1.1 rjs printf("Next chk - Next is a MIDDLE/LAST\n");
1470 1.1 rjs printf("Gak, Evil plot, new prev chunk is a LAST\n");
1471 1.1 rjs }
1472 1.1 rjs #endif
1473 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1474 1.1 rjs if (oper) {
1475 1.1 rjs struct sctp_paramhdr *ph;
1476 1.1 rjs u_int32_t *ippp;
1477 1.1 rjs
1478 1.1 rjs oper->m_len =
1479 1.1 rjs sizeof(struct sctp_paramhdr) +
1480 1.1 rjs sizeof(*ippp);
1481 1.1 rjs ph = mtod(oper,
1482 1.1 rjs struct sctp_paramhdr *);
1483 1.1 rjs ph->param_type =
1484 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1485 1.1 rjs ph->param_length =
1486 1.1 rjs htons(oper->m_len);
1487 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1488 1.1 rjs *ippp = htonl(0x1000000a);
1489 1.1 rjs }
1490 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1491 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1492 1.1 rjs
1493 1.1 rjs *abort_flag = 1;
1494 1.1 rjs return;
1495 1.1 rjs }
1496 1.1 rjs if (chk->rec.data.stream_number !=
1497 1.1 rjs next->rec.data.stream_number) {
1498 1.1 rjs /*
1499 1.1 rjs * Huh, need the correct STR here, they
1500 1.1 rjs * must be the same.
1501 1.1 rjs */
1502 1.1 rjs #ifdef SCTP_DEBUG
1503 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1504 1.1 rjs printf("Next chk - Gak, Evil plot, ssn:%d not the same as at:%d\n",
1505 1.1 rjs chk->rec.data.stream_number,
1506 1.1 rjs next->rec.data.stream_number);
1507 1.1 rjs }
1508 1.1 rjs #endif
1509 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1510 1.1 rjs if (oper) {
1511 1.1 rjs struct sctp_paramhdr *ph;
1512 1.1 rjs u_int32_t *ippp;
1513 1.1 rjs
1514 1.1 rjs oper->m_len =
1515 1.1 rjs sizeof(struct sctp_paramhdr) +
1516 1.1 rjs sizeof(*ippp);
1517 1.1 rjs ph = mtod(oper,
1518 1.1 rjs struct sctp_paramhdr *);
1519 1.1 rjs ph->param_type =
1520 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1521 1.1 rjs ph->param_length =
1522 1.1 rjs htons(oper->m_len);
1523 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1524 1.1 rjs *ippp = htonl(0x1000000b);
1525 1.1 rjs }
1526 1.1 rjs
1527 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1528 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1529 1.1 rjs
1530 1.1 rjs *abort_flag = 1;
1531 1.1 rjs return;
1532 1.1 rjs }
1533 1.1 rjs if ((next->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 &&
1534 1.1 rjs chk->rec.data.stream_seq !=
1535 1.1 rjs next->rec.data.stream_seq) {
1536 1.1 rjs /*
1537 1.1 rjs * Huh, need the correct STR here, they
1538 1.1 rjs * must be the same.
1539 1.1 rjs */
1540 1.1 rjs #ifdef SCTP_DEBUG
1541 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1542 1.1 rjs printf("Next chk - Gak, Evil plot, sseq:%d not the same as at:%d\n",
1543 1.1 rjs chk->rec.data.stream_seq,
1544 1.1 rjs next->rec.data.stream_seq);
1545 1.1 rjs }
1546 1.1 rjs #endif
1547 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1548 1.1 rjs if (oper) {
1549 1.1 rjs struct sctp_paramhdr *ph;
1550 1.1 rjs u_int32_t *ippp;
1551 1.1 rjs
1552 1.1 rjs oper->m_len =
1553 1.1 rjs sizeof(struct sctp_paramhdr) +
1554 1.1 rjs sizeof(*ippp);
1555 1.1 rjs ph = mtod(oper,
1556 1.1 rjs struct sctp_paramhdr *);
1557 1.1 rjs ph->param_type =
1558 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1559 1.1 rjs ph->param_length =
1560 1.1 rjs htons(oper->m_len);
1561 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1562 1.1 rjs *ippp = htonl(0x1000000c);
1563 1.1 rjs }
1564 1.1 rjs
1565 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
1566 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
1567 1.1 rjs
1568 1.1 rjs *abort_flag = 1;
1569 1.1 rjs return;
1570 1.1 rjs
1571 1.1 rjs }
1572 1.1 rjs }
1573 1.1 rjs }
1574 1.1 rjs }
1575 1.1 rjs /*
1576 1.1 rjs * now that we have all in there place we must check a number of
1577 1.1 rjs * things to see if we can send data to the ULP.
1578 1.1 rjs */
1579 1.1 rjs /* we need to do some delivery, if we can */
1580 1.1 rjs chk = TAILQ_FIRST(&asoc->reasmqueue);
1581 1.1 rjs if (chk == NULL) {
1582 1.1 rjs /* Huh? */
1583 1.1 rjs asoc->size_on_reasm_queue = 0;
1584 1.1 rjs asoc->cnt_on_reasm_queue = 0;
1585 1.1 rjs return;
1586 1.1 rjs }
1587 1.1 rjs if (asoc->fragmented_delivery_inprogress == 0) {
1588 1.1 rjs nxt_todel =
1589 1.1 rjs asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1;
1590 1.1 rjs if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) &&
1591 1.1 rjs (nxt_todel == chk->rec.data.stream_seq ||
1592 1.1 rjs (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) {
1593 1.1 rjs /*
1594 1.1 rjs * Yep the first one is here and its
1595 1.1 rjs * ok to deliver but should we?
1596 1.1 rjs */
1597 1.1 rjs if (TAILQ_EMPTY(&asoc->delivery_queue) &&
1598 1.1 rjs (sctp_is_all_msg_on_reasm(asoc, &tsize) ||
1599 1.1 rjs (asoc->size_on_reasm_queue >=
1600 1.1 rjs (stcb->sctp_socket->so_rcv.sb_hiwat >> 2) &&
1601 1.1 rjs tsize))) {
1602 1.1 rjs /*
1603 1.1 rjs * Yes, we setup to
1604 1.1 rjs * start reception, by backing down the TSN
1605 1.1 rjs * just in case we can't deliver. If we
1606 1.1 rjs */
1607 1.1 rjs asoc->fragmented_delivery_inprogress = 1;
1608 1.1 rjs asoc->tsn_last_delivered =
1609 1.1 rjs chk->rec.data.TSN_seq - 1;
1610 1.1 rjs asoc->str_of_pdapi =
1611 1.1 rjs chk->rec.data.stream_number;
1612 1.1 rjs asoc->ssn_of_pdapi = chk->rec.data.stream_seq;
1613 1.1 rjs asoc->fragment_flags = chk->rec.data.rcv_flags;
1614 1.1 rjs sctp_service_reassembly(stcb, asoc, 0);
1615 1.1 rjs }
1616 1.1 rjs }
1617 1.1 rjs } else {
1618 1.1 rjs sctp_service_reassembly(stcb, asoc, 0);
1619 1.1 rjs }
1620 1.1 rjs }
1621 1.1 rjs
1622 1.1 rjs /*
1623 1.1 rjs * This is an unfortunate routine. It checks to make sure a evil guy is not
1624 1.1 rjs * stuffing us full of bad packet fragments. A broken peer could also do this
1625 1.1 rjs * but this is doubtful. It is to bad I must worry about evil crackers sigh
1626 1.1 rjs * :< more cycles.
1627 1.1 rjs */
1628 1.1 rjs static int
1629 1.1 rjs sctp_does_chk_belong_to_reasm(struct sctp_association *asoc,
1630 1.1 rjs struct sctp_tmit_chunk *chk)
1631 1.1 rjs {
1632 1.1 rjs struct sctp_tmit_chunk *at;
1633 1.1 rjs u_int32_t tsn_est;
1634 1.1 rjs
1635 1.1 rjs TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) {
1636 1.1 rjs if (compare_with_wrap(chk->rec.data.TSN_seq,
1637 1.1 rjs at->rec.data.TSN_seq, MAX_TSN)) {
1638 1.1 rjs /* is it one bigger? */
1639 1.1 rjs tsn_est = at->rec.data.TSN_seq + 1;
1640 1.1 rjs if (tsn_est == chk->rec.data.TSN_seq) {
1641 1.1 rjs /* yep. It better be a last then*/
1642 1.1 rjs if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
1643 1.1 rjs SCTP_DATA_LAST_FRAG) {
1644 1.1 rjs /*
1645 1.1 rjs * Ok this guy belongs next to a guy
1646 1.1 rjs * that is NOT last, it should be a
1647 1.1 rjs * middle/last, not a complete chunk.
1648 1.1 rjs */
1649 1.1 rjs return (1);
1650 1.1 rjs } else {
1651 1.1 rjs /*
1652 1.1 rjs * This guy is ok since its a LAST and
1653 1.1 rjs * the new chunk is a fully self-
1654 1.1 rjs * contained one.
1655 1.1 rjs */
1656 1.1 rjs return (0);
1657 1.1 rjs }
1658 1.1 rjs }
1659 1.1 rjs } else if (chk->rec.data.TSN_seq == at->rec.data.TSN_seq) {
1660 1.1 rjs /* Software error since I have a dup? */
1661 1.1 rjs return (1);
1662 1.1 rjs } else {
1663 1.1 rjs /*
1664 1.1 rjs * Ok, 'at' is larger than new chunk but does it
1665 1.1 rjs * need to be right before it.
1666 1.1 rjs */
1667 1.1 rjs tsn_est = chk->rec.data.TSN_seq + 1;
1668 1.1 rjs if (tsn_est == at->rec.data.TSN_seq) {
1669 1.1 rjs /* Yep, It better be a first */
1670 1.1 rjs if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
1671 1.1 rjs SCTP_DATA_FIRST_FRAG) {
1672 1.1 rjs return (1);
1673 1.1 rjs } else {
1674 1.1 rjs return (0);
1675 1.1 rjs }
1676 1.1 rjs }
1677 1.1 rjs }
1678 1.1 rjs }
1679 1.1 rjs return (0);
1680 1.1 rjs }
1681 1.1 rjs
1682 1.1 rjs extern unsigned int sctp_max_chunks_on_queue;
1683 1.1 rjs static int
1684 1.1 rjs sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
1685 1.1 rjs struct mbuf **m, int offset, struct sctp_data_chunk *ch, int chk_length,
1686 1.1 rjs struct sctp_nets *net, u_int32_t *high_tsn, int *abort_flag,
1687 1.1 rjs int *break_flag, int last_chunk)
1688 1.1 rjs {
1689 1.1 rjs /* Process a data chunk */
1690 1.1 rjs /* struct sctp_tmit_chunk *chk;*/
1691 1.1 rjs struct sctp_tmit_chunk *chk;
1692 1.1 rjs u_int32_t tsn, gap;
1693 1.1 rjs struct mbuf *dmbuf;
1694 1.1 rjs int the_len;
1695 1.1 rjs u_int16_t strmno, strmseq;
1696 1.1 rjs struct mbuf *oper;
1697 1.1 rjs
1698 1.1 rjs chk = NULL;
1699 1.1 rjs tsn = ntohl(ch->dp.tsn);
1700 1.1 rjs #ifdef SCTP_MAP_LOGGING
1701 1.1 rjs sctp_log_map(0, tsn, asoc->cumulative_tsn, SCTP_MAP_PREPARE_SLIDE);
1702 1.1 rjs #endif
1703 1.1 rjs if (compare_with_wrap(asoc->cumulative_tsn, tsn, MAX_TSN) ||
1704 1.1 rjs asoc->cumulative_tsn == tsn) {
1705 1.1 rjs /* It is a duplicate */
1706 1.1 rjs sctp_pegs[SCTP_DUPTSN_RECVD]++;
1707 1.1 rjs if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) {
1708 1.1 rjs /* Record a dup for the next outbound sack */
1709 1.1 rjs asoc->dup_tsns[asoc->numduptsns] = tsn;
1710 1.1 rjs asoc->numduptsns++;
1711 1.1 rjs }
1712 1.1 rjs return (0);
1713 1.1 rjs }
1714 1.1 rjs /* Calculate the number of TSN's between the base and this TSN */
1715 1.1 rjs if (tsn >= asoc->mapping_array_base_tsn) {
1716 1.1 rjs gap = tsn - asoc->mapping_array_base_tsn;
1717 1.1 rjs } else {
1718 1.1 rjs gap = (MAX_TSN - asoc->mapping_array_base_tsn) + tsn + 1;
1719 1.1 rjs }
1720 1.1 rjs if (gap >= (SCTP_MAPPING_ARRAY << 3)) {
1721 1.1 rjs /* Can't hold the bit in the mapping at max array, toss it */
1722 1.1 rjs return (0);
1723 1.1 rjs }
1724 1.1 rjs if (gap >= (uint32_t)(asoc->mapping_array_size << 3)) {
1725 1.1 rjs if (sctp_expand_mapping_array(asoc)) {
1726 1.1 rjs /* Can't expand, drop it */
1727 1.1 rjs return (0);
1728 1.1 rjs }
1729 1.1 rjs }
1730 1.1 rjs if (compare_with_wrap(tsn, *high_tsn, MAX_TSN)) {
1731 1.1 rjs *high_tsn = tsn;
1732 1.1 rjs }
1733 1.1 rjs /* See if we have received this one already */
1734 1.1 rjs if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) {
1735 1.1 rjs sctp_pegs[SCTP_DUPTSN_RECVD]++;
1736 1.1 rjs if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) {
1737 1.1 rjs /* Record a dup for the next outbound sack */
1738 1.1 rjs asoc->dup_tsns[asoc->numduptsns] = tsn;
1739 1.1 rjs asoc->numduptsns++;
1740 1.1 rjs }
1741 1.1 rjs if (!callout_pending(&asoc->dack_timer.timer)) {
1742 1.1 rjs /*
1743 1.1 rjs * By starting the timer we assure that we
1744 1.1 rjs * WILL sack at the end of the packet
1745 1.1 rjs * when sctp_sack_check gets called.
1746 1.1 rjs */
1747 1.1 rjs sctp_timer_start(SCTP_TIMER_TYPE_RECV, stcb->sctp_ep,
1748 1.1 rjs stcb, NULL);
1749 1.1 rjs }
1750 1.1 rjs return (0);
1751 1.1 rjs }
1752 1.1 rjs /*
1753 1.1 rjs * Check to see about the GONE flag, duplicates would cause
1754 1.1 rjs * a sack to be sent up above
1755 1.1 rjs */
1756 1.1 rjs if (stcb && (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1757 1.1 rjs /*
1758 1.1 rjs * wait a minute, this guy is gone, there is no
1759 1.1 rjs * longer a receiver. Send peer an ABORT!
1760 1.1 rjs */
1761 1.1 rjs struct mbuf *op_err;
1762 1.1 rjs op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC);
1763 1.1 rjs sctp_abort_an_association(stcb->sctp_ep, stcb, 0, op_err);
1764 1.1 rjs *abort_flag = 1;
1765 1.1 rjs return (0);
1766 1.1 rjs }
1767 1.1 rjs /*
1768 1.1 rjs * Now before going further we see if there is room. If NOT then
1769 1.1 rjs * we MAY let one through only IF this TSN is the one we are
1770 1.1 rjs * waiting for on a partial delivery API.
1771 1.1 rjs */
1772 1.1 rjs
1773 1.1 rjs /* now do the tests */
1774 1.1 rjs if (((asoc->cnt_on_all_streams +
1775 1.1 rjs asoc->cnt_on_delivery_queue +
1776 1.1 rjs asoc->cnt_on_reasm_queue +
1777 1.1 rjs asoc->cnt_msg_on_sb) > sctp_max_chunks_on_queue) ||
1778 1.1 rjs (((int)asoc->my_rwnd) <= 0)) {
1779 1.1 rjs /*
1780 1.1 rjs * When we have NO room in the rwnd we check
1781 1.1 rjs * to make sure the reader is doing its job...
1782 1.1 rjs */
1783 1.1 rjs if (stcb->sctp_socket->so_rcv.sb_cc) {
1784 1.1 rjs /* some to read, wake-up */
1785 1.1 rjs sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
1786 1.1 rjs }
1787 1.1 rjs /* now is it in the mapping array of what we have accepted? */
1788 1.1 rjs if (compare_with_wrap(tsn,
1789 1.1 rjs asoc->highest_tsn_inside_map, MAX_TSN)) {
1790 1.1 rjs
1791 1.1 rjs /* Nope not in the valid range dump it */
1792 1.1 rjs #ifdef SCTP_DEBUG
1793 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1794 1.1 rjs printf("My rwnd overrun1:tsn:%lx rwnd %lu sbspace:%ld delq:%d!\n",
1795 1.1 rjs (u_long)tsn, (u_long)asoc->my_rwnd,
1796 1.1 rjs sctp_sbspace(&stcb->sctp_socket->so_rcv),
1797 1.1 rjs stcb->asoc.cnt_on_delivery_queue);
1798 1.1 rjs }
1799 1.1 rjs #endif
1800 1.1 rjs sctp_set_rwnd(stcb, asoc);
1801 1.1 rjs if ((asoc->cnt_on_all_streams +
1802 1.1 rjs asoc->cnt_on_delivery_queue +
1803 1.1 rjs asoc->cnt_on_reasm_queue +
1804 1.1 rjs asoc->cnt_msg_on_sb) > sctp_max_chunks_on_queue) {
1805 1.1 rjs sctp_pegs[SCTP_MSGC_DROP]++;
1806 1.1 rjs } else {
1807 1.1 rjs sctp_pegs[SCTP_RWND_DROPS]++;
1808 1.1 rjs }
1809 1.1 rjs *break_flag = 1;
1810 1.1 rjs return (0);
1811 1.1 rjs }
1812 1.1 rjs }
1813 1.1 rjs strmno = ntohs(ch->dp.stream_id);
1814 1.1 rjs if (strmno >= asoc->streamincnt) {
1815 1.1 rjs struct sctp_paramhdr *phdr;
1816 1.1 rjs struct mbuf *mb;
1817 1.1 rjs
1818 1.1 rjs MGETHDR(mb, M_DONTWAIT, MT_DATA);
1819 1.1 rjs if (mb != NULL) {
1820 1.1 rjs /* add some space up front so prepend will work well */
1821 1.1 rjs mb->m_data += sizeof(struct sctp_chunkhdr);
1822 1.1 rjs phdr = mtod(mb, struct sctp_paramhdr *);
1823 1.1 rjs /*
1824 1.1 rjs * Error causes are just param's and this one has
1825 1.1 rjs * two back to back phdr, one with the error type
1826 1.1 rjs * and size, the other with the streamid and a rsvd
1827 1.1 rjs */
1828 1.1 rjs mb->m_pkthdr.len = mb->m_len =
1829 1.1 rjs (sizeof(struct sctp_paramhdr) * 2);
1830 1.1 rjs phdr->param_type = htons(SCTP_CAUSE_INV_STRM);
1831 1.1 rjs phdr->param_length =
1832 1.1 rjs htons(sizeof(struct sctp_paramhdr) * 2);
1833 1.1 rjs phdr++;
1834 1.1 rjs /* We insert the stream in the type field */
1835 1.1 rjs phdr->param_type = ch->dp.stream_id;
1836 1.1 rjs /* And set the length to 0 for the rsvd field */
1837 1.1 rjs phdr->param_length = 0;
1838 1.1 rjs sctp_queue_op_err(stcb, mb);
1839 1.1 rjs }
1840 1.1 rjs sctp_pegs[SCTP_BAD_STRMNO]++;
1841 1.1 rjs return (0);
1842 1.1 rjs }
1843 1.1 rjs /*
1844 1.1 rjs * Before we continue lets validate that we are not
1845 1.1 rjs * being fooled by an evil attacker. We can only
1846 1.1 rjs * have 4k chunks based on our TSN spread allowed
1847 1.1 rjs * by the mapping array 512 * 8 bits, so there is
1848 1.1 rjs * no way our stream sequence numbers could have wrapped.
1849 1.1 rjs * We of course only validate the FIRST fragment so the
1850 1.1 rjs * bit must be set.
1851 1.1 rjs */
1852 1.1 rjs strmseq = ntohs(ch->dp.stream_sequence);
1853 1.1 rjs if ((ch->ch.chunk_flags & SCTP_DATA_FIRST_FRAG) &&
1854 1.1 rjs (ch->ch.chunk_flags & SCTP_DATA_UNORDERED) == 0 &&
1855 1.1 rjs (compare_with_wrap(asoc->strmin[strmno].last_sequence_delivered,
1856 1.1 rjs strmseq, MAX_SEQ) ||
1857 1.1 rjs asoc->strmin[strmno].last_sequence_delivered == strmseq)) {
1858 1.1 rjs /* The incoming sseq is behind where we last delivered? */
1859 1.1 rjs #ifdef SCTP_DEBUG
1860 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
1861 1.1 rjs printf("EVIL/Broken-Dup S-SEQ:%d delivered:%d from peer, Abort!\n",
1862 1.1 rjs strmseq,
1863 1.1 rjs asoc->strmin[strmno].last_sequence_delivered);
1864 1.1 rjs }
1865 1.1 rjs #endif
1866 1.1 rjs /*
1867 1.1 rjs * throw it in the stream so it gets cleaned up in
1868 1.1 rjs * association destruction
1869 1.1 rjs */
1870 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
1871 1.1 rjs if (oper) {
1872 1.1 rjs struct sctp_paramhdr *ph;
1873 1.1 rjs u_int32_t *ippp;
1874 1.1 rjs
1875 1.1 rjs oper->m_len = sizeof(struct sctp_paramhdr) +
1876 1.1 rjs sizeof(*ippp);
1877 1.1 rjs ph = mtod(oper, struct sctp_paramhdr *);
1878 1.1 rjs ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1879 1.1 rjs ph->param_length = htons(oper->m_len);
1880 1.1 rjs ippp = (u_int32_t *)(ph + 1);
1881 1.1 rjs *ippp = htonl(0x20000001);
1882 1.1 rjs }
1883 1.1 rjs sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY,
1884 1.1 rjs oper);
1885 1.1 rjs sctp_pegs[SCTP_BAD_SSN_WRAP]++;
1886 1.1 rjs *abort_flag = 1;
1887 1.1 rjs return (0);
1888 1.1 rjs }
1889 1.1 rjs
1890 1.1 rjs the_len = (chk_length-sizeof(struct sctp_data_chunk));
1891 1.1 rjs if (last_chunk == 0) {
1892 1.1 rjs dmbuf = sctp_m_copym(*m,
1893 1.1 rjs (offset + sizeof(struct sctp_data_chunk)),
1894 1.1 rjs the_len, M_DONTWAIT);
1895 1.1 rjs } else {
1896 1.1 rjs /* We can steal the last chunk */
1897 1.1 rjs dmbuf = *m;
1898 1.1 rjs /* lop off the top part */
1899 1.1 rjs m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk)));
1900 1.1 rjs if (dmbuf->m_pkthdr.len > the_len) {
1901 1.1 rjs /* Trim the end round bytes off too */
1902 1.1 rjs m_adj(dmbuf, -(dmbuf->m_pkthdr.len-the_len));
1903 1.1 rjs }
1904 1.1 rjs sctp_pegs[SCTP_NO_COPY_IN]++;
1905 1.1 rjs }
1906 1.1 rjs if (dmbuf == NULL) {
1907 1.1 rjs sctp_pegs[SCTP_DROP_NOMEMORY]++;
1908 1.1 rjs return (0);
1909 1.1 rjs }
1910 1.1 rjs if ((ch->ch.chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG &&
1911 1.1 rjs asoc->fragmented_delivery_inprogress == 0 &&
1912 1.1 rjs TAILQ_EMPTY(&asoc->delivery_queue) &&
1913 1.1 rjs ((ch->ch.chunk_flags & SCTP_DATA_UNORDERED) ||
1914 1.1 rjs ((asoc->strmin[strmno].last_sequence_delivered + 1) == strmseq &&
1915 1.1 rjs TAILQ_EMPTY(&asoc->strmin[strmno].inqueue))) &&
1916 1.1 rjs ((long)(stcb->sctp_socket->so_rcv.sb_hiwat -
1917 1.1 rjs stcb->sctp_socket->so_rcv.sb_cc) >= (long)the_len)) {
1918 1.1 rjs /* Candidate for express delivery */
1919 1.1 rjs /*
1920 1.1 rjs * Its not fragmented,
1921 1.1 rjs * No PD-API is up,
1922 1.1 rjs * Nothing in the delivery queue,
1923 1.1 rjs * Its un-ordered OR ordered and the next to deliver AND
1924 1.1 rjs * nothing else is stuck on the stream queue,
1925 1.1 rjs * And there is room for it in the socket buffer.
1926 1.1 rjs * Lets just stuff it up the buffer....
1927 1.1 rjs */
1928 1.1 rjs
1929 1.1 rjs struct mbuf *control, *mmm;
1930 1.1 rjs struct sockaddr_in6 sin6;
1931 1.1 rjs struct sockaddr_in6 lsa6;
1932 1.1 rjs const struct sockaddr *to;
1933 1.1 rjs
1934 1.1 rjs /* It would be nice to avoid this copy if we could :< */
1935 1.1 rjs control = sctp_build_ctl_nchunk(stcb, tsn,
1936 1.1 rjs ch->dp.protocol_id, 0, strmno, strmseq,
1937 1.1 rjs ch->ch.chunk_flags);
1938 1.1 rjs /* XXX need to append PKTHDR to the socket buffer first */
1939 1.1 rjs
1940 1.1 rjs if ((dmbuf->m_flags & M_PKTHDR) == 0) {
1941 1.1 rjs struct mbuf *tmp;
1942 1.1 rjs MGETHDR(tmp, M_DONTWAIT, MT_DATA);
1943 1.1 rjs if (tmp == NULL) {
1944 1.1 rjs
1945 1.1 rjs /* no room! */
1946 1.1 rjs if (control) {
1947 1.1 rjs sctp_m_freem(control);
1948 1.1 rjs stcb->asoc.my_rwnd_control_len -=
1949 1.1 rjs CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
1950 1.1 rjs }
1951 1.1 rjs
1952 1.1 rjs goto failed_express_del;
1953 1.1 rjs }
1954 1.1 rjs tmp->m_pkthdr.len = the_len;
1955 1.1 rjs tmp->m_len = 0;
1956 1.1 rjs tmp->m_next = dmbuf;
1957 1.1 rjs dmbuf = tmp;
1958 1.1 rjs }
1959 1.1 rjs to = rtcache_getdst(&net->ro);
1960 1.1 rjs if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) &&
1961 1.1 rjs to->sa_family == AF_INET) {
1962 1.1 rjs const struct sockaddr_in *sin;
1963 1.1 rjs
1964 1.1 rjs sin = satocsin(to);
1965 1.1 rjs memset(&sin6, 0, sizeof(sin6));
1966 1.1 rjs sin6.sin6_family = AF_INET6;
1967 1.1 rjs sin6.sin6_len = sizeof(struct sockaddr_in6);
1968 1.1 rjs sin6.sin6_addr.s6_addr16[2] = 0xffff;
1969 1.1 rjs bcopy(&sin->sin_addr,
1970 1.1 rjs &sin6.sin6_addr.s6_addr16[3],
1971 1.1 rjs sizeof(sin6.sin6_addr.s6_addr16[3]));
1972 1.1 rjs sin6.sin6_port = sin->sin_port;
1973 1.1 rjs to = (struct sockaddr *)&sin6;
1974 1.1 rjs }
1975 1.1 rjs
1976 1.1 rjs /* check and strip embedded scope junk */
1977 1.1 rjs to = (const struct sockaddr *)sctp_recover_scope((const struct sockaddr_in6 *)to,
1978 1.1 rjs &lsa6);
1979 1.1 rjs if (((const struct sockaddr_in *)to)->sin_port == 0) {
1980 1.1 rjs printf("Huh c, port is %d not net:%p %d?\n",
1981 1.1 rjs ((const struct sockaddr_in *)to)->sin_port,
1982 1.1 rjs net,
1983 1.1 rjs (int)(ntohs(stcb->rport)));
1984 1.1 rjs /*((struct sockaddr_in *)to)->sin_port = stcb->rport;*/
1985 1.1 rjs /* XXX */
1986 1.1 rjs }
1987 1.1 rjs
1988 1.1 rjs mmm = dmbuf;
1989 1.1 rjs /* Mark the EOR */
1990 1.1 rjs while (mmm->m_next != NULL) {
1991 1.1 rjs mmm = mmm->m_next;
1992 1.1 rjs }
1993 1.1 rjs mmm->m_flags |= M_EOR;
1994 1.1 rjs if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) {
1995 1.1 rjs /* we have a new high score */
1996 1.1 rjs asoc->highest_tsn_inside_map = tsn;
1997 1.1 rjs #ifdef SCTP_MAP_LOGGING
1998 1.1 rjs sctp_log_map(0, 1, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
1999 1.1 rjs #endif
2000 1.1 rjs }
2001 1.1 rjs SCTP_TCB_UNLOCK(stcb);
2002 1.1 rjs SCTP_INP_WLOCK(stcb->sctp_ep);
2003 1.1 rjs SCTP_TCB_LOCK(stcb);
2004 1.1 rjs if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, dmbuf,
2005 1.1 rjs control, stcb->asoc.my_vtag, stcb->sctp_ep)) {
2006 1.1 rjs if (control) {
2007 1.1 rjs sctp_m_freem(control);
2008 1.1 rjs stcb->asoc.my_rwnd_control_len -=
2009 1.1 rjs CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
2010 1.1 rjs }
2011 1.1 rjs sctp_m_freem(dmbuf);
2012 1.1 rjs goto failed_express_del;
2013 1.1 rjs }
2014 1.1 rjs if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) {
2015 1.1 rjs if (sctp_add_to_socket_q(stcb->sctp_ep, stcb)) {
2016 1.1 rjs stcb->asoc.my_rwnd_control_len += sizeof(struct mbuf);
2017 1.1 rjs }
2018 1.1 rjs } else {
2019 1.1 rjs stcb->asoc.my_rwnd_control_len += sizeof(struct mbuf);
2020 1.1 rjs }
2021 1.1 rjs SCTP_INP_WUNLOCK(stcb->sctp_ep);
2022 1.1 rjs sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
2023 1.1 rjs if ((ch->ch.chunk_flags & SCTP_DATA_UNORDERED) == 0) {
2024 1.1 rjs
2025 1.1 rjs /* for ordered, bump what we delivered */
2026 1.1 rjs asoc->strmin[strmno].last_sequence_delivered++;
2027 1.1 rjs }
2028 1.1 rjs sctp_pegs[SCTP_EXPRESS_ROUTE]++;
2029 1.1 rjs #ifdef SCTP_STR_LOGGING
2030 1.1 rjs sctp_log_strm_del_alt(tsn, strmseq,
2031 1.1 rjs SCTP_STR_LOG_FROM_EXPRS_DEL);
2032 1.1 rjs #endif
2033 1.1 rjs #ifdef SCTP_DEBUG
2034 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
2035 1.1 rjs printf("Express Delivery succeeds\n");
2036 1.1 rjs }
2037 1.1 rjs #endif
2038 1.1 rjs goto finish_express_del;
2039 1.1 rjs }
2040 1.1 rjs
2041 1.1 rjs failed_express_del:
2042 1.1 rjs /* If we reach here this is a new chunk */
2043 1.1 rjs chk = (struct sctp_tmit_chunk *)SCTP_ZONE_GET(sctppcbinfo.ipi_zone_chunk);
2044 1.1 rjs if (chk == NULL) {
2045 1.1 rjs /* No memory so we drop the chunk */
2046 1.1 rjs sctp_pegs[SCTP_DROP_NOMEMORY]++;
2047 1.1 rjs if (last_chunk == 0) {
2048 1.1 rjs /* we copied it, free the copy */
2049 1.1 rjs sctp_m_freem(dmbuf);
2050 1.1 rjs }
2051 1.1 rjs return (0);
2052 1.1 rjs }
2053 1.1 rjs sctppcbinfo.ipi_count_chunk++;
2054 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
2055 1.1 rjs chk->rec.data.TSN_seq = tsn;
2056 1.1 rjs chk->rec.data.stream_seq = strmseq;
2057 1.1 rjs chk->rec.data.stream_number = strmno;
2058 1.1 rjs chk->rec.data.payloadtype = ch->dp.protocol_id;
2059 1.1 rjs chk->rec.data.context = 0;
2060 1.1 rjs chk->rec.data.doing_fast_retransmit = 0;
2061 1.1 rjs chk->rec.data.rcv_flags = ch->ch.chunk_flags;
2062 1.1 rjs chk->asoc = asoc;
2063 1.1 rjs chk->send_size = the_len;
2064 1.1 rjs chk->whoTo = net;
2065 1.1 rjs net->ref_count++;
2066 1.1 rjs chk->data = dmbuf;
2067 1.1 rjs
2068 1.1 rjs
2069 1.1 rjs /* Mark it as received */
2070 1.1 rjs /* Now queue it where it belongs */
2071 1.1 rjs if ((chk->rec.data.rcv_flags & SCTP_DATA_NOT_FRAG) ==
2072 1.1 rjs SCTP_DATA_NOT_FRAG) {
2073 1.1 rjs /* First a sanity check */
2074 1.1 rjs if (asoc->fragmented_delivery_inprogress) {
2075 1.1 rjs /*
2076 1.1 rjs * Ok, we have a fragmented delivery in progress
2077 1.1 rjs * if this chunk is next to deliver OR belongs in
2078 1.1 rjs * our view to the reassembly, the peer is evil
2079 1.1 rjs * or broken.
2080 1.1 rjs */
2081 1.1 rjs u_int32_t estimate_tsn;
2082 1.1 rjs estimate_tsn = asoc->tsn_last_delivered + 1;
2083 1.1 rjs if (TAILQ_EMPTY(&asoc->reasmqueue) &&
2084 1.1 rjs (estimate_tsn == chk->rec.data.TSN_seq)) {
2085 1.1 rjs /* Evil/Broke peer */
2086 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
2087 1.1 rjs if (oper) {
2088 1.1 rjs struct sctp_paramhdr *ph;
2089 1.1 rjs u_int32_t *ippp;
2090 1.1 rjs
2091 1.1 rjs oper->m_len =
2092 1.1 rjs sizeof(struct sctp_paramhdr) +
2093 1.1 rjs sizeof(*ippp);
2094 1.1 rjs ph = mtod(oper, struct sctp_paramhdr *);
2095 1.1 rjs ph->param_type =
2096 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
2097 1.1 rjs ph->param_length = htons(oper->m_len);
2098 1.1 rjs ippp = (u_int32_t *)(ph + 1);
2099 1.1 rjs *ippp = htonl(0x20000002);
2100 1.1 rjs }
2101 1.1 rjs sctp_abort_an_association(stcb->sctp_ep, stcb,
2102 1.1 rjs SCTP_PEER_FAULTY, oper);
2103 1.1 rjs
2104 1.1 rjs *abort_flag = 1;
2105 1.1 rjs sctp_pegs[SCTP_DROP_FRAG]++;
2106 1.1 rjs return (0);
2107 1.1 rjs } else {
2108 1.1 rjs if (sctp_does_chk_belong_to_reasm(asoc, chk)) {
2109 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
2110 1.1 rjs if (oper) {
2111 1.1 rjs struct sctp_paramhdr *ph;
2112 1.1 rjs u_int32_t *ippp;
2113 1.1 rjs
2114 1.1 rjs oper->m_len =
2115 1.1 rjs sizeof(struct sctp_paramhdr) +
2116 1.1 rjs sizeof(*ippp);
2117 1.1 rjs ph = mtod(oper,
2118 1.1 rjs struct sctp_paramhdr *);
2119 1.1 rjs ph->param_type =
2120 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
2121 1.1 rjs ph->param_length =
2122 1.1 rjs htons(oper->m_len);
2123 1.1 rjs ippp = (u_int32_t *)(ph + 1);
2124 1.1 rjs *ippp = htonl(0x20000003);
2125 1.1 rjs }
2126 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
2127 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
2128 1.1 rjs
2129 1.1 rjs *abort_flag = 1;
2130 1.1 rjs sctp_pegs[SCTP_DROP_FRAG]++;
2131 1.1 rjs return (0);
2132 1.1 rjs }
2133 1.1 rjs }
2134 1.1 rjs } else {
2135 1.1 rjs if (!TAILQ_EMPTY(&asoc->reasmqueue)) {
2136 1.1 rjs /*
2137 1.1 rjs * Reassembly queue is NOT empty
2138 1.1 rjs * validate that this chk does not need to
2139 1.1 rjs * be in reasembly queue. If it does then
2140 1.1 rjs * our peer is broken or evil.
2141 1.1 rjs */
2142 1.1 rjs if (sctp_does_chk_belong_to_reasm(asoc, chk)) {
2143 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
2144 1.1 rjs if (oper) {
2145 1.1 rjs struct sctp_paramhdr *ph;
2146 1.1 rjs u_int32_t *ippp;
2147 1.1 rjs
2148 1.1 rjs oper->m_len =
2149 1.1 rjs sizeof(struct sctp_paramhdr) +
2150 1.1 rjs sizeof(*ippp);
2151 1.1 rjs ph = mtod(oper,
2152 1.1 rjs struct sctp_paramhdr *);
2153 1.1 rjs ph->param_type =
2154 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
2155 1.1 rjs ph->param_length =
2156 1.1 rjs htons(oper->m_len);
2157 1.1 rjs ippp = (u_int32_t *)(ph + 1);
2158 1.1 rjs *ippp = htonl(0x20000004);
2159 1.1 rjs }
2160 1.1 rjs sctp_abort_an_association(stcb->sctp_ep,
2161 1.1 rjs stcb, SCTP_PEER_FAULTY, oper);
2162 1.1 rjs
2163 1.1 rjs *abort_flag = 1;
2164 1.1 rjs sctp_pegs[SCTP_DROP_FRAG]++;
2165 1.1 rjs return (0);
2166 1.1 rjs }
2167 1.1 rjs }
2168 1.1 rjs }
2169 1.1 rjs if (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) {
2170 1.1 rjs /* queue directly into socket buffer */
2171 1.1 rjs sctp_deliver_data(stcb, asoc, chk, 0);
2172 1.1 rjs sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
2173 1.1 rjs } else {
2174 1.1 rjs /* Special check for when streams are resetting.
2175 1.1 rjs * We could be more smart about this and check the
2176 1.1 rjs * actual stream to see if it is not being reset.. that
2177 1.1 rjs * way we would not create a HOLB when amongst streams
2178 1.1 rjs * being reset and those not being reset.
2179 1.1 rjs *
2180 1.1 rjs * We take complete messages that have a stream reset
2181 1.1 rjs * intervening (aka the TSN is after where our cum-ack needs
2182 1.1 rjs * to be) off and put them on a pending_reply_queue. The
2183 1.1 rjs * reassembly ones we do not have to worry about since
2184 1.1 rjs * they are all sorted and proceessed by TSN order. It
2185 1.1 rjs * is only the singletons I must worry about.
2186 1.1 rjs */
2187 1.1 rjs if ((asoc->pending_reply) &&
2188 1.1 rjs ((compare_with_wrap(tsn, ntohl(asoc->pending_reply->reset_at_tsn), MAX_TSN)) ||
2189 1.1 rjs (tsn == ntohl(asoc->pending_reply->reset_at_tsn)))
2190 1.1 rjs ) {
2191 1.1 rjs /* yep its past where we need to reset... go ahead and
2192 1.1 rjs * queue it.
2193 1.1 rjs */
2194 1.1 rjs TAILQ_INSERT_TAIL(&asoc->pending_reply_queue , chk, sctp_next);
2195 1.1 rjs } else {
2196 1.1 rjs sctp_queue_data_to_stream(stcb, asoc, chk, abort_flag);
2197 1.1 rjs }
2198 1.1 rjs }
2199 1.1 rjs } else {
2200 1.1 rjs /* Into the re-assembly queue */
2201 1.1 rjs sctp_queue_data_for_reasm(stcb, asoc, chk, abort_flag);
2202 1.1 rjs if (*abort_flag) {
2203 1.1 rjs sctp_pegs[SCTP_DROP_FRAG]++;
2204 1.1 rjs return (0);
2205 1.1 rjs }
2206 1.1 rjs }
2207 1.1 rjs if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) {
2208 1.1 rjs /* we have a new high score */
2209 1.1 rjs asoc->highest_tsn_inside_map = tsn;
2210 1.1 rjs #ifdef SCTP_MAP_LOGGING
2211 1.1 rjs sctp_log_map(0, 2, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
2212 1.1 rjs #endif
2213 1.1 rjs }
2214 1.1 rjs finish_express_del:
2215 1.1 rjs if (last_chunk) {
2216 1.1 rjs *m = NULL;
2217 1.1 rjs }
2218 1.1 rjs sctp_pegs[SCTP_PEG_TSNS_RCVD]++;
2219 1.1 rjs /* Set it present please */
2220 1.1 rjs #ifdef SCTP_STR_LOGGING
2221 1.1 rjs sctp_log_strm_del_alt(tsn, strmseq, SCTP_STR_LOG_FROM_MARK_TSN);
2222 1.1 rjs #endif
2223 1.1 rjs #ifdef SCTP_MAP_LOGGING
2224 1.1 rjs sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn,
2225 1.1 rjs asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE);
2226 1.1 rjs #endif
2227 1.1 rjs SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap);
2228 1.1 rjs return (1);
2229 1.1 rjs }
2230 1.1 rjs
2231 1.1 rjs void
2232 1.1 rjs sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort_flag)
2233 1.1 rjs {
2234 1.1 rjs /*
2235 1.1 rjs * Now we also need to check the mapping array in a couple of ways.
2236 1.1 rjs * 1) Did we move the cum-ack point?
2237 1.1 rjs */
2238 1.1 rjs struct sctp_association *asoc;
2239 1.1 rjs int i, at;
2240 1.1 rjs int m_size, all_ones;
2241 1.1 rjs int slide_from, slide_end, lgap, distance;
2242 1.1 rjs #ifdef SCTP_MAP_LOGGING
2243 1.1 rjs uint32_t old_cumack, old_base, old_highest;
2244 1.1 rjs unsigned char aux_array[64];
2245 1.1 rjs #endif
2246 1.1 rjs
2247 1.1 rjs asoc = &stcb->asoc;
2248 1.1 rjs at = 0;
2249 1.1 rjs
2250 1.1 rjs #ifdef SCTP_MAP_LOGGING
2251 1.1 rjs old_cumack = asoc->cumulative_tsn;
2252 1.1 rjs old_base = asoc->mapping_array_base_tsn;
2253 1.1 rjs old_highest = asoc->highest_tsn_inside_map;
2254 1.1 rjs if (asoc->mapping_array_size < 64)
2255 1.1 rjs memcpy(aux_array, asoc->mapping_array,
2256 1.1 rjs asoc->mapping_array_size);
2257 1.1 rjs else
2258 1.1 rjs memcpy(aux_array, asoc->mapping_array, 64);
2259 1.1 rjs #endif
2260 1.1 rjs
2261 1.1 rjs /*
2262 1.1 rjs * We could probably improve this a small bit by calculating the
2263 1.1 rjs * offset of the current cum-ack as the starting point.
2264 1.1 rjs */
2265 1.1 rjs all_ones = 1;
2266 1.1 rjs m_size = stcb->asoc.mapping_array_size << 3;
2267 1.1 rjs for (i = 0; i < m_size; i++) {
2268 1.1 rjs if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, i)) {
2269 1.1 rjs /*
2270 1.1 rjs * Ok we found the first place that we are
2271 1.1 rjs * missing a TSN.
2272 1.1 rjs */
2273 1.1 rjs at = i;
2274 1.1 rjs all_ones = 0;
2275 1.1 rjs asoc->cumulative_tsn = asoc->mapping_array_base_tsn +
2276 1.1 rjs (i - 1);
2277 1.1 rjs break;
2278 1.1 rjs }
2279 1.1 rjs }
2280 1.1 rjs if (compare_with_wrap(asoc->cumulative_tsn,
2281 1.1 rjs asoc->highest_tsn_inside_map,
2282 1.1 rjs MAX_TSN)) {
2283 1.1 rjs panic("huh, cumack greater than high-tsn in map");
2284 1.1 rjs }
2285 1.1 rjs if (all_ones ||
2286 1.1 rjs (asoc->cumulative_tsn == asoc->highest_tsn_inside_map && at >= 8)) {
2287 1.1 rjs /* The complete array was completed by a single FR */
2288 1.1 rjs /* higest becomes the cum-ack */
2289 1.1 rjs int clr;
2290 1.1 rjs asoc->cumulative_tsn = asoc->highest_tsn_inside_map;
2291 1.1 rjs /* clear the array */
2292 1.1 rjs if (all_ones)
2293 1.1 rjs clr = asoc->mapping_array_size;
2294 1.1 rjs else {
2295 1.1 rjs clr = (at >> 3) + 1;
2296 1.1 rjs /*
2297 1.1 rjs * this should be the allones case
2298 1.1 rjs * but just in case :>
2299 1.1 rjs */
2300 1.1 rjs if (clr > asoc->mapping_array_size)
2301 1.1 rjs clr = asoc->mapping_array_size;
2302 1.1 rjs }
2303 1.1 rjs memset(asoc->mapping_array, 0, clr);
2304 1.1 rjs /* base becomes one ahead of the cum-ack */
2305 1.1 rjs asoc->mapping_array_base_tsn = asoc->cumulative_tsn + 1;
2306 1.1 rjs #ifdef SCTP_MAP_LOGGING
2307 1.1 rjs sctp_log_map(old_base, old_cumack, old_highest,
2308 1.1 rjs SCTP_MAP_PREPARE_SLIDE);
2309 1.1 rjs sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn,
2310 1.1 rjs asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_CLEARED);
2311 1.1 rjs #endif
2312 1.1 rjs } else if (at >= 8) {
2313 1.1 rjs /* we can slide the mapping array down */
2314 1.1 rjs /* Calculate the new byte postion we can move down */
2315 1.1 rjs slide_from = at >> 3;
2316 1.1 rjs /* now calculate the ceiling of the move using our highest TSN value */
2317 1.1 rjs if (asoc->highest_tsn_inside_map >= asoc->mapping_array_base_tsn) {
2318 1.1 rjs lgap = asoc->highest_tsn_inside_map -
2319 1.1 rjs asoc->mapping_array_base_tsn;
2320 1.1 rjs } else {
2321 1.1 rjs lgap = (MAX_TSN - asoc->mapping_array_base_tsn) +
2322 1.1 rjs asoc->highest_tsn_inside_map + 1;
2323 1.1 rjs }
2324 1.1 rjs slide_end = lgap >> 3;
2325 1.1 rjs if (slide_end < slide_from) {
2326 1.1 rjs panic("impossible slide");
2327 1.1 rjs }
2328 1.1 rjs distance = (slide_end-slide_from) + 1;
2329 1.1 rjs #ifdef SCTP_MAP_LOGGING
2330 1.1 rjs sctp_log_map(old_base, old_cumack, old_highest,
2331 1.1 rjs SCTP_MAP_PREPARE_SLIDE);
2332 1.1 rjs sctp_log_map((uint32_t)slide_from, (uint32_t)slide_end,
2333 1.1 rjs (uint32_t)lgap, SCTP_MAP_SLIDE_FROM);
2334 1.1 rjs #endif
2335 1.1 rjs if (distance + slide_from > asoc->mapping_array_size ||
2336 1.1 rjs distance < 0) {
2337 1.1 rjs #ifdef SCTP_DEBUG
2338 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
2339 1.1 rjs printf("Ugh bad addition.. you can't hrumpp!\n");
2340 1.1 rjs }
2341 1.1 rjs #endif
2342 1.1 rjs /*
2343 1.1 rjs * Here we do NOT slide forward the array so that
2344 1.1 rjs * hopefully when more data comes in to fill it up
2345 1.1 rjs * we will be able to slide it forward. Really
2346 1.1 rjs * I don't think this should happen :-0
2347 1.1 rjs */
2348 1.1 rjs
2349 1.1 rjs #ifdef SCTP_MAP_LOGGING
2350 1.1 rjs sctp_log_map((uint32_t)distance, (uint32_t)slide_from,
2351 1.1 rjs (uint32_t)asoc->mapping_array_size,
2352 1.1 rjs SCTP_MAP_SLIDE_NONE);
2353 1.1 rjs #endif
2354 1.1 rjs } else {
2355 1.1 rjs int ii;
2356 1.1 rjs for (ii = 0; ii < distance; ii++) {
2357 1.1 rjs asoc->mapping_array[ii] =
2358 1.1 rjs asoc->mapping_array[slide_from + ii];
2359 1.1 rjs }
2360 1.1 rjs for (ii = distance;ii <= slide_end; ii++) {
2361 1.1 rjs asoc->mapping_array[ii] = 0;
2362 1.1 rjs }
2363 1.1 rjs asoc->mapping_array_base_tsn += (slide_from << 3);
2364 1.1 rjs #ifdef SCTP_MAP_LOGGING
2365 1.1 rjs sctp_log_map(asoc->mapping_array_base_tsn,
2366 1.1 rjs asoc->cumulative_tsn, asoc->highest_tsn_inside_map,
2367 1.1 rjs SCTP_MAP_SLIDE_RESULT);
2368 1.1 rjs #endif
2369 1.1 rjs }
2370 1.1 rjs }
2371 1.1 rjs
2372 1.1 rjs /* check the special flag for stream resets */
2373 1.1 rjs if ((asoc->pending_reply) &&
2374 1.1 rjs ((compare_with_wrap((asoc->cumulative_tsn+1), ntohl(asoc->pending_reply->reset_at_tsn), MAX_TSN)) ||
2375 1.1 rjs ((asoc->cumulative_tsn+1) == ntohl(asoc->pending_reply->reset_at_tsn)))
2376 1.1 rjs ) {
2377 1.1 rjs /* we have finished working through the backlogged TSN's now
2378 1.1 rjs * time to reset streams.
2379 1.1 rjs * 1: call reset function.
2380 1.1 rjs * 2: free pending_reply space
2381 1.1 rjs * 3: distribute any chunks in pending_reply_queue.
2382 1.1 rjs */
2383 1.1 rjs struct sctp_tmit_chunk *chk;
2384 1.1 rjs sctp_handle_stream_reset_response(stcb, asoc->pending_reply);
2385 1.1 rjs free(asoc->pending_reply, M_PCB);
2386 1.1 rjs asoc->pending_reply = NULL;
2387 1.1 rjs chk = TAILQ_FIRST(&asoc->pending_reply_queue);
2388 1.1 rjs while (chk) {
2389 1.1 rjs TAILQ_REMOVE(&asoc->pending_reply_queue, chk, sctp_next);
2390 1.1 rjs sctp_queue_data_to_stream(stcb, asoc, chk, abort_flag);
2391 1.1 rjs if (*abort_flag) {
2392 1.1 rjs return;
2393 1.1 rjs }
2394 1.1 rjs chk = TAILQ_FIRST(&asoc->pending_reply_queue);
2395 1.1 rjs }
2396 1.1 rjs }
2397 1.1 rjs /*
2398 1.1 rjs * Now we need to see if we need to queue a sack or just start
2399 1.1 rjs * the timer (if allowed).
2400 1.1 rjs */
2401 1.1 rjs if (ok_to_sack) {
2402 1.1 rjs if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) {
2403 1.1 rjs /*
2404 1.1 rjs * Ok special case, in SHUTDOWN-SENT case.
2405 1.1 rjs * here we maker sure SACK timer is off and
2406 1.1 rjs * instead send a SHUTDOWN and a SACK
2407 1.1 rjs */
2408 1.1 rjs if (callout_pending(&stcb->asoc.dack_timer.timer)) {
2409 1.1 rjs sctp_timer_stop(SCTP_TIMER_TYPE_RECV,
2410 1.1 rjs stcb->sctp_ep, stcb, NULL);
2411 1.1 rjs }
2412 1.1 rjs #ifdef SCTP_DEBUG
2413 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
2414 1.1 rjs printf("%s:%d sends a shutdown\n",
2415 1.1 rjs __FILE__,
2416 1.1 rjs __LINE__
2417 1.1 rjs );
2418 1.1 rjs }
2419 1.1 rjs #endif
2420 1.1 rjs sctp_send_shutdown(stcb, stcb->asoc.primary_destination);
2421 1.1 rjs sctp_send_sack(stcb);
2422 1.1 rjs } else {
2423 1.1 rjs int is_a_gap;
2424 1.1 rjs /* is there a gap now ? */
2425 1.1 rjs is_a_gap = compare_with_wrap(stcb->asoc.highest_tsn_inside_map,
2426 1.1 rjs stcb->asoc.cumulative_tsn, MAX_TSN);
2427 1.1 rjs if ((stcb->asoc.first_ack_sent == 0) || /* First time we send a sack */
2428 1.1 rjs ((was_a_gap) && (is_a_gap == 0)) || /* was a gap, but no longer is one */
2429 1.1 rjs (stcb->asoc.numduptsns) || /* we have dup's */
2430 1.1 rjs (is_a_gap) || /* is still a gap */
2431 1.1 rjs (callout_pending(&stcb->asoc.dack_timer.timer)) /* timer was up . second packet */
2432 1.1 rjs ) {
2433 1.1 rjs /*
2434 1.1 rjs * Ok we must build a SACK since the timer
2435 1.1 rjs * is pending, we got our first packet OR
2436 1.1 rjs * there are gaps or duplicates.
2437 1.1 rjs */
2438 1.1 rjs stcb->asoc.first_ack_sent = 1;
2439 1.1 rjs sctp_send_sack(stcb);
2440 1.1 rjs /* The sending will stop the timer */
2441 1.1 rjs } else {
2442 1.1 rjs sctp_timer_start(SCTP_TIMER_TYPE_RECV,
2443 1.1 rjs stcb->sctp_ep, stcb, NULL);
2444 1.1 rjs }
2445 1.1 rjs }
2446 1.1 rjs }
2447 1.1 rjs }
2448 1.1 rjs
2449 1.1 rjs void
2450 1.1 rjs sctp_service_queues(struct sctp_tcb *stcb, struct sctp_association *asoc, int hold_locks)
2451 1.1 rjs {
2452 1.1 rjs struct sctp_tmit_chunk *chk;
2453 1.1 rjs int tsize, cntDel;
2454 1.1 rjs u_int16_t nxt_todel;
2455 1.1 rjs
2456 1.1 rjs cntDel = 0;
2457 1.1 rjs if (asoc->fragmented_delivery_inprogress) {
2458 1.1 rjs sctp_service_reassembly(stcb, asoc, hold_locks);
2459 1.1 rjs }
2460 1.1 rjs /* Can we proceed further, i.e. the PD-API is complete */
2461 1.1 rjs if (asoc->fragmented_delivery_inprogress) {
2462 1.1 rjs /* no */
2463 1.1 rjs return;
2464 1.1 rjs }
2465 1.1 rjs
2466 1.1 rjs /*
2467 1.1 rjs * Yes, reassembly delivery no longer in progress see if we
2468 1.1 rjs * have some on the sb hold queue.
2469 1.1 rjs */
2470 1.1 rjs do {
2471 1.1 rjs if (stcb->sctp_socket->so_rcv.sb_cc >= stcb->sctp_socket->so_rcv.sb_hiwat) {
2472 1.1 rjs if (cntDel == 0)
2473 1.1 rjs sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
2474 1.1 rjs break;
2475 1.1 rjs }
2476 1.1 rjs /* If deliver_data says no we must stop */
2477 1.1 rjs if (sctp_deliver_data(stcb, asoc, (struct sctp_tmit_chunk *)NULL, hold_locks) == 0)
2478 1.1 rjs break;
2479 1.1 rjs cntDel++;
2480 1.1 rjs chk = TAILQ_FIRST(&asoc->delivery_queue);
2481 1.1 rjs } while (chk);
2482 1.1 rjs if (cntDel) {
2483 1.1 rjs sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
2484 1.1 rjs }
2485 1.1 rjs /*
2486 1.1 rjs * Now is there some other chunk I can deliver
2487 1.1 rjs * from the reassembly queue.
2488 1.1 rjs */
2489 1.1 rjs chk = TAILQ_FIRST(&asoc->reasmqueue);
2490 1.1 rjs if (chk == NULL) {
2491 1.1 rjs asoc->size_on_reasm_queue = 0;
2492 1.1 rjs asoc->cnt_on_reasm_queue = 0;
2493 1.1 rjs return;
2494 1.1 rjs }
2495 1.1 rjs nxt_todel = asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1;
2496 1.1 rjs if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) &&
2497 1.1 rjs ((nxt_todel == chk->rec.data.stream_seq) ||
2498 1.1 rjs (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) {
2499 1.1 rjs /*
2500 1.1 rjs * Yep the first one is here. We setup to
2501 1.1 rjs * start reception, by backing down the TSN
2502 1.1 rjs * just in case we can't deliver.
2503 1.1 rjs */
2504 1.1 rjs
2505 1.1 rjs /*
2506 1.1 rjs * Before we start though either all of the
2507 1.1 rjs * message should be here or 1/4 the socket buffer
2508 1.1 rjs * max or nothing on the delivery queue and something
2509 1.1 rjs * can be delivered.
2510 1.1 rjs */
2511 1.1 rjs if (TAILQ_EMPTY(&asoc->delivery_queue) &&
2512 1.1 rjs (sctp_is_all_msg_on_reasm(asoc, &tsize) ||
2513 1.1 rjs (asoc->size_on_reasm_queue >=
2514 1.1 rjs (stcb->sctp_socket->so_rcv.sb_hiwat >> 2) && tsize))) {
2515 1.1 rjs asoc->fragmented_delivery_inprogress = 1;
2516 1.1 rjs asoc->tsn_last_delivered = chk->rec.data.TSN_seq-1;
2517 1.1 rjs asoc->str_of_pdapi = chk->rec.data.stream_number;
2518 1.1 rjs asoc->ssn_of_pdapi = chk->rec.data.stream_seq;
2519 1.1 rjs asoc->fragment_flags = chk->rec.data.rcv_flags;
2520 1.1 rjs sctp_service_reassembly(stcb, asoc, hold_locks);
2521 1.1 rjs }
2522 1.1 rjs }
2523 1.1 rjs }
2524 1.1 rjs
2525 1.1 rjs int
2526 1.1 rjs sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length,
2527 1.1 rjs struct sctphdr *sh, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2528 1.1 rjs struct sctp_nets *net, u_int32_t *high_tsn)
2529 1.1 rjs {
2530 1.1 rjs struct sctp_data_chunk *ch, chunk_buf;
2531 1.1 rjs struct sctp_association *asoc;
2532 1.1 rjs int num_chunks = 0; /* number of control chunks processed */
2533 1.1 rjs int chk_length, break_flag, last_chunk;
2534 1.1 rjs int abort_flag = 0, was_a_gap = 0;
2535 1.1 rjs struct mbuf *m;
2536 1.1 rjs
2537 1.1 rjs /* set the rwnd */
2538 1.1 rjs sctp_set_rwnd(stcb, &stcb->asoc);
2539 1.1 rjs
2540 1.1 rjs m = *mm;
2541 1.1 rjs asoc = &stcb->asoc;
2542 1.1 rjs if (compare_with_wrap(stcb->asoc.highest_tsn_inside_map,
2543 1.1 rjs stcb->asoc.cumulative_tsn, MAX_TSN)) {
2544 1.1 rjs /* there was a gap before this data was processed */
2545 1.1 rjs was_a_gap = 1;
2546 1.1 rjs }
2547 1.1 rjs /*
2548 1.1 rjs * setup where we got the last DATA packet from for
2549 1.1 rjs * any SACK that may need to go out. Don't bump
2550 1.1 rjs * the net. This is done ONLY when a chunk
2551 1.1 rjs * is assigned.
2552 1.1 rjs */
2553 1.1 rjs asoc->last_data_chunk_from = net;
2554 1.1 rjs
2555 1.1 rjs /*
2556 1.1 rjs * Now before we proceed we must figure out if this
2557 1.1 rjs * is a wasted cluster... i.e. it is a small packet
2558 1.1 rjs * sent in and yet the driver underneath allocated a
2559 1.1 rjs * full cluster for it. If so we must copy it to a
2560 1.1 rjs * smaller mbuf and free up the cluster mbuf. This
2561 1.1 rjs * will help with cluster starvation.
2562 1.1 rjs */
2563 1.1 rjs if (m->m_len < (long)MHLEN && m->m_next == NULL) {
2564 1.1 rjs /* we only handle mbufs that are singletons.. not chains */
2565 1.1 rjs MGET(m, M_DONTWAIT, MT_DATA);
2566 1.1 rjs if (m) {
2567 1.1 rjs /* ok lets see if we can copy the data up */
2568 1.1 rjs vaddr_t *from, *to;
2569 1.1 rjs
2570 1.1 rjs if ((*mm)->m_flags & M_PKTHDR) {
2571 1.1 rjs /* got to copy the header first */
2572 1.1 rjs #ifdef __APPLE__
2573 1.1 rjs M_COPY_PKTHDR(m, (*mm));
2574 1.1 rjs #else
2575 1.1 rjs M_MOVE_PKTHDR(m, (*mm));
2576 1.1 rjs #endif
2577 1.1 rjs }
2578 1.1 rjs /* get the pointers and copy */
2579 1.1 rjs to = mtod(m, vaddr_t *);
2580 1.1 rjs from = mtod((*mm), vaddr_t *);
2581 1.1 rjs memcpy(to, from, (*mm)->m_len);
2582 1.1 rjs /* copy the length and free up the old */
2583 1.1 rjs m->m_len = (*mm)->m_len;
2584 1.1 rjs sctp_m_freem(*mm);
2585 1.1 rjs /* sucess, back copy */
2586 1.1 rjs *mm = m;
2587 1.1 rjs } else {
2588 1.1 rjs /* We are in trouble in the mbuf world .. yikes */
2589 1.1 rjs m = *mm;
2590 1.1 rjs }
2591 1.1 rjs }
2592 1.1 rjs /* get pointer to the first chunk header */
2593 1.1 rjs ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset,
2594 1.1 rjs sizeof(chunk_buf), (u_int8_t *)&chunk_buf);
2595 1.1 rjs if (ch == NULL) {
2596 1.1 rjs printf(" ... its short\n");
2597 1.1 rjs return (1);
2598 1.1 rjs }
2599 1.1 rjs /*
2600 1.1 rjs * process all DATA chunks...
2601 1.1 rjs */
2602 1.1 rjs
2603 1.1 rjs #ifdef SCTP_DEBUG
2604 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
2605 1.1 rjs printf("In process data off:%d length:%d iphlen:%d ch->type:%d\n",
2606 1.1 rjs *offset, length, iphlen, (int)ch->ch.chunk_type);
2607 1.1 rjs }
2608 1.1 rjs #endif
2609 1.1 rjs
2610 1.1 rjs *high_tsn = asoc->cumulative_tsn;
2611 1.1 rjs break_flag = 0;
2612 1.1 rjs while (ch->ch.chunk_type == SCTP_DATA) {
2613 1.1 rjs /* validate chunk length */
2614 1.1 rjs chk_length = ntohs(ch->ch.chunk_length);
2615 1.1 rjs if ((size_t)chk_length < sizeof(struct sctp_data_chunk) + 1 ||
2616 1.1 rjs length - *offset < chk_length) {
2617 1.1 rjs /*
2618 1.1 rjs * Need to send an abort since we had a invalid
2619 1.1 rjs * data chunk.
2620 1.1 rjs */
2621 1.1 rjs struct mbuf *op_err;
2622 1.1 rjs MGET(op_err, M_DONTWAIT, MT_DATA);
2623 1.1 rjs if (op_err) {
2624 1.1 rjs struct sctp_paramhdr *ph;
2625 1.1 rjs u_int32_t *ippp;
2626 1.1 rjs
2627 1.1 rjs op_err->m_len = sizeof(struct sctp_paramhdr) +
2628 1.1 rjs sizeof(*ippp);
2629 1.1 rjs ph = mtod(op_err, struct sctp_paramhdr *);
2630 1.1 rjs ph->param_type =
2631 1.1 rjs htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
2632 1.1 rjs ph->param_length = htons(op_err->m_len);
2633 1.1 rjs ippp = (u_int32_t *)(ph + 1);
2634 1.1 rjs *ippp = htonl(0x30000001);
2635 1.1 rjs }
2636 1.1 rjs sctp_abort_association(inp, stcb, m, iphlen, sh,
2637 1.1 rjs op_err);
2638 1.1 rjs return (2);
2639 1.1 rjs }
2640 1.1 rjs #ifdef SCTP_DEBUG
2641 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
2642 1.1 rjs printf("A chunk of len:%d to process (tot:%d)\n",
2643 1.1 rjs chk_length, length - *offset);
2644 1.1 rjs }
2645 1.1 rjs #endif
2646 1.1 rjs
2647 1.1 rjs #ifdef SCTP_AUDITING_ENABLED
2648 1.1 rjs sctp_audit_log(0xB1, 0);
2649 1.1 rjs #endif
2650 1.1 rjs if (SCTP_SIZE32(chk_length) == *offset - length) {
2651 1.1 rjs last_chunk = 1;
2652 1.1 rjs } else {
2653 1.1 rjs last_chunk = 0;
2654 1.1 rjs }
2655 1.1 rjs if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset, ch,
2656 1.1 rjs chk_length, net, high_tsn, &abort_flag, &break_flag,
2657 1.1 rjs last_chunk)) {
2658 1.1 rjs num_chunks++;
2659 1.1 rjs #ifdef SCTP_DEBUG
2660 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
2661 1.1 rjs printf("Now incr num_chunks to %d\n",
2662 1.1 rjs num_chunks);
2663 1.1 rjs }
2664 1.1 rjs #endif
2665 1.1 rjs }
2666 1.1 rjs if (abort_flag)
2667 1.1 rjs return (2);
2668 1.1 rjs
2669 1.1 rjs if (break_flag) {
2670 1.1 rjs /*
2671 1.1 rjs * Set because of out of rwnd space and no drop rep
2672 1.1 rjs * space left.
2673 1.1 rjs */
2674 1.1 rjs break;
2675 1.1 rjs }
2676 1.1 rjs
2677 1.1 rjs *offset += SCTP_SIZE32(chk_length);
2678 1.1 rjs if (*offset >= length) {
2679 1.1 rjs /* no more data left in the mbuf chain */
2680 1.1 rjs break;
2681 1.1 rjs }
2682 1.1 rjs ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset,
2683 1.1 rjs sizeof(chunk_buf), (u_int8_t *)&chunk_buf);
2684 1.1 rjs if (ch == NULL) {
2685 1.1 rjs *offset = length;
2686 1.1 rjs break;
2687 1.1 rjs }
2688 1.1 rjs } /* while */
2689 1.1 rjs if (break_flag) {
2690 1.1 rjs /*
2691 1.1 rjs * we need to report rwnd overrun drops.
2692 1.1 rjs */
2693 1.1 rjs sctp_send_packet_dropped(stcb, net, *mm, iphlen, 0);
2694 1.1 rjs }
2695 1.1 rjs if (num_chunks) {
2696 1.1 rjs /*
2697 1.1 rjs * Did we get data, if so update the time for
2698 1.1 rjs * auto-close and give peer credit for being
2699 1.1 rjs * alive.
2700 1.1 rjs */
2701 1.1 rjs sctp_pegs[SCTP_DATA_DG_RECV]++;
2702 1.1 rjs stcb->asoc.overall_error_count = 0;
2703 1.1 rjs SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_last_rcvd);
2704 1.1 rjs }
2705 1.1 rjs /* now service all of the reassm queue and delivery queue */
2706 1.1 rjs sctp_service_queues(stcb, asoc, 0);
2707 1.1 rjs if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) {
2708 1.1 rjs /*
2709 1.1 rjs * Assure that we ack right away by making
2710 1.1 rjs * sure that a d-ack timer is running. So the
2711 1.1 rjs * sack_check will send a sack.
2712 1.1 rjs */
2713 1.1 rjs sctp_timer_start(SCTP_TIMER_TYPE_RECV, stcb->sctp_ep, stcb,
2714 1.1 rjs net);
2715 1.1 rjs }
2716 1.1 rjs /* Start a sack timer or QUEUE a SACK for sending */
2717 1.1 rjs sctp_sack_check(stcb, 1, was_a_gap, &abort_flag);
2718 1.1 rjs if (abort_flag)
2719 1.1 rjs return (2);
2720 1.1 rjs
2721 1.1 rjs return (0);
2722 1.1 rjs }
2723 1.1 rjs
2724 1.1 rjs static void
2725 1.1 rjs sctp_handle_segments(struct sctp_tcb *stcb, struct sctp_association *asoc,
2726 1.1 rjs struct sctp_sack_chunk *ch, u_long last_tsn, u_long *biggest_tsn_acked,
2727 1.1 rjs u_long *biggest_newly_acked_tsn, int num_seg, int *ecn_seg_sums)
2728 1.1 rjs {
2729 1.1 rjs /************************************************/
2730 1.1 rjs /* process fragments and update sendqueue */
2731 1.1 rjs /************************************************/
2732 1.1 rjs struct sctp_sack *sack;
2733 1.1 rjs struct sctp_gap_ack_block *frag;
2734 1.1 rjs struct sctp_tmit_chunk *tp1;
2735 1.1 rjs int i;
2736 1.1 rjs unsigned int j;
2737 1.1 rjs #ifdef SCTP_FR_LOGGING
2738 1.1 rjs int num_frs=0;
2739 1.1 rjs #endif
2740 1.1 rjs uint16_t frag_strt, frag_end, primary_flag_set;
2741 1.1 rjs u_long last_frag_high;
2742 1.1 rjs
2743 1.1 rjs if (asoc->primary_destination->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
2744 1.1 rjs primary_flag_set = 1;
2745 1.1 rjs } else {
2746 1.1 rjs primary_flag_set = 0;
2747 1.1 rjs }
2748 1.1 rjs
2749 1.1 rjs sack = &ch->sack;
2750 1.1 rjs frag = (struct sctp_gap_ack_block *)((vaddr_t)sack +
2751 1.1 rjs sizeof(struct sctp_sack));
2752 1.1 rjs tp1 = NULL;
2753 1.1 rjs last_frag_high = 0;
2754 1.1 rjs for (i = 0; i < num_seg; i++) {
2755 1.1 rjs frag_strt = ntohs(frag->start);
2756 1.1 rjs frag_end = ntohs(frag->end);
2757 1.1 rjs /* some sanity checks on the fargment offsets */
2758 1.1 rjs if (frag_strt > frag_end) {
2759 1.1 rjs /* this one is malformed, skip */
2760 1.1 rjs frag++;
2761 1.1 rjs continue;
2762 1.1 rjs }
2763 1.1 rjs if (compare_with_wrap((frag_end+last_tsn), *biggest_tsn_acked,
2764 1.1 rjs MAX_TSN))
2765 1.1 rjs *biggest_tsn_acked = frag_end+last_tsn;
2766 1.1 rjs
2767 1.1 rjs /* mark acked dgs and find out the highestTSN being acked */
2768 1.1 rjs if (tp1 == NULL) {
2769 1.1 rjs tp1 = TAILQ_FIRST(&asoc->sent_queue);
2770 1.1 rjs
2771 1.1 rjs /* save the locations of the last frags */
2772 1.1 rjs last_frag_high = frag_end + last_tsn;
2773 1.1 rjs } else {
2774 1.1 rjs /*
2775 1.1 rjs * now lets see if we need to reset the queue
2776 1.1 rjs * due to a out-of-order SACK fragment
2777 1.1 rjs */
2778 1.1 rjs if (compare_with_wrap(frag_strt+last_tsn,
2779 1.1 rjs last_frag_high, MAX_TSN)) {
2780 1.1 rjs /*
2781 1.1 rjs * if the new frag starts after the last TSN
2782 1.1 rjs * frag covered, we are ok
2783 1.1 rjs * and this one is beyond the last one
2784 1.1 rjs */
2785 1.1 rjs ;
2786 1.1 rjs } else {
2787 1.1 rjs /*
2788 1.1 rjs * ok, they have reset us, so we need to reset
2789 1.1 rjs * the queue this will cause extra hunting but
2790 1.1 rjs * hey, they chose the performance
2791 1.1 rjs * hit when they failed to order there gaps..
2792 1.1 rjs */
2793 1.1 rjs tp1 = TAILQ_FIRST(&asoc->sent_queue);
2794 1.1 rjs }
2795 1.1 rjs last_frag_high = frag_end + last_tsn;
2796 1.1 rjs }
2797 1.1 rjs for (j = frag_strt + last_tsn; j <= frag_end + last_tsn; j++) {
2798 1.1 rjs while (tp1) {
2799 1.1 rjs #ifdef SCTP_FR_LOGGING
2800 1.1 rjs if (tp1->rec.data.doing_fast_retransmit)
2801 1.1 rjs num_frs++;
2802 1.1 rjs #endif
2803 1.1 rjs
2804 1.1 rjs if (tp1->rec.data.TSN_seq == j) {
2805 1.1 rjs if (tp1->sent != SCTP_DATAGRAM_UNSENT) {
2806 1.1 rjs /* must be held until cum-ack passes */
2807 1.1 rjs /* ECN Nonce: Add the nonce value to the sender's nonce sum */
2808 1.1 rjs if (tp1->sent < SCTP_DATAGRAM_ACKED) {
2809 1.1 rjs /*
2810 1.1 rjs * If it is less than
2811 1.1 rjs * ACKED, it is now
2812 1.1 rjs * no-longer in flight.
2813 1.1 rjs * Higher values may
2814 1.1 rjs * already be set via
2815 1.1 rjs * previous Gap Ack
2816 1.1 rjs * Blocks...
2817 1.1 rjs * i.e. ACKED or MARKED.
2818 1.1 rjs */
2819 1.1 rjs if (compare_with_wrap(tp1->rec.data.TSN_seq,
2820 1.1 rjs *biggest_newly_acked_tsn,
2821 1.1 rjs MAX_TSN)) {
2822 1.1 rjs *biggest_newly_acked_tsn =
2823 1.1 rjs tp1->rec.data.TSN_seq;
2824 1.1 rjs }
2825 1.1 rjs sctp_flight_size_decrease(tp1);
2826 1.1 rjs
2827 1.1 rjs sctp_total_flight_decrease(stcb, tp1);
2828 1.1 rjs
2829 1.1 rjs if (tp1->snd_count < 2) {
2830 1.1 rjs /* True non-retransmited chunk */
2831 1.1 rjs tp1->whoTo->net_ack2 +=
2832 1.1 rjs tp1->send_size;
2833 1.1 rjs
2834 1.1 rjs /* update RTO too? */
2835 1.1 rjs if (tp1->do_rtt) {
2836 1.1 rjs tp1->whoTo->RTO =
2837 1.1 rjs sctp_calculate_rto(stcb,
2838 1.1 rjs asoc,
2839 1.1 rjs tp1->whoTo,
2840 1.1 rjs &tp1->sent_rcv_time);
2841 1.1 rjs tp1->whoTo->rto_pending = 0;
2842 1.1 rjs tp1->do_rtt = 0;
2843 1.1 rjs }
2844 1.1 rjs }
2845 1.1 rjs }
2846 1.1 rjs if (tp1->sent <= SCTP_DATAGRAM_RESEND &&
2847 1.1 rjs tp1->sent != SCTP_DATAGRAM_UNSENT &&
2848 1.1 rjs compare_with_wrap(tp1->rec.data.TSN_seq,
2849 1.1 rjs asoc->this_sack_highest_gap,
2850 1.1 rjs MAX_TSN)) {
2851 1.1 rjs asoc->this_sack_highest_gap =
2852 1.1 rjs tp1->rec.data.TSN_seq;
2853 1.1 rjs if (primary_flag_set) {
2854 1.1 rjs tp1->whoTo->cacc_saw_newack = 1;
2855 1.1 rjs }
2856 1.1 rjs }
2857 1.1 rjs if (tp1->sent == SCTP_DATAGRAM_RESEND) {
2858 1.1 rjs #ifdef SCTP_DEBUG
2859 1.1 rjs if (sctp_debug_on &
2860 1.1 rjs SCTP_DEBUG_INDATA3) {
2861 1.1 rjs printf("Hmm. one that is in RESEND that is now ACKED\n");
2862 1.1 rjs }
2863 1.1 rjs #endif
2864 1.1 rjs sctp_ucount_decr(asoc->sent_queue_retran_cnt);
2865 1.1 rjs #ifdef SCTP_AUDITING_ENABLED
2866 1.1 rjs sctp_audit_log(0xB2,
2867 1.1 rjs (asoc->sent_queue_retran_cnt & 0x000000ff));
2868 1.1 rjs #endif
2869 1.1 rjs
2870 1.1 rjs }
2871 1.1 rjs (*ecn_seg_sums) += tp1->rec.data.ect_nonce;
2872 1.1 rjs (*ecn_seg_sums) &= SCTP_SACK_NONCE_SUM;
2873 1.1 rjs tp1->sent = SCTP_DATAGRAM_MARKED;
2874 1.1 rjs }
2875 1.1 rjs break;
2876 1.1 rjs } /* if (tp1->TSN_seq == j) */
2877 1.1 rjs if (compare_with_wrap(tp1->rec.data.TSN_seq, j,
2878 1.1 rjs MAX_TSN))
2879 1.1 rjs break;
2880 1.1 rjs tp1 = TAILQ_NEXT(tp1, sctp_next);
2881 1.1 rjs }/* end while (tp1) */
2882 1.1 rjs } /* end for (j = fragStart */
2883 1.1 rjs frag++; /* next one */
2884 1.1 rjs }
2885 1.1 rjs #ifdef SCTP_FR_LOGGING
2886 1.1 rjs if (num_frs)
2887 1.1 rjs sctp_log_fr(*biggest_tsn_acked, *biggest_newly_acked_tsn,
2888 1.1 rjs last_tsn, SCTP_FR_LOG_BIGGEST_TSNS);
2889 1.1 rjs #endif
2890 1.1 rjs }
2891 1.1 rjs
2892 1.1 rjs static void
2893 1.1 rjs sctp_check_for_revoked(struct sctp_association *asoc, u_long cum_ack,
2894 1.1 rjs u_long biggest_tsn_acked)
2895 1.1 rjs {
2896 1.1 rjs struct sctp_tmit_chunk *tp1;
2897 1.1 rjs int tot_revoked=0;
2898 1.1 rjs
2899 1.1 rjs tp1 = TAILQ_FIRST(&asoc->sent_queue);
2900 1.1 rjs while (tp1) {
2901 1.1 rjs if (compare_with_wrap(tp1->rec.data.TSN_seq, cum_ack,
2902 1.1 rjs MAX_TSN)) {
2903 1.1 rjs /*
2904 1.1 rjs * ok this guy is either ACK or MARKED. If it is ACKED
2905 1.1 rjs * it has been previously acked but not this time i.e.
2906 1.1 rjs * revoked. If it is MARKED it was ACK'ed again.
2907 1.1 rjs */
2908 1.1 rjs if (tp1->sent == SCTP_DATAGRAM_ACKED) {
2909 1.1 rjs /* it has been revoked */
2910 1.1 rjs /*
2911 1.1 rjs * We do NOT add back to flight size here since
2912 1.1 rjs * it is really NOT in flight. Resend (when/if
2913 1.1 rjs * it occurs will add to flight size
2914 1.1 rjs */
2915 1.1 rjs tp1->sent = SCTP_DATAGRAM_SENT;
2916 1.1 rjs tot_revoked++;
2917 1.1 rjs } else if (tp1->sent == SCTP_DATAGRAM_MARKED) {
2918 1.1 rjs /* it has been re-acked in this SACK */
2919 1.1 rjs tp1->sent = SCTP_DATAGRAM_ACKED;
2920 1.1 rjs }
2921 1.1 rjs }
2922 1.1 rjs if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked,
2923 1.1 rjs MAX_TSN)) {
2924 1.1 rjs /* above the sack */
2925 1.1 rjs break;
2926 1.1 rjs }
2927 1.1 rjs if (tp1->sent == SCTP_DATAGRAM_UNSENT)
2928 1.1 rjs break;
2929 1.1 rjs tp1 = TAILQ_NEXT(tp1, sctp_next);
2930 1.1 rjs }
2931 1.1 rjs if (tot_revoked > 0) {
2932 1.1 rjs /* Setup the ecn nonce re-sync point. We
2933 1.1 rjs * do this since once data is revoked
2934 1.1 rjs * we begin to retransmit things, which
2935 1.1 rjs * do NOT have the ECN bits set. This means
2936 1.1 rjs * we are now out of sync and must wait until
2937 1.1 rjs * we get back in sync with the peer to
2938 1.1 rjs * check ECN bits.
2939 1.1 rjs */
2940 1.1 rjs tp1 = TAILQ_FIRST(&asoc->send_queue);
2941 1.1 rjs if (tp1 == NULL) {
2942 1.1 rjs asoc->nonce_resync_tsn = asoc->sending_seq;
2943 1.1 rjs } else {
2944 1.1 rjs asoc->nonce_resync_tsn = tp1->rec.data.TSN_seq;
2945 1.1 rjs }
2946 1.1 rjs asoc->nonce_wait_for_ecne = 0;
2947 1.1 rjs asoc->nonce_sum_check = 0;
2948 1.1 rjs }
2949 1.1 rjs
2950 1.1 rjs }
2951 1.1 rjs
2952 1.1 rjs extern int sctp_peer_chunk_oh;
2953 1.1 rjs
2954 1.1 rjs static void
2955 1.1 rjs sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc,
2956 1.1 rjs u_long biggest_tsn_acked, int strike_enabled,
2957 1.1 rjs u_long biggest_tsn_newly_acked, int accum_moved)
2958 1.1 rjs {
2959 1.1 rjs struct sctp_tmit_chunk *tp1;
2960 1.1 rjs int strike_flag=0;
2961 1.1 rjs struct timeval now;
2962 1.1 rjs int tot_retrans=0;
2963 1.1 rjs u_int32_t sending_seq;
2964 1.1 rjs int primary_switch_active = 0;
2965 1.1 rjs int double_switch_active = 0;
2966 1.1 rjs
2967 1.1 rjs /* select the sending_seq, this is
2968 1.1 rjs * either the next thing ready to
2969 1.1 rjs * be sent but not transmitted, OR,
2970 1.1 rjs * the next seq we assign.
2971 1.1 rjs */
2972 1.1 rjs tp1 = TAILQ_FIRST(&stcb->asoc.send_queue);
2973 1.1 rjs if (tp1 == NULL) {
2974 1.1 rjs sending_seq = asoc->sending_seq;
2975 1.1 rjs } else {
2976 1.1 rjs sending_seq = tp1->rec.data.TSN_seq;
2977 1.1 rjs }
2978 1.1 rjs
2979 1.1 rjs if (asoc->primary_destination->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
2980 1.1 rjs primary_switch_active = 1;
2981 1.1 rjs }
2982 1.1 rjs if (asoc->primary_destination->dest_state & SCTP_ADDR_DOUBLE_SWITCH) {
2983 1.1 rjs double_switch_active = 1;
2984 1.1 rjs }
2985 1.1 rjs if (stcb->asoc.peer_supports_prsctp ) {
2986 1.1 rjs SCTP_GETTIME_TIMEVAL(&now);
2987 1.1 rjs }
2988 1.1 rjs tp1 = TAILQ_FIRST(&asoc->sent_queue);
2989 1.1 rjs while (tp1) {
2990 1.1 rjs strike_flag=0;
2991 1.1 rjs if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked,
2992 1.1 rjs MAX_TSN) ||
2993 1.1 rjs tp1->sent == SCTP_DATAGRAM_UNSENT) {
2994 1.1 rjs /* done */
2995 1.1 rjs break;
2996 1.1 rjs }
2997 1.1 rjs if ((tp1->flags & (SCTP_PR_SCTP_ENABLED|SCTP_PR_SCTP_BUFFER)) ==
2998 1.1 rjs SCTP_PR_SCTP_ENABLED &&
2999 1.1 rjs tp1->sent < SCTP_DATAGRAM_ACKED) {
3000 1.1 rjs /* Is it expired? */
3001 1.1 rjs #ifndef __FreeBSD__
3002 1.1 rjs if (timercmp(&now, &tp1->rec.data.timetodrop, >))
3003 1.1 rjs #else
3004 1.1 rjs if (timevalcmp(&now, &tp1->rec.data.timetodrop, >))
3005 1.1 rjs #endif
3006 1.1 rjs {
3007 1.1 rjs /* Yes so drop it */
3008 1.1 rjs if (tp1->data != NULL) {
3009 1.1 rjs sctp_release_pr_sctp_chunk(stcb, tp1,
3010 1.1 rjs (SCTP_RESPONSE_TO_USER_REQ|SCTP_NOTIFY_DATAGRAM_SENT),
3011 1.1 rjs &asoc->sent_queue);
3012 1.1 rjs }
3013 1.1 rjs tp1 = TAILQ_NEXT(tp1, sctp_next);
3014 1.1 rjs continue;
3015 1.1 rjs }
3016 1.1 rjs }
3017 1.1 rjs
3018 1.1 rjs if (compare_with_wrap(tp1->rec.data.TSN_seq,
3019 1.1 rjs asoc->this_sack_highest_gap, MAX_TSN)) {
3020 1.1 rjs /* we are beyond the tsn in the sack */
3021 1.1 rjs break;
3022 1.1 rjs }
3023 1.1 rjs if (tp1->sent >= SCTP_DATAGRAM_RESEND) {
3024 1.1 rjs /* either a RESEND, ACKED, or MARKED */
3025 1.1 rjs /* skip */
3026 1.1 rjs tp1 = TAILQ_NEXT(tp1, sctp_next);
3027 1.1 rjs continue;
3028 1.1 rjs }
3029 1.1 rjs if (primary_switch_active && (strike_enabled == 0)) {
3030 1.1 rjs if (tp1->whoTo != asoc->primary_destination) {
3031 1.1 rjs /*
3032 1.1 rjs * We can only strike things on the primary if
3033 1.1 rjs * the strike_enabled flag is clear
3034 1.1 rjs */
3035 1.1 rjs tp1 = TAILQ_NEXT(tp1, sctp_next);
3036 1.1 rjs continue;
3037 1.1 rjs }
3038 1.1 rjs } else if (primary_switch_active) {
3039 1.1 rjs if (tp1->whoTo->cacc_saw_newack == 0) {
3040 1.1 rjs /*
3041 1.1 rjs * Only one was received but it was NOT
3042 1.1 rjs * this one.
3043 1.1 rjs */
3044 1.1 rjs tp1 = TAILQ_NEXT(tp1, sctp_next);
3045 1.1 rjs continue;
3046 1.1 rjs }
3047 1.1 rjs }
3048 1.1 rjs if (double_switch_active &&
3049 1.1 rjs (compare_with_wrap(asoc->primary_destination->next_tsn_at_change,
3050 1.1 rjs tp1->rec.data.TSN_seq, MAX_TSN))) {
3051 1.1 rjs /*
3052 1.1 rjs * With a double switch we do NOT mark unless we
3053 1.1 rjs * are beyond the switch point.
3054 1.1 rjs */
3055 1.1 rjs tp1 = TAILQ_NEXT(tp1, sctp_next);
3056 1.1 rjs continue;
3057 1.1 rjs }
3058 1.1 rjs /*
3059 1.1 rjs * Here we check to see if we were have already done a FR
3060 1.1 rjs * and if so we see if the biggest TSN we saw in the sack is
3061 1.1 rjs * smaller than the recovery point. If so we don't strike the
3062 1.1 rjs * tsn... otherwise we CAN strike the TSN.
3063 1.1 rjs */
3064 1.1 rjs if (accum_moved && asoc->fast_retran_loss_recovery) {
3065 1.1 rjs /*
3066 1.1 rjs * Strike the TSN if in fast-recovery and
3067 1.1 rjs * cum-ack moved.
3068 1.1 rjs */
3069 1.1 rjs tp1->sent++;
3070 1.1 rjs } else if (tp1->rec.data.doing_fast_retransmit) {
3071 1.1 rjs /*
3072 1.1 rjs * For those that have done a FR we must
3073 1.1 rjs * take special consideration if we strike. I.e
3074 1.1 rjs * the biggest_newly_acked must be higher
3075 1.1 rjs * than the sending_seq at the time we did
3076 1.1 rjs * the FR.
3077 1.1 rjs */
3078 1.1 rjs #ifdef SCTP_FR_TO_ALTERNATE
3079 1.1 rjs /*
3080 1.1 rjs * If FR's go to new networks, then we
3081 1.1 rjs * must only do this for singly homed asoc's. However
3082 1.1 rjs * if the FR's go to the same network (Armando's work)
3083 1.1 rjs * then its ok to FR multiple times.
3084 1.1 rjs */
3085 1.1 rjs if (asoc->numnets < 2)
3086 1.1 rjs #else
3087 1.1 rjs if (1)
3088 1.1 rjs #endif
3089 1.1 rjs {
3090 1.1 rjs if ((compare_with_wrap(biggest_tsn_newly_acked,
3091 1.1 rjs tp1->rec.data.fast_retran_tsn, MAX_TSN)) ||
3092 1.1 rjs (biggest_tsn_newly_acked ==
3093 1.1 rjs tp1->rec.data.fast_retran_tsn)) {
3094 1.1 rjs /*
3095 1.1 rjs * Strike the TSN, since this ack is
3096 1.1 rjs * beyond where things were when we did
3097 1.1 rjs * a FR.
3098 1.1 rjs */
3099 1.1 rjs #ifdef SCTP_FR_LOGGING
3100 1.1 rjs sctp_log_fr(biggest_tsn_newly_acked,
3101 1.1 rjs tp1->rec.data.TSN_seq,
3102 1.1 rjs tp1->rec.data.fast_retran_tsn,
3103 1.1 rjs SCTP_FR_LOG_STRIKE_CHUNK);
3104 1.1 rjs #endif
3105 1.1 rjs tp1->sent++;
3106 1.1 rjs strike_flag=1;
3107 1.1 rjs }
3108 1.1 rjs }
3109 1.1 rjs } else if (compare_with_wrap(tp1->rec.data.TSN_seq,
3110 1.1 rjs biggest_tsn_newly_acked, MAX_TSN)) {
3111 1.1 rjs /*
3112 1.1 rjs * We don't strike these:
3113 1.1 rjs * This is the HTNA algorithm i.e. we don't strike
3114 1.1 rjs * If our TSN is larger than the Highest TSN Newly
3115 1.1 rjs * Acked.
3116 1.1 rjs */
3117 1.1 rjs ;
3118 1.1 rjs } else {
3119 1.1 rjs /* Strike the TSN */
3120 1.1 rjs tp1->sent++;
3121 1.1 rjs }
3122 1.1 rjs if (tp1->sent == SCTP_DATAGRAM_RESEND) {
3123 1.1 rjs /* Increment the count to resend */
3124 1.1 rjs struct sctp_nets *alt;
3125 1.1 rjs
3126 1.1 rjs #ifdef SCTP_FR_LOGGING
3127 1.1 rjs sctp_log_fr(tp1->rec.data.TSN_seq, tp1->snd_count,
3128 1.1 rjs 0, SCTP_FR_MARKED);
3129 1.1 rjs #endif
3130 1.1 rjs if (strike_flag) {
3131 1.1 rjs /* This is a subsequent FR */
3132 1.1 rjs sctp_pegs[SCTP_DUP_FR]++;
3133 1.1 rjs }
3134 1.1 rjs asoc->sent_queue_retran_cnt++;
3135 1.1 rjs #ifdef SCTP_FR_TO_ALTERNATE
3136 1.1 rjs /* Can we find an alternate? */
3137 1.1 rjs alt = sctp_find_alternate_net(stcb, tp1->whoTo);
3138 1.1 rjs #else
3139 1.1 rjs /*
3140 1.1 rjs * default behavior is to NOT retransmit FR's
3141 1.1 rjs * to an alternate. Armando Caro's paper details
3142 1.1 rjs * why.
3143 1.1 rjs */
3144 1.1 rjs alt = tp1->whoTo;
3145 1.1 rjs #endif
3146 1.1 rjs tp1->rec.data.doing_fast_retransmit = 1;
3147 1.1 rjs tot_retrans++;
3148 1.1 rjs /* mark the sending seq for possible subsequent FR's */
3149 1.1 rjs if (TAILQ_EMPTY(&asoc->send_queue)) {
3150 1.1 rjs /*
3151 1.1 rjs * If the queue of send is empty then its the
3152 1.1 rjs * next sequence number that will be assigned so
3153 1.1 rjs * we subtract one from this to get the one we
3154 1.1 rjs * last sent.
3155 1.1 rjs */
3156 1.1 rjs tp1->rec.data.fast_retran_tsn = sending_seq - 1;
3157 1.1 rjs } else {
3158 1.1 rjs /*
3159 1.1 rjs * If there are chunks on the send queue
3160 1.1 rjs * (unsent data that has made it from the
3161 1.1 rjs * stream queues but not out the door, we take
3162 1.1 rjs * the first one (which will have the lowest
3163 1.1 rjs * TSN) and subtract one to get the one we last
3164 1.1 rjs * sent.
3165 1.1 rjs */
3166 1.1 rjs struct sctp_tmit_chunk *ttt;
3167 1.1 rjs ttt = TAILQ_FIRST(&asoc->send_queue);
3168 1.1 rjs tp1->rec.data.fast_retran_tsn =
3169 1.1 rjs ttt->rec.data.TSN_seq - 1;
3170 1.1 rjs }
3171 1.1 rjs if (tp1->do_rtt) {
3172 1.1 rjs /*
3173 1.1 rjs * this guy had a RTO calculation pending on it,
3174 1.1 rjs * cancel it
3175 1.1 rjs */
3176 1.1 rjs tp1->whoTo->rto_pending = 0;
3177 1.1 rjs tp1->do_rtt = 0;
3178 1.1 rjs }
3179 1.1 rjs /* fix counts and things */
3180 1.1 rjs
3181 1.1 rjs tp1->whoTo->net_ack++;
3182 1.1 rjs sctp_flight_size_decrease(tp1);
3183 1.1 rjs #ifdef SCTP_LOG_RWND
3184 1.1 rjs sctp_log_rwnd(SCTP_INCREASE_PEER_RWND,
3185 1.1 rjs asoc->peers_rwnd , tp1->send_size, sctp_peer_chunk_oh);
3186 1.1 rjs #endif
3187 1.1 rjs /* add back to the rwnd */
3188 1.1 rjs asoc->peers_rwnd += (tp1->send_size + sctp_peer_chunk_oh);
3189 1.1 rjs
3190 1.1 rjs /* remove from the total flight */
3191 1.1 rjs sctp_total_flight_decrease(stcb, tp1);
3192 1.1 rjs if (alt != tp1->whoTo) {
3193 1.1 rjs /* yes, there is an alternate. */
3194 1.1 rjs sctp_free_remote_addr(tp1->whoTo);
3195 1.1 rjs tp1->whoTo = alt;
3196 1.1 rjs alt->ref_count++;
3197 1.1 rjs }
3198 1.1 rjs }
3199 1.1 rjs tp1 = TAILQ_NEXT(tp1, sctp_next);
3200 1.1 rjs } /* while (tp1) */
3201 1.1 rjs
3202 1.1 rjs if (tot_retrans > 0) {
3203 1.1 rjs /* Setup the ecn nonce re-sync point. We
3204 1.1 rjs * do this since once we go to FR something
3205 1.1 rjs * we introduce a Karn's rule scenario and
3206 1.1 rjs * won't know the totals for the ECN bits.
3207 1.1 rjs */
3208 1.1 rjs asoc->nonce_resync_tsn = sending_seq;
3209 1.1 rjs asoc->nonce_wait_for_ecne = 0;
3210 1.1 rjs asoc->nonce_sum_check = 0;
3211 1.1 rjs }
3212 1.1 rjs
3213 1.1 rjs }
3214 1.1 rjs
3215 1.1 rjs struct sctp_tmit_chunk *
3216 1.1 rjs sctp_try_advance_peer_ack_point(struct sctp_tcb *stcb,
3217 1.1 rjs struct sctp_association *asoc)
3218 1.1 rjs {
3219 1.1 rjs struct sctp_tmit_chunk *tp1, *tp2, *a_adv=NULL;
3220 1.1 rjs struct timeval now;
3221 1.1 rjs int now_filled=0;
3222 1.1 rjs
3223 1.1 rjs if (asoc->peer_supports_prsctp == 0) {
3224 1.1 rjs return (NULL);
3225 1.1 rjs }
3226 1.1 rjs tp1 = TAILQ_FIRST(&asoc->sent_queue);
3227 1.1 rjs while (tp1) {
3228 1.1 rjs if (tp1->sent != SCTP_FORWARD_TSN_SKIP &&
3229 1.1 rjs tp1->sent != SCTP_DATAGRAM_RESEND) {
3230 1.1 rjs /* no chance to advance, out of here */
3231 1.1 rjs break;
3232 1.1 rjs }
3233 1.1 rjs if ((tp1->flags & SCTP_PR_SCTP_ENABLED) == 0) {
3234 1.1 rjs /*
3235 1.1 rjs * We can't fwd-tsn past any that are reliable
3236 1.1 rjs * aka retransmitted until the asoc fails.
3237 1.1 rjs */
3238 1.1 rjs break;
3239 1.1 rjs }
3240 1.1 rjs if (!now_filled) {
3241 1.1 rjs SCTP_GETTIME_TIMEVAL(&now);
3242 1.1 rjs now_filled = 1;
3243 1.1 rjs }
3244 1.1 rjs tp2 = TAILQ_NEXT(tp1, sctp_next);
3245 1.1 rjs /*
3246 1.1 rjs * now we got a chunk which is marked for another
3247 1.1 rjs * retransmission to a PR-stream but has run
3248 1.1 rjs * out its chances already maybe OR has been
3249 1.1 rjs * marked to skip now. Can we skip it if its a
3250 1.1 rjs * resend?
3251 1.1 rjs */
3252 1.1 rjs if (tp1->sent == SCTP_DATAGRAM_RESEND &&
3253 1.1 rjs (tp1->flags & SCTP_PR_SCTP_BUFFER) == 0) {
3254 1.1 rjs /*
3255 1.1 rjs * Now is this one marked for resend and its time
3256 1.1 rjs * is now up?
3257 1.1 rjs */
3258 1.1 rjs #ifndef __FreeBSD__
3259 1.1 rjs if (timercmp(&now, &tp1->rec.data.timetodrop, >))
3260 1.1 rjs #else
3261 1.1 rjs if (timevalcmp(&now, &tp1->rec.data.timetodrop, >))
3262 1.1 rjs #endif
3263 1.1 rjs {
3264 1.1 rjs /* Yes so drop it */
3265 1.1 rjs if (tp1->data) {
3266 1.1 rjs sctp_release_pr_sctp_chunk(stcb, tp1,
3267 1.1 rjs (SCTP_RESPONSE_TO_USER_REQ|SCTP_NOTIFY_DATAGRAM_SENT),
3268 1.1 rjs &asoc->sent_queue);
3269 1.1 rjs }
3270 1.1 rjs } else {
3271 1.1 rjs /*
3272 1.1 rjs * No, we are done when hit one for resend whos
3273 1.1 rjs * time as not expired.
3274 1.1 rjs */
3275 1.1 rjs break;
3276 1.1 rjs }
3277 1.1 rjs }
3278 1.1 rjs /*
3279 1.1 rjs * Ok now if this chunk is marked to drop it
3280 1.1 rjs * we can clean up the chunk, advance our peer ack point
3281 1.1 rjs * and we can check the next chunk.
3282 1.1 rjs */
3283 1.1 rjs if (tp1->sent == SCTP_FORWARD_TSN_SKIP) {
3284 1.1 rjs /* advance PeerAckPoint goes forward */
3285 1.1 rjs asoc->advanced_peer_ack_point = tp1->rec.data.TSN_seq;
3286 1.1 rjs a_adv = tp1;
3287 1.1 rjs /*
3288 1.1 rjs * we don't want to de-queue it here. Just wait for the
3289 1.1 rjs * next peer SACK to come with a new cumTSN and then
3290 1.1 rjs * the chunk will be droped in the normal fashion.
3291 1.1 rjs */
3292 1.1 rjs if (tp1->data) {
3293 1.1 rjs sctp_free_bufspace(stcb, asoc, tp1);
3294 1.1 rjs #ifdef SCTP_DEBUG
3295 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
3296 1.1 rjs printf("--total out:%lu total_mbuf_out:%lu\n",
3297 1.1 rjs (u_long)asoc->total_output_queue_size,
3298 1.1 rjs (u_long)asoc->total_output_mbuf_queue_size);
3299 1.1 rjs }
3300 1.1 rjs #endif
3301 1.1 rjs /*
3302 1.1 rjs * Maybe there should be another notification
3303 1.1 rjs * type
3304 1.1 rjs */
3305 1.1 rjs sctp_ulp_notify(SCTP_NOTIFY_DG_FAIL, stcb,
3306 1.1 rjs (SCTP_RESPONSE_TO_USER_REQ|SCTP_NOTIFY_DATAGRAM_SENT),
3307 1.1 rjs tp1);
3308 1.1 rjs sctp_m_freem(tp1->data);
3309 1.1 rjs tp1->data = NULL;
3310 1.1 rjs sctp_sowwakeup(stcb->sctp_ep,
3311 1.1 rjs stcb->sctp_socket);
3312 1.1 rjs }
3313 1.1 rjs } else {
3314 1.1 rjs /* If it is still in RESEND we can advance no further */
3315 1.1 rjs break;
3316 1.1 rjs }
3317 1.1 rjs /*
3318 1.1 rjs * If we hit here we just dumped tp1, move to next
3319 1.1 rjs * tsn on sent queue.
3320 1.1 rjs */
3321 1.1 rjs tp1 = tp2;
3322 1.1 rjs }
3323 1.1 rjs return (a_adv);
3324 1.1 rjs }
3325 1.1 rjs
3326 1.1 rjs #ifdef SCTP_HIGH_SPEED
3327 1.1 rjs struct sctp_hs_raise_drop {
3328 1.1 rjs int32_t cwnd;
3329 1.1 rjs int32_t increase;
3330 1.1 rjs int32_t drop_percent;
3331 1.1 rjs };
3332 1.1 rjs
3333 1.1 rjs #define SCTP_HS_TABLE_SIZE 73
3334 1.1 rjs
3335 1.1 rjs struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
3336 1.1 rjs {38,1,50}, /* 0 */
3337 1.1 rjs {118,2,44}, /* 1 */
3338 1.1 rjs {221,3,41}, /* 2 */
3339 1.1 rjs {347,4,38}, /* 3 */
3340 1.1 rjs {495,5,37}, /* 4 */
3341 1.1 rjs {663,6,35}, /* 5 */
3342 1.1 rjs {851,7,34}, /* 6 */
3343 1.1 rjs {1058,8,33}, /* 7 */
3344 1.1 rjs {1284,9,32}, /* 8 */
3345 1.1 rjs {1529,10,31}, /* 9 */
3346 1.1 rjs {1793,11,30}, /* 10 */
3347 1.1 rjs {2076,12,29}, /* 11 */
3348 1.1 rjs {2378,13,28}, /* 12 */
3349 1.1 rjs {2699,14,28}, /* 13 */
3350 1.1 rjs {3039,15,27}, /* 14 */
3351 1.1 rjs {3399,16,27}, /* 15 */
3352 1.1 rjs {3778,17,26}, /* 16 */
3353 1.1 rjs {4177,18,26}, /* 17 */
3354 1.1 rjs {4596,19,25}, /* 18 */
3355 1.1 rjs {5036,20,25}, /* 19 */
3356 1.1 rjs {5497,21,24}, /* 20 */
3357 1.1 rjs {5979,22,24}, /* 21 */
3358 1.1 rjs {6483,23,23}, /* 22 */
3359 1.1 rjs {7009,24,23}, /* 23 */
3360 1.1 rjs {7558,25,22}, /* 24 */
3361 1.1 rjs {8130,26,22}, /* 25 */
3362 1.1 rjs {8726,27,22}, /* 26 */
3363 1.1 rjs {9346,28,21}, /* 27 */
3364 1.1 rjs {9991,29,21}, /* 28 */
3365 1.1 rjs {10661,30,21}, /* 29 */
3366 1.1 rjs {11358,31,20}, /* 30 */
3367 1.1 rjs {12082,32,20}, /* 31 */
3368 1.1 rjs {12834,33,20}, /* 32 */
3369 1.1 rjs {13614,34,19}, /* 33 */
3370 1.1 rjs {14424,35,19}, /* 34 */
3371 1.1 rjs {15265,36,19}, /* 35 */
3372 1.1 rjs {16137,37,19}, /* 36 */
3373 1.1 rjs {17042,38,18}, /* 37 */
3374 1.1 rjs {17981,39,18}, /* 38 */
3375 1.1 rjs {18955,40,18}, /* 39 */
3376 1.1 rjs {19965,41,17}, /* 40 */
3377 1.1 rjs {21013,42,17}, /* 41 */
3378 1.1 rjs {22101,43,17}, /* 42 */
3379 1.1 rjs {23230,44,17}, /* 43 */
3380 1.1 rjs {24402,45,16}, /* 44 */
3381 1.1 rjs {25618,46,16}, /* 45 */
3382 1.1 rjs {26881,47,16}, /* 46 */
3383 1.1 rjs {28193,48,16}, /* 47 */
3384 1.1 rjs {29557,49,15}, /* 48 */
3385 1.1 rjs {30975,50,15}, /* 49 */
3386 1.1 rjs {32450,51,15}, /* 50 */
3387 1.1 rjs {33986,52,15}, /* 51 */
3388 1.1 rjs {35586,53,14}, /* 52 */
3389 1.1 rjs {37253,54,14}, /* 53 */
3390 1.1 rjs {38992,55,14}, /* 54 */
3391 1.1 rjs {40808,56,14}, /* 55 */
3392 1.1 rjs {42707,57,13}, /* 56 */
3393 1.1 rjs {44694,58,13}, /* 57 */
3394 1.1 rjs {46776,59,13}, /* 58 */
3395 1.1 rjs {48961,60,13}, /* 59 */
3396 1.1 rjs {51258,61,13}, /* 60 */
3397 1.1 rjs {53677,62,12}, /* 61 */
3398 1.1 rjs {56230,63,12}, /* 62 */
3399 1.1 rjs {58932,64,12}, /* 63 */
3400 1.1 rjs {61799,65,12}, /* 64 */
3401 1.1 rjs {64851,66,11}, /* 65 */
3402 1.1 rjs {68113,67,11}, /* 66 */
3403 1.1 rjs {71617,68,11}, /* 67 */
3404 1.1 rjs {75401,69,10}, /* 68 */
3405 1.1 rjs {79517,70,10}, /* 69 */
3406 1.1 rjs {84035,71,10}, /* 70 */
3407 1.1 rjs {89053,72,10}, /* 71 */
3408 1.1 rjs {94717,73,9} /* 72 */
3409 1.1 rjs };
3410 1.1 rjs
3411 1.1 rjs static void
3412 1.1 rjs sctp_hs_cwnd_increase(struct sctp_nets *net)
3413 1.1 rjs {
3414 1.1 rjs int cur_val, i, indx, incr;
3415 1.1 rjs
3416 1.1 rjs cur_val = net->cwnd >> 10;
3417 1.1 rjs indx = SCTP_HS_TABLE_SIZE - 1;
3418 1.1 rjs
3419 1.1 rjs if (cur_val < sctp_cwnd_adjust[0].cwnd) {
3420 1.1 rjs /* normal mode */
3421 1.1 rjs if (net->net_ack > net->mtu) {
3422 1.1 rjs net->cwnd += net->mtu;
3423 1.1 rjs #ifdef SCTP_CWND_LOGGING
3424 1.1 rjs sctp_log_cwnd(net, net->mtu, SCTP_CWND_LOG_FROM_SS);
3425 1.1 rjs #endif
3426 1.1 rjs } else {
3427 1.1 rjs net->cwnd += net->net_ack;
3428 1.1 rjs #ifdef SCTP_CWND_LOGGING
3429 1.1 rjs sctp_log_cwnd(net, net->net_ack, SCTP_CWND_LOG_FROM_SS);
3430 1.1 rjs #endif
3431 1.1 rjs }
3432 1.1 rjs } else {
3433 1.1 rjs for (i=net->last_hs_used; i<SCTP_HS_TABLE_SIZE; i++) {
3434 1.1 rjs if (cur_val < sctp_cwnd_adjust[i].cwnd) {
3435 1.1 rjs indx = i;
3436 1.1 rjs break;
3437 1.1 rjs }
3438 1.1 rjs }
3439 1.1 rjs net->last_hs_used = indx;
3440 1.1 rjs incr = ((sctp_cwnd_adjust[indx].increase) << 10);
3441 1.1 rjs net->cwnd += incr;
3442 1.1 rjs #ifdef SCTP_CWND_LOGGING
3443 1.1 rjs sctp_log_cwnd(net, incr, SCTP_CWND_LOG_FROM_SS);
3444 1.1 rjs #endif
3445 1.1 rjs }
3446 1.1 rjs }
3447 1.1 rjs
3448 1.1 rjs static void
3449 1.1 rjs sctp_hs_cwnd_decrease(struct sctp_nets *net)
3450 1.1 rjs {
3451 1.1 rjs int cur_val, i, indx;
3452 1.1 rjs #ifdef SCTP_CWND_LOGGING
3453 1.1 rjs int old_cwnd = net->cwnd;
3454 1.1 rjs #endif
3455 1.1 rjs
3456 1.1 rjs cur_val = net->cwnd >> 10;
3457 1.1 rjs indx = net->last_hs_used;
3458 1.1 rjs if (cur_val < sctp_cwnd_adjust[0].cwnd) {
3459 1.1 rjs /* normal mode */
3460 1.1 rjs net->ssthresh = net->cwnd / 2;
3461 1.1 rjs if (net->ssthresh < (net->mtu*2)) {
3462 1.1 rjs net->ssthresh = 2 * net->mtu;
3463 1.1 rjs }
3464 1.1 rjs net->cwnd = net->ssthresh;
3465 1.1 rjs #ifdef SCTP_CWND_LOGGING
3466 1.1 rjs sctp_log_cwnd(net, (net->cwnd-old_cwnd), SCTP_CWND_LOG_FROM_FR);
3467 1.1 rjs #endif
3468 1.1 rjs } else {
3469 1.1 rjs /* drop by the proper amount */
3470 1.1 rjs net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
3471 1.1 rjs sctp_cwnd_adjust[net->last_hs_used].drop_percent);
3472 1.1 rjs net->cwnd = net->ssthresh;
3473 1.1 rjs /* now where are we */
3474 1.1 rjs indx = net->last_hs_used;
3475 1.1 rjs cur_val = net->cwnd >> 10;
3476 1.1 rjs /* reset where we are in the table */
3477 1.1 rjs if (cur_val < sctp_cwnd_adjust[0].cwnd) {
3478 1.1 rjs /* feel out of hs */
3479 1.1 rjs net->last_hs_used = 0;
3480 1.1 rjs } else {
3481 1.1 rjs for (i = indx; i >= 1; i--) {
3482 1.1 rjs if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
3483 1.1 rjs break;
3484 1.1 rjs }
3485 1.1 rjs }
3486 1.1 rjs net->last_hs_used = indx;
3487 1.1 rjs }
3488 1.1 rjs }
3489 1.1 rjs }
3490 1.1 rjs #endif
3491 1.1 rjs
3492 1.1 rjs void
3493 1.1 rjs sctp_handle_sack(struct sctp_sack_chunk *ch, struct sctp_tcb *stcb,
3494 1.1 rjs struct sctp_nets *net_from, int *abort_now)
3495 1.1 rjs {
3496 1.1 rjs struct sctp_association *asoc;
3497 1.1 rjs struct sctp_sack *sack;
3498 1.1 rjs struct sctp_tmit_chunk *tp1, *tp2;
3499 1.1 rjs u_long cum_ack, last_tsn, biggest_tsn_acked, biggest_tsn_newly_acked;
3500 1.1 rjs uint16_t num_seg;
3501 1.1 rjs unsigned int sack_length;
3502 1.1 rjs uint32_t send_s;
3503 1.1 rjs int some_on_streamwheel;
3504 1.1 rjs int strike_enabled = 0, cnt_of_cacc = 0;
3505 1.1 rjs int accum_moved = 0;
3506 1.1 rjs int marking_allowed = 1;
3507 1.1 rjs int will_exit_fast_recovery=0;
3508 1.1 rjs u_int32_t a_rwnd;
3509 1.1 rjs struct sctp_nets *net = NULL;
3510 1.1 rjs int nonce_sum_flag, ecn_seg_sums=0;
3511 1.1 rjs asoc = &stcb->asoc;
3512 1.1 rjs
3513 1.1 rjs /*
3514 1.1 rjs * Handle the incoming sack on data I have been sending.
3515 1.1 rjs */
3516 1.1 rjs
3517 1.1 rjs /*
3518 1.1 rjs * we take any chance we can to service our queues since we
3519 1.1 rjs * cannot get awoken when the socket is read from :<
3520 1.1 rjs */
3521 1.1 rjs asoc->overall_error_count = 0;
3522 1.1 rjs
3523 1.1 rjs if (asoc->sent_queue_retran_cnt) {
3524 1.1 rjs #ifdef SCTP_DEBUG
3525 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
3526 1.1 rjs printf("Handling SACK for asoc:%p retran:%d\n",
3527 1.1 rjs asoc, asoc->sent_queue_retran_cnt);
3528 1.1 rjs }
3529 1.1 rjs #endif
3530 1.1 rjs }
3531 1.1 rjs
3532 1.1 rjs sctp_service_queues(stcb, asoc, 0);
3533 1.1 rjs
3534 1.1 rjs /*
3535 1.1 rjs * Now perform the actual SACK handling:
3536 1.1 rjs * 1) Verify that it is not an old sack, if so discard.
3537 1.1 rjs * 2) If there is nothing left in the send queue (cum-ack is equal
3538 1.1 rjs * to last acked) then you have a duplicate too, update any rwnd
3539 1.1 rjs * change and verify no timers are running. then return.
3540 1.1 rjs * 3) Process any new consequtive data i.e. cum-ack moved
3541 1.1 rjs * process these first and note that it moved.
3542 1.1 rjs * 4) Process any sack blocks.
3543 1.1 rjs * 5) Drop any acked from the queue.
3544 1.1 rjs * 6) Check for any revoked blocks and mark.
3545 1.1 rjs * 7) Update the cwnd.
3546 1.1 rjs * 8) Nothing left, sync up flightsizes and things, stop all timers
3547 1.1 rjs * and also check for shutdown_pending state. If so then go ahead
3548 1.1 rjs * and send off the shutdown. If in shutdown recv, send off the
3549 1.1 rjs * shutdown-ack and start that timer, Ret.
3550 1.1 rjs * 9) Strike any non-acked things and do FR procedure if needed being
3551 1.1 rjs * sure to set the FR flag.
3552 1.1 rjs * 10) Do pr-sctp procedures.
3553 1.1 rjs * 11) Apply any FR penalties.
3554 1.1 rjs * 12) Assure we will SACK if in shutdown_recv state.
3555 1.1 rjs */
3556 1.1 rjs
3557 1.1 rjs sack_length = ntohs(ch->ch.chunk_length);
3558 1.1 rjs if (sack_length < sizeof(struct sctp_sack_chunk)) {
3559 1.1 rjs #ifdef SCTP_DEBUG
3560 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
3561 1.1 rjs printf("Bad size on sack chunk .. to small\n");
3562 1.1 rjs }
3563 1.1 rjs #endif
3564 1.1 rjs return;
3565 1.1 rjs }
3566 1.1 rjs /* ECN Nonce */
3567 1.1 rjs nonce_sum_flag = ch->ch.chunk_flags & SCTP_SACK_NONCE_SUM;
3568 1.1 rjs sack = &ch->sack;
3569 1.1 rjs cum_ack = last_tsn = ntohl(sack->cum_tsn_ack);
3570 1.1 rjs num_seg = ntohs(sack->num_gap_ack_blks);
3571 1.1 rjs
3572 1.1 rjs /* reality check */
3573 1.1 rjs if (TAILQ_EMPTY(&asoc->send_queue)) {
3574 1.1 rjs send_s = asoc->sending_seq;
3575 1.1 rjs } else {
3576 1.1 rjs tp1 = TAILQ_FIRST(&asoc->send_queue);
3577 1.1 rjs send_s = tp1->rec.data.TSN_seq;
3578 1.1 rjs }
3579 1.1 rjs
3580 1.1 rjs if (sctp_strict_sacks) {
3581 1.1 rjs if (cum_ack == send_s ||
3582 1.1 rjs compare_with_wrap(cum_ack, send_s, MAX_TSN)) {
3583 1.1 rjs struct mbuf *oper;
3584 1.1 rjs /*
3585 1.1 rjs * no way, we have not even sent this TSN out yet.
3586 1.1 rjs * Peer is hopelessly messed up with us.
3587 1.1 rjs */
3588 1.1 rjs hopeless_peer:
3589 1.1 rjs *abort_now = 1;
3590 1.1 rjs /* XXX */
3591 1.1 rjs MGET(oper, M_DONTWAIT, MT_DATA);
3592 1.1 rjs if (oper) {
3593 1.1 rjs struct sctp_paramhdr *ph;
3594 1.1 rjs u_int32_t *ippp;
3595 1.1 rjs
3596 1.1 rjs oper->m_len = sizeof(struct sctp_paramhdr) +
3597 1.1 rjs sizeof(*ippp);
3598 1.1 rjs ph = mtod(oper, struct sctp_paramhdr *);
3599 1.1 rjs ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
3600 1.1 rjs ph->param_length = htons(oper->m_len);
3601 1.1 rjs ippp = (u_int32_t *)(ph + 1);
3602 1.1 rjs *ippp = htonl(0x30000002);
3603 1.1 rjs }
3604 1.1 rjs sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper);
3605 1.1 rjs return;
3606 1.1 rjs }
3607 1.1 rjs }
3608 1.1 rjs /* update the Rwnd of the peer */
3609 1.1 rjs a_rwnd = (u_int32_t)ntohl(sack->a_rwnd);
3610 1.1 rjs if (asoc->sent_queue_retran_cnt) {
3611 1.1 rjs #ifdef SCTP_DEBUG
3612 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
3613 1.1 rjs printf("cum_ack:%lx num_seg:%u last_acked_seq:%x\n",
3614 1.1 rjs cum_ack, (u_int)num_seg, asoc->last_acked_seq);
3615 1.1 rjs }
3616 1.1 rjs #endif
3617 1.1 rjs }
3618 1.1 rjs if (compare_with_wrap(asoc->t3timeout_highest_marked, cum_ack, MAX_TSN)) {
3619 1.1 rjs /* we are not allowed to mark for FR */
3620 1.1 rjs marking_allowed = 0;
3621 1.1 rjs }
3622 1.1 rjs /**********************/
3623 1.1 rjs /* 1) check the range */
3624 1.1 rjs /**********************/
3625 1.1 rjs if (compare_with_wrap(asoc->last_acked_seq, last_tsn, MAX_TSN)) {
3626 1.1 rjs /* acking something behind */
3627 1.1 rjs if (asoc->sent_queue_retran_cnt) {
3628 1.1 rjs #ifdef SCTP_DEBUG
3629 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
3630 1.1 rjs printf("The cum-ack is behind us\n");
3631 1.1 rjs }
3632 1.1 rjs #endif
3633 1.1 rjs }
3634 1.1 rjs return;
3635 1.1 rjs }
3636 1.1 rjs
3637 1.1 rjs if (TAILQ_EMPTY(&asoc->sent_queue)) {
3638 1.1 rjs /* nothing left on sendqueue.. consider done */
3639 1.1 rjs #ifdef SCTP_LOG_RWND
3640 1.1 rjs sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK,
3641 1.1 rjs asoc->peers_rwnd, 0, 0, a_rwnd);
3642 1.1 rjs #endif
3643 1.1 rjs asoc->peers_rwnd = a_rwnd;
3644 1.1 rjs if (asoc->sent_queue_retran_cnt) {
3645 1.1 rjs #ifdef SCTP_DEBUG
3646 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
3647 1.1 rjs printf("Huh? retran set but none on queue\n");
3648 1.1 rjs }
3649 1.1 rjs #endif
3650 1.1 rjs asoc->sent_queue_retran_cnt = 0;
3651 1.1 rjs }
3652 1.1 rjs if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
3653 1.1 rjs /* SWS sender side engages */
3654 1.1 rjs asoc->peers_rwnd = 0;
3655 1.1 rjs }
3656 1.1 rjs /* stop any timers */
3657 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
3658 1.1 rjs sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
3659 1.1 rjs stcb, net);
3660 1.1 rjs net->partial_bytes_acked = 0;
3661 1.1 rjs net->flight_size = 0;
3662 1.1 rjs }
3663 1.1 rjs asoc->total_flight = 0;
3664 1.1 rjs asoc->total_flight_count = 0;
3665 1.1 rjs return;
3666 1.1 rjs }
3667 1.1 rjs /*
3668 1.1 rjs * We init netAckSz and netAckSz2 to 0. These are used to track 2
3669 1.1 rjs * things. The total byte count acked is tracked in netAckSz AND
3670 1.1 rjs * netAck2 is used to track the total bytes acked that are un-
3671 1.1 rjs * amibguious and were never retransmitted. We track these on a
3672 1.1 rjs * per destination address basis.
3673 1.1 rjs */
3674 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
3675 1.1 rjs net->prev_cwnd = net->cwnd;
3676 1.1 rjs net->net_ack = 0;
3677 1.1 rjs net->net_ack2 = 0;
3678 1.1 rjs }
3679 1.1 rjs /* process the new consecutive TSN first */
3680 1.1 rjs tp1 = TAILQ_FIRST(&asoc->sent_queue);
3681 1.1 rjs while (tp1) {
3682 1.1 rjs if (compare_with_wrap(last_tsn, tp1->rec.data.TSN_seq,
3683 1.1 rjs MAX_TSN) ||
3684 1.1 rjs last_tsn == tp1->rec.data.TSN_seq) {
3685 1.1 rjs if (tp1->sent != SCTP_DATAGRAM_UNSENT) {
3686 1.1 rjs /* ECN Nonce: Add the nonce to the sender's nonce sum */
3687 1.1 rjs asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce;
3688 1.1 rjs accum_moved = 1;
3689 1.1 rjs if (tp1->sent < SCTP_DATAGRAM_ACKED) {
3690 1.1 rjs /*
3691 1.1 rjs * If it is less than ACKED, it is now
3692 1.1 rjs * no-longer in flight. Higher values
3693 1.1 rjs * may occur during marking
3694 1.1 rjs */
3695 1.1 rjs if ((tp1->whoTo->dest_state &
3696 1.1 rjs SCTP_ADDR_UNCONFIRMED) &&
3697 1.1 rjs (tp1->snd_count < 2) ) {
3698 1.1 rjs /*
3699 1.1 rjs * If there was no retran and
3700 1.1 rjs * the address is un-confirmed
3701 1.1 rjs * and we sent there and are
3702 1.1 rjs * now sacked.. its confirmed,
3703 1.1 rjs * mark it so.
3704 1.1 rjs */
3705 1.1 rjs tp1->whoTo->dest_state &=
3706 1.1 rjs ~SCTP_ADDR_UNCONFIRMED;
3707 1.1 rjs }
3708 1.1 rjs sctp_flight_size_decrease(tp1);
3709 1.1 rjs sctp_total_flight_decrease(stcb, tp1);
3710 1.1 rjs tp1->whoTo->net_ack += tp1->send_size;
3711 1.1 rjs if (tp1->snd_count < 2) {
3712 1.1 rjs /* True non-retransmited chunk */
3713 1.1 rjs tp1->whoTo->net_ack2 +=
3714 1.1 rjs tp1->send_size;
3715 1.1 rjs /* update RTO too? */
3716 1.1 rjs if (tp1->do_rtt) {
3717 1.1 rjs tp1->whoTo->RTO =
3718 1.1 rjs sctp_calculate_rto(stcb,
3719 1.1 rjs asoc, tp1->whoTo,
3720 1.1 rjs &tp1->sent_rcv_time);
3721 1.1 rjs tp1->whoTo->rto_pending = 0;
3722 1.1 rjs tp1->do_rtt = 0;
3723 1.1 rjs }
3724 1.1 rjs }
3725 1.1 rjs }
3726 1.1 rjs if (tp1->sent == SCTP_DATAGRAM_RESEND) {
3727 1.1 rjs #ifdef SCTP_DEBUG
3728 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA3) {
3729 1.1 rjs printf("Hmm. one that is in RESEND that is now ACKED\n");
3730 1.1 rjs }
3731 1.1 rjs #endif
3732 1.1 rjs sctp_ucount_decr(asoc->sent_queue_retran_cnt);
3733 1.1 rjs #ifdef SCTP_AUDITING_ENABLED
3734 1.1 rjs sctp_audit_log(0xB3,
3735 1.1 rjs (asoc->sent_queue_retran_cnt & 0x000000ff));
3736 1.1 rjs #endif
3737 1.1 rjs
3738 1.1 rjs }
3739 1.1 rjs tp1->sent = SCTP_DATAGRAM_ACKED;
3740 1.1 rjs }
3741 1.1 rjs } else {
3742 1.1 rjs break;
3743 1.1 rjs }
3744 1.1 rjs tp1 = TAILQ_NEXT(tp1, sctp_next);
3745 1.1 rjs }
3746 1.1 rjs /*******************************************/
3747 1.1 rjs /* cancel ALL T3-send timer if accum moved */
3748 1.1 rjs /*******************************************/
3749 1.1 rjs if (accum_moved) {
3750 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
3751 1.1 rjs sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
3752 1.1 rjs stcb, net);
3753 1.1 rjs }
3754 1.1 rjs }
3755 1.1 rjs biggest_tsn_newly_acked = biggest_tsn_acked = last_tsn;
3756 1.1 rjs /* always set this up to cum-ack */
3757 1.1 rjs asoc->this_sack_highest_gap = last_tsn;
3758 1.1 rjs
3759 1.1 rjs if (((num_seg * sizeof (sizeof(struct sctp_gap_ack_block))) + sizeof(struct sctp_sack_chunk)) > sack_length) {
3760 1.1 rjs /* skip corrupt segments */
3761 1.1 rjs strike_enabled = 0;
3762 1.1 rjs goto skip_segments;
3763 1.1 rjs }
3764 1.1 rjs
3765 1.1 rjs if (num_seg > 0) {
3766 1.1 rjs if (asoc->primary_destination->dest_state &
3767 1.1 rjs SCTP_ADDR_SWITCH_PRIMARY) {
3768 1.1 rjs /* clear the nets CACC flags */
3769 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
3770 1.1 rjs net->cacc_saw_newack = 0;
3771 1.1 rjs }
3772 1.1 rjs }
3773 1.1 rjs /*
3774 1.1 rjs * thisSackHighestGap will increase while handling NEW segments
3775 1.1 rjs */
3776 1.1 rjs
3777 1.1 rjs sctp_handle_segments(stcb, asoc, ch, last_tsn,
3778 1.1 rjs &biggest_tsn_acked, &biggest_tsn_newly_acked,
3779 1.1 rjs num_seg, &ecn_seg_sums);
3780 1.1 rjs
3781 1.1 rjs if (sctp_strict_sacks) {
3782 1.1 rjs /* validate the biggest_tsn_acked in the gap acks
3783 1.1 rjs * if strict adherence is wanted.
3784 1.1 rjs */
3785 1.1 rjs if ((biggest_tsn_acked == send_s) ||
3786 1.1 rjs (compare_with_wrap(biggest_tsn_acked, send_s, MAX_TSN))) {
3787 1.1 rjs /*
3788 1.1 rjs * peer is either confused or we are under
3789 1.1 rjs * attack. We must abort.
3790 1.1 rjs */
3791 1.1 rjs goto hopeless_peer;
3792 1.1 rjs }
3793 1.1 rjs }
3794 1.1 rjs
3795 1.1 rjs if (asoc->primary_destination->dest_state &
3796 1.1 rjs SCTP_ADDR_SWITCH_PRIMARY) {
3797 1.1 rjs /* clear the nets CACC flags */
3798 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
3799 1.1 rjs if (net->cacc_saw_newack) {
3800 1.1 rjs cnt_of_cacc++;
3801 1.1 rjs }
3802 1.1 rjs }
3803 1.1 rjs }
3804 1.1 rjs
3805 1.1 rjs }
3806 1.1 rjs
3807 1.1 rjs if (cnt_of_cacc < 2) {
3808 1.1 rjs strike_enabled = 1;
3809 1.1 rjs } else {
3810 1.1 rjs strike_enabled = 0;
3811 1.1 rjs }
3812 1.1 rjs skip_segments:
3813 1.1 rjs /********************************************/
3814 1.1 rjs /* drop the acked chunks from the sendqueue */
3815 1.1 rjs /********************************************/
3816 1.1 rjs asoc->last_acked_seq = cum_ack;
3817 1.1 rjs if (asoc->primary_destination->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
3818 1.1 rjs if ((cum_ack == asoc->primary_destination->next_tsn_at_change) ||
3819 1.1 rjs (compare_with_wrap(cum_ack,
3820 1.1 rjs asoc->primary_destination->next_tsn_at_change, MAX_TSN))) {
3821 1.1 rjs struct sctp_nets *lnet;
3822 1.1 rjs /* Turn off the switch flag for ALL addresses */
3823 1.1 rjs TAILQ_FOREACH(lnet, &asoc->nets, sctp_next) {
3824 1.1 rjs asoc->primary_destination->dest_state &=
3825 1.1 rjs ~(SCTP_ADDR_SWITCH_PRIMARY|SCTP_ADDR_DOUBLE_SWITCH);
3826 1.1 rjs }
3827 1.1 rjs }
3828 1.1 rjs }
3829 1.1 rjs /* Drag along the t3 timeout point so we don't have a problem at wrap */
3830 1.1 rjs if (marking_allowed) {
3831 1.1 rjs asoc->t3timeout_highest_marked = cum_ack;
3832 1.1 rjs }
3833 1.1 rjs tp1 = TAILQ_FIRST(&asoc->sent_queue);
3834 1.1 rjs do {
3835 1.1 rjs if (compare_with_wrap(tp1->rec.data.TSN_seq, cum_ack,
3836 1.1 rjs MAX_TSN)) {
3837 1.1 rjs break;
3838 1.1 rjs }
3839 1.1 rjs if (tp1->sent == SCTP_DATAGRAM_UNSENT) {
3840 1.1 rjs /* no more sent on list */
3841 1.1 rjs break;
3842 1.1 rjs }
3843 1.1 rjs tp2 = TAILQ_NEXT(tp1, sctp_next);
3844 1.1 rjs TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next);
3845 1.1 rjs if (tp1->data) {
3846 1.1 rjs sctp_free_bufspace(stcb, asoc, tp1);
3847 1.1 rjs #ifdef SCTP_DEBUG
3848 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
3849 1.1 rjs printf("--total out:%lu total_mbuf_out:%lu\n",
3850 1.1 rjs (u_long)asoc->total_output_queue_size,
3851 1.1 rjs (u_long)asoc->total_output_mbuf_queue_size);
3852 1.1 rjs }
3853 1.1 rjs #endif
3854 1.1 rjs
3855 1.1 rjs sctp_m_freem(tp1->data);
3856 1.1 rjs if (tp1->flags & SCTP_PR_SCTP_BUFFER) {
3857 1.1 rjs asoc->sent_queue_cnt_removeable--;
3858 1.1 rjs }
3859 1.1 rjs
3860 1.1 rjs }
3861 1.1 rjs tp1->data = NULL;
3862 1.1 rjs asoc->sent_queue_cnt--;
3863 1.1 rjs sctp_free_remote_addr(tp1->whoTo);
3864 1.1 rjs sctppcbinfo.ipi_count_chunk--;
3865 1.1 rjs asoc->chunks_on_out_queue--;
3866 1.1 rjs
3867 1.1 rjs if ((int)sctppcbinfo.ipi_count_chunk < 0) {
3868 1.1 rjs panic("Chunk count is going negative");
3869 1.1 rjs }
3870 1.1 rjs SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, tp1);
3871 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
3872 1.1 rjs sctp_sowwakeup(stcb->sctp_ep, stcb->sctp_socket);
3873 1.1 rjs tp1 = tp2;
3874 1.1 rjs } while (tp1 != NULL);
3875 1.1 rjs
3876 1.1 rjs
3877 1.1 rjs if (asoc->fast_retran_loss_recovery && accum_moved) {
3878 1.1 rjs if (compare_with_wrap(asoc->last_acked_seq,
3879 1.1 rjs asoc->fast_recovery_tsn, MAX_TSN) ||
3880 1.1 rjs asoc->last_acked_seq == asoc->fast_recovery_tsn) {
3881 1.1 rjs /* Setup so we will exit RFC2582 fast recovery */
3882 1.1 rjs will_exit_fast_recovery = 1;
3883 1.1 rjs }
3884 1.1 rjs }
3885 1.1 rjs
3886 1.1 rjs /* Check for revoked fragments if we hand
3887 1.1 rjs * fragments in a previous segment. If we
3888 1.1 rjs * had no previous fragments we cannot have
3889 1.1 rjs * a revoke issue.
3890 1.1 rjs */
3891 1.1 rjs if (asoc->saw_sack_with_frags)
3892 1.1 rjs sctp_check_for_revoked(asoc, cum_ack, biggest_tsn_acked);
3893 1.1 rjs
3894 1.1 rjs if (num_seg)
3895 1.1 rjs asoc->saw_sack_with_frags = 1;
3896 1.1 rjs else
3897 1.1 rjs asoc->saw_sack_with_frags = 0;
3898 1.1 rjs
3899 1.1 rjs /******************************/
3900 1.1 rjs /* update cwnd */
3901 1.1 rjs /******************************/
3902 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
3903 1.1 rjs /* if nothing was acked on this destination skip it */
3904 1.1 rjs if (net->net_ack == 0)
3905 1.1 rjs continue;
3906 1.1 rjs
3907 1.1 rjs if (net->net_ack2 > 0) {
3908 1.1 rjs /*
3909 1.1 rjs * Karn's rule applies to clearing error count,
3910 1.1 rjs * this is optional.
3911 1.1 rjs */
3912 1.1 rjs net->error_count = 0;
3913 1.1 rjs if ((net->dest_state&SCTP_ADDR_NOT_REACHABLE) ==
3914 1.1 rjs SCTP_ADDR_NOT_REACHABLE) {
3915 1.1 rjs /* addr came good */
3916 1.1 rjs net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
3917 1.1 rjs net->dest_state |= SCTP_ADDR_REACHABLE;
3918 1.1 rjs sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
3919 1.1 rjs SCTP_RECEIVED_SACK, (void *)net);
3920 1.1 rjs /* now was it the primary? if so restore */
3921 1.1 rjs if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
3922 1.1 rjs sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
3923 1.1 rjs }
3924 1.1 rjs }
3925 1.1 rjs }
3926 1.1 rjs
3927 1.1 rjs if (asoc->fast_retran_loss_recovery &&
3928 1.1 rjs will_exit_fast_recovery == 0) {
3929 1.1 rjs /* If we are in loss recovery we skip any cwnd update */
3930 1.1 rjs sctp_pegs[SCTP_CWND_SKIP]++;
3931 1.1 rjs goto skip_cwnd_update;
3932 1.1 rjs }
3933 1.1 rjs if (accum_moved) {
3934 1.1 rjs /* If the cumulative ack moved we can proceed */
3935 1.1 rjs if (net->cwnd <= net->ssthresh) {
3936 1.1 rjs /* We are in slow start */
3937 1.1 rjs if (net->flight_size + net->net_ack >=
3938 1.1 rjs net->cwnd ) {
3939 1.1 rjs #ifdef SCTP_HIGH_SPEED
3940 1.1 rjs sctp_hs_cwnd_increase(net);
3941 1.1 rjs #else
3942 1.1 rjs if (net->net_ack > net->mtu) {
3943 1.1 rjs net->cwnd += net->mtu;
3944 1.1 rjs #ifdef SCTP_CWND_LOGGING
3945 1.1 rjs sctp_log_cwnd(net, net->mtu,
3946 1.1 rjs SCTP_CWND_LOG_FROM_SS);
3947 1.1 rjs #endif
3948 1.1 rjs
3949 1.1 rjs } else {
3950 1.1 rjs net->cwnd += net->net_ack;
3951 1.1 rjs #ifdef SCTP_CWND_LOGGING
3952 1.1 rjs sctp_log_cwnd(net, net->net_ack,
3953 1.1 rjs SCTP_CWND_LOG_FROM_SS);
3954 1.1 rjs #endif
3955 1.1 rjs
3956 1.1 rjs }
3957 1.1 rjs #endif
3958 1.1 rjs sctp_pegs[SCTP_CWND_SS]++;
3959 1.1 rjs } else {
3960 1.1 rjs unsigned int dif;
3961 1.1 rjs sctp_pegs[SCTP_CWND_NOUSE_SS]++;
3962 1.1 rjs dif = net->cwnd - (net->flight_size +
3963 1.1 rjs net->net_ack);
3964 1.1 rjs #ifdef SCTP_CWND_LOGGING
3965 1.1 rjs /* sctp_log_cwnd(net, net->net_ack,
3966 1.1 rjs SCTP_CWND_LOG_NOADV_SS);*/
3967 1.1 rjs #endif
3968 1.1 rjs if (dif > sctp_pegs[SCTP_CWND_DIFF_SA]) {
3969 1.1 rjs sctp_pegs[SCTP_CWND_DIFF_SA] =
3970 1.1 rjs dif;
3971 1.1 rjs sctp_pegs[SCTP_OQS_AT_SS] =
3972 1.1 rjs asoc->total_output_queue_size;
3973 1.1 rjs sctp_pegs[SCTP_SQQ_AT_SS] =
3974 1.1 rjs asoc->sent_queue_cnt;
3975 1.1 rjs sctp_pegs[SCTP_SQC_AT_SS] =
3976 1.1 rjs asoc->send_queue_cnt;
3977 1.1 rjs }
3978 1.1 rjs }
3979 1.1 rjs } else {
3980 1.1 rjs /* We are in congestion avoidance */
3981 1.1 rjs if (net->flight_size + net->net_ack >=
3982 1.1 rjs net->cwnd) {
3983 1.1 rjs /*
3984 1.1 rjs * add to pba only if we had a cwnd's
3985 1.1 rjs * worth (or so) in flight OR the
3986 1.1 rjs * burst limit was applied.
3987 1.1 rjs */
3988 1.1 rjs net->partial_bytes_acked +=
3989 1.1 rjs net->net_ack;
3990 1.1 rjs
3991 1.1 rjs /*
3992 1.1 rjs * Do we need to increase
3993 1.1 rjs * (if pba is > cwnd)?
3994 1.1 rjs */
3995 1.1 rjs if (net->partial_bytes_acked >=
3996 1.1 rjs net->cwnd) {
3997 1.1 rjs if (net->cwnd <
3998 1.1 rjs net->partial_bytes_acked) {
3999 1.1 rjs net->partial_bytes_acked -=
4000 1.1 rjs net->cwnd;
4001 1.1 rjs } else {
4002 1.1 rjs net->partial_bytes_acked =
4003 1.1 rjs 0;
4004 1.1 rjs }
4005 1.1 rjs net->cwnd += net->mtu;
4006 1.1 rjs #ifdef SCTP_CWND_LOGGING
4007 1.1 rjs sctp_log_cwnd(net, net->mtu,
4008 1.1 rjs SCTP_CWND_LOG_FROM_CA);
4009 1.1 rjs #endif
4010 1.1 rjs sctp_pegs[SCTP_CWND_CA]++;
4011 1.1 rjs }
4012 1.1 rjs } else {
4013 1.1 rjs unsigned int dif;
4014 1.1 rjs sctp_pegs[SCTP_CWND_NOUSE_CA]++;
4015 1.1 rjs #ifdef SCTP_CWND_LOGGING
4016 1.1 rjs /* sctp_log_cwnd(net, net->net_ack,
4017 1.1 rjs SCTP_CWND_LOG_NOADV_CA);
4018 1.1 rjs */
4019 1.1 rjs #endif
4020 1.1 rjs dif = net->cwnd - (net->flight_size +
4021 1.1 rjs net->net_ack);
4022 1.1 rjs if (dif > sctp_pegs[SCTP_CWND_DIFF_CA]) {
4023 1.1 rjs sctp_pegs[SCTP_CWND_DIFF_CA] =
4024 1.1 rjs dif;
4025 1.1 rjs sctp_pegs[SCTP_OQS_AT_CA] =
4026 1.1 rjs asoc->total_output_queue_size;
4027 1.1 rjs sctp_pegs[SCTP_SQQ_AT_CA] =
4028 1.1 rjs asoc->sent_queue_cnt;
4029 1.1 rjs sctp_pegs[SCTP_SQC_AT_CA] =
4030 1.1 rjs asoc->send_queue_cnt;
4031 1.1 rjs
4032 1.1 rjs }
4033 1.1 rjs
4034 1.1 rjs }
4035 1.1 rjs }
4036 1.1 rjs } else {
4037 1.1 rjs sctp_pegs[SCTP_CWND_NOCUM]++;
4038 1.1 rjs }
4039 1.1 rjs skip_cwnd_update:
4040 1.1 rjs /*
4041 1.1 rjs * NOW, according to Karn's rule do we need to restore the
4042 1.1 rjs * RTO timer back? Check our net_ack2. If not set then we
4043 1.1 rjs * have a ambiguity.. i.e. all data ack'd was sent to more
4044 1.1 rjs * than one place.
4045 1.1 rjs */
4046 1.1 rjs
4047 1.1 rjs if (net->net_ack2) {
4048 1.1 rjs /* restore any doubled timers */
4049 1.1 rjs net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
4050 1.1 rjs if (net->RTO < stcb->asoc.minrto) {
4051 1.1 rjs net->RTO = stcb->asoc.minrto;
4052 1.1 rjs }
4053 1.1 rjs if (net->RTO > stcb->asoc.maxrto) {
4054 1.1 rjs net->RTO = stcb->asoc.maxrto;
4055 1.1 rjs }
4056 1.1 rjs }
4057 1.1 rjs if (net->cwnd > sctp_pegs[SCTP_MAX_CWND]) {
4058 1.1 rjs sctp_pegs[SCTP_MAX_CWND] = net->cwnd;
4059 1.1 rjs }
4060 1.1 rjs }
4061 1.1 rjs /**********************************/
4062 1.1 rjs /* Now what about shutdown issues */
4063 1.1 rjs /**********************************/
4064 1.1 rjs some_on_streamwheel = 0;
4065 1.1 rjs if (!TAILQ_EMPTY(&asoc->out_wheel)) {
4066 1.1 rjs /* Check to see if some data queued */
4067 1.1 rjs struct sctp_stream_out *outs;
4068 1.1 rjs TAILQ_FOREACH(outs, &asoc->out_wheel, next_spoke) {
4069 1.1 rjs if (!TAILQ_EMPTY(&outs->outqueue)) {
4070 1.1 rjs some_on_streamwheel = 1;
4071 1.1 rjs break;
4072 1.1 rjs }
4073 1.1 rjs }
4074 1.1 rjs }
4075 1.1 rjs if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue) &&
4076 1.1 rjs some_on_streamwheel == 0) {
4077 1.1 rjs /* nothing left on sendqueue.. consider done */
4078 1.1 rjs /* stop all timers */
4079 1.1 rjs #ifdef SCTP_LOG_RWND
4080 1.1 rjs sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK,
4081 1.1 rjs asoc->peers_rwnd, 0, 0, a_rwnd);
4082 1.1 rjs #endif
4083 1.1 rjs asoc->peers_rwnd = a_rwnd;
4084 1.1 rjs if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
4085 1.1 rjs /* SWS sender side engages */
4086 1.1 rjs asoc->peers_rwnd = 0;
4087 1.1 rjs }
4088 1.1 rjs /* stop any timers */
4089 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4090 1.1 rjs sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
4091 1.1 rjs stcb, net);
4092 1.1 rjs net->flight_size = 0;
4093 1.1 rjs net->partial_bytes_acked = 0;
4094 1.1 rjs }
4095 1.1 rjs asoc->total_flight = 0;
4096 1.1 rjs asoc->total_flight_count = 0;
4097 1.1 rjs /* clean up */
4098 1.1 rjs if (asoc->state & SCTP_STATE_SHUTDOWN_PENDING) {
4099 1.1 rjs asoc->state = SCTP_STATE_SHUTDOWN_SENT;
4100 1.1 rjs #ifdef SCTP_DEBUG
4101 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
4102 1.1 rjs printf("%s:%d sends a shutdown\n",
4103 1.1 rjs __FILE__,
4104 1.1 rjs __LINE__
4105 1.1 rjs );
4106 1.1 rjs }
4107 1.1 rjs #endif
4108 1.1 rjs sctp_send_shutdown(stcb,
4109 1.1 rjs stcb->asoc.primary_destination);
4110 1.1 rjs sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
4111 1.1 rjs stcb->sctp_ep, stcb, asoc->primary_destination);
4112 1.1 rjs sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
4113 1.1 rjs stcb->sctp_ep, stcb, asoc->primary_destination);
4114 1.1 rjs } else if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) {
4115 1.1 rjs asoc->state = SCTP_STATE_SHUTDOWN_ACK_SENT;
4116 1.1 rjs
4117 1.1 rjs sctp_send_shutdown_ack(stcb,
4118 1.1 rjs stcb->asoc.primary_destination);
4119 1.1 rjs
4120 1.1 rjs sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK,
4121 1.1 rjs stcb->sctp_ep, stcb, asoc->primary_destination);
4122 1.1 rjs }
4123 1.1 rjs return;
4124 1.1 rjs }
4125 1.1 rjs /*
4126 1.1 rjs * Now here we are going to recycle net_ack for a different
4127 1.1 rjs * use... HEADS UP.
4128 1.1 rjs */
4129 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4130 1.1 rjs net->net_ack = 0;
4131 1.1 rjs }
4132 1.1 rjs if ((num_seg > 0) && marking_allowed) {
4133 1.1 rjs sctp_strike_gap_ack_chunks(stcb, asoc, biggest_tsn_acked,
4134 1.1 rjs strike_enabled, biggest_tsn_newly_acked, accum_moved);
4135 1.1 rjs }
4136 1.1 rjs
4137 1.1 rjs /*********************************************/
4138 1.1 rjs /* Here we perform PR-SCTP procedures */
4139 1.1 rjs /* (section 4.2) */
4140 1.1 rjs /*********************************************/
4141 1.1 rjs /* C1. update advancedPeerAckPoint */
4142 1.1 rjs if (compare_with_wrap(cum_ack, asoc->advanced_peer_ack_point, MAX_TSN)) {
4143 1.1 rjs asoc->advanced_peer_ack_point = cum_ack;
4144 1.1 rjs }
4145 1.1 rjs /* C2. try to further move advancedPeerAckPoint ahead */
4146 1.1 rjs if (asoc->peer_supports_prsctp) {
4147 1.1 rjs struct sctp_tmit_chunk *lchk;
4148 1.1 rjs lchk = sctp_try_advance_peer_ack_point(stcb, asoc);
4149 1.1 rjs /* C3. See if we need to send a Fwd-TSN */
4150 1.1 rjs if (compare_with_wrap(asoc->advanced_peer_ack_point, cum_ack,
4151 1.1 rjs MAX_TSN)) {
4152 1.1 rjs /*
4153 1.1 rjs * ISSUE with ECN, see FWD-TSN processing for notes
4154 1.1 rjs * on issues that will occur when the ECN NONCE stuff
4155 1.1 rjs * is put into SCTP for cross checking.
4156 1.1 rjs */
4157 1.1 rjs send_forward_tsn(stcb, asoc);
4158 1.1 rjs
4159 1.1 rjs /* ECN Nonce: Disable Nonce Sum check when FWD TSN is sent and store resync tsn*/
4160 1.1 rjs asoc->nonce_sum_check = 0;
4161 1.1 rjs asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point;
4162 1.1 rjs if (lchk) {
4163 1.1 rjs /* Assure a timer is up */
4164 1.1 rjs sctp_timer_start(SCTP_TIMER_TYPE_SEND,
4165 1.1 rjs stcb->sctp_ep, stcb, lchk->whoTo);
4166 1.1 rjs }
4167 1.1 rjs }
4168 1.1 rjs }
4169 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4170 1.1 rjs if (asoc->fast_retran_loss_recovery == 0) {
4171 1.1 rjs /* out of a RFC2582 Fast recovery window? */
4172 1.1 rjs if (net->net_ack > 0) {
4173 1.1 rjs /*
4174 1.1 rjs * per section 7.2.3, are there
4175 1.1 rjs * any destinations that had a fast
4176 1.1 rjs * retransmit to them. If so what we
4177 1.1 rjs * need to do is adjust ssthresh and
4178 1.1 rjs * cwnd.
4179 1.1 rjs */
4180 1.1 rjs struct sctp_tmit_chunk *lchk;
4181 1.1 rjs #ifdef SCTP_HIGH_SPEED
4182 1.1 rjs sctp_hs_cwnd_decrease(net);
4183 1.1 rjs #else
4184 1.1 rjs #ifdef SCTP_CWND_LOGGING
4185 1.1 rjs int old_cwnd = net->cwnd;
4186 1.1 rjs #endif
4187 1.1 rjs net->ssthresh = net->cwnd / 2;
4188 1.1 rjs if (net->ssthresh < (net->mtu*2)) {
4189 1.1 rjs net->ssthresh = 2 * net->mtu;
4190 1.1 rjs }
4191 1.1 rjs net->cwnd = net->ssthresh;
4192 1.1 rjs #ifdef SCTP_CWND_LOGGING
4193 1.1 rjs sctp_log_cwnd(net, (net->cwnd-old_cwnd),
4194 1.1 rjs SCTP_CWND_LOG_FROM_FR);
4195 1.1 rjs #endif
4196 1.1 rjs #endif
4197 1.1 rjs
4198 1.1 rjs lchk = TAILQ_FIRST(&asoc->send_queue);
4199 1.1 rjs
4200 1.1 rjs net->partial_bytes_acked = 0;
4201 1.1 rjs /* Turn on fast recovery window */
4202 1.1 rjs asoc->fast_retran_loss_recovery = 1;
4203 1.1 rjs if (lchk == NULL) {
4204 1.1 rjs /* Mark end of the window */
4205 1.1 rjs asoc->fast_recovery_tsn = asoc->sending_seq - 1;
4206 1.1 rjs } else {
4207 1.1 rjs asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
4208 1.1 rjs }
4209 1.1 rjs
4210 1.1 rjs
4211 1.1 rjs /* Disable Nonce Sum Checking and store the resync tsn*/
4212 1.1 rjs asoc->nonce_sum_check = 0;
4213 1.1 rjs asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
4214 1.1 rjs
4215 1.1 rjs sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
4216 1.1 rjs stcb->sctp_ep, stcb, net);
4217 1.1 rjs sctp_timer_start(SCTP_TIMER_TYPE_SEND,
4218 1.1 rjs stcb->sctp_ep, stcb, net);
4219 1.1 rjs }
4220 1.1 rjs } else if (net->net_ack > 0) {
4221 1.1 rjs /*
4222 1.1 rjs * Mark a peg that we WOULD have done a cwnd reduction
4223 1.1 rjs * but RFC2582 prevented this action.
4224 1.1 rjs */
4225 1.1 rjs sctp_pegs[SCTP_FR_INAWINDOW]++;
4226 1.1 rjs }
4227 1.1 rjs }
4228 1.1 rjs
4229 1.1 rjs
4230 1.1 rjs /******************************************************************
4231 1.1 rjs * Here we do the stuff with ECN Nonce checking.
4232 1.1 rjs * We basically check to see if the nonce sum flag was incorrect
4233 1.1 rjs * or if resynchronization needs to be done. Also if we catch a
4234 1.1 rjs * misbehaving receiver we give him the kick.
4235 1.1 rjs ******************************************************************/
4236 1.1 rjs
4237 1.1 rjs if (asoc->ecn_nonce_allowed) {
4238 1.1 rjs if (asoc->nonce_sum_check) {
4239 1.1 rjs if (nonce_sum_flag != ((asoc->nonce_sum_expect_base + ecn_seg_sums) & SCTP_SACK_NONCE_SUM)) {
4240 1.1 rjs if (asoc->nonce_wait_for_ecne == 0) {
4241 1.1 rjs struct sctp_tmit_chunk *lchk;
4242 1.1 rjs lchk = TAILQ_FIRST(&asoc->send_queue);
4243 1.1 rjs asoc->nonce_wait_for_ecne = 1;
4244 1.1 rjs if (lchk) {
4245 1.1 rjs asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq;
4246 1.1 rjs } else {
4247 1.1 rjs asoc->nonce_wait_tsn = asoc->sending_seq;
4248 1.1 rjs }
4249 1.1 rjs } else {
4250 1.1 rjs if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) ||
4251 1.1 rjs (asoc->last_acked_seq == asoc->nonce_wait_tsn)) {
4252 1.1 rjs /* Misbehaving peer. We need to react to this guy */
4253 1.1 rjs printf("Mis-behaving peer detected\n");
4254 1.1 rjs asoc->ecn_allowed = 0;
4255 1.1 rjs asoc->ecn_nonce_allowed = 0;
4256 1.1 rjs }
4257 1.1 rjs }
4258 1.1 rjs }
4259 1.1 rjs } else {
4260 1.1 rjs /* See if Resynchronization Possible */
4261 1.1 rjs if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) {
4262 1.1 rjs asoc->nonce_sum_check = 1;
4263 1.1 rjs /* now we must calculate what the base
4264 1.1 rjs * is. We do this based on two things, we know
4265 1.1 rjs * the total's for all the segments gap-acked
4266 1.1 rjs * in the SACK, its stored in ecn_seg_sums.
4267 1.1 rjs * We also know the SACK's nonce sum, its
4268 1.1 rjs * in nonce_sum_flag. So we can build a truth
4269 1.1 rjs * table to back-calculate the new value of asoc->nonce_sum_expect_base:
4270 1.1 rjs *
4271 1.1 rjs * SACK-flag-Value Seg-Sums Base
4272 1.1 rjs * 0 0 0
4273 1.1 rjs * 1 0 1
4274 1.1 rjs * 0 1 1
4275 1.1 rjs * 1 1 0
4276 1.1 rjs */
4277 1.1 rjs asoc->nonce_sum_expect_base = (ecn_seg_sums ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM;
4278 1.1 rjs }
4279 1.1 rjs }
4280 1.1 rjs }
4281 1.1 rjs /* Now are we exiting loss recovery ? */
4282 1.1 rjs if (will_exit_fast_recovery) {
4283 1.1 rjs /* Ok, we must exit fast recovery */
4284 1.1 rjs asoc->fast_retran_loss_recovery = 0;
4285 1.1 rjs }
4286 1.1 rjs if ((asoc->sat_t3_loss_recovery) &&
4287 1.1 rjs ((compare_with_wrap(asoc->last_acked_seq, asoc->sat_t3_recovery_tsn,
4288 1.1 rjs MAX_TSN) ||
4289 1.1 rjs (asoc->last_acked_seq == asoc->sat_t3_recovery_tsn)))) {
4290 1.1 rjs /* end satellite t3 loss recovery */
4291 1.1 rjs asoc->sat_t3_loss_recovery = 0;
4292 1.1 rjs }
4293 1.1 rjs /* Adjust and set the new rwnd value */
4294 1.1 rjs #ifdef SCTP_LOG_RWND
4295 1.1 rjs sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK,
4296 1.1 rjs asoc->peers_rwnd, asoc->total_flight, (asoc->sent_queue_cnt * sctp_peer_chunk_oh), a_rwnd);
4297 1.1 rjs #endif
4298 1.1 rjs
4299 1.1 rjs asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd,
4300 1.1 rjs (u_int32_t)(asoc->total_flight + (asoc->sent_queue_cnt * sctp_peer_chunk_oh)));
4301 1.1 rjs if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
4302 1.1 rjs /* SWS sender side engages */
4303 1.1 rjs asoc->peers_rwnd = 0;
4304 1.1 rjs }
4305 1.1 rjs /*
4306 1.1 rjs * Now we must setup so we have a timer up for anyone with
4307 1.1 rjs * outstanding data.
4308 1.1 rjs */
4309 1.1 rjs TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4310 1.1 rjs struct sctp_tmit_chunk *chk;
4311 1.1 rjs TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
4312 1.1 rjs if (chk->whoTo == net &&
4313 1.1 rjs (chk->sent < SCTP_DATAGRAM_ACKED ||
4314 1.1 rjs chk->sent == SCTP_FORWARD_TSN_SKIP)) {
4315 1.1 rjs /*
4316 1.1 rjs * Not ack'ed and still outstanding to this
4317 1.1 rjs * destination or marked and must be
4318 1.1 rjs * sacked after fwd-tsn sent.
4319 1.1 rjs */
4320 1.1 rjs sctp_timer_start(SCTP_TIMER_TYPE_SEND,
4321 1.1 rjs stcb->sctp_ep, stcb, net);
4322 1.1 rjs break;
4323 1.1 rjs }
4324 1.1 rjs }
4325 1.1 rjs }
4326 1.1 rjs }
4327 1.1 rjs
4328 1.1 rjs void
4329 1.1 rjs sctp_update_acked(struct sctp_tcb *stcb, struct sctp_shutdown_chunk *cp,
4330 1.1 rjs struct sctp_nets *netp, int *abort_flag)
4331 1.1 rjs {
4332 1.1 rjs /* Mutate a shutdown into a SACK */
4333 1.1 rjs struct sctp_sack_chunk sack;
4334 1.1 rjs
4335 1.1 rjs /* Copy cum-ack */
4336 1.1 rjs sack.sack.cum_tsn_ack = cp->cumulative_tsn_ack;
4337 1.1 rjs /* Arrange so a_rwnd does NOT change */
4338 1.1 rjs sack.ch.chunk_type = SCTP_SELECTIVE_ACK;
4339 1.1 rjs sack.ch.chunk_flags = 0;
4340 1.1 rjs sack.ch.chunk_length = ntohs(sizeof(struct sctp_sack_chunk));
4341 1.1 rjs sack.sack.a_rwnd =
4342 1.1 rjs htonl(stcb->asoc.peers_rwnd + stcb->asoc.total_flight);
4343 1.1 rjs /*
4344 1.1 rjs * no gaps in this one. This may cause a temporal view to reneging,
4345 1.1 rjs * but hopefully the second chunk is a true SACK in the packet and
4346 1.1 rjs * will correct this view. One will come soon after no matter what
4347 1.1 rjs * to fix this.
4348 1.1 rjs */
4349 1.1 rjs sack.sack.num_gap_ack_blks = 0;
4350 1.1 rjs sack.sack.num_dup_tsns = 0;
4351 1.1 rjs /* Now call the SACK processor */
4352 1.1 rjs sctp_handle_sack(&sack, stcb, netp, abort_flag);
4353 1.1 rjs }
4354 1.1 rjs
4355 1.1 rjs static void
4356 1.1 rjs sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb,
4357 1.1 rjs struct sctp_stream_in *strmin)
4358 1.1 rjs {
4359 1.1 rjs struct sctp_tmit_chunk *chk, *nchk;
4360 1.1 rjs struct sctp_association *asoc;
4361 1.1 rjs int tt;
4362 1.1 rjs
4363 1.1 rjs asoc = &stcb->asoc;
4364 1.1 rjs tt = strmin->last_sequence_delivered;
4365 1.1 rjs /*
4366 1.1 rjs * First deliver anything prior to and including the stream no that
4367 1.1 rjs * came in
4368 1.1 rjs */
4369 1.1 rjs chk = TAILQ_FIRST(&strmin->inqueue);
4370 1.1 rjs while (chk) {
4371 1.1 rjs nchk = TAILQ_NEXT(chk, sctp_next);
4372 1.1 rjs if (compare_with_wrap(tt, chk->rec.data.stream_seq, MAX_SEQ) ||
4373 1.1 rjs (tt == chk->rec.data.stream_seq)) {
4374 1.1 rjs /* this is deliverable now */
4375 1.1 rjs TAILQ_REMOVE(&strmin->inqueue, chk, sctp_next);
4376 1.1 rjs /* subtract pending on streams */
4377 1.1 rjs asoc->size_on_all_streams -= chk->send_size;
4378 1.1 rjs asoc->cnt_on_all_streams--;
4379 1.1 rjs /* deliver it to at least the delivery-q */
4380 1.1 rjs sctp_deliver_data(stcb, &stcb->asoc, chk, 0);
4381 1.1 rjs } else {
4382 1.1 rjs /* no more delivery now. */
4383 1.1 rjs break;
4384 1.1 rjs }
4385 1.1 rjs chk = nchk;
4386 1.1 rjs }
4387 1.1 rjs /*
4388 1.1 rjs * now we must deliver things in queue the normal way if any
4389 1.1 rjs * are now ready.
4390 1.1 rjs */
4391 1.1 rjs tt = strmin->last_sequence_delivered + 1;
4392 1.1 rjs chk = TAILQ_FIRST(&strmin->inqueue);
4393 1.1 rjs while (chk) {
4394 1.1 rjs nchk = TAILQ_NEXT(chk, sctp_next);
4395 1.1 rjs if (tt == chk->rec.data.stream_seq) {
4396 1.1 rjs /* this is deliverable now */
4397 1.1 rjs TAILQ_REMOVE(&strmin->inqueue, chk, sctp_next);
4398 1.1 rjs /* subtract pending on streams */
4399 1.1 rjs asoc->size_on_all_streams -= chk->send_size;
4400 1.1 rjs asoc->cnt_on_all_streams--;
4401 1.1 rjs /* deliver it to at least the delivery-q */
4402 1.1 rjs strmin->last_sequence_delivered =
4403 1.1 rjs chk->rec.data.stream_seq;
4404 1.1 rjs sctp_deliver_data(stcb, &stcb->asoc, chk, 0);
4405 1.1 rjs tt = strmin->last_sequence_delivered + 1;
4406 1.1 rjs } else {
4407 1.1 rjs break;
4408 1.1 rjs }
4409 1.1 rjs chk = nchk;
4410 1.1 rjs }
4411 1.1 rjs
4412 1.1 rjs }
4413 1.1 rjs
4414 1.1 rjs void
4415 1.1 rjs sctp_handle_forward_tsn(struct sctp_tcb *stcb,
4416 1.1 rjs struct sctp_forward_tsn_chunk *fwd, int *abort_flag)
4417 1.1 rjs {
4418 1.1 rjs /*
4419 1.1 rjs * ISSUES that MUST be fixed for ECN! When we are the
4420 1.1 rjs * sender of the forward TSN, when the SACK comes back
4421 1.1 rjs * that acknowledges the FWD-TSN we must reset the
4422 1.1 rjs * NONCE sum to match correctly. This will get quite
4423 1.1 rjs * tricky since we may have sent more data interveneing and
4424 1.1 rjs * must carefully account for what the SACK says on the
4425 1.1 rjs * nonce and any gaps that are reported. This work
4426 1.1 rjs * will NOT be done here, but I note it here since
4427 1.1 rjs * it is really related to PR-SCTP and FWD-TSN's
4428 1.1 rjs */
4429 1.1 rjs
4430 1.1 rjs /* The pr-sctp fwd tsn */
4431 1.1 rjs /*
4432 1.1 rjs * here we will perform all the data receiver side steps for
4433 1.1 rjs * processing FwdTSN, as required in by pr-sctp draft:
4434 1.1 rjs *
4435 1.1 rjs * Assume we get FwdTSN(x):
4436 1.1 rjs *
4437 1.1 rjs * 1) update local cumTSN to x
4438 1.1 rjs * 2) try to further advance cumTSN to x + others we have
4439 1.1 rjs * 3) examine and update re-ordering queue on pr-in-streams
4440 1.1 rjs * 4) clean up re-assembly queue
4441 1.1 rjs * 5) Send a sack to report where we are.
4442 1.1 rjs */
4443 1.1 rjs struct sctp_strseq *stseq;
4444 1.1 rjs struct sctp_association *asoc;
4445 1.1 rjs u_int32_t new_cum_tsn, gap, back_out_htsn;
4446 1.1 rjs unsigned int i, cnt_gone, fwd_sz, cumack_set_flag, m_size;
4447 1.1 rjs struct sctp_stream_in *strm;
4448 1.1 rjs struct sctp_tmit_chunk *chk, *at;
4449 1.1 rjs
4450 1.1 rjs cumack_set_flag = 0;
4451 1.1 rjs asoc = &stcb->asoc;
4452 1.1 rjs cnt_gone = 0;
4453 1.1 rjs if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) {
4454 1.1 rjs #ifdef SCTP_DEBUG
4455 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
4456 1.1 rjs printf("Bad size too small/big fwd-tsn\n");
4457 1.1 rjs }
4458 1.1 rjs #endif
4459 1.1 rjs return;
4460 1.1 rjs }
4461 1.1 rjs m_size = (stcb->asoc.mapping_array_size << 3);
4462 1.1 rjs /*************************************************************/
4463 1.1 rjs /* 1. Here we update local cumTSN and shift the bitmap array */
4464 1.1 rjs /*************************************************************/
4465 1.1 rjs new_cum_tsn = ntohl(fwd->new_cumulative_tsn);
4466 1.1 rjs
4467 1.1 rjs if (compare_with_wrap(asoc->cumulative_tsn, new_cum_tsn, MAX_TSN) ||
4468 1.1 rjs asoc->cumulative_tsn == new_cum_tsn) {
4469 1.1 rjs /* Already got there ... */
4470 1.1 rjs return;
4471 1.1 rjs }
4472 1.1 rjs
4473 1.1 rjs back_out_htsn = asoc->highest_tsn_inside_map;
4474 1.1 rjs if (compare_with_wrap(new_cum_tsn, asoc->highest_tsn_inside_map,
4475 1.1 rjs MAX_TSN)) {
4476 1.1 rjs asoc->highest_tsn_inside_map = new_cum_tsn;
4477 1.1 rjs #ifdef SCTP_MAP_LOGGING
4478 1.1 rjs sctp_log_map(0, 0, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
4479 1.1 rjs #endif
4480 1.1 rjs }
4481 1.1 rjs /*
4482 1.1 rjs * now we know the new TSN is more advanced, let's find the
4483 1.1 rjs * actual gap
4484 1.1 rjs */
4485 1.1 rjs if ((compare_with_wrap(new_cum_tsn, asoc->mapping_array_base_tsn,
4486 1.1 rjs MAX_TSN)) ||
4487 1.1 rjs (new_cum_tsn == asoc->mapping_array_base_tsn)) {
4488 1.1 rjs gap = new_cum_tsn - asoc->mapping_array_base_tsn;
4489 1.1 rjs } else {
4490 1.1 rjs /* try to prevent underflow here */
4491 1.1 rjs gap = new_cum_tsn + (MAX_TSN - asoc->mapping_array_base_tsn) + 1;
4492 1.1 rjs }
4493 1.1 rjs
4494 1.1 rjs if (gap >= m_size) {
4495 1.1 rjs asoc->highest_tsn_inside_map = back_out_htsn;
4496 1.1 rjs if ((long)gap > sctp_sbspace(&stcb->sctp_socket->so_rcv)) {
4497 1.1 rjs /*
4498 1.1 rjs * out of range (of single byte chunks in the rwnd I
4499 1.1 rjs * give out)
4500 1.1 rjs * too questionable. better to drop it silently
4501 1.1 rjs */
4502 1.1 rjs return;
4503 1.1 rjs }
4504 1.1 rjs if (asoc->highest_tsn_inside_map >
4505 1.1 rjs asoc->mapping_array_base_tsn) {
4506 1.1 rjs gap = asoc->highest_tsn_inside_map -
4507 1.1 rjs asoc->mapping_array_base_tsn;
4508 1.1 rjs } else {
4509 1.1 rjs gap = asoc->highest_tsn_inside_map +
4510 1.1 rjs (MAX_TSN - asoc->mapping_array_base_tsn) + 1;
4511 1.1 rjs }
4512 1.1 rjs cumack_set_flag = 1;
4513 1.1 rjs }
4514 1.1 rjs for (i = 0; i <= gap; i++) {
4515 1.1 rjs SCTP_SET_TSN_PRESENT(asoc->mapping_array, i);
4516 1.1 rjs }
4517 1.1 rjs /*
4518 1.1 rjs * Now after marking all, slide thing forward but no
4519 1.1 rjs * sack please.
4520 1.1 rjs */
4521 1.1 rjs sctp_sack_check(stcb, 0, 0, abort_flag);
4522 1.1 rjs if (*abort_flag)
4523 1.1 rjs return;
4524 1.1 rjs
4525 1.1 rjs if (cumack_set_flag) {
4526 1.1 rjs /*
4527 1.1 rjs * fwd-tsn went outside my gap array - not a
4528 1.1 rjs * common occurance. Do the same thing we
4529 1.1 rjs * do when a cookie-echo arrives.
4530 1.1 rjs */
4531 1.1 rjs asoc->highest_tsn_inside_map = new_cum_tsn - 1;
4532 1.1 rjs asoc->mapping_array_base_tsn = new_cum_tsn;
4533 1.1 rjs asoc->cumulative_tsn = asoc->highest_tsn_inside_map;
4534 1.1 rjs #ifdef SCTP_MAP_LOGGING
4535 1.1 rjs sctp_log_map(0, 3, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
4536 1.1 rjs #endif
4537 1.1 rjs asoc->last_echo_tsn = asoc->highest_tsn_inside_map;
4538 1.1 rjs }
4539 1.1 rjs /*************************************************************/
4540 1.1 rjs /* 2. Clear up re-assembly queue */
4541 1.1 rjs /*************************************************************/
4542 1.1 rjs
4543 1.1 rjs /*
4544 1.1 rjs * First service it if pd-api is up, just in case we can
4545 1.1 rjs * progress it forward
4546 1.1 rjs */
4547 1.1 rjs if (asoc->fragmented_delivery_inprogress) {
4548 1.1 rjs sctp_service_reassembly(stcb, asoc, 0);
4549 1.1 rjs }
4550 1.1 rjs if (!TAILQ_EMPTY(&asoc->reasmqueue)) {
4551 1.1 rjs /* For each one on here see if we need to toss it */
4552 1.1 rjs /*
4553 1.1 rjs * For now large messages held on the reasmqueue that are
4554 1.1 rjs * complete will be tossed too. We could in theory do more
4555 1.1 rjs * work to spin through and stop after dumping one msg
4556 1.1 rjs * aka seeing the start of a new msg at the head, and call
4557 1.1 rjs * the delivery function... to see if it can be delivered...
4558 1.1 rjs * But for now we just dump everything on the queue.
4559 1.1 rjs */
4560 1.1 rjs chk = TAILQ_FIRST(&asoc->reasmqueue);
4561 1.1 rjs while (chk) {
4562 1.1 rjs at = TAILQ_NEXT(chk, sctp_next);
4563 1.1 rjs if (compare_with_wrap(asoc->cumulative_tsn,
4564 1.1 rjs chk->rec.data.TSN_seq, MAX_TSN) ||
4565 1.1 rjs asoc->cumulative_tsn == chk->rec.data.TSN_seq) {
4566 1.1 rjs /* It needs to be tossed */
4567 1.1 rjs TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
4568 1.1 rjs if (compare_with_wrap(chk->rec.data.TSN_seq,
4569 1.1 rjs asoc->tsn_last_delivered, MAX_TSN)) {
4570 1.1 rjs asoc->tsn_last_delivered =
4571 1.1 rjs chk->rec.data.TSN_seq;
4572 1.1 rjs asoc->str_of_pdapi =
4573 1.1 rjs chk->rec.data.stream_number;
4574 1.1 rjs asoc->ssn_of_pdapi =
4575 1.1 rjs chk->rec.data.stream_seq;
4576 1.1 rjs asoc->fragment_flags =
4577 1.1 rjs chk->rec.data.rcv_flags;
4578 1.1 rjs }
4579 1.1 rjs asoc->size_on_reasm_queue -= chk->send_size;
4580 1.1 rjs asoc->cnt_on_reasm_queue--;
4581 1.1 rjs cnt_gone++;
4582 1.1 rjs
4583 1.1 rjs /* Clear up any stream problem */
4584 1.1 rjs if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) !=
4585 1.1 rjs SCTP_DATA_UNORDERED &&
4586 1.1 rjs (compare_with_wrap(chk->rec.data.stream_seq,
4587 1.1 rjs asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered,
4588 1.1 rjs MAX_SEQ))) {
4589 1.1 rjs /*
4590 1.1 rjs * We must dump forward this streams
4591 1.1 rjs * sequence number if the chunk is not
4592 1.1 rjs * unordered that is being skipped.
4593 1.1 rjs * There is a chance that if the peer
4594 1.1 rjs * does not include the last fragment
4595 1.1 rjs * in its FWD-TSN we WILL have a problem
4596 1.1 rjs * here since you would have a partial
4597 1.1 rjs * chunk in queue that may not be
4598 1.1 rjs * deliverable.
4599 1.1 rjs * Also if a Partial delivery API as
4600 1.1 rjs * started the user may get a partial
4601 1.1 rjs * chunk. The next read returning a new
4602 1.1 rjs * chunk... really ugly but I see no way
4603 1.1 rjs * around it! Maybe a notify??
4604 1.1 rjs */
4605 1.1 rjs asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered =
4606 1.1 rjs chk->rec.data.stream_seq;
4607 1.1 rjs }
4608 1.1 rjs if (chk->data) {
4609 1.1 rjs sctp_m_freem(chk->data);
4610 1.1 rjs chk->data = NULL;
4611 1.1 rjs }
4612 1.1 rjs sctp_free_remote_addr(chk->whoTo);
4613 1.1 rjs SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
4614 1.1 rjs sctppcbinfo.ipi_count_chunk--;
4615 1.1 rjs if ((int)sctppcbinfo.ipi_count_chunk < 0) {
4616 1.1 rjs panic("Chunk count is negative");
4617 1.1 rjs }
4618 1.1 rjs sctppcbinfo.ipi_gencnt_chunk++;
4619 1.1 rjs } else {
4620 1.1 rjs /*
4621 1.1 rjs * Ok we have gone beyond the end of the
4622 1.1 rjs * fwd-tsn's mark. Some checks...
4623 1.1 rjs */
4624 1.1 rjs if ((asoc->fragmented_delivery_inprogress) &&
4625 1.1 rjs (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG)) {
4626 1.1 rjs /* Special case PD-API is up and what we fwd-tsn'
4627 1.1 rjs * over includes one that had the LAST_FRAG. We
4628 1.1 rjs * no longer need to do the PD-API.
4629 1.1 rjs */
4630 1.1 rjs asoc->fragmented_delivery_inprogress = 0;
4631 1.1 rjs sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION,
4632 1.1 rjs stcb, SCTP_PARTIAL_DELIVERY_ABORTED, (void *)NULL);
4633 1.1 rjs
4634 1.1 rjs }
4635 1.1 rjs break;
4636 1.1 rjs }
4637 1.1 rjs chk = at;
4638 1.1 rjs }
4639 1.1 rjs }
4640 1.1 rjs if (asoc->fragmented_delivery_inprogress) {
4641 1.1 rjs /*
4642 1.1 rjs * Ok we removed cnt_gone chunks in the PD-API queue that
4643 1.1 rjs * were being delivered. So now we must turn off the
4644 1.1 rjs * flag.
4645 1.1 rjs */
4646 1.1 rjs sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION,
4647 1.1 rjs stcb, SCTP_PARTIAL_DELIVERY_ABORTED, (void *)NULL);
4648 1.1 rjs asoc->fragmented_delivery_inprogress = 0;
4649 1.1 rjs }
4650 1.1 rjs /*************************************************************/
4651 1.1 rjs /* 3. Update the PR-stream re-ordering queues */
4652 1.1 rjs /*************************************************************/
4653 1.1 rjs stseq = (struct sctp_strseq *)((vaddr_t)fwd + sizeof(*fwd));
4654 1.1 rjs fwd_sz -= sizeof(*fwd);
4655 1.1 rjs {
4656 1.1 rjs /* New method. */
4657 1.1 rjs int num_str;
4658 1.1 rjs num_str = fwd_sz/sizeof(struct sctp_strseq);
4659 1.1 rjs #ifdef SCTP_DEBUG
4660 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
4661 1.1 rjs printf("Using NEW method, %d strseq's reported in FWD-TSN\n",
4662 1.1 rjs num_str);
4663 1.1 rjs }
4664 1.1 rjs #endif
4665 1.1 rjs for (i = 0; i < num_str; i++) {
4666 1.1 rjs u_int16_t st;
4667 1.1 rjs #if 0
4668 1.1 rjs unsigned char *xx;
4669 1.1 rjs /* Convert */
4670 1.1 rjs xx = (unsigned char *)&stseq[i];
4671 1.1 rjs #endif
4672 1.1 rjs st = ntohs(stseq[i].stream);
4673 1.1 rjs stseq[i].stream = st;
4674 1.1 rjs st = ntohs(stseq[i].sequence);
4675 1.1 rjs stseq[i].sequence = st;
4676 1.1 rjs /* now process */
4677 1.1 rjs if (stseq[i].stream > asoc->streamincnt) {
4678 1.1 rjs #ifdef SCTP_DEBUG
4679 1.1 rjs if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
4680 1.1 rjs printf("Bogus stream number %d "
4681 1.1 rjs "streamincnt is %d\n",
4682 1.1 rjs stseq[i].stream, asoc->streamincnt);
4683 1.1 rjs }
4684 1.1 rjs #endif
4685 1.1 rjs /*
4686 1.1 rjs * It is arguable if we should continue. Since
4687 1.1 rjs * the peer sent bogus stream info we may be in
4688 1.1 rjs * deep trouble..
4689 1.1 rjs * a return may be a better choice?
4690 1.1 rjs */
4691 1.1 rjs continue;
4692 1.1 rjs }
4693 1.1 rjs strm = &asoc->strmin[stseq[i].stream];
4694 1.1 rjs if (compare_with_wrap(stseq[i].sequence,
4695 1.1 rjs strm->last_sequence_delivered, MAX_SEQ)) {
4696 1.1 rjs /* Update the sequence number */
4697 1.1 rjs strm->last_sequence_delivered =
4698 1.1 rjs stseq[i].sequence;
4699 1.1 rjs }
4700 1.1 rjs /* now kick the stream the new way */
4701 1.1 rjs sctp_kick_prsctp_reorder_queue(stcb, strm);
4702 1.1 rjs }
4703 1.1 rjs }
4704 1.1 rjs }
4705