datasets: parse defaults section from yaml

Datasets can now have a global defaults setting in suricata.yaml. In
case the settings for memcap and hashsize are not find in the yaml or
rule, this shall be the fallback.

Example:

datasets:
  defaults:
    memcap: 100mb
    hashsize: 2048
  ua-seen:
    type: string
    load: datasets.csv
pull/5407/head
Shivani Bhardwaj 5 years ago committed by Victor Julien
parent 5ac94fc407
commit 1286b0a8f1

@ -49,6 +49,7 @@ static inline void DatasetUnlockData(THashData *d)
THashDataUnlock(d);
}
static bool DatasetIsStatic(const char *save, const char *load);
static void GetDefaultMemcap(uint64_t *memcap, uint32_t *hashsize);
enum DatasetTypes DatasetGetTypeFromString(const char *s)
{
@ -423,6 +424,8 @@ Dataset *DatasetFind(const char *name, enum DatasetTypes type)
Dataset *DatasetGet(const char *name, enum DatasetTypes type, const char *save, const char *load,
uint64_t memcap, uint32_t hashsize)
{
uint64_t default_memcap = 0;
uint32_t default_hashsize = 0;
if (strlen(name) > DATASET_NAME_MAX_LEN) {
return NULL;
}
@ -491,6 +494,7 @@ Dataset *DatasetGet(const char *name, enum DatasetTypes type, const char *save,
char cnf_name[128];
snprintf(cnf_name, sizeof(cnf_name), "datasets.%s.hash", name);
GetDefaultMemcap(&default_memcap, &default_hashsize);
switch (type) {
case DATASET_TYPE_MD5:
set->hash = THashInit(cnf_name, sizeof(Md5Type), Md5StrSet, Md5StrFree, Md5StrHash,
@ -597,11 +601,37 @@ void DatasetPostReloadCleanup(void)
SCMutexUnlock(&sets_lock);
}
static void GetDefaultMemcap(uint64_t *memcap, uint32_t *hashsize)
{
const char *str = NULL;
if (ConfGetValue("datasets.defaults.memcap", &str) == 1) {
if (ParseSizeStringU64(str, memcap) < 0) {
SCLogWarning(SC_ERR_INVALID_VALUE,
"memcap value cannot be deduced: %s,"
" resetting to default",
str);
*memcap = 0;
}
}
if (ConfGetValue("datasets.defaults.hashsize", &str) == 1) {
if (ParseSizeStringU32(str, hashsize) < 0) {
SCLogWarning(SC_ERR_INVALID_VALUE,
"hashsize value cannot be deduced: %s,"
" resetting to default",
str);
*hashsize = 0;
}
}
}
int DatasetsInit(void)
{
SCLogDebug("datasets start");
int n = 0;
ConfNode *datasets = ConfGetNode("datasets");
uint64_t default_memcap = 0;
uint32_t default_hashsize = 0;
GetDefaultMemcap(&default_memcap, &default_hashsize);
if (datasets != NULL) {
int list_pos = 0;
ConfNode *iter = NULL;

@ -969,6 +969,13 @@ app-layer:
# Limit for the maximum number of asn1 frames to decode (default 256)
asn1-max-frames: 256
# Datasets default settings
# datasets:
# # Default fallback memcap and hashsize values for datasets in case these
# # were not explicitly defined.
# defaults:
# memcap: 100mb
# hashsize: 2048
##############################################################################
##

Loading…
Cancel
Save