Go to the documentation of this file.
95 #define DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT 3000
97 #define DEFAULT_MAX_FLOWBITS_PER_SIGNATURE 8
104 static uint32_t TenantIdHash(
HashTable *h,
void *
data, uint16_t data_len);
105 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len);
106 static void TenantIdFree(
void *d);
107 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *
p);
108 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *
p);
109 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *
p);
111 static bool DetectEngineMultiTenantEnabledWithLock(
void);
143 return "packet_filter";
177 FatalError(
"failed to register inspect engine %s: %s",
name, strerror(errno));
179 new_engine->
sm_list = (uint16_t)sm_list;
184 if (g_pkt_inspect_engines == NULL) {
185 g_pkt_inspect_engines = new_engine;
188 while (t->
next != NULL) {
192 t->
next = new_engine;
199 static void AppLayerInspectEngineRegisterInternal(
const char *
name,
AppProto alproto, uint32_t dir,
220 (Callback == NULL)) {
224 SCLogError(
"Invalid arguments: must register "
225 "GetData with DetectEngineInspectBufferGeneric");
228 SCLogError(
"Invalid arguments: must register "
229 "GetData with DetectEngineInspectBufferGeneric");
232 SCLogError(
"Invalid arguments: must register "
233 "GetData with DetectEngineInspectMultiBufferGeneric");
249 new_engine->
dir = direction;
250 new_engine->
sm_list = (uint16_t)sm_list;
263 if (g_app_inspect_engines == NULL) {
264 g_app_inspect_engines = new_engine;
267 while (t->
next != NULL) {
271 t->
next = new_engine;
285 if (t->
sm_list == sm_list && t->
alproto == alproto && t_direction == dir &&
294 AppLayerInspectEngineRegisterInternal(
295 name, alproto, dir, 0, (uint8_t)progress, Callback, GetData, NULL, NULL);
309 if (t->
sm_list == sm_list && t->
alproto == alproto && t_direction == dir &&
318 AppLayerInspectEngineRegisterInternal(
319 name, alproto, dir, sub_state, progress, Callback, GetData, NULL, NULL);
331 if (t->
sm_list == sm_list && t->
alproto == alproto && t_direction == dir &&
340 AppLayerInspectEngineRegisterInternal(
341 name, alproto, dir, 0, (uint8_t)progress, Callback, NULL, GetData, NULL);
345 static void DetectAppLayerInspectEngineCopy(
347 int sm_list,
int new_list,
360 new_engine->
sm_list = (uint16_t)new_list;
365 new_engine->
v2 = t->
v2;
372 while (list->
next != NULL) {
376 list->
next = new_engine;
399 new_engine->
v2 = t->
v2;
404 list->
next = new_engine;
413 static void DetectPktInspectEngineCopy(
415 int sm_list,
int new_list,
426 new_engine->
sm_list = (uint16_t)new_list;
429 new_engine->
v1 = t->
v1;
436 while (list->
next != NULL) {
440 list->
next = new_engine;
459 new_engine->
v1 = t->
v1;
465 while (list->
next != NULL) {
469 list->
next = new_engine;
501 FatalError(
"failed to register inspect engine %s: %s",
name, strerror(errno));
503 new_engine->
sm_list = (uint16_t)sm_list;
505 new_engine->
dir = direction;
514 while (list->
next != NULL) {
518 list->
next = new_engine;
537 new_engine->
sm_list = (uint16_t)new_list;
543 new_engine->
v1 = t->
v1;
548 while (list->
next != NULL) {
552 list->
next = new_engine;
574 new_engine->
v1 = t->
v1;
580 while (list->
next != NULL) {
584 list->
next = new_engine;
596 static void AppendStreamInspectEngine(
599 bool prepend =
false;
608 new_engine->
mpm =
true;
611 new_engine->
dir = direction;
612 new_engine->
stream =
true;
615 new_engine->
smd = stream;
623 }
else if (prepend) {
630 while (a->
next != NULL) {
634 a->
next = new_engine;
637 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
644 bool prepend =
false;
667 new_engine->
mpm =
true;
673 new_engine->
smd = smd;
674 new_engine->
v1 = u->
v1;
680 }
else if (prepend) {
685 while (a->
next != NULL) {
689 a->
next = new_engine;
697 bool prepend =
false;
707 new_engine->
mpm =
true;
712 new_engine->
smd = smd;
713 new_engine->
v1 = e->
v1;
719 }
else if (prepend) {
724 while (a->
next != NULL) {
728 a->
next = new_engine;
734 const int mpm_list,
const int files_id, uint8_t *last_id,
bool *head_is_mpm)
764 SCLogDebug(
"app engine: t %p t->id %u => alproto:%s files:%s", t, t->
id,
772 bool prepend =
false;
777 new_engine->
mpm =
true;
784 new_engine->
smd = smd;
788 new_engine->
v2 = t->
v2;
794 if (new_engine->
sm_list == files_id) {
796 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
799 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
807 if (new_engine->
sm_list == files_id) {
809 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
811 new_engine->
id = ++(*last_id);
812 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
818 while (a->
next != NULL) {
826 a->
next = new_engine;
827 if (new_engine->
sm_list == files_id) {
829 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
831 new_engine->
id = ++(*last_id);
832 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
837 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
846 const AppProto p,
const uint8_t sub_state,
const uint8_t state,
const uint8_t direction)
848 if (!((direction & (STREAM_TOSERVER | STREAM_TOCLIENT)) == STREAM_TOSERVER) &&
849 !((direction & (STREAM_TOSERVER | STREAM_TOCLIENT)) == STREAM_TOCLIENT))
852 if (sub_state == 0) {
854 p, state, direction);
857 if (direction == STREAM_TOSERVER) {
858 pname =
"request_started";
860 pname =
"response_started";
864 if (state == complete) {
865 if (direction == STREAM_TOSERVER) {
866 pname =
"request_complete";
868 pname =
"response_complete";
885 const AppProto p,
const uint8_t sub_state,
const uint8_t state,
const uint8_t direction)
888 if (app_proto == NULL) {
893 char generic_hook_name[256];
894 if (sub_state == 0) {
896 p, 0, state, direction & (STREAM_TOSERVER | STREAM_TOCLIENT));
901 snprintf(generic_hook_name,
sizeof(generic_hook_name),
"%s:%s:generic", app_proto,
name);
906 "no list registered as %s for %s hook %s", generic_hook_name, app_proto,
name);
921 snprintf(generic_hook_name,
sizeof(generic_hook_name),
"%s:%s:%s:generic", app_proto, sname,
926 SCLogError(
"no list registered as %s for %s sub_state %s hook %s", generic_hook_name,
927 app_proto, sname,
name);
942 bool head_is_mpm =
false;
950 uint8_t direction = 0;
955 direction = STREAM_TOSERVER;
958 direction = STREAM_TOCLIENT;
971 .sm_list = (uint16_t)sm_list,
972 .sm_list_base = (uint16_t)sm_list,
975 AppendAppInspectEngine(
de_ctx, &t, s, NULL, mpm_list, files_id, &last_id, &head_is_mpm);
976 SCLogDebug(
"sid %u: appended pass-tru engine at hook:%u sm_list:%d for "
977 "SIG_FLAG_INIT_HOOK_LTE",
978 s->
id, state, sm_list);
993 u != NULL; u = u->
next) {
995 AppendFrameInspectEngine(
de_ctx, u, s, smd, mpm_list);
1004 AppendPacketInspectEngine(
de_ctx, e, s, smd, mpm_list);
1022 AppendAppInspectEngine(
1023 de_ctx, t, s, smd, mpm_list, files_id, &last_id, &head_is_mpm);
1058 AppendAppInspectEngine(
de_ctx, &t, s, NULL, mpm_list, files_id, &last_id, &head_is_mpm);
1068 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
1070 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
1072 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
1073 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
1085 SCLogDebug(
"%u: engine %s id %u progress %d %s", s->
id,
1087 iter->
sm_list == mpm_list ?
"MPM" :
"");
1138 for (
int i = 0; i < arrays; i++) {
1139 if (bufs[i] == ie->
smd) {
1145 bufs[arrays++] = ie->
smd;
1155 for (
int i = 0; i < arrays; i++) {
1156 if (bufs[i] == e->
smd) {
1162 bufs[arrays++] = e->
smd;
1172 for (
int i = 0; i < arrays; i++) {
1173 if (bufs[i] == u->
smd) {
1179 bufs[arrays++] = u->
smd;
1185 for (
int i = 0; i < engines; i++) {
1186 if (bufs[i] == NULL)
1207 static int g_buffer_type_reg_closed = 0;
1211 return g_buffer_type_id;
1227 static uint32_t DetectBufferTypeHashNameFunc(
HashListTable *ht,
void *data, uint16_t datalen)
1251 static uint32_t DetectBufferTypeHashIdFunc(
HashListTable *ht,
void *data, uint16_t datalen)
1254 uint32_t hash = map->
id;
1259 static char DetectBufferTypeCompareNameFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
1264 char r = (strcmp(map1->
name, map2->
name) == 0);
1277 SCLogDebug(
"%s: transform ids match; checking specialized data", map1->
name);
1286 SCLogDebug(
"identity data: only one is null");
1311 static char DetectBufferTypeCompareIdFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
1315 return map1->
id == map2->
id;
1318 static void DetectBufferTypeFreeFunc(
void *data)
1332 SCLogError(
"%s allocates transform option memory but has no free routine",
1342 static int DetectBufferTypeInit(
void)
1344 BUG_ON(g_buffer_type_hash);
1346 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
1347 if (g_buffer_type_hash == NULL)
1353 static void DetectBufferTypeFree(
void)
1355 if (g_buffer_type_hash == NULL)
1359 g_buffer_type_hash = NULL;
1362 static int DetectBufferTypeAdd(
const char *
string)
1364 BUG_ON(
string == NULL || strlen(
string) >= 64);
1371 map->
id = g_buffer_type_id++;
1381 memset(&map, 0,
sizeof(map));
1390 BUG_ON(g_buffer_type_reg_closed);
1391 if (g_buffer_type_hash == NULL)
1392 DetectBufferTypeInit();
1396 return DetectBufferTypeAdd(
name);
1404 BUG_ON(g_buffer_type_reg_closed);
1409 SCLogDebug(
"%p %s -- %d supports multi instance", exists,
name, exists->
id);
1414 BUG_ON(g_buffer_type_reg_closed);
1418 exists->
frame =
true;
1419 SCLogDebug(
"%p %s -- %d supports frame inspection", exists,
name, exists->
id);
1424 BUG_ON(g_buffer_type_reg_closed);
1429 SCLogDebug(
"%p %s -- %d supports packet inspection", exists,
name, exists->
id);
1434 BUG_ON(g_buffer_type_reg_closed);
1444 BUG_ON(g_buffer_type_reg_closed);
1449 SCLogDebug(
"%p %s -- %d supports transformations", exists,
name, exists->
id);
1465 memset(&map, 0,
sizeof(map));
1475 memset(&lookup, 0,
sizeof(lookup));
1485 return res ? res->
name : NULL;
1490 BUG_ON(
string == NULL || strlen(
string) >= 32);
1506 const int direction,
const AppProto alproto,
const uint8_t frame_type)
1513 const int buffer_id = DetectEngineBufferTypeAdd(
de_ctx,
name);
1514 if (buffer_id < 0) {
1543 return DetectEngineBufferTypeAdd(
de_ctx,
name);
1551 BUG_ON(desc == NULL || strlen(desc) >= 128);
1593 exists->
frame =
true;
1594 SCLogDebug(
"%p %s -- %d supports frame inspection", exists,
name, exists->
id);
1602 SCLogDebug(
"%p %s -- %d supports packet inspection", exists,
name, exists->
id);
1618 SCLogDebug(
"%p %s -- %d supports transformations", exists,
name, exists->
id);
1660 BUG_ON(g_buffer_type_reg_closed);
1676 const char *
name,
bool (*ValidateCallback)(
const Signature *,
const char **sigerror,
1679 BUG_ON(g_buffer_type_reg_closed);
1726 const uint8_t *content, uint16_t content_len,
const char **namestr)
1752 const int size = g_buffer_type_id;
1756 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
1759 HashListTableInit(256, DetectBufferTypeHashIdFunc, DetectBufferTypeCompareIdFunc,
1771 memcpy(copy, map,
sizeof(*copy));
1777 SCLogDebug(
"name %s id %d mpm %s packet %s -- %s. "
1778 "Callbacks: Setup %p Validate %p",
1779 map->
name, map->
id, map->
mpm ?
"true" :
"false", map->
packet ?
"true" :
"false",
1786 DetectAppLayerInspectEngineCopyListToDetectCtx(
de_ctx);
1788 DetectFrameInspectEngineCopyListToDetectCtx(
de_ctx);
1790 DetectPktInspectEngineCopyListToDetectCtx(
de_ctx);
1832 while (framemlist) {
1843 BUG_ON(g_buffer_type_hash == NULL);
1845 g_buffer_type_reg_closed = 1;
1856 SCLogError(
"buffer '%s' does not support transformations", base_map->
name);
1863 memset(&t, 0,
sizeof(t));
1864 for (
int i = 0; i < transform_cnt; i++) {
1867 t.
cnt = transform_cnt;
1870 memset(&lookup_map, 0,
sizeof(lookup_map));
1876 DetectBufferAddTransformData(&lookup_map);
1893 map->
mpm = base_map->
mpm;
1900 }
else if (map->
packet) {
1910 SCLogDebug(
"buffer %s registered with id %d, parent %d", map->name, map->id, map->parent_id);
1913 DetectFrameInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1914 }
else if (map->packet) {
1915 DetectPktInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1917 DetectAppLayerInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1923 static int DetectEngineInspectRulePacketMatches(
1927 Packet *
p, uint8_t *_alert_flags)
1935 SCLogDebug(
"running match functions, sm %p", smd);
1953 static int DetectEngineInspectRulePayloadMatches(
1975 SCLogDebug(
"no match in stream, fall back to packet payload");
1983 SCLogDebug(
"SIG_FLAG_REQUIRE_STREAM_ONLY, so no match");
2001 uint8_t *alert_flags)
2007 SCLogDebug(
"sid %u: e %p Callback returned no match", s->
id, e);
2010 SCLogDebug(
"sid %u: e %p Callback returned true", s->
id, e);
2029 e->
sm_list = (uint16_t)list_id;
2038 while (a->
next != NULL) {
2050 if (DetectEnginePktInspectionAppend(
2053 SCLogDebug(
"sid %u: DetectEngineInspectRulePayloadMatches appended", s->
id);
2057 if (DetectEnginePktInspectionAppend(
2060 SCLogDebug(
"sid %u: DetectEngineInspectRulePacketMatches appended", s->
id);
2135 static bool DetectTxCompleted(
2149 if (progress < engine->progress) {
2157 uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
2160 SCLogDebug(
"running match functions, sm %p", smd);
2166 AppLayerTxMatch(det_ctx,
f,
flags, alstate, txv, s, smd->
ctx);
2176 return DetectTxCompleted(
f, txv,
flags, engine)
2209 void *alstate,
void *txv, uint64_t tx_id)
2211 const int list_id = engine->
sm_list;
2212 SCLogDebug(
"running inspect on %d", list_id);
2214 const bool eof = DetectTxCompleted(
f, txv,
flags, engine);
2235 const uint8_t *data = buffer->
inspect;
2240 ci_flags |= buffer->
flags;
2269 void *alstate,
void *txv, uint64_t tx_id)
2271 const int list_id = engine->
sm_list;
2272 SCLogDebug(
"running inspect on %d", list_id);
2274 const bool eof = DetectTxCompleted(
f, txv,
flags, engine);
2296 const uint8_t *data = buffer->
inspect;
2301 ci_flags |= buffer->
flags;
2321 AppLayerInspectEngineRegisterInternal(
name, alproto, dir, sub_state, progress,
2324 GetData, alproto, sub_state, progress);
2333 AppLayerInspectEngineRegisterInternal(
name, alproto, dir, 0, (uint8_t)progress,
2344 if (buffer->
inspect == NULL) {
2345 const uint8_t *b = NULL;
2348 if (!GetBuf(txv, flow_flags, &b, &b_len))
2361 if (buffer == NULL) {
2368 const uint8_t *data = NULL;
2369 uint32_t data_len = 0;
2371 if (!GetBuf(det_ctx, txv, flow_flags, index, &data, &data_len)) {
2384 uint32_t local_id = 0;
2394 if (buffer == NULL || buffer->
inspect == NULL)
2406 if (local_id == 0) {
2408 const bool eof = DetectTxCompleted(
f, txv,
flags, engine);
2432 const int list_id = engine->
sm_list;
2433 SCLogDebug(
"running inspect on %d", list_id);
2451 ci_flags |= buffer->
flags;
2470 static void InjectPackets(
2478 for (
int i = 0; i < no_of_detect_tvs; i++) {
2479 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) != 1) {
2480 if (detect_tvs[i]->inq != NULL) {
2499 char varname[128] =
"detect.flowbits.max-per-signature";
2501 snprintf(varname,
sizeof(varname),
"%s.detect.flowbits.max-per-signature",
2512 SCLogWarning(
"Invalid setting for flowbits.max-per-signature %d, resetting to the "
2518 "Invalid setting for flowbits.max-per-signature, resetting to the default");
2546 if (no_of_detect_tvs == 0) {
2556 memset(detect_tvs, 0x00, (no_of_detect_tvs *
sizeof(
ThreadVars *)));
2581 if (new_det_ctx[i] == NULL) {
2583 "failure in live rule swap. Let's get out of here");
2587 SCLogDebug(
"live rule swap created new det_ctx - %p and de_ctx "
2588 "- %p\n", new_det_ctx[i], new_de_ctx);
2593 BUG_ON(i != no_of_detect_tvs);
2606 SCLogDebug(
"swapping new det_ctx - %p with older one - %p",
2619 SCLogDebug(
"Live rule swap has swapped %d old det_ctx's with new ones, "
2620 "along with the new de_ctx", no_of_detect_tvs);
2622 InjectPackets(detect_tvs, new_det_ctx, no_of_detect_tvs);
2626 uint32_t threads_done = 0;
2628 for (i = 0; i < no_of_detect_tvs; i++) {
2630 threads_done = no_of_detect_tvs;
2634 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) == 1) {
2635 SCLogDebug(
"new_det_ctx - %p used by detect engine", new_det_ctx[i]);
2638 TmThreadsCaptureBreakLoop(detect_tvs[i]);
2641 if (threads_done < no_of_detect_tvs) {
2652 if (i != no_of_detect_tvs) {
2665 for (i = 0; i < no_of_detect_tvs; i++) {
2666 SCLogDebug(
"Freeing old_det_ctx - %p used by detect",
2676 for (i = 0; i < no_of_detect_tvs; i++) {
2677 if (new_det_ctx[i] != NULL)
2685 int sgh_mpm_caching = 0;
2686 if (
SCConfGetBool(
"detect.sgh-mpm-caching", &sgh_mpm_caching) != 1) {
2689 return (
bool)sgh_mpm_caching;
2698 char yamlpath[] =
"detect.sgh-mpm-caching-path";
2699 const char *strval = NULL;
2700 if (
SCConfGet(yamlpath, &strval) == 1 && strval != NULL) {
2704 static bool notified =
false;
2706 SCLogInfo(
"%s has no path specified, using %s", yamlpath, SGH_CACHE_DIR);
2709 return SGH_CACHE_DIR;
2797 if (prefix != NULL) {
2801 int failure_fatal = 0;
2802 if (
SCConfGetBool(
"engine.init-failure-fatal", (
int *)&failure_fatal) != 1) {
2803 SCLogDebug(
"ConfGetBool could not load the value.");
2811 SCLogDebug(
"Unable to alloc SpmGlobalThreadCtx.");
2823 if (DetectEngineCtxLoadConf(
de_ctx) == -1) {
2832 DetectBufferTypeSetupDetectEngine(
de_ctx);
2880 if (prefix == NULL || strlen(prefix) == 0)
2918 #ifdef PROFILE_RULES
2919 if (
de_ctx->profile_ctx != NULL) {
2920 SCProfilingRuleDestroyCtx(
de_ctx->profile_ctx);
2921 de_ctx->profile_ctx = NULL;
2964 DetectEngineCtxFreeThreadKeywordData(
de_ctx);
2966 DetectEngineCtxFreeFailedSigs(
de_ctx);
2986 DetectBufferTypeFreeDetectEngine(
de_ctx);
3025 const char *max_uniq_toclient_groups_str = NULL;
3026 const char *max_uniq_toserver_groups_str = NULL;
3027 const char *sgh_mpm_context = NULL;
3028 const char *de_ctx_profile = NULL;
3030 (void)
SCConfGet(
"detect.profile", &de_ctx_profile);
3031 (void)
SCConfGet(
"detect.sgh-mpm-context", &sgh_mpm_context);
3036 if (de_ctx_custom != NULL) {
3038 if (de_ctx_profile == NULL) {
3039 if (opt->
val && strcmp(opt->
val,
"profile") == 0) {
3040 de_ctx_profile = opt->head.tqh_first->
val;
3044 if (sgh_mpm_context == NULL) {
3045 if (opt->
val && strcmp(opt->
val,
"sgh-mpm-context") == 0) {
3046 sgh_mpm_context = opt->head.tqh_first->
val;
3052 if (de_ctx_profile != NULL) {
3053 if (strcmp(de_ctx_profile,
"low") == 0 ||
3054 strcmp(de_ctx_profile,
"lowest") == 0) {
3056 }
else if (strcmp(de_ctx_profile,
"medium") == 0) {
3058 }
else if (strcmp(de_ctx_profile,
"high") == 0 ||
3059 strcmp(de_ctx_profile,
"highest") == 0) {
3061 }
else if (strcmp(de_ctx_profile,
"custom") == 0) {
3064 SCLogError(
"invalid value for detect.profile: '%s'. "
3065 "Valid options: low, medium, high and custom.",
3070 SCLogDebug(
"Profile for detection engine groups is \"%s\"", de_ctx_profile);
3072 SCLogDebug(
"Profile for detection engine groups not provided "
3073 "at suricata.yaml. Using default (\"medium\").");
3077 if (sgh_mpm_context == NULL || strcmp(sgh_mpm_context,
"auto") == 0) {
3087 if (strcmp(sgh_mpm_context,
"single") == 0) {
3089 }
else if (strcmp(sgh_mpm_context,
"full") == 0) {
3093 "invalid conf value for detect-engine.sgh-mpm-context-"
3118 (void)
SCConfGet(
"detect.custom-values.toclient-groups", &max_uniq_toclient_groups_str);
3119 (void)
SCConfGet(
"detect.custom-values.toserver-groups", &max_uniq_toserver_groups_str);
3121 if (de_ctx_custom != NULL) {
3123 if (opt->
val && strcmp(opt->
val,
"custom-values") == 0) {
3124 if (max_uniq_toclient_groups_str == NULL) {
3126 opt->head.tqh_first,
"toclient-sp-groups");
3128 if (max_uniq_toclient_groups_str == NULL) {
3130 opt->head.tqh_first,
"toclient-groups");
3132 if (max_uniq_toserver_groups_str == NULL) {
3134 opt->head.tqh_first,
"toserver-dp-groups");
3136 if (max_uniq_toserver_groups_str == NULL) {
3138 opt->head.tqh_first,
"toserver-groups");
3143 if (max_uniq_toclient_groups_str != NULL) {
3145 (uint16_t)strlen(max_uniq_toclient_groups_str),
3146 (
const char *)max_uniq_toclient_groups_str) <= 0) {
3150 "toclient-groups failed, using %u",
3158 if (max_uniq_toserver_groups_str != NULL) {
3160 (uint16_t)strlen(max_uniq_toserver_groups_str),
3161 (
const char *)max_uniq_toserver_groups_str) <= 0) {
3165 "toserver-groups failed, using %u",
3185 if (
SCConfGetInt(
"detect.inspection-recursion-limit", &value) == 1) {
3186 if (value >= 0 && value <= INT_MAX) {
3192 SCConfNode *insp_recursion_limit_node = NULL;
3193 char *insp_recursion_limit = NULL;
3195 if (de_ctx_custom != NULL) {
3198 if (opt->
val && strcmp(opt->
val,
"inspection-recursion-limit") != 0)
3202 if (insp_recursion_limit_node == NULL) {
3204 "entry for detect-engine:inspection-recursion-limit");
3207 insp_recursion_limit = insp_recursion_limit_node->
val;
3208 SCLogDebug(
"Found detect-engine.inspection-recursion-limit - %s:%s",
3209 insp_recursion_limit_node->
name, insp_recursion_limit_node->
val);
3213 if (insp_recursion_limit != NULL) {
3215 0, (
const char *)insp_recursion_limit) < 0) {
3217 "detect-engine.inspection-recursion-limit: %s "
3230 SCLogDebug(
"de_ctx->inspection_recursion_limit: %d",
3235 if (
SCConfGetInt(
"detect.stream-tx-log-limit", &value) == 1) {
3236 if (value >= 0 && value <= UINT8_MAX) {
3239 SCLogWarning(
"Invalid value for detect-engine.stream-tx-log-limit: must be between 0 "
3240 "and 255, will default to 4");
3243 int guess_applayer = 0;
3244 if ((
SCConfGetBool(
"detect.guess-applayer-tx", &guess_applayer)) == 1) {
3245 if (guess_applayer == 1) {
3252 const char *ports = NULL;
3253 (void)
SCConfGet(
"detect.grouping.tcp-priority-ports", &ports);
3255 SCLogConfig(
"grouping: tcp-priority-ports %s", ports);
3257 (void)
SCConfGet(
"detect.grouping.tcp-whitelist", &ports);
3260 "grouping: tcp-priority-ports from legacy 'tcp-whitelist' setting: %s", ports);
3262 ports =
"53, 80, 139, 443, 445, 1433, 3306, 3389, 6666, 6667, 8080";
3263 SCLogConfig(
"grouping: tcp-priority-ports (default) %s", ports);
3268 "for detect.grouping.tcp-priority-ports",
3272 for ( ; x != NULL; x = x->
next) {
3275 "for detect.grouping.tcp-priority-ports: only single ports allowed",
3284 (void)
SCConfGet(
"detect.grouping.udp-priority-ports", &ports);
3286 SCLogConfig(
"grouping: udp-priority-ports %s", ports);
3288 (void)
SCConfGet(
"detect.grouping.udp-whitelist", &ports);
3291 "grouping: udp-priority-ports from legacy 'udp-whitelist' setting: %s", ports);
3293 ports =
"53, 135, 5060";
3294 SCLogConfig(
"grouping: udp-priority-ports (default) %s", ports);
3299 "for detect.grouping.udp-priority-ports",
3305 "for detect.grouping.udp-priority-ports: only single ports allowed",
3313 DetectEngineLoadFlowbitSettings(
de_ctx);
3316 const char *pf_setting = NULL;
3317 if (
SCConfGet(
"detect.prefilter.default", &pf_setting) == 1 && pf_setting) {
3318 if (strcasecmp(pf_setting,
"mpm") == 0) {
3320 }
else if (strcasecmp(pf_setting,
"auto") == 0) {
3329 SCLogConfig(
"prefilter engines: MPM and keywords");
3349 SCLogError(
"setting up thread local detect ctx");
3358 SCLogError(
"setting up thread local detect ctx "
3359 "for keyword \"%s\" failed",
3397 SCLogError(
"setting up thread local detect ctx");
3409 SCLogError(
"setting up thread local detect ctx "
3410 "for keyword \"%s\" failed",
3441 uint32_t map_array_size = 0;
3442 uint32_t map_cnt = 0;
3443 uint32_t max_tenant_id = 0;
3451 "set using multi-detect.selector");
3465 HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree);
3466 if (mt_det_ctxs_hash == NULL) {
3471 SCLogInfo(
"no tenants left, or none registered yet");
3482 map_array_size = map_cnt + 1;
3484 map_array =
SCCalloc(map_array_size,
sizeof(*map_array));
3485 if (map_array == NULL)
3492 if (map_cnt >= map_array_size) {
3504 list = master->
list;
3509 if (mt_det_ctx == NULL)
3511 if (
HashTableAdd(mt_det_ctxs_hash, mt_det_ctx, 0) != 0) {
3520 mt_det_ctxs_hash = NULL;
3532 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromVlanId;
3536 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromLivedev;
3540 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromPcap;
3547 if (map_array != NULL)
3549 if (mt_det_ctxs_hash != NULL)
3577 if (det_ctx->
replace == NULL) {
3627 DetectEngineThreadCtxInitGlobalKeywords(det_ctx);
3628 #ifdef PROFILE_RULES
3629 SCProfilingRuleThreadSetup(
de_ctx->profile_ctx, det_ctx);
3668 if (det_ctx->
de_ctx == NULL) {
3729 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3738 *data = (
void *)det_ctx;
3762 if (det_ctx->
de_ctx == NULL) {
3793 if (mt && DetectEngineMultiTenantEnabledWithLock()) {
3794 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3807 SCLogDebug(
"PACKET PKT_STREAM_ADD: %"PRIu64, det_ctx->pkt_stream_add_cnt);
3809 SCLogDebug(
"PAYLOAD MPM %"PRIu64
"/%"PRIu64, det_ctx->payload_mpm_cnt, det_ctx->payload_mpm_size);
3810 SCLogDebug(
"STREAM MPM %"PRIu64
"/%"PRIu64, det_ctx->stream_mpm_cnt, det_ctx->stream_mpm_size);
3812 SCLogDebug(
"PAYLOAD SIG %"PRIu64
"/%"PRIu64, det_ctx->payload_persig_cnt, det_ctx->payload_persig_size);
3813 SCLogDebug(
"STREAM SIG %"PRIu64
"/%"PRIu64, det_ctx->stream_persig_cnt, det_ctx->stream_persig_size);
3821 #ifdef PROFILE_RULES
3822 SCProfilingRuleThreadCleanup(det_ctx);
3831 if (det_ctx->
de_ctx != NULL) {
3872 for (uint32_t x = 0; x < fb->
size; x++) {
3883 DetectEngineThreadCtxDeinitGlobalKeywords(det_ctx);
3884 if (det_ctx->
de_ctx != NULL) {
3885 DetectEngineThreadCtxDeinitKeywords(det_ctx->
de_ctx, det_ctx);
3909 if (det_ctx == NULL) {
3918 DetectEngineThreadCtxFree(det_ctx);
3923 static uint32_t DetectKeywordCtxHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
3930 return (uint32_t)hash;
3933 static char DetectKeywordCtxCompareFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
3937 const char *name1 = ctx1->
name;
3938 const char *name2 = ctx2->
name;
3939 return (strcmp(name1, name2) == 0 && ctx1->
data == ctx2->
data);
3942 static void DetectKeywordCtxFreeFunc(
void *ptr)
3965 BUG_ON(
de_ctx == NULL || InitFunc == NULL || FreeFunc == NULL);
3969 DetectKeywordCtxHashFunc, DetectKeywordCtxCompareFunc, DetectKeywordCtxFreeFunc);
4054 const char *
name,
void *(*InitFunc)(
void *),
void *data,
void (*FreeFunc)(
void *))
4057 BUG_ON(InitFunc == NULL || FreeFunc == NULL);
4063 while (item != NULL) {
4064 if (strcmp(
name, item->
name) == 0) {
4114 if (master->
list == NULL) {
4173 static bool DetectEngineMultiTenantEnabledWithLock(
void)
4183 bool enabled = DetectEngineMultiTenantEnabledWithLock();
4198 static int DetectEngineMultiTenantLoadTenant(uint32_t tenant_id,
const char *filename,
int loader_id)
4203 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
4206 if (
SCStatFn(filename, &st) != 0) {
4207 SCLogError(
"failed to stat file %s", filename);
4213 SCLogError(
"tenant %u already registered", tenant_id);
4220 SCLogError(
"failed to properly setup yaml %s", filename);
4256 static int DetectEngineMultiTenantReloadTenant(uint32_t tenant_id,
const char *filename,
int reload_cnt)
4259 if (old_de_ctx == NULL) {
4260 SCLogError(
"tenant detect engine not found");
4264 if (filename == NULL)
4268 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u.reload.%d", tenant_id, reload_cnt);
4279 SCLogError(
"failed to properly setup yaml %s", filename);
4284 if (new_de_ctx == NULL) {
4297 goto new_de_ctx_error;
4302 goto new_de_ctx_error;
4327 static void DetectLoaderFreeTenant(
void *
ctx)
4330 if (t->
yaml != NULL) {
4336 static int DetectLoaderFuncLoadTenant(
void *vctx,
int loader_id)
4341 if (DetectEngineMultiTenantLoadTenant(
ctx->tenant_id,
ctx->yaml, loader_id) != 0) {
4347 static int DetectLoaderSetupLoadTenant(uint32_t tenant_id,
const char *yaml)
4355 if (t->
yaml == NULL) {
4363 static int DetectLoaderFuncReloadTenant(
void *vctx,
int loader_id)
4369 if (DetectEngineMultiTenantReloadTenant(
ctx->tenant_id,
ctx->yaml,
ctx->reload_cnt) != 0) {
4375 static int DetectLoaderSetupReloadTenants(
const int reload_cnt)
4394 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4408 static int DetectLoaderSetupReloadTenant(uint32_t tenant_id,
const char *yaml,
int reload_cnt)
4411 if (old_de_ctx == NULL)
4423 if (t->
yaml == NULL) {
4433 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4440 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml);
4454 int r = DetectLoaderSetupReloadTenant(tenant_id, yaml, reload_cnt);
4468 int r = DetectLoaderSetupReloadTenants(reload_cnt);
4478 static int DetectEngineMultiTenantSetupLoadLivedevMappings(
4479 const SCConfNode *mappings_root_node,
bool failure_fatal)
4483 int mapping_cnt = 0;
4484 if (mappings_root_node != NULL) {
4487 if (tenant_id_node == NULL)
4490 if (device_node == NULL)
4493 uint32_t tenant_id = 0;
4495 tenant_id_node->
val) < 0) {
4498 tenant_id_node->
val);
4502 const char *dev = device_node->
val;
4521 SCLogConfig(
"device %s connected to tenant-id %u", dev, tenant_id);
4530 SCLogConfig(
"%d device - tenant-id mappings defined", mapping_cnt);
4537 static int DetectEngineMultiTenantSetupLoadVlanMappings(
4538 const SCConfNode *mappings_root_node,
bool failure_fatal)
4542 int mapping_cnt = 0;
4543 if (mappings_root_node != NULL) {
4546 if (tenant_id_node == NULL)
4549 if (vlan_id_node == NULL)
4552 uint32_t tenant_id = 0;
4554 tenant_id_node->
val) < 0) {
4557 tenant_id_node->
val);
4561 uint16_t vlan_id = 0;
4563 &vlan_id, 10, (uint16_t)strlen(vlan_id_node->
val), vlan_id_node->
val) < 0) {
4569 if (vlan_id == 0 || vlan_id >= 4095) {
4571 "of %s is invalid. Valid range 1-4094.",
4579 SCLogConfig(
"vlan %u connected to tenant-id %u", vlan_id, tenant_id);
4605 int failure_fatal = 0;
4606 (void)
SCConfGetBool(
"engine.init-failure-fatal", &failure_fatal);
4619 const char *handler = NULL;
4621 SCLogConfig(
"multi-tenant selector type %s", handler);
4623 if (strcmp(handler,
"vlan") == 0) {
4627 if ((
SCConfGetBool(
"vlan.use-for-tracking", &vlanbool)) == 1 && vlanbool == 0) {
4629 "can't use multi-detect selector 'vlan'");
4634 }
else if (strcmp(handler,
"direct") == 0) {
4636 }
else if (strcmp(handler,
"device") == 0) {
4639 SCLogWarning(
"multi-tenant 'device' mode not supported for IPS");
4646 "multi-detect.selector",
4653 SCLogConfig(
"multi-detect is enabled (multi tenancy). Selector: %s", handler);
4659 int mapping_cnt = DetectEngineMultiTenantSetupLoadVlanMappings(mappings_root_node,
4661 if (mapping_cnt == 0) {
4667 SCLogNotice(
"no tenant traffic mappings defined, "
4668 "tenants won't be used until mappings are added");
4670 if (failure_fatal) {
4671 SCLogError(
"no multi-detect mappings defined");
4679 int mapping_cnt = DetectEngineMultiTenantSetupLoadLivedevMappings(mappings_root_node,
4681 if (mapping_cnt == 0) {
4682 if (failure_fatal) {
4683 SCLogError(
"no multi-detect mappings defined");
4695 if (tenants_root_node != NULL) {
4696 const char *path = NULL;
4699 path = path_node->
val;
4705 if (id_node == NULL) {
4709 if (yaml_node == NULL) {
4713 uint32_t tenant_id = 0;
4715 &tenant_id, 10, (uint16_t)strlen(id_node->
val), id_node->
val) < 0) {
4723 char yaml_path[PATH_MAX] =
"";
4725 if (
PathMerge(yaml_path, PATH_MAX, path, yaml_node->
val) < 0)
4728 size_t r =
strlcpy(yaml_path, yaml_node->
val,
sizeof(yaml_path));
4729 if (r >=
sizeof(yaml_path))
4737 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
4739 SCLogError(
"failed to load yaml %s", yaml_path);
4743 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml_path);
4764 SCLogDebug(
"multi-detect not enabled (multi tenancy)");
4771 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *
p)
4775 uint32_t vlan_id = 0;
4795 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *
p)
4800 if (ld == NULL || det_ctx == NULL)
4807 static int DetectEngineTenantRegisterSelector(
4814 SCLogInfo(
"conflicting selector already set");
4821 if (
m->traffic_id == traffic_id) {
4822 SCLogInfo(
"traffic id already registered");
4843 SCLogDebug(
"tenant handler %u %u %u registered", selector, tenant_id, traffic_id);
4848 static int DetectEngineTenantUnregisterSelector(
4872 SCLogInfo(
"tenant handler %u %u %u unregistered", selector, tenant_id, traffic_id);
4886 return DetectEngineTenantRegisterSelector(
4897 return DetectEngineTenantUnregisterSelector(
TENANT_SELECTOR_VLAN, tenant_id, (uint32_t)vlan_id);
4912 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *
p)
4922 if (master->
list == NULL) {
4946 (*de_ctx)->ref_cnt--;
4954 if (instance == NULL)
4957 if (master->
list == NULL) {
4958 master->
list = instance;
4961 master->
list = instance;
4978 r = DetectEngineAddToList(
de_ctx);
4986 if (instance == NULL) {
4991 if (instance ==
de_ctx) {
4995 instance = instance->
next;
5000 if (instance ==
de_ctx) {
5008 if (instance == NULL) {
5014 instance->
next = NULL;
5032 ret = DetectEngineMoveToFreeListNoLock(master,
de_ctx);
5056 SCLogDebug(
"freeing detect engine %p", instance);
5078 DetectEngineMoveToFreeListNoLock(master, instance);
5085 static int reloads = 0;
5100 memset(prefix, 0,
sizeof(prefix));
5105 snprintf(prefix,
sizeof(prefix),
"detect-engine-reloads.%d", reloads++);
5132 if (old_de_ctx == NULL)
5134 SCLogDebug(
"get ref to old_de_ctx %p", old_de_ctx);
5148 if (new_de_ctx == NULL) {
5161 SCLogDebug(
"set up new_de_ctx %p", new_de_ctx);
5174 SCLogDebug(
"going to reload the threads to use new_de_ctx %p", new_de_ctx);
5179 DetectEngineReloadThreads(new_de_ctx);
5182 SCLogDebug(
"threads now run new_de_ctx %p", new_de_ctx);
5191 SCLogDebug(
"old_de_ctx should have been freed");
5197 #ifdef HAVE_MALLOC_TRIM
5208 static uint32_t TenantIdHash(
HashTable *h,
void *data, uint16_t data_len)
5214 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len)
5221 static void TenantIdFree(
void *d)
5223 DetectEngineThreadCtxFree(d);
5239 for ( ; list != NULL; list = list->
next) {
5250 if (stub_de_ctx == NULL) {
5252 if (stub_de_ctx == NULL) {
5257 if (master->
list == NULL) {
5258 master->
list = stub_de_ctx;
5261 master->
list = stub_de_ctx;
5267 DetectEngineReloadThreads(stub_de_ctx);
5277 SCLogDebug(
"old_de_ctx should have been freed");
5281 static int g_parse_metadata = 0;
5285 g_parse_metadata = 1;
5290 g_parse_metadata = 0;
5295 return g_parse_metadata;
5304 return "packet/stream payload";
5310 return "base64_data";
5313 return "post-match";
5321 return "max (internal)";
5340 for (; sm != NULL; sm = sm->
next) {
5346 *sigerror =
"md5-like keyword should not be used together with "
5347 "nocase, since the rule is automatically "
5348 "lowercased anyway which makes nocase redundant.";
5353 *sigerror =
"Invalid length for md5-like keyword (should "
5354 "be 32 characters long). This rule will therefore "
5361 if (!isxdigit(cd->
content[i])) {
5363 "Invalid md5-like string (should be string of hexadecimal characters)."
5364 "This rule will therefore never match.";
5381 for (; sm != NULL; sm = sm->
next) {
5387 bool changed =
false;
5390 if (isupper(cd->
content[u])) {
5409 SCLogError(
"no detection engine available for rate filter callback registration");
5446 static int DetectEngineInitYamlConf(
const char *conf)
5453 static void DetectEngineDeInitYamlConf(
void)
5459 static int DetectEngineTest01(
void)
5465 " - profile: medium\n"
5466 " - custom-values:\n"
5467 " toclient_src_groups: 2\n"
5468 " toclient_dst_groups: 2\n"
5469 " toclient_sp_groups: 2\n"
5470 " toclient_dp_groups: 3\n"
5471 " toserver_src_groups: 2\n"
5472 " toserver_dst_groups: 4\n"
5473 " toserver_sp_groups: 2\n"
5474 " toserver_dp_groups: 25\n"
5475 " - inspection-recursion-limit: 0\n";
5477 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5486 DetectEngineDeInitYamlConf();
5491 static int DetectEngineTest02(
void)
5497 " - profile: medium\n"
5498 " - custom-values:\n"
5499 " toclient_src_groups: 2\n"
5500 " toclient_dst_groups: 2\n"
5501 " toclient_sp_groups: 2\n"
5502 " toclient_dp_groups: 3\n"
5503 " toserver_src_groups: 2\n"
5504 " toserver_dst_groups: 4\n"
5505 " toserver_sp_groups: 2\n"
5506 " toserver_dp_groups: 25\n"
5507 " - inspection-recursion-limit:\n";
5509 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5519 DetectEngineDeInitYamlConf();
5524 static int DetectEngineTest03(
void)
5530 " - profile: medium\n"
5531 " - custom-values:\n"
5532 " toclient_src_groups: 2\n"
5533 " toclient_dst_groups: 2\n"
5534 " toclient_sp_groups: 2\n"
5535 " toclient_dp_groups: 3\n"
5536 " toserver_src_groups: 2\n"
5537 " toserver_dst_groups: 4\n"
5538 " toserver_sp_groups: 2\n"
5539 " toserver_dp_groups: 25\n";
5541 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5551 DetectEngineDeInitYamlConf();
5556 static int DetectEngineTest04(
void)
5562 " - profile: medium\n"
5563 " - custom-values:\n"
5564 " toclient_src_groups: 2\n"
5565 " toclient_dst_groups: 2\n"
5566 " toclient_sp_groups: 2\n"
5567 " toclient_dp_groups: 3\n"
5568 " toserver_src_groups: 2\n"
5569 " toserver_dst_groups: 4\n"
5570 " toserver_sp_groups: 2\n"
5571 " toserver_dp_groups: 25\n"
5572 " - inspection-recursion-limit: 10\n";
5574 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5583 DetectEngineDeInitYamlConf();
5588 static int DetectEngineTest08(
void)
5594 " - profile: custom\n"
5595 " - custom-values:\n"
5596 " toclient-groups: 23\n"
5597 " toserver-groups: 27\n";
5599 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5609 DetectEngineDeInitYamlConf();
5615 static int DetectEngineTest09(
void)
5621 " - profile: custom\n"
5622 " - custom-values:\n"
5623 " toclient-groups: BA\n"
5624 " toserver-groups: BA\n"
5625 " - inspection-recursion-limit: 10\n";
5627 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5637 DetectEngineDeInitYamlConf();
5644 static void *DetectEngineFailingThreadKeywordInit(
void *data)
5650 static void DetectEngineNoopThreadKeywordFree(
void *
ctx)
5658 static int DetectEngineThreadCtxInitKeywordFailTest(
void)
5675 DetectEngineFailingThreadKeywordInit, NULL, DetectEngineNoopThreadKeywordFree, 0);
5692 static int DetectEngineStatefulFlagTest01(
void)
5708 UtRegisterTest(
"DetectEngineStatefulFlagTest01", DetectEngineStatefulFlagTest01);
5716 "DetectEngineThreadCtxInitKeywordFailTest", DetectEngineThreadCtxInitKeywordFailTest);
#define DETECT_CONTENT_NOCASE
#define HashListTableGetListData(hb)
#define DE_STATE_ID_FILE_INSPECT
void SCProfilingSghThreadCleanup(DetectEngineThreadCtx *det_ctx)
DetectEngineCtx * DetectEngineCtxInitWithPrefix(const char *prefix, uint32_t tenant_id)
#define DEFAULT_MAX_FLOWBITS_PER_SIGNATURE
int SCConfYamlLoadString(const char *string, size_t len)
Load configuration from a YAML string.
InspectionBuffer * DetectGetMultiData(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id, uint32_t index, InspectionMultiBufferGetDataPtr GetBuf)
struct DetectEngineThreadCtx_::@101 inspect
#define DETECT_ENGINE_MPM_CACHE_OP_PRUNE
struct DetectEngineAppInspectionEngine_::@82 v2
void DetectEngineResetMaxSigId(DetectEngineCtx *de_ctx)
int DetectEngineMTApply(void)
void SCProfilingKeywordDestroyCtx(DetectEngineCtx *de_ctx)
bool DetectEngineBufferTypeSupportsPacketGetById(const DetectEngineCtx *de_ctx, const int id)
DetectEngineThreadCtx * DetectEngineThreadCtxInitForReload(ThreadVars *tv, DetectEngineCtx *new_de_ctx, int mt)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void SCConfNodeRemove(SCConfNode *node)
Remove (and SCFree) the provided configuration node.
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
void SCProfilingKeywordThreadCleanup(DetectEngineThreadCtx *det_ctx)
int SCConfGetTime(const char *name, uint64_t *val)
Retrieve a configuration value as a time duration in seconds.
void DetectBufferTypeRegisterSetupCallback(const char *name, void(*SetupCallback)(const DetectEngineCtx *, Signature *, const DetectBufferType *))
void AlertQueueFree(DetectEngineThreadCtx *det_ctx)
const char * DetectEngineAppHookToName(const AppProto p, const uint8_t sub_state, const uint8_t state, const uint8_t direction)
void SCProfilingSghThreadSetup(SCProfileSghDetectCtx *ctx, DetectEngineThreadCtx *det_ctx)
StatsCounterId counter_alerts
int DetectParseDupSigHashInit(DetectEngineCtx *de_ctx)
Initializes the hash table that is used to cull duplicate sigs.
#define SIG_FLAG_FW_HOOK_LTE
InspectionBuffer * DetectGetSingleData(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id, InspectionSingleBufferGetDataPtr GetBuf)
SigTableElmt * sigmatch_table
#define SIG_JSON_CONTENT_ARRAY_LEN
void DetectLoaderThreadSpawn(void)
spawn the detect loader manager thread
int AppLayerParserIsEnabled(AppProto alproto)
simple way to globally test if a alproto is registered and fully enabled in the configuration.
uint8_t SinglePatternMatchDefaultMatcher(void)
Returns the single pattern matcher algorithm to be used, based on the spm-algo setting in yaml.
void DetectEngineDeReference(DetectEngineCtx **de_ctx)
#define DETECT_CI_FLAGS_START
uint8_t DetectEngineInspectBufferGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
void(* Free)(DetectEngineCtx *, void *)
int DetectEngineMustParseMetadata(void)
const char * AppLayerParserGetStateNameById(uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
void MpmFactoryDeRegisterAllMpmCtxProfiles(DetectEngineCtx *de_ctx)
@ DETECT_TABLE_APP_FILTER
DetectEngineTenantMapping * tenant_mapping_list
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
struct DetectEngineAppInspectionEngine_ * next
InspectionBuffer * SCInspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
uint8_t DetectEngineInspectMultiBufferGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
void MpmStoreFree(DetectEngineCtx *de_ctx)
Frees the hash table - DetectEngineCtx->mpm_hash_table, allocated by MpmStoreInit() function.
void DetectFrameMpmRegisterByParentId(DetectEngineCtx *de_ctx, const int id, const int parent_id, DetectEngineTransforms *transforms)
copy a mpm engine from parent_id, add in transforms
void DetectEngineBufferTypeSupportsPacket(DetectEngineCtx *de_ctx, const char *name)
void DetectEngineBufferRunSetupCallback(const DetectEngineCtx *de_ctx, const int id, Signature *s)
enum DetectEngineType type
void DetectEnginePruneFreeList(void)
int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exclusive)
Load signatures.
#define SIGMATCH_BAN_FIREWALL_RULE
uint8_t DetectEngineInspectBufferSingle(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
void * DetectThreadCtxGetKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define SIG_FLAG_INIT_NEED_FLUSH
void SCClassSCConfInit(DetectEngineCtx *de_ctx)
uint8_t app_progress_hook
DetectEngineCtx * DetectEngineCtxInitStubForDD(void)
#define KEYWORD_PROFILING_SET_LIST(ctx, list)
uint16_t max_uniq_toclient_groups
int ActionInitConfig(void)
Load the action order from config. If none is provided, it will be default to ACTION_PASS,...
int DetectEngineAppHookToSmlist(const AppProto p, const uint8_t sub_state, const uint8_t state, const uint8_t direction)
get the sm_list for a app hook
InspectEngineFuncPtr Callback
int PathMerge(char *out_buf, size_t buf_size, const char *const dir, const char *const fname)
@ DETECT_TABLE_PACKET_PRE_STREAM
StatsCounterId StatsRegisterCounter(const char *name, StatsThreadContext *stats)
Registers a normal, unqualified counter.
void PacketEnqueue(PacketQueue *q, Packet *p)
DetectFileDataCfg * filedata_config
struct HtpBodyChunk_ * next
struct SignatureHook_::@87::@88 app
void DetectBufferTypeSupportsFrames(const char *name)
void DetectEngineMpmCacheService(uint32_t op_flags)
void DetectMpmInitializeFrameMpms(DetectEngineCtx *de_ctx)
simple fifo queue for packets with mutex and cond Calling the mutex or triggering the cond is respons...
@ DETECT_SM_LIST_DYNAMIC_START
AppLayerDecoderEvents * decoder_events
uint8_t AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
union SignatureHook_::@87 t
void *(* InitFunc)(void *)
#define SCMutexIsLocked(mut)
InspectionBufferGetDataPtr GetData
DetectBufferMpmRegistry * pkt_mpms_list
void TmThreadContinueDetectLoaderThreads(void)
Unpauses all threads present in tv_root.
@ DETECT_SM_LIST_THRESHOLD
int SCConfYamlHandleInclude(SCConfNode *parent, const char *filename)
Include a file in the configuration.
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its normalized string equivalent.
int DetectEngineReloadTenantBlocking(uint32_t tenant_id, const char *yaml, int reload_cnt)
Reload a tenant and wait for loading to complete.
int inspection_recursion_limit
void DetectAddressMapFree(DetectEngineCtx *de_ctx)
const DetectEngineTransforms * transforms
main detection engine ctx
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
void DetectEngineReloadSetIdle(void)
void DetectBufferTypeRegisterValidateCallback(const char *name, bool(*ValidateCallback)(const Signature *, const char **sigerror, const DetectBufferType *))
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
void ** global_keyword_ctxs_array
DetectEngineCtx * DetectEngineGetCurrent(void)
void SCInspectionBufferSetupAndApplyTransforms(DetectEngineThreadCtx *det_ctx, const int list_id, InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len, const DetectEngineTransforms *transforms)
setup the buffer with our initial data
uint8_t(* SCDetectRateFilterFunc)(const Packet *p, uint32_t sid, uint32_t gid, uint32_t rev, uint8_t original_action, uint8_t new_action, void *arg)
Function type for rate filter callback.
Signature * pkt_policy_signatures[DETECT_FIREWALL_POLICY_SIZE]
uint32_t TmThreadCountThreadsByTmmFlags(uint8_t flags)
returns a count of all the threads that match the flag
void DetectBufferTypeSupportsMultiInstance(const char *name)
HashListTableBucket * HashListTableGetListHead(HashListTable *ht)
#define TAILQ_FOREACH(var, head, field)
LiveDevice * LiveDeviceGetById(const int id)
uint8_t DetectEngineInspectPacketPayload(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p)
Do the content inspection & validation for a signature.
int DetectEngineAddToMaster(DetectEngineCtx *de_ctx)
InspectionBuffer *(* InspectionBufferGetPktDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Packet *p, const int list_id)
void DetectAppLayerMultiRegisterSubState(const char *name, AppProto alproto, uint32_t dir, uint8_t sub_state, uint8_t progress, InspectionMultiBufferGetDataPtr GetData, int priority)
void SCSigSignatureOrderingModuleCleanup(DetectEngineCtx *de_ctx)
De-registers all the signature ordering functions registered.
const char * DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
void(* CacheStatsPrint)(void *data)
int DetectEngineBufferTypeGetByIdTransforms(DetectEngineCtx *de_ctx, const int id, TransformData *transforms, uint8_t transform_cnt)
int DetectEngineMultiTenantSetup(const bool unix_socket)
setup multi-detect / multi-tenancy
void PrefilterDeinit(DetectEngineCtx *de_ctx)
struct DetectBufferMpmRegistry_ * next
#define SIG_FLAG_REQUIRE_STREAM
struct DetectEngineTenantMapping_ * next
void DetectEngineSetEvent(DetectEngineThreadCtx *det_ctx, uint8_t e)
#define SIG_FLAG_TXBOTHDIR
bool DetectContentInspectionMatchOnAbsentBuffer(const SigMatchData *smd)
tells if we should match on absent buffer, because there is an absent keyword being used
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
struct SCProfileSghDetectCtx_ * profile_sgh_ctx
ThreadVars * tv_root[TVT_MAX]
one time registration of keywords at start up
void SCReferenceConfDeinit(DetectEngineCtx *de_ctx)
struct DetectPort_ * next
DetectPort * tcp_priorityports
void DetectEngineCtxFree(DetectEngineCtx *de_ctx)
Free a DetectEngineCtx::
StatsCounterId counter_alerts_overflow
void(* TransformId)(const uint8_t **data, uint32_t *length, const void *context)
SpmThreadCtx * spm_thread_ctx
int DetectEngineReloadTenantsBlocking(const int reload_cnt)
Reload all tenants and wait for loading to complete.
#define SCMUTEX_INITIALIZER
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
const char * conf_filename
enum DetectEnginePrefilterSetting prefilter_setting
void DetectParseDupSigHashFree(DetectEngineCtx *de_ctx)
Frees the hash table that is used to cull duplicate sigs.
DetectPort * udp_priorityports
int SCConfYamlLoadFileWithPrefix(const char *filename, const char *prefix)
Load configuration from a YAML file, insert in tree at 'prefix'.
int StringParseInt32(int32_t *res, int base, size_t len, const char *str)
int PrefilterGenericMpmFrameRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
@ ENGINE_SGH_MPM_FACTORY_CONTEXT_FULL
uint32_t DetectEngineGetVersion(void)
StatsCounterId counter_alerts_suppressed
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
void SigCleanSignatures(DetectEngineCtx *de_ctx)
StatsCounterId lua_instruction_limit_errors
void * HashListTableLookup(HashListTable *ht, void *data, uint16_t datalen)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
StatsCounterId counter_firewall_discarded_alerts
bool EngineModeIsFirewall(void)
#define SIG_FLAG_TOCLIENT
bool DetectMd5ValidateCallback(const Signature *s, const char **sigerror, const DetectBufferType *map)
bool DetectEngineMpmCachingEnabled(void)
bool DetectBufferIsPresent(const Signature *s, const uint32_t buf_id)
#define KEYWORD_PROFILING_START
StatsCounterAvgId StatsRegisterAvgCounter(const char *name, StatsThreadContext *stats)
Registers a counter, whose value holds the average of all the values assigned to it.
HashTable * non_pf_engine_names
void * SCDetectThreadCtxGetGlobalKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
int PrefilterMultiGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
DetectEngineFrameInspectionEngine * frame_inspect
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, uint8_t progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
void DetectBufferTypeCloseRegistration(void)
const DetectEngineTransforms * transforms
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
void(* SetupCallback)(const struct DetectEngineCtx_ *, struct Signature_ *, const struct DetectBufferType_ *)
#define SIGMATCH_BAN_FIREWALL_MODE
void HashTableFree(HashTable *ht)
Free a HashTable and all its contents.
const char * cache_dir_path
void SCAppLayerDecoderEventsSetEventRaw(AppLayerDecoderEvents **sevents, uint8_t event)
Set an app layer decoder event.
int DetectBufferTypeGetByName(const char *name)
#define KEYWORD_PROFILING_END(ctx, type, m)
void DetectBufferTypeSupportsPacket(const char *name)
InspectionBufferFrameInspectFunc Callback
int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen)
int SigGroupHeadHashInit(DetectEngineCtx *de_ctx)
Initializes the hash table in the detection engine context to hold the SigGroupHeads.
void SCRConfDeInitContext(DetectEngineCtx *de_ctx)
Releases de_ctx resources related to Reference Config API.
HashTable * mt_det_ctxs_hash
size_t strlcpy(char *dst, const char *src, size_t siz)
bool DetectEnginePktInspectionRun(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p, uint8_t *alert_flags)
void DetectAppLayerMpmRegisterByParentId(DetectEngineCtx *de_ctx, const int id, const int parent_id, DetectEngineTransforms *transforms)
copy a mpm engine from parent_id, add in transforms
void AlertQueueInit(DetectEngineThreadCtx *det_ctx)
void DetectBufferTypeSetRunAlways(const char *name)
uint16_t base64_decode_max_len
@ SIGNATURE_HOOK_TYPE_APP
#define PKT_SET_SRC(p, src_val)
void SCConfInit(void)
Initialize the configuration system.
struct DetectEngineThreadCtx_::@102 multi_inspect
void SCConfDump(void)
Dump configuration to stdout.
@ TENANT_SELECTOR_UNKNOWN
#define HashListTableGetListNext(hb)
int StringParseUint8(uint8_t *res, int base, size_t len, const char *str)
@ DETECT_SM_LIST_POSTMATCH
#define SIG_FLAG_TOSERVER
DetectEngineTenantSelectors
int DetectPortParse(const DetectEngineCtx *de_ctx, DetectPort **head, const char *str)
Function for parsing port strings.
int(* InspectionBufferPktInspectFunc)(struct DetectEngineThreadCtx_ *, const struct DetectEnginePktInspectionEngine *engine, const struct Signature_ *s, Packet *p, uint8_t *alert_flags)
void InspectionBufferFree(InspectionBuffer *buffer)
HashListTable * HashListTableInit(uint32_t size, uint32_t(*Hash)(struct HashListTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
SCDetectRequiresStatus * requirements
#define TAILQ_REMOVE(head, elm, field)
SCRunMode SCRunmodeGet(void)
Get the current run mode.
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
bool(* ValidateCallback)(const struct Signature_ *, const char **sigerror, const struct DetectBufferType_ *)
int DetectEngineMoveToFreeList(DetectEngineCtx *de_ctx)
struct DetectFirewallPolicies * fw_policies
bool(* TransformValidate)(const uint8_t *content, uint16_t content_len, const void *context)
StatsCounterAvgId counter_mpm_list
#define PASS
Pass the test.
const char * DetectTableToString(enum DetectTable table)
SpmGlobalThreadCtx * SpmInitGlobalThreadCtx(uint8_t matcher)
void SCProfilingPrefilterDestroyCtx(DetectEngineCtx *de_ctx)
void DetectMpmInitializePktMpms(DetectEngineCtx *de_ctx)
void DetectAppLayerMpmMultiRegisterSubState(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionMultiBufferGetDataPtr GetData, AppProto alproto, uint8_t sub_state, uint8_t tx_min_progress)
StatsCounterId lua_memory_limit_errors
void DetectLoadersInit(void)
struct TmSlot_ * tm_slots
const char * DetectEngineBufferTypeGetDescriptionById(const DetectEngineCtx *de_ctx, const int id)
#define SCMutexUnlock(mut)
@ DETECT_SM_LIST_BASE64_DATA
@ ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE
#define PKT_PSEUDO_STREAM_END
InspectionBuffer * buffers
DetectEngineThreadKeywordCtxItem * keyword_list
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
enum DetectEngineTenantSelectors tenant_selector
HashListTable * keyword_hash
void DetectPktInspectEngineRegister(const char *name, InspectionBufferGetPktDataPtr GetPktData, InspectionBufferPktInspectFunc Callback)
register inspect engine at start up time
int DetectEngineInspectStreamPayload(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p)
Do the content inspection & validation for a signature on the raw stream.
DetectEnginePktInspectionEngine * pkt_inspect
InspectionMultiBufferGetDataPtr GetMultiData
int DetectBufferTypeMaxId(void)
void DatasetPostReloadCleanup(void)
int SCConfGetNonNull(const char *name, const char **vptr)
Retrieve the non-null value of a configuration node.
Per thread variable structure.
bool DetectEngineBufferTypeValidateTransform(DetectEngineCtx *de_ctx, int sm_list, const uint8_t *content, uint16_t content_len, const char **namestr)
Check content byte array compatibility with transforms.
bool * sm_types_prefilter
int DetectEngineEnabled(void)
Check if detection is enabled.
SigMatchData * SigMatchList2DataArray(SigMatch *head)
convert SigMatch list to SigMatchData array
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
void(* CacheStatsDeinit)(void *data)
int DetectEngineReloadIsIdle(void)
#define DETECT_ENGINE_INSPECT_SIG_MATCH
void DetectEngineBufferTypeSetRunAlways(DetectEngineCtx *de_ctx, const int id)
#define PKT_DETECT_HAS_STREAMDATA
bool(* InspectionSingleBufferGetDataPtr)(const void *txv, const uint8_t flow_flags, const uint8_t **buf, uint32_t *buf_len)
@ DETECT_TABLE_PACKET_PRE_FLOW
void SCClassConfDeinit(DetectEngineCtx *de_ctx)
@ DETECT_TABLE_PACKET_FILTER
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
DetectEngineFrameInspectionEngine * frame_inspect_engines
DetectEngineCtx * free_list
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
struct DetectEngineThreadKeywordCtxItem_ * next
#define SCLogWarning(...)
Macro used to log WARNING messages.
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
int DetectEngineBufferTypeRegister(DetectEngineCtx *de_ctx, const char *name)
Port structure for detection engine.
uint8_t json_content_capacity
DetectEngineAppInspectionEngine * app_inspect
struct ThreadVars_ * next
bool DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Packet *p, Flow *f, const uint8_t *buffer, const uint32_t buffer_len, const uint64_t stream_start_offset, const uint8_t flags, const enum DetectContentInspectionType inspection_mode)
wrapper around DetectEngineContentInspectionInternal to return true/false only
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *tx, uint8_t flags)
get the progress value for a tx/protocol
StatsCounterId lua_rule_errors
uint32_t hashlittle_safe(const void *key, size_t length, uint32_t initval)
int SigGroupCleanup(DetectEngineCtx *de_ctx)
uint8_t DetectEngineInspectStream(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
inspect engine for stateful rules
int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml)
Load a tenant and wait for loading to complete.
void TmModuleDetectLoaderRegister(void)
struct DetectEngineFrameInspectionEngine::@86 v1
TransformIdData xform_id[DETECT_TRANSFORMS_MAX]
DetectEngineCtx * DetectEngineCtxInit(void)
void RuleMatchCandidateTxArrayFree(DetectEngineThreadCtx *det_ctx)
void DetectEngineInitializeFastPatternList(DetectEngineCtx *de_ctx)
#define DE_STATE_FLAG_BASE
void PatternMatchThreadPrepare(MpmThreadCtx *mpm_thread_ctx, DetectEngineCtx *de_ctx)
int SCRConfLoadReferenceConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
Loads the Reference info from the reference.config file.
int DetectEngineTenantRegisterLivedev(uint32_t tenant_id, int device_id)
#define DETECT_CI_FLAGS_END
void DetectEngineBufferTypeSupportsFrames(DetectEngineCtx *de_ctx, const char *name)
int(* InspectionBufferFrameInspectFunc)(struct DetectEngineThreadCtx_ *, const struct DetectEngineFrameInspectionEngine *engine, const struct Signature_ *s, Packet *p, const struct Frames *frames, const struct Frame *frame)
void *(* CacheStatsInit)(void)
DetectBufferMpmRegistry * frame_mpms_list
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
struct TenantLoaderCtx_ TenantLoaderCtx
uint16_t max_uniq_toserver_groups
int(* CacheRuleset)(MpmConfig *)
const DetectBufferType * DetectEngineBufferTypeGetById(const DetectEngineCtx *de_ctx, const int id)
InspectionBufferPktInspectFunc Callback
int ThresholdCacheThreadInit(DetectEngineThreadCtx *det_ctx)
SignatureInitData * init_data
enum DetectEngineSyncState state
SpmThreadCtx * SpmMakeThreadCtx(const SpmGlobalThreadCtx *global_thread_ctx)
void SCReferenceSCConfInit(DetectEngineCtx *de_ctx)
struct SCProfileKeywordDetectCtx_ * profile_keyword_ctx
InspectionSingleBufferGetDataPtr GetDataSingle
const char ** additional_configs
Data structures and function prototypes for keeping state for the detection engine.
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
void SCProfilingPrefilterThreadCleanup(DetectEngineThreadCtx *det_ctx)
void SCConfCreateContextBackup(void)
Creates a backup of the conf_hash hash_table used by the conf API.
int DetectEngineThreadCtxGetJsonContext(DetectEngineThreadCtx *det_ctx)
int32_t byte_extract_max_local_id
@ SIG_PROP_FLOW_ACTION_PACKET
bool DetectEngineMultiTenantEnabled(void)
const struct SignatureProperties signature_properties[SIG_TYPE_MAX]
SCDetectRateFilterFunc RateFilterCallback
int RunmodeIsUnittests(void)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
#define SIG_FLAG_REQUIRE_STREAM_ONLY
void SpmDestroyGlobalThreadCtx(SpmGlobalThreadCtx *global_thread_ctx)
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH
void DetectEngineRegisterTests(void)
int DetectLoaderQueueTask(int loader_id, LoaderFunc Func, void *func_ctx, LoaderFreeFunc FreeFunc)
@ DETECT_ENGINE_TYPE_TENANT
void DetectEngineBufferTypeSupportsTransformations(DetectEngineCtx *de_ctx, const char *name)
#define PACKET_ALERT_FLAG_STREAM_MATCH
bool(* InspectionMultiBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const void *txv, const uint8_t flow_flags, uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
bool DetectEngineBufferTypeSupportsMpmGetById(const DetectEngineCtx *de_ctx, const int id)
void DetectAppLayerMpmMultiRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionMultiBufferGetDataPtr GetData, AppProto alproto, uint8_t tx_min_progress)
const char * DetectSigmatchListEnumToString(enum DetectSigmatchListEnum type)
#define SCRealloc(ptr, sz)
uint64_t cache_max_age_seconds
void SRepReloadComplete(void)
Increment effective reputation version after a rule/reputation reload is complete.
#define SIG_FLAG_INIT_STATE_MATCH
bool DetectEngineBufferTypeSupportsFramesGetById(const DetectEngineCtx *de_ctx, const int id)
int DetectEngineBufferTypeRegisterWithFrameEngines(DetectEngineCtx *de_ctx, const char *name, const int direction, const AppProto alproto, const uint8_t frame_type)
InspectionBufferGetPktDataPtr GetData
SCConfNode * SCConfNodeLookupChild(const SCConfNode *node, const char *name)
Lookup a child configuration node by name.
@ DETECT_ENGINE_TYPE_NORMAL
void * FlowWorkerGetDetectCtxPtr(void *flow_worker)
#define APP_LAYER_MAX_PROGRESS
bool DetectEngineBufferTypeSupportsMultiInstanceGetById(const DetectEngineCtx *de_ctx, const int id)
SigFileLoaderStat sig_stat
void DetectEngineFrameMpmRegister(DetectEngineCtx *de_ctx, const char *name, int direction, int priority, int(*PrefilterRegister)(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id), AppProto alproto, uint8_t type)
uint32_t * to_clear_queue
void SpmDestroyThreadCtx(SpmThreadCtx *thread_ctx)
struct SCProfilePrefilterDetectCtx_ * profile_prefilter_ctx
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
#define DETECT_CI_FLAGS_SINGLE
int DetectEnginePktInspectionSetup(Signature *s)
int DetectBufferTypeRegister(const char *name)
uint8_t(* InspectEngineFuncPtr)(struct DetectEngineCtx_ *de_ctx, struct DetectEngineThreadCtx_ *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const struct Signature_ *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
int DetectRegisterThreadCtxFuncs(DetectEngineCtx *de_ctx, const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *), int mode)
Register Thread keyword context Funcs.
void DetectAppLayerMultiRegister(const char *name, AppProto alproto, uint32_t dir, uint8_t progress, InspectionMultiBufferGetDataPtr GetData, int priority)
int MpmStoreInit(DetectEngineCtx *de_ctx)
Initializes the MpmStore mpm hash table to be used by the detection engine context.
DetectBufferMpmRegistry * app_mpms_list
struct DetectEnginePktInspectionEngine::@85 v1
@ SIG_PROP_FLOW_ACTION_FLOW_IF_STATEFUL
DetectEngineCtx * DetectEngineCtxInitStubForMT(void)
void DetectBufferTypeSupportsMpm(const char *name)
void HashListTableFree(HashListTable *ht)
#define DETECT_FIREWALL_POLICY_SIZE
HashListTable * buffer_type_hash_name
struct DetectEngineCtx_ * next
const char * AppProtoToStringRaw(AppProto alproto)
Maps the ALPROTO_*, to its registered string equivalent.
@ DETECT_ENGINE_TYPE_DD_STUB
void DetectEngineBumpVersion(void)
struct DetectEngineFrameInspectionEngine * next
enum SignatureHookType type
int DetectEngineInspectFrameBufferGeneric(DetectEngineThreadCtx *det_ctx, const DetectEngineFrameInspectionEngine *engine, const Signature *s, Packet *p, const Frames *frames, const Frame *frame)
Do the content inspection & validation for a signature.
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
struct DetectEnginePktInspectionEngine * next
void * rate_filter_callback_arg
#define DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT
PostRuleMatchWorkQueueItem * q
uint8_t PatternMatchDefaultMatcher(void)
Function to return the multi pattern matcher algorithm to be used by the engine, based on the mpm-alg...
const char * AppLayerParserGetSubStateProgressName(const AppProto alproto, const uint8_t sub_state, const uint8_t state, const uint8_t dir_flag)
void SCConfDeInit(void)
De-initializes the configuration system.
int DetectEngineTenantRegisterPcapFile(uint32_t tenant_id)
void SigGroupHeadHashFree(DetectEngineCtx *de_ctx)
Frees the hash table - DetectEngineCtx->sgh_hash_table, allocated by SigGroupHeadHashInit() function.
void SCAppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
uint8_t DetectEngineInspectGenericList(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
void DetectEngineAppInspectionEngineSignatureFree(DetectEngineCtx *de_ctx, Signature *s)
free app inspect engines for a signature
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_HEADER
#define DETECT_ENGINE_INSPECT_SIG_NO_MATCH
DetectEnginePktInspectionEngine * pkt_inspect_engines
void DetectEngineBufferTypeSupportsMpm(DetectEngineCtx *de_ctx, const char *name)
bool * sm_types_silent_error
void DetectAppLayerInspectEngineRegisterSubState(const char *name, AppProto alproto, uint32_t dir, uint8_t sub_state, uint8_t progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
register an app inspection engine for a tx type
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
void DetectEngineFreeFastPatternList(DetectEngineCtx *de_ctx)
#define SIGMATCH_INFO_BITFLAGS_UINT
void DetectBufferTypeSupportsTransformations(const char *name)
const char * DetectEngineMpmCachingGetPath(void)
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
#define DETECT_ENGINE_MPM_CACHE_OP_SAVE
int DetectAddressMapInit(DetectEngineCtx *de_ctx)
SignatureInitDataBuffer * buffers
DetectEngineAppInspectionEngine * app_inspect_engines
int filemagic_thread_ctx_id
int global_keyword_ctxs_size
SigJsonContent * json_content
void PrefilterInit(DetectEngineCtx *de_ctx)
const Signature ** replace
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
#define SCLogError(...)
Macro used to log ERROR messages.
int SRepInit(DetectEngineCtx *de_ctx)
init reputation
int DetectEngineReloadStart(void)
void DetectEngineUnsetParseMetadata(void)
@ PKT_SRC_DETECT_RELOAD_FLUSH
void ** keyword_ctxs_array
const char * AppLayerParserGetSubStateName(const AppProto alproto, const uint8_t sub_state)
uint8_t guess_applayer_log_limit
int HashListTableRemove(HashListTable *ht, void *data, uint16_t datalen)
DetectEngineTransforms transforms
void SCConfRestoreContextBackup(void)
Restores the backup of the hash_table present in backup_conf_hash back to conf_hash.
a single match condition for a signature
const DetectEngineTransforms * transforms
int DetectLoadersSync(void)
wait for loader tasks to complete
void SCProfilingSghDestroyCtx(DetectEngineCtx *de_ctx)
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
uint8_t AppLayerParserGetTxEndState(uint8_t ipproto, AppProto alproto, void *tx, uint8_t flags)
get the end state (progress) for a transaction.
SpmTableElmt spm_table[SPM_TABLE_SIZE]
DetectEngineCtx * DetectEngineReference(DetectEngineCtx *de_ctx)
bool SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc fn, void *arg)
Register a callback when a rate_filter has been applied to an alert.
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
struct DetectEngineSyncer_ DetectEngineSyncer
void DetectMpmInitializeAppMpms(DetectEngineCtx *de_ctx)
int EngineModeIsIPS(void)
void(* ConfigDeinit)(MpmConfig **)
void InspectionBufferSetupMultiEmpty(InspectionBuffer *buffer)
setup the buffer empty
void(* ConfigCacheDirSet)(MpmConfig *, const char *dir_path)
InspectionBuffer *(* InspectionBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id)
void PmqFree(PrefilterRuleStore *pmq)
Cleanup and free a Pmq.
int(* CachePrune)(MpmConfig *)
@ DETECT_ENGINE_TYPE_MT_STUB
uint16_t vlan_id[VLAN_MAX_LAYERS]
int DetectEngineReload(const SCInstance *suri)
Reload the detection engine.
bool DetectEngineBufferRunValidateCallback(const DetectEngineCtx *de_ctx, const int id, const Signature *s, const char **sigerror)
bool DetectEngineContentInspectionBuffer(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Packet *p, Flow *f, const InspectionBuffer *b, const enum DetectContentInspectionType inspection_mode)
wrapper around DetectEngineContentInspectionInternal to return true/false only
SpmGlobalThreadCtx * spm_global_thread_ctx
void DetectEngineClearMaster(void)
StatsCounterAvgId counter_match_list
void SRepDestroy(DetectEngineCtx *de_ctx)
MpmConfig *(* ConfigInit)(void)
bool AppLayerParserSupportsSubStates(const AppProto alproto)
@ SIG_PROP_FLOW_ACTION_FLOW
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
#define SCStatFn(pathname, statbuf)
int DetectUnregisterThreadCtxFuncs(DetectEngineCtx *de_ctx, void *data, const char *name)
Remove Thread keyword context registration.
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
void DetectAppLayerInspectEngineRegisterSingle(const char *name, AppProto alproto, uint32_t dir, uint8_t progress, InspectEngineFuncPtr Callback, InspectionSingleBufferGetDataPtr GetData)
void DetectEngineFrameInspectEngineRegister(DetectEngineCtx *de_ctx, const char *name, int dir, InspectionBufferFrameInspectFunc Callback, AppProto alproto, uint8_t type)
register inspect engine at start up time
int DetectEngineTenantRegisterVlanId(uint32_t tenant_id, uint16_t vlan_id)
#define SIGMATCH_STATEFUL
void DetectEngineSetParseMetadata(void)
int TmThreadsCheckFlag(ThreadVars *tv, uint32_t flag)
Check if a thread flag is set.
int SCDetectRegisterThreadCtxGlobalFuncs(const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *))
Register Thread keyword context Funcs (Global)
#define SCLogNotice(...)
Macro used to log NOTICE messages.
void DetectPktMpmRegisterByParentId(DetectEngineCtx *de_ctx, const int id, const int parent_id, DetectEngineTransforms *transforms)
copy a mpm engine from parent_id, add in transforms
void SpmDestroyCtx(SpmCtx *ctx)
@ TENANT_SELECTOR_LIVEDEV
AppProto alproto
application level protocol
int DetectEngineTenantUnregisterPcapFile(uint32_t tenant_id)
Signature loader statistics.
int DetectEngineInspectPktBufferGeneric(DetectEngineThreadCtx *det_ctx, const DetectEnginePktInspectionEngine *engine, const Signature *s, Packet *p, uint8_t *_alert_flags)
Do the content inspection & validation for a signature.
HashListTable * buffer_type_hash_id
DetectEngineCtx * DetectEngineGetByTenantId(uint32_t tenant_id)
SpmCtx * SpmInitCtx(const uint8_t *needle, uint16_t needle_len, int nocase, SpmGlobalThreadCtx *global_thread_ctx)
void DetectPortCleanupList(const DetectEngineCtx *de_ctx, DetectPort *head)
Free a DetectPort list and each of its members.
@ DETECT_SM_LIST_SUPPRESS
InspectionBuffer * inspection_buffers
void DetectLowerSetupCallback(const DetectEngineCtx *de_ctx, Signature *s, const DetectBufferType *map)
#define DEBUG_VALIDATE_BUG_ON(exp)
int DetectEngineAppInspectionEngine2Signature(DetectEngineCtx *de_ctx, Signature *s)
bool SCClassConfLoadClassificationConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
Loads the Classtype info from the classification.config file.
void InspectionBufferSetupMulti(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer, const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
StatsCounterId lua_blocked_function_errors
int DetectEngineTenantUnregisterVlanId(uint32_t tenant_id, uint16_t vlan_id)
int PmqSetup(PrefilterRuleStore *pmq)
Setup a pmq.
void PatternMatchThreadDestroy(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher)
int VarNameStoreActivate(void)
InspectionBuffer * InspectionBufferMultipleForListGet(DetectEngineThreadCtx *det_ctx, const int list_id, const uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
void RuleMatchCandidateTxArrayInit(DetectEngineThreadCtx *det_ctx, uint32_t size)
void SCProfilingKeywordThreadSetup(SCProfileKeywordDetectCtx *ctx, DetectEngineThreadCtx *det_ctx)
int DetectEngineReloadIsStart(void)
PostRuleMatchWorkQueue post_rule_work_queue
uint32_t tenant_array_size
struct DetectEngineTenantMapping_ * tenant_array
volatile uint8_t suricata_ctl_flags
#define TM_FLAG_FLOWWORKER_TM
void FlowWorkerReplaceDetectCtx(void *flow_worker, void *detect_ctx)
uint32_t StringHashDjb2(const uint8_t *data, uint32_t datalen)
uint32_t(* TenantGetId)(const void *, const Packet *p)
void SCProfilingPrefilterThreadSetup(SCProfilePrefilterDetectCtx *ctx, DetectEngineThreadCtx *det_ctx)
void SCClassConfDeInitContext(DetectEngineCtx *de_ctx)
Releases resources used by the Classification Config API.
void PrefilterPktNonPFStatsDump(void)
#define SIG_FLAG_REQUIRE_PACKET