From 4e0683c3f520ff73cef7d33779f269b54aaa8e0f Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 20 Feb 2015 09:33:53 +0100 Subject: [PATCH] multi-detect: cleanup, reuse tenant loading code Reuse tenant loading from YAML code for Unix Socket. --- src/detect-engine.h | 2 ++ src/runmode-unix-socket.c | 38 +++++--------------------------------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/src/detect-engine.h b/src/detect-engine.h index b263e83bb3..ee2d89de0a 100644 --- a/src/detect-engine.h +++ b/src/detect-engine.h @@ -86,6 +86,8 @@ int DetectEngineReloadIsStart(void); void DetectEngineReloadSetDone(void); int DetectEngineReloadIsDone(void); +int DetectEngineMultiTenantLoadTenant(uint32_t tenant_id, const char *filename); + int DetectEngineTentantRegisterVlanId(uint32_t tenant_id, uint16_t vlan_id); int DetectEngineTentantUnregisterVlanId(uint32_t tenant_id, uint16_t vlan_id); int DetectEngineTentantRegisterPcapFile(uint32_t tenant_id); diff --git a/src/runmode-unix-socket.c b/src/runmode-unix-socket.c index 6b4490d784..a08a335c29 100644 --- a/src/runmode-unix-socket.c +++ b/src/runmode-unix-socket.c @@ -638,48 +638,20 @@ TmEcode UnixSocketRegisterTenant(json_t *cmd, json_t* answer, void *data) SCLogDebug("add-tenant: %d %s", tenant_id, filename); - /* 3 register it in the system */ - - /* 3A yaml parsing */ - char prefix[64]; - snprintf(prefix, sizeof(prefix), "multi-detect.%d", tenant_id); - - if (ConfYamlLoadFileWithPrefix(filename, prefix) != 0) { - json_object_set_new(answer, "message", json_string("YAML loading failed, ConfYamlLoadFileWithPrefix failed")); - return TM_ECODE_FAILED; - } - - ConfNode *node = ConfGetNode(prefix); - if (node == NULL) { - json_object_set_new(answer, "message", json_string("YAML loading failed, node == NULL")); - return TM_ECODE_FAILED; - } -#if 0 - ConfDump(); -#endif - - /* 3B setup the de_ctx */ - DetectEngineCtx *de_ctx = DetectEngineCtxInitWithPrefix(prefix); - if (de_ctx == NULL) { - json_object_set_new(answer, "message", json_string("detect engine failed to load")); + /* 3 load into the system */ + if (DetectEngineMultiTenantLoadTenant(tenant_id, filename) != 0) { + json_object_set_new(answer, "message", json_string("adding tenant failed")); return TM_ECODE_FAILED; } - SCLogDebug("de_ctx %p with prefix %s", de_ctx, de_ctx->config_prefix); - de_ctx->tenant_id = tenant_id; - - SigLoadSignatures(de_ctx, NULL, 0); - - DetectEngineAddToMaster(de_ctx); - - /* 3C for each thread, replace det_ctx */ + /* 4 apply to the running system */ if (DetectEngineMTApply() < 0) { json_object_set_new(answer, "message", json_string("couldn't apply settings")); // TODO cleanup return TM_ECODE_FAILED; } - json_object_set_new(answer, "message", json_string("work in progress")); + json_object_set_new(answer, "message", json_string("adding tenant succeeded")); return TM_ECODE_OK; }