1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
50
51#include <linux/types.h>
52#include <linux/list.h>
53#include <linux/socket.h>
54#include <linux/ip.h>
55#include <linux/slab.h>
56#include <net/sock.h>
57
58#include <net/sctp/sctp.h>
59#include <net/sctp/sm.h>
60
61
62static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn);
63static void sctp_check_transmitted(struct sctp_outq *q,
64 struct list_head *transmitted_queue,
65 struct sctp_transport *transport,
66 struct sctp_sackhdr *sack,
67 __u32 *highest_new_tsn);
68
69static void sctp_mark_missing(struct sctp_outq *q,
70 struct list_head *transmitted_queue,
71 struct sctp_transport *transport,
72 __u32 highest_new_tsn,
73 int count_of_newacks);
74
75static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
76
77static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout);
78
79
80static inline void sctp_outq_head_data(struct sctp_outq *q,
81 struct sctp_chunk *ch)
82{
83 list_add(&ch->list, &q->out_chunk_list);
84 q->out_qlen += ch->skb->len;
85}
86
87
88static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q)
89{
90 struct sctp_chunk *ch = NULL;
91
92 if (!list_empty(&q->out_chunk_list)) {
93 struct list_head *entry = q->out_chunk_list.next;
94
95 ch = list_entry(entry, struct sctp_chunk, list);
96 list_del_init(entry);
97 q->out_qlen -= ch->skb->len;
98 }
99 return ch;
100}
101
102static inline void sctp_outq_tail_data(struct sctp_outq *q,
103 struct sctp_chunk *ch)
104{
105 list_add_tail(&ch->list, &q->out_chunk_list);
106 q->out_qlen += ch->skb->len;
107}
108
109
110
111
112
113
114
115static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary,
116 struct sctp_transport *transport,
117 int count_of_newacks)
118{
119 if (count_of_newacks >=2 && transport != primary)
120 return 1;
121 return 0;
122}
123
124
125
126
127
128
129
130
131static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport,
132 int count_of_newacks)
133{
134 if (count_of_newacks < 2 &&
135 (transport && !transport->cacc.cacc_saw_newack))
136 return 1;
137 return 0;
138}
139
140
141
142
143
144
145
146
147static inline int sctp_cacc_skip_3_1(struct sctp_transport *primary,
148 struct sctp_transport *transport,
149 int count_of_newacks)
150{
151 if (!primary->cacc.cycling_changeover) {
152 if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks))
153 return 1;
154 if (sctp_cacc_skip_3_1_f(transport, count_of_newacks))
155 return 1;
156 return 0;
157 }
158 return 0;
159}
160
161
162
163
164
165
166
167
168static inline int sctp_cacc_skip_3_2(struct sctp_transport *primary, __u32 tsn)
169{
170 if (primary->cacc.cycling_changeover &&
171 TSN_lt(tsn, primary->cacc.next_tsn_at_change))
172 return 1;
173 return 0;
174}
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190static inline int sctp_cacc_skip(struct sctp_transport *primary,
191 struct sctp_transport *transport,
192 int count_of_newacks,
193 __u32 tsn)
194{
195 if (primary->cacc.changeover_active &&
196 (sctp_cacc_skip_3_1(primary, transport, count_of_newacks) ||
197 sctp_cacc_skip_3_2(primary, tsn)))
198 return 1;
199 return 0;
200}
201
202
203
204
205
206void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
207{
208 q->asoc = asoc;
209 INIT_LIST_HEAD(&q->out_chunk_list);
210 INIT_LIST_HEAD(&q->control_chunk_list);
211 INIT_LIST_HEAD(&q->retransmit);
212 INIT_LIST_HEAD(&q->sacked);
213 INIT_LIST_HEAD(&q->abandoned);
214
215 q->fast_rtx = 0;
216 q->outstanding_bytes = 0;
217 q->empty = 1;
218 q->cork = 0;
219
220 q->malloced = 0;
221 q->out_qlen = 0;
222}
223
224
225
226void sctp_outq_teardown(struct sctp_outq *q)
227{
228 struct sctp_transport *transport;
229 struct list_head *lchunk, *temp;
230 struct sctp_chunk *chunk, *tmp;
231
232
233 list_for_each_entry(transport, &q->asoc->peer.transport_addr_list,
234 transports) {
235 while ((lchunk = sctp_list_dequeue(&transport->transmitted)) != NULL) {
236 chunk = list_entry(lchunk, struct sctp_chunk,
237 transmitted_list);
238
239 sctp_chunk_fail(chunk, q->error);
240 sctp_chunk_free(chunk);
241 }
242 }
243
244
245 list_for_each_safe(lchunk, temp, &q->sacked) {
246 list_del_init(lchunk);
247 chunk = list_entry(lchunk, struct sctp_chunk,
248 transmitted_list);
249 sctp_chunk_fail(chunk, q->error);
250 sctp_chunk_free(chunk);
251 }
252
253
254 list_for_each_safe(lchunk, temp, &q->retransmit) {
255 list_del_init(lchunk);
256 chunk = list_entry(lchunk, struct sctp_chunk,
257 transmitted_list);
258 sctp_chunk_fail(chunk, q->error);
259 sctp_chunk_free(chunk);
260 }
261
262
263 list_for_each_safe(lchunk, temp, &q->abandoned) {
264 list_del_init(lchunk);
265 chunk = list_entry(lchunk, struct sctp_chunk,
266 transmitted_list);
267 sctp_chunk_fail(chunk, q->error);
268 sctp_chunk_free(chunk);
269 }
270
271
272 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
273
274
275 sctp_chunk_fail(chunk, q->error);
276 sctp_chunk_free(chunk);
277 }
278
279 q->error = 0;
280
281
282 list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) {
283 list_del_init(&chunk->list);
284 sctp_chunk_free(chunk);
285 }
286}
287
288
289void sctp_outq_free(struct sctp_outq *q)
290{
291
292 sctp_outq_teardown(q);
293
294
295 if (q->malloced)
296 kfree(q);
297}
298
299
300int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
301{
302 int error = 0;
303
304 SCTP_DEBUG_PRINTK("sctp_outq_tail(%p, %p[%s])\n",
305 q, chunk, chunk && chunk->chunk_hdr ?
306 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
307 : "Illegal Chunk");
308
309
310
311
312 if (sctp_chunk_is_data(chunk)) {
313
314
315
316
317
318
319
320
321
322 switch (q->asoc->state) {
323 case SCTP_STATE_CLOSED:
324 case SCTP_STATE_SHUTDOWN_PENDING:
325 case SCTP_STATE_SHUTDOWN_SENT:
326 case SCTP_STATE_SHUTDOWN_RECEIVED:
327 case SCTP_STATE_SHUTDOWN_ACK_SENT:
328
329 error = -ESHUTDOWN;
330 break;
331
332 default:
333 SCTP_DEBUG_PRINTK("outqueueing (%p, %p[%s])\n",
334 q, chunk, chunk && chunk->chunk_hdr ?
335 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type))
336 : "Illegal Chunk");
337
338 sctp_outq_tail_data(q, chunk);
339 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
340 SCTP_INC_STATS(SCTP_MIB_OUTUNORDERCHUNKS);
341 else
342 SCTP_INC_STATS(SCTP_MIB_OUTORDERCHUNKS);
343 q->empty = 0;
344 break;
345 }
346 } else {
347 list_add_tail(&chunk->list, &q->control_chunk_list);
348 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
349 }
350
351 if (error < 0)
352 return error;
353
354 if (!q->cork)
355 error = sctp_outq_flush(q, 0);
356
357 return error;
358}
359
360
361
362
363static void sctp_insert_list(struct list_head *head, struct list_head *new)
364{
365 struct list_head *pos;
366 struct sctp_chunk *nchunk, *lchunk;
367 __u32 ntsn, ltsn;
368 int done = 0;
369
370 nchunk = list_entry(new, struct sctp_chunk, transmitted_list);
371 ntsn = ntohl(nchunk->subh.data_hdr->tsn);
372
373 list_for_each(pos, head) {
374 lchunk = list_entry(pos, struct sctp_chunk, transmitted_list);
375 ltsn = ntohl(lchunk->subh.data_hdr->tsn);
376 if (TSN_lt(ntsn, ltsn)) {
377 list_add(new, pos->prev);
378 done = 1;
379 break;
380 }
381 }
382 if (!done)
383 list_add_tail(new, head);
384}
385
386
387void 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
394
395 list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
396 chunk = list_entry(lchunk, struct sctp_chunk,
397 transmitted_list);
398
399
400 if (sctp_chunk_abandoned(chunk)) {
401 list_del_init(lchunk);
402 sctp_insert_list(&q->abandoned, lchunk);
403
404
405
406
407
408
409 if (!chunk->tsn_gap_acked) {
410 if (chunk->transport)
411 chunk->transport->flight_size -=
412 sctp_data_size(chunk);
413 q->outstanding_bytes -= sctp_data_size(chunk);
414 q->asoc->peer.rwnd += (sctp_data_size(chunk) +
415 sizeof(struct sk_buff));
416 }
417 continue;
418 }
419
420
421
422
423
424 if ((reason == SCTP_RTXR_FAST_RTX &&
425 (chunk->fast_retransmit == SCTP_NEED_FRTX)) ||
426 (reason != SCTP_RTXR_FAST_RTX && !chunk->tsn_gap_acked)) {
427
428
429
430
431
432
433
434
435 q->asoc->peer.rwnd += (sctp_data_size(chunk) +
436 sizeof(struct sk_buff));
437 q->outstanding_bytes -= sctp_data_size(chunk);
438 if (chunk->transport)
439 transport->flight_size -= sctp_data_size(chunk);
440
441
442
443
444
445
446 chunk->tsn_missing_report = 0;
447
448
449
450
451
452
453
454 if (chunk->rtt_in_progress) {
455 chunk->rtt_in_progress = 0;
456 transport->rto_pending = 0;
457 }
458
459
460
461
462 list_del_init(lchunk);
463 sctp_insert_list(&q->retransmit, lchunk);
464 }
465 }
466
467 SCTP_DEBUG_PRINTK("%s: transport: %p, reason: %d, "
468 "cwnd: %d, ssthresh: %d, flight_size: %d, "
469 "pba: %d\n", __func__,
470 transport, reason,
471 transport->cwnd, transport->ssthresh,
472 transport->flight_size,
473 transport->partial_bytes_acked);
474
475}
476
477
478
479
480void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
481 sctp_retransmit_reason_t reason)
482{
483 int error = 0;
484
485 switch(reason) {
486 case SCTP_RTXR_T3_RTX:
487 SCTP_INC_STATS(SCTP_MIB_T3_RETRANSMITS);
488 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
489
490
491
492 if (transport == transport->asoc->peer.retran_path)
493 sctp_assoc_update_retran_path(transport->asoc);
494 transport->asoc->rtx_data_chunks +=
495 transport->asoc->unack_data;
496 break;
497 case SCTP_RTXR_FAST_RTX:
498 SCTP_INC_STATS(SCTP_MIB_FAST_RETRANSMITS);
499 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
500 q->fast_rtx = 1;
501 break;
502 case SCTP_RTXR_PMTUD:
503 SCTP_INC_STATS(SCTP_MIB_PMTUD_RETRANSMITS);
504 break;
505 case SCTP_RTXR_T1_RTX:
506 SCTP_INC_STATS(SCTP_MIB_T1_RETRANSMITS);
507 transport->asoc->init_retries++;
508 break;
509 default:
510 BUG();
511 }
512
513 sctp_retransmit_mark(q, transport, reason);
514
515
516
517
518
519 if (reason == SCTP_RTXR_T3_RTX)
520 sctp_generate_fwdtsn(q, q->asoc->ctsn_ack_point);
521
522
523
524
525
526 if (reason != SCTP_RTXR_FAST_RTX)
527 error = sctp_outq_flush(q, 1);
528
529 if (error)
530 q->asoc->base.sk->sk_err = -error;
531}
532
533
534
535
536
537
538
539
540
541static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
542 int rtx_timeout, int *start_timer)
543{
544 struct list_head *lqueue;
545 struct sctp_transport *transport = pkt->transport;
546 sctp_xmit_t status;
547 struct sctp_chunk *chunk, *chunk1;
548 int fast_rtx;
549 int error = 0;
550 int timer = 0;
551 int done = 0;
552
553 lqueue = &q->retransmit;
554 fast_rtx = q->fast_rtx;
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579 list_for_each_entry_safe(chunk, chunk1, lqueue, transmitted_list) {
580
581 if (sctp_chunk_abandoned(chunk)) {
582 list_del_init(&chunk->transmitted_list);
583 sctp_insert_list(&q->abandoned,
584 &chunk->transmitted_list);
585 continue;
586 }
587
588
589
590
591
592
593 if (chunk->tsn_gap_acked) {
594 list_del(&chunk->transmitted_list);
595 list_add_tail(&chunk->transmitted_list,
596 &transport->transmitted);
597 continue;
598 }
599
600
601
602
603 if (fast_rtx && !chunk->fast_retransmit)
604 continue;
605
606redo:
607
608 status = sctp_packet_append_chunk(pkt, chunk);
609
610 switch (status) {
611 case SCTP_XMIT_PMTU_FULL:
612 if (!pkt->has_data && !pkt->has_cookie_echo) {
613
614
615
616
617
618
619 sctp_packet_transmit(pkt);
620 goto redo;
621 }
622
623
624 error = sctp_packet_transmit(pkt);
625
626
627
628
629
630 if (rtx_timeout || fast_rtx)
631 done = 1;
632 else
633 goto redo;
634
635
636 break;
637
638 case SCTP_XMIT_RWND_FULL:
639
640 error = sctp_packet_transmit(pkt);
641
642
643
644
645 done = 1;
646 break;
647
648 case SCTP_XMIT_NAGLE_DELAY:
649
650 error = sctp_packet_transmit(pkt);
651
652
653 done = 1;
654 break;
655
656 default:
657
658
659
660 list_del(&chunk->transmitted_list);
661 list_add_tail(&chunk->transmitted_list,
662 &transport->transmitted);
663
664
665
666
667 if (chunk->fast_retransmit == SCTP_NEED_FRTX)
668 chunk->fast_retransmit = SCTP_DONT_FRTX;
669
670 q->empty = 0;
671 break;
672 }
673
674
675 if (!error && !timer)
676 timer = 1;
677
678 if (done)
679 break;
680 }
681
682
683
684
685
686
687 if (rtx_timeout || fast_rtx) {
688 list_for_each_entry(chunk1, lqueue, transmitted_list) {
689 if (chunk1->fast_retransmit == SCTP_NEED_FRTX)
690 chunk1->fast_retransmit = SCTP_DONT_FRTX;
691 }
692 }
693
694 *start_timer = timer;
695
696
697 if (fast_rtx)
698 q->fast_rtx = 0;
699
700 return error;
701}
702
703
704int sctp_outq_uncork(struct sctp_outq *q)
705{
706 int error = 0;
707 if (q->cork)
708 q->cork = 0;
709 error = sctp_outq_flush(q, 0);
710 return error;
711}
712
713
714
715
716
717
718
719
720
721
722
723static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
724{
725 struct sctp_packet *packet;
726 struct sctp_packet singleton;
727 struct sctp_association *asoc = q->asoc;
728 __u16 sport = asoc->base.bind_addr.port;
729 __u16 dport = asoc->peer.port;
730 __u32 vtag = asoc->peer.i.init_tag;
731 struct sctp_transport *transport = NULL;
732 struct sctp_transport *new_transport;
733 struct sctp_chunk *chunk, *tmp;
734 sctp_xmit_t status;
735 int error = 0;
736 int start_timer = 0;
737 int one_packet = 0;
738
739
740 struct list_head transport_list;
741 struct list_head *ltransport;
742
743 INIT_LIST_HEAD(&transport_list);
744 packet = NULL;
745
746
747
748
749
750
751
752
753
754
755
756 list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) {
757 list_del_init(&chunk->list);
758
759
760 new_transport = chunk->transport;
761
762 if (!new_transport) {
763
764
765
766
767
768
769
770
771
772
773 if (transport &&
774 sctp_cmp_addr_exact(&chunk->dest,
775 &transport->ipaddr))
776 new_transport = transport;
777 else
778 new_transport = sctp_assoc_lookup_paddr(asoc,
779 &chunk->dest);
780
781
782
783
784 if (!new_transport)
785 new_transport = asoc->peer.active_path;
786 } else if ((new_transport->state == SCTP_INACTIVE) ||
787 (new_transport->state == SCTP_UNCONFIRMED)) {
788
789
790
791
792
793
794
795
796
797
798
799
800
801 if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT &&
802 chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT_ACK &&
803 chunk->chunk_hdr->type != SCTP_CID_ASCONF_ACK)
804 new_transport = asoc->peer.active_path;
805 }
806
807
808
809
810 if (new_transport != transport) {
811 transport = new_transport;
812 if (list_empty(&transport->send_ready)) {
813 list_add_tail(&transport->send_ready,
814 &transport_list);
815 }
816 packet = &transport->packet;
817 sctp_packet_config(packet, vtag,
818 asoc->peer.ecn_capable);
819 }
820
821 switch (chunk->chunk_hdr->type) {
822
823
824
825
826
827
828 case SCTP_CID_INIT:
829 case SCTP_CID_INIT_ACK:
830 case SCTP_CID_SHUTDOWN_COMPLETE:
831 sctp_packet_init(&singleton, transport, sport, dport);
832 sctp_packet_config(&singleton, vtag, 0);
833 sctp_packet_append_chunk(&singleton, chunk);
834 error = sctp_packet_transmit(&singleton);
835 if (error < 0)
836 return error;
837 break;
838
839 case SCTP_CID_ABORT:
840 if (sctp_test_T_bit(chunk)) {
841 packet->vtag = asoc->c.my_vtag;
842 }
843
844
845
846
847
848 case SCTP_CID_HEARTBEAT_ACK:
849 case SCTP_CID_SHUTDOWN_ACK:
850 case SCTP_CID_COOKIE_ACK:
851 case SCTP_CID_COOKIE_ECHO:
852 case SCTP_CID_ERROR:
853 case SCTP_CID_ECN_CWR:
854 case SCTP_CID_ASCONF_ACK:
855 one_packet = 1;
856
857
858 case SCTP_CID_SACK:
859 case SCTP_CID_HEARTBEAT:
860 case SCTP_CID_SHUTDOWN:
861 case SCTP_CID_ECN_ECNE:
862 case SCTP_CID_ASCONF:
863 case SCTP_CID_FWD_TSN:
864 status = sctp_packet_transmit_chunk(packet, chunk,
865 one_packet);
866 if (status != SCTP_XMIT_OK) {
867
868 list_add(&chunk->list, &q->control_chunk_list);
869 } else if (chunk->chunk_hdr->type == SCTP_CID_FWD_TSN) {
870
871
872
873
874 sctp_transport_reset_timers(transport);
875 }
876 break;
877
878 default:
879
880 BUG();
881 }
882 }
883
884
885 switch (asoc->state) {
886 case SCTP_STATE_COOKIE_ECHOED:
887
888
889
890 if (!packet || !packet->has_cookie_echo)
891 break;
892
893
894 case SCTP_STATE_ESTABLISHED:
895 case SCTP_STATE_SHUTDOWN_PENDING:
896 case SCTP_STATE_SHUTDOWN_RECEIVED:
897
898
899
900
901
902
903
904
905
906 if (!list_empty(&q->retransmit)) {
907 if (transport == asoc->peer.retran_path)
908 goto retran;
909
910
911
912 transport = asoc->peer.retran_path;
913
914 if (list_empty(&transport->send_ready)) {
915 list_add_tail(&transport->send_ready,
916 &transport_list);
917 }
918
919 packet = &transport->packet;
920 sctp_packet_config(packet, vtag,
921 asoc->peer.ecn_capable);
922 retran:
923 error = sctp_outq_flush_rtx(q, packet,
924 rtx_timeout, &start_timer);
925
926 if (start_timer)
927 sctp_transport_reset_timers(transport);
928
929
930
931
932 if (packet->has_cookie_echo)
933 goto sctp_flush_out;
934
935
936
937
938 if (!list_empty(&q->retransmit))
939 goto sctp_flush_out;
940 }
941
942
943
944
945
946
947 if (transport)
948 sctp_transport_burst_limited(transport);
949
950
951 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
952
953
954
955 if (chunk->sinfo.sinfo_stream >=
956 asoc->c.sinit_num_ostreams) {
957
958
959 sctp_chunk_fail(chunk, SCTP_ERROR_INV_STRM);
960 sctp_chunk_free(chunk);
961 continue;
962 }
963
964
965 if (sctp_chunk_abandoned(chunk)) {
966 sctp_chunk_fail(chunk, 0);
967 sctp_chunk_free(chunk);
968 continue;
969 }
970
971
972
973
974 new_transport = chunk->transport;
975 if (!new_transport ||
976 ((new_transport->state == SCTP_INACTIVE) ||
977 (new_transport->state == SCTP_UNCONFIRMED)))
978 new_transport = asoc->peer.active_path;
979
980
981 if (new_transport != transport) {
982 transport = new_transport;
983
984
985
986
987 if (list_empty(&transport->send_ready)) {
988 list_add_tail(&transport->send_ready,
989 &transport_list);
990 }
991
992 packet = &transport->packet;
993 sctp_packet_config(packet, vtag,
994 asoc->peer.ecn_capable);
995
996
997
998 sctp_transport_burst_limited(transport);
999 }
1000
1001 SCTP_DEBUG_PRINTK("sctp_outq_flush(%p, %p[%s]), ",
1002 q, chunk,
1003 chunk && chunk->chunk_hdr ?
1004 sctp_cname(SCTP_ST_CHUNK(
1005 chunk->chunk_hdr->type))
1006 : "Illegal Chunk");
1007
1008 SCTP_DEBUG_PRINTK("TX TSN 0x%x skb->head "
1009 "%p skb->users %d.\n",
1010 ntohl(chunk->subh.data_hdr->tsn),
1011 chunk->skb ?chunk->skb->head : NULL,
1012 chunk->skb ?
1013 atomic_read(&chunk->skb->users) : -1);
1014
1015
1016 status = sctp_packet_transmit_chunk(packet, chunk, 0);
1017
1018 switch (status) {
1019 case SCTP_XMIT_PMTU_FULL:
1020 case SCTP_XMIT_RWND_FULL:
1021 case SCTP_XMIT_NAGLE_DELAY:
1022
1023
1024
1025 SCTP_DEBUG_PRINTK("sctp_outq_flush: could "
1026 "not transmit TSN: 0x%x, status: %d\n",
1027 ntohl(chunk->subh.data_hdr->tsn),
1028 status);
1029 sctp_outq_head_data(q, chunk);
1030 goto sctp_flush_out;
1031 break;
1032
1033 case SCTP_XMIT_OK:
1034
1035
1036
1037
1038 if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
1039 chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
1040
1041 break;
1042
1043 default:
1044 BUG();
1045 }
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057 list_add_tail(&chunk->transmitted_list,
1058 &transport->transmitted);
1059
1060 sctp_transport_reset_timers(transport);
1061
1062 q->empty = 0;
1063
1064
1065
1066
1067 if (packet->has_cookie_echo)
1068 goto sctp_flush_out;
1069 }
1070 break;
1071
1072 default:
1073
1074 break;
1075 }
1076
1077sctp_flush_out:
1078
1079
1080
1081
1082
1083
1084
1085
1086 while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL ) {
1087 struct sctp_transport *t = list_entry(ltransport,
1088 struct sctp_transport,
1089 send_ready);
1090 packet = &t->packet;
1091 if (!sctp_packet_empty(packet))
1092 error = sctp_packet_transmit(packet);
1093
1094
1095 sctp_transport_burst_reset(t);
1096 }
1097
1098 return error;
1099}
1100
1101
1102static void sctp_sack_update_unack_data(struct sctp_association *assoc,
1103 struct sctp_sackhdr *sack)
1104{
1105 sctp_sack_variable_t *frags;
1106 __u16 unack_data;
1107 int i;
1108
1109 unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
1110
1111 frags = sack->variable;
1112 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
1113 unack_data -= ((ntohs(frags[i].gab.end) -
1114 ntohs(frags[i].gab.start) + 1));
1115 }
1116
1117 assoc->unack_data = unack_data;
1118}
1119
1120
1121
1122
1123
1124
1125int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack)
1126{
1127 struct sctp_association *asoc = q->asoc;
1128 struct sctp_transport *transport;
1129 struct sctp_chunk *tchunk = NULL;
1130 struct list_head *lchunk, *transport_list, *temp;
1131 sctp_sack_variable_t *frags = sack->variable;
1132 __u32 sack_ctsn, ctsn, tsn;
1133 __u32 highest_tsn, highest_new_tsn;
1134 __u32 sack_a_rwnd;
1135 unsigned outstanding;
1136 struct sctp_transport *primary = asoc->peer.primary_path;
1137 int count_of_newacks = 0;
1138 int gap_ack_blocks;
1139 u8 accum_moved = 0;
1140
1141
1142 transport_list = &asoc->peer.transport_addr_list;
1143
1144 sack_ctsn = ntohl(sack->cum_tsn_ack);
1145 gap_ack_blocks = ntohs(sack->num_gap_ack_blocks);
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164 if (primary->cacc.changeover_active) {
1165 u8 clear_cycling = 0;
1166
1167 if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
1168 primary->cacc.changeover_active = 0;
1169 clear_cycling = 1;
1170 }
1171
1172 if (clear_cycling || gap_ack_blocks) {
1173 list_for_each_entry(transport, transport_list,
1174 transports) {
1175 if (clear_cycling)
1176 transport->cacc.cycling_changeover = 0;
1177 if (gap_ack_blocks)
1178 transport->cacc.cacc_saw_newack = 0;
1179 }
1180 }
1181 }
1182
1183
1184 highest_tsn = sack_ctsn;
1185 if (gap_ack_blocks)
1186 highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);
1187
1188 if (TSN_lt(asoc->highest_sacked, highest_tsn))
1189 asoc->highest_sacked = highest_tsn;
1190
1191 highest_new_tsn = sack_ctsn;
1192
1193
1194
1195
1196 sctp_check_transmitted(q, &q->retransmit, NULL, sack, &highest_new_tsn);
1197
1198
1199
1200
1201
1202
1203 list_for_each_entry(transport, transport_list, transports) {
1204 sctp_check_transmitted(q, &transport->transmitted,
1205 transport, sack, &highest_new_tsn);
1206
1207
1208
1209
1210
1211 if (transport->cacc.cacc_saw_newack)
1212 count_of_newacks ++;
1213 }
1214
1215
1216 if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn)) {
1217 asoc->ctsn_ack_point = sack_ctsn;
1218 accum_moved = 1;
1219 }
1220
1221 if (gap_ack_blocks) {
1222
1223 if (asoc->fast_recovery && accum_moved)
1224 highest_new_tsn = highest_tsn;
1225
1226 list_for_each_entry(transport, transport_list, transports)
1227 sctp_mark_missing(q, &transport->transmitted, transport,
1228 highest_new_tsn, count_of_newacks);
1229 }
1230
1231
1232 sctp_sack_update_unack_data(asoc, sack);
1233
1234 ctsn = asoc->ctsn_ack_point;
1235
1236
1237 list_for_each_safe(lchunk, temp, &q->sacked) {
1238 tchunk = list_entry(lchunk, struct sctp_chunk,
1239 transmitted_list);
1240 tsn = ntohl(tchunk->subh.data_hdr->tsn);
1241 if (TSN_lte(tsn, ctsn)) {
1242 list_del_init(&tchunk->transmitted_list);
1243 sctp_chunk_free(tchunk);
1244 }
1245 }
1246
1247
1248
1249
1250
1251
1252 sack_a_rwnd = ntohl(sack->a_rwnd);
1253 outstanding = q->outstanding_bytes;
1254
1255 if (outstanding < sack_a_rwnd)
1256 sack_a_rwnd -= outstanding;
1257 else
1258 sack_a_rwnd = 0;
1259
1260 asoc->peer.rwnd = sack_a_rwnd;
1261
1262 sctp_generate_fwdtsn(q, sack_ctsn);
1263
1264 SCTP_DEBUG_PRINTK("%s: sack Cumulative TSN Ack is 0x%x.\n",
1265 __func__, sack_ctsn);
1266 SCTP_DEBUG_PRINTK("%s: Cumulative TSN Ack of association, "
1267 "%p is 0x%x. Adv peer ack point: 0x%x\n",
1268 __func__, asoc, ctsn, asoc->adv_peer_ack_point);
1269
1270
1271
1272
1273 q->empty = (list_empty(&q->out_chunk_list) &&
1274 list_empty(&q->retransmit));
1275 if (!q->empty)
1276 goto finish;
1277
1278 list_for_each_entry(transport, transport_list, transports) {
1279 q->empty = q->empty && list_empty(&transport->transmitted);
1280 if (!q->empty)
1281 goto finish;
1282 }
1283
1284 SCTP_DEBUG_PRINTK("sack queue is empty.\n");
1285finish:
1286 return q->empty;
1287}
1288
1289
1290int sctp_outq_is_empty(const struct sctp_outq *q)
1291{
1292 return q->empty;
1293}
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309static void sctp_check_transmitted(struct sctp_outq *q,
1310 struct list_head *transmitted_queue,
1311 struct sctp_transport *transport,
1312 struct sctp_sackhdr *sack,
1313 __u32 *highest_new_tsn_in_sack)
1314{
1315 struct list_head *lchunk;
1316 struct sctp_chunk *tchunk;
1317 struct list_head tlist;
1318 __u32 tsn;
1319 __u32 sack_ctsn;
1320 __u32 rtt;
1321 __u8 restart_timer = 0;
1322 int bytes_acked = 0;
1323 int migrate_bytes = 0;
1324
1325
1326
1327#if SCTP_DEBUG
1328 __u32 dbg_ack_tsn = 0;
1329 __u32 dbg_last_ack_tsn = 0;
1330 __u32 dbg_kept_tsn = 0;
1331 __u32 dbg_last_kept_tsn = 0;
1332
1333
1334
1335
1336
1337 int dbg_prt_state = -1;
1338#endif
1339
1340 sack_ctsn = ntohl(sack->cum_tsn_ack);
1341
1342 INIT_LIST_HEAD(&tlist);
1343
1344
1345 while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
1346 tchunk = list_entry(lchunk, struct sctp_chunk,
1347 transmitted_list);
1348
1349 if (sctp_chunk_abandoned(tchunk)) {
1350
1351 sctp_insert_list(&q->abandoned, lchunk);
1352
1353
1354
1355
1356 if (!tchunk->tsn_gap_acked) {
1357 if (tchunk->transport)
1358 tchunk->transport->flight_size -=
1359 sctp_data_size(tchunk);
1360 q->outstanding_bytes -= sctp_data_size(tchunk);
1361 }
1362 continue;
1363 }
1364
1365 tsn = ntohl(tchunk->subh.data_hdr->tsn);
1366 if (sctp_acked(sack, tsn)) {
1367
1368
1369
1370
1371
1372 if (transport) {
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384 if (!tchunk->tsn_gap_acked &&
1385 tchunk->rtt_in_progress) {
1386 tchunk->rtt_in_progress = 0;
1387 rtt = jiffies - tchunk->sent_at;
1388 sctp_transport_update_rto(transport,
1389 rtt);
1390 }
1391 }
1392
1393
1394
1395
1396
1397
1398
1399 if (!tchunk->tsn_gap_acked) {
1400 tchunk->tsn_gap_acked = 1;
1401 *highest_new_tsn_in_sack = tsn;
1402 bytes_acked += sctp_data_size(tchunk);
1403 if (!tchunk->transport)
1404 migrate_bytes += sctp_data_size(tchunk);
1405 }
1406
1407 if (TSN_lte(tsn, sack_ctsn)) {
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417 restart_timer = 1;
1418
1419 if (!tchunk->tsn_gap_acked) {
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433 if (transport &&
1434 sack->num_gap_ack_blocks &&
1435 q->asoc->peer.primary_path->cacc.
1436 changeover_active)
1437 transport->cacc.cacc_saw_newack
1438 = 1;
1439 }
1440
1441 list_add_tail(&tchunk->transmitted_list,
1442 &q->sacked);
1443 } else {
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459 list_add_tail(lchunk, &tlist);
1460 }
1461
1462#if SCTP_DEBUG
1463 switch (dbg_prt_state) {
1464 case 0:
1465 if (dbg_last_ack_tsn + 1 == tsn) {
1466
1467
1468
1469 break;
1470 }
1471
1472 if (dbg_last_ack_tsn != dbg_ack_tsn) {
1473
1474
1475
1476 SCTP_DEBUG_PRINTK_CONT("-%08x",
1477 dbg_last_ack_tsn);
1478 }
1479
1480
1481 SCTP_DEBUG_PRINTK_CONT(",%08x", tsn);
1482 dbg_ack_tsn = tsn;
1483 break;
1484
1485 case 1:
1486 if (dbg_last_kept_tsn != dbg_kept_tsn) {
1487
1488 SCTP_DEBUG_PRINTK_CONT("-%08x",
1489 dbg_last_kept_tsn);
1490 }
1491
1492 SCTP_DEBUG_PRINTK_CONT("\n");
1493
1494
1495 default:
1496
1497
1498 SCTP_DEBUG_PRINTK("ACKed: %08x", tsn);
1499 dbg_prt_state = 0;
1500 dbg_ack_tsn = tsn;
1501 }
1502
1503 dbg_last_ack_tsn = tsn;
1504#endif
1505
1506 } else {
1507 if (tchunk->tsn_gap_acked) {
1508 SCTP_DEBUG_PRINTK("%s: Receiver reneged on "
1509 "data TSN: 0x%x\n",
1510 __func__,
1511 tsn);
1512 tchunk->tsn_gap_acked = 0;
1513
1514 if (tchunk->transport)
1515 bytes_acked -= sctp_data_size(tchunk);
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526 restart_timer = 1;
1527 }
1528
1529 list_add_tail(lchunk, &tlist);
1530
1531#if SCTP_DEBUG
1532
1533 switch (dbg_prt_state) {
1534 case 1:
1535 if (dbg_last_kept_tsn + 1 == tsn)
1536 break;
1537
1538 if (dbg_last_kept_tsn != dbg_kept_tsn)
1539 SCTP_DEBUG_PRINTK_CONT("-%08x",
1540 dbg_last_kept_tsn);
1541
1542 SCTP_DEBUG_PRINTK_CONT(",%08x", tsn);
1543 dbg_kept_tsn = tsn;
1544 break;
1545
1546 case 0:
1547 if (dbg_last_ack_tsn != dbg_ack_tsn)
1548 SCTP_DEBUG_PRINTK_CONT("-%08x",
1549 dbg_last_ack_tsn);
1550 SCTP_DEBUG_PRINTK_CONT("\n");
1551
1552
1553 default:
1554 SCTP_DEBUG_PRINTK("KEPT: %08x",tsn);
1555 dbg_prt_state = 1;
1556 dbg_kept_tsn = tsn;
1557 }
1558
1559 dbg_last_kept_tsn = tsn;
1560#endif
1561 }
1562 }
1563
1564#if SCTP_DEBUG
1565
1566 switch (dbg_prt_state) {
1567 case 0:
1568 if (dbg_last_ack_tsn != dbg_ack_tsn) {
1569 SCTP_DEBUG_PRINTK_CONT("-%08x\n", dbg_last_ack_tsn);
1570 } else {
1571 SCTP_DEBUG_PRINTK_CONT("\n");
1572 }
1573 break;
1574
1575 case 1:
1576 if (dbg_last_kept_tsn != dbg_kept_tsn) {
1577 SCTP_DEBUG_PRINTK_CONT("-%08x\n", dbg_last_kept_tsn);
1578 } else {
1579 SCTP_DEBUG_PRINTK_CONT("\n");
1580 }
1581 }
1582#endif
1583 if (transport) {
1584 if (bytes_acked) {
1585 struct sctp_association *asoc = transport->asoc;
1586
1587
1588
1589
1590
1591
1592
1593 bytes_acked -= migrate_bytes;
1594
1595
1596
1597
1598
1599
1600
1601
1602 transport->error_count = 0;
1603 transport->asoc->overall_error_count = 0;
1604
1605
1606
1607
1608
1609
1610
1611 if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING &&
1612 del_timer(&asoc->timers
1613 [SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]))
1614 sctp_association_put(asoc);
1615
1616
1617
1618
1619 if ((transport->state == SCTP_INACTIVE) ||
1620 (transport->state == SCTP_UNCONFIRMED)) {
1621 sctp_assoc_control_transport(
1622 transport->asoc,
1623 transport,
1624 SCTP_TRANSPORT_UP,
1625 SCTP_RECEIVED_SACK);
1626 }
1627
1628 sctp_transport_raise_cwnd(transport, sack_ctsn,
1629 bytes_acked);
1630
1631 transport->flight_size -= bytes_acked;
1632 if (transport->flight_size == 0)
1633 transport->partial_bytes_acked = 0;
1634 q->outstanding_bytes -= bytes_acked + migrate_bytes;
1635 } else {
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650 if (!q->asoc->peer.rwnd &&
1651 !list_empty(&tlist) &&
1652 (sack_ctsn+2 == q->asoc->next_tsn) &&
1653 q->asoc->state < SCTP_STATE_SHUTDOWN_PENDING) {
1654 SCTP_DEBUG_PRINTK("%s: SACK received for zero "
1655 "window probe: %u\n",
1656 __func__, sack_ctsn);
1657 q->asoc->overall_error_count = 0;
1658 transport->error_count = 0;
1659 }
1660 }
1661
1662
1663
1664
1665
1666
1667
1668 if (!transport->flight_size) {
1669 if (timer_pending(&transport->T3_rtx_timer) &&
1670 del_timer(&transport->T3_rtx_timer)) {
1671 sctp_transport_put(transport);
1672 }
1673 } else if (restart_timer) {
1674 if (!mod_timer(&transport->T3_rtx_timer,
1675 jiffies + transport->rto))
1676 sctp_transport_hold(transport);
1677 }
1678 }
1679
1680 list_splice(&tlist, transmitted_queue);
1681}
1682
1683
1684static void sctp_mark_missing(struct sctp_outq *q,
1685 struct list_head *transmitted_queue,
1686 struct sctp_transport *transport,
1687 __u32 highest_new_tsn_in_sack,
1688 int count_of_newacks)
1689{
1690 struct sctp_chunk *chunk;
1691 __u32 tsn;
1692 char do_fast_retransmit = 0;
1693 struct sctp_association *asoc = q->asoc;
1694 struct sctp_transport *primary = asoc->peer.primary_path;
1695
1696 list_for_each_entry(chunk, transmitted_queue, transmitted_list) {
1697
1698 tsn = ntohl(chunk->subh.data_hdr->tsn);
1699
1700
1701
1702
1703
1704
1705
1706
1707 if (chunk->fast_retransmit == SCTP_CAN_FRTX &&
1708 !chunk->tsn_gap_acked &&
1709 TSN_lt(tsn, highest_new_tsn_in_sack)) {
1710
1711
1712
1713
1714 if (!transport || !sctp_cacc_skip(primary,
1715 chunk->transport,
1716 count_of_newacks, tsn)) {
1717 chunk->tsn_missing_report++;
1718
1719 SCTP_DEBUG_PRINTK(
1720 "%s: TSN 0x%x missing counter: %d\n",
1721 __func__, tsn,
1722 chunk->tsn_missing_report);
1723 }
1724 }
1725
1726
1727
1728
1729
1730
1731
1732 if (chunk->tsn_missing_report >= 3) {
1733 chunk->fast_retransmit = SCTP_NEED_FRTX;
1734 do_fast_retransmit = 1;
1735 }
1736 }
1737
1738 if (transport) {
1739 if (do_fast_retransmit)
1740 sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
1741
1742 SCTP_DEBUG_PRINTK("%s: transport: %p, cwnd: %d, "
1743 "ssthresh: %d, flight_size: %d, pba: %d\n",
1744 __func__, transport, transport->cwnd,
1745 transport->ssthresh, transport->flight_size,
1746 transport->partial_bytes_acked);
1747 }
1748}
1749
1750
1751static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
1752{
1753 int i;
1754 sctp_sack_variable_t *frags;
1755 __u16 gap;
1756 __u32 ctsn = ntohl(sack->cum_tsn_ack);
1757
1758 if (TSN_lte(tsn, ctsn))
1759 goto pass;
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773 frags = sack->variable;
1774 gap = tsn - ctsn;
1775 for (i = 0; i < ntohs(sack->num_gap_ack_blocks); ++i) {
1776 if (TSN_lte(ntohs(frags[i].gab.start), gap) &&
1777 TSN_lte(gap, ntohs(frags[i].gab.end)))
1778 goto pass;
1779 }
1780
1781 return 0;
1782pass:
1783 return 1;
1784}
1785
1786static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist,
1787 int nskips, __be16 stream)
1788{
1789 int i;
1790
1791 for (i = 0; i < nskips; i++) {
1792 if (skiplist[i].stream == stream)
1793 return i;
1794 }
1795 return i;
1796}
1797
1798
1799static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
1800{
1801 struct sctp_association *asoc = q->asoc;
1802 struct sctp_chunk *ftsn_chunk = NULL;
1803 struct sctp_fwdtsn_skip ftsn_skip_arr[10];
1804 int nskips = 0;
1805 int skip_pos = 0;
1806 __u32 tsn;
1807 struct sctp_chunk *chunk;
1808 struct list_head *lchunk, *temp;
1809
1810 if (!asoc->peer.prsctp_capable)
1811 return;
1812
1813
1814
1815
1816
1817
1818
1819 if (TSN_lt(asoc->adv_peer_ack_point, ctsn))
1820 asoc->adv_peer_ack_point = ctsn;
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843 list_for_each_safe(lchunk, temp, &q->abandoned) {
1844 chunk = list_entry(lchunk, struct sctp_chunk,
1845 transmitted_list);
1846 tsn = ntohl(chunk->subh.data_hdr->tsn);
1847
1848
1849
1850
1851 if (TSN_lte(tsn, ctsn)) {
1852 list_del_init(lchunk);
1853 sctp_chunk_free(chunk);
1854 } else {
1855 if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
1856 asoc->adv_peer_ack_point = tsn;
1857 if (chunk->chunk_hdr->flags &
1858 SCTP_DATA_UNORDERED)
1859 continue;
1860 skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0],
1861 nskips,
1862 chunk->subh.data_hdr->stream);
1863 ftsn_skip_arr[skip_pos].stream =
1864 chunk->subh.data_hdr->stream;
1865 ftsn_skip_arr[skip_pos].ssn =
1866 chunk->subh.data_hdr->ssn;
1867 if (skip_pos == nskips)
1868 nskips++;
1869 if (nskips == 10)
1870 break;
1871 } else
1872 break;
1873 }
1874 }
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894 if (asoc->adv_peer_ack_point > ctsn)
1895 ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point,
1896 nskips, &ftsn_skip_arr[0]);
1897
1898 if (ftsn_chunk) {
1899 list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
1900 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1901 }
1902}
1903