outqueue.c 52 KB

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