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