detect: use PrefilterIsPrefilterableById where possible

cocci script used:

@@
identifier s, sm, DETECT_TYPE;
@@

- for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
-     switch (sm->type) {
-         case DETECT_TYPE:
-             return true;
-     }
- }
- return false;
+ return PrefilterIsPrefilterableById(s, DETECT_TYPE);

followed by some basic cmdline manipulations to get rid of extras left.
This commit is contained in:
Shivani Bhardwaj
2025-12-12 13:20:15 +00:00
committed by Victor Julien
parent 726139a539
commit a53ba4af94
16 changed files with 16 additions and 128 deletions
+1 -8
View File
@@ -195,14 +195,7 @@ static int PrefilterSetupDsize(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterDsizeIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_DSIZE:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_DSIZE);
}
/** \brief get max dsize "depth"
+1 -8
View File
@@ -511,14 +511,7 @@ static int PrefilterSetupFlow(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterFlowIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_FLOW:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_FLOW);
}
#ifdef UNITTESTS
+1 -8
View File
@@ -175,14 +175,7 @@ static int PrefilterSetupFragBits(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterFragBitsIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_FRAGBITS:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_FRAGBITS);
}
/*
+1 -8
View File
@@ -187,14 +187,7 @@ static int PrefilterSetupFragOffset(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterFragOffsetIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_FRAGOFFSET:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_FRAGOFFSET);
}
#ifdef UNITTESTS
+1 -8
View File
@@ -207,14 +207,7 @@ static int PrefilterSetupIcmpId(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterIcmpIdIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_ICMP_ID:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_ICMP_ID);
}
#ifdef UNITTESTS
+1 -8
View File
@@ -210,14 +210,7 @@ static int PrefilterSetupIcmpSeq(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterIcmpSeqIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_ICMP_SEQ:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_ICMP_SEQ);
}
#ifdef UNITTESTS
+1 -8
View File
@@ -177,14 +177,7 @@ static int PrefilterSetupICode(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterICodeIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_ICODE:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_ICODE);
}
#ifdef UNITTESTS
+1 -8
View File
@@ -177,14 +177,7 @@ static int PrefilterSetupId(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterIdIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_ID:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_ID);
}
#ifdef UNITTESTS /* UNITTESTS */
+1 -8
View File
@@ -179,14 +179,7 @@ static int PrefilterSetupIType(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterITypeIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_ITYPE:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_ITYPE);
}
#ifdef UNITTESTS
+1 -8
View File
@@ -167,14 +167,7 @@ static int PrefilterSetupTcpAck(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterTcpAckIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_ACK:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_ACK);
}
#ifdef UNITTESTS
+1 -8
View File
@@ -238,14 +238,7 @@ static int PrefilterSetupTcpFlags(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterTcpFlagsIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_FLAGS:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_FLAGS);
}
/*
+1 -8
View File
@@ -162,14 +162,7 @@ static int PrefilterSetupTcpSeq(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterTcpSeqIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_SEQ:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_SEQ);
}
+1 -8
View File
@@ -164,12 +164,5 @@ static int PrefilterSetupTcpWscale(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterTcpWscaleIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH]; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_TCP_WSCALE:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_TCP_WSCALE);
}
+1 -8
View File
@@ -165,12 +165,5 @@ static int PrefilterSetupTcpmss(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterTcpmssIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_TCPMSS:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_TCPMSS);
}
+1 -8
View File
@@ -177,12 +177,5 @@ static int PrefilterSetupTemplate2(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterTemplate2IsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_TEMPLATE2:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_TEMPLATE2);
}
+1 -8
View File
@@ -176,14 +176,7 @@ static int PrefilterSetupTtl(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
static bool PrefilterTtlIsPrefilterable(const Signature *s)
{
const SigMatch *sm;
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
switch (sm->type) {
case DETECT_TTL:
return true;
}
}
return false;
return PrefilterIsPrefilterableById(s, DETECT_TTL);
}
#ifdef UNITTESTS