outqueue.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853
  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 == SCTP_NEED_FRTX)) ||
  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. time_before(jiffies, chunk->sent_at +
  387. transport->last_rto))
  388. continue;
  389. /* RFC 2960 6.2.1 Processing a Received SACK
  390. *
  391. * C) Any time a DATA chunk is marked for
  392. * retransmission (via either T3-rtx timer expiration
  393. * (Section 6.3.3) or via fast retransmit
  394. * (Section 7.2.4)), add the data size of those
  395. * chunks to the rwnd.
  396. */
  397. q->asoc->peer.rwnd += (sctp_data_size(chunk) +
  398. sizeof(struct sk_buff));
  399. q->outstanding_bytes -= sctp_data_size(chunk);
  400. transport->flight_size -= sctp_data_size(chunk);
  401. /* sctpimpguide-05 Section 2.8.2
  402. * M5) If a T3-rtx timer expires, the
  403. * 'TSN.Missing.Report' of all affected TSNs is set
  404. * to 0.
  405. */
  406. chunk->tsn_missing_report = 0;
  407. /* If a chunk that is being used for RTT measurement
  408. * has to be retransmitted, we cannot use this chunk
  409. * anymore for RTT measurements. Reset rto_pending so
  410. * that a new RTT measurement is started when a new
  411. * data chunk is sent.
  412. */
  413. if (chunk->rtt_in_progress) {
  414. chunk->rtt_in_progress = 0;
  415. transport->rto_pending = 0;
  416. }
  417. /* Move the chunk to the retransmit queue. The chunks
  418. * on the retransmit queue are always kept in order.
  419. */
  420. list_del_init(lchunk);
  421. sctp_insert_list(&q->retransmit, lchunk);
  422. }
  423. }
  424. SCTP_DEBUG_PRINTK("%s: transport: %p, reason: %d, "
  425. "cwnd: %d, ssthresh: %d, flight_size: %d, "
  426. "pba: %d\n", __func__,
  427. transport, reason,
  428. transport->cwnd, transport->ssthresh,
  429. transport->flight_size,
  430. transport->partial_bytes_acked);
  431. }
  432. /* Mark all the eligible packets on a transport for retransmission and force
  433. * one packet out.
  434. */
  435. void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
  436. sctp_retransmit_reason_t reason)
  437. {
  438. int error = 0;
  439. switch(reason) {
  440. case SCTP_RTXR_T3_RTX:
  441. SCTP_INC_STATS(SCTP_MIB_T3_RETRANSMITS);
  442. sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
  443. /* Update the retran path if the T3-rtx timer has expired for
  444. * the current retran path.
  445. */
  446. if (transport == transport->asoc->peer.retran_path)
  447. sctp_assoc_update_retran_path(transport->asoc);
  448. transport->asoc->rtx_data_chunks +=
  449. transport->asoc->unack_data;
  450. break;
  451. case SCTP_RTXR_FAST_RTX:
  452. SCTP_INC_STATS(SCTP_MIB_FAST_RETRANSMITS);
  453. sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
  454. q->fast_rtx = 1;
  455. break;
  456. case SCTP_RTXR_PMTUD:
  457. SCTP_INC_STATS(SCTP_MIB_PMTUD_RETRANSMITS);
  458. break;
  459. case SCTP_RTXR_T1_RTX:
  460. SCTP_INC_STATS(SCTP_MIB_T1_RETRANSMITS);
  461. transport->asoc->init_retries++;
  462. break;
  463. default:
  464. BUG();
  465. }
  466. sctp_retransmit_mark(q, transport, reason);
  467. /* PR-SCTP A5) Any time the T3-rtx timer expires, on any destination,
  468. * the sender SHOULD try to advance the "Advanced.Peer.Ack.Point" by
  469. * following the procedures outlined in C1 - C5.
  470. */
  471. if (reason == SCTP_RTXR_T3_RTX)
  472. sctp_generate_fwdtsn(q, q->asoc->ctsn_ack_point);
  473. /* Flush the queues only on timeout, since fast_rtx is only
  474. * triggered during sack processing and the queue
  475. * will be flushed at the end.
  476. */
  477. if (reason != SCTP_RTXR_FAST_RTX)
  478. error = sctp_outq_flush(q, /* rtx_timeout */ 1);
  479. if (error)
  480. q->asoc->base.sk->sk_err = -error;
  481. }
  482. /*
  483. * Transmit DATA chunks on the retransmit queue. Upon return from
  484. * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
  485. * need to be transmitted by the caller.
  486. * We assume that pkt->transport has already been set.
  487. *
  488. * The return value is a normal kernel error return value.
  489. */
  490. static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
  491. int rtx_timeout, int *start_timer)
  492. {
  493. struct list_head *lqueue;
  494. struct sctp_transport *transport = pkt->transport;
  495. sctp_xmit_t status;
  496. struct sctp_chunk *chunk, *chunk1;
  497. struct sctp_association *asoc;
  498. int fast_rtx;
  499. int error = 0;
  500. int timer = 0;
  501. int done = 0;
  502. asoc = q->asoc;
  503. lqueue = &q->retransmit;
  504. fast_rtx = q->fast_rtx;
  505. /* This loop handles time-out retransmissions, fast retransmissions,
  506. * and retransmissions due to opening of whindow.
  507. *
  508. * RFC 2960 6.3.3 Handle T3-rtx Expiration
  509. *
  510. * E3) Determine how many of the earliest (i.e., lowest TSN)
  511. * outstanding DATA chunks for the address for which the
  512. * T3-rtx has expired will fit into a single packet, subject
  513. * to the MTU constraint for the path corresponding to the
  514. * destination transport address to which the retransmission
  515. * is being sent (this may be different from the address for
  516. * which the timer expires [see Section 6.4]). Call this value
  517. * K. Bundle and retransmit those K DATA chunks in a single
  518. * packet to the destination endpoint.
  519. *
  520. * [Just to be painfully clear, if we are retransmitting
  521. * because a timeout just happened, we should send only ONE
  522. * packet of retransmitted data.]
  523. *
  524. * For fast retransmissions we also send only ONE packet. However,
  525. * if we are just flushing the queue due to open window, we'll
  526. * try to send as much as possible.
  527. */
  528. list_for_each_entry_safe(chunk, chunk1, lqueue, transmitted_list) {
  529. /* Make sure that Gap Acked TSNs are not retransmitted. A
  530. * simple approach is just to move such TSNs out of the
  531. * way and into a 'transmitted' queue and skip to the
  532. * next chunk.
  533. */
  534. if (chunk->tsn_gap_acked) {
  535. list_del(&chunk->transmitted_list);
  536. list_add_tail(&chunk->transmitted_list,
  537. &transport->transmitted);
  538. continue;
  539. }
  540. /* If we are doing fast retransmit, ignore non-fast_rtransmit
  541. * chunks
  542. */
  543. if (fast_rtx && !chunk->fast_retransmit)
  544. continue;
  545. /* Attempt to append this chunk to the packet. */
  546. status = sctp_packet_append_chunk(pkt, chunk);
  547. switch (status) {
  548. case SCTP_XMIT_PMTU_FULL:
  549. /* Send this packet. */
  550. error = sctp_packet_transmit(pkt);
  551. /* If we are retransmitting, we should only
  552. * send a single packet.
  553. */
  554. if (rtx_timeout || fast_rtx)
  555. done = 1;
  556. /* Bundle next chunk in the next round. */
  557. break;
  558. case SCTP_XMIT_RWND_FULL:
  559. /* Send this packet. */
  560. error = sctp_packet_transmit(pkt);
  561. /* Stop sending DATA as there is no more room
  562. * at the receiver.
  563. */
  564. done = 1;
  565. break;
  566. case SCTP_XMIT_NAGLE_DELAY:
  567. /* Send this packet. */
  568. error = sctp_packet_transmit(pkt);
  569. /* Stop sending DATA because of nagle delay. */
  570. done = 1;
  571. break;
  572. default:
  573. /* The append was successful, so add this chunk to
  574. * the transmitted list.
  575. */
  576. list_del(&chunk->transmitted_list);
  577. list_add_tail(&chunk->transmitted_list,
  578. &transport->transmitted);
  579. /* Mark the chunk as ineligible for fast retransmit
  580. * after it is retransmitted.
  581. */
  582. if (chunk->fast_retransmit == SCTP_NEED_FRTX)
  583. chunk->fast_retransmit = SCTP_DONT_FRTX;
  584. /* Force start T3-rtx timer when fast retransmitting
  585. * the earliest outstanding TSN
  586. */
  587. if (!timer && fast_rtx &&
  588. ntohl(chunk->subh.data_hdr->tsn) ==
  589. asoc->ctsn_ack_point + 1)
  590. timer = 2;
  591. q->empty = 0;
  592. break;
  593. }
  594. /* Set the timer if there were no errors */
  595. if (!error && !timer)
  596. timer = 1;
  597. if (done)
  598. break;
  599. }
  600. /* If we are here due to a retransmit timeout or a fast
  601. * retransmit and if there are any chunks left in the retransmit
  602. * queue that could not fit in the PMTU sized packet, they need
  603. * to be marked as ineligible for a subsequent fast retransmit.
  604. */
  605. if (rtx_timeout || fast_rtx) {
  606. list_for_each_entry(chunk1, lqueue, transmitted_list) {
  607. if (chunk1->fast_retransmit == SCTP_NEED_FRTX)
  608. chunk1->fast_retransmit = SCTP_DONT_FRTX;
  609. }
  610. }
  611. *start_timer = timer;
  612. /* Clear fast retransmit hint */
  613. if (fast_rtx)
  614. q->fast_rtx = 0;
  615. return error;
  616. }
  617. /* Cork the outqueue so queued chunks are really queued. */
  618. int sctp_outq_uncork(struct sctp_outq *q)
  619. {
  620. int error = 0;
  621. if (q->cork)
  622. q->cork = 0;
  623. error = sctp_outq_flush(q, 0);
  624. return error;
  625. }
  626. /*
  627. * Try to flush an outqueue.
  628. *
  629. * Description: Send everything in q which we legally can, subject to
  630. * congestion limitations.
  631. * * Note: This function can be called from multiple contexts so appropriate
  632. * locking concerns must be made. Today we use the sock lock to protect
  633. * this function.
  634. */
  635. static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
  636. {
  637. struct sctp_packet *packet;
  638. struct sctp_packet singleton;
  639. struct sctp_association *asoc = q->asoc;
  640. __u16 sport = asoc->base.bind_addr.port;
  641. __u16 dport = asoc->peer.port;
  642. __u32 vtag = asoc->peer.i.init_tag;
  643. struct sctp_transport *transport = NULL;
  644. struct sctp_transport *new_transport;
  645. struct sctp_chunk *chunk, *tmp;
  646. sctp_xmit_t status;
  647. int error = 0;
  648. int start_timer = 0;
  649. int one_packet = 0;
  650. /* These transports have chunks to send. */
  651. struct list_head transport_list;
  652. struct list_head *ltransport;
  653. INIT_LIST_HEAD(&transport_list);
  654. packet = NULL;
  655. /*
  656. * 6.10 Bundling
  657. * ...
  658. * When bundling control chunks with DATA chunks, an
  659. * endpoint MUST place control chunks first in the outbound
  660. * SCTP packet. The transmitter MUST transmit DATA chunks
  661. * within a SCTP packet in increasing order of TSN.
  662. * ...
  663. */
  664. list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) {
  665. list_del_init(&chunk->list);
  666. /* Pick the right transport to use. */
  667. new_transport = chunk->transport;
  668. if (!new_transport) {
  669. /*
  670. * If we have a prior transport pointer, see if
  671. * the destination address of the chunk
  672. * matches the destination address of the
  673. * current transport. If not a match, then
  674. * try to look up the transport with a given
  675. * destination address. We do this because
  676. * after processing ASCONFs, we may have new
  677. * transports created.
  678. */
  679. if (transport &&
  680. sctp_cmp_addr_exact(&chunk->dest,
  681. &transport->ipaddr))
  682. new_transport = transport;
  683. else
  684. new_transport = sctp_assoc_lookup_paddr(asoc,
  685. &chunk->dest);
  686. /* if we still don't have a new transport, then
  687. * use the current active path.
  688. */
  689. if (!new_transport)
  690. new_transport = asoc->peer.active_path;
  691. } else if ((new_transport->state == SCTP_INACTIVE) ||
  692. (new_transport->state == SCTP_UNCONFIRMED)) {
  693. /* If the chunk is Heartbeat or Heartbeat Ack,
  694. * send it to chunk->transport, even if it's
  695. * inactive.
  696. *
  697. * 3.3.6 Heartbeat Acknowledgement:
  698. * ...
  699. * A HEARTBEAT ACK is always sent to the source IP
  700. * address of the IP datagram containing the
  701. * HEARTBEAT chunk to which this ack is responding.
  702. * ...
  703. *
  704. * ASCONF_ACKs also must be sent to the source.
  705. */
  706. if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT &&
  707. chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT_ACK &&
  708. chunk->chunk_hdr->type != SCTP_CID_ASCONF_ACK)
  709. new_transport = asoc->peer.active_path;
  710. }
  711. /* Are we switching transports?
  712. * Take care of transport locks.
  713. */
  714. if (new_transport != transport) {
  715. transport = new_transport;
  716. if (list_empty(&transport->send_ready)) {
  717. list_add_tail(&transport->send_ready,
  718. &transport_list);
  719. }
  720. packet = &transport->packet;
  721. sctp_packet_config(packet, vtag,
  722. asoc->peer.ecn_capable);
  723. }
  724. switch (chunk->chunk_hdr->type) {
  725. /*
  726. * 6.10 Bundling
  727. * ...
  728. * An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
  729. * COMPLETE with any other chunks. [Send them immediately.]
  730. */
  731. case SCTP_CID_INIT:
  732. case SCTP_CID_INIT_ACK:
  733. case SCTP_CID_SHUTDOWN_COMPLETE:
  734. sctp_packet_init(&singleton, transport, sport, dport);
  735. sctp_packet_config(&singleton, vtag, 0);
  736. sctp_packet_append_chunk(&singleton, chunk);
  737. error = sctp_packet_transmit(&singleton);
  738. if (error < 0)
  739. return error;
  740. break;
  741. case SCTP_CID_ABORT:
  742. if (sctp_test_T_bit(chunk)) {
  743. packet->vtag = asoc->c.my_vtag;
  744. }
  745. /* The following chunks are "response" chunks, i.e.
  746. * they are generated in response to something we
  747. * received. If we are sending these, then we can
  748. * send only 1 packet containing these chunks.
  749. */
  750. case SCTP_CID_HEARTBEAT_ACK:
  751. case SCTP_CID_SHUTDOWN_ACK:
  752. case SCTP_CID_COOKIE_ACK:
  753. case SCTP_CID_COOKIE_ECHO:
  754. case SCTP_CID_ERROR:
  755. case SCTP_CID_ECN_CWR:
  756. case SCTP_CID_ASCONF_ACK:
  757. one_packet = 1;
  758. /* Fall throught */
  759. case SCTP_CID_SACK:
  760. case SCTP_CID_HEARTBEAT:
  761. case SCTP_CID_SHUTDOWN:
  762. case SCTP_CID_ECN_ECNE:
  763. case SCTP_CID_ASCONF:
  764. case SCTP_CID_FWD_TSN:
  765. status = sctp_packet_transmit_chunk(packet, chunk,
  766. one_packet);
  767. if (status != SCTP_XMIT_OK) {
  768. /* put the chunk back */
  769. list_add(&chunk->list, &q->control_chunk_list);
  770. }
  771. break;
  772. default:
  773. /* We built a chunk with an illegal type! */
  774. BUG();
  775. }
  776. }
  777. /* Is it OK to send data chunks? */
  778. switch (asoc->state) {
  779. case SCTP_STATE_COOKIE_ECHOED:
  780. /* Only allow bundling when this packet has a COOKIE-ECHO
  781. * chunk.
  782. */
  783. if (!packet || !packet->has_cookie_echo)
  784. break;
  785. /* fallthru */
  786. case SCTP_STATE_ESTABLISHED:
  787. case SCTP_STATE_SHUTDOWN_PENDING:
  788. case SCTP_STATE_SHUTDOWN_RECEIVED:
  789. /*
  790. * RFC 2960 6.1 Transmission of DATA Chunks
  791. *
  792. * C) When the time comes for the sender to transmit,
  793. * before sending new DATA chunks, the sender MUST
  794. * first transmit any outstanding DATA chunks which
  795. * are marked for retransmission (limited by the
  796. * current cwnd).
  797. */
  798. if (!list_empty(&q->retransmit)) {
  799. if (transport == asoc->peer.retran_path)
  800. goto retran;
  801. /* Switch transports & prepare the packet. */
  802. transport = asoc->peer.retran_path;
  803. if (list_empty(&transport->send_ready)) {
  804. list_add_tail(&transport->send_ready,
  805. &transport_list);
  806. }
  807. packet = &transport->packet;
  808. sctp_packet_config(packet, vtag,
  809. asoc->peer.ecn_capable);
  810. retran:
  811. error = sctp_outq_flush_rtx(q, packet,
  812. rtx_timeout, &start_timer);
  813. if (start_timer)
  814. sctp_transport_reset_timers(transport,
  815. start_timer-1);
  816. /* This can happen on COOKIE-ECHO resend. Only
  817. * one chunk can get bundled with a COOKIE-ECHO.
  818. */
  819. if (packet->has_cookie_echo)
  820. goto sctp_flush_out;
  821. /* Don't send new data if there is still data
  822. * waiting to retransmit.
  823. */
  824. if (!list_empty(&q->retransmit))
  825. goto sctp_flush_out;
  826. }
  827. /* Finally, transmit new packets. */
  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, 0);
  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. int gap_ack_blocks;
  998. /* Grab the association's destination address list. */
  999. transport_list = &asoc->peer.transport_addr_list;
  1000. sack_ctsn = ntohl(sack->cum_tsn_ack);
  1001. gap_ack_blocks = ntohs(sack->num_gap_ack_blocks);
  1002. /*
  1003. * SFR-CACC algorithm:
  1004. * On receipt of a SACK the sender SHOULD execute the
  1005. * following statements.
  1006. *
  1007. * 1) If the cumulative ack in the SACK passes next tsn_at_change
  1008. * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
  1009. * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
  1010. * all destinations.
  1011. * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
  1012. * is set the receiver of the SACK MUST take the following actions:
  1013. *
  1014. * A) Initialize the cacc_saw_newack to 0 for all destination
  1015. * addresses.
  1016. *
  1017. * Only bother if changeover_active is set. Otherwise, this is
  1018. * totally suboptimal to do on every SACK.
  1019. */
  1020. if (primary->cacc.changeover_active) {
  1021. u8 clear_cycling = 0;
  1022. if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
  1023. primary->cacc.changeover_active = 0;
  1024. clear_cycling = 1;
  1025. }
  1026. if (clear_cycling || gap_ack_blocks) {
  1027. list_for_each_entry(transport, transport_list,
  1028. transports) {
  1029. if (clear_cycling)
  1030. transport->cacc.cycling_changeover = 0;
  1031. if (gap_ack_blocks)
  1032. transport->cacc.cacc_saw_newack = 0;
  1033. }
  1034. }
  1035. }
  1036. /* Get the highest TSN in the sack. */
  1037. highest_tsn = sack_ctsn;
  1038. if (gap_ack_blocks)
  1039. highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);
  1040. if (TSN_lt(asoc->highest_sacked, highest_tsn)) {
  1041. highest_new_tsn = highest_tsn;
  1042. asoc->highest_sacked = highest_tsn;
  1043. } else {
  1044. highest_new_tsn = sctp_highest_new_tsn(sack, asoc);
  1045. }
  1046. /* Run through the retransmit queue. Credit bytes received
  1047. * and free those chunks that we can.
  1048. */
  1049. sctp_check_transmitted(q, &q->retransmit, NULL, sack, highest_new_tsn);
  1050. /* Run through the transmitted queue.
  1051. * Credit bytes received and free those chunks which we can.
  1052. *
  1053. * This is a MASSIVE candidate for optimization.
  1054. */
  1055. list_for_each_entry(transport, transport_list, transports) {
  1056. sctp_check_transmitted(q, &transport->transmitted,
  1057. transport, sack, highest_new_tsn);
  1058. /*
  1059. * SFR-CACC algorithm:
  1060. * C) Let count_of_newacks be the number of
  1061. * destinations for which cacc_saw_newack is set.
  1062. */
  1063. if (transport->cacc.cacc_saw_newack)
  1064. count_of_newacks ++;
  1065. }
  1066. if (gap_ack_blocks) {
  1067. list_for_each_entry(transport, transport_list, transports)
  1068. sctp_mark_missing(q, &transport->transmitted, transport,
  1069. highest_new_tsn, count_of_newacks);
  1070. }
  1071. /* Move the Cumulative TSN Ack Point if appropriate. */
  1072. if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn))
  1073. asoc->ctsn_ack_point = sack_ctsn;
  1074. /* Update unack_data field in the assoc. */
  1075. sctp_sack_update_unack_data(asoc, sack);
  1076. ctsn = asoc->ctsn_ack_point;
  1077. /* Throw away stuff rotting on the sack queue. */
  1078. list_for_each_safe(lchunk, temp, &q->sacked) {
  1079. tchunk = list_entry(lchunk, struct sctp_chunk,
  1080. transmitted_list);
  1081. tsn = ntohl(tchunk->subh.data_hdr->tsn);
  1082. if (TSN_lte(tsn, ctsn)) {
  1083. list_del_init(&tchunk->transmitted_list);
  1084. sctp_chunk_free(tchunk);
  1085. }
  1086. }
  1087. /* ii) Set rwnd equal to the newly received a_rwnd minus the
  1088. * number of bytes still outstanding after processing the
  1089. * Cumulative TSN Ack and the Gap Ack Blocks.
  1090. */
  1091. sack_a_rwnd = ntohl(sack->a_rwnd);
  1092. outstanding = q->outstanding_bytes;
  1093. if (outstanding < sack_a_rwnd)
  1094. sack_a_rwnd -= outstanding;
  1095. else
  1096. sack_a_rwnd = 0;
  1097. asoc->peer.rwnd = sack_a_rwnd;
  1098. sctp_generate_fwdtsn(q, sack_ctsn);
  1099. SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
  1100. __func__, sack_ctsn);
  1101. SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association, "
  1102. "%p is 0x%x. Adv peer ack point: 0x%x\n",
  1103. __func__, asoc, ctsn, asoc->adv_peer_ack_point);
  1104. /* See if all chunks are acked.
  1105. * Make sure the empty queue handler will get run later.
  1106. */
  1107. q->empty = (list_empty(&q->out_chunk_list) &&
  1108. list_empty(&q->retransmit));
  1109. if (!q->empty)
  1110. goto finish;
  1111. list_for_each_entry(transport, transport_list, transports) {
  1112. q->empty = q->empty && list_empty(&transport->transmitted);
  1113. if (!q->empty)
  1114. goto finish;
  1115. }
  1116. SCTP_DEBUG_PRINTK("sack queue is empty.\n");
  1117. finish:
  1118. return q->empty;
  1119. }
  1120. /* Is the outqueue empty? */
  1121. int sctp_outq_is_empty(const struct sctp_outq *q)
  1122. {
  1123. return q->empty;
  1124. }
  1125. /********************************************************************
  1126. * 2nd Level Abstractions
  1127. ********************************************************************/
  1128. /* Go through a transport's transmitted list or the association's retransmit
  1129. * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
  1130. * The retransmit list will not have an associated transport.
  1131. *
  1132. * I added coherent debug information output. --xguo
  1133. *
  1134. * Instead of printing 'sacked' or 'kept' for each TSN on the
  1135. * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
  1136. * KEPT TSN6-TSN7, etc.
  1137. */
  1138. static void sctp_check_transmitted(struct sctp_outq *q,
  1139. struct list_head *transmitted_queue,
  1140. struct sctp_transport *transport,
  1141. struct sctp_sackhdr *sack,
  1142. __u32 highest_new_tsn_in_sack)
  1143. {
  1144. struct list_head *lchunk;
  1145. struct sctp_chunk *tchunk;
  1146. struct list_head tlist;
  1147. __u32 tsn;
  1148. __u32 sack_ctsn;
  1149. __u32 rtt;
  1150. __u8 restart_timer = 0;
  1151. int bytes_acked = 0;
  1152. /* These state variables are for coherent debug output. --xguo */
  1153. #if SCTP_DEBUG
  1154. __u32 dbg_ack_tsn = 0; /* An ACKed TSN range starts here... */
  1155. __u32 dbg_last_ack_tsn = 0; /* ...and finishes here. */
  1156. __u32 dbg_kept_tsn = 0; /* An un-ACKed range starts here... */
  1157. __u32 dbg_last_kept_tsn = 0; /* ...and finishes here. */
  1158. /* 0 : The last TSN was ACKed.
  1159. * 1 : The last TSN was NOT ACKed (i.e. KEPT).
  1160. * -1: We need to initialize.
  1161. */
  1162. int dbg_prt_state = -1;
  1163. #endif /* SCTP_DEBUG */
  1164. sack_ctsn = ntohl(sack->cum_tsn_ack);
  1165. INIT_LIST_HEAD(&tlist);
  1166. /* The while loop will skip empty transmitted queues. */
  1167. while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
  1168. tchunk = list_entry(lchunk, struct sctp_chunk,
  1169. transmitted_list);
  1170. if (sctp_chunk_abandoned(tchunk)) {
  1171. /* Move the chunk to abandoned list. */
  1172. sctp_insert_list(&q->abandoned, lchunk);
  1173. /* If this chunk has not been acked, stop
  1174. * considering it as 'outstanding'.
  1175. */
  1176. if (!tchunk->tsn_gap_acked) {
  1177. tchunk->transport->flight_size -=
  1178. sctp_data_size(tchunk);
  1179. q->outstanding_bytes -= sctp_data_size(tchunk);
  1180. }
  1181. continue;
  1182. }
  1183. tsn = ntohl(tchunk->subh.data_hdr->tsn);
  1184. if (sctp_acked(sack, tsn)) {
  1185. /* If this queue is the retransmit queue, the
  1186. * retransmit timer has already reclaimed
  1187. * the outstanding bytes for this chunk, so only
  1188. * count bytes associated with a transport.
  1189. */
  1190. if (transport) {
  1191. /* If this chunk is being used for RTT
  1192. * measurement, calculate the RTT and update
  1193. * the RTO using this value.
  1194. *
  1195. * 6.3.1 C5) Karn's algorithm: RTT measurements
  1196. * MUST NOT be made using packets that were
  1197. * retransmitted (and thus for which it is
  1198. * ambiguous whether the reply was for the
  1199. * first instance of the packet or a later
  1200. * instance).
  1201. */
  1202. if (!tchunk->tsn_gap_acked &&
  1203. !tchunk->resent &&
  1204. tchunk->rtt_in_progress) {
  1205. tchunk->rtt_in_progress = 0;
  1206. rtt = jiffies - tchunk->sent_at;
  1207. sctp_transport_update_rto(transport,
  1208. rtt);
  1209. }
  1210. }
  1211. if (TSN_lte(tsn, sack_ctsn)) {
  1212. /* RFC 2960 6.3.2 Retransmission Timer Rules
  1213. *
  1214. * R3) Whenever a SACK is received
  1215. * that acknowledges the DATA chunk
  1216. * with the earliest outstanding TSN
  1217. * for that address, restart T3-rtx
  1218. * timer for that address with its
  1219. * current RTO.
  1220. */
  1221. restart_timer = 1;
  1222. if (!tchunk->tsn_gap_acked) {
  1223. tchunk->tsn_gap_acked = 1;
  1224. bytes_acked += sctp_data_size(tchunk);
  1225. /*
  1226. * SFR-CACC algorithm:
  1227. * 2) If the SACK contains gap acks
  1228. * and the flag CHANGEOVER_ACTIVE is
  1229. * set the receiver of the SACK MUST
  1230. * take the following action:
  1231. *
  1232. * B) For each TSN t being acked that
  1233. * has not been acked in any SACK so
  1234. * far, set cacc_saw_newack to 1 for
  1235. * the destination that the TSN was
  1236. * sent to.
  1237. */
  1238. if (transport &&
  1239. sack->num_gap_ack_blocks &&
  1240. q->asoc->peer.primary_path->cacc.
  1241. changeover_active)
  1242. transport->cacc.cacc_saw_newack
  1243. = 1;
  1244. }
  1245. list_add_tail(&tchunk->transmitted_list,
  1246. &q->sacked);
  1247. } else {
  1248. /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
  1249. * M2) Each time a SACK arrives reporting
  1250. * 'Stray DATA chunk(s)' record the highest TSN
  1251. * reported as newly acknowledged, call this
  1252. * value 'HighestTSNinSack'. A newly
  1253. * acknowledged DATA chunk is one not
  1254. * previously acknowledged in a SACK.
  1255. *
  1256. * When the SCTP sender of data receives a SACK
  1257. * chunk that acknowledges, for the first time,
  1258. * the receipt of a DATA chunk, all the still
  1259. * unacknowledged DATA chunks whose TSN is
  1260. * older than that newly acknowledged DATA
  1261. * chunk, are qualified as 'Stray DATA chunks'.
  1262. */
  1263. if (!tchunk->tsn_gap_acked) {
  1264. tchunk->tsn_gap_acked = 1;
  1265. bytes_acked += sctp_data_size(tchunk);
  1266. }
  1267. list_add_tail(lchunk, &tlist);
  1268. }
  1269. #if SCTP_DEBUG
  1270. switch (dbg_prt_state) {
  1271. case 0: /* last TSN was ACKed */
  1272. if (dbg_last_ack_tsn + 1 == tsn) {
  1273. /* This TSN belongs to the
  1274. * current ACK range.
  1275. */
  1276. break;
  1277. }
  1278. if (dbg_last_ack_tsn != dbg_ack_tsn) {
  1279. /* Display the end of the
  1280. * current range.
  1281. */
  1282. SCTP_DEBUG_PRINTK("-%08x",
  1283. dbg_last_ack_tsn);
  1284. }
  1285. /* Start a new range. */
  1286. SCTP_DEBUG_PRINTK(",%08x", tsn);
  1287. dbg_ack_tsn = tsn;
  1288. break;
  1289. case 1: /* The last TSN was NOT ACKed. */
  1290. if (dbg_last_kept_tsn != dbg_kept_tsn) {
  1291. /* Display the end of current range. */
  1292. SCTP_DEBUG_PRINTK("-%08x",
  1293. dbg_last_kept_tsn);
  1294. }
  1295. SCTP_DEBUG_PRINTK("\n");
  1296. /* FALL THROUGH... */
  1297. default:
  1298. /* This is the first-ever TSN we examined. */
  1299. /* Start a new range of ACK-ed TSNs. */
  1300. SCTP_DEBUG_PRINTK("ACKed: %08x", tsn);
  1301. dbg_prt_state = 0;
  1302. dbg_ack_tsn = tsn;
  1303. }
  1304. dbg_last_ack_tsn = tsn;
  1305. #endif /* SCTP_DEBUG */
  1306. } else {
  1307. if (tchunk->tsn_gap_acked) {
  1308. SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
  1309. "data TSN: 0x%x\n",
  1310. __func__,
  1311. tsn);
  1312. tchunk->tsn_gap_acked = 0;
  1313. bytes_acked -= sctp_data_size(tchunk);
  1314. /* RFC 2960 6.3.2 Retransmission Timer Rules
  1315. *
  1316. * R4) Whenever a SACK is received missing a
  1317. * TSN that was previously acknowledged via a
  1318. * Gap Ack Block, start T3-rtx for the
  1319. * destination address to which the DATA
  1320. * chunk was originally
  1321. * transmitted if it is not already running.
  1322. */
  1323. restart_timer = 1;
  1324. }
  1325. list_add_tail(lchunk, &tlist);
  1326. #if SCTP_DEBUG
  1327. /* See the above comments on ACK-ed TSNs. */
  1328. switch (dbg_prt_state) {
  1329. case 1:
  1330. if (dbg_last_kept_tsn + 1 == tsn)
  1331. break;
  1332. if (dbg_last_kept_tsn != dbg_kept_tsn)
  1333. SCTP_DEBUG_PRINTK("-%08x",
  1334. dbg_last_kept_tsn);
  1335. SCTP_DEBUG_PRINTK(",%08x", tsn);
  1336. dbg_kept_tsn = tsn;
  1337. break;
  1338. case 0:
  1339. if (dbg_last_ack_tsn != dbg_ack_tsn)
  1340. SCTP_DEBUG_PRINTK("-%08x",
  1341. dbg_last_ack_tsn);
  1342. SCTP_DEBUG_PRINTK("\n");
  1343. /* FALL THROUGH... */
  1344. default:
  1345. SCTP_DEBUG_PRINTK("KEPT: %08x",tsn);
  1346. dbg_prt_state = 1;
  1347. dbg_kept_tsn = tsn;
  1348. }
  1349. dbg_last_kept_tsn = tsn;
  1350. #endif /* SCTP_DEBUG */
  1351. }
  1352. }
  1353. #if SCTP_DEBUG
  1354. /* Finish off the last range, displaying its ending TSN. */
  1355. switch (dbg_prt_state) {
  1356. case 0:
  1357. if (dbg_last_ack_tsn != dbg_ack_tsn) {
  1358. SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_ack_tsn);
  1359. } else {
  1360. SCTP_DEBUG_PRINTK("\n");
  1361. }
  1362. break;
  1363. case 1:
  1364. if (dbg_last_kept_tsn != dbg_kept_tsn) {
  1365. SCTP_DEBUG_PRINTK("-%08x\n", dbg_last_kept_tsn);
  1366. } else {
  1367. SCTP_DEBUG_PRINTK("\n");
  1368. }
  1369. }
  1370. #endif /* SCTP_DEBUG */
  1371. if (transport) {
  1372. if (bytes_acked) {
  1373. /* 8.2. When an outstanding TSN is acknowledged,
  1374. * the endpoint shall clear the error counter of
  1375. * the destination transport address to which the
  1376. * DATA chunk was last sent.
  1377. * The association's overall error counter is
  1378. * also cleared.
  1379. */
  1380. transport->error_count = 0;
  1381. transport->asoc->overall_error_count = 0;
  1382. /* Mark the destination transport address as
  1383. * active if it is not so marked.
  1384. */
  1385. if ((transport->state == SCTP_INACTIVE) ||
  1386. (transport->state == SCTP_UNCONFIRMED)) {
  1387. sctp_assoc_control_transport(
  1388. transport->asoc,
  1389. transport,
  1390. SCTP_TRANSPORT_UP,
  1391. SCTP_RECEIVED_SACK);
  1392. }
  1393. sctp_transport_raise_cwnd(transport, sack_ctsn,
  1394. bytes_acked);
  1395. transport->flight_size -= bytes_acked;
  1396. if (transport->flight_size == 0)
  1397. transport->partial_bytes_acked = 0;
  1398. q->outstanding_bytes -= bytes_acked;
  1399. } else {
  1400. /* RFC 2960 6.1, sctpimpguide-06 2.15.2
  1401. * When a sender is doing zero window probing, it
  1402. * should not timeout the association if it continues
  1403. * to receive new packets from the receiver. The
  1404. * reason is that the receiver MAY keep its window
  1405. * closed for an indefinite time.
  1406. * A sender is doing zero window probing when the
  1407. * receiver's advertised window is zero, and there is
  1408. * only one data chunk in flight to the receiver.
  1409. */
  1410. if (!q->asoc->peer.rwnd &&
  1411. !list_empty(&tlist) &&
  1412. (sack_ctsn+2 == q->asoc->next_tsn)) {
  1413. SCTP_DEBUG_PRINTK("%s: SACK received for zero "
  1414. "window probe: %u\n",
  1415. __func__, sack_ctsn);
  1416. q->asoc->overall_error_count = 0;
  1417. transport->error_count = 0;
  1418. }
  1419. }
  1420. /* RFC 2960 6.3.2 Retransmission Timer Rules
  1421. *
  1422. * R2) Whenever all outstanding data sent to an address have
  1423. * been acknowledged, turn off the T3-rtx timer of that
  1424. * address.
  1425. */
  1426. if (!transport->flight_size) {
  1427. if (timer_pending(&transport->T3_rtx_timer) &&
  1428. del_timer(&transport->T3_rtx_timer)) {
  1429. sctp_transport_put(transport);
  1430. }
  1431. } else if (restart_timer) {
  1432. if (!mod_timer(&transport->T3_rtx_timer,
  1433. jiffies + transport->rto))
  1434. sctp_transport_hold(transport);
  1435. }
  1436. }
  1437. list_splice(&tlist, transmitted_queue);
  1438. }
  1439. /* Mark chunks as missing and consequently may get retransmitted. */
  1440. static void sctp_mark_missing(struct sctp_outq *q,
  1441. struct list_head *transmitted_queue,
  1442. struct sctp_transport *transport,
  1443. __u32 highest_new_tsn_in_sack,
  1444. int count_of_newacks)
  1445. {
  1446. struct sctp_chunk *chunk;
  1447. __u32 tsn;
  1448. char do_fast_retransmit = 0;
  1449. struct sctp_transport *primary = q->asoc->peer.primary_path;
  1450. list_for_each_entry(chunk, transmitted_queue, transmitted_list) {
  1451. tsn = ntohl(chunk->subh.data_hdr->tsn);
  1452. /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
  1453. * 'Unacknowledged TSN's', if the TSN number of an
  1454. * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
  1455. * value, increment the 'TSN.Missing.Report' count on that
  1456. * chunk if it has NOT been fast retransmitted or marked for
  1457. * fast retransmit already.
  1458. */
  1459. if (chunk->fast_retransmit == SCTP_CAN_FRTX &&
  1460. !chunk->tsn_gap_acked &&
  1461. TSN_lt(tsn, highest_new_tsn_in_sack)) {
  1462. /* SFR-CACC may require us to skip marking
  1463. * this chunk as missing.
  1464. */
  1465. if (!transport || !sctp_cacc_skip(primary, transport,
  1466. count_of_newacks, tsn)) {
  1467. chunk->tsn_missing_report++;
  1468. SCTP_DEBUG_PRINTK(
  1469. "%s: TSN 0x%x missing counter: %d\n",
  1470. __func__, tsn,
  1471. chunk->tsn_missing_report);
  1472. }
  1473. }
  1474. /*
  1475. * M4) If any DATA chunk is found to have a
  1476. * 'TSN.Missing.Report'
  1477. * value larger than or equal to 3, mark that chunk for
  1478. * retransmission and start the fast retransmit procedure.
  1479. */
  1480. if (chunk->tsn_missing_report >= 3) {
  1481. chunk->fast_retransmit = SCTP_NEED_FRTX;
  1482. do_fast_retransmit = 1;
  1483. }
  1484. }
  1485. if (transport) {
  1486. if (do_fast_retransmit)
  1487. sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
  1488. SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
  1489. "ssthresh: %d, flight_size: %d, pba: %d\n",
  1490. __func__, transport, transport->cwnd,
  1491. transport->ssthresh, transport->flight_size,
  1492. transport->partial_bytes_acked);
  1493. }
  1494. }
  1495. /* Is the given TSN acked by this packet? */
  1496. static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
  1497. {
  1498. int i;
  1499. sctp_sack_variable_t *frags;
  1500. __u16 gap;
  1501. __u32 ctsn = ntohl(sack->cum_tsn_ack);
  1502. if (TSN_lte(tsn, ctsn))
  1503. goto pass;
  1504. /* 3.3.4 Selective Acknowledgement (SACK) (3):
  1505. *
  1506. * Gap Ack Blocks:
  1507. * These fields contain the Gap Ack Blocks. They are repeated
  1508. * for each Gap Ack Block up to the number of Gap Ack Blocks
  1509. * defined in the Number of Gap Ack Blocks field. All DATA
  1510. * chunks with TSNs greater than or equal to (Cumulative TSN
  1511. * Ack + Gap Ack Block Start) and less than or equal to
  1512. * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
  1513. * Block are assumed to have been received correctly.
  1514. */
  1515. frags = sack->variable;
  1516. gap = tsn - ctsn;
  1517. for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
  1518. if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
  1519. TSN_lte(gap, ntohs(frags[i].gab.end)))
  1520. goto pass;
  1521. }
  1522. return 0;
  1523. pass:
  1524. return 1;
  1525. }
  1526. static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist,
  1527. int nskips, __be16 stream)
  1528. {
  1529. int i;
  1530. for (i = 0; i < nskips; i++) {
  1531. if (skiplist[i].stream == stream)
  1532. return i;
  1533. }
  1534. return i;
  1535. }
  1536. /* Create and add a fwdtsn chunk to the outq's control queue if needed. */
  1537. static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
  1538. {
  1539. struct sctp_association *asoc = q->asoc;
  1540. struct sctp_chunk *ftsn_chunk = NULL;
  1541. struct sctp_fwdtsn_skip ftsn_skip_arr[10];
  1542. int nskips = 0;
  1543. int skip_pos = 0;
  1544. __u32 tsn;
  1545. struct sctp_chunk *chunk;
  1546. struct list_head *lchunk, *temp;
  1547. if (!asoc->peer.prsctp_capable)
  1548. return;
  1549. /* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the
  1550. * received SACK.
  1551. *
  1552. * If (Advanced.Peer.Ack.Point < SackCumAck), then update
  1553. * Advanced.Peer.Ack.Point to be equal to SackCumAck.
  1554. */
  1555. if (TSN_lt(asoc->adv_peer_ack_point, ctsn))
  1556. asoc->adv_peer_ack_point = ctsn;
  1557. /* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point"
  1558. * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as
  1559. * the chunk next in the out-queue space is marked as "abandoned" as
  1560. * shown in the following example:
  1561. *
  1562. * Assuming that a SACK arrived with the Cumulative TSN ACK 102
  1563. * and the Advanced.Peer.Ack.Point is updated to this value:
  1564. *
  1565. * out-queue at the end of ==> out-queue after Adv.Ack.Point
  1566. * normal SACK processing local advancement
  1567. * ... ...
  1568. * Adv.Ack.Pt-> 102 acked 102 acked
  1569. * 103 abandoned 103 abandoned
  1570. * 104 abandoned Adv.Ack.P-> 104 abandoned
  1571. * 105 105
  1572. * 106 acked 106 acked
  1573. * ... ...
  1574. *
  1575. * In this example, the data sender successfully advanced the
  1576. * "Advanced.Peer.Ack.Point" from 102 to 104 locally.
  1577. */
  1578. list_for_each_safe(lchunk, temp, &q->abandoned) {
  1579. chunk = list_entry(lchunk, struct sctp_chunk,
  1580. transmitted_list);
  1581. tsn = ntohl(chunk->subh.data_hdr->tsn);
  1582. /* Remove any chunks in the abandoned queue that are acked by
  1583. * the ctsn.
  1584. */
  1585. if (TSN_lte(tsn, ctsn)) {
  1586. list_del_init(lchunk);
  1587. sctp_chunk_free(chunk);
  1588. } else {
  1589. if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
  1590. asoc->adv_peer_ack_point = tsn;
  1591. if (chunk->chunk_hdr->flags &
  1592. SCTP_DATA_UNORDERED)
  1593. continue;
  1594. skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0],
  1595. nskips,
  1596. chunk->subh.data_hdr->stream);
  1597. ftsn_skip_arr[skip_pos].stream =
  1598. chunk->subh.data_hdr->stream;
  1599. ftsn_skip_arr[skip_pos].ssn =
  1600. chunk->subh.data_hdr->ssn;
  1601. if (skip_pos == nskips)
  1602. nskips++;
  1603. if (nskips == 10)
  1604. break;
  1605. } else
  1606. break;
  1607. }
  1608. }
  1609. /* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point"
  1610. * is greater than the Cumulative TSN ACK carried in the received
  1611. * SACK, the data sender MUST send the data receiver a FORWARD TSN
  1612. * chunk containing the latest value of the
  1613. * "Advanced.Peer.Ack.Point".
  1614. *
  1615. * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD
  1616. * list each stream and sequence number in the forwarded TSN. This
  1617. * information will enable the receiver to easily find any
  1618. * stranded TSN's waiting on stream reorder queues. Each stream
  1619. * SHOULD only be reported once; this means that if multiple
  1620. * abandoned messages occur in the same stream then only the
  1621. * highest abandoned stream sequence number is reported. If the
  1622. * total size of the FORWARD TSN does NOT fit in a single MTU then
  1623. * the sender of the FORWARD TSN SHOULD lower the
  1624. * Advanced.Peer.Ack.Point to the last TSN that will fit in a
  1625. * single MTU.
  1626. */
  1627. if (asoc->adv_peer_ack_point > ctsn)
  1628. ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point,
  1629. nskips, &ftsn_skip_arr[0]);
  1630. if (ftsn_chunk) {
  1631. list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
  1632. SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
  1633. }
  1634. }