outqueue.c 52 KB

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