outqueue.c 52 KB

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