blob: 072bf6ae3c26da20baa92d07b9c6248b86db95b2 [file] [log] [blame]
Vlad Yasevich60c778b2008-01-11 09:57:09 -05001/* SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * (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.
6 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -05007 * This file is part of the SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * These functions implement the sctp_outq class. The outqueue handles
10 * bundling and queueing of outgoing SCTP chunks.
11 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -050012 * This SCTP implementation is free software;
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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.
17 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -050018 * This SCTP implementation is distributed in the hope that it
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * 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.
23 *
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.
28 *
29 * Please send any bug reports or fixes you make to the
30 * email address(es):
31 * lksctp developers <[email protected]>
32 *
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
35 *
36 * Written or modified by:
37 * La Monte H.P. Yarroll <[email protected]>
38 * Karl Knutson <[email protected]>
39 * Perry Melange <[email protected]>
40 * Xingang Guo <[email protected]>
41 * Hui Huang <[email protected]>
42 * Sridhar Samudrala <[email protected]>
43 * Jon Grimm <[email protected]>
44 *
45 * Any bugs reported given to us we will try to fix... any fixes shared will
46 * be incorporated into the next SCTP release.
47 */
48
Joe Perches145ce502010-08-24 13:21:08 +000049#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/types.h>
52#include <linux/list.h> /* For struct list_head */
53#include <linux/socket.h>
54#include <linux/ip.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090055#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <net/sock.h> /* For skb_set_owner_w */
57
58#include <net/sctp/sctp.h>
59#include <net/sctp/sm.h>
60
61/* Declare internal functions here. */
62static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn);
63static void sctp_check_transmitted(struct sctp_outq *q,
64 struct list_head *transmitted_queue,
65 struct sctp_transport *transport,
66 struct sctp_sackhdr *sack,
Vlad Yasevichbfa0d982010-04-30 22:41:10 -040067 __u32 *highest_new_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69static void sctp_mark_missing(struct sctp_outq *q,
70 struct list_head *transmitted_queue,
71 struct sctp_transport *transport,
72 __u32 highest_new_tsn,
73 int count_of_newacks);
74
75static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
76
Adrian Bunkabd0b1982008-07-22 14:20:45 -070077static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout);
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079/* Add data to the front of the queue. */
80static inline void sctp_outq_head_data(struct sctp_outq *q,
81 struct sctp_chunk *ch)
82{
David S. Miller79af02c2005-07-08 21:47:49 -070083 list_add(&ch->list, &q->out_chunk_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 q->out_qlen += ch->skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
87/* Take data from the front of the queue. */
88static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q)
89{
David S. Miller79af02c2005-07-08 21:47:49 -070090 struct sctp_chunk *ch = NULL;
91
92 if (!list_empty(&q->out_chunk_list)) {
93 struct list_head *entry = q->out_chunk_list.next;
94
95 ch = list_entry(entry, struct sctp_chunk, list);
96 list_del_init(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 q->out_qlen -= ch->skb->len;
David S. Miller79af02c2005-07-08 21:47:49 -070098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return ch;
100}
101/* Add data chunk to the end of the queue. */
102static inline void sctp_outq_tail_data(struct sctp_outq *q,
103 struct sctp_chunk *ch)
104{
David S. Miller79af02c2005-07-08 21:47:49 -0700105 list_add_tail(&ch->list, &q->out_chunk_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 q->out_qlen += ch->skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
109/*
110 * SFR-CACC algorithm:
111 * D) If count_of_newacks is greater than or equal to 2
112 * and t was not sent to the current primary then the
113 * sender MUST NOT increment missing report count for t.
114 */
115static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary,
116 struct sctp_transport *transport,
117 int count_of_newacks)
118{
119 if (count_of_newacks >=2 && transport != primary)
120 return 1;
121 return 0;
122}
123
124/*
125 * SFR-CACC algorithm:
126 * F) If count_of_newacks is less than 2, let d be the
127 * destination to which t was sent. If cacc_saw_newack
128 * is 0 for destination d, then the sender MUST NOT
129 * increment missing report count for t.
130 */
131static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport,
132 int count_of_newacks)
133{
Vlad Yasevichf246a7b2011-04-18 19:13:56 +0000134 if (count_of_newacks < 2 &&
135 (transport && !transport->cacc.cacc_saw_newack))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return 1;
137 return 0;
138}
139
140/*
141 * SFR-CACC algorithm:
142 * 3.1) If CYCLING_CHANGEOVER is 0, the sender SHOULD
143 * execute steps C, D, F.
144 *
145 * C has been implemented in sctp_outq_sack
146 */
147static inline int sctp_cacc_skip_3_1(struct sctp_transport *primary,
148 struct sctp_transport *transport,
149 int count_of_newacks)
150{
151 if (!primary->cacc.cycling_changeover) {
152 if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks))
153 return 1;
154 if (sctp_cacc_skip_3_1_f(transport, count_of_newacks))
155 return 1;
156 return 0;
157 }
158 return 0;
159}
160
161/*
162 * SFR-CACC algorithm:
163 * 3.2) Else if CYCLING_CHANGEOVER is 1, and t is less
164 * than next_tsn_at_change of the current primary, then
165 * the sender MUST NOT increment missing report count
166 * for t.
167 */
168static inline int sctp_cacc_skip_3_2(struct sctp_transport *primary, __u32 tsn)
169{
170 if (primary->cacc.cycling_changeover &&
171 TSN_lt(tsn, primary->cacc.next_tsn_at_change))
172 return 1;
173 return 0;
174}
175
176/*
177 * SFR-CACC algorithm:
178 * 3) If the missing report count for TSN t is to be
179 * incremented according to [RFC2960] and
180 * [SCTP_STEWART-2002], and CHANGEOVER_ACTIVE is set,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300181 * then the sender MUST further execute steps 3.1 and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 * 3.2 to determine if the missing report count for
183 * TSN t SHOULD NOT be incremented.
184 *
185 * 3.3) If 3.1 and 3.2 do not dictate that the missing
186 * report count for t should not be incremented, then
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300187 * the sender SHOULD increment missing report count for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 * t (according to [RFC2960] and [SCTP_STEWART_2002]).
189 */
190static inline int sctp_cacc_skip(struct sctp_transport *primary,
191 struct sctp_transport *transport,
192 int count_of_newacks,
193 __u32 tsn)
194{
195 if (primary->cacc.changeover_active &&
Joe Perchesf64f9e72009-11-29 16:55:45 -0800196 (sctp_cacc_skip_3_1(primary, transport, count_of_newacks) ||
197 sctp_cacc_skip_3_2(primary, tsn)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 return 1;
199 return 0;
200}
201
202/* Initialize an existing sctp_outq. This does the boring stuff.
203 * You still need to define handlers if you really want to DO
204 * something with this structure...
205 */
206void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
207{
208 q->asoc = asoc;
David S. Miller79af02c2005-07-08 21:47:49 -0700209 INIT_LIST_HEAD(&q->out_chunk_list);
210 INIT_LIST_HEAD(&q->control_chunk_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 INIT_LIST_HEAD(&q->retransmit);
212 INIT_LIST_HEAD(&q->sacked);
213 INIT_LIST_HEAD(&q->abandoned);
214
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700215 q->fast_rtx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 q->outstanding_bytes = 0;
217 q->empty = 1;
218 q->cork = 0;
219
220 q->malloced = 0;
221 q->out_qlen = 0;
222}
223
224/* Free the outqueue structure and any related pending chunks.
225 */
226void sctp_outq_teardown(struct sctp_outq *q)
227{
228 struct sctp_transport *transport;
Robert P. J. Day9dbc15f02008-04-12 18:54:24 -0700229 struct list_head *lchunk, *temp;
David S. Miller79af02c2005-07-08 21:47:49 -0700230 struct sctp_chunk *chunk, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 /* Throw away unacknowledged chunks. */
Robert P. J. Day9dbc15f02008-04-12 18:54:24 -0700233 list_for_each_entry(transport, &q->asoc->peer.transport_addr_list,
234 transports) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 while ((lchunk = sctp_list_dequeue(&transport->transmitted)) != NULL) {
236 chunk = list_entry(lchunk, struct sctp_chunk,
237 transmitted_list);
238 /* Mark as part of a failed message. */
239 sctp_chunk_fail(chunk, q->error);
240 sctp_chunk_free(chunk);
241 }
242 }
243
244 /* Throw away chunks that have been gap ACKed. */
245 list_for_each_safe(lchunk, temp, &q->sacked) {
246 list_del_init(lchunk);
247 chunk = list_entry(lchunk, struct sctp_chunk,
248 transmitted_list);
249 sctp_chunk_fail(chunk, q->error);
250 sctp_chunk_free(chunk);
251 }
252
253 /* Throw away any chunks in the retransmit queue. */
254 list_for_each_safe(lchunk, temp, &q->retransmit) {
255 list_del_init(lchunk);
256 chunk = list_entry(lchunk, struct sctp_chunk,
257 transmitted_list);
258 sctp_chunk_fail(chunk, q->error);
259 sctp_chunk_free(chunk);
260 }
261
262 /* Throw away any chunks that are in the abandoned queue. */
263 list_for_each_safe(lchunk, temp, &q->abandoned) {
264 list_del_init(lchunk);
265 chunk = list_entry(lchunk, struct sctp_chunk,
266 transmitted_list);
267 sctp_chunk_fail(chunk, q->error);
268 sctp_chunk_free(chunk);
269 }
270
271 /* Throw away any leftover data chunks. */
272 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
273
274 /* Mark as send failure. */
275 sctp_chunk_fail(chunk, q->error);
276 sctp_chunk_free(chunk);
277 }
278
279 q->error = 0;
280
281 /* Throw away any leftover control chunks. */
David S. Miller79af02c2005-07-08 21:47:49 -0700282 list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) {
283 list_del_init(&chunk->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 sctp_chunk_free(chunk);
David S. Miller79af02c2005-07-08 21:47:49 -0700285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
288/* Free the outqueue structure and any related pending chunks. */
289void sctp_outq_free(struct sctp_outq *q)
290{
291 /* Throw away leftover chunks. */
292 sctp_outq_teardown(q);
293
294 /* If we were kmalloc()'d, free the memory. */
295 if (q->malloced)
296 kfree(q);
297}
298
299/* Put a new chunk in an sctp_outq. */
300int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
301{
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000302 struct net *net = sock_net(q->asoc->base.sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 int error = 0;
304
305 SCTP_DEBUG_PRINTK("sctp_outq_tail(%p, %p[%s])\n",
306 q, chunk, chunk && chunk->chunk_hdr ?
307 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
308 : "Illegal Chunk");
309
310 /* If it is data, queue it up, otherwise, send it
311 * immediately.
312 */
Shan Weiec7b9512010-04-30 22:41:09 -0400313 if (sctp_chunk_is_data(chunk)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 /* Is it OK to queue data chunks? */
315 /* From 9. Termination of Association
316 *
317 * When either endpoint performs a shutdown, the
318 * association on each peer will stop accepting new
319 * data from its user and only deliver data in queue
320 * at the time of sending or receiving the SHUTDOWN
321 * chunk.
322 */
323 switch (q->asoc->state) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 case SCTP_STATE_CLOSED:
325 case SCTP_STATE_SHUTDOWN_PENDING:
326 case SCTP_STATE_SHUTDOWN_SENT:
327 case SCTP_STATE_SHUTDOWN_RECEIVED:
328 case SCTP_STATE_SHUTDOWN_ACK_SENT:
329 /* Cannot send after transport endpoint shutdown */
330 error = -ESHUTDOWN;
331 break;
332
333 default:
334 SCTP_DEBUG_PRINTK("outqueueing (%p, %p[%s])\n",
335 q, chunk, chunk && chunk->chunk_hdr ?
336 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
337 : "Illegal Chunk");
338
339 sctp_outq_tail_data(q, chunk);
340 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000341 SCTP_INC_STATS(net, SCTP_MIB_OUTUNORDERCHUNKS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 else
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000343 SCTP_INC_STATS(net, SCTP_MIB_OUTORDERCHUNKS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 q->empty = 0;
345 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 } else {
David S. Miller79af02c2005-07-08 21:47:49 -0700348 list_add_tail(&chunk->list, &q->control_chunk_list);
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000349 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
352 if (error < 0)
353 return error;
354
355 if (!q->cork)
356 error = sctp_outq_flush(q, 0);
357
358 return error;
359}
360
361/* Insert a chunk into the sorted list based on the TSNs. The retransmit list
362 * and the abandoned list are in ascending order.
363 */
364static void sctp_insert_list(struct list_head *head, struct list_head *new)
365{
366 struct list_head *pos;
367 struct sctp_chunk *nchunk, *lchunk;
368 __u32 ntsn, ltsn;
369 int done = 0;
370
371 nchunk = list_entry(new, struct sctp_chunk, transmitted_list);
372 ntsn = ntohl(nchunk->subh.data_hdr->tsn);
373
374 list_for_each(pos, head) {
375 lchunk = list_entry(pos, struct sctp_chunk, transmitted_list);
376 ltsn = ntohl(lchunk->subh.data_hdr->tsn);
377 if (TSN_lt(ntsn, ltsn)) {
378 list_add(new, pos->prev);
379 done = 1;
380 break;
381 }
382 }
383 if (!done)
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900384 list_add_tail(new, head);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
387/* Mark all the eligible packets on a transport for retransmission. */
388void sctp_retransmit_mark(struct sctp_outq *q,
389 struct sctp_transport *transport,
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400390 __u8 reason)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
392 struct list_head *lchunk, *ltemp;
393 struct sctp_chunk *chunk;
394
395 /* Walk through the specified transmitted queue. */
396 list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
397 chunk = list_entry(lchunk, struct sctp_chunk,
398 transmitted_list);
399
400 /* If the chunk is abandoned, move it to abandoned list. */
401 if (sctp_chunk_abandoned(chunk)) {
402 list_del_init(lchunk);
403 sctp_insert_list(&q->abandoned, lchunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -0800404
405 /* If this chunk has not been previousely acked,
406 * stop considering it 'outstanding'. Our peer
407 * will most likely never see it since it will
408 * not be retransmitted
409 */
410 if (!chunk->tsn_gap_acked) {
Vlad Yasevich31b02e12009-09-04 18:21:00 -0400411 if (chunk->transport)
412 chunk->transport->flight_size -=
413 sctp_data_size(chunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -0800414 q->outstanding_bytes -= sctp_data_size(chunk);
Thomas Grafa76c0ad2011-12-19 04:11:40 +0000415 q->asoc->peer.rwnd += sctp_data_size(chunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -0800416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 continue;
418 }
419
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400420 /* If we are doing retransmission due to a timeout or pmtu
421 * discovery, only the chunks that are not yet acked should
422 * be added to the retransmit queue.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 */
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400424 if ((reason == SCTP_RTXR_FAST_RTX &&
Neil Hormanc226ef92008-07-25 12:44:09 -0400425 (chunk->fast_retransmit == SCTP_NEED_FRTX)) ||
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400426 (reason != SCTP_RTXR_FAST_RTX && !chunk->tsn_gap_acked)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 /* RFC 2960 6.2.1 Processing a Received SACK
428 *
429 * C) Any time a DATA chunk is marked for
430 * retransmission (via either T3-rtx timer expiration
431 * (Section 6.3.3) or via fast retransmit
432 * (Section 7.2.4)), add the data size of those
433 * chunks to the rwnd.
434 */
Thomas Grafa76c0ad2011-12-19 04:11:40 +0000435 q->asoc->peer.rwnd += sctp_data_size(chunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 q->outstanding_bytes -= sctp_data_size(chunk);
Vlad Yasevich31b02e12009-09-04 18:21:00 -0400437 if (chunk->transport)
438 transport->flight_size -= sctp_data_size(chunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 /* sctpimpguide-05 Section 2.8.2
441 * M5) If a T3-rtx timer expires, the
442 * 'TSN.Missing.Report' of all affected TSNs is set
443 * to 0.
444 */
445 chunk->tsn_missing_report = 0;
446
447 /* If a chunk that is being used for RTT measurement
448 * has to be retransmitted, we cannot use this chunk
449 * anymore for RTT measurements. Reset rto_pending so
450 * that a new RTT measurement is started when a new
451 * data chunk is sent.
452 */
453 if (chunk->rtt_in_progress) {
454 chunk->rtt_in_progress = 0;
455 transport->rto_pending = 0;
456 }
457
458 /* Move the chunk to the retransmit queue. The chunks
459 * on the retransmit queue are always kept in order.
460 */
461 list_del_init(lchunk);
462 sctp_insert_list(&q->retransmit, lchunk);
463 }
464 }
465
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400466 SCTP_DEBUG_PRINTK("%s: transport: %p, reason: %d, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 "cwnd: %d, ssthresh: %d, flight_size: %d, "
Harvey Harrison0dc47872008-03-05 20:47:47 -0800468 "pba: %d\n", __func__,
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400469 transport, reason,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 transport->cwnd, transport->ssthresh,
471 transport->flight_size,
472 transport->partial_bytes_acked);
473
474}
475
476/* Mark all the eligible packets on a transport for retransmission and force
477 * one packet out.
478 */
479void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
480 sctp_retransmit_reason_t reason)
481{
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000482 struct net *net = sock_net(q->asoc->base.sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 switch(reason) {
486 case SCTP_RTXR_T3_RTX:
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000487 SCTP_INC_STATS(net, SCTP_MIB_T3_RETRANSMITS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
489 /* Update the retran path if the T3-rtx timer has expired for
490 * the current retran path.
491 */
492 if (transport == transport->asoc->peer.retran_path)
493 sctp_assoc_update_retran_path(transport->asoc);
Neil Horman58fbbed2008-02-29 11:40:56 -0800494 transport->asoc->rtx_data_chunks +=
495 transport->asoc->unack_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 break;
497 case SCTP_RTXR_FAST_RTX:
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000498 SCTP_INC_STATS(net, SCTP_MIB_FAST_RETRANSMITS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700500 q->fast_rtx = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 break;
502 case SCTP_RTXR_PMTUD:
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000503 SCTP_INC_STATS(net, SCTP_MIB_PMTUD_RETRANSMITS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 break;
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400505 case SCTP_RTXR_T1_RTX:
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000506 SCTP_INC_STATS(net, SCTP_MIB_T1_RETRANSMITS);
Neil Horman58fbbed2008-02-29 11:40:56 -0800507 transport->asoc->init_retries++;
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400508 break;
Sridhar Samudralaac0b0462006-08-22 00:15:33 -0700509 default:
510 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400513 sctp_retransmit_mark(q, transport, reason);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 /* PR-SCTP A5) Any time the T3-rtx timer expires, on any destination,
516 * the sender SHOULD try to advance the "Advanced.Peer.Ack.Point" by
517 * following the procedures outlined in C1 - C5.
518 */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700519 if (reason == SCTP_RTXR_T3_RTX)
520 sctp_generate_fwdtsn(q, q->asoc->ctsn_ack_point);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700522 /* Flush the queues only on timeout, since fast_rtx is only
523 * triggered during sack processing and the queue
524 * will be flushed at the end.
525 */
526 if (reason != SCTP_RTXR_FAST_RTX)
527 error = sctp_outq_flush(q, /* rtx_timeout */ 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 if (error)
530 q->asoc->base.sk->sk_err = -error;
531}
532
533/*
534 * Transmit DATA chunks on the retransmit queue. Upon return from
535 * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
536 * need to be transmitted by the caller.
537 * We assume that pkt->transport has already been set.
538 *
539 * The return value is a normal kernel error return value.
540 */
541static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
542 int rtx_timeout, int *start_timer)
543{
544 struct list_head *lqueue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 struct sctp_transport *transport = pkt->transport;
546 sctp_xmit_t status;
547 struct sctp_chunk *chunk, *chunk1;
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700548 int fast_rtx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 int error = 0;
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700550 int timer = 0;
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700551 int done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 lqueue = &q->retransmit;
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700554 fast_rtx = q->fast_rtx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700556 /* This loop handles time-out retransmissions, fast retransmissions,
557 * and retransmissions due to opening of whindow.
558 *
559 * RFC 2960 6.3.3 Handle T3-rtx Expiration
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 *
561 * E3) Determine how many of the earliest (i.e., lowest TSN)
562 * outstanding DATA chunks for the address for which the
563 * T3-rtx has expired will fit into a single packet, subject
564 * to the MTU constraint for the path corresponding to the
565 * destination transport address to which the retransmission
566 * is being sent (this may be different from the address for
567 * which the timer expires [see Section 6.4]). Call this value
568 * K. Bundle and retransmit those K DATA chunks in a single
569 * packet to the destination endpoint.
570 *
571 * [Just to be painfully clear, if we are retransmitting
572 * because a timeout just happened, we should send only ONE
573 * packet of retransmitted data.]
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700574 *
575 * For fast retransmissions we also send only ONE packet. However,
576 * if we are just flushing the queue due to open window, we'll
577 * try to send as much as possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700579 list_for_each_entry_safe(chunk, chunk1, lqueue, transmitted_list) {
Wei Yongjun4c6a6f422011-04-19 21:32:28 +0000580 /* If the chunk is abandoned, move it to abandoned list. */
581 if (sctp_chunk_abandoned(chunk)) {
582 list_del_init(&chunk->transmitted_list);
583 sctp_insert_list(&q->abandoned,
584 &chunk->transmitted_list);
585 continue;
586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 /* Make sure that Gap Acked TSNs are not retransmitted. A
589 * simple approach is just to move such TSNs out of the
590 * way and into a 'transmitted' queue and skip to the
591 * next chunk.
592 */
593 if (chunk->tsn_gap_acked) {
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700594 list_del(&chunk->transmitted_list);
595 list_add_tail(&chunk->transmitted_list,
596 &transport->transmitted);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 continue;
598 }
599
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700600 /* If we are doing fast retransmit, ignore non-fast_rtransmit
601 * chunks
602 */
603 if (fast_rtx && !chunk->fast_retransmit)
604 continue;
605
Wei Yongjunbc4f8412010-04-30 22:38:53 -0400606redo:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 /* Attempt to append this chunk to the packet. */
608 status = sctp_packet_append_chunk(pkt, chunk);
609
610 switch (status) {
611 case SCTP_XMIT_PMTU_FULL:
Wei Yongjunbc4f8412010-04-30 22:38:53 -0400612 if (!pkt->has_data && !pkt->has_cookie_echo) {
613 /* If this packet did not contain DATA then
614 * retransmission did not happen, so do it
615 * again. We'll ignore the error here since
616 * control chunks are already freed so there
617 * is nothing we can do.
618 */
619 sctp_packet_transmit(pkt);
620 goto redo;
621 }
622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 /* Send this packet. */
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700624 error = sctp_packet_transmit(pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626 /* If we are retransmitting, we should only
627 * send a single packet.
Vlad Yasevichf246a7b2011-04-18 19:13:56 +0000628 * Otherwise, try appending this chunk again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700630 if (rtx_timeout || fast_rtx)
631 done = 1;
Vlad Yasevichf246a7b2011-04-18 19:13:56 +0000632 else
633 goto redo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700635 /* Bundle next chunk in the next round. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 break;
637
638 case SCTP_XMIT_RWND_FULL:
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900639 /* Send this packet. */
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700640 error = sctp_packet_transmit(pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 /* Stop sending DATA as there is no more room
643 * at the receiver.
644 */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700645 done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 break;
647
648 case SCTP_XMIT_NAGLE_DELAY:
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900649 /* Send this packet. */
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700650 error = sctp_packet_transmit(pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652 /* Stop sending DATA because of nagle delay. */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700653 done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 break;
655
656 default:
657 /* The append was successful, so add this chunk to
658 * the transmitted list.
659 */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700660 list_del(&chunk->transmitted_list);
661 list_add_tail(&chunk->transmitted_list,
662 &transport->transmitted);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900664 /* Mark the chunk as ineligible for fast retransmit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 * after it is retransmitted.
666 */
Neil Hormanc226ef92008-07-25 12:44:09 -0400667 if (chunk->fast_retransmit == SCTP_NEED_FRTX)
668 chunk->fast_retransmit = SCTP_DONT_FRTX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 q->empty = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700674 /* Set the timer if there were no errors */
675 if (!error && !timer)
676 timer = 1;
677
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700678 if (done)
679 break;
680 }
681
682 /* If we are here due to a retransmit timeout or a fast
683 * retransmit and if there are any chunks left in the retransmit
684 * queue that could not fit in the PMTU sized packet, they need
685 * to be marked as ineligible for a subsequent fast retransmit.
686 */
687 if (rtx_timeout || fast_rtx) {
688 list_for_each_entry(chunk1, lqueue, transmitted_list) {
Neil Hormanc226ef92008-07-25 12:44:09 -0400689 if (chunk1->fast_retransmit == SCTP_NEED_FRTX)
690 chunk1->fast_retransmit = SCTP_DONT_FRTX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 }
692 }
693
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700694 *start_timer = timer;
695
696 /* Clear fast retransmit hint */
697 if (fast_rtx)
698 q->fast_rtx = 0;
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 return error;
701}
702
703/* Cork the outqueue so queued chunks are really queued. */
704int sctp_outq_uncork(struct sctp_outq *q)
705{
706 int error = 0;
Vlad Yasevich7d54dc62007-11-09 11:43:41 -0500707 if (q->cork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 q->cork = 0;
Vlad Yasevich7d54dc62007-11-09 11:43:41 -0500709 error = sctp_outq_flush(q, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 return error;
711}
712
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714/*
715 * Try to flush an outqueue.
716 *
717 * Description: Send everything in q which we legally can, subject to
718 * congestion limitations.
719 * * Note: This function can be called from multiple contexts so appropriate
720 * locking concerns must be made. Today we use the sock lock to protect
721 * this function.
722 */
Adrian Bunkabd0b1982008-07-22 14:20:45 -0700723static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
725 struct sctp_packet *packet;
726 struct sctp_packet singleton;
727 struct sctp_association *asoc = q->asoc;
728 __u16 sport = asoc->base.bind_addr.port;
729 __u16 dport = asoc->peer.port;
730 __u32 vtag = asoc->peer.i.init_tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 struct sctp_transport *transport = NULL;
732 struct sctp_transport *new_transport;
David S. Miller79af02c2005-07-08 21:47:49 -0700733 struct sctp_chunk *chunk, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 sctp_xmit_t status;
735 int error = 0;
736 int start_timer = 0;
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700737 int one_packet = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 /* These transports have chunks to send. */
740 struct list_head transport_list;
741 struct list_head *ltransport;
742
743 INIT_LIST_HEAD(&transport_list);
744 packet = NULL;
745
746 /*
747 * 6.10 Bundling
748 * ...
749 * When bundling control chunks with DATA chunks, an
750 * endpoint MUST place control chunks first in the outbound
751 * SCTP packet. The transmitter MUST transmit DATA chunks
752 * within a SCTP packet in increasing order of TSN.
753 * ...
754 */
755
David S. Miller79af02c2005-07-08 21:47:49 -0700756 list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) {
Michio Honda8a07eb02011-04-26 20:19:36 +0900757 /* RFC 5061, 5.3
758 * F1) This means that until such time as the ASCONF
759 * containing the add is acknowledged, the sender MUST
760 * NOT use the new IP address as a source for ANY SCTP
761 * packet except on carrying an ASCONF Chunk.
762 */
763 if (asoc->src_out_of_asoc_ok &&
764 chunk->chunk_hdr->type != SCTP_CID_ASCONF)
765 continue;
766
David S. Miller79af02c2005-07-08 21:47:49 -0700767 list_del_init(&chunk->list);
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 /* Pick the right transport to use. */
770 new_transport = chunk->transport;
771
772 if (!new_transport) {
Vlad Yasevicha08de642007-12-20 14:11:47 -0800773 /*
774 * If we have a prior transport pointer, see if
775 * the destination address of the chunk
776 * matches the destination address of the
777 * current transport. If not a match, then
778 * try to look up the transport with a given
779 * destination address. We do this because
780 * after processing ASCONFs, we may have new
781 * transports created.
782 */
783 if (transport &&
784 sctp_cmp_addr_exact(&chunk->dest,
785 &transport->ipaddr))
786 new_transport = transport;
787 else
788 new_transport = sctp_assoc_lookup_paddr(asoc,
789 &chunk->dest);
790
791 /* if we still don't have a new transport, then
792 * use the current active path.
793 */
794 if (!new_transport)
795 new_transport = asoc->peer.active_path;
Sridhar Samudralaad8fec12006-07-21 14:48:50 -0700796 } else if ((new_transport->state == SCTP_INACTIVE) ||
Neil Horman5aa93bc2012-07-21 07:56:07 +0000797 (new_transport->state == SCTP_UNCONFIRMED) ||
798 (new_transport->state == SCTP_PF)) {
Frank Filz3f7a87d2005-06-20 13:14:57 -0700799 /* If the chunk is Heartbeat or Heartbeat Ack,
800 * send it to chunk->transport, even if it's
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 * inactive.
802 *
803 * 3.3.6 Heartbeat Acknowledgement:
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900804 * ...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 * A HEARTBEAT ACK is always sent to the source IP
806 * address of the IP datagram containing the
807 * HEARTBEAT chunk to which this ack is responding.
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900808 * ...
Vlad Yasevicha08de642007-12-20 14:11:47 -0800809 *
810 * ASCONF_ACKs also must be sent to the source.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 */
812 if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT &&
Vlad Yasevicha08de642007-12-20 14:11:47 -0800813 chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT_ACK &&
814 chunk->chunk_hdr->type != SCTP_CID_ASCONF_ACK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 new_transport = asoc->peer.active_path;
816 }
817
818 /* Are we switching transports?
819 * Take care of transport locks.
820 */
821 if (new_transport != transport) {
822 transport = new_transport;
823 if (list_empty(&transport->send_ready)) {
824 list_add_tail(&transport->send_ready,
825 &transport_list);
826 }
827 packet = &transport->packet;
828 sctp_packet_config(packet, vtag,
829 asoc->peer.ecn_capable);
830 }
831
832 switch (chunk->chunk_hdr->type) {
833 /*
834 * 6.10 Bundling
835 * ...
836 * An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
837 * COMPLETE with any other chunks. [Send them immediately.]
838 */
839 case SCTP_CID_INIT:
840 case SCTP_CID_INIT_ACK:
841 case SCTP_CID_SHUTDOWN_COMPLETE:
842 sctp_packet_init(&singleton, transport, sport, dport);
843 sctp_packet_config(&singleton, vtag, 0);
844 sctp_packet_append_chunk(&singleton, chunk);
845 error = sctp_packet_transmit(&singleton);
846 if (error < 0)
847 return error;
848 break;
849
850 case SCTP_CID_ABORT:
Gui Jianfengf4ad85c2008-04-12 18:39:34 -0700851 if (sctp_test_T_bit(chunk)) {
852 packet->vtag = asoc->c.my_vtag;
853 }
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700854 /* The following chunks are "response" chunks, i.e.
855 * they are generated in response to something we
856 * received. If we are sending these, then we can
857 * send only 1 packet containing these chunks.
858 */
859 case SCTP_CID_HEARTBEAT_ACK:
860 case SCTP_CID_SHUTDOWN_ACK:
861 case SCTP_CID_COOKIE_ACK:
862 case SCTP_CID_COOKIE_ECHO:
863 case SCTP_CID_ERROR:
864 case SCTP_CID_ECN_CWR:
865 case SCTP_CID_ASCONF_ACK:
866 one_packet = 1;
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300867 /* Fall through */
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 case SCTP_CID_SACK:
870 case SCTP_CID_HEARTBEAT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 case SCTP_CID_SHUTDOWN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 case SCTP_CID_ECN_ECNE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 case SCTP_CID_ASCONF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 case SCTP_CID_FWD_TSN:
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700875 status = sctp_packet_transmit_chunk(packet, chunk,
876 one_packet);
877 if (status != SCTP_XMIT_OK) {
878 /* put the chunk back */
879 list_add(&chunk->list, &q->control_chunk_list);
Wei Yongjunbd69b982010-04-30 21:42:43 -0400880 } else if (chunk->chunk_hdr->type == SCTP_CID_FWD_TSN) {
881 /* PR-SCTP C5) If a FORWARD TSN is sent, the
882 * sender MUST assure that at least one T3-rtx
883 * timer is running.
884 */
Vlad Yasevichd9efc222010-04-30 22:41:09 -0400885 sctp_transport_reset_timers(transport);
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 break;
888
889 default:
890 /* We built a chunk with an illegal type! */
891 BUG();
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700892 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 }
894
Michio Honda8a07eb02011-04-26 20:19:36 +0900895 if (q->asoc->src_out_of_asoc_ok)
896 goto sctp_flush_out;
897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 /* Is it OK to send data chunks? */
899 switch (asoc->state) {
900 case SCTP_STATE_COOKIE_ECHOED:
901 /* Only allow bundling when this packet has a COOKIE-ECHO
902 * chunk.
903 */
904 if (!packet || !packet->has_cookie_echo)
905 break;
906
907 /* fallthru */
908 case SCTP_STATE_ESTABLISHED:
909 case SCTP_STATE_SHUTDOWN_PENDING:
910 case SCTP_STATE_SHUTDOWN_RECEIVED:
911 /*
912 * RFC 2960 6.1 Transmission of DATA Chunks
913 *
914 * C) When the time comes for the sender to transmit,
915 * before sending new DATA chunks, the sender MUST
916 * first transmit any outstanding DATA chunks which
917 * are marked for retransmission (limited by the
918 * current cwnd).
919 */
920 if (!list_empty(&q->retransmit)) {
Michio Hondaf207c052011-06-16 10:54:23 +0900921 if (asoc->peer.retran_path->state == SCTP_UNCONFIRMED)
922 goto sctp_flush_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 if (transport == asoc->peer.retran_path)
924 goto retran;
925
926 /* Switch transports & prepare the packet. */
927
928 transport = asoc->peer.retran_path;
929
930 if (list_empty(&transport->send_ready)) {
931 list_add_tail(&transport->send_ready,
932 &transport_list);
933 }
934
935 packet = &transport->packet;
936 sctp_packet_config(packet, vtag,
937 asoc->peer.ecn_capable);
938 retran:
939 error = sctp_outq_flush_rtx(q, packet,
940 rtx_timeout, &start_timer);
941
942 if (start_timer)
Vlad Yasevichd9efc222010-04-30 22:41:09 -0400943 sctp_transport_reset_timers(transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
945 /* This can happen on COOKIE-ECHO resend. Only
946 * one chunk can get bundled with a COOKIE-ECHO.
947 */
948 if (packet->has_cookie_echo)
949 goto sctp_flush_out;
950
951 /* Don't send new data if there is still data
952 * waiting to retransmit.
953 */
954 if (!list_empty(&q->retransmit))
955 goto sctp_flush_out;
956 }
957
Vlad Yasevich46d5a802009-11-23 15:54:00 -0500958 /* Apply Max.Burst limitation to the current transport in
959 * case it will be used for new data. We are going to
960 * rest it before we return, but we want to apply the limit
961 * to the currently queued data.
962 */
963 if (transport)
964 sctp_transport_burst_limited(transport);
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 /* Finally, transmit new packets. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
968 /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
969 * stream identifier.
970 */
971 if (chunk->sinfo.sinfo_stream >=
972 asoc->c.sinit_num_ostreams) {
973
974 /* Mark as failed send. */
975 sctp_chunk_fail(chunk, SCTP_ERROR_INV_STRM);
976 sctp_chunk_free(chunk);
977 continue;
978 }
979
980 /* Has this chunk expired? */
981 if (sctp_chunk_abandoned(chunk)) {
982 sctp_chunk_fail(chunk, 0);
983 sctp_chunk_free(chunk);
984 continue;
985 }
986
987 /* If there is a specified transport, use it.
988 * Otherwise, we want to use the active path.
989 */
990 new_transport = chunk->transport;
Frank Filz3f7a87d2005-06-20 13:14:57 -0700991 if (!new_transport ||
Sridhar Samudralaad8fec12006-07-21 14:48:50 -0700992 ((new_transport->state == SCTP_INACTIVE) ||
Neil Horman5aa93bc2012-07-21 07:56:07 +0000993 (new_transport->state == SCTP_UNCONFIRMED) ||
994 (new_transport->state == SCTP_PF)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 new_transport = asoc->peer.active_path;
Michio Hondaf207c052011-06-16 10:54:23 +0900996 if (new_transport->state == SCTP_UNCONFIRMED)
997 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
999 /* Change packets if necessary. */
1000 if (new_transport != transport) {
1001 transport = new_transport;
1002
1003 /* Schedule to have this transport's
1004 * packet flushed.
1005 */
1006 if (list_empty(&transport->send_ready)) {
1007 list_add_tail(&transport->send_ready,
1008 &transport_list);
1009 }
1010
1011 packet = &transport->packet;
1012 sctp_packet_config(packet, vtag,
1013 asoc->peer.ecn_capable);
Vlad Yasevich46d5a802009-11-23 15:54:00 -05001014 /* We've switched transports, so apply the
1015 * Burst limit to the new transport.
1016 */
1017 sctp_transport_burst_limited(transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019
1020 SCTP_DEBUG_PRINTK("sctp_outq_flush(%p, %p[%s]), ",
1021 q, chunk,
1022 chunk && chunk->chunk_hdr ?
1023 sctp_cname(SCTP_ST_CHUNK(
1024 chunk->chunk_hdr->type))
1025 : "Illegal Chunk");
1026
1027 SCTP_DEBUG_PRINTK("TX TSN 0x%x skb->head "
1028 "%p skb->users %d.\n",
1029 ntohl(chunk->subh.data_hdr->tsn),
1030 chunk->skb ?chunk->skb->head : NULL,
1031 chunk->skb ?
1032 atomic_read(&chunk->skb->users) : -1);
1033
1034 /* Add the chunk to the packet. */
Vlad Yasevich2e3216c2008-06-19 16:08:18 -07001035 status = sctp_packet_transmit_chunk(packet, chunk, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
1037 switch (status) {
1038 case SCTP_XMIT_PMTU_FULL:
1039 case SCTP_XMIT_RWND_FULL:
1040 case SCTP_XMIT_NAGLE_DELAY:
1041 /* We could not append this chunk, so put
1042 * the chunk back on the output queue.
1043 */
1044 SCTP_DEBUG_PRINTK("sctp_outq_flush: could "
1045 "not transmit TSN: 0x%x, status: %d\n",
1046 ntohl(chunk->subh.data_hdr->tsn),
1047 status);
1048 sctp_outq_head_data(q, chunk);
1049 goto sctp_flush_out;
1050 break;
1051
1052 case SCTP_XMIT_OK:
Wei Yongjunb93d6472009-11-23 15:53:56 -05001053 /* The sender is in the SHUTDOWN-PENDING state,
1054 * The sender MAY set the I-bit in the DATA
1055 * chunk header.
1056 */
1057 if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
1058 chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
1059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 break;
1061
1062 default:
1063 BUG();
1064 }
1065
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001066 /* BUG: We assume that the sctp_packet_transmit()
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 * call below will succeed all the time and add the
1068 * chunk to the transmitted list and restart the
1069 * timers.
1070 * It is possible that the call can fail under OOM
1071 * conditions.
1072 *
1073 * Is this really a problem? Won't this behave
1074 * like a lost TSN?
1075 */
1076 list_add_tail(&chunk->transmitted_list,
1077 &transport->transmitted);
1078
Vlad Yasevichd9efc222010-04-30 22:41:09 -04001079 sctp_transport_reset_timers(transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 q->empty = 0;
1082
1083 /* Only let one DATA chunk get bundled with a
1084 * COOKIE-ECHO chunk.
1085 */
1086 if (packet->has_cookie_echo)
1087 goto sctp_flush_out;
1088 }
1089 break;
1090
1091 default:
1092 /* Do nothing. */
1093 break;
1094 }
1095
1096sctp_flush_out:
1097
1098 /* Before returning, examine all the transports touched in
1099 * this call. Right now, we bluntly force clear all the
1100 * transports. Things might change after we implement Nagle.
1101 * But such an examination is still required.
1102 *
1103 * --xguo
1104 */
1105 while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL ) {
1106 struct sctp_transport *t = list_entry(ltransport,
1107 struct sctp_transport,
1108 send_ready);
1109 packet = &t->packet;
1110 if (!sctp_packet_empty(packet))
1111 error = sctp_packet_transmit(packet);
Vlad Yasevich46d5a802009-11-23 15:54:00 -05001112
1113 /* Clear the burst limited state, if any */
1114 sctp_transport_burst_reset(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 }
1116
1117 return error;
1118}
1119
1120/* Update unack_data based on the incoming SACK chunk */
1121static void sctp_sack_update_unack_data(struct sctp_association *assoc,
1122 struct sctp_sackhdr *sack)
1123{
1124 sctp_sack_variable_t *frags;
1125 __u16 unack_data;
1126 int i;
1127
1128 unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
1129
1130 frags = sack->variable;
1131 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
1132 unack_data -= ((ntohs(frags[i].gab.end) -
1133 ntohs(frags[i].gab.start) + 1));
1134 }
1135
1136 assoc->unack_data = unack_data;
1137}
1138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139/* This is where we REALLY process a SACK.
1140 *
1141 * Process the SACK against the outqueue. Mostly, this just frees
1142 * things off the transmitted queue.
1143 */
1144int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
1145{
1146 struct sctp_association *asoc = q->asoc;
1147 struct sctp_transport *transport;
1148 struct sctp_chunk *tchunk = NULL;
Robert P. J. Day9dbc15f02008-04-12 18:54:24 -07001149 struct list_head *lchunk, *transport_list, *temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 sctp_sack_variable_t *frags = sack->variable;
1151 __u32 sack_ctsn, ctsn, tsn;
1152 __u32 highest_tsn, highest_new_tsn;
1153 __u32 sack_a_rwnd;
Eric Dumazet95c96172012-04-15 05:58:06 +00001154 unsigned int outstanding;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 struct sctp_transport *primary = asoc->peer.primary_path;
1156 int count_of_newacks = 0;
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001157 int gap_ack_blocks;
Vlad Yasevichea862c82010-04-30 22:41:10 -04001158 u8 accum_moved = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 /* Grab the association's destination address list. */
1161 transport_list = &asoc->peer.transport_addr_list;
1162
1163 sack_ctsn = ntohl(sack->cum_tsn_ack);
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001164 gap_ack_blocks = ntohs(sack->num_gap_ack_blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 /*
1166 * SFR-CACC algorithm:
1167 * On receipt of a SACK the sender SHOULD execute the
1168 * following statements.
1169 *
1170 * 1) If the cumulative ack in the SACK passes next tsn_at_change
1171 * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
1172 * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
1173 * all destinations.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
1175 * is set the receiver of the SACK MUST take the following actions:
1176 *
1177 * A) Initialize the cacc_saw_newack to 0 for all destination
1178 * addresses.
Vlad Yasevichab5216a2008-06-19 18:17:24 -04001179 *
1180 * Only bother if changeover_active is set. Otherwise, this is
1181 * totally suboptimal to do on every SACK.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 */
Vlad Yasevichab5216a2008-06-19 18:17:24 -04001183 if (primary->cacc.changeover_active) {
1184 u8 clear_cycling = 0;
1185
1186 if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
1187 primary->cacc.changeover_active = 0;
1188 clear_cycling = 1;
1189 }
1190
1191 if (clear_cycling || gap_ack_blocks) {
1192 list_for_each_entry(transport, transport_list,
1193 transports) {
1194 if (clear_cycling)
1195 transport->cacc.cycling_changeover = 0;
1196 if (gap_ack_blocks)
1197 transport->cacc.cacc_saw_newack = 0;
1198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
1200 }
1201
1202 /* Get the highest TSN in the sack. */
1203 highest_tsn = sack_ctsn;
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001204 if (gap_ack_blocks)
1205 highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Vlad Yasevichbfa0d982010-04-30 22:41:10 -04001207 if (TSN_lt(asoc->highest_sacked, highest_tsn))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 asoc->highest_sacked = highest_tsn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Vlad Yasevichbfa0d982010-04-30 22:41:10 -04001210 highest_new_tsn = sack_ctsn;
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001211
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 /* Run through the retransmit queue. Credit bytes received
1213 * and free those chunks that we can.
1214 */
Vlad Yasevichbfa0d982010-04-30 22:41:10 -04001215 sctp_check_transmitted(q, &q->retransmit, NULL, sack, &highest_new_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 /* Run through the transmitted queue.
1218 * Credit bytes received and free those chunks which we can.
1219 *
1220 * This is a MASSIVE candidate for optimization.
1221 */
Robert P. J. Day9dbc15f02008-04-12 18:54:24 -07001222 list_for_each_entry(transport, transport_list, transports) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 sctp_check_transmitted(q, &transport->transmitted,
Vlad Yasevichbfa0d982010-04-30 22:41:10 -04001224 transport, sack, &highest_new_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 /*
1226 * SFR-CACC algorithm:
1227 * C) Let count_of_newacks be the number of
1228 * destinations for which cacc_saw_newack is set.
1229 */
1230 if (transport->cacc.cacc_saw_newack)
1231 count_of_newacks ++;
1232 }
1233
Vlad Yasevichea862c82010-04-30 22:41:10 -04001234 /* Move the Cumulative TSN Ack Point if appropriate. */
1235 if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn)) {
1236 asoc->ctsn_ack_point = sack_ctsn;
1237 accum_moved = 1;
1238 }
1239
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001240 if (gap_ack_blocks) {
Vlad Yasevichea862c82010-04-30 22:41:10 -04001241
1242 if (asoc->fast_recovery && accum_moved)
1243 highest_new_tsn = highest_tsn;
1244
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001245 list_for_each_entry(transport, transport_list, transports)
1246 sctp_mark_missing(q, &transport->transmitted, transport,
1247 highest_new_tsn, count_of_newacks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 }
1249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 /* Update unack_data field in the assoc. */
1251 sctp_sack_update_unack_data(asoc, sack);
1252
1253 ctsn = asoc->ctsn_ack_point;
1254
1255 /* Throw away stuff rotting on the sack queue. */
1256 list_for_each_safe(lchunk, temp, &q->sacked) {
1257 tchunk = list_entry(lchunk, struct sctp_chunk,
1258 transmitted_list);
1259 tsn = ntohl(tchunk->subh.data_hdr->tsn);
Vlad Yasevich5f9646c2008-02-05 14:23:44 -05001260 if (TSN_lte(tsn, ctsn)) {
1261 list_del_init(&tchunk->transmitted_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 sctp_chunk_free(tchunk);
Vlad Yasevich5f9646c2008-02-05 14:23:44 -05001263 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 }
1265
1266 /* ii) Set rwnd equal to the newly received a_rwnd minus the
1267 * number of bytes still outstanding after processing the
1268 * Cumulative TSN Ack and the Gap Ack Blocks.
1269 */
1270
1271 sack_a_rwnd = ntohl(sack->a_rwnd);
1272 outstanding = q->outstanding_bytes;
1273
1274 if (outstanding < sack_a_rwnd)
1275 sack_a_rwnd -= outstanding;
1276 else
1277 sack_a_rwnd = 0;
1278
1279 asoc->peer.rwnd = sack_a_rwnd;
1280
1281 sctp_generate_fwdtsn(q, sack_ctsn);
1282
1283 SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001284 __func__, sack_ctsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association, "
1286 "%p is 0x%x. Adv peer ack point: 0x%x\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001287 __func__, asoc, ctsn, asoc->adv_peer_ack_point);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 /* See if all chunks are acked.
1290 * Make sure the empty queue handler will get run later.
1291 */
David S. Miller79af02c2005-07-08 21:47:49 -07001292 q->empty = (list_empty(&q->out_chunk_list) &&
David S. Miller79af02c2005-07-08 21:47:49 -07001293 list_empty(&q->retransmit));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 if (!q->empty)
1295 goto finish;
1296
Robert P. J. Day9dbc15f02008-04-12 18:54:24 -07001297 list_for_each_entry(transport, transport_list, transports) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 q->empty = q->empty && list_empty(&transport->transmitted);
1299 if (!q->empty)
1300 goto finish;
1301 }
1302
1303 SCTP_DEBUG_PRINTK("sack queue is empty.\n");
1304finish:
1305 return q->empty;
1306}
1307
1308/* Is the outqueue empty? */
1309int sctp_outq_is_empty(const struct sctp_outq *q)
1310{
1311 return q->empty;
1312}
1313
1314/********************************************************************
1315 * 2nd Level Abstractions
1316 ********************************************************************/
1317
1318/* Go through a transport's transmitted list or the association's retransmit
1319 * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
1320 * The retransmit list will not have an associated transport.
1321 *
1322 * I added coherent debug information output. --xguo
1323 *
1324 * Instead of printing 'sacked' or 'kept' for each TSN on the
1325 * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
1326 * KEPT TSN6-TSN7, etc.
1327 */
1328static void sctp_check_transmitted(struct sctp_outq *q,
1329 struct list_head *transmitted_queue,
1330 struct sctp_transport *transport,
1331 struct sctp_sackhdr *sack,
Vlad Yasevichbfa0d982010-04-30 22:41:10 -04001332 __u32 *highest_new_tsn_in_sack)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333{
1334 struct list_head *lchunk;
1335 struct sctp_chunk *tchunk;
1336 struct list_head tlist;
1337 __u32 tsn;
1338 __u32 sack_ctsn;
1339 __u32 rtt;
1340 __u8 restart_timer = 0;
1341 int bytes_acked = 0;
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001342 int migrate_bytes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 /* These state variables are for coherent debug output. --xguo */
1345
1346#if SCTP_DEBUG
1347 __u32 dbg_ack_tsn = 0; /* An ACKed TSN range starts here... */
1348 __u32 dbg_last_ack_tsn = 0; /* ...and finishes here. */
1349 __u32 dbg_kept_tsn = 0; /* An un-ACKed range starts here... */
1350 __u32 dbg_last_kept_tsn = 0; /* ...and finishes here. */
1351
1352 /* 0 : The last TSN was ACKed.
1353 * 1 : The last TSN was NOT ACKed (i.e. KEPT).
1354 * -1: We need to initialize.
1355 */
1356 int dbg_prt_state = -1;
1357#endif /* SCTP_DEBUG */
1358
1359 sack_ctsn = ntohl(sack->cum_tsn_ack);
1360
1361 INIT_LIST_HEAD(&tlist);
1362
1363 /* The while loop will skip empty transmitted queues. */
1364 while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
1365 tchunk = list_entry(lchunk, struct sctp_chunk,
1366 transmitted_list);
1367
1368 if (sctp_chunk_abandoned(tchunk)) {
1369 /* Move the chunk to abandoned list. */
1370 sctp_insert_list(&q->abandoned, lchunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -08001371
1372 /* If this chunk has not been acked, stop
1373 * considering it as 'outstanding'.
1374 */
1375 if (!tchunk->tsn_gap_acked) {
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001376 if (tchunk->transport)
1377 tchunk->transport->flight_size -=
1378 sctp_data_size(tchunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -08001379 q->outstanding_bytes -= sctp_data_size(tchunk);
1380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 continue;
1382 }
1383
1384 tsn = ntohl(tchunk->subh.data_hdr->tsn);
1385 if (sctp_acked(sack, tsn)) {
1386 /* If this queue is the retransmit queue, the
1387 * retransmit timer has already reclaimed
1388 * the outstanding bytes for this chunk, so only
1389 * count bytes associated with a transport.
1390 */
1391 if (transport) {
1392 /* If this chunk is being used for RTT
1393 * measurement, calculate the RTT and update
1394 * the RTO using this value.
1395 *
1396 * 6.3.1 C5) Karn's algorithm: RTT measurements
1397 * MUST NOT be made using packets that were
1398 * retransmitted (and thus for which it is
1399 * ambiguous whether the reply was for the
1400 * first instance of the packet or a later
1401 * instance).
1402 */
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001403 if (!tchunk->tsn_gap_acked &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 tchunk->rtt_in_progress) {
Vlad Yasevich4c9f5d52006-06-17 22:56:08 -07001405 tchunk->rtt_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 rtt = jiffies - tchunk->sent_at;
1407 sctp_transport_update_rto(transport,
1408 rtt);
1409 }
1410 }
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001411
1412 /* If the chunk hasn't been marked as ACKED,
1413 * mark it and account bytes_acked if the
1414 * chunk had a valid transport (it will not
1415 * have a transport if ASCONF had deleted it
1416 * while DATA was outstanding).
1417 */
1418 if (!tchunk->tsn_gap_acked) {
1419 tchunk->tsn_gap_acked = 1;
Vlad Yasevichbfa0d982010-04-30 22:41:10 -04001420 *highest_new_tsn_in_sack = tsn;
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001421 bytes_acked += sctp_data_size(tchunk);
1422 if (!tchunk->transport)
1423 migrate_bytes += sctp_data_size(tchunk);
1424 }
1425
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001426 if (TSN_lte(tsn, sack_ctsn)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 /* RFC 2960 6.3.2 Retransmission Timer Rules
1428 *
1429 * R3) Whenever a SACK is received
1430 * that acknowledges the DATA chunk
1431 * with the earliest outstanding TSN
1432 * for that address, restart T3-rtx
1433 * timer for that address with its
1434 * current RTO.
1435 */
1436 restart_timer = 1;
1437
1438 if (!tchunk->tsn_gap_acked) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 /*
1440 * SFR-CACC algorithm:
1441 * 2) If the SACK contains gap acks
1442 * and the flag CHANGEOVER_ACTIVE is
1443 * set the receiver of the SACK MUST
1444 * take the following action:
1445 *
1446 * B) For each TSN t being acked that
1447 * has not been acked in any SACK so
1448 * far, set cacc_saw_newack to 1 for
1449 * the destination that the TSN was
1450 * sent to.
1451 */
1452 if (transport &&
1453 sack->num_gap_ack_blocks &&
1454 q->asoc->peer.primary_path->cacc.
1455 changeover_active)
1456 transport->cacc.cacc_saw_newack
1457 = 1;
1458 }
1459
1460 list_add_tail(&tchunk->transmitted_list,
1461 &q->sacked);
1462 } else {
1463 /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
1464 * M2) Each time a SACK arrives reporting
1465 * 'Stray DATA chunk(s)' record the highest TSN
1466 * reported as newly acknowledged, call this
1467 * value 'HighestTSNinSack'. A newly
1468 * acknowledged DATA chunk is one not
1469 * previously acknowledged in a SACK.
1470 *
1471 * When the SCTP sender of data receives a SACK
1472 * chunk that acknowledges, for the first time,
1473 * the receipt of a DATA chunk, all the still
1474 * unacknowledged DATA chunks whose TSN is
1475 * older than that newly acknowledged DATA
1476 * chunk, are qualified as 'Stray DATA chunks'.
1477 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 list_add_tail(lchunk, &tlist);
1479 }
1480
1481#if SCTP_DEBUG
1482 switch (dbg_prt_state) {
1483 case 0: /* last TSN was ACKed */
1484 if (dbg_last_ack_tsn + 1 == tsn) {
1485 /* This TSN belongs to the
1486 * current ACK range.
1487 */
1488 break;
1489 }
1490
1491 if (dbg_last_ack_tsn != dbg_ack_tsn) {
1492 /* Display the end of the
1493 * current range.
1494 */
Joe Perches145ce502010-08-24 13:21:08 +00001495 SCTP_DEBUG_PRINTK_CONT("-%08x",
1496 dbg_last_ack_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 }
1498
1499 /* Start a new range. */
Joe Perches145ce502010-08-24 13:21:08 +00001500 SCTP_DEBUG_PRINTK_CONT(",%08x", tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 dbg_ack_tsn = tsn;
1502 break;
1503
1504 case 1: /* The last TSN was NOT ACKed. */
1505 if (dbg_last_kept_tsn != dbg_kept_tsn) {
1506 /* Display the end of current range. */
Joe Perches145ce502010-08-24 13:21:08 +00001507 SCTP_DEBUG_PRINTK_CONT("-%08x",
1508 dbg_last_kept_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 }
1510
Joe Perches145ce502010-08-24 13:21:08 +00001511 SCTP_DEBUG_PRINTK_CONT("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
1513 /* FALL THROUGH... */
1514 default:
1515 /* This is the first-ever TSN we examined. */
1516 /* Start a new range of ACK-ed TSNs. */
1517 SCTP_DEBUG_PRINTK("ACKed: %08x", tsn);
1518 dbg_prt_state = 0;
1519 dbg_ack_tsn = tsn;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07001520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522 dbg_last_ack_tsn = tsn;
1523#endif /* SCTP_DEBUG */
1524
1525 } else {
1526 if (tchunk->tsn_gap_acked) {
1527 SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
1528 "data TSN: 0x%x\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001529 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 tsn);
1531 tchunk->tsn_gap_acked = 0;
1532
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001533 if (tchunk->transport)
1534 bytes_acked -= sctp_data_size(tchunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536 /* RFC 2960 6.3.2 Retransmission Timer Rules
1537 *
1538 * R4) Whenever a SACK is received missing a
1539 * TSN that was previously acknowledged via a
1540 * Gap Ack Block, start T3-rtx for the
1541 * destination address to which the DATA
1542 * chunk was originally
1543 * transmitted if it is not already running.
1544 */
1545 restart_timer = 1;
1546 }
1547
1548 list_add_tail(lchunk, &tlist);
1549
1550#if SCTP_DEBUG
1551 /* See the above comments on ACK-ed TSNs. */
1552 switch (dbg_prt_state) {
1553 case 1:
1554 if (dbg_last_kept_tsn + 1 == tsn)
1555 break;
1556
1557 if (dbg_last_kept_tsn != dbg_kept_tsn)
Joe Perches145ce502010-08-24 13:21:08 +00001558 SCTP_DEBUG_PRINTK_CONT("-%08x",
1559 dbg_last_kept_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Joe Perches145ce502010-08-24 13:21:08 +00001561 SCTP_DEBUG_PRINTK_CONT(",%08x", tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 dbg_kept_tsn = tsn;
1563 break;
1564
1565 case 0:
1566 if (dbg_last_ack_tsn != dbg_ack_tsn)
Joe Perches145ce502010-08-24 13:21:08 +00001567 SCTP_DEBUG_PRINTK_CONT("-%08x",
1568 dbg_last_ack_tsn);
1569 SCTP_DEBUG_PRINTK_CONT("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
1571 /* FALL THROUGH... */
1572 default:
1573 SCTP_DEBUG_PRINTK("KEPT: %08x",tsn);
1574 dbg_prt_state = 1;
1575 dbg_kept_tsn = tsn;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07001576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
1578 dbg_last_kept_tsn = tsn;
1579#endif /* SCTP_DEBUG */
1580 }
1581 }
1582
1583#if SCTP_DEBUG
1584 /* Finish off the last range, displaying its ending TSN. */
1585 switch (dbg_prt_state) {
1586 case 0:
1587 if (dbg_last_ack_tsn != dbg_ack_tsn) {
Joe Perches145ce502010-08-24 13:21:08 +00001588 SCTP_DEBUG_PRINTK_CONT("-%08x\n", dbg_last_ack_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 } else {
Joe Perches145ce502010-08-24 13:21:08 +00001590 SCTP_DEBUG_PRINTK_CONT("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 }
1592 break;
1593
1594 case 1:
1595 if (dbg_last_kept_tsn != dbg_kept_tsn) {
Joe Perches145ce502010-08-24 13:21:08 +00001596 SCTP_DEBUG_PRINTK_CONT("-%08x\n", dbg_last_kept_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 } else {
Joe Perches145ce502010-08-24 13:21:08 +00001598 SCTP_DEBUG_PRINTK_CONT("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 }
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07001600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601#endif /* SCTP_DEBUG */
1602 if (transport) {
1603 if (bytes_acked) {
Thomas Graff8d96052011-07-07 00:28:35 +00001604 struct sctp_association *asoc = transport->asoc;
1605
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001606 /* We may have counted DATA that was migrated
1607 * to this transport due to DEL-IP operation.
1608 * Subtract those bytes, since the were never
1609 * send on this transport and shouldn't be
1610 * credited to this transport.
1611 */
1612 bytes_acked -= migrate_bytes;
1613
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 /* 8.2. When an outstanding TSN is acknowledged,
1615 * the endpoint shall clear the error counter of
1616 * the destination transport address to which the
1617 * DATA chunk was last sent.
1618 * The association's overall error counter is
1619 * also cleared.
1620 */
1621 transport->error_count = 0;
1622 transport->asoc->overall_error_count = 0;
1623
Thomas Graff8d96052011-07-07 00:28:35 +00001624 /*
1625 * While in SHUTDOWN PENDING, we may have started
1626 * the T5 shutdown guard timer after reaching the
1627 * retransmission limit. Stop that timer as soon
1628 * as the receiver acknowledged any data.
1629 */
1630 if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING &&
1631 del_timer(&asoc->timers
1632 [SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]))
1633 sctp_association_put(asoc);
1634
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 /* Mark the destination transport address as
1636 * active if it is not so marked.
1637 */
Sridhar Samudralaad8fec12006-07-21 14:48:50 -07001638 if ((transport->state == SCTP_INACTIVE) ||
1639 (transport->state == SCTP_UNCONFIRMED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 sctp_assoc_control_transport(
1641 transport->asoc,
1642 transport,
1643 SCTP_TRANSPORT_UP,
1644 SCTP_RECEIVED_SACK);
1645 }
1646
1647 sctp_transport_raise_cwnd(transport, sack_ctsn,
1648 bytes_acked);
1649
1650 transport->flight_size -= bytes_acked;
Gui Jianfeng8b73a072008-04-17 14:22:18 -07001651 if (transport->flight_size == 0)
1652 transport->partial_bytes_acked = 0;
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001653 q->outstanding_bytes -= bytes_acked + migrate_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 } else {
1655 /* RFC 2960 6.1, sctpimpguide-06 2.15.2
1656 * When a sender is doing zero window probing, it
1657 * should not timeout the association if it continues
1658 * to receive new packets from the receiver. The
1659 * reason is that the receiver MAY keep its window
1660 * closed for an indefinite time.
1661 * A sender is doing zero window probing when the
1662 * receiver's advertised window is zero, and there is
1663 * only one data chunk in flight to the receiver.
Thomas Graff8d96052011-07-07 00:28:35 +00001664 *
1665 * Allow the association to timeout while in SHUTDOWN
1666 * PENDING or SHUTDOWN RECEIVED in case the receiver
1667 * stays in zero window mode forever.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 */
1669 if (!q->asoc->peer.rwnd &&
1670 !list_empty(&tlist) &&
Thomas Graff8d96052011-07-07 00:28:35 +00001671 (sack_ctsn+2 == q->asoc->next_tsn) &&
1672 q->asoc->state < SCTP_STATE_SHUTDOWN_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 SCTP_DEBUG_PRINTK("%s: SACK received for zero "
1674 "window probe: %u\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001675 __func__, sack_ctsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 q->asoc->overall_error_count = 0;
1677 transport->error_count = 0;
1678 }
1679 }
1680
1681 /* RFC 2960 6.3.2 Retransmission Timer Rules
1682 *
1683 * R2) Whenever all outstanding data sent to an address have
1684 * been acknowledged, turn off the T3-rtx timer of that
1685 * address.
1686 */
1687 if (!transport->flight_size) {
1688 if (timer_pending(&transport->T3_rtx_timer) &&
1689 del_timer(&transport->T3_rtx_timer)) {
1690 sctp_transport_put(transport);
1691 }
1692 } else if (restart_timer) {
1693 if (!mod_timer(&transport->T3_rtx_timer,
1694 jiffies + transport->rto))
1695 sctp_transport_hold(transport);
1696 }
1697 }
1698
1699 list_splice(&tlist, transmitted_queue);
1700}
1701
1702/* Mark chunks as missing and consequently may get retransmitted. */
1703static void sctp_mark_missing(struct sctp_outq *q,
1704 struct list_head *transmitted_queue,
1705 struct sctp_transport *transport,
1706 __u32 highest_new_tsn_in_sack,
1707 int count_of_newacks)
1708{
1709 struct sctp_chunk *chunk;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 __u32 tsn;
1711 char do_fast_retransmit = 0;
Vlad Yasevichea862c82010-04-30 22:41:10 -04001712 struct sctp_association *asoc = q->asoc;
1713 struct sctp_transport *primary = asoc->peer.primary_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
Robert P. J. Day9dbc15f02008-04-12 18:54:24 -07001715 list_for_each_entry(chunk, transmitted_queue, transmitted_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 tsn = ntohl(chunk->subh.data_hdr->tsn);
1718
1719 /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
1720 * 'Unacknowledged TSN's', if the TSN number of an
1721 * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
1722 * value, increment the 'TSN.Missing.Report' count on that
1723 * chunk if it has NOT been fast retransmitted or marked for
1724 * fast retransmit already.
1725 */
Neil Hormanc226ef92008-07-25 12:44:09 -04001726 if (chunk->fast_retransmit == SCTP_CAN_FRTX &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 !chunk->tsn_gap_acked &&
1728 TSN_lt(tsn, highest_new_tsn_in_sack)) {
1729
1730 /* SFR-CACC may require us to skip marking
1731 * this chunk as missing.
1732 */
Vlad Yasevichf246a7b2011-04-18 19:13:56 +00001733 if (!transport || !sctp_cacc_skip(primary,
1734 chunk->transport,
1735 count_of_newacks, tsn)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 chunk->tsn_missing_report++;
1737
1738 SCTP_DEBUG_PRINTK(
1739 "%s: TSN 0x%x missing counter: %d\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001740 __func__, tsn,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 chunk->tsn_missing_report);
1742 }
1743 }
1744 /*
1745 * M4) If any DATA chunk is found to have a
1746 * 'TSN.Missing.Report'
Vlad Yasevich27852c22006-02-02 16:57:31 -08001747 * value larger than or equal to 3, mark that chunk for
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 * retransmission and start the fast retransmit procedure.
1749 */
1750
Vlad Yasevich27852c22006-02-02 16:57:31 -08001751 if (chunk->tsn_missing_report >= 3) {
Neil Hormanc226ef92008-07-25 12:44:09 -04001752 chunk->fast_retransmit = SCTP_NEED_FRTX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 do_fast_retransmit = 1;
1754 }
1755 }
1756
1757 if (transport) {
1758 if (do_fast_retransmit)
1759 sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
1760
1761 SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
1762 "ssthresh: %d, flight_size: %d, pba: %d\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001763 __func__, transport, transport->cwnd,
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001764 transport->ssthresh, transport->flight_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 transport->partial_bytes_acked);
1766 }
1767}
1768
1769/* Is the given TSN acked by this packet? */
1770static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
1771{
1772 int i;
1773 sctp_sack_variable_t *frags;
1774 __u16 gap;
1775 __u32 ctsn = ntohl(sack->cum_tsn_ack);
1776
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001777 if (TSN_lte(tsn, ctsn))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 goto pass;
1779
1780 /* 3.3.4 Selective Acknowledgement (SACK) (3):
1781 *
1782 * Gap Ack Blocks:
1783 * These fields contain the Gap Ack Blocks. They are repeated
1784 * for each Gap Ack Block up to the number of Gap Ack Blocks
1785 * defined in the Number of Gap Ack Blocks field. All DATA
1786 * chunks with TSNs greater than or equal to (Cumulative TSN
1787 * Ack + Gap Ack Block Start) and less than or equal to
1788 * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
1789 * Block are assumed to have been received correctly.
1790 */
1791
1792 frags = sack->variable;
1793 gap = tsn - ctsn;
1794 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
1795 if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
1796 TSN_lte(gap, ntohs(frags[i].gab.end)))
1797 goto pass;
1798 }
1799
1800 return 0;
1801pass:
1802 return 1;
1803}
1804
1805static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist,
Al Viro9f81bcd2006-11-20 17:26:34 -08001806 int nskips, __be16 stream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807{
1808 int i;
1809
1810 for (i = 0; i < nskips; i++) {
1811 if (skiplist[i].stream == stream)
1812 return i;
1813 }
1814 return i;
1815}
1816
1817/* Create and add a fwdtsn chunk to the outq's control queue if needed. */
1818static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
1819{
1820 struct sctp_association *asoc = q->asoc;
1821 struct sctp_chunk *ftsn_chunk = NULL;
1822 struct sctp_fwdtsn_skip ftsn_skip_arr[10];
1823 int nskips = 0;
1824 int skip_pos = 0;
1825 __u32 tsn;
1826 struct sctp_chunk *chunk;
1827 struct list_head *lchunk, *temp;
1828
Wei Yongjun76595022009-03-12 09:49:19 +00001829 if (!asoc->peer.prsctp_capable)
1830 return;
1831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 /* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the
1833 * received SACK.
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001834 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 * If (Advanced.Peer.Ack.Point < SackCumAck), then update
1836 * Advanced.Peer.Ack.Point to be equal to SackCumAck.
1837 */
1838 if (TSN_lt(asoc->adv_peer_ack_point, ctsn))
1839 asoc->adv_peer_ack_point = ctsn;
1840
1841 /* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point"
1842 * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as
1843 * the chunk next in the out-queue space is marked as "abandoned" as
1844 * shown in the following example:
1845 *
1846 * Assuming that a SACK arrived with the Cumulative TSN ACK 102
1847 * and the Advanced.Peer.Ack.Point is updated to this value:
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001848 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 * out-queue at the end of ==> out-queue after Adv.Ack.Point
1850 * normal SACK processing local advancement
1851 * ... ...
1852 * Adv.Ack.Pt-> 102 acked 102 acked
1853 * 103 abandoned 103 abandoned
1854 * 104 abandoned Adv.Ack.P-> 104 abandoned
1855 * 105 105
1856 * 106 acked 106 acked
1857 * ... ...
1858 *
1859 * In this example, the data sender successfully advanced the
1860 * "Advanced.Peer.Ack.Point" from 102 to 104 locally.
1861 */
1862 list_for_each_safe(lchunk, temp, &q->abandoned) {
1863 chunk = list_entry(lchunk, struct sctp_chunk,
1864 transmitted_list);
1865 tsn = ntohl(chunk->subh.data_hdr->tsn);
1866
1867 /* Remove any chunks in the abandoned queue that are acked by
1868 * the ctsn.
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001869 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 if (TSN_lte(tsn, ctsn)) {
1871 list_del_init(lchunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 sctp_chunk_free(chunk);
1873 } else {
1874 if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
1875 asoc->adv_peer_ack_point = tsn;
1876 if (chunk->chunk_hdr->flags &
1877 SCTP_DATA_UNORDERED)
1878 continue;
1879 skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0],
1880 nskips,
1881 chunk->subh.data_hdr->stream);
1882 ftsn_skip_arr[skip_pos].stream =
1883 chunk->subh.data_hdr->stream;
1884 ftsn_skip_arr[skip_pos].ssn =
1885 chunk->subh.data_hdr->ssn;
1886 if (skip_pos == nskips)
1887 nskips++;
1888 if (nskips == 10)
1889 break;
1890 } else
1891 break;
1892 }
1893 }
1894
1895 /* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point"
1896 * is greater than the Cumulative TSN ACK carried in the received
1897 * SACK, the data sender MUST send the data receiver a FORWARD TSN
1898 * chunk containing the latest value of the
1899 * "Advanced.Peer.Ack.Point".
1900 *
1901 * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD
1902 * list each stream and sequence number in the forwarded TSN. This
1903 * information will enable the receiver to easily find any
1904 * stranded TSN's waiting on stream reorder queues. Each stream
1905 * SHOULD only be reported once; this means that if multiple
1906 * abandoned messages occur in the same stream then only the
1907 * highest abandoned stream sequence number is reported. If the
1908 * total size of the FORWARD TSN does NOT fit in a single MTU then
1909 * the sender of the FORWARD TSN SHOULD lower the
1910 * Advanced.Peer.Ack.Point to the last TSN that will fit in a
1911 * single MTU.
1912 */
1913 if (asoc->adv_peer_ack_point > ctsn)
1914 ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point,
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001915 nskips, &ftsn_skip_arr[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
1917 if (ftsn_chunk) {
David S. Miller79af02c2005-07-08 21:47:49 -07001918 list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
Eric W. Biedermanb01a2402012-08-06 08:47:55 +00001919 SCTP_INC_STATS(sock_net(asoc->base.sk), SCTP_MIB_OUTCTRLCHUNKS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 }
1921}