blob: da2418b64c862a1a36900cd0becf018a4e4b2e40 [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
Jeff Kirsher4b2f13a2013-12-06 06:28:48 -080025 * along with GNU CC; see the file COPYING. If not, see
26 * <http://www.gnu.org/licenses/>.
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 *
28 * Please send any bug reports or fixes you make to the
29 * email address(es):
Daniel Borkmann91705c62013-07-23 14:51:47 +020030 * lksctp developers <linux-sctp@vger.kernel.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 * Written or modified by:
33 * La Monte H.P. Yarroll <piggy@acm.org>
34 * Karl Knutson <karl@athena.chicago.il.us>
35 * Perry Melange <pmelange@null.cc.uic.edu>
36 * Xingang Guo <xingang.guo@intel.com>
37 * Hui Huang <hui.huang@nokia.com>
38 * Sridhar Samudrala <sri@us.ibm.com>
39 * Jon Grimm <jgrimm@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 */
41
Joe Perches145ce502010-08-24 13:21:08 +000042#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/types.h>
45#include <linux/list.h> /* For struct list_head */
46#include <linux/socket.h>
47#include <linux/ip.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090048#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <net/sock.h> /* For skb_set_owner_w */
50
51#include <net/sctp/sctp.h>
52#include <net/sctp/sm.h>
53
54/* Declare internal functions here. */
55static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn);
56static void sctp_check_transmitted(struct sctp_outq *q,
57 struct list_head *transmitted_queue,
58 struct sctp_transport *transport,
Nicolas Dichteledfee032012-10-03 05:43:22 +000059 union sctp_addr *saddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 struct sctp_sackhdr *sack,
Vlad Yasevichbfa0d982010-04-30 22:41:10 -040061 __u32 *highest_new_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63static void sctp_mark_missing(struct sctp_outq *q,
64 struct list_head *transmitted_queue,
65 struct sctp_transport *transport,
66 __u32 highest_new_tsn,
67 int count_of_newacks);
68
69static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
70
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -030071static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp);
Adrian Bunkabd0b1982008-07-22 14:20:45 -070072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* Add data to the front of the queue. */
74static inline void sctp_outq_head_data(struct sctp_outq *q,
75 struct sctp_chunk *ch)
76{
David S. Miller79af02c2005-07-08 21:47:49 -070077 list_add(&ch->list, &q->out_chunk_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 q->out_qlen += ch->skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
81/* Take data from the front of the queue. */
82static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q)
83{
David S. Miller79af02c2005-07-08 21:47:49 -070084 struct sctp_chunk *ch = NULL;
85
86 if (!list_empty(&q->out_chunk_list)) {
87 struct list_head *entry = q->out_chunk_list.next;
88
89 ch = list_entry(entry, struct sctp_chunk, list);
90 list_del_init(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 q->out_qlen -= ch->skb->len;
David S. Miller79af02c2005-07-08 21:47:49 -070092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return ch;
94}
95/* Add data chunk to the end of the queue. */
96static inline void sctp_outq_tail_data(struct sctp_outq *q,
97 struct sctp_chunk *ch)
98{
David S. Miller79af02c2005-07-08 21:47:49 -070099 list_add_tail(&ch->list, &q->out_chunk_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 q->out_qlen += ch->skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
103/*
104 * SFR-CACC algorithm:
105 * D) If count_of_newacks is greater than or equal to 2
106 * and t was not sent to the current primary then the
107 * sender MUST NOT increment missing report count for t.
108 */
109static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary,
110 struct sctp_transport *transport,
111 int count_of_newacks)
112{
wangweidongcb3f8372013-12-23 12:16:50 +0800113 if (count_of_newacks >= 2 && transport != primary)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return 1;
115 return 0;
116}
117
118/*
119 * SFR-CACC algorithm:
120 * F) If count_of_newacks is less than 2, let d be the
121 * destination to which t was sent. If cacc_saw_newack
122 * is 0 for destination d, then the sender MUST NOT
123 * increment missing report count for t.
124 */
125static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport,
126 int count_of_newacks)
127{
Vlad Yasevichf246a7b2011-04-18 19:13:56 +0000128 if (count_of_newacks < 2 &&
129 (transport && !transport->cacc.cacc_saw_newack))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return 1;
131 return 0;
132}
133
134/*
135 * SFR-CACC algorithm:
136 * 3.1) If CYCLING_CHANGEOVER is 0, the sender SHOULD
137 * execute steps C, D, F.
138 *
139 * C has been implemented in sctp_outq_sack
140 */
141static inline int sctp_cacc_skip_3_1(struct sctp_transport *primary,
142 struct sctp_transport *transport,
143 int count_of_newacks)
144{
145 if (!primary->cacc.cycling_changeover) {
146 if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks))
147 return 1;
148 if (sctp_cacc_skip_3_1_f(transport, count_of_newacks))
149 return 1;
150 return 0;
151 }
152 return 0;
153}
154
155/*
156 * SFR-CACC algorithm:
157 * 3.2) Else if CYCLING_CHANGEOVER is 1, and t is less
158 * than next_tsn_at_change of the current primary, then
159 * the sender MUST NOT increment missing report count
160 * for t.
161 */
162static inline int sctp_cacc_skip_3_2(struct sctp_transport *primary, __u32 tsn)
163{
164 if (primary->cacc.cycling_changeover &&
165 TSN_lt(tsn, primary->cacc.next_tsn_at_change))
166 return 1;
167 return 0;
168}
169
170/*
171 * SFR-CACC algorithm:
172 * 3) If the missing report count for TSN t is to be
173 * incremented according to [RFC2960] and
174 * [SCTP_STEWART-2002], and CHANGEOVER_ACTIVE is set,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300175 * then the sender MUST further execute steps 3.1 and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 * 3.2 to determine if the missing report count for
177 * TSN t SHOULD NOT be incremented.
178 *
179 * 3.3) If 3.1 and 3.2 do not dictate that the missing
180 * report count for t should not be incremented, then
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300181 * the sender SHOULD increment missing report count for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 * t (according to [RFC2960] and [SCTP_STEWART_2002]).
183 */
184static inline int sctp_cacc_skip(struct sctp_transport *primary,
185 struct sctp_transport *transport,
186 int count_of_newacks,
187 __u32 tsn)
188{
189 if (primary->cacc.changeover_active &&
Joe Perchesf64f9e72009-11-29 16:55:45 -0800190 (sctp_cacc_skip_3_1(primary, transport, count_of_newacks) ||
191 sctp_cacc_skip_3_2(primary, tsn)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return 1;
193 return 0;
194}
195
196/* Initialize an existing sctp_outq. This does the boring stuff.
197 * You still need to define handlers if you really want to DO
198 * something with this structure...
199 */
200void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
201{
Neil Hormanc5c77742013-06-12 14:26:44 -0400202 memset(q, 0, sizeof(struct sctp_outq));
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 q->asoc = asoc;
David S. Miller79af02c2005-07-08 21:47:49 -0700205 INIT_LIST_HEAD(&q->out_chunk_list);
206 INIT_LIST_HEAD(&q->control_chunk_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 INIT_LIST_HEAD(&q->retransmit);
208 INIT_LIST_HEAD(&q->sacked);
209 INIT_LIST_HEAD(&q->abandoned);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
211
212/* Free the outqueue structure and any related pending chunks.
213 */
Neil Horman2f94aab2013-01-17 11:15:08 +0000214static void __sctp_outq_teardown(struct sctp_outq *q)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
216 struct sctp_transport *transport;
Robert P. J. Day9dbc15f2008-04-12 18:54:24 -0700217 struct list_head *lchunk, *temp;
David S. Miller79af02c2005-07-08 21:47:49 -0700218 struct sctp_chunk *chunk, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 /* Throw away unacknowledged chunks. */
Robert P. J. Day9dbc15f2008-04-12 18:54:24 -0700221 list_for_each_entry(transport, &q->asoc->peer.transport_addr_list,
222 transports) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 while ((lchunk = sctp_list_dequeue(&transport->transmitted)) != NULL) {
224 chunk = list_entry(lchunk, struct sctp_chunk,
225 transmitted_list);
226 /* Mark as part of a failed message. */
227 sctp_chunk_fail(chunk, q->error);
228 sctp_chunk_free(chunk);
229 }
230 }
231
232 /* Throw away chunks that have been gap ACKed. */
233 list_for_each_safe(lchunk, temp, &q->sacked) {
234 list_del_init(lchunk);
235 chunk = list_entry(lchunk, struct sctp_chunk,
236 transmitted_list);
237 sctp_chunk_fail(chunk, q->error);
238 sctp_chunk_free(chunk);
239 }
240
241 /* Throw away any chunks in the retransmit queue. */
242 list_for_each_safe(lchunk, temp, &q->retransmit) {
243 list_del_init(lchunk);
244 chunk = list_entry(lchunk, struct sctp_chunk,
245 transmitted_list);
246 sctp_chunk_fail(chunk, q->error);
247 sctp_chunk_free(chunk);
248 }
249
250 /* Throw away any chunks that are in the abandoned queue. */
251 list_for_each_safe(lchunk, temp, &q->abandoned) {
252 list_del_init(lchunk);
253 chunk = list_entry(lchunk, struct sctp_chunk,
254 transmitted_list);
255 sctp_chunk_fail(chunk, q->error);
256 sctp_chunk_free(chunk);
257 }
258
259 /* Throw away any leftover data chunks. */
260 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
261
262 /* Mark as send failure. */
263 sctp_chunk_fail(chunk, q->error);
264 sctp_chunk_free(chunk);
265 }
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 /* Throw away any leftover control chunks. */
David S. Miller79af02c2005-07-08 21:47:49 -0700268 list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) {
269 list_del_init(&chunk->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 sctp_chunk_free(chunk);
David S. Miller79af02c2005-07-08 21:47:49 -0700271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272}
273
Neil Horman2f94aab2013-01-17 11:15:08 +0000274void sctp_outq_teardown(struct sctp_outq *q)
275{
276 __sctp_outq_teardown(q);
277 sctp_outq_init(q->asoc, q);
278}
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280/* Free the outqueue structure and any related pending chunks. */
281void sctp_outq_free(struct sctp_outq *q)
282{
283 /* Throw away leftover chunks. */
Neil Horman2f94aab2013-01-17 11:15:08 +0000284 __sctp_outq_teardown(q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
287/* Put a new chunk in an sctp_outq. */
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300288int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk, gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000290 struct net *net = sock_net(q->asoc->base.sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 int error = 0;
292
Daniel Borkmannbb333812013-06-28 19:49:40 +0200293 pr_debug("%s: outq:%p, chunk:%p[%s]\n", __func__, q, chunk,
294 chunk && chunk->chunk_hdr ?
295 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
296 "illegal chunk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 /* If it is data, queue it up, otherwise, send it
299 * immediately.
300 */
Shan Weiec7b9512010-04-30 22:41:09 -0400301 if (sctp_chunk_is_data(chunk)) {
Xin Long2c897912016-09-14 02:04:18 +0800302 pr_debug("%s: outqueueing: outq:%p, chunk:%p[%s])\n",
303 __func__, q, chunk, chunk && chunk->chunk_hdr ?
304 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
305 "illegal chunk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Xin Long2c897912016-09-14 02:04:18 +0800307 sctp_chunk_hold(chunk);
308 sctp_outq_tail_data(q, chunk);
309 if (chunk->asoc->prsctp_enable &&
310 SCTP_PR_PRIO_ENABLED(chunk->sinfo.sinfo_flags))
311 chunk->asoc->sent_cnt_removable++;
312 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
313 SCTP_INC_STATS(net, SCTP_MIB_OUTUNORDERCHUNKS);
314 else
315 SCTP_INC_STATS(net, SCTP_MIB_OUTORDERCHUNKS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 } else {
David S. Miller79af02c2005-07-08 21:47:49 -0700317 list_add_tail(&chunk->list, &q->control_chunk_list);
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000318 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 if (!q->cork)
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300322 error = sctp_outq_flush(q, 0, gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 return error;
325}
326
327/* Insert a chunk into the sorted list based on the TSNs. The retransmit list
328 * and the abandoned list are in ascending order.
329 */
330static void sctp_insert_list(struct list_head *head, struct list_head *new)
331{
332 struct list_head *pos;
333 struct sctp_chunk *nchunk, *lchunk;
334 __u32 ntsn, ltsn;
335 int done = 0;
336
337 nchunk = list_entry(new, struct sctp_chunk, transmitted_list);
338 ntsn = ntohl(nchunk->subh.data_hdr->tsn);
339
340 list_for_each(pos, head) {
341 lchunk = list_entry(pos, struct sctp_chunk, transmitted_list);
342 ltsn = ntohl(lchunk->subh.data_hdr->tsn);
343 if (TSN_lt(ntsn, ltsn)) {
344 list_add(new, pos->prev);
345 done = 1;
346 break;
347 }
348 }
349 if (!done)
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900350 list_add_tail(new, head);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
Xin Long8dbdf1f2016-07-09 19:47:45 +0800353static int sctp_prsctp_prune_sent(struct sctp_association *asoc,
354 struct sctp_sndrcvinfo *sinfo,
355 struct list_head *queue, int msg_len)
356{
357 struct sctp_chunk *chk, *temp;
358
359 list_for_each_entry_safe(chk, temp, queue, transmitted_list) {
360 if (!SCTP_PR_PRIO_ENABLED(chk->sinfo.sinfo_flags) ||
361 chk->prsctp_param <= sinfo->sinfo_timetolive)
362 continue;
363
364 list_del_init(&chk->transmitted_list);
365 sctp_insert_list(&asoc->outqueue.abandoned,
366 &chk->transmitted_list);
367
368 asoc->sent_cnt_removable--;
369 asoc->abandoned_sent[SCTP_PR_INDEX(PRIO)]++;
370
371 if (!chk->tsn_gap_acked) {
372 if (chk->transport)
373 chk->transport->flight_size -=
374 sctp_data_size(chk);
375 asoc->outqueue.outstanding_bytes -= sctp_data_size(chk);
376 }
377
378 msg_len -= SCTP_DATA_SNDSIZE(chk) +
379 sizeof(struct sk_buff) +
380 sizeof(struct sctp_chunk);
381 if (msg_len <= 0)
382 break;
383 }
384
385 return msg_len;
386}
387
388static int sctp_prsctp_prune_unsent(struct sctp_association *asoc,
389 struct sctp_sndrcvinfo *sinfo,
390 struct list_head *queue, int msg_len)
391{
392 struct sctp_chunk *chk, *temp;
393
394 list_for_each_entry_safe(chk, temp, queue, list) {
395 if (!SCTP_PR_PRIO_ENABLED(chk->sinfo.sinfo_flags) ||
396 chk->prsctp_param <= sinfo->sinfo_timetolive)
397 continue;
398
399 list_del_init(&chk->list);
400 asoc->sent_cnt_removable--;
401 asoc->abandoned_unsent[SCTP_PR_INDEX(PRIO)]++;
402
403 msg_len -= SCTP_DATA_SNDSIZE(chk) +
404 sizeof(struct sk_buff) +
405 sizeof(struct sctp_chunk);
406 sctp_chunk_free(chk);
407 if (msg_len <= 0)
408 break;
409 }
410
411 return msg_len;
412}
413
414/* Abandon the chunks according their priorities */
415void sctp_prsctp_prune(struct sctp_association *asoc,
416 struct sctp_sndrcvinfo *sinfo, int msg_len)
417{
418 struct sctp_transport *transport;
419
420 if (!asoc->prsctp_enable || !asoc->sent_cnt_removable)
421 return;
422
423 msg_len = sctp_prsctp_prune_sent(asoc, sinfo,
424 &asoc->outqueue.retransmit,
425 msg_len);
426 if (msg_len <= 0)
427 return;
428
429 list_for_each_entry(transport, &asoc->peer.transport_addr_list,
430 transports) {
431 msg_len = sctp_prsctp_prune_sent(asoc, sinfo,
432 &transport->transmitted,
433 msg_len);
434 if (msg_len <= 0)
435 return;
436 }
437
438 sctp_prsctp_prune_unsent(asoc, sinfo,
439 &asoc->outqueue.out_chunk_list,
440 msg_len);
441}
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443/* Mark all the eligible packets on a transport for retransmission. */
444void sctp_retransmit_mark(struct sctp_outq *q,
445 struct sctp_transport *transport,
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400446 __u8 reason)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
448 struct list_head *lchunk, *ltemp;
449 struct sctp_chunk *chunk;
450
451 /* Walk through the specified transmitted queue. */
452 list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
453 chunk = list_entry(lchunk, struct sctp_chunk,
454 transmitted_list);
455
456 /* If the chunk is abandoned, move it to abandoned list. */
457 if (sctp_chunk_abandoned(chunk)) {
458 list_del_init(lchunk);
459 sctp_insert_list(&q->abandoned, lchunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -0800460
461 /* If this chunk has not been previousely acked,
462 * stop considering it 'outstanding'. Our peer
463 * will most likely never see it since it will
464 * not be retransmitted
465 */
466 if (!chunk->tsn_gap_acked) {
Vlad Yasevich31b02e12009-09-04 18:21:00 -0400467 if (chunk->transport)
468 chunk->transport->flight_size -=
469 sctp_data_size(chunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -0800470 q->outstanding_bytes -= sctp_data_size(chunk);
Thomas Grafa76c0ad2011-12-19 04:11:40 +0000471 q->asoc->peer.rwnd += sctp_data_size(chunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -0800472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 continue;
474 }
475
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400476 /* If we are doing retransmission due to a timeout or pmtu
477 * discovery, only the chunks that are not yet acked should
478 * be added to the retransmit queue.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 */
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400480 if ((reason == SCTP_RTXR_FAST_RTX &&
Neil Hormanc226ef92008-07-25 12:44:09 -0400481 (chunk->fast_retransmit == SCTP_NEED_FRTX)) ||
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400482 (reason != SCTP_RTXR_FAST_RTX && !chunk->tsn_gap_acked)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 /* RFC 2960 6.2.1 Processing a Received SACK
484 *
485 * C) Any time a DATA chunk is marked for
486 * retransmission (via either T3-rtx timer expiration
487 * (Section 6.3.3) or via fast retransmit
488 * (Section 7.2.4)), add the data size of those
489 * chunks to the rwnd.
490 */
Thomas Grafa76c0ad2011-12-19 04:11:40 +0000491 q->asoc->peer.rwnd += sctp_data_size(chunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 q->outstanding_bytes -= sctp_data_size(chunk);
Vlad Yasevich31b02e12009-09-04 18:21:00 -0400493 if (chunk->transport)
494 transport->flight_size -= sctp_data_size(chunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 /* sctpimpguide-05 Section 2.8.2
497 * M5) If a T3-rtx timer expires, the
498 * 'TSN.Missing.Report' of all affected TSNs is set
499 * to 0.
500 */
501 chunk->tsn_missing_report = 0;
502
503 /* If a chunk that is being used for RTT measurement
504 * has to be retransmitted, we cannot use this chunk
505 * anymore for RTT measurements. Reset rto_pending so
506 * that a new RTT measurement is started when a new
507 * data chunk is sent.
508 */
509 if (chunk->rtt_in_progress) {
510 chunk->rtt_in_progress = 0;
511 transport->rto_pending = 0;
512 }
513
Xufeng Zhang6eabca52013-11-25 11:26:57 +0800514 chunk->resent = 1;
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 /* Move the chunk to the retransmit queue. The chunks
517 * on the retransmit queue are always kept in order.
518 */
519 list_del_init(lchunk);
520 sctp_insert_list(&q->retransmit, lchunk);
521 }
522 }
523
Daniel Borkmannbb333812013-06-28 19:49:40 +0200524 pr_debug("%s: transport:%p, reason:%d, cwnd:%d, ssthresh:%d, "
525 "flight_size:%d, pba:%d\n", __func__, transport, reason,
526 transport->cwnd, transport->ssthresh, transport->flight_size,
527 transport->partial_bytes_acked);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528}
529
530/* Mark all the eligible packets on a transport for retransmission and force
531 * one packet out.
532 */
533void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
534 sctp_retransmit_reason_t reason)
535{
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000536 struct net *net = sock_net(q->asoc->base.sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
wangweidongcb3f8372013-12-23 12:16:50 +0800539 switch (reason) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 case SCTP_RTXR_T3_RTX:
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000541 SCTP_INC_STATS(net, SCTP_MIB_T3_RETRANSMITS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
543 /* Update the retran path if the T3-rtx timer has expired for
544 * the current retran path.
545 */
546 if (transport == transport->asoc->peer.retran_path)
547 sctp_assoc_update_retran_path(transport->asoc);
Neil Horman58fbbed2008-02-29 11:40:56 -0800548 transport->asoc->rtx_data_chunks +=
549 transport->asoc->unack_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 break;
551 case SCTP_RTXR_FAST_RTX:
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000552 SCTP_INC_STATS(net, SCTP_MIB_FAST_RETRANSMITS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700554 q->fast_rtx = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 break;
556 case SCTP_RTXR_PMTUD:
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000557 SCTP_INC_STATS(net, SCTP_MIB_PMTUD_RETRANSMITS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 break;
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400559 case SCTP_RTXR_T1_RTX:
Eric W. Biedermanb01a2402012-08-06 08:47:55 +0000560 SCTP_INC_STATS(net, SCTP_MIB_T1_RETRANSMITS);
Neil Horman58fbbed2008-02-29 11:40:56 -0800561 transport->asoc->init_retries++;
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400562 break;
Sridhar Samudralaac0b0462006-08-22 00:15:33 -0700563 default:
564 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
566
Vlad Yasevichb6157d82007-10-24 15:59:16 -0400567 sctp_retransmit_mark(q, transport, reason);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 /* PR-SCTP A5) Any time the T3-rtx timer expires, on any destination,
570 * the sender SHOULD try to advance the "Advanced.Peer.Ack.Point" by
571 * following the procedures outlined in C1 - C5.
572 */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700573 if (reason == SCTP_RTXR_T3_RTX)
574 sctp_generate_fwdtsn(q, q->asoc->ctsn_ack_point);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700576 /* Flush the queues only on timeout, since fast_rtx is only
577 * triggered during sack processing and the queue
578 * will be flushed at the end.
579 */
580 if (reason != SCTP_RTXR_FAST_RTX)
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300581 error = sctp_outq_flush(q, /* rtx_timeout */ 1, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 if (error)
584 q->asoc->base.sk->sk_err = -error;
585}
586
587/*
588 * Transmit DATA chunks on the retransmit queue. Upon return from
589 * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
590 * need to be transmitted by the caller.
591 * We assume that pkt->transport has already been set.
592 *
593 * The return value is a normal kernel error return value.
594 */
595static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
596 int rtx_timeout, int *start_timer)
597{
598 struct list_head *lqueue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 struct sctp_transport *transport = pkt->transport;
600 sctp_xmit_t status;
601 struct sctp_chunk *chunk, *chunk1;
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700602 int fast_rtx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 int error = 0;
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700604 int timer = 0;
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700605 int done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 lqueue = &q->retransmit;
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700608 fast_rtx = q->fast_rtx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700610 /* This loop handles time-out retransmissions, fast retransmissions,
611 * and retransmissions due to opening of whindow.
612 *
613 * RFC 2960 6.3.3 Handle T3-rtx Expiration
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 *
615 * E3) Determine how many of the earliest (i.e., lowest TSN)
616 * outstanding DATA chunks for the address for which the
617 * T3-rtx has expired will fit into a single packet, subject
618 * to the MTU constraint for the path corresponding to the
619 * destination transport address to which the retransmission
620 * is being sent (this may be different from the address for
621 * which the timer expires [see Section 6.4]). Call this value
622 * K. Bundle and retransmit those K DATA chunks in a single
623 * packet to the destination endpoint.
624 *
625 * [Just to be painfully clear, if we are retransmitting
626 * because a timeout just happened, we should send only ONE
627 * packet of retransmitted data.]
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700628 *
629 * For fast retransmissions we also send only ONE packet. However,
630 * if we are just flushing the queue due to open window, we'll
631 * try to send as much as possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700633 list_for_each_entry_safe(chunk, chunk1, lqueue, transmitted_list) {
Wei Yongjun4c6a6f42011-04-19 21:32:28 +0000634 /* If the chunk is abandoned, move it to abandoned list. */
635 if (sctp_chunk_abandoned(chunk)) {
636 list_del_init(&chunk->transmitted_list);
637 sctp_insert_list(&q->abandoned,
638 &chunk->transmitted_list);
639 continue;
640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 /* Make sure that Gap Acked TSNs are not retransmitted. A
643 * simple approach is just to move such TSNs out of the
644 * way and into a 'transmitted' queue and skip to the
645 * next chunk.
646 */
647 if (chunk->tsn_gap_acked) {
Wei Yongjun54a27922012-09-03 23:58:16 +0000648 list_move_tail(&chunk->transmitted_list,
649 &transport->transmitted);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 continue;
651 }
652
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700653 /* If we are doing fast retransmit, ignore non-fast_rtransmit
654 * chunks
655 */
656 if (fast_rtx && !chunk->fast_retransmit)
657 continue;
658
Wei Yongjunbc4f8412010-04-30 22:38:53 -0400659redo:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 /* Attempt to append this chunk to the packet. */
661 status = sctp_packet_append_chunk(pkt, chunk);
662
663 switch (status) {
664 case SCTP_XMIT_PMTU_FULL:
Wei Yongjunbc4f8412010-04-30 22:38:53 -0400665 if (!pkt->has_data && !pkt->has_cookie_echo) {
666 /* If this packet did not contain DATA then
667 * retransmission did not happen, so do it
668 * again. We'll ignore the error here since
669 * control chunks are already freed so there
670 * is nothing we can do.
671 */
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300672 sctp_packet_transmit(pkt, GFP_ATOMIC);
Wei Yongjunbc4f8412010-04-30 22:38:53 -0400673 goto redo;
674 }
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 /* Send this packet. */
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300677 error = sctp_packet_transmit(pkt, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679 /* If we are retransmitting, we should only
680 * send a single packet.
Vlad Yasevichf246a7b2011-04-18 19:13:56 +0000681 * Otherwise, try appending this chunk again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700683 if (rtx_timeout || fast_rtx)
684 done = 1;
Vlad Yasevichf246a7b2011-04-18 19:13:56 +0000685 else
686 goto redo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700688 /* Bundle next chunk in the next round. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 break;
690
691 case SCTP_XMIT_RWND_FULL:
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900692 /* Send this packet. */
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300693 error = sctp_packet_transmit(pkt, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 /* Stop sending DATA as there is no more room
696 * at the receiver.
697 */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700698 done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 break;
700
David Laight526cbef2014-07-22 08:59:14 +0000701 case SCTP_XMIT_DELAY:
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900702 /* Send this packet. */
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300703 error = sctp_packet_transmit(pkt, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 /* Stop sending DATA because of nagle delay. */
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700706 done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 break;
708
709 default:
710 /* The append was successful, so add this chunk to
711 * the transmitted list.
712 */
Wei Yongjun54a27922012-09-03 23:58:16 +0000713 list_move_tail(&chunk->transmitted_list,
714 &transport->transmitted);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900716 /* Mark the chunk as ineligible for fast retransmit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 * after it is retransmitted.
718 */
Neil Hormanc226ef92008-07-25 12:44:09 -0400719 if (chunk->fast_retransmit == SCTP_NEED_FRTX)
720 chunk->fast_retransmit = SCTP_DONT_FRTX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Michele Baldessari196d6752012-12-01 04:49:42 +0000722 q->asoc->stats.rtxchunks++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700724 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700726 /* Set the timer if there were no errors */
727 if (!error && !timer)
728 timer = 1;
729
Vlad Yasevich8b750ce2008-06-04 12:39:36 -0700730 if (done)
731 break;
732 }
733
734 /* If we are here due to a retransmit timeout or a fast
735 * retransmit and if there are any chunks left in the retransmit
736 * queue that could not fit in the PMTU sized packet, they need
737 * to be marked as ineligible for a subsequent fast retransmit.
738 */
739 if (rtx_timeout || fast_rtx) {
740 list_for_each_entry(chunk1, lqueue, transmitted_list) {
Neil Hormanc226ef92008-07-25 12:44:09 -0400741 if (chunk1->fast_retransmit == SCTP_NEED_FRTX)
742 chunk1->fast_retransmit = SCTP_DONT_FRTX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 }
744 }
745
Vlad Yasevich62aeaff2008-06-04 12:39:11 -0700746 *start_timer = timer;
747
748 /* Clear fast retransmit hint */
749 if (fast_rtx)
750 q->fast_rtx = 0;
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 return error;
753}
754
755/* Cork the outqueue so queued chunks are really queued. */
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300756int sctp_outq_uncork(struct sctp_outq *q, gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Vlad Yasevich7d54dc62007-11-09 11:43:41 -0500758 if (q->cork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 q->cork = 0;
Daniel Borkmanndacda322013-04-16 11:07:14 +0000760
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300761 return sctp_outq_flush(q, 0, gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762}
763
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700764
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765/*
766 * Try to flush an outqueue.
767 *
768 * Description: Send everything in q which we legally can, subject to
769 * congestion limitations.
770 * * Note: This function can be called from multiple contexts so appropriate
771 * locking concerns must be made. Today we use the sock lock to protect
772 * this function.
773 */
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300774static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
776 struct sctp_packet *packet;
777 struct sctp_packet singleton;
778 struct sctp_association *asoc = q->asoc;
779 __u16 sport = asoc->base.bind_addr.port;
780 __u16 dport = asoc->peer.port;
781 __u32 vtag = asoc->peer.i.init_tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 struct sctp_transport *transport = NULL;
783 struct sctp_transport *new_transport;
David S. Miller79af02c2005-07-08 21:47:49 -0700784 struct sctp_chunk *chunk, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 sctp_xmit_t status;
786 int error = 0;
787 int start_timer = 0;
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700788 int one_packet = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 /* These transports have chunks to send. */
791 struct list_head transport_list;
792 struct list_head *ltransport;
793
794 INIT_LIST_HEAD(&transport_list);
795 packet = NULL;
796
797 /*
798 * 6.10 Bundling
799 * ...
800 * When bundling control chunks with DATA chunks, an
801 * endpoint MUST place control chunks first in the outbound
802 * SCTP packet. The transmitter MUST transmit DATA chunks
803 * within a SCTP packet in increasing order of TSN.
804 * ...
805 */
806
David S. Miller79af02c2005-07-08 21:47:49 -0700807 list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) {
Michio Honda8a07eb02011-04-26 20:19:36 +0900808 /* RFC 5061, 5.3
809 * F1) This means that until such time as the ASCONF
810 * containing the add is acknowledged, the sender MUST
811 * NOT use the new IP address as a source for ANY SCTP
812 * packet except on carrying an ASCONF Chunk.
813 */
814 if (asoc->src_out_of_asoc_ok &&
815 chunk->chunk_hdr->type != SCTP_CID_ASCONF)
816 continue;
817
David S. Miller79af02c2005-07-08 21:47:49 -0700818 list_del_init(&chunk->list);
819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 /* Pick the right transport to use. */
821 new_transport = chunk->transport;
822
823 if (!new_transport) {
Vlad Yasevicha08de642007-12-20 14:11:47 -0800824 /*
825 * If we have a prior transport pointer, see if
826 * the destination address of the chunk
827 * matches the destination address of the
828 * current transport. If not a match, then
829 * try to look up the transport with a given
830 * destination address. We do this because
831 * after processing ASCONFs, we may have new
832 * transports created.
833 */
834 if (transport &&
835 sctp_cmp_addr_exact(&chunk->dest,
836 &transport->ipaddr))
837 new_transport = transport;
838 else
839 new_transport = sctp_assoc_lookup_paddr(asoc,
840 &chunk->dest);
841
842 /* if we still don't have a new transport, then
843 * use the current active path.
844 */
845 if (!new_transport)
846 new_transport = asoc->peer.active_path;
Sridhar Samudralaad8fec12006-07-21 14:48:50 -0700847 } else if ((new_transport->state == SCTP_INACTIVE) ||
Neil Horman5aa93bc2012-07-21 07:56:07 +0000848 (new_transport->state == SCTP_UNCONFIRMED) ||
849 (new_transport->state == SCTP_PF)) {
Frank Filz3f7a87d2005-06-20 13:14:57 -0700850 /* If the chunk is Heartbeat or Heartbeat Ack,
851 * send it to chunk->transport, even if it's
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 * inactive.
853 *
854 * 3.3.6 Heartbeat Acknowledgement:
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900855 * ...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 * A HEARTBEAT ACK is always sent to the source IP
857 * address of the IP datagram containing the
858 * HEARTBEAT chunk to which this ack is responding.
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900859 * ...
Vlad Yasevicha08de642007-12-20 14:11:47 -0800860 *
861 * ASCONF_ACKs also must be sent to the source.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 */
863 if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT &&
Vlad Yasevicha08de642007-12-20 14:11:47 -0800864 chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT_ACK &&
865 chunk->chunk_hdr->type != SCTP_CID_ASCONF_ACK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 new_transport = asoc->peer.active_path;
867 }
868
869 /* Are we switching transports?
870 * Take care of transport locks.
871 */
872 if (new_transport != transport) {
873 transport = new_transport;
874 if (list_empty(&transport->send_ready)) {
875 list_add_tail(&transport->send_ready,
876 &transport_list);
877 }
878 packet = &transport->packet;
879 sctp_packet_config(packet, vtag,
880 asoc->peer.ecn_capable);
881 }
882
883 switch (chunk->chunk_hdr->type) {
884 /*
885 * 6.10 Bundling
886 * ...
887 * An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
888 * COMPLETE with any other chunks. [Send them immediately.]
889 */
890 case SCTP_CID_INIT:
891 case SCTP_CID_INIT_ACK:
892 case SCTP_CID_SHUTDOWN_COMPLETE:
893 sctp_packet_init(&singleton, transport, sport, dport);
894 sctp_packet_config(&singleton, vtag, 0);
895 sctp_packet_append_chunk(&singleton, chunk);
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300896 error = sctp_packet_transmit(&singleton, gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 if (error < 0)
898 return error;
899 break;
900
901 case SCTP_CID_ABORT:
Gui Jianfengf4ad85c2008-04-12 18:39:34 -0700902 if (sctp_test_T_bit(chunk)) {
903 packet->vtag = asoc->c.my_vtag;
904 }
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700905 /* The following chunks are "response" chunks, i.e.
906 * they are generated in response to something we
907 * received. If we are sending these, then we can
908 * send only 1 packet containing these chunks.
909 */
910 case SCTP_CID_HEARTBEAT_ACK:
911 case SCTP_CID_SHUTDOWN_ACK:
912 case SCTP_CID_COOKIE_ACK:
913 case SCTP_CID_COOKIE_ECHO:
914 case SCTP_CID_ERROR:
915 case SCTP_CID_ECN_CWR:
916 case SCTP_CID_ASCONF_ACK:
917 one_packet = 1;
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300918 /* Fall through */
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 case SCTP_CID_SACK:
921 case SCTP_CID_HEARTBEAT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 case SCTP_CID_SHUTDOWN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 case SCTP_CID_ECN_ECNE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 case SCTP_CID_ASCONF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 case SCTP_CID_FWD_TSN:
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700926 status = sctp_packet_transmit_chunk(packet, chunk,
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -0300927 one_packet, gfp);
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700928 if (status != SCTP_XMIT_OK) {
929 /* put the chunk back */
930 list_add(&chunk->list, &q->control_chunk_list);
Michele Baldessari196d6752012-12-01 04:49:42 +0000931 } else {
932 asoc->stats.octrlchunks++;
Wei Yongjunbd69b982010-04-30 21:42:43 -0400933 /* PR-SCTP C5) If a FORWARD TSN is sent, the
934 * sender MUST assure that at least one T3-rtx
935 * timer is running.
936 */
Marcelo Ricardo Leitnerba6f5e32016-04-06 15:15:19 -0300937 if (chunk->chunk_hdr->type == SCTP_CID_FWD_TSN) {
938 sctp_transport_reset_t3_rtx(transport);
939 transport->last_time_sent = jiffies;
940 }
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 break;
943
944 default:
945 /* We built a chunk with an illegal type! */
946 BUG();
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 }
949
Michio Honda8a07eb02011-04-26 20:19:36 +0900950 if (q->asoc->src_out_of_asoc_ok)
951 goto sctp_flush_out;
952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 /* Is it OK to send data chunks? */
954 switch (asoc->state) {
955 case SCTP_STATE_COOKIE_ECHOED:
956 /* Only allow bundling when this packet has a COOKIE-ECHO
957 * chunk.
958 */
959 if (!packet || !packet->has_cookie_echo)
960 break;
961
962 /* fallthru */
963 case SCTP_STATE_ESTABLISHED:
964 case SCTP_STATE_SHUTDOWN_PENDING:
965 case SCTP_STATE_SHUTDOWN_RECEIVED:
966 /*
967 * RFC 2960 6.1 Transmission of DATA Chunks
968 *
969 * C) When the time comes for the sender to transmit,
970 * before sending new DATA chunks, the sender MUST
971 * first transmit any outstanding DATA chunks which
972 * are marked for retransmission (limited by the
973 * current cwnd).
974 */
975 if (!list_empty(&q->retransmit)) {
Michio Hondaf207c052011-06-16 10:54:23 +0900976 if (asoc->peer.retran_path->state == SCTP_UNCONFIRMED)
977 goto sctp_flush_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 if (transport == asoc->peer.retran_path)
979 goto retran;
980
981 /* Switch transports & prepare the packet. */
982
983 transport = asoc->peer.retran_path;
984
985 if (list_empty(&transport->send_ready)) {
986 list_add_tail(&transport->send_ready,
987 &transport_list);
988 }
989
990 packet = &transport->packet;
991 sctp_packet_config(packet, vtag,
992 asoc->peer.ecn_capable);
993 retran:
994 error = sctp_outq_flush_rtx(q, packet,
995 rtx_timeout, &start_timer);
996
Marcelo Ricardo Leitnerba6f5e32016-04-06 15:15:19 -0300997 if (start_timer) {
998 sctp_transport_reset_t3_rtx(transport);
999 transport->last_time_sent = jiffies;
1000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 /* This can happen on COOKIE-ECHO resend. Only
1003 * one chunk can get bundled with a COOKIE-ECHO.
1004 */
1005 if (packet->has_cookie_echo)
1006 goto sctp_flush_out;
1007
1008 /* Don't send new data if there is still data
1009 * waiting to retransmit.
1010 */
1011 if (!list_empty(&q->retransmit))
1012 goto sctp_flush_out;
1013 }
1014
Vlad Yasevich46d5a802009-11-23 15:54:00 -05001015 /* Apply Max.Burst limitation to the current transport in
1016 * case it will be used for new data. We are going to
1017 * rest it before we return, but we want to apply the limit
1018 * to the currently queued data.
1019 */
1020 if (transport)
1021 sctp_transport_burst_limited(transport);
1022
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 /* Finally, transmit new packets. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
1025 /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
1026 * stream identifier.
1027 */
1028 if (chunk->sinfo.sinfo_stream >=
1029 asoc->c.sinit_num_ostreams) {
1030
1031 /* Mark as failed send. */
1032 sctp_chunk_fail(chunk, SCTP_ERROR_INV_STRM);
Xin Long8dbdf1f2016-07-09 19:47:45 +08001033 if (asoc->prsctp_enable &&
1034 SCTP_PR_PRIO_ENABLED(chunk->sinfo.sinfo_flags))
1035 asoc->sent_cnt_removable--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 sctp_chunk_free(chunk);
1037 continue;
1038 }
1039
1040 /* Has this chunk expired? */
1041 if (sctp_chunk_abandoned(chunk)) {
1042 sctp_chunk_fail(chunk, 0);
1043 sctp_chunk_free(chunk);
1044 continue;
1045 }
1046
1047 /* If there is a specified transport, use it.
1048 * Otherwise, we want to use the active path.
1049 */
1050 new_transport = chunk->transport;
Frank Filz3f7a87d2005-06-20 13:14:57 -07001051 if (!new_transport ||
Sridhar Samudralaad8fec12006-07-21 14:48:50 -07001052 ((new_transport->state == SCTP_INACTIVE) ||
Neil Horman5aa93bc2012-07-21 07:56:07 +00001053 (new_transport->state == SCTP_UNCONFIRMED) ||
1054 (new_transport->state == SCTP_PF)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 new_transport = asoc->peer.active_path;
Marcelo Ricardo Leitner31b055e2016-03-18 18:39:19 -03001056 if (new_transport->state == SCTP_UNCONFIRMED) {
1057 WARN_ONCE(1, "Atempt to send packet on unconfirmed path.");
1058 sctp_chunk_fail(chunk, 0);
1059 sctp_chunk_free(chunk);
Michio Hondaf207c052011-06-16 10:54:23 +09001060 continue;
Marcelo Ricardo Leitner31b055e2016-03-18 18:39:19 -03001061 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 /* Change packets if necessary. */
1064 if (new_transport != transport) {
1065 transport = new_transport;
1066
1067 /* Schedule to have this transport's
1068 * packet flushed.
1069 */
1070 if (list_empty(&transport->send_ready)) {
1071 list_add_tail(&transport->send_ready,
1072 &transport_list);
1073 }
1074
1075 packet = &transport->packet;
1076 sctp_packet_config(packet, vtag,
1077 asoc->peer.ecn_capable);
Vlad Yasevich46d5a802009-11-23 15:54:00 -05001078 /* We've switched transports, so apply the
1079 * Burst limit to the new transport.
1080 */
1081 sctp_transport_burst_limited(transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 }
1083
Daniel Borkmannbb333812013-06-28 19:49:40 +02001084 pr_debug("%s: outq:%p, chunk:%p[%s], tx-tsn:0x%x skb->head:%p "
1085 "skb->users:%d\n",
1086 __func__, q, chunk, chunk && chunk->chunk_hdr ?
1087 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
1088 "illegal chunk", ntohl(chunk->subh.data_hdr->tsn),
1089 chunk->skb ? chunk->skb->head : NULL, chunk->skb ?
1090 atomic_read(&chunk->skb->users) : -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 /* Add the chunk to the packet. */
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -03001093 status = sctp_packet_transmit_chunk(packet, chunk, 0, gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
1095 switch (status) {
1096 case SCTP_XMIT_PMTU_FULL:
1097 case SCTP_XMIT_RWND_FULL:
David Laight526cbef2014-07-22 08:59:14 +00001098 case SCTP_XMIT_DELAY:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 /* We could not append this chunk, so put
1100 * the chunk back on the output queue.
1101 */
Daniel Borkmannbb333812013-06-28 19:49:40 +02001102 pr_debug("%s: could not transmit tsn:0x%x, status:%d\n",
1103 __func__, ntohl(chunk->subh.data_hdr->tsn),
1104 status);
1105
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 sctp_outq_head_data(q, chunk);
1107 goto sctp_flush_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109 case SCTP_XMIT_OK:
Wei Yongjunb93d6472009-11-23 15:53:56 -05001110 /* The sender is in the SHUTDOWN-PENDING state,
1111 * The sender MAY set the I-bit in the DATA
1112 * chunk header.
1113 */
1114 if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
1115 chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
Michele Baldessari196d6752012-12-01 04:49:42 +00001116 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
1117 asoc->stats.ouodchunks++;
1118 else
1119 asoc->stats.oodchunks++;
Wei Yongjunb93d6472009-11-23 15:53:56 -05001120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 break;
1122
1123 default:
1124 BUG();
1125 }
1126
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001127 /* BUG: We assume that the sctp_packet_transmit()
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 * call below will succeed all the time and add the
1129 * chunk to the transmitted list and restart the
1130 * timers.
1131 * It is possible that the call can fail under OOM
1132 * conditions.
1133 *
1134 * Is this really a problem? Won't this behave
1135 * like a lost TSN?
1136 */
1137 list_add_tail(&chunk->transmitted_list,
1138 &transport->transmitted);
1139
Marcelo Ricardo Leitnerba6f5e32016-04-06 15:15:19 -03001140 sctp_transport_reset_t3_rtx(transport);
1141 transport->last_time_sent = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 /* Only let one DATA chunk get bundled with a
1144 * COOKIE-ECHO chunk.
1145 */
1146 if (packet->has_cookie_echo)
1147 goto sctp_flush_out;
1148 }
1149 break;
1150
1151 default:
1152 /* Do nothing. */
1153 break;
1154 }
1155
1156sctp_flush_out:
1157
1158 /* Before returning, examine all the transports touched in
1159 * this call. Right now, we bluntly force clear all the
1160 * transports. Things might change after we implement Nagle.
1161 * But such an examination is still required.
1162 *
1163 * --xguo
1164 */
wangweidongcb3f8372013-12-23 12:16:50 +08001165 while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 struct sctp_transport *t = list_entry(ltransport,
1167 struct sctp_transport,
1168 send_ready);
1169 packet = &t->packet;
1170 if (!sctp_packet_empty(packet))
Marcelo Ricardo Leitnercea87682016-03-10 18:33:07 -03001171 error = sctp_packet_transmit(packet, gfp);
Vlad Yasevich46d5a802009-11-23 15:54:00 -05001172
1173 /* Clear the burst limited state, if any */
1174 sctp_transport_burst_reset(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
1176
1177 return error;
1178}
1179
1180/* Update unack_data based on the incoming SACK chunk */
1181static void sctp_sack_update_unack_data(struct sctp_association *assoc,
1182 struct sctp_sackhdr *sack)
1183{
1184 sctp_sack_variable_t *frags;
1185 __u16 unack_data;
1186 int i;
1187
1188 unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
1189
1190 frags = sack->variable;
1191 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
1192 unack_data -= ((ntohs(frags[i].gab.end) -
1193 ntohs(frags[i].gab.start) + 1));
1194 }
1195
1196 assoc->unack_data = unack_data;
1197}
1198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199/* This is where we REALLY process a SACK.
1200 *
1201 * Process the SACK against the outqueue. Mostly, this just frees
1202 * things off the transmitted queue.
1203 */
Nicolas Dichteledfee032012-10-03 05:43:22 +00001204int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205{
1206 struct sctp_association *asoc = q->asoc;
Nicolas Dichteledfee032012-10-03 05:43:22 +00001207 struct sctp_sackhdr *sack = chunk->subh.sack_hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 struct sctp_transport *transport;
1209 struct sctp_chunk *tchunk = NULL;
Robert P. J. Day9dbc15f2008-04-12 18:54:24 -07001210 struct list_head *lchunk, *transport_list, *temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 sctp_sack_variable_t *frags = sack->variable;
1212 __u32 sack_ctsn, ctsn, tsn;
1213 __u32 highest_tsn, highest_new_tsn;
1214 __u32 sack_a_rwnd;
Eric Dumazet95c96172012-04-15 05:58:06 +00001215 unsigned int outstanding;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 struct sctp_transport *primary = asoc->peer.primary_path;
1217 int count_of_newacks = 0;
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001218 int gap_ack_blocks;
Vlad Yasevichea862c82010-04-30 22:41:10 -04001219 u8 accum_moved = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 /* Grab the association's destination address list. */
1222 transport_list = &asoc->peer.transport_addr_list;
1223
1224 sack_ctsn = ntohl(sack->cum_tsn_ack);
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001225 gap_ack_blocks = ntohs(sack->num_gap_ack_blocks);
Michele Baldessari196d6752012-12-01 04:49:42 +00001226 asoc->stats.gapcnt += gap_ack_blocks;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 /*
1228 * SFR-CACC algorithm:
1229 * On receipt of a SACK the sender SHOULD execute the
1230 * following statements.
1231 *
1232 * 1) If the cumulative ack in the SACK passes next tsn_at_change
1233 * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
1234 * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
1235 * all destinations.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
1237 * is set the receiver of the SACK MUST take the following actions:
1238 *
1239 * A) Initialize the cacc_saw_newack to 0 for all destination
1240 * addresses.
Vlad Yasevichab5216a2008-06-19 18:17:24 -04001241 *
1242 * Only bother if changeover_active is set. Otherwise, this is
1243 * totally suboptimal to do on every SACK.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 */
Vlad Yasevichab5216a2008-06-19 18:17:24 -04001245 if (primary->cacc.changeover_active) {
1246 u8 clear_cycling = 0;
1247
1248 if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
1249 primary->cacc.changeover_active = 0;
1250 clear_cycling = 1;
1251 }
1252
1253 if (clear_cycling || gap_ack_blocks) {
1254 list_for_each_entry(transport, transport_list,
1255 transports) {
1256 if (clear_cycling)
1257 transport->cacc.cycling_changeover = 0;
1258 if (gap_ack_blocks)
1259 transport->cacc.cacc_saw_newack = 0;
1260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 }
1262 }
1263
1264 /* Get the highest TSN in the sack. */
1265 highest_tsn = sack_ctsn;
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001266 if (gap_ack_blocks)
1267 highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Vlad Yasevichbfa0d982010-04-30 22:41:10 -04001269 if (TSN_lt(asoc->highest_sacked, highest_tsn))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 asoc->highest_sacked = highest_tsn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Vlad Yasevichbfa0d982010-04-30 22:41:10 -04001272 highest_new_tsn = sack_ctsn;
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 /* Run through the retransmit queue. Credit bytes received
1275 * and free those chunks that we can.
1276 */
Nicolas Dichteledfee032012-10-03 05:43:22 +00001277 sctp_check_transmitted(q, &q->retransmit, NULL, NULL, sack, &highest_new_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
1279 /* Run through the transmitted queue.
1280 * Credit bytes received and free those chunks which we can.
1281 *
1282 * This is a MASSIVE candidate for optimization.
1283 */
Robert P. J. Day9dbc15f2008-04-12 18:54:24 -07001284 list_for_each_entry(transport, transport_list, transports) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 sctp_check_transmitted(q, &transport->transmitted,
Nicolas Dichteledfee032012-10-03 05:43:22 +00001286 transport, &chunk->source, sack,
1287 &highest_new_tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 /*
1289 * SFR-CACC algorithm:
1290 * C) Let count_of_newacks be the number of
1291 * destinations for which cacc_saw_newack is set.
1292 */
1293 if (transport->cacc.cacc_saw_newack)
wangweidongcb3f8372013-12-23 12:16:50 +08001294 count_of_newacks++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 }
1296
Vlad Yasevichea862c82010-04-30 22:41:10 -04001297 /* Move the Cumulative TSN Ack Point if appropriate. */
1298 if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn)) {
1299 asoc->ctsn_ack_point = sack_ctsn;
1300 accum_moved = 1;
1301 }
1302
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001303 if (gap_ack_blocks) {
Vlad Yasevichea862c82010-04-30 22:41:10 -04001304
1305 if (asoc->fast_recovery && accum_moved)
1306 highest_new_tsn = highest_tsn;
1307
Vlad Yasevich2cd9b822008-06-19 17:59:13 -04001308 list_for_each_entry(transport, transport_list, transports)
1309 sctp_mark_missing(q, &transport->transmitted, transport,
1310 highest_new_tsn, count_of_newacks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
1312
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 /* Update unack_data field in the assoc. */
1314 sctp_sack_update_unack_data(asoc, sack);
1315
1316 ctsn = asoc->ctsn_ack_point;
1317
1318 /* Throw away stuff rotting on the sack queue. */
1319 list_for_each_safe(lchunk, temp, &q->sacked) {
1320 tchunk = list_entry(lchunk, struct sctp_chunk,
1321 transmitted_list);
1322 tsn = ntohl(tchunk->subh.data_hdr->tsn);
Vlad Yasevich5f9646c2008-02-05 14:23:44 -05001323 if (TSN_lte(tsn, ctsn)) {
1324 list_del_init(&tchunk->transmitted_list);
Xin Long8dbdf1f2016-07-09 19:47:45 +08001325 if (asoc->prsctp_enable &&
1326 SCTP_PR_PRIO_ENABLED(chunk->sinfo.sinfo_flags))
1327 asoc->sent_cnt_removable--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 sctp_chunk_free(tchunk);
Vlad Yasevich5f9646c2008-02-05 14:23:44 -05001329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
1331
1332 /* ii) Set rwnd equal to the newly received a_rwnd minus the
1333 * number of bytes still outstanding after processing the
1334 * Cumulative TSN Ack and the Gap Ack Blocks.
1335 */
1336
1337 sack_a_rwnd = ntohl(sack->a_rwnd);
lucien8a0d19c2015-12-05 15:35:36 +08001338 asoc->peer.zero_window_announced = !sack_a_rwnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 outstanding = q->outstanding_bytes;
1340
1341 if (outstanding < sack_a_rwnd)
1342 sack_a_rwnd -= outstanding;
1343 else
1344 sack_a_rwnd = 0;
1345
1346 asoc->peer.rwnd = sack_a_rwnd;
1347
1348 sctp_generate_fwdtsn(q, sack_ctsn);
1349
Daniel Borkmannbb333812013-06-28 19:49:40 +02001350 pr_debug("%s: sack cumulative tsn ack:0x%x\n", __func__, sack_ctsn);
1351 pr_debug("%s: cumulative tsn ack of assoc:%p is 0x%x, "
1352 "advertised peer ack point:0x%x\n", __func__, asoc, ctsn,
1353 asoc->adv_peer_ack_point);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Vlad Yasevich619a60e2014-01-02 14:39:44 -05001355 return sctp_outq_is_empty(q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356}
1357
Vlad Yasevich619a60e2014-01-02 14:39:44 -05001358/* Is the outqueue empty?
1359 * The queue is empty when we have not pending data, no in-flight data
1360 * and nothing pending retransmissions.
1361 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362int sctp_outq_is_empty(const struct sctp_outq *q)
1363{
Vlad Yasevich619a60e2014-01-02 14:39:44 -05001364 return q->out_qlen == 0 && q->outstanding_bytes == 0 &&
1365 list_empty(&q->retransmit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366}
1367
1368/********************************************************************
1369 * 2nd Level Abstractions
1370 ********************************************************************/
1371
1372/* Go through a transport's transmitted list or the association's retransmit
1373 * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
1374 * The retransmit list will not have an associated transport.
1375 *
1376 * I added coherent debug information output. --xguo
1377 *
1378 * Instead of printing 'sacked' or 'kept' for each TSN on the
1379 * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
1380 * KEPT TSN6-TSN7, etc.
1381 */
1382static void sctp_check_transmitted(struct sctp_outq *q,
1383 struct list_head *transmitted_queue,
1384 struct sctp_transport *transport,
Nicolas Dichteledfee032012-10-03 05:43:22 +00001385 union sctp_addr *saddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 struct sctp_sackhdr *sack,
Vlad Yasevichbfa0d982010-04-30 22:41:10 -04001387 __u32 *highest_new_tsn_in_sack)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388{
1389 struct list_head *lchunk;
1390 struct sctp_chunk *tchunk;
1391 struct list_head tlist;
1392 __u32 tsn;
1393 __u32 sack_ctsn;
1394 __u32 rtt;
1395 __u8 restart_timer = 0;
1396 int bytes_acked = 0;
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001397 int migrate_bytes = 0;
Daniel Borkmann8c2f4142013-07-09 16:17:04 +02001398 bool forward_progress = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 sack_ctsn = ntohl(sack->cum_tsn_ack);
1401
1402 INIT_LIST_HEAD(&tlist);
1403
1404 /* The while loop will skip empty transmitted queues. */
1405 while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
1406 tchunk = list_entry(lchunk, struct sctp_chunk,
1407 transmitted_list);
1408
1409 if (sctp_chunk_abandoned(tchunk)) {
1410 /* Move the chunk to abandoned list. */
1411 sctp_insert_list(&q->abandoned, lchunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -08001412
1413 /* If this chunk has not been acked, stop
1414 * considering it as 'outstanding'.
1415 */
1416 if (!tchunk->tsn_gap_acked) {
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001417 if (tchunk->transport)
1418 tchunk->transport->flight_size -=
1419 sctp_data_size(tchunk);
Vlad Yasevich8c4a2d42007-02-21 02:06:04 -08001420 q->outstanding_bytes -= sctp_data_size(tchunk);
1421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 continue;
1423 }
1424
1425 tsn = ntohl(tchunk->subh.data_hdr->tsn);
1426 if (sctp_acked(sack, tsn)) {
1427 /* If this queue is the retransmit queue, the
1428 * retransmit timer has already reclaimed
1429 * the outstanding bytes for this chunk, so only
1430 * count bytes associated with a transport.
1431 */
1432 if (transport) {
1433 /* If this chunk is being used for RTT
1434 * measurement, calculate the RTT and update
1435 * the RTO using this value.
1436 *
1437 * 6.3.1 C5) Karn's algorithm: RTT measurements
1438 * MUST NOT be made using packets that were
1439 * retransmitted (and thus for which it is
1440 * ambiguous whether the reply was for the
1441 * first instance of the packet or a later
1442 * instance).
1443 */
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001444 if (!tchunk->tsn_gap_acked &&
Xufeng Zhang6eabca52013-11-25 11:26:57 +08001445 !tchunk->resent &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 tchunk->rtt_in_progress) {
Vlad Yasevich4c9f5d52006-06-17 22:56:08 -07001447 tchunk->rtt_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 rtt = jiffies - tchunk->sent_at;
1449 sctp_transport_update_rto(transport,
1450 rtt);
1451 }
1452 }
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001453
1454 /* If the chunk hasn't been marked as ACKED,
1455 * mark it and account bytes_acked if the
1456 * chunk had a valid transport (it will not
1457 * have a transport if ASCONF had deleted it
1458 * while DATA was outstanding).
1459 */
1460 if (!tchunk->tsn_gap_acked) {
1461 tchunk->tsn_gap_acked = 1;
Chang Xiangzhongd6c41612013-11-21 22:56:28 +01001462 if (TSN_lt(*highest_new_tsn_in_sack, tsn))
1463 *highest_new_tsn_in_sack = tsn;
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001464 bytes_acked += sctp_data_size(tchunk);
1465 if (!tchunk->transport)
1466 migrate_bytes += sctp_data_size(tchunk);
Daniel Borkmann8c2f4142013-07-09 16:17:04 +02001467 forward_progress = true;
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001468 }
1469
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001470 if (TSN_lte(tsn, sack_ctsn)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 /* RFC 2960 6.3.2 Retransmission Timer Rules
1472 *
1473 * R3) Whenever a SACK is received
1474 * that acknowledges the DATA chunk
1475 * with the earliest outstanding TSN
1476 * for that address, restart T3-rtx
1477 * timer for that address with its
1478 * current RTO.
1479 */
1480 restart_timer = 1;
Daniel Borkmann8c2f4142013-07-09 16:17:04 +02001481 forward_progress = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
1483 if (!tchunk->tsn_gap_acked) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 /*
1485 * SFR-CACC algorithm:
1486 * 2) If the SACK contains gap acks
1487 * and the flag CHANGEOVER_ACTIVE is
1488 * set the receiver of the SACK MUST
1489 * take the following action:
1490 *
1491 * B) For each TSN t being acked that
1492 * has not been acked in any SACK so
1493 * far, set cacc_saw_newack to 1 for
1494 * the destination that the TSN was
1495 * sent to.
1496 */
1497 if (transport &&
1498 sack->num_gap_ack_blocks &&
1499 q->asoc->peer.primary_path->cacc.
1500 changeover_active)
1501 transport->cacc.cacc_saw_newack
1502 = 1;
1503 }
1504
1505 list_add_tail(&tchunk->transmitted_list,
1506 &q->sacked);
1507 } else {
1508 /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
1509 * M2) Each time a SACK arrives reporting
1510 * 'Stray DATA chunk(s)' record the highest TSN
1511 * reported as newly acknowledged, call this
1512 * value 'HighestTSNinSack'. A newly
1513 * acknowledged DATA chunk is one not
1514 * previously acknowledged in a SACK.
1515 *
1516 * When the SCTP sender of data receives a SACK
1517 * chunk that acknowledges, for the first time,
1518 * the receipt of a DATA chunk, all the still
1519 * unacknowledged DATA chunks whose TSN is
1520 * older than that newly acknowledged DATA
1521 * chunk, are qualified as 'Stray DATA chunks'.
1522 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 list_add_tail(lchunk, &tlist);
1524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 } else {
1526 if (tchunk->tsn_gap_acked) {
Daniel Borkmannbb333812013-06-28 19:49:40 +02001527 pr_debug("%s: receiver reneged on data TSN:0x%x\n",
1528 __func__, tsn);
1529
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 tchunk->tsn_gap_acked = 0;
1531
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001532 if (tchunk->transport)
1533 bytes_acked -= sctp_data_size(tchunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
1535 /* RFC 2960 6.3.2 Retransmission Timer Rules
1536 *
1537 * R4) Whenever a SACK is received missing a
1538 * TSN that was previously acknowledged via a
1539 * Gap Ack Block, start T3-rtx for the
1540 * destination address to which the DATA
1541 * chunk was originally
1542 * transmitted if it is not already running.
1543 */
1544 restart_timer = 1;
1545 }
1546
1547 list_add_tail(lchunk, &tlist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
1549 }
1550
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 if (transport) {
1552 if (bytes_acked) {
Thomas Graff8d96052011-07-07 00:28:35 +00001553 struct sctp_association *asoc = transport->asoc;
1554
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001555 /* We may have counted DATA that was migrated
1556 * to this transport due to DEL-IP operation.
1557 * Subtract those bytes, since the were never
1558 * send on this transport and shouldn't be
1559 * credited to this transport.
1560 */
1561 bytes_acked -= migrate_bytes;
1562
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 /* 8.2. When an outstanding TSN is acknowledged,
1564 * the endpoint shall clear the error counter of
1565 * the destination transport address to which the
1566 * DATA chunk was last sent.
1567 * The association's overall error counter is
1568 * also cleared.
1569 */
1570 transport->error_count = 0;
1571 transport->asoc->overall_error_count = 0;
Daniel Borkmann8c2f4142013-07-09 16:17:04 +02001572 forward_progress = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
Thomas Graff8d96052011-07-07 00:28:35 +00001574 /*
1575 * While in SHUTDOWN PENDING, we may have started
1576 * the T5 shutdown guard timer after reaching the
1577 * retransmission limit. Stop that timer as soon
1578 * as the receiver acknowledged any data.
1579 */
1580 if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING &&
1581 del_timer(&asoc->timers
1582 [SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]))
1583 sctp_association_put(asoc);
1584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 /* Mark the destination transport address as
1586 * active if it is not so marked.
1587 */
Nicolas Dichteledfee032012-10-03 05:43:22 +00001588 if ((transport->state == SCTP_INACTIVE ||
1589 transport->state == SCTP_UNCONFIRMED) &&
1590 sctp_cmp_addr_exact(&transport->ipaddr, saddr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 sctp_assoc_control_transport(
1592 transport->asoc,
1593 transport,
1594 SCTP_TRANSPORT_UP,
1595 SCTP_RECEIVED_SACK);
1596 }
1597
1598 sctp_transport_raise_cwnd(transport, sack_ctsn,
1599 bytes_acked);
1600
1601 transport->flight_size -= bytes_acked;
Gui Jianfeng8b73a072008-04-17 14:22:18 -07001602 if (transport->flight_size == 0)
1603 transport->partial_bytes_acked = 0;
Vlad Yasevich31b02e12009-09-04 18:21:00 -04001604 q->outstanding_bytes -= bytes_acked + migrate_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 } else {
1606 /* RFC 2960 6.1, sctpimpguide-06 2.15.2
1607 * When a sender is doing zero window probing, it
1608 * should not timeout the association if it continues
1609 * to receive new packets from the receiver. The
1610 * reason is that the receiver MAY keep its window
1611 * closed for an indefinite time.
1612 * A sender is doing zero window probing when the
1613 * receiver's advertised window is zero, and there is
1614 * only one data chunk in flight to the receiver.
Thomas Graff8d96052011-07-07 00:28:35 +00001615 *
1616 * Allow the association to timeout while in SHUTDOWN
1617 * PENDING or SHUTDOWN RECEIVED in case the receiver
1618 * stays in zero window mode forever.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 */
1620 if (!q->asoc->peer.rwnd &&
1621 !list_empty(&tlist) &&
Thomas Graff8d96052011-07-07 00:28:35 +00001622 (sack_ctsn+2 == q->asoc->next_tsn) &&
1623 q->asoc->state < SCTP_STATE_SHUTDOWN_PENDING) {
Daniel Borkmannbb333812013-06-28 19:49:40 +02001624 pr_debug("%s: sack received for zero window "
1625 "probe:%u\n", __func__, sack_ctsn);
1626
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 q->asoc->overall_error_count = 0;
1628 transport->error_count = 0;
1629 }
1630 }
1631
1632 /* RFC 2960 6.3.2 Retransmission Timer Rules
1633 *
1634 * R2) Whenever all outstanding data sent to an address have
1635 * been acknowledged, turn off the T3-rtx timer of that
1636 * address.
1637 */
1638 if (!transport->flight_size) {
Ying Xue25cc4ae2013-02-03 20:32:57 +00001639 if (del_timer(&transport->T3_rtx_timer))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 sctp_transport_put(transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 } else if (restart_timer) {
1642 if (!mod_timer(&transport->T3_rtx_timer,
1643 jiffies + transport->rto))
1644 sctp_transport_hold(transport);
1645 }
Daniel Borkmann8c2f4142013-07-09 16:17:04 +02001646
1647 if (forward_progress) {
1648 if (transport->dst)
1649 dst_confirm(transport->dst);
1650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 }
1652
1653 list_splice(&tlist, transmitted_queue);
1654}
1655
1656/* Mark chunks as missing and consequently may get retransmitted. */
1657static void sctp_mark_missing(struct sctp_outq *q,
1658 struct list_head *transmitted_queue,
1659 struct sctp_transport *transport,
1660 __u32 highest_new_tsn_in_sack,
1661 int count_of_newacks)
1662{
1663 struct sctp_chunk *chunk;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 __u32 tsn;
1665 char do_fast_retransmit = 0;
Vlad Yasevichea862c82010-04-30 22:41:10 -04001666 struct sctp_association *asoc = q->asoc;
1667 struct sctp_transport *primary = asoc->peer.primary_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Robert P. J. Day9dbc15f2008-04-12 18:54:24 -07001669 list_for_each_entry(chunk, transmitted_queue, transmitted_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 tsn = ntohl(chunk->subh.data_hdr->tsn);
1672
1673 /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
1674 * 'Unacknowledged TSN's', if the TSN number of an
1675 * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
1676 * value, increment the 'TSN.Missing.Report' count on that
1677 * chunk if it has NOT been fast retransmitted or marked for
1678 * fast retransmit already.
1679 */
Neil Hormanc226ef92008-07-25 12:44:09 -04001680 if (chunk->fast_retransmit == SCTP_CAN_FRTX &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 !chunk->tsn_gap_acked &&
1682 TSN_lt(tsn, highest_new_tsn_in_sack)) {
1683
1684 /* SFR-CACC may require us to skip marking
1685 * this chunk as missing.
1686 */
Vlad Yasevichf246a7b2011-04-18 19:13:56 +00001687 if (!transport || !sctp_cacc_skip(primary,
1688 chunk->transport,
1689 count_of_newacks, tsn)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 chunk->tsn_missing_report++;
1691
Daniel Borkmannbb333812013-06-28 19:49:40 +02001692 pr_debug("%s: tsn:0x%x missing counter:%d\n",
1693 __func__, tsn, chunk->tsn_missing_report);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 }
1695 }
1696 /*
1697 * M4) If any DATA chunk is found to have a
1698 * 'TSN.Missing.Report'
Vlad Yasevich27852c22006-02-02 16:57:31 -08001699 * value larger than or equal to 3, mark that chunk for
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 * retransmission and start the fast retransmit procedure.
1701 */
1702
Vlad Yasevich27852c22006-02-02 16:57:31 -08001703 if (chunk->tsn_missing_report >= 3) {
Neil Hormanc226ef92008-07-25 12:44:09 -04001704 chunk->fast_retransmit = SCTP_NEED_FRTX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 do_fast_retransmit = 1;
1706 }
1707 }
1708
1709 if (transport) {
1710 if (do_fast_retransmit)
1711 sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
1712
Daniel Borkmannbb333812013-06-28 19:49:40 +02001713 pr_debug("%s: transport:%p, cwnd:%d, ssthresh:%d, "
1714 "flight_size:%d, pba:%d\n", __func__, transport,
1715 transport->cwnd, transport->ssthresh,
1716 transport->flight_size, transport->partial_bytes_acked);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 }
1718}
1719
1720/* Is the given TSN acked by this packet? */
1721static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
1722{
1723 int i;
1724 sctp_sack_variable_t *frags;
1725 __u16 gap;
1726 __u32 ctsn = ntohl(sack->cum_tsn_ack);
1727
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001728 if (TSN_lte(tsn, ctsn))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 goto pass;
1730
1731 /* 3.3.4 Selective Acknowledgement (SACK) (3):
1732 *
1733 * Gap Ack Blocks:
1734 * These fields contain the Gap Ack Blocks. They are repeated
1735 * for each Gap Ack Block up to the number of Gap Ack Blocks
1736 * defined in the Number of Gap Ack Blocks field. All DATA
1737 * chunks with TSNs greater than or equal to (Cumulative TSN
1738 * Ack + Gap Ack Block Start) and less than or equal to
1739 * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
1740 * Block are assumed to have been received correctly.
1741 */
1742
1743 frags = sack->variable;
1744 gap = tsn - ctsn;
1745 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
1746 if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
1747 TSN_lte(gap, ntohs(frags[i].gab.end)))
1748 goto pass;
1749 }
1750
1751 return 0;
1752pass:
1753 return 1;
1754}
1755
1756static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist,
Al Viro9f81bcd2006-11-20 17:26:34 -08001757 int nskips, __be16 stream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758{
1759 int i;
1760
1761 for (i = 0; i < nskips; i++) {
1762 if (skiplist[i].stream == stream)
1763 return i;
1764 }
1765 return i;
1766}
1767
1768/* Create and add a fwdtsn chunk to the outq's control queue if needed. */
1769static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
1770{
1771 struct sctp_association *asoc = q->asoc;
1772 struct sctp_chunk *ftsn_chunk = NULL;
1773 struct sctp_fwdtsn_skip ftsn_skip_arr[10];
1774 int nskips = 0;
1775 int skip_pos = 0;
1776 __u32 tsn;
1777 struct sctp_chunk *chunk;
1778 struct list_head *lchunk, *temp;
1779
Wei Yongjun76595022009-03-12 09:49:19 +00001780 if (!asoc->peer.prsctp_capable)
1781 return;
1782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 /* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the
1784 * received SACK.
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001785 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 * If (Advanced.Peer.Ack.Point < SackCumAck), then update
1787 * Advanced.Peer.Ack.Point to be equal to SackCumAck.
1788 */
1789 if (TSN_lt(asoc->adv_peer_ack_point, ctsn))
1790 asoc->adv_peer_ack_point = ctsn;
1791
1792 /* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point"
1793 * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as
1794 * the chunk next in the out-queue space is marked as "abandoned" as
1795 * shown in the following example:
1796 *
1797 * Assuming that a SACK arrived with the Cumulative TSN ACK 102
1798 * and the Advanced.Peer.Ack.Point is updated to this value:
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001799 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 * out-queue at the end of ==> out-queue after Adv.Ack.Point
1801 * normal SACK processing local advancement
1802 * ... ...
1803 * Adv.Ack.Pt-> 102 acked 102 acked
1804 * 103 abandoned 103 abandoned
1805 * 104 abandoned Adv.Ack.P-> 104 abandoned
1806 * 105 105
1807 * 106 acked 106 acked
1808 * ... ...
1809 *
1810 * In this example, the data sender successfully advanced the
1811 * "Advanced.Peer.Ack.Point" from 102 to 104 locally.
1812 */
1813 list_for_each_safe(lchunk, temp, &q->abandoned) {
1814 chunk = list_entry(lchunk, struct sctp_chunk,
1815 transmitted_list);
1816 tsn = ntohl(chunk->subh.data_hdr->tsn);
1817
1818 /* Remove any chunks in the abandoned queue that are acked by
1819 * the ctsn.
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001820 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 if (TSN_lte(tsn, ctsn)) {
1822 list_del_init(lchunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 sctp_chunk_free(chunk);
1824 } else {
1825 if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
1826 asoc->adv_peer_ack_point = tsn;
1827 if (chunk->chunk_hdr->flags &
1828 SCTP_DATA_UNORDERED)
1829 continue;
1830 skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0],
1831 nskips,
1832 chunk->subh.data_hdr->stream);
1833 ftsn_skip_arr[skip_pos].stream =
1834 chunk->subh.data_hdr->stream;
1835 ftsn_skip_arr[skip_pos].ssn =
1836 chunk->subh.data_hdr->ssn;
1837 if (skip_pos == nskips)
1838 nskips++;
1839 if (nskips == 10)
1840 break;
1841 } else
1842 break;
1843 }
1844 }
1845
1846 /* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point"
1847 * is greater than the Cumulative TSN ACK carried in the received
1848 * SACK, the data sender MUST send the data receiver a FORWARD TSN
1849 * chunk containing the latest value of the
1850 * "Advanced.Peer.Ack.Point".
1851 *
1852 * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD
1853 * list each stream and sequence number in the forwarded TSN. This
1854 * information will enable the receiver to easily find any
1855 * stranded TSN's waiting on stream reorder queues. Each stream
1856 * SHOULD only be reported once; this means that if multiple
1857 * abandoned messages occur in the same stream then only the
1858 * highest abandoned stream sequence number is reported. If the
1859 * total size of the FORWARD TSN does NOT fit in a single MTU then
1860 * the sender of the FORWARD TSN SHOULD lower the
1861 * Advanced.Peer.Ack.Point to the last TSN that will fit in a
1862 * single MTU.
1863 */
1864 if (asoc->adv_peer_ack_point > ctsn)
1865 ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point,
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001866 nskips, &ftsn_skip_arr[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
1868 if (ftsn_chunk) {
David S. Miller79af02c2005-07-08 21:47:49 -07001869 list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
Eric W. Biedermanb01a2402012-08-06 08:47:55 +00001870 SCTP_INC_STATS(sock_net(asoc->base.sk), SCTP_MIB_OUTCTRLCHUNKS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 }
1872}