(void) THashDecrUsecnt(d);
THashDataUnlock(d);
}
+static bool DatasetIsStatic(const char *save, const char *load);
enum DatasetTypes DatasetGetTypeFromString(const char *s)
{
{
Dataset *set = sets;
while (set) {
- if (strcasecmp(name, set->name) == 0) {
+ if (strcasecmp(name, set->name) == 0 && set->hidden == false) {
return set;
}
set = set->next;
return NULL;
}
+static bool DatasetIsStatic(const char *save, const char *load)
+{
+ /* A set is static if it does not have any dynamic properties like
+ * save and/or state defined but has load defined.
+ * */
+ if ((load != NULL || strlen(load) > 0) &&
+ (save == NULL || strlen(save) == 0)) {
+ return true;
+ }
+ return false;
+}
+
+void DatasetReload(void)
+{
+ /* In order to reload the datasets, just mark the current sets as hidden
+ * and clean them up later.
+ * New datasets shall be created with the rule reload and do not require
+ * any intervention.
+ * */
+ SCMutexLock(&sets_lock);
+ Dataset *set = sets;
+ while (set) {
+ if (!DatasetIsStatic(set->save, set->load) || set->from_yaml == true) {
+ SCLogDebug("Not a static set, skipping %s", set->name);
+ set = set->next;
+ continue;
+ }
+ set->hidden = true;
+ SCLogDebug("Set %s at %p hidden successfully", set->name, set);
+ set = set->next;
+ }
+ SCMutexUnlock(&sets_lock);
+}
+
+void DatasetPostReloadCleanup(void)
+{
+ SCLogDebug("Post Reload Cleanup starting.. Hidden sets will be removed");
+ SCMutexLock(&sets_lock);
+ Dataset *cur = sets;
+ Dataset *prev = NULL;
+ while (cur) {
+ Dataset *next = cur->next;
+ if (cur->hidden == false) {
+ prev = cur;
+ cur = next;
+ continue;
+ }
+ // Delete the set in case it was hidden
+ if (prev != NULL) {
+ prev->next = next;
+ } else {
+ sets = next;
+ }
+ THashShutdown(cur->hash);
+ SCFree(cur);
+ cur = next;
+ }
+ SCMutexUnlock(&sets_lock);
+}
+
int DatasetsInit(void)
{
SCLogDebug("datasets start");
if (dset == NULL)
FatalError(SC_ERR_FATAL, "failed to setup dataset for %s", set_name);
SCLogDebug("dataset %s: id %d type %s", set_name, n, set_type->val);
+ dset->from_yaml = true;
n++;
} else if (strcmp(set_type->val, "sha256") == 0) {
if (dset == NULL)
FatalError(SC_ERR_FATAL, "failed to setup dataset for %s", set_name);
SCLogDebug("dataset %s: id %d type %s", set_name, n, set_type->val);
+ dset->from_yaml = true;
n++;
} else if (strcmp(set_type->val, "string") == 0) {
if (dset == NULL)
FatalError(SC_ERR_FATAL, "failed to setup dataset for %s", set_name);
SCLogDebug("dataset %s: id %d type %s", set_name, n, set_type->val);
+ dset->from_yaml = true;
n++;
}
#include "flow-worker.h"
#include "conf.h"
#include "conf-yaml-loader.h"
+#include "datasets.h"
#include "app-layer-parser.h"
#include "app-layer-htp.h"
if (old_de_ctx == NULL)
return -1;
SCLogDebug("get ref to old_de_ctx %p", old_de_ctx);
+ DatasetReload();
/* only reload a regular 'normal' and 'delayed detect stub' detect engines */
if (!(old_de_ctx->type == DETECT_ENGINE_TYPE_NORMAL ||
/* walk free list, freeing the old_de_ctx */
DetectEnginePruneFreeList();
+ DatasetPostReloadCleanup();
+
DetectEngineBumpVersion();
SCLogDebug("old_de_ctx should have been freed");