outqueue.c 52 KB

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