]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream: test cleanups and fixes
authorVictor Julien <victor@inliniac.net>
Thu, 28 Apr 2016 15:20:11 +0000 (17:20 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 20 Apr 2017 15:41:11 +0000 (17:41 +0200)
src/stream-tcp-reassemble.c
src/stream-tcp.c
src/stream-tcp.h

index f39c1cd122c819d16e51828d8d51a28968c6f88c..d2f2b971b8505690a67beb8d3f3d4bb8baa7bd50 100644 (file)
@@ -104,6 +104,7 @@ void StreamTcpReassemblePseudoPacketCreate(TcpStream *, Packet *, PacketQueue *)
 void StreamTcpReassembleIncrMemuse(uint64_t size)
 {
     (void) SC_ATOMIC_ADD(ra_memuse, size);
+    SCLogDebug("REASSEMBLY %"PRIu64", incr %"PRIu64, StreamTcpReassembleMemuseGlobalCounter(), size);
     return;
 }
 
@@ -115,7 +116,22 @@ void StreamTcpReassembleIncrMemuse(uint64_t size)
  */
 void StreamTcpReassembleDecrMemuse(uint64_t size)
 {
+#ifdef UNITTESTS
+    uint64_t presize = SC_ATOMIC_GET(ra_memuse);
+    if (RunmodeIsUnittests()) {
+        BUG_ON(presize > UINT_MAX);
+    }
+#endif
+
     (void) SC_ATOMIC_SUB(ra_memuse, size);
+
+#ifdef UNITTESTS
+    if (RunmodeIsUnittests()) {
+        uint64_t postsize = SC_ATOMIC_GET(ra_memuse);
+        BUG_ON(postsize > presize);
+    }
+#endif
+    SCLogDebug("REASSEMBLY %"PRIu64", decr %"PRIu64, StreamTcpReassembleMemuseGlobalCounter(), size);
     return;
 }
 
@@ -2035,7 +2051,9 @@ static int VALIDATE(TcpStream *stream, uint8_t *data, uint32_t data_len)
                                                 \
     TcpStream *stream = &ssn.client;
 
-#define MISSED_END                             \
+#define MISSED_END                              \
+    StreamTcpUTClearSession(&ssn);              \
+    StreamTcpUTDeinit(ra_ctx);                  \
     PASS
 
 #define MISSED_STEP(seq, seg, seglen, buf, buflen) \
@@ -2129,25 +2147,18 @@ static int StreamTcpReassembleTest33(void)
 {
     TcpSession ssn;
     Packet *p = PacketGetFromAlloc();
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow f;
     TCPHdr tcph;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
-    TcpStream stream;
-    memset(&stream, 0, sizeof (TcpStream));
-    stream.os_policy = OS_POLICY_BSD;
+    TcpReassemblyThreadCtx *ra_ctx = NULL;
+    ssn.client.os_policy = OS_POLICY_BSD;
     uint8_t packet[1460] = "";
 
-    StreamTcpInitConfig(TRUE);
-
-    /* prevent L7 from kicking in */
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 4096);
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOCLIENT, 4096);
+    StreamTcpUTInit(&ra_ctx);
+    StreamTcpUTSetupSession(&ssn);
 
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
-    memset(&ssn, 0, sizeof (TcpSession));
     memset(&f, 0, sizeof (Flow));
     memset(&tcph, 0, sizeof (TCPHdr));
     ThreadVars tv;
@@ -2169,58 +2180,45 @@ static int StreamTcpReassembleTest33(void)
     p->tcph->th_ack = htonl(31);
     p->payload_len = 10;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(20);
     p->tcph->th_ack = htonl(31);
     p->payload_len = 10;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(40);
     p->tcph->th_ack = htonl(31);
     p->payload_len = 10;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(5);
     p->tcph->th_ack = htonl(31);
     p->payload_len = 30;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
-    StreamTcpFreeConfig(TRUE);
+    StreamTcpUTClearSession(&ssn);
+    StreamTcpUTDeinit(ra_ctx);
     SCFree(p);
-    return 1;
+    PASS;
 }
 
 static int StreamTcpReassembleTest34(void)
 {
     TcpSession ssn;
     Packet *p = PacketGetFromAlloc();
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow f;
     TCPHdr tcph;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
-    TcpStream stream;
-    memset(&stream, 0, sizeof (TcpStream));
-    stream.os_policy = OS_POLICY_BSD;
+    TcpReassemblyThreadCtx *ra_ctx = NULL;
+    ssn.client.os_policy = OS_POLICY_BSD;
     uint8_t packet[1460] = "";
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&ra_ctx);
+    StreamTcpUTSetupSession(&ssn);
 
     /* prevent L7 from kicking in */
     StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 4096);
@@ -2228,7 +2226,6 @@ static int StreamTcpReassembleTest34(void)
 
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
-    memset(&ssn, 0, sizeof (TcpSession));
     memset(&f, 0, sizeof (Flow));
     memset(&tcph, 0, sizeof (TCPHdr));
     ThreadVars tv;
@@ -2245,47 +2242,36 @@ static int StreamTcpReassembleTest34(void)
     p->tcph = &tcph;
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload = packet;
-    SET_ISN(&stream, 857961230);
+    SET_ISN(&ssn.client, 857961230);
 
     p->tcph->th_seq = htonl(857961230);
     p->tcph->th_ack = htonl(31);
     p->payload_len = 304;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(857961534);
     p->tcph->th_ack = htonl(31);
     p->payload_len = 1460;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(857963582);
     p->tcph->th_ack = htonl(31);
     p->payload_len = 1460;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(857960946);
     p->tcph->th_ack = htonl(31);
     p->payload_len = 1460;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
-    StreamTcpFreeConfig(TRUE);
+    StreamTcpUTClearSession(&ssn);
+    StreamTcpUTDeinit(ra_ctx);
     SCFree(p);
-    return 1;
+    PASS;
 }
 
 /** \test Test the bug 76 condition */
@@ -2294,25 +2280,22 @@ static int StreamTcpReassembleTest37(void)
     TcpSession ssn;
     Flow f;
     TCPHdr tcph;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
-    TcpStream stream;
+    TcpReassemblyThreadCtx *ra_ctx = NULL;
     uint8_t packet[1460] = "";
     PacketQueue pq;
     ThreadVars tv;
 
     Packet *p = PacketGetFromAlloc();
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&ra_ctx);
+    StreamTcpUTSetupSession(&ssn);
 
     /* prevent L7 from kicking in */
     StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 10);
     StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOCLIENT, 10);
 
-    memset(&stream, 0, sizeof (TcpStream));
     memset(&pq,0,sizeof(PacketQueue));
-    memset(&ssn, 0, sizeof (TcpSession));
     memset(&f, 0, sizeof (Flow));
     memset(&tcph, 0, sizeof (TCPHdr));
     memset(&tv, 0, sizeof (ThreadVars));
@@ -2329,43 +2312,35 @@ static int StreamTcpReassembleTest37(void)
     p->tcph = &tcph;
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload = packet;
-    stream.os_policy = OS_POLICY_BSD;
+    ssn.client.os_policy = OS_POLICY_BSD;
 
     p->tcph->th_seq = htonl(3061088537UL);
     p->tcph->th_ack = htonl(1729548549UL);
     p->payload_len = 1391;
-    stream.last_ack = 3061091137UL;
-    SET_ISN(&stream, 3061091309UL);
+    ssn.client.last_ack = 3061091137UL;
+    SET_ISN(&ssn.client, 3061091309UL);
 
     /* pre base_seq, so should be rejected */
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) != -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) != -1);
 
     p->tcph->th_seq = htonl(3061089928UL);
     p->tcph->th_ack = htonl(1729548549UL);
     p->payload_len = 1391;
-    stream.last_ack = 3061091137UL;
+    ssn.client.last_ack = 3061091137UL;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(3061091319UL);
     p->tcph->th_ack = htonl(1729548549UL);
     p->payload_len = 1391;
-    stream.last_ack = 3061091137UL;
+    ssn.client.last_ack = 3061091137UL;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &stream, p, &pq) == -1) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
 
-    StreamTcpFreeConfig(TRUE);
+    StreamTcpUTClearSession(&ssn);
+    StreamTcpUTDeinit(ra_ctx);
     SCFree(p);
-    return 1;
+    PASS;
 }
 
 /**
@@ -2377,10 +2352,8 @@ static int StreamTcpReassembleTest37(void)
  */
 static int StreamTcpReassembleTest38 (void)
 {
-    int ret = 0;
     Packet *p = PacketGetFromAlloc();
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow f;
     TCPHdr tcph;
     Port sp;
@@ -2391,12 +2364,12 @@ static int StreamTcpReassembleTest38 (void)
     memset(&pq,0,sizeof(PacketQueue));
     memset(&f, 0, sizeof (Flow));
     memset(&tcph, 0, sizeof (TCPHdr));
-    memset(&ssn, 0, sizeof(TcpSession));
     ThreadVars tv;
     memset(&tv, 0, sizeof (ThreadVars));
+    TcpReassemblyThreadCtx *ra_ctx = NULL;
 
-    StreamTcpInitConfig(TRUE);
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
+    StreamTcpUTInit(&ra_ctx);
+    StreamTcpUTSetupSession(&ssn);
 
     uint8_t httpbuf2[] = "POST / HTTP/1.0\r\nUser-Agent: Victor/1.0\r\n\r\n";
     uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
@@ -2405,11 +2378,9 @@ static int StreamTcpReassembleTest38 (void)
     uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
 
     FLOW_INITIALIZE(&f);
-    if (inet_pton(AF_INET, "1.2.3.4", &in) != 1)
-        goto end;
+    FAIL_IF(inet_pton(AF_INET, "1.2.3.4", &in) != 1);
     f.src.addr_data32[0] = in.s_addr;
-    if (inet_pton(AF_INET, "1.2.3.5", &in) != 1)
-        goto end;
+    FAIL_IF(inet_pton(AF_INET, "1.2.3.5", &in) != 1);
     f.dst.addr_data32[0] = in.s_addr;
     sp = 200;
     dp = 220;
@@ -2441,17 +2412,10 @@ static int StreamTcpReassembleTest38 (void)
     TcpStream *s = NULL;
     s = &ssn.server;
 
-    FLOWLOCK_WRLOCK(&f);
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) {
-        printf("failed in segments reassembly, while processing toserver packet (1): ");
-        goto end;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1);
 
     /* Check if we have stream smsgs in queue */
-    if (UtSsnSmsgCnt(&ssn, STREAM_TOSERVER) > 0) {
-        printf("there shouldn't be any stream smsgs in the queue (2): ");
-        goto end;
-    }
+    FAIL_IF(UtSsnSmsgCnt(&ssn, STREAM_TOSERVER) > 0);
 
     p->flowflags = FLOW_PKT_TOCLIENT;
     p->payload = httpbuf1;
@@ -2460,24 +2424,15 @@ static int StreamTcpReassembleTest38 (void)
     tcph.th_ack = htonl(55);
     s = &ssn.client;
 
-    if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) {
-        printf("failed in segments reassembly, while processing toserver packet (3): ");
-        goto end;
-    }
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1);
 
     /* Check if we have stream smsgs in queue */
-    if (UtSsnSmsgCnt(&ssn, STREAM_TOSERVER) != 1) {
-        printf("there should one stream smsg in the queue (6): ");
-        goto end;
-    }
+    FAIL_IF(UtSsnSmsgCnt(&ssn, STREAM_TOSERVER) != 1);
 
-    ret = 1;
-end:
-    StreamTcpReassembleFreeThreadCtx(ra_ctx);
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
+    StreamTcpUTClearSession(&ssn);
+    StreamTcpUTDeinit(ra_ctx);
     SCFree(p);
-    return ret;
+    PASS;
 }
 
 /**
@@ -2491,18 +2446,18 @@ end:
 static int StreamTcpReassembleTest39 (void)
 {
     Packet *p = PacketGetFromAlloc();
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow f;
     ThreadVars tv;
-    StreamTcpThread *stt = NULL;
+    StreamTcpThread stt;
     TCPHdr tcph;
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
-    StreamTcpThreadInit(&tv, NULL, (void **)&stt);
+    memset(&stt, 0, sizeof (stt));
     memset(&tcph, 0, sizeof (TCPHdr));
+    TcpSession *ssn = NULL;
 
     FLOW_INITIALIZE(&f);
     f.flags = FLOW_IPV4;
@@ -2513,7 +2468,7 @@ static int StreamTcpReassembleTest39 (void)
     FLOWLOCK_WRLOCK(&f);
     int ret = 0;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     /* handshake */
     tcph.th_win = htons(5480);
@@ -2521,10 +2476,10 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
-    TcpSession *ssn = (TcpSession *)f.protoctx;
+    ssn = (TcpSession *)f.protoctx;
 
     if (StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2549,7 +2504,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOCLIENT;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2575,7 +2530,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2602,7 +2557,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload_len = sizeof(request1);
     p->payload = request1;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2630,7 +2585,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOCLIENT;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2669,7 +2624,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload_len = sizeof(request2);
     p->payload = request2;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2740,7 +2695,7 @@ static int StreamTcpReassembleTest39 (void)
     p->payload_len = sizeof(response);
     p->payload = response;
 
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         !StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2767,7 +2722,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         !StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2794,7 +2749,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOCLIENT;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         !StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2820,7 +2775,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         !StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2846,7 +2801,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOCLIENT;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         !StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2874,7 +2829,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload_len = sizeof(request1);
     p->payload = request1;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         !StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2902,7 +2857,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOCLIENT;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         !StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2929,7 +2884,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload_len = sizeof(request2);
     p->payload = request2;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         !StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2957,7 +2912,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOCLIENT;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         !StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -2998,7 +2953,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOCLIENT;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
     SCLogDebug("StreamTcpIsSetStreamFlagAppProtoDetectionCompleted %s, "
@@ -3035,7 +2990,7 @@ static int StreamTcpReassembleTest39 (void)
     p->flowflags = FLOW_PKT_TOSERVER;
     p->payload_len = 0;
     p->payload = NULL;
-    if (StreamTcpPacket(&tv, p, stt, &pq) == -1)
+    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
     if (//!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->server) ||
         //!StreamTcpIsSetStreamFlagAppProtoDetectionCompleted(&ssn->client) ||
@@ -3057,9 +3012,8 @@ static int StreamTcpReassembleTest39 (void)
 
     ret = 1;
 end:
-    StreamTcpThreadDeinit(&tv, (void *)stt);
-    StreamTcpSessionClear(p->flow->protoctx);
-    StreamTcpFreeConfig(TRUE);
+    StreamTcpSessionClear(ssn);
+    StreamTcpUTDeinit(stt.ra_ctx);
     SCFree(p);
     FLOWLOCK_UNLOCK(&f);
     return ret;
@@ -3084,11 +3038,11 @@ static int StreamTcpReassembleTest40 (void)
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
     memset(&tcph, 0, sizeof (TCPHdr));
-    memset(&ssn, 0, sizeof(TcpSession));
     ThreadVars tv;
     memset(&tv, 0, sizeof (ThreadVars));
 
     StreamTcpInitConfig(TRUE);
+    StreamTcpUTSetupSession(&ssn);
     StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 130);
 
     TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
@@ -3259,6 +3213,7 @@ static int StreamTcpReassembleTest40 (void)
 
     ret = 1;
 end:
+    StreamTcpUTClearSession(&ssn);
     StreamTcpReassembleFreeThreadCtx(ra_ctx);
     StreamTcpFreeConfig(TRUE);
     SCFree(p);
@@ -3283,11 +3238,11 @@ static int StreamTcpReassembleTest43 (void)
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
     memset(&tcph, 0, sizeof (TCPHdr));
-    memset(&ssn, 0, sizeof(TcpSession));
     ThreadVars tv;
     memset(&tv, 0, sizeof (ThreadVars));
 
     StreamTcpInitConfig(TRUE);
+    StreamTcpUTSetupSession(&ssn);
     TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
 
     uint8_t httpbuf1[] = "/ HTTP/1.0\r\nUser-Agent: Victor/1.0";
@@ -3430,6 +3385,7 @@ static int StreamTcpReassembleTest43 (void)
 
     ret = 1;
 end:
+    StreamTcpUTClearSession(&ssn);
     StreamTcpReassembleFreeThreadCtx(ra_ctx);
     StreamTcpFreeConfig(TRUE);
     SCFree(p);
@@ -3576,10 +3532,8 @@ end:
 
 static int StreamTcpReassembleTest47 (void)
 {
-    int ret = 0;
     Packet *p = PacketGetFromAlloc();
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow *f = NULL;
     TCPHdr tcph;
     TcpSession ssn;
@@ -3587,7 +3541,6 @@ static int StreamTcpReassembleTest47 (void)
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
     memset(&tcph, 0, sizeof (TCPHdr));
-    memset(&ssn, 0, sizeof(TcpSession));
     memset(&tv, 0, sizeof (ThreadVars));
 
     /* prevent L7 from kicking in */
@@ -3595,6 +3548,7 @@ static int StreamTcpReassembleTest47 (void)
     StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOCLIENT, 0);
 
     StreamTcpInitConfig(TRUE);
+    StreamTcpUTSetupSession(&ssn);
     TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
 
     uint8_t httpbuf1[] = "GET /EVILSUFF HTTP/1.1\r\n\r\n";
@@ -3607,8 +3561,7 @@ static int StreamTcpReassembleTest47 (void)
     ssn.client.last_ack = 21;
 
     f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 200, 220);
-    if (f == NULL)
-        goto end;
+    FAIL_IF(f == NULL);
     f->protoctx = &ssn;
     f->proto = IPPROTO_TCP;
     p->flow = f;
@@ -3618,7 +3571,6 @@ static int StreamTcpReassembleTest47 (void)
     TcpStream *s = NULL;
     uint8_t cnt = 0;
 
-    FLOWLOCK_WRLOCK(f);
     for (cnt=0; cnt < httplen1; cnt++) {
         tcph.th_seq = htonl(ssn.client.isn + 1 + cnt);
         tcph.th_ack = htonl(572799782UL);
@@ -3629,11 +3581,7 @@ static int StreamTcpReassembleTest47 (void)
         p->payload_len = 1;
         s = &ssn.client;
 
-        if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) {
-            printf("failed in segments reassembly, while processing toserver "
-                    "packet\n");
-            goto end;
-        }
+        FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1);
 
         p->flowflags = FLOW_PKT_TOCLIENT;
         p->payload = NULL;
@@ -3644,26 +3592,17 @@ static int StreamTcpReassembleTest47 (void)
         p->tcph = &tcph;
         s = &ssn.server;
 
-        if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) {
-            printf("failed in segments reassembly, while processing toserver "
-                    "packet\n");
-            goto end;
-        }
+        FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1);
     }
 
-    if (f->alproto != ALPROTO_HTTP) {
-        printf("App layer protocol (HTTP) should have been detected\n");
-        goto end;
-    }
+    FAIL_IF(f->alproto != ALPROTO_HTTP);
 
-    ret = 1;
-end:
+    StreamTcpUTClearSession(&ssn);
     StreamTcpReassembleFreeThreadCtx(ra_ctx);
     StreamTcpFreeConfig(TRUE);
     SCFree(p);
-    FLOWLOCK_UNLOCK(f);
     UTHFreeFlow(f);
-    return ret;
+    PASS;
 }
 
 /** \test 3 in order segments in inline reassembly */
index e0ce65073ef52f68ce56ecd7b10194a299ae9e6e..8cebb3da8b519b341dd82e7666465ebd48b973a3 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2016 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -112,6 +112,7 @@ static SCMutex ssn_pool_mutex = SCMUTEX_INITIALIZER; /**< init only, protect ini
 static uint64_t ssn_pool_cnt = 0; /** counts ssns, protected by ssn_pool_mutex */
 #endif
 
+uint64_t StreamTcpMemuseCounter(void);
 uint64_t StreamTcpReassembleMemuseGlobalCounter(void);
 SC_ATOMIC_DECLARE(uint64_t, st_memuse);
 
@@ -121,12 +122,28 @@ int stream_inline = 0;
 void StreamTcpIncrMemuse(uint64_t size)
 {
     (void) SC_ATOMIC_ADD(st_memuse, size);
+    SCLogDebug("STREAM %"PRIu64", incr %"PRIu64, StreamTcpMemuseCounter(), size);
     return;
 }
 
 void StreamTcpDecrMemuse(uint64_t size)
 {
+#ifdef DEBUG_VALIDATION
+    uint64_t presize = SC_ATOMIC_GET(st_memuse);
+    if (RunmodeIsUnittests()) {
+        BUG_ON(presize > UINT_MAX);
+    }
+#endif
+
     (void) SC_ATOMIC_SUB(st_memuse, size);
+
+#ifdef DEBUG_VALIDATION
+    if (RunmodeIsUnittests()) {
+        uint64_t postsize = SC_ATOMIC_GET(st_memuse);
+        BUG_ON(postsize > presize);
+    }
+#endif
+    SCLogDebug("STREAM %"PRIu64", decr %"PRIu64, StreamTcpMemuseCounter(), size);
     return;
 }
 
@@ -5845,6 +5862,7 @@ void TcpSessionSetReassemblyDepth(TcpSession *ssn, uint32_t size)
 
 static int StreamTcpTest01 (void)
 {
+    StreamTcpThread stt;
     Packet *p = SCMalloc(SIZE_OF_PACKET);
     if (unlikely(p == NULL))
         return 0;
@@ -5855,7 +5873,7 @@ static int StreamTcpTest01 (void)
     p->flow = &f;
     int ret = 0;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     TcpSession *ssn = StreamTcpNewSession(p, 0);
     if (ssn == NULL) {
@@ -5877,9 +5895,9 @@ static int StreamTcpTest01 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -5894,14 +5912,11 @@ end:
 static int StreamTcpTest02 (void)
 {
     Packet *p = SCMalloc(SIZE_OF_PACKET);
-    if (unlikely(p == NULL))
-        return 0;
-    int ret = 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow f;
     ThreadVars tv;
     StreamTcpThread stt;
     uint8_t payload[4];
-    TcpReassemblyThreadCtx *ra_ctx = NULL;;
     TCPHdr tcph;
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
@@ -5911,39 +5926,29 @@ static int StreamTcpTest02 (void)
     memset(&stt, 0, sizeof (StreamTcpThread));
     memset(&tcph, 0, sizeof (TCPHdr));
 
-    ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
-    if (ra_ctx == NULL) {
-        goto end;
-    }
     FLOW_INITIALIZE(&f);
     p->flow = &f;
     tcph.th_win = htons(5480);
     tcph.th_flags = TH_SYN;
     p->tcph = &tcph;
     p->flowflags = FLOW_PKT_TOSERVER;
-    stt.ra_ctx = ra_ctx;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
-    FLOWLOCK_WRLOCK(&f);
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1) {
-        goto end;
-    }
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_ack = htonl(1);
     p->tcph->th_flags = TH_SYN | TH_ACK;
     p->flowflags = FLOW_PKT_TOCLIENT;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_ack = htonl(1);
     p->tcph->th_seq = htonl(1);
     p->tcph->th_flags = TH_ACK;
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_ack = htonl(1);
     p->tcph->th_seq = htonl(2);
@@ -5954,12 +5959,10 @@ static int StreamTcpTest02 (void)
     p->payload = payload;
     p->payload_len = 3;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->flowflags = FLOW_PKT_TOCLIENT;
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_ack = htonl(1);
     p->tcph->th_seq = htonl(6);
@@ -5970,22 +5973,18 @@ static int StreamTcpTest02 (void)
     p->payload = payload;
     p->payload_len = 3;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->flowflags = FLOW_PKT_TOCLIENT;
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     StreamTcpSessionClear(p->flow->protoctx);
+    //StreamTcpUTClearSession(p->flow->protoctx);
 
-    ret = 1;
-end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
-    return ret;
+    StreamTcpUTDeinit(stt.ra_ctx);
+    PASS;
 }
 
 /**
@@ -6015,7 +6014,7 @@ static int StreamTcpTest03 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
@@ -6024,7 +6023,6 @@ static int StreamTcpTest03 (void)
     p->tcph = &tcph;
     int ret = 0;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -6059,10 +6057,9 @@ static int StreamTcpTest03 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -6093,7 +6090,7 @@ static int StreamTcpTest04 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
@@ -6103,7 +6100,6 @@ static int StreamTcpTest04 (void)
 
     int ret = 0;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -6130,10 +6126,9 @@ static int StreamTcpTest04 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -6166,7 +6161,7 @@ static int StreamTcpTest05 (void)
     p->flow = &f;
     int ret = 0;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     /* prevent L7 from kicking in */
     StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 4096);
@@ -6182,7 +6177,6 @@ static int StreamTcpTest05 (void)
     p->payload = payload;
     p->payload_len = 3;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -6237,10 +6231,9 @@ static int StreamTcpTest05 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -6274,12 +6267,11 @@ static int StreamTcpTest06 (void)
     p->flow = &f;
     int ret = 0;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     tcph.th_flags = TH_FIN;
     p->tcph = &tcph;
 
-    FLOWLOCK_WRLOCK(&f);
     /* StreamTcpPacket returns -1 on unsolicited FIN */
     if (StreamTcpPacket(&tv, p, &stt, &pq) != -1) {
         printf("StreamTcpPacket failed: ");
@@ -6305,18 +6297,15 @@ static int StreamTcpTest06 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
 /**
  *  \test   Test the working on PAWS. The packet will be dropped by stream, as
  *          its timestamp is old, although the segment is in the window.
- *
- *  \retval On success it returns 1 and on failure 0.
  */
 
 static int StreamTcpTest07 (void)
@@ -6340,13 +6329,9 @@ static int StreamTcpTest07 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
     stream_config.midstream = TRUE;
 
-    /* prevent L7 from kicking in */
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 4096);
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOCLIENT, 4096);
-
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
     tcph.th_ack = htonl(20);
@@ -6360,7 +6345,6 @@ static int StreamTcpTest07 (void)
     p->payload = payload;
     p->payload_len = 1;
 
-    FLOWLOCK_WRLOCK(&f);
     FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(11);
@@ -6372,21 +6356,18 @@ static int StreamTcpTest07 (void)
 
     FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) != -1);
 
-    FAIL_IF (((TcpSession *) (p->flow->protoctx))->client.next_seq != 11);
+    FAIL_IF(((TcpSession *) (p->flow->protoctx))->client.next_seq != 11);
 
     StreamTcpSessionClear(p->flow->protoctx);
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     PASS;
 }
 
 /**
  *  \test   Test the working on PAWS. The packet will be accpeted by engine as
  *          the timestamp is valid and it is in window.
- *
- *  \retval On success it returns 1 and on failure 0.
  */
 
 static int StreamTcpTest08 (void)
@@ -6410,13 +6391,9 @@ static int StreamTcpTest08 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
     stream_config.midstream = TRUE;
 
-    /* prevent L7 from kicking in */
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 4096);
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOCLIENT, 4096);
-
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
     tcph.th_ack = htonl(20);
@@ -6430,7 +6407,6 @@ static int StreamTcpTest08 (void)
     p->payload = payload;
     p->payload_len = 1;
 
-    FLOWLOCK_WRLOCK(&f);
     FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(11);
@@ -6446,26 +6422,21 @@ static int StreamTcpTest08 (void)
 
     StreamTcpSessionClear(p->flow->protoctx);
 
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     PASS;
 }
 
 /**
  *  \test   Test the working of No stream reassembly flag. The stream will not
  *          reassemble the segment if the flag is set.
- *
- *  \retval On success it returns 1 and on failure 0.
  */
 
 static int StreamTcpTest09 (void)
 {
-
     Packet *p = SCMalloc(SIZE_OF_PACKET);
-    if (unlikely(p == NULL))
-    return 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow f;
     ThreadVars tv;
     StreamTcpThread stt;
@@ -6482,15 +6453,10 @@ static int StreamTcpTest09 (void)
 
     FLOW_INITIALIZE(&f);
     p->flow = &f;
-    int ret = 0;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
     stream_config.midstream = TRUE;
 
-    //prevent L7 from kicking in
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 4096);
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOCLIENT, 4096);
-
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
     tcph.th_ack = htonl(20);
@@ -6500,52 +6466,44 @@ static int StreamTcpTest09 (void)
     p->payload = payload;
     p->payload_len = 1;
 
-    FLOWLOCK_WRLOCK(&f);
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(12);
     p->tcph->th_ack = htonl(23);
     p->tcph->th_flags = TH_ACK|TH_PUSH;
     p->flowflags = FLOW_PKT_TOSERVER;
 
+    FAIL_IF(p->flow->protoctx == NULL);
+
     StreamTcpSetSessionNoReassemblyFlag(((TcpSession *)(p->flow->protoctx)), 0);
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(11);
     p->tcph->th_ack = htonl(23);
     p->tcph->th_flags = TH_ACK|TH_PUSH;
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
-    if (((TcpSession *) (p->flow->protoctx))->client.seg_list->next == NULL)
-        ret = 1;
+    FAIL_IF(((TcpSession *) (p->flow->protoctx))->client.seg_list->next != NULL);
 
     StreamTcpSessionClear(p->flow->protoctx);
-end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
-    return ret;
+    StreamTcpUTDeinit(stt.ra_ctx);
+    PASS;
 }
 
 /**
  *  \test   Test the setting up a TCP session when we are seeing asynchronous
  *          stream, while we see all the packets in that stream from start.
- *
- *  \retval On success it returns 1 and on failure 0.
  */
 
 static int StreamTcpTest10 (void)
 {
     Packet *p = SCMalloc(SIZE_OF_PACKET);
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow f;
     ThreadVars tv;
     StreamTcpThread stt;
@@ -6561,26 +6519,23 @@ static int StreamTcpTest10 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
+    stream_config.async_oneside = TRUE;
 
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
     tcph.th_ack = htonl(11);
     tcph.th_flags = TH_SYN;
     p->tcph = &tcph;
-    int ret = 0;
 
-    FLOWLOCK_WRLOCK(&f);
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(11);
     p->tcph->th_ack = htonl(11);
     p->tcph->th_flags = TH_ACK;
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(11);
     p->tcph->th_ack = htonl(11);
@@ -6591,8 +6546,7 @@ static int StreamTcpTest10 (void)
     p->payload = payload;
     p->payload_len = 3;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(6);
     p->tcph->th_ack = htonl(11);
@@ -6603,53 +6557,32 @@ static int StreamTcpTest10 (void)
     p->payload = payload;
     p->payload_len = 3;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
-    if (stream_config.async_oneside != TRUE) {
-        ret = 1;
-        goto end;
-    }
-    if (((TcpSession *)(p->flow->protoctx))->state != TCP_ESTABLISHED) {
-        printf("failed in setting state\n");
-        goto end;
-    }
+    FAIL_IF(((TcpSession *)(p->flow->protoctx))->state != TCP_ESTABLISHED);
 
-    if (! (((TcpSession *)(p->flow->protoctx))->flags & STREAMTCP_FLAG_ASYNC)) {
-        printf("failed in setting asynchronous session\n");
-        goto end;
-    }
+    FAIL_IF(! (((TcpSession *)(p->flow->protoctx))->flags & STREAMTCP_FLAG_ASYNC));
 
-    if (((TcpSession *)(p->flow->protoctx))->client.last_ack != 6 &&
-            ((TcpSession *)(p->flow->protoctx))->server.next_seq != 11) {
-        printf("failed in seq %"PRIu32" match\n",
-                ((TcpSession *)(p->flow->protoctx))->client.last_ack);
-        goto end;
-    }
+    FAIL_IF(((TcpSession *)(p->flow->protoctx))->client.last_ack != 6 &&
+            ((TcpSession *)(p->flow->protoctx))->server.next_seq != 11);
 
     StreamTcpSessionClear(p->flow->protoctx);
 
-    ret = 1;
-end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
-    return ret;
+    StreamTcpUTDeinit(stt.ra_ctx);
+    PASS;
 }
 
 /**
  *  \test   Test the setting up a TCP session when we are seeing asynchronous
  *          stream, while we missed the SYN packet of that stream.
- *
- *  \retval On success it returns 1 and on failure 0.
  */
 
 static int StreamTcpTest11 (void)
 {
     Packet *p = SCMalloc(SIZE_OF_PACKET);
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow f;
     ThreadVars tv;
     StreamTcpThread stt;
@@ -6665,26 +6598,23 @@ static int StreamTcpTest11 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
+    stream_config.async_oneside = TRUE;
 
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
     tcph.th_ack = htonl(1);
     tcph.th_flags = TH_SYN|TH_ACK;
     p->tcph = &tcph;
-    int ret = 0;
 
-    FLOWLOCK_WRLOCK(&f);
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(11);
     p->tcph->th_ack = htonl(1);
     p->tcph->th_flags = TH_ACK;
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(11);
     p->tcph->th_ack = htonl(1);
@@ -6695,8 +6625,7 @@ static int StreamTcpTest11 (void)
     p->payload = payload;
     p->payload_len = 3;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
     p->tcph->th_seq = htonl(2);
     p->tcph->th_ack = htonl(1);
@@ -6707,40 +6636,20 @@ static int StreamTcpTest11 (void)
     p->payload = payload;
     p->payload_len = 3;
 
-    if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
-        goto end;
+    FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
 
-    if (stream_config.async_oneside != TRUE) {
-        ret = 1;
-        goto end;
-    }
+    FAIL_IF(! (((TcpSession *)(p->flow->protoctx))->flags & STREAMTCP_FLAG_ASYNC));
 
-    if (! (((TcpSession *)(p->flow->protoctx))->flags & STREAMTCP_FLAG_ASYNC)) {
-        printf("failed in setting asynchronous session\n");
-        goto end;
-    }
+    FAIL_IF(((TcpSession *)(p->flow->protoctx))->state != TCP_ESTABLISHED);
 
-    if (((TcpSession *)(p->flow->protoctx))->state != TCP_ESTABLISHED) {
-        printf("failed in setting state\n");
-        goto end;
-    }
-
-    if (((TcpSession *)(p->flow->protoctx))->server.last_ack != 2 &&
-            ((TcpSession *)(p->flow->protoctx))->client.next_seq != 1) {
-        printf("failed in seq %"PRIu32" match\n",
-                ((TcpSession *)(p->flow->protoctx))->server.last_ack);
-        goto end;
-    }
+    FAIL_IF(((TcpSession *)(p->flow->protoctx))->server.last_ack != 2 &&
+            ((TcpSession *)(p->flow->protoctx))->client.next_seq != 1);
 
     StreamTcpSessionClear(p->flow->protoctx);
-
-    ret = 1;
-end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
-    return ret;
+    StreamTcpUTDeinit(stt.ra_ctx);
+    PASS;
 }
 
 /**
@@ -6770,7 +6679,7 @@ static int StreamTcpTest12 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
@@ -6779,7 +6688,6 @@ static int StreamTcpTest12 (void)
     p->tcph = &tcph;
     int ret = 0;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -6833,10 +6741,9 @@ static int StreamTcpTest12 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -6868,7 +6775,7 @@ static int StreamTcpTest13 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
@@ -6877,7 +6784,6 @@ static int StreamTcpTest13 (void)
     p->tcph = &tcph;
     int ret = 0;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -6943,10 +6849,9 @@ static int StreamTcpTest13 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -7078,7 +6983,7 @@ static int StreamTcpTest14 (void)
     p->flow = &f;
     int ret = 0;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     /* Load the config string in to parser */
     ConfCreateContextBackup();
@@ -7208,12 +7113,12 @@ static int StreamTcpTest14 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     ConfDeInit();
     ConfRestoreContextBackup();
     FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -7244,7 +7149,7 @@ static int StreamTcp4WHSTest01 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
@@ -7252,7 +7157,6 @@ static int StreamTcp4WHSTest01 (void)
     tcph.th_flags = TH_SYN;
     p->tcph = &tcph;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -7293,10 +7197,9 @@ static int StreamTcp4WHSTest01 (void)
     ret = 1;
 end:
     StreamTcpSessionClear(p->flow->protoctx);
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -7328,7 +7231,7 @@ static int StreamTcp4WHSTest02 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
@@ -7336,7 +7239,6 @@ static int StreamTcp4WHSTest02 (void)
     tcph.th_flags = TH_SYN;
     p->tcph = &tcph;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -7366,10 +7268,9 @@ static int StreamTcp4WHSTest02 (void)
     ret = 1;
 end:
     StreamTcpSessionClear(p->flow->protoctx);
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -7385,8 +7286,7 @@ static int StreamTcp4WHSTest03 (void)
 {
     int ret = 0;
     Packet *p = SCMalloc(SIZE_OF_PACKET);
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
     Flow f;
     ThreadVars tv;
     StreamTcpThread stt;
@@ -7401,7 +7301,7 @@ static int StreamTcp4WHSTest03 (void)
     FLOW_INITIALIZE(&f);
     p->flow = &f;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     tcph.th_win = htons(5480);
     tcph.th_seq = htonl(10);
@@ -7409,7 +7309,6 @@ static int StreamTcp4WHSTest03 (void)
     tcph.th_flags = TH_SYN;
     p->tcph = &tcph;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -7450,10 +7349,9 @@ static int StreamTcp4WHSTest03 (void)
     ret = 1;
 end:
     StreamTcpSessionClear(p->flow->protoctx);
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -7492,7 +7390,7 @@ static int StreamTcpTest15 (void)
     p->flow = &f;
     int ret = 0;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     /* Load the config string in to parser */
     ConfCreateContextBackup();
@@ -7524,7 +7422,6 @@ static int StreamTcpTest15 (void)
     p->payload = payload;
     p->payload_len = 3;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -7622,12 +7519,11 @@ static int StreamTcpTest15 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     ConfDeInit();
     ConfRestoreContextBackup();
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -7666,7 +7562,7 @@ static int StreamTcpTest16 (void)
     p->flow = &f;
     int ret = 0;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     /* Load the config string in to parser */
     ConfCreateContextBackup();
@@ -7796,12 +7692,12 @@ static int StreamTcpTest16 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     ConfDeInit();
     ConfRestoreContextBackup();
     FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -7841,7 +7737,7 @@ static int StreamTcpTest17 (void)
     p->flow = &f;
     int ret = 0;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     /* Load the config string in to parser */
     ConfCreateContextBackup();
@@ -7971,12 +7867,12 @@ static int StreamTcpTest17 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     ConfDeInit();
     ConfRestoreContextBackup();
     FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -7984,7 +7880,7 @@ end:
             confuguration defined in 'dummy_conf_string1' */
 static int StreamTcpTest18 (void)
 {
-
+    StreamTcpThread stt;
     struct in_addr addr;
     char os_policy_name[10] = "windows";
     char *ip_addr;
@@ -8000,7 +7896,7 @@ static int StreamTcpTest18 (void)
     memset(p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(ipv4h));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
     SCHInfoCleanResources();
 
     /* Load the config string in to parser */
@@ -8023,17 +7919,17 @@ static int StreamTcpTest18 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     ConfDeInit();
     ConfRestoreContextBackup();
     SCFree(p);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 /** \test   Test the various OS policies based on different IP addresses from
             confuguration defined in 'dummy_conf_string1' */
 static int StreamTcpTest19 (void)
 {
-
+    StreamTcpThread stt;
     struct in_addr addr;
     char os_policy_name[10] = "windows";
     char *ip_addr;
@@ -8049,7 +7945,7 @@ static int StreamTcpTest19 (void)
     memset(p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(ipv4h));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
     SCHInfoCleanResources();
 
     /* Load the config string in to parser */
@@ -8075,17 +7971,17 @@ static int StreamTcpTest19 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     ConfDeInit();
     ConfRestoreContextBackup();
     SCFree(p);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 /** \test   Test the various OS policies based on different IP addresses from
             confuguration defined in 'dummy_conf_string1' */
 static int StreamTcpTest20 (void)
 {
-
+    StreamTcpThread stt;
     struct in_addr addr;
     char os_policy_name[10] = "linux";
     char *ip_addr;
@@ -8101,7 +7997,7 @@ static int StreamTcpTest20 (void)
     memset(p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(ipv4h));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
     SCHInfoCleanResources();
 
     /* Load the config string in to parser */
@@ -8127,17 +8023,17 @@ static int StreamTcpTest20 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     ConfDeInit();
     ConfRestoreContextBackup();
     SCFree(p);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 /** \test   Test the various OS policies based on different IP addresses from
             confuguration defined in 'dummy_conf_string1' */
 static int StreamTcpTest21 (void)
 {
-
+    StreamTcpThread stt;
     struct in_addr addr;
     char os_policy_name[10] = "linux";
     char *ip_addr;
@@ -8153,7 +8049,7 @@ static int StreamTcpTest21 (void)
     memset(p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(ipv4h));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
     SCHInfoCleanResources();
 
     /* Load the config string in to parser */
@@ -8179,17 +8075,17 @@ static int StreamTcpTest21 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     ConfDeInit();
     ConfRestoreContextBackup();
     SCFree(p);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 /** \test   Test the various OS policies based on different IP addresses from
             confuguration defined in 'dummy_conf_string1' */
 static int StreamTcpTest22 (void)
 {
-
+    StreamTcpThread stt;
     struct in_addr addr;
     char os_policy_name[10] = "windows";
     char *ip_addr;
@@ -8205,7 +8101,7 @@ static int StreamTcpTest22 (void)
     memset(p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(ipv4h));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
     SCHInfoCleanResources();
 
     /* Load the config string in to parser */
@@ -8231,20 +8127,20 @@ static int StreamTcpTest22 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
     ConfDeInit();
     ConfRestoreContextBackup();
     SCFree(p);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
 /** \test   Test the stream mem leaks conditions. */
 static int StreamTcpTest23(void)
 {
+    StreamTcpThread stt;
     TcpSession ssn;
     Flow f;
     TCPHdr tcph;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     uint8_t packet[1460] = "";
     ThreadVars tv;
     PacketQueue pq;
@@ -8253,13 +8149,13 @@ static int StreamTcpTest23(void)
     FAIL_IF(p == NULL);
 
     memset(&pq,0,sizeof(PacketQueue));
-    memset(&ssn, 0, sizeof (TcpSession));
     memset(p, 0, SIZE_OF_PACKET);
     memset(&f, 0, sizeof (Flow));
     memset(&tcph, 0, sizeof (TCPHdr));
     memset(&tv, 0, sizeof (ThreadVars));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
+    StreamTcpUTSetupSession(&ssn);
 
     /* prevent L7 from kicking in */
     StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 4096);
@@ -8283,52 +8179,48 @@ static int StreamTcpTest23(void)
     p->tcph->th_ack = htonl(3373419609UL);
     p->payload_len = 2;
 
-    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, stt.ra_ctx, &ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(3184324455UL);
     p->tcph->th_ack = htonl(3373419621UL);
     p->payload_len = 2;
 
-    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, stt.ra_ctx, &ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(3184324453UL);
     p->tcph->th_ack = htonl(3373419621UL);
     p->payload_len = 6;
 
-    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, stt.ra_ctx, &ssn, &ssn.client, p, &pq) == -1);
 
     FAIL_IF(ssn.client.seg_list_tail == NULL);
     FAIL_IF(TCP_SEG_LEN(ssn.client.seg_list_tail) != 2);
 
-    StreamTcpReturnStreamSegments(&ssn.client);
-    StreamTcpFreeConfig(TRUE);
-    FAIL_IF(SC_ATOMIC_GET(st_memuse) > 0);
+    StreamTcpUTClearSession(&ssn);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
+    FAIL_IF(SC_ATOMIC_GET(st_memuse) > 0);
     PASS;
 }
 
 /** \test   Test the stream mem leaks conditions. */
 static int StreamTcpTest24(void)
 {
+    StreamTcpThread stt;
     TcpSession ssn;
     Packet *p = SCMalloc(SIZE_OF_PACKET);
     FAIL_IF (p == NULL);
     Flow f;
     TCPHdr tcph;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     uint8_t packet[1460] = "";
     ThreadVars tv;
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
+    StreamTcpUTSetupSession(&ssn);
 
-    /* prevent L7 from kicking in */
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 4096);
-    StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOCLIENT, 4096);
-
-    memset(&ssn, 0, sizeof (TcpSession));
     memset(p, 0, SIZE_OF_PACKET);
     memset(&f, 0, sizeof (Flow));
     memset(&tv, 0, sizeof (ThreadVars));
@@ -8352,28 +8244,28 @@ static int StreamTcpTest24(void)
     p->tcph->th_ack = htonl(3373419621UL);
     p->payload_len = 4;
 
-    FAIL_IF (StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
+    FAIL_IF (StreamTcpReassembleHandleSegment(&tv, stt.ra_ctx, &ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(3184324459UL);
     p->tcph->th_ack = htonl(3373419633UL);
     p->payload_len = 2;
 
-    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, stt.ra_ctx, &ssn, &ssn.client, p, &pq) == -1);
 
     p->tcph->th_seq = htonl(3184324459UL);
     p->tcph->th_ack = htonl(3373419657UL);
     p->payload_len = 4;
 
-    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx,&ssn, &ssn.client, p, &pq) == -1);
+    FAIL_IF(StreamTcpReassembleHandleSegment(&tv, stt.ra_ctx, &ssn, &ssn.client, p, &pq) == -1);
 
     FAIL_IF(ssn.client.seg_list_tail == NULL);
     FAIL_IF(TCP_SEG_LEN(ssn.client.seg_list_tail) != 4);
 
-    StreamTcpReturnStreamSegments(&ssn.client);
-    StreamTcpFreeConfig(TRUE);
-    FAIL_IF(SC_ATOMIC_GET(st_memuse) > 0);
+    StreamTcpUTClearSession(&ssn);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
+    FAIL_IF(SC_ATOMIC_GET(st_memuse) > 0);
     PASS;
 }
 
@@ -8392,7 +8284,6 @@ static int StreamTcpTest25(void)
     StreamTcpThread stt;
     uint8_t payload[4];
     TCPHdr tcph;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     int ret = 0;
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
@@ -8404,7 +8295,6 @@ static int StreamTcpTest25(void)
     memset(&tcph, 0, sizeof (TCPHdr));
 
     FLOW_INITIALIZE(&f);
-    stt.ra_ctx = ra_ctx;
     p->flow = &f;
     tcph.th_win = htons(5480);
     tcph.th_flags = TH_SYN | TH_CWR;
@@ -8415,9 +8305,8 @@ static int StreamTcpTest25(void)
     StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOSERVER, 4096);
     StreamMsgQueueSetMinChunkLen(FLOW_PKT_TOCLIENT, 4096);
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -8472,10 +8361,9 @@ static int StreamTcpTest25(void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -8494,7 +8382,6 @@ static int StreamTcpTest26(void)
     StreamTcpThread stt;
     uint8_t payload[4];
     TCPHdr tcph;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     int ret = 0;
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
@@ -8506,16 +8393,14 @@ static int StreamTcpTest26(void)
     memset(&tcph, 0, sizeof (TCPHdr));
 
     FLOW_INITIALIZE(&f);
-    stt.ra_ctx = ra_ctx;
     p->flow = &f;
     tcph.th_win = htons(5480);
     tcph.th_flags = TH_SYN | TH_ECN;
     p->tcph = &tcph;
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -8570,10 +8455,9 @@ static int StreamTcpTest26(void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -8592,7 +8476,6 @@ static int StreamTcpTest27(void)
     StreamTcpThread stt;
     uint8_t payload[4];
     TCPHdr tcph;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     int ret = 0;
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
@@ -8604,16 +8487,14 @@ static int StreamTcpTest27(void)
     memset(&tcph, 0, sizeof (TCPHdr));
 
     FLOW_INITIALIZE(&f);
-    stt.ra_ctx = ra_ctx;
     p->flow = &f;
     tcph.th_win = htons(5480);
     tcph.th_flags = TH_SYN | TH_CWR | TH_ECN;
     p->tcph = &tcph;
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -8668,54 +8549,34 @@ static int StreamTcpTest27(void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
 /** \test   Test the memcap incrementing/decrementing and memcap check */
 static int StreamTcpTest28(void)
 {
-    uint8_t ret = 0;
-    StreamTcpInitConfig(TRUE);
+    StreamTcpThread stt;
+    StreamTcpUTInit(&stt.ra_ctx);
+
     uint32_t memuse = SC_ATOMIC_GET(st_memuse);
 
     StreamTcpIncrMemuse(500);
-    if (SC_ATOMIC_GET(st_memuse) != (memuse+500)) {
-        printf("failed in incrementing the memory");
-        goto end;
-    }
+    FAIL_IF(SC_ATOMIC_GET(st_memuse) != (memuse+500));
 
     StreamTcpDecrMemuse(500);
-    if (SC_ATOMIC_GET(st_memuse) != memuse) {
-        printf("failed in decrementing the memory");
-        goto end;
-    }
-
-    if (StreamTcpCheckMemcap(500) != 1) {
-        printf("failed in validating the memcap");
-        goto end;
-    }
+    FAIL_IF(SC_ATOMIC_GET(st_memuse) != memuse);
 
-    if (StreamTcpCheckMemcap((memuse + stream_config.memcap)) != 0) {
-        printf("failed in validating the overflowed memcap");
-        goto end;
-    }
+    FAIL_IF(StreamTcpCheckMemcap(500) != 1);
 
-    StreamTcpFreeConfig(TRUE);
+    FAIL_IF(StreamTcpCheckMemcap((memuse + stream_config.memcap)) != 0);
 
-    if (SC_ATOMIC_GET(st_memuse) != 0) {
-        printf("failed in clearing the memory");
-        goto end;
-    }
+    StreamTcpUTDeinit(stt.ra_ctx);
 
-    ret = 1;
-    return ret;
-end:
-    StreamTcpFreeConfig(TRUE);
-    return ret;
+    FAIL_IF(SC_ATOMIC_GET(st_memuse) != 0);
+    PASS;
 }
 
 #if 0
@@ -8735,7 +8596,6 @@ static int StreamTcpTest29(void)
     TCPHdr tcph;
     TcpSession ssn;
     IPV4Hdr ipv4h;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     struct in_addr addr;
     struct in_addr addr1;
     TCPCache tcpc;
@@ -8874,7 +8734,6 @@ static int StreamTcpTest30(void)
     TCPHdr tcph;
     TcpSession ssn;
     IPV4Hdr ipv4h;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     struct in_addr addr;
     struct in_addr addr1;
     TCPCache tcpc;
@@ -9597,7 +9456,6 @@ static int StreamTcpTest37(void)
     StreamTcpThread stt;
     uint8_t payload[4];
     TCPHdr tcph;
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     int ret = 0;
     PacketQueue pq;
     memset(&pq,0,sizeof(PacketQueue));
@@ -9610,16 +9468,14 @@ static int StreamTcpTest37(void)
 
     FLOW_INITIALIZE(&f);
 
-    stt.ra_ctx = ra_ctx;
     p->flow = &f;
     tcph.th_win = htons(5480);
     tcph.th_flags = TH_SYN;
     p->tcph = &tcph;
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1) {
         printf("failed in processing packet\n");
         goto end;
@@ -9696,10 +9552,9 @@ static int StreamTcpTest37(void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -9720,7 +9575,6 @@ static int StreamTcpTest38 (void)
     TCPHdr tcph;
     PacketQueue pq;
 
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -9738,10 +9592,8 @@ static int StreamTcpTest38 (void)
     tcph.th_flags = TH_SYN;
     p->tcph = &tcph;
     p->flowflags = FLOW_PKT_TOSERVER;
-    stt.ra_ctx = ra_ctx;
 
-    StreamTcpInitConfig(TRUE);
-    FLOWLOCK_WRLOCK(&f);
+    StreamTcpUTInit(&stt.ra_ctx);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1) {
         printf("failed in processing packet in StreamTcpPacket\n");
         goto end;
@@ -9856,12 +9708,9 @@ static int StreamTcpTest38 (void)
 
 end:
     StreamTcpSessionClear(p->flow->protoctx);
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
-    if (stt.ra_ctx != NULL)
-        StreamTcpReassembleFreeThreadCtx(stt.ra_ctx);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -9881,7 +9730,6 @@ static int StreamTcpTest39 (void)
     TCPHdr tcph;
     PacketQueue pq;
 
-    TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -9900,11 +9748,9 @@ static int StreamTcpTest39 (void)
     p->tcph = &tcph;
     p->flowflags = FLOW_PKT_TOSERVER;
     int ret = 0;
-    stt.ra_ctx = ra_ctx;
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1) {
         printf("failed in processing packet in StreamTcpPacket\n");
         goto end;
@@ -9997,12 +9843,9 @@ static int StreamTcpTest39 (void)
 
 end:
     StreamTcpSessionClear(p->flow->protoctx);
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
-    if (stt.ra_ctx != NULL)
-        StreamTcpReassembleFreeThreadCtx(stt.ra_ctx);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -10018,8 +9861,7 @@ static int StreamTcpTest40(void)
         0x00, 0x04, 0xf0, 0xc8, 0x01, 0x99, 0xa3, 0xf3
     };
     Packet *p = SCMalloc(SIZE_OF_PACKET);
-    if (unlikely(p == NULL))
-        return 0;
+    FAIL_IF(unlikely(p == NULL));
     ThreadVars tv;
     DecodeThreadVars dtv;
 
@@ -10035,33 +9877,23 @@ static int StreamTcpTest40(void)
 
     DecodeVLAN(&tv, &dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), NULL);
 
-    if(p->vlanh[0] == NULL) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(p->vlanh[0] == NULL);
 
-    if(p->tcph == NULL) {
-        SCFree(p);
-        return 0;
-    }
+    FAIL_IF(p->tcph == NULL);
 
     Packet *np = StreamTcpPseudoSetup(p, GET_PKT_DATA(p), GET_PKT_LEN(p));
-    if (np == NULL) {
-        printf("the packet received from packet allocation is NULL: ");
-        return 0;
-    }
+    FAIL_IF(np == NULL);
 
     StreamTcpPseudoPacketSetupHeader(np,p);
 
-    if (((uint8_t *)p->tcph - (uint8_t *)p->ip4h) != ((uint8_t *)np->tcph - (uint8_t *)np->ip4h)) {
-        return 0;
-    }
+    FAIL_IF(((uint8_t *)p->tcph - (uint8_t *)p->ip4h) != ((uint8_t *)np->tcph - (uint8_t *)np->ip4h));
 
-    PACKET_RECYCLE(np);
-    PACKET_RECYCLE(p);
+    PACKET_DESTRUCTOR(np);
+    PACKET_DESTRUCTOR(p);
     FlowShutdown();
-
-    return 1;
+    PacketFree(np);
+    PacketFree(p);
+    PASS;
 }
 
 static int StreamTcpTest41(void)
@@ -10152,7 +9984,7 @@ static int StreamTcpTest42 (void)
     memset(&stt, 0, sizeof (StreamTcpThread));
     memset(&tcph, 0, sizeof (TCPHdr));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     FLOW_INITIALIZE(&f);
     p->tcph = &tcph;
@@ -10164,7 +9996,6 @@ static int StreamTcpTest42 (void)
     tcph.th_seq = htonl(100);
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -10217,10 +10048,9 @@ static int StreamTcpTest42 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -10246,7 +10076,7 @@ static int StreamTcpTest43 (void)
     memset(&stt, 0, sizeof (StreamTcpThread));
     memset(&tcph, 0, sizeof (TCPHdr));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     FLOW_INITIALIZE(&f);
     p->tcph = &tcph;
@@ -10258,7 +10088,6 @@ static int StreamTcpTest43 (void)
     tcph.th_seq = htonl(100);
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -10311,10 +10140,9 @@ static int StreamTcpTest43 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -10340,7 +10168,7 @@ static int StreamTcpTest44 (void)
     memset(&stt, 0, sizeof (StreamTcpThread));
     memset(&tcph, 0, sizeof (TCPHdr));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
 
     FLOW_INITIALIZE(&f);
     p->tcph = &tcph;
@@ -10352,7 +10180,6 @@ static int StreamTcpTest44 (void)
     tcph.th_seq = htonl(100);
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -10400,10 +10227,9 @@ static int StreamTcpTest44 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
     FLOW_DESTROY(&f);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
@@ -10429,7 +10255,7 @@ static int StreamTcpTest45 (void)
     memset(&stt, 0, sizeof (StreamTcpThread));
     memset(&tcph, 0, sizeof (TCPHdr));
 
-    StreamTcpInitConfig(TRUE);
+    StreamTcpUTInit(&stt.ra_ctx);
     stream_config.max_synack_queued = 2;
 
     FLOW_INITIALIZE(&f);
@@ -10442,7 +10268,6 @@ static int StreamTcpTest45 (void)
     tcph.th_seq = htonl(100);
     p->flowflags = FLOW_PKT_TOSERVER;
 
-    FLOWLOCK_WRLOCK(&f);
     if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
         goto end;
 
@@ -10513,9 +10338,8 @@ static int StreamTcpTest45 (void)
 
     ret = 1;
 end:
-    StreamTcpFreeConfig(TRUE);
-    FLOWLOCK_UNLOCK(&f);
     SCFree(p);
+    StreamTcpUTDeinit(stt.ra_ctx);
     return ret;
 }
 
index 2a42785c5506d59c54f545beac8c00a0bdc3ed71..7feb057be3f16690c4fb7c20700a4d2880ae6fad 100644 (file)
@@ -105,6 +105,7 @@ void StreamTcpSessionPktFree (Packet *);
 void StreamTcpIncrMemuse(uint64_t);
 void StreamTcpDecrMemuse(uint64_t);
 int StreamTcpCheckMemcap(uint64_t);
+uint64_t StreamTcpReassembleMemuseGlobalCounter(void);
 
 Packet *StreamTcpPseudoSetup(Packet *, uint8_t *, uint32_t);