outqueue.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798
  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_t3_rtx(transport);
  777. transport->last_time_sent = jiffies;
  778. }
  779. }
  780. break;
  781. default:
  782. /* We built a chunk with an illegal type! */
  783. BUG();
  784. }
  785. }
  786. if (q->asoc->src_out_of_asoc_ok)
  787. goto sctp_flush_out;
  788. /* Is it OK to send data chunks? */
  789. switch (asoc->state) {
  790. case SCTP_STATE_COOKIE_ECHOED:
  791. /* Only allow bundling when this packet has a COOKIE-ECHO
  792. * chunk.
  793. */
  794. if (!packet || !packet->has_cookie_echo)
  795. break;
  796. /* fallthru */
  797. case SCTP_STATE_ESTABLISHED:
  798. case SCTP_STATE_SHUTDOWN_PENDING:
  799. case SCTP_STATE_SHUTDOWN_RECEIVED:
  800. /*
  801. * RFC 2960 6.1 Transmission of DATA Chunks
  802. *
  803. * C) When the time comes for the sender to transmit,
  804. * before sending new DATA chunks, the sender MUST
  805. * first transmit any outstanding DATA chunks which
  806. * are marked for retransmission (limited by the
  807. * current cwnd).
  808. */
  809. if (!list_empty(&q->retransmit)) {
  810. if (asoc->peer.retran_path->state == SCTP_UNCONFIRMED)
  811. goto sctp_flush_out;
  812. if (transport == asoc->peer.retran_path)
  813. goto retran;
  814. /* Switch transports & prepare the packet. */
  815. transport = asoc->peer.retran_path;
  816. if (list_empty(&transport->send_ready)) {
  817. list_add_tail(&transport->send_ready,
  818. &transport_list);
  819. }
  820. packet = &transport->packet;
  821. sctp_packet_config(packet, vtag,
  822. asoc->peer.ecn_capable);
  823. retran:
  824. error = sctp_outq_flush_rtx(q, packet,
  825. rtx_timeout, &start_timer);
  826. if (start_timer) {
  827. sctp_transport_reset_t3_rtx(transport);
  828. transport->last_time_sent = jiffies;
  829. }
  830. /* This can happen on COOKIE-ECHO resend. Only
  831. * one chunk can get bundled with a COOKIE-ECHO.
  832. */
  833. if (packet->has_cookie_echo)
  834. goto sctp_flush_out;
  835. /* Don't send new data if there is still data
  836. * waiting to retransmit.
  837. */
  838. if (!list_empty(&q->retransmit))
  839. goto sctp_flush_out;
  840. }
  841. /* Apply Max.Burst limitation to the current transport in
  842. * case it will be used for new data. We are going to
  843. * rest it before we return, but we want to apply the limit
  844. * to the currently queued data.
  845. */
  846. if (transport)
  847. sctp_transport_burst_limited(transport);
  848. /* Finally, transmit new packets. */
  849. while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
  850. /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
  851. * stream identifier.
  852. */
  853. if (chunk->sinfo.sinfo_stream >=
  854. asoc->c.sinit_num_ostreams) {
  855. /* Mark as failed send. */
  856. sctp_chunk_fail(chunk, SCTP_ERROR_INV_STRM);
  857. sctp_chunk_free(chunk);
  858. continue;
  859. }
  860. /* Has this chunk expired? */
  861. if (sctp_chunk_abandoned(chunk)) {
  862. sctp_chunk_fail(chunk, 0);
  863. sctp_chunk_free(chunk);
  864. continue;
  865. }
  866. /* If there is a specified transport, use it.
  867. * Otherwise, we want to use the active path.
  868. */
  869. new_transport = chunk->transport;
  870. if (!new_transport ||
  871. ((new_transport->state == SCTP_INACTIVE) ||
  872. (new_transport->state == SCTP_UNCONFIRMED) ||
  873. (new_transport->state == SCTP_PF)))
  874. new_transport = asoc->peer.active_path;
  875. if (new_transport->state == SCTP_UNCONFIRMED) {
  876. WARN_ONCE(1, "Atempt to send packet on unconfirmed path.");
  877. sctp_chunk_fail(chunk, 0);
  878. sctp_chunk_free(chunk);
  879. continue;
  880. }
  881. /* Change packets if necessary. */
  882. if (new_transport != transport) {
  883. transport = new_transport;
  884. /* Schedule to have this transport's
  885. * packet flushed.
  886. */
  887. if (list_empty(&transport->send_ready)) {
  888. list_add_tail(&transport->send_ready,
  889. &transport_list);
  890. }
  891. packet = &transport->packet;
  892. sctp_packet_config(packet, vtag,
  893. asoc->peer.ecn_capable);
  894. /* We've switched transports, so apply the
  895. * Burst limit to the new transport.
  896. */
  897. sctp_transport_burst_limited(transport);
  898. }
  899. pr_debug("%s: outq:%p, chunk:%p[%s], tx-tsn:0x%x skb->head:%p "
  900. "skb->users:%d\n",
  901. __func__, q, chunk, chunk && chunk->chunk_hdr ?
  902. sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
  903. "illegal chunk", ntohl(chunk->subh.data_hdr->tsn),
  904. chunk->skb ? chunk->skb->head : NULL, chunk->skb ?
  905. atomic_read(&chunk->skb->users) : -1);
  906. /* Add the chunk to the packet. */
  907. status = sctp_packet_transmit_chunk(packet, chunk, 0, gfp);
  908. switch (status) {
  909. case SCTP_XMIT_PMTU_FULL:
  910. case SCTP_XMIT_RWND_FULL:
  911. case SCTP_XMIT_DELAY:
  912. /* We could not append this chunk, so put
  913. * the chunk back on the output queue.
  914. */
  915. pr_debug("%s: could not transmit tsn:0x%x, status:%d\n",
  916. __func__, ntohl(chunk->subh.data_hdr->tsn),
  917. status);
  918. sctp_outq_head_data(q, chunk);
  919. goto sctp_flush_out;
  920. case SCTP_XMIT_OK:
  921. /* The sender is in the SHUTDOWN-PENDING state,
  922. * The sender MAY set the I-bit in the DATA
  923. * chunk header.
  924. */
  925. if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
  926. chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
  927. if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
  928. asoc->stats.ouodchunks++;
  929. else
  930. asoc->stats.oodchunks++;
  931. break;
  932. default:
  933. BUG();
  934. }
  935. /* BUG: We assume that the sctp_packet_transmit()
  936. * call below will succeed all the time and add the
  937. * chunk to the transmitted list and restart the
  938. * timers.
  939. * It is possible that the call can fail under OOM
  940. * conditions.
  941. *
  942. * Is this really a problem? Won't this behave
  943. * like a lost TSN?
  944. */
  945. list_add_tail(&chunk->transmitted_list,
  946. &transport->transmitted);
  947. sctp_transport_reset_t3_rtx(transport);
  948. transport->last_time_sent = jiffies;
  949. /* Only let one DATA chunk get bundled with a
  950. * COOKIE-ECHO chunk.
  951. */
  952. if (packet->has_cookie_echo)
  953. goto sctp_flush_out;
  954. }
  955. break;
  956. default:
  957. /* Do nothing. */
  958. break;
  959. }
  960. sctp_flush_out:
  961. /* Before returning, examine all the transports touched in
  962. * this call. Right now, we bluntly force clear all the
  963. * transports. Things might change after we implement Nagle.
  964. * But such an examination is still required.
  965. *
  966. * --xguo
  967. */
  968. while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL) {
  969. struct sctp_transport *t = list_entry(ltransport,
  970. struct sctp_transport,
  971. send_ready);
  972. packet = &t->packet;
  973. if (!sctp_packet_empty(packet))
  974. error = sctp_packet_transmit(packet, gfp);
  975. /* Clear the burst limited state, if any */
  976. sctp_transport_burst_reset(t);
  977. }
  978. return error;
  979. }
  980. /* Update unack_data based on the incoming SACK chunk */
  981. static void sctp_sack_update_unack_data(struct sctp_association *assoc,
  982. struct sctp_sackhdr *sack)
  983. {
  984. sctp_sack_variable_t *frags;
  985. __u16 unack_data;
  986. int i;
  987. unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
  988. frags = sack->variable;
  989. for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
  990. unack_data -= ((ntohs(frags[i].gab.end) -
  991. ntohs(frags[i].gab.start) + 1));
  992. }
  993. assoc->unack_data = unack_data;
  994. }
  995. /* This is where we REALLY process a SACK.
  996. *
  997. * Process the SACK against the outqueue. Mostly, this just frees
  998. * things off the transmitted queue.
  999. */
  1000. int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
  1001. {
  1002. struct sctp_association *asoc = q->asoc;
  1003. struct sctp_sackhdr *sack = chunk->subh.sack_hdr;
  1004. struct sctp_transport *transport;
  1005. struct sctp_chunk *tchunk = NULL;
  1006. struct list_head *lchunk, *transport_list, *temp;
  1007. sctp_sack_variable_t *frags = sack->variable;
  1008. __u32 sack_ctsn, ctsn, tsn;
  1009. __u32 highest_tsn, highest_new_tsn;
  1010. __u32 sack_a_rwnd;
  1011. unsigned int outstanding;
  1012. struct sctp_transport *primary = asoc->peer.primary_path;
  1013. int count_of_newacks = 0;
  1014. int gap_ack_blocks;
  1015. u8 accum_moved = 0;
  1016. /* Grab the association's destination address list. */
  1017. transport_list = &asoc->peer.transport_addr_list;
  1018. sack_ctsn = ntohl(sack->cum_tsn_ack);
  1019. gap_ack_blocks = ntohs(sack->num_gap_ack_blocks);
  1020. asoc->stats.gapcnt += gap_ack_blocks;
  1021. /*
  1022. * SFR-CACC algorithm:
  1023. * On receipt of a SACK the sender SHOULD execute the
  1024. * following statements.
  1025. *
  1026. * 1) If the cumulative ack in the SACK passes next tsn_at_change
  1027. * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
  1028. * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
  1029. * all destinations.
  1030. * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
  1031. * is set the receiver of the SACK MUST take the following actions:
  1032. *
  1033. * A) Initialize the cacc_saw_newack to 0 for all destination
  1034. * addresses.
  1035. *
  1036. * Only bother if changeover_active is set. Otherwise, this is
  1037. * totally suboptimal to do on every SACK.
  1038. */
  1039. if (primary->cacc.changeover_active) {
  1040. u8 clear_cycling = 0;
  1041. if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
  1042. primary->cacc.changeover_active = 0;
  1043. clear_cycling = 1;
  1044. }
  1045. if (clear_cycling || gap_ack_blocks) {
  1046. list_for_each_entry(transport, transport_list,
  1047. transports) {
  1048. if (clear_cycling)
  1049. transport->cacc.cycling_changeover = 0;
  1050. if (gap_ack_blocks)
  1051. transport->cacc.cacc_saw_newack = 0;
  1052. }
  1053. }
  1054. }
  1055. /* Get the highest TSN in the sack. */
  1056. highest_tsn = sack_ctsn;
  1057. if (gap_ack_blocks)
  1058. highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);
  1059. if (TSN_lt(asoc->highest_sacked, highest_tsn))
  1060. asoc->highest_sacked = highest_tsn;
  1061. highest_new_tsn = sack_ctsn;
  1062. /* Run through the retransmit queue. Credit bytes received
  1063. * and free those chunks that we can.
  1064. */
  1065. sctp_check_transmitted(q, &q->retransmit, NULL, NULL, sack, &highest_new_tsn);
  1066. /* Run through the transmitted queue.
  1067. * Credit bytes received and free those chunks which we can.
  1068. *
  1069. * This is a MASSIVE candidate for optimization.
  1070. */
  1071. list_for_each_entry(transport, transport_list, transports) {
  1072. sctp_check_transmitted(q, &transport->transmitted,
  1073. transport, &chunk->source, sack,
  1074. &highest_new_tsn);
  1075. /*
  1076. * SFR-CACC algorithm:
  1077. * C) Let count_of_newacks be the number of
  1078. * destinations for which cacc_saw_newack is set.
  1079. */
  1080. if (transport->cacc.cacc_saw_newack)
  1081. count_of_newacks++;
  1082. }
  1083. /* Move the Cumulative TSN Ack Point if appropriate. */
  1084. if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn)) {
  1085. asoc->ctsn_ack_point = sack_ctsn;
  1086. accum_moved = 1;
  1087. }
  1088. if (gap_ack_blocks) {
  1089. if (asoc->fast_recovery && accum_moved)
  1090. highest_new_tsn = highest_tsn;
  1091. list_for_each_entry(transport, transport_list, transports)
  1092. sctp_mark_missing(q, &transport->transmitted, transport,
  1093. highest_new_tsn, count_of_newacks);
  1094. }
  1095. /* Update unack_data field in the assoc. */
  1096. sctp_sack_update_unack_data(asoc, sack);
  1097. ctsn = asoc->ctsn_ack_point;
  1098. /* Throw away stuff rotting on the sack queue. */
  1099. list_for_each_safe(lchunk, temp, &q->sacked) {
  1100. tchunk = list_entry(lchunk, struct sctp_chunk,
  1101. transmitted_list);
  1102. tsn = ntohl(tchunk->subh.data_hdr->tsn);
  1103. if (TSN_lte(tsn, ctsn)) {
  1104. list_del_init(&tchunk->transmitted_list);
  1105. sctp_chunk_free(tchunk);
  1106. }
  1107. }
  1108. /* ii) Set rwnd equal to the newly received a_rwnd minus the
  1109. * number of bytes still outstanding after processing the
  1110. * Cumulative TSN Ack and the Gap Ack Blocks.
  1111. */
  1112. sack_a_rwnd = ntohl(sack->a_rwnd);
  1113. asoc->peer.zero_window_announced = !sack_a_rwnd;
  1114. outstanding = q->outstanding_bytes;
  1115. if (outstanding < sack_a_rwnd)
  1116. sack_a_rwnd -= outstanding;
  1117. else
  1118. sack_a_rwnd = 0;
  1119. asoc->peer.rwnd = sack_a_rwnd;
  1120. sctp_generate_fwdtsn(q, sack_ctsn);
  1121. pr_debug("%s: sack cumulative tsn ack:0x%x\n", __func__, sack_ctsn);
  1122. pr_debug("%s: cumulative tsn ack of assoc:%p is 0x%x, "
  1123. "advertised peer ack point:0x%x\n", __func__, asoc, ctsn,
  1124. asoc->adv_peer_ack_point);
  1125. return sctp_outq_is_empty(q);
  1126. }
  1127. /* Is the outqueue empty?
  1128. * The queue is empty when we have not pending data, no in-flight data
  1129. * and nothing pending retransmissions.
  1130. */
  1131. int sctp_outq_is_empty(const struct sctp_outq *q)
  1132. {
  1133. return q->out_qlen == 0 && q->outstanding_bytes == 0 &&
  1134. list_empty(&q->retransmit);
  1135. }
  1136. /********************************************************************
  1137. * 2nd Level Abstractions
  1138. ********************************************************************/
  1139. /* Go through a transport's transmitted list or the association's retransmit
  1140. * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
  1141. * The retransmit list will not have an associated transport.
  1142. *
  1143. * I added coherent debug information output. --xguo
  1144. *
  1145. * Instead of printing 'sacked' or 'kept' for each TSN on the
  1146. * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
  1147. * KEPT TSN6-TSN7, etc.
  1148. */
  1149. static void sctp_check_transmitted(struct sctp_outq *q,
  1150. struct list_head *transmitted_queue,
  1151. struct sctp_transport *transport,
  1152. union sctp_addr *saddr,
  1153. struct sctp_sackhdr *sack,
  1154. __u32 *highest_new_tsn_in_sack)
  1155. {
  1156. struct list_head *lchunk;
  1157. struct sctp_chunk *tchunk;
  1158. struct list_head tlist;
  1159. __u32 tsn;
  1160. __u32 sack_ctsn;
  1161. __u32 rtt;
  1162. __u8 restart_timer = 0;
  1163. int bytes_acked = 0;
  1164. int migrate_bytes = 0;
  1165. bool forward_progress = false;
  1166. sack_ctsn = ntohl(sack->cum_tsn_ack);
  1167. INIT_LIST_HEAD(&tlist);
  1168. /* The while loop will skip empty transmitted queues. */
  1169. while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
  1170. tchunk = list_entry(lchunk, struct sctp_chunk,
  1171. transmitted_list);
  1172. if (sctp_chunk_abandoned(tchunk)) {
  1173. /* Move the chunk to abandoned list. */
  1174. sctp_insert_list(&q->abandoned, lchunk);
  1175. /* If this chunk has not been acked, stop
  1176. * considering it as 'outstanding'.
  1177. */
  1178. if (!tchunk->tsn_gap_acked) {
  1179. if (tchunk->transport)
  1180. tchunk->transport->flight_size -=
  1181. sctp_data_size(tchunk);
  1182. q->outstanding_bytes -= sctp_data_size(tchunk);
  1183. }
  1184. continue;
  1185. }
  1186. tsn = ntohl(tchunk->subh.data_hdr->tsn);
  1187. if (sctp_acked(sack, tsn)) {
  1188. /* If this queue is the retransmit queue, the
  1189. * retransmit timer has already reclaimed
  1190. * the outstanding bytes for this chunk, so only
  1191. * count bytes associated with a transport.
  1192. */
  1193. if (transport) {
  1194. /* If this chunk is being used for RTT
  1195. * measurement, calculate the RTT and update
  1196. * the RTO using this value.
  1197. *
  1198. * 6.3.1 C5) Karn's algorithm: RTT measurements
  1199. * MUST NOT be made using packets that were
  1200. * retransmitted (and thus for which it is
  1201. * ambiguous whether the reply was for the
  1202. * first instance of the packet or a later
  1203. * instance).
  1204. */
  1205. if (!tchunk->tsn_gap_acked &&
  1206. !tchunk->resent &&
  1207. tchunk->rtt_in_progress) {
  1208. tchunk->rtt_in_progress = 0;
  1209. rtt = jiffies - tchunk->sent_at;
  1210. sctp_transport_update_rto(transport,
  1211. rtt);
  1212. }
  1213. }
  1214. /* If the chunk hasn't been marked as ACKED,
  1215. * mark it and account bytes_acked if the
  1216. * chunk had a valid transport (it will not
  1217. * have a transport if ASCONF had deleted it
  1218. * while DATA was outstanding).
  1219. */
  1220. if (!tchunk->tsn_gap_acked) {
  1221. tchunk->tsn_gap_acked = 1;
  1222. if (TSN_lt(*highest_new_tsn_in_sack, tsn))
  1223. *highest_new_tsn_in_sack = tsn;
  1224. bytes_acked += sctp_data_size(tchunk);
  1225. if (!tchunk->transport)
  1226. migrate_bytes += sctp_data_size(tchunk);
  1227. forward_progress = true;
  1228. }
  1229. if (TSN_lte(tsn, sack_ctsn)) {
  1230. /* RFC 2960 6.3.2 Retransmission Timer Rules
  1231. *
  1232. * R3) Whenever a SACK is received
  1233. * that acknowledges the DATA chunk
  1234. * with the earliest outstanding TSN
  1235. * for that address, restart T3-rtx
  1236. * timer for that address with its
  1237. * current RTO.
  1238. */
  1239. restart_timer = 1;
  1240. forward_progress = true;
  1241. if (!tchunk->tsn_gap_acked) {
  1242. /*
  1243. * SFR-CACC algorithm:
  1244. * 2) If the SACK contains gap acks
  1245. * and the flag CHANGEOVER_ACTIVE is
  1246. * set the receiver of the SACK MUST
  1247. * take the following action:
  1248. *
  1249. * B) For each TSN t being acked that
  1250. * has not been acked in any SACK so
  1251. * far, set cacc_saw_newack to 1 for
  1252. * the destination that the TSN was
  1253. * sent to.
  1254. */
  1255. if (transport &&
  1256. sack->num_gap_ack_blocks &&
  1257. q->asoc->peer.primary_path->cacc.
  1258. changeover_active)
  1259. transport->cacc.cacc_saw_newack
  1260. = 1;
  1261. }
  1262. list_add_tail(&tchunk->transmitted_list,
  1263. &q->sacked);
  1264. } else {
  1265. /* RFC2960 7.2.4, sctpimpguide-05 2.8.2
  1266. * M2) Each time a SACK arrives reporting
  1267. * 'Stray DATA chunk(s)' record the highest TSN
  1268. * reported as newly acknowledged, call this
  1269. * value 'HighestTSNinSack'. A newly
  1270. * acknowledged DATA chunk is one not
  1271. * previously acknowledged in a SACK.
  1272. *
  1273. * When the SCTP sender of data receives a SACK
  1274. * chunk that acknowledges, for the first time,
  1275. * the receipt of a DATA chunk, all the still
  1276. * unacknowledged DATA chunks whose TSN is
  1277. * older than that newly acknowledged DATA
  1278. * chunk, are qualified as 'Stray DATA chunks'.
  1279. */
  1280. list_add_tail(lchunk, &tlist);
  1281. }
  1282. } else {
  1283. if (tchunk->tsn_gap_acked) {
  1284. pr_debug("%s: receiver reneged on data TSN:0x%x\n",
  1285. __func__, tsn);
  1286. tchunk->tsn_gap_acked = 0;
  1287. if (tchunk->transport)
  1288. bytes_acked -= sctp_data_size(tchunk);
  1289. /* RFC 2960 6.3.2 Retransmission Timer Rules
  1290. *
  1291. * R4) Whenever a SACK is received missing a
  1292. * TSN that was previously acknowledged via a
  1293. * Gap Ack Block, start T3-rtx for the
  1294. * destination address to which the DATA
  1295. * chunk was originally
  1296. * transmitted if it is not already running.
  1297. */
  1298. restart_timer = 1;
  1299. }
  1300. list_add_tail(lchunk, &tlist);
  1301. }
  1302. }
  1303. if (transport) {
  1304. if (bytes_acked) {
  1305. struct sctp_association *asoc = transport->asoc;
  1306. /* We may have counted DATA that was migrated
  1307. * to this transport due to DEL-IP operation.
  1308. * Subtract those bytes, since the were never
  1309. * send on this transport and shouldn't be
  1310. * credited to this transport.
  1311. */
  1312. bytes_acked -= migrate_bytes;
  1313. /* 8.2. When an outstanding TSN is acknowledged,
  1314. * the endpoint shall clear the error counter of
  1315. * the destination transport address to which the
  1316. * DATA chunk was last sent.
  1317. * The association's overall error counter is
  1318. * also cleared.
  1319. */
  1320. transport->error_count = 0;
  1321. transport->asoc->overall_error_count = 0;
  1322. forward_progress = true;
  1323. /*
  1324. * While in SHUTDOWN PENDING, we may have started
  1325. * the T5 shutdown guard timer after reaching the
  1326. * retransmission limit. Stop that timer as soon
  1327. * as the receiver acknowledged any data.
  1328. */
  1329. if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING &&
  1330. del_timer(&asoc->timers
  1331. [SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]))
  1332. sctp_association_put(asoc);
  1333. /* Mark the destination transport address as
  1334. * active if it is not so marked.
  1335. */
  1336. if ((transport->state == SCTP_INACTIVE ||
  1337. transport->state == SCTP_UNCONFIRMED) &&
  1338. sctp_cmp_addr_exact(&transport->ipaddr, saddr)) {
  1339. sctp_assoc_control_transport(
  1340. transport->asoc,
  1341. transport,
  1342. SCTP_TRANSPORT_UP,
  1343. SCTP_RECEIVED_SACK);
  1344. }
  1345. sctp_transport_raise_cwnd(transport, sack_ctsn,
  1346. bytes_acked);
  1347. transport->flight_size -= bytes_acked;
  1348. if (transport->flight_size == 0)
  1349. transport->partial_bytes_acked = 0;
  1350. q->outstanding_bytes -= bytes_acked + migrate_bytes;
  1351. } else {
  1352. /* RFC 2960 6.1, sctpimpguide-06 2.15.2
  1353. * When a sender is doing zero window probing, it
  1354. * should not timeout the association if it continues
  1355. * to receive new packets from the receiver. The
  1356. * reason is that the receiver MAY keep its window
  1357. * closed for an indefinite time.
  1358. * A sender is doing zero window probing when the
  1359. * receiver's advertised window is zero, and there is
  1360. * only one data chunk in flight to the receiver.
  1361. *
  1362. * Allow the association to timeout while in SHUTDOWN
  1363. * PENDING or SHUTDOWN RECEIVED in case the receiver
  1364. * stays in zero window mode forever.
  1365. */
  1366. if (!q->asoc->peer.rwnd &&
  1367. !list_empty(&tlist) &&
  1368. (sack_ctsn+2 == q->asoc->next_tsn) &&
  1369. q->asoc->state < SCTP_STATE_SHUTDOWN_PENDING) {
  1370. pr_debug("%s: sack received for zero window "
  1371. "probe:%u\n", __func__, sack_ctsn);
  1372. q->asoc->overall_error_count = 0;
  1373. transport->error_count = 0;
  1374. }
  1375. }
  1376. /* RFC 2960 6.3.2 Retransmission Timer Rules
  1377. *
  1378. * R2) Whenever all outstanding data sent to an address have
  1379. * been acknowledged, turn off the T3-rtx timer of that
  1380. * address.
  1381. */
  1382. if (!transport->flight_size) {
  1383. if (del_timer(&transport->T3_rtx_timer))
  1384. sctp_transport_put(transport);
  1385. } else if (restart_timer) {
  1386. if (!mod_timer(&transport->T3_rtx_timer,
  1387. jiffies + transport->rto))
  1388. sctp_transport_hold(transport);
  1389. }
  1390. if (forward_progress) {
  1391. if (transport->dst)
  1392. dst_confirm(transport->dst);
  1393. }
  1394. }
  1395. list_splice(&tlist, transmitted_queue);
  1396. }
  1397. /* Mark chunks as missing and consequently may get retransmitted. */
  1398. static void sctp_mark_missing(struct sctp_outq *q,
  1399. struct list_head *transmitted_queue,
  1400. struct sctp_transport *transport,
  1401. __u32 highest_new_tsn_in_sack,
  1402. int count_of_newacks)
  1403. {
  1404. struct sctp_chunk *chunk;
  1405. __u32 tsn;
  1406. char do_fast_retransmit = 0;
  1407. struct sctp_association *asoc = q->asoc;
  1408. struct sctp_transport *primary = asoc->peer.primary_path;
  1409. list_for_each_entry(chunk, transmitted_queue, transmitted_list) {
  1410. tsn = ntohl(chunk->subh.data_hdr->tsn);
  1411. /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
  1412. * 'Unacknowledged TSN's', if the TSN number of an
  1413. * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
  1414. * value, increment the 'TSN.Missing.Report' count on that
  1415. * chunk if it has NOT been fast retransmitted or marked for
  1416. * fast retransmit already.
  1417. */
  1418. if (chunk->fast_retransmit == SCTP_CAN_FRTX &&
  1419. !chunk->tsn_gap_acked &&
  1420. TSN_lt(tsn, highest_new_tsn_in_sack)) {
  1421. /* SFR-CACC may require us to skip marking
  1422. * this chunk as missing.
  1423. */
  1424. if (!transport || !sctp_cacc_skip(primary,
  1425. chunk->transport,
  1426. count_of_newacks, tsn)) {
  1427. chunk->tsn_missing_report++;
  1428. pr_debug("%s: tsn:0x%x missing counter:%d\n",
  1429. __func__, tsn, chunk->tsn_missing_report);
  1430. }
  1431. }
  1432. /*
  1433. * M4) If any DATA chunk is found to have a
  1434. * 'TSN.Missing.Report'
  1435. * value larger than or equal to 3, mark that chunk for
  1436. * retransmission and start the fast retransmit procedure.
  1437. */
  1438. if (chunk->tsn_missing_report >= 3) {
  1439. chunk->fast_retransmit = SCTP_NEED_FRTX;
  1440. do_fast_retransmit = 1;
  1441. }
  1442. }
  1443. if (transport) {
  1444. if (do_fast_retransmit)
  1445. sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
  1446. pr_debug("%s: transport:%p, cwnd:%d, ssthresh:%d, "
  1447. "flight_size:%d, pba:%d\n", __func__, transport,
  1448. transport->cwnd, transport->ssthresh,
  1449. transport->flight_size, transport->partial_bytes_acked);
  1450. }
  1451. }
  1452. /* Is the given TSN acked by this packet? */
  1453. static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
  1454. {
  1455. int i;
  1456. sctp_sack_variable_t *frags;
  1457. __u16 gap;
  1458. __u32 ctsn = ntohl(sack->cum_tsn_ack);
  1459. if (TSN_lte(tsn, ctsn))
  1460. goto pass;
  1461. /* 3.3.4 Selective Acknowledgement (SACK) (3):
  1462. *
  1463. * Gap Ack Blocks:
  1464. * These fields contain the Gap Ack Blocks. They are repeated
  1465. * for each Gap Ack Block up to the number of Gap Ack Blocks
  1466. * defined in the Number of Gap Ack Blocks field. All DATA
  1467. * chunks with TSNs greater than or equal to (Cumulative TSN
  1468. * Ack + Gap Ack Block Start) and less than or equal to
  1469. * (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
  1470. * Block are assumed to have been received correctly.
  1471. */
  1472. frags = sack->variable;
  1473. gap = tsn - ctsn;
  1474. for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
  1475. if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
  1476. TSN_lte(gap, ntohs(frags[i].gab.end)))
  1477. goto pass;
  1478. }
  1479. return 0;
  1480. pass:
  1481. return 1;
  1482. }
  1483. static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist,
  1484. int nskips, __be16 stream)
  1485. {
  1486. int i;
  1487. for (i = 0; i < nskips; i++) {
  1488. if (skiplist[i].stream == stream)
  1489. return i;
  1490. }
  1491. return i;
  1492. }
  1493. /* Create and add a fwdtsn chunk to the outq's control queue if needed. */
  1494. static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
  1495. {
  1496. struct sctp_association *asoc = q->asoc;
  1497. struct sctp_chunk *ftsn_chunk = NULL;
  1498. struct sctp_fwdtsn_skip ftsn_skip_arr[10];
  1499. int nskips = 0;
  1500. int skip_pos = 0;
  1501. __u32 tsn;
  1502. struct sctp_chunk *chunk;
  1503. struct list_head *lchunk, *temp;
  1504. if (!asoc->peer.prsctp_capable)
  1505. return;
  1506. /* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the
  1507. * received SACK.
  1508. *
  1509. * If (Advanced.Peer.Ack.Point < SackCumAck), then update
  1510. * Advanced.Peer.Ack.Point to be equal to SackCumAck.
  1511. */
  1512. if (TSN_lt(asoc->adv_peer_ack_point, ctsn))
  1513. asoc->adv_peer_ack_point = ctsn;
  1514. /* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point"
  1515. * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as
  1516. * the chunk next in the out-queue space is marked as "abandoned" as
  1517. * shown in the following example:
  1518. *
  1519. * Assuming that a SACK arrived with the Cumulative TSN ACK 102
  1520. * and the Advanced.Peer.Ack.Point is updated to this value:
  1521. *
  1522. * out-queue at the end of ==> out-queue after Adv.Ack.Point
  1523. * normal SACK processing local advancement
  1524. * ... ...
  1525. * Adv.Ack.Pt-> 102 acked 102 acked
  1526. * 103 abandoned 103 abandoned
  1527. * 104 abandoned Adv.Ack.P-> 104 abandoned
  1528. * 105 105
  1529. * 106 acked 106 acked
  1530. * ... ...
  1531. *
  1532. * In this example, the data sender successfully advanced the
  1533. * "Advanced.Peer.Ack.Point" from 102 to 104 locally.
  1534. */
  1535. list_for_each_safe(lchunk, temp, &q->abandoned) {
  1536. chunk = list_entry(lchunk, struct sctp_chunk,
  1537. transmitted_list);
  1538. tsn = ntohl(chunk->subh.data_hdr->tsn);
  1539. /* Remove any chunks in the abandoned queue that are acked by
  1540. * the ctsn.
  1541. */
  1542. if (TSN_lte(tsn, ctsn)) {
  1543. list_del_init(lchunk);
  1544. sctp_chunk_free(chunk);
  1545. } else {
  1546. if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
  1547. asoc->adv_peer_ack_point = tsn;
  1548. if (chunk->chunk_hdr->flags &
  1549. SCTP_DATA_UNORDERED)
  1550. continue;
  1551. skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0],
  1552. nskips,
  1553. chunk->subh.data_hdr->stream);
  1554. ftsn_skip_arr[skip_pos].stream =
  1555. chunk->subh.data_hdr->stream;
  1556. ftsn_skip_arr[skip_pos].ssn =
  1557. chunk->subh.data_hdr->ssn;
  1558. if (skip_pos == nskips)
  1559. nskips++;
  1560. if (nskips == 10)
  1561. break;
  1562. } else
  1563. break;
  1564. }
  1565. }
  1566. /* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point"
  1567. * is greater than the Cumulative TSN ACK carried in the received
  1568. * SACK, the data sender MUST send the data receiver a FORWARD TSN
  1569. * chunk containing the latest value of the
  1570. * "Advanced.Peer.Ack.Point".
  1571. *
  1572. * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD
  1573. * list each stream and sequence number in the forwarded TSN. This
  1574. * information will enable the receiver to easily find any
  1575. * stranded TSN's waiting on stream reorder queues. Each stream
  1576. * SHOULD only be reported once; this means that if multiple
  1577. * abandoned messages occur in the same stream then only the
  1578. * highest abandoned stream sequence number is reported. If the
  1579. * total size of the FORWARD TSN does NOT fit in a single MTU then
  1580. * the sender of the FORWARD TSN SHOULD lower the
  1581. * Advanced.Peer.Ack.Point to the last TSN that will fit in a
  1582. * single MTU.
  1583. */
  1584. if (asoc->adv_peer_ack_point > ctsn)
  1585. ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point,
  1586. nskips, &ftsn_skip_arr[0]);
  1587. if (ftsn_chunk) {
  1588. list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
  1589. SCTP_INC_STATS(sock_net(asoc->base.sk), SCTP_MIB_OUTCTRLCHUNKS);
  1590. }
  1591. }