1 /* SCTP kernel 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 implementation
9 * These functions implement the sctp_outq class. The outqueue handles
10 * bundling and queueing of outgoing SCTP chunks.
12 * This SCTP 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 * This SCTP 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 list_add(&ch
->list
, &q
->out_chunk_list
);
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
= NULL
;
88 if (!list_empty(&q
->out_chunk_list
)) {
89 struct list_head
*entry
= q
->out_chunk_list
.next
;
91 ch
= list_entry(entry
, struct sctp_chunk
, list
);
93 q
->out_qlen
-= ch
->skb
->len
;
97 /* Add data chunk to the end of the queue. */
98 static inline void sctp_outq_tail_data(struct sctp_outq
*q
,
99 struct sctp_chunk
*ch
)
101 list_add_tail(&ch
->list
, &q
->out_chunk_list
);
102 q
->out_qlen
+= ch
->skb
->len
;
107 * SFR-CACC algorithm:
108 * D) If count_of_newacks is greater than or equal to 2
109 * and t was not sent to the current primary then the
110 * sender MUST NOT increment missing report count for t.
112 static inline int sctp_cacc_skip_3_1_d(struct sctp_transport
*primary
,
113 struct sctp_transport
*transport
,
114 int count_of_newacks
)
116 if (count_of_newacks
>=2 && transport
!= primary
)
122 * SFR-CACC algorithm:
123 * F) If count_of_newacks is less than 2, let d be the
124 * destination to which t was sent. If cacc_saw_newack
125 * is 0 for destination d, then the sender MUST NOT
126 * increment missing report count for t.
128 static inline int sctp_cacc_skip_3_1_f(struct sctp_transport
*transport
,
129 int count_of_newacks
)
131 if (count_of_newacks
< 2 && !transport
->cacc
.cacc_saw_newack
)
137 * SFR-CACC algorithm:
138 * 3.1) If CYCLING_CHANGEOVER is 0, the sender SHOULD
139 * execute steps C, D, F.
141 * C has been implemented in sctp_outq_sack
143 static inline int sctp_cacc_skip_3_1(struct sctp_transport
*primary
,
144 struct sctp_transport
*transport
,
145 int count_of_newacks
)
147 if (!primary
->cacc
.cycling_changeover
) {
148 if (sctp_cacc_skip_3_1_d(primary
, transport
, count_of_newacks
))
150 if (sctp_cacc_skip_3_1_f(transport
, count_of_newacks
))
158 * SFR-CACC algorithm:
159 * 3.2) Else if CYCLING_CHANGEOVER is 1, and t is less
160 * than next_tsn_at_change of the current primary, then
161 * the sender MUST NOT increment missing report count
164 static inline int sctp_cacc_skip_3_2(struct sctp_transport
*primary
, __u32 tsn
)
166 if (primary
->cacc
.cycling_changeover
&&
167 TSN_lt(tsn
, primary
->cacc
.next_tsn_at_change
))
173 * SFR-CACC algorithm:
174 * 3) If the missing report count for TSN t is to be
175 * incremented according to [RFC2960] and
176 * [SCTP_STEWART-2002], and CHANGEOVER_ACTIVE is set,
177 * then the sender MUST futher execute steps 3.1 and
178 * 3.2 to determine if the missing report count for
179 * TSN t SHOULD NOT be incremented.
181 * 3.3) If 3.1 and 3.2 do not dictate that the missing
182 * report count for t should not be incremented, then
183 * the sender SOULD increment missing report count for
184 * t (according to [RFC2960] and [SCTP_STEWART_2002]).
186 static inline int sctp_cacc_skip(struct sctp_transport
*primary
,
187 struct sctp_transport
*transport
,
188 int count_of_newacks
,
191 if (primary
->cacc
.changeover_active
&&
192 (sctp_cacc_skip_3_1(primary
, transport
, count_of_newacks
)
193 || sctp_cacc_skip_3_2(primary
, tsn
)))
198 /* Initialize an existing sctp_outq. This does the boring stuff.
199 * You still need to define handlers if you really want to DO
200 * something with this structure...
202 void sctp_outq_init(struct sctp_association
*asoc
, struct sctp_outq
*q
)
205 INIT_LIST_HEAD(&q
->out_chunk_list
);
206 INIT_LIST_HEAD(&q
->control_chunk_list
);
207 INIT_LIST_HEAD(&q
->retransmit
);
208 INIT_LIST_HEAD(&q
->sacked
);
209 INIT_LIST_HEAD(&q
->abandoned
);
211 q
->outstanding_bytes
= 0;
219 /* Free the outqueue structure and any related pending chunks.
221 void sctp_outq_teardown(struct sctp_outq
*q
)
223 struct sctp_transport
*transport
;
224 struct list_head
*lchunk
, *pos
, *temp
;
225 struct sctp_chunk
*chunk
, *tmp
;
227 /* Throw away unacknowledged chunks. */
228 list_for_each(pos
, &q
->asoc
->peer
.transport_addr_list
) {
229 transport
= list_entry(pos
, struct sctp_transport
, transports
);
230 while ((lchunk
= sctp_list_dequeue(&transport
->transmitted
)) != NULL
) {
231 chunk
= list_entry(lchunk
, struct sctp_chunk
,
233 /* Mark as part of a failed message. */
234 sctp_chunk_fail(chunk
, q
->error
);
235 sctp_chunk_free(chunk
);
239 /* Throw away chunks that have been gap ACKed. */
240 list_for_each_safe(lchunk
, temp
, &q
->sacked
) {
241 list_del_init(lchunk
);
242 chunk
= list_entry(lchunk
, struct sctp_chunk
,
244 sctp_chunk_fail(chunk
, q
->error
);
245 sctp_chunk_free(chunk
);
248 /* Throw away any chunks in the retransmit queue. */
249 list_for_each_safe(lchunk
, temp
, &q
->retransmit
) {
250 list_del_init(lchunk
);
251 chunk
= list_entry(lchunk
, struct sctp_chunk
,
253 sctp_chunk_fail(chunk
, q
->error
);
254 sctp_chunk_free(chunk
);
257 /* Throw away any chunks that are in the abandoned queue. */
258 list_for_each_safe(lchunk
, temp
, &q
->abandoned
) {
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 leftover data chunks. */
267 while ((chunk
= sctp_outq_dequeue_data(q
)) != NULL
) {
269 /* Mark as send failure. */
270 sctp_chunk_fail(chunk
, q
->error
);
271 sctp_chunk_free(chunk
);
276 /* Throw away any leftover control chunks. */
277 list_for_each_entry_safe(chunk
, tmp
, &q
->control_chunk_list
, list
) {
278 list_del_init(&chunk
->list
);
279 sctp_chunk_free(chunk
);
283 /* Free the outqueue structure and any related pending chunks. */
284 void sctp_outq_free(struct sctp_outq
*q
)
286 /* Throw away leftover chunks. */
287 sctp_outq_teardown(q
);
289 /* If we were kmalloc()'d, free the memory. */
294 /* Put a new chunk in an sctp_outq. */
295 int sctp_outq_tail(struct sctp_outq
*q
, struct sctp_chunk
*chunk
)
299 SCTP_DEBUG_PRINTK("sctp_outq_tail(%p, %p[%s])\n",
300 q
, chunk
, chunk
&& chunk
->chunk_hdr
?
301 sctp_cname(SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
))
304 /* If it is data, queue it up, otherwise, send it
307 if (SCTP_CID_DATA
== chunk
->chunk_hdr
->type
) {
308 /* Is it OK to queue data chunks? */
309 /* From 9. Termination of Association
311 * When either endpoint performs a shutdown, the
312 * association on each peer will stop accepting new
313 * data from its user and only deliver data in queue
314 * at the time of sending or receiving the SHUTDOWN
317 switch (q
->asoc
->state
) {
318 case SCTP_STATE_EMPTY
:
319 case SCTP_STATE_CLOSED
:
320 case SCTP_STATE_SHUTDOWN_PENDING
:
321 case SCTP_STATE_SHUTDOWN_SENT
:
322 case SCTP_STATE_SHUTDOWN_RECEIVED
:
323 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
324 /* Cannot send after transport endpoint shutdown */
329 SCTP_DEBUG_PRINTK("outqueueing (%p, %p[%s])\n",
330 q
, chunk
, chunk
&& chunk
->chunk_hdr
?
331 sctp_cname(SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
))
334 sctp_outq_tail_data(q
, chunk
);
335 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
)
336 SCTP_INC_STATS(SCTP_MIB_OUTUNORDERCHUNKS
);
338 SCTP_INC_STATS(SCTP_MIB_OUTORDERCHUNKS
);
343 list_add_tail(&chunk
->list
, &q
->control_chunk_list
);
344 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
351 error
= sctp_outq_flush(q
, 0);
356 /* Insert a chunk into the sorted list based on the TSNs. The retransmit list
357 * and the abandoned list are in ascending order.
359 static void sctp_insert_list(struct list_head
*head
, struct list_head
*new)
361 struct list_head
*pos
;
362 struct sctp_chunk
*nchunk
, *lchunk
;
366 nchunk
= list_entry(new, struct sctp_chunk
, transmitted_list
);
367 ntsn
= ntohl(nchunk
->subh
.data_hdr
->tsn
);
369 list_for_each(pos
, head
) {
370 lchunk
= list_entry(pos
, struct sctp_chunk
, transmitted_list
);
371 ltsn
= ntohl(lchunk
->subh
.data_hdr
->tsn
);
372 if (TSN_lt(ntsn
, ltsn
)) {
373 list_add(new, pos
->prev
);
379 list_add_tail(new, head
);
382 /* Mark all the eligible packets on a transport for retransmission. */
383 void sctp_retransmit_mark(struct sctp_outq
*q
,
384 struct sctp_transport
*transport
,
387 struct list_head
*lchunk
, *ltemp
;
388 struct sctp_chunk
*chunk
;
390 /* Walk through the specified transmitted queue. */
391 list_for_each_safe(lchunk
, ltemp
, &transport
->transmitted
) {
392 chunk
= list_entry(lchunk
, struct sctp_chunk
,
395 /* If the chunk is abandoned, move it to abandoned list. */
396 if (sctp_chunk_abandoned(chunk
)) {
397 list_del_init(lchunk
);
398 sctp_insert_list(&q
->abandoned
, lchunk
);
400 /* If this chunk has not been previousely acked,
401 * stop considering it 'outstanding'. Our peer
402 * will most likely never see it since it will
403 * not be retransmitted
405 if (!chunk
->tsn_gap_acked
) {
406 chunk
->transport
->flight_size
-=
407 sctp_data_size(chunk
);
408 q
->outstanding_bytes
-= sctp_data_size(chunk
);
409 q
->asoc
->peer
.rwnd
+= (sctp_data_size(chunk
) +
410 sizeof(struct sk_buff
));
415 /* If we are doing retransmission due to a timeout or pmtu
416 * discovery, only the chunks that are not yet acked should
417 * be added to the retransmit queue.
419 if ((reason
== SCTP_RTXR_FAST_RTX
&&
420 (chunk
->fast_retransmit
> 0)) ||
421 (reason
!= SCTP_RTXR_FAST_RTX
&& !chunk
->tsn_gap_acked
)) {
422 /* If this chunk was sent less then 1 rto ago, do not
423 * retransmit this chunk, but give the peer time
424 * to acknowlege it. Do this only when
425 * retransmitting due to T3 timeout.
427 if (reason
== SCTP_RTXR_T3_RTX
&&
428 (jiffies
- chunk
->sent_at
) < transport
->last_rto
)
431 /* RFC 2960 6.2.1 Processing a Received SACK
433 * C) Any time a DATA chunk is marked for
434 * retransmission (via either T3-rtx timer expiration
435 * (Section 6.3.3) or via fast retransmit
436 * (Section 7.2.4)), add the data size of those
437 * chunks to the rwnd.
439 q
->asoc
->peer
.rwnd
+= (sctp_data_size(chunk
) +
440 sizeof(struct sk_buff
));
441 q
->outstanding_bytes
-= sctp_data_size(chunk
);
442 transport
->flight_size
-= sctp_data_size(chunk
);
444 /* sctpimpguide-05 Section 2.8.2
445 * M5) If a T3-rtx timer expires, the
446 * 'TSN.Missing.Report' of all affected TSNs is set
449 chunk
->tsn_missing_report
= 0;
451 /* If a chunk that is being used for RTT measurement
452 * has to be retransmitted, we cannot use this chunk
453 * anymore for RTT measurements. Reset rto_pending so
454 * that a new RTT measurement is started when a new
455 * data chunk is sent.
457 if (chunk
->rtt_in_progress
) {
458 chunk
->rtt_in_progress
= 0;
459 transport
->rto_pending
= 0;
462 /* Move the chunk to the retransmit queue. The chunks
463 * on the retransmit queue are always kept in order.
465 list_del_init(lchunk
);
466 sctp_insert_list(&q
->retransmit
, lchunk
);
470 SCTP_DEBUG_PRINTK("%s: transport: %p, reason: %d, "
471 "cwnd: %d, ssthresh: %d, flight_size: %d, "
472 "pba: %d\n", __func__
,
474 transport
->cwnd
, transport
->ssthresh
,
475 transport
->flight_size
,
476 transport
->partial_bytes_acked
);
480 /* Mark all the eligible packets on a transport for retransmission and force
483 void sctp_retransmit(struct sctp_outq
*q
, struct sctp_transport
*transport
,
484 sctp_retransmit_reason_t reason
)
489 case SCTP_RTXR_T3_RTX
:
490 SCTP_INC_STATS(SCTP_MIB_T3_RETRANSMITS
);
491 sctp_transport_lower_cwnd(transport
, SCTP_LOWER_CWND_T3_RTX
);
492 /* Update the retran path if the T3-rtx timer has expired for
493 * the current retran path.
495 if (transport
== transport
->asoc
->peer
.retran_path
)
496 sctp_assoc_update_retran_path(transport
->asoc
);
497 transport
->asoc
->rtx_data_chunks
+=
498 transport
->asoc
->unack_data
;
500 case SCTP_RTXR_FAST_RTX
:
501 SCTP_INC_STATS(SCTP_MIB_FAST_RETRANSMITS
);
502 sctp_transport_lower_cwnd(transport
, SCTP_LOWER_CWND_FAST_RTX
);
504 case SCTP_RTXR_PMTUD
:
505 SCTP_INC_STATS(SCTP_MIB_PMTUD_RETRANSMITS
);
507 case SCTP_RTXR_T1_RTX
:
508 SCTP_INC_STATS(SCTP_MIB_T1_RETRANSMITS
);
509 transport
->asoc
->init_retries
++;
515 sctp_retransmit_mark(q
, transport
, reason
);
517 /* PR-SCTP A5) Any time the T3-rtx timer expires, on any destination,
518 * the sender SHOULD try to advance the "Advanced.Peer.Ack.Point" by
519 * following the procedures outlined in C1 - C5.
521 sctp_generate_fwdtsn(q
, q
->asoc
->ctsn_ack_point
);
523 error
= sctp_outq_flush(q
, /* rtx_timeout */ 1);
526 q
->asoc
->base
.sk
->sk_err
= -error
;
530 * Transmit DATA chunks on the retransmit queue. Upon return from
531 * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
532 * need to be transmitted by the caller.
533 * We assume that pkt->transport has already been set.
535 * The return value is a normal kernel error return value.
537 static int sctp_outq_flush_rtx(struct sctp_outq
*q
, struct sctp_packet
*pkt
,
538 int rtx_timeout
, int *start_timer
)
540 struct list_head
*lqueue
;
541 struct list_head
*lchunk
, *lchunk1
;
542 struct sctp_transport
*transport
= pkt
->transport
;
544 struct sctp_chunk
*chunk
, *chunk1
;
545 struct sctp_association
*asoc
;
549 lqueue
= &q
->retransmit
;
551 /* RFC 2960 6.3.3 Handle T3-rtx Expiration
553 * E3) Determine how many of the earliest (i.e., lowest TSN)
554 * outstanding DATA chunks for the address for which the
555 * T3-rtx has expired will fit into a single packet, subject
556 * to the MTU constraint for the path corresponding to the
557 * destination transport address to which the retransmission
558 * is being sent (this may be different from the address for
559 * which the timer expires [see Section 6.4]). Call this value
560 * K. Bundle and retransmit those K DATA chunks in a single
561 * packet to the destination endpoint.
563 * [Just to be painfully clear, if we are retransmitting
564 * because a timeout just happened, we should send only ONE
565 * packet of retransmitted data.]
567 lchunk
= sctp_list_dequeue(lqueue
);
570 chunk
= list_entry(lchunk
, struct sctp_chunk
,
573 /* Make sure that Gap Acked TSNs are not retransmitted. A
574 * simple approach is just to move such TSNs out of the
575 * way and into a 'transmitted' queue and skip to the
578 if (chunk
->tsn_gap_acked
) {
579 list_add_tail(lchunk
, &transport
->transmitted
);
580 lchunk
= sctp_list_dequeue(lqueue
);
584 /* Attempt to append this chunk to the packet. */
585 status
= sctp_packet_append_chunk(pkt
, chunk
);
588 case SCTP_XMIT_PMTU_FULL
:
589 /* Send this packet. */
590 if ((error
= sctp_packet_transmit(pkt
)) == 0)
593 /* If we are retransmitting, we should only
594 * send a single packet.
597 list_add(lchunk
, lqueue
);
601 /* Bundle lchunk in the next round. */
604 case SCTP_XMIT_RWND_FULL
:
605 /* Send this packet. */
606 if ((error
= sctp_packet_transmit(pkt
)) == 0)
609 /* Stop sending DATA as there is no more room
612 list_add(lchunk
, lqueue
);
616 case SCTP_XMIT_NAGLE_DELAY
:
617 /* Send this packet. */
618 if ((error
= sctp_packet_transmit(pkt
)) == 0)
621 /* Stop sending DATA because of nagle delay. */
622 list_add(lchunk
, lqueue
);
627 /* The append was successful, so add this chunk to
628 * the transmitted list.
630 list_add_tail(lchunk
, &transport
->transmitted
);
632 /* Mark the chunk as ineligible for fast retransmit
633 * after it is retransmitted.
635 if (chunk
->fast_retransmit
> 0)
636 chunk
->fast_retransmit
= -1;
641 /* Retrieve a new chunk to bundle. */
642 lchunk
= sctp_list_dequeue(lqueue
);
646 /* If we are here due to a retransmit timeout or a fast
647 * retransmit and if there are any chunks left in the retransmit
648 * queue that could not fit in the PMTU sized packet, they need
649 * to be marked as ineligible for a subsequent fast retransmit.
651 if (rtx_timeout
&& !lchunk
) {
652 list_for_each(lchunk1
, lqueue
) {
653 chunk1
= list_entry(lchunk1
, struct sctp_chunk
,
655 if (chunk1
->fast_retransmit
> 0)
656 chunk1
->fast_retransmit
= -1;
664 /* Cork the outqueue so queued chunks are really queued. */
665 int sctp_outq_uncork(struct sctp_outq
*q
)
670 error
= sctp_outq_flush(q
, 0);
675 * Try to flush an outqueue.
677 * Description: Send everything in q which we legally can, subject to
678 * congestion limitations.
679 * * Note: This function can be called from multiple contexts so appropriate
680 * locking concerns must be made. Today we use the sock lock to protect
683 int sctp_outq_flush(struct sctp_outq
*q
, int rtx_timeout
)
685 struct sctp_packet
*packet
;
686 struct sctp_packet singleton
;
687 struct sctp_association
*asoc
= q
->asoc
;
688 __u16 sport
= asoc
->base
.bind_addr
.port
;
689 __u16 dport
= asoc
->peer
.port
;
690 __u32 vtag
= asoc
->peer
.i
.init_tag
;
691 struct sctp_transport
*transport
= NULL
;
692 struct sctp_transport
*new_transport
;
693 struct sctp_chunk
*chunk
, *tmp
;
698 /* These transports have chunks to send. */
699 struct list_head transport_list
;
700 struct list_head
*ltransport
;
702 INIT_LIST_HEAD(&transport_list
);
708 * When bundling control chunks with DATA chunks, an
709 * endpoint MUST place control chunks first in the outbound
710 * SCTP packet. The transmitter MUST transmit DATA chunks
711 * within a SCTP packet in increasing order of TSN.
715 list_for_each_entry_safe(chunk
, tmp
, &q
->control_chunk_list
, list
) {
716 list_del_init(&chunk
->list
);
718 /* Pick the right transport to use. */
719 new_transport
= chunk
->transport
;
721 if (!new_transport
) {
723 * If we have a prior transport pointer, see if
724 * the destination address of the chunk
725 * matches the destination address of the
726 * current transport. If not a match, then
727 * try to look up the transport with a given
728 * destination address. We do this because
729 * after processing ASCONFs, we may have new
730 * transports created.
733 sctp_cmp_addr_exact(&chunk
->dest
,
735 new_transport
= transport
;
737 new_transport
= sctp_assoc_lookup_paddr(asoc
,
740 /* if we still don't have a new transport, then
741 * use the current active path.
744 new_transport
= asoc
->peer
.active_path
;
745 } else if ((new_transport
->state
== SCTP_INACTIVE
) ||
746 (new_transport
->state
== SCTP_UNCONFIRMED
)) {
747 /* If the chunk is Heartbeat or Heartbeat Ack,
748 * send it to chunk->transport, even if it's
751 * 3.3.6 Heartbeat Acknowledgement:
753 * A HEARTBEAT ACK is always sent to the source IP
754 * address of the IP datagram containing the
755 * HEARTBEAT chunk to which this ack is responding.
758 * ASCONF_ACKs also must be sent to the source.
760 if (chunk
->chunk_hdr
->type
!= SCTP_CID_HEARTBEAT
&&
761 chunk
->chunk_hdr
->type
!= SCTP_CID_HEARTBEAT_ACK
&&
762 chunk
->chunk_hdr
->type
!= SCTP_CID_ASCONF_ACK
)
763 new_transport
= asoc
->peer
.active_path
;
766 /* Are we switching transports?
767 * Take care of transport locks.
769 if (new_transport
!= transport
) {
770 transport
= new_transport
;
771 if (list_empty(&transport
->send_ready
)) {
772 list_add_tail(&transport
->send_ready
,
775 packet
= &transport
->packet
;
776 sctp_packet_config(packet
, vtag
,
777 asoc
->peer
.ecn_capable
);
780 switch (chunk
->chunk_hdr
->type
) {
784 * An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
785 * COMPLETE with any other chunks. [Send them immediately.]
788 case SCTP_CID_INIT_ACK
:
789 case SCTP_CID_SHUTDOWN_COMPLETE
:
790 sctp_packet_init(&singleton
, transport
, sport
, dport
);
791 sctp_packet_config(&singleton
, vtag
, 0);
792 sctp_packet_append_chunk(&singleton
, chunk
);
793 error
= sctp_packet_transmit(&singleton
);
800 case SCTP_CID_HEARTBEAT
:
801 case SCTP_CID_HEARTBEAT_ACK
:
802 case SCTP_CID_SHUTDOWN
:
803 case SCTP_CID_SHUTDOWN_ACK
:
805 case SCTP_CID_COOKIE_ECHO
:
806 case SCTP_CID_COOKIE_ACK
:
807 case SCTP_CID_ECN_ECNE
:
808 case SCTP_CID_ECN_CWR
:
809 case SCTP_CID_ASCONF
:
810 case SCTP_CID_ASCONF_ACK
:
811 case SCTP_CID_FWD_TSN
:
812 sctp_packet_transmit_chunk(packet
, chunk
);
816 /* We built a chunk with an illegal type! */
821 /* Is it OK to send data chunks? */
822 switch (asoc
->state
) {
823 case SCTP_STATE_COOKIE_ECHOED
:
824 /* Only allow bundling when this packet has a COOKIE-ECHO
827 if (!packet
|| !packet
->has_cookie_echo
)
831 case SCTP_STATE_ESTABLISHED
:
832 case SCTP_STATE_SHUTDOWN_PENDING
:
833 case SCTP_STATE_SHUTDOWN_RECEIVED
:
835 * RFC 2960 6.1 Transmission of DATA Chunks
837 * C) When the time comes for the sender to transmit,
838 * before sending new DATA chunks, the sender MUST
839 * first transmit any outstanding DATA chunks which
840 * are marked for retransmission (limited by the
843 if (!list_empty(&q
->retransmit
)) {
844 if (transport
== asoc
->peer
.retran_path
)
847 /* Switch transports & prepare the packet. */
849 transport
= asoc
->peer
.retran_path
;
851 if (list_empty(&transport
->send_ready
)) {
852 list_add_tail(&transport
->send_ready
,
856 packet
= &transport
->packet
;
857 sctp_packet_config(packet
, vtag
,
858 asoc
->peer
.ecn_capable
);
860 error
= sctp_outq_flush_rtx(q
, packet
,
861 rtx_timeout
, &start_timer
);
864 sctp_transport_reset_timers(transport
);
866 /* This can happen on COOKIE-ECHO resend. Only
867 * one chunk can get bundled with a COOKIE-ECHO.
869 if (packet
->has_cookie_echo
)
872 /* Don't send new data if there is still data
873 * waiting to retransmit.
875 if (!list_empty(&q
->retransmit
))
879 /* Finally, transmit new packets. */
881 while ((chunk
= sctp_outq_dequeue_data(q
)) != NULL
) {
882 /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
885 if (chunk
->sinfo
.sinfo_stream
>=
886 asoc
->c
.sinit_num_ostreams
) {
888 /* Mark as failed send. */
889 sctp_chunk_fail(chunk
, SCTP_ERROR_INV_STRM
);
890 sctp_chunk_free(chunk
);
894 /* Has this chunk expired? */
895 if (sctp_chunk_abandoned(chunk
)) {
896 sctp_chunk_fail(chunk
, 0);
897 sctp_chunk_free(chunk
);
901 /* If there is a specified transport, use it.
902 * Otherwise, we want to use the active path.
904 new_transport
= chunk
->transport
;
905 if (!new_transport
||
906 ((new_transport
->state
== SCTP_INACTIVE
) ||
907 (new_transport
->state
== SCTP_UNCONFIRMED
)))
908 new_transport
= asoc
->peer
.active_path
;
910 /* Change packets if necessary. */
911 if (new_transport
!= transport
) {
912 transport
= new_transport
;
914 /* Schedule to have this transport's
917 if (list_empty(&transport
->send_ready
)) {
918 list_add_tail(&transport
->send_ready
,
922 packet
= &transport
->packet
;
923 sctp_packet_config(packet
, vtag
,
924 asoc
->peer
.ecn_capable
);
927 SCTP_DEBUG_PRINTK("sctp_outq_flush(%p, %p[%s]), ",
929 chunk
&& chunk
->chunk_hdr
?
930 sctp_cname(SCTP_ST_CHUNK(
931 chunk
->chunk_hdr
->type
))
934 SCTP_DEBUG_PRINTK("TX TSN 0x%x skb->head "
935 "%p skb->users %d.\n",
936 ntohl(chunk
->subh
.data_hdr
->tsn
),
937 chunk
->skb
?chunk
->skb
->head
: NULL
,
939 atomic_read(&chunk
->skb
->users
) : -1);
941 /* Add the chunk to the packet. */
942 status
= sctp_packet_transmit_chunk(packet
, chunk
);
945 case SCTP_XMIT_PMTU_FULL
:
946 case SCTP_XMIT_RWND_FULL
:
947 case SCTP_XMIT_NAGLE_DELAY
:
948 /* We could not append this chunk, so put
949 * the chunk back on the output queue.
951 SCTP_DEBUG_PRINTK("sctp_outq_flush: could "
952 "not transmit TSN: 0x%x, status: %d\n",
953 ntohl(chunk
->subh
.data_hdr
->tsn
),
955 sctp_outq_head_data(q
, chunk
);
966 /* BUG: We assume that the sctp_packet_transmit()
967 * call below will succeed all the time and add the
968 * chunk to the transmitted list and restart the
970 * It is possible that the call can fail under OOM
973 * Is this really a problem? Won't this behave
976 list_add_tail(&chunk
->transmitted_list
,
977 &transport
->transmitted
);
979 sctp_transport_reset_timers(transport
);
983 /* Only let one DATA chunk get bundled with a
986 if (packet
->has_cookie_echo
)
998 /* Before returning, examine all the transports touched in
999 * this call. Right now, we bluntly force clear all the
1000 * transports. Things might change after we implement Nagle.
1001 * But such an examination is still required.
1005 while ((ltransport
= sctp_list_dequeue(&transport_list
)) != NULL
) {
1006 struct sctp_transport
*t
= list_entry(ltransport
,
1007 struct sctp_transport
,
1009 packet
= &t
->packet
;
1010 if (!sctp_packet_empty(packet
))
1011 error
= sctp_packet_transmit(packet
);
1017 /* Update unack_data based on the incoming SACK chunk */
1018 static void sctp_sack_update_unack_data(struct sctp_association
*assoc
,
1019 struct sctp_sackhdr
*sack
)
1021 sctp_sack_variable_t
*frags
;
1025 unack_data
= assoc
->next_tsn
- assoc
->ctsn_ack_point
- 1;
1027 frags
= sack
->variable
;
1028 for (i
= 0; i
< ntohs(sack
->num_gap_ack_blocks
); i
++) {
1029 unack_data
-= ((ntohs(frags
[i
].gab
.end
) -
1030 ntohs(frags
[i
].gab
.start
) + 1));
1033 assoc
->unack_data
= unack_data
;
1036 /* Return the highest new tsn that is acknowledged by the given SACK chunk. */
1037 static __u32
sctp_highest_new_tsn(struct sctp_sackhdr
*sack
,
1038 struct sctp_association
*asoc
)
1040 struct list_head
*ltransport
, *lchunk
;
1041 struct sctp_transport
*transport
;
1042 struct sctp_chunk
*chunk
;
1043 __u32 highest_new_tsn
, tsn
;
1044 struct list_head
*transport_list
= &asoc
->peer
.transport_addr_list
;
1046 highest_new_tsn
= ntohl(sack
->cum_tsn_ack
);
1048 list_for_each(ltransport
, transport_list
) {
1049 transport
= list_entry(ltransport
, struct sctp_transport
,
1051 list_for_each(lchunk
, &transport
->transmitted
) {
1052 chunk
= list_entry(lchunk
, struct sctp_chunk
,
1054 tsn
= ntohl(chunk
->subh
.data_hdr
->tsn
);
1056 if (!chunk
->tsn_gap_acked
&&
1057 TSN_lt(highest_new_tsn
, tsn
) &&
1058 sctp_acked(sack
, tsn
))
1059 highest_new_tsn
= tsn
;
1063 return highest_new_tsn
;
1066 /* This is where we REALLY process a SACK.
1068 * Process the SACK against the outqueue. Mostly, this just frees
1069 * things off the transmitted queue.
1071 int sctp_outq_sack(struct sctp_outq
*q
, struct sctp_sackhdr
*sack
)
1073 struct sctp_association
*asoc
= q
->asoc
;
1074 struct sctp_transport
*transport
;
1075 struct sctp_chunk
*tchunk
= NULL
;
1076 struct list_head
*lchunk
, *transport_list
, *pos
, *temp
;
1077 sctp_sack_variable_t
*frags
= sack
->variable
;
1078 __u32 sack_ctsn
, ctsn
, tsn
;
1079 __u32 highest_tsn
, highest_new_tsn
;
1081 unsigned outstanding
;
1082 struct sctp_transport
*primary
= asoc
->peer
.primary_path
;
1083 int count_of_newacks
= 0;
1085 /* Grab the association's destination address list. */
1086 transport_list
= &asoc
->peer
.transport_addr_list
;
1088 sack_ctsn
= ntohl(sack
->cum_tsn_ack
);
1091 * SFR-CACC algorithm:
1092 * On receipt of a SACK the sender SHOULD execute the
1093 * following statements.
1095 * 1) If the cumulative ack in the SACK passes next tsn_at_change
1096 * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
1097 * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
1100 if (TSN_lte(primary
->cacc
.next_tsn_at_change
, sack_ctsn
)) {
1101 primary
->cacc
.changeover_active
= 0;
1102 list_for_each(pos
, transport_list
) {
1103 transport
= list_entry(pos
, struct sctp_transport
,
1105 transport
->cacc
.cycling_changeover
= 0;
1110 * SFR-CACC algorithm:
1111 * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
1112 * is set the receiver of the SACK MUST take the following actions:
1114 * A) Initialize the cacc_saw_newack to 0 for all destination
1117 if (sack
->num_gap_ack_blocks
&&
1118 primary
->cacc
.changeover_active
) {
1119 list_for_each(pos
, transport_list
) {
1120 transport
= list_entry(pos
, struct sctp_transport
,
1122 transport
->cacc
.cacc_saw_newack
= 0;
1126 /* Get the highest TSN in the sack. */
1127 highest_tsn
= sack_ctsn
;
1128 if (sack
->num_gap_ack_blocks
)
1130 ntohs(frags
[ntohs(sack
->num_gap_ack_blocks
) - 1].gab
.end
);
1132 if (TSN_lt(asoc
->highest_sacked
, highest_tsn
)) {
1133 highest_new_tsn
= highest_tsn
;
1134 asoc
->highest_sacked
= highest_tsn
;
1136 highest_new_tsn
= sctp_highest_new_tsn(sack
, asoc
);
1139 /* Run through the retransmit queue. Credit bytes received
1140 * and free those chunks that we can.
1142 sctp_check_transmitted(q
, &q
->retransmit
, NULL
, sack
, highest_new_tsn
);
1143 sctp_mark_missing(q
, &q
->retransmit
, NULL
, highest_new_tsn
, 0);
1145 /* Run through the transmitted queue.
1146 * Credit bytes received and free those chunks which we can.
1148 * This is a MASSIVE candidate for optimization.
1150 list_for_each(pos
, transport_list
) {
1151 transport
= list_entry(pos
, struct sctp_transport
,
1153 sctp_check_transmitted(q
, &transport
->transmitted
,
1154 transport
, sack
, highest_new_tsn
);
1156 * SFR-CACC algorithm:
1157 * C) Let count_of_newacks be the number of
1158 * destinations for which cacc_saw_newack is set.
1160 if (transport
->cacc
.cacc_saw_newack
)
1161 count_of_newacks
++;
1164 list_for_each(pos
, transport_list
) {
1165 transport
= list_entry(pos
, struct sctp_transport
,
1167 sctp_mark_missing(q
, &transport
->transmitted
, transport
,
1168 highest_new_tsn
, count_of_newacks
);
1171 /* Move the Cumulative TSN Ack Point if appropriate. */
1172 if (TSN_lt(asoc
->ctsn_ack_point
, sack_ctsn
))
1173 asoc
->ctsn_ack_point
= sack_ctsn
;
1175 /* Update unack_data field in the assoc. */
1176 sctp_sack_update_unack_data(asoc
, sack
);
1178 ctsn
= asoc
->ctsn_ack_point
;
1180 /* Throw away stuff rotting on the sack queue. */
1181 list_for_each_safe(lchunk
, temp
, &q
->sacked
) {
1182 tchunk
= list_entry(lchunk
, struct sctp_chunk
,
1184 tsn
= ntohl(tchunk
->subh
.data_hdr
->tsn
);
1185 if (TSN_lte(tsn
, ctsn
)) {
1186 list_del_init(&tchunk
->transmitted_list
);
1187 sctp_chunk_free(tchunk
);
1191 /* ii) Set rwnd equal to the newly received a_rwnd minus the
1192 * number of bytes still outstanding after processing the
1193 * Cumulative TSN Ack and the Gap Ack Blocks.
1196 sack_a_rwnd
= ntohl(sack
->a_rwnd
);
1197 outstanding
= q
->outstanding_bytes
;
1199 if (outstanding
< sack_a_rwnd
)
1200 sack_a_rwnd
-= outstanding
;
1204 asoc
->peer
.rwnd
= sack_a_rwnd
;
1206 sctp_generate_fwdtsn(q
, sack_ctsn
);
1208 SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
1209 __func__
, sack_ctsn
);
1210 SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association, "
1211 "%p is 0x%x. Adv peer ack point: 0x%x\n",
1212 __func__
, asoc
, ctsn
, asoc
->adv_peer_ack_point
);
1214 /* See if all chunks are acked.
1215 * Make sure the empty queue handler will get run later.
1217 q
->empty
= (list_empty(&q
->out_chunk_list
) &&
1218 list_empty(&q
->control_chunk_list
) &&
1219 list_empty(&q
->retransmit
));
1223 list_for_each(pos
, transport_list
) {
1224 transport
= list_entry(pos
, struct sctp_transport
,
1226 q
->empty
= q
->empty
&& list_empty(&transport
->transmitted
);
1231 SCTP_DEBUG_PRINTK("sack queue is empty.\n");
1236 /* Is the outqueue empty? */
1237 int sctp_outq_is_empty(const struct sctp_outq
*q
)
1242 /********************************************************************
1243 * 2nd Level Abstractions
1244 ********************************************************************/
1246 /* Go through a transport's transmitted list or the association's retransmit
1247 * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
1248 * The retransmit list will not have an associated transport.
1250 * I added coherent debug information output. --xguo
1252 * Instead of printing 'sacked' or 'kept' for each TSN on the
1253 * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
1254 * KEPT TSN6-TSN7, etc.
1256 static void sctp_check_transmitted(struct sctp_outq
*q
,
1257 struct list_head
*transmitted_queue
,
1258 struct sctp_transport
*transport
,
1259 struct sctp_sackhdr
*sack
,
1260 __u32 highest_new_tsn_in_sack
)
1262 struct list_head
*lchunk
;
1263 struct sctp_chunk
*tchunk
;
1264 struct list_head tlist
;
1268 __u8 restart_timer
= 0;
1269 int bytes_acked
= 0;
1271 /* These state variables are for coherent debug output. --xguo */
1274 __u32 dbg_ack_tsn
= 0; /* An ACKed TSN range starts here... */
1275 __u32 dbg_last_ack_tsn
= 0; /* ...and finishes here. */
1276 __u32 dbg_kept_tsn
= 0; /* An un-ACKed range starts here... */
1277 __u32 dbg_last_kept_tsn
= 0; /* ...and finishes here. */
1279 /* 0 : The last TSN was ACKed.
1280 * 1 : The last TSN was NOT ACKed (i.e. KEPT).
1281 * -1: We need to initialize.
1283 int dbg_prt_state
= -1;
1284 #endif /* SCTP_DEBUG */
1286 sack_ctsn
= ntohl(sack
->cum_tsn_ack
);
1288 INIT_LIST_HEAD(&tlist
);
1290 /* The while loop will skip empty transmitted queues. */
1291 while (NULL
!= (lchunk
= sctp_list_dequeue(transmitted_queue
))) {
1292 tchunk
= list_entry(lchunk
, struct sctp_chunk
,
1295 if (sctp_chunk_abandoned(tchunk
)) {
1296 /* Move the chunk to abandoned list. */
1297 sctp_insert_list(&q
->abandoned
, lchunk
);
1299 /* If this chunk has not been acked, stop
1300 * considering it as 'outstanding'.
1302 if (!tchunk
->tsn_gap_acked
) {
1303 tchunk
->transport
->flight_size
-=
1304 sctp_data_size(tchunk
);
1305 q
->outstanding_bytes
-= sctp_data_size(tchunk
);
1310 tsn
= ntohl(tchunk
->subh
.data_hdr
->tsn
);
1311 if (sctp_acked(sack
, tsn
)) {
1312 /* If this queue is the retransmit queue, the
1313 * retransmit timer has already reclaimed
1314 * the outstanding bytes for this chunk, so only
1315 * count bytes associated with a transport.
1318 /* If this chunk is being used for RTT
1319 * measurement, calculate the RTT and update
1320 * the RTO using this value.
1322 * 6.3.1 C5) Karn's algorithm: RTT measurements
1323 * MUST NOT be made using packets that were
1324 * retransmitted (and thus for which it is
1325 * ambiguous whether the reply was for the
1326 * first instance of the packet or a later
1329 if (!tchunk
->tsn_gap_acked
&&
1331 tchunk
->rtt_in_progress
) {
1332 tchunk
->rtt_in_progress
= 0;
1333 rtt
= jiffies
- tchunk
->sent_at
;
1334 sctp_transport_update_rto(transport
,
1338 if (TSN_lte(tsn
, sack_ctsn
)) {
1339 /* RFC 2960 6.3.2 Retransmission Timer Rules
1341 * R3) Whenever a SACK is received
1342 * that acknowledges the DATA chunk
1343 * with the earliest outstanding TSN
1344 * for that address, restart T3-rtx
1345 * timer for that address with its
1350 if (!tchunk
->tsn_gap_acked
) {
1351 tchunk
->tsn_gap_acked
= 1;
1352 bytes_acked
+= sctp_data_size(tchunk
);
1354 * SFR-CACC algorithm:
1355 * 2) If the SACK contains gap acks
1356 * and the flag CHANGEOVER_ACTIVE is
1357 * set the receiver of the SACK MUST
1358 * take the following action:
1360 * B) For each TSN t being acked that
1361 * has not been acked in any SACK so
1362 * far, set cacc_saw_newack to 1 for
1363 * the destination that the TSN was
1367 sack
->num_gap_ack_blocks
&&
1368 q
->asoc
->peer
.primary_path
->cacc
.
1370 transport
->cacc
.cacc_saw_newack
1374 list_add_tail(&tchunk
->transmitted_list
,
1377 /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
1378 * M2) Each time a SACK arrives reporting
1379 * 'Stray DATA chunk(s)' record the highest TSN
1380 * reported as newly acknowledged, call this
1381 * value 'HighestTSNinSack'. A newly
1382 * acknowledged DATA chunk is one not
1383 * previously acknowledged in a SACK.
1385 * When the SCTP sender of data receives a SACK
1386 * chunk that acknowledges, for the first time,
1387 * the receipt of a DATA chunk, all the still
1388 * unacknowledged DATA chunks whose TSN is
1389 * older than that newly acknowledged DATA
1390 * chunk, are qualified as 'Stray DATA chunks'.
1392 if (!tchunk
->tsn_gap_acked
) {
1393 tchunk
->tsn_gap_acked
= 1;
1394 bytes_acked
+= sctp_data_size(tchunk
);
1396 list_add_tail(lchunk
, &tlist
);
1400 switch (dbg_prt_state
) {
1401 case 0: /* last TSN was ACKed */
1402 if (dbg_last_ack_tsn
+ 1 == tsn
) {
1403 /* This TSN belongs to the
1404 * current ACK range.
1409 if (dbg_last_ack_tsn
!= dbg_ack_tsn
) {
1410 /* Display the end of the
1413 SCTP_DEBUG_PRINTK("-%08x",
1417 /* Start a new range. */
1418 SCTP_DEBUG_PRINTK(",%08x", tsn
);
1422 case 1: /* The last TSN was NOT ACKed. */
1423 if (dbg_last_kept_tsn
!= dbg_kept_tsn
) {
1424 /* Display the end of current range. */
1425 SCTP_DEBUG_PRINTK("-%08x",
1429 SCTP_DEBUG_PRINTK("\n");
1431 /* FALL THROUGH... */
1433 /* This is the first-ever TSN we examined. */
1434 /* Start a new range of ACK-ed TSNs. */
1435 SCTP_DEBUG_PRINTK("ACKed: %08x", tsn
);
1440 dbg_last_ack_tsn
= tsn
;
1441 #endif /* SCTP_DEBUG */
1444 if (tchunk
->tsn_gap_acked
) {
1445 SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
1449 tchunk
->tsn_gap_acked
= 0;
1451 bytes_acked
-= sctp_data_size(tchunk
);
1453 /* RFC 2960 6.3.2 Retransmission Timer Rules
1455 * R4) Whenever a SACK is received missing a
1456 * TSN that was previously acknowledged via a
1457 * Gap Ack Block, start T3-rtx for the
1458 * destination address to which the DATA
1459 * chunk was originally
1460 * transmitted if it is not already running.
1465 list_add_tail(lchunk
, &tlist
);
1468 /* See the above comments on ACK-ed TSNs. */
1469 switch (dbg_prt_state
) {
1471 if (dbg_last_kept_tsn
+ 1 == tsn
)
1474 if (dbg_last_kept_tsn
!= dbg_kept_tsn
)
1475 SCTP_DEBUG_PRINTK("-%08x",
1478 SCTP_DEBUG_PRINTK(",%08x", tsn
);
1483 if (dbg_last_ack_tsn
!= dbg_ack_tsn
)
1484 SCTP_DEBUG_PRINTK("-%08x",
1486 SCTP_DEBUG_PRINTK("\n");
1488 /* FALL THROUGH... */
1490 SCTP_DEBUG_PRINTK("KEPT: %08x",tsn
);
1495 dbg_last_kept_tsn
= tsn
;
1496 #endif /* SCTP_DEBUG */
1501 /* Finish off the last range, displaying its ending TSN. */
1502 switch (dbg_prt_state
) {
1504 if (dbg_last_ack_tsn
!= dbg_ack_tsn
) {
1505 SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_ack_tsn
);
1507 SCTP_DEBUG_PRINTK("\n");
1512 if (dbg_last_kept_tsn
!= dbg_kept_tsn
) {
1513 SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_kept_tsn
);
1515 SCTP_DEBUG_PRINTK("\n");
1518 #endif /* SCTP_DEBUG */
1521 /* 8.2. When an outstanding TSN is acknowledged,
1522 * the endpoint shall clear the error counter of
1523 * the destination transport address to which the
1524 * DATA chunk was last sent.
1525 * The association's overall error counter is
1528 transport
->error_count
= 0;
1529 transport
->asoc
->overall_error_count
= 0;
1531 /* Mark the destination transport address as
1532 * active if it is not so marked.
1534 if ((transport
->state
== SCTP_INACTIVE
) ||
1535 (transport
->state
== SCTP_UNCONFIRMED
)) {
1536 sctp_assoc_control_transport(
1540 SCTP_RECEIVED_SACK
);
1543 sctp_transport_raise_cwnd(transport
, sack_ctsn
,
1546 transport
->flight_size
-= bytes_acked
;
1547 q
->outstanding_bytes
-= bytes_acked
;
1549 /* RFC 2960 6.1, sctpimpguide-06 2.15.2
1550 * When a sender is doing zero window probing, it
1551 * should not timeout the association if it continues
1552 * to receive new packets from the receiver. The
1553 * reason is that the receiver MAY keep its window
1554 * closed for an indefinite time.
1555 * A sender is doing zero window probing when the
1556 * receiver's advertised window is zero, and there is
1557 * only one data chunk in flight to the receiver.
1559 if (!q
->asoc
->peer
.rwnd
&&
1560 !list_empty(&tlist
) &&
1561 (sack_ctsn
+2 == q
->asoc
->next_tsn
)) {
1562 SCTP_DEBUG_PRINTK("%s: SACK received for zero "
1563 "window probe: %u\n",
1564 __func__
, sack_ctsn
);
1565 q
->asoc
->overall_error_count
= 0;
1566 transport
->error_count
= 0;
1570 /* RFC 2960 6.3.2 Retransmission Timer Rules
1572 * R2) Whenever all outstanding data sent to an address have
1573 * been acknowledged, turn off the T3-rtx timer of that
1576 if (!transport
->flight_size
) {
1577 if (timer_pending(&transport
->T3_rtx_timer
) &&
1578 del_timer(&transport
->T3_rtx_timer
)) {
1579 sctp_transport_put(transport
);
1581 } else if (restart_timer
) {
1582 if (!mod_timer(&transport
->T3_rtx_timer
,
1583 jiffies
+ transport
->rto
))
1584 sctp_transport_hold(transport
);
1588 list_splice(&tlist
, transmitted_queue
);
1591 /* Mark chunks as missing and consequently may get retransmitted. */
1592 static void sctp_mark_missing(struct sctp_outq
*q
,
1593 struct list_head
*transmitted_queue
,
1594 struct sctp_transport
*transport
,
1595 __u32 highest_new_tsn_in_sack
,
1596 int count_of_newacks
)
1598 struct sctp_chunk
*chunk
;
1599 struct list_head
*pos
;
1601 char do_fast_retransmit
= 0;
1602 struct sctp_transport
*primary
= q
->asoc
->peer
.primary_path
;
1604 list_for_each(pos
, transmitted_queue
) {
1606 chunk
= list_entry(pos
, struct sctp_chunk
, transmitted_list
);
1607 tsn
= ntohl(chunk
->subh
.data_hdr
->tsn
);
1609 /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
1610 * 'Unacknowledged TSN's', if the TSN number of an
1611 * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
1612 * value, increment the 'TSN.Missing.Report' count on that
1613 * chunk if it has NOT been fast retransmitted or marked for
1614 * fast retransmit already.
1616 if (!chunk
->fast_retransmit
&&
1617 !chunk
->tsn_gap_acked
&&
1618 TSN_lt(tsn
, highest_new_tsn_in_sack
)) {
1620 /* SFR-CACC may require us to skip marking
1621 * this chunk as missing.
1623 if (!transport
|| !sctp_cacc_skip(primary
, transport
,
1624 count_of_newacks
, tsn
)) {
1625 chunk
->tsn_missing_report
++;
1628 "%s: TSN 0x%x missing counter: %d\n",
1630 chunk
->tsn_missing_report
);
1634 * M4) If any DATA chunk is found to have a
1635 * 'TSN.Missing.Report'
1636 * value larger than or equal to 3, mark that chunk for
1637 * retransmission and start the fast retransmit procedure.
1640 if (chunk
->tsn_missing_report
>= 3) {
1641 chunk
->fast_retransmit
= 1;
1642 do_fast_retransmit
= 1;
1647 if (do_fast_retransmit
)
1648 sctp_retransmit(q
, transport
, SCTP_RTXR_FAST_RTX
);
1650 SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
1651 "ssthresh: %d, flight_size: %d, pba: %d\n",
1652 __func__
, transport
, transport
->cwnd
,
1653 transport
->ssthresh
, transport
->flight_size
,
1654 transport
->partial_bytes_acked
);
1658 /* Is the given TSN acked by this packet? */
1659 static int sctp_acked(struct sctp_sackhdr
*sack
, __u32 tsn
)
1662 sctp_sack_variable_t
*frags
;
1664 __u32 ctsn
= ntohl(sack
->cum_tsn_ack
);
1666 if (TSN_lte(tsn
, ctsn
))
1669 /* 3.3.4 Selective Acknowledgement (SACK) (3):
1672 * These fields contain the Gap Ack Blocks. They are repeated
1673 * for each Gap Ack Block up to the number of Gap Ack Blocks
1674 * defined in the Number of Gap Ack Blocks field. All DATA
1675 * chunks with TSNs greater than or equal to (Cumulative TSN
1676 * Ack + Gap Ack Block Start) and less than or equal to
1677 * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
1678 * Block are assumed to have been received correctly.
1681 frags
= sack
->variable
;
1683 for (i
= 0; i
< ntohs(sack
->num_gap_ack_blocks
); ++i
) {
1684 if (TSN_lte(ntohs(frags
[i
].gab
.start
), gap
) &&
1685 TSN_lte(gap
, ntohs(frags
[i
].gab
.end
)))
1694 static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip
*skiplist
,
1695 int nskips
, __be16 stream
)
1699 for (i
= 0; i
< nskips
; i
++) {
1700 if (skiplist
[i
].stream
== stream
)
1706 /* Create and add a fwdtsn chunk to the outq's control queue if needed. */
1707 static void sctp_generate_fwdtsn(struct sctp_outq
*q
, __u32 ctsn
)
1709 struct sctp_association
*asoc
= q
->asoc
;
1710 struct sctp_chunk
*ftsn_chunk
= NULL
;
1711 struct sctp_fwdtsn_skip ftsn_skip_arr
[10];
1715 struct sctp_chunk
*chunk
;
1716 struct list_head
*lchunk
, *temp
;
1718 /* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the
1721 * If (Advanced.Peer.Ack.Point < SackCumAck), then update
1722 * Advanced.Peer.Ack.Point to be equal to SackCumAck.
1724 if (TSN_lt(asoc
->adv_peer_ack_point
, ctsn
))
1725 asoc
->adv_peer_ack_point
= ctsn
;
1727 /* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point"
1728 * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as
1729 * the chunk next in the out-queue space is marked as "abandoned" as
1730 * shown in the following example:
1732 * Assuming that a SACK arrived with the Cumulative TSN ACK 102
1733 * and the Advanced.Peer.Ack.Point is updated to this value:
1735 * out-queue at the end of ==> out-queue after Adv.Ack.Point
1736 * normal SACK processing local advancement
1738 * Adv.Ack.Pt-> 102 acked 102 acked
1739 * 103 abandoned 103 abandoned
1740 * 104 abandoned Adv.Ack.P-> 104 abandoned
1742 * 106 acked 106 acked
1745 * In this example, the data sender successfully advanced the
1746 * "Advanced.Peer.Ack.Point" from 102 to 104 locally.
1748 list_for_each_safe(lchunk
, temp
, &q
->abandoned
) {
1749 chunk
= list_entry(lchunk
, struct sctp_chunk
,
1751 tsn
= ntohl(chunk
->subh
.data_hdr
->tsn
);
1753 /* Remove any chunks in the abandoned queue that are acked by
1756 if (TSN_lte(tsn
, ctsn
)) {
1757 list_del_init(lchunk
);
1758 sctp_chunk_free(chunk
);
1760 if (TSN_lte(tsn
, asoc
->adv_peer_ack_point
+1)) {
1761 asoc
->adv_peer_ack_point
= tsn
;
1762 if (chunk
->chunk_hdr
->flags
&
1763 SCTP_DATA_UNORDERED
)
1765 skip_pos
= sctp_get_skip_pos(&ftsn_skip_arr
[0],
1767 chunk
->subh
.data_hdr
->stream
);
1768 ftsn_skip_arr
[skip_pos
].stream
=
1769 chunk
->subh
.data_hdr
->stream
;
1770 ftsn_skip_arr
[skip_pos
].ssn
=
1771 chunk
->subh
.data_hdr
->ssn
;
1772 if (skip_pos
== nskips
)
1781 /* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point"
1782 * is greater than the Cumulative TSN ACK carried in the received
1783 * SACK, the data sender MUST send the data receiver a FORWARD TSN
1784 * chunk containing the latest value of the
1785 * "Advanced.Peer.Ack.Point".
1787 * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD
1788 * list each stream and sequence number in the forwarded TSN. This
1789 * information will enable the receiver to easily find any
1790 * stranded TSN's waiting on stream reorder queues. Each stream
1791 * SHOULD only be reported once; this means that if multiple
1792 * abandoned messages occur in the same stream then only the
1793 * highest abandoned stream sequence number is reported. If the
1794 * total size of the FORWARD TSN does NOT fit in a single MTU then
1795 * the sender of the FORWARD TSN SHOULD lower the
1796 * Advanced.Peer.Ack.Point to the last TSN that will fit in a
1799 if (asoc
->adv_peer_ack_point
> ctsn
)
1800 ftsn_chunk
= sctp_make_fwdtsn(asoc
, asoc
->adv_peer_ack_point
,
1801 nskips
, &ftsn_skip_arr
[0]);
1804 list_add_tail(&ftsn_chunk
->list
, &q
->control_chunk_list
);
1805 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);