outqueue.c 51 KB

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