Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/lib/custom/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ int main(int argc, char **argv)
* ThreadVars will be ready. */
SuricataInit();

SCDetectEngineRegisterRateFilterCallback(RateFilterCallback, NULL);
if (DetectEngineEnabled()) {
SCDetectEngineRegisterRateFilterCallback(RateFilterCallback, NULL);
} else {
SCLogWarning("detection engine not enabled, rate filter callback not registered");
}

/* Spawn our worker threads. */
pthread_t worker;
Expand Down
6 changes: 5 additions & 1 deletion examples/lib/live/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ int main(int argc, char **argv)
* ThreadVars will be ready. */
SuricataInit();

SCDetectEngineRegisterRateFilterCallback(RateFilterCallback, NULL);
if (DetectEngineEnabled()) {
SCDetectEngineRegisterRateFilterCallback(RateFilterCallback, NULL);
} else {
SCLogWarning("detection engine not enabled, rate filter callback not registered");
}

/* Spawn our worker threads, one for each interface. */
pthread_t workers[MAX_INTERFACES];
Expand Down
4 changes: 4 additions & 0 deletions src/detect-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -5206,6 +5206,10 @@ void DetectLowerSetupCallback(
void SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc fn, void *arg)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is right to have a bool return value, but the examples should use it and warn as commented in #15380 (comment)

{
DetectEngineCtx *de_ctx = DetectEngineGetCurrent();
if (de_ctx == NULL) {
SCLogError("no detection engine available for rate filter callback registration");
return;
}
de_ctx->RateFilterCallback = fn;
de_ctx->rate_filter_callback_arg = arg;
DetectEngineDeReference(&de_ctx);
Expand Down