Skip to content

Commit

Permalink
detect/multi-tenant: Make tenant_id 32 bits everywhere
Browse files Browse the repository at this point in the history
Issue: 6047

This commit ensures that the tenant id is contained in a unsigned 32 bit
container.
  • Loading branch information
jlucovsky authored and victorjulien committed Jul 17, 2023
1 parent 3286c3b commit 9fd77c7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/detect-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/detect-engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
2 changes: 1 addition & 1 deletion src/detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 9 additions & 17 deletions src/runmode-unix-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 9fd77c7

Please sign in to comment.