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
7 changes: 6 additions & 1 deletion src/detect-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -5203,12 +5203,17 @@ void DetectLowerSetupCallback(
}
}

void SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc fn, void *arg)
bool SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc fn, void *arg)
{
DetectEngineCtx *de_ctx = DetectEngineGetCurrent();
if (de_ctx == NULL) {
SCLogError("no detection engine available for rate filter callback registration");
return false;
}
de_ctx->RateFilterCallback = fn;
de_ctx->rate_filter_callback_arg = arg;
DetectEngineDeReference(&de_ctx);
return true;

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.

Why do we add a return value and ignore it ?

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.

Looks like #15380 (comment) was not taken into account

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Looks like #15380 (comment) was not taken into account

Addressed in #15558: reverted the return type back to void — adding bool while ignoring the return value in all call sites was pointless. The NULL guard and SCLogError are kept; examples are unchanged.

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)

}

int DetectEngineThreadCtxGetJsonContext(DetectEngineThreadCtx *det_ctx)
Expand Down
2 changes: 1 addition & 1 deletion src/detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ typedef struct DetectEngineCtx_ {
* This callback is added to the current detection engine and will be
* copied to all future detection engines over rule reloads.
*/
void SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc cb, void *arg);
bool SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc cb, void *arg);

/* Engine groups profiles (low, medium, high, custom) */
enum {
Expand Down