2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 /* $KAME: sctp_indata.c,v 1.36 2005/03/06 16:04:17 itojun Exp $ */
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
37 #include <netinet/sctp_var.h>
38 #include <netinet/sctp_sysctl.h>
39 #include <netinet/sctp_pcb.h>
40 #include <netinet/sctp_header.h>
41 #include <netinet/sctputil.h>
42 #include <netinet/sctp_output.h>
43 #include <netinet/sctp_input.h>
44 #include <netinet/sctp_indata.h>
45 #include <netinet/sctp_uio.h>
46 #include <netinet/sctp_timer.h>
50 * NOTES: On the outbound side of things I need to check the sack timer to
51 * see if I should generate a sack into the chunk queue (if I have data to
52 * send that is and will be sending it .. for bundling.
54 * The callback in sctp_usrreq.c will get called when the socket is read from.
55 * This will cause sctp_service_queues() to get called on the top entry in
60 sctp_set_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc)
62 uint32_t calc, calc_w_oh;
65 * This is really set wrong with respect to a 1-2-m socket. Since
66 * the sb_cc is the count that everyone as put up. When we re-write
67 * sctp_soreceive then we will fix this so that ONLY this
68 * associations data is taken into account.
70 if (stcb->sctp_socket == NULL)
73 if (stcb->asoc.sb_cc == 0 &&
74 asoc->size_on_reasm_queue == 0 &&
75 asoc->size_on_all_streams == 0) {
76 /* Full rwnd granted */
77 asoc->my_rwnd = max(SCTP_SB_LIMIT_RCV(stcb->sctp_socket),
81 /* get actual space */
82 calc = (uint32_t) sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv);
85 * take out what has NOT been put on socket queue and we yet hold
88 calc = sctp_sbspace_sub(calc, (uint32_t) asoc->size_on_reasm_queue);
89 calc = sctp_sbspace_sub(calc, (uint32_t) asoc->size_on_all_streams);
96 /* what is the overhead of all these rwnd's */
97 calc_w_oh = sctp_sbspace_sub(calc, stcb->asoc.my_rwnd_control_len);
101 * If our overhead is greater than the advertised rwnd, we
102 * clamp the rwnd to 1. This lets us still accept inbound
103 * segments, but hopefully will shut the sender down when he
104 * finally gets the message.
110 (asoc->my_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_receiver)) {
111 /* SWS engaged, tell peer none left */
117 /* Calculate what the rwnd would be */
120 sctp_calc_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc)
122 uint32_t calc = 0, calc_w_oh;
125 * This is really set wrong with respect to a 1-2-m socket. Since
126 * the sb_cc is the count that everyone as put up. When we re-write
127 * sctp_soreceive then we will fix this so that ONLY this
128 * associations data is taken into account.
130 if (stcb->sctp_socket == NULL)
133 if (stcb->asoc.sb_cc == 0 &&
134 asoc->size_on_reasm_queue == 0 &&
135 asoc->size_on_all_streams == 0) {
136 /* Full rwnd granted */
137 calc = max(SCTP_SB_LIMIT_RCV(stcb->sctp_socket),
141 /* get actual space */
142 calc = (uint32_t) sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv);
145 * take out what has NOT been put on socket queue and we yet hold
148 calc = sctp_sbspace_sub(calc, (uint32_t) asoc->size_on_reasm_queue);
149 calc = sctp_sbspace_sub(calc, (uint32_t) asoc->size_on_all_streams);
155 /* what is the overhead of all these rwnd's */
156 calc_w_oh = sctp_sbspace_sub(calc, stcb->asoc.my_rwnd_control_len);
157 if (calc_w_oh == 0) {
159 * If our overhead is greater than the advertised rwnd, we
160 * clamp the rwnd to 1. This lets us still accept inbound
161 * segments, but hopefully will shut the sender down when he
162 * finally gets the message.
168 (calc < stcb->sctp_ep->sctp_ep.sctp_sws_receiver)) {
169 /* SWS engaged, tell peer none left */
179 * Build out our readq entry based on the incoming packet.
181 struct sctp_queued_to_read *
182 sctp_build_readq_entry(struct sctp_tcb *stcb,
183 struct sctp_nets *net,
184 uint32_t tsn, uint32_t ppid,
185 uint32_t context, uint16_t stream_no,
186 uint16_t stream_seq, uint8_t flags,
189 struct sctp_queued_to_read *read_queue_e = NULL;
191 sctp_alloc_a_readq(stcb, read_queue_e);
192 if (read_queue_e == NULL) {
195 read_queue_e->sinfo_stream = stream_no;
196 read_queue_e->sinfo_ssn = stream_seq;
197 read_queue_e->sinfo_flags = (flags << 8);
198 read_queue_e->sinfo_ppid = ppid;
199 read_queue_e->sinfo_context = stcb->asoc.context;
200 read_queue_e->sinfo_timetolive = 0;
201 read_queue_e->sinfo_tsn = tsn;
202 read_queue_e->sinfo_cumtsn = tsn;
203 read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb);
204 read_queue_e->whoFrom = net;
205 read_queue_e->length = 0;
206 atomic_add_int(&net->ref_count, 1);
207 read_queue_e->data = dm;
208 read_queue_e->spec_flags = 0;
209 read_queue_e->tail_mbuf = NULL;
210 read_queue_e->aux_data = NULL;
211 read_queue_e->stcb = stcb;
212 read_queue_e->port_from = stcb->rport;
213 read_queue_e->do_not_ref_stcb = 0;
214 read_queue_e->end_added = 0;
215 read_queue_e->some_taken = 0;
216 read_queue_e->pdapi_aborted = 0;
218 return (read_queue_e);
223 * Build out our readq entry based on the incoming packet.
225 static struct sctp_queued_to_read *
226 sctp_build_readq_entry_chk(struct sctp_tcb *stcb,
227 struct sctp_tmit_chunk *chk)
229 struct sctp_queued_to_read *read_queue_e = NULL;
231 sctp_alloc_a_readq(stcb, read_queue_e);
232 if (read_queue_e == NULL) {
235 read_queue_e->sinfo_stream = chk->rec.data.stream_number;
236 read_queue_e->sinfo_ssn = chk->rec.data.stream_seq;
237 read_queue_e->sinfo_flags = (chk->rec.data.rcv_flags << 8);
238 read_queue_e->sinfo_ppid = chk->rec.data.payloadtype;
239 read_queue_e->sinfo_context = stcb->asoc.context;
240 read_queue_e->sinfo_timetolive = 0;
241 read_queue_e->sinfo_tsn = chk->rec.data.TSN_seq;
242 read_queue_e->sinfo_cumtsn = chk->rec.data.TSN_seq;
243 read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb);
244 read_queue_e->whoFrom = chk->whoTo;
245 read_queue_e->aux_data = NULL;
246 read_queue_e->length = 0;
247 atomic_add_int(&chk->whoTo->ref_count, 1);
248 read_queue_e->data = chk->data;
249 read_queue_e->tail_mbuf = NULL;
250 read_queue_e->stcb = stcb;
251 read_queue_e->port_from = stcb->rport;
252 read_queue_e->spec_flags = 0;
253 read_queue_e->do_not_ref_stcb = 0;
254 read_queue_e->end_added = 0;
255 read_queue_e->some_taken = 0;
256 read_queue_e->pdapi_aborted = 0;
258 return (read_queue_e);
263 sctp_build_ctl_nchunk(struct sctp_inpcb *inp,
264 struct sctp_sndrcvinfo *sinfo)
266 struct sctp_sndrcvinfo *outinfo;
270 int use_extended = 0;
272 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) {
273 /* user does not want the sndrcv ctl */
276 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) {
278 len = CMSG_LEN(sizeof(struct sctp_extrcvinfo));
280 len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
284 ret = sctp_get_mbuf_for_msg(len,
285 0, M_DONTWAIT, 1, MT_DATA);
291 /* We need a CMSG header followed by the struct */
292 cmh = mtod(ret, struct cmsghdr *);
293 outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh);
294 cmh->cmsg_level = IPPROTO_SCTP;
296 cmh->cmsg_type = SCTP_EXTRCV;
298 memcpy(outinfo, sinfo, len);
300 cmh->cmsg_type = SCTP_SNDRCV;
304 SCTP_BUF_LEN(ret) = cmh->cmsg_len;
310 sctp_build_ctl_cchunk(struct sctp_inpcb *inp,
312 struct sctp_sndrcvinfo *sinfo)
314 struct sctp_sndrcvinfo *outinfo;
318 int use_extended = 0;
320 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) {
321 /* user does not want the sndrcv ctl */
324 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) {
326 len = CMSG_LEN(sizeof(struct sctp_extrcvinfo));
328 len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
330 SCTP_MALLOC(buf, char *, len, SCTP_M_CMSG);
335 /* We need a CMSG header followed by the struct */
336 cmh = (struct cmsghdr *)buf;
337 outinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmh);
338 cmh->cmsg_level = IPPROTO_SCTP;
340 cmh->cmsg_type = SCTP_EXTRCV;
342 memcpy(outinfo, sinfo, len);
344 cmh->cmsg_type = SCTP_SNDRCV;
354 * We are delivering currently from the reassembly queue. We must continue to
355 * deliver until we either: 1) run out of space. 2) run out of sequential
356 * TSN's 3) hit the SCTP_DATA_LAST_FRAG flag.
359 sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc)
361 struct sctp_tmit_chunk *chk;
366 struct sctp_queued_to_read *control, *ctl, *ctlat;
371 cntDel = stream_no = 0;
372 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
373 (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) {
374 /* socket above is long gone */
375 asoc->fragmented_delivery_inprogress = 0;
376 chk = TAILQ_FIRST(&asoc->reasmqueue);
378 TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
379 asoc->size_on_reasm_queue -= chk->send_size;
380 sctp_ucount_decr(asoc->cnt_on_reasm_queue);
382 * Lose the data pointer, since its in the socket
386 sctp_m_freem(chk->data);
389 /* Now free the address and data */
390 sctp_free_a_chunk(stcb, chk);
391 /* sa_ignore FREED_MEMORY */
392 chk = TAILQ_FIRST(&asoc->reasmqueue);
396 SCTP_TCB_LOCK_ASSERT(stcb);
398 chk = TAILQ_FIRST(&asoc->reasmqueue);
402 if (chk->rec.data.TSN_seq != (asoc->tsn_last_delivered + 1)) {
403 /* Can't deliver more :< */
406 stream_no = chk->rec.data.stream_number;
407 nxt_todel = asoc->strmin[stream_no].last_sequence_delivered + 1;
408 if (nxt_todel != chk->rec.data.stream_seq &&
409 (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) {
411 * Not the next sequence to deliver in its stream OR
416 if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
418 control = sctp_build_readq_entry_chk(stcb, chk);
419 if (control == NULL) {
423 /* save it off for our future deliveries */
424 stcb->asoc.control_pdapi = control;
425 if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG)
429 sctp_add_to_readq(stcb->sctp_ep,
430 stcb, control, &stcb->sctp_socket->so_rcv, end);
433 if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG)
437 if (sctp_append_to_readq(stcb->sctp_ep, stcb,
438 stcb->asoc.control_pdapi,
439 chk->data, end, chk->rec.data.TSN_seq,
440 &stcb->sctp_socket->so_rcv)) {
442 * something is very wrong, either
443 * control_pdapi is NULL, or the tail_mbuf
444 * is corrupt, or there is a EOM already on
447 if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) {
448 panic("This should not happen control_pdapi NULL?");
450 /* if we did not panic, it was a EOM */
451 panic("Bad chunking ??");
456 /* pull it we did it */
457 TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
458 if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
459 asoc->fragmented_delivery_inprogress = 0;
460 if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) {
461 asoc->strmin[stream_no].last_sequence_delivered++;
463 if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) {
464 SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs);
466 } else if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
468 * turn the flag back on since we just delivered
471 asoc->fragmented_delivery_inprogress = 1;
473 asoc->tsn_of_pdapi_last_delivered = chk->rec.data.TSN_seq;
474 asoc->last_flags_delivered = chk->rec.data.rcv_flags;
475 asoc->last_strm_seq_delivered = chk->rec.data.stream_seq;
476 asoc->last_strm_no_delivered = chk->rec.data.stream_number;
478 asoc->tsn_last_delivered = chk->rec.data.TSN_seq;
479 asoc->size_on_reasm_queue -= chk->send_size;
480 sctp_ucount_decr(asoc->cnt_on_reasm_queue);
481 /* free up the chk */
483 sctp_free_a_chunk(stcb, chk);
485 if (asoc->fragmented_delivery_inprogress == 0) {
487 * Now lets see if we can deliver the next one on
490 struct sctp_stream_in *strm;
492 strm = &asoc->strmin[stream_no];
493 nxt_todel = strm->last_sequence_delivered + 1;
494 ctl = TAILQ_FIRST(&strm->inqueue);
495 if (ctl && (nxt_todel == ctl->sinfo_ssn)) {
496 while (ctl != NULL) {
497 /* Deliver more if we can. */
498 if (nxt_todel == ctl->sinfo_ssn) {
499 ctlat = TAILQ_NEXT(ctl, next);
500 TAILQ_REMOVE(&strm->inqueue, ctl, next);
501 asoc->size_on_all_streams -= ctl->length;
502 sctp_ucount_decr(asoc->cnt_on_all_streams);
503 strm->last_sequence_delivered++;
504 sctp_add_to_readq(stcb->sctp_ep, stcb,
506 &stcb->sctp_socket->so_rcv, 1);
511 nxt_todel = strm->last_sequence_delivered + 1;
516 /* sa_ignore FREED_MEMORY */
517 chk = TAILQ_FIRST(&asoc->reasmqueue);
522 * Queue the chunk either right into the socket buffer if it is the next one
523 * to go OR put it in the correct place in the delivery queue. If we do
524 * append to the so_buf, keep doing so until we are out of order. One big
525 * question still remains, what to do when the socket buffer is FULL??
528 sctp_queue_data_to_stream(struct sctp_tcb *stcb, struct sctp_association *asoc,
529 struct sctp_queued_to_read *control, int *abort_flag)
532 * FIX-ME maybe? What happens when the ssn wraps? If we are getting
533 * all the data in one stream this could happen quite rapidly. One
534 * could use the TSN to keep track of things, but this scheme breaks
535 * down in the other type of stream useage that could occur. Send a
536 * single msg to stream 0, send 4Billion messages to stream 1, now
537 * send a message to stream 0. You have a situation where the TSN
538 * has wrapped but not in the stream. Is this worth worrying about
539 * or should we just change our queue sort at the bottom to be by
542 * Could it also be legal for a peer to send ssn 1 with TSN 2 and ssn 2
543 * with TSN 1? If the peer is doing some sort of funky TSN/SSN
544 * assignment this could happen... and I don't see how this would be
545 * a violation. So for now I am undecided an will leave the sort by
546 * SSN alone. Maybe a hybred approach is the answer
549 struct sctp_stream_in *strm;
550 struct sctp_queued_to_read *at;
556 asoc->size_on_all_streams += control->length;
557 sctp_ucount_incr(asoc->cnt_on_all_streams);
558 strm = &asoc->strmin[control->sinfo_stream];
559 nxt_todel = strm->last_sequence_delivered + 1;
560 if (sctp_logging_level & SCTP_STR_LOGGING_ENABLE) {
561 sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD);
563 SCTPDBG(SCTP_DEBUG_INDATA1,
564 "queue to stream called for ssn:%u lastdel:%u nxt:%u\n",
565 (uint32_t) control->sinfo_stream,
566 (uint32_t) strm->last_sequence_delivered,
567 (uint32_t) nxt_todel);
568 if (compare_with_wrap(strm->last_sequence_delivered,
569 control->sinfo_ssn, MAX_SEQ) ||
570 (strm->last_sequence_delivered == control->sinfo_ssn)) {
571 /* The incoming sseq is behind where we last delivered? */
572 SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ:%d delivered:%d from peer, Abort association\n",
573 control->sinfo_ssn, strm->last_sequence_delivered);
575 * throw it in the stream so it gets cleaned up in
576 * association destruction
578 TAILQ_INSERT_HEAD(&strm->inqueue, control, next);
579 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
580 0, M_DONTWAIT, 1, MT_DATA);
582 struct sctp_paramhdr *ph;
585 SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) +
586 (sizeof(uint32_t) * 3);
587 ph = mtod(oper, struct sctp_paramhdr *);
588 ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
589 ph->param_length = htons(SCTP_BUF_LEN(oper));
590 ippp = (uint32_t *) (ph + 1);
591 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_1);
593 *ippp = control->sinfo_tsn;
595 *ippp = ((control->sinfo_stream << 16) | control->sinfo_ssn);
597 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_1;
598 sctp_abort_an_association(stcb->sctp_ep, stcb,
599 SCTP_PEER_FAULTY, oper);
605 if (nxt_todel == control->sinfo_ssn) {
606 /* can be delivered right away? */
607 if (sctp_logging_level & SCTP_STR_LOGGING_ENABLE) {
608 sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_IMMED_DEL);
611 asoc->size_on_all_streams -= control->length;
612 sctp_ucount_decr(asoc->cnt_on_all_streams);
613 strm->last_sequence_delivered++;
614 sctp_add_to_readq(stcb->sctp_ep, stcb,
616 &stcb->sctp_socket->so_rcv, 1);
617 control = TAILQ_FIRST(&strm->inqueue);
618 while (control != NULL) {
620 nxt_todel = strm->last_sequence_delivered + 1;
621 if (nxt_todel == control->sinfo_ssn) {
622 at = TAILQ_NEXT(control, next);
623 TAILQ_REMOVE(&strm->inqueue, control, next);
624 asoc->size_on_all_streams -= control->length;
625 sctp_ucount_decr(asoc->cnt_on_all_streams);
626 strm->last_sequence_delivered++;
628 * We ignore the return of deliver_data here
629 * since we always can hold the chunk on the
630 * d-queue. And we have a finite number that
631 * can be delivered from the strq.
633 if (sctp_logging_level & SCTP_STR_LOGGING_ENABLE) {
634 sctp_log_strm_del(control, NULL,
635 SCTP_STR_LOG_FROM_IMMED_DEL);
637 sctp_add_to_readq(stcb->sctp_ep, stcb,
639 &stcb->sctp_socket->so_rcv, 1);
648 * Ok, we did not deliver this guy, find the correct place
649 * to put it on the queue.
651 if (TAILQ_EMPTY(&strm->inqueue)) {
653 if (sctp_logging_level & SCTP_STR_LOGGING_ENABLE) {
654 sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INSERT_HD);
656 TAILQ_INSERT_HEAD(&strm->inqueue, control, next);
658 TAILQ_FOREACH(at, &strm->inqueue, next) {
659 if (compare_with_wrap(at->sinfo_ssn,
660 control->sinfo_ssn, MAX_SEQ)) {
662 * one in queue is bigger than the
663 * new one, insert before this one
665 if (sctp_logging_level & SCTP_STR_LOGGING_ENABLE) {
666 sctp_log_strm_del(control, at,
667 SCTP_STR_LOG_FROM_INSERT_MD);
669 TAILQ_INSERT_BEFORE(at, control, next);
671 } else if (at->sinfo_ssn == control->sinfo_ssn) {
673 * Gak, He sent me a duplicate str
677 * foo bar, I guess I will just free
678 * this new guy, should we abort
679 * too? FIX ME MAYBE? Or it COULD be
680 * that the SSN's have wrapped.
681 * Maybe I should compare to TSN
682 * somehow... sigh for now just blow
687 sctp_m_freem(control->data);
688 control->data = NULL;
689 asoc->size_on_all_streams -= control->length;
690 sctp_ucount_decr(asoc->cnt_on_all_streams);
691 if (control->whoFrom)
692 sctp_free_remote_addr(control->whoFrom);
693 control->whoFrom = NULL;
694 sctp_free_a_readq(stcb, control);
697 if (TAILQ_NEXT(at, next) == NULL) {
699 * We are at the end, insert
702 if (sctp_logging_level & SCTP_STR_LOGGING_ENABLE) {
703 sctp_log_strm_del(control, at,
704 SCTP_STR_LOG_FROM_INSERT_TL);
706 TAILQ_INSERT_AFTER(&strm->inqueue,
717 * Returns two things: You get the total size of the deliverable parts of the
718 * first fragmented message on the reassembly queue. And you get a 1 back if
719 * all of the message is ready or a 0 back if the message is still incomplete
722 sctp_is_all_msg_on_reasm(struct sctp_association *asoc, uint32_t * t_size)
724 struct sctp_tmit_chunk *chk;
728 chk = TAILQ_FIRST(&asoc->reasmqueue);
730 /* nothing on the queue */
733 if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) {
734 /* Not a first on the queue */
737 tsn = chk->rec.data.TSN_seq;
739 if (tsn != chk->rec.data.TSN_seq) {
742 *t_size += chk->send_size;
743 if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
747 chk = TAILQ_NEXT(chk, sctp_next);
753 sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc)
755 struct sctp_tmit_chunk *chk;
760 chk = TAILQ_FIRST(&asoc->reasmqueue);
763 asoc->size_on_reasm_queue = 0;
764 asoc->cnt_on_reasm_queue = 0;
767 if (asoc->fragmented_delivery_inprogress == 0) {
769 asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1;
770 if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) &&
771 (nxt_todel == chk->rec.data.stream_seq ||
772 (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) {
774 * Yep the first one is here and its ok to deliver
777 if ((sctp_is_all_msg_on_reasm(asoc, &tsize) ||
778 (tsize > stcb->sctp_ep->partial_delivery_point))) {
781 * Yes, we setup to start reception, by
782 * backing down the TSN just in case we
783 * can't deliver. If we
785 asoc->fragmented_delivery_inprogress = 1;
786 asoc->tsn_last_delivered =
787 chk->rec.data.TSN_seq - 1;
789 chk->rec.data.stream_number;
790 asoc->ssn_of_pdapi = chk->rec.data.stream_seq;
791 asoc->pdapi_ppid = chk->rec.data.payloadtype;
792 asoc->fragment_flags = chk->rec.data.rcv_flags;
793 sctp_service_reassembly(stcb, asoc);
798 * Service re-assembly will deliver stream data queued at
799 * the end of fragmented delivery.. but it wont know to go
800 * back and call itself again... we do that here with the
803 sctp_service_reassembly(stcb, asoc);
804 if (asoc->fragmented_delivery_inprogress == 0) {
806 * finished our Fragmented delivery, could be more
815 * Dump onto the re-assembly queue, in its proper place. After dumping on the
816 * queue, see if anthing can be delivered. If so pull it off (or as much as
817 * we can. If we run out of space then we must dump what we can and set the
818 * appropriate flag to say we queued what we could.
821 sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
822 struct sctp_tmit_chunk *chk, int *abort_flag)
825 uint32_t cum_ackp1, last_tsn, prev_tsn, post_tsn;
827 struct sctp_tmit_chunk *at, *prev, *next;
830 cum_ackp1 = asoc->tsn_last_delivered + 1;
831 if (TAILQ_EMPTY(&asoc->reasmqueue)) {
832 /* This is the first one on the queue */
833 TAILQ_INSERT_HEAD(&asoc->reasmqueue, chk, sctp_next);
835 * we do not check for delivery of anything when only one
838 asoc->size_on_reasm_queue = chk->send_size;
839 sctp_ucount_incr(asoc->cnt_on_reasm_queue);
840 if (chk->rec.data.TSN_seq == cum_ackp1) {
841 if (asoc->fragmented_delivery_inprogress == 0 &&
842 (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) !=
843 SCTP_DATA_FIRST_FRAG) {
845 * An empty queue, no delivery inprogress,
846 * we hit the next one and it does NOT have
847 * a FIRST fragment mark.
849 SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not first, no fragmented delivery in progress\n");
850 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
851 0, M_DONTWAIT, 1, MT_DATA);
854 struct sctp_paramhdr *ph;
858 sizeof(struct sctp_paramhdr) +
859 (sizeof(uint32_t) * 3);
860 ph = mtod(oper, struct sctp_paramhdr *);
862 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
863 ph->param_length = htons(SCTP_BUF_LEN(oper));
864 ippp = (uint32_t *) (ph + 1);
865 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_2);
867 *ippp = chk->rec.data.TSN_seq;
869 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
872 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2;
873 sctp_abort_an_association(stcb->sctp_ep, stcb,
874 SCTP_PEER_FAULTY, oper);
876 } else if (asoc->fragmented_delivery_inprogress &&
877 (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) {
879 * We are doing a partial delivery and the
880 * NEXT chunk MUST be either the LAST or
881 * MIDDLE fragment NOT a FIRST
883 SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS a first and fragmented delivery in progress\n");
884 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
885 0, M_DONTWAIT, 1, MT_DATA);
887 struct sctp_paramhdr *ph;
891 sizeof(struct sctp_paramhdr) +
892 (3 * sizeof(uint32_t));
893 ph = mtod(oper, struct sctp_paramhdr *);
895 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
896 ph->param_length = htons(SCTP_BUF_LEN(oper));
897 ippp = (uint32_t *) (ph + 1);
898 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_3);
900 *ippp = chk->rec.data.TSN_seq;
902 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
904 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_3;
905 sctp_abort_an_association(stcb->sctp_ep, stcb,
906 SCTP_PEER_FAULTY, oper);
908 } else if (asoc->fragmented_delivery_inprogress) {
910 * Here we are ok with a MIDDLE or LAST
913 if (chk->rec.data.stream_number !=
914 asoc->str_of_pdapi) {
915 /* Got to be the right STR No */
916 SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream number %d vs %d\n",
917 chk->rec.data.stream_number,
919 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
920 0, M_DONTWAIT, 1, MT_DATA);
922 struct sctp_paramhdr *ph;
926 sizeof(struct sctp_paramhdr) +
927 (sizeof(uint32_t) * 3);
929 struct sctp_paramhdr *);
931 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
933 htons(SCTP_BUF_LEN(oper));
934 ippp = (uint32_t *) (ph + 1);
935 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_4);
937 *ippp = chk->rec.data.TSN_seq;
939 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
941 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_4;
942 sctp_abort_an_association(stcb->sctp_ep,
943 stcb, SCTP_PEER_FAULTY, oper);
945 } else if ((asoc->fragment_flags & SCTP_DATA_UNORDERED) !=
946 SCTP_DATA_UNORDERED &&
947 chk->rec.data.stream_seq !=
948 asoc->ssn_of_pdapi) {
949 /* Got to be the right STR Seq */
950 SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream seq %d vs %d\n",
951 chk->rec.data.stream_seq,
953 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
954 0, M_DONTWAIT, 1, MT_DATA);
956 struct sctp_paramhdr *ph;
960 sizeof(struct sctp_paramhdr) +
961 (3 * sizeof(uint32_t));
963 struct sctp_paramhdr *);
965 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
967 htons(SCTP_BUF_LEN(oper));
968 ippp = (uint32_t *) (ph + 1);
969 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_5);
971 *ippp = chk->rec.data.TSN_seq;
973 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
976 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_5;
977 sctp_abort_an_association(stcb->sctp_ep,
978 stcb, SCTP_PEER_FAULTY, oper);
986 TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) {
987 if (compare_with_wrap(at->rec.data.TSN_seq,
988 chk->rec.data.TSN_seq, MAX_TSN)) {
990 * one in queue is bigger than the new one, insert
994 asoc->size_on_reasm_queue += chk->send_size;
995 sctp_ucount_incr(asoc->cnt_on_reasm_queue);
997 TAILQ_INSERT_BEFORE(at, chk, sctp_next);
999 } else if (at->rec.data.TSN_seq == chk->rec.data.TSN_seq) {
1000 /* Gak, He sent me a duplicate str seq number */
1002 * foo bar, I guess I will just free this new guy,
1003 * should we abort too? FIX ME MAYBE? Or it COULD be
1004 * that the SSN's have wrapped. Maybe I should
1005 * compare to TSN somehow... sigh for now just blow
1009 sctp_m_freem(chk->data);
1012 sctp_free_a_chunk(stcb, chk);
1015 last_flags = at->rec.data.rcv_flags;
1016 last_tsn = at->rec.data.TSN_seq;
1018 if (TAILQ_NEXT(at, sctp_next) == NULL) {
1020 * We are at the end, insert it after this
1023 /* check it first */
1024 asoc->size_on_reasm_queue += chk->send_size;
1025 sctp_ucount_incr(asoc->cnt_on_reasm_queue);
1026 TAILQ_INSERT_AFTER(&asoc->reasmqueue, at, chk, sctp_next);
1031 /* Now the audits */
1033 prev_tsn = chk->rec.data.TSN_seq - 1;
1034 if (prev_tsn == prev->rec.data.TSN_seq) {
1036 * Ok the one I am dropping onto the end is the
1037 * NEXT. A bit of valdiation here.
1039 if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1040 SCTP_DATA_FIRST_FRAG ||
1041 (prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1042 SCTP_DATA_MIDDLE_FRAG) {
1044 * Insert chk MUST be a MIDDLE or LAST
1047 if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1048 SCTP_DATA_FIRST_FRAG) {
1049 SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - It can be a midlle or last but not a first\n");
1050 SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it's a FIRST!\n");
1051 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1052 0, M_DONTWAIT, 1, MT_DATA);
1054 struct sctp_paramhdr *ph;
1057 SCTP_BUF_LEN(oper) =
1058 sizeof(struct sctp_paramhdr) +
1059 (3 * sizeof(uint32_t));
1061 struct sctp_paramhdr *);
1063 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1065 htons(SCTP_BUF_LEN(oper));
1066 ippp = (uint32_t *) (ph + 1);
1067 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_6);
1069 *ippp = chk->rec.data.TSN_seq;
1071 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
1074 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_6;
1075 sctp_abort_an_association(stcb->sctp_ep,
1076 stcb, SCTP_PEER_FAULTY, oper);
1080 if (chk->rec.data.stream_number !=
1081 prev->rec.data.stream_number) {
1083 * Huh, need the correct STR here,
1084 * they must be the same.
1086 SCTP_PRINTF("Prev check - Gak, Evil plot, ssn:%d not the same as at:%d\n",
1087 chk->rec.data.stream_number,
1088 prev->rec.data.stream_number);
1089 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1090 0, M_DONTWAIT, 1, MT_DATA);
1092 struct sctp_paramhdr *ph;
1095 SCTP_BUF_LEN(oper) =
1096 sizeof(struct sctp_paramhdr) +
1097 (3 * sizeof(uint32_t));
1099 struct sctp_paramhdr *);
1101 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1103 htons(SCTP_BUF_LEN(oper));
1104 ippp = (uint32_t *) (ph + 1);
1105 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_7);
1107 *ippp = chk->rec.data.TSN_seq;
1109 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
1111 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_7;
1112 sctp_abort_an_association(stcb->sctp_ep,
1113 stcb, SCTP_PEER_FAULTY, oper);
1118 if ((prev->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 &&
1119 chk->rec.data.stream_seq !=
1120 prev->rec.data.stream_seq) {
1122 * Huh, need the correct STR here,
1123 * they must be the same.
1125 SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, Evil plot, sseq:%d not the same as at:%d\n",
1126 chk->rec.data.stream_seq,
1127 prev->rec.data.stream_seq);
1128 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1129 0, M_DONTWAIT, 1, MT_DATA);
1131 struct sctp_paramhdr *ph;
1134 SCTP_BUF_LEN(oper) =
1135 sizeof(struct sctp_paramhdr) +
1136 (3 * sizeof(uint32_t));
1138 struct sctp_paramhdr *);
1140 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1142 htons(SCTP_BUF_LEN(oper));
1143 ippp = (uint32_t *) (ph + 1);
1144 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_8);
1146 *ippp = chk->rec.data.TSN_seq;
1148 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
1150 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_8;
1151 sctp_abort_an_association(stcb->sctp_ep,
1152 stcb, SCTP_PEER_FAULTY, oper);
1157 } else if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1158 SCTP_DATA_LAST_FRAG) {
1159 /* Insert chk MUST be a FIRST */
1160 if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
1161 SCTP_DATA_FIRST_FRAG) {
1162 SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, evil plot, its not FIRST and it must be!\n");
1163 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1164 0, M_DONTWAIT, 1, MT_DATA);
1166 struct sctp_paramhdr *ph;
1169 SCTP_BUF_LEN(oper) =
1170 sizeof(struct sctp_paramhdr) +
1171 (3 * sizeof(uint32_t));
1173 struct sctp_paramhdr *);
1175 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1177 htons(SCTP_BUF_LEN(oper));
1178 ippp = (uint32_t *) (ph + 1);
1179 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_9);
1181 *ippp = chk->rec.data.TSN_seq;
1183 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
1186 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_9;
1187 sctp_abort_an_association(stcb->sctp_ep,
1188 stcb, SCTP_PEER_FAULTY, oper);
1197 post_tsn = chk->rec.data.TSN_seq + 1;
1198 if (post_tsn == next->rec.data.TSN_seq) {
1200 * Ok the one I am inserting ahead of is my NEXT
1201 * one. A bit of valdiation here.
1203 if (next->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
1204 /* Insert chk MUST be a last fragment */
1205 if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK)
1206 != SCTP_DATA_LAST_FRAG) {
1207 SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is FIRST, we must be LAST\n");
1208 SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not a last!\n");
1209 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1210 0, M_DONTWAIT, 1, MT_DATA);
1212 struct sctp_paramhdr *ph;
1215 SCTP_BUF_LEN(oper) =
1216 sizeof(struct sctp_paramhdr) +
1217 (3 * sizeof(uint32_t));
1219 struct sctp_paramhdr *);
1221 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1223 htons(SCTP_BUF_LEN(oper));
1224 ippp = (uint32_t *) (ph + 1);
1225 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_10);
1227 *ippp = chk->rec.data.TSN_seq;
1229 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
1231 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_10;
1232 sctp_abort_an_association(stcb->sctp_ep,
1233 stcb, SCTP_PEER_FAULTY, oper);
1238 } else if ((next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1239 SCTP_DATA_MIDDLE_FRAG ||
1240 (next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1241 SCTP_DATA_LAST_FRAG) {
1243 * Insert chk CAN be MIDDLE or FIRST NOT
1246 if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
1247 SCTP_DATA_LAST_FRAG) {
1248 SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is a MIDDLE/LAST\n");
1249 SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, new prev chunk is a LAST\n");
1250 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1251 0, M_DONTWAIT, 1, MT_DATA);
1253 struct sctp_paramhdr *ph;
1256 SCTP_BUF_LEN(oper) =
1257 sizeof(struct sctp_paramhdr) +
1258 (3 * sizeof(uint32_t));
1260 struct sctp_paramhdr *);
1262 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1264 htons(SCTP_BUF_LEN(oper));
1265 ippp = (uint32_t *) (ph + 1);
1266 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_11);
1268 *ippp = chk->rec.data.TSN_seq;
1270 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
1273 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_11;
1274 sctp_abort_an_association(stcb->sctp_ep,
1275 stcb, SCTP_PEER_FAULTY, oper);
1280 if (chk->rec.data.stream_number !=
1281 next->rec.data.stream_number) {
1283 * Huh, need the correct STR here,
1284 * they must be the same.
1286 SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, ssn:%d not the same as at:%d\n",
1287 chk->rec.data.stream_number,
1288 next->rec.data.stream_number);
1289 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1290 0, M_DONTWAIT, 1, MT_DATA);
1292 struct sctp_paramhdr *ph;
1295 SCTP_BUF_LEN(oper) =
1296 sizeof(struct sctp_paramhdr) +
1297 (3 * sizeof(uint32_t));
1299 struct sctp_paramhdr *);
1301 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1303 htons(SCTP_BUF_LEN(oper));
1304 ippp = (uint32_t *) (ph + 1);
1305 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_12);
1307 *ippp = chk->rec.data.TSN_seq;
1309 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
1312 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_12;
1313 sctp_abort_an_association(stcb->sctp_ep,
1314 stcb, SCTP_PEER_FAULTY, oper);
1319 if ((next->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 &&
1320 chk->rec.data.stream_seq !=
1321 next->rec.data.stream_seq) {
1323 * Huh, need the correct STR here,
1324 * they must be the same.
1326 SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, sseq:%d not the same as at:%d\n",
1327 chk->rec.data.stream_seq,
1328 next->rec.data.stream_seq);
1329 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1330 0, M_DONTWAIT, 1, MT_DATA);
1332 struct sctp_paramhdr *ph;
1335 SCTP_BUF_LEN(oper) =
1336 sizeof(struct sctp_paramhdr) +
1337 (3 * sizeof(uint32_t));
1339 struct sctp_paramhdr *);
1341 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1343 htons(SCTP_BUF_LEN(oper));
1344 ippp = (uint32_t *) (ph + 1);
1345 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_13);
1347 *ippp = chk->rec.data.TSN_seq;
1349 *ippp = ((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq);
1351 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_13;
1352 sctp_abort_an_association(stcb->sctp_ep,
1353 stcb, SCTP_PEER_FAULTY, oper);
1362 /* Do we need to do some delivery? check */
1363 sctp_deliver_reasm_check(stcb, asoc);
1367 * This is an unfortunate routine. It checks to make sure a evil guy is not
1368 * stuffing us full of bad packet fragments. A broken peer could also do this
1369 * but this is doubtful. It is to bad I must worry about evil crackers sigh
1373 sctp_does_tsn_belong_to_reasm(struct sctp_association *asoc,
1376 struct sctp_tmit_chunk *at;
1379 TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) {
1380 if (compare_with_wrap(TSN_seq,
1381 at->rec.data.TSN_seq, MAX_TSN)) {
1382 /* is it one bigger? */
1383 tsn_est = at->rec.data.TSN_seq + 1;
1384 if (tsn_est == TSN_seq) {
1385 /* yep. It better be a last then */
1386 if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
1387 SCTP_DATA_LAST_FRAG) {
1389 * Ok this guy belongs next to a guy
1390 * that is NOT last, it should be a
1391 * middle/last, not a complete
1397 * This guy is ok since its a LAST
1398 * and the new chunk is a fully
1399 * self- contained one.
1404 } else if (TSN_seq == at->rec.data.TSN_seq) {
1405 /* Software error since I have a dup? */
1409 * Ok, 'at' is larger than new chunk but does it
1410 * need to be right before it.
1412 tsn_est = TSN_seq + 1;
1413 if (tsn_est == at->rec.data.TSN_seq) {
1414 /* Yep, It better be a first */
1415 if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
1416 SCTP_DATA_FIRST_FRAG) {
1429 sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
1430 struct mbuf **m, int offset, struct sctp_data_chunk *ch, int chk_length,
1431 struct sctp_nets *net, uint32_t * high_tsn, int *abort_flag,
1432 int *break_flag, int last_chunk)
1434 /* Process a data chunk */
1435 /* struct sctp_tmit_chunk *chk; */
1436 struct sctp_tmit_chunk *chk;
1440 int need_reasm_check = 0;
1441 uint16_t strmno, strmseq;
1443 struct sctp_queued_to_read *control;
1445 uint32_t protocol_id;
1446 uint8_t chunk_flags;
1447 struct sctp_stream_reset_list *liste;
1450 tsn = ntohl(ch->dp.tsn);
1451 chunk_flags = ch->ch.chunk_flags;
1452 protocol_id = ch->dp.protocol_id;
1453 ordered = ((ch->ch.chunk_flags & SCTP_DATA_UNORDERED) == 0);
1454 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
1455 sctp_log_map(0, tsn, asoc->cumulative_tsn, SCTP_MAP_PREPARE_SLIDE);
1460 SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, ch->ch.chunk_type, tsn);
1461 if (compare_with_wrap(asoc->cumulative_tsn, tsn, MAX_TSN) ||
1462 asoc->cumulative_tsn == tsn) {
1463 /* It is a duplicate */
1464 SCTP_STAT_INCR(sctps_recvdupdata);
1465 if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) {
1466 /* Record a dup for the next outbound sack */
1467 asoc->dup_tsns[asoc->numduptsns] = tsn;
1472 /* Calculate the number of TSN's between the base and this TSN */
1473 if (tsn >= asoc->mapping_array_base_tsn) {
1474 gap = tsn - asoc->mapping_array_base_tsn;
1476 gap = (MAX_TSN - asoc->mapping_array_base_tsn) + tsn + 1;
1478 if (gap >= (SCTP_MAPPING_ARRAY << 3)) {
1479 /* Can't hold the bit in the mapping at max array, toss it */
1482 if (gap >= (uint32_t) (asoc->mapping_array_size << 3)) {
1483 SCTP_TCB_LOCK_ASSERT(stcb);
1484 if (sctp_expand_mapping_array(asoc, gap)) {
1485 /* Can't expand, drop it */
1489 if (compare_with_wrap(tsn, *high_tsn, MAX_TSN)) {
1492 /* See if we have received this one already */
1493 if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) {
1494 SCTP_STAT_INCR(sctps_recvdupdata);
1495 if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) {
1496 /* Record a dup for the next outbound sack */
1497 asoc->dup_tsns[asoc->numduptsns] = tsn;
1500 asoc->send_sack = 1;
1504 * Check to see about the GONE flag, duplicates would cause a sack
1505 * to be sent up above
1507 if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
1508 (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1509 (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET))
1512 * wait a minute, this guy is gone, there is no longer a
1513 * receiver. Send peer an ABORT!
1515 struct mbuf *op_err;
1517 op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC);
1518 sctp_abort_an_association(stcb->sctp_ep, stcb, 0, op_err);
1523 * Now before going further we see if there is room. If NOT then we
1524 * MAY let one through only IF this TSN is the one we are waiting
1525 * for on a partial delivery API.
1528 /* now do the tests */
1529 if (((asoc->cnt_on_all_streams +
1530 asoc->cnt_on_reasm_queue +
1531 asoc->cnt_msg_on_sb) > sctp_max_chunks_on_queue) ||
1532 (((int)asoc->my_rwnd) <= 0)) {
1534 * When we have NO room in the rwnd we check to make sure
1535 * the reader is doing its job...
1537 if (stcb->sctp_socket->so_rcv.sb_cc) {
1538 /* some to read, wake-up */
1539 sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
1541 /* now is it in the mapping array of what we have accepted? */
1542 if (compare_with_wrap(tsn,
1543 asoc->highest_tsn_inside_map, MAX_TSN)) {
1545 /* Nope not in the valid range dump it */
1546 SCTPDBG(SCTP_DEBUG_INDATA1, "My rwnd overrun1:tsn:%lx rwnd %lu sbspace:%ld\n",
1547 (u_long)tsn, (u_long)asoc->my_rwnd,
1548 sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv));
1549 sctp_set_rwnd(stcb, asoc);
1550 if ((asoc->cnt_on_all_streams +
1551 asoc->cnt_on_reasm_queue +
1552 asoc->cnt_msg_on_sb) > sctp_max_chunks_on_queue) {
1553 SCTP_STAT_INCR(sctps_datadropchklmt);
1555 SCTP_STAT_INCR(sctps_datadroprwnd);
1562 strmno = ntohs(ch->dp.stream_id);
1563 if (strmno >= asoc->streamincnt) {
1564 struct sctp_paramhdr *phdr;
1567 mb = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) * 2),
1568 0, M_DONTWAIT, 1, MT_DATA);
1570 /* add some space up front so prepend will work well */
1571 SCTP_BUF_RESV_UF(mb, sizeof(struct sctp_chunkhdr));
1572 phdr = mtod(mb, struct sctp_paramhdr *);
1574 * Error causes are just param's and this one has
1575 * two back to back phdr, one with the error type
1576 * and size, the other with the streamid and a rsvd
1578 SCTP_BUF_LEN(mb) = (sizeof(struct sctp_paramhdr) * 2);
1579 phdr->param_type = htons(SCTP_CAUSE_INVALID_STREAM);
1580 phdr->param_length =
1581 htons(sizeof(struct sctp_paramhdr) * 2);
1583 /* We insert the stream in the type field */
1584 phdr->param_type = ch->dp.stream_id;
1585 /* And set the length to 0 for the rsvd field */
1586 phdr->param_length = 0;
1587 sctp_queue_op_err(stcb, mb);
1589 SCTP_STAT_INCR(sctps_badsid);
1590 SCTP_TCB_LOCK_ASSERT(stcb);
1591 SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap);
1592 if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) {
1593 /* we have a new high score */
1594 asoc->highest_tsn_inside_map = tsn;
1595 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
1596 sctp_log_map(0, 2, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
1599 if (tsn == (asoc->cumulative_tsn + 1)) {
1600 /* Update cum-ack */
1601 asoc->cumulative_tsn = tsn;
1606 * Before we continue lets validate that we are not being fooled by
1607 * an evil attacker. We can only have 4k chunks based on our TSN
1608 * spread allowed by the mapping array 512 * 8 bits, so there is no
1609 * way our stream sequence numbers could have wrapped. We of course
1610 * only validate the FIRST fragment so the bit must be set.
1612 strmseq = ntohs(ch->dp.stream_sequence);
1613 #ifdef SCTP_ASOCLOG_OF_TSNS
1614 SCTP_TCB_LOCK_ASSERT(stcb);
1615 if (asoc->tsn_in_at >= SCTP_TSN_LOG_SIZE) {
1616 asoc->tsn_in_at = 0;
1617 asoc->tsn_in_wrapped = 1;
1619 asoc->in_tsnlog[asoc->tsn_in_at].tsn = tsn;
1620 asoc->in_tsnlog[asoc->tsn_in_at].strm = strmno;
1621 asoc->in_tsnlog[asoc->tsn_in_at].seq = strmseq;
1622 asoc->in_tsnlog[asoc->tsn_in_at].sz = chk_length;
1623 asoc->in_tsnlog[asoc->tsn_in_at].flgs = chunk_flags;
1624 asoc->in_tsnlog[asoc->tsn_in_at].stcb = (void *)stcb;
1625 asoc->in_tsnlog[asoc->tsn_in_at].in_pos = asoc->tsn_in_at;
1626 asoc->in_tsnlog[asoc->tsn_in_at].in_out = 1;
1629 if ((chunk_flags & SCTP_DATA_FIRST_FRAG) &&
1630 (TAILQ_EMPTY(&asoc->resetHead)) &&
1631 (chunk_flags & SCTP_DATA_UNORDERED) == 0 &&
1632 (compare_with_wrap(asoc->strmin[strmno].last_sequence_delivered,
1633 strmseq, MAX_SEQ) ||
1634 asoc->strmin[strmno].last_sequence_delivered == strmseq)) {
1635 /* The incoming sseq is behind where we last delivered? */
1636 SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ:%d delivered:%d from peer, Abort!\n",
1637 strmseq, asoc->strmin[strmno].last_sequence_delivered);
1638 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1639 0, M_DONTWAIT, 1, MT_DATA);
1641 struct sctp_paramhdr *ph;
1644 SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) +
1645 (3 * sizeof(uint32_t));
1646 ph = mtod(oper, struct sctp_paramhdr *);
1647 ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1648 ph->param_length = htons(SCTP_BUF_LEN(oper));
1649 ippp = (uint32_t *) (ph + 1);
1650 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_14);
1654 *ippp = ((strmno << 16) | strmseq);
1657 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_14;
1658 sctp_abort_an_association(stcb->sctp_ep, stcb,
1659 SCTP_PEER_FAULTY, oper);
1663 /************************************
1664 * From here down we may find ch-> invalid
1665 * so its a good idea NOT to use it.
1666 *************************************/
1668 the_len = (chk_length - sizeof(struct sctp_data_chunk));
1669 if (last_chunk == 0) {
1670 dmbuf = SCTP_M_COPYM(*m,
1671 (offset + sizeof(struct sctp_data_chunk)),
1672 the_len, M_DONTWAIT);
1673 #ifdef SCTP_MBUF_LOGGING
1674 if (sctp_logging_level & SCTP_MBUF_LOGGING_ENABLE) {
1679 if (SCTP_BUF_IS_EXTENDED(mat)) {
1680 sctp_log_mb(mat, SCTP_MBUF_ICOPY);
1682 mat = SCTP_BUF_NEXT(mat);
1687 /* We can steal the last chunk */
1691 /* lop off the top part */
1692 m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk)));
1693 if (SCTP_BUF_NEXT(dmbuf) == NULL) {
1694 l_len = SCTP_BUF_LEN(dmbuf);
1697 * need to count up the size hopefully does not hit
1705 l_len += SCTP_BUF_LEN(lat);
1706 lat = SCTP_BUF_NEXT(lat);
1709 if (l_len > the_len) {
1710 /* Trim the end round bytes off too */
1711 m_adj(dmbuf, -(l_len - the_len));
1714 if (dmbuf == NULL) {
1715 SCTP_STAT_INCR(sctps_nomem);
1718 if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG &&
1719 asoc->fragmented_delivery_inprogress == 0 &&
1720 TAILQ_EMPTY(&asoc->resetHead) &&
1722 ((asoc->strmin[strmno].last_sequence_delivered + 1) == strmseq &&
1723 TAILQ_EMPTY(&asoc->strmin[strmno].inqueue)))) {
1724 /* Candidate for express delivery */
1726 * Its not fragmented, No PD-API is up, Nothing in the
1727 * delivery queue, Its un-ordered OR ordered and the next to
1728 * deliver AND nothing else is stuck on the stream queue,
1729 * And there is room for it in the socket buffer. Lets just
1730 * stuff it up the buffer....
1733 /* It would be nice to avoid this copy if we could :< */
1734 sctp_alloc_a_readq(stcb, control);
1735 sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn,
1741 if (control == NULL) {
1742 goto failed_express_del;
1744 sctp_add_to_readq(stcb->sctp_ep, stcb, control, &stcb->sctp_socket->so_rcv, 1);
1745 if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) {
1746 /* for ordered, bump what we delivered */
1747 asoc->strmin[strmno].last_sequence_delivered++;
1749 SCTP_STAT_INCR(sctps_recvexpress);
1750 if (sctp_logging_level & SCTP_STR_LOGGING_ENABLE) {
1751 sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno,
1752 SCTP_STR_LOG_FROM_EXPRS_DEL);
1755 goto finish_express_del;
1758 /* If we reach here this is a new chunk */
1761 /* Express for fragmented delivery? */
1762 if ((asoc->fragmented_delivery_inprogress) &&
1763 (stcb->asoc.control_pdapi) &&
1764 (asoc->str_of_pdapi == strmno) &&
1765 (asoc->ssn_of_pdapi == strmseq)
1767 control = stcb->asoc.control_pdapi;
1768 if ((chunk_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) {
1769 /* Can't be another first? */
1770 goto failed_pdapi_express_del;
1772 if (tsn == (control->sinfo_tsn + 1)) {
1773 /* Yep, we can add it on */
1777 if (chunk_flags & SCTP_DATA_LAST_FRAG) {
1780 cumack = asoc->cumulative_tsn;
1781 if ((cumack + 1) == tsn)
1784 if (sctp_append_to_readq(stcb->sctp_ep, stcb, control, dmbuf, end,
1786 &stcb->sctp_socket->so_rcv)) {
1787 SCTP_PRINTF("Append fails end:%d\n", end);
1788 goto failed_pdapi_express_del;
1790 SCTP_STAT_INCR(sctps_recvexpressm);
1791 control->sinfo_tsn = tsn;
1792 asoc->tsn_last_delivered = tsn;
1793 asoc->fragment_flags = chunk_flags;
1794 asoc->tsn_of_pdapi_last_delivered = tsn;
1795 asoc->last_flags_delivered = chunk_flags;
1796 asoc->last_strm_seq_delivered = strmseq;
1797 asoc->last_strm_no_delivered = strmno;
1799 /* clean up the flags and such */
1800 asoc->fragmented_delivery_inprogress = 0;
1801 if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) {
1802 asoc->strmin[strmno].last_sequence_delivered++;
1804 stcb->asoc.control_pdapi = NULL;
1805 if (TAILQ_EMPTY(&asoc->reasmqueue) == 0) {
1807 * There could be another message
1810 need_reasm_check = 1;
1814 goto finish_express_del;
1817 failed_pdapi_express_del:
1819 if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) {
1820 sctp_alloc_a_chunk(stcb, chk);
1822 /* No memory so we drop the chunk */
1823 SCTP_STAT_INCR(sctps_nomem);
1824 if (last_chunk == 0) {
1825 /* we copied it, free the copy */
1826 sctp_m_freem(dmbuf);
1830 chk->rec.data.TSN_seq = tsn;
1831 chk->no_fr_allowed = 0;
1832 chk->rec.data.stream_seq = strmseq;
1833 chk->rec.data.stream_number = strmno;
1834 chk->rec.data.payloadtype = protocol_id;
1835 chk->rec.data.context = stcb->asoc.context;
1836 chk->rec.data.doing_fast_retransmit = 0;
1837 chk->rec.data.rcv_flags = chunk_flags;
1839 chk->send_size = the_len;
1841 atomic_add_int(&net->ref_count, 1);
1844 sctp_alloc_a_readq(stcb, control);
1845 sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn,
1851 if (control == NULL) {
1852 /* No memory so we drop the chunk */
1853 SCTP_STAT_INCR(sctps_nomem);
1854 if (last_chunk == 0) {
1855 /* we copied it, free the copy */
1856 sctp_m_freem(dmbuf);
1860 control->length = the_len;
1863 /* Mark it as received */
1864 /* Now queue it where it belongs */
1865 if (control != NULL) {
1866 /* First a sanity check */
1867 if (asoc->fragmented_delivery_inprogress) {
1869 * Ok, we have a fragmented delivery in progress if
1870 * this chunk is next to deliver OR belongs in our
1871 * view to the reassembly, the peer is evil or
1874 uint32_t estimate_tsn;
1876 estimate_tsn = asoc->tsn_last_delivered + 1;
1877 if (TAILQ_EMPTY(&asoc->reasmqueue) &&
1878 (estimate_tsn == control->sinfo_tsn)) {
1879 /* Evil/Broke peer */
1880 sctp_m_freem(control->data);
1881 control->data = NULL;
1882 if (control->whoFrom) {
1883 sctp_free_remote_addr(control->whoFrom);
1884 control->whoFrom = NULL;
1886 sctp_free_a_readq(stcb, control);
1887 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1888 0, M_DONTWAIT, 1, MT_DATA);
1890 struct sctp_paramhdr *ph;
1893 SCTP_BUF_LEN(oper) =
1894 sizeof(struct sctp_paramhdr) +
1895 (3 * sizeof(uint32_t));
1896 ph = mtod(oper, struct sctp_paramhdr *);
1898 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1899 ph->param_length = htons(SCTP_BUF_LEN(oper));
1900 ippp = (uint32_t *) (ph + 1);
1901 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_15);
1905 *ippp = ((strmno << 16) | strmseq);
1907 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_15;
1908 sctp_abort_an_association(stcb->sctp_ep, stcb,
1909 SCTP_PEER_FAULTY, oper);
1914 if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) {
1915 sctp_m_freem(control->data);
1916 control->data = NULL;
1917 if (control->whoFrom) {
1918 sctp_free_remote_addr(control->whoFrom);
1919 control->whoFrom = NULL;
1921 sctp_free_a_readq(stcb, control);
1923 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1924 0, M_DONTWAIT, 1, MT_DATA);
1926 struct sctp_paramhdr *ph;
1929 SCTP_BUF_LEN(oper) =
1930 sizeof(struct sctp_paramhdr) +
1931 (3 * sizeof(uint32_t));
1933 struct sctp_paramhdr *);
1935 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1937 htons(SCTP_BUF_LEN(oper));
1938 ippp = (uint32_t *) (ph + 1);
1939 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_16);
1943 *ippp = ((strmno << 16) | strmseq);
1945 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16;
1946 sctp_abort_an_association(stcb->sctp_ep,
1947 stcb, SCTP_PEER_FAULTY, oper);
1954 /* No PDAPI running */
1955 if (!TAILQ_EMPTY(&asoc->reasmqueue)) {
1957 * Reassembly queue is NOT empty validate
1958 * that this tsn does not need to be in
1959 * reasembly queue. If it does then our peer
1960 * is broken or evil.
1962 if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) {
1963 sctp_m_freem(control->data);
1964 control->data = NULL;
1965 if (control->whoFrom) {
1966 sctp_free_remote_addr(control->whoFrom);
1967 control->whoFrom = NULL;
1969 sctp_free_a_readq(stcb, control);
1970 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
1971 0, M_DONTWAIT, 1, MT_DATA);
1973 struct sctp_paramhdr *ph;
1976 SCTP_BUF_LEN(oper) =
1977 sizeof(struct sctp_paramhdr) +
1978 (3 * sizeof(uint32_t));
1980 struct sctp_paramhdr *);
1982 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
1984 htons(SCTP_BUF_LEN(oper));
1985 ippp = (uint32_t *) (ph + 1);
1986 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_17);
1990 *ippp = ((strmno << 16) | strmseq);
1992 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_17;
1993 sctp_abort_an_association(stcb->sctp_ep,
1994 stcb, SCTP_PEER_FAULTY, oper);
2001 /* ok, if we reach here we have passed the sanity checks */
2002 if (chunk_flags & SCTP_DATA_UNORDERED) {
2003 /* queue directly into socket buffer */
2004 sctp_add_to_readq(stcb->sctp_ep, stcb,
2006 &stcb->sctp_socket->so_rcv, 1);
2009 * Special check for when streams are resetting. We
2010 * could be more smart about this and check the
2011 * actual stream to see if it is not being reset..
2012 * that way we would not create a HOLB when amongst
2013 * streams being reset and those not being reset.
2015 * We take complete messages that have a stream reset
2016 * intervening (aka the TSN is after where our
2017 * cum-ack needs to be) off and put them on a
2018 * pending_reply_queue. The reassembly ones we do
2019 * not have to worry about since they are all sorted
2020 * and proceessed by TSN order. It is only the
2021 * singletons I must worry about.
2023 if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) &&
2024 ((compare_with_wrap(tsn, liste->tsn, MAX_TSN)))
2027 * yep its past where we need to reset... go
2028 * ahead and queue it.
2030 if (TAILQ_EMPTY(&asoc->pending_reply_queue)) {
2032 TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next);
2034 struct sctp_queued_to_read *ctlOn;
2035 unsigned char inserted = 0;
2037 ctlOn = TAILQ_FIRST(&asoc->pending_reply_queue);
2039 if (compare_with_wrap(control->sinfo_tsn,
2040 ctlOn->sinfo_tsn, MAX_TSN)) {
2041 ctlOn = TAILQ_NEXT(ctlOn, next);
2044 TAILQ_INSERT_BEFORE(ctlOn, control, next);
2049 if (inserted == 0) {
2051 * must be put at end, use
2052 * prevP (all setup from
2053 * loop) to setup nextP.
2055 TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next);
2059 sctp_queue_data_to_stream(stcb, asoc, control, abort_flag);
2066 /* Into the re-assembly queue */
2067 sctp_queue_data_for_reasm(stcb, asoc, chk, abort_flag);
2070 * the assoc is now gone and chk was put onto the
2071 * reasm queue, which has all been freed.
2078 if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) {
2079 /* we have a new high score */
2080 asoc->highest_tsn_inside_map = tsn;
2081 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
2082 sctp_log_map(0, 2, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
2085 if (tsn == (asoc->cumulative_tsn + 1)) {
2086 /* Update cum-ack */
2087 asoc->cumulative_tsn = tsn;
2093 SCTP_STAT_INCR_COUNTER64(sctps_inorderchunks);
2095 SCTP_STAT_INCR_COUNTER64(sctps_inunorderchunks);
2097 SCTP_STAT_INCR(sctps_recvdata);
2098 /* Set it present please */
2099 if (sctp_logging_level & SCTP_STR_LOGGING_ENABLE) {
2100 sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, SCTP_STR_LOG_FROM_MARK_TSN);
2102 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
2103 sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn,
2104 asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE);
2106 SCTP_TCB_LOCK_ASSERT(stcb);
2107 SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap);
2108 /* check the special flag for stream resets */
2109 if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) &&
2110 ((compare_with_wrap(asoc->cumulative_tsn, liste->tsn, MAX_TSN)) ||
2111 (asoc->cumulative_tsn == liste->tsn))
2114 * we have finished working through the backlogged TSN's now
2115 * time to reset streams. 1: call reset function. 2: free
2116 * pending_reply space 3: distribute any chunks in
2117 * pending_reply_queue.
2119 struct sctp_queued_to_read *ctl;
2121 sctp_reset_in_stream(stcb, liste->number_entries, liste->req.list_of_streams);
2122 TAILQ_REMOVE(&asoc->resetHead, liste, next_resp);
2123 SCTP_FREE(liste, SCTP_M_STRESET);
2124 /* sa_ignore FREED_MEMORY */
2125 liste = TAILQ_FIRST(&asoc->resetHead);
2126 ctl = TAILQ_FIRST(&asoc->pending_reply_queue);
2127 if (ctl && (liste == NULL)) {
2128 /* All can be removed */
2130 TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next);
2131 sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag);
2135 ctl = TAILQ_FIRST(&asoc->pending_reply_queue);
2138 /* more than one in queue */
2139 while (!compare_with_wrap(ctl->sinfo_tsn, liste->tsn, MAX_TSN)) {
2141 * if ctl->sinfo_tsn is <= liste->tsn we can
2142 * process it which is the NOT of
2143 * ctl->sinfo_tsn > liste->tsn
2145 TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next);
2146 sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag);
2150 ctl = TAILQ_FIRST(&asoc->pending_reply_queue);
2154 * Now service re-assembly to pick up anything that has been
2155 * held on reassembly queue?
2157 sctp_deliver_reasm_check(stcb, asoc);
2158 need_reasm_check = 0;
2160 if (need_reasm_check) {
2161 /* Another one waits ? */
2162 sctp_deliver_reasm_check(stcb, asoc);
2167 int8_t sctp_map_lookup_tab[256] = {
2168 -1, 0, -1, 1, -1, 0, -1, 2,
2169 -1, 0, -1, 1, -1, 0, -1, 3,
2170 -1, 0, -1, 1, -1, 0, -1, 2,
2171 -1, 0, -1, 1, -1, 0, -1, 4,
2172 -1, 0, -1, 1, -1, 0, -1, 2,
2173 -1, 0, -1, 1, -1, 0, -1, 3,
2174 -1, 0, -1, 1, -1, 0, -1, 2,
2175 -1, 0, -1, 1, -1, 0, -1, 5,
2176 -1, 0, -1, 1, -1, 0, -1, 2,
2177 -1, 0, -1, 1, -1, 0, -1, 3,
2178 -1, 0, -1, 1, -1, 0, -1, 2,
2179 -1, 0, -1, 1, -1, 0, -1, 4,
2180 -1, 0, -1, 1, -1, 0, -1, 2,
2181 -1, 0, -1, 1, -1, 0, -1, 3,
2182 -1, 0, -1, 1, -1, 0, -1, 2,
2183 -1, 0, -1, 1, -1, 0, -1, 6,
2184 -1, 0, -1, 1, -1, 0, -1, 2,
2185 -1, 0, -1, 1, -1, 0, -1, 3,
2186 -1, 0, -1, 1, -1, 0, -1, 2,
2187 -1, 0, -1, 1, -1, 0, -1, 4,
2188 -1, 0, -1, 1, -1, 0, -1, 2,
2189 -1, 0, -1, 1, -1, 0, -1, 3,
2190 -1, 0, -1, 1, -1, 0, -1, 2,
2191 -1, 0, -1, 1, -1, 0, -1, 5,
2192 -1, 0, -1, 1, -1, 0, -1, 2,
2193 -1, 0, -1, 1, -1, 0, -1, 3,
2194 -1, 0, -1, 1, -1, 0, -1, 2,
2195 -1, 0, -1, 1, -1, 0, -1, 4,
2196 -1, 0, -1, 1, -1, 0, -1, 2,
2197 -1, 0, -1, 1, -1, 0, -1, 3,
2198 -1, 0, -1, 1, -1, 0, -1, 2,
2199 -1, 0, -1, 1, -1, 0, -1, 7,
2204 sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort_flag)
2207 * Now we also need to check the mapping array in a couple of ways.
2208 * 1) Did we move the cum-ack point?
2210 struct sctp_association *asoc;
2212 int all_ones, last_all_ones = 0;
2213 int slide_from, slide_end, lgap, distance;
2214 uint32_t old_cumack, old_base, old_highest;
2215 unsigned char aux_array[64];
2221 old_cumack = asoc->cumulative_tsn;
2222 old_base = asoc->mapping_array_base_tsn;
2223 old_highest = asoc->highest_tsn_inside_map;
2224 if (asoc->mapping_array_size < 64)
2225 memcpy(aux_array, asoc->mapping_array,
2226 asoc->mapping_array_size);
2228 memcpy(aux_array, asoc->mapping_array, 64);
2231 * We could probably improve this a small bit by calculating the
2232 * offset of the current cum-ack as the starting point.
2236 for (i = 0; i < stcb->asoc.mapping_array_size; i++) {
2238 if (asoc->mapping_array[i] == 0xff) {
2242 /* there is a 0 bit */
2244 at += sctp_map_lookup_tab[asoc->mapping_array[i]];
2249 asoc->cumulative_tsn = asoc->mapping_array_base_tsn + (at - last_all_ones);
2250 /* at is one off, since in the table a embedded -1 is present */
2253 if (compare_with_wrap(asoc->cumulative_tsn,
2254 asoc->highest_tsn_inside_map,
2257 panic("huh, cumack greater than high-tsn in map");
2259 SCTP_PRINTF("huh, cumack greater than high-tsn in map - should panic?\n");
2260 asoc->highest_tsn_inside_map = asoc->cumulative_tsn;
2264 (asoc->cumulative_tsn == asoc->highest_tsn_inside_map && at >= 8)) {
2265 /* The complete array was completed by a single FR */
2266 /* higest becomes the cum-ack */
2269 asoc->cumulative_tsn = asoc->highest_tsn_inside_map;
2270 /* clear the array */
2272 clr = asoc->mapping_array_size;
2274 clr = (at >> 3) + 1;
2276 * this should be the allones case but just in case
2279 if (clr > asoc->mapping_array_size)
2280 clr = asoc->mapping_array_size;
2282 memset(asoc->mapping_array, 0, clr);
2283 /* base becomes one ahead of the cum-ack */
2284 asoc->mapping_array_base_tsn = asoc->cumulative_tsn + 1;
2285 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
2286 sctp_log_map(old_base, old_cumack, old_highest,
2287 SCTP_MAP_PREPARE_SLIDE);
2288 sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn,
2289 asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_CLEARED);
2291 } else if (at >= 8) {
2292 /* we can slide the mapping array down */
2293 /* Calculate the new byte postion we can move down */
2294 slide_from = at >> 3;
2296 * now calculate the ceiling of the move using our highest
2299 if (asoc->highest_tsn_inside_map >= asoc->mapping_array_base_tsn) {
2300 lgap = asoc->highest_tsn_inside_map -
2301 asoc->mapping_array_base_tsn;
2303 lgap = (MAX_TSN - asoc->mapping_array_base_tsn) +
2304 asoc->highest_tsn_inside_map + 1;
2306 slide_end = lgap >> 3;
2307 if (slide_end < slide_from) {
2308 panic("impossible slide");
2310 distance = (slide_end - slide_from) + 1;
2311 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
2312 sctp_log_map(old_base, old_cumack, old_highest,
2313 SCTP_MAP_PREPARE_SLIDE);
2314 sctp_log_map((uint32_t) slide_from, (uint32_t) slide_end,
2315 (uint32_t) lgap, SCTP_MAP_SLIDE_FROM);
2317 if (distance + slide_from > asoc->mapping_array_size ||
2320 * Here we do NOT slide forward the array so that
2321 * hopefully when more data comes in to fill it up
2322 * we will be able to slide it forward. Really I
2323 * don't think this should happen :-0
2326 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
2327 sctp_log_map((uint32_t) distance, (uint32_t) slide_from,
2328 (uint32_t) asoc->mapping_array_size,
2329 SCTP_MAP_SLIDE_NONE);
2334 for (ii = 0; ii < distance; ii++) {
2335 asoc->mapping_array[ii] =
2336 asoc->mapping_array[slide_from + ii];
2338 for (ii = distance; ii <= slide_end; ii++) {
2339 asoc->mapping_array[ii] = 0;
2341 asoc->mapping_array_base_tsn += (slide_from << 3);
2342 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
2343 sctp_log_map(asoc->mapping_array_base_tsn,
2344 asoc->cumulative_tsn, asoc->highest_tsn_inside_map,
2345 SCTP_MAP_SLIDE_RESULT);
2350 * Now we need to see if we need to queue a sack or just start the
2351 * timer (if allowed).
2354 if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) {
2356 * Ok special case, in SHUTDOWN-SENT case. here we
2357 * maker sure SACK timer is off and instead send a
2358 * SHUTDOWN and a SACK
2360 if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
2361 sctp_timer_stop(SCTP_TIMER_TYPE_RECV,
2362 stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_INDATA + SCTP_LOC_18);
2364 sctp_send_shutdown(stcb, stcb->asoc.primary_destination);
2365 sctp_send_sack(stcb);
2369 /* is there a gap now ? */
2370 is_a_gap = compare_with_wrap(stcb->asoc.highest_tsn_inside_map,
2371 stcb->asoc.cumulative_tsn, MAX_TSN);
2374 * CMT DAC algorithm: increase number of packets
2375 * received since last ack
2377 stcb->asoc.cmt_dac_pkts_rcvd++;
2379 if ((stcb->asoc.send_sack == 1) || /* We need to send a
2381 ((was_a_gap) && (is_a_gap == 0)) || /* was a gap, but no
2383 (stcb->asoc.numduptsns) || /* we have dup's */
2384 (is_a_gap) || /* is still a gap */
2385 (stcb->asoc.delayed_ack == 0) || /* Delayed sack disabled */
2386 (stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) /* hit limit of pkts */
2389 if ((sctp_cmt_on_off) && (sctp_cmt_use_dac) &&
2390 (stcb->asoc.send_sack == 0) &&
2391 (stcb->asoc.numduptsns == 0) &&
2392 (stcb->asoc.delayed_ack) &&
2393 (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer))) {
2396 * CMT DAC algorithm: With CMT,
2397 * delay acks even in the face of
2399 * reordering. Therefore, if acks that
2400 * do not have to be sent because of
2401 * the above reasons, will be
2402 * delayed. That is, acks that would
2403 * have been sent due to gap reports
2404 * will be delayed with DAC. Start
2405 * the delayed ack timer.
2407 sctp_timer_start(SCTP_TIMER_TYPE_RECV,
2408 stcb->sctp_ep, stcb, NULL);
2411 * Ok we must build a SACK since the
2412 * timer is pending, we got our
2413 * first packet OR there are gaps or
2416 (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer);
2417 sctp_send_sack(stcb);
2420 if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
2421 sctp_timer_start(SCTP_TIMER_TYPE_RECV,
2422 stcb->sctp_ep, stcb, NULL);
2430 sctp_service_queues(struct sctp_tcb *stcb, struct sctp_association *asoc)
2432 struct sctp_tmit_chunk *chk;
2436 if (asoc->fragmented_delivery_inprogress) {
2437 sctp_service_reassembly(stcb, asoc);
2439 /* Can we proceed further, i.e. the PD-API is complete */
2440 if (asoc->fragmented_delivery_inprogress) {
2445 * Now is there some other chunk I can deliver from the reassembly
2449 chk = TAILQ_FIRST(&asoc->reasmqueue);
2451 asoc->size_on_reasm_queue = 0;
2452 asoc->cnt_on_reasm_queue = 0;
2455 nxt_todel = asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1;
2456 if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) &&
2457 ((nxt_todel == chk->rec.data.stream_seq) ||
2458 (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) {
2460 * Yep the first one is here. We setup to start reception,
2461 * by backing down the TSN just in case we can't deliver.
2465 * Before we start though either all of the message should
2466 * be here or 1/4 the socket buffer max or nothing on the
2467 * delivery queue and something can be delivered.
2469 if ((sctp_is_all_msg_on_reasm(asoc, &tsize) ||
2470 (tsize > stcb->sctp_ep->partial_delivery_point))) {
2471 asoc->fragmented_delivery_inprogress = 1;
2472 asoc->tsn_last_delivered = chk->rec.data.TSN_seq - 1;
2473 asoc->str_of_pdapi = chk->rec.data.stream_number;
2474 asoc->ssn_of_pdapi = chk->rec.data.stream_seq;
2475 asoc->pdapi_ppid = chk->rec.data.payloadtype;
2476 asoc->fragment_flags = chk->rec.data.rcv_flags;
2477 sctp_service_reassembly(stcb, asoc);
2478 if (asoc->fragmented_delivery_inprogress == 0) {
2486 sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length,
2487 struct sctphdr *sh, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2488 struct sctp_nets *net, uint32_t * high_tsn)
2490 struct sctp_data_chunk *ch, chunk_buf;
2491 struct sctp_association *asoc;
2492 int num_chunks = 0; /* number of control chunks processed */
2494 int chk_length, break_flag, last_chunk;
2495 int abort_flag = 0, was_a_gap = 0;
2499 sctp_set_rwnd(stcb, &stcb->asoc);
2502 SCTP_TCB_LOCK_ASSERT(stcb);
2504 if (compare_with_wrap(stcb->asoc.highest_tsn_inside_map,
2505 stcb->asoc.cumulative_tsn, MAX_TSN)) {
2506 /* there was a gap before this data was processed */
2510 * setup where we got the last DATA packet from for any SACK that
2511 * may need to go out. Don't bump the net. This is done ONLY when a
2512 * chunk is assigned.
2514 asoc->last_data_chunk_from = net;
2517 * Now before we proceed we must figure out if this is a wasted
2518 * cluster... i.e. it is a small packet sent in and yet the driver
2519 * underneath allocated a full cluster for it. If so we must copy it
2520 * to a smaller mbuf and free up the cluster mbuf. This will help
2521 * with cluster starvation. Note for __Panda__ we don't do this
2522 * since it has clusters all the way down to 64 bytes.
2524 if (SCTP_BUF_LEN(m) < (long)MLEN && SCTP_BUF_NEXT(m) == NULL) {
2525 /* we only handle mbufs that are singletons.. not chains */
2526 m = sctp_get_mbuf_for_msg(SCTP_BUF_LEN(m), 0, M_DONTWAIT, 1, MT_DATA);
2528 /* ok lets see if we can copy the data up */
2531 /* get the pointers and copy */
2532 to = mtod(m, caddr_t *);
2533 from = mtod((*mm), caddr_t *);
2534 memcpy(to, from, SCTP_BUF_LEN((*mm)));
2535 /* copy the length and free up the old */
2536 SCTP_BUF_LEN(m) = SCTP_BUF_LEN((*mm));
2538 /* sucess, back copy */
2541 /* We are in trouble in the mbuf world .. yikes */
2545 /* get pointer to the first chunk header */
2546 ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset,
2547 sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf);
2552 * process all DATA chunks...
2554 *high_tsn = asoc->cumulative_tsn;
2556 asoc->data_pkts_seen++;
2557 while (stop_proc == 0) {
2558 /* validate chunk length */
2559 chk_length = ntohs(ch->ch.chunk_length);
2560 if (length - *offset < chk_length) {
2561 /* all done, mutulated chunk */
2565 if (ch->ch.chunk_type == SCTP_DATA) {
2566 if ((size_t)chk_length < sizeof(struct sctp_data_chunk) + 1) {
2568 * Need to send an abort since we had a
2569 * invalid data chunk.
2571 struct mbuf *op_err;
2573 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 2 * sizeof(uint32_t)),
2574 0, M_DONTWAIT, 1, MT_DATA);
2577 struct sctp_paramhdr *ph;
2580 SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr) +
2581 (2 * sizeof(uint32_t));
2582 ph = mtod(op_err, struct sctp_paramhdr *);
2584 htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
2585 ph->param_length = htons(SCTP_BUF_LEN(op_err));
2586 ippp = (uint32_t *) (ph + 1);
2587 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_19);
2589 *ippp = asoc->cumulative_tsn;
2592 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_19;
2593 sctp_abort_association(inp, stcb, m, iphlen, sh,
2597 #ifdef SCTP_AUDITING_ENABLED
2598 sctp_audit_log(0xB1, 0);
2600 if (SCTP_SIZE32(chk_length) == (length - *offset)) {
2605 if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset, ch,
2606 chk_length, net, high_tsn, &abort_flag, &break_flag,
2615 * Set because of out of rwnd space and no
2616 * drop rep space left.
2622 /* not a data chunk in the data region */
2623 switch (ch->ch.chunk_type) {
2624 case SCTP_INITIATION:
2625 case SCTP_INITIATION_ACK:
2626 case SCTP_SELECTIVE_ACK:
2627 case SCTP_HEARTBEAT_REQUEST:
2628 case SCTP_HEARTBEAT_ACK:
2629 case SCTP_ABORT_ASSOCIATION:
2631 case SCTP_SHUTDOWN_ACK:
2632 case SCTP_OPERATION_ERROR:
2633 case SCTP_COOKIE_ECHO:
2634 case SCTP_COOKIE_ACK:
2637 case SCTP_SHUTDOWN_COMPLETE:
2638 case SCTP_AUTHENTICATION:
2639 case SCTP_ASCONF_ACK:
2640 case SCTP_PACKET_DROPPED:
2641 case SCTP_STREAM_RESET:
2642 case SCTP_FORWARD_CUM_TSN:
2645 * Now, what do we do with KNOWN chunks that
2646 * are NOT in the right place?
2648 * For now, I do nothing but ignore them. We
2649 * may later want to add sysctl stuff to
2650 * switch out and do either an ABORT() or
2651 * possibly process them.
2653 if (sctp_strict_data_order) {
2654 struct mbuf *op_err;
2656 op_err = sctp_generate_invmanparam(SCTP_CAUSE_PROTOCOL_VIOLATION);
2657 sctp_abort_association(inp, stcb, m, iphlen, sh, op_err, 0);
2662 /* unknown chunk type, use bit rules */
2663 if (ch->ch.chunk_type & 0x40) {
2664 /* Add a error report to the queue */
2666 struct sctp_paramhdr *phd;
2668 merr = sctp_get_mbuf_for_msg(sizeof(*phd), 0, M_DONTWAIT, 1, MT_DATA);
2670 phd = mtod(merr, struct sctp_paramhdr *);
2672 * We cheat and use param
2673 * type since we did not
2674 * bother to define a error
2675 * cause struct. They are
2676 * the same basic format
2677 * with different names.
2680 htons(SCTP_CAUSE_UNRECOG_CHUNK);
2682 htons(chk_length + sizeof(*phd));
2683 SCTP_BUF_LEN(merr) = sizeof(*phd);
2684 SCTP_BUF_NEXT(merr) = SCTP_M_COPYM(m, *offset,
2685 SCTP_SIZE32(chk_length),
2687 if (SCTP_BUF_NEXT(merr)) {
2688 sctp_queue_op_err(stcb, merr);
2694 if ((ch->ch.chunk_type & 0x80) == 0) {
2695 /* discard the rest of this packet */
2697 } /* else skip this bad chunk and
2700 }; /* switch of chunk type */
2702 *offset += SCTP_SIZE32(chk_length);
2703 if ((*offset >= length) || stop_proc) {
2704 /* no more data left in the mbuf chain */
2708 ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset,
2709 sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf);
2719 * we need to report rwnd overrun drops.
2721 sctp_send_packet_dropped(stcb, net, *mm, iphlen, 0);
2725 * Did we get data, if so update the time for auto-close and
2726 * give peer credit for being alive.
2728 SCTP_STAT_INCR(sctps_recvpktwithdata);
2729 stcb->asoc.overall_error_count = 0;
2730 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_last_rcvd);
2732 /* now service all of the reassm queue if needed */
2733 if (!(TAILQ_EMPTY(&asoc->reasmqueue)))
2734 sctp_service_queues(stcb, asoc);
2736 if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) {
2737 /* Assure that we ack right away */
2738 stcb->asoc.send_sack = 1;
2740 /* Start a sack timer or QUEUE a SACK for sending */
2741 if ((stcb->asoc.cumulative_tsn == stcb->asoc.highest_tsn_inside_map) &&
2742 (stcb->asoc.mapping_array[0] != 0xff)) {
2743 if ((stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) ||
2744 (stcb->asoc.delayed_ack == 0) ||
2745 (stcb->asoc.send_sack == 1)) {
2746 if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
2747 (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer);
2749 sctp_send_sack(stcb);
2751 if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
2752 sctp_timer_start(SCTP_TIMER_TYPE_RECV,
2753 stcb->sctp_ep, stcb, NULL);
2757 sctp_sack_check(stcb, 1, was_a_gap, &abort_flag);
2766 sctp_handle_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct sctp_association *asoc,
2767 struct sctp_sack_chunk *ch, uint32_t last_tsn, uint32_t * biggest_tsn_acked,
2768 uint32_t * biggest_newly_acked_tsn, uint32_t * this_sack_lowest_newack,
2769 int num_seg, int *ecn_seg_sums)
2771 /************************************************/
2772 /* process fragments and update sendqueue */
2773 /************************************************/
2774 struct sctp_sack *sack;
2775 struct sctp_gap_ack_block *frag, block;
2776 struct sctp_tmit_chunk *tp1;
2781 uint16_t frag_strt, frag_end, primary_flag_set;
2782 u_long last_frag_high;
2785 * @@@ JRI : TODO: This flag is not used anywhere .. remove?
2787 if (asoc->primary_destination->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
2788 primary_flag_set = 1;
2790 primary_flag_set = 0;
2794 frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset,
2795 sizeof(struct sctp_gap_ack_block), (uint8_t *) & block);
2796 *offset += sizeof(block);
2802 for (i = 0; i < num_seg; i++) {
2803 frag_strt = ntohs(frag->start);
2804 frag_end = ntohs(frag->end);
2805 /* some sanity checks on the fargment offsets */
2806 if (frag_strt > frag_end) {
2807 /* this one is malformed, skip */
2811 if (compare_with_wrap((frag_end + last_tsn), *biggest_tsn_acked,
2813 *biggest_tsn_acked = frag_end + last_tsn;
2815 /* mark acked dgs and find out the highestTSN being acked */
2817 tp1 = TAILQ_FIRST(&asoc->sent_queue);
2819 /* save the locations of the last frags */
2820 last_frag_high = frag_end + last_tsn;
2823 * now lets see if we need to reset the queue due to
2824 * a out-of-order SACK fragment
2826 if (compare_with_wrap(frag_strt + last_tsn,
2827 last_frag_high, MAX_TSN)) {
2829 * if the new frag starts after the last TSN
2830 * frag covered, we are ok and this one is
2831 * beyond the last one
2836 * ok, they have reset us, so we need to
2837 * reset the queue this will cause extra
2838 * hunting but hey, they chose the
2839 * performance hit when they failed to order
2842 tp1 = TAILQ_FIRST(&asoc->sent_queue);
2844 last_frag_high = frag_end + last_tsn;
2846 for (j = frag_strt + last_tsn; j <= frag_end + last_tsn; j++) {
2848 if (tp1->rec.data.doing_fast_retransmit)
2852 * CMT: CUCv2 algorithm. For each TSN being
2853 * processed from the sent queue, track the
2854 * next expected pseudo-cumack, or
2855 * rtx_pseudo_cumack, if required. Separate
2856 * cumack trackers for first transmissions,
2857 * and retransmissions.
2859 if ((tp1->whoTo->find_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) &&
2860 (tp1->snd_count == 1)) {
2861 tp1->whoTo->pseudo_cumack = tp1->rec.data.TSN_seq;
2862 tp1->whoTo->find_pseudo_cumack = 0;
2864 if ((tp1->whoTo->find_rtx_pseudo_cumack == 1) && (tp1->sent < SCTP_DATAGRAM_RESEND) &&
2865 (tp1->snd_count > 1)) {
2866 tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.TSN_seq;
2867 tp1->whoTo->find_rtx_pseudo_cumack = 0;
2869 if (tp1->rec.data.TSN_seq == j) {
2870 if (tp1->sent != SCTP_DATAGRAM_UNSENT) {
2872 * must be held until
2876 * ECN Nonce: Add the nonce
2877 * value to the sender's
2880 if (tp1->sent < SCTP_DATAGRAM_RESEND) {
2882 * If it is less than RESEND, it is
2883 * now no-longer in flight.
2884 * Higher values may already be set
2885 * via previous Gap Ack Blocks...
2886 * i.e. ACKED or RESEND.
2888 if (compare_with_wrap(tp1->rec.data.TSN_seq,
2889 *biggest_newly_acked_tsn, MAX_TSN)) {
2890 *biggest_newly_acked_tsn = tp1->rec.data.TSN_seq;
2899 * this_sack_highest_
2903 if (tp1->rec.data.chunk_was_revoked == 0)
2904 tp1->whoTo->saw_newack = 1;
2906 if (compare_with_wrap(tp1->rec.data.TSN_seq,
2907 tp1->whoTo->this_sack_highest_newack,
2909 tp1->whoTo->this_sack_highest_newack =
2910 tp1->rec.data.TSN_seq;
2915 * this_sack_lowest_n
2918 if (*this_sack_lowest_newack == 0) {
2919 if (sctp_logging_level & SCTP_SACK_LOGGING_ENABLE) {
2920 sctp_log_sack(*this_sack_lowest_newack,
2922 tp1->rec.data.TSN_seq,
2925 SCTP_LOG_TSN_ACKED);
2927 *this_sack_lowest_newack = tp1->rec.data.TSN_seq;
2932 * (rtx-)pseudo-cumac
2937 * (rtx-)pseudo-cumac
2939 * new_(rtx_)pseudo_c
2947 * (rtx-)pseudo-cumac
2955 if (tp1->rec.data.TSN_seq == tp1->whoTo->pseudo_cumack) {
2956 if (tp1->rec.data.chunk_was_revoked == 0) {
2957 tp1->whoTo->new_pseudo_cumack = 1;
2959 tp1->whoTo->find_pseudo_cumack = 1;
2961 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
2962 sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK);
2964 if (tp1->rec.data.TSN_seq == tp1->whoTo->rtx_pseudo_cumack) {
2965 if (tp1->rec.data.chunk_was_revoked == 0) {
2966 tp1->whoTo->new_pseudo_cumack = 1;
2968 tp1->whoTo->find_rtx_pseudo_cumack = 1;
2970 if (sctp_logging_level & SCTP_SACK_LOGGING_ENABLE) {
2971 sctp_log_sack(*biggest_newly_acked_tsn,
2973 tp1->rec.data.TSN_seq,
2976 SCTP_LOG_TSN_ACKED);
2978 if (sctp_logging_level & SCTP_FLIGHT_LOGGING_ENABLE) {
2979 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP,
2980 tp1->whoTo->flight_size,
2982 (uintptr_t) tp1->whoTo,
2983 tp1->rec.data.TSN_seq);
2985 sctp_flight_size_decrease(tp1);
2986 sctp_total_flight_decrease(stcb, tp1);
2988 tp1->whoTo->net_ack += tp1->send_size;
2989 if (tp1->snd_count < 2) {
2995 tp1->whoTo->net_ack2 += tp1->send_size;
3002 sctp_calculate_rto(stcb,
3005 &tp1->sent_rcv_time,
3006 sctp_align_safe_nocopy);
3011 if (tp1->sent <= SCTP_DATAGRAM_RESEND) {
3012 (*ecn_seg_sums) += tp1->rec.data.ect_nonce;
3013 (*ecn_seg_sums) &= SCTP_SACK_NONCE_SUM;
3014 if (compare_with_wrap(tp1->rec.data.TSN_seq,
3015 asoc->this_sack_highest_gap,
3017 asoc->this_sack_highest_gap =
3018 tp1->rec.data.TSN_seq;
3020 if (tp1->sent == SCTP_DATAGRAM_RESEND) {
3021 sctp_ucount_decr(asoc->sent_queue_retran_cnt);
3022 #ifdef SCTP_AUDITING_ENABLED
3023 sctp_audit_log(0xB2,
3024 (asoc->sent_queue_retran_cnt & 0x000000ff));
3029 * All chunks NOT UNSENT
3030 * fall through here and are
3033 tp1->sent = SCTP_DATAGRAM_MARKED;
3034 if (tp1->rec.data.chunk_was_revoked) {
3035 /* deflate the cwnd */
3036 tp1->whoTo->cwnd -= tp1->book_size;
3037 tp1->rec.data.chunk_was_revoked = 0;
3041 } /* if (tp1->TSN_seq == j) */
3042 if (compare_with_wrap(tp1->rec.data.TSN_seq, j,
3046 tp1 = TAILQ_NEXT(tp1, sctp_next);
3047 } /* end while (tp1) */
3048 } /* end for (j = fragStart */
3049 frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset,
3050 sizeof(struct sctp_gap_ack_block), (uint8_t *) & block);
3051 *offset += sizeof(block);
3056 if (sctp_logging_level & SCTP_FR_LOGGING_ENABLE) {
3058 sctp_log_fr(*biggest_tsn_acked,
3059 *biggest_newly_acked_tsn,
3060 last_tsn, SCTP_FR_LOG_BIGGEST_TSNS);
3065 sctp_check_for_revoked(struct sctp_tcb *stcb,
3066 struct sctp_association *asoc, uint32_t cumack,
3067 u_long biggest_tsn_acked)
3069 struct sctp_tmit_chunk *tp1;
3070 int tot_revoked = 0;
3072 tp1 = TAILQ_FIRST(&asoc->sent_queue);
3074 if (compare_with_wrap(tp1->rec.data.TSN_seq, cumack,
3077 * ok this guy is either ACK or MARKED. If it is
3078 * ACKED it has been previously acked but not this
3079 * time i.e. revoked. If it is MARKED it was ACK'ed
3082 if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked,
3087 if (tp1->sent == SCTP_DATAGRAM_ACKED) {
3088 /* it has been revoked */
3089 tp1->sent = SCTP_DATAGRAM_SENT;
3090 tp1->rec.data.chunk_was_revoked = 1;
3092 * We must add this stuff back in to assure
3093 * timers and such get started.
3095 if (sctp_logging_level & SCTP_FLIGHT_LOGGING_ENABLE) {
3096 sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE,
3097 tp1->whoTo->flight_size,
3099 (uintptr_t) tp1->whoTo,
3100 tp1->rec.data.TSN_seq);
3102 sctp_flight_size_increase(tp1);
3103 sctp_total_flight_increase(stcb, tp1);
3105 * We inflate the cwnd to compensate for our
3106 * artificial inflation of the flight_size.
3108 tp1->whoTo->cwnd += tp1->book_size;
3110 if (sctp_logging_level & SCTP_SACK_LOGGING_ENABLE) {
3111 sctp_log_sack(asoc->last_acked_seq,
3113 tp1->rec.data.TSN_seq,
3116 SCTP_LOG_TSN_REVOKED);
3118 } else if (tp1->sent == SCTP_DATAGRAM_MARKED) {
3119 /* it has been re-acked in this SACK */
3120 tp1->sent = SCTP_DATAGRAM_ACKED;
3123 if (tp1->sent == SCTP_DATAGRAM_UNSENT)
3125 tp1 = TAILQ_NEXT(tp1, sctp_next);
3127 if (tot_revoked > 0) {
3129 * Setup the ecn nonce re-sync point. We do this since once
3130 * data is revoked we begin to retransmit things, which do
3131 * NOT have the ECN bits set. This means we are now out of
3132 * sync and must wait until we get back in sync with the
3133 * peer to check ECN bits.
3135 tp1 = TAILQ_FIRST(&asoc->send_queue);
3137 asoc->nonce_resync_tsn = asoc->sending_seq;
3139 asoc->nonce_resync_tsn = tp1->rec.data.TSN_seq;
3141 asoc->nonce_wait_for_ecne = 0;
3142 asoc->nonce_sum_check = 0;
3147 sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc,
3148 u_long biggest_tsn_acked, u_long biggest_tsn_newly_acked, u_long this_sack_lowest_newack, int accum_moved)
3150 struct sctp_tmit_chunk *tp1;
3151 int strike_flag = 0;
3153 int tot_retrans = 0;
3154 uint32_t sending_seq;
3155 struct sctp_nets *net;
3156 int num_dests_sacked = 0;
3159 * select the sending_seq, this is either the next thing ready to be
3160 * sent but not transmitted, OR, the next seq we assign.
3162 tp1 = TAILQ_FIRST(&stcb->asoc.send_queue);
3164 sending_seq = asoc->sending_seq;
3166 sending_seq = tp1->rec.data.TSN_seq;
3169 /* CMT DAC algo: finding out if SACK is a mixed SACK */
3170 if (sctp_cmt_on_off && sctp_cmt_use_dac) {
3171 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
3172 if (net->saw_newack)
3176 if (stcb->asoc.peer_supports_prsctp) {
3177 (void)SCTP_GETTIME_TIMEVAL(&now);
3179 tp1 = TAILQ_FIRST(&asoc->sent_queue);
3182 if (tp1->no_fr_allowed) {
3183 /* this one had a timeout or something */
3184 tp1 = TAILQ_NEXT(tp1, sctp_next);
3187 if (sctp_logging_level & SCTP_FR_LOGGING_ENABLE) {
3188 if (tp1->sent < SCTP_DATAGRAM_RESEND)
3189 sctp_log_fr(biggest_tsn_newly_acked,
3190 tp1->rec.data.TSN_seq,
3192 SCTP_FR_LOG_CHECK_STRIKE);
3194 if (compare_with_wrap(tp1->rec.data.TSN_seq, biggest_tsn_acked,
3196 tp1->sent == SCTP_DATAGRAM_UNSENT) {
3200 if (stcb->asoc.peer_supports_prsctp) {
3201 if ((PR_SCTP_TTL_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) {
3202 /* Is it expired? */
3204 (timevalcmp(&now, &tp1->rec.data.timetodrop, >))
3206 /* Yes so drop it */
3207 if (tp1->data != NULL) {
3208 (void)sctp_release_pr_sctp_chunk(stcb, tp1,
3209 (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT),
3212 tp1 = TAILQ_NEXT(tp1, sctp_next);
3216 if ((PR_SCTP_RTX_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) {
3217 /* Has it been retransmitted tv_sec times? */
3218 if (tp1->snd_count > tp1->rec.data.timetodrop.tv_sec) {
3219 /* Yes, so drop it */
3220 if (tp1->data != NULL) {
3221 (void)sctp_release_pr_sctp_chunk(stcb, tp1,
3222 (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT),
3225 tp1 = TAILQ_NEXT(tp1, sctp_next);
3230 if (compare_with_wrap(tp1->rec.data.TSN_seq,
3231 asoc->this_sack_highest_gap, MAX_TSN)) {
3232 /* we are beyond the tsn in the sack */
3235 if (tp1->sent >= SCTP_DATAGRAM_RESEND) {
3236 /* either a RESEND, ACKED, or MARKED */
3238 tp1 = TAILQ_NEXT(tp1, sctp_next);
3242 * CMT : SFR algo (covers part of DAC and HTNA as well)
3244 if (tp1->whoTo && tp1->whoTo->saw_newack == 0) {
3246 * No new acks were receieved for data sent to this
3247 * dest. Therefore, according to the SFR algo for
3248 * CMT, no data sent to this dest can be marked for
3249 * FR using this SACK.
3251 tp1 = TAILQ_NEXT(tp1, sctp_next);
3253 } else if (tp1->whoTo && compare_with_wrap(tp1->rec.data.TSN_seq,
3254 tp1->whoTo->this_sack_highest_newack, MAX_TSN)) {
3256 * CMT: New acks were receieved for data sent to
3257 * this dest. But no new acks were seen for data
3258 * sent after tp1. Therefore, according to the SFR
3259 * algo for CMT, tp1 cannot be marked for FR using
3260 * this SACK. This step covers part of the DAC algo
3261 * and the HTNA algo as well.
3263 tp1 = TAILQ_NEXT(tp1, sctp_next);
3267 * Here we check to see if we were have already done a FR
3268 * and if so we see if the biggest TSN we saw in the sack is
3269 * smaller than the recovery point. If so we don't strike
3270 * the tsn... otherwise we CAN strike the TSN.
3273 * @@@ JRI: Check for CMT if (accum_moved &&
3274 * asoc->fast_retran_loss_recovery && (sctp_cmt_on_off ==
3277 if (accum_moved && asoc->fast_retran_loss_recovery) {
3279 * Strike the TSN if in fast-recovery and cum-ack
3282 if (sctp_logging_level & SCTP_FR_LOGGING_ENABLE) {
3283 sctp_log_fr(biggest_tsn_newly_acked,
3284 tp1->rec.data.TSN_seq,
3286 SCTP_FR_LOG_STRIKE_CHUNK);
3288 if (tp1->sent < SCTP_DATAGRAM_RESEND) {
3291 if (sctp_cmt_on_off && sctp_cmt_use_dac) {
3293 * CMT DAC algorithm: If SACK flag is set to
3294 * 0, then lowest_newack test will not pass
3295 * because it would have been set to the
3296 * cumack earlier. If not already to be
3297 * rtx'd, If not a mixed sack and if tp1 is
3298 * not between two sacked TSNs, then mark by
3299 * one more. NOTE that we are marking by one
3300 * additional time since the SACK DAC flag
3301 * indicates that two packets have been
3302 * received after this missing TSN.
3304 if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) &&
3305 compare_with_wrap(this_sack_lowest_newack, tp1->rec.data.TSN_seq, MAX_TSN)) {
3306 if (sctp_logging_level & SCTP_FR_LOGGING_ENABLE) {
3307 sctp_log_fr(16 + num_dests_sacked,
3308 tp1->rec.data.TSN_seq,
3310 SCTP_FR_LOG_STRIKE_CHUNK);
3315 } else if (tp1->rec.data.doing_fast_retransmit) {
3317 * For those that have done a FR we must take
3318 * special consideration if we strike. I.e the
3319 * biggest_newly_acked must be higher than the
3320 * sending_seq at the time we did the FR.
3323 #ifdef SCTP_FR_TO_ALTERNATE
3325 * If FR's go to new networks, then we must only do
3326 * this for singly homed asoc's. However if the FR's
3327 * go to the same network (Armando's work) then its
3328 * ok to FR multiple times.
3336 if ((compare_with_wrap(biggest_tsn_newly_acked,
3337 tp1->rec.data.fast_retran_tsn, MAX_TSN)) ||
3338 (biggest_tsn_newly_acked ==
3339 tp1->rec.data.fast_retran_tsn)) {
3341 * Strike the TSN, since this ack is
3342 * beyond where things were when we
3345 if (sctp_logging_level & SCTP_FR_LOGGING_ENABLE) {
3346 sctp_log_fr(biggest_tsn_newly_acked,
3347 tp1->rec.data.TSN_seq,
3349 SCTP_FR_LOG_STRIKE_CHUNK);
3351 if (tp1->sent < SCTP_DATAGRAM_RESEND) {
3355 if (sctp_cmt_on_off && sctp_cmt_use_dac) {
3357 * CMT DAC algorithm: If
3358 * SACK flag is set to 0,
3359 * then lowest_newack test
3360 * will not pass because it
3361 * would have been set to
3362 * the cumack earlier. If
3363 * not already to be rtx'd,
3364 * If not a mixed sack and
3365 * if tp1 is not between two
3366 * sacked TSNs, then mark by
3367 * one more. NOTE that we
3368 * are marking by one
3369 * additional time since the
3370 * SACK DAC flag indicates
3371 * that two packets have
3372 * been received after this
3375 if ((tp1->sent < SCTP_DATAGRAM_RESEND) &&
3376 (num_dests_sacked == 1) &&
3377 compare_with_wrap(this_sack_lowest_newack,
3378 tp1->rec.data.TSN_seq, MAX_TSN)) {
3379 if (sctp_logging_level & SCTP_FR_LOGGING_ENABLE) {
3380 sctp_log_fr(32 + num_dests_sacked,
3381 tp1->rec.data.TSN_seq,
3383 SCTP_FR_LOG_STRIKE_CHUNK);
3385 if (tp1->sent < SCTP_DATAGRAM_RESEND) {
3394 * JRI: TODO: remove code for HTNA algo. CMT's SFR
3397 } else if (compare_with_wrap(tp1->rec.data.TSN_seq,
3398 biggest_tsn_newly_acked, MAX_TSN)) {
3400 * We don't strike these: This is the HTNA
3401 * algorithm i.e. we don't strike If our TSN is
3402 * larger than the Highest TSN Newly Acked.
3406 /* Strike the TSN */
3407 if (sctp_logging_level & SCTP_FR_LOGGING_ENABLE) {
3408 sctp_log_fr(biggest_tsn_newly_acked,
3409 tp1->rec.data.TSN_seq,
3411 SCTP_FR_LOG_STRIKE_CHUNK);
3413 if (tp1->sent < SCTP_DATAGRAM_RESEND) {
3416 if (sctp_cmt_on_off && sctp_cmt_use_dac) {
3418 * CMT DAC algorithm: If SACK flag is set to
3419 * 0, then lowest_newack test will not pass
3420 * because it would have been set to the
3421 * cumack earlier. If not already to be
3422 * rtx'd, If not a mixed sack and if tp1 is
3423 * not between two sacked TSNs, then mark by
3424 * one more. NOTE that we are marking by one
3425 * additional time since the SACK DAC flag
3426 * indicates that two packets have been
3427 * received after this missing TSN.
3429 if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) &&
3430 compare_with_wrap(this_sack_lowest_newack, tp1->rec.data.TSN_seq, MAX_TSN)) {
3431 if (sctp_logging_level & SCTP_FR_LOGGING_ENABLE) {
3432 sctp_log_fr(48 + num_dests_sacked,
3433 tp1->rec.data.TSN_seq,
3435 SCTP_FR_LOG_STRIKE_CHUNK);
3441 if (tp1->sent == SCTP_DATAGRAM_RESEND) {
3442 /* Increment the count to resend */
3443 struct sctp_nets *alt;
3445 /* printf("OK, we are now ready to FR this guy\n"); */
3446 if (sctp_logging_level & SCTP_FR_LOGGING_ENABLE) {
3447 sctp_log_fr(tp1->rec.data.TSN_seq, tp1->snd_count,
3451 /* This is a subsequent FR */
3452 SCTP_STAT_INCR(sctps_sendmultfastretrans);
3454 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
3455 if (sctp_cmt_on_off) {
3457 * CMT: Using RTX_SSTHRESH policy for CMT.
3458 * If CMT is being used, then pick dest with
3459 * largest ssthresh for any retransmission.
3461 tp1->no_fr_allowed = 1;
3463 /* sa_ignore NO_NULL_CHK */
3464 if (sctp_cmt_on_off && sctp_cmt_pf) {
3466 * JRS 5/18/07 - If CMT PF is on,
3467 * use the PF version of
3470 alt = sctp_find_alternate_net(stcb, alt, 2);
3473 * JRS 5/18/07 - If only CMT is on,
3474 * use the CMT version of
3477 /* sa_ignore NO_NULL_CHK */
3478 alt = sctp_find_alternate_net(stcb, alt, 1);
3484 * CUCv2: If a different dest is picked for
3485 * the retransmission, then new
3486 * (rtx-)pseudo_cumack needs to be tracked
3487 * for orig dest. Let CUCv2 track new (rtx-)
3488 * pseudo-cumack always.
3491 tp1->whoTo->find_pseudo_cumack = 1;
3492 tp1->whoTo->find_rtx_pseudo_cumack = 1;
3494 } else {/* CMT is OFF */
3496 #ifdef SCTP_FR_TO_ALTERNATE
3497 /* Can we find an alternate? */
3498 alt = sctp_find_alternate_net(stcb, tp1->whoTo, 0);
3501 * default behavior is to NOT retransmit
3502 * FR's to an alternate. Armando Caro's
3503 * paper details why.
3509 tp1->rec.data.doing_fast_retransmit = 1;
3511 /* mark the sending seq for possible subsequent FR's */
3513 * printf("Marking TSN for FR new value %x\n",
3514 * (uint32_t)tpi->rec.data.TSN_seq);
3516 if (TAILQ_EMPTY(&asoc->send_queue)) {
3518 * If the queue of send is empty then its
3519 * the next sequence number that will be
3520 * assigned so we subtract one from this to
3521 * get the one we last sent.
3523 tp1->rec.data.fast_retran_tsn = sending_seq;
3526 * If there are chunks on the send queue
3527 * (unsent data that has made it from the
3528 * stream queues but not out the door, we
3529 * take the first one (which will have the
3530 * lowest TSN) and subtract one to get the
3533 struct sctp_tmit_chunk *ttt;
3535 ttt = TAILQ_FIRST(&asoc->send_queue);
3536 tp1->rec.data.fast_retran_tsn =
3537 ttt->rec.data.TSN_seq;
3542 * this guy had a RTO calculation pending on
3547 /* fix counts and things */
3548 if (sctp_logging_level & SCTP_FLIGHT_LOGGING_ENABLE) {
3549 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND,
3550 (tp1->whoTo ? (tp1->whoTo->flight_size) : 0),
3552 (uintptr_t) tp1->whoTo,
3553 tp1->rec.data.TSN_seq);
3556 tp1->whoTo->net_ack++;
3557 sctp_flight_size_decrease(tp1);
3559 if (sctp_logging_level & SCTP_LOG_RWND_ENABLE) {
3560 sctp_log_rwnd(SCTP_INCREASE_PEER_RWND,
3561 asoc->peers_rwnd, tp1->send_size, sctp_peer_chunk_oh);
3563 /* add back to the rwnd */
3564 asoc->peers_rwnd += (tp1->send_size + sctp_peer_chunk_oh);
3566 /* remove from the total flight */
3567 sctp_total_flight_decrease(stcb, tp1);
3568 if (alt != tp1->whoTo) {
3569 /* yes, there is an alternate. */
3570 sctp_free_remote_addr(tp1->whoTo);
3571 /* sa_ignore FREED_MEMORY */
3573 atomic_add_int(&alt->ref_count, 1);
3576 tp1 = TAILQ_NEXT(tp1, sctp_next);
3579 if (tot_retrans > 0) {
3581 * Setup the ecn nonce re-sync point. We do this since once
3582 * we go to FR something we introduce a Karn's rule scenario
3583 * and won't know the totals for the ECN bits.
3585 asoc->nonce_resync_tsn = sending_seq;
3586 asoc->nonce_wait_for_ecne = 0;
3587 asoc->nonce_sum_check = 0;
3591 struct sctp_tmit_chunk *
3592 sctp_try_advance_peer_ack_point(struct sctp_tcb *stcb,
3593 struct sctp_association *asoc)
3595 struct sctp_tmit_chunk *tp1, *tp2, *a_adv = NULL;
3599 if (asoc->peer_supports_prsctp == 0) {
3602 tp1 = TAILQ_FIRST(&asoc->sent_queue);
3604 if (tp1->sent != SCTP_FORWARD_TSN_SKIP &&
3605 tp1->sent != SCTP_DATAGRAM_RESEND) {
3606 /* no chance to advance, out of here */
3609 if (!PR_SCTP_ENABLED(tp1->flags)) {
3611 * We can't fwd-tsn past any that are reliable aka
3612 * retransmitted until the asoc fails.
3617 (void)SCTP_GETTIME_TIMEVAL(&now);
3620 tp2 = TAILQ_NEXT(tp1, sctp_next);
3622 * now we got a chunk which is marked for another
3623 * retransmission to a PR-stream but has run out its chances
3624 * already maybe OR has been marked to skip now. Can we skip
3625 * it if its a resend?
3627 if (tp1->sent == SCTP_DATAGRAM_RESEND &&
3628 (PR_SCTP_TTL_ENABLED(tp1->flags))) {
3630 * Now is this one marked for resend and its time is
3633 if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) {
3634 /* Yes so drop it */
3636 (void)sctp_release_pr_sctp_chunk(stcb, tp1,
3637 (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT),
3642 * No, we are done when hit one for resend
3643 * whos time as not expired.
3649 * Ok now if this chunk is marked to drop it we can clean up
3650 * the chunk, advance our peer ack point and we can check
3653 if (tp1->sent == SCTP_FORWARD_TSN_SKIP) {
3654 /* advance PeerAckPoint goes forward */
3655 asoc->advanced_peer_ack_point = tp1->rec.data.TSN_seq;
3658 * we don't want to de-queue it here. Just wait for
3659 * the next peer SACK to come with a new cumTSN and
3660 * then the chunk will be droped in the normal
3664 sctp_free_bufspace(stcb, asoc, tp1, 1);
3666 * Maybe there should be another
3669 sctp_ulp_notify(SCTP_NOTIFY_DG_FAIL, stcb,
3670 (SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT),
3672 sctp_m_freem(tp1->data);
3674 if (stcb->sctp_socket) {
3675 sctp_sowwakeup(stcb->sctp_ep,
3677 if (sctp_logging_level & SCTP_WAKE_LOGGING_ENABLE) {
3678 sctp_wakeup_log(stcb, tp1->rec.data.TSN_seq, 1, SCTP_WAKESND_FROM_FWDTSN);
3684 * If it is still in RESEND we can advance no
3690 * If we hit here we just dumped tp1, move to next tsn on
3699 sctp_fs_audit(struct sctp_association *asoc)
3701 struct sctp_tmit_chunk *chk;
3702 int inflight = 0, resend = 0, inbetween = 0, acked = 0, above = 0;
3704 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
3705 if (chk->sent < SCTP_DATAGRAM_RESEND) {
3707 } else if (chk->sent == SCTP_DATAGRAM_RESEND) {
3709 } else if (chk->sent < SCTP_DATAGRAM_ACKED) {
3711 } else if (chk->sent > SCTP_DATAGRAM_ACKED) {
3718 if ((inflight > 0) || (inbetween > 0)) {
3720 panic("Flight size-express incorrect? \n");
3722 SCTP_PRINTF("Flight size-express incorrect inflight:%d inbetween:%d\n",
3723 inflight, inbetween);
3730 sctp_window_probe_recovery(struct sctp_tcb *stcb,
3731 struct sctp_association *asoc,
3732 struct sctp_nets *net,
3733 struct sctp_tmit_chunk *tp1)
3735 struct sctp_tmit_chunk *chk;
3737 /* First setup this one and get it moved back */
3738 tp1->sent = SCTP_DATAGRAM_UNSENT;
3739 if (sctp_logging_level & SCTP_FLIGHT_LOGGING_ENABLE) {
3740 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_WP,
3741 tp1->whoTo->flight_size,
3743 (uintptr_t) tp1->whoTo,
3744 tp1->rec.data.TSN_seq);
3746 sctp_flight_size_decrease(tp1);
3747 sctp_total_flight_decrease(stcb, tp1);
3748 TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next);
3749 TAILQ_INSERT_HEAD(&asoc->send_queue, tp1, sctp_next);
3750 asoc->sent_queue_cnt--;
3751 asoc->send_queue_cnt++;
3753 * Now all guys marked for RESEND on the sent_queue must be moved
3756 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
3757 if (chk->sent == SCTP_DATAGRAM_RESEND) {
3758 /* Another chunk to move */
3759 chk->sent = SCTP_DATAGRAM_UNSENT;
3760 /* It should not be in flight */
3761 TAILQ_REMOVE(&asoc->sent_queue, chk, sctp_next);
3762 TAILQ_INSERT_AFTER(&asoc->send_queue, tp1, chk, sctp_next);
3763 asoc->sent_queue_cnt--;
3764 asoc->send_queue_cnt++;
3765 sctp_ucount_decr(asoc->sent_queue_retran_cnt);
3771 sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack,
3772 uint32_t rwnd, int nonce_sum_flag, int *abort_now)
3774 struct sctp_nets *net;
3775 struct sctp_association *asoc;
3776 struct sctp_tmit_chunk *tp1, *tp2;
3778 int win_probe_recovery = 0;
3779 int win_probe_recovered = 0;
3780 int j, done_once = 0;
3783 if (sctp_logging_level & SCTP_LOG_SACK_ARRIVALS_ENABLE) {
3784 sctp_misc_ints(SCTP_SACK_LOG_EXPRESS, cumack,
3785 rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd);
3787 SCTP_TCB_LOCK_ASSERT(stcb);
3788 #ifdef SCTP_ASOCLOG_OF_TSNS
3789 stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cumack;
3790 stcb->asoc.cumack_log_at++;
3791 if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) {
3792 stcb->asoc.cumack_log_at = 0;
3796 old_rwnd = asoc->peers_rwnd;
3797 if (compare_with_wrap(asoc->last_acked_seq, cumack, MAX_TSN)) {
3800 } else if (asoc->last_acked_seq == cumack) {
3801 /* Window update sack */
3802 asoc->peers_rwnd = sctp_sbspace_sub(rwnd,
3803 (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * sctp_peer_chunk_oh)));
3804 if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
3805 /* SWS sender side engages */
3806 asoc->peers_rwnd = 0;
3808 if (asoc->peers_rwnd > old_rwnd) {
3814 /* First setup for CC stuff */
3815 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
3816 net->prev_cwnd = net->cwnd;
3821 * CMT: Reset CUC and Fast recovery algo variables before
3824 net->new_pseudo_cumack = 0;
3825 net->will_exit_fast_recovery = 0;
3827 if (sctp_strict_sacks) {
3830 if (!TAILQ_EMPTY(&asoc->sent_queue)) {
3831 tp1 = TAILQ_LAST(&asoc->sent_queue,
3832 sctpchunk_listhead);
3833 send_s = tp1->rec.data.TSN_seq + 1;
3835 send_s = asoc->sending_seq;
3837 if ((cumack == send_s) ||
3838 compare_with_wrap(cumack, send_s, MAX_TSN)) {
3844 panic("Impossible sack 1");
3848 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
3849 0, M_DONTWAIT, 1, MT_DATA);
3851 struct sctp_paramhdr *ph;
3854 SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) +
3856 ph = mtod(oper, struct sctp_paramhdr *);
3857 ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
3858 ph->param_length = htons(SCTP_BUF_LEN(oper));
3859 ippp = (uint32_t *) (ph + 1);
3860 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25);
3862 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25;
3863 sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper);
3868 asoc->this_sack_highest_gap = cumack;
3869 stcb->asoc.overall_error_count = 0;
3870 if (compare_with_wrap(cumack, asoc->last_acked_seq, MAX_TSN)) {
3871 /* process the new consecutive TSN first */
3872 tp1 = TAILQ_FIRST(&asoc->sent_queue);
3874 tp2 = TAILQ_NEXT(tp1, sctp_next);
3875 if (compare_with_wrap(cumack, tp1->rec.data.TSN_seq,
3877 cumack == tp1->rec.data.TSN_seq) {
3878 if (tp1->sent == SCTP_DATAGRAM_UNSENT) {
3879 printf("Warning, an unsent is now acked?\n");
3882 * ECN Nonce: Add the nonce to the sender's
3885 asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce;
3886 if (tp1->sent < SCTP_DATAGRAM_ACKED) {
3888 * If it is less than ACKED, it is
3889 * now no-longer in flight. Higher
3890 * values may occur during marking
3892 if (tp1->sent < SCTP_DATAGRAM_RESEND) {
3893 if (sctp_logging_level & SCTP_FLIGHT_LOGGING_ENABLE) {
3894 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA,
3895 tp1->whoTo->flight_size,
3897 (uintptr_t) tp1->whoTo,
3898 tp1->rec.data.TSN_seq);
3900 sctp_flight_size_decrease(tp1);
3901 sctp_total_flight_decrease(stcb, tp1);
3903 tp1->whoTo->net_ack += tp1->send_size;
3904 if (tp1->snd_count < 2) {
3906 * True non-retransmited
3909 tp1->whoTo->net_ack2 +=
3912 /* update RTO too? */
3915 sctp_calculate_rto(stcb,
3917 &tp1->sent_rcv_time,
3918 sctp_align_safe_nocopy);
3923 * CMT: CUCv2 algorithm. From the
3924 * cumack'd TSNs, for each TSN being
3925 * acked for the first time, set the
3926 * following variables for the
3927 * corresp destination.
3928 * new_pseudo_cumack will trigger a
3930 * find_(rtx_)pseudo_cumack will
3931 * trigger search for the next
3932 * expected (rtx-)pseudo-cumack.
3934 tp1->whoTo->new_pseudo_cumack = 1;
3935 tp1->whoTo->find_pseudo_cumack = 1;
3936 tp1->whoTo->find_rtx_pseudo_cumack = 1;
3938 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
3939 sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK);
3942 if (tp1->sent == SCTP_DATAGRAM_RESEND) {
3943 sctp_ucount_decr(asoc->sent_queue_retran_cnt);
3945 if (tp1->rec.data.chunk_was_revoked) {
3946 /* deflate the cwnd */
3947 tp1->whoTo->cwnd -= tp1->book_size;
3948 tp1->rec.data.chunk_was_revoked = 0;
3950 tp1->sent = SCTP_DATAGRAM_ACKED;
3951 TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next);
3953 sctp_free_bufspace(stcb, asoc, tp1, 1);
3954 sctp_m_freem(tp1->data);
3956 if (sctp_logging_level & SCTP_SACK_LOGGING_ENABLE) {
3957 sctp_log_sack(asoc->last_acked_seq,
3959 tp1->rec.data.TSN_seq,
3962 SCTP_LOG_FREE_SENT);
3965 asoc->sent_queue_cnt--;
3966 sctp_free_a_chunk(stcb, tp1);
3974 if (stcb->sctp_socket) {
3975 SOCKBUF_LOCK(&stcb->sctp_socket->so_snd);
3976 if (sctp_logging_level & SCTP_WAKE_LOGGING_ENABLE) {
3977 sctp_wakeup_log(stcb, cumack, 1, SCTP_WAKESND_FROM_SACK);
3979 sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket);
3981 if (sctp_logging_level & SCTP_WAKE_LOGGING_ENABLE) {
3982 sctp_wakeup_log(stcb, cumack, 1, SCTP_NOWAKE_FROM_SACK);
3986 /* JRS - Use the congestion control given in the CC module */
3987 if (asoc->last_acked_seq != cumack)
3988 asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, 1, 0, 0);
3990 asoc->last_acked_seq = cumack;
3992 if (TAILQ_EMPTY(&asoc->sent_queue)) {
3993 /* nothing left in-flight */
3994 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
3995 net->flight_size = 0;
3996 net->partial_bytes_acked = 0;
3998 asoc->total_flight = 0;
3999 asoc->total_flight_count = 0;
4001 /* Fix up the a-p-a-p for future PR-SCTP sends */
4002 if (compare_with_wrap(cumack, asoc->advanced_peer_ack_point, MAX_TSN)) {
4003 asoc->advanced_peer_ack_point = cumack;
4005 /* ECN Nonce updates */
4006 if (asoc->ecn_nonce_allowed) {
4007 if (asoc->nonce_sum_check) {
4008 if (nonce_sum_flag != ((asoc->nonce_sum_expect_base) & SCTP_SACK_NONCE_SUM)) {
4009 if (asoc->nonce_wait_for_ecne == 0) {
4010 struct sctp_tmit_chunk *lchk;
4012 lchk = TAILQ_FIRST(&asoc->send_queue);
4013 asoc->nonce_wait_for_ecne = 1;
4015 asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq;
4017 asoc->nonce_wait_tsn = asoc->sending_seq;
4020 if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) ||
4021 (asoc->last_acked_seq == asoc->nonce_wait_tsn)) {
4023 * Misbehaving peer. We need
4024 * to react to this guy
4026 asoc->ecn_allowed = 0;
4027 asoc->ecn_nonce_allowed = 0;
4032 /* See if Resynchronization Possible */
4033 if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) {
4034 asoc->nonce_sum_check = 1;
4036 * now we must calculate what the base is.
4037 * We do this based on two things, we know
4038 * the total's for all the segments
4039 * gap-acked in the SACK (none), We also
4040 * know the SACK's nonce sum, its in
4041 * nonce_sum_flag. So we can build a truth
4042 * table to back-calculate the new value of
4043 * asoc->nonce_sum_expect_base:
4045 * SACK-flag-Value Seg-Sums Base 0 0 0
4049 asoc->nonce_sum_expect_base = (0 ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM;
4054 asoc->peers_rwnd = sctp_sbspace_sub(rwnd,
4055 (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * sctp_peer_chunk_oh)));
4056 if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
4057 /* SWS sender side engages */
4058 asoc->peers_rwnd = 0;
4060 if (asoc->peers_rwnd > old_rwnd) {
4061 win_probe_recovery = 1;
4063 /* Now assure a timer where data is queued at */
4066 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4067 if (win_probe_recovery && (net->window_probe)) {
4068 net->window_probe = 0;
4069 win_probe_recovered = 1;
4071 * Find first chunk that was used with window probe
4072 * and clear the sent
4074 /* sa_ignore FREED_MEMORY */
4075 TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) {
4076 if (tp1->window_probe) {
4077 /* move back to data send queue */
4078 sctp_window_probe_recovery(stcb, asoc, net, tp1);
4083 if (net->flight_size) {
4086 if (net->RTO == 0) {
4087 to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
4089 to_ticks = MSEC_TO_TICKS(net->RTO);
4092 (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks,
4093 sctp_timeout_handler, &net->rxt_timer);
4095 if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
4096 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
4098 SCTP_FROM_SCTP_INDATA + SCTP_LOC_22);
4100 if (sctp_early_fr) {
4101 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
4102 SCTP_STAT_INCR(sctps_earlyfrstpidsck4);
4103 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
4104 SCTP_FROM_SCTP_INDATA + SCTP_LOC_23);
4110 (!TAILQ_EMPTY(&asoc->sent_queue)) &&
4111 (asoc->sent_queue_retran_cnt == 0) &&
4112 (win_probe_recovered == 0) &&
4114 /* huh, this should not happen */
4115 sctp_fs_audit(asoc);
4116 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4117 net->flight_size = 0;
4119 asoc->total_flight = 0;
4120 asoc->total_flight_count = 0;
4121 asoc->sent_queue_retran_cnt = 0;
4122 TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) {
4123 if (tp1->sent < SCTP_DATAGRAM_RESEND) {
4124 sctp_flight_size_increase(tp1);
4125 sctp_total_flight_increase(stcb, tp1);
4126 } else if (tp1->sent == SCTP_DATAGRAM_RESEND) {
4127 asoc->sent_queue_retran_cnt++;
4133 /**********************************/
4134 /* Now what about shutdown issues */
4135 /**********************************/
4136 if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) {
4137 /* nothing left on sendqueue.. consider done */
4139 if ((asoc->stream_queue_cnt == 1) &&
4140 ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) ||
4141 (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) &&
4142 (asoc->locked_on_sending)
4144 struct sctp_stream_queue_pending *sp;
4147 * I may be in a state where we got all across.. but
4148 * cannot write more due to a shutdown... we abort
4149 * since the user did not indicate EOR in this case.
4150 * The sp will be cleaned during free of the asoc.
4152 sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue),
4154 if ((sp) && (sp->length == 0) && (sp->msg_is_complete == 0)) {
4155 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
4156 asoc->locked_on_sending = NULL;
4157 asoc->stream_queue_cnt--;
4160 if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) &&
4161 (asoc->stream_queue_cnt == 0)) {
4162 if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) {
4163 /* Need to abort here */
4169 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
4170 0, M_DONTWAIT, 1, MT_DATA);
4172 struct sctp_paramhdr *ph;
4175 SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) +
4177 ph = mtod(oper, struct sctp_paramhdr *);
4178 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
4179 ph->param_length = htons(SCTP_BUF_LEN(oper));
4180 ippp = (uint32_t *) (ph + 1);
4181 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_24);
4183 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24;
4184 sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper);
4186 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
4187 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
4188 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
4190 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
4191 sctp_stop_timers_for_shutdown(stcb);
4192 sctp_send_shutdown(stcb,
4193 stcb->asoc.primary_destination);
4194 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
4195 stcb->sctp_ep, stcb, asoc->primary_destination);
4196 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
4197 stcb->sctp_ep, stcb, asoc->primary_destination);
4199 } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) &&
4200 (asoc->stream_queue_cnt == 0)) {
4201 if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) {
4204 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
4205 asoc->state = SCTP_STATE_SHUTDOWN_ACK_SENT;
4206 sctp_send_shutdown_ack(stcb,
4207 stcb->asoc.primary_destination);
4209 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK,
4210 stcb->sctp_ep, stcb, asoc->primary_destination);
4213 if (sctp_logging_level & SCTP_SACK_RWND_LOGGING_ENABLE) {
4214 sctp_misc_ints(SCTP_SACK_RWND_UPDATE,
4216 stcb->asoc.peers_rwnd,
4217 stcb->asoc.total_flight,
4218 stcb->asoc.total_output_queue_size);
4223 sctp_handle_sack(struct mbuf *m, int offset,
4224 struct sctp_sack_chunk *ch, struct sctp_tcb *stcb,
4225 struct sctp_nets *net_from, int *abort_now, int sack_len, uint32_t rwnd)
4227 struct sctp_association *asoc;
4228 struct sctp_sack *sack;
4229 struct sctp_tmit_chunk *tp1, *tp2;
4230 uint32_t cum_ack, last_tsn, biggest_tsn_acked, biggest_tsn_newly_acked,
4231 this_sack_lowest_newack;
4232 uint32_t sav_cum_ack;
4233 uint16_t num_seg, num_dup;
4234 uint16_t wake_him = 0;
4235 unsigned int sack_length;
4236 uint32_t send_s = 0;
4238 int accum_moved = 0;
4239 int will_exit_fast_recovery = 0;
4240 uint32_t a_rwnd, old_rwnd;
4241 int win_probe_recovery = 0;
4242 int win_probe_recovered = 0;
4243 struct sctp_nets *net = NULL;
4244 int nonce_sum_flag, ecn_seg_sums = 0;
4246 uint8_t reneged_all = 0;
4247 uint8_t cmt_dac_flag;
4250 * we take any chance we can to service our queues since we cannot
4251 * get awoken when the socket is read from :<
4254 * Now perform the actual SACK handling: 1) Verify that it is not an
4255 * old sack, if so discard. 2) If there is nothing left in the send
4256 * queue (cum-ack is equal to last acked) then you have a duplicate
4257 * too, update any rwnd change and verify no timers are running.
4258 * then return. 3) Process any new consequtive data i.e. cum-ack
4259 * moved process these first and note that it moved. 4) Process any
4260 * sack blocks. 5) Drop any acked from the queue. 6) Check for any
4261 * revoked blocks and mark. 7) Update the cwnd. 8) Nothing left,
4262 * sync up flightsizes and things, stop all timers and also check
4263 * for shutdown_pending state. If so then go ahead and send off the
4264 * shutdown. If in shutdown recv, send off the shutdown-ack and
4265 * start that timer, Ret. 9) Strike any non-acked things and do FR
4266 * procedure if needed being sure to set the FR flag. 10) Do pr-sctp
4267 * procedures. 11) Apply any FR penalties. 12) Assure we will SACK
4268 * if in shutdown_recv state.
4270 SCTP_TCB_LOCK_ASSERT(stcb);
4273 this_sack_lowest_newack = 0;
4275 sack_length = (unsigned int)sack_len;
4277 SCTP_STAT_INCR(sctps_slowpath_sack);
4278 nonce_sum_flag = ch->ch.chunk_flags & SCTP_SACK_NONCE_SUM;
4279 cum_ack = last_tsn = ntohl(sack->cum_tsn_ack);
4280 #ifdef SCTP_ASOCLOG_OF_TSNS
4281 stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cum_ack;
4282 stcb->asoc.cumack_log_at++;
4283 if (stcb->asoc.cumack_log_at > SCTP_TSN_LOG_SIZE) {
4284 stcb->asoc.cumack_log_at = 0;
4287 num_seg = ntohs(sack->num_gap_ack_blks);
4290 if (sctp_logging_level & SCTP_LOG_SACK_ARRIVALS_ENABLE) {
4291 sctp_misc_ints(SCTP_SACK_LOG_NORMAL, cum_ack,
4292 rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd);
4295 cmt_dac_flag = ch->ch.chunk_flags & SCTP_SACK_CMT_DAC;
4296 num_dup = ntohs(sack->num_dup_tsns);
4298 old_rwnd = stcb->asoc.peers_rwnd;
4299 stcb->asoc.overall_error_count = 0;
4301 if (sctp_logging_level & SCTP_SACK_LOGGING_ENABLE) {
4302 sctp_log_sack(asoc->last_acked_seq,
4309 if ((num_dup) && (sctp_logging_level & (SCTP_FR_LOGGING_ENABLE | SCTP_EARLYFR_LOGGING_ENABLE))) {
4310 int off_to_dup, iii;
4311 uint32_t *dupdata, dblock;
4313 off_to_dup = (num_seg * sizeof(struct sctp_gap_ack_block)) + sizeof(struct sctp_sack_chunk);
4314 if ((off_to_dup + (num_dup * sizeof(uint32_t))) <= sack_length) {
4315 dupdata = (uint32_t *) sctp_m_getptr(m, off_to_dup,
4316 sizeof(uint32_t), (uint8_t *) & dblock);
4317 off_to_dup += sizeof(uint32_t);
4319 for (iii = 0; iii < num_dup; iii++) {
4320 sctp_log_fr(*dupdata, 0, 0, SCTP_FR_DUPED);
4321 dupdata = (uint32_t *) sctp_m_getptr(m, off_to_dup,
4322 sizeof(uint32_t), (uint8_t *) & dblock);
4323 if (dupdata == NULL)
4325 off_to_dup += sizeof(uint32_t);
4331 SCTP_PRINTF("Size invalid offset to dups:%d number dups:%d sack_len:%d num gaps:%d\n",
4332 off_to_dup, num_dup, sack_length, num_seg);
4335 if (sctp_strict_sacks) {
4337 if (!TAILQ_EMPTY(&asoc->sent_queue)) {
4338 tp1 = TAILQ_LAST(&asoc->sent_queue,
4339 sctpchunk_listhead);
4340 send_s = tp1->rec.data.TSN_seq + 1;
4342 send_s = asoc->sending_seq;
4344 if (cum_ack == send_s ||
4345 compare_with_wrap(cum_ack, send_s, MAX_TSN)) {
4352 panic("Impossible sack 1");
4357 * no way, we have not even sent this TSN out yet.
4358 * Peer is hopelessly messed up with us.
4363 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
4364 0, M_DONTWAIT, 1, MT_DATA);
4366 struct sctp_paramhdr *ph;
4369 SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) +
4371 ph = mtod(oper, struct sctp_paramhdr *);
4372 ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
4373 ph->param_length = htons(SCTP_BUF_LEN(oper));
4374 ippp = (uint32_t *) (ph + 1);
4375 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_25);
4377 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25;
4378 sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_PEER_FAULTY, oper);
4383 /**********************/
4384 /* 1) check the range */
4385 /**********************/
4386 if (compare_with_wrap(asoc->last_acked_seq, last_tsn, MAX_TSN)) {
4387 /* acking something behind */
4390 sav_cum_ack = asoc->last_acked_seq;
4392 /* update the Rwnd of the peer */
4393 if (TAILQ_EMPTY(&asoc->sent_queue) &&
4394 TAILQ_EMPTY(&asoc->send_queue) &&
4395 (asoc->stream_queue_cnt == 0)
4397 /* nothing left on send/sent and strmq */
4398 if (sctp_logging_level & SCTP_LOG_RWND_ENABLE) {
4399 sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK,
4400 asoc->peers_rwnd, 0, 0, a_rwnd);
4402 asoc->peers_rwnd = a_rwnd;
4403 if (asoc->sent_queue_retran_cnt) {
4404 asoc->sent_queue_retran_cnt = 0;
4406 if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
4407 /* SWS sender side engages */
4408 asoc->peers_rwnd = 0;
4410 /* stop any timers */
4411 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4412 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
4413 stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_26);
4414 if (sctp_early_fr) {
4415 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
4416 SCTP_STAT_INCR(sctps_earlyfrstpidsck1);
4417 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
4418 SCTP_FROM_SCTP_INDATA + SCTP_LOC_26);
4421 net->partial_bytes_acked = 0;
4422 net->flight_size = 0;
4424 asoc->total_flight = 0;
4425 asoc->total_flight_count = 0;
4429 * We init netAckSz and netAckSz2 to 0. These are used to track 2
4430 * things. The total byte count acked is tracked in netAckSz AND
4431 * netAck2 is used to track the total bytes acked that are un-
4432 * amibguious and were never retransmitted. We track these on a per
4433 * destination address basis.
4435 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4436 net->prev_cwnd = net->cwnd;
4441 * CMT: Reset CUC and Fast recovery algo variables before
4444 net->new_pseudo_cumack = 0;
4445 net->will_exit_fast_recovery = 0;
4447 /* process the new consecutive TSN first */
4448 tp1 = TAILQ_FIRST(&asoc->sent_queue);
4450 if (compare_with_wrap(last_tsn, tp1->rec.data.TSN_seq,
4452 last_tsn == tp1->rec.data.TSN_seq) {
4453 if (tp1->sent != SCTP_DATAGRAM_UNSENT) {
4455 * ECN Nonce: Add the nonce to the sender's
4458 asoc->nonce_sum_expect_base += tp1->rec.data.ect_nonce;
4460 if (tp1->sent < SCTP_DATAGRAM_ACKED) {
4462 * If it is less than ACKED, it is
4463 * now no-longer in flight. Higher
4464 * values may occur during marking
4466 if ((tp1->whoTo->dest_state &
4467 SCTP_ADDR_UNCONFIRMED) &&
4468 (tp1->snd_count < 2)) {
4470 * If there was no retran
4471 * and the address is
4472 * un-confirmed and we sent
4474 * sacked.. its confirmed,
4477 tp1->whoTo->dest_state &=
4478 ~SCTP_ADDR_UNCONFIRMED;
4480 if (tp1->sent < SCTP_DATAGRAM_RESEND) {
4481 if (sctp_logging_level & SCTP_FLIGHT_LOGGING_ENABLE) {
4482 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA,
4483 tp1->whoTo->flight_size,
4485 (uintptr_t) tp1->whoTo,
4486 tp1->rec.data.TSN_seq);
4488 sctp_flight_size_decrease(tp1);
4489 sctp_total_flight_decrease(stcb, tp1);
4491 tp1->whoTo->net_ack += tp1->send_size;
4493 /* CMT SFR and DAC algos */
4494 this_sack_lowest_newack = tp1->rec.data.TSN_seq;
4495 tp1->whoTo->saw_newack = 1;
4497 if (tp1->snd_count < 2) {
4499 * True non-retransmited
4502 tp1->whoTo->net_ack2 +=
4505 /* update RTO too? */
4508 sctp_calculate_rto(stcb,
4510 &tp1->sent_rcv_time,
4511 sctp_align_safe_nocopy);
4516 * CMT: CUCv2 algorithm. From the
4517 * cumack'd TSNs, for each TSN being
4518 * acked for the first time, set the
4519 * following variables for the
4520 * corresp destination.
4521 * new_pseudo_cumack will trigger a
4523 * find_(rtx_)pseudo_cumack will
4524 * trigger search for the next
4525 * expected (rtx-)pseudo-cumack.
4527 tp1->whoTo->new_pseudo_cumack = 1;
4528 tp1->whoTo->find_pseudo_cumack = 1;
4529 tp1->whoTo->find_rtx_pseudo_cumack = 1;
4532 if (sctp_logging_level & SCTP_SACK_LOGGING_ENABLE) {
4533 sctp_log_sack(asoc->last_acked_seq,
4535 tp1->rec.data.TSN_seq,
4538 SCTP_LOG_TSN_ACKED);
4540 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
4541 sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK);
4544 if (tp1->sent == SCTP_DATAGRAM_RESEND) {
4545 sctp_ucount_decr(asoc->sent_queue_retran_cnt);
4546 #ifdef SCTP_AUDITING_ENABLED
4547 sctp_audit_log(0xB3,
4548 (asoc->sent_queue_retran_cnt & 0x000000ff));
4551 if (tp1->rec.data.chunk_was_revoked) {
4552 /* deflate the cwnd */
4553 tp1->whoTo->cwnd -= tp1->book_size;
4554 tp1->rec.data.chunk_was_revoked = 0;
4556 tp1->sent = SCTP_DATAGRAM_ACKED;
4561 tp1 = TAILQ_NEXT(tp1, sctp_next);
4563 biggest_tsn_newly_acked = biggest_tsn_acked = last_tsn;
4564 /* always set this up to cum-ack */
4565 asoc->this_sack_highest_gap = last_tsn;
4567 /* Move offset up to point to gaps/dups */
4568 offset += sizeof(struct sctp_sack_chunk);
4569 if (((num_seg * (sizeof(struct sctp_gap_ack_block))) + sizeof(struct sctp_sack_chunk)) > sack_length) {
4571 /* skip corrupt segments */
4577 * CMT: SFR algo (and HTNA) - this_sack_highest_newack has
4578 * to be greater than the cumack. Also reset saw_newack to 0
4581 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4582 net->saw_newack = 0;
4583 net->this_sack_highest_newack = last_tsn;
4587 * thisSackHighestGap will increase while handling NEW
4588 * segments this_sack_highest_newack will increase while
4589 * handling NEWLY ACKED chunks. this_sack_lowest_newack is
4590 * used for CMT DAC algo. saw_newack will also change.
4592 sctp_handle_segments(m, &offset, stcb, asoc, ch, last_tsn,
4593 &biggest_tsn_acked, &biggest_tsn_newly_acked, &this_sack_lowest_newack,
4594 num_seg, &ecn_seg_sums);
4596 if (sctp_strict_sacks) {
4598 * validate the biggest_tsn_acked in the gap acks if
4599 * strict adherence is wanted.
4601 if ((biggest_tsn_acked == send_s) ||
4602 (compare_with_wrap(biggest_tsn_acked, send_s, MAX_TSN))) {
4604 * peer is either confused or we are under
4605 * attack. We must abort.
4612 /*******************************************/
4613 /* cancel ALL T3-send timer if accum moved */
4614 /*******************************************/
4615 if (sctp_cmt_on_off) {
4616 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4617 if (net->new_pseudo_cumack)
4618 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
4620 SCTP_FROM_SCTP_INDATA + SCTP_LOC_27);
4625 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4626 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
4627 stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_28);
4631 /********************************************/
4632 /* drop the acked chunks from the sendqueue */
4633 /********************************************/
4634 asoc->last_acked_seq = cum_ack;
4636 tp1 = TAILQ_FIRST(&asoc->sent_queue);
4640 if (compare_with_wrap(tp1->rec.data.TSN_seq, cum_ack,
4644 if (tp1->sent == SCTP_DATAGRAM_UNSENT) {
4645 /* no more sent on list */
4646 printf("Warning, tp1->sent == %d and its now acked?\n",
4649 tp2 = TAILQ_NEXT(tp1, sctp_next);
4650 TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next);
4651 if (tp1->pr_sctp_on) {
4652 if (asoc->pr_sctp_cnt != 0)
4653 asoc->pr_sctp_cnt--;
4655 if ((TAILQ_FIRST(&asoc->sent_queue) == NULL) &&
4656 (asoc->total_flight > 0)) {
4658 panic("Warning flight size is postive and should be 0");
4660 SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n",
4661 asoc->total_flight);
4663 asoc->total_flight = 0;
4666 sctp_free_bufspace(stcb, asoc, tp1, 1);
4667 sctp_m_freem(tp1->data);
4668 if (PR_SCTP_BUF_ENABLED(tp1->flags)) {
4669 asoc->sent_queue_cnt_removeable--;
4672 if (sctp_logging_level & SCTP_SACK_LOGGING_ENABLE) {
4673 sctp_log_sack(asoc->last_acked_seq,
4675 tp1->rec.data.TSN_seq,
4678 SCTP_LOG_FREE_SENT);
4681 asoc->sent_queue_cnt--;
4682 sctp_free_a_chunk(stcb, tp1);
4685 } while (tp1 != NULL);
4688 if ((wake_him) && (stcb->sctp_socket)) {
4689 SOCKBUF_LOCK(&stcb->sctp_socket->so_snd);
4690 if (sctp_logging_level & SCTP_WAKE_LOGGING_ENABLE) {
4691 sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_WAKESND_FROM_SACK);
4693 sctp_sowwakeup_locked(stcb->sctp_ep, stcb->sctp_socket);
4695 if (sctp_logging_level & SCTP_WAKE_LOGGING_ENABLE) {
4696 sctp_wakeup_log(stcb, cum_ack, wake_him, SCTP_NOWAKE_FROM_SACK);
4700 if (asoc->fast_retran_loss_recovery && accum_moved) {
4701 if (compare_with_wrap(asoc->last_acked_seq,
4702 asoc->fast_recovery_tsn, MAX_TSN) ||
4703 asoc->last_acked_seq == asoc->fast_recovery_tsn) {
4704 /* Setup so we will exit RFC2582 fast recovery */
4705 will_exit_fast_recovery = 1;
4709 * Check for revoked fragments:
4711 * if Previous sack - Had no frags then we can't have any revoked if
4712 * Previous sack - Had frag's then - If we now have frags aka
4713 * num_seg > 0 call sctp_check_for_revoked() to tell if peer revoked
4714 * some of them. else - The peer revoked all ACKED fragments, since
4715 * we had some before and now we have NONE.
4719 sctp_check_for_revoked(stcb, asoc, cum_ack, biggest_tsn_acked);
4720 else if (asoc->saw_sack_with_frags) {
4721 int cnt_revoked = 0;
4723 tp1 = TAILQ_FIRST(&asoc->sent_queue);
4725 /* Peer revoked all dg's marked or acked */
4726 TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) {
4727 if ((tp1->sent > SCTP_DATAGRAM_RESEND) &&
4728 (tp1->sent < SCTP_FORWARD_TSN_SKIP)) {
4729 tp1->sent = SCTP_DATAGRAM_SENT;
4730 if (sctp_logging_level & SCTP_FLIGHT_LOGGING_ENABLE) {
4731 sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE,
4732 tp1->whoTo->flight_size,
4734 (uintptr_t) tp1->whoTo,
4735 tp1->rec.data.TSN_seq);
4737 sctp_flight_size_increase(tp1);
4738 sctp_total_flight_increase(stcb, tp1);
4739 tp1->rec.data.chunk_was_revoked = 1;
4741 * To ensure that this increase in
4742 * flightsize, which is artificial,
4743 * does not throttle the sender, we
4744 * also increase the cwnd
4747 tp1->whoTo->cwnd += tp1->book_size;
4755 asoc->saw_sack_with_frags = 0;
4758 asoc->saw_sack_with_frags = 1;
4760 asoc->saw_sack_with_frags = 0;
4762 /* JRS - Use the congestion control given in the CC module */
4763 asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, accum_moved, reneged_all, will_exit_fast_recovery);
4765 if (TAILQ_EMPTY(&asoc->sent_queue)) {
4766 /* nothing left in-flight */
4767 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4768 /* stop all timers */
4769 if (sctp_early_fr) {
4770 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
4771 SCTP_STAT_INCR(sctps_earlyfrstpidsck4);
4772 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
4773 SCTP_FROM_SCTP_INDATA + SCTP_LOC_29);
4776 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
4777 stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_30);
4778 net->flight_size = 0;
4779 net->partial_bytes_acked = 0;
4781 asoc->total_flight = 0;
4782 asoc->total_flight_count = 0;
4784 /**********************************/
4785 /* Now what about shutdown issues */
4786 /**********************************/
4787 if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) {
4788 /* nothing left on sendqueue.. consider done */
4789 if (sctp_logging_level & SCTP_LOG_RWND_ENABLE) {
4790 sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK,
4791 asoc->peers_rwnd, 0, 0, a_rwnd);
4793 asoc->peers_rwnd = a_rwnd;
4794 if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
4795 /* SWS sender side engages */
4796 asoc->peers_rwnd = 0;
4799 if ((asoc->stream_queue_cnt == 1) &&
4800 ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) ||
4801 (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) &&
4802 (asoc->locked_on_sending)
4804 struct sctp_stream_queue_pending *sp;
4807 * I may be in a state where we got all across.. but
4808 * cannot write more due to a shutdown... we abort
4809 * since the user did not indicate EOR in this case.
4811 sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue),
4813 if ((sp) && (sp->length == 0) && (sp->msg_is_complete == 0)) {
4814 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
4815 asoc->locked_on_sending = NULL;
4816 asoc->stream_queue_cnt--;
4819 if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) &&
4820 (asoc->stream_queue_cnt == 0)) {
4821 if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) {
4822 /* Need to abort here */
4828 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
4829 0, M_DONTWAIT, 1, MT_DATA);
4831 struct sctp_paramhdr *ph;
4834 SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) +
4836 ph = mtod(oper, struct sctp_paramhdr *);
4837 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
4838 ph->param_length = htons(SCTP_BUF_LEN(oper));
4839 ippp = (uint32_t *) (ph + 1);
4840 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_31);
4842 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_31;
4843 sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, oper);
4846 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
4847 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
4848 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
4850 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
4851 sctp_stop_timers_for_shutdown(stcb);
4852 sctp_send_shutdown(stcb,
4853 stcb->asoc.primary_destination);
4854 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
4855 stcb->sctp_ep, stcb, asoc->primary_destination);
4856 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
4857 stcb->sctp_ep, stcb, asoc->primary_destination);
4860 } else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) &&
4861 (asoc->stream_queue_cnt == 0)) {
4862 if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) {
4865 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
4866 asoc->state = SCTP_STATE_SHUTDOWN_ACK_SENT;
4867 sctp_send_shutdown_ack(stcb,
4868 stcb->asoc.primary_destination);
4870 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK,
4871 stcb->sctp_ep, stcb, asoc->primary_destination);
4876 * Now here we are going to recycle net_ack for a different use...
4879 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
4884 * CMT DAC algorithm: If SACK DAC flag was 0, then no extra marking
4885 * to be done. Setting this_sack_lowest_newack to the cum_ack will
4886 * automatically ensure that.
4888 if (sctp_cmt_on_off && sctp_cmt_use_dac && (cmt_dac_flag == 0)) {
4889 this_sack_lowest_newack = cum_ack;
4892 sctp_strike_gap_ack_chunks(stcb, asoc, biggest_tsn_acked,
4893 biggest_tsn_newly_acked, this_sack_lowest_newack, accum_moved);
4895 /*********************************************/
4896 /* Here we perform PR-SCTP procedures */
4898 /*********************************************/
4899 /* C1. update advancedPeerAckPoint */
4900 if (compare_with_wrap(cum_ack, asoc->advanced_peer_ack_point, MAX_TSN)) {
4901 asoc->advanced_peer_ack_point = cum_ack;
4903 /* C2. try to further move advancedPeerAckPoint ahead */
4905 if ((asoc->peer_supports_prsctp) && (asoc->pr_sctp_cnt > 0)) {
4906 struct sctp_tmit_chunk *lchk;
4908 lchk = sctp_try_advance_peer_ack_point(stcb, asoc);
4909 /* C3. See if we need to send a Fwd-TSN */
4910 if (compare_with_wrap(asoc->advanced_peer_ack_point, cum_ack,
4913 * ISSUE with ECN, see FWD-TSN processing for notes
4914 * on issues that will occur when the ECN NONCE
4915 * stuff is put into SCTP for cross checking.
4917 send_forward_tsn(stcb, asoc);
4920 * ECN Nonce: Disable Nonce Sum check when FWD TSN
4921 * is sent and store resync tsn
4923 asoc->nonce_sum_check = 0;
4924 asoc->nonce_resync_tsn = asoc->advanced_peer_ack_point;
4926 /* Assure a timer is up */
4927 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
4928 stcb->sctp_ep, stcb, lchk->whoTo);
4932 /* JRS - Use the congestion control given in the CC module */
4933 asoc->cc_functions.sctp_cwnd_update_after_fr(stcb, asoc);
4935 /******************************************************************
4936 * Here we do the stuff with ECN Nonce checking.
4937 * We basically check to see if the nonce sum flag was incorrect
4938 * or if resynchronization needs to be done. Also if we catch a
4939 * misbehaving receiver we give him the kick.
4940 ******************************************************************/
4942 if (asoc->ecn_nonce_allowed) {
4943 if (asoc->nonce_sum_check) {
4944 if (nonce_sum_flag != ((asoc->nonce_sum_expect_base + ecn_seg_sums) & SCTP_SACK_NONCE_SUM)) {
4945 if (asoc->nonce_wait_for_ecne == 0) {
4946 struct sctp_tmit_chunk *lchk;
4948 lchk = TAILQ_FIRST(&asoc->send_queue);
4949 asoc->nonce_wait_for_ecne = 1;
4951 asoc->nonce_wait_tsn = lchk->rec.data.TSN_seq;
4953 asoc->nonce_wait_tsn = asoc->sending_seq;
4956 if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_wait_tsn, MAX_TSN) ||
4957 (asoc->last_acked_seq == asoc->nonce_wait_tsn)) {
4959 * Misbehaving peer. We need
4960 * to react to this guy
4962 asoc->ecn_allowed = 0;
4963 asoc->ecn_nonce_allowed = 0;
4968 /* See if Resynchronization Possible */
4969 if (compare_with_wrap(asoc->last_acked_seq, asoc->nonce_resync_tsn, MAX_TSN)) {
4970 asoc->nonce_sum_check = 1;
4972 * now we must calculate what the base is.
4973 * We do this based on two things, we know
4974 * the total's for all the segments
4975 * gap-acked in the SACK, its stored in
4976 * ecn_seg_sums. We also know the SACK's
4977 * nonce sum, its in nonce_sum_flag. So we
4978 * can build a truth table to back-calculate
4980 * asoc->nonce_sum_expect_base:
4982 * SACK-flag-Value Seg-Sums Base 0 0 0
4986 asoc->nonce_sum_expect_base = (ecn_seg_sums ^ nonce_sum_flag) & SCTP_SACK_NONCE_SUM;
4990 /* Now are we exiting loss recovery ? */
4991 if (will_exit_fast_recovery) {
4992 /* Ok, we must exit fast recovery */
4993 asoc->fast_retran_loss_recovery = 0;
4995 if ((asoc->sat_t3_loss_recovery) &&
4996 ((compare_with_wrap(asoc->last_acked_seq, asoc->sat_t3_recovery_tsn,
4998 (asoc->last_acked_seq == asoc->sat_t3_recovery_tsn)))) {
4999 /* end satellite t3 loss recovery */
5000 asoc->sat_t3_loss_recovery = 0;
5005 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
5006 if (net->will_exit_fast_recovery) {
5007 /* Ok, we must exit fast recovery */
5008 net->fast_retran_loss_recovery = 0;
5012 /* Adjust and set the new rwnd value */
5013 if (sctp_logging_level & SCTP_LOG_RWND_ENABLE) {
5014 sctp_log_rwnd_set(SCTP_SET_PEER_RWND_VIA_SACK,
5015 asoc->peers_rwnd, asoc->total_flight, (asoc->sent_queue_cnt * sctp_peer_chunk_oh), a_rwnd);
5017 asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd,
5018 (uint32_t) (asoc->total_flight + (asoc->sent_queue_cnt * sctp_peer_chunk_oh)));
5019 if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
5020 /* SWS sender side engages */
5021 asoc->peers_rwnd = 0;
5023 if (asoc->peers_rwnd > old_rwnd) {
5024 win_probe_recovery = 1;
5027 * Now we must setup so we have a timer up for anyone with
5033 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
5034 if (win_probe_recovery && (net->window_probe)) {
5035 net->window_probe = 0;
5036 win_probe_recovered = 1;
5038 * Find first chunk that was used with
5039 * window probe and clear the event. Put
5040 * it back into the send queue as if has
5043 TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) {
5044 if (tp1->window_probe) {
5045 sctp_window_probe_recovery(stcb, asoc, net, tp1);
5050 if (net->flight_size) {
5052 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
5053 stcb->sctp_ep, stcb, net);
5055 if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
5056 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
5058 SCTP_FROM_SCTP_INDATA + SCTP_LOC_22);
5060 if (sctp_early_fr) {
5061 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
5062 SCTP_STAT_INCR(sctps_earlyfrstpidsck4);
5063 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
5064 SCTP_FROM_SCTP_INDATA + SCTP_LOC_23);
5070 (!TAILQ_EMPTY(&asoc->sent_queue)) &&
5071 (asoc->sent_queue_retran_cnt == 0) &&
5072 (win_probe_recovered == 0) &&
5074 /* huh, this should not happen */
5075 sctp_fs_audit(asoc);
5076 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
5077 net->flight_size = 0;
5079 asoc->total_flight = 0;
5080 asoc->total_flight_count = 0;
5081 asoc->sent_queue_retran_cnt = 0;
5082 TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) {
5083 if (tp1->sent < SCTP_DATAGRAM_RESEND) {
5084 sctp_flight_size_increase(tp1);
5085 sctp_total_flight_increase(stcb, tp1);
5086 } else if (tp1->sent == SCTP_DATAGRAM_RESEND) {
5087 asoc->sent_queue_retran_cnt++;
5093 if (sctp_logging_level & SCTP_SACK_RWND_LOGGING_ENABLE) {
5094 sctp_misc_ints(SCTP_SACK_RWND_UPDATE,
5096 stcb->asoc.peers_rwnd,
5097 stcb->asoc.total_flight,
5098 stcb->asoc.total_output_queue_size);
5103 sctp_update_acked(struct sctp_tcb *stcb, struct sctp_shutdown_chunk *cp,
5104 struct sctp_nets *netp, int *abort_flag)
5107 uint32_t cum_ack, a_rwnd;
5109 cum_ack = ntohl(cp->cumulative_tsn_ack);
5110 /* Arrange so a_rwnd does NOT change */
5111 a_rwnd = stcb->asoc.peers_rwnd + stcb->asoc.total_flight;
5113 /* Now call the express sack handling */
5114 sctp_express_handle_sack(stcb, cum_ack, a_rwnd, 0, abort_flag);
5118 sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb,
5119 struct sctp_stream_in *strmin)
5121 struct sctp_queued_to_read *ctl, *nctl;
5122 struct sctp_association *asoc;
5126 tt = strmin->last_sequence_delivered;
5128 * First deliver anything prior to and including the stream no that
5131 ctl = TAILQ_FIRST(&strmin->inqueue);
5133 nctl = TAILQ_NEXT(ctl, next);
5134 if (compare_with_wrap(tt, ctl->sinfo_ssn, MAX_SEQ) ||
5135 (tt == ctl->sinfo_ssn)) {
5136 /* this is deliverable now */
5137 TAILQ_REMOVE(&strmin->inqueue, ctl, next);
5138 /* subtract pending on streams */
5139 asoc->size_on_all_streams -= ctl->length;
5140 sctp_ucount_decr(asoc->cnt_on_all_streams);
5141 /* deliver it to at least the delivery-q */
5142 if (stcb->sctp_socket) {
5143 sctp_add_to_readq(stcb->sctp_ep, stcb,
5145 &stcb->sctp_socket->so_rcv, 1);
5148 /* no more delivery now. */
5154 * now we must deliver things in queue the normal way if any are
5157 tt = strmin->last_sequence_delivered + 1;
5158 ctl = TAILQ_FIRST(&strmin->inqueue);
5160 nctl = TAILQ_NEXT(ctl, next);
5161 if (tt == ctl->sinfo_ssn) {
5162 /* this is deliverable now */
5163 TAILQ_REMOVE(&strmin->inqueue, ctl, next);
5164 /* subtract pending on streams */
5165 asoc->size_on_all_streams -= ctl->length;
5166 sctp_ucount_decr(asoc->cnt_on_all_streams);
5167 /* deliver it to at least the delivery-q */
5168 strmin->last_sequence_delivered = ctl->sinfo_ssn;
5169 if (stcb->sctp_socket) {
5170 sctp_add_to_readq(stcb->sctp_ep, stcb,
5172 &stcb->sctp_socket->so_rcv, 1);
5174 tt = strmin->last_sequence_delivered + 1;
5183 sctp_handle_forward_tsn(struct sctp_tcb *stcb,
5184 struct sctp_forward_tsn_chunk *fwd, int *abort_flag, struct mbuf *m, int offset)
5187 * ISSUES that MUST be fixed for ECN! When we are the sender of the
5188 * forward TSN, when the SACK comes back that acknowledges the
5189 * FWD-TSN we must reset the NONCE sum to match correctly. This will
5190 * get quite tricky since we may have sent more data interveneing
5191 * and must carefully account for what the SACK says on the nonce
5192 * and any gaps that are reported. This work will NOT be done here,
5193 * but I note it here since it is really related to PR-SCTP and
5197 /* The pr-sctp fwd tsn */
5199 * here we will perform all the data receiver side steps for
5200 * processing FwdTSN, as required in by pr-sctp draft:
5202 * Assume we get FwdTSN(x):
5204 * 1) update local cumTSN to x 2) try to further advance cumTSN to x +
5205 * others we have 3) examine and update re-ordering queue on
5206 * pr-in-streams 4) clean up re-assembly queue 5) Send a sack to
5207 * report where we are.
5209 struct sctp_association *asoc;
5210 uint32_t new_cum_tsn, gap, back_out_htsn;
5211 unsigned int i, cnt_gone, fwd_sz, cumack_set_flag, m_size;
5212 struct sctp_stream_in *strm;
5213 struct sctp_tmit_chunk *chk, *at;
5215 cumack_set_flag = 0;
5218 if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) {
5219 SCTPDBG(SCTP_DEBUG_INDATA1,
5220 "Bad size too small/big fwd-tsn\n");
5223 m_size = (stcb->asoc.mapping_array_size << 3);
5224 /*************************************************************/
5225 /* 1. Here we update local cumTSN and shift the bitmap array */
5226 /*************************************************************/
5227 new_cum_tsn = ntohl(fwd->new_cumulative_tsn);
5229 if (compare_with_wrap(asoc->cumulative_tsn, new_cum_tsn, MAX_TSN) ||
5230 asoc->cumulative_tsn == new_cum_tsn) {
5231 /* Already got there ... */
5234 back_out_htsn = asoc->highest_tsn_inside_map;
5235 if (compare_with_wrap(new_cum_tsn, asoc->highest_tsn_inside_map,
5237 asoc->highest_tsn_inside_map = new_cum_tsn;
5238 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
5239 sctp_log_map(0, 0, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
5243 * now we know the new TSN is more advanced, let's find the actual
5246 if ((compare_with_wrap(new_cum_tsn, asoc->mapping_array_base_tsn,
5248 (new_cum_tsn == asoc->mapping_array_base_tsn)) {
5249 gap = new_cum_tsn - asoc->mapping_array_base_tsn;
5251 /* try to prevent underflow here */
5252 gap = new_cum_tsn + (MAX_TSN - asoc->mapping_array_base_tsn) + 1;
5256 asoc->highest_tsn_inside_map = back_out_htsn;
5257 if ((long)gap > sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv)) {
5261 * out of range (of single byte chunks in the rwnd I
5262 * give out). This must be an attacker.
5265 oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
5266 0, M_DONTWAIT, 1, MT_DATA);
5268 struct sctp_paramhdr *ph;
5271 SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) +
5272 (sizeof(uint32_t) * 3);
5273 ph = mtod(oper, struct sctp_paramhdr *);
5274 ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
5275 ph->param_length = htons(SCTP_BUF_LEN(oper));
5276 ippp = (uint32_t *) (ph + 1);
5277 *ippp = htonl(SCTP_FROM_SCTP_INDATA + SCTP_LOC_33);
5279 *ippp = asoc->highest_tsn_inside_map;
5281 *ippp = new_cum_tsn;
5283 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_33;
5284 sctp_abort_an_association(stcb->sctp_ep, stcb,
5285 SCTP_PEER_FAULTY, oper);
5288 if (asoc->highest_tsn_inside_map >
5289 asoc->mapping_array_base_tsn) {
5290 gap = asoc->highest_tsn_inside_map -
5291 asoc->mapping_array_base_tsn;
5293 gap = asoc->highest_tsn_inside_map +
5294 (MAX_TSN - asoc->mapping_array_base_tsn) + 1;
5296 SCTP_STAT_INCR(sctps_fwdtsn_map_over);
5297 cumack_set_flag = 1;
5299 SCTP_TCB_LOCK_ASSERT(stcb);
5300 for (i = 0; i <= gap; i++) {
5301 SCTP_SET_TSN_PRESENT(asoc->mapping_array, i);
5304 * Now after marking all, slide thing forward but no sack please.
5306 sctp_sack_check(stcb, 0, 0, abort_flag);
5310 if (cumack_set_flag) {
5312 * fwd-tsn went outside my gap array - not a common
5313 * occurance. Do the same thing we do when a cookie-echo
5316 asoc->highest_tsn_inside_map = new_cum_tsn - 1;
5317 asoc->mapping_array_base_tsn = new_cum_tsn;
5318 asoc->cumulative_tsn = asoc->highest_tsn_inside_map;
5319 if (sctp_logging_level & SCTP_MAP_LOGGING_ENABLE) {
5320 sctp_log_map(0, 3, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
5322 asoc->last_echo_tsn = asoc->highest_tsn_inside_map;
5324 /*************************************************************/
5325 /* 2. Clear up re-assembly queue */
5326 /*************************************************************/
5329 * First service it if pd-api is up, just in case we can progress it
5332 if (asoc->fragmented_delivery_inprogress) {
5333 sctp_service_reassembly(stcb, asoc);
5335 if (!TAILQ_EMPTY(&asoc->reasmqueue)) {
5336 /* For each one on here see if we need to toss it */
5338 * For now large messages held on the reasmqueue that are
5339 * complete will be tossed too. We could in theory do more
5340 * work to spin through and stop after dumping one msg aka
5341 * seeing the start of a new msg at the head, and call the
5342 * delivery function... to see if it can be delivered... But
5343 * for now we just dump everything on the queue.
5345 chk = TAILQ_FIRST(&asoc->reasmqueue);
5347 at = TAILQ_NEXT(chk, sctp_next);
5348 if (compare_with_wrap(asoc->cumulative_tsn,
5349 chk->rec.data.TSN_seq, MAX_TSN) ||
5350 asoc->cumulative_tsn == chk->rec.data.TSN_seq) {
5351 /* It needs to be tossed */
5352 TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
5353 if (compare_with_wrap(chk->rec.data.TSN_seq,
5354 asoc->tsn_last_delivered, MAX_TSN)) {
5355 asoc->tsn_last_delivered =
5356 chk->rec.data.TSN_seq;
5357 asoc->str_of_pdapi =
5358 chk->rec.data.stream_number;
5359 asoc->ssn_of_pdapi =
5360 chk->rec.data.stream_seq;
5361 asoc->fragment_flags =
5362 chk->rec.data.rcv_flags;
5364 asoc->size_on_reasm_queue -= chk->send_size;
5365 sctp_ucount_decr(asoc->cnt_on_reasm_queue);
5368 /* Clear up any stream problem */
5369 if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) !=
5370 SCTP_DATA_UNORDERED &&
5371 (compare_with_wrap(chk->rec.data.stream_seq,
5372 asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered,
5375 * We must dump forward this streams
5376 * sequence number if the chunk is
5377 * not unordered that is being
5378 * skipped. There is a chance that
5379 * if the peer does not include the
5380 * last fragment in its FWD-TSN we
5381 * WILL have a problem here since
5382 * you would have a partial chunk in
5383 * queue that may not be
5384 * deliverable. Also if a Partial
5385 * delivery API as started the user
5386 * may get a partial chunk. The next
5387 * read returning a new chunk...
5388 * really ugly but I see no way
5389 * around it! Maybe a notify??
5391 asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered =
5392 chk->rec.data.stream_seq;
5395 sctp_m_freem(chk->data);
5398 sctp_free_a_chunk(stcb, chk);
5401 * Ok we have gone beyond the end of the
5402 * fwd-tsn's mark. Some checks...
5404 if ((asoc->fragmented_delivery_inprogress) &&
5405 (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG)) {
5409 * Special case PD-API is up and
5410 * what we fwd-tsn' over includes
5411 * one that had the LAST_FRAG. We no
5412 * longer need to do the PD-API.
5414 asoc->fragmented_delivery_inprogress = 0;
5416 str_seq = (asoc->str_of_pdapi << 16) | asoc->ssn_of_pdapi;
5417 sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION,
5418 stcb, SCTP_PARTIAL_DELIVERY_ABORTED, (void *)&str_seq);
5426 if (asoc->fragmented_delivery_inprogress) {
5428 * Ok we removed cnt_gone chunks in the PD-API queue that
5429 * were being delivered. So now we must turn off the flag.
5433 str_seq = (asoc->str_of_pdapi << 16) | asoc->ssn_of_pdapi;
5434 sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION,
5435 stcb, SCTP_PARTIAL_DELIVERY_ABORTED, (void *)&str_seq);
5436 asoc->fragmented_delivery_inprogress = 0;
5438 /*************************************************************/
5439 /* 3. Update the PR-stream re-ordering queues */
5440 /*************************************************************/
5441 fwd_sz -= sizeof(*fwd);
5444 unsigned int num_str;
5445 struct sctp_strseq *stseq, strseqbuf;
5447 offset += sizeof(*fwd);
5449 num_str = fwd_sz / sizeof(struct sctp_strseq);
5450 for (i = 0; i < num_str; i++) {
5454 stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset,
5455 sizeof(struct sctp_strseq),
5456 (uint8_t *) & strseqbuf);
5457 offset += sizeof(struct sctp_strseq);
5461 xx = (unsigned char *)&stseq[i];
5462 st = ntohs(stseq[i].stream);
5463 stseq[i].stream = st;
5464 st = ntohs(stseq[i].sequence);
5465 stseq[i].sequence = st;
5467 if (stseq[i].stream >= asoc->streamincnt) {
5469 * It is arguable if we should continue.
5470 * Since the peer sent bogus stream info we
5471 * may be in deep trouble.. a return may be
5476 strm = &asoc->strmin[stseq[i].stream];
5477 if (compare_with_wrap(stseq[i].sequence,
5478 strm->last_sequence_delivered, MAX_SEQ)) {
5479 /* Update the sequence number */
5480 strm->last_sequence_delivered =
5483 /* now kick the stream the new way */
5484 sctp_kick_prsctp_reorder_queue(stcb, strm);
5487 if (TAILQ_FIRST(&asoc->reasmqueue)) {
5488 /* now lets kick out and check for more fragmented delivery */
5489 sctp_deliver_reasm_check(stcb, &stcb->asoc);