outqueue.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  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. redo:
  540. /* Attempt to append this chunk to the packet. */
  541. status = sctp_packet_append_chunk(pkt, chunk);
  542. switch (status) {
  543. case SCTP_XMIT_PMTU_FULL:
  544. if (!pkt->has_data && !pkt->has_cookie_echo) {
  545. /* If this packet did not contain DATA then
  546. * retransmission did not happen, so do it
  547. * again. We'll ignore the error here since
  548. * control chunks are already freed so there
  549. * is nothing we can do.
  550. */
  551. sctp_packet_transmit(pkt);
  552. goto redo;
  553. }
  554. /* Send this packet. */
  555. error = sctp_packet_transmit(pkt);
  556. /* If we are retransmitting, we should only
  557. * send a single packet.
  558. */
  559. if (rtx_timeout || fast_rtx)
  560. done = 1;
  561. /* Bundle next chunk in the next round. */
  562. break;
  563. case SCTP_XMIT_RWND_FULL:
  564. /* Send this packet. */
  565. error = sctp_packet_transmit(pkt);
  566. /* Stop sending DATA as there is no more room
  567. * at the receiver.
  568. */
  569. done = 1;
  570. break;
  571. case SCTP_XMIT_NAGLE_DELAY:
  572. /* Send this packet. */
  573. error = sctp_packet_transmit(pkt);
  574. /* Stop sending DATA because of nagle delay. */
  575. done = 1;
  576. break;
  577. default:
  578. /* The append was successful, so add this chunk to
  579. * the transmitted list.
  580. */
  581. list_del(&chunk->transmitted_list);
  582. list_add_tail(&chunk->transmitted_list,
  583. &transport->transmitted);
  584. /* Mark the chunk as ineligible for fast retransmit
  585. * after it is retransmitted.
  586. */
  587. if (chunk->fast_retransmit == SCTP_NEED_FRTX)
  588. chunk->fast_retransmit = SCTP_DONT_FRTX;
  589. /* Force start T3-rtx timer when fast retransmitting
  590. * the earliest outstanding TSN
  591. */
  592. if (!timer && fast_rtx &&
  593. ntohl(chunk->subh.data_hdr->tsn) ==
  594. asoc->ctsn_ack_point + 1)
  595. timer = 2;
  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 throught */
  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, 0);
  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. start_timer-1);
  827. /* This can happen on COOKIE-ECHO resend. Only
  828. * one chunk can get bundled with a COOKIE-ECHO.
  829. */
  830. if (packet->has_cookie_echo)
  831. goto sctp_flush_out;
  832. /* Don't send new data if there is still data
  833. * waiting to retransmit.
  834. */
  835. if (!list_empty(&q->retransmit))
  836. goto sctp_flush_out;
  837. }
  838. /* Apply Max.Burst limitation to the current transport in
  839. * case it will be used for new data. We are going to
  840. * rest it before we return, but we want to apply the limit
  841. * to the currently queued data.
  842. */
  843. if (transport)
  844. sctp_transport_burst_limited(transport);
  845. /* Finally, transmit new packets. */
  846. while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
  847. /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
  848. * stream identifier.
  849. */
  850. if (chunk->sinfo.sinfo_stream >=
  851. asoc->c.sinit_num_ostreams) {
  852. /* Mark as failed send. */
  853. sctp_chunk_fail(chunk, SCTP_ERROR_INV_STRM);
  854. sctp_chunk_free(chunk);
  855. continue;
  856. }
  857. /* Has this chunk expired? */
  858. if (sctp_chunk_abandoned(chunk)) {
  859. sctp_chunk_fail(chunk, 0);
  860. sctp_chunk_free(chunk);
  861. continue;
  862. }
  863. /* If there is a specified transport, use it.
  864. * Otherwise, we want to use the active path.
  865. */
  866. new_transport = chunk->transport;
  867. if (!new_transport ||
  868. ((new_transport->state == SCTP_INACTIVE) ||
  869. (new_transport->state == SCTP_UNCONFIRMED)))
  870. new_transport = asoc->peer.active_path;
  871. /* Change packets if necessary. */
  872. if (new_transport != transport) {
  873. transport = new_transport;
  874. /* Schedule to have this transport's
  875. * packet flushed.
  876. */
  877. if (list_empty(&transport->send_ready)) {
  878. list_add_tail(&transport->send_ready,
  879. &transport_list);
  880. }
  881. packet = &transport->packet;
  882. sctp_packet_config(packet, vtag,
  883. asoc->peer.ecn_capable);
  884. /* We've switched transports, so apply the
  885. * Burst limit to the new transport.
  886. */
  887. sctp_transport_burst_limited(transport);
  888. }
  889. SCTP_DEBUG_PRINTK("sctp_outq_flush(%p, %p[%s]), ",
  890. q, chunk,
  891. chunk && chunk->chunk_hdr ?
  892. sctp_cname(SCTP_ST_CHUNK(
  893. chunk->chunk_hdr->type))
  894. : "Illegal Chunk");
  895. SCTP_DEBUG_PRINTK("TX TSN 0x%x skb->head "
  896. "%p skb->users %d.\n",
  897. ntohl(chunk->subh.data_hdr->tsn),
  898. chunk->skb ?chunk->skb->head : NULL,
  899. chunk->skb ?
  900. atomic_read(&chunk->skb->users) : -1);
  901. /* Add the chunk to the packet. */
  902. status = sctp_packet_transmit_chunk(packet, chunk, 0);
  903. switch (status) {
  904. case SCTP_XMIT_PMTU_FULL:
  905. case SCTP_XMIT_RWND_FULL:
  906. case SCTP_XMIT_NAGLE_DELAY:
  907. /* We could not append this chunk, so put
  908. * the chunk back on the output queue.
  909. */
  910. SCTP_DEBUG_PRINTK("sctp_outq_flush: could "
  911. "not transmit TSN: 0x%x, status: %d\n",
  912. ntohl(chunk->subh.data_hdr->tsn),
  913. status);
  914. sctp_outq_head_data(q, chunk);
  915. goto sctp_flush_out;
  916. break;
  917. case SCTP_XMIT_OK:
  918. /* The sender is in the SHUTDOWN-PENDING state,
  919. * The sender MAY set the I-bit in the DATA
  920. * chunk header.
  921. */
  922. if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
  923. chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
  924. break;
  925. default:
  926. BUG();
  927. }
  928. /* BUG: We assume that the sctp_packet_transmit()
  929. * call below will succeed all the time and add the
  930. * chunk to the transmitted list and restart the
  931. * timers.
  932. * It is possible that the call can fail under OOM
  933. * conditions.
  934. *
  935. * Is this really a problem? Won't this behave
  936. * like a lost TSN?
  937. */
  938. list_add_tail(&chunk->transmitted_list,
  939. &transport->transmitted);
  940. sctp_transport_reset_timers(transport, 0);
  941. q->empty = 0;
  942. /* Only let one DATA chunk get bundled with a
  943. * COOKIE-ECHO chunk.
  944. */
  945. if (packet->has_cookie_echo)
  946. goto sctp_flush_out;
  947. }
  948. break;
  949. default:
  950. /* Do nothing. */
  951. break;
  952. }
  953. sctp_flush_out:
  954. /* Before returning, examine all the transports touched in
  955. * this call. Right now, we bluntly force clear all the
  956. * transports. Things might change after we implement Nagle.
  957. * But such an examination is still required.
  958. *
  959. * --xguo
  960. */
  961. while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL ) {
  962. struct sctp_transport *t = list_entry(ltransport,
  963. struct sctp_transport,
  964. send_ready);
  965. packet = &t->packet;
  966. if (!sctp_packet_empty(packet))
  967. error = sctp_packet_transmit(packet);
  968. /* Clear the burst limited state, if any */
  969. sctp_transport_burst_reset(t);
  970. }
  971. return error;
  972. }
  973. /* Update unack_data based on the incoming SACK chunk */
  974. static void sctp_sack_update_unack_data(struct sctp_association *assoc,
  975. struct sctp_sackhdr *sack)
  976. {
  977. sctp_sack_variable_t *frags;
  978. __u16 unack_data;
  979. int i;
  980. unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
  981. frags = sack->variable;
  982. for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
  983. unack_data -= ((ntohs(frags[i].gab.end) -
  984. ntohs(frags[i].gab.start) + 1));
  985. }
  986. assoc->unack_data = unack_data;
  987. }
  988. /* Return the highest new tsn that is acknowledged by the given SACK chunk. */
  989. static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack,
  990. struct sctp_association *asoc)
  991. {
  992. struct sctp_transport *transport;
  993. struct sctp_chunk *chunk;
  994. __u32 highest_new_tsn, tsn;
  995. struct list_head *transport_list = &asoc->peer.transport_addr_list;
  996. highest_new_tsn = ntohl(sack->cum_tsn_ack);
  997. list_for_each_entry(transport, transport_list, transports) {
  998. list_for_each_entry(chunk, &transport->transmitted,
  999. transmitted_list) {
  1000. tsn = ntohl(chunk->subh.data_hdr->tsn);
  1001. if (!chunk->tsn_gap_acked &&
  1002. TSN_lt(highest_new_tsn, tsn) &&
  1003. sctp_acked(sack, tsn))
  1004. highest_new_tsn = tsn;
  1005. }
  1006. }
  1007. return highest_new_tsn;
  1008. }
  1009. /* This is where we REALLY process a SACK.
  1010. *
  1011. * Process the SACK against the outqueue. Mostly, this just frees
  1012. * things off the transmitted queue.
  1013. */
  1014. int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
  1015. {
  1016. struct sctp_association *asoc = q->asoc;
  1017. struct sctp_transport *transport;
  1018. struct sctp_chunk *tchunk = NULL;
  1019. struct list_head *lchunk, *transport_list, *temp;
  1020. sctp_sack_variable_t *frags = sack->variable;
  1021. __u32 sack_ctsn, ctsn, tsn;
  1022. __u32 highest_tsn, highest_new_tsn;
  1023. __u32 sack_a_rwnd;
  1024. unsigned outstanding;
  1025. struct sctp_transport *primary = asoc->peer.primary_path;
  1026. int count_of_newacks = 0;
  1027. int gap_ack_blocks;
  1028. /* Grab the association's destination address list. */
  1029. transport_list = &asoc->peer.transport_addr_list;
  1030. sack_ctsn = ntohl(sack->cum_tsn_ack);
  1031. gap_ack_blocks = ntohs(sack->num_gap_ack_blocks);
  1032. /*
  1033. * SFR-CACC algorithm:
  1034. * On receipt of a SACK the sender SHOULD execute the
  1035. * following statements.
  1036. *
  1037. * 1) If the cumulative ack in the SACK passes next tsn_at_change
  1038. * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
  1039. * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
  1040. * all destinations.
  1041. * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
  1042. * is set the receiver of the SACK MUST take the following actions:
  1043. *
  1044. * A) Initialize the cacc_saw_newack to 0 for all destination
  1045. * addresses.
  1046. *
  1047. * Only bother if changeover_active is set. Otherwise, this is
  1048. * totally suboptimal to do on every SACK.
  1049. */
  1050. if (primary->cacc.changeover_active) {
  1051. u8 clear_cycling = 0;
  1052. if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
  1053. primary->cacc.changeover_active = 0;
  1054. clear_cycling = 1;
  1055. }
  1056. if (clear_cycling || gap_ack_blocks) {
  1057. list_for_each_entry(transport, transport_list,
  1058. transports) {
  1059. if (clear_cycling)
  1060. transport->cacc.cycling_changeover = 0;
  1061. if (gap_ack_blocks)
  1062. transport->cacc.cacc_saw_newack = 0;
  1063. }
  1064. }
  1065. }
  1066. /* Get the highest TSN in the sack. */
  1067. highest_tsn = sack_ctsn;
  1068. if (gap_ack_blocks)
  1069. highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);
  1070. if (TSN_lt(asoc->highest_sacked, highest_tsn)) {
  1071. highest_new_tsn = highest_tsn;
  1072. asoc->highest_sacked = highest_tsn;
  1073. } else {
  1074. highest_new_tsn = sctp_highest_new_tsn(sack, asoc);
  1075. }
  1076. /* Run through the retransmit queue. Credit bytes received
  1077. * and free those chunks that we can.
  1078. */
  1079. sctp_check_transmitted(q, &q->retransmit, NULL, sack, highest_new_tsn);
  1080. /* Run through the transmitted queue.
  1081. * Credit bytes received and free those chunks which we can.
  1082. *
  1083. * This is a MASSIVE candidate for optimization.
  1084. */
  1085. list_for_each_entry(transport, transport_list, transports) {
  1086. sctp_check_transmitted(q, &transport->transmitted,
  1087. transport, sack, highest_new_tsn);
  1088. /*
  1089. * SFR-CACC algorithm:
  1090. * C) Let count_of_newacks be the number of
  1091. * destinations for which cacc_saw_newack is set.
  1092. */
  1093. if (transport->cacc.cacc_saw_newack)
  1094. count_of_newacks ++;
  1095. }
  1096. if (gap_ack_blocks) {
  1097. list_for_each_entry(transport, transport_list, transports)
  1098. sctp_mark_missing(q, &transport->transmitted, transport,
  1099. highest_new_tsn, count_of_newacks);
  1100. }
  1101. /* Move the Cumulative TSN Ack Point if appropriate. */
  1102. if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn))
  1103. asoc->ctsn_ack_point = sack_ctsn;
  1104. /* Update unack_data field in the assoc. */
  1105. sctp_sack_update_unack_data(asoc, sack);
  1106. ctsn = asoc->ctsn_ack_point;
  1107. /* Throw away stuff rotting on the sack queue. */
  1108. list_for_each_safe(lchunk, temp, &q->sacked) {
  1109. tchunk = list_entry(lchunk, struct sctp_chunk,
  1110. transmitted_list);
  1111. tsn = ntohl(tchunk->subh.data_hdr->tsn);
  1112. if (TSN_lte(tsn, ctsn)) {
  1113. list_del_init(&tchunk->transmitted_list);
  1114. sctp_chunk_free(tchunk);
  1115. }
  1116. }
  1117. /* ii) Set rwnd equal to the newly received a_rwnd minus the
  1118. * number of bytes still outstanding after processing the
  1119. * Cumulative TSN Ack and the Gap Ack Blocks.
  1120. */
  1121. sack_a_rwnd = ntohl(sack->a_rwnd);
  1122. outstanding = q->outstanding_bytes;
  1123. if (outstanding < sack_a_rwnd)
  1124. sack_a_rwnd -= outstanding;
  1125. else
  1126. sack_a_rwnd = 0;
  1127. asoc->peer.rwnd = sack_a_rwnd;
  1128. sctp_generate_fwdtsn(q, sack_ctsn);
  1129. SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
  1130. __func__, sack_ctsn);
  1131. SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association, "
  1132. "%p is 0x%x. Adv peer ack point: 0x%x\n",
  1133. __func__, asoc, ctsn, asoc->adv_peer_ack_point);
  1134. /* See if all chunks are acked.
  1135. * Make sure the empty queue handler will get run later.
  1136. */
  1137. q->empty = (list_empty(&q->out_chunk_list) &&
  1138. list_empty(&q->retransmit));
  1139. if (!q->empty)
  1140. goto finish;
  1141. list_for_each_entry(transport, transport_list, transports) {
  1142. q->empty = q->empty && list_empty(&transport->transmitted);
  1143. if (!q->empty)
  1144. goto finish;
  1145. }
  1146. SCTP_DEBUG_PRINTK("sack queue is empty.\n");
  1147. finish:
  1148. return q->empty;
  1149. }
  1150. /* Is the outqueue empty? */
  1151. int sctp_outq_is_empty(const struct sctp_outq *q)
  1152. {
  1153. return q->empty;
  1154. }
  1155. /********************************************************************
  1156. * 2nd Level Abstractions
  1157. ********************************************************************/
  1158. /* Go through a transport's transmitted list or the association's retransmit
  1159. * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
  1160. * The retransmit list will not have an associated transport.
  1161. *
  1162. * I added coherent debug information output. --xguo
  1163. *
  1164. * Instead of printing 'sacked' or 'kept' for each TSN on the
  1165. * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
  1166. * KEPT TSN6-TSN7, etc.
  1167. */
  1168. static void sctp_check_transmitted(struct sctp_outq *q,
  1169. struct list_head *transmitted_queue,
  1170. struct sctp_transport *transport,
  1171. struct sctp_sackhdr *sack,
  1172. __u32 highest_new_tsn_in_sack)
  1173. {
  1174. struct list_head *lchunk;
  1175. struct sctp_chunk *tchunk;
  1176. struct list_head tlist;
  1177. __u32 tsn;
  1178. __u32 sack_ctsn;
  1179. __u32 rtt;
  1180. __u8 restart_timer = 0;
  1181. int bytes_acked = 0;
  1182. int migrate_bytes = 0;
  1183. /* These state variables are for coherent debug output. --xguo */
  1184. #if SCTP_DEBUG
  1185. __u32 dbg_ack_tsn = 0; /* An ACKed TSN range starts here... */
  1186. __u32 dbg_last_ack_tsn = 0; /* ...and finishes here. */
  1187. __u32 dbg_kept_tsn = 0; /* An un-ACKed range starts here... */
  1188. __u32 dbg_last_kept_tsn = 0; /* ...and finishes here. */
  1189. /* 0 : The last TSN was ACKed.
  1190. * 1 : The last TSN was NOT ACKed (i.e. KEPT).
  1191. * -1: We need to initialize.
  1192. */
  1193. int dbg_prt_state = -1;
  1194. #endif /* SCTP_DEBUG */
  1195. sack_ctsn = ntohl(sack->cum_tsn_ack);
  1196. INIT_LIST_HEAD(&tlist);
  1197. /* The while loop will skip empty transmitted queues. */
  1198. while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
  1199. tchunk = list_entry(lchunk, struct sctp_chunk,
  1200. transmitted_list);
  1201. if (sctp_chunk_abandoned(tchunk)) {
  1202. /* Move the chunk to abandoned list. */
  1203. sctp_insert_list(&q->abandoned, lchunk);
  1204. /* If this chunk has not been acked, stop
  1205. * considering it as 'outstanding'.
  1206. */
  1207. if (!tchunk->tsn_gap_acked) {
  1208. if (tchunk->transport)
  1209. tchunk->transport->flight_size -=
  1210. sctp_data_size(tchunk);
  1211. q->outstanding_bytes -= sctp_data_size(tchunk);
  1212. }
  1213. continue;
  1214. }
  1215. tsn = ntohl(tchunk->subh.data_hdr->tsn);
  1216. if (sctp_acked(sack, tsn)) {
  1217. /* If this queue is the retransmit queue, the
  1218. * retransmit timer has already reclaimed
  1219. * the outstanding bytes for this chunk, so only
  1220. * count bytes associated with a transport.
  1221. */
  1222. if (transport) {
  1223. /* If this chunk is being used for RTT
  1224. * measurement, calculate the RTT and update
  1225. * the RTO using this value.
  1226. *
  1227. * 6.3.1 C5) Karn's algorithm: RTT measurements
  1228. * MUST NOT be made using packets that were
  1229. * retransmitted (and thus for which it is
  1230. * ambiguous whether the reply was for the
  1231. * first instance of the packet or a later
  1232. * instance).
  1233. */
  1234. if (!tchunk->tsn_gap_acked &&
  1235. !tchunk->resent &&
  1236. tchunk->rtt_in_progress) {
  1237. tchunk->rtt_in_progress = 0;
  1238. rtt = jiffies - tchunk->sent_at;
  1239. sctp_transport_update_rto(transport,
  1240. rtt);
  1241. }
  1242. }
  1243. /* If the chunk hasn't been marked as ACKED,
  1244. * mark it and account bytes_acked if the
  1245. * chunk had a valid transport (it will not
  1246. * have a transport if ASCONF had deleted it
  1247. * while DATA was outstanding).
  1248. */
  1249. if (!tchunk->tsn_gap_acked) {
  1250. tchunk->tsn_gap_acked = 1;
  1251. bytes_acked += sctp_data_size(tchunk);
  1252. if (!tchunk->transport)
  1253. migrate_bytes += sctp_data_size(tchunk);
  1254. }
  1255. if (TSN_lte(tsn, sack_ctsn)) {
  1256. /* RFC 2960 6.3.2 Retransmission Timer Rules
  1257. *
  1258. * R3) Whenever a SACK is received
  1259. * that acknowledges the DATA chunk
  1260. * with the earliest outstanding TSN
  1261. * for that address, restart T3-rtx
  1262. * timer for that address with its
  1263. * current RTO.
  1264. */
  1265. restart_timer = 1;
  1266. if (!tchunk->tsn_gap_acked) {
  1267. /*
  1268. * SFR-CACC algorithm:
  1269. * 2) If the SACK contains gap acks
  1270. * and the flag CHANGEOVER_ACTIVE is
  1271. * set the receiver of the SACK MUST
  1272. * take the following action:
  1273. *
  1274. * B) For each TSN t being acked that
  1275. * has not been acked in any SACK so
  1276. * far, set cacc_saw_newack to 1 for
  1277. * the destination that the TSN was
  1278. * sent to.
  1279. */
  1280. if (transport &&
  1281. sack->num_gap_ack_blocks &&
  1282. q->asoc->peer.primary_path->cacc.
  1283. changeover_active)
  1284. transport->cacc.cacc_saw_newack
  1285. = 1;
  1286. }
  1287. list_add_tail(&tchunk->transmitted_list,
  1288. &q->sacked);
  1289. } else {
  1290. /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
  1291. * M2) Each time a SACK arrives reporting
  1292. * 'Stray DATA chunk(s)' record the highest TSN
  1293. * reported as newly acknowledged, call this
  1294. * value 'HighestTSNinSack'. A newly
  1295. * acknowledged DATA chunk is one not
  1296. * previously acknowledged in a SACK.
  1297. *
  1298. * When the SCTP sender of data receives a SACK
  1299. * chunk that acknowledges, for the first time,
  1300. * the receipt of a DATA chunk, all the still
  1301. * unacknowledged DATA chunks whose TSN is
  1302. * older than that newly acknowledged DATA
  1303. * chunk, are qualified as 'Stray DATA chunks'.
  1304. */
  1305. list_add_tail(lchunk, &tlist);
  1306. }
  1307. #if SCTP_DEBUG
  1308. switch (dbg_prt_state) {
  1309. case 0: /* last TSN was ACKed */
  1310. if (dbg_last_ack_tsn + 1 == tsn) {
  1311. /* This TSN belongs to the
  1312. * current ACK range.
  1313. */
  1314. break;
  1315. }
  1316. if (dbg_last_ack_tsn != dbg_ack_tsn) {
  1317. /* Display the end of the
  1318. * current range.
  1319. */
  1320. SCTP_DEBUG_PRINTK("-%08x",
  1321. dbg_last_ack_tsn);
  1322. }
  1323. /* Start a new range. */
  1324. SCTP_DEBUG_PRINTK(",%08x", tsn);
  1325. dbg_ack_tsn = tsn;
  1326. break;
  1327. case 1: /* The last TSN was NOT ACKed. */
  1328. if (dbg_last_kept_tsn != dbg_kept_tsn) {
  1329. /* Display the end of current range. */
  1330. SCTP_DEBUG_PRINTK("-%08x",
  1331. dbg_last_kept_tsn);
  1332. }
  1333. SCTP_DEBUG_PRINTK("\n");
  1334. /* FALL THROUGH... */
  1335. default:
  1336. /* This is the first-ever TSN we examined. */
  1337. /* Start a new range of ACK-ed TSNs. */
  1338. SCTP_DEBUG_PRINTK("ACKed: %08x", tsn);
  1339. dbg_prt_state = 0;
  1340. dbg_ack_tsn = tsn;
  1341. }
  1342. dbg_last_ack_tsn = tsn;
  1343. #endif /* SCTP_DEBUG */
  1344. } else {
  1345. if (tchunk->tsn_gap_acked) {
  1346. SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
  1347. "data TSN: 0x%x\n",
  1348. __func__,
  1349. tsn);
  1350. tchunk->tsn_gap_acked = 0;
  1351. if (tchunk->transport)
  1352. bytes_acked -= sctp_data_size(tchunk);
  1353. /* RFC 2960 6.3.2 Retransmission Timer Rules
  1354. *
  1355. * R4) Whenever a SACK is received missing a
  1356. * TSN that was previously acknowledged via a
  1357. * Gap Ack Block, start T3-rtx for the
  1358. * destination address to which the DATA
  1359. * chunk was originally
  1360. * transmitted if it is not already running.
  1361. */
  1362. restart_timer = 1;
  1363. }
  1364. list_add_tail(lchunk, &tlist);
  1365. #if SCTP_DEBUG
  1366. /* See the above comments on ACK-ed TSNs. */
  1367. switch (dbg_prt_state) {
  1368. case 1:
  1369. if (dbg_last_kept_tsn + 1 == tsn)
  1370. break;
  1371. if (dbg_last_kept_tsn != dbg_kept_tsn)
  1372. SCTP_DEBUG_PRINTK("-%08x",
  1373. dbg_last_kept_tsn);
  1374. SCTP_DEBUG_PRINTK(",%08x", tsn);
  1375. dbg_kept_tsn = tsn;
  1376. break;
  1377. case 0:
  1378. if (dbg_last_ack_tsn != dbg_ack_tsn)
  1379. SCTP_DEBUG_PRINTK("-%08x",
  1380. dbg_last_ack_tsn);
  1381. SCTP_DEBUG_PRINTK("\n");
  1382. /* FALL THROUGH... */
  1383. default:
  1384. SCTP_DEBUG_PRINTK("KEPT: %08x",tsn);
  1385. dbg_prt_state = 1;
  1386. dbg_kept_tsn = tsn;
  1387. }
  1388. dbg_last_kept_tsn = tsn;
  1389. #endif /* SCTP_DEBUG */
  1390. }
  1391. }
  1392. #if SCTP_DEBUG
  1393. /* Finish off the last range, displaying its ending TSN. */
  1394. switch (dbg_prt_state) {
  1395. case 0:
  1396. if (dbg_last_ack_tsn != dbg_ack_tsn) {
  1397. SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_ack_tsn);
  1398. } else {
  1399. SCTP_DEBUG_PRINTK("\n");
  1400. }
  1401. break;
  1402. case 1:
  1403. if (dbg_last_kept_tsn != dbg_kept_tsn) {
  1404. SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_kept_tsn);
  1405. } else {
  1406. SCTP_DEBUG_PRINTK("\n");
  1407. }
  1408. }
  1409. #endif /* SCTP_DEBUG */
  1410. if (transport) {
  1411. if (bytes_acked) {
  1412. /* We may have counted DATA that was migrated
  1413. * to this transport due to DEL-IP operation.
  1414. * Subtract those bytes, since the were never
  1415. * send on this transport and shouldn't be
  1416. * credited to this transport.
  1417. */
  1418. bytes_acked -= migrate_bytes;
  1419. /* 8.2. When an outstanding TSN is acknowledged,
  1420. * the endpoint shall clear the error counter of
  1421. * the destination transport address to which the
  1422. * DATA chunk was last sent.
  1423. * The association's overall error counter is
  1424. * also cleared.
  1425. */
  1426. transport->error_count = 0;
  1427. transport->asoc->overall_error_count = 0;
  1428. /* Mark the destination transport address as
  1429. * active if it is not so marked.
  1430. */
  1431. if ((transport->state == SCTP_INACTIVE) ||
  1432. (transport->state == SCTP_UNCONFIRMED)) {
  1433. sctp_assoc_control_transport(
  1434. transport->asoc,
  1435. transport,
  1436. SCTP_TRANSPORT_UP,
  1437. SCTP_RECEIVED_SACK);
  1438. }
  1439. sctp_transport_raise_cwnd(transport, sack_ctsn,
  1440. bytes_acked);
  1441. transport->flight_size -= bytes_acked;
  1442. if (transport->flight_size == 0)
  1443. transport->partial_bytes_acked = 0;
  1444. q->outstanding_bytes -= bytes_acked + migrate_bytes;
  1445. } else {
  1446. /* RFC 2960 6.1, sctpimpguide-06 2.15.2
  1447. * When a sender is doing zero window probing, it
  1448. * should not timeout the association if it continues
  1449. * to receive new packets from the receiver. The
  1450. * reason is that the receiver MAY keep its window
  1451. * closed for an indefinite time.
  1452. * A sender is doing zero window probing when the
  1453. * receiver's advertised window is zero, and there is
  1454. * only one data chunk in flight to the receiver.
  1455. */
  1456. if (!q->asoc->peer.rwnd &&
  1457. !list_empty(&tlist) &&
  1458. (sack_ctsn+2 == q->asoc->next_tsn)) {
  1459. SCTP_DEBUG_PRINTK("%s: SACK received for zero "
  1460. "window probe: %u\n",
  1461. __func__, sack_ctsn);
  1462. q->asoc->overall_error_count = 0;
  1463. transport->error_count = 0;
  1464. }
  1465. }
  1466. /* RFC 2960 6.3.2 Retransmission Timer Rules
  1467. *
  1468. * R2) Whenever all outstanding data sent to an address have
  1469. * been acknowledged, turn off the T3-rtx timer of that
  1470. * address.
  1471. */
  1472. if (!transport->flight_size) {
  1473. if (timer_pending(&transport->T3_rtx_timer) &&
  1474. del_timer(&transport->T3_rtx_timer)) {
  1475. sctp_transport_put(transport);
  1476. }
  1477. } else if (restart_timer) {
  1478. if (!mod_timer(&transport->T3_rtx_timer,
  1479. jiffies + transport->rto))
  1480. sctp_transport_hold(transport);
  1481. }
  1482. }
  1483. list_splice(&tlist, transmitted_queue);
  1484. }
  1485. /* Mark chunks as missing and consequently may get retransmitted. */
  1486. static void sctp_mark_missing(struct sctp_outq *q,
  1487. struct list_head *transmitted_queue,
  1488. struct sctp_transport *transport,
  1489. __u32 highest_new_tsn_in_sack,
  1490. int count_of_newacks)
  1491. {
  1492. struct sctp_chunk *chunk;
  1493. __u32 tsn;
  1494. char do_fast_retransmit = 0;
  1495. struct sctp_transport *primary = q->asoc->peer.primary_path;
  1496. list_for_each_entry(chunk, transmitted_queue, transmitted_list) {
  1497. tsn = ntohl(chunk->subh.data_hdr->tsn);
  1498. /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
  1499. * 'Unacknowledged TSN's', if the TSN number of an
  1500. * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
  1501. * value, increment the 'TSN.Missing.Report' count on that
  1502. * chunk if it has NOT been fast retransmitted or marked for
  1503. * fast retransmit already.
  1504. */
  1505. if (chunk->fast_retransmit == SCTP_CAN_FRTX &&
  1506. !chunk->tsn_gap_acked &&
  1507. TSN_lt(tsn, highest_new_tsn_in_sack)) {
  1508. /* SFR-CACC may require us to skip marking
  1509. * this chunk as missing.
  1510. */
  1511. if (!transport || !sctp_cacc_skip(primary, transport,
  1512. count_of_newacks, tsn)) {
  1513. chunk->tsn_missing_report++;
  1514. SCTP_DEBUG_PRINTK(
  1515. "%s: TSN 0x%x missing counter: %d\n",
  1516. __func__, tsn,
  1517. chunk->tsn_missing_report);
  1518. }
  1519. }
  1520. /*
  1521. * M4) If any DATA chunk is found to have a
  1522. * 'TSN.Missing.Report'
  1523. * value larger than or equal to 3, mark that chunk for
  1524. * retransmission and start the fast retransmit procedure.
  1525. */
  1526. if (chunk->tsn_missing_report >= 3) {
  1527. chunk->fast_retransmit = SCTP_NEED_FRTX;
  1528. do_fast_retransmit = 1;
  1529. }
  1530. }
  1531. if (transport) {
  1532. if (do_fast_retransmit)
  1533. sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
  1534. SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
  1535. "ssthresh: %d, flight_size: %d, pba: %d\n",
  1536. __func__, transport, transport->cwnd,
  1537. transport->ssthresh, transport->flight_size,
  1538. transport->partial_bytes_acked);
  1539. }
  1540. }
  1541. /* Is the given TSN acked by this packet? */
  1542. static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
  1543. {
  1544. int i;
  1545. sctp_sack_variable_t *frags;
  1546. __u16 gap;
  1547. __u32 ctsn = ntohl(sack->cum_tsn_ack);
  1548. if (TSN_lte(tsn, ctsn))
  1549. goto pass;
  1550. /* 3.3.4 Selective Acknowledgement (SACK) (3):
  1551. *
  1552. * Gap Ack Blocks:
  1553. * These fields contain the Gap Ack Blocks. They are repeated
  1554. * for each Gap Ack Block up to the number of Gap Ack Blocks
  1555. * defined in the Number of Gap Ack Blocks field. All DATA
  1556. * chunks with TSNs greater than or equal to (Cumulative TSN
  1557. * Ack + Gap Ack Block Start) and less than or equal to
  1558. * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
  1559. * Block are assumed to have been received correctly.
  1560. */
  1561. frags = sack->variable;
  1562. gap = tsn - ctsn;
  1563. for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
  1564. if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
  1565. TSN_lte(gap, ntohs(frags[i].gab.end)))
  1566. goto pass;
  1567. }
  1568. return 0;
  1569. pass:
  1570. return 1;
  1571. }
  1572. static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist,
  1573. int nskips, __be16 stream)
  1574. {
  1575. int i;
  1576. for (i = 0; i < nskips; i++) {
  1577. if (skiplist[i].stream == stream)
  1578. return i;
  1579. }
  1580. return i;
  1581. }
  1582. /* Create and add a fwdtsn chunk to the outq's control queue if needed. */
  1583. static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
  1584. {
  1585. struct sctp_association *asoc = q->asoc;
  1586. struct sctp_chunk *ftsn_chunk = NULL;
  1587. struct sctp_fwdtsn_skip ftsn_skip_arr[10];
  1588. int nskips = 0;
  1589. int skip_pos = 0;
  1590. __u32 tsn;
  1591. struct sctp_chunk *chunk;
  1592. struct list_head *lchunk, *temp;
  1593. if (!asoc->peer.prsctp_capable)
  1594. return;
  1595. /* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the
  1596. * received SACK.
  1597. *
  1598. * If (Advanced.Peer.Ack.Point < SackCumAck), then update
  1599. * Advanced.Peer.Ack.Point to be equal to SackCumAck.
  1600. */
  1601. if (TSN_lt(asoc->adv_peer_ack_point, ctsn))
  1602. asoc->adv_peer_ack_point = ctsn;
  1603. /* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point"
  1604. * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as
  1605. * the chunk next in the out-queue space is marked as "abandoned" as
  1606. * shown in the following example:
  1607. *
  1608. * Assuming that a SACK arrived with the Cumulative TSN ACK 102
  1609. * and the Advanced.Peer.Ack.Point is updated to this value:
  1610. *
  1611. * out-queue at the end of ==> out-queue after Adv.Ack.Point
  1612. * normal SACK processing local advancement
  1613. * ... ...
  1614. * Adv.Ack.Pt-> 102 acked 102 acked
  1615. * 103 abandoned 103 abandoned
  1616. * 104 abandoned Adv.Ack.P-> 104 abandoned
  1617. * 105 105
  1618. * 106 acked 106 acked
  1619. * ... ...
  1620. *
  1621. * In this example, the data sender successfully advanced the
  1622. * "Advanced.Peer.Ack.Point" from 102 to 104 locally.
  1623. */
  1624. list_for_each_safe(lchunk, temp, &q->abandoned) {
  1625. chunk = list_entry(lchunk, struct sctp_chunk,
  1626. transmitted_list);
  1627. tsn = ntohl(chunk->subh.data_hdr->tsn);
  1628. /* Remove any chunks in the abandoned queue that are acked by
  1629. * the ctsn.
  1630. */
  1631. if (TSN_lte(tsn, ctsn)) {
  1632. list_del_init(lchunk);
  1633. sctp_chunk_free(chunk);
  1634. } else {
  1635. if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
  1636. asoc->adv_peer_ack_point = tsn;
  1637. if (chunk->chunk_hdr->flags &
  1638. SCTP_DATA_UNORDERED)
  1639. continue;
  1640. skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0],
  1641. nskips,
  1642. chunk->subh.data_hdr->stream);
  1643. ftsn_skip_arr[skip_pos].stream =
  1644. chunk->subh.data_hdr->stream;
  1645. ftsn_skip_arr[skip_pos].ssn =
  1646. chunk->subh.data_hdr->ssn;
  1647. if (skip_pos == nskips)
  1648. nskips++;
  1649. if (nskips == 10)
  1650. break;
  1651. } else
  1652. break;
  1653. }
  1654. }
  1655. /* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point"
  1656. * is greater than the Cumulative TSN ACK carried in the received
  1657. * SACK, the data sender MUST send the data receiver a FORWARD TSN
  1658. * chunk containing the latest value of the
  1659. * "Advanced.Peer.Ack.Point".
  1660. *
  1661. * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD
  1662. * list each stream and sequence number in the forwarded TSN. This
  1663. * information will enable the receiver to easily find any
  1664. * stranded TSN's waiting on stream reorder queues. Each stream
  1665. * SHOULD only be reported once; this means that if multiple
  1666. * abandoned messages occur in the same stream then only the
  1667. * highest abandoned stream sequence number is reported. If the
  1668. * total size of the FORWARD TSN does NOT fit in a single MTU then
  1669. * the sender of the FORWARD TSN SHOULD lower the
  1670. * Advanced.Peer.Ack.Point to the last TSN that will fit in a
  1671. * single MTU.
  1672. */
  1673. if (asoc->adv_peer_ack_point > ctsn)
  1674. ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point,
  1675. nskips, &ftsn_skip_arr[0]);
  1676. if (ftsn_chunk) {
  1677. list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
  1678. SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
  1679. }
  1680. }