From e5b638e5e8292b4532e68373a5af57ff553f20b6 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Wed, 2 Nov 2011 15:17:44 +0100 Subject: [PATCH] threshold: introduce SigGetThresholdTypeIter function This patch introduces a function called SigGetThresholdTypeIter which iterate on all Threshold for a given signature returning the next DetectThresholdData. --- src/detect-engine-threshold.c | 33 ++++++++++++++++++++++++++++++--- src/detect-engine-threshold.h | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/detect-engine-threshold.c b/src/detect-engine-threshold.c index 71790c81a0..b0b25be229 100644 --- a/src/detect-engine-threshold.c +++ b/src/detect-engine-threshold.c @@ -64,24 +64,38 @@ #include "tm-threads.h" /** - * \brief Check if a certain signature has threshold option + * \brief Return next DetectThresholdData for signature * * \param sig Signature pointer * \param p Packet structure + * \param sm Pointer to a Signature Match pointer * * \retval tsh Return the threshold data from signature or NULL if not found + * + * */ -DetectThresholdData *SigGetThresholdType(Signature *sig, Packet *p) +DetectThresholdData *SigGetThresholdTypeIter(Signature *sig, Packet *p, SigMatch **psm) { - SigMatch *sm = sig->sm_lists_tail[DETECT_SM_LIST_MATCH]; + SigMatch *sm = NULL; DetectThresholdData *tsh = NULL; + if (sig == NULL) + return NULL; + + if (*psm == NULL) { + sm = sig->sm_lists_tail[DETECT_SM_LIST_MATCH]; + } else { + /* Iteration in progress, using provided value */ + sm = *psm; + } + if (p == NULL) return NULL; while (sm != NULL) { if (sm->type == DETECT_THRESHOLD || sm->type == DETECT_DETECTION_FILTER) { tsh = (DetectThresholdData *)sm->ctx; + *psm = sm->prev; return tsh; } @@ -91,6 +105,19 @@ DetectThresholdData *SigGetThresholdType(Signature *sig, Packet *p) return NULL; } +/** + * \brief Check if a certain signature has threshold option + * + * \param sig Signature pointer + * \param p Packet structure + * + * \retval tsh Return the threshold data from signature or NULL if not found + */ +DetectThresholdData *SigGetThresholdType(Signature *sig, Packet *p) +{ + return SigGetThresholdTypeIter(sig, p, NULL); +} + /** * \brief Search for a threshold data into threshold hash table * diff --git a/src/detect-engine-threshold.h b/src/detect-engine-threshold.h index 679f8b95be..b547a636cc 100644 --- a/src/detect-engine-threshold.h +++ b/src/detect-engine-threshold.h @@ -30,6 +30,7 @@ #define THRESHOLD_HASH_SIZE 0xffff DetectThresholdData *SigGetThresholdType(Signature *, Packet *); +DetectThresholdData *SigGetThresholdTypeIter(Signature *sig, Packet *p, SigMatch **psm); int PacketAlertThreshold(DetectEngineCtx *, DetectEngineThreadCtx *, DetectThresholdData *, Packet *, Signature *); void ThresholdFreeFunc(void *data);