50 static void StreamTcpSackPrintList(
TcpStream *stream)
96 SCLogDebug(
"-> (fwd) tr %p %u/%u REMOVED ECLIPSED2", tr, tr->
le, tr->
re);
97 TCPSACK_RB_REMOVE(tree, tr);
98 StreamTcpSackRecordFree(tr);
108 SCLogDebug(
"-> (fwd) tr %p %u/%u REMOVED ECLIPSED", tr, tr->
le, tr->
re);
110 TCPSACK_RB_REMOVE(tree, tr);
111 StreamTcpSackRecordFree(tr);
126 SCLogDebug(
"-> (fwd) tr %p %u/%u REMOVED MERGED", tr, tr->
le, tr->
re);
127 TCPSACK_RB_REMOVE(tree, tr);
128 StreamTcpSackRecordFree(tr);
133 static inline void ConsolidateBackward(
TcpStream *stream,
150 SCLogDebug(
"-> (bwd) tr %p %u/%u REMOVED ECLIPSED2", tr, tr->
le, tr->
re);
151 TCPSACK_RB_REMOVE(tree, tr);
152 StreamTcpSackRecordFree(tr);
162 SCLogDebug(
"-> (bwd) tr %p %u/%u REMOVED ECLIPSED", tr, tr->
le, tr->
re);
164 TCPSACK_RB_REMOVE(tree, tr);
165 StreamTcpSackRecordFree(tr);
178 SCLogDebug(
"-> (bwd) tr %p %u/%u REMOVED MERGED", tr, tr->
le, tr->
re);
179 TCPSACK_RB_REMOVE(tree, tr);
180 StreamTcpSackRecordFree(tr);
185 static int Insert(
TcpStream *stream,
struct TCPSACK *tree, uint32_t
le, uint32_t
re)
197 SCLogDebug(
"* insert failed: exact match in tree with %p %u/%u", res, res->
le, res->
re);
198 StreamTcpSackRecordFree(sa);
202 ConsolidateBackward(stream, tree, sa);
203 ConsolidateFwd(stream, tree, sa);
216 static int StreamTcpSackInsertRange(
TcpStream *stream, uint32_t
le, uint32_t
re)
220 StreamTcpSackPrintList(stream);
253 const TCPHdr *tcph = PacketGetTCP(p);
257 if (records == 0 || data == NULL)
263 uint32_t first_le = 0;
264 uint32_t first_re = 0;
266 for (
int record = 0; record < records; record++) {
275 SCLogDebug(
"%p last_ack %u, left edge %u, right edge %u pkt ACK %u", sack_rec,
284 }
else if (record == 1) {
286 SCLogDebug(
"packet: %" PRIu64
": D-SACK? %u-%u inside 2nd range %u-%u ACK %u",
309 if (StreamTcpSackInsertRange(stream,
le,
re) == -1) {
318 StreamTcpSackPrintList(stream);
323 static inline int CompareOverlap(
326 if (lookup->
re <= intree->
le)
328 else if (lookup->
re >= intree->
le && lookup->
le < intree->
re)
343 const int comp = CompareOverlap(elm, tmp);
348 }
else if (comp > 0) {
359 const TCPHdr *tcph = PacketGetTCP(p);
362 if (records > 0 && data != NULL) {
363 int sack_outdated = 0;
366 for (
int record = 0; record < records; record++) {
376 if (
le >= res->
le && re <= res->
re) {
377 SCLogDebug(
"SACK rec le:%u re:%u eclipsed by in tree le:%u re:%u",
le,
re,
381 SCLogDebug(
"SACK rec le:%u re:%u SACKs new DATA vs in tree le:%u re:%u",
le,
re,
385 SCLogDebug(
"SACK rec le:%u re:%u SACKs new DATA. No match in tree",
le,
re);
390 StreamTcpSackPrintList(stream);
392 if (records != sack_outdated) {
412 TCPSACK_RB_REMOVE(&stream->
sack_tree, rec);
413 StreamTcpSackRecordFree(rec);
423 SCLogDebug(
"record beyond last_ack, nothing to do. Bailing out.");
428 StreamTcpSackPrintList(stream);
445 TCPSACK_RB_REMOVE(&stream->
sack_tree, rec);
446 StreamTcpSackRecordFree(rec);
461 static int StreamTcpSackTest01 (
void)
464 memset(&stream, 0,
sizeof(stream));
467 StreamTcpSackInsertRange(&stream, 1, 10);
469 StreamTcpSackInsertRange(&stream, 10, 20);
471 StreamTcpSackInsertRange(&stream, 10, 20);
473 StreamTcpSackInsertRange(&stream, 1, 20);
476 StreamTcpSackPrintList(&stream);
485 FAIL_IF(StreamTcpSackedSize(&stream) != 19);
496 static int StreamTcpSackTest02 (
void)
499 memset(&stream, 0,
sizeof(stream));
502 StreamTcpSackInsertRange(&stream, 10, 20);
503 StreamTcpSackInsertRange(&stream, 1, 20);
505 StreamTcpSackPrintList(&stream);
514 FAIL_IF(StreamTcpSackedSize(&stream) != 19);
525 static int StreamTcpSackTest03 (
void)
528 memset(&stream, 0,
sizeof(stream));
531 StreamTcpSackInsertRange(&stream, 10, 20);
532 StreamTcpSackInsertRange(&stream, 5, 15);
534 StreamTcpSackPrintList(&stream);
536 StreamTcpSackInsertRange(&stream, 15, 25);
538 StreamTcpSackPrintList(&stream);
547 FAIL_IF(StreamTcpSackedSize(&stream) != 20);
558 static int StreamTcpSackTest04 (
void)
561 memset(&stream, 0,
sizeof(stream));
564 StreamTcpSackInsertRange(&stream, 0, 20);
565 StreamTcpSackInsertRange(&stream, 30, 50);
566 StreamTcpSackInsertRange(&stream, 10, 25);
568 StreamTcpSackPrintList(&stream);
577 FAIL_IF(StreamTcpSackedSize(&stream) != 45);
588 static int StreamTcpSackTest05 (
void)
591 memset(&stream, 0,
sizeof(stream));
594 StreamTcpSackInsertRange(&stream, 0, 20);
595 StreamTcpSackInsertRange(&stream, 30, 50);
596 StreamTcpSackInsertRange(&stream, 10, 35);
598 StreamTcpSackPrintList(&stream);
607 FAIL_IF(StreamTcpSackedSize(&stream) != 50);
618 static int StreamTcpSackTest06 (
void)
621 memset(&stream, 0,
sizeof(stream));
624 StreamTcpSackInsertRange(&stream, 0, 9);
625 StreamTcpSackInsertRange(&stream, 11, 19);
626 StreamTcpSackInsertRange(&stream, 21, 29);
627 StreamTcpSackInsertRange(&stream, 31, 39);
628 StreamTcpSackInsertRange(&stream, 0, 40);
630 StreamTcpSackPrintList(&stream);
639 FAIL_IF(StreamTcpSackedSize(&stream) != 40);
650 static int StreamTcpSackTest07 (
void)
653 memset(&stream, 0,
sizeof(stream));
656 StreamTcpSackInsertRange(&stream, 0, 9);
657 StreamTcpSackInsertRange(&stream, 11, 19);
658 StreamTcpSackInsertRange(&stream, 21, 29);
659 StreamTcpSackInsertRange(&stream, 31, 39);
660 StreamTcpSackInsertRange(&stream, 0, 40);
662 StreamTcpSackPrintList(&stream);
669 FAIL_IF(StreamTcpSackedSize(&stream) != 40);
673 FAIL_IF(StreamTcpSackedSize(&stream) != 30);
685 static int StreamTcpSackTest08 (
void)
688 memset(&stream, 0,
sizeof(stream));
691 StreamTcpSackInsertRange(&stream, 0, 9);
692 StreamTcpSackInsertRange(&stream, 11, 19);
693 StreamTcpSackInsertRange(&stream, 21, 29);
694 StreamTcpSackInsertRange(&stream, 31, 39);
695 StreamTcpSackInsertRange(&stream, 0, 40);
697 StreamTcpSackPrintList(&stream);
704 FAIL_IF(StreamTcpSackedSize(&stream) != 40);
708 FAIL_IF(StreamTcpSackedSize(&stream) != 0);
720 static int StreamTcpSackTest09 (
void)
723 memset(&stream, 0,
sizeof(stream));
726 StreamTcpSackInsertRange(&stream, 0, 9);
727 StreamTcpSackInsertRange(&stream, 11, 19);
728 StreamTcpSackInsertRange(&stream, 21, 29);
729 StreamTcpSackInsertRange(&stream, 31, 39);
730 StreamTcpSackInsertRange(&stream, 0, 40);
733 StreamTcpSackPrintList(&stream);
740 FAIL_IF(StreamTcpSackedSize(&stream) != 40);
744 FAIL_IF(StreamTcpSackedSize(&stream) != 1);
756 static int StreamTcpSackTest10 (
void)
759 memset(&stream, 0,
sizeof(stream));
762 StreamTcpSackInsertRange(&stream, 100, 119);
763 StreamTcpSackInsertRange(&stream, 111, 119);
764 StreamTcpSackInsertRange(&stream, 121, 129);
765 StreamTcpSackInsertRange(&stream, 131, 139);
766 StreamTcpSackInsertRange(&stream, 100, 140);
768 StreamTcpSackPrintList(&stream);
775 FAIL_IF(StreamTcpSackedSize(&stream) != 40);
779 FAIL_IF(StreamTcpSackedSize(&stream) != 40);
791 static int StreamTcpSackTest11 (
void)
794 memset(&stream, 0,
sizeof(stream));
797 StreamTcpSackInsertRange(&stream, 100, 119);
798 StreamTcpSackInsertRange(&stream, 111, 119);
799 StreamTcpSackInsertRange(&stream, 121, 129);
800 StreamTcpSackInsertRange(&stream, 131, 139);
801 StreamTcpSackInsertRange(&stream, 101, 140);
803 StreamTcpSackPrintList(&stream);
810 FAIL_IF(StreamTcpSackedSize(&stream) != 40);
814 FAIL_IF(StreamTcpSackedSize(&stream) != 40);
826 static int StreamTcpSackTest12 (
void)
829 memset(&stream, 0,
sizeof(stream));
832 StreamTcpSackInsertRange(&stream, 800, 1000);
833 StreamTcpSackInsertRange(&stream, 700, 900);
834 StreamTcpSackInsertRange(&stream, 600, 800);
835 StreamTcpSackInsertRange(&stream, 500, 700);
836 StreamTcpSackInsertRange(&stream, 100, 600);
838 StreamTcpSackPrintList(&stream);
845 FAIL_IF(StreamTcpSackedSize(&stream) != 900);
847 StreamTcpSackInsertRange(&stream, 0, 1000);
848 FAIL_IF(StreamTcpSackedSize(&stream) != 1000);
852 FAIL_IF(StreamTcpSackedSize(&stream) != 500);
864 static int StreamTcpSackTest13 (
void) {
866 memset(&stream, 0,
sizeof(stream));
870 for (
int i = 0; i < 10; i++) {
871 StreamTcpSackInsertRange(&stream, 100+(20*i), 110+(20*i));
874 StreamTcpSackPrintList(&stream);
877 FAIL_IF(StreamTcpSackedSize(&stream) != 0);
889 static int StreamTcpSackTest14 (
void) {
891 memset(&stream, 0,
sizeof(stream));
895 for (
int i = 0; i < 10; i++) {
896 StreamTcpSackInsertRange(&stream, 4000+(20*i), 4010+(20*i));
899 StreamTcpSackPrintList(&stream);
902 FAIL_IF(StreamTcpSackedSize(&stream) != 0);
913 UtRegisterTest(
"StreamTcpSackTest01 -- Insertion", StreamTcpSackTest01);
914 UtRegisterTest(
"StreamTcpSackTest02 -- Insertion", StreamTcpSackTest02);
915 UtRegisterTest(
"StreamTcpSackTest03 -- Insertion", StreamTcpSackTest03);
916 UtRegisterTest(
"StreamTcpSackTest04 -- Insertion", StreamTcpSackTest04);
917 UtRegisterTest(
"StreamTcpSackTest05 -- Insertion", StreamTcpSackTest05);
918 UtRegisterTest(
"StreamTcpSackTest06 -- Insertion", StreamTcpSackTest06);
919 UtRegisterTest(
"StreamTcpSackTest07 -- Pruning", StreamTcpSackTest07);
920 UtRegisterTest(
"StreamTcpSackTest08 -- Pruning", StreamTcpSackTest08);
921 UtRegisterTest(
"StreamTcpSackTest09 -- Pruning", StreamTcpSackTest09);
922 UtRegisterTest(
"StreamTcpSackTest10 -- Pruning", StreamTcpSackTest10);
924 StreamTcpSackTest11);
926 StreamTcpSackTest12);
928 StreamTcpSackTest13);
930 StreamTcpSackTest14);