outqueue.c 53 KB

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