outqueue.c 54 KB

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