Go to the documentation of this file.
96 #define DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT 3000
98 #define DEFAULT_MAX_FLOWBITS_PER_SIGNATURE 8
105 static uint32_t TenantIdHash(
HashTable *h,
void *
data, uint16_t data_len);
106 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len);
107 static void TenantIdFree(
void *d);
108 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *
p);
109 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *
p);
110 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *
p);
112 static bool DetectEngineMultiTenantEnabledWithLock(
void);
144 return "packet_filter";
178 FatalError(
"failed to register inspect engine %s: %s",
name, strerror(errno));
180 new_engine->
sm_list = (uint16_t)sm_list;
185 if (g_pkt_inspect_engines == NULL) {
186 g_pkt_inspect_engines = new_engine;
189 while (t->
next != NULL) {
193 t->
next = new_engine;
200 static void AppLayerInspectEngineRegisterInternal(
const char *
name,
AppProto alproto, uint32_t dir,
221 (Callback == NULL)) {
225 SCLogError(
"Invalid arguments: must register "
226 "GetData with DetectEngineInspectBufferGeneric");
229 SCLogError(
"Invalid arguments: must register "
230 "GetData with DetectEngineInspectBufferGeneric");
233 SCLogError(
"Invalid arguments: must register "
234 "GetData with DetectEngineInspectMultiBufferGeneric");
250 new_engine->
dir = direction;
251 new_engine->
sm_list = (uint16_t)sm_list;
264 if (g_app_inspect_engines == NULL) {
265 g_app_inspect_engines = new_engine;
268 while (t->
next != NULL) {
272 t->
next = new_engine;
286 if (t->
sm_list == sm_list && t->
alproto == alproto && t_direction == dir &&
295 AppLayerInspectEngineRegisterInternal(
296 name, alproto, dir, 0, (uint8_t)progress, Callback, GetData, NULL, NULL);
310 if (t->
sm_list == sm_list && t->
alproto == alproto && t_direction == dir &&
319 AppLayerInspectEngineRegisterInternal(
320 name, alproto, dir, sub_state, progress, Callback, GetData, NULL, NULL);
332 if (t->
sm_list == sm_list && t->
alproto == alproto && t_direction == dir &&
341 AppLayerInspectEngineRegisterInternal(
342 name, alproto, dir, 0, (uint8_t)progress, Callback, NULL, GetData, NULL);
346 static void DetectAppLayerInspectEngineCopy(
348 int sm_list,
int new_list,
361 new_engine->
sm_list = (uint16_t)new_list;
366 new_engine->
v2 = t->
v2;
373 while (list->
next != NULL) {
377 list->
next = new_engine;
400 new_engine->
v2 = t->
v2;
405 list->
next = new_engine;
414 static void DetectPktInspectEngineCopy(
416 int sm_list,
int new_list,
427 new_engine->
sm_list = (uint16_t)new_list;
430 new_engine->
v1 = t->
v1;
437 while (list->
next != NULL) {
441 list->
next = new_engine;
460 new_engine->
v1 = t->
v1;
466 while (list->
next != NULL) {
470 list->
next = new_engine;
502 FatalError(
"failed to register inspect engine %s: %s",
name, strerror(errno));
504 new_engine->
sm_list = (uint16_t)sm_list;
506 new_engine->
dir = direction;
515 while (list->
next != NULL) {
519 list->
next = new_engine;
538 new_engine->
sm_list = (uint16_t)new_list;
544 new_engine->
v1 = t->
v1;
549 while (list->
next != NULL) {
553 list->
next = new_engine;
575 new_engine->
v1 = t->
v1;
581 while (list->
next != NULL) {
585 list->
next = new_engine;
597 static void AppendStreamInspectEngine(
600 bool prepend =
false;
609 new_engine->
mpm =
true;
612 new_engine->
dir = direction;
613 new_engine->
stream =
true;
616 new_engine->
smd = stream;
624 }
else if (prepend) {
631 while (a->
next != NULL) {
635 a->
next = new_engine;
638 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
645 bool prepend =
false;
668 new_engine->
mpm =
true;
674 new_engine->
smd = smd;
675 new_engine->
v1 = u->
v1;
681 }
else if (prepend) {
686 while (a->
next != NULL) {
690 a->
next = new_engine;
698 bool prepend =
false;
708 new_engine->
mpm =
true;
713 new_engine->
smd = smd;
714 new_engine->
v1 = e->
v1;
720 }
else if (prepend) {
725 while (a->
next != NULL) {
729 a->
next = new_engine;
735 const int mpm_list,
const int files_id, uint8_t *last_id,
bool *head_is_mpm)
765 SCLogDebug(
"app engine: t %p t->id %u => alproto:%s files:%s", t, t->
id,
773 bool prepend =
false;
778 new_engine->
mpm =
true;
785 new_engine->
smd = smd;
789 new_engine->
v2 = t->
v2;
795 if (new_engine->
sm_list == files_id) {
797 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
800 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
808 if (new_engine->
sm_list == files_id) {
810 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
812 new_engine->
id = ++(*last_id);
813 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
819 while (a->
next != NULL) {
827 a->
next = new_engine;
828 if (new_engine->
sm_list == files_id) {
830 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
832 new_engine->
id = ++(*last_id);
833 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
838 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
847 const AppProto p,
const uint8_t sub_state,
const uint8_t state,
const uint8_t direction)
849 if (!((direction & (STREAM_TOSERVER | STREAM_TOCLIENT)) == STREAM_TOSERVER) &&
850 !((direction & (STREAM_TOSERVER | STREAM_TOCLIENT)) == STREAM_TOCLIENT))
853 if (sub_state == 0) {
855 p, state, direction);
858 if (direction == STREAM_TOSERVER) {
859 pname =
"request_started";
861 pname =
"response_started";
865 if (state == complete) {
866 if (direction == STREAM_TOSERVER) {
867 pname =
"request_complete";
869 pname =
"response_complete";
886 const AppProto p,
const uint8_t sub_state,
const uint8_t state,
const uint8_t direction)
889 if (app_proto == NULL) {
894 char generic_hook_name[256];
895 if (sub_state == 0) {
897 p, 0, state, direction & (STREAM_TOSERVER | STREAM_TOCLIENT));
902 snprintf(generic_hook_name,
sizeof(generic_hook_name),
"%s:%s:generic", app_proto,
name);
907 "no list registered as %s for %s hook %s", generic_hook_name, app_proto,
name);
922 snprintf(generic_hook_name,
sizeof(generic_hook_name),
"%s:%s:%s:generic", app_proto, sname,
927 SCLogError(
"no list registered as %s for %s sub_state %s hook %s", generic_hook_name,
928 app_proto, sname,
name);
943 bool head_is_mpm =
false;
951 uint8_t direction = 0;
956 direction = STREAM_TOSERVER;
959 direction = STREAM_TOCLIENT;
972 .sm_list = (uint16_t)sm_list,
973 .sm_list_base = (uint16_t)sm_list,
976 AppendAppInspectEngine(
de_ctx, &t, s, NULL, mpm_list, files_id, &last_id, &head_is_mpm);
977 SCLogDebug(
"sid %u: appended pass-tru engine at hook:%u sm_list:%d for "
978 "SIG_FLAG_INIT_HOOK_LTE",
979 s->
id, state, sm_list);
994 u != NULL; u = u->
next) {
996 AppendFrameInspectEngine(
de_ctx, u, s, smd, mpm_list);
1005 AppendPacketInspectEngine(
de_ctx, e, s, smd, mpm_list);
1023 AppendAppInspectEngine(
1024 de_ctx, t, s, smd, mpm_list, files_id, &last_id, &head_is_mpm);
1059 AppendAppInspectEngine(
de_ctx, &t, s, NULL, mpm_list, files_id, &last_id, &head_is_mpm);
1069 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
1071 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
1073 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
1074 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
1086 SCLogDebug(
"%u: engine %s id %u progress %d %s", s->
id,
1088 iter->
sm_list == mpm_list ?
"MPM" :
"");
1139 for (
int i = 0; i < arrays; i++) {
1140 if (bufs[i] == ie->
smd) {
1146 bufs[arrays++] = ie->
smd;
1156 for (
int i = 0; i < arrays; i++) {
1157 if (bufs[i] == e->
smd) {
1163 bufs[arrays++] = e->
smd;
1173 for (
int i = 0; i < arrays; i++) {
1174 if (bufs[i] == u->
smd) {
1180 bufs[arrays++] = u->
smd;
1186 for (
int i = 0; i < engines; i++) {
1187 if (bufs[i] == NULL)
1208 static int g_buffer_type_reg_closed = 0;
1212 return g_buffer_type_id;
1228 static uint32_t DetectBufferTypeHashNameFunc(
HashListTable *ht,
void *data, uint16_t datalen)
1252 static uint32_t DetectBufferTypeHashIdFunc(
HashListTable *ht,
void *data, uint16_t datalen)
1255 uint32_t hash = map->
id;
1260 static char DetectBufferTypeCompareNameFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
1265 char r = (strcmp(map1->
name, map2->
name) == 0);
1278 SCLogDebug(
"%s: transform ids match; checking specialized data", map1->
name);
1287 SCLogDebug(
"identity data: only one is null");
1312 static char DetectBufferTypeCompareIdFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
1316 return map1->
id == map2->
id;
1319 static void DetectBufferTypeFreeFunc(
void *data)
1333 SCLogError(
"%s allocates transform option memory but has no free routine",
1343 static int DetectBufferTypeInit(
void)
1345 BUG_ON(g_buffer_type_hash);
1347 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
1348 if (g_buffer_type_hash == NULL)
1354 static void DetectBufferTypeFree(
void)
1356 if (g_buffer_type_hash == NULL)
1360 g_buffer_type_hash = NULL;
1363 static int DetectBufferTypeAdd(
const char *
string)
1365 BUG_ON(
string == NULL || strlen(
string) >= 64);
1372 map->
id = g_buffer_type_id++;
1382 memset(&map, 0,
sizeof(map));
1391 BUG_ON(g_buffer_type_reg_closed);
1392 if (g_buffer_type_hash == NULL)
1393 DetectBufferTypeInit();
1397 return DetectBufferTypeAdd(
name);
1405 BUG_ON(g_buffer_type_reg_closed);
1410 SCLogDebug(
"%p %s -- %d supports multi instance", exists,
name, exists->
id);
1415 BUG_ON(g_buffer_type_reg_closed);
1419 exists->
frame =
true;
1420 SCLogDebug(
"%p %s -- %d supports frame inspection", exists,
name, exists->
id);
1425 BUG_ON(g_buffer_type_reg_closed);
1430 SCLogDebug(
"%p %s -- %d supports packet inspection", exists,
name, exists->
id);
1435 BUG_ON(g_buffer_type_reg_closed);
1445 BUG_ON(g_buffer_type_reg_closed);
1450 SCLogDebug(
"%p %s -- %d supports transformations", exists,
name, exists->
id);
1466 memset(&map, 0,
sizeof(map));
1476 memset(&lookup, 0,
sizeof(lookup));
1486 return res ? res->
name : NULL;
1491 BUG_ON(
string == NULL || strlen(
string) >= 32);
1507 const int direction,
const AppProto alproto,
const uint8_t frame_type)
1514 const int buffer_id = DetectEngineBufferTypeAdd(
de_ctx,
name);
1515 if (buffer_id < 0) {
1544 return DetectEngineBufferTypeAdd(
de_ctx,
name);
1552 BUG_ON(desc == NULL || strlen(desc) >= 128);
1574 exists->
frame =
true;
1575 SCLogDebug(
"%p %s -- %d supports frame inspection", exists,
name, exists->
id);
1583 SCLogDebug(
"%p %s -- %d supports packet inspection", exists,
name, exists->
id);
1599 SCLogDebug(
"%p %s -- %d supports transformations", exists,
name, exists->
id);
1641 BUG_ON(g_buffer_type_reg_closed);
1657 const char *
name,
bool (*ValidateCallback)(
const Signature *,
const char **sigerror,
1660 BUG_ON(g_buffer_type_reg_closed);
1707 const uint8_t *content, uint16_t content_len,
const char **namestr)
1733 const int size = g_buffer_type_id;
1737 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
1740 HashListTableInit(256, DetectBufferTypeHashIdFunc, DetectBufferTypeCompareIdFunc,
1752 memcpy(copy, map,
sizeof(*copy));
1758 SCLogDebug(
"name %s id %d mpm %s packet %s -- %s. "
1759 "Callbacks: Setup %p Validate %p",
1760 map->
name, map->
id, map->
mpm ?
"true" :
"false", map->
packet ?
"true" :
"false",
1767 DetectAppLayerInspectEngineCopyListToDetectCtx(
de_ctx);
1769 DetectFrameInspectEngineCopyListToDetectCtx(
de_ctx);
1771 DetectPktInspectEngineCopyListToDetectCtx(
de_ctx);
1813 while (framemlist) {
1824 BUG_ON(g_buffer_type_hash == NULL);
1826 g_buffer_type_reg_closed = 1;
1837 SCLogError(
"buffer '%s' does not support transformations", base_map->
name);
1844 memset(&t, 0,
sizeof(t));
1845 for (
int i = 0; i < transform_cnt; i++) {
1848 t.
cnt = transform_cnt;
1851 memset(&lookup_map, 0,
sizeof(lookup_map));
1857 DetectBufferAddTransformData(&lookup_map);
1874 map->
mpm = base_map->
mpm;
1881 }
else if (map->
packet) {
1891 SCLogDebug(
"buffer %s registered with id %d, parent %d", map->name, map->id, map->parent_id);
1894 DetectFrameInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1895 }
else if (map->packet) {
1896 DetectPktInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1898 DetectAppLayerInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1904 static int DetectEngineInspectRulePacketMatches(
1908 Packet *
p, uint8_t *_alert_flags)
1916 SCLogDebug(
"running match functions, sm %p", smd);
1934 static int DetectEngineInspectRulePayloadMatches(
1956 SCLogDebug(
"no match in stream, fall back to packet payload");
1964 SCLogDebug(
"SIG_FLAG_REQUIRE_STREAM_ONLY, so no match");
1982 uint8_t *alert_flags)
1988 SCLogDebug(
"sid %u: e %p Callback returned no match", s->
id, e);
1991 SCLogDebug(
"sid %u: e %p Callback returned true", s->
id, e);
2010 e->
sm_list = (uint16_t)list_id;
2019 while (a->
next != NULL) {
2031 if (DetectEnginePktInspectionAppend(
2034 SCLogDebug(
"sid %u: DetectEngineInspectRulePayloadMatches appended", s->
id);
2038 if (DetectEnginePktInspectionAppend(
2041 SCLogDebug(
"sid %u: DetectEngineInspectRulePacketMatches appended", s->
id);
2123 uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
2126 SCLogDebug(
"running match functions, sm %p", smd);
2132 AppLayerTxMatch(det_ctx, f,
flags, alstate, txv, s, smd->
ctx);
2149 static bool DetectTxCompleted(
2175 void *alstate,
void *txv, uint64_t tx_id)
2177 const int list_id = engine->
sm_list;
2178 SCLogDebug(
"running inspect on %d", list_id);
2180 const bool eof = DetectTxCompleted(f, txv,
flags, engine);
2201 const uint8_t *data = buffer->
inspect;
2206 ci_flags |= buffer->
flags;
2235 void *alstate,
void *txv, uint64_t tx_id)
2237 const int list_id = engine->
sm_list;
2238 SCLogDebug(
"running inspect on %d", list_id);
2240 const bool eof = DetectTxCompleted(f, txv,
flags, engine);
2252 f,
flags, txv, list_id);
2262 const uint8_t *data = buffer->
inspect;
2267 ci_flags |= buffer->
flags;
2287 AppLayerInspectEngineRegisterInternal(
name, alproto, dir, sub_state, progress,
2290 GetData, alproto, sub_state, progress);
2299 AppLayerInspectEngineRegisterInternal(
name, alproto, dir, 0, (uint8_t)progress,
2310 if (buffer->
inspect == NULL) {
2311 const uint8_t *b = NULL;
2314 if (!GetBuf(txv, flow_flags, &b, &b_len))
2327 if (buffer == NULL) {
2334 const uint8_t *data = NULL;
2335 uint32_t data_len = 0;
2337 if (!GetBuf(det_ctx, txv, flow_flags, index, &data, &data_len)) {
2348 const Signature *s,
Flow *f, uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
2350 uint32_t local_id = 0;
2360 if (buffer == NULL || buffer->
inspect == NULL)
2372 if (local_id == 0) {
2374 const bool eof = DetectTxCompleted(f, txv,
flags, engine);
2398 const int list_id = engine->
sm_list;
2399 SCLogDebug(
"running inspect on %d", list_id);
2417 ci_flags |= buffer->
flags;
2436 static void InjectPackets(
2444 for (
int i = 0; i < no_of_detect_tvs; i++) {
2445 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) != 1) {
2446 if (detect_tvs[i]->inq != NULL) {
2465 char varname[128] =
"detect.flowbits.max-per-signature";
2467 snprintf(varname,
sizeof(varname),
"%s.detect.flowbits.max-per-signature",
2478 SCLogWarning(
"Invalid setting for flowbits.max-per-signature %d, resetting to the "
2484 "Invalid setting for flowbits.max-per-signature, resetting to the default");
2512 if (no_of_detect_tvs == 0) {
2522 memset(detect_tvs, 0x00, (no_of_detect_tvs *
sizeof(
ThreadVars *)));
2547 if (new_det_ctx[i] == NULL) {
2549 "failure in live rule swap. Let's get out of here");
2553 SCLogDebug(
"live rule swap created new det_ctx - %p and de_ctx "
2554 "- %p\n", new_det_ctx[i], new_de_ctx);
2559 BUG_ON(i != no_of_detect_tvs);
2572 SCLogDebug(
"swapping new det_ctx - %p with older one - %p",
2585 SCLogDebug(
"Live rule swap has swapped %d old det_ctx's with new ones, "
2586 "along with the new de_ctx", no_of_detect_tvs);
2588 InjectPackets(detect_tvs, new_det_ctx, no_of_detect_tvs);
2592 uint32_t threads_done = 0;
2594 for (i = 0; i < no_of_detect_tvs; i++) {
2596 threads_done = no_of_detect_tvs;
2600 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) == 1) {
2601 SCLogDebug(
"new_det_ctx - %p used by detect engine", new_det_ctx[i]);
2604 TmThreadsCaptureBreakLoop(detect_tvs[i]);
2607 if (threads_done < no_of_detect_tvs) {
2618 if (i != no_of_detect_tvs) {
2631 for (i = 0; i < no_of_detect_tvs; i++) {
2632 SCLogDebug(
"Freeing old_det_ctx - %p used by detect",
2642 for (i = 0; i < no_of_detect_tvs; i++) {
2643 if (new_det_ctx[i] != NULL)
2651 int sgh_mpm_caching = 0;
2652 if (
SCConfGetBool(
"detect.sgh-mpm-caching", &sgh_mpm_caching) != 1) {
2655 return (
bool)sgh_mpm_caching;
2664 char yamlpath[] =
"detect.sgh-mpm-caching-path";
2665 const char *strval = NULL;
2666 if (
SCConfGet(yamlpath, &strval) == 1 && strval != NULL) {
2670 static bool notified =
false;
2672 SCLogInfo(
"%s has no path specified, using %s", yamlpath, SGH_CACHE_DIR);
2675 return SGH_CACHE_DIR;
2763 if (prefix != NULL) {
2767 int failure_fatal = 0;
2768 if (
SCConfGetBool(
"engine.init-failure-fatal", (
int *)&failure_fatal) != 1) {
2769 SCLogDebug(
"ConfGetBool could not load the value.");
2777 SCLogDebug(
"Unable to alloc SpmGlobalThreadCtx.");
2789 if (DetectEngineCtxLoadConf(
de_ctx) == -1) {
2798 DetectBufferTypeSetupDetectEngine(
de_ctx);
2846 if (prefix == NULL || strlen(prefix) == 0)
2884 #ifdef PROFILE_RULES
2885 if (
de_ctx->profile_ctx != NULL) {
2886 SCProfilingRuleDestroyCtx(
de_ctx->profile_ctx);
2887 de_ctx->profile_ctx = NULL;
2930 DetectEngineCtxFreeThreadKeywordData(
de_ctx);
2932 DetectEngineCtxFreeFailedSigs(
de_ctx);
2952 DetectBufferTypeFreeDetectEngine(
de_ctx);
2991 const char *max_uniq_toclient_groups_str = NULL;
2992 const char *max_uniq_toserver_groups_str = NULL;
2993 const char *sgh_mpm_context = NULL;
2994 const char *de_ctx_profile = NULL;
2996 (void)
SCConfGet(
"detect.profile", &de_ctx_profile);
2997 (void)
SCConfGet(
"detect.sgh-mpm-context", &sgh_mpm_context);
3002 if (de_ctx_custom != NULL) {
3004 if (de_ctx_profile == NULL) {
3005 if (opt->
val && strcmp(opt->
val,
"profile") == 0) {
3006 de_ctx_profile = opt->head.tqh_first->
val;
3010 if (sgh_mpm_context == NULL) {
3011 if (opt->
val && strcmp(opt->
val,
"sgh-mpm-context") == 0) {
3012 sgh_mpm_context = opt->head.tqh_first->
val;
3018 if (de_ctx_profile != NULL) {
3019 if (strcmp(de_ctx_profile,
"low") == 0 ||
3020 strcmp(de_ctx_profile,
"lowest") == 0) {
3022 }
else if (strcmp(de_ctx_profile,
"medium") == 0) {
3024 }
else if (strcmp(de_ctx_profile,
"high") == 0 ||
3025 strcmp(de_ctx_profile,
"highest") == 0) {
3027 }
else if (strcmp(de_ctx_profile,
"custom") == 0) {
3030 SCLogError(
"invalid value for detect.profile: '%s'. "
3031 "Valid options: low, medium, high and custom.",
3036 SCLogDebug(
"Profile for detection engine groups is \"%s\"", de_ctx_profile);
3038 SCLogDebug(
"Profile for detection engine groups not provided "
3039 "at suricata.yaml. Using default (\"medium\").");
3043 if (sgh_mpm_context == NULL || strcmp(sgh_mpm_context,
"auto") == 0) {
3053 if (strcmp(sgh_mpm_context,
"single") == 0) {
3055 }
else if (strcmp(sgh_mpm_context,
"full") == 0) {
3059 "invalid conf value for detect-engine.sgh-mpm-context-"
3084 (void)
SCConfGet(
"detect.custom-values.toclient-groups", &max_uniq_toclient_groups_str);
3085 (void)
SCConfGet(
"detect.custom-values.toserver-groups", &max_uniq_toserver_groups_str);
3087 if (de_ctx_custom != NULL) {
3089 if (opt->
val && strcmp(opt->
val,
"custom-values") == 0) {
3090 if (max_uniq_toclient_groups_str == NULL) {
3092 opt->head.tqh_first,
"toclient-sp-groups");
3094 if (max_uniq_toclient_groups_str == NULL) {
3096 opt->head.tqh_first,
"toclient-groups");
3098 if (max_uniq_toserver_groups_str == NULL) {
3100 opt->head.tqh_first,
"toserver-dp-groups");
3102 if (max_uniq_toserver_groups_str == NULL) {
3104 opt->head.tqh_first,
"toserver-groups");
3109 if (max_uniq_toclient_groups_str != NULL) {
3111 (uint16_t)strlen(max_uniq_toclient_groups_str),
3112 (
const char *)max_uniq_toclient_groups_str) <= 0) {
3116 "toclient-groups failed, using %u",
3124 if (max_uniq_toserver_groups_str != NULL) {
3126 (uint16_t)strlen(max_uniq_toserver_groups_str),
3127 (
const char *)max_uniq_toserver_groups_str) <= 0) {
3131 "toserver-groups failed, using %u",
3151 if (
SCConfGetInt(
"detect.inspection-recursion-limit", &value) == 1) {
3152 if (value >= 0 && value <= INT_MAX) {
3158 SCConfNode *insp_recursion_limit_node = NULL;
3159 char *insp_recursion_limit = NULL;
3161 if (de_ctx_custom != NULL) {
3164 if (opt->
val && strcmp(opt->
val,
"inspection-recursion-limit") != 0)
3168 if (insp_recursion_limit_node == NULL) {
3170 "entry for detect-engine:inspection-recursion-limit");
3173 insp_recursion_limit = insp_recursion_limit_node->
val;
3174 SCLogDebug(
"Found detect-engine.inspection-recursion-limit - %s:%s",
3175 insp_recursion_limit_node->
name, insp_recursion_limit_node->
val);
3179 if (insp_recursion_limit != NULL) {
3181 0, (
const char *)insp_recursion_limit) < 0) {
3183 "detect-engine.inspection-recursion-limit: %s "
3196 SCLogDebug(
"de_ctx->inspection_recursion_limit: %d",
3201 if (
SCConfGetInt(
"detect.stream-tx-log-limit", &value) == 1) {
3202 if (value >= 0 && value <= UINT8_MAX) {
3205 SCLogWarning(
"Invalid value for detect-engine.stream-tx-log-limit: must be between 0 "
3206 "and 255, will default to 4");
3209 int guess_applayer = 0;
3210 if ((
SCConfGetBool(
"detect.guess-applayer-tx", &guess_applayer)) == 1) {
3211 if (guess_applayer == 1) {
3218 const char *ports = NULL;
3219 (void)
SCConfGet(
"detect.grouping.tcp-priority-ports", &ports);
3221 SCLogConfig(
"grouping: tcp-priority-ports %s", ports);
3223 (void)
SCConfGet(
"detect.grouping.tcp-whitelist", &ports);
3226 "grouping: tcp-priority-ports from legacy 'tcp-whitelist' setting: %s", ports);
3228 ports =
"53, 80, 139, 443, 445, 1433, 3306, 3389, 6666, 6667, 8080";
3229 SCLogConfig(
"grouping: tcp-priority-ports (default) %s", ports);
3234 "for detect.grouping.tcp-priority-ports",
3238 for ( ; x != NULL; x = x->
next) {
3241 "for detect.grouping.tcp-priority-ports: only single ports allowed",
3250 (void)
SCConfGet(
"detect.grouping.udp-priority-ports", &ports);
3252 SCLogConfig(
"grouping: udp-priority-ports %s", ports);
3254 (void)
SCConfGet(
"detect.grouping.udp-whitelist", &ports);
3257 "grouping: udp-priority-ports from legacy 'udp-whitelist' setting: %s", ports);
3259 ports =
"53, 135, 5060";
3260 SCLogConfig(
"grouping: udp-priority-ports (default) %s", ports);
3265 "for detect.grouping.udp-priority-ports",
3271 "for detect.grouping.udp-priority-ports: only single ports allowed",
3279 DetectEngineLoadFlowbitSettings(
de_ctx);
3282 const char *pf_setting = NULL;
3283 if (
SCConfGet(
"detect.prefilter.default", &pf_setting) == 1 && pf_setting) {
3284 if (strcasecmp(pf_setting,
"mpm") == 0) {
3286 }
else if (strcasecmp(pf_setting,
"auto") == 0) {
3295 SCLogConfig(
"prefilter engines: MPM and keywords");
3315 SCLogError(
"setting up thread local detect ctx");
3324 SCLogError(
"setting up thread local detect ctx "
3325 "for keyword \"%s\" failed",
3363 SCLogError(
"setting up thread local detect ctx");
3375 SCLogError(
"setting up thread local detect ctx "
3376 "for keyword \"%s\" failed",
3407 uint32_t map_array_size = 0;
3408 uint32_t map_cnt = 0;
3409 uint32_t max_tenant_id = 0;
3417 "set using multi-detect.selector");
3431 HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree);
3432 if (mt_det_ctxs_hash == NULL) {
3437 SCLogInfo(
"no tenants left, or none registered yet");
3448 map_array_size = map_cnt + 1;
3450 map_array =
SCCalloc(map_array_size,
sizeof(*map_array));
3451 if (map_array == NULL)
3458 if (map_cnt >= map_array_size) {
3470 list = master->
list;
3475 if (mt_det_ctx == NULL)
3477 if (
HashTableAdd(mt_det_ctxs_hash, mt_det_ctx, 0) != 0) {
3486 mt_det_ctxs_hash = NULL;
3498 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromVlanId;
3502 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromLivedev;
3506 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromPcap;
3513 if (map_array != NULL)
3515 if (mt_det_ctxs_hash != NULL)
3543 if (det_ctx->
replace == NULL) {
3593 DetectEngineThreadCtxInitGlobalKeywords(det_ctx);
3594 #ifdef PROFILE_RULES
3595 SCProfilingRuleThreadSetup(
de_ctx->profile_ctx, det_ctx);
3634 if (det_ctx->
de_ctx == NULL) {
3695 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3704 *data = (
void *)det_ctx;
3728 if (det_ctx->
de_ctx == NULL) {
3759 if (mt && DetectEngineMultiTenantEnabledWithLock()) {
3760 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3773 SCLogDebug(
"PACKET PKT_STREAM_ADD: %"PRIu64, det_ctx->pkt_stream_add_cnt);
3775 SCLogDebug(
"PAYLOAD MPM %"PRIu64
"/%"PRIu64, det_ctx->payload_mpm_cnt, det_ctx->payload_mpm_size);
3776 SCLogDebug(
"STREAM MPM %"PRIu64
"/%"PRIu64, det_ctx->stream_mpm_cnt, det_ctx->stream_mpm_size);
3778 SCLogDebug(
"PAYLOAD SIG %"PRIu64
"/%"PRIu64, det_ctx->payload_persig_cnt, det_ctx->payload_persig_size);
3779 SCLogDebug(
"STREAM SIG %"PRIu64
"/%"PRIu64, det_ctx->stream_persig_cnt, det_ctx->stream_persig_size);
3787 #ifdef PROFILE_RULES
3788 SCProfilingRuleThreadCleanup(det_ctx);
3797 if (det_ctx->
de_ctx != NULL) {
3838 for (uint32_t x = 0; x < fb->
size; x++) {
3849 DetectEngineThreadCtxDeinitGlobalKeywords(det_ctx);
3850 if (det_ctx->
de_ctx != NULL) {
3851 DetectEngineThreadCtxDeinitKeywords(det_ctx->
de_ctx, det_ctx);
3875 if (det_ctx == NULL) {
3884 DetectEngineThreadCtxFree(det_ctx);
3889 static uint32_t DetectKeywordCtxHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
3896 return (uint32_t)hash;
3899 static char DetectKeywordCtxCompareFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
3903 const char *name1 = ctx1->
name;
3904 const char *name2 = ctx2->
name;
3905 return (strcmp(name1, name2) == 0 && ctx1->
data == ctx2->
data);
3908 static void DetectKeywordCtxFreeFunc(
void *ptr)
3931 BUG_ON(
de_ctx == NULL || InitFunc == NULL || FreeFunc == NULL);
3935 DetectKeywordCtxHashFunc, DetectKeywordCtxCompareFunc, DetectKeywordCtxFreeFunc);
4020 const char *
name,
void *(*InitFunc)(
void *),
void *data,
void (*FreeFunc)(
void *))
4023 BUG_ON(InitFunc == NULL || FreeFunc == NULL);
4029 while (item != NULL) {
4030 if (strcmp(
name, item->
name) == 0) {
4080 if (master->
list == NULL) {
4139 static bool DetectEngineMultiTenantEnabledWithLock(
void)
4149 bool enabled = DetectEngineMultiTenantEnabledWithLock();
4164 static int DetectEngineMultiTenantLoadTenant(uint32_t tenant_id,
const char *filename,
int loader_id)
4169 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
4172 if (
SCStatFn(filename, &st) != 0) {
4173 SCLogError(
"failed to stat file %s", filename);
4179 SCLogError(
"tenant %u already registered", tenant_id);
4186 SCLogError(
"failed to properly setup yaml %s", filename);
4222 static int DetectEngineMultiTenantReloadTenant(uint32_t tenant_id,
const char *filename,
int reload_cnt)
4225 if (old_de_ctx == NULL) {
4226 SCLogError(
"tenant detect engine not found");
4230 if (filename == NULL)
4234 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u.reload.%d", tenant_id, reload_cnt);
4245 SCLogError(
"failed to properly setup yaml %s", filename);
4250 if (new_de_ctx == NULL) {
4263 goto new_de_ctx_error;
4268 goto new_de_ctx_error;
4293 static void DetectLoaderFreeTenant(
void *
ctx)
4296 if (t->
yaml != NULL) {
4302 static int DetectLoaderFuncLoadTenant(
void *vctx,
int loader_id)
4307 if (DetectEngineMultiTenantLoadTenant(
ctx->tenant_id,
ctx->yaml, loader_id) != 0) {
4313 static int DetectLoaderSetupLoadTenant(uint32_t tenant_id,
const char *yaml)
4321 if (t->
yaml == NULL) {
4329 static int DetectLoaderFuncReloadTenant(
void *vctx,
int loader_id)
4335 if (DetectEngineMultiTenantReloadTenant(
ctx->tenant_id,
ctx->yaml,
ctx->reload_cnt) != 0) {
4341 static int DetectLoaderSetupReloadTenants(
const int reload_cnt)
4360 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4374 static int DetectLoaderSetupReloadTenant(uint32_t tenant_id,
const char *yaml,
int reload_cnt)
4377 if (old_de_ctx == NULL)
4389 if (t->
yaml == NULL) {
4399 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4406 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml);
4420 int r = DetectLoaderSetupReloadTenant(tenant_id, yaml, reload_cnt);
4434 int r = DetectLoaderSetupReloadTenants(reload_cnt);
4444 static int DetectEngineMultiTenantSetupLoadLivedevMappings(
4445 const SCConfNode *mappings_root_node,
bool failure_fatal)
4449 int mapping_cnt = 0;
4450 if (mappings_root_node != NULL) {
4453 if (tenant_id_node == NULL)
4456 if (device_node == NULL)
4459 uint32_t tenant_id = 0;
4461 tenant_id_node->
val) < 0) {
4464 tenant_id_node->
val);
4468 const char *dev = device_node->
val;
4487 SCLogConfig(
"device %s connected to tenant-id %u", dev, tenant_id);
4496 SCLogConfig(
"%d device - tenant-id mappings defined", mapping_cnt);
4503 static int DetectEngineMultiTenantSetupLoadVlanMappings(
4504 const SCConfNode *mappings_root_node,
bool failure_fatal)
4508 int mapping_cnt = 0;
4509 if (mappings_root_node != NULL) {
4512 if (tenant_id_node == NULL)
4515 if (vlan_id_node == NULL)
4518 uint32_t tenant_id = 0;
4520 tenant_id_node->
val) < 0) {
4523 tenant_id_node->
val);
4527 uint16_t vlan_id = 0;
4529 &vlan_id, 10, (uint16_t)strlen(vlan_id_node->
val), vlan_id_node->
val) < 0) {
4535 if (vlan_id == 0 || vlan_id >= 4095) {
4537 "of %s is invalid. Valid range 1-4094.",
4545 SCLogConfig(
"vlan %u connected to tenant-id %u", vlan_id, tenant_id);
4571 int failure_fatal = 0;
4572 (void)
SCConfGetBool(
"engine.init-failure-fatal", &failure_fatal);
4585 const char *handler = NULL;
4587 SCLogConfig(
"multi-tenant selector type %s", handler);
4589 if (strcmp(handler,
"vlan") == 0) {
4593 if ((
SCConfGetBool(
"vlan.use-for-tracking", &vlanbool)) == 1 && vlanbool == 0) {
4595 "can't use multi-detect selector 'vlan'");
4600 }
else if (strcmp(handler,
"direct") == 0) {
4602 }
else if (strcmp(handler,
"device") == 0) {
4605 SCLogWarning(
"multi-tenant 'device' mode not supported for IPS");
4612 "multi-detect.selector",
4619 SCLogConfig(
"multi-detect is enabled (multi tenancy). Selector: %s", handler);
4625 int mapping_cnt = DetectEngineMultiTenantSetupLoadVlanMappings(mappings_root_node,
4627 if (mapping_cnt == 0) {
4633 SCLogNotice(
"no tenant traffic mappings defined, "
4634 "tenants won't be used until mappings are added");
4636 if (failure_fatal) {
4637 SCLogError(
"no multi-detect mappings defined");
4645 int mapping_cnt = DetectEngineMultiTenantSetupLoadLivedevMappings(mappings_root_node,
4647 if (mapping_cnt == 0) {
4648 if (failure_fatal) {
4649 SCLogError(
"no multi-detect mappings defined");
4661 if (tenants_root_node != NULL) {
4662 const char *path = NULL;
4665 path = path_node->
val;
4671 if (id_node == NULL) {
4675 if (yaml_node == NULL) {
4679 uint32_t tenant_id = 0;
4681 &tenant_id, 10, (uint16_t)strlen(id_node->
val), id_node->
val) < 0) {
4689 char yaml_path[PATH_MAX] =
"";
4691 if (
PathMerge(yaml_path, PATH_MAX, path, yaml_node->
val) < 0)
4694 size_t r =
strlcpy(yaml_path, yaml_node->
val,
sizeof(yaml_path));
4695 if (r >=
sizeof(yaml_path))
4703 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
4705 SCLogError(
"failed to load yaml %s", yaml_path);
4709 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml_path);
4730 SCLogDebug(
"multi-detect not enabled (multi tenancy)");
4737 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *
p)
4741 uint32_t vlan_id = 0;
4761 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *
p)
4766 if (ld == NULL || det_ctx == NULL)
4773 static int DetectEngineTenantRegisterSelector(
4780 SCLogInfo(
"conflicting selector already set");
4787 if (
m->traffic_id == traffic_id) {
4788 SCLogInfo(
"traffic id already registered");
4809 SCLogDebug(
"tenant handler %u %u %u registered", selector, tenant_id, traffic_id);
4814 static int DetectEngineTenantUnregisterSelector(
4838 SCLogInfo(
"tenant handler %u %u %u unregistered", selector, tenant_id, traffic_id);
4852 return DetectEngineTenantRegisterSelector(
4863 return DetectEngineTenantUnregisterSelector(
TENANT_SELECTOR_VLAN, tenant_id, (uint32_t)vlan_id);
4878 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *
p)
4888 if (master->
list == NULL) {
4912 (*de_ctx)->ref_cnt--;
4920 if (instance == NULL)
4923 if (master->
list == NULL) {
4924 master->
list = instance;
4927 master->
list = instance;
4944 r = DetectEngineAddToList(
de_ctx);
4952 if (instance == NULL) {
4957 if (instance ==
de_ctx) {
4961 instance = instance->
next;
4966 if (instance ==
de_ctx) {
4974 if (instance == NULL) {
4980 instance->
next = NULL;
4998 ret = DetectEngineMoveToFreeListNoLock(master,
de_ctx);
5022 SCLogDebug(
"freeing detect engine %p", instance);
5044 DetectEngineMoveToFreeListNoLock(master, instance);
5051 static int reloads = 0;
5066 memset(prefix, 0,
sizeof(prefix));
5071 snprintf(prefix,
sizeof(prefix),
"detect-engine-reloads.%d", reloads++);
5098 if (old_de_ctx == NULL)
5100 SCLogDebug(
"get ref to old_de_ctx %p", old_de_ctx);
5114 if (new_de_ctx == NULL) {
5127 SCLogDebug(
"set up new_de_ctx %p", new_de_ctx);
5140 SCLogDebug(
"going to reload the threads to use new_de_ctx %p", new_de_ctx);
5145 DetectEngineReloadThreads(new_de_ctx);
5148 SCLogDebug(
"threads now run new_de_ctx %p", new_de_ctx);
5157 SCLogDebug(
"old_de_ctx should have been freed");
5163 #ifdef HAVE_MALLOC_TRIM
5174 static uint32_t TenantIdHash(
HashTable *h,
void *data, uint16_t data_len)
5180 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len)
5187 static void TenantIdFree(
void *d)
5189 DetectEngineThreadCtxFree(d);
5205 for ( ; list != NULL; list = list->
next) {
5216 if (stub_de_ctx == NULL) {
5218 if (stub_de_ctx == NULL) {
5223 if (master->
list == NULL) {
5224 master->
list = stub_de_ctx;
5227 master->
list = stub_de_ctx;
5233 DetectEngineReloadThreads(stub_de_ctx);
5243 SCLogDebug(
"old_de_ctx should have been freed");
5247 static int g_parse_metadata = 0;
5251 g_parse_metadata = 1;
5256 g_parse_metadata = 0;
5261 return g_parse_metadata;
5270 return "packet/stream payload";
5276 return "base64_data";
5279 return "post-match";
5287 return "max (internal)";
5306 for (; sm != NULL; sm = sm->
next) {
5312 *sigerror =
"md5-like keyword should not be used together with "
5313 "nocase, since the rule is automatically "
5314 "lowercased anyway which makes nocase redundant.";
5319 *sigerror =
"Invalid length for md5-like keyword (should "
5320 "be 32 characters long). This rule will therefore "
5327 if (!isxdigit(cd->
content[i])) {
5329 "Invalid md5-like string (should be string of hexadecimal characters)."
5330 "This rule will therefore never match.";
5347 for (; sm != NULL; sm = sm->
next) {
5353 bool changed =
false;
5356 if (isupper(cd->
content[u])) {
5375 SCLogError(
"no detection engine available for rate filter callback registration");
5412 static int DetectEngineInitYamlConf(
const char *conf)
5419 static void DetectEngineDeInitYamlConf(
void)
5425 static int DetectEngineTest01(
void)
5431 " - profile: medium\n"
5432 " - custom-values:\n"
5433 " toclient_src_groups: 2\n"
5434 " toclient_dst_groups: 2\n"
5435 " toclient_sp_groups: 2\n"
5436 " toclient_dp_groups: 3\n"
5437 " toserver_src_groups: 2\n"
5438 " toserver_dst_groups: 4\n"
5439 " toserver_sp_groups: 2\n"
5440 " toserver_dp_groups: 25\n"
5441 " - inspection-recursion-limit: 0\n";
5443 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5452 DetectEngineDeInitYamlConf();
5457 static int DetectEngineTest02(
void)
5463 " - profile: medium\n"
5464 " - custom-values:\n"
5465 " toclient_src_groups: 2\n"
5466 " toclient_dst_groups: 2\n"
5467 " toclient_sp_groups: 2\n"
5468 " toclient_dp_groups: 3\n"
5469 " toserver_src_groups: 2\n"
5470 " toserver_dst_groups: 4\n"
5471 " toserver_sp_groups: 2\n"
5472 " toserver_dp_groups: 25\n"
5473 " - inspection-recursion-limit:\n";
5475 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5485 DetectEngineDeInitYamlConf();
5490 static int DetectEngineTest03(
void)
5496 " - profile: medium\n"
5497 " - custom-values:\n"
5498 " toclient_src_groups: 2\n"
5499 " toclient_dst_groups: 2\n"
5500 " toclient_sp_groups: 2\n"
5501 " toclient_dp_groups: 3\n"
5502 " toserver_src_groups: 2\n"
5503 " toserver_dst_groups: 4\n"
5504 " toserver_sp_groups: 2\n"
5505 " toserver_dp_groups: 25\n";
5507 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5517 DetectEngineDeInitYamlConf();
5522 static int DetectEngineTest04(
void)
5528 " - profile: medium\n"
5529 " - custom-values:\n"
5530 " toclient_src_groups: 2\n"
5531 " toclient_dst_groups: 2\n"
5532 " toclient_sp_groups: 2\n"
5533 " toclient_dp_groups: 3\n"
5534 " toserver_src_groups: 2\n"
5535 " toserver_dst_groups: 4\n"
5536 " toserver_sp_groups: 2\n"
5537 " toserver_dp_groups: 25\n"
5538 " - inspection-recursion-limit: 10\n";
5540 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5549 DetectEngineDeInitYamlConf();
5554 static int DetectEngineTest08(
void)
5560 " - profile: custom\n"
5561 " - custom-values:\n"
5562 " toclient-groups: 23\n"
5563 " toserver-groups: 27\n";
5565 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5575 DetectEngineDeInitYamlConf();
5581 static int DetectEngineTest09(
void)
5587 " - profile: custom\n"
5588 " - custom-values:\n"
5589 " toclient-groups: BA\n"
5590 " toserver-groups: BA\n"
5591 " - inspection-recursion-limit: 10\n";
5593 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5603 DetectEngineDeInitYamlConf();
5610 static void *DetectEngineFailingThreadKeywordInit(
void *data)
5616 static void DetectEngineNoopThreadKeywordFree(
void *
ctx)
5624 static int DetectEngineThreadCtxInitKeywordFailTest(
void)
5641 DetectEngineFailingThreadKeywordInit, NULL, DetectEngineNoopThreadKeywordFree, 0);
5666 "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.
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_ *)
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)
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
#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)
Do the content inspection & validation for a signature.
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)
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 *))
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)
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