49 static void DetectStreamSizeRegisterTests(
void);
52 static bool PrefilterStreamSizeIsPrefilterable(
const Signature *s);
73 static int DetectStreamSizeMatchAux(
const DetectStreamSizeData *sd,
const TcpSession *ssn)
79 if (sd->flags == StreamSizeServer) {
84 }
else if (sd->flags == StreamSizeClient) {
89 }
else if (sd->flags == StreamSizeBoth) {
96 }
else if (sd->flags == StreamSizeEither) {
118 static int DetectStreamSizeMatch(
121 const DetectStreamSizeData *sd = (
const DetectStreamSizeData *)
ctx;
123 if (!(PacketIsTCP(p)))
145 DetectStreamSizeData *sd = rs_detect_stream_size_parse(streamstr);
164 rs_detect_stream_size_free(ptr);
169 static void PrefilterPacketStreamsizeMatch(
172 if (!(PacketIsTCP(p)))
181 if (!PrefilterPacketHeaderExtraMatch(
ctx, p))
184 DetectStreamSizeData dsd;
185 dsd.du32.mode =
ctx->v1.u8[0];
186 dsd.flags =
ctx->v1.u8[1];
187 dsd.du32.arg1 =
ctx->v1.u32[2];
191 if (DetectStreamSizeMatchAux(&dsd, ssn)) {
192 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
198 const DetectStreamSizeData *a = smctx;
199 v->
u8[0] = a->du32.mode;
201 v->
u32[2] = a->du32.arg1;
206 const DetectStreamSizeData *a = smctx;
207 if (v.
u8[0] == a->du32.mode && v.
u8[1] == a->flags && v.
u32[2] == a->du32.arg1)
215 PrefilterPacketStreamSizeSet, PrefilterPacketStreamSizeCompare,
216 PrefilterPacketStreamsizeMatch);
219 static bool PrefilterStreamSizeIsPrefilterable(
const Signature *s)
237 static int DetectStreamSizeParseTest01 (
void)
240 DetectStreamSizeData *sd = NULL;
241 sd = rs_detect_stream_size_parse(
"server,<,6");
243 if (sd->flags & StreamSizeServer && sd->du32.mode ==
DETECT_UINT_LT && sd->du32.arg1 == 6)
256 static int DetectStreamSizeParseTest02 (
void)
259 DetectStreamSizeData *sd = NULL;
260 sd = rs_detect_stream_size_parse(
"invalidoption,<,6");
262 printf(
"expected: NULL got 0x%02X %" PRIu32
": ", sd->flags, sd->du32.arg1);
275 static int DetectStreamSizeParseTest03 (
void)
279 DetectStreamSizeData *sd = NULL;
298 memset(&f, 0,
sizeof(
Flow));
299 memset(&tcph, 0,
sizeof(
TCPHdr));
301 sd = rs_detect_stream_size_parse(
"client,>,8");
303 if (!(sd->flags & StreamSizeClient)) {
304 printf(
"sd->flags not STREAM_SIZE_CLIENT: ");
311 printf(
"sd->mode not DETECTSSIZE_GT: ");
317 if (sd->du32.arg1 != 8) {
318 printf(
"sd->ssize is %" PRIu32
", not 8: ", sd->du32.arg1);
324 printf(
"sd == NULL: ");
334 PacketSetTCP(p, (uint8_t *)&tcph);
337 result = DetectStreamSizeMatch(&dtx, p, &s, sm.
ctx);
339 printf(
"result 0 != 1: ");
351 static int DetectStreamSizeParseTest04 (
void)
355 DetectStreamSizeData *sd = NULL;
374 memset(&f, 0,
sizeof(
Flow));
375 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
377 sd = rs_detect_stream_size_parse(
" client , > , 8 ");
379 if (!(sd->flags & StreamSizeClient) && sd->du32.mode !=
DETECT_UINT_GT &&
380 sd->du32.arg1 != 8) {
398 if (!DetectStreamSizeMatch(&dtx, p, &s, sm.
ctx))
408 void DetectStreamSizeRegisterTests(
void)
410 UtRegisterTest(
"DetectStreamSizeParseTest01", DetectStreamSizeParseTest01);
411 UtRegisterTest(
"DetectStreamSizeParseTest02", DetectStreamSizeParseTest02);
412 UtRegisterTest(
"DetectStreamSizeParseTest03", DetectStreamSizeParseTest03);
413 UtRegisterTest(
"DetectStreamSizeParseTest04", DetectStreamSizeParseTest04);