Skip to content

Commit a53ba4a

Browse files
inashivbvictorjulien
authored andcommitted
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.
1 parent 726139a commit a53ba4a

16 files changed

Lines changed: 16 additions & 128 deletions

src/detect-dsize.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,7 @@ static int PrefilterSetupDsize(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
195195

196196
static bool PrefilterDsizeIsPrefilterable(const Signature *s)
197197
{
198-
const SigMatch *sm;
199-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
200-
switch (sm->type) {
201-
case DETECT_DSIZE:
202-
return true;
203-
}
204-
}
205-
return false;
198+
return PrefilterIsPrefilterableById(s, DETECT_DSIZE);
206199
}
207200

208201
/** \brief get max dsize "depth"

src/detect-flow.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,7 @@ static int PrefilterSetupFlow(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
511511

512512
static bool PrefilterFlowIsPrefilterable(const Signature *s)
513513
{
514-
const SigMatch *sm;
515-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
516-
switch (sm->type) {
517-
case DETECT_FLOW:
518-
return true;
519-
}
520-
}
521-
return false;
514+
return PrefilterIsPrefilterableById(s, DETECT_FLOW);
522515
}
523516

524517
#ifdef UNITTESTS

src/detect-fragbits.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,7 @@ static int PrefilterSetupFragBits(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
175175

176176
static bool PrefilterFragBitsIsPrefilterable(const Signature *s)
177177
{
178-
const SigMatch *sm;
179-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
180-
switch (sm->type) {
181-
case DETECT_FRAGBITS:
182-
return true;
183-
}
184-
}
185-
return false;
178+
return PrefilterIsPrefilterableById(s, DETECT_FRAGBITS);
186179
}
187180

188181
/*

src/detect-fragoffset.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,7 @@ static int PrefilterSetupFragOffset(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
187187

188188
static bool PrefilterFragOffsetIsPrefilterable(const Signature *s)
189189
{
190-
const SigMatch *sm;
191-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
192-
switch (sm->type) {
193-
case DETECT_FRAGOFFSET:
194-
return true;
195-
}
196-
}
197-
return false;
190+
return PrefilterIsPrefilterableById(s, DETECT_FRAGOFFSET);
198191
}
199192

200193
#ifdef UNITTESTS

src/detect-icmp-id.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,7 @@ static int PrefilterSetupIcmpId(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
207207

208208
static bool PrefilterIcmpIdIsPrefilterable(const Signature *s)
209209
{
210-
const SigMatch *sm;
211-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
212-
switch (sm->type) {
213-
case DETECT_ICMP_ID:
214-
return true;
215-
}
216-
}
217-
return false;
210+
return PrefilterIsPrefilterableById(s, DETECT_ICMP_ID);
218211
}
219212

220213
#ifdef UNITTESTS

src/detect-icmp-seq.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,7 @@ static int PrefilterSetupIcmpSeq(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
210210

211211
static bool PrefilterIcmpSeqIsPrefilterable(const Signature *s)
212212
{
213-
const SigMatch *sm;
214-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
215-
switch (sm->type) {
216-
case DETECT_ICMP_SEQ:
217-
return true;
218-
}
219-
}
220-
return false;
213+
return PrefilterIsPrefilterableById(s, DETECT_ICMP_SEQ);
221214
}
222215

223216
#ifdef UNITTESTS

src/detect-icode.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,7 @@ static int PrefilterSetupICode(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
177177

178178
static bool PrefilterICodeIsPrefilterable(const Signature *s)
179179
{
180-
const SigMatch *sm;
181-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
182-
switch (sm->type) {
183-
case DETECT_ICODE:
184-
return true;
185-
}
186-
}
187-
return false;
180+
return PrefilterIsPrefilterableById(s, DETECT_ICODE);
188181
}
189182

190183
#ifdef UNITTESTS

src/detect-id.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,7 @@ static int PrefilterSetupId(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
177177

178178
static bool PrefilterIdIsPrefilterable(const Signature *s)
179179
{
180-
const SigMatch *sm;
181-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
182-
switch (sm->type) {
183-
case DETECT_ID:
184-
return true;
185-
}
186-
}
187-
return false;
180+
return PrefilterIsPrefilterableById(s, DETECT_ID);
188181
}
189182

190183
#ifdef UNITTESTS /* UNITTESTS */

src/detect-itype.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,7 @@ static int PrefilterSetupIType(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
179179

180180
static bool PrefilterITypeIsPrefilterable(const Signature *s)
181181
{
182-
const SigMatch *sm;
183-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
184-
switch (sm->type) {
185-
case DETECT_ITYPE:
186-
return true;
187-
}
188-
}
189-
return false;
182+
return PrefilterIsPrefilterableById(s, DETECT_ITYPE);
190183
}
191184

192185
#ifdef UNITTESTS

src/detect-tcp-ack.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,7 @@ static int PrefilterSetupTcpAck(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
167167

168168
static bool PrefilterTcpAckIsPrefilterable(const Signature *s)
169169
{
170-
const SigMatch *sm;
171-
for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
172-
switch (sm->type) {
173-
case DETECT_ACK:
174-
return true;
175-
}
176-
}
177-
return false;
170+
return PrefilterIsPrefilterableById(s, DETECT_ACK);
178171
}
179172

180173
#ifdef UNITTESTS

0 commit comments

Comments
 (0)