1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2003 Intel Corp.
7 * This file is part of the SCTP kernel reference Implementation
9 * These functions implement the sctp_outq class. The outqueue handles
10 * bundling and queueing of outgoing SCTP chunks.
12 * The SCTP reference implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * The SCTP reference implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
29 * Please send any bug reports or fixes you make to the
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
36 * Written or modified by:
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Perry Melange <pmelange@null.cc.uic.edu>
40 * Xingang Guo <xingang.guo@intel.com>
41 * Hui Huang <hui.huang@nokia.com>
42 * Sridhar Samudrala <sri@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
45 * Any bugs reported given to us we will try to fix... any fixes shared will
46 * be incorporated into the next SCTP release.
49 #include <linux/types.h>
50 #include <linux/list.h> /* For struct list_head */
51 #include <linux/socket.h>
53 #include <net/sock.h> /* For skb_set_owner_w */
55 #include <net/sctp/sctp.h>
56 #include <net/sctp/sm.h>
58 /* Declare internal functions here. */
59 static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn);
60 static void sctp_check_transmitted(struct sctp_outq *q,
61 struct list_head *transmitted_queue,
62 struct sctp_transport *transport,
63 struct sctp_sackhdr *sack,
64 __u32 highest_new_tsn);
66 static void sctp_mark_missing(struct sctp_outq *q,
67 struct list_head *transmitted_queue,
68 struct sctp_transport *transport,
69 __u32 highest_new_tsn,
70 int count_of_newacks);
72 static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
74 /* Add data to the front of the queue. */
75 static inline void sctp_outq_head_data(struct sctp_outq *q,
76 struct sctp_chunk *ch)
78 __skb_queue_head(&q->out, (struct sk_buff *)ch);
79 q->out_qlen += ch->skb->len;
83 /* Take data from the front of the queue. */
84 static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q)
86 struct sctp_chunk *ch;
87 ch = (struct sctp_chunk *)__skb_dequeue(&q->out);
89 q->out_qlen -= ch->skb->len;
92 /* Add data chunk to the end of the queue. */
93 static inline void sctp_outq_tail_data(struct sctp_outq *q,
94 struct sctp_chunk *ch)
96 __skb_queue_tail(&q->out, (struct sk_buff *)ch);
97 q->out_qlen += ch->skb->len;
101 /* Insert a chunk behind chunk 'pos'. */
102 static inline void sctp_outq_insert_data(struct sctp_outq *q,
103 struct sctp_chunk *ch,
104 struct sctp_chunk *pos)
106 __skb_insert((struct sk_buff *)ch, (struct sk_buff *)pos->prev,
107 (struct sk_buff *)pos, pos->list);
108 q->out_qlen += ch->skb->len;
112 * SFR-CACC algorithm:
113 * D) If count_of_newacks is greater than or equal to 2
114 * and t was not sent to the current primary then the
115 * sender MUST NOT increment missing report count for t.
117 static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary,
118 struct sctp_transport *transport,
119 int count_of_newacks)
121 if (count_of_newacks >=2 && transport != primary)
127 * SFR-CACC algorithm:
128 * F) If count_of_newacks is less than 2, let d be the
129 * destination to which t was sent. If cacc_saw_newack
130 * is 0 for destination d, then the sender MUST NOT
131 * increment missing report count for t.
133 static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport,
134 int count_of_newacks)
136 if (count_of_newacks < 2 && !transport->cacc.cacc_saw_newack)
142 * SFR-CACC algorithm:
143 * 3.1) If CYCLING_CHANGEOVER is 0, the sender SHOULD
144 * execute steps C, D, F.
146 * C has been implemented in sctp_outq_sack
148 static inline int sctp_cacc_skip_3_1(struct sctp_transport *primary,
149 struct sctp_transport *transport,
150 int count_of_newacks)
152 if (!primary->cacc.cycling_changeover) {
153 if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks))
155 if (sctp_cacc_skip_3_1_f(transport, count_of_newacks))
163 * SFR-CACC algorithm:
164 * 3.2) Else if CYCLING_CHANGEOVER is 1, and t is less
165 * than next_tsn_at_change of the current primary, then
166 * the sender MUST NOT increment missing report count
169 static inline int sctp_cacc_skip_3_2(struct sctp_transport *primary, __u32 tsn)
171 if (primary->cacc.cycling_changeover &&
172 TSN_lt(tsn, primary->cacc.next_tsn_at_change))
178 * SFR-CACC algorithm:
179 * 3) If the missing report count for TSN t is to be
180 * incremented according to [RFC2960] and
181 * [SCTP_STEWART-2002], and CHANGEOVER_ACTIVE is set,
182 * then the sender MUST futher execute steps 3.1 and
183 * 3.2 to determine if the missing report count for
184 * TSN t SHOULD NOT be incremented.
186 * 3.3) If 3.1 and 3.2 do not dictate that the missing
187 * report count for t should not be incremented, then
188 * the sender SOULD increment missing report count for
189 * t (according to [RFC2960] and [SCTP_STEWART_2002]).
191 static inline int sctp_cacc_skip(struct sctp_transport *primary,
192 struct sctp_transport *transport,
193 int count_of_newacks,
196 if (primary->cacc.changeover_active &&
197 (sctp_cacc_skip_3_1(primary, transport, count_of_newacks)
198 || sctp_cacc_skip_3_2(primary, tsn)))
203 /* Generate a new outqueue. */
204 struct sctp_outq *sctp_outq_new(struct sctp_association *asoc)
208 q = t_new(struct sctp_outq, GFP_KERNEL);
210 sctp_outq_init(asoc, q);
216 /* Initialize an existing sctp_outq. This does the boring stuff.
217 * You still need to define handlers if you really want to DO
218 * something with this structure...
220 void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
223 skb_queue_head_init(&q->out);
224 skb_queue_head_init(&q->control);
225 INIT_LIST_HEAD(&q->retransmit);
226 INIT_LIST_HEAD(&q->sacked);
227 INIT_LIST_HEAD(&q->abandoned);
229 q->outstanding_bytes = 0;
237 /* Free the outqueue structure and any related pending chunks.
239 void sctp_outq_teardown(struct sctp_outq *q)
241 struct sctp_transport *transport;
242 struct list_head *lchunk, *pos, *temp;
243 struct sctp_chunk *chunk;
245 /* Throw away unacknowledged chunks. */
246 list_for_each(pos, &q->asoc->peer.transport_addr_list) {
247 transport = list_entry(pos, struct sctp_transport, transports);
248 while ((lchunk = sctp_list_dequeue(&transport->transmitted)) != NULL) {
249 chunk = list_entry(lchunk, struct sctp_chunk,
251 /* Mark as part of a failed message. */
252 sctp_chunk_fail(chunk, q->error);
253 sctp_chunk_free(chunk);
257 /* Throw away chunks that have been gap ACKed. */
258 list_for_each_safe(lchunk, temp, &q->sacked) {
259 list_del_init(lchunk);
260 chunk = list_entry(lchunk, struct sctp_chunk,
262 sctp_chunk_fail(chunk, q->error);
263 sctp_chunk_free(chunk);
266 /* Throw away any chunks in the retransmit queue. */
267 list_for_each_safe(lchunk, temp, &q->retransmit) {
268 list_del_init(lchunk);
269 chunk = list_entry(lchunk, struct sctp_chunk,
271 sctp_chunk_fail(chunk, q->error);
272 sctp_chunk_free(chunk);
275 /* Throw away any chunks that are in the abandoned queue. */
276 list_for_each_safe(lchunk, temp, &q->abandoned) {
277 list_del_init(lchunk);
278 chunk = list_entry(lchunk, struct sctp_chunk,
280 sctp_chunk_fail(chunk, q->error);
281 sctp_chunk_free(chunk);
284 /* Throw away any leftover data chunks. */
285 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
287 /* Mark as send failure. */
288 sctp_chunk_fail(chunk, q->error);
289 sctp_chunk_free(chunk);
294 /* Throw away any leftover control chunks. */
295 while ((chunk = (struct sctp_chunk *) skb_dequeue(&q->control)) != NULL)
296 sctp_chunk_free(chunk);
299 /* Free the outqueue structure and any related pending chunks. */
300 void sctp_outq_free(struct sctp_outq *q)
302 /* Throw away leftover chunks. */
303 sctp_outq_teardown(q);
305 /* If we were kmalloc()'d, free the memory. */
310 /* Put a new chunk in an sctp_outq. */
311 int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
315 SCTP_DEBUG_PRINTK("sctp_outq_tail(%p, %p[%s])\n",
316 q, chunk, chunk && chunk->chunk_hdr ?
317 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
320 /* If it is data, queue it up, otherwise, send it
323 if (SCTP_CID_DATA == chunk->chunk_hdr->type) {
324 /* Is it OK to queue data chunks? */
325 /* From 9. Termination of Association
327 * When either endpoint performs a shutdown, the
328 * association on each peer will stop accepting new
329 * data from its user and only deliver data in queue
330 * at the time of sending or receiving the SHUTDOWN
333 switch (q->asoc->state) {
334 case SCTP_STATE_EMPTY:
335 case SCTP_STATE_CLOSED:
336 case SCTP_STATE_SHUTDOWN_PENDING:
337 case SCTP_STATE_SHUTDOWN_SENT:
338 case SCTP_STATE_SHUTDOWN_RECEIVED:
339 case SCTP_STATE_SHUTDOWN_ACK_SENT:
340 /* Cannot send after transport endpoint shutdown */
345 SCTP_DEBUG_PRINTK("outqueueing (%p, %p[%s])\n",
346 q, chunk, chunk && chunk->chunk_hdr ?
347 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
350 sctp_outq_tail_data(q, chunk);
351 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
352 SCTP_INC_STATS(SCTP_MIB_OUTUNORDERCHUNKS);
354 SCTP_INC_STATS(SCTP_MIB_OUTORDERCHUNKS);
359 __skb_queue_tail(&q->control, (struct sk_buff *) chunk);
360 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
367 error = sctp_outq_flush(q, 0);
372 /* Insert a chunk into the sorted list based on the TSNs. The retransmit list
373 * and the abandoned list are in ascending order.
375 void sctp_insert_list(struct list_head *head, struct list_head *new)
377 struct list_head *pos;
378 struct sctp_chunk *nchunk, *lchunk;
382 nchunk = list_entry(new, struct sctp_chunk, transmitted_list);
383 ntsn = ntohl(nchunk->subh.data_hdr->tsn);
385 list_for_each(pos, head) {
386 lchunk = list_entry(pos, struct sctp_chunk, transmitted_list);
387 ltsn = ntohl(lchunk->subh.data_hdr->tsn);
388 if (TSN_lt(ntsn, ltsn)) {
389 list_add(new, pos->prev);
395 list_add_tail(new, head);
398 /* Mark all the eligible packets on a transport for retransmission. */
399 void sctp_retransmit_mark(struct sctp_outq *q,
400 struct sctp_transport *transport,
401 __u8 fast_retransmit)
403 struct list_head *lchunk, *ltemp;
404 struct sctp_chunk *chunk;
406 /* Walk through the specified transmitted queue. */
407 list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
408 chunk = list_entry(lchunk, struct sctp_chunk,
411 /* If the chunk is abandoned, move it to abandoned list. */
412 if (sctp_chunk_abandoned(chunk)) {
413 list_del_init(lchunk);
414 sctp_insert_list(&q->abandoned, lchunk);
418 /* If we are doing retransmission due to a fast retransmit,
419 * only the chunk's that are marked for fast retransmit
420 * should be added to the retransmit queue. If we are doing
421 * retransmission due to a timeout or pmtu discovery, only the
422 * chunks that are not yet acked should be added to the
425 if ((fast_retransmit && chunk->fast_retransmit) ||
426 (!fast_retransmit && !chunk->tsn_gap_acked)) {
427 /* RFC 2960 6.2.1 Processing a Received SACK
429 * C) Any time a DATA chunk is marked for
430 * retransmission (via either T3-rtx timer expiration
431 * (Section 6.3.3) or via fast retransmit
432 * (Section 7.2.4)), add the data size of those
433 * chunks to the rwnd.
435 q->asoc->peer.rwnd += sctp_data_size(chunk);
436 q->outstanding_bytes -= sctp_data_size(chunk);
437 transport->flight_size -= sctp_data_size(chunk);
439 /* sctpimpguide-05 Section 2.8.2
440 * M5) If a T3-rtx timer expires, the
441 * 'TSN.Missing.Report' of all affected TSNs is set
444 chunk->tsn_missing_report = 0;
446 /* If a chunk that is being used for RTT measurement
447 * has to be retransmitted, we cannot use this chunk
448 * anymore for RTT measurements. Reset rto_pending so
449 * that a new RTT measurement is started when a new
450 * data chunk is sent.
452 if (chunk->rtt_in_progress) {
453 chunk->rtt_in_progress = 0;
454 transport->rto_pending = 0;
457 /* Move the chunk to the retransmit queue. The chunks
458 * on the retransmit queue are always kept in order.
460 list_del_init(lchunk);
461 sctp_insert_list(&q->retransmit, lchunk);
465 SCTP_DEBUG_PRINTK("%s: transport: %p, fast_retransmit: %d, "
466 "cwnd: %d, ssthresh: %d, flight_size: %d, "
467 "pba: %d\n", __FUNCTION__,
468 transport, fast_retransmit,
469 transport->cwnd, transport->ssthresh,
470 transport->flight_size,
471 transport->partial_bytes_acked);
475 /* Mark all the eligible packets on a transport for retransmission and force
478 void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
479 sctp_retransmit_reason_t reason)
482 __u8 fast_retransmit = 0;
485 case SCTP_RTXR_T3_RTX:
486 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
487 /* Update the retran path if the T3-rtx timer has expired for
488 * the current retran path.
490 if (transport == transport->asoc->peer.retran_path)
491 sctp_assoc_update_retran_path(transport->asoc);
493 case SCTP_RTXR_FAST_RTX:
494 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
497 case SCTP_RTXR_PMTUD:
502 sctp_retransmit_mark(q, transport, fast_retransmit);
504 /* PR-SCTP A5) Any time the T3-rtx timer expires, on any destination,
505 * the sender SHOULD try to advance the "Advanced.Peer.Ack.Point" by
506 * following the procedures outlined in C1 - C5.
508 sctp_generate_fwdtsn(q, q->asoc->ctsn_ack_point);
510 error = sctp_outq_flush(q, /* rtx_timeout */ 1);
513 q->asoc->base.sk->sk_err = -error;
517 * Transmit DATA chunks on the retransmit queue. Upon return from
518 * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
519 * need to be transmitted by the caller.
520 * We assume that pkt->transport has already been set.
522 * The return value is a normal kernel error return value.
524 static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
525 int rtx_timeout, int *start_timer)
527 struct list_head *lqueue;
528 struct list_head *lchunk, *lchunk1;
529 struct sctp_transport *transport = pkt->transport;
531 struct sctp_chunk *chunk, *chunk1;
532 struct sctp_association *asoc;
536 lqueue = &q->retransmit;
538 /* RFC 2960 6.3.3 Handle T3-rtx Expiration
540 * E3) Determine how many of the earliest (i.e., lowest TSN)
541 * outstanding DATA chunks for the address for which the
542 * T3-rtx has expired will fit into a single packet, subject
543 * to the MTU constraint for the path corresponding to the
544 * destination transport address to which the retransmission
545 * is being sent (this may be different from the address for
546 * which the timer expires [see Section 6.4]). Call this value
547 * K. Bundle and retransmit those K DATA chunks in a single
548 * packet to the destination endpoint.
550 * [Just to be painfully clear, if we are retransmitting
551 * because a timeout just happened, we should send only ONE
552 * packet of retransmitted data.]
554 lchunk = sctp_list_dequeue(lqueue);
557 chunk = list_entry(lchunk, struct sctp_chunk,
560 /* Make sure that Gap Acked TSNs are not retransmitted. A
561 * simple approach is just to move such TSNs out of the
562 * way and into a 'transmitted' queue and skip to the
565 if (chunk->tsn_gap_acked) {
566 list_add_tail(lchunk, &transport->transmitted);
567 lchunk = sctp_list_dequeue(lqueue);
571 /* Attempt to append this chunk to the packet. */
572 status = sctp_packet_append_chunk(pkt, chunk);
575 case SCTP_XMIT_PMTU_FULL:
576 /* Send this packet. */
577 if ((error = sctp_packet_transmit(pkt)) == 0)
580 /* If we are retransmitting, we should only
581 * send a single packet.
584 list_add(lchunk, lqueue);
588 /* Bundle lchunk in the next round. */
591 case SCTP_XMIT_RWND_FULL:
592 /* Send this packet. */
593 if ((error = sctp_packet_transmit(pkt)) == 0)
596 /* Stop sending DATA as there is no more room
599 list_add(lchunk, lqueue);
603 case SCTP_XMIT_NAGLE_DELAY:
604 /* Send this packet. */
605 if ((error = sctp_packet_transmit(pkt)) == 0)
608 /* Stop sending DATA because of nagle delay. */
609 list_add(lchunk, lqueue);
614 /* The append was successful, so add this chunk to
615 * the transmitted list.
617 list_add_tail(lchunk, &transport->transmitted);
619 /* Mark the chunk as ineligible for fast retransmit
620 * after it is retransmitted.
622 chunk->fast_retransmit = 0;
627 /* Retrieve a new chunk to bundle. */
628 lchunk = sctp_list_dequeue(lqueue);
632 /* If we are here due to a retransmit timeout or a fast
633 * retransmit and if there are any chunks left in the retransmit
634 * queue that could not fit in the PMTU sized packet, they need * to be marked as ineligible for a subsequent fast retransmit.
636 if (rtx_timeout && !lchunk) {
637 list_for_each(lchunk1, lqueue) {
638 chunk1 = list_entry(lchunk1, struct sctp_chunk,
640 chunk1->fast_retransmit = 0;
648 /* Cork the outqueue so queued chunks are really queued. */
649 int sctp_outq_uncork(struct sctp_outq *q)
654 error = sctp_outq_flush(q, 0);
660 * Try to flush an outqueue.
662 * Description: Send everything in q which we legally can, subject to
663 * congestion limitations.
664 * * Note: This function can be called from multiple contexts so appropriate
665 * locking concerns must be made. Today we use the sock lock to protect
668 int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
670 struct sctp_packet *packet;
671 struct sctp_packet singleton;
672 struct sctp_association *asoc = q->asoc;
673 __u16 sport = asoc->base.bind_addr.port;
674 __u16 dport = asoc->peer.port;
675 __u32 vtag = asoc->peer.i.init_tag;
676 struct sk_buff_head *queue;
677 struct sctp_transport *transport = NULL;
678 struct sctp_transport *new_transport;
679 struct sctp_chunk *chunk;
684 /* These transports have chunks to send. */
685 struct list_head transport_list;
686 struct list_head *ltransport;
688 INIT_LIST_HEAD(&transport_list);
694 * When bundling control chunks with DATA chunks, an
695 * endpoint MUST place control chunks first in the outbound
696 * SCTP packet. The transmitter MUST transmit DATA chunks
697 * within a SCTP packet in increasing order of TSN.
702 while ((chunk = (struct sctp_chunk *)skb_dequeue(queue)) != NULL) {
703 /* Pick the right transport to use. */
704 new_transport = chunk->transport;
706 if (!new_transport) {
707 new_transport = asoc->peer.active_path;
708 } else if (!new_transport->active) {
709 /* If the chunk is Heartbeat, send it to
710 * chunk->transport, even it's inactive.
712 if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT)
713 new_transport = asoc->peer.active_path;
716 /* Are we switching transports?
717 * Take care of transport locks.
719 if (new_transport != transport) {
720 transport = new_transport;
721 if (list_empty(&transport->send_ready)) {
722 list_add_tail(&transport->send_ready,
725 packet = &transport->packet;
726 sctp_packet_config(packet, vtag,
727 asoc->peer.ecn_capable);
730 switch (chunk->chunk_hdr->type) {
734 * An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
735 * COMPLETE with any other chunks. [Send them immediately.]
738 case SCTP_CID_INIT_ACK:
739 case SCTP_CID_SHUTDOWN_COMPLETE:
740 sctp_packet_init(&singleton, transport, sport, dport);
741 sctp_packet_config(&singleton, vtag, 0);
742 sctp_packet_append_chunk(&singleton, chunk);
743 error = sctp_packet_transmit(&singleton);
750 case SCTP_CID_HEARTBEAT:
751 case SCTP_CID_HEARTBEAT_ACK:
752 case SCTP_CID_SHUTDOWN:
753 case SCTP_CID_SHUTDOWN_ACK:
755 case SCTP_CID_COOKIE_ECHO:
756 case SCTP_CID_COOKIE_ACK:
757 case SCTP_CID_ECN_ECNE:
758 case SCTP_CID_ECN_CWR:
759 case SCTP_CID_ASCONF:
760 case SCTP_CID_ASCONF_ACK:
761 case SCTP_CID_FWD_TSN:
762 sctp_packet_transmit_chunk(packet, chunk);
766 /* We built a chunk with an illegal type! */
771 /* Is it OK to send data chunks? */
772 switch (asoc->state) {
773 case SCTP_STATE_COOKIE_ECHOED:
774 /* Only allow bundling when this packet has a COOKIE-ECHO
777 if (!packet || !packet->has_cookie_echo)
781 case SCTP_STATE_ESTABLISHED:
782 case SCTP_STATE_SHUTDOWN_PENDING:
783 case SCTP_STATE_SHUTDOWN_RECEIVED:
785 * RFC 2960 6.1 Transmission of DATA Chunks
787 * C) When the time comes for the sender to transmit,
788 * before sending new DATA chunks, the sender MUST
789 * first transmit any outstanding DATA chunks which
790 * are marked for retransmission (limited by the
793 if (!list_empty(&q->retransmit)) {
794 if (transport == asoc->peer.retran_path)
797 /* Switch transports & prepare the packet. */
799 transport = asoc->peer.retran_path;
801 if (list_empty(&transport->send_ready)) {
802 list_add_tail(&transport->send_ready,
806 packet = &transport->packet;
807 sctp_packet_config(packet, vtag,
808 asoc->peer.ecn_capable);
810 error = sctp_outq_flush_rtx(q, packet,
811 rtx_timeout, &start_timer);
814 sctp_transport_reset_timers(transport);
816 /* This can happen on COOKIE-ECHO resend. Only
817 * one chunk can get bundled with a COOKIE-ECHO.
819 if (packet->has_cookie_echo)
822 /* Don't send new data if there is still data
823 * waiting to retransmit.
825 if (!list_empty(&q->retransmit))
829 /* Finally, transmit new packets. */
833 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
834 /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
837 if (chunk->sinfo.sinfo_stream >=
838 asoc->c.sinit_num_ostreams) {
840 /* Mark as failed send. */
841 sctp_chunk_fail(chunk, SCTP_ERROR_INV_STRM);
842 sctp_chunk_free(chunk);
846 /* Has this chunk expired? */
847 if (sctp_chunk_abandoned(chunk)) {
848 sctp_chunk_fail(chunk, 0);
849 sctp_chunk_free(chunk);
853 /* If there is a specified transport, use it.
854 * Otherwise, we want to use the active path.
856 new_transport = chunk->transport;
857 if (!new_transport || !new_transport->active)
858 new_transport = asoc->peer.active_path;
860 /* Change packets if necessary. */
861 if (new_transport != transport) {
862 transport = new_transport;
864 /* Schedule to have this transport's
867 if (list_empty(&transport->send_ready)) {
868 list_add_tail(&transport->send_ready,
872 packet = &transport->packet;
873 sctp_packet_config(packet, vtag,
874 asoc->peer.ecn_capable);
877 SCTP_DEBUG_PRINTK("sctp_outq_flush(%p, %p[%s]), ",
879 chunk && chunk->chunk_hdr ?
880 sctp_cname(SCTP_ST_CHUNK(
881 chunk->chunk_hdr->type))
884 SCTP_DEBUG_PRINTK("TX TSN 0x%x skb->head "
885 "%p skb->users %d.\n",
886 ntohl(chunk->subh.data_hdr->tsn),
887 chunk->skb ?chunk->skb->head : NULL,
889 atomic_read(&chunk->skb->users) : -1);
891 /* Add the chunk to the packet. */
892 status = sctp_packet_transmit_chunk(packet, chunk);
895 case SCTP_XMIT_PMTU_FULL:
896 case SCTP_XMIT_RWND_FULL:
897 case SCTP_XMIT_NAGLE_DELAY:
898 /* We could not append this chunk, so put
899 * the chunk back on the output queue.
901 SCTP_DEBUG_PRINTK("sctp_outq_flush: could "
902 "not transmit TSN: 0x%x, status: %d\n",
903 ntohl(chunk->subh.data_hdr->tsn),
905 sctp_outq_head_data(q, chunk);
916 /* BUG: We assume that the sctp_packet_transmit()
917 * call below will succeed all the time and add the
918 * chunk to the transmitted list and restart the
920 * It is possible that the call can fail under OOM
923 * Is this really a problem? Won't this behave
926 list_add_tail(&chunk->transmitted_list,
927 &transport->transmitted);
929 sctp_transport_reset_timers(transport);
933 /* Only let one DATA chunk get bundled with a
936 if (packet->has_cookie_echo)
948 /* Before returning, examine all the transports touched in
949 * this call. Right now, we bluntly force clear all the
950 * transports. Things might change after we implement Nagle.
951 * But such an examination is still required.
955 while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL ) {
956 struct sctp_transport *t = list_entry(ltransport,
957 struct sctp_transport,
960 if (!sctp_packet_empty(packet))
961 error = sctp_packet_transmit(packet);
967 /* Update unack_data based on the incoming SACK chunk */
968 static void sctp_sack_update_unack_data(struct sctp_association *assoc,
969 struct sctp_sackhdr *sack)
971 sctp_sack_variable_t *frags;
975 unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
977 frags = sack->variable;
978 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
979 unack_data -= ((ntohs(frags[i].gab.end) -
980 ntohs(frags[i].gab.start) + 1));
983 assoc->unack_data = unack_data;
986 /* Return the highest new tsn that is acknowledged by the given SACK chunk. */
987 static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack,
988 struct sctp_association *asoc)
990 struct list_head *ltransport, *lchunk;
991 struct sctp_transport *transport;
992 struct sctp_chunk *chunk;
993 __u32 highest_new_tsn, tsn;
994 struct list_head *transport_list = &asoc->peer.transport_addr_list;
996 highest_new_tsn = ntohl(sack->cum_tsn_ack);
998 list_for_each(ltransport, transport_list) {
999 transport = list_entry(ltransport, struct sctp_transport,
1001 list_for_each(lchunk, &transport->transmitted) {
1002 chunk = list_entry(lchunk, struct sctp_chunk,
1004 tsn = ntohl(chunk->subh.data_hdr->tsn);
1006 if (!chunk->tsn_gap_acked &&
1007 TSN_lt(highest_new_tsn, tsn) &&
1008 sctp_acked(sack, tsn))
1009 highest_new_tsn = tsn;
1013 return highest_new_tsn;
1016 /* This is where we REALLY process a SACK.
1018 * Process the SACK against the outqueue. Mostly, this just frees
1019 * things off the transmitted queue.
1021 int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
1023 struct sctp_association *asoc = q->asoc;
1024 struct sctp_transport *transport;
1025 struct sctp_chunk *tchunk = NULL;
1026 struct list_head *lchunk, *transport_list, *pos, *temp;
1027 sctp_sack_variable_t *frags = sack->variable;
1028 __u32 sack_ctsn, ctsn, tsn;
1029 __u32 highest_tsn, highest_new_tsn;
1031 unsigned outstanding;
1032 struct sctp_transport *primary = asoc->peer.primary_path;
1033 int count_of_newacks = 0;
1035 /* Grab the association's destination address list. */
1036 transport_list = &asoc->peer.transport_addr_list;
1038 sack_ctsn = ntohl(sack->cum_tsn_ack);
1041 * SFR-CACC algorithm:
1042 * On receipt of a SACK the sender SHOULD execute the
1043 * following statements.
1045 * 1) If the cumulative ack in the SACK passes next tsn_at_change
1046 * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
1047 * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
1050 if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
1051 primary->cacc.changeover_active = 0;
1052 list_for_each(pos, transport_list) {
1053 transport = list_entry(pos, struct sctp_transport,
1055 transport->cacc.cycling_changeover = 0;
1060 * SFR-CACC algorithm:
1061 * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
1062 * is set the receiver of the SACK MUST take the following actions:
1064 * A) Initialize the cacc_saw_newack to 0 for all destination
1067 if (sack->num_gap_ack_blocks > 0 &&
1068 primary->cacc.changeover_active) {
1069 list_for_each(pos, transport_list) {
1070 transport = list_entry(pos, struct sctp_transport,
1072 transport->cacc.cacc_saw_newack = 0;
1076 /* Get the highest TSN in the sack. */
1077 highest_tsn = sack_ctsn;
1078 if (sack->num_gap_ack_blocks)
1080 ntohs(frags[ntohs(sack->num_gap_ack_blocks) - 1].gab.end);
1082 if (TSN_lt(asoc->highest_sacked, highest_tsn)) {
1083 highest_new_tsn = highest_tsn;
1084 asoc->highest_sacked = highest_tsn;
1086 highest_new_tsn = sctp_highest_new_tsn(sack, asoc);
1089 /* Run through the retransmit queue. Credit bytes received
1090 * and free those chunks that we can.
1092 sctp_check_transmitted(q, &q->retransmit, NULL, sack, highest_new_tsn);
1093 sctp_mark_missing(q, &q->retransmit, NULL, highest_new_tsn, 0);
1095 /* Run through the transmitted queue.
1096 * Credit bytes received and free those chunks which we can.
1098 * This is a MASSIVE candidate for optimization.
1100 list_for_each(pos, transport_list) {
1101 transport = list_entry(pos, struct sctp_transport,
1103 sctp_check_transmitted(q, &transport->transmitted,
1104 transport, sack, highest_new_tsn);
1106 * SFR-CACC algorithm:
1107 * C) Let count_of_newacks be the number of
1108 * destinations for which cacc_saw_newack is set.
1110 if (transport->cacc.cacc_saw_newack)
1111 count_of_newacks ++;
1114 list_for_each(pos, transport_list) {
1115 transport = list_entry(pos, struct sctp_transport,
1117 sctp_mark_missing(q, &transport->transmitted, transport,
1118 highest_new_tsn, count_of_newacks);
1121 /* Move the Cumulative TSN Ack Point if appropriate. */
1122 if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn))
1123 asoc->ctsn_ack_point = sack_ctsn;
1125 /* Update unack_data field in the assoc. */
1126 sctp_sack_update_unack_data(asoc, sack);
1128 ctsn = asoc->ctsn_ack_point;
1130 /* Throw away stuff rotting on the sack queue. */
1131 list_for_each_safe(lchunk, temp, &q->sacked) {
1132 tchunk = list_entry(lchunk, struct sctp_chunk,
1134 tsn = ntohl(tchunk->subh.data_hdr->tsn);
1135 if (TSN_lte(tsn, ctsn))
1136 sctp_chunk_free(tchunk);
1139 /* ii) Set rwnd equal to the newly received a_rwnd minus the
1140 * number of bytes still outstanding after processing the
1141 * Cumulative TSN Ack and the Gap Ack Blocks.
1144 sack_a_rwnd = ntohl(sack->a_rwnd);
1145 outstanding = q->outstanding_bytes;
1147 if (outstanding < sack_a_rwnd)
1148 sack_a_rwnd -= outstanding;
1152 asoc->peer.rwnd = sack_a_rwnd;
1154 sctp_generate_fwdtsn(q, sack_ctsn);
1156 SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
1157 __FUNCTION__, sack_ctsn);
1158 SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association, "
1159 "%p is 0x%x. Adv peer ack point: 0x%x\n",
1160 __FUNCTION__, asoc, ctsn, asoc->adv_peer_ack_point);
1162 /* See if all chunks are acked.
1163 * Make sure the empty queue handler will get run later.
1165 q->empty = skb_queue_empty(&q->out) && skb_queue_empty(&q->control) &&
1166 list_empty(&q->retransmit);
1170 list_for_each(pos, transport_list) {
1171 transport = list_entry(pos, struct sctp_transport,
1173 q->empty = q->empty && list_empty(&transport->transmitted);
1178 SCTP_DEBUG_PRINTK("sack queue is empty.\n");
1183 /* Is the outqueue empty? */
1184 int sctp_outq_is_empty(const struct sctp_outq *q)
1189 /********************************************************************
1190 * 2nd Level Abstractions
1191 ********************************************************************/
1193 /* Go through a transport's transmitted list or the association's retransmit
1194 * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
1195 * The retransmit list will not have an associated transport.
1197 * I added coherent debug information output. --xguo
1199 * Instead of printing 'sacked' or 'kept' for each TSN on the
1200 * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
1201 * KEPT TSN6-TSN7, etc.
1203 static void sctp_check_transmitted(struct sctp_outq *q,
1204 struct list_head *transmitted_queue,
1205 struct sctp_transport *transport,
1206 struct sctp_sackhdr *sack,
1207 __u32 highest_new_tsn_in_sack)
1209 struct list_head *lchunk;
1210 struct sctp_chunk *tchunk;
1211 struct list_head tlist;
1215 __u8 restart_timer = 0;
1216 int bytes_acked = 0;
1218 /* These state variables are for coherent debug output. --xguo */
1221 __u32 dbg_ack_tsn = 0; /* An ACKed TSN range starts here... */
1222 __u32 dbg_last_ack_tsn = 0; /* ...and finishes here. */
1223 __u32 dbg_kept_tsn = 0; /* An un-ACKed range starts here... */
1224 __u32 dbg_last_kept_tsn = 0; /* ...and finishes here. */
1226 /* 0 : The last TSN was ACKed.
1227 * 1 : The last TSN was NOT ACKed (i.e. KEPT).
1228 * -1: We need to initialize.
1230 int dbg_prt_state = -1;
1231 #endif /* SCTP_DEBUG */
1233 sack_ctsn = ntohl(sack->cum_tsn_ack);
1235 INIT_LIST_HEAD(&tlist);
1237 /* The while loop will skip empty transmitted queues. */
1238 while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
1239 tchunk = list_entry(lchunk, struct sctp_chunk,
1242 if (sctp_chunk_abandoned(tchunk)) {
1243 /* Move the chunk to abandoned list. */
1244 sctp_insert_list(&q->abandoned, lchunk);
1248 tsn = ntohl(tchunk->subh.data_hdr->tsn);
1249 if (sctp_acked(sack, tsn)) {
1250 /* If this queue is the retransmit queue, the
1251 * retransmit timer has already reclaimed
1252 * the outstanding bytes for this chunk, so only
1253 * count bytes associated with a transport.
1256 /* If this chunk is being used for RTT
1257 * measurement, calculate the RTT and update
1258 * the RTO using this value.
1260 * 6.3.1 C5) Karn's algorithm: RTT measurements
1261 * MUST NOT be made using packets that were
1262 * retransmitted (and thus for which it is
1263 * ambiguous whether the reply was for the
1264 * first instance of the packet or a later
1267 if (!tchunk->tsn_gap_acked &&
1269 tchunk->rtt_in_progress) {
1270 rtt = jiffies - tchunk->sent_at;
1271 sctp_transport_update_rto(transport,
1275 if (TSN_lte(tsn, sack_ctsn)) {
1276 /* RFC 2960 6.3.2 Retransmission Timer Rules
1278 * R3) Whenever a SACK is received
1279 * that acknowledges the DATA chunk
1280 * with the earliest outstanding TSN
1281 * for that address, restart T3-rtx
1282 * timer for that address with its
1287 if (!tchunk->tsn_gap_acked) {
1288 tchunk->tsn_gap_acked = 1;
1289 bytes_acked += sctp_data_size(tchunk);
1291 * SFR-CACC algorithm:
1292 * 2) If the SACK contains gap acks
1293 * and the flag CHANGEOVER_ACTIVE is
1294 * set the receiver of the SACK MUST
1295 * take the following action:
1297 * B) For each TSN t being acked that
1298 * has not been acked in any SACK so
1299 * far, set cacc_saw_newack to 1 for
1300 * the destination that the TSN was
1304 sack->num_gap_ack_blocks &&
1305 q->asoc->peer.primary_path->cacc.
1307 transport->cacc.cacc_saw_newack
1311 list_add_tail(&tchunk->transmitted_list,
1314 /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
1315 * M2) Each time a SACK arrives reporting
1316 * 'Stray DATA chunk(s)' record the highest TSN
1317 * reported as newly acknowledged, call this
1318 * value 'HighestTSNinSack'. A newly
1319 * acknowledged DATA chunk is one not
1320 * previously acknowledged in a SACK.
1322 * When the SCTP sender of data receives a SACK
1323 * chunk that acknowledges, for the first time,
1324 * the receipt of a DATA chunk, all the still
1325 * unacknowledged DATA chunks whose TSN is
1326 * older than that newly acknowledged DATA
1327 * chunk, are qualified as 'Stray DATA chunks'.
1329 if (!tchunk->tsn_gap_acked) {
1330 tchunk->tsn_gap_acked = 1;
1331 bytes_acked += sctp_data_size(tchunk);
1333 list_add_tail(lchunk, &tlist);
1337 switch (dbg_prt_state) {
1338 case 0: /* last TSN was ACKed */
1339 if (dbg_last_ack_tsn + 1 == tsn) {
1340 /* This TSN belongs to the
1341 * current ACK range.
1346 if (dbg_last_ack_tsn != dbg_ack_tsn) {
1347 /* Display the end of the
1350 SCTP_DEBUG_PRINTK("-%08x",
1354 /* Start a new range. */
1355 SCTP_DEBUG_PRINTK(",%08x", tsn);
1359 case 1: /* The last TSN was NOT ACKed. */
1360 if (dbg_last_kept_tsn != dbg_kept_tsn) {
1361 /* Display the end of current range. */
1362 SCTP_DEBUG_PRINTK("-%08x",
1366 SCTP_DEBUG_PRINTK("\n");
1368 /* FALL THROUGH... */
1370 /* This is the first-ever TSN we examined. */
1371 /* Start a new range of ACK-ed TSNs. */
1372 SCTP_DEBUG_PRINTK("ACKed: %08x", tsn);
1377 dbg_last_ack_tsn = tsn;
1378 #endif /* SCTP_DEBUG */
1381 if (tchunk->tsn_gap_acked) {
1382 SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
1386 tchunk->tsn_gap_acked = 0;
1388 bytes_acked -= sctp_data_size(tchunk);
1390 /* RFC 2960 6.3.2 Retransmission Timer Rules
1392 * R4) Whenever a SACK is received missing a
1393 * TSN that was previously acknowledged via a
1394 * Gap Ack Block, start T3-rtx for the
1395 * destination address to which the DATA
1396 * chunk was originally
1397 * transmitted if it is not already running.
1402 list_add_tail(lchunk, &tlist);
1405 /* See the above comments on ACK-ed TSNs. */
1406 switch (dbg_prt_state) {
1408 if (dbg_last_kept_tsn + 1 == tsn)
1411 if (dbg_last_kept_tsn != dbg_kept_tsn)
1412 SCTP_DEBUG_PRINTK("-%08x",
1415 SCTP_DEBUG_PRINTK(",%08x", tsn);
1420 if (dbg_last_ack_tsn != dbg_ack_tsn)
1421 SCTP_DEBUG_PRINTK("-%08x",
1423 SCTP_DEBUG_PRINTK("\n");
1425 /* FALL THROUGH... */
1427 SCTP_DEBUG_PRINTK("KEPT: %08x",tsn);
1432 dbg_last_kept_tsn = tsn;
1433 #endif /* SCTP_DEBUG */
1438 /* Finish off the last range, displaying its ending TSN. */
1439 switch (dbg_prt_state) {
1441 if (dbg_last_ack_tsn != dbg_ack_tsn) {
1442 SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_ack_tsn);
1444 SCTP_DEBUG_PRINTK("\n");
1449 if (dbg_last_kept_tsn != dbg_kept_tsn) {
1450 SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_kept_tsn);
1452 SCTP_DEBUG_PRINTK("\n");
1455 #endif /* SCTP_DEBUG */
1458 /* 8.2. When an outstanding TSN is acknowledged,
1459 * the endpoint shall clear the error counter of
1460 * the destination transport address to which the
1461 * DATA chunk was last sent.
1462 * The association's overall error counter is
1465 transport->error_count = 0;
1466 transport->asoc->overall_error_count = 0;
1468 /* Mark the destination transport address as
1469 * active if it is not so marked.
1471 if (!transport->active) {
1472 sctp_assoc_control_transport(
1476 SCTP_RECEIVED_SACK);
1479 sctp_transport_raise_cwnd(transport, sack_ctsn,
1482 transport->flight_size -= bytes_acked;
1483 q->outstanding_bytes -= bytes_acked;
1485 /* RFC 2960 6.1, sctpimpguide-06 2.15.2
1486 * When a sender is doing zero window probing, it
1487 * should not timeout the association if it continues
1488 * to receive new packets from the receiver. The
1489 * reason is that the receiver MAY keep its window
1490 * closed for an indefinite time.
1491 * A sender is doing zero window probing when the
1492 * receiver's advertised window is zero, and there is
1493 * only one data chunk in flight to the receiver.
1495 if (!q->asoc->peer.rwnd &&
1496 !list_empty(&tlist) &&
1497 (sack_ctsn+2 == q->asoc->next_tsn)) {
1498 SCTP_DEBUG_PRINTK("%s: SACK received for zero "
1499 "window probe: %u\n",
1500 __FUNCTION__, sack_ctsn);
1501 q->asoc->overall_error_count = 0;
1502 transport->error_count = 0;
1506 /* RFC 2960 6.3.2 Retransmission Timer Rules
1508 * R2) Whenever all outstanding data sent to an address have
1509 * been acknowledged, turn off the T3-rtx timer of that
1512 if (!transport->flight_size) {
1513 if (timer_pending(&transport->T3_rtx_timer) &&
1514 del_timer(&transport->T3_rtx_timer)) {
1515 sctp_transport_put(transport);
1517 } else if (restart_timer) {
1518 if (!mod_timer(&transport->T3_rtx_timer,
1519 jiffies + transport->rto))
1520 sctp_transport_hold(transport);
1524 list_splice(&tlist, transmitted_queue);
1527 /* Mark chunks as missing and consequently may get retransmitted. */
1528 static void sctp_mark_missing(struct sctp_outq *q,
1529 struct list_head *transmitted_queue,
1530 struct sctp_transport *transport,
1531 __u32 highest_new_tsn_in_sack,
1532 int count_of_newacks)
1534 struct sctp_chunk *chunk;
1535 struct list_head *pos;
1537 char do_fast_retransmit = 0;
1538 struct sctp_transport *primary = q->asoc->peer.primary_path;
1540 list_for_each(pos, transmitted_queue) {
1542 chunk = list_entry(pos, struct sctp_chunk, transmitted_list);
1543 tsn = ntohl(chunk->subh.data_hdr->tsn);
1545 /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
1546 * 'Unacknowledged TSN's', if the TSN number of an
1547 * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
1548 * value, increment the 'TSN.Missing.Report' count on that
1549 * chunk if it has NOT been fast retransmitted or marked for
1550 * fast retransmit already.
1552 if (!chunk->fast_retransmit &&
1553 !chunk->tsn_gap_acked &&
1554 TSN_lt(tsn, highest_new_tsn_in_sack)) {
1556 /* SFR-CACC may require us to skip marking
1557 * this chunk as missing.
1559 if (!transport || !sctp_cacc_skip(primary, transport,
1560 count_of_newacks, tsn)) {
1561 chunk->tsn_missing_report++;
1564 "%s: TSN 0x%x missing counter: %d\n",
1566 chunk->tsn_missing_report);
1570 * M4) If any DATA chunk is found to have a
1571 * 'TSN.Missing.Report'
1572 * value larger than or equal to 4, mark that chunk for
1573 * retransmission and start the fast retransmit procedure.
1576 if (chunk->tsn_missing_report >= 4) {
1577 chunk->fast_retransmit = 1;
1578 do_fast_retransmit = 1;
1583 if (do_fast_retransmit)
1584 sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
1586 SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
1587 "ssthresh: %d, flight_size: %d, pba: %d\n",
1588 __FUNCTION__, transport, transport->cwnd,
1589 transport->ssthresh, transport->flight_size,
1590 transport->partial_bytes_acked);
1594 /* Is the given TSN acked by this packet? */
1595 static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
1598 sctp_sack_variable_t *frags;
1600 __u32 ctsn = ntohl(sack->cum_tsn_ack);
1602 if (TSN_lte(tsn, ctsn))
1605 /* 3.3.4 Selective Acknowledgement (SACK) (3):
1608 * These fields contain the Gap Ack Blocks. They are repeated
1609 * for each Gap Ack Block up to the number of Gap Ack Blocks
1610 * defined in the Number of Gap Ack Blocks field. All DATA
1611 * chunks with TSNs greater than or equal to (Cumulative TSN
1612 * Ack + Gap Ack Block Start) and less than or equal to
1613 * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
1614 * Block are assumed to have been received correctly.
1617 frags = sack->variable;
1619 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
1620 if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
1621 TSN_lte(gap, ntohs(frags[i].gab.end)))
1630 static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist,
1631 int nskips, __u16 stream)
1635 for (i = 0; i < nskips; i++) {
1636 if (skiplist[i].stream == stream)
1642 /* Create and add a fwdtsn chunk to the outq's control queue if needed. */
1643 static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
1645 struct sctp_association *asoc = q->asoc;
1646 struct sctp_chunk *ftsn_chunk = NULL;
1647 struct sctp_fwdtsn_skip ftsn_skip_arr[10];
1651 struct sctp_chunk *chunk;
1652 struct list_head *lchunk, *temp;
1654 /* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the
1657 * If (Advanced.Peer.Ack.Point < SackCumAck), then update
1658 * Advanced.Peer.Ack.Point to be equal to SackCumAck.
1660 if (TSN_lt(asoc->adv_peer_ack_point, ctsn))
1661 asoc->adv_peer_ack_point = ctsn;
1663 /* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point"
1664 * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as
1665 * the chunk next in the out-queue space is marked as "abandoned" as
1666 * shown in the following example:
1668 * Assuming that a SACK arrived with the Cumulative TSN ACK 102
1669 * and the Advanced.Peer.Ack.Point is updated to this value:
1671 * out-queue at the end of ==> out-queue after Adv.Ack.Point
1672 * normal SACK processing local advancement
1674 * Adv.Ack.Pt-> 102 acked 102 acked
1675 * 103 abandoned 103 abandoned
1676 * 104 abandoned Adv.Ack.P-> 104 abandoned
1678 * 106 acked 106 acked
1681 * In this example, the data sender successfully advanced the
1682 * "Advanced.Peer.Ack.Point" from 102 to 104 locally.
1684 list_for_each_safe(lchunk, temp, &q->abandoned) {
1685 chunk = list_entry(lchunk, struct sctp_chunk,
1687 tsn = ntohl(chunk->subh.data_hdr->tsn);
1689 /* Remove any chunks in the abandoned queue that are acked by
1692 if (TSN_lte(tsn, ctsn)) {
1693 list_del_init(lchunk);
1694 if (!chunk->tsn_gap_acked) {
1695 chunk->transport->flight_size -=
1696 sctp_data_size(chunk);
1697 q->outstanding_bytes -= sctp_data_size(chunk);
1699 sctp_chunk_free(chunk);
1701 if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
1702 asoc->adv_peer_ack_point = tsn;
1703 if (chunk->chunk_hdr->flags &
1704 SCTP_DATA_UNORDERED)
1706 skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0],
1708 chunk->subh.data_hdr->stream);
1709 ftsn_skip_arr[skip_pos].stream =
1710 chunk->subh.data_hdr->stream;
1711 ftsn_skip_arr[skip_pos].ssn =
1712 chunk->subh.data_hdr->ssn;
1713 if (skip_pos == nskips)
1722 /* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point"
1723 * is greater than the Cumulative TSN ACK carried in the received
1724 * SACK, the data sender MUST send the data receiver a FORWARD TSN
1725 * chunk containing the latest value of the
1726 * "Advanced.Peer.Ack.Point".
1728 * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD
1729 * list each stream and sequence number in the forwarded TSN. This
1730 * information will enable the receiver to easily find any
1731 * stranded TSN's waiting on stream reorder queues. Each stream
1732 * SHOULD only be reported once; this means that if multiple
1733 * abandoned messages occur in the same stream then only the
1734 * highest abandoned stream sequence number is reported. If the
1735 * total size of the FORWARD TSN does NOT fit in a single MTU then
1736 * the sender of the FORWARD TSN SHOULD lower the
1737 * Advanced.Peer.Ack.Point to the last TSN that will fit in a
1740 if (asoc->adv_peer_ack_point > ctsn)
1741 ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point,
1742 nskips, &ftsn_skip_arr[0]);
1745 __skb_queue_tail(&q->control, (struct sk_buff *)ftsn_chunk);
1746 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);