outqueue.c 52 KB

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