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