Skip to content

Commit

Permalink
detect/threshold: make hash size and memcap configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
victorjulien committed Jun 28, 2024
1 parent 10eaf55 commit 7d4fcc3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/detect-engine-threshold.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "detect-engine-address.h"
#include "detect-engine-address-ipv6.h"

#include "util-misc.h"
#include "util-time.h"
#include "util-error.h"
#include "util-debug.h"
Expand Down Expand Up @@ -183,14 +184,38 @@ static bool ThresholdEntryExpire(void *data, const SCTime_t ts)

static int ThresholdsInit(struct Thresholds *t)
{
uint64_t memcap = 16 * 1024 * 1024;
uint32_t hashsize = 16384;
uint64_t memcap = 16 * 1024 * 1024;

const char *str;
if (ConfGet("detect.thresholds.memcap", &str) == 1) {
if (ParseSizeStringU64(str, &memcap) < 0) {
SCLogError("Error parsing detect.thresholds.memcap from conf file - %s", str);
return -1;
}
}

intmax_t value = 0;
if ((ConfGetInt("detect.thresholds.hash-size", &value)) == 1) {
if (value < 256 || value > INT_MAX) {
SCLogError("'detect.thresholds.hash-size' value %" PRIiMAX
" out of range. Valid range 256-2147483647.",
value);
return -1;
}
hashsize = (uint32_t)value;
}

t->thash = THashInit("thresholds", sizeof(ThresholdEntry), ThresholdEntrySet,
ThresholdEntryFree, ThresholdEntryHash, ThresholdEntryCompare, ThresholdEntryExpire, 0,
memcap, hashsize);
BUG_ON(t->thash == NULL);
if (t->thash == NULL) {
SCLogError("failed to initialize thresholds hash table");
return -1;
}
return 0;
}

static void ThresholdsDestroy(struct Thresholds *t)
{
if (t->thash) {
Expand Down
5 changes: 5 additions & 0 deletions suricata.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,11 @@ detect:
#tcp-whitelist: 53, 80, 139, 443, 445, 1433, 3306, 3389, 6666, 6667, 8080
#udp-whitelist: 53, 135, 5060

# Thresholding hash table settings.
thresholds:
hash-size: 16384
memcap: 16mb

profiling:
# Log the rules that made it past the prefilter stage, per packet
# default is off. The threshold setting determines how many rules
Expand Down

0 comments on commit 7d4fcc3

Please sign in to comment.