outqueue.c 53 KB

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