outqueue.c 53 KB

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