*/
SigMatch *DetectByteExtractRetrieveSMVar(const char *arg, const Signature *s)
{
- DetectByteExtractData *bed = NULL;
- int list;
- const int nlists = DetectBufferTypeMaxId();
-
- for (list = 0; list < nlists; list++) {
+ const int nlists = s->init_data->smlists_array_size;
+ for (int list = 0; list < nlists; list++) {
SigMatch *sm = s->init_data->smlists[list];
while (sm != NULL) {
if (sm->type == DETECT_BYTE_EXTRACT) {
- bed = (DetectByteExtractData *)sm->ctx;
+ const DetectByteExtractData *bed = (const DetectByteExtractData *)sm->ctx;
if (strcmp(bed->name, arg) == 0) {
return sm;
}
{
BUG_ON(s == NULL || s->init_data == NULL);
- int nlists = DetectBufferTypeMaxId();
- int list = 0;
- for (list = 0; list < nlists; list++) {
+ uint32_t list = 0;
+ for (list = 0; list < s->init_data->smlists_array_size; list++) {
uint16_t offset = 0;
uint16_t offset_plus_pat = 0;
uint16_t depth = 0;
uint32_t warn_no_direction = 0;
uint32_t warn_both_direction = 0;
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = de_ctx->buffer_type_id;
const int filedata_id = DetectBufferTypeGetByName("file_data");
const int httpmethod_id = DetectBufferTypeGetByName("http_method");
const int httpuri_id = DetectBufferTypeGetByName("http_uri");
return 0;
/* for now assume that all registered buffer types are incompatible */
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = s->init_data->smlists_array_size;
for (int i = 0; i < nlists; i++) {
if (s->init_data->smlists[i] == NULL)
continue;
return 0;
/* for now assume that all registered buffer types are incompatible */
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = s->init_data->smlists_array_size;
for (int i = 0; i < nlists; i++) {
if (s->init_data->smlists[i] == NULL)
continue;
}
/* for now assume that all registered buffer types are incompatible */
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = s->init_data->smlists_array_size;
for (int i = 0; i < nlists; i++) {
if (s->init_data->smlists[i] == NULL)
continue;
uint32_t cnt_payload = 0;
uint32_t cnt_applayer = 0;
uint32_t cnt_deonly = 0;
- const int nlists = DetectBufferTypeMaxId();
if (!(de_ctx->flags & DE_QUIET)) {
SCLogDebug("building signature grouping structure, stage 1: "
int prefilter_list = DETECT_TBLSIZE;
/* get the keyword supporting prefilter with the lowest type */
- for (i = 0; i < nlists; i++) {
+ for (i = 0; i < (int)tmp_s->init_data->smlists_array_size; i++) {
SigMatch *sm = tmp_s->init_data->smlists[i];
while (sm != NULL) {
if (sigmatch_table[sm->type].SupportsPrefilter != NULL) {
/* apply that keyword as prefilter */
if (prefilter_list != DETECT_TBLSIZE) {
- for (i = 0; i < nlists; i++) {
+ for (i = 0; i < (int)tmp_s->init_data->smlists_array_size; i++) {
SigMatch *sm = tmp_s->init_data->smlists[i];
while (sm != NULL) {
if (sm->type == prefilter_list) {
/* run buffer type callbacks if any */
int x;
- for (x = 0; x < nlists; x++) {
+ for (x = 0; x < (int)tmp_s->init_data->smlists_array_size; x++) {
if (tmp_s->init_data->smlists[x])
DetectBufferRunSetupCallback(de_ctx, x, tmp_s);
}
{
SCEnter();
- const int nlists = DetectBufferTypeMaxId();
Signature *s = de_ctx->sig_list;
for (; s != NULL; s = s->next) {
/* set up inspect engines */
}
/* free lists. Ctx' are xferred to sm_arrays so won't get freed */
- int i;
- for (i = 0; i < nlists; i++) {
+ uint32_t i;
+ for (i = 0; i < s->init_data->smlists_array_size; i++) {
SigMatch *sm = s->init_data->smlists[i];
while (sm != NULL) {
SigMatch *nsm = sm->next;
if (s->init_data->mpm_sm != NULL)
return;
- const int nlists = DetectBufferTypeMaxId();
-
SigMatch *mpm_sm = NULL, *sm = NULL;
+ const int nlists = s->init_data->smlists_array_size;
int nn_sm_list[nlists];
int n_sm_list[nlists];
memset(nn_sm_list, 0, nlists * sizeof(int));
int max_len = 0;
int i;
for (i = 0; i < count_final_sm_list; i++) {
+ if (final_sm_list[i] >= (int)s->init_data->smlists_array_size)
+ continue;
+
for (sm = s->init_data->smlists[final_sm_list[i]]; sm != NULL; sm = sm->next) {
if (sm->type != DETECT_CONTENT)
continue;
}
for (i = 0; i < count_final_sm_list; i++) {
+ if (final_sm_list[i] >= (int)s->init_data->smlists_array_size)
+ continue;
+
for (sm = s->init_data->smlists[final_sm_list[i]]; sm != NULL; sm = sm->next) {
if (sm->type != DETECT_CONTENT)
continue;
*/
int DetectEngineAppInspectionEngine2Signature(DetectEngineCtx *de_ctx, Signature *s)
{
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = s->init_data->smlists_array_size;
SigMatchData *ptrs[nlists];
memset(&ptrs, 0, (nlists * sizeof(SigMatchData *)));
while (t != NULL) {
bool prepend = false;
+ if (t->sm_list >= nlists)
+ goto next;
+
if (ptrs[t->sm_list] == NULL)
goto next;
*/
void DetectEngineAppInspectionEngineSignatureFree(Signature *s)
{
- const int nlists = DetectBufferTypeMaxId();
+ int nlists = 0;
+
+ DetectEngineAppInspectionEngine *ie = s->app_inspect;
+ while (ie) {
+ nlists = MAX(ie->sm_list, nlists);
+ ie = ie->next;
+ }
+ if (nlists == 0)
+ return;
+ nlists++;
+
SigMatchData *ptrs[nlists];
memset(&ptrs, 0, (nlists * sizeof(SigMatchData *)));
/* free engines and put smd in the array */
- DetectEngineAppInspectionEngine *ie = s->app_inspect;
+ ie = s->app_inspect;
while (ie) {
DetectEngineAppInspectionEngine *next = ie->next;
BUG_ON(ptrs[ie->sm_list] != NULL && ptrs[ie->sm_list] != ie->smd);
map->description, map->SetupCallback, map->ValidateCallback);
b = HashListTableGetListNext(b);
}
+
+ de_ctx->buffer_type_hash = HashListTableInit(256,
+ DetectBufferTypeHashFunc,
+ DetectBufferTypeCompareFunc,
+ DetectBufferTypeFreeFunc);
+ if (de_ctx->buffer_type_hash == NULL) {
+ BUG_ON(1);
+ }
+ de_ctx->buffer_type_id = g_buffer_type_id;
}
+
static void DetectBufferTypeFreeDetectEngine(DetectEngineCtx *de_ctx)
{
- if (de_ctx && de_ctx->buffer_type_map)
- SCFree(de_ctx->buffer_type_map);
+ if (de_ctx) {
+ if (de_ctx->buffer_type_map)
+ SCFree(de_ctx->buffer_type_map);
+ if (de_ctx->buffer_type_hash)
+ HashListTableFree(de_ctx->buffer_type_hash);
+ }
}
void DetectBufferTypeCloseRegistration(void)
t.cnt = transform_cnt;
DetectBufferType lookup_map = { (char *)base_map->string, NULL, 0, 0, 0, 0, false, NULL, NULL, t };
- DetectBufferType *res = HashListTableLookup(g_buffer_type_hash, &lookup_map, 0);
+ DetectBufferType *res = HashListTableLookup(de_ctx->buffer_type_hash, &lookup_map, 0);
SCLogDebug("res %p", res);
if (res != NULL) {
return -1;
map->string = base_map->string;
- map->id = g_buffer_type_id++;
+ map->id = de_ctx->buffer_type_id++;
map->parent_id = base_map->id;
map->transforms = t;
map->mpm = base_map->mpm;
map->ValidateCallback = base_map->ValidateCallback;
DetectAppLayerMpmRegisterByParentId(map->id, map->parent_id, &map->transforms);
- BUG_ON(HashListTableAdd(g_buffer_type_hash, (void *)map, 0) != 0);
+ BUG_ON(HashListTableAdd(de_ctx->buffer_type_hash, (void *)map, 0) != 0);
SCLogDebug("buffer %s registered with id %d, parent %d", map->string, map->id, map->parent_id);
if (map->id >= 0 && (uint32_t)map->id >= de_ctx->buffer_type_map_elements) {
det_ctx->base64_decoded_len = 0;
}
- det_ctx->inspect_buffers_size = (uint32_t)DetectBufferTypeMaxId();
+ det_ctx->inspect_buffers_size = de_ctx->buffer_type_id;
det_ctx->inspect_buffers = SCCalloc(det_ctx->inspect_buffers_size, sizeof(InspectionBuffer));
if (det_ctx->inspect_buffers == NULL) {
return TM_ECODE_FAILED;
}
- det_ctx->multi_inspect_buffers_size = (uint32_t)DetectBufferTypeMaxId();
+ det_ctx->multi_inspect_buffers_size = de_ctx->buffer_type_id;
det_ctx->multi_inspect_buffers = SCCalloc(det_ctx->multi_inspect_buffers_size, sizeof(InspectionBufferMultipleForList));
if (det_ctx->multi_inspect_buffers == NULL) {
return TM_ECODE_FAILED;
int ov[MAX_SUBSTRINGS];
char arg_substr[128] = "";
DetectContentData *cd = NULL;
- const int nlists = DetectBufferTypeMaxId();
SigMatch *pm1 = DetectGetLastSMFromMpmLists(de_ctx, s);
SigMatch *pm2 = DetectGetLastSMFromLists(s, DETECT_CONTENT, -1);
goto error;
}
else { /*allow only one content to have fast_pattern modifier*/
- int list_id = 0;
- for (list_id = 0; list_id < nlists; list_id++) {
+ uint32_t list_id = 0;
+ for (list_id = 0; list_id < s->init_data->smlists_array_size; list_id++) {
SigMatch *sm = NULL;
for (sm = s->init_data->smlists[list_id]; sm != NULL; sm = sm->next) {
if (sm->type == DETECT_CONTENT) {
void DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx)
{
- const int nlists = DetectBufferTypeMaxId();
-
const uint32_t max_fb_id = de_ctx->max_fb_id;
if (max_fb_id == 0)
return;
bool has_state = false;
/* see if the signature uses stateful matching */
- for (int x = DETECT_SM_LIST_DYNAMIC_START; x < nlists; x++) {
+ for (uint32_t x = DETECT_SM_LIST_DYNAMIC_START; x < s->init_data->smlists_array_size; x++) {
if (s->init_data->smlists[x] == NULL)
continue;
has_state = true;
{
SigMatch *sm_last = NULL;
SigMatch *sm_new;
- int sm_type;
+ uint32_t sm_type;
/* if we have a sticky buffer, use that */
if (s->init_data->list != DETECT_SM_LIST_NOTSET) {
}
/* otherwise brute force it */
- const int nlists = DetectBufferTypeMaxId();
- for (sm_type = 0; sm_type < nlists; sm_type++) {
+ for (sm_type = 0; sm_type < s->init_data->smlists_array_size; sm_type++) {
if (!DetectBufferTypeSupportsMpmGetById(de_ctx, sm_type))
continue;
SigMatch *sm_list = s->init_data->smlists_tail[sm_type];
SigMatch *sm_new;
/* otherwise brute force it */
- const int nlists = DetectBufferTypeMaxId();
- for (int buf_type = 0; buf_type < nlists; buf_type++) {
+ for (int buf_type = 0; buf_type < (int)s->init_data->smlists_array_size; buf_type++) {
if (s->init_data->smlists[buf_type] == NULL)
continue;
if (s->init_data->list != DETECT_SM_LIST_NOTSET &&
*/
SigMatch *DetectGetLastSM(const Signature *s)
{
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = s->init_data->smlists_array_size;
SigMatch *sm_last = NULL;
SigMatch *sm_new;
int i;
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
{
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = s->init_data->smlists_array_size;
int list = 0;
for (list = 0; list < nlists; list++) {
void SigFree(Signature *s)
{
- const int nlists = DetectBufferTypeMaxId();
-
if (s == NULL)
return;
int i;
if (s->init_data) {
+ const int nlists = s->init_data->smlists_array_size;
for (i = 0; i < nlists; i++) {
SigMatch *sm = s->init_data->smlists[i];
while (sm != NULL) {
{
uint32_t sig_flags = 0;
SigMatch *sm, *pm;
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = s->init_data->smlists_array_size;
SCEnter();
SigBuildAddressMatchArray(sig);
/* run buffer type callbacks if any */
- const int nlists = DetectBufferTypeMaxId();
- int x;
- for (x = 0; x < nlists; x++) {
+ for (uint32_t x = 0; x < sig->init_data->smlists_array_size; x++) {
if (sig->init_data->smlists[x])
DetectBufferRunSetupCallback(de_ctx, x, sig);
}
if (pflow != NULL) {
// TODO clean this up
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = det_ctx->de_ctx->buffer_type_id;
for (int i = 0; i < nlists; i++) {
InspectionBuffer *buffer = &det_ctx->inspect_buffers[i];
buffer->inspect = NULL;
DetectBufferType **buffer_type_map;
uint32_t buffer_type_map_elements;
+ /* hash table with rule-time buffer registration. Start time registration
+ * is in detect-engine.c::g_buffer_type_hash */
+ HashListTable *buffer_type_hash;
+ int buffer_type_id;
+
/** table with mpms and their registration function
* \todo we only need this at init, so perhaps this
* can move to a DetectEngineCtx 'init' struct */
if (profiling_keyword_enabled == 0)
return;
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = de_ctx->buffer_type_id;
gettimeofday(&tval, NULL);
tms = SCLocalTime(tval.tv_sec, &local_tm);
DetroyCtx(de_ctx->profile_keyword_ctx);
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = de_ctx->buffer_type_id;
int i;
for (i = 0; i < nlists; i++) {
DetroyCtx(de_ctx->profile_keyword_ctx_per_list[i]);
det_ctx->keyword_perf_data = a;
}
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = det_ctx->de_ctx->buffer_type_id;
det_ctx->keyword_perf_data_per_list = SCCalloc(nlists, sizeof(SCProfileKeywordData *));
BUG_ON(det_ctx->keyword_perf_data_per_list == NULL);
de_ctx->profile_keyword_ctx->data[i].max = det_ctx->keyword_perf_data[i].max;
}
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = det_ctx->de_ctx->buffer_type_id;
int j;
for (j = 0; j < nlists; j++) {
for (i = 0; i < DETECT_TBLSIZE; i++) {
SCFree(det_ctx->keyword_perf_data);
det_ctx->keyword_perf_data = NULL;
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = det_ctx->de_ctx->buffer_type_id;
int i;
for (i = 0; i < nlists; i++) {
SCFree(det_ctx->keyword_perf_data_per_list[i]);
if (profiling_keyword_enabled == 0)
return;
- const int nlists = DetectBufferTypeMaxId();
+ const int nlists = de_ctx->buffer_type_id;
de_ctx->profile_keyword_ctx = SCProfilingKeywordInitCtx();
BUG_ON(de_ctx->profile_keyword_ctx == NULL);