outqueue.c 54 KB

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