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.

(cherry picked from commit 9fd77c7)
  • Loading branch information
jlucovsky committed Jul 18, 2023
1 parent c231d90 commit c1ae5c1
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 @@ -2591,7 +2591,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 @@ -3923,7 +3923,7 @@ static uint32_t DetectEngineTentantGetIdFromPcap(const void *ctx, const Packet *
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 @@ -92,7 +92,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 @@ -759,7 +759,7 @@ typedef struct DetectEngineCtx_ {
uint8_t flags;
int failure_fatal;

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 @@ -56,7 +56,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 @@ -246,16 +246,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 @@ -308,7 +300,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 @@ -769,7 +761,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 @@ -850,7 +842,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 @@ -935,7 +927,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 @@ -1011,7 +1003,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 @@ -1081,7 +1073,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 c1ae5c1

Please sign in to comment.