outqueue.c 54 KB

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