outqueue.c 53 KB

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