outqueue.c 53 KB

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