18 #include "../suricata-common.h"
19 #include "../stream-tcp-private.h"
20 #include "../stream-tcp.h"
21 #include "../stream-tcp-reassemble.h"
22 #include "../stream-tcp-inline.h"
23 #include "../stream-tcp-list.h"
24 #include "../stream-tcp-util.h"
25 #include "../util-streaming-buffer.h"
26 #include "../util-print.h"
27 #include "../util-unittest.h"
34 static int TestReassembleRawCallback(
35 void *cb_data,
const uint8_t *data,
const uint32_t data_len,
const uint64_t
offset)
54 const uint8_t *data,
const uint32_t data_len)
57 uint64_t progress = 0;
66 #define RAWREASSEMBLY_START(isn) \
67 TcpReassemblyThreadCtx *ra_ctx = NULL; \
70 memset(&tv, 0, sizeof(tv)); \
74 StreamTcpUTInit(&ra_ctx); \
75 StreamTcpUTInitInline(); \
76 stream_config.reassembly_toserver_chunk_size = 9; \
77 stream_config.reassembly_toclient_chunk_size = 9; \
78 StreamTcpUTSetupSession(&ssn); \
79 StreamTcpUTSetupStream(&ssn.server, (isn)); \
80 StreamTcpUTSetupStream(&ssn.client, (isn)); \
81 ssn.server.last_ack = (isn) + 1; \
82 ssn.client.last_ack = (isn) + 1; \
84 TcpStream *stream = &ssn.client;
86 #define RAWREASSEMBLY_END \
87 StreamTcpUTClearSession(&ssn); \
88 StreamTcpUTDeinit(ra_ctx); \
91 #define RAWREASSEMBLY_STEP(seq, seg, seglen, buf, buflen) \
92 p = PacketGetFromAlloc(); \
95 SCLogNotice("SEQ %u block of %u", (seq), (seglen)); \
96 p->flowflags = FLOW_PKT_TOSERVER; \
98 memset(&tcphdr, 0, sizeof(tcphdr)); \
99 UTHSetTCPHdr(p, &tcphdr); \
100 tcphdr.th_seq = htonl((seq)); \
101 tcphdr.th_ack = htonl(10); \
102 p->payload_len = (seglen); \
104 FAIL_IF(StreamTcpUTAddPayload( \
105 &tv, ra_ctx, &ssn, stream, (seq), (uint8_t *)(seg), (seglen)) != 0); \
106 p->flags |= PKT_STREAM_ADD; \
107 FAIL_IF(!(TestReassembleRawValidate(&ssn, p, (uint8_t *)(buf), (buflen)))); \
111 #define RAWREASSEMBLY_STEP_WITH_PROGRESS(seq, seg, seglen, buf, buflen, lastack, progress) \
112 stream->last_ack = (lastack); \
113 RAWREASSEMBLY_STEP((seq),(seg),(seglen),(buf),(buflen)); \
114 FAIL_IF(STREAM_RAW_PROGRESS(stream) != (progress));
116 static int StreamTcpReassembleRawTest01 (
void)
125 static int StreamTcpReassembleRawTest02 (
void)
135 static int StreamTcpReassembleRawTest03 (
void)
144 static int StreamTcpReassembleRawTest04 (
void)
153 static int StreamTcpReassembleRawTest05 (
void)
162 static int StreamTcpReassembleRawTest06 (
void)
172 static int StreamTcpReassembleRawTest07 (
void)
182 static int StreamTcpReassembleRawTest08 (
void)
192 static void StreamTcpReassembleRawRegisterTests(
void)
195 StreamTcpReassembleRawTest01);
197 StreamTcpReassembleRawTest02);
199 StreamTcpReassembleRawTest03);
201 StreamTcpReassembleRawTest04);
203 StreamTcpReassembleRawTest05);
205 StreamTcpReassembleRawTest06);
207 StreamTcpReassembleRawTest07);
209 StreamTcpReassembleRawTest08);