From 9fd77c737f4f2d14f0e79df8958c21a3ccb3ed85 Mon Sep 17 00:00:00 2001 From: Jeff Lucovsky Date: Wed, 21 Jun 2023 09:09:45 -0400 Subject: [PATCH] detect/multi-tenant: Make tenant_id 32 bits everywhere Issue: 6047 This commit ensures that the tenant id is contained in a unsigned 32 bit container. --- src/detect-engine.c | 4 ++-- src/detect-engine.h | 2 +- src/detect.h | 2 +- src/runmode-unix-socket.c | 26 +++++++++----------------- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/detect-engine.c b/src/detect-engine.c index f4a0aa8c9dac..141b48a902eb 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -3084,7 +3084,7 @@ static TmEcode DetectEngineThreadCtxInitForMT(ThreadVars *tv, DetectEngineThread DetectEngineTenantMapping *map_array = NULL; uint32_t map_array_size = 0; uint32_t map_cnt = 0; - int max_tenant_id = 0; + uint32_t max_tenant_id = 0; DetectEngineCtx *list = master->list; HashTable *mt_det_ctxs_hash = NULL; @@ -4433,7 +4433,7 @@ static uint32_t DetectEngineTenantGetIdFromPcap(const void *ctx, const Packet *p return p->pcap_v.tenant_id; } -DetectEngineCtx *DetectEngineGetByTenantId(int tenant_id) +DetectEngineCtx *DetectEngineGetByTenantId(uint32_t tenant_id) { DetectEngineMasterCtx *master = &g_master_de_ctx; SCMutexLock(&master->lock); diff --git a/src/detect-engine.h b/src/detect-engine.h index 6fef8261738f..7617e66a466d 100644 --- a/src/detect-engine.h +++ b/src/detect-engine.h @@ -111,7 +111,7 @@ uint32_t DetectEngineGetVersion(void); void DetectEngineBumpVersion(void); int DetectEngineAddToMaster(DetectEngineCtx *de_ctx); DetectEngineCtx *DetectEngineGetCurrent(void); -DetectEngineCtx *DetectEngineGetByTenantId(int tenant_id); +DetectEngineCtx *DetectEngineGetByTenantId(uint32_t tenant_id); void DetectEnginePruneFreeList(void); int DetectEngineMoveToFreeList(DetectEngineCtx *de_ctx); DetectEngineCtx *DetectEngineReference(DetectEngineCtx *); diff --git a/src/detect.h b/src/detect.h index fe2bbfa6e27b..2760dda89464 100644 --- a/src/detect.h +++ b/src/detect.h @@ -829,7 +829,7 @@ typedef struct DetectEngineCtx_ { uint8_t mpm_matcher; /**< mpm matcher this ctx uses */ uint8_t spm_matcher; /**< spm matcher this ctx uses */ - int tenant_id; + uint32_t tenant_id; Signature *sig_list; uint32_t sig_cnt; diff --git a/src/runmode-unix-socket.c b/src/runmode-unix-socket.c index 5469d66e3335..98b508fe6fbc 100644 --- a/src/runmode-unix-socket.c +++ b/src/runmode-unix-socket.c @@ -59,7 +59,7 @@ int unix_socket_mode_is_running = 0; typedef struct PcapFiles_ { char *filename; char *output_dir; - int tenant_id; + uint32_t tenant_id; time_t delay; time_t poll_interval; bool continuous; @@ -265,16 +265,8 @@ static void PcapFilesFree(PcapFiles *cfile) * * \retval 0 in case of error, 1 in case of success */ -static TmEcode UnixListAddFile( - PcapCommand *this, - const char *filename, - const char *output_dir, - int tenant_id, - bool continuous, - bool should_delete, - time_t delay, - time_t poll_interval -) +static TmEcode UnixListAddFile(PcapCommand *this, const char *filename, const char *output_dir, + uint32_t tenant_id, bool continuous, bool should_delete, time_t delay, time_t poll_interval) { PcapFiles *cfile = NULL; if (filename == NULL || this == NULL) @@ -327,7 +319,7 @@ static TmEcode UnixSocketAddPcapFileImpl(json_t *cmd, json_t* answer, void *data PcapCommand *this = (PcapCommand *) data; const char *filename; const char *output_dir; - int tenant_id = 0; + uint32_t tenant_id = 0; bool should_delete = false; time_t delay = 30; time_t poll_interval = 5; @@ -876,7 +868,7 @@ TmEcode UnixSocketRegisterTenantHandler(json_t *cmd, json_t* answer, void *data) json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - int tenant_id = json_integer_value(jarg); + uint32_t tenant_id = json_integer_value(jarg); /* 2 get tenant handler type */ jarg = json_object_get(cmd, "htype"); @@ -957,7 +949,7 @@ TmEcode UnixSocketUnregisterTenantHandler(json_t *cmd, json_t* answer, void *dat json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - int tenant_id = json_integer_value(jarg); + uint32_t tenant_id = json_integer_value(jarg); /* 2 get tenant handler type */ jarg = json_object_get(cmd, "htype"); @@ -1042,7 +1034,7 @@ TmEcode UnixSocketRegisterTenant(json_t *cmd, json_t* answer, void *data) json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - int tenant_id = json_integer_value(jarg); + uint32_t tenant_id = json_integer_value(jarg); /* 2 get tenant yaml */ jarg = json_object_get(cmd, "filename"); @@ -1118,7 +1110,7 @@ TmEcode UnixSocketReloadTenant(json_t *cmd, json_t* answer, void *data) json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - int tenant_id = json_integer_value(jarg); + uint32_t tenant_id = json_integer_value(jarg); /* 2 get tenant yaml */ jarg = json_object_get(cmd, "filename"); @@ -1188,7 +1180,7 @@ TmEcode UnixSocketUnregisterTenant(json_t *cmd, json_t* answer, void *data) json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - int tenant_id = json_integer_value(jarg); + uint32_t tenant_id = json_integer_value(jarg); SCLogInfo("remove-tenant: removing tenant %d", tenant_id);