outqueue.c 52 KB

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