Commit | Line | Data |
---|---|---|
60c778b2 | 1 | /* SCTP kernel implementation |
1da177e4 LT |
2 | * (C) Copyright IBM Corp. 2001, 2004 |
3 | * Copyright (c) 1999-2000 Cisco, Inc. | |
4 | * Copyright (c) 1999-2001 Motorola, Inc. | |
5 | * Copyright (c) 2001-2003 Intel Corp. | |
6 | * | |
60c778b2 | 7 | * This file is part of the SCTP kernel implementation |
1da177e4 LT |
8 | * |
9 | * These functions implement the sctp_outq class. The outqueue handles | |
10 | * bundling and queueing of outgoing SCTP chunks. | |
11 | * | |
60c778b2 | 12 | * This SCTP implementation is free software; |
1da177e4 LT |
13 | * you can redistribute it and/or modify it under the terms of |
14 | * the GNU General Public License as published by | |
15 | * the Free Software Foundation; either version 2, or (at your option) | |
16 | * any later version. | |
17 | * | |
60c778b2 | 18 | * This SCTP implementation is distributed in the hope that it |
1da177e4 LT |
19 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
20 | * ************************ | |
21 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
22 | * See the GNU General Public License for more details. | |
23 | * | |
24 | * You should have received a copy of the GNU General Public License | |
4b2f13a2 JK |
25 | * along with GNU CC; see the file COPYING. If not, see |
26 | * <http://www.gnu.org/licenses/>. | |
1da177e4 LT |
27 | * |
28 | * Please send any bug reports or fixes you make to the | |
29 | * email address(es): | |
91705c61 | 30 | * lksctp developers <linux-sctp@vger.kernel.org> |
1da177e4 | 31 | * |
1da177e4 LT |
32 | * 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> | |
1da177e4 LT |
40 | */ |
41 | ||
145ce502 JP |
42 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
43 | ||
1da177e4 LT |
44 | #include <linux/types.h> |
45 | #include <linux/list.h> /* For struct list_head */ | |
46 | #include <linux/socket.h> | |
47 | #include <linux/ip.h> | |
5a0e3ad6 | 48 | #include <linux/slab.h> |
1da177e4 LT |
49 | #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. */ | |
55 | static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn); | |
56 | static void sctp_check_transmitted(struct sctp_outq *q, | |
57 | struct list_head *transmitted_queue, | |
58 | struct sctp_transport *transport, | |
edfee033 | 59 | union sctp_addr *saddr, |
1da177e4 | 60 | struct sctp_sackhdr *sack, |
bfa0d984 | 61 | __u32 *highest_new_tsn); |
1da177e4 LT |
62 | |
63 | static 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 | ||
69 | static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn); | |
70 | ||
83dbc3d4 | 71 | static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp); |
abd0b198 | 72 | |
1da177e4 LT |
73 | /* Add data to the front of the queue. */ |
74 | static inline void sctp_outq_head_data(struct sctp_outq *q, | |
75 | struct sctp_chunk *ch) | |
76 | { | |
79af02c2 | 77 | list_add(&ch->list, &q->out_chunk_list); |
1da177e4 | 78 | q->out_qlen += ch->skb->len; |
1da177e4 LT |
79 | } |
80 | ||
81 | /* Take data from the front of the queue. */ | |
82 | static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q) | |
83 | { | |
79af02c2 DM |
84 | 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); | |
1da177e4 | 91 | q->out_qlen -= ch->skb->len; |
79af02c2 | 92 | } |
1da177e4 LT |
93 | return ch; |
94 | } | |
95 | /* Add data chunk to the end of the queue. */ | |
96 | static inline void sctp_outq_tail_data(struct sctp_outq *q, | |
97 | struct sctp_chunk *ch) | |
98 | { | |
79af02c2 | 99 | list_add_tail(&ch->list, &q->out_chunk_list); |
1da177e4 | 100 | q->out_qlen += ch->skb->len; |
1da177e4 LT |
101 | } |
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 | */ | |
109 | static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary, | |
110 | struct sctp_transport *transport, | |
111 | int count_of_newacks) | |
112 | { | |
cb3f837b | 113 | if (count_of_newacks >= 2 && transport != primary) |
1da177e4 LT |
114 | 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 | */ | |
125 | static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport, | |
126 | int count_of_newacks) | |
127 | { | |
f246a7b7 VY |
128 | if (count_of_newacks < 2 && |
129 | (transport && !transport->cacc.cacc_saw_newack)) | |
1da177e4 LT |
130 | 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 | */ | |
141 | static 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 | */ | |
162 | static 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, | |
25985edc | 175 | * then the sender MUST further execute steps 3.1 and |
1da177e4 LT |
176 | * 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 | |
25985edc | 181 | * the sender SHOULD increment missing report count for |
1da177e4 LT |
182 | * t (according to [RFC2960] and [SCTP_STEWART_2002]). |
183 | */ | |
184 | static 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 && | |
f64f9e71 JP |
190 | (sctp_cacc_skip_3_1(primary, transport, count_of_newacks) || |
191 | sctp_cacc_skip_3_2(primary, tsn))) | |
1da177e4 LT |
192 | 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 | */ | |
200 | void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q) | |
201 | { | |
c5c7774d NH |
202 | memset(q, 0, sizeof(struct sctp_outq)); |
203 | ||
1da177e4 | 204 | q->asoc = asoc; |
79af02c2 DM |
205 | INIT_LIST_HEAD(&q->out_chunk_list); |
206 | INIT_LIST_HEAD(&q->control_chunk_list); | |
1da177e4 LT |
207 | INIT_LIST_HEAD(&q->retransmit); |
208 | INIT_LIST_HEAD(&q->sacked); | |
209 | INIT_LIST_HEAD(&q->abandoned); | |
1da177e4 LT |
210 | } |
211 | ||
212 | /* Free the outqueue structure and any related pending chunks. | |
213 | */ | |
2f94aabd | 214 | static void __sctp_outq_teardown(struct sctp_outq *q) |
1da177e4 LT |
215 | { |
216 | struct sctp_transport *transport; | |
9dbc15f0 | 217 | struct list_head *lchunk, *temp; |
79af02c2 | 218 | struct sctp_chunk *chunk, *tmp; |
1da177e4 LT |
219 | |
220 | /* Throw away unacknowledged chunks. */ | |
9dbc15f0 RD |
221 | list_for_each_entry(transport, &q->asoc->peer.transport_addr_list, |
222 | transports) { | |
1da177e4 LT |
223 | 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 | ||
1da177e4 | 267 | /* Throw away any leftover control chunks. */ |
79af02c2 DM |
268 | list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) { |
269 | list_del_init(&chunk->list); | |
1da177e4 | 270 | sctp_chunk_free(chunk); |
79af02c2 | 271 | } |
1da177e4 LT |
272 | } |
273 | ||
2f94aabd NH |
274 | void sctp_outq_teardown(struct sctp_outq *q) |
275 | { | |
276 | __sctp_outq_teardown(q); | |
277 | sctp_outq_init(q->asoc, q); | |
278 | } | |
279 | ||
1da177e4 LT |
280 | /* Free the outqueue structure and any related pending chunks. */ |
281 | void sctp_outq_free(struct sctp_outq *q) | |
282 | { | |
283 | /* Throw away leftover chunks. */ | |
2f94aabd | 284 | __sctp_outq_teardown(q); |
1da177e4 LT |
285 | } |
286 | ||
287 | /* Put a new chunk in an sctp_outq. */ | |
83dbc3d4 | 288 | void sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk, gfp_t gfp) |
1da177e4 | 289 | { |
b01a2407 | 290 | struct net *net = sock_net(q->asoc->base.sk); |
1da177e4 | 291 | |
bb33381d DB |
292 | pr_debug("%s: outq:%p, chunk:%p[%s]\n", __func__, q, chunk, |
293 | chunk && chunk->chunk_hdr ? | |
294 | sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) : | |
295 | "illegal chunk"); | |
1da177e4 LT |
296 | |
297 | /* If it is data, queue it up, otherwise, send it | |
298 | * immediately. | |
299 | */ | |
ec7b9519 | 300 | if (sctp_chunk_is_data(chunk)) { |
2c89791e XL |
301 | pr_debug("%s: outqueueing: outq:%p, chunk:%p[%s])\n", |
302 | __func__, q, chunk, chunk && chunk->chunk_hdr ? | |
303 | sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) : | |
304 | "illegal chunk"); | |
305 | ||
2c89791e | 306 | sctp_outq_tail_data(q, chunk); |
b50afd20 | 307 | if (chunk->asoc->peer.prsctp_capable && |
2c89791e XL |
308 | SCTP_PR_PRIO_ENABLED(chunk->sinfo.sinfo_flags)) |
309 | chunk->asoc->sent_cnt_removable++; | |
310 | if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) | |
311 | SCTP_INC_STATS(net, SCTP_MIB_OUTUNORDERCHUNKS); | |
312 | else | |
313 | SCTP_INC_STATS(net, SCTP_MIB_OUTORDERCHUNKS); | |
1da177e4 | 314 | } else { |
79af02c2 | 315 | list_add_tail(&chunk->list, &q->control_chunk_list); |
b01a2407 | 316 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
1da177e4 LT |
317 | } |
318 | ||
1da177e4 | 319 | if (!q->cork) |
83dbc3d4 | 320 | sctp_outq_flush(q, 0, gfp); |
1da177e4 LT |
321 | } |
322 | ||
323 | /* Insert a chunk into the sorted list based on the TSNs. The retransmit list | |
324 | * and the abandoned list are in ascending order. | |
325 | */ | |
326 | static void sctp_insert_list(struct list_head *head, struct list_head *new) | |
327 | { | |
328 | struct list_head *pos; | |
329 | struct sctp_chunk *nchunk, *lchunk; | |
330 | __u32 ntsn, ltsn; | |
331 | int done = 0; | |
332 | ||
333 | nchunk = list_entry(new, struct sctp_chunk, transmitted_list); | |
334 | ntsn = ntohl(nchunk->subh.data_hdr->tsn); | |
335 | ||
336 | list_for_each(pos, head) { | |
337 | lchunk = list_entry(pos, struct sctp_chunk, transmitted_list); | |
338 | ltsn = ntohl(lchunk->subh.data_hdr->tsn); | |
339 | if (TSN_lt(ntsn, ltsn)) { | |
340 | list_add(new, pos->prev); | |
341 | done = 1; | |
342 | break; | |
343 | } | |
344 | } | |
345 | if (!done) | |
d808ad9a | 346 | list_add_tail(new, head); |
1da177e4 LT |
347 | } |
348 | ||
8dbdf1f5 XL |
349 | static int sctp_prsctp_prune_sent(struct sctp_association *asoc, |
350 | struct sctp_sndrcvinfo *sinfo, | |
351 | struct list_head *queue, int msg_len) | |
352 | { | |
353 | struct sctp_chunk *chk, *temp; | |
354 | ||
355 | list_for_each_entry_safe(chk, temp, queue, transmitted_list) { | |
d229d48d XL |
356 | struct sctp_stream_out *streamout; |
357 | ||
8dbdf1f5 | 358 | if (!SCTP_PR_PRIO_ENABLED(chk->sinfo.sinfo_flags) || |
0605483f | 359 | chk->sinfo.sinfo_timetolive <= sinfo->sinfo_timetolive) |
8dbdf1f5 XL |
360 | continue; |
361 | ||
362 | list_del_init(&chk->transmitted_list); | |
363 | sctp_insert_list(&asoc->outqueue.abandoned, | |
364 | &chk->transmitted_list); | |
365 | ||
cee360ab | 366 | streamout = &asoc->stream.out[chk->sinfo.sinfo_stream]; |
8dbdf1f5 XL |
367 | asoc->sent_cnt_removable--; |
368 | asoc->abandoned_sent[SCTP_PR_INDEX(PRIO)]++; | |
d229d48d | 369 | streamout->abandoned_sent[SCTP_PR_INDEX(PRIO)]++; |
8dbdf1f5 | 370 | |
7a7bcee6 XL |
371 | if (queue != &asoc->outqueue.retransmit && |
372 | !chk->tsn_gap_acked) { | |
8dbdf1f5 XL |
373 | if (chk->transport) |
374 | chk->transport->flight_size -= | |
375 | sctp_data_size(chk); | |
376 | asoc->outqueue.outstanding_bytes -= sctp_data_size(chk); | |
377 | } | |
378 | ||
379 | msg_len -= SCTP_DATA_SNDSIZE(chk) + | |
380 | sizeof(struct sk_buff) + | |
381 | sizeof(struct sctp_chunk); | |
382 | if (msg_len <= 0) | |
383 | break; | |
384 | } | |
385 | ||
386 | return msg_len; | |
387 | } | |
388 | ||
389 | static int sctp_prsctp_prune_unsent(struct sctp_association *asoc, | |
23bb09cf | 390 | struct sctp_sndrcvinfo *sinfo, int msg_len) |
8dbdf1f5 | 391 | { |
23bb09cf | 392 | struct sctp_outq *q = &asoc->outqueue; |
8dbdf1f5 XL |
393 | struct sctp_chunk *chk, *temp; |
394 | ||
23bb09cf | 395 | list_for_each_entry_safe(chk, temp, &q->out_chunk_list, list) { |
8dbdf1f5 | 396 | if (!SCTP_PR_PRIO_ENABLED(chk->sinfo.sinfo_flags) || |
0605483f | 397 | chk->sinfo.sinfo_timetolive <= sinfo->sinfo_timetolive) |
8dbdf1f5 XL |
398 | continue; |
399 | ||
400 | list_del_init(&chk->list); | |
23bb09cf | 401 | q->out_qlen -= chk->skb->len; |
8dbdf1f5 XL |
402 | asoc->sent_cnt_removable--; |
403 | asoc->abandoned_unsent[SCTP_PR_INDEX(PRIO)]++; | |
cee360ab | 404 | if (chk->sinfo.sinfo_stream < asoc->stream.outcnt) { |
d229d48d | 405 | struct sctp_stream_out *streamout = |
cee360ab | 406 | &asoc->stream.out[chk->sinfo.sinfo_stream]; |
d229d48d XL |
407 | |
408 | streamout->abandoned_unsent[SCTP_PR_INDEX(PRIO)]++; | |
409 | } | |
8dbdf1f5 XL |
410 | |
411 | msg_len -= SCTP_DATA_SNDSIZE(chk) + | |
412 | sizeof(struct sk_buff) + | |
413 | sizeof(struct sctp_chunk); | |
414 | sctp_chunk_free(chk); | |
415 | if (msg_len <= 0) | |
416 | break; | |
417 | } | |
418 | ||
419 | return msg_len; | |
420 | } | |
421 | ||
422 | /* Abandon the chunks according their priorities */ | |
423 | void sctp_prsctp_prune(struct sctp_association *asoc, | |
424 | struct sctp_sndrcvinfo *sinfo, int msg_len) | |
425 | { | |
426 | struct sctp_transport *transport; | |
427 | ||
be4947bf | 428 | if (!asoc->peer.prsctp_capable || !asoc->sent_cnt_removable) |
8dbdf1f5 XL |
429 | return; |
430 | ||
431 | msg_len = sctp_prsctp_prune_sent(asoc, sinfo, | |
432 | &asoc->outqueue.retransmit, | |
433 | msg_len); | |
434 | if (msg_len <= 0) | |
435 | return; | |
436 | ||
437 | list_for_each_entry(transport, &asoc->peer.transport_addr_list, | |
438 | transports) { | |
439 | msg_len = sctp_prsctp_prune_sent(asoc, sinfo, | |
440 | &transport->transmitted, | |
441 | msg_len); | |
442 | if (msg_len <= 0) | |
443 | return; | |
444 | } | |
445 | ||
23bb09cf | 446 | sctp_prsctp_prune_unsent(asoc, sinfo, msg_len); |
8dbdf1f5 XL |
447 | } |
448 | ||
1da177e4 LT |
449 | /* Mark all the eligible packets on a transport for retransmission. */ |
450 | void sctp_retransmit_mark(struct sctp_outq *q, | |
451 | struct sctp_transport *transport, | |
b6157d8e | 452 | __u8 reason) |
1da177e4 LT |
453 | { |
454 | struct list_head *lchunk, *ltemp; | |
455 | struct sctp_chunk *chunk; | |
456 | ||
457 | /* Walk through the specified transmitted queue. */ | |
458 | list_for_each_safe(lchunk, ltemp, &transport->transmitted) { | |
459 | chunk = list_entry(lchunk, struct sctp_chunk, | |
460 | transmitted_list); | |
461 | ||
462 | /* If the chunk is abandoned, move it to abandoned list. */ | |
463 | if (sctp_chunk_abandoned(chunk)) { | |
464 | list_del_init(lchunk); | |
465 | sctp_insert_list(&q->abandoned, lchunk); | |
8c4a2d41 VY |
466 | |
467 | /* If this chunk has not been previousely acked, | |
468 | * stop considering it 'outstanding'. Our peer | |
469 | * will most likely never see it since it will | |
470 | * not be retransmitted | |
471 | */ | |
472 | if (!chunk->tsn_gap_acked) { | |
31b02e15 VY |
473 | if (chunk->transport) |
474 | chunk->transport->flight_size -= | |
475 | sctp_data_size(chunk); | |
8c4a2d41 | 476 | q->outstanding_bytes -= sctp_data_size(chunk); |
a76c0adf | 477 | q->asoc->peer.rwnd += sctp_data_size(chunk); |
8c4a2d41 | 478 | } |
1da177e4 LT |
479 | continue; |
480 | } | |
481 | ||
b6157d8e VY |
482 | /* If we are doing retransmission due to a timeout or pmtu |
483 | * discovery, only the chunks that are not yet acked should | |
484 | * be added to the retransmit queue. | |
1da177e4 | 485 | */ |
b6157d8e | 486 | if ((reason == SCTP_RTXR_FAST_RTX && |
c226ef9b | 487 | (chunk->fast_retransmit == SCTP_NEED_FRTX)) || |
b6157d8e | 488 | (reason != SCTP_RTXR_FAST_RTX && !chunk->tsn_gap_acked)) { |
1da177e4 LT |
489 | /* RFC 2960 6.2.1 Processing a Received SACK |
490 | * | |
491 | * C) Any time a DATA chunk is marked for | |
492 | * retransmission (via either T3-rtx timer expiration | |
493 | * (Section 6.3.3) or via fast retransmit | |
494 | * (Section 7.2.4)), add the data size of those | |
495 | * chunks to the rwnd. | |
496 | */ | |
a76c0adf | 497 | q->asoc->peer.rwnd += sctp_data_size(chunk); |
1da177e4 | 498 | q->outstanding_bytes -= sctp_data_size(chunk); |
31b02e15 VY |
499 | if (chunk->transport) |
500 | transport->flight_size -= sctp_data_size(chunk); | |
1da177e4 LT |
501 | |
502 | /* sctpimpguide-05 Section 2.8.2 | |
503 | * M5) If a T3-rtx timer expires, the | |
504 | * 'TSN.Missing.Report' of all affected TSNs is set | |
505 | * to 0. | |
506 | */ | |
507 | chunk->tsn_missing_report = 0; | |
508 | ||
509 | /* If a chunk that is being used for RTT measurement | |
510 | * has to be retransmitted, we cannot use this chunk | |
511 | * anymore for RTT measurements. Reset rto_pending so | |
512 | * that a new RTT measurement is started when a new | |
513 | * data chunk is sent. | |
514 | */ | |
515 | if (chunk->rtt_in_progress) { | |
516 | chunk->rtt_in_progress = 0; | |
517 | transport->rto_pending = 0; | |
518 | } | |
519 | ||
520 | /* Move the chunk to the retransmit queue. The chunks | |
521 | * on the retransmit queue are always kept in order. | |
522 | */ | |
523 | list_del_init(lchunk); | |
524 | sctp_insert_list(&q->retransmit, lchunk); | |
525 | } | |
526 | } | |
527 | ||
bb33381d DB |
528 | pr_debug("%s: transport:%p, reason:%d, cwnd:%d, ssthresh:%d, " |
529 | "flight_size:%d, pba:%d\n", __func__, transport, reason, | |
530 | transport->cwnd, transport->ssthresh, transport->flight_size, | |
531 | transport->partial_bytes_acked); | |
1da177e4 LT |
532 | } |
533 | ||
534 | /* Mark all the eligible packets on a transport for retransmission and force | |
535 | * one packet out. | |
536 | */ | |
537 | void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport, | |
125c2982 | 538 | enum sctp_retransmit_reason reason) |
1da177e4 | 539 | { |
b01a2407 | 540 | struct net *net = sock_net(q->asoc->base.sk); |
1da177e4 | 541 | |
cb3f837b | 542 | switch (reason) { |
1da177e4 | 543 | case SCTP_RTXR_T3_RTX: |
b01a2407 | 544 | SCTP_INC_STATS(net, SCTP_MIB_T3_RETRANSMITS); |
1da177e4 LT |
545 | sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX); |
546 | /* Update the retran path if the T3-rtx timer has expired for | |
547 | * the current retran path. | |
548 | */ | |
549 | if (transport == transport->asoc->peer.retran_path) | |
550 | sctp_assoc_update_retran_path(transport->asoc); | |
58fbbed4 NH |
551 | transport->asoc->rtx_data_chunks += |
552 | transport->asoc->unack_data; | |
1da177e4 LT |
553 | break; |
554 | case SCTP_RTXR_FAST_RTX: | |
b01a2407 | 555 | SCTP_INC_STATS(net, SCTP_MIB_FAST_RETRANSMITS); |
1da177e4 | 556 | sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX); |
62aeaff5 | 557 | q->fast_rtx = 1; |
1da177e4 LT |
558 | break; |
559 | case SCTP_RTXR_PMTUD: | |
b01a2407 | 560 | SCTP_INC_STATS(net, SCTP_MIB_PMTUD_RETRANSMITS); |
1da177e4 | 561 | break; |
b6157d8e | 562 | case SCTP_RTXR_T1_RTX: |
b01a2407 | 563 | SCTP_INC_STATS(net, SCTP_MIB_T1_RETRANSMITS); |
58fbbed4 | 564 | transport->asoc->init_retries++; |
b6157d8e | 565 | break; |
ac0b0462 SS |
566 | default: |
567 | BUG(); | |
1da177e4 LT |
568 | } |
569 | ||
b6157d8e | 570 | sctp_retransmit_mark(q, transport, reason); |
1da177e4 LT |
571 | |
572 | /* PR-SCTP A5) Any time the T3-rtx timer expires, on any destination, | |
573 | * the sender SHOULD try to advance the "Advanced.Peer.Ack.Point" by | |
574 | * following the procedures outlined in C1 - C5. | |
575 | */ | |
8b750ce5 VY |
576 | if (reason == SCTP_RTXR_T3_RTX) |
577 | sctp_generate_fwdtsn(q, q->asoc->ctsn_ack_point); | |
1da177e4 | 578 | |
8b750ce5 VY |
579 | /* Flush the queues only on timeout, since fast_rtx is only |
580 | * triggered during sack processing and the queue | |
581 | * will be flushed at the end. | |
582 | */ | |
583 | if (reason != SCTP_RTXR_FAST_RTX) | |
64519440 | 584 | sctp_outq_flush(q, /* rtx_timeout */ 1, GFP_ATOMIC); |
1da177e4 LT |
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 | */ | |
595 | static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt, | |
596 | int rtx_timeout, int *start_timer) | |
597 | { | |
1da177e4 | 598 | struct sctp_transport *transport = pkt->transport; |
1da177e4 | 599 | struct sctp_chunk *chunk, *chunk1; |
86b36f2a XL |
600 | struct list_head *lqueue; |
601 | enum sctp_xmit status; | |
1da177e4 | 602 | int error = 0; |
62aeaff5 | 603 | int timer = 0; |
8b750ce5 | 604 | int done = 0; |
86b36f2a | 605 | int fast_rtx; |
1da177e4 | 606 | |
1da177e4 | 607 | lqueue = &q->retransmit; |
62aeaff5 | 608 | fast_rtx = q->fast_rtx; |
1da177e4 | 609 | |
8b750ce5 VY |
610 | /* 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 | |
1da177e4 LT |
614 | * |
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.] | |
8b750ce5 VY |
628 | * |
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. | |
1da177e4 | 632 | */ |
8b750ce5 | 633 | list_for_each_entry_safe(chunk, chunk1, lqueue, transmitted_list) { |
4c6a6f42 WY |
634 | /* 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 | } | |
1da177e4 LT |
641 | |
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) { | |
54a27924 WY |
648 | list_move_tail(&chunk->transmitted_list, |
649 | &transport->transmitted); | |
1da177e4 LT |
650 | continue; |
651 | } | |
652 | ||
8b750ce5 VY |
653 | /* If we are doing fast retransmit, ignore non-fast_rtransmit |
654 | * chunks | |
655 | */ | |
656 | if (fast_rtx && !chunk->fast_retransmit) | |
657 | continue; | |
658 | ||
bc4f841a | 659 | redo: |
1da177e4 LT |
660 | /* 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: | |
bc4f841a WY |
665 | 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 | */ | |
cea8768f | 672 | sctp_packet_transmit(pkt, GFP_ATOMIC); |
bc4f841a WY |
673 | goto redo; |
674 | } | |
675 | ||
1da177e4 | 676 | /* Send this packet. */ |
cea8768f | 677 | error = sctp_packet_transmit(pkt, GFP_ATOMIC); |
1da177e4 LT |
678 | |
679 | /* If we are retransmitting, we should only | |
680 | * send a single packet. | |
f246a7b7 | 681 | * Otherwise, try appending this chunk again. |
1da177e4 | 682 | */ |
8b750ce5 VY |
683 | if (rtx_timeout || fast_rtx) |
684 | done = 1; | |
f246a7b7 VY |
685 | else |
686 | goto redo; | |
1da177e4 | 687 | |
8b750ce5 | 688 | /* Bundle next chunk in the next round. */ |
1da177e4 LT |
689 | break; |
690 | ||
691 | case SCTP_XMIT_RWND_FULL: | |
d808ad9a | 692 | /* Send this packet. */ |
cea8768f | 693 | error = sctp_packet_transmit(pkt, GFP_ATOMIC); |
1da177e4 LT |
694 | |
695 | /* Stop sending DATA as there is no more room | |
696 | * at the receiver. | |
697 | */ | |
8b750ce5 | 698 | done = 1; |
1da177e4 LT |
699 | break; |
700 | ||
526cbef7 | 701 | case SCTP_XMIT_DELAY: |
d808ad9a | 702 | /* Send this packet. */ |
cea8768f | 703 | error = sctp_packet_transmit(pkt, GFP_ATOMIC); |
1da177e4 LT |
704 | |
705 | /* Stop sending DATA because of nagle delay. */ | |
8b750ce5 | 706 | done = 1; |
1da177e4 LT |
707 | break; |
708 | ||
709 | default: | |
710 | /* The append was successful, so add this chunk to | |
711 | * the transmitted list. | |
712 | */ | |
54a27924 WY |
713 | list_move_tail(&chunk->transmitted_list, |
714 | &transport->transmitted); | |
1da177e4 | 715 | |
d808ad9a | 716 | /* Mark the chunk as ineligible for fast retransmit |
1da177e4 LT |
717 | * after it is retransmitted. |
718 | */ | |
c226ef9b NH |
719 | if (chunk->fast_retransmit == SCTP_NEED_FRTX) |
720 | chunk->fast_retransmit = SCTP_DONT_FRTX; | |
1da177e4 | 721 | |
196d6759 | 722 | q->asoc->stats.rtxchunks++; |
1da177e4 | 723 | break; |
3ff50b79 | 724 | } |
1da177e4 | 725 | |
62aeaff5 VY |
726 | /* Set the timer if there were no errors */ |
727 | if (!error && !timer) | |
728 | timer = 1; | |
729 | ||
8b750ce5 VY |
730 | 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) { | |
c226ef9b NH |
741 | if (chunk1->fast_retransmit == SCTP_NEED_FRTX) |
742 | chunk1->fast_retransmit = SCTP_DONT_FRTX; | |
1da177e4 LT |
743 | } |
744 | } | |
745 | ||
62aeaff5 VY |
746 | *start_timer = timer; |
747 | ||
748 | /* Clear fast retransmit hint */ | |
749 | if (fast_rtx) | |
750 | q->fast_rtx = 0; | |
751 | ||
1da177e4 LT |
752 | return error; |
753 | } | |
754 | ||
755 | /* Cork the outqueue so queued chunks are really queued. */ | |
83dbc3d4 | 756 | void sctp_outq_uncork(struct sctp_outq *q, gfp_t gfp) |
1da177e4 | 757 | { |
7d54dc68 | 758 | if (q->cork) |
1da177e4 | 759 | q->cork = 0; |
dacda32e | 760 | |
83dbc3d4 | 761 | sctp_outq_flush(q, 0, gfp); |
1da177e4 LT |
762 | } |
763 | ||
2e3216cd | 764 | |
1da177e4 LT |
765 | /* |
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 | */ | |
83dbc3d4 | 774 | static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp) |
1da177e4 LT |
775 | { |
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; | |
1da177e4 LT |
782 | struct sctp_transport *transport = NULL; |
783 | struct sctp_transport *new_transport; | |
79af02c2 | 784 | struct sctp_chunk *chunk, *tmp; |
86b36f2a | 785 | enum sctp_xmit status; |
1da177e4 LT |
786 | int error = 0; |
787 | int start_timer = 0; | |
2e3216cd | 788 | int one_packet = 0; |
1da177e4 LT |
789 | |
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 | ||
79af02c2 | 807 | list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) { |
8a07eb0a MH |
808 | /* 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 | ||
79af02c2 DM |
818 | list_del_init(&chunk->list); |
819 | ||
1da177e4 LT |
820 | /* Pick the right transport to use. */ |
821 | new_transport = chunk->transport; | |
822 | ||
823 | if (!new_transport) { | |
a08de64d VY |
824 | /* |
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; | |
ad8fec17 | 847 | } else if ((new_transport->state == SCTP_INACTIVE) || |
5aa93bcf NH |
848 | (new_transport->state == SCTP_UNCONFIRMED) || |
849 | (new_transport->state == SCTP_PF)) { | |
3f7a87d2 FF |
850 | /* If the chunk is Heartbeat or Heartbeat Ack, |
851 | * send it to chunk->transport, even if it's | |
1da177e4 LT |
852 | * inactive. |
853 | * | |
854 | * 3.3.6 Heartbeat Acknowledgement: | |
d808ad9a | 855 | * ... |
1da177e4 LT |
856 | * 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. | |
d808ad9a | 859 | * ... |
a08de64d VY |
860 | * |
861 | * ASCONF_ACKs also must be sent to the source. | |
1da177e4 LT |
862 | */ |
863 | if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT && | |
a08de64d VY |
864 | chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT_ACK && |
865 | chunk->chunk_hdr->type != SCTP_CID_ASCONF_ACK) | |
1da177e4 LT |
866 | 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); | |
cea8768f | 896 | error = sctp_packet_transmit(&singleton, gfp); |
64519440 XL |
897 | if (error < 0) { |
898 | asoc->base.sk->sk_err = -error; | |
83dbc3d4 | 899 | return; |
64519440 | 900 | } |
1da177e4 LT |
901 | break; |
902 | ||
903 | case SCTP_CID_ABORT: | |
f4ad85ca GJ |
904 | if (sctp_test_T_bit(chunk)) { |
905 | packet->vtag = asoc->c.my_vtag; | |
906 | } | |
2e3216cd VY |
907 | /* The following chunks are "response" chunks, i.e. |
908 | * they are generated in response to something we | |
909 | * received. If we are sending these, then we can | |
910 | * send only 1 packet containing these chunks. | |
911 | */ | |
1da177e4 | 912 | case SCTP_CID_HEARTBEAT_ACK: |
1da177e4 | 913 | case SCTP_CID_SHUTDOWN_ACK: |
1da177e4 | 914 | case SCTP_CID_COOKIE_ACK: |
2e3216cd VY |
915 | case SCTP_CID_COOKIE_ECHO: |
916 | case SCTP_CID_ERROR: | |
1da177e4 | 917 | case SCTP_CID_ECN_CWR: |
1da177e4 | 918 | case SCTP_CID_ASCONF_ACK: |
2e3216cd | 919 | one_packet = 1; |
25985edc | 920 | /* Fall through */ |
2e3216cd VY |
921 | |
922 | case SCTP_CID_SACK: | |
923 | case SCTP_CID_HEARTBEAT: | |
924 | case SCTP_CID_SHUTDOWN: | |
925 | case SCTP_CID_ECN_ECNE: | |
926 | case SCTP_CID_ASCONF: | |
1da177e4 | 927 | case SCTP_CID_FWD_TSN: |
7f9d68ac | 928 | case SCTP_CID_RECONF: |
2e3216cd | 929 | status = sctp_packet_transmit_chunk(packet, chunk, |
cea8768f | 930 | one_packet, gfp); |
2e3216cd VY |
931 | if (status != SCTP_XMIT_OK) { |
932 | /* put the chunk back */ | |
933 | list_add(&chunk->list, &q->control_chunk_list); | |
7f9d68ac XL |
934 | break; |
935 | } | |
936 | ||
937 | asoc->stats.octrlchunks++; | |
938 | /* PR-SCTP C5) If a FORWARD TSN is sent, the | |
939 | * sender MUST assure that at least one T3-rtx | |
940 | * timer is running. | |
941 | */ | |
942 | if (chunk->chunk_hdr->type == SCTP_CID_FWD_TSN) { | |
943 | sctp_transport_reset_t3_rtx(transport); | |
944 | transport->last_time_sent = jiffies; | |
2e3216cd | 945 | } |
7f9d68ac XL |
946 | |
947 | if (chunk == asoc->strreset_chunk) | |
948 | sctp_transport_reset_reconf_timer(transport); | |
949 | ||
1da177e4 LT |
950 | break; |
951 | ||
952 | default: | |
953 | /* We built a chunk with an illegal type! */ | |
954 | BUG(); | |
3ff50b79 | 955 | } |
1da177e4 LT |
956 | } |
957 | ||
8a07eb0a MH |
958 | if (q->asoc->src_out_of_asoc_ok) |
959 | goto sctp_flush_out; | |
960 | ||
1da177e4 LT |
961 | /* Is it OK to send data chunks? */ |
962 | switch (asoc->state) { | |
963 | case SCTP_STATE_COOKIE_ECHOED: | |
964 | /* Only allow bundling when this packet has a COOKIE-ECHO | |
965 | * chunk. | |
966 | */ | |
967 | if (!packet || !packet->has_cookie_echo) | |
968 | break; | |
969 | ||
970 | /* fallthru */ | |
971 | case SCTP_STATE_ESTABLISHED: | |
972 | case SCTP_STATE_SHUTDOWN_PENDING: | |
973 | case SCTP_STATE_SHUTDOWN_RECEIVED: | |
974 | /* | |
975 | * RFC 2960 6.1 Transmission of DATA Chunks | |
976 | * | |
977 | * C) When the time comes for the sender to transmit, | |
978 | * before sending new DATA chunks, the sender MUST | |
979 | * first transmit any outstanding DATA chunks which | |
980 | * are marked for retransmission (limited by the | |
981 | * current cwnd). | |
982 | */ | |
983 | if (!list_empty(&q->retransmit)) { | |
f207c050 MH |
984 | if (asoc->peer.retran_path->state == SCTP_UNCONFIRMED) |
985 | goto sctp_flush_out; | |
1da177e4 LT |
986 | if (transport == asoc->peer.retran_path) |
987 | goto retran; | |
988 | ||
989 | /* Switch transports & prepare the packet. */ | |
990 | ||
991 | transport = asoc->peer.retran_path; | |
992 | ||
993 | if (list_empty(&transport->send_ready)) { | |
994 | list_add_tail(&transport->send_ready, | |
995 | &transport_list); | |
996 | } | |
997 | ||
998 | packet = &transport->packet; | |
999 | sctp_packet_config(packet, vtag, | |
1000 | asoc->peer.ecn_capable); | |
1001 | retran: | |
1002 | error = sctp_outq_flush_rtx(q, packet, | |
1003 | rtx_timeout, &start_timer); | |
64519440 XL |
1004 | if (error < 0) |
1005 | asoc->base.sk->sk_err = -error; | |
1da177e4 | 1006 | |
ba6f5e33 MRL |
1007 | if (start_timer) { |
1008 | sctp_transport_reset_t3_rtx(transport); | |
1009 | transport->last_time_sent = jiffies; | |
1010 | } | |
1da177e4 LT |
1011 | |
1012 | /* This can happen on COOKIE-ECHO resend. Only | |
1013 | * one chunk can get bundled with a COOKIE-ECHO. | |
1014 | */ | |
1015 | if (packet->has_cookie_echo) | |
1016 | goto sctp_flush_out; | |
1017 | ||
1018 | /* Don't send new data if there is still data | |
1019 | * waiting to retransmit. | |
1020 | */ | |
1021 | if (!list_empty(&q->retransmit)) | |
1022 | goto sctp_flush_out; | |
1023 | } | |
1024 | ||
46d5a808 VY |
1025 | /* Apply Max.Burst limitation to the current transport in |
1026 | * case it will be used for new data. We are going to | |
1027 | * rest it before we return, but we want to apply the limit | |
1028 | * to the currently queued data. | |
1029 | */ | |
1030 | if (transport) | |
1031 | sctp_transport_burst_limited(transport); | |
1032 | ||
1da177e4 | 1033 | /* Finally, transmit new packets. */ |
1da177e4 | 1034 | while ((chunk = sctp_outq_dequeue_data(q)) != NULL) { |
7f9d68ac XL |
1035 | __u32 sid = ntohs(chunk->subh.data_hdr->stream); |
1036 | ||
1da177e4 LT |
1037 | /* RFC 2960 6.5 Every DATA chunk MUST carry a valid |
1038 | * stream identifier. | |
1039 | */ | |
cee360ab | 1040 | if (chunk->sinfo.sinfo_stream >= asoc->stream.outcnt) { |
1da177e4 LT |
1041 | |
1042 | /* Mark as failed send. */ | |
1043 | sctp_chunk_fail(chunk, SCTP_ERROR_INV_STRM); | |
be4947bf | 1044 | if (asoc->peer.prsctp_capable && |
8dbdf1f5 XL |
1045 | SCTP_PR_PRIO_ENABLED(chunk->sinfo.sinfo_flags)) |
1046 | asoc->sent_cnt_removable--; | |
1da177e4 LT |
1047 | sctp_chunk_free(chunk); |
1048 | continue; | |
1049 | } | |
1050 | ||
1051 | /* Has this chunk expired? */ | |
1052 | if (sctp_chunk_abandoned(chunk)) { | |
1053 | sctp_chunk_fail(chunk, 0); | |
1054 | sctp_chunk_free(chunk); | |
1055 | continue; | |
1056 | } | |
1057 | ||
cee360ab | 1058 | if (asoc->stream.out[sid].state == SCTP_STREAM_CLOSED) { |
7f9d68ac XL |
1059 | sctp_outq_head_data(q, chunk); |
1060 | goto sctp_flush_out; | |
1061 | } | |
1062 | ||
1da177e4 LT |
1063 | /* If there is a specified transport, use it. |
1064 | * Otherwise, we want to use the active path. | |
1065 | */ | |
1066 | new_transport = chunk->transport; | |
3f7a87d2 | 1067 | if (!new_transport || |
ad8fec17 | 1068 | ((new_transport->state == SCTP_INACTIVE) || |
5aa93bcf NH |
1069 | (new_transport->state == SCTP_UNCONFIRMED) || |
1070 | (new_transport->state == SCTP_PF))) | |
1da177e4 | 1071 | new_transport = asoc->peer.active_path; |
31b055ef | 1072 | if (new_transport->state == SCTP_UNCONFIRMED) { |
eb004603 | 1073 | WARN_ONCE(1, "Attempt to send packet on unconfirmed path."); |
31b055ef MRL |
1074 | sctp_chunk_fail(chunk, 0); |
1075 | sctp_chunk_free(chunk); | |
f207c050 | 1076 | continue; |
31b055ef | 1077 | } |
1da177e4 LT |
1078 | |
1079 | /* Change packets if necessary. */ | |
1080 | if (new_transport != transport) { | |
1081 | transport = new_transport; | |
1082 | ||
1083 | /* Schedule to have this transport's | |
1084 | * packet flushed. | |
1085 | */ | |
1086 | if (list_empty(&transport->send_ready)) { | |
1087 | list_add_tail(&transport->send_ready, | |
1088 | &transport_list); | |
1089 | } | |
1090 | ||
1091 | packet = &transport->packet; | |
1092 | sctp_packet_config(packet, vtag, | |
1093 | asoc->peer.ecn_capable); | |
46d5a808 VY |
1094 | /* We've switched transports, so apply the |
1095 | * Burst limit to the new transport. | |
1096 | */ | |
1097 | sctp_transport_burst_limited(transport); | |
1da177e4 LT |
1098 | } |
1099 | ||
bb33381d DB |
1100 | pr_debug("%s: outq:%p, chunk:%p[%s], tx-tsn:0x%x skb->head:%p " |
1101 | "skb->users:%d\n", | |
1102 | __func__, q, chunk, chunk && chunk->chunk_hdr ? | |
1103 | sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) : | |
1104 | "illegal chunk", ntohl(chunk->subh.data_hdr->tsn), | |
1105 | chunk->skb ? chunk->skb->head : NULL, chunk->skb ? | |
63354797 | 1106 | refcount_read(&chunk->skb->users) : -1); |
1da177e4 LT |
1107 | |
1108 | /* Add the chunk to the packet. */ | |
cea8768f | 1109 | status = sctp_packet_transmit_chunk(packet, chunk, 0, gfp); |
1da177e4 LT |
1110 | |
1111 | switch (status) { | |
1112 | case SCTP_XMIT_PMTU_FULL: | |
1113 | case SCTP_XMIT_RWND_FULL: | |
526cbef7 | 1114 | case SCTP_XMIT_DELAY: |
1da177e4 LT |
1115 | /* We could not append this chunk, so put |
1116 | * the chunk back on the output queue. | |
1117 | */ | |
bb33381d DB |
1118 | pr_debug("%s: could not transmit tsn:0x%x, status:%d\n", |
1119 | __func__, ntohl(chunk->subh.data_hdr->tsn), | |
1120 | status); | |
1121 | ||
1da177e4 LT |
1122 | sctp_outq_head_data(q, chunk); |
1123 | goto sctp_flush_out; | |
1da177e4 LT |
1124 | |
1125 | case SCTP_XMIT_OK: | |
b93d6471 WY |
1126 | /* The sender is in the SHUTDOWN-PENDING state, |
1127 | * The sender MAY set the I-bit in the DATA | |
1128 | * chunk header. | |
1129 | */ | |
1130 | if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING) | |
1131 | chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM; | |
196d6759 MB |
1132 | if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) |
1133 | asoc->stats.ouodchunks++; | |
1134 | else | |
1135 | asoc->stats.oodchunks++; | |
b93d6471 | 1136 | |
1da177e4 LT |
1137 | break; |
1138 | ||
1139 | default: | |
1140 | BUG(); | |
1141 | } | |
1142 | ||
d808ad9a | 1143 | /* BUG: We assume that the sctp_packet_transmit() |
1da177e4 LT |
1144 | * call below will succeed all the time and add the |
1145 | * chunk to the transmitted list and restart the | |
1146 | * timers. | |
1147 | * It is possible that the call can fail under OOM | |
1148 | * conditions. | |
1149 | * | |
1150 | * Is this really a problem? Won't this behave | |
1151 | * like a lost TSN? | |
1152 | */ | |
1153 | list_add_tail(&chunk->transmitted_list, | |
1154 | &transport->transmitted); | |
1155 | ||
ba6f5e33 MRL |
1156 | sctp_transport_reset_t3_rtx(transport); |
1157 | transport->last_time_sent = jiffies; | |
1da177e4 | 1158 | |
1da177e4 LT |
1159 | /* Only let one DATA chunk get bundled with a |
1160 | * COOKIE-ECHO chunk. | |
1161 | */ | |
1162 | if (packet->has_cookie_echo) | |
1163 | goto sctp_flush_out; | |
1164 | } | |
1165 | break; | |
1166 | ||
1167 | default: | |
1168 | /* Do nothing. */ | |
1169 | break; | |
1170 | } | |
1171 | ||
1172 | sctp_flush_out: | |
1173 | ||
1174 | /* Before returning, examine all the transports touched in | |
1175 | * this call. Right now, we bluntly force clear all the | |
1176 | * transports. Things might change after we implement Nagle. | |
1177 | * But such an examination is still required. | |
1178 | * | |
1179 | * --xguo | |
1180 | */ | |
cb3f837b | 1181 | while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL) { |
1da177e4 LT |
1182 | struct sctp_transport *t = list_entry(ltransport, |
1183 | struct sctp_transport, | |
1184 | send_ready); | |
1185 | packet = &t->packet; | |
64519440 | 1186 | if (!sctp_packet_empty(packet)) { |
cea8768f | 1187 | error = sctp_packet_transmit(packet, gfp); |
64519440 XL |
1188 | if (error < 0) |
1189 | asoc->base.sk->sk_err = -error; | |
1190 | } | |
46d5a808 VY |
1191 | |
1192 | /* Clear the burst limited state, if any */ | |
1193 | sctp_transport_burst_reset(t); | |
1da177e4 | 1194 | } |
1da177e4 LT |
1195 | } |
1196 | ||
1197 | /* Update unack_data based on the incoming SACK chunk */ | |
1198 | static void sctp_sack_update_unack_data(struct sctp_association *assoc, | |
1199 | struct sctp_sackhdr *sack) | |
1200 | { | |
afd93b7b | 1201 | union sctp_sack_variable *frags; |
1da177e4 LT |
1202 | __u16 unack_data; |
1203 | int i; | |
1204 | ||
1205 | unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1; | |
1206 | ||
1207 | frags = sack->variable; | |
1208 | for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) { | |
1209 | unack_data -= ((ntohs(frags[i].gab.end) - | |
1210 | ntohs(frags[i].gab.start) + 1)); | |
1211 | } | |
1212 | ||
1213 | assoc->unack_data = unack_data; | |
1214 | } | |
1215 | ||
1da177e4 LT |
1216 | /* This is where we REALLY process a SACK. |
1217 | * | |
1218 | * Process the SACK against the outqueue. Mostly, this just frees | |
1219 | * things off the transmitted queue. | |
1220 | */ | |
edfee033 | 1221 | int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk) |
1da177e4 LT |
1222 | { |
1223 | struct sctp_association *asoc = q->asoc; | |
edfee033 | 1224 | struct sctp_sackhdr *sack = chunk->subh.sack_hdr; |
1da177e4 LT |
1225 | struct sctp_transport *transport; |
1226 | struct sctp_chunk *tchunk = NULL; | |
9dbc15f0 | 1227 | struct list_head *lchunk, *transport_list, *temp; |
afd93b7b | 1228 | union sctp_sack_variable *frags = sack->variable; |
1da177e4 LT |
1229 | __u32 sack_ctsn, ctsn, tsn; |
1230 | __u32 highest_tsn, highest_new_tsn; | |
1231 | __u32 sack_a_rwnd; | |
95c96174 | 1232 | unsigned int outstanding; |
1da177e4 LT |
1233 | struct sctp_transport *primary = asoc->peer.primary_path; |
1234 | int count_of_newacks = 0; | |
2cd9b822 | 1235 | int gap_ack_blocks; |
ea862c8d | 1236 | u8 accum_moved = 0; |
1da177e4 LT |
1237 | |
1238 | /* Grab the association's destination address list. */ | |
1239 | transport_list = &asoc->peer.transport_addr_list; | |
1240 | ||
1241 | sack_ctsn = ntohl(sack->cum_tsn_ack); | |
2cd9b822 | 1242 | gap_ack_blocks = ntohs(sack->num_gap_ack_blocks); |
196d6759 | 1243 | asoc->stats.gapcnt += gap_ack_blocks; |
1da177e4 LT |
1244 | /* |
1245 | * SFR-CACC algorithm: | |
1246 | * On receipt of a SACK the sender SHOULD execute the | |
1247 | * following statements. | |
1248 | * | |
1249 | * 1) If the cumulative ack in the SACK passes next tsn_at_change | |
1250 | * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be | |
1251 | * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for | |
1252 | * all destinations. | |
1da177e4 LT |
1253 | * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE |
1254 | * is set the receiver of the SACK MUST take the following actions: | |
1255 | * | |
1256 | * A) Initialize the cacc_saw_newack to 0 for all destination | |
1257 | * addresses. | |
ab5216a5 VY |
1258 | * |
1259 | * Only bother if changeover_active is set. Otherwise, this is | |
1260 | * totally suboptimal to do on every SACK. | |
1da177e4 | 1261 | */ |
ab5216a5 VY |
1262 | if (primary->cacc.changeover_active) { |
1263 | u8 clear_cycling = 0; | |
1264 | ||
1265 | if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) { | |
1266 | primary->cacc.changeover_active = 0; | |
1267 | clear_cycling = 1; | |
1268 | } | |
1269 | ||
1270 | if (clear_cycling || gap_ack_blocks) { | |
1271 | list_for_each_entry(transport, transport_list, | |
1272 | transports) { | |
1273 | if (clear_cycling) | |
1274 | transport->cacc.cycling_changeover = 0; | |
1275 | if (gap_ack_blocks) | |
1276 | transport->cacc.cacc_saw_newack = 0; | |
1277 | } | |
1da177e4 LT |
1278 | } |
1279 | } | |
1280 | ||
1281 | /* Get the highest TSN in the sack. */ | |
1282 | highest_tsn = sack_ctsn; | |
2cd9b822 VY |
1283 | if (gap_ack_blocks) |
1284 | highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end); | |
1da177e4 | 1285 | |
bfa0d984 | 1286 | if (TSN_lt(asoc->highest_sacked, highest_tsn)) |
1da177e4 | 1287 | asoc->highest_sacked = highest_tsn; |
1da177e4 | 1288 | |
bfa0d984 | 1289 | highest_new_tsn = sack_ctsn; |
2cd9b822 | 1290 | |
1da177e4 LT |
1291 | /* Run through the retransmit queue. Credit bytes received |
1292 | * and free those chunks that we can. | |
1293 | */ | |
edfee033 | 1294 | sctp_check_transmitted(q, &q->retransmit, NULL, NULL, sack, &highest_new_tsn); |
1da177e4 LT |
1295 | |
1296 | /* Run through the transmitted queue. | |
1297 | * Credit bytes received and free those chunks which we can. | |
1298 | * | |
1299 | * This is a MASSIVE candidate for optimization. | |
1300 | */ | |
9dbc15f0 | 1301 | list_for_each_entry(transport, transport_list, transports) { |
1da177e4 | 1302 | sctp_check_transmitted(q, &transport->transmitted, |
edfee033 ND |
1303 | transport, &chunk->source, sack, |
1304 | &highest_new_tsn); | |
1da177e4 LT |
1305 | /* |
1306 | * SFR-CACC algorithm: | |
1307 | * C) Let count_of_newacks be the number of | |
1308 | * destinations for which cacc_saw_newack is set. | |
1309 | */ | |
1310 | if (transport->cacc.cacc_saw_newack) | |
cb3f837b | 1311 | count_of_newacks++; |
1da177e4 LT |
1312 | } |
1313 | ||
ea862c8d VY |
1314 | /* Move the Cumulative TSN Ack Point if appropriate. */ |
1315 | if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn)) { | |
1316 | asoc->ctsn_ack_point = sack_ctsn; | |
1317 | accum_moved = 1; | |
1318 | } | |
1319 | ||
2cd9b822 | 1320 | if (gap_ack_blocks) { |
ea862c8d VY |
1321 | |
1322 | if (asoc->fast_recovery && accum_moved) | |
1323 | highest_new_tsn = highest_tsn; | |
1324 | ||
2cd9b822 VY |
1325 | list_for_each_entry(transport, transport_list, transports) |
1326 | sctp_mark_missing(q, &transport->transmitted, transport, | |
1327 | highest_new_tsn, count_of_newacks); | |
1da177e4 LT |
1328 | } |
1329 | ||
1da177e4 LT |
1330 | /* Update unack_data field in the assoc. */ |
1331 | sctp_sack_update_unack_data(asoc, sack); | |
1332 | ||
1333 | ctsn = asoc->ctsn_ack_point; | |
1334 | ||
1335 | /* Throw away stuff rotting on the sack queue. */ | |
1336 | list_for_each_safe(lchunk, temp, &q->sacked) { | |
1337 | tchunk = list_entry(lchunk, struct sctp_chunk, | |
1338 | transmitted_list); | |
1339 | tsn = ntohl(tchunk->subh.data_hdr->tsn); | |
5f9646c3 VY |
1340 | if (TSN_lte(tsn, ctsn)) { |
1341 | list_del_init(&tchunk->transmitted_list); | |
be4947bf | 1342 | if (asoc->peer.prsctp_capable && |
8dbdf1f5 XL |
1343 | SCTP_PR_PRIO_ENABLED(chunk->sinfo.sinfo_flags)) |
1344 | asoc->sent_cnt_removable--; | |
1da177e4 | 1345 | sctp_chunk_free(tchunk); |
5f9646c3 | 1346 | } |
1da177e4 LT |
1347 | } |
1348 | ||
1349 | /* ii) Set rwnd equal to the newly received a_rwnd minus the | |
1350 | * number of bytes still outstanding after processing the | |
1351 | * Cumulative TSN Ack and the Gap Ack Blocks. | |
1352 | */ | |
1353 | ||
1354 | sack_a_rwnd = ntohl(sack->a_rwnd); | |
8a0d19c5 | 1355 | asoc->peer.zero_window_announced = !sack_a_rwnd; |
1da177e4 LT |
1356 | outstanding = q->outstanding_bytes; |
1357 | ||
1358 | if (outstanding < sack_a_rwnd) | |
1359 | sack_a_rwnd -= outstanding; | |
1360 | else | |
1361 | sack_a_rwnd = 0; | |
1362 | ||
1363 | asoc->peer.rwnd = sack_a_rwnd; | |
1364 | ||
1365 | sctp_generate_fwdtsn(q, sack_ctsn); | |
1366 | ||
bb33381d DB |
1367 | pr_debug("%s: sack cumulative tsn ack:0x%x\n", __func__, sack_ctsn); |
1368 | pr_debug("%s: cumulative tsn ack of assoc:%p is 0x%x, " | |
1369 | "advertised peer ack point:0x%x\n", __func__, asoc, ctsn, | |
1370 | asoc->adv_peer_ack_point); | |
1da177e4 | 1371 | |
619a60ee | 1372 | return sctp_outq_is_empty(q); |
1da177e4 LT |
1373 | } |
1374 | ||
619a60ee VY |
1375 | /* Is the outqueue empty? |
1376 | * The queue is empty when we have not pending data, no in-flight data | |
1377 | * and nothing pending retransmissions. | |
1378 | */ | |
1da177e4 LT |
1379 | int sctp_outq_is_empty(const struct sctp_outq *q) |
1380 | { | |
619a60ee VY |
1381 | return q->out_qlen == 0 && q->outstanding_bytes == 0 && |
1382 | list_empty(&q->retransmit); | |
1da177e4 LT |
1383 | } |
1384 | ||
1385 | /******************************************************************** | |
1386 | * 2nd Level Abstractions | |
1387 | ********************************************************************/ | |
1388 | ||
1389 | /* Go through a transport's transmitted list or the association's retransmit | |
1390 | * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked. | |
1391 | * The retransmit list will not have an associated transport. | |
1392 | * | |
1393 | * I added coherent debug information output. --xguo | |
1394 | * | |
1395 | * Instead of printing 'sacked' or 'kept' for each TSN on the | |
1396 | * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5. | |
1397 | * KEPT TSN6-TSN7, etc. | |
1398 | */ | |
1399 | static void sctp_check_transmitted(struct sctp_outq *q, | |
1400 | struct list_head *transmitted_queue, | |
1401 | struct sctp_transport *transport, | |
edfee033 | 1402 | union sctp_addr *saddr, |
1da177e4 | 1403 | struct sctp_sackhdr *sack, |
bfa0d984 | 1404 | __u32 *highest_new_tsn_in_sack) |
1da177e4 LT |
1405 | { |
1406 | struct list_head *lchunk; | |
1407 | struct sctp_chunk *tchunk; | |
1408 | struct list_head tlist; | |
1409 | __u32 tsn; | |
1410 | __u32 sack_ctsn; | |
1411 | __u32 rtt; | |
1412 | __u8 restart_timer = 0; | |
1413 | int bytes_acked = 0; | |
31b02e15 | 1414 | int migrate_bytes = 0; |
8c2f414a | 1415 | bool forward_progress = false; |
1da177e4 | 1416 | |
1da177e4 LT |
1417 | sack_ctsn = ntohl(sack->cum_tsn_ack); |
1418 | ||
1419 | INIT_LIST_HEAD(&tlist); | |
1420 | ||
1421 | /* The while loop will skip empty transmitted queues. */ | |
1422 | while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) { | |
1423 | tchunk = list_entry(lchunk, struct sctp_chunk, | |
1424 | transmitted_list); | |
1425 | ||
1426 | if (sctp_chunk_abandoned(tchunk)) { | |
1427 | /* Move the chunk to abandoned list. */ | |
1428 | sctp_insert_list(&q->abandoned, lchunk); | |
8c4a2d41 VY |
1429 | |
1430 | /* If this chunk has not been acked, stop | |
1431 | * considering it as 'outstanding'. | |
1432 | */ | |
7a7bcee6 XL |
1433 | if (transmitted_queue != &q->retransmit && |
1434 | !tchunk->tsn_gap_acked) { | |
31b02e15 VY |
1435 | if (tchunk->transport) |
1436 | tchunk->transport->flight_size -= | |
1437 | sctp_data_size(tchunk); | |
8c4a2d41 VY |
1438 | q->outstanding_bytes -= sctp_data_size(tchunk); |
1439 | } | |
1da177e4 LT |
1440 | continue; |
1441 | } | |
1442 | ||
1443 | tsn = ntohl(tchunk->subh.data_hdr->tsn); | |
1444 | if (sctp_acked(sack, tsn)) { | |
1445 | /* If this queue is the retransmit queue, the | |
1446 | * retransmit timer has already reclaimed | |
1447 | * the outstanding bytes for this chunk, so only | |
1448 | * count bytes associated with a transport. | |
1449 | */ | |
1450 | if (transport) { | |
1451 | /* If this chunk is being used for RTT | |
1452 | * measurement, calculate the RTT and update | |
1453 | * the RTO using this value. | |
1454 | * | |
1455 | * 6.3.1 C5) Karn's algorithm: RTT measurements | |
1456 | * MUST NOT be made using packets that were | |
1457 | * retransmitted (and thus for which it is | |
1458 | * ambiguous whether the reply was for the | |
1459 | * first instance of the packet or a later | |
1460 | * instance). | |
1461 | */ | |
d808ad9a | 1462 | if (!tchunk->tsn_gap_acked && |
cc6ac9bc | 1463 | !sctp_chunk_retransmitted(tchunk) && |
1da177e4 | 1464 | tchunk->rtt_in_progress) { |
4c9f5d53 | 1465 | tchunk->rtt_in_progress = 0; |
1da177e4 LT |
1466 | rtt = jiffies - tchunk->sent_at; |
1467 | sctp_transport_update_rto(transport, | |
1468 | rtt); | |
1469 | } | |
1470 | } | |
31b02e15 VY |
1471 | |
1472 | /* If the chunk hasn't been marked as ACKED, | |
1473 | * mark it and account bytes_acked if the | |
1474 | * chunk had a valid transport (it will not | |
1475 | * have a transport if ASCONF had deleted it | |
1476 | * while DATA was outstanding). | |
1477 | */ | |
1478 | if (!tchunk->tsn_gap_acked) { | |
1479 | tchunk->tsn_gap_acked = 1; | |
d6c41614 CX |
1480 | if (TSN_lt(*highest_new_tsn_in_sack, tsn)) |
1481 | *highest_new_tsn_in_sack = tsn; | |
31b02e15 VY |
1482 | bytes_acked += sctp_data_size(tchunk); |
1483 | if (!tchunk->transport) | |
1484 | migrate_bytes += sctp_data_size(tchunk); | |
8c2f414a | 1485 | forward_progress = true; |
31b02e15 VY |
1486 | } |
1487 | ||
d808ad9a | 1488 | if (TSN_lte(tsn, sack_ctsn)) { |
1da177e4 LT |
1489 | /* RFC 2960 6.3.2 Retransmission Timer Rules |
1490 | * | |
1491 | * R3) Whenever a SACK is received | |
1492 | * that acknowledges the DATA chunk | |
1493 | * with the earliest outstanding TSN | |
1494 | * for that address, restart T3-rtx | |
1495 | * timer for that address with its | |
1496 | * current RTO. | |
1497 | */ | |
1498 | restart_timer = 1; | |
8c2f414a | 1499 | forward_progress = true; |
1da177e4 LT |
1500 | |
1501 | if (!tchunk->tsn_gap_acked) { | |
1da177e4 LT |
1502 | /* |
1503 | * SFR-CACC algorithm: | |
1504 | * 2) If the SACK contains gap acks | |
1505 | * and the flag CHANGEOVER_ACTIVE is | |
1506 | * set the receiver of the SACK MUST | |
1507 | * take the following action: | |
1508 | * | |
1509 | * B) For each TSN t being acked that | |
1510 | * has not been acked in any SACK so | |
1511 | * far, set cacc_saw_newack to 1 for | |
1512 | * the destination that the TSN was | |
1513 | * sent to. | |
1514 | */ | |
1515 | if (transport && | |
1516 | sack->num_gap_ack_blocks && | |
1517 | q->asoc->peer.primary_path->cacc. | |
1518 | changeover_active) | |
1519 | transport->cacc.cacc_saw_newack | |
1520 | = 1; | |
1521 | } | |
1522 | ||
1523 | list_add_tail(&tchunk->transmitted_list, | |
1524 | &q->sacked); | |
1525 | } else { | |
1526 | /* RFC2960 7.2.4, sctpimpguide-05 2.8.2 | |
1527 | * M2) Each time a SACK arrives reporting | |
1528 | * 'Stray DATA chunk(s)' record the highest TSN | |
1529 | * reported as newly acknowledged, call this | |
1530 | * value 'HighestTSNinSack'. A newly | |
1531 | * acknowledged DATA chunk is one not | |
1532 | * previously acknowledged in a SACK. | |
1533 | * | |
1534 | * When the SCTP sender of data receives a SACK | |
1535 | * chunk that acknowledges, for the first time, | |
1536 | * the receipt of a DATA chunk, all the still | |
1537 | * unacknowledged DATA chunks whose TSN is | |
1538 | * older than that newly acknowledged DATA | |
1539 | * chunk, are qualified as 'Stray DATA chunks'. | |
1540 | */ | |
1da177e4 LT |
1541 | list_add_tail(lchunk, &tlist); |
1542 | } | |
1da177e4 LT |
1543 | } else { |
1544 | if (tchunk->tsn_gap_acked) { | |
bb33381d DB |
1545 | pr_debug("%s: receiver reneged on data TSN:0x%x\n", |
1546 | __func__, tsn); | |
1547 | ||
1da177e4 LT |
1548 | tchunk->tsn_gap_acked = 0; |
1549 | ||
31b02e15 VY |
1550 | if (tchunk->transport) |
1551 | bytes_acked -= sctp_data_size(tchunk); | |
1da177e4 LT |
1552 | |
1553 | /* RFC 2960 6.3.2 Retransmission Timer Rules | |
1554 | * | |
1555 | * R4) Whenever a SACK is received missing a | |
1556 | * TSN that was previously acknowledged via a | |
1557 | * Gap Ack Block, start T3-rtx for the | |
1558 | * destination address to which the DATA | |
1559 | * chunk was originally | |
1560 | * transmitted if it is not already running. | |
1561 | */ | |
1562 | restart_timer = 1; | |
1563 | } | |
1564 | ||
1565 | list_add_tail(lchunk, &tlist); | |
1da177e4 LT |
1566 | } |
1567 | } | |
1568 | ||
1da177e4 LT |
1569 | if (transport) { |
1570 | if (bytes_acked) { | |
f8d96052 TG |
1571 | struct sctp_association *asoc = transport->asoc; |
1572 | ||
31b02e15 VY |
1573 | /* We may have counted DATA that was migrated |
1574 | * to this transport due to DEL-IP operation. | |
1575 | * Subtract those bytes, since the were never | |
1576 | * send on this transport and shouldn't be | |
1577 | * credited to this transport. | |
1578 | */ | |
1579 | bytes_acked -= migrate_bytes; | |
1580 | ||
1da177e4 LT |
1581 | /* 8.2. When an outstanding TSN is acknowledged, |
1582 | * the endpoint shall clear the error counter of | |
1583 | * the destination transport address to which the | |
1584 | * DATA chunk was last sent. | |
1585 | * The association's overall error counter is | |
1586 | * also cleared. | |
1587 | */ | |
1588 | transport->error_count = 0; | |
1589 | transport->asoc->overall_error_count = 0; | |
8c2f414a | 1590 | forward_progress = true; |
1da177e4 | 1591 | |
f8d96052 TG |
1592 | /* |
1593 | * While in SHUTDOWN PENDING, we may have started | |
1594 | * the T5 shutdown guard timer after reaching the | |
1595 | * retransmission limit. Stop that timer as soon | |
1596 | * as the receiver acknowledged any data. | |
1597 | */ | |
1598 | if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING && | |
1599 | del_timer(&asoc->timers | |
1600 | [SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD])) | |
1601 | sctp_association_put(asoc); | |
1602 | ||
1da177e4 LT |
1603 | /* Mark the destination transport address as |
1604 | * active if it is not so marked. | |
1605 | */ | |
edfee033 ND |
1606 | if ((transport->state == SCTP_INACTIVE || |
1607 | transport->state == SCTP_UNCONFIRMED) && | |
1608 | sctp_cmp_addr_exact(&transport->ipaddr, saddr)) { | |
1da177e4 LT |
1609 | sctp_assoc_control_transport( |
1610 | transport->asoc, | |
1611 | transport, | |
1612 | SCTP_TRANSPORT_UP, | |
1613 | SCTP_RECEIVED_SACK); | |
1614 | } | |
1615 | ||
1616 | sctp_transport_raise_cwnd(transport, sack_ctsn, | |
1617 | bytes_acked); | |
1618 | ||
1619 | transport->flight_size -= bytes_acked; | |
8b73a07c GJ |
1620 | if (transport->flight_size == 0) |
1621 | transport->partial_bytes_acked = 0; | |
31b02e15 | 1622 | q->outstanding_bytes -= bytes_acked + migrate_bytes; |
1da177e4 LT |
1623 | } else { |
1624 | /* RFC 2960 6.1, sctpimpguide-06 2.15.2 | |
1625 | * When a sender is doing zero window probing, it | |
1626 | * should not timeout the association if it continues | |
1627 | * to receive new packets from the receiver. The | |
1628 | * reason is that the receiver MAY keep its window | |
1629 | * closed for an indefinite time. | |
1630 | * A sender is doing zero window probing when the | |
1631 | * receiver's advertised window is zero, and there is | |
1632 | * only one data chunk in flight to the receiver. | |
f8d96052 TG |
1633 | * |
1634 | * Allow the association to timeout while in SHUTDOWN | |
1635 | * PENDING or SHUTDOWN RECEIVED in case the receiver | |
1636 | * stays in zero window mode forever. | |
1da177e4 LT |
1637 | */ |
1638 | if (!q->asoc->peer.rwnd && | |
1639 | !list_empty(&tlist) && | |
f8d96052 TG |
1640 | (sack_ctsn+2 == q->asoc->next_tsn) && |
1641 | q->asoc->state < SCTP_STATE_SHUTDOWN_PENDING) { | |
bb33381d DB |
1642 | pr_debug("%s: sack received for zero window " |
1643 | "probe:%u\n", __func__, sack_ctsn); | |
1644 | ||
1da177e4 LT |
1645 | q->asoc->overall_error_count = 0; |
1646 | transport->error_count = 0; | |
1647 | } | |
1648 | } | |
1649 | ||
1650 | /* RFC 2960 6.3.2 Retransmission Timer Rules | |
1651 | * | |
1652 | * R2) Whenever all outstanding data sent to an address have | |
1653 | * been acknowledged, turn off the T3-rtx timer of that | |
1654 | * address. | |
1655 | */ | |
1656 | if (!transport->flight_size) { | |
25cc4ae9 | 1657 | if (del_timer(&transport->T3_rtx_timer)) |
1da177e4 | 1658 | sctp_transport_put(transport); |
1da177e4 LT |
1659 | } else if (restart_timer) { |
1660 | if (!mod_timer(&transport->T3_rtx_timer, | |
1661 | jiffies + transport->rto)) | |
1662 | sctp_transport_hold(transport); | |
1663 | } | |
8c2f414a DB |
1664 | |
1665 | if (forward_progress) { | |
1666 | if (transport->dst) | |
c86a773c | 1667 | sctp_transport_dst_confirm(transport); |
8c2f414a | 1668 | } |
1da177e4 LT |
1669 | } |
1670 | ||
1671 | list_splice(&tlist, transmitted_queue); | |
1672 | } | |
1673 | ||
1674 | /* Mark chunks as missing and consequently may get retransmitted. */ | |
1675 | static void sctp_mark_missing(struct sctp_outq *q, | |
1676 | struct list_head *transmitted_queue, | |
1677 | struct sctp_transport *transport, | |
1678 | __u32 highest_new_tsn_in_sack, | |
1679 | int count_of_newacks) | |
1680 | { | |
1681 | struct sctp_chunk *chunk; | |
1da177e4 LT |
1682 | __u32 tsn; |
1683 | char do_fast_retransmit = 0; | |
ea862c8d VY |
1684 | struct sctp_association *asoc = q->asoc; |
1685 | struct sctp_transport *primary = asoc->peer.primary_path; | |
1da177e4 | 1686 | |
9dbc15f0 | 1687 | list_for_each_entry(chunk, transmitted_queue, transmitted_list) { |
1da177e4 | 1688 | |
1da177e4 LT |
1689 | tsn = ntohl(chunk->subh.data_hdr->tsn); |
1690 | ||
1691 | /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all | |
1692 | * 'Unacknowledged TSN's', if the TSN number of an | |
1693 | * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack' | |
1694 | * value, increment the 'TSN.Missing.Report' count on that | |
1695 | * chunk if it has NOT been fast retransmitted or marked for | |
1696 | * fast retransmit already. | |
1697 | */ | |
c226ef9b | 1698 | if (chunk->fast_retransmit == SCTP_CAN_FRTX && |
1da177e4 LT |
1699 | !chunk->tsn_gap_acked && |
1700 | TSN_lt(tsn, highest_new_tsn_in_sack)) { | |
1701 | ||
1702 | /* SFR-CACC may require us to skip marking | |
1703 | * this chunk as missing. | |
1704 | */ | |
f246a7b7 VY |
1705 | if (!transport || !sctp_cacc_skip(primary, |
1706 | chunk->transport, | |
1707 | count_of_newacks, tsn)) { | |
1da177e4 LT |
1708 | chunk->tsn_missing_report++; |
1709 | ||
bb33381d DB |
1710 | pr_debug("%s: tsn:0x%x missing counter:%d\n", |
1711 | __func__, tsn, chunk->tsn_missing_report); | |
1da177e4 LT |
1712 | } |
1713 | } | |
1714 | /* | |
1715 | * M4) If any DATA chunk is found to have a | |
1716 | * 'TSN.Missing.Report' | |
27852c26 | 1717 | * value larger than or equal to 3, mark that chunk for |
1da177e4 LT |
1718 | * retransmission and start the fast retransmit procedure. |
1719 | */ | |
1720 | ||
27852c26 | 1721 | if (chunk->tsn_missing_report >= 3) { |
c226ef9b | 1722 | chunk->fast_retransmit = SCTP_NEED_FRTX; |
1da177e4 LT |
1723 | do_fast_retransmit = 1; |
1724 | } | |
1725 | } | |
1726 | ||
1727 | if (transport) { | |
1728 | if (do_fast_retransmit) | |
1729 | sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX); | |
1730 | ||
bb33381d DB |
1731 | pr_debug("%s: transport:%p, cwnd:%d, ssthresh:%d, " |
1732 | "flight_size:%d, pba:%d\n", __func__, transport, | |
1733 | transport->cwnd, transport->ssthresh, | |
1734 | transport->flight_size, transport->partial_bytes_acked); | |
1da177e4 LT |
1735 | } |
1736 | } | |
1737 | ||
1738 | /* Is the given TSN acked by this packet? */ | |
1739 | static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn) | |
1740 | { | |
1da177e4 | 1741 | __u32 ctsn = ntohl(sack->cum_tsn_ack); |
afd93b7b XL |
1742 | union sctp_sack_variable *frags; |
1743 | __u16 tsn_offset, blocks; | |
1744 | int i; | |
1da177e4 | 1745 | |
d808ad9a | 1746 | if (TSN_lte(tsn, ctsn)) |
1da177e4 LT |
1747 | goto pass; |
1748 | ||
1749 | /* 3.3.4 Selective Acknowledgement (SACK) (3): | |
1750 | * | |
1751 | * Gap Ack Blocks: | |
1752 | * These fields contain the Gap Ack Blocks. They are repeated | |
1753 | * for each Gap Ack Block up to the number of Gap Ack Blocks | |
1754 | * defined in the Number of Gap Ack Blocks field. All DATA | |
1755 | * chunks with TSNs greater than or equal to (Cumulative TSN | |
1756 | * Ack + Gap Ack Block Start) and less than or equal to | |
1757 | * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack | |
1758 | * Block are assumed to have been received correctly. | |
1759 | */ | |
1760 | ||
1761 | frags = sack->variable; | |
a3007446 MRL |
1762 | blocks = ntohs(sack->num_gap_ack_blocks); |
1763 | tsn_offset = tsn - ctsn; | |
1764 | for (i = 0; i < blocks; ++i) { | |
1765 | if (tsn_offset >= ntohs(frags[i].gab.start) && | |
1766 | tsn_offset <= ntohs(frags[i].gab.end)) | |
1da177e4 LT |
1767 | goto pass; |
1768 | } | |
1769 | ||
1770 | return 0; | |
1771 | pass: | |
1772 | return 1; | |
1773 | } | |
1774 | ||
1775 | static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist, | |
9f81bcd9 | 1776 | int nskips, __be16 stream) |
1da177e4 LT |
1777 | { |
1778 | int i; | |
1779 | ||
1780 | for (i = 0; i < nskips; i++) { | |
1781 | if (skiplist[i].stream == stream) | |
1782 | return i; | |
1783 | } | |
1784 | return i; | |
1785 | } | |
1786 | ||
1787 | /* Create and add a fwdtsn chunk to the outq's control queue if needed. */ | |
1788 | static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn) | |
1789 | { | |
1790 | struct sctp_association *asoc = q->asoc; | |
1791 | struct sctp_chunk *ftsn_chunk = NULL; | |
1792 | struct sctp_fwdtsn_skip ftsn_skip_arr[10]; | |
1793 | int nskips = 0; | |
1794 | int skip_pos = 0; | |
1795 | __u32 tsn; | |
1796 | struct sctp_chunk *chunk; | |
1797 | struct list_head *lchunk, *temp; | |
1798 | ||
76595024 WY |
1799 | if (!asoc->peer.prsctp_capable) |
1800 | return; | |
1801 | ||
1da177e4 LT |
1802 | /* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the |
1803 | * received SACK. | |
d808ad9a | 1804 | * |
1da177e4 LT |
1805 | * If (Advanced.Peer.Ack.Point < SackCumAck), then update |
1806 | * Advanced.Peer.Ack.Point to be equal to SackCumAck. | |
1807 | */ | |
1808 | if (TSN_lt(asoc->adv_peer_ack_point, ctsn)) | |
1809 | asoc->adv_peer_ack_point = ctsn; | |
1810 | ||
1811 | /* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point" | |
1812 | * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as | |
1813 | * the chunk next in the out-queue space is marked as "abandoned" as | |
1814 | * shown in the following example: | |
1815 | * | |
1816 | * Assuming that a SACK arrived with the Cumulative TSN ACK 102 | |
1817 | * and the Advanced.Peer.Ack.Point is updated to this value: | |
d808ad9a | 1818 | * |
1da177e4 LT |
1819 | * out-queue at the end of ==> out-queue after Adv.Ack.Point |
1820 | * normal SACK processing local advancement | |
1821 | * ... ... | |
1822 | * Adv.Ack.Pt-> 102 acked 102 acked | |
1823 | * 103 abandoned 103 abandoned | |
1824 | * 104 abandoned Adv.Ack.P-> 104 abandoned | |
1825 | * 105 105 | |
1826 | * 106 acked 106 acked | |
1827 | * ... ... | |
1828 | * | |
1829 | * In this example, the data sender successfully advanced the | |
1830 | * "Advanced.Peer.Ack.Point" from 102 to 104 locally. | |
1831 | */ | |
1832 | list_for_each_safe(lchunk, temp, &q->abandoned) { | |
1833 | chunk = list_entry(lchunk, struct sctp_chunk, | |
1834 | transmitted_list); | |
1835 | tsn = ntohl(chunk->subh.data_hdr->tsn); | |
1836 | ||
1837 | /* Remove any chunks in the abandoned queue that are acked by | |
1838 | * the ctsn. | |
d808ad9a | 1839 | */ |
1da177e4 LT |
1840 | if (TSN_lte(tsn, ctsn)) { |
1841 | list_del_init(lchunk); | |
1da177e4 LT |
1842 | sctp_chunk_free(chunk); |
1843 | } else { | |
1844 | if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) { | |
1845 | asoc->adv_peer_ack_point = tsn; | |
1846 | if (chunk->chunk_hdr->flags & | |
1847 | SCTP_DATA_UNORDERED) | |
1848 | continue; | |
1849 | skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0], | |
1850 | nskips, | |
1851 | chunk->subh.data_hdr->stream); | |
1852 | ftsn_skip_arr[skip_pos].stream = | |
1853 | chunk->subh.data_hdr->stream; | |
1854 | ftsn_skip_arr[skip_pos].ssn = | |
1855 | chunk->subh.data_hdr->ssn; | |
1856 | if (skip_pos == nskips) | |
1857 | nskips++; | |
1858 | if (nskips == 10) | |
1859 | break; | |
1860 | } else | |
1861 | break; | |
1862 | } | |
1863 | } | |
1864 | ||
1865 | /* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point" | |
1866 | * is greater than the Cumulative TSN ACK carried in the received | |
1867 | * SACK, the data sender MUST send the data receiver a FORWARD TSN | |
1868 | * chunk containing the latest value of the | |
1869 | * "Advanced.Peer.Ack.Point". | |
1870 | * | |
1871 | * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD | |
1872 | * list each stream and sequence number in the forwarded TSN. This | |
1873 | * information will enable the receiver to easily find any | |
1874 | * stranded TSN's waiting on stream reorder queues. Each stream | |
1875 | * SHOULD only be reported once; this means that if multiple | |
1876 | * abandoned messages occur in the same stream then only the | |
1877 | * highest abandoned stream sequence number is reported. If the | |
1878 | * total size of the FORWARD TSN does NOT fit in a single MTU then | |
1879 | * the sender of the FORWARD TSN SHOULD lower the | |
1880 | * Advanced.Peer.Ack.Point to the last TSN that will fit in a | |
1881 | * single MTU. | |
1882 | */ | |
1883 | if (asoc->adv_peer_ack_point > ctsn) | |
1884 | ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point, | |
d808ad9a | 1885 | nskips, &ftsn_skip_arr[0]); |
1da177e4 LT |
1886 | |
1887 | if (ftsn_chunk) { | |
79af02c2 | 1888 | list_add_tail(&ftsn_chunk->list, &q->control_chunk_list); |
b01a2407 | 1889 | SCTP_INC_STATS(sock_net(asoc->base.sk), SCTP_MIB_OUTCTRLCHUNKS); |
1da177e4 LT |
1890 | } |
1891 | } |