49static void DetectStreamSizeRegisterTests(
void);
52static bool PrefilterStreamSizeIsPrefilterable(
const Signature *s);
73static 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) {
118static int DetectStreamSizeMatch(
121 const DetectStreamSizeData *sd = (
const DetectStreamSizeData *)
ctx;
123 if (!(PacketIsTCP(p)))
145 DetectStreamSizeData *sd = SCDetectStreamSizeParse(streamstr);
164 SCDetectStreamSizeFree(ptr);
169static 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);
219static bool PrefilterStreamSizeIsPrefilterable(
const Signature *s)
237static int DetectStreamSizeParseTest01 (
void)
240 DetectStreamSizeData *sd = NULL;
241 sd = SCDetectStreamSizeParse(
"server,<,6");
243 if (sd->flags & StreamSizeServer && sd->du32.mode ==
DETECT_UINT_LT && sd->du32.arg1 == 6)
256static int DetectStreamSizeParseTest02 (
void)
259 DetectStreamSizeData *sd = NULL;
260 sd = SCDetectStreamSizeParse(
"invalidoption,<,6");
262 printf(
"expected: NULL got 0x%02X %" PRIu32
": ", sd->flags, sd->du32.arg1);
275static int DetectStreamSizeParseTest03 (
void)
279 DetectStreamSizeData *sd = NULL;
298 memset(&f, 0,
sizeof(
Flow));
299 memset(&tcph, 0,
sizeof(
TCPHdr));
301 sd = SCDetectStreamSizeParse(
"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: ");
351static int DetectStreamSizeParseTest04 (
void)
355 DetectStreamSizeData *sd = NULL;
374 memset(&f, 0,
sizeof(
Flow));
375 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
377 sd = SCDetectStreamSizeParse(
" 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))
408void DetectStreamSizeRegisterTests(
void)
410 UtRegisterTest(
"DetectStreamSizeParseTest01", DetectStreamSizeParseTest01);
411 UtRegisterTest(
"DetectStreamSizeParseTest02", DetectStreamSizeParseTest02);
412 UtRegisterTest(
"DetectStreamSizeParseTest03", DetectStreamSizeParseTest03);
413 UtRegisterTest(
"DetectStreamSizeParseTest04", DetectStreamSizeParseTest04);
int PrefilterSetupPacketHeader(DetectEngineCtx *de_ctx, SigGroupHead *sgh, int sm_type, SignatureMask mask, void(*Set)(PrefilterPacketHeaderValue *v, void *), bool(*Compare)(PrefilterPacketHeaderValue v, void *), void(*Match)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx))
int DetectU32Match(const uint32_t parg, const DetectUintData_u32 *du32)
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
SigTableElmt * sigmatch_table
void DetectStreamSizeRegister(void)
Registration function for stream_size: keyword.
void DetectStreamSizeFree(DetectEngineCtx *de_ctx, void *)
this function will free memory associated with DetectStreamSizeData
#define SIG_MASK_REQUIRE_FLOW
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
main detection engine ctx
Container for matching data for a signature group.
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
a single match condition for a signature
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
void(* Free)(DetectEngineCtx *, void *)
void(* RegisterTests)(void)
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
bool(* SupportsPrefilter)(const Signature *s)
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
SignatureInitData * init_data
Per thread variable structure.
void UTHSetIPV4Hdr(Packet *p, IPV4Hdr *ip4h)