From a53ba4af94f36d8ed69ce4fd4101c398f0b28422 Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Fri, 12 Dec 2025 12:19:16 +0530 Subject: [PATCH] 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. --- src/detect-dsize.c | 9 +-------- src/detect-flow.c | 9 +-------- src/detect-fragbits.c | 9 +-------- src/detect-fragoffset.c | 9 +-------- src/detect-icmp-id.c | 9 +-------- src/detect-icmp-seq.c | 9 +-------- src/detect-icode.c | 9 +-------- src/detect-id.c | 9 +-------- src/detect-itype.c | 9 +-------- src/detect-tcp-ack.c | 9 +-------- src/detect-tcp-flags.c | 9 +-------- src/detect-tcp-seq.c | 9 +-------- src/detect-tcp-wscale.c | 9 +-------- src/detect-tcpmss.c | 9 +-------- src/detect-template2.c | 9 +-------- src/detect-ttl.c | 9 +-------- 16 files changed, 16 insertions(+), 128 deletions(-) diff --git a/src/detect-dsize.c b/src/detect-dsize.c index fcd89445b5..d253b26f79 100644 --- a/src/detect-dsize.c +++ b/src/detect-dsize.c @@ -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" diff --git a/src/detect-flow.c b/src/detect-flow.c index 6dff0b0f59..b3a691ef2b 100644 --- a/src/detect-flow.c +++ b/src/detect-flow.c @@ -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 diff --git a/src/detect-fragbits.c b/src/detect-fragbits.c index 0986610cfa..e6f95b736f 100644 --- a/src/detect-fragbits.c +++ b/src/detect-fragbits.c @@ -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); } /* diff --git a/src/detect-fragoffset.c b/src/detect-fragoffset.c index 707305d79c..34b141abda 100644 --- a/src/detect-fragoffset.c +++ b/src/detect-fragoffset.c @@ -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 diff --git a/src/detect-icmp-id.c b/src/detect-icmp-id.c index aa0fd07771..52db2eb243 100644 --- a/src/detect-icmp-id.c +++ b/src/detect-icmp-id.c @@ -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 diff --git a/src/detect-icmp-seq.c b/src/detect-icmp-seq.c index 5de95b8d92..2b00cddc6c 100644 --- a/src/detect-icmp-seq.c +++ b/src/detect-icmp-seq.c @@ -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 diff --git a/src/detect-icode.c b/src/detect-icode.c index 284ebd3a15..8dcb83b64b 100644 --- a/src/detect-icode.c +++ b/src/detect-icode.c @@ -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 diff --git a/src/detect-id.c b/src/detect-id.c index 82a8bf21f8..6fdb50b86a 100644 --- a/src/detect-id.c +++ b/src/detect-id.c @@ -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 */ diff --git a/src/detect-itype.c b/src/detect-itype.c index 5f9ca7dad8..d9f48a44ca 100644 --- a/src/detect-itype.c +++ b/src/detect-itype.c @@ -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 diff --git a/src/detect-tcp-ack.c b/src/detect-tcp-ack.c index 22a0e733a5..e3e629a9e9 100644 --- a/src/detect-tcp-ack.c +++ b/src/detect-tcp-ack.c @@ -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 diff --git a/src/detect-tcp-flags.c b/src/detect-tcp-flags.c index c8c139391b..10140e02fc 100644 --- a/src/detect-tcp-flags.c +++ b/src/detect-tcp-flags.c @@ -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); } /* diff --git a/src/detect-tcp-seq.c b/src/detect-tcp-seq.c index 840fec3df4..b38cb97f2e 100644 --- a/src/detect-tcp-seq.c +++ b/src/detect-tcp-seq.c @@ -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); } diff --git a/src/detect-tcp-wscale.c b/src/detect-tcp-wscale.c index 637dc94ca6..4f42a41014 100644 --- a/src/detect-tcp-wscale.c +++ b/src/detect-tcp-wscale.c @@ -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); } diff --git a/src/detect-tcpmss.c b/src/detect-tcpmss.c index 361210ee98..f34d10ef2e 100644 --- a/src/detect-tcpmss.c +++ b/src/detect-tcpmss.c @@ -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); } diff --git a/src/detect-template2.c b/src/detect-template2.c index 4920941418..b5a7d155f5 100644 --- a/src/detect-template2.c +++ b/src/detect-template2.c @@ -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); } diff --git a/src/detect-ttl.c b/src/detect-ttl.c index 44e370fe4a..6837f5198a 100644 --- a/src/detect-ttl.c +++ b/src/detect-ttl.c @@ -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