Go to the documentation of this file.
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"
41 #define INLINE_START(isn) \
43 TcpReassemblyThreadCtx *ra_ctx = NULL; \
46 memset(&tv, 0, sizeof(tv)); \
48 StreamTcpUTInit(&ra_ctx); \
49 StreamTcpUTInitInline(); \
51 StreamTcpUTSetupSession(&ssn); \
52 StreamTcpUTSetupStream(&ssn.server, (isn)); \
53 StreamTcpUTSetupStream(&ssn.client, (isn)); \
55 TcpStream *stream = &ssn.client;
58 StreamTcpUTClearSession(&ssn); \
59 StreamTcpUTDeinit(ra_ctx); \
62 #define INLINE_ADD_PAYLOAD(rseq, seg, seglen, packet, packetlen) \
63 p = UTHBuildPacketReal( \
64 (uint8_t *)(seg), (seglen), IPPROTO_TCP, "1.1.1.1", "2.2.2.2", 1024, 80); \
66 p->l4.hdrs.tcph->th_seq = htonl(stream->isn + (rseq)); \
67 p->l4.hdrs.tcph->th_ack = htonl(31); \
68 FAIL_IF(StreamTcpReassembleHandleSegmentHandleData(&tv, ra_ctx, &ssn, stream, p) < 0); \
69 FAIL_IF(memcmp(p->payload, packet, MIN((packetlen), p->payload_len)) != 0); \
72 #define INLINE_STEP(rseq, seg, seglen, buf, buflen, packet, packetlen) \
73 INLINE_ADD_PAYLOAD((rseq), (seg), (seglen), (packet), (packetlen)); \
74 FAIL_IF(!(VALIDATE(stream, (uint8_t *)(buf), (buflen))));
81 static int StreamTcpInlineTest01(
void)
90 static int StreamTcpInlineTest02(
void)
99 static int StreamTcpInlineTest03(
void)
102 INLINE_STEP(1,
"ABCDE", 5,
"ABCDE", 5,
"ABCDE", 5);
103 INLINE_STEP(3,
"xxxxx", 5,
"ABCDExx", 7,
"CDExx", 5);
108 static int StreamTcpInlineTest04(
void)
114 INLINE_STEP(1,
"xxxxx", 5,
"xxABCDE", 7,
"xxABC", 5);
119 static int StreamTcpInlineTest05(
void)
133 static int StreamTcpInlineTest06(
void)
160 INLINE_STEP(1,
"xxxxxxxxx", 9,
"xAxAxAxAx", 9,
"xAxAxAxAx", 9);
165 static int StreamTcpInlineTest07(
void)
171 INLINE_STEP(1,
"XXABC", 5,
"XXABCDE", 7,
"XXABC", 5);
175 static int StreamTcpInlineTest08(
void)
178 INLINE_STEP(1,
"AAAAA", 5,
"AAAAA", 5,
"AAAAA", 5);
179 INLINE_STEP(1,
"BBBBB", 5,
"AAAAA", 5,
"AAAAA", 5);
180 INLINE_STEP(1,
"CCCCCCCCCC", 10,
"AAAAACCCCC", 10,
"AAAAACCCCC", 10);
182 INLINE_STEP(11,
"X", 1,
"AAAAACCCCCX", 11,
"X", 1);
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define INLINE_ADD_PAYLOAD(rseq, seg, seglen, packet, packetlen)
int UTHCheckDataAtPosition(TcpStream *stream, int pos, uint64_t offset, const char *data, uint32_t len)
void PrintRawDataFp(FILE *fp, const uint8_t *buf, uint32_t buflen)
int StreamingBufferCompareRawData(const StreamingBuffer *sb, const uint8_t *rawdata, uint32_t rawdata_len)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define INLINE_STEP(rseq, seg, seglen, buf, buflen, packet, packetlen)
#define INLINE_START(isn)
void StreamTcpInlineRegisterTests(void)
int UTHCheckGapAtPosition(TcpStream *stream, int pos, uint64_t offset, uint32_t len)