PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/net/sctp/outqueue.c

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