51static void DsizeRegisterTests(
void);
56static bool PrefilterDsizeIsPrefilterable(
const Signature *s);
124 "the same sig. Invalidating signature.");
145 SCLogDebug(
"dd->arg1 %" PRIu16
", dd->arg2 %" PRIu16
", dd->mode %" PRIu8
"", dd->arg1,
166 SCDetectU16Free(de_ptr);
175 if (!PrefilterPacketHeaderExtraMatch(
ctx, p))
180 du16.mode =
ctx->v1.u8[0];
181 du16.arg1 =
ctx->v1.u16[1];
182 du16.arg2 =
ctx->v1.u16[2];
186 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
196static bool PrefilterDsizeIsPrefilterable(
const Signature *s)
243 uint16_t high = 65535;
276 SCLogDebug(
"low %u, high %u, mode %u", low, high, dd->mode);
310 if (total_length > dsize) {
311 SCLogDebug(
"required_dsize: %d exceeds dsize: %d", total_length, dsize);
315 if ((total_length +
offset) > dsize) {
316 SCLogDebug(
"length + offset: %d exceeds dsize: %d", total_length +
offset, dsize);
317 return total_length +
offset;
341 for ( ; sm != NULL; sm = sm->
next) {
353 cd->
depth = (uint16_t)dsize;
354 SCLogDebug(
"updated %u, content %u to have depth %u "
355 "because of dsize.", s->
id, cd->
id, cd->
depth);
375static int DsizeTestParse01(
void)
382 DetectDsizeFree(NULL, dd);
390static int DsizeTestParse02(
void)
396 DetectDsizeFree(NULL, dd);
404static int DsizeTestParse03(
void)
411 DetectDsizeFree(NULL, dd);
419static int DsizeTestParse04(
void)
427 DetectDsizeFree(NULL, dd);
435static int DsizeTestParse05(
void)
443 DetectDsizeFree(NULL, dd);
451static int DsizeTestParse06(
void)
458 DetectDsizeFree(NULL, dd);
466static int DsizeTestParse07(
void)
473 DetectDsizeFree(NULL, dd);
481static int DsizeTestParse08(
void)
488 DetectDsizeFree(NULL, dd);
496static int DsizeTestParse09(
void)
500 DetectDsizeFree(NULL, dd);
508static int DsizeTestParse10(
void)
512 DetectDsizeFree(NULL, dd);
521static int DsizeTestParse11(
void)
523 const char *strings[] = {
"A",
">10<>10",
"<>10",
"1<>",
"",
" ",
"2<>1",
"1!", NULL };
524 for (
int i = 0; strings[i]; i++) {
536static int DsizeTestMatch01(
void)
539 uint16_t dsizelow = 2;
540 uint16_t dsizehigh = 0;
543 du16.arg1 = dsizelow;
544 du16.arg2 = dsizehigh;
554static int DsizeTestMatch02(
void)
557 uint16_t dsizelow = 1;
558 uint16_t dsizehigh = 0;
561 du16.arg1 = dsizelow;
562 du16.arg2 = dsizehigh;
573static int DetectDsizeIcmpv6Test01(
void)
575 static uint8_t raw_icmpv6[] = {
576 0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
577 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
579 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
580 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
581 0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
582 0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
583 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
584 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
585 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
586 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
612 "alert icmp any any -> any any "
613 "(msg:\"ICMP Large ICMP Packet\"; dsize:>8; sid:1; rev:4;)");
617 "alert icmp any any -> any any "
618 "(msg:\"ICMP Large ICMP Packet\"; dsize:>800; sid:2; rev:4;)");
641static void DsizeRegisterTests(
void)
657 UtRegisterTest(
"DetectDsizeIcmpv6Test01", DetectDsizeIcmpv6Test01);
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
void SigParseRequiredContentSize(const Signature *s, const uint64_t max_size, const SigMatch *sm, int *len, int *offset)
Determine the size needed to accommodate the content elements of a signature.
#define DETECT_CONTENT_DEPTH
void SigParseApplyDsizeToContent(Signature *s)
Apply dsize as depth to content matches in the rule.
int SigParseMaxRequiredDsize(const Signature *s)
Determine the required dsize for the signature.
void DetectDsizeRegister(void)
Registration function for dsize: keyword.
void SigParseSetDsizePair(Signature *s)
set prefilter dsize pair
int SigParseGetMaxDsize(const Signature *s, uint16_t *dsize)
get max dsize "depth"
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
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))
DetectEngineCtx * DetectEngineCtxInit(void)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
int DetectU16Match(const uint16_t parg, const DetectUintData_u16 *du16)
void PrefilterPacketU16Set(PrefilterPacketHeaderValue *v, void *smctx)
bool PrefilterPacketU16Compare(PrefilterPacketHeaderValue v, void *smctx)
DetectUintData_u16 * DetectU16Parse(const char *u16str)
This function is used to parse u16 options passed via some u16 keyword.
DetectUintData_u16 DetectU16Data
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
SigMatch * DetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
SigTableElmt * sigmatch_table
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
#define SIG_FLAG_REQUIRE_PACKET
#define SIGMATCH_SUPPORT_FIREWALL
#define SIG_MASK_REQUIRE_REAL_PKT
void FlowInitConfig(bool quiet)
initialize the configuration
void FlowShutdown(void)
shutdown the flow engine
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
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 PASS
Pass the test.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
void PacketRecycle(Packet *p)
Structure to hold thread specific data for all decode modules.
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.
#define SCLogError(...)
Macro used to log ERROR messages.
#define DEBUG_VALIDATE_BUG_ON(exp)