Merge with Linux 2.5.74.
[linux-2.6/linux-mips.git] / net / sctp / outqueue.c
blobb7bd2bf6e6a2fd4895e2ec208af26210831d12a6
1 /* SCTP kernel reference Implementation
2 * Copyright (c) 1999-2000 Cisco, Inc.
3 * Copyright (c) 1999-2001 Motorola, Inc.
4 * Copyright (c) 2001-2003 Intel Corp.
5 * Copyright (c) 2001-2003 International Business Machines 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)
16 * any later version.
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
30 * email address(es):
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>
52 #include <linux/ip.h>
53 #include <net/sock.h> /* For skb_set_owner_w */
55 #include <net/sctp/sctp.h>
57 /* Declare internal functions here. */
58 static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn);
59 static void sctp_check_transmitted(struct sctp_outq *q,
60 struct list_head *transmitted_queue,
61 struct sctp_transport *transport,
62 struct sctp_sackhdr *sack,
63 __u32 highest_new_tsn);
65 static void sctp_mark_missing(struct sctp_outq *q,
66 struct list_head *transmitted_queue,
67 struct sctp_transport *transport,
68 __u32 highest_new_tsn,
69 int count_of_newacks);
71 /* Add data to the front of the queue. */
72 static inline void sctp_outq_head_data(struct sctp_outq *q,
73 struct sctp_chunk *ch)
75 __skb_queue_head(&q->out, (struct sk_buff *)ch);
76 q->out_qlen += ch->skb->len;
77 return;
80 /* Take data from the front of the queue. */
81 static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q)
83 struct sctp_chunk *ch;
84 ch = (struct sctp_chunk *)__skb_dequeue(&q->out);
85 if (ch)
86 q->out_qlen -= ch->skb->len;
87 return ch;
89 /* Add data chunk to the end of the queue. */
90 static inline void sctp_outq_tail_data(struct sctp_outq *q,
91 struct sctp_chunk *ch)
93 __skb_queue_tail(&q->out, (struct sk_buff *)ch);
94 q->out_qlen += ch->skb->len;
95 return;
98 /* Insert a chunk behind chunk 'pos'. */
99 static inline void sctp_outq_insert_data(struct sctp_outq *q,
100 struct sctp_chunk *ch,
101 struct sctp_chunk *pos)
103 __skb_insert((struct sk_buff *)ch, (struct sk_buff *)pos->prev,
104 (struct sk_buff *)pos, pos->list);
105 q->out_qlen += ch->skb->len;
109 * SFR-CACC algorithm:
110 * D) If count_of_newacks is greater than or equal to 2
111 * and t was not sent to the current primary then the
112 * sender MUST NOT increment missing report count for t.
114 static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary,
115 struct sctp_transport *transport,
116 int count_of_newacks)
118 if (count_of_newacks >=2 && transport != primary)
119 return 1;
120 return 0;
124 * SFR-CACC algorithm:
125 * F) If count_of_newacks is less than 2, let d be the
126 * destination to which t was sent. If cacc_saw_newack
127 * is 0 for destination d, then the sender MUST NOT
128 * increment missing report count for t.
130 static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport,
131 int count_of_newacks)
133 if (count_of_newacks < 2 && !transport->cacc.cacc_saw_newack)
134 return 1;
135 return 0;
139 * SFR-CACC algorithm:
140 * 3.1) If CYCLING_CHANGEOVER is 0, the sender SHOULD
141 * execute steps C, D, F.
143 * C has been implemented in sctp_outq_sack
145 static inline int sctp_cacc_skip_3_1(struct sctp_transport *primary,
146 struct sctp_transport *transport,
147 int count_of_newacks)
149 if (!primary->cacc.cycling_changeover) {
150 if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks))
151 return 1;
152 if (sctp_cacc_skip_3_1_f(transport, count_of_newacks));
153 return 1;
154 return 0;
156 return 0;
160 * SFR-CACC algorithm:
161 * 3.2) Else if CYCLING_CHANGEOVER is 1, and t is less
162 * than next_tsn_at_change of the current primary, then
163 * the sender MUST NOT increment missing report count
164 * for t.
166 static inline int sctp_cacc_skip_3_2(struct sctp_transport *primary, __u32 tsn)
168 if (primary->cacc.cycling_changeover &&
169 TSN_lt(tsn, primary->cacc.next_tsn_at_change))
170 return 1;
171 return 0;
175 * SFR-CACC algorithm:
176 * 3) If the missing report count for TSN t is to be
177 * incremented according to [RFC2960] and
178 * [SCTP_STEWART-2002], and CHANGEOVER_ACTIVE is set,
179 * then the sender MUST futher execute steps 3.1 and
180 * 3.2 to determine if the missing report count for
181 * TSN t SHOULD NOT be incremented.
183 * 3.3) If 3.1 and 3.2 do not dictate that the missing
184 * report count for t should not be incremented, then
185 * the sender SOULD increment missing report count for
186 * t (according to [RFC2960] and [SCTP_STEWART_2002]).
188 static inline int sctp_cacc_skip(struct sctp_transport *primary,
189 struct sctp_transport *transport,
190 int count_of_newacks,
191 __u32 tsn)
193 if (primary->cacc.changeover_active &&
194 (sctp_cacc_skip_3_1(primary, transport, count_of_newacks)
195 || sctp_cacc_skip_3_2(primary, tsn)))
196 return 1;
197 return 0;
200 /* Generate a new outqueue. */
201 struct sctp_outq *sctp_outq_new(struct sctp_association *asoc)
203 struct sctp_outq *q;
205 q = t_new(struct sctp_outq, GFP_KERNEL);
206 if (q) {
207 sctp_outq_init(asoc, q);
208 q->malloced = 1;
210 return q;
213 /* Initialize an existing sctp_outq. This does the boring stuff.
214 * You still need to define handlers if you really want to DO
215 * something with this structure...
217 void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
219 q->asoc = asoc;
220 skb_queue_head_init(&q->out);
221 skb_queue_head_init(&q->control);
222 INIT_LIST_HEAD(&q->retransmit);
223 INIT_LIST_HEAD(&q->sacked);
225 q->init_output = NULL;
226 q->config_output = NULL;
227 q->append_output = NULL;
228 q->build_output = NULL;
229 q->force_output = NULL;
231 q->outstanding_bytes = 0;
232 q->empty = 1;
233 q->cork = 0;
235 q->malloced = 0;
236 q->out_qlen = 0;
239 /* Free the outqueue structure and any related pending chunks.
241 void sctp_outq_teardown(struct sctp_outq *q)
243 struct sctp_transport *transport;
244 struct list_head *lchunk, *pos, *temp;
245 struct sctp_chunk *chunk;
247 /* Throw away unacknowledged chunks. */
248 list_for_each(pos, &q->asoc->peer.transport_addr_list) {
249 transport = list_entry(pos, struct sctp_transport, transports);
250 while ((lchunk = sctp_list_dequeue(&transport->transmitted))) {
251 chunk = list_entry(lchunk, struct sctp_chunk,
252 transmitted_list);
253 /* Mark as part of a failed message. */
254 sctp_datamsg_fail(chunk, q->error);
255 sctp_chunk_free(chunk);
259 /* Throw away chunks that have been gap ACKed. */
260 list_for_each_safe(lchunk, temp, &q->sacked) {
261 list_del(lchunk);
262 chunk = list_entry(lchunk, struct sctp_chunk,
263 transmitted_list);
264 sctp_datamsg_fail(chunk, q->error);
265 sctp_chunk_free(chunk);
268 /* Throw away any chunks in the retransmit queue. */
269 list_for_each_safe(lchunk, temp, &q->retransmit) {
270 list_del(lchunk);
271 chunk = list_entry(lchunk, struct sctp_chunk,
272 transmitted_list);
273 sctp_datamsg_fail(chunk, q->error);
274 sctp_chunk_free(chunk);
277 /* Throw away any leftover data chunks. */
278 while ((chunk = sctp_outq_dequeue_data(q))) {
280 /* Mark as send failure. */
281 sctp_datamsg_fail(chunk, q->error);
282 sctp_chunk_free(chunk);
285 q->error = 0;
287 /* Throw away any leftover control chunks. */
288 while ((chunk = (struct sctp_chunk *) skb_dequeue(&q->control)))
289 sctp_chunk_free(chunk);
292 /* Free the outqueue structure and any related pending chunks. */
293 void sctp_outq_free(struct sctp_outq *q)
295 /* Throw away leftover chunks. */
296 sctp_outq_teardown(q);
298 /* If we were kmalloc()'d, free the memory. */
299 if (q->malloced)
300 kfree(q);
303 /* Put a new chunk in an sctp_outq. */
304 int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
306 int error = 0;
308 SCTP_DEBUG_PRINTK("sctp_outq_tail(%p, %p[%s])\n",
309 q, chunk, chunk && chunk->chunk_hdr ?
310 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
311 : "Illegal Chunk");
313 /* If it is data, queue it up, otherwise, send it
314 * immediately.
316 if (SCTP_CID_DATA == chunk->chunk_hdr->type) {
317 /* Is it OK to queue data chunks? */
318 /* From 9. Termination of Association
320 * When either endpoint performs a shutdown, the
321 * association on each peer will stop accepting new
322 * data from its user and only deliver data in queue
323 * at the time of sending or receiving the SHUTDOWN
324 * chunk.
326 switch (q->asoc->state) {
327 case SCTP_STATE_EMPTY:
328 case SCTP_STATE_CLOSED:
329 case SCTP_STATE_SHUTDOWN_PENDING:
330 case SCTP_STATE_SHUTDOWN_SENT:
331 case SCTP_STATE_SHUTDOWN_RECEIVED:
332 case SCTP_STATE_SHUTDOWN_ACK_SENT:
333 /* Cannot send after transport endpoint shutdown */
334 error = -ESHUTDOWN;
335 break;
337 default:
338 SCTP_DEBUG_PRINTK("outqueueing (%p, %p[%s])\n",
339 q, chunk, chunk && chunk->chunk_hdr ?
340 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
341 : "Illegal Chunk");
343 sctp_outq_tail_data(q, chunk);
344 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
345 SCTP_INC_STATS(SctpOutUnorderChunks);
346 else
347 SCTP_INC_STATS(SctpOutOrderChunks);
348 q->empty = 0;
349 break;
351 } else {
352 __skb_queue_tail(&q->control, (struct sk_buff *) chunk);
353 SCTP_INC_STATS(SctpOutCtrlChunks);
356 if (error < 0)
357 return error;
359 if (!q->cork)
360 error = sctp_outq_flush(q, 0);
362 return error;
365 /* Insert a chunk into the retransmit queue. Chunks on the retransmit
366 * queue are kept in order, based on the TSNs.
368 void sctp_retransmit_insert(struct list_head *tlchunk, struct sctp_outq *q)
370 struct list_head *rlchunk;
371 struct sctp_chunk *tchunk, *rchunk;
372 __u32 ttsn, rtsn;
373 int done = 0;
375 tchunk = list_entry(tlchunk, struct sctp_chunk, transmitted_list);
376 ttsn = ntohl(tchunk->subh.data_hdr->tsn);
378 list_for_each(rlchunk, &q->retransmit) {
379 rchunk = list_entry(rlchunk, struct sctp_chunk,
380 transmitted_list);
381 rtsn = ntohl(rchunk->subh.data_hdr->tsn);
382 if (TSN_lt(ttsn, rtsn)) {
383 list_add(tlchunk, rlchunk->prev);
384 done = 1;
385 break;
388 if (!done) {
389 list_add_tail(tlchunk, &q->retransmit);
393 /* Mark all the eligible packets on a transport for retransmission. */
394 void sctp_retransmit_mark(struct sctp_outq *q,
395 struct sctp_transport *transport,
396 __u8 fast_retransmit)
398 struct list_head *lchunk, *ltemp;
399 struct sctp_chunk *chunk;
401 /* Walk through the specified transmitted queue. */
402 list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
403 chunk = list_entry(lchunk, struct sctp_chunk,
404 transmitted_list);
406 /* If we are doing retransmission due to a fast retransmit,
407 * only the chunk's that are marked for fast retransmit
408 * should be added to the retransmit queue. If we are doing
409 * retransmission due to a timeout or pmtu discovery, only the
410 * chunks that are not yet acked should be added to the
411 * retransmit queue.
413 if ((fast_retransmit && chunk->fast_retransmit) ||
414 (!fast_retransmit && !chunk->tsn_gap_acked)) {
415 /* RFC 2960 6.2.1 Processing a Received SACK
417 * C) Any time a DATA chunk is marked for
418 * retransmission (via either T3-rtx timer expiration
419 * (Section 6.3.3) or via fast retransmit
420 * (Section 7.2.4)), add the data size of those
421 * chunks to the rwnd.
423 q->asoc->peer.rwnd += sctp_data_size(chunk);
424 q->outstanding_bytes -= sctp_data_size(chunk);
425 transport->flight_size -= sctp_data_size(chunk);
427 /* sctpimpguide-05 Section 2.8.2
428 * M5) If a T3-rtx timer expires, the
429 * 'TSN.Missing.Report' of all affected TSNs is set
430 * to 0.
432 chunk->tsn_missing_report = 0;
434 /* If a chunk that is being used for RTT measurement
435 * has to be retransmitted, we cannot use this chunk
436 * anymore for RTT measurements. Reset rto_pending so
437 * that a new RTT measurement is started when a new
438 * data chunk is sent.
440 if (chunk->rtt_in_progress) {
441 chunk->rtt_in_progress = 0;
442 transport->rto_pending = 0;
445 /* Move the chunk to the retransmit queue. The chunks
446 * on the retransmit queue is always kept in order.
448 list_del(lchunk);
449 sctp_retransmit_insert(lchunk, q);
453 SCTP_DEBUG_PRINTK("%s: transport: %p, fast_retransmit: %d, "
454 "cwnd: %d, ssthresh: %d, flight_size: %d, "
455 "pba: %d\n", __FUNCTION__,
456 transport, fast_retransmit,
457 transport->cwnd, transport->ssthresh,
458 transport->flight_size,
459 transport->partial_bytes_acked);
463 /* Mark all the eligible packets on a transport for retransmission and force
464 * one packet out.
466 void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
467 sctp_retransmit_reason_t reason)
469 int error = 0;
470 __u8 fast_retransmit = 0;
472 switch(reason) {
473 case SCTP_RTXR_T3_RTX:
474 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
475 /* Update the retran path if the T3-rtx timer has expired for
476 * the current retran path.
478 if (transport == transport->asoc->peer.retran_path)
479 sctp_assoc_update_retran_path(transport->asoc);
480 break;
481 case SCTP_RTXR_FAST_RTX:
482 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
483 fast_retransmit = 1;
484 break;
485 case SCTP_RTXR_PMTUD:
486 default:
487 break;
490 sctp_retransmit_mark(q, transport, fast_retransmit);
492 error = sctp_outq_flush(q, /* rtx_timeout */ 1);
494 if (error)
495 q->asoc->base.sk->sk_err = -error;
499 * Transmit DATA chunks on the retransmit queue. Upon return from
500 * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
501 * need to be transmitted by the caller.
502 * We assume that pkt->transport has already been set.
504 * The return value is a normal kernel error return value.
506 static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
507 int rtx_timeout, int *start_timer)
509 struct list_head *lqueue;
510 struct list_head *lchunk;
511 struct sctp_transport *transport = pkt->transport;
512 sctp_xmit_t status;
513 struct sctp_chunk *chunk;
514 struct sctp_association *asoc;
515 int error = 0;
517 asoc = q->asoc;
518 lqueue = &q->retransmit;
520 /* RFC 2960 6.3.3 Handle T3-rtx Expiration
522 * E3) Determine how many of the earliest (i.e., lowest TSN)
523 * outstanding DATA chunks for the address for which the
524 * T3-rtx has expired will fit into a single packet, subject
525 * to the MTU constraint for the path corresponding to the
526 * destination transport address to which the retransmission
527 * is being sent (this may be different from the address for
528 * which the timer expires [see Section 6.4]). Call this value
529 * K. Bundle and retransmit those K DATA chunks in a single
530 * packet to the destination endpoint.
532 * [Just to be painfully clear, if we are retransmitting
533 * because a timeout just happened, we should send only ONE
534 * packet of retransmitted data.]
536 lchunk = sctp_list_dequeue(lqueue);
538 while (lchunk) {
539 chunk = list_entry(lchunk, struct sctp_chunk,
540 transmitted_list);
542 /* Make sure that Gap Acked TSNs are not retransmitted. A
543 * simple approach is just to move such TSNs out of the
544 * way and into a 'transmitted' queue and skip to the
545 * next chunk.
547 if (chunk->tsn_gap_acked) {
548 list_add_tail(lchunk, &transport->transmitted);
549 lchunk = sctp_list_dequeue(lqueue);
550 continue;
553 /* Attempt to append this chunk to the packet. */
554 status = (*q->append_output)(pkt, chunk);
556 switch (status) {
557 case SCTP_XMIT_PMTU_FULL:
558 /* Send this packet. */
559 if ((error = (*q->force_output)(pkt)) == 0)
560 *start_timer = 1;
562 /* If we are retransmitting, we should only
563 * send a single packet.
565 if (rtx_timeout) {
566 list_add(lchunk, lqueue);
567 lchunk = NULL;
570 /* Bundle lchunk in the next round. */
571 break;
573 case SCTP_XMIT_RWND_FULL:
574 /* Send this packet. */
575 if ((error = (*q->force_output)(pkt)) == 0)
576 *start_timer = 1;
578 /* Stop sending DATA as there is no more room
579 * at the receiver.
581 list_add(lchunk, lqueue);
582 lchunk = NULL;
583 break;
585 default:
586 /* The append was successful, so add this chunk to
587 * the transmitted list.
589 list_add_tail(lchunk, &transport->transmitted);
590 *start_timer = 1;
591 q->empty = 0;
593 /* Retrieve a new chunk to bundle. */
594 lchunk = sctp_list_dequeue(lqueue);
595 break;
599 return error;
602 /* Cork the outqueue so queued chunks are really queued. */
603 int sctp_outq_uncork(struct sctp_outq *q)
605 int error = 0;
606 if (q->cork) {
607 q->cork = 0;
608 error = sctp_outq_flush(q, 0);
610 return error;
614 * Try to flush an outqueue.
616 * Description: Send everything in q which we legally can, subject to
617 * congestion limitations.
618 * * Note: This function can be called from multiple contexts so appropriate
619 * locking concerns must be made. Today we use the sock lock to protect
620 * this function.
622 int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
624 struct sctp_packet *packet;
625 struct sctp_packet singleton;
626 struct sctp_association *asoc = q->asoc;
627 int ecn_capable = asoc->peer.ecn_capable;
628 __u16 sport = asoc->base.bind_addr.port;
629 __u16 dport = asoc->peer.port;
630 __u32 vtag = asoc->peer.i.init_tag;
631 /* This is the ECNE handler for singleton packets. */
632 sctp_packet_phandler_t *s_ecne_handler = NULL;
633 sctp_packet_phandler_t *ecne_handler = NULL;
634 struct sk_buff_head *queue;
635 struct sctp_transport *transport = NULL;
636 struct sctp_transport *new_transport;
637 struct sctp_chunk *chunk;
638 sctp_xmit_t status;
639 int error = 0;
640 int start_timer = 0;
642 /* These transports have chunks to send. */
643 struct list_head transport_list;
644 struct list_head *ltransport;
646 INIT_LIST_HEAD(&transport_list);
647 packet = NULL;
650 * 6.10 Bundling
651 * ...
652 * When bundling control chunks with DATA chunks, an
653 * endpoint MUST place control chunks first in the outbound
654 * SCTP packet. The transmitter MUST transmit DATA chunks
655 * within a SCTP packet in increasing order of TSN.
656 * ...
658 if (ecn_capable) {
659 s_ecne_handler = &sctp_get_no_prepend;
660 ecne_handler = &sctp_get_ecne_prepend;
663 queue = &q->control;
664 while ((chunk = (struct sctp_chunk *)skb_dequeue(queue))) {
665 /* Pick the right transport to use. */
666 new_transport = chunk->transport;
668 if (!new_transport) {
669 new_transport = asoc->peer.active_path;
670 } else if (!new_transport->active) {
671 /* If the chunk is Heartbeat, send it to
672 * chunk->transport, even it's inactive.
674 if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT)
675 new_transport = asoc->peer.active_path;
678 /* Are we switching transports?
679 * Take care of transport locks.
681 if (new_transport != transport) {
682 transport = new_transport;
683 if (list_empty(&transport->send_ready)) {
684 list_add_tail(&transport->send_ready,
685 &transport_list);
687 packet = &transport->packet;
688 (*q->config_output)(packet, vtag,
689 ecn_capable, ecne_handler);
692 switch (chunk->chunk_hdr->type) {
694 * 6.10 Bundling
695 * ...
696 * An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
697 * COMPLETE with any other chunks. [Send them immediately.]
699 case SCTP_CID_INIT:
700 case SCTP_CID_INIT_ACK:
701 case SCTP_CID_SHUTDOWN_COMPLETE:
702 (*q->init_output)(&singleton, transport, sport, dport);
703 (*q->config_output)(&singleton, vtag, ecn_capable,
704 s_ecne_handler);
705 (void) (*q->build_output)(&singleton, chunk);
706 error = (*q->force_output)(&singleton);
707 if (error < 0)
708 return error;
709 break;
711 case SCTP_CID_ABORT:
712 case SCTP_CID_SACK:
713 case SCTP_CID_HEARTBEAT:
714 case SCTP_CID_HEARTBEAT_ACK:
715 case SCTP_CID_SHUTDOWN:
716 case SCTP_CID_SHUTDOWN_ACK:
717 case SCTP_CID_ERROR:
718 case SCTP_CID_COOKIE_ECHO:
719 case SCTP_CID_COOKIE_ACK:
720 case SCTP_CID_ECN_ECNE:
721 case SCTP_CID_ECN_CWR:
722 (void) (*q->build_output)(packet, chunk);
723 break;
725 case SCTP_CID_ASCONF:
726 case SCTP_CID_ASCONF_ACK:
727 (void) (*q->build_output)(packet, chunk);
728 break;
730 default:
731 /* We built a chunk with an illegal type! */
732 BUG();
736 /* Is it OK to send data chunks? */
737 switch (asoc->state) {
738 case SCTP_STATE_COOKIE_ECHOED:
739 /* Only allow bundling when this packet has a COOKIE-ECHO
740 * chunk.
742 if (!packet || !packet->has_cookie_echo)
743 break;
745 /* fallthru */
746 case SCTP_STATE_ESTABLISHED:
747 case SCTP_STATE_SHUTDOWN_PENDING:
748 case SCTP_STATE_SHUTDOWN_RECEIVED:
750 * RFC 2960 6.1 Transmission of DATA Chunks
752 * C) When the time comes for the sender to transmit,
753 * before sending new DATA chunks, the sender MUST
754 * first transmit any outstanding DATA chunks which
755 * are marked for retransmission (limited by the
756 * current cwnd).
758 if (!list_empty(&q->retransmit)) {
759 if (transport == asoc->peer.retran_path)
760 goto retran;
762 /* Switch transports & prepare the packet. */
764 transport = asoc->peer.retran_path;
766 if (list_empty(&transport->send_ready)) {
767 list_add_tail(&transport->send_ready,
768 &transport_list);
771 packet = &transport->packet;
772 (*q->config_output)(packet, vtag,
773 ecn_capable, ecne_handler);
774 retran:
775 error = sctp_outq_flush_rtx(q, packet,
776 rtx_timeout, &start_timer);
778 if (start_timer)
779 sctp_transport_reset_timers(transport);
781 /* This can happen on COOKIE-ECHO resend. Only
782 * one chunk can get bundled with a COOKIE-ECHO.
784 if (packet->has_cookie_echo)
785 goto sctp_flush_out;
787 /* Don't send new data if there is still data
788 * waiting to retransmit.
790 if (!list_empty(&q->retransmit))
791 goto sctp_flush_out;
794 /* Finally, transmit new packets. */
795 start_timer = 0;
796 queue = &q->out;
798 while ((chunk = sctp_outq_dequeue_data(q))) {
799 /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
800 * stream identifier.
802 if (chunk->sinfo.sinfo_stream >=
803 asoc->c.sinit_num_ostreams) {
805 /* Mark as s failed send. */
806 sctp_datamsg_fail(chunk, SCTP_ERROR_INV_STRM);
807 sctp_chunk_free(chunk);
808 continue;
811 /* Has this chunk expired? */
812 if (sctp_datamsg_expires(chunk)) {
813 sctp_datamsg_fail(chunk, 0);
814 sctp_chunk_free(chunk);
815 continue;
818 /* If there is a specified transport, use it.
819 * Otherwise, we want to use the active path.
821 new_transport = chunk->transport;
822 if (!new_transport || !new_transport->active)
823 new_transport = asoc->peer.active_path;
825 /* Change packets if necessary. */
826 if (new_transport != transport) {
827 transport = new_transport;
829 /* Schedule to have this transport's
830 * packet flushed.
832 if (list_empty(&transport->send_ready)) {
833 list_add_tail(&transport->send_ready,
834 &transport_list);
837 packet = &transport->packet;
838 (*q->config_output)(packet, vtag,
839 ecn_capable, ecne_handler);
842 SCTP_DEBUG_PRINTK("sctp_transmit_packet(%p, %p[%s]), ",
843 q, chunk,
844 chunk && chunk->chunk_hdr ?
845 sctp_cname(SCTP_ST_CHUNK(
846 chunk->chunk_hdr->type))
847 : "Illegal Chunk");
849 SCTP_DEBUG_PRINTK("TX TSN 0x%x skb->head "
850 "%p skb->users %d.\n",
851 ntohl(chunk->subh.data_hdr->tsn),
852 chunk->skb ?chunk->skb->head : 0,
853 chunk->skb ?
854 atomic_read(&chunk->skb->users) : -1);
856 /* Add the chunk to the packet. */
857 status = (*q->build_output)(packet, chunk);
859 switch (status) {
860 case SCTP_XMIT_PMTU_FULL:
861 case SCTP_XMIT_RWND_FULL:
862 case SCTP_XMIT_NAGLE_DELAY:
863 /* We could not append this chunk, so put
864 * the chunk back on the output queue.
866 SCTP_DEBUG_PRINTK("sctp_outq_flush: could "
867 "not transmit TSN: 0x%x, status: %d\n",
868 ntohl(chunk->subh.data_hdr->tsn),
869 status);
870 sctp_outq_head_data(q, chunk);
871 goto sctp_flush_out;
872 break;
874 case SCTP_XMIT_OK:
875 break;
877 default:
878 BUG();
881 /* BUG: We assume that the (*q->force_output())
882 * call below will succeed all the time and add the
883 * chunk to the transmitted list and restart the
884 * timers.
885 * It is possible that the call can fail under OOM
886 * conditions.
888 * Is this really a problem? Won't this behave
889 * like a lost TSN?
891 list_add_tail(&chunk->transmitted_list,
892 &transport->transmitted);
894 sctp_transport_reset_timers(transport);
896 q->empty = 0;
898 /* Only let one DATA chunk get bundled with a
899 * COOKIE-ECHO chunk.
901 if (packet->has_cookie_echo)
902 goto sctp_flush_out;
904 break;
906 default:
907 /* Do nothing. */
908 break;
911 sctp_flush_out:
913 /* Before returning, examine all the transports touched in
914 * this call. Right now, we bluntly force clear all the
915 * transports. Things might change after we implement Nagle.
916 * But such an examination is still required.
918 * --xguo
920 while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL ) {
921 struct sctp_transport *t = list_entry(ltransport,
922 struct sctp_transport,
923 send_ready);
924 if (t != transport)
925 transport = t;
927 packet = &transport->packet;
928 if (packet->size != SCTP_IP_OVERHEAD)
929 error = (*q->force_output)(packet);
932 return error;
935 /* Set the various output handling callbacks. */
936 int sctp_outq_set_output_handlers(struct sctp_outq *q,
937 sctp_outq_ohandler_init_t init,
938 sctp_outq_ohandler_config_t config,
939 sctp_outq_ohandler_t append,
940 sctp_outq_ohandler_t build,
941 sctp_outq_ohandler_force_t force)
943 q->init_output = init;
944 q->config_output = config;
945 q->append_output = append;
946 q->build_output = build;
947 q->force_output = force;
948 return 0;
951 /* Update unack_data based on the incoming SACK chunk */
952 static void sctp_sack_update_unack_data(struct sctp_association *assoc,
953 struct sctp_sackhdr *sack)
955 sctp_sack_variable_t *frags;
956 __u16 unack_data;
957 int i;
959 unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
961 frags = sack->variable;
962 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
963 unack_data -= ((ntohs(frags[i].gab.end) -
964 ntohs(frags[i].gab.start) + 1));
967 assoc->unack_data = unack_data;
970 /* Return the highest new tsn that is acknowledged by the given SACK chunk. */
971 static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack,
972 struct sctp_association *asoc)
974 struct list_head *ltransport, *lchunk;
975 struct sctp_transport *transport;
976 struct sctp_chunk *chunk;
977 __u32 highest_new_tsn, tsn;
978 struct list_head *transport_list = &asoc->peer.transport_addr_list;
980 highest_new_tsn = ntohl(sack->cum_tsn_ack);
982 list_for_each(ltransport, transport_list) {
983 transport = list_entry(ltransport, struct sctp_transport,
984 transports);
985 list_for_each(lchunk, &transport->transmitted) {
986 chunk = list_entry(lchunk, struct sctp_chunk,
987 transmitted_list);
988 tsn = ntohl(chunk->subh.data_hdr->tsn);
990 if (!chunk->tsn_gap_acked &&
991 TSN_lt(highest_new_tsn, tsn) &&
992 sctp_acked(sack, tsn))
993 highest_new_tsn = tsn;
997 return highest_new_tsn;
1000 /* This is where we REALLY process a SACK.
1002 * Process the SACK against the outqueue. Mostly, this just frees
1003 * things off the transmitted queue.
1005 int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
1007 struct sctp_association *asoc = q->asoc;
1008 struct sctp_transport *transport;
1009 struct sctp_chunk *tchunk;
1010 struct list_head *lchunk, *transport_list, *pos;
1011 sctp_sack_variable_t *frags = sack->variable;
1012 __u32 sack_ctsn, ctsn, tsn;
1013 __u32 highest_tsn, highest_new_tsn;
1014 __u32 sack_a_rwnd;
1015 unsigned outstanding;
1016 struct sctp_transport *primary = asoc->peer.primary_path;
1017 int count_of_newacks = 0;
1019 /* Grab the association's destination address list. */
1020 transport_list = &asoc->peer.transport_addr_list;
1022 sack_ctsn = ntohl(sack->cum_tsn_ack);
1025 * SFR-CACC algorithm:
1026 * On receipt of a SACK the sender SHOULD execute the
1027 * following statements.
1029 * 1) If the cumulative ack in the SACK passes next tsn_at_change
1030 * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
1031 * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
1032 * all destinations.
1034 if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
1035 primary->cacc.changeover_active = 0;
1036 list_for_each(pos, transport_list) {
1037 transport = list_entry(pos, struct sctp_transport,
1038 transports);
1039 transport->cacc.cycling_changeover = 0;
1044 * SFR-CACC algorithm:
1045 * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
1046 * is set the receiver of the SACK MUST take the following actions:
1048 * A) Initialize the cacc_saw_newack to 0 for all destination
1049 * addresses.
1051 if (sack->num_gap_ack_blocks > 0 &&
1052 primary->cacc.changeover_active) {
1053 list_for_each(pos, transport_list) {
1054 transport = list_entry(pos, struct sctp_transport,
1055 transports);
1056 transport->cacc.cacc_saw_newack = 0;
1060 /* Get the highest TSN in the sack. */
1061 highest_tsn = sack_ctsn +
1062 ntohs(frags[ntohs(sack->num_gap_ack_blocks) - 1].gab.end);
1064 if (TSN_lt(asoc->highest_sacked, highest_tsn)) {
1065 highest_new_tsn = highest_tsn;
1066 asoc->highest_sacked = highest_tsn;
1067 } else {
1068 highest_new_tsn = sctp_highest_new_tsn(sack, asoc);
1071 /* Run through the retransmit queue. Credit bytes received
1072 * and free those chunks that we can.
1074 sctp_check_transmitted(q, &q->retransmit, NULL, sack, highest_new_tsn);
1075 sctp_mark_missing(q, &q->retransmit, NULL, highest_new_tsn, 0);
1077 /* Run through the transmitted queue.
1078 * Credit bytes received and free those chunks which we can.
1080 * This is a MASSIVE candidate for optimization.
1082 list_for_each(pos, transport_list) {
1083 transport = list_entry(pos, struct sctp_transport,
1084 transports);
1085 sctp_check_transmitted(q, &transport->transmitted,
1086 transport, sack, highest_new_tsn);
1088 * SFR-CACC algorithm:
1089 * C) Let count_of_newacks be the number of
1090 * destinations for which cacc_saw_newack is set.
1092 if (transport->cacc.cacc_saw_newack)
1093 count_of_newacks ++;
1096 list_for_each(pos, transport_list) {
1097 transport = list_entry(pos, struct sctp_transport,
1098 transports);
1099 sctp_mark_missing(q, &transport->transmitted, transport,
1100 highest_new_tsn, count_of_newacks);
1103 /* Move the Cumulative TSN Ack Point if appropriate. */
1104 if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn))
1105 asoc->ctsn_ack_point = sack_ctsn;
1107 /* Update unack_data field in the assoc. */
1108 sctp_sack_update_unack_data(asoc, sack);
1110 ctsn = asoc->ctsn_ack_point;
1112 SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
1113 __FUNCTION__, sack_ctsn);
1114 SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association "
1115 "%p is 0x%x.\n", __FUNCTION__, asoc, ctsn);
1117 /* Throw away stuff rotting on the sack queue. */
1118 list_for_each(lchunk, &q->sacked) {
1119 tchunk = list_entry(lchunk, struct sctp_chunk,
1120 transmitted_list);
1121 tsn = ntohl(tchunk->subh.data_hdr->tsn);
1122 if (TSN_lte(tsn, ctsn)) {
1123 lchunk = lchunk->prev;
1124 sctp_chunk_free(tchunk);
1128 /* ii) Set rwnd equal to the newly received a_rwnd minus the
1129 * number of bytes still outstanding after processing the
1130 * Cumulative TSN Ack and the Gap Ack Blocks.
1133 sack_a_rwnd = ntohl(sack->a_rwnd);
1134 outstanding = q->outstanding_bytes;
1136 if (outstanding < sack_a_rwnd)
1137 sack_a_rwnd -= outstanding;
1138 else
1139 sack_a_rwnd = 0;
1141 asoc->peer.rwnd = sack_a_rwnd;
1143 /* See if all chunks are acked.
1144 * Make sure the empty queue handler will get run later.
1146 q->empty = skb_queue_empty(&q->out) && list_empty(&q->retransmit);
1147 if (!q->empty)
1148 goto finish;
1150 list_for_each(pos, transport_list) {
1151 transport = list_entry(pos, struct sctp_transport,
1152 transports);
1153 q->empty = q->empty && list_empty(&transport->transmitted);
1154 if (!q->empty)
1155 goto finish;
1158 SCTP_DEBUG_PRINTK("sack queue is empty.\n");
1159 finish:
1160 return q->empty;
1163 /* Is the outqueue empty? */
1164 int sctp_outq_is_empty(const struct sctp_outq *q)
1166 return q->empty;
1169 /********************************************************************
1170 * 2nd Level Abstractions
1171 ********************************************************************/
1173 /* Go through a transport's transmitted list or the association's retransmit
1174 * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
1175 * The retransmit list will not have an associated transport.
1177 * I added coherent debug information output. --xguo
1179 * Instead of printing 'sacked' or 'kept' for each TSN on the
1180 * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
1181 * KEPT TSN6-TSN7, etc.
1183 static void sctp_check_transmitted(struct sctp_outq *q,
1184 struct list_head *transmitted_queue,
1185 struct sctp_transport *transport,
1186 struct sctp_sackhdr *sack,
1187 __u32 highest_new_tsn_in_sack)
1189 struct list_head *lchunk;
1190 struct sctp_chunk *tchunk;
1191 struct list_head tlist;
1192 __u32 tsn;
1193 __u32 sack_ctsn;
1194 __u32 rtt;
1195 __u8 restart_timer = 0;
1196 int bytes_acked = 0;
1198 /* These state variables are for coherent debug output. --xguo */
1200 #if SCTP_DEBUG
1201 __u32 dbg_ack_tsn = 0; /* An ACKed TSN range starts here... */
1202 __u32 dbg_last_ack_tsn = 0; /* ...and finishes here. */
1203 __u32 dbg_kept_tsn = 0; /* An un-ACKed range starts here... */
1204 __u32 dbg_last_kept_tsn = 0; /* ...and finishes here. */
1206 /* 0 : The last TSN was ACKed.
1207 * 1 : The last TSN was NOT ACKed (i.e. KEPT).
1208 * -1: We need to initialize.
1210 int dbg_prt_state = -1;
1211 #endif /* SCTP_DEBUG */
1213 sack_ctsn = ntohl(sack->cum_tsn_ack);
1215 INIT_LIST_HEAD(&tlist);
1217 /* The while loop will skip empty transmitted queues. */
1218 while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
1219 tchunk = list_entry(lchunk, struct sctp_chunk,
1220 transmitted_list);
1222 tsn = ntohl(tchunk->subh.data_hdr->tsn);
1223 if (sctp_acked(sack, tsn)) {
1224 /* If this queue is the retransmit queue, the
1225 * retransmit timer has already reclaimed
1226 * the outstanding bytes for this chunk, so only
1227 * count bytes associated with a transport.
1229 if (transport) {
1230 /* If this chunk is being used for RTT
1231 * measurement, calculate the RTT and update
1232 * the RTO using this value.
1234 * 6.3.1 C5) Karn's algorithm: RTT measurements
1235 * MUST NOT be made using packets that were
1236 * retransmitted (and thus for which it is
1237 * ambiguous whether the reply was for the
1238 * first instance of the packet or a later
1239 * instance).
1241 if (!tchunk->tsn_gap_acked &&
1242 !tchunk->resent &&
1243 tchunk->rtt_in_progress) {
1244 rtt = jiffies - tchunk->sent_at;
1245 sctp_transport_update_rto(transport,
1246 rtt);
1249 if (TSN_lte(tsn, sack_ctsn)) {
1250 /* RFC 2960 6.3.2 Retransmission Timer Rules
1252 * R3) Whenever a SACK is received
1253 * that acknowledges the DATA chunk
1254 * with the earliest outstanding TSN
1255 * for that address, restart T3-rtx
1256 * timer for that address with its
1257 * current RTO.
1259 restart_timer = 1;
1261 if (!tchunk->tsn_gap_acked) {
1262 tchunk->tsn_gap_acked = 1;
1263 bytes_acked += sctp_data_size(tchunk);
1265 * SFR-CACC algorithm:
1266 * 2) If the SACK contains gap acks
1267 * and the flag CHANGEOVER_ACTIVE is
1268 * set the receiver of the SACK MUST
1269 * take the following action:
1271 * B) For each TSN t being acked that
1272 * has not been acked in any SACK so
1273 * far, set cacc_saw_newack to 1 for
1274 * the destination that the TSN was
1275 * sent to.
1277 if (transport &&
1278 sack->num_gap_ack_blocks &&
1279 q->asoc->peer.primary_path->cacc.
1280 changeover_active)
1281 transport->cacc.cacc_saw_newack
1282 = 1;
1285 list_add_tail(&tchunk->transmitted_list,
1286 &q->sacked);
1287 } else {
1288 /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
1289 * M2) Each time a SACK arrives reporting
1290 * 'Stray DATA chunk(s)' record the highest TSN
1291 * reported as newly acknowledged, call this
1292 * value 'HighestTSNinSack'. A newly
1293 * acknowledged DATA chunk is one not
1294 * previously acknowledged in a SACK.
1296 * When the SCTP sender of data receives a SACK
1297 * chunk that acknowledges, for the first time,
1298 * the receipt of a DATA chunk, all the still
1299 * unacknowledged DATA chunks whose TSN is
1300 * older than that newly acknowledged DATA
1301 * chunk, are qualified as 'Stray DATA chunks'.
1303 if (!tchunk->tsn_gap_acked) {
1304 tchunk->tsn_gap_acked = 1;
1305 bytes_acked += sctp_data_size(tchunk);
1307 list_add_tail(lchunk, &tlist);
1310 #if SCTP_DEBUG
1311 switch (dbg_prt_state) {
1312 case 0: /* last TSN was ACKed */
1313 if (dbg_last_ack_tsn + 1 == tsn) {
1314 /* This TSN belongs to the
1315 * current ACK range.
1317 break;
1320 if (dbg_last_ack_tsn != dbg_ack_tsn) {
1321 /* Display the end of the
1322 * current range.
1324 SCTP_DEBUG_PRINTK("-%08x",
1325 dbg_last_ack_tsn);
1328 /* Start a new range. */
1329 SCTP_DEBUG_PRINTK(",%08x", tsn);
1330 dbg_ack_tsn = tsn;
1331 break;
1333 case 1: /* The last TSN was NOT ACKed. */
1334 if (dbg_last_kept_tsn != dbg_kept_tsn) {
1335 /* Display the end of current range. */
1336 SCTP_DEBUG_PRINTK("-%08x",
1337 dbg_last_kept_tsn);
1340 SCTP_DEBUG_PRINTK("\n");
1342 /* FALL THROUGH... */
1343 default:
1344 /* This is the first-ever TSN we examined. */
1345 /* Start a new range of ACK-ed TSNs. */
1346 SCTP_DEBUG_PRINTK("ACKed: %08x", tsn);
1347 dbg_prt_state = 0;
1348 dbg_ack_tsn = tsn;
1351 dbg_last_ack_tsn = tsn;
1352 #endif /* SCTP_DEBUG */
1354 } else {
1355 if (tchunk->tsn_gap_acked) {
1356 SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
1357 "data TSN: 0x%x\n",
1358 __FUNCTION__,
1359 tsn);
1360 tchunk->tsn_gap_acked = 0;
1362 bytes_acked -= sctp_data_size(tchunk);
1364 /* RFC 2960 6.3.2 Retransmission Timer Rules
1366 * R4) Whenever a SACK is received missing a
1367 * TSN that was previously acknowledged via a
1368 * Gap Ack Block, start T3-rtx for the
1369 * destination address to which the DATA
1370 * chunk was originally
1371 * transmitted if it is not already running.
1373 restart_timer = 1;
1376 list_add_tail(lchunk, &tlist);
1378 #if SCTP_DEBUG
1379 /* See the above comments on ACK-ed TSNs. */
1380 switch (dbg_prt_state) {
1381 case 1:
1382 if (dbg_last_kept_tsn + 1 == tsn)
1383 break;
1385 if (dbg_last_kept_tsn != dbg_kept_tsn)
1386 SCTP_DEBUG_PRINTK("-%08x",
1387 dbg_last_kept_tsn);
1389 SCTP_DEBUG_PRINTK(",%08x", tsn);
1390 dbg_kept_tsn = tsn;
1391 break;
1393 case 0:
1394 if (dbg_last_ack_tsn != dbg_ack_tsn)
1395 SCTP_DEBUG_PRINTK("-%08x",
1396 dbg_last_ack_tsn);
1397 SCTP_DEBUG_PRINTK("\n");
1399 /* FALL THROUGH... */
1400 default:
1401 SCTP_DEBUG_PRINTK("KEPT: %08x",tsn);
1402 dbg_prt_state = 1;
1403 dbg_kept_tsn = tsn;
1406 dbg_last_kept_tsn = tsn;
1407 #endif /* SCTP_DEBUG */
1411 #if SCTP_DEBUG
1412 /* Finish off the last range, displaying its ending TSN. */
1413 switch (dbg_prt_state) {
1414 case 0:
1415 if (dbg_last_ack_tsn != dbg_ack_tsn) {
1416 SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_ack_tsn);
1417 } else {
1418 SCTP_DEBUG_PRINTK("\n");
1420 break;
1422 case 1:
1423 if (dbg_last_kept_tsn != dbg_kept_tsn) {
1424 SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_kept_tsn);
1425 } else {
1426 SCTP_DEBUG_PRINTK("\n");
1429 #endif /* SCTP_DEBUG */
1430 if (transport) {
1431 if (bytes_acked) {
1432 /* 8.2. When an outstanding TSN is acknowledged,
1433 * the endpoint shall clear the error counter of
1434 * the destination transport address to which the
1435 * DATA chunk was last sent.
1436 * The association's overall error counter is
1437 * also cleared.
1439 transport->error_count = 0;
1440 transport->asoc->overall_error_count = 0;
1442 /* Mark the destination transport address as
1443 * active if it is not so marked.
1445 if (!transport->active) {
1446 sctp_assoc_control_transport(
1447 transport->asoc,
1448 transport,
1449 SCTP_TRANSPORT_UP,
1450 SCTP_RECEIVED_SACK);
1453 sctp_transport_raise_cwnd(transport, sack_ctsn,
1454 bytes_acked);
1456 transport->flight_size -= bytes_acked;
1457 q->outstanding_bytes -= bytes_acked;
1458 } else {
1459 /* RFC 2960 6.1, sctpimpguide-06 2.15.2
1460 * When a sender is doing zero window probing, it
1461 * should not timeout the association if it continues
1462 * to receive new packets from the receiver. The
1463 * reason is that the receiver MAY keep its window
1464 * closed for an indefinite time.
1465 * A sender is doing zero window probing when the
1466 * receiver's advertised window is zero, and there is
1467 * only one data chunk in flight to the receiver.
1469 if (!q->asoc->peer.rwnd &&
1470 !list_empty(&tlist) &&
1471 (sack_ctsn+2 == q->asoc->next_tsn)) {
1472 SCTP_DEBUG_PRINTK("%s: SACK received for zero "
1473 "window probe: %u\n",
1474 __FUNCTION__, sack_ctsn);
1475 q->asoc->overall_error_count = 0;
1476 transport->error_count = 0;
1480 /* RFC 2960 6.3.2 Retransmission Timer Rules
1482 * R2) Whenever all outstanding data sent to an address have
1483 * been acknowledged, turn off the T3-rtx timer of that
1484 * address.
1486 if (!transport->flight_size) {
1487 if (timer_pending(&transport->T3_rtx_timer) &&
1488 del_timer(&transport->T3_rtx_timer)) {
1489 sctp_transport_put(transport);
1491 } else if (restart_timer) {
1492 if (!mod_timer(&transport->T3_rtx_timer,
1493 jiffies + transport->rto))
1494 sctp_transport_hold(transport);
1498 list_splice(&tlist, transmitted_queue);
1501 /* Mark chunks as missing and consequently may get retransmitted. */
1502 static void sctp_mark_missing(struct sctp_outq *q,
1503 struct list_head *transmitted_queue,
1504 struct sctp_transport *transport,
1505 __u32 highest_new_tsn_in_sack,
1506 int count_of_newacks)
1508 struct sctp_chunk *chunk;
1509 struct list_head *pos;
1510 __u32 tsn;
1511 char do_fast_retransmit = 0;
1512 struct sctp_transport *primary = q->asoc->peer.primary_path;
1514 list_for_each(pos, transmitted_queue) {
1516 chunk = list_entry(pos, struct sctp_chunk, transmitted_list);
1517 tsn = ntohl(chunk->subh.data_hdr->tsn);
1519 /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
1520 * 'Unacknowledged TSN's', if the TSN number of an
1521 * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
1522 * value, increment the 'TSN.Missing.Report' count on that
1523 * chunk if it has NOT been fast retransmitted or marked for
1524 * fast retransmit already.
1526 if (!chunk->fast_retransmit &&
1527 !chunk->tsn_gap_acked &&
1528 TSN_lt(tsn, highest_new_tsn_in_sack)) {
1530 /* SFR-CACC may require us to skip marking
1531 * this chunk as missing.
1533 if (!transport || !sctp_cacc_skip(primary, transport,
1534 count_of_newacks, tsn)) {
1535 chunk->tsn_missing_report++;
1537 SCTP_DEBUG_PRINTK(
1538 "%s: TSN 0x%x missing counter: %d\n",
1539 __FUNCTION__, tsn,
1540 chunk->tsn_missing_report);
1544 * M4) If any DATA chunk is found to have a
1545 * 'TSN.Missing.Report'
1546 * value larger than or equal to 4, mark that chunk for
1547 * retransmission and start the fast retransmit procedure.
1550 if (chunk->tsn_missing_report >= 4) {
1551 chunk->fast_retransmit = 1;
1552 do_fast_retransmit = 1;
1556 if (transport) {
1557 if (do_fast_retransmit)
1558 sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
1560 SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
1561 "ssthresh: %d, flight_size: %d, pba: %d\n",
1562 __FUNCTION__, transport, transport->cwnd,
1563 transport->ssthresh, transport->flight_size,
1564 transport->partial_bytes_acked);
1568 /* Is the given TSN acked by this packet? */
1569 static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
1571 int i;
1572 sctp_sack_variable_t *frags;
1573 __u16 gap;
1574 __u32 ctsn = ntohl(sack->cum_tsn_ack);
1576 if (TSN_lte(tsn, ctsn))
1577 goto pass;
1579 /* 3.3.4 Selective Acknowledgement (SACK) (3):
1581 * Gap Ack Blocks:
1582 * These fields contain the Gap Ack Blocks. They are repeated
1583 * for each Gap Ack Block up to the number of Gap Ack Blocks
1584 * defined in the Number of Gap Ack Blocks field. All DATA
1585 * chunks with TSNs greater than or equal to (Cumulative TSN
1586 * Ack + Gap Ack Block Start) and less than or equal to
1587 * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
1588 * Block are assumed to have been received correctly.
1591 frags = sack->variable;
1592 gap = tsn - ctsn;
1593 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
1594 if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
1595 TSN_lte(gap, ntohs(frags[i].gab.end)))
1596 goto pass;
1599 return 0;
1600 pass:
1601 return 1;