49 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
51 #include <linux/types.h>
52 #include <linux/list.h>
53 #include <linux/socket.h>
55 #include <linux/slab.h>
63 static void sctp_check_transmitted(
struct sctp_outq *
q,
68 __u32 *highest_new_tsn);
70 static void sctp_mark_missing(
struct sctp_outq *
q,
73 __u32 highest_new_tsn,
74 int count_of_newacks);
78 static int sctp_outq_flush(
struct sctp_outq *
q,
int rtx_timeout);
81 static inline void sctp_outq_head_data(
struct sctp_outq *
q,
103 static inline void sctp_outq_tail_data(
struct sctp_outq *q,
118 int count_of_newacks)
120 if (count_of_newacks >=2 && transport != primary)
132 static inline int sctp_cacc_skip_3_1_f(
struct sctp_transport *transport,
133 int count_of_newacks)
135 if (count_of_newacks < 2 &&
136 (transport && !transport->
cacc.cacc_saw_newack))
148 static inline int sctp_cacc_skip_3_1(
struct sctp_transport *primary,
150 int count_of_newacks)
152 if (!primary->
cacc.cycling_changeover) {
153 if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks))
155 if (sctp_cacc_skip_3_1_f(transport, count_of_newacks))
171 if (primary->
cacc.cycling_changeover &&
172 TSN_lt(tsn, primary->
cacc.next_tsn_at_change))
193 int count_of_newacks,
196 if (primary->
cacc.changeover_active &&
197 (sctp_cacc_skip_3_1(primary, transport, count_of_newacks) ||
198 sctp_cacc_skip_3_2(primary, tsn)))
213 INIT_LIST_HEAD(&q->
sacked);
236 while ((lchunk = sctp_list_dequeue(&transport->
transmitted)) !=
NULL) {
247 list_del_init(lchunk);
256 list_del_init(lchunk);
265 list_del_init(lchunk);
273 while ((chunk = sctp_outq_dequeue_data(q)) !=
NULL) {
284 list_del_init(&chunk->
list);
324 switch (q->
asoc->state) {
340 sctp_outq_tail_data(q, chunk);
357 error = sctp_outq_flush(q, 0);
378 if (TSN_lt(ntsn, ltsn)) {
379 list_add(
new, pos->
prev);
403 list_del_init(lchunk);
414 sctp_data_size(chunk);
416 q->
asoc->peer.rwnd += sctp_data_size(chunk);
436 q->
asoc->peer.rwnd += sctp_data_size(chunk);
462 list_del_init(lchunk);
468 "cwnd: %d, ssthresh: %d, flight_size: %d, "
469 "pba: %d\n", __func__,
493 if (transport == transport->
asoc->peer.retran_path)
495 transport->
asoc->rtx_data_chunks +=
496 transport->
asoc->unack_data;
508 transport->
asoc->init_retries++;
521 sctp_generate_fwdtsn(q, q->
asoc->ctsn_ack_point);
528 error = sctp_outq_flush(q, 1);
543 int rtx_timeout,
int *start_timer)
630 if (rtx_timeout || fast_rtx)
674 if (!error && !timer)
686 if (rtx_timeout || fast_rtx) {
693 *start_timer =
timer;
708 error = sctp_outq_flush(q, 0);
722 static int sctp_outq_flush(
struct sctp_outq *q,
int rtx_timeout)
742 INIT_LIST_HEAD(&transport_list);
766 list_del_init(&chunk->
list);
771 if (!new_transport) {
794 new_transport = asoc->
peer.active_path;
814 new_transport = asoc->
peer.active_path;
820 if (new_transport != transport) {
821 transport = new_transport;
826 packet = &transport->
packet;
828 asoc->
peer.ecn_capable);
851 packet->
vtag = asoc->
c.my_vtag;
894 if (q->
asoc->src_out_of_asoc_ok)
898 switch (asoc->
state) {
922 if (transport == asoc->
peer.retran_path)
927 transport = asoc->
peer.retran_path;
934 packet = &transport->
packet;
936 asoc->
peer.ecn_capable);
938 error = sctp_outq_flush_rtx(q, packet,
939 rtx_timeout, &start_timer);
966 while ((chunk = sctp_outq_dequeue_data(q)) !=
NULL) {
970 if (chunk->
sinfo.sinfo_stream >=
971 asoc->
c.sinit_num_ostreams) {
990 if (!new_transport ||
994 new_transport = asoc->
peer.active_path;
999 if (new_transport != transport) {
1000 transport = new_transport;
1010 packet = &transport->
packet;
1012 asoc->
peer.ecn_capable);
1027 "%p skb->users %d.\n",
1044 "not transmit TSN: 0x%x, status: %d\n",
1047 sctp_outq_head_data(q, chunk);
1048 goto sctp_flush_out;
1086 goto sctp_flush_out;
1104 while ((ltransport = sctp_list_dequeue(&transport_list)) !=
NULL ) {
1109 if (!sctp_packet_empty(packet))
1131 unack_data -= ((
ntohs(frags[i].
gab.end) -
1151 __u32 sack_ctsn, ctsn, tsn;
1152 __u32 highest_tsn, highest_new_tsn;
1154 unsigned int outstanding;
1156 int count_of_newacks = 0;
1161 transport_list = &asoc->
peer.transport_addr_list;
1183 if (primary->
cacc.changeover_active) {
1184 u8 clear_cycling = 0;
1186 if (TSN_lte(primary->
cacc.next_tsn_at_change, sack_ctsn)) {
1187 primary->
cacc.changeover_active = 0;
1191 if (clear_cycling || gap_ack_blocks) {
1195 transport->
cacc.cycling_changeover = 0;
1197 transport->
cacc.cacc_saw_newack = 0;
1203 highest_tsn = sack_ctsn;
1205 highest_tsn +=
ntohs(frags[gap_ack_blocks - 1].
gab.end);
1210 highest_new_tsn = sack_ctsn;
1223 sctp_check_transmitted(q, &transport->
transmitted,
1224 transport, &chunk->
source, sack,
1231 if (transport->
cacc.cacc_saw_newack)
1232 count_of_newacks ++;
1241 if (gap_ack_blocks) {
1244 highest_new_tsn = highest_tsn;
1247 sctp_mark_missing(q, &transport->
transmitted, transport,
1248 highest_new_tsn, count_of_newacks);
1252 sctp_sack_update_unack_data(asoc, sack);
1261 if (TSN_lte(tsn, ctsn)) {
1275 if (outstanding < sack_a_rwnd)
1276 sack_a_rwnd -= outstanding;
1280 asoc->
peer.rwnd = sack_a_rwnd;
1282 sctp_generate_fwdtsn(q, sack_ctsn);
1285 __func__, sack_ctsn);
1287 "%p is 0x%x. Adv peer ack point: 0x%x\n",
1329 static void sctp_check_transmitted(
struct sctp_outq *q,
1334 __u32 *highest_new_tsn_in_sack)
1342 __u8 restart_timer = 0;
1343 int bytes_acked = 0;
1344 int migrate_bytes = 0;
1349 __u32 dbg_ack_tsn = 0;
1350 __u32 dbg_last_ack_tsn = 0;
1351 __u32 dbg_kept_tsn = 0;
1352 __u32 dbg_last_kept_tsn = 0;
1358 int dbg_prt_state = -1;
1363 INIT_LIST_HEAD(&tlist);
1366 while (
NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
1372 sctp_insert_list(&q->
abandoned, lchunk);
1380 sctp_data_size(tchunk);
1387 if (sctp_acked(sack, tsn)) {
1422 *highest_new_tsn_in_sack = tsn;
1423 bytes_acked += sctp_data_size(tchunk);
1425 migrate_bytes += sctp_data_size(tchunk);
1428 if (TSN_lte(tsn, sack_ctsn)) {
1456 q->
asoc->peer.primary_path->cacc.
1458 transport->
cacc.cacc_saw_newack
1484 switch (dbg_prt_state) {
1486 if (dbg_last_ack_tsn + 1 == tsn) {
1493 if (dbg_last_ack_tsn != dbg_ack_tsn) {
1507 if (dbg_last_kept_tsn != dbg_kept_tsn) {
1524 dbg_last_ack_tsn = tsn;
1536 bytes_acked -= sctp_data_size(tchunk);
1554 switch (dbg_prt_state) {
1556 if (dbg_last_kept_tsn + 1 == tsn)
1559 if (dbg_last_kept_tsn != dbg_kept_tsn)
1568 if (dbg_last_ack_tsn != dbg_ack_tsn)
1580 dbg_last_kept_tsn = tsn;
1587 switch (dbg_prt_state) {
1589 if (dbg_last_ack_tsn != dbg_ack_tsn) {
1597 if (dbg_last_kept_tsn != dbg_kept_tsn) {
1614 bytes_acked -= migrate_bytes;
1624 transport->
asoc->overall_error_count = 0;
1672 if (!q->
asoc->peer.rwnd &&
1673 !list_empty(&tlist) &&
1674 (sack_ctsn+2 == q->
asoc->next_tsn) &&
1677 "window probe: %u\n",
1678 __func__, sack_ctsn);
1679 q->
asoc->overall_error_count = 0;
1695 }
else if (restart_timer) {
1697 jiffies + transport->
rto))
1702 list_splice(&tlist, transmitted_queue);
1706 static void sctp_mark_missing(
struct sctp_outq *q,
1709 __u32 highest_new_tsn_in_sack,
1710 int count_of_newacks)
1714 char do_fast_retransmit = 0;
1731 TSN_lt(tsn, highest_new_tsn_in_sack)) {
1736 if (!transport || !sctp_cacc_skip(primary,
1738 count_of_newacks, tsn)) {
1742 "%s: TSN 0x%x missing counter: %d\n",
1756 do_fast_retransmit = 1;
1761 if (do_fast_retransmit)
1765 "ssthresh: %d, flight_size: %d, pba: %d\n",
1766 __func__, transport, transport->
cwnd,
1780 if (TSN_lte(tsn, ctsn))
1798 if (TSN_lte(
ntohs(frags[i].
gab.start), gap) &&
1799 TSN_lte(gap,
ntohs(frags[i].
gab.end)))
1809 int nskips,
__be16 stream)
1813 for (i = 0; i < nskips; i++) {
1814 if (skiplist[i].stream == stream)
1821 static void sctp_generate_fwdtsn(
struct sctp_outq *q,
__u32 ctsn)
1832 if (!asoc->
peer.prsctp_capable)
1873 if (TSN_lte(tsn, ctsn)) {
1874 list_del_init(lchunk);
1882 skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0],
1885 ftsn_skip_arr[skip_pos].stream =
1887 ftsn_skip_arr[skip_pos].ssn =
1889 if (skip_pos == nskips)
1918 nskips, &ftsn_skip_arr[0]);