]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
multi-detect: allow start up with 0 tenants
authorVictor Julien <victor@inliniac.net>
Thu, 12 Feb 2015 10:04:35 +0000 (11:04 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 23 Jul 2015 17:36:15 +0000 (19:36 +0200)
src/detect-engine.c

index 1eaa3465c3ce32711e79ea7522cdfa15d327050f..4ed25c094aeef256d271e711e1fcaa4d30e51d40 100644 (file)
@@ -1996,6 +1996,7 @@ static DetectEngineThreadCtx *DetectEngineThreadCtxInitForMT(ThreadVars *tv)
     uint32_t map_cnt = 0;
     int max_tenant_id = 0;
     DetectEngineCtx *list = master->list;
+    DetectEngineThreadCtx **tenant_det_ctxs = NULL;
 
     while (list) {
         if (list->tenant_id > max_tenant_id)
@@ -2005,49 +2006,48 @@ static DetectEngineThreadCtx *DetectEngineThreadCtxInitForMT(ThreadVars *tv)
     }
 
     if (max_tenant_id == 0) {
-        SCLogInfo("no tenants left");
-        return NULL;
-    }
-
-    max_tenant_id++;
-
-    DetectEngineTenantMapping *map = master->tenant_mapping_list;
-    while (map) {
-        map_cnt++;
-        map = map->next;
-    }
-
-    if (map_cnt > 0) {
-        map_array_size = map_cnt + 1;
-
-        map_array = SCCalloc(map_array_size, sizeof(*map_array));
-        if (map_array == NULL)
-            goto error;
+        SCLogInfo("no tenants left, or none registered yet");
+    } else {
+        max_tenant_id++;
 
-        /* fill the array */
-        map_cnt = 0;
-        map = master->tenant_mapping_list;
+        DetectEngineTenantMapping *map = master->tenant_mapping_list;
         while (map) {
-            BUG_ON(map_cnt > map_array_size);
-            map_array[map_cnt].traffic_id = map->traffic_id;
-            map_array[map_cnt].tenant_id = map->tenant_id;
             map_cnt++;
             map = map->next;
         }
 
-    }
-
-    DetectEngineThreadCtx **tenant_det_ctxs = SCCalloc(max_tenant_id, sizeof(DetectEngineThreadCtx *));
-    BUG_ON(tenant_det_ctxs == NULL);
+        if (map_cnt > 0) {
+            map_array_size = map_cnt + 1;
 
-    list = master->list;
-    while (list) {
-        if (list->tenant_id != 0) {
-            tenant_det_ctxs[list->tenant_id] = DetectEngineThreadCtxInitForReload(tv, list);
-            if (tenant_det_ctxs[list->tenant_id] == NULL)
+            map_array = SCCalloc(map_array_size, sizeof(*map_array));
+            if (map_array == NULL)
                 goto error;
+
+            /* fill the array */
+            map_cnt = 0;
+            map = master->tenant_mapping_list;
+            while (map) {
+                BUG_ON(map_cnt > map_array_size);
+                map_array[map_cnt].traffic_id = map->traffic_id;
+                map_array[map_cnt].tenant_id = map->tenant_id;
+                map_cnt++;
+                map = map->next;
+            }
+
+        }
+
+        tenant_det_ctxs = SCCalloc(max_tenant_id, sizeof(DetectEngineThreadCtx *));
+        BUG_ON(tenant_det_ctxs == NULL);
+
+        list = master->list;
+        while (list) {
+            if (list->tenant_id != 0) {
+                tenant_det_ctxs[list->tenant_id] = DetectEngineThreadCtxInitForReload(tv, list);
+                if (tenant_det_ctxs[list->tenant_id] == NULL)
+                    goto error;
+            }
+            list = list->next;
         }
-        list = list->next;
     }
 
     DetectEngineThreadCtx *det_ctx = SCCalloc(1, sizeof(DetectEngineThreadCtx));