Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 1 | /* SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 7 | * This file is part of the SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * These functions implement the sctp_outq class. The outqueue handles |
| 10 | * bundling and queueing of outgoing SCTP chunks. |
| 11 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 12 | * This SCTP implementation is free software; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 18 | * This SCTP implementation is distributed in the hope that it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
| 25 | * along with GNU CC; see the file COPYING. If not, write to |
| 26 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
| 27 | * Boston, MA 02111-1307, USA. |
| 28 | * |
| 29 | * Please send any bug reports or fixes you make to the |
| 30 | * email address(es): |
| 31 | * lksctp developers <lksctp-developers@lists.sourceforge.net> |
| 32 | * |
| 33 | * Or submit a bug report through the following website: |
| 34 | * http://www.sf.net/projects/lksctp |
| 35 | * |
| 36 | * Written or modified by: |
| 37 | * La Monte H.P. Yarroll <piggy@acm.org> |
| 38 | * Karl Knutson <karl@athena.chicago.il.us> |
| 39 | * Perry Melange <pmelange@null.cc.uic.edu> |
| 40 | * Xingang Guo <xingang.guo@intel.com> |
| 41 | * Hui Huang <hui.huang@nokia.com> |
| 42 | * Sridhar Samudrala <sri@us.ibm.com> |
| 43 | * Jon Grimm <jgrimm@us.ibm.com> |
| 44 | * |
| 45 | * Any bugs reported given to us we will try to fix... any fixes shared will |
| 46 | * be incorporated into the next SCTP release. |
| 47 | */ |
| 48 | |
| 49 | #include <linux/types.h> |
| 50 | #include <linux/list.h> /* For struct list_head */ |
| 51 | #include <linux/socket.h> |
| 52 | #include <linux/ip.h> |
| 53 | #include <net/sock.h> /* For skb_set_owner_w */ |
| 54 | |
| 55 | #include <net/sctp/sctp.h> |
| 56 | #include <net/sctp/sm.h> |
| 57 | |
| 58 | /* Declare internal functions here. */ |
| 59 | static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn); |
| 60 | static void sctp_check_transmitted(struct sctp_outq *q, |
| 61 | struct list_head *transmitted_queue, |
| 62 | struct sctp_transport *transport, |
| 63 | struct sctp_sackhdr *sack, |
| 64 | __u32 highest_new_tsn); |
| 65 | |
| 66 | static void sctp_mark_missing(struct sctp_outq *q, |
| 67 | struct list_head *transmitted_queue, |
| 68 | struct sctp_transport *transport, |
| 69 | __u32 highest_new_tsn, |
| 70 | int count_of_newacks); |
| 71 | |
| 72 | static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn); |
| 73 | |
Adrian Bunk | abd0b198 | 2008-07-22 14:20:45 -0700 | [diff] [blame] | 74 | static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout); |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* Add data to the front of the queue. */ |
| 77 | static inline void sctp_outq_head_data(struct sctp_outq *q, |
| 78 | struct sctp_chunk *ch) |
| 79 | { |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 80 | list_add(&ch->list, &q->out_chunk_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | q->out_qlen += ch->skb->len; |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | /* Take data from the front of the queue. */ |
| 86 | static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q) |
| 87 | { |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 88 | struct sctp_chunk *ch = NULL; |
| 89 | |
| 90 | if (!list_empty(&q->out_chunk_list)) { |
| 91 | struct list_head *entry = q->out_chunk_list.next; |
| 92 | |
| 93 | ch = list_entry(entry, struct sctp_chunk, list); |
| 94 | list_del_init(entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | q->out_qlen -= ch->skb->len; |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 96 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | return ch; |
| 98 | } |
| 99 | /* Add data chunk to the end of the queue. */ |
| 100 | static inline void sctp_outq_tail_data(struct sctp_outq *q, |
| 101 | struct sctp_chunk *ch) |
| 102 | { |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 103 | list_add_tail(&ch->list, &q->out_chunk_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | q->out_qlen += ch->skb->len; |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * SFR-CACC algorithm: |
| 110 | * D) If count_of_newacks is greater than or equal to 2 |
| 111 | * and t was not sent to the current primary then the |
| 112 | * sender MUST NOT increment missing report count for t. |
| 113 | */ |
| 114 | static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary, |
| 115 | struct sctp_transport *transport, |
| 116 | int count_of_newacks) |
| 117 | { |
| 118 | if (count_of_newacks >=2 && transport != primary) |
| 119 | return 1; |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * SFR-CACC algorithm: |
| 125 | * F) If count_of_newacks is less than 2, let d be the |
| 126 | * destination to which t was sent. If cacc_saw_newack |
| 127 | * is 0 for destination d, then the sender MUST NOT |
| 128 | * increment missing report count for t. |
| 129 | */ |
| 130 | static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport, |
| 131 | int count_of_newacks) |
| 132 | { |
| 133 | if (count_of_newacks < 2 && !transport->cacc.cacc_saw_newack) |
| 134 | return 1; |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * SFR-CACC algorithm: |
| 140 | * 3.1) If CYCLING_CHANGEOVER is 0, the sender SHOULD |
| 141 | * execute steps C, D, F. |
| 142 | * |
| 143 | * C has been implemented in sctp_outq_sack |
| 144 | */ |
| 145 | static inline int sctp_cacc_skip_3_1(struct sctp_transport *primary, |
| 146 | struct sctp_transport *transport, |
| 147 | int count_of_newacks) |
| 148 | { |
| 149 | if (!primary->cacc.cycling_changeover) { |
| 150 | if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks)) |
| 151 | return 1; |
| 152 | if (sctp_cacc_skip_3_1_f(transport, count_of_newacks)) |
| 153 | return 1; |
| 154 | return 0; |
| 155 | } |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * SFR-CACC algorithm: |
| 161 | * 3.2) Else if CYCLING_CHANGEOVER is 1, and t is less |
| 162 | * than next_tsn_at_change of the current primary, then |
| 163 | * the sender MUST NOT increment missing report count |
| 164 | * for t. |
| 165 | */ |
| 166 | static inline int sctp_cacc_skip_3_2(struct sctp_transport *primary, __u32 tsn) |
| 167 | { |
| 168 | if (primary->cacc.cycling_changeover && |
| 169 | TSN_lt(tsn, primary->cacc.next_tsn_at_change)) |
| 170 | return 1; |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * SFR-CACC algorithm: |
| 176 | * 3) If the missing report count for TSN t is to be |
| 177 | * incremented according to [RFC2960] and |
| 178 | * [SCTP_STEWART-2002], and CHANGEOVER_ACTIVE is set, |
| 179 | * then the sender MUST futher execute steps 3.1 and |
| 180 | * 3.2 to determine if the missing report count for |
| 181 | * TSN t SHOULD NOT be incremented. |
| 182 | * |
| 183 | * 3.3) If 3.1 and 3.2 do not dictate that the missing |
| 184 | * report count for t should not be incremented, then |
| 185 | * the sender SOULD increment missing report count for |
| 186 | * t (according to [RFC2960] and [SCTP_STEWART_2002]). |
| 187 | */ |
| 188 | static inline int sctp_cacc_skip(struct sctp_transport *primary, |
| 189 | struct sctp_transport *transport, |
| 190 | int count_of_newacks, |
| 191 | __u32 tsn) |
| 192 | { |
| 193 | if (primary->cacc.changeover_active && |
| 194 | (sctp_cacc_skip_3_1(primary, transport, count_of_newacks) |
| 195 | || sctp_cacc_skip_3_2(primary, tsn))) |
| 196 | return 1; |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | /* Initialize an existing sctp_outq. This does the boring stuff. |
| 201 | * You still need to define handlers if you really want to DO |
| 202 | * something with this structure... |
| 203 | */ |
| 204 | void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q) |
| 205 | { |
| 206 | q->asoc = asoc; |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 207 | INIT_LIST_HEAD(&q->out_chunk_list); |
| 208 | INIT_LIST_HEAD(&q->control_chunk_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | INIT_LIST_HEAD(&q->retransmit); |
| 210 | INIT_LIST_HEAD(&q->sacked); |
| 211 | INIT_LIST_HEAD(&q->abandoned); |
| 212 | |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 213 | q->fast_rtx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | q->outstanding_bytes = 0; |
| 215 | q->empty = 1; |
| 216 | q->cork = 0; |
| 217 | |
| 218 | q->malloced = 0; |
| 219 | q->out_qlen = 0; |
| 220 | } |
| 221 | |
| 222 | /* Free the outqueue structure and any related pending chunks. |
| 223 | */ |
| 224 | void sctp_outq_teardown(struct sctp_outq *q) |
| 225 | { |
| 226 | struct sctp_transport *transport; |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 227 | struct list_head *lchunk, *temp; |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 228 | struct sctp_chunk *chunk, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | /* Throw away unacknowledged chunks. */ |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 231 | list_for_each_entry(transport, &q->asoc->peer.transport_addr_list, |
| 232 | transports) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | while ((lchunk = sctp_list_dequeue(&transport->transmitted)) != NULL) { |
| 234 | chunk = list_entry(lchunk, struct sctp_chunk, |
| 235 | transmitted_list); |
| 236 | /* Mark as part of a failed message. */ |
| 237 | sctp_chunk_fail(chunk, q->error); |
| 238 | sctp_chunk_free(chunk); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /* Throw away chunks that have been gap ACKed. */ |
| 243 | list_for_each_safe(lchunk, temp, &q->sacked) { |
| 244 | list_del_init(lchunk); |
| 245 | chunk = list_entry(lchunk, struct sctp_chunk, |
| 246 | transmitted_list); |
| 247 | sctp_chunk_fail(chunk, q->error); |
| 248 | sctp_chunk_free(chunk); |
| 249 | } |
| 250 | |
| 251 | /* Throw away any chunks in the retransmit queue. */ |
| 252 | list_for_each_safe(lchunk, temp, &q->retransmit) { |
| 253 | list_del_init(lchunk); |
| 254 | chunk = list_entry(lchunk, struct sctp_chunk, |
| 255 | transmitted_list); |
| 256 | sctp_chunk_fail(chunk, q->error); |
| 257 | sctp_chunk_free(chunk); |
| 258 | } |
| 259 | |
| 260 | /* Throw away any chunks that are in the abandoned queue. */ |
| 261 | list_for_each_safe(lchunk, temp, &q->abandoned) { |
| 262 | list_del_init(lchunk); |
| 263 | chunk = list_entry(lchunk, struct sctp_chunk, |
| 264 | transmitted_list); |
| 265 | sctp_chunk_fail(chunk, q->error); |
| 266 | sctp_chunk_free(chunk); |
| 267 | } |
| 268 | |
| 269 | /* Throw away any leftover data chunks. */ |
| 270 | while ((chunk = sctp_outq_dequeue_data(q)) != NULL) { |
| 271 | |
| 272 | /* Mark as send failure. */ |
| 273 | sctp_chunk_fail(chunk, q->error); |
| 274 | sctp_chunk_free(chunk); |
| 275 | } |
| 276 | |
| 277 | q->error = 0; |
| 278 | |
| 279 | /* Throw away any leftover control chunks. */ |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 280 | list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) { |
| 281 | list_del_init(&chunk->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | sctp_chunk_free(chunk); |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /* Free the outqueue structure and any related pending chunks. */ |
| 287 | void sctp_outq_free(struct sctp_outq *q) |
| 288 | { |
| 289 | /* Throw away leftover chunks. */ |
| 290 | sctp_outq_teardown(q); |
| 291 | |
| 292 | /* If we were kmalloc()'d, free the memory. */ |
| 293 | if (q->malloced) |
| 294 | kfree(q); |
| 295 | } |
| 296 | |
| 297 | /* Put a new chunk in an sctp_outq. */ |
| 298 | int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk) |
| 299 | { |
| 300 | int error = 0; |
| 301 | |
| 302 | SCTP_DEBUG_PRINTK("sctp_outq_tail(%p, %p[%s])\n", |
| 303 | q, chunk, chunk && chunk->chunk_hdr ? |
| 304 | sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) |
| 305 | : "Illegal Chunk"); |
| 306 | |
| 307 | /* If it is data, queue it up, otherwise, send it |
| 308 | * immediately. |
| 309 | */ |
| 310 | if (SCTP_CID_DATA == chunk->chunk_hdr->type) { |
| 311 | /* Is it OK to queue data chunks? */ |
| 312 | /* From 9. Termination of Association |
| 313 | * |
| 314 | * When either endpoint performs a shutdown, the |
| 315 | * association on each peer will stop accepting new |
| 316 | * data from its user and only deliver data in queue |
| 317 | * at the time of sending or receiving the SHUTDOWN |
| 318 | * chunk. |
| 319 | */ |
| 320 | switch (q->asoc->state) { |
| 321 | case SCTP_STATE_EMPTY: |
| 322 | case SCTP_STATE_CLOSED: |
| 323 | case SCTP_STATE_SHUTDOWN_PENDING: |
| 324 | case SCTP_STATE_SHUTDOWN_SENT: |
| 325 | case SCTP_STATE_SHUTDOWN_RECEIVED: |
| 326 | case SCTP_STATE_SHUTDOWN_ACK_SENT: |
| 327 | /* Cannot send after transport endpoint shutdown */ |
| 328 | error = -ESHUTDOWN; |
| 329 | break; |
| 330 | |
| 331 | default: |
| 332 | SCTP_DEBUG_PRINTK("outqueueing (%p, %p[%s])\n", |
| 333 | q, chunk, chunk && chunk->chunk_hdr ? |
| 334 | sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) |
| 335 | : "Illegal Chunk"); |
| 336 | |
| 337 | sctp_outq_tail_data(q, chunk); |
| 338 | if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) |
| 339 | SCTP_INC_STATS(SCTP_MIB_OUTUNORDERCHUNKS); |
| 340 | else |
| 341 | SCTP_INC_STATS(SCTP_MIB_OUTORDERCHUNKS); |
| 342 | q->empty = 0; |
| 343 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } else { |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 346 | list_add_tail(&chunk->list, &q->control_chunk_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
| 348 | } |
| 349 | |
| 350 | if (error < 0) |
| 351 | return error; |
| 352 | |
| 353 | if (!q->cork) |
| 354 | error = sctp_outq_flush(q, 0); |
| 355 | |
| 356 | return error; |
| 357 | } |
| 358 | |
| 359 | /* Insert a chunk into the sorted list based on the TSNs. The retransmit list |
| 360 | * and the abandoned list are in ascending order. |
| 361 | */ |
| 362 | static void sctp_insert_list(struct list_head *head, struct list_head *new) |
| 363 | { |
| 364 | struct list_head *pos; |
| 365 | struct sctp_chunk *nchunk, *lchunk; |
| 366 | __u32 ntsn, ltsn; |
| 367 | int done = 0; |
| 368 | |
| 369 | nchunk = list_entry(new, struct sctp_chunk, transmitted_list); |
| 370 | ntsn = ntohl(nchunk->subh.data_hdr->tsn); |
| 371 | |
| 372 | list_for_each(pos, head) { |
| 373 | lchunk = list_entry(pos, struct sctp_chunk, transmitted_list); |
| 374 | ltsn = ntohl(lchunk->subh.data_hdr->tsn); |
| 375 | if (TSN_lt(ntsn, ltsn)) { |
| 376 | list_add(new, pos->prev); |
| 377 | done = 1; |
| 378 | break; |
| 379 | } |
| 380 | } |
| 381 | if (!done) |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 382 | list_add_tail(new, head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /* Mark all the eligible packets on a transport for retransmission. */ |
| 386 | void sctp_retransmit_mark(struct sctp_outq *q, |
| 387 | struct sctp_transport *transport, |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 388 | __u8 reason) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | { |
| 390 | struct list_head *lchunk, *ltemp; |
| 391 | struct sctp_chunk *chunk; |
| 392 | |
| 393 | /* Walk through the specified transmitted queue. */ |
| 394 | list_for_each_safe(lchunk, ltemp, &transport->transmitted) { |
| 395 | chunk = list_entry(lchunk, struct sctp_chunk, |
| 396 | transmitted_list); |
| 397 | |
| 398 | /* If the chunk is abandoned, move it to abandoned list. */ |
| 399 | if (sctp_chunk_abandoned(chunk)) { |
| 400 | list_del_init(lchunk); |
| 401 | sctp_insert_list(&q->abandoned, lchunk); |
Vlad Yasevich | 8c4a2d4 | 2007-02-21 02:06:04 -0800 | [diff] [blame] | 402 | |
| 403 | /* If this chunk has not been previousely acked, |
| 404 | * stop considering it 'outstanding'. Our peer |
| 405 | * will most likely never see it since it will |
| 406 | * not be retransmitted |
| 407 | */ |
| 408 | if (!chunk->tsn_gap_acked) { |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 409 | if (chunk->transport) |
| 410 | chunk->transport->flight_size -= |
| 411 | sctp_data_size(chunk); |
Vlad Yasevich | 8c4a2d4 | 2007-02-21 02:06:04 -0800 | [diff] [blame] | 412 | q->outstanding_bytes -= sctp_data_size(chunk); |
| 413 | q->asoc->peer.rwnd += (sctp_data_size(chunk) + |
| 414 | sizeof(struct sk_buff)); |
| 415 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | continue; |
| 417 | } |
| 418 | |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 419 | /* If we are doing retransmission due to a timeout or pmtu |
| 420 | * discovery, only the chunks that are not yet acked should |
| 421 | * be added to the retransmit queue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | */ |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 423 | if ((reason == SCTP_RTXR_FAST_RTX && |
Neil Horman | c226ef9 | 2008-07-25 12:44:09 -0400 | [diff] [blame] | 424 | (chunk->fast_retransmit == SCTP_NEED_FRTX)) || |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 425 | (reason != SCTP_RTXR_FAST_RTX && !chunk->tsn_gap_acked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | /* RFC 2960 6.2.1 Processing a Received SACK |
| 427 | * |
| 428 | * C) Any time a DATA chunk is marked for |
| 429 | * retransmission (via either T3-rtx timer expiration |
| 430 | * (Section 6.3.3) or via fast retransmit |
| 431 | * (Section 7.2.4)), add the data size of those |
| 432 | * chunks to the rwnd. |
| 433 | */ |
Sridhar Samudrala | cd49788 | 2006-09-29 17:09:05 -0700 | [diff] [blame] | 434 | q->asoc->peer.rwnd += (sctp_data_size(chunk) + |
| 435 | sizeof(struct sk_buff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | q->outstanding_bytes -= sctp_data_size(chunk); |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 437 | if (chunk->transport) |
| 438 | transport->flight_size -= sctp_data_size(chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| 440 | /* sctpimpguide-05 Section 2.8.2 |
| 441 | * M5) If a T3-rtx timer expires, the |
| 442 | * 'TSN.Missing.Report' of all affected TSNs is set |
| 443 | * to 0. |
| 444 | */ |
| 445 | chunk->tsn_missing_report = 0; |
| 446 | |
| 447 | /* If a chunk that is being used for RTT measurement |
| 448 | * has to be retransmitted, we cannot use this chunk |
| 449 | * anymore for RTT measurements. Reset rto_pending so |
| 450 | * that a new RTT measurement is started when a new |
| 451 | * data chunk is sent. |
| 452 | */ |
| 453 | if (chunk->rtt_in_progress) { |
| 454 | chunk->rtt_in_progress = 0; |
| 455 | transport->rto_pending = 0; |
| 456 | } |
| 457 | |
| 458 | /* Move the chunk to the retransmit queue. The chunks |
| 459 | * on the retransmit queue are always kept in order. |
| 460 | */ |
| 461 | list_del_init(lchunk); |
| 462 | sctp_insert_list(&q->retransmit, lchunk); |
| 463 | } |
| 464 | } |
| 465 | |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 466 | SCTP_DEBUG_PRINTK("%s: transport: %p, reason: %d, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | "cwnd: %d, ssthresh: %d, flight_size: %d, " |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 468 | "pba: %d\n", __func__, |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 469 | transport, reason, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | transport->cwnd, transport->ssthresh, |
| 471 | transport->flight_size, |
| 472 | transport->partial_bytes_acked); |
| 473 | |
| 474 | } |
| 475 | |
| 476 | /* Mark all the eligible packets on a transport for retransmission and force |
| 477 | * one packet out. |
| 478 | */ |
| 479 | void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport, |
| 480 | sctp_retransmit_reason_t reason) |
| 481 | { |
| 482 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | switch(reason) { |
| 485 | case SCTP_RTXR_T3_RTX: |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 486 | SCTP_INC_STATS(SCTP_MIB_T3_RETRANSMITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX); |
| 488 | /* Update the retran path if the T3-rtx timer has expired for |
| 489 | * the current retran path. |
| 490 | */ |
| 491 | if (transport == transport->asoc->peer.retran_path) |
| 492 | sctp_assoc_update_retran_path(transport->asoc); |
Neil Horman | 58fbbed | 2008-02-29 11:40:56 -0800 | [diff] [blame] | 493 | transport->asoc->rtx_data_chunks += |
| 494 | transport->asoc->unack_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | break; |
| 496 | case SCTP_RTXR_FAST_RTX: |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 497 | SCTP_INC_STATS(SCTP_MIB_FAST_RETRANSMITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX); |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 499 | q->fast_rtx = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | break; |
| 501 | case SCTP_RTXR_PMTUD: |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 502 | SCTP_INC_STATS(SCTP_MIB_PMTUD_RETRANSMITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | break; |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 504 | case SCTP_RTXR_T1_RTX: |
| 505 | SCTP_INC_STATS(SCTP_MIB_T1_RETRANSMITS); |
Neil Horman | 58fbbed | 2008-02-29 11:40:56 -0800 | [diff] [blame] | 506 | transport->asoc->init_retries++; |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 507 | break; |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 508 | default: |
| 509 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 512 | sctp_retransmit_mark(q, transport, reason); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | /* PR-SCTP A5) Any time the T3-rtx timer expires, on any destination, |
| 515 | * the sender SHOULD try to advance the "Advanced.Peer.Ack.Point" by |
| 516 | * following the procedures outlined in C1 - C5. |
| 517 | */ |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 518 | if (reason == SCTP_RTXR_T3_RTX) |
| 519 | sctp_generate_fwdtsn(q, q->asoc->ctsn_ack_point); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 521 | /* Flush the queues only on timeout, since fast_rtx is only |
| 522 | * triggered during sack processing and the queue |
| 523 | * will be flushed at the end. |
| 524 | */ |
| 525 | if (reason != SCTP_RTXR_FAST_RTX) |
| 526 | error = sctp_outq_flush(q, /* rtx_timeout */ 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
| 528 | if (error) |
| 529 | q->asoc->base.sk->sk_err = -error; |
| 530 | } |
| 531 | |
| 532 | /* |
| 533 | * Transmit DATA chunks on the retransmit queue. Upon return from |
| 534 | * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which |
| 535 | * need to be transmitted by the caller. |
| 536 | * We assume that pkt->transport has already been set. |
| 537 | * |
| 538 | * The return value is a normal kernel error return value. |
| 539 | */ |
| 540 | static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt, |
| 541 | int rtx_timeout, int *start_timer) |
| 542 | { |
| 543 | struct list_head *lqueue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | struct sctp_transport *transport = pkt->transport; |
| 545 | sctp_xmit_t status; |
| 546 | struct sctp_chunk *chunk, *chunk1; |
| 547 | struct sctp_association *asoc; |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 548 | int fast_rtx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | int error = 0; |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 550 | int timer = 0; |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 551 | int done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
| 553 | asoc = q->asoc; |
| 554 | lqueue = &q->retransmit; |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 555 | fast_rtx = q->fast_rtx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 557 | /* This loop handles time-out retransmissions, fast retransmissions, |
| 558 | * and retransmissions due to opening of whindow. |
| 559 | * |
| 560 | * RFC 2960 6.3.3 Handle T3-rtx Expiration |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | * |
| 562 | * E3) Determine how many of the earliest (i.e., lowest TSN) |
| 563 | * outstanding DATA chunks for the address for which the |
| 564 | * T3-rtx has expired will fit into a single packet, subject |
| 565 | * to the MTU constraint for the path corresponding to the |
| 566 | * destination transport address to which the retransmission |
| 567 | * is being sent (this may be different from the address for |
| 568 | * which the timer expires [see Section 6.4]). Call this value |
| 569 | * K. Bundle and retransmit those K DATA chunks in a single |
| 570 | * packet to the destination endpoint. |
| 571 | * |
| 572 | * [Just to be painfully clear, if we are retransmitting |
| 573 | * because a timeout just happened, we should send only ONE |
| 574 | * packet of retransmitted data.] |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 575 | * |
| 576 | * For fast retransmissions we also send only ONE packet. However, |
| 577 | * if we are just flushing the queue due to open window, we'll |
| 578 | * try to send as much as possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | */ |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 580 | list_for_each_entry_safe(chunk, chunk1, lqueue, transmitted_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | /* Make sure that Gap Acked TSNs are not retransmitted. A |
| 583 | * simple approach is just to move such TSNs out of the |
| 584 | * way and into a 'transmitted' queue and skip to the |
| 585 | * next chunk. |
| 586 | */ |
| 587 | if (chunk->tsn_gap_acked) { |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 588 | list_del(&chunk->transmitted_list); |
| 589 | list_add_tail(&chunk->transmitted_list, |
| 590 | &transport->transmitted); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | continue; |
| 592 | } |
| 593 | |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 594 | /* If we are doing fast retransmit, ignore non-fast_rtransmit |
| 595 | * chunks |
| 596 | */ |
| 597 | if (fast_rtx && !chunk->fast_retransmit) |
| 598 | continue; |
| 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | /* Attempt to append this chunk to the packet. */ |
| 601 | status = sctp_packet_append_chunk(pkt, chunk); |
| 602 | |
| 603 | switch (status) { |
| 604 | case SCTP_XMIT_PMTU_FULL: |
| 605 | /* Send this packet. */ |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 606 | error = sctp_packet_transmit(pkt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | /* If we are retransmitting, we should only |
| 609 | * send a single packet. |
| 610 | */ |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 611 | if (rtx_timeout || fast_rtx) |
| 612 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 614 | /* Bundle next chunk in the next round. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | break; |
| 616 | |
| 617 | case SCTP_XMIT_RWND_FULL: |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 618 | /* Send this packet. */ |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 619 | error = sctp_packet_transmit(pkt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
| 621 | /* Stop sending DATA as there is no more room |
| 622 | * at the receiver. |
| 623 | */ |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 624 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | break; |
| 626 | |
| 627 | case SCTP_XMIT_NAGLE_DELAY: |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 628 | /* Send this packet. */ |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 629 | error = sctp_packet_transmit(pkt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | /* Stop sending DATA because of nagle delay. */ |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 632 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | break; |
| 634 | |
| 635 | default: |
| 636 | /* The append was successful, so add this chunk to |
| 637 | * the transmitted list. |
| 638 | */ |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 639 | list_del(&chunk->transmitted_list); |
| 640 | list_add_tail(&chunk->transmitted_list, |
| 641 | &transport->transmitted); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 643 | /* Mark the chunk as ineligible for fast retransmit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | * after it is retransmitted. |
| 645 | */ |
Neil Horman | c226ef9 | 2008-07-25 12:44:09 -0400 | [diff] [blame] | 646 | if (chunk->fast_retransmit == SCTP_NEED_FRTX) |
| 647 | chunk->fast_retransmit = SCTP_DONT_FRTX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 649 | /* Force start T3-rtx timer when fast retransmitting |
| 650 | * the earliest outstanding TSN |
| 651 | */ |
| 652 | if (!timer && fast_rtx && |
| 653 | ntohl(chunk->subh.data_hdr->tsn) == |
| 654 | asoc->ctsn_ack_point + 1) |
| 655 | timer = 2; |
| 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | q->empty = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 661 | /* Set the timer if there were no errors */ |
| 662 | if (!error && !timer) |
| 663 | timer = 1; |
| 664 | |
Vlad Yasevich | 8b750ce | 2008-06-04 12:39:36 -0700 | [diff] [blame] | 665 | if (done) |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | /* If we are here due to a retransmit timeout or a fast |
| 670 | * retransmit and if there are any chunks left in the retransmit |
| 671 | * queue that could not fit in the PMTU sized packet, they need |
| 672 | * to be marked as ineligible for a subsequent fast retransmit. |
| 673 | */ |
| 674 | if (rtx_timeout || fast_rtx) { |
| 675 | list_for_each_entry(chunk1, lqueue, transmitted_list) { |
Neil Horman | c226ef9 | 2008-07-25 12:44:09 -0400 | [diff] [blame] | 676 | if (chunk1->fast_retransmit == SCTP_NEED_FRTX) |
| 677 | chunk1->fast_retransmit = SCTP_DONT_FRTX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 681 | *start_timer = timer; |
| 682 | |
| 683 | /* Clear fast retransmit hint */ |
| 684 | if (fast_rtx) |
| 685 | q->fast_rtx = 0; |
| 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return error; |
| 688 | } |
| 689 | |
| 690 | /* Cork the outqueue so queued chunks are really queued. */ |
| 691 | int sctp_outq_uncork(struct sctp_outq *q) |
| 692 | { |
| 693 | int error = 0; |
Vlad Yasevich | 7d54dc6 | 2007-11-09 11:43:41 -0500 | [diff] [blame] | 694 | if (q->cork) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | q->cork = 0; |
Vlad Yasevich | 7d54dc6 | 2007-11-09 11:43:41 -0500 | [diff] [blame] | 696 | error = sctp_outq_flush(q, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | return error; |
| 698 | } |
| 699 | |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | /* |
| 702 | * Try to flush an outqueue. |
| 703 | * |
| 704 | * Description: Send everything in q which we legally can, subject to |
| 705 | * congestion limitations. |
| 706 | * * Note: This function can be called from multiple contexts so appropriate |
| 707 | * locking concerns must be made. Today we use the sock lock to protect |
| 708 | * this function. |
| 709 | */ |
Adrian Bunk | abd0b198 | 2008-07-22 14:20:45 -0700 | [diff] [blame] | 710 | static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
| 712 | struct sctp_packet *packet; |
| 713 | struct sctp_packet singleton; |
| 714 | struct sctp_association *asoc = q->asoc; |
| 715 | __u16 sport = asoc->base.bind_addr.port; |
| 716 | __u16 dport = asoc->peer.port; |
| 717 | __u32 vtag = asoc->peer.i.init_tag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | struct sctp_transport *transport = NULL; |
| 719 | struct sctp_transport *new_transport; |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 720 | struct sctp_chunk *chunk, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | sctp_xmit_t status; |
| 722 | int error = 0; |
| 723 | int start_timer = 0; |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 724 | int one_packet = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
| 726 | /* These transports have chunks to send. */ |
| 727 | struct list_head transport_list; |
| 728 | struct list_head *ltransport; |
| 729 | |
| 730 | INIT_LIST_HEAD(&transport_list); |
| 731 | packet = NULL; |
| 732 | |
| 733 | /* |
| 734 | * 6.10 Bundling |
| 735 | * ... |
| 736 | * When bundling control chunks with DATA chunks, an |
| 737 | * endpoint MUST place control chunks first in the outbound |
| 738 | * SCTP packet. The transmitter MUST transmit DATA chunks |
| 739 | * within a SCTP packet in increasing order of TSN. |
| 740 | * ... |
| 741 | */ |
| 742 | |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 743 | list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) { |
| 744 | list_del_init(&chunk->list); |
| 745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | /* Pick the right transport to use. */ |
| 747 | new_transport = chunk->transport; |
| 748 | |
| 749 | if (!new_transport) { |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 750 | /* |
| 751 | * If we have a prior transport pointer, see if |
| 752 | * the destination address of the chunk |
| 753 | * matches the destination address of the |
| 754 | * current transport. If not a match, then |
| 755 | * try to look up the transport with a given |
| 756 | * destination address. We do this because |
| 757 | * after processing ASCONFs, we may have new |
| 758 | * transports created. |
| 759 | */ |
| 760 | if (transport && |
| 761 | sctp_cmp_addr_exact(&chunk->dest, |
| 762 | &transport->ipaddr)) |
| 763 | new_transport = transport; |
| 764 | else |
| 765 | new_transport = sctp_assoc_lookup_paddr(asoc, |
| 766 | &chunk->dest); |
| 767 | |
| 768 | /* if we still don't have a new transport, then |
| 769 | * use the current active path. |
| 770 | */ |
| 771 | if (!new_transport) |
| 772 | new_transport = asoc->peer.active_path; |
Sridhar Samudrala | ad8fec1 | 2006-07-21 14:48:50 -0700 | [diff] [blame] | 773 | } else if ((new_transport->state == SCTP_INACTIVE) || |
| 774 | (new_transport->state == SCTP_UNCONFIRMED)) { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 775 | /* If the chunk is Heartbeat or Heartbeat Ack, |
| 776 | * send it to chunk->transport, even if it's |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | * inactive. |
| 778 | * |
| 779 | * 3.3.6 Heartbeat Acknowledgement: |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 780 | * ... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | * A HEARTBEAT ACK is always sent to the source IP |
| 782 | * address of the IP datagram containing the |
| 783 | * HEARTBEAT chunk to which this ack is responding. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 784 | * ... |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 785 | * |
| 786 | * ASCONF_ACKs also must be sent to the source. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | */ |
| 788 | if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT && |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 789 | chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT_ACK && |
| 790 | chunk->chunk_hdr->type != SCTP_CID_ASCONF_ACK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | new_transport = asoc->peer.active_path; |
| 792 | } |
| 793 | |
| 794 | /* Are we switching transports? |
| 795 | * Take care of transport locks. |
| 796 | */ |
| 797 | if (new_transport != transport) { |
| 798 | transport = new_transport; |
| 799 | if (list_empty(&transport->send_ready)) { |
| 800 | list_add_tail(&transport->send_ready, |
| 801 | &transport_list); |
| 802 | } |
| 803 | packet = &transport->packet; |
| 804 | sctp_packet_config(packet, vtag, |
| 805 | asoc->peer.ecn_capable); |
| 806 | } |
| 807 | |
| 808 | switch (chunk->chunk_hdr->type) { |
| 809 | /* |
| 810 | * 6.10 Bundling |
| 811 | * ... |
| 812 | * An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN |
| 813 | * COMPLETE with any other chunks. [Send them immediately.] |
| 814 | */ |
| 815 | case SCTP_CID_INIT: |
| 816 | case SCTP_CID_INIT_ACK: |
| 817 | case SCTP_CID_SHUTDOWN_COMPLETE: |
| 818 | sctp_packet_init(&singleton, transport, sport, dport); |
| 819 | sctp_packet_config(&singleton, vtag, 0); |
| 820 | sctp_packet_append_chunk(&singleton, chunk); |
| 821 | error = sctp_packet_transmit(&singleton); |
| 822 | if (error < 0) |
| 823 | return error; |
| 824 | break; |
| 825 | |
| 826 | case SCTP_CID_ABORT: |
Gui Jianfeng | f4ad85c | 2008-04-12 18:39:34 -0700 | [diff] [blame] | 827 | if (sctp_test_T_bit(chunk)) { |
| 828 | packet->vtag = asoc->c.my_vtag; |
| 829 | } |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 830 | /* The following chunks are "response" chunks, i.e. |
| 831 | * they are generated in response to something we |
| 832 | * received. If we are sending these, then we can |
| 833 | * send only 1 packet containing these chunks. |
| 834 | */ |
| 835 | case SCTP_CID_HEARTBEAT_ACK: |
| 836 | case SCTP_CID_SHUTDOWN_ACK: |
| 837 | case SCTP_CID_COOKIE_ACK: |
| 838 | case SCTP_CID_COOKIE_ECHO: |
| 839 | case SCTP_CID_ERROR: |
| 840 | case SCTP_CID_ECN_CWR: |
| 841 | case SCTP_CID_ASCONF_ACK: |
| 842 | one_packet = 1; |
| 843 | /* Fall throught */ |
| 844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | case SCTP_CID_SACK: |
| 846 | case SCTP_CID_HEARTBEAT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | case SCTP_CID_SHUTDOWN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | case SCTP_CID_ECN_ECNE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | case SCTP_CID_ASCONF: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | case SCTP_CID_FWD_TSN: |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 851 | status = sctp_packet_transmit_chunk(packet, chunk, |
| 852 | one_packet); |
| 853 | if (status != SCTP_XMIT_OK) { |
| 854 | /* put the chunk back */ |
| 855 | list_add(&chunk->list, &q->control_chunk_list); |
| 856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | break; |
| 858 | |
| 859 | default: |
| 860 | /* We built a chunk with an illegal type! */ |
| 861 | BUG(); |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 862 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | /* Is it OK to send data chunks? */ |
| 866 | switch (asoc->state) { |
| 867 | case SCTP_STATE_COOKIE_ECHOED: |
| 868 | /* Only allow bundling when this packet has a COOKIE-ECHO |
| 869 | * chunk. |
| 870 | */ |
| 871 | if (!packet || !packet->has_cookie_echo) |
| 872 | break; |
| 873 | |
| 874 | /* fallthru */ |
| 875 | case SCTP_STATE_ESTABLISHED: |
| 876 | case SCTP_STATE_SHUTDOWN_PENDING: |
| 877 | case SCTP_STATE_SHUTDOWN_RECEIVED: |
| 878 | /* |
| 879 | * RFC 2960 6.1 Transmission of DATA Chunks |
| 880 | * |
| 881 | * C) When the time comes for the sender to transmit, |
| 882 | * before sending new DATA chunks, the sender MUST |
| 883 | * first transmit any outstanding DATA chunks which |
| 884 | * are marked for retransmission (limited by the |
| 885 | * current cwnd). |
| 886 | */ |
| 887 | if (!list_empty(&q->retransmit)) { |
| 888 | if (transport == asoc->peer.retran_path) |
| 889 | goto retran; |
| 890 | |
| 891 | /* Switch transports & prepare the packet. */ |
| 892 | |
| 893 | transport = asoc->peer.retran_path; |
| 894 | |
| 895 | if (list_empty(&transport->send_ready)) { |
| 896 | list_add_tail(&transport->send_ready, |
| 897 | &transport_list); |
| 898 | } |
| 899 | |
| 900 | packet = &transport->packet; |
| 901 | sctp_packet_config(packet, vtag, |
| 902 | asoc->peer.ecn_capable); |
| 903 | retran: |
| 904 | error = sctp_outq_flush_rtx(q, packet, |
| 905 | rtx_timeout, &start_timer); |
| 906 | |
| 907 | if (start_timer) |
Vlad Yasevich | 62aeaff | 2008-06-04 12:39:11 -0700 | [diff] [blame] | 908 | sctp_transport_reset_timers(transport, |
| 909 | start_timer-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
| 911 | /* This can happen on COOKIE-ECHO resend. Only |
| 912 | * one chunk can get bundled with a COOKIE-ECHO. |
| 913 | */ |
| 914 | if (packet->has_cookie_echo) |
| 915 | goto sctp_flush_out; |
| 916 | |
| 917 | /* Don't send new data if there is still data |
| 918 | * waiting to retransmit. |
| 919 | */ |
| 920 | if (!list_empty(&q->retransmit)) |
| 921 | goto sctp_flush_out; |
| 922 | } |
| 923 | |
Vlad Yasevich | 46d5a80 | 2009-11-23 15:54:00 -0500 | [diff] [blame] | 924 | /* Apply Max.Burst limitation to the current transport in |
| 925 | * case it will be used for new data. We are going to |
| 926 | * rest it before we return, but we want to apply the limit |
| 927 | * to the currently queued data. |
| 928 | */ |
| 929 | if (transport) |
| 930 | sctp_transport_burst_limited(transport); |
| 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | /* Finally, transmit new packets. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | while ((chunk = sctp_outq_dequeue_data(q)) != NULL) { |
| 934 | /* RFC 2960 6.5 Every DATA chunk MUST carry a valid |
| 935 | * stream identifier. |
| 936 | */ |
| 937 | if (chunk->sinfo.sinfo_stream >= |
| 938 | asoc->c.sinit_num_ostreams) { |
| 939 | |
| 940 | /* Mark as failed send. */ |
| 941 | sctp_chunk_fail(chunk, SCTP_ERROR_INV_STRM); |
| 942 | sctp_chunk_free(chunk); |
| 943 | continue; |
| 944 | } |
| 945 | |
| 946 | /* Has this chunk expired? */ |
| 947 | if (sctp_chunk_abandoned(chunk)) { |
| 948 | sctp_chunk_fail(chunk, 0); |
| 949 | sctp_chunk_free(chunk); |
| 950 | continue; |
| 951 | } |
| 952 | |
| 953 | /* If there is a specified transport, use it. |
| 954 | * Otherwise, we want to use the active path. |
| 955 | */ |
| 956 | new_transport = chunk->transport; |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 957 | if (!new_transport || |
Sridhar Samudrala | ad8fec1 | 2006-07-21 14:48:50 -0700 | [diff] [blame] | 958 | ((new_transport->state == SCTP_INACTIVE) || |
| 959 | (new_transport->state == SCTP_UNCONFIRMED))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | new_transport = asoc->peer.active_path; |
| 961 | |
| 962 | /* Change packets if necessary. */ |
| 963 | if (new_transport != transport) { |
| 964 | transport = new_transport; |
| 965 | |
| 966 | /* Schedule to have this transport's |
| 967 | * packet flushed. |
| 968 | */ |
| 969 | if (list_empty(&transport->send_ready)) { |
| 970 | list_add_tail(&transport->send_ready, |
| 971 | &transport_list); |
| 972 | } |
| 973 | |
| 974 | packet = &transport->packet; |
| 975 | sctp_packet_config(packet, vtag, |
| 976 | asoc->peer.ecn_capable); |
Vlad Yasevich | 46d5a80 | 2009-11-23 15:54:00 -0500 | [diff] [blame] | 977 | /* We've switched transports, so apply the |
| 978 | * Burst limit to the new transport. |
| 979 | */ |
| 980 | sctp_transport_burst_limited(transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | SCTP_DEBUG_PRINTK("sctp_outq_flush(%p, %p[%s]), ", |
| 984 | q, chunk, |
| 985 | chunk && chunk->chunk_hdr ? |
| 986 | sctp_cname(SCTP_ST_CHUNK( |
| 987 | chunk->chunk_hdr->type)) |
| 988 | : "Illegal Chunk"); |
| 989 | |
| 990 | SCTP_DEBUG_PRINTK("TX TSN 0x%x skb->head " |
| 991 | "%p skb->users %d.\n", |
| 992 | ntohl(chunk->subh.data_hdr->tsn), |
| 993 | chunk->skb ?chunk->skb->head : NULL, |
| 994 | chunk->skb ? |
| 995 | atomic_read(&chunk->skb->users) : -1); |
| 996 | |
| 997 | /* Add the chunk to the packet. */ |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 998 | status = sctp_packet_transmit_chunk(packet, chunk, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | |
| 1000 | switch (status) { |
| 1001 | case SCTP_XMIT_PMTU_FULL: |
| 1002 | case SCTP_XMIT_RWND_FULL: |
| 1003 | case SCTP_XMIT_NAGLE_DELAY: |
| 1004 | /* We could not append this chunk, so put |
| 1005 | * the chunk back on the output queue. |
| 1006 | */ |
| 1007 | SCTP_DEBUG_PRINTK("sctp_outq_flush: could " |
| 1008 | "not transmit TSN: 0x%x, status: %d\n", |
| 1009 | ntohl(chunk->subh.data_hdr->tsn), |
| 1010 | status); |
| 1011 | sctp_outq_head_data(q, chunk); |
| 1012 | goto sctp_flush_out; |
| 1013 | break; |
| 1014 | |
| 1015 | case SCTP_XMIT_OK: |
Wei Yongjun | b93d647 | 2009-11-23 15:53:56 -0500 | [diff] [blame] | 1016 | /* The sender is in the SHUTDOWN-PENDING state, |
| 1017 | * The sender MAY set the I-bit in the DATA |
| 1018 | * chunk header. |
| 1019 | */ |
| 1020 | if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING) |
| 1021 | chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM; |
| 1022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | break; |
| 1024 | |
| 1025 | default: |
| 1026 | BUG(); |
| 1027 | } |
| 1028 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1029 | /* BUG: We assume that the sctp_packet_transmit() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | * call below will succeed all the time and add the |
| 1031 | * chunk to the transmitted list and restart the |
| 1032 | * timers. |
| 1033 | * It is possible that the call can fail under OOM |
| 1034 | * conditions. |
| 1035 | * |
| 1036 | * Is this really a problem? Won't this behave |
| 1037 | * like a lost TSN? |
| 1038 | */ |
| 1039 | list_add_tail(&chunk->transmitted_list, |
| 1040 | &transport->transmitted); |
| 1041 | |
Vlad Yasevich | 6574df9 | 2009-01-22 14:52:43 -0800 | [diff] [blame] | 1042 | sctp_transport_reset_timers(transport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
| 1044 | q->empty = 0; |
| 1045 | |
| 1046 | /* Only let one DATA chunk get bundled with a |
| 1047 | * COOKIE-ECHO chunk. |
| 1048 | */ |
| 1049 | if (packet->has_cookie_echo) |
| 1050 | goto sctp_flush_out; |
| 1051 | } |
| 1052 | break; |
| 1053 | |
| 1054 | default: |
| 1055 | /* Do nothing. */ |
| 1056 | break; |
| 1057 | } |
| 1058 | |
| 1059 | sctp_flush_out: |
| 1060 | |
| 1061 | /* Before returning, examine all the transports touched in |
| 1062 | * this call. Right now, we bluntly force clear all the |
| 1063 | * transports. Things might change after we implement Nagle. |
| 1064 | * But such an examination is still required. |
| 1065 | * |
| 1066 | * --xguo |
| 1067 | */ |
| 1068 | while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL ) { |
| 1069 | struct sctp_transport *t = list_entry(ltransport, |
| 1070 | struct sctp_transport, |
| 1071 | send_ready); |
| 1072 | packet = &t->packet; |
| 1073 | if (!sctp_packet_empty(packet)) |
| 1074 | error = sctp_packet_transmit(packet); |
Vlad Yasevich | 46d5a80 | 2009-11-23 15:54:00 -0500 | [diff] [blame] | 1075 | |
| 1076 | /* Clear the burst limited state, if any */ |
| 1077 | sctp_transport_burst_reset(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | return error; |
| 1081 | } |
| 1082 | |
| 1083 | /* Update unack_data based on the incoming SACK chunk */ |
| 1084 | static void sctp_sack_update_unack_data(struct sctp_association *assoc, |
| 1085 | struct sctp_sackhdr *sack) |
| 1086 | { |
| 1087 | sctp_sack_variable_t *frags; |
| 1088 | __u16 unack_data; |
| 1089 | int i; |
| 1090 | |
| 1091 | unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1; |
| 1092 | |
| 1093 | frags = sack->variable; |
| 1094 | for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) { |
| 1095 | unack_data -= ((ntohs(frags[i].gab.end) - |
| 1096 | ntohs(frags[i].gab.start) + 1)); |
| 1097 | } |
| 1098 | |
| 1099 | assoc->unack_data = unack_data; |
| 1100 | } |
| 1101 | |
| 1102 | /* Return the highest new tsn that is acknowledged by the given SACK chunk. */ |
| 1103 | static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack, |
| 1104 | struct sctp_association *asoc) |
| 1105 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | struct sctp_transport *transport; |
| 1107 | struct sctp_chunk *chunk; |
| 1108 | __u32 highest_new_tsn, tsn; |
| 1109 | struct list_head *transport_list = &asoc->peer.transport_addr_list; |
| 1110 | |
| 1111 | highest_new_tsn = ntohl(sack->cum_tsn_ack); |
| 1112 | |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 1113 | list_for_each_entry(transport, transport_list, transports) { |
| 1114 | list_for_each_entry(chunk, &transport->transmitted, |
| 1115 | transmitted_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | tsn = ntohl(chunk->subh.data_hdr->tsn); |
| 1117 | |
| 1118 | if (!chunk->tsn_gap_acked && |
| 1119 | TSN_lt(highest_new_tsn, tsn) && |
| 1120 | sctp_acked(sack, tsn)) |
| 1121 | highest_new_tsn = tsn; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | return highest_new_tsn; |
| 1126 | } |
| 1127 | |
| 1128 | /* This is where we REALLY process a SACK. |
| 1129 | * |
| 1130 | * Process the SACK against the outqueue. Mostly, this just frees |
| 1131 | * things off the transmitted queue. |
| 1132 | */ |
| 1133 | int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack) |
| 1134 | { |
| 1135 | struct sctp_association *asoc = q->asoc; |
| 1136 | struct sctp_transport *transport; |
| 1137 | struct sctp_chunk *tchunk = NULL; |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 1138 | struct list_head *lchunk, *transport_list, *temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | sctp_sack_variable_t *frags = sack->variable; |
| 1140 | __u32 sack_ctsn, ctsn, tsn; |
| 1141 | __u32 highest_tsn, highest_new_tsn; |
| 1142 | __u32 sack_a_rwnd; |
| 1143 | unsigned outstanding; |
| 1144 | struct sctp_transport *primary = asoc->peer.primary_path; |
| 1145 | int count_of_newacks = 0; |
Vlad Yasevich | 2cd9b82 | 2008-06-19 17:59:13 -0400 | [diff] [blame] | 1146 | int gap_ack_blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | |
| 1148 | /* Grab the association's destination address list. */ |
| 1149 | transport_list = &asoc->peer.transport_addr_list; |
| 1150 | |
| 1151 | sack_ctsn = ntohl(sack->cum_tsn_ack); |
Vlad Yasevich | 2cd9b82 | 2008-06-19 17:59:13 -0400 | [diff] [blame] | 1152 | gap_ack_blocks = ntohs(sack->num_gap_ack_blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | /* |
| 1154 | * SFR-CACC algorithm: |
| 1155 | * On receipt of a SACK the sender SHOULD execute the |
| 1156 | * following statements. |
| 1157 | * |
| 1158 | * 1) If the cumulative ack in the SACK passes next tsn_at_change |
| 1159 | * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be |
| 1160 | * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for |
| 1161 | * all destinations. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE |
| 1163 | * is set the receiver of the SACK MUST take the following actions: |
| 1164 | * |
| 1165 | * A) Initialize the cacc_saw_newack to 0 for all destination |
| 1166 | * addresses. |
Vlad Yasevich | ab5216a | 2008-06-19 18:17:24 -0400 | [diff] [blame] | 1167 | * |
| 1168 | * Only bother if changeover_active is set. Otherwise, this is |
| 1169 | * totally suboptimal to do on every SACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | */ |
Vlad Yasevich | ab5216a | 2008-06-19 18:17:24 -0400 | [diff] [blame] | 1171 | if (primary->cacc.changeover_active) { |
| 1172 | u8 clear_cycling = 0; |
| 1173 | |
| 1174 | if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) { |
| 1175 | primary->cacc.changeover_active = 0; |
| 1176 | clear_cycling = 1; |
| 1177 | } |
| 1178 | |
| 1179 | if (clear_cycling || gap_ack_blocks) { |
| 1180 | list_for_each_entry(transport, transport_list, |
| 1181 | transports) { |
| 1182 | if (clear_cycling) |
| 1183 | transport->cacc.cycling_changeover = 0; |
| 1184 | if (gap_ack_blocks) |
| 1185 | transport->cacc.cacc_saw_newack = 0; |
| 1186 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | /* Get the highest TSN in the sack. */ |
| 1191 | highest_tsn = sack_ctsn; |
Vlad Yasevich | 2cd9b82 | 2008-06-19 17:59:13 -0400 | [diff] [blame] | 1192 | if (gap_ack_blocks) |
| 1193 | highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
| 1195 | if (TSN_lt(asoc->highest_sacked, highest_tsn)) { |
| 1196 | highest_new_tsn = highest_tsn; |
| 1197 | asoc->highest_sacked = highest_tsn; |
| 1198 | } else { |
| 1199 | highest_new_tsn = sctp_highest_new_tsn(sack, asoc); |
| 1200 | } |
| 1201 | |
Vlad Yasevich | 2cd9b82 | 2008-06-19 17:59:13 -0400 | [diff] [blame] | 1202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | /* Run through the retransmit queue. Credit bytes received |
| 1204 | * and free those chunks that we can. |
| 1205 | */ |
| 1206 | sctp_check_transmitted(q, &q->retransmit, NULL, sack, highest_new_tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | |
| 1208 | /* Run through the transmitted queue. |
| 1209 | * Credit bytes received and free those chunks which we can. |
| 1210 | * |
| 1211 | * This is a MASSIVE candidate for optimization. |
| 1212 | */ |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 1213 | list_for_each_entry(transport, transport_list, transports) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | sctp_check_transmitted(q, &transport->transmitted, |
| 1215 | transport, sack, highest_new_tsn); |
| 1216 | /* |
| 1217 | * SFR-CACC algorithm: |
| 1218 | * C) Let count_of_newacks be the number of |
| 1219 | * destinations for which cacc_saw_newack is set. |
| 1220 | */ |
| 1221 | if (transport->cacc.cacc_saw_newack) |
| 1222 | count_of_newacks ++; |
| 1223 | } |
| 1224 | |
Vlad Yasevich | 2cd9b82 | 2008-06-19 17:59:13 -0400 | [diff] [blame] | 1225 | if (gap_ack_blocks) { |
Vlad Yasevich | 2cd9b82 | 2008-06-19 17:59:13 -0400 | [diff] [blame] | 1226 | list_for_each_entry(transport, transport_list, transports) |
| 1227 | sctp_mark_missing(q, &transport->transmitted, transport, |
| 1228 | highest_new_tsn, count_of_newacks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | /* Move the Cumulative TSN Ack Point if appropriate. */ |
| 1232 | if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn)) |
| 1233 | asoc->ctsn_ack_point = sack_ctsn; |
| 1234 | |
| 1235 | /* Update unack_data field in the assoc. */ |
| 1236 | sctp_sack_update_unack_data(asoc, sack); |
| 1237 | |
| 1238 | ctsn = asoc->ctsn_ack_point; |
| 1239 | |
| 1240 | /* Throw away stuff rotting on the sack queue. */ |
| 1241 | list_for_each_safe(lchunk, temp, &q->sacked) { |
| 1242 | tchunk = list_entry(lchunk, struct sctp_chunk, |
| 1243 | transmitted_list); |
| 1244 | tsn = ntohl(tchunk->subh.data_hdr->tsn); |
Vlad Yasevich | 5f9646c | 2008-02-05 14:23:44 -0500 | [diff] [blame] | 1245 | if (TSN_lte(tsn, ctsn)) { |
| 1246 | list_del_init(&tchunk->transmitted_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | sctp_chunk_free(tchunk); |
Vlad Yasevich | 5f9646c | 2008-02-05 14:23:44 -0500 | [diff] [blame] | 1248 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | /* ii) Set rwnd equal to the newly received a_rwnd minus the |
| 1252 | * number of bytes still outstanding after processing the |
| 1253 | * Cumulative TSN Ack and the Gap Ack Blocks. |
| 1254 | */ |
| 1255 | |
| 1256 | sack_a_rwnd = ntohl(sack->a_rwnd); |
| 1257 | outstanding = q->outstanding_bytes; |
| 1258 | |
| 1259 | if (outstanding < sack_a_rwnd) |
| 1260 | sack_a_rwnd -= outstanding; |
| 1261 | else |
| 1262 | sack_a_rwnd = 0; |
| 1263 | |
| 1264 | asoc->peer.rwnd = sack_a_rwnd; |
| 1265 | |
| 1266 | sctp_generate_fwdtsn(q, sack_ctsn); |
| 1267 | |
| 1268 | SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1269 | __func__, sack_ctsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association, " |
| 1271 | "%p is 0x%x. Adv peer ack point: 0x%x\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1272 | __func__, asoc, ctsn, asoc->adv_peer_ack_point); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | |
| 1274 | /* See if all chunks are acked. |
| 1275 | * Make sure the empty queue handler will get run later. |
| 1276 | */ |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 1277 | q->empty = (list_empty(&q->out_chunk_list) && |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 1278 | list_empty(&q->retransmit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | if (!q->empty) |
| 1280 | goto finish; |
| 1281 | |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 1282 | list_for_each_entry(transport, transport_list, transports) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | q->empty = q->empty && list_empty(&transport->transmitted); |
| 1284 | if (!q->empty) |
| 1285 | goto finish; |
| 1286 | } |
| 1287 | |
| 1288 | SCTP_DEBUG_PRINTK("sack queue is empty.\n"); |
| 1289 | finish: |
| 1290 | return q->empty; |
| 1291 | } |
| 1292 | |
| 1293 | /* Is the outqueue empty? */ |
| 1294 | int sctp_outq_is_empty(const struct sctp_outq *q) |
| 1295 | { |
| 1296 | return q->empty; |
| 1297 | } |
| 1298 | |
| 1299 | /******************************************************************** |
| 1300 | * 2nd Level Abstractions |
| 1301 | ********************************************************************/ |
| 1302 | |
| 1303 | /* Go through a transport's transmitted list or the association's retransmit |
| 1304 | * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked. |
| 1305 | * The retransmit list will not have an associated transport. |
| 1306 | * |
| 1307 | * I added coherent debug information output. --xguo |
| 1308 | * |
| 1309 | * Instead of printing 'sacked' or 'kept' for each TSN on the |
| 1310 | * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5. |
| 1311 | * KEPT TSN6-TSN7, etc. |
| 1312 | */ |
| 1313 | static void sctp_check_transmitted(struct sctp_outq *q, |
| 1314 | struct list_head *transmitted_queue, |
| 1315 | struct sctp_transport *transport, |
| 1316 | struct sctp_sackhdr *sack, |
| 1317 | __u32 highest_new_tsn_in_sack) |
| 1318 | { |
| 1319 | struct list_head *lchunk; |
| 1320 | struct sctp_chunk *tchunk; |
| 1321 | struct list_head tlist; |
| 1322 | __u32 tsn; |
| 1323 | __u32 sack_ctsn; |
| 1324 | __u32 rtt; |
| 1325 | __u8 restart_timer = 0; |
| 1326 | int bytes_acked = 0; |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 1327 | int migrate_bytes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | |
| 1329 | /* These state variables are for coherent debug output. --xguo */ |
| 1330 | |
| 1331 | #if SCTP_DEBUG |
| 1332 | __u32 dbg_ack_tsn = 0; /* An ACKed TSN range starts here... */ |
| 1333 | __u32 dbg_last_ack_tsn = 0; /* ...and finishes here. */ |
| 1334 | __u32 dbg_kept_tsn = 0; /* An un-ACKed range starts here... */ |
| 1335 | __u32 dbg_last_kept_tsn = 0; /* ...and finishes here. */ |
| 1336 | |
| 1337 | /* 0 : The last TSN was ACKed. |
| 1338 | * 1 : The last TSN was NOT ACKed (i.e. KEPT). |
| 1339 | * -1: We need to initialize. |
| 1340 | */ |
| 1341 | int dbg_prt_state = -1; |
| 1342 | #endif /* SCTP_DEBUG */ |
| 1343 | |
| 1344 | sack_ctsn = ntohl(sack->cum_tsn_ack); |
| 1345 | |
| 1346 | INIT_LIST_HEAD(&tlist); |
| 1347 | |
| 1348 | /* The while loop will skip empty transmitted queues. */ |
| 1349 | while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) { |
| 1350 | tchunk = list_entry(lchunk, struct sctp_chunk, |
| 1351 | transmitted_list); |
| 1352 | |
| 1353 | if (sctp_chunk_abandoned(tchunk)) { |
| 1354 | /* Move the chunk to abandoned list. */ |
| 1355 | sctp_insert_list(&q->abandoned, lchunk); |
Vlad Yasevich | 8c4a2d4 | 2007-02-21 02:06:04 -0800 | [diff] [blame] | 1356 | |
| 1357 | /* If this chunk has not been acked, stop |
| 1358 | * considering it as 'outstanding'. |
| 1359 | */ |
| 1360 | if (!tchunk->tsn_gap_acked) { |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 1361 | if (tchunk->transport) |
| 1362 | tchunk->transport->flight_size -= |
| 1363 | sctp_data_size(tchunk); |
Vlad Yasevich | 8c4a2d4 | 2007-02-21 02:06:04 -0800 | [diff] [blame] | 1364 | q->outstanding_bytes -= sctp_data_size(tchunk); |
| 1365 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | continue; |
| 1367 | } |
| 1368 | |
| 1369 | tsn = ntohl(tchunk->subh.data_hdr->tsn); |
| 1370 | if (sctp_acked(sack, tsn)) { |
| 1371 | /* If this queue is the retransmit queue, the |
| 1372 | * retransmit timer has already reclaimed |
| 1373 | * the outstanding bytes for this chunk, so only |
| 1374 | * count bytes associated with a transport. |
| 1375 | */ |
| 1376 | if (transport) { |
| 1377 | /* If this chunk is being used for RTT |
| 1378 | * measurement, calculate the RTT and update |
| 1379 | * the RTO using this value. |
| 1380 | * |
| 1381 | * 6.3.1 C5) Karn's algorithm: RTT measurements |
| 1382 | * MUST NOT be made using packets that were |
| 1383 | * retransmitted (and thus for which it is |
| 1384 | * ambiguous whether the reply was for the |
| 1385 | * first instance of the packet or a later |
| 1386 | * instance). |
| 1387 | */ |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1388 | if (!tchunk->tsn_gap_acked && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | !tchunk->resent && |
| 1390 | tchunk->rtt_in_progress) { |
Vlad Yasevich | 4c9f5d5 | 2006-06-17 22:56:08 -0700 | [diff] [blame] | 1391 | tchunk->rtt_in_progress = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | rtt = jiffies - tchunk->sent_at; |
| 1393 | sctp_transport_update_rto(transport, |
| 1394 | rtt); |
| 1395 | } |
| 1396 | } |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 1397 | |
| 1398 | /* If the chunk hasn't been marked as ACKED, |
| 1399 | * mark it and account bytes_acked if the |
| 1400 | * chunk had a valid transport (it will not |
| 1401 | * have a transport if ASCONF had deleted it |
| 1402 | * while DATA was outstanding). |
| 1403 | */ |
| 1404 | if (!tchunk->tsn_gap_acked) { |
| 1405 | tchunk->tsn_gap_acked = 1; |
| 1406 | bytes_acked += sctp_data_size(tchunk); |
| 1407 | if (!tchunk->transport) |
| 1408 | migrate_bytes += sctp_data_size(tchunk); |
| 1409 | } |
| 1410 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1411 | if (TSN_lte(tsn, sack_ctsn)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | /* RFC 2960 6.3.2 Retransmission Timer Rules |
| 1413 | * |
| 1414 | * R3) Whenever a SACK is received |
| 1415 | * that acknowledges the DATA chunk |
| 1416 | * with the earliest outstanding TSN |
| 1417 | * for that address, restart T3-rtx |
| 1418 | * timer for that address with its |
| 1419 | * current RTO. |
| 1420 | */ |
| 1421 | restart_timer = 1; |
| 1422 | |
| 1423 | if (!tchunk->tsn_gap_acked) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | /* |
| 1425 | * SFR-CACC algorithm: |
| 1426 | * 2) If the SACK contains gap acks |
| 1427 | * and the flag CHANGEOVER_ACTIVE is |
| 1428 | * set the receiver of the SACK MUST |
| 1429 | * take the following action: |
| 1430 | * |
| 1431 | * B) For each TSN t being acked that |
| 1432 | * has not been acked in any SACK so |
| 1433 | * far, set cacc_saw_newack to 1 for |
| 1434 | * the destination that the TSN was |
| 1435 | * sent to. |
| 1436 | */ |
| 1437 | if (transport && |
| 1438 | sack->num_gap_ack_blocks && |
| 1439 | q->asoc->peer.primary_path->cacc. |
| 1440 | changeover_active) |
| 1441 | transport->cacc.cacc_saw_newack |
| 1442 | = 1; |
| 1443 | } |
| 1444 | |
| 1445 | list_add_tail(&tchunk->transmitted_list, |
| 1446 | &q->sacked); |
| 1447 | } else { |
| 1448 | /* RFC2960 7.2.4, sctpimpguide-05 2.8.2 |
| 1449 | * M2) Each time a SACK arrives reporting |
| 1450 | * 'Stray DATA chunk(s)' record the highest TSN |
| 1451 | * reported as newly acknowledged, call this |
| 1452 | * value 'HighestTSNinSack'. A newly |
| 1453 | * acknowledged DATA chunk is one not |
| 1454 | * previously acknowledged in a SACK. |
| 1455 | * |
| 1456 | * When the SCTP sender of data receives a SACK |
| 1457 | * chunk that acknowledges, for the first time, |
| 1458 | * the receipt of a DATA chunk, all the still |
| 1459 | * unacknowledged DATA chunks whose TSN is |
| 1460 | * older than that newly acknowledged DATA |
| 1461 | * chunk, are qualified as 'Stray DATA chunks'. |
| 1462 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | list_add_tail(lchunk, &tlist); |
| 1464 | } |
| 1465 | |
| 1466 | #if SCTP_DEBUG |
| 1467 | switch (dbg_prt_state) { |
| 1468 | case 0: /* last TSN was ACKed */ |
| 1469 | if (dbg_last_ack_tsn + 1 == tsn) { |
| 1470 | /* This TSN belongs to the |
| 1471 | * current ACK range. |
| 1472 | */ |
| 1473 | break; |
| 1474 | } |
| 1475 | |
| 1476 | if (dbg_last_ack_tsn != dbg_ack_tsn) { |
| 1477 | /* Display the end of the |
| 1478 | * current range. |
| 1479 | */ |
| 1480 | SCTP_DEBUG_PRINTK("-%08x", |
| 1481 | dbg_last_ack_tsn); |
| 1482 | } |
| 1483 | |
| 1484 | /* Start a new range. */ |
| 1485 | SCTP_DEBUG_PRINTK(",%08x", tsn); |
| 1486 | dbg_ack_tsn = tsn; |
| 1487 | break; |
| 1488 | |
| 1489 | case 1: /* The last TSN was NOT ACKed. */ |
| 1490 | if (dbg_last_kept_tsn != dbg_kept_tsn) { |
| 1491 | /* Display the end of current range. */ |
| 1492 | SCTP_DEBUG_PRINTK("-%08x", |
| 1493 | dbg_last_kept_tsn); |
| 1494 | } |
| 1495 | |
| 1496 | SCTP_DEBUG_PRINTK("\n"); |
| 1497 | |
| 1498 | /* FALL THROUGH... */ |
| 1499 | default: |
| 1500 | /* This is the first-ever TSN we examined. */ |
| 1501 | /* Start a new range of ACK-ed TSNs. */ |
| 1502 | SCTP_DEBUG_PRINTK("ACKed: %08x", tsn); |
| 1503 | dbg_prt_state = 0; |
| 1504 | dbg_ack_tsn = tsn; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 1505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | |
| 1507 | dbg_last_ack_tsn = tsn; |
| 1508 | #endif /* SCTP_DEBUG */ |
| 1509 | |
| 1510 | } else { |
| 1511 | if (tchunk->tsn_gap_acked) { |
| 1512 | SCTP_DEBUG_PRINTK("%s: Receiver reneged on " |
| 1513 | "data TSN: 0x%x\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1514 | __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | tsn); |
| 1516 | tchunk->tsn_gap_acked = 0; |
| 1517 | |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 1518 | if (tchunk->transport) |
| 1519 | bytes_acked -= sctp_data_size(tchunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | |
| 1521 | /* RFC 2960 6.3.2 Retransmission Timer Rules |
| 1522 | * |
| 1523 | * R4) Whenever a SACK is received missing a |
| 1524 | * TSN that was previously acknowledged via a |
| 1525 | * Gap Ack Block, start T3-rtx for the |
| 1526 | * destination address to which the DATA |
| 1527 | * chunk was originally |
| 1528 | * transmitted if it is not already running. |
| 1529 | */ |
| 1530 | restart_timer = 1; |
| 1531 | } |
| 1532 | |
| 1533 | list_add_tail(lchunk, &tlist); |
| 1534 | |
| 1535 | #if SCTP_DEBUG |
| 1536 | /* See the above comments on ACK-ed TSNs. */ |
| 1537 | switch (dbg_prt_state) { |
| 1538 | case 1: |
| 1539 | if (dbg_last_kept_tsn + 1 == tsn) |
| 1540 | break; |
| 1541 | |
| 1542 | if (dbg_last_kept_tsn != dbg_kept_tsn) |
| 1543 | SCTP_DEBUG_PRINTK("-%08x", |
| 1544 | dbg_last_kept_tsn); |
| 1545 | |
| 1546 | SCTP_DEBUG_PRINTK(",%08x", tsn); |
| 1547 | dbg_kept_tsn = tsn; |
| 1548 | break; |
| 1549 | |
| 1550 | case 0: |
| 1551 | if (dbg_last_ack_tsn != dbg_ack_tsn) |
| 1552 | SCTP_DEBUG_PRINTK("-%08x", |
| 1553 | dbg_last_ack_tsn); |
| 1554 | SCTP_DEBUG_PRINTK("\n"); |
| 1555 | |
| 1556 | /* FALL THROUGH... */ |
| 1557 | default: |
| 1558 | SCTP_DEBUG_PRINTK("KEPT: %08x",tsn); |
| 1559 | dbg_prt_state = 1; |
| 1560 | dbg_kept_tsn = tsn; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 1561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | |
| 1563 | dbg_last_kept_tsn = tsn; |
| 1564 | #endif /* SCTP_DEBUG */ |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | #if SCTP_DEBUG |
| 1569 | /* Finish off the last range, displaying its ending TSN. */ |
| 1570 | switch (dbg_prt_state) { |
| 1571 | case 0: |
| 1572 | if (dbg_last_ack_tsn != dbg_ack_tsn) { |
| 1573 | SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_ack_tsn); |
| 1574 | } else { |
| 1575 | SCTP_DEBUG_PRINTK("\n"); |
| 1576 | } |
| 1577 | break; |
| 1578 | |
| 1579 | case 1: |
| 1580 | if (dbg_last_kept_tsn != dbg_kept_tsn) { |
| 1581 | SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_kept_tsn); |
| 1582 | } else { |
| 1583 | SCTP_DEBUG_PRINTK("\n"); |
| 1584 | } |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 1585 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | #endif /* SCTP_DEBUG */ |
| 1587 | if (transport) { |
| 1588 | if (bytes_acked) { |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 1589 | /* We may have counted DATA that was migrated |
| 1590 | * to this transport due to DEL-IP operation. |
| 1591 | * Subtract those bytes, since the were never |
| 1592 | * send on this transport and shouldn't be |
| 1593 | * credited to this transport. |
| 1594 | */ |
| 1595 | bytes_acked -= migrate_bytes; |
| 1596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | /* 8.2. When an outstanding TSN is acknowledged, |
| 1598 | * the endpoint shall clear the error counter of |
| 1599 | * the destination transport address to which the |
| 1600 | * DATA chunk was last sent. |
| 1601 | * The association's overall error counter is |
| 1602 | * also cleared. |
| 1603 | */ |
| 1604 | transport->error_count = 0; |
| 1605 | transport->asoc->overall_error_count = 0; |
| 1606 | |
| 1607 | /* Mark the destination transport address as |
| 1608 | * active if it is not so marked. |
| 1609 | */ |
Sridhar Samudrala | ad8fec1 | 2006-07-21 14:48:50 -0700 | [diff] [blame] | 1610 | if ((transport->state == SCTP_INACTIVE) || |
| 1611 | (transport->state == SCTP_UNCONFIRMED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | sctp_assoc_control_transport( |
| 1613 | transport->asoc, |
| 1614 | transport, |
| 1615 | SCTP_TRANSPORT_UP, |
| 1616 | SCTP_RECEIVED_SACK); |
| 1617 | } |
| 1618 | |
| 1619 | sctp_transport_raise_cwnd(transport, sack_ctsn, |
| 1620 | bytes_acked); |
| 1621 | |
| 1622 | transport->flight_size -= bytes_acked; |
Gui Jianfeng | 8b73a07 | 2008-04-17 14:22:18 -0700 | [diff] [blame] | 1623 | if (transport->flight_size == 0) |
| 1624 | transport->partial_bytes_acked = 0; |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 1625 | q->outstanding_bytes -= bytes_acked + migrate_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | } else { |
| 1627 | /* RFC 2960 6.1, sctpimpguide-06 2.15.2 |
| 1628 | * When a sender is doing zero window probing, it |
| 1629 | * should not timeout the association if it continues |
| 1630 | * to receive new packets from the receiver. The |
| 1631 | * reason is that the receiver MAY keep its window |
| 1632 | * closed for an indefinite time. |
| 1633 | * A sender is doing zero window probing when the |
| 1634 | * receiver's advertised window is zero, and there is |
| 1635 | * only one data chunk in flight to the receiver. |
| 1636 | */ |
| 1637 | if (!q->asoc->peer.rwnd && |
| 1638 | !list_empty(&tlist) && |
| 1639 | (sack_ctsn+2 == q->asoc->next_tsn)) { |
| 1640 | SCTP_DEBUG_PRINTK("%s: SACK received for zero " |
| 1641 | "window probe: %u\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1642 | __func__, sack_ctsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | q->asoc->overall_error_count = 0; |
| 1644 | transport->error_count = 0; |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | /* RFC 2960 6.3.2 Retransmission Timer Rules |
| 1649 | * |
| 1650 | * R2) Whenever all outstanding data sent to an address have |
| 1651 | * been acknowledged, turn off the T3-rtx timer of that |
| 1652 | * address. |
| 1653 | */ |
| 1654 | if (!transport->flight_size) { |
| 1655 | if (timer_pending(&transport->T3_rtx_timer) && |
| 1656 | del_timer(&transport->T3_rtx_timer)) { |
| 1657 | sctp_transport_put(transport); |
| 1658 | } |
| 1659 | } else if (restart_timer) { |
| 1660 | if (!mod_timer(&transport->T3_rtx_timer, |
| 1661 | jiffies + transport->rto)) |
| 1662 | sctp_transport_hold(transport); |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | list_splice(&tlist, transmitted_queue); |
| 1667 | } |
| 1668 | |
| 1669 | /* Mark chunks as missing and consequently may get retransmitted. */ |
| 1670 | static void sctp_mark_missing(struct sctp_outq *q, |
| 1671 | struct list_head *transmitted_queue, |
| 1672 | struct sctp_transport *transport, |
| 1673 | __u32 highest_new_tsn_in_sack, |
| 1674 | int count_of_newacks) |
| 1675 | { |
| 1676 | struct sctp_chunk *chunk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | __u32 tsn; |
| 1678 | char do_fast_retransmit = 0; |
| 1679 | struct sctp_transport *primary = q->asoc->peer.primary_path; |
| 1680 | |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 1681 | list_for_each_entry(chunk, transmitted_queue, transmitted_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | tsn = ntohl(chunk->subh.data_hdr->tsn); |
| 1684 | |
| 1685 | /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all |
| 1686 | * 'Unacknowledged TSN's', if the TSN number of an |
| 1687 | * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack' |
| 1688 | * value, increment the 'TSN.Missing.Report' count on that |
| 1689 | * chunk if it has NOT been fast retransmitted or marked for |
| 1690 | * fast retransmit already. |
| 1691 | */ |
Neil Horman | c226ef9 | 2008-07-25 12:44:09 -0400 | [diff] [blame] | 1692 | if (chunk->fast_retransmit == SCTP_CAN_FRTX && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | !chunk->tsn_gap_acked && |
| 1694 | TSN_lt(tsn, highest_new_tsn_in_sack)) { |
| 1695 | |
| 1696 | /* SFR-CACC may require us to skip marking |
| 1697 | * this chunk as missing. |
| 1698 | */ |
| 1699 | if (!transport || !sctp_cacc_skip(primary, transport, |
| 1700 | count_of_newacks, tsn)) { |
| 1701 | chunk->tsn_missing_report++; |
| 1702 | |
| 1703 | SCTP_DEBUG_PRINTK( |
| 1704 | "%s: TSN 0x%x missing counter: %d\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1705 | __func__, tsn, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | chunk->tsn_missing_report); |
| 1707 | } |
| 1708 | } |
| 1709 | /* |
| 1710 | * M4) If any DATA chunk is found to have a |
| 1711 | * 'TSN.Missing.Report' |
Vlad Yasevich | 27852c2 | 2006-02-02 16:57:31 -0800 | [diff] [blame] | 1712 | * value larger than or equal to 3, mark that chunk for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | * retransmission and start the fast retransmit procedure. |
| 1714 | */ |
| 1715 | |
Vlad Yasevich | 27852c2 | 2006-02-02 16:57:31 -0800 | [diff] [blame] | 1716 | if (chunk->tsn_missing_report >= 3) { |
Neil Horman | c226ef9 | 2008-07-25 12:44:09 -0400 | [diff] [blame] | 1717 | chunk->fast_retransmit = SCTP_NEED_FRTX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | do_fast_retransmit = 1; |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | if (transport) { |
| 1723 | if (do_fast_retransmit) |
| 1724 | sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX); |
| 1725 | |
| 1726 | SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, " |
| 1727 | "ssthresh: %d, flight_size: %d, pba: %d\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1728 | __func__, transport, transport->cwnd, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1729 | transport->ssthresh, transport->flight_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | transport->partial_bytes_acked); |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | /* Is the given TSN acked by this packet? */ |
| 1735 | static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn) |
| 1736 | { |
| 1737 | int i; |
| 1738 | sctp_sack_variable_t *frags; |
| 1739 | __u16 gap; |
| 1740 | __u32 ctsn = ntohl(sack->cum_tsn_ack); |
| 1741 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1742 | if (TSN_lte(tsn, ctsn)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | goto pass; |
| 1744 | |
| 1745 | /* 3.3.4 Selective Acknowledgement (SACK) (3): |
| 1746 | * |
| 1747 | * Gap Ack Blocks: |
| 1748 | * These fields contain the Gap Ack Blocks. They are repeated |
| 1749 | * for each Gap Ack Block up to the number of Gap Ack Blocks |
| 1750 | * defined in the Number of Gap Ack Blocks field. All DATA |
| 1751 | * chunks with TSNs greater than or equal to (Cumulative TSN |
| 1752 | * Ack + Gap Ack Block Start) and less than or equal to |
| 1753 | * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack |
| 1754 | * Block are assumed to have been received correctly. |
| 1755 | */ |
| 1756 | |
| 1757 | frags = sack->variable; |
| 1758 | gap = tsn - ctsn; |
| 1759 | for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) { |
| 1760 | if (TSN_lte(ntohs(frags[i].gab.start), gap) && |
| 1761 | TSN_lte(gap, ntohs(frags[i].gab.end))) |
| 1762 | goto pass; |
| 1763 | } |
| 1764 | |
| 1765 | return 0; |
| 1766 | pass: |
| 1767 | return 1; |
| 1768 | } |
| 1769 | |
| 1770 | static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist, |
Al Viro | 9f81bcd | 2006-11-20 17:26:34 -0800 | [diff] [blame] | 1771 | int nskips, __be16 stream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | { |
| 1773 | int i; |
| 1774 | |
| 1775 | for (i = 0; i < nskips; i++) { |
| 1776 | if (skiplist[i].stream == stream) |
| 1777 | return i; |
| 1778 | } |
| 1779 | return i; |
| 1780 | } |
| 1781 | |
| 1782 | /* Create and add a fwdtsn chunk to the outq's control queue if needed. */ |
| 1783 | static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn) |
| 1784 | { |
| 1785 | struct sctp_association *asoc = q->asoc; |
| 1786 | struct sctp_chunk *ftsn_chunk = NULL; |
| 1787 | struct sctp_fwdtsn_skip ftsn_skip_arr[10]; |
| 1788 | int nskips = 0; |
| 1789 | int skip_pos = 0; |
| 1790 | __u32 tsn; |
| 1791 | struct sctp_chunk *chunk; |
| 1792 | struct list_head *lchunk, *temp; |
| 1793 | |
Wei Yongjun | 7659502 | 2009-03-12 09:49:19 +0000 | [diff] [blame] | 1794 | if (!asoc->peer.prsctp_capable) |
| 1795 | return; |
| 1796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | /* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the |
| 1798 | * received SACK. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1799 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | * If (Advanced.Peer.Ack.Point < SackCumAck), then update |
| 1801 | * Advanced.Peer.Ack.Point to be equal to SackCumAck. |
| 1802 | */ |
| 1803 | if (TSN_lt(asoc->adv_peer_ack_point, ctsn)) |
| 1804 | asoc->adv_peer_ack_point = ctsn; |
| 1805 | |
| 1806 | /* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point" |
| 1807 | * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as |
| 1808 | * the chunk next in the out-queue space is marked as "abandoned" as |
| 1809 | * shown in the following example: |
| 1810 | * |
| 1811 | * Assuming that a SACK arrived with the Cumulative TSN ACK 102 |
| 1812 | * and the Advanced.Peer.Ack.Point is updated to this value: |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1813 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | * out-queue at the end of ==> out-queue after Adv.Ack.Point |
| 1815 | * normal SACK processing local advancement |
| 1816 | * ... ... |
| 1817 | * Adv.Ack.Pt-> 102 acked 102 acked |
| 1818 | * 103 abandoned 103 abandoned |
| 1819 | * 104 abandoned Adv.Ack.P-> 104 abandoned |
| 1820 | * 105 105 |
| 1821 | * 106 acked 106 acked |
| 1822 | * ... ... |
| 1823 | * |
| 1824 | * In this example, the data sender successfully advanced the |
| 1825 | * "Advanced.Peer.Ack.Point" from 102 to 104 locally. |
| 1826 | */ |
| 1827 | list_for_each_safe(lchunk, temp, &q->abandoned) { |
| 1828 | chunk = list_entry(lchunk, struct sctp_chunk, |
| 1829 | transmitted_list); |
| 1830 | tsn = ntohl(chunk->subh.data_hdr->tsn); |
| 1831 | |
| 1832 | /* Remove any chunks in the abandoned queue that are acked by |
| 1833 | * the ctsn. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1834 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | if (TSN_lte(tsn, ctsn)) { |
| 1836 | list_del_init(lchunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | sctp_chunk_free(chunk); |
| 1838 | } else { |
| 1839 | if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) { |
| 1840 | asoc->adv_peer_ack_point = tsn; |
| 1841 | if (chunk->chunk_hdr->flags & |
| 1842 | SCTP_DATA_UNORDERED) |
| 1843 | continue; |
| 1844 | skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0], |
| 1845 | nskips, |
| 1846 | chunk->subh.data_hdr->stream); |
| 1847 | ftsn_skip_arr[skip_pos].stream = |
| 1848 | chunk->subh.data_hdr->stream; |
| 1849 | ftsn_skip_arr[skip_pos].ssn = |
| 1850 | chunk->subh.data_hdr->ssn; |
| 1851 | if (skip_pos == nskips) |
| 1852 | nskips++; |
| 1853 | if (nskips == 10) |
| 1854 | break; |
| 1855 | } else |
| 1856 | break; |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | /* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point" |
| 1861 | * is greater than the Cumulative TSN ACK carried in the received |
| 1862 | * SACK, the data sender MUST send the data receiver a FORWARD TSN |
| 1863 | * chunk containing the latest value of the |
| 1864 | * "Advanced.Peer.Ack.Point". |
| 1865 | * |
| 1866 | * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD |
| 1867 | * list each stream and sequence number in the forwarded TSN. This |
| 1868 | * information will enable the receiver to easily find any |
| 1869 | * stranded TSN's waiting on stream reorder queues. Each stream |
| 1870 | * SHOULD only be reported once; this means that if multiple |
| 1871 | * abandoned messages occur in the same stream then only the |
| 1872 | * highest abandoned stream sequence number is reported. If the |
| 1873 | * total size of the FORWARD TSN does NOT fit in a single MTU then |
| 1874 | * the sender of the FORWARD TSN SHOULD lower the |
| 1875 | * Advanced.Peer.Ack.Point to the last TSN that will fit in a |
| 1876 | * single MTU. |
| 1877 | */ |
| 1878 | if (asoc->adv_peer_ack_point > ctsn) |
| 1879 | ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1880 | nskips, &ftsn_skip_arr[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | |
| 1882 | if (ftsn_chunk) { |
David S. Miller | 79af02c | 2005-07-08 21:47:49 -0700 | [diff] [blame] | 1883 | list_add_tail(&ftsn_chunk->list, &q->control_chunk_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
| 1885 | } |
| 1886 | } |