outqueue.c 52 KB

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