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