outqueue.c 53 KB

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