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);
2165 void *alstate,
void *txv, uint64_t tx_id)
2167 const int list_id = engine->
sm_list;
2168 SCLogDebug(
"running inspect on %d", list_id);
2192 const uint8_t *data = buffer->
inspect;
2197 ci_flags |= buffer->
flags;
2226 void *alstate,
void *txv, uint64_t tx_id)
2228 const int list_id = engine->
sm_list;
2229 SCLogDebug(
"running inspect on %d", list_id);
2243 f,
flags, txv, list_id);
2253 const uint8_t *data = buffer->
inspect;
2258 ci_flags |= buffer->
flags;
2278 AppLayerInspectEngineRegisterInternal(
name, alproto, dir, sub_state, progress,
2281 GetData, alproto, sub_state, progress);
2290 AppLayerInspectEngineRegisterInternal(
name, alproto, dir, 0, (uint8_t)progress,
2301 if (buffer->
inspect == NULL) {
2302 const uint8_t *b = NULL;
2305 if (!GetBuf(txv, flow_flags, &b, &b_len))
2318 if (buffer == NULL) {
2325 const uint8_t *data = NULL;
2326 uint32_t data_len = 0;
2328 if (!GetBuf(det_ctx, txv, flow_flags, index, &data, &data_len)) {
2339 const Signature *s,
Flow *f, uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
2341 uint32_t local_id = 0;
2351 if (buffer == NULL || buffer->
inspect == NULL)
2363 if (local_id == 0) {
2390 const int list_id = engine->
sm_list;
2391 SCLogDebug(
"running inspect on %d", list_id);
2409 ci_flags |= buffer->
flags;
2428 static void InjectPackets(
2436 for (
int i = 0; i < no_of_detect_tvs; i++) {
2437 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) != 1) {
2438 if (detect_tvs[i]->inq != NULL) {
2457 char varname[128] =
"detect.flowbits.max-per-signature";
2459 snprintf(varname,
sizeof(varname),
"%s.detect.flowbits.max-per-signature",
2470 SCLogWarning(
"Invalid setting for flowbits.max-per-signature %d, resetting to the "
2476 "Invalid setting for flowbits.max-per-signature, resetting to the default");
2504 if (no_of_detect_tvs == 0) {
2514 memset(detect_tvs, 0x00, (no_of_detect_tvs *
sizeof(
ThreadVars *)));
2539 if (new_det_ctx[i] == NULL) {
2541 "failure in live rule swap. Let's get out of here");
2545 SCLogDebug(
"live rule swap created new det_ctx - %p and de_ctx "
2546 "- %p\n", new_det_ctx[i], new_de_ctx);
2551 BUG_ON(i != no_of_detect_tvs);
2564 SCLogDebug(
"swapping new det_ctx - %p with older one - %p",
2577 SCLogDebug(
"Live rule swap has swapped %d old det_ctx's with new ones, "
2578 "along with the new de_ctx", no_of_detect_tvs);
2580 InjectPackets(detect_tvs, new_det_ctx, no_of_detect_tvs);
2584 uint32_t threads_done = 0;
2586 for (i = 0; i < no_of_detect_tvs; i++) {
2588 threads_done = no_of_detect_tvs;
2592 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) == 1) {
2593 SCLogDebug(
"new_det_ctx - %p used by detect engine", new_det_ctx[i]);
2596 TmThreadsCaptureBreakLoop(detect_tvs[i]);
2599 if (threads_done < no_of_detect_tvs) {
2610 if (i != no_of_detect_tvs) {
2623 for (i = 0; i < no_of_detect_tvs; i++) {
2624 SCLogDebug(
"Freeing old_det_ctx - %p used by detect",
2634 for (i = 0; i < no_of_detect_tvs; i++) {
2635 if (new_det_ctx[i] != NULL)
2643 int sgh_mpm_caching = 0;
2644 if (
SCConfGetBool(
"detect.sgh-mpm-caching", &sgh_mpm_caching) != 1) {
2647 return (
bool)sgh_mpm_caching;
2656 char yamlpath[] =
"detect.sgh-mpm-caching-path";
2657 const char *strval = NULL;
2658 if (
SCConfGet(yamlpath, &strval) == 1 && strval != NULL) {
2662 static bool notified =
false;
2664 SCLogInfo(
"%s has no path specified, using %s", yamlpath, SGH_CACHE_DIR);
2667 return SGH_CACHE_DIR;
2755 if (prefix != NULL) {
2759 int failure_fatal = 0;
2760 if (
SCConfGetBool(
"engine.init-failure-fatal", (
int *)&failure_fatal) != 1) {
2761 SCLogDebug(
"ConfGetBool could not load the value.");
2769 SCLogDebug(
"Unable to alloc SpmGlobalThreadCtx.");
2781 if (DetectEngineCtxLoadConf(
de_ctx) == -1) {
2790 DetectBufferTypeSetupDetectEngine(
de_ctx);
2838 if (prefix == NULL || strlen(prefix) == 0)
2876 #ifdef PROFILE_RULES
2877 if (
de_ctx->profile_ctx != NULL) {
2878 SCProfilingRuleDestroyCtx(
de_ctx->profile_ctx);
2879 de_ctx->profile_ctx = NULL;
2922 DetectEngineCtxFreeThreadKeywordData(
de_ctx);
2924 DetectEngineCtxFreeFailedSigs(
de_ctx);
2944 DetectBufferTypeFreeDetectEngine(
de_ctx);
2983 const char *max_uniq_toclient_groups_str = NULL;
2984 const char *max_uniq_toserver_groups_str = NULL;
2985 const char *sgh_mpm_context = NULL;
2986 const char *de_ctx_profile = NULL;
2988 (void)
SCConfGet(
"detect.profile", &de_ctx_profile);
2989 (void)
SCConfGet(
"detect.sgh-mpm-context", &sgh_mpm_context);
2994 if (de_ctx_custom != NULL) {
2996 if (de_ctx_profile == NULL) {
2997 if (opt->
val && strcmp(opt->
val,
"profile") == 0) {
2998 de_ctx_profile = opt->head.tqh_first->
val;
3002 if (sgh_mpm_context == NULL) {
3003 if (opt->
val && strcmp(opt->
val,
"sgh-mpm-context") == 0) {
3004 sgh_mpm_context = opt->head.tqh_first->
val;
3010 if (de_ctx_profile != NULL) {
3011 if (strcmp(de_ctx_profile,
"low") == 0 ||
3012 strcmp(de_ctx_profile,
"lowest") == 0) {
3014 }
else if (strcmp(de_ctx_profile,
"medium") == 0) {
3016 }
else if (strcmp(de_ctx_profile,
"high") == 0 ||
3017 strcmp(de_ctx_profile,
"highest") == 0) {
3019 }
else if (strcmp(de_ctx_profile,
"custom") == 0) {
3022 SCLogError(
"invalid value for detect.profile: '%s'. "
3023 "Valid options: low, medium, high and custom.",
3028 SCLogDebug(
"Profile for detection engine groups is \"%s\"", de_ctx_profile);
3030 SCLogDebug(
"Profile for detection engine groups not provided "
3031 "at suricata.yaml. Using default (\"medium\").");
3035 if (sgh_mpm_context == NULL || strcmp(sgh_mpm_context,
"auto") == 0) {
3045 if (strcmp(sgh_mpm_context,
"single") == 0) {
3047 }
else if (strcmp(sgh_mpm_context,
"full") == 0) {
3051 "invalid conf value for detect-engine.sgh-mpm-context-"
3076 (void)
SCConfGet(
"detect.custom-values.toclient-groups", &max_uniq_toclient_groups_str);
3077 (void)
SCConfGet(
"detect.custom-values.toserver-groups", &max_uniq_toserver_groups_str);
3079 if (de_ctx_custom != NULL) {
3081 if (opt->
val && strcmp(opt->
val,
"custom-values") == 0) {
3082 if (max_uniq_toclient_groups_str == NULL) {
3084 opt->head.tqh_first,
"toclient-sp-groups");
3086 if (max_uniq_toclient_groups_str == NULL) {
3088 opt->head.tqh_first,
"toclient-groups");
3090 if (max_uniq_toserver_groups_str == NULL) {
3092 opt->head.tqh_first,
"toserver-dp-groups");
3094 if (max_uniq_toserver_groups_str == NULL) {
3096 opt->head.tqh_first,
"toserver-groups");
3101 if (max_uniq_toclient_groups_str != NULL) {
3103 (uint16_t)strlen(max_uniq_toclient_groups_str),
3104 (
const char *)max_uniq_toclient_groups_str) <= 0) {
3108 "toclient-groups failed, using %u",
3116 if (max_uniq_toserver_groups_str != NULL) {
3118 (uint16_t)strlen(max_uniq_toserver_groups_str),
3119 (
const char *)max_uniq_toserver_groups_str) <= 0) {
3123 "toserver-groups failed, using %u",
3143 if (
SCConfGetInt(
"detect.inspection-recursion-limit", &value) == 1) {
3144 if (value >= 0 && value <= INT_MAX) {
3150 SCConfNode *insp_recursion_limit_node = NULL;
3151 char *insp_recursion_limit = NULL;
3153 if (de_ctx_custom != NULL) {
3156 if (opt->
val && strcmp(opt->
val,
"inspection-recursion-limit") != 0)
3160 if (insp_recursion_limit_node == NULL) {
3162 "entry for detect-engine:inspection-recursion-limit");
3165 insp_recursion_limit = insp_recursion_limit_node->
val;
3166 SCLogDebug(
"Found detect-engine.inspection-recursion-limit - %s:%s",
3167 insp_recursion_limit_node->
name, insp_recursion_limit_node->
val);
3171 if (insp_recursion_limit != NULL) {
3173 0, (
const char *)insp_recursion_limit) < 0) {
3175 "detect-engine.inspection-recursion-limit: %s "
3188 SCLogDebug(
"de_ctx->inspection_recursion_limit: %d",
3193 if (
SCConfGetInt(
"detect.stream-tx-log-limit", &value) == 1) {
3194 if (value >= 0 && value <= UINT8_MAX) {
3197 SCLogWarning(
"Invalid value for detect-engine.stream-tx-log-limit: must be between 0 "
3198 "and 255, will default to 4");
3201 int guess_applayer = 0;
3202 if ((
SCConfGetBool(
"detect.guess-applayer-tx", &guess_applayer)) == 1) {
3203 if (guess_applayer == 1) {
3210 const char *ports = NULL;
3211 (void)
SCConfGet(
"detect.grouping.tcp-priority-ports", &ports);
3213 SCLogConfig(
"grouping: tcp-priority-ports %s", ports);
3215 (void)
SCConfGet(
"detect.grouping.tcp-whitelist", &ports);
3218 "grouping: tcp-priority-ports from legacy 'tcp-whitelist' setting: %s", ports);
3220 ports =
"53, 80, 139, 443, 445, 1433, 3306, 3389, 6666, 6667, 8080";
3221 SCLogConfig(
"grouping: tcp-priority-ports (default) %s", ports);
3226 "for detect.grouping.tcp-priority-ports",
3230 for ( ; x != NULL; x = x->
next) {
3233 "for detect.grouping.tcp-priority-ports: only single ports allowed",
3242 (void)
SCConfGet(
"detect.grouping.udp-priority-ports", &ports);
3244 SCLogConfig(
"grouping: udp-priority-ports %s", ports);
3246 (void)
SCConfGet(
"detect.grouping.udp-whitelist", &ports);
3249 "grouping: udp-priority-ports from legacy 'udp-whitelist' setting: %s", ports);
3251 ports =
"53, 135, 5060";
3252 SCLogConfig(
"grouping: udp-priority-ports (default) %s", ports);
3257 "for detect.grouping.udp-priority-ports",
3263 "for detect.grouping.udp-priority-ports: only single ports allowed",
3271 DetectEngineLoadFlowbitSettings(
de_ctx);
3274 const char *pf_setting = NULL;
3275 if (
SCConfGet(
"detect.prefilter.default", &pf_setting) == 1 && pf_setting) {
3276 if (strcasecmp(pf_setting,
"mpm") == 0) {
3278 }
else if (strcasecmp(pf_setting,
"auto") == 0) {
3287 SCLogConfig(
"prefilter engines: MPM and keywords");
3307 SCLogError(
"setting up thread local detect ctx");
3316 SCLogError(
"setting up thread local detect ctx "
3317 "for keyword \"%s\" failed",
3355 SCLogError(
"setting up thread local detect ctx");
3367 SCLogError(
"setting up thread local detect ctx "
3368 "for keyword \"%s\" failed",
3399 uint32_t map_array_size = 0;
3400 uint32_t map_cnt = 0;
3401 uint32_t max_tenant_id = 0;
3409 "set using multi-detect.selector");
3423 HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree);
3424 if (mt_det_ctxs_hash == NULL) {
3429 SCLogInfo(
"no tenants left, or none registered yet");
3440 map_array_size = map_cnt + 1;
3442 map_array =
SCCalloc(map_array_size,
sizeof(*map_array));
3443 if (map_array == NULL)
3450 if (map_cnt >= map_array_size) {
3462 list = master->
list;
3467 if (mt_det_ctx == NULL)
3469 if (
HashTableAdd(mt_det_ctxs_hash, mt_det_ctx, 0) != 0) {
3478 mt_det_ctxs_hash = NULL;
3490 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromVlanId;
3494 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromLivedev;
3498 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromPcap;
3505 if (map_array != NULL)
3507 if (mt_det_ctxs_hash != NULL)
3535 if (det_ctx->
replace == NULL) {
3585 DetectEngineThreadCtxInitGlobalKeywords(det_ctx);
3586 #ifdef PROFILE_RULES
3587 SCProfilingRuleThreadSetup(
de_ctx->profile_ctx, det_ctx);
3626 if (det_ctx->
de_ctx == NULL) {
3687 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3696 *data = (
void *)det_ctx;
3720 if (det_ctx->
de_ctx == NULL) {
3751 if (mt && DetectEngineMultiTenantEnabledWithLock()) {
3752 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3765 SCLogDebug(
"PACKET PKT_STREAM_ADD: %"PRIu64, det_ctx->pkt_stream_add_cnt);
3767 SCLogDebug(
"PAYLOAD MPM %"PRIu64
"/%"PRIu64, det_ctx->payload_mpm_cnt, det_ctx->payload_mpm_size);
3768 SCLogDebug(
"STREAM MPM %"PRIu64
"/%"PRIu64, det_ctx->stream_mpm_cnt, det_ctx->stream_mpm_size);
3770 SCLogDebug(
"PAYLOAD SIG %"PRIu64
"/%"PRIu64, det_ctx->payload_persig_cnt, det_ctx->payload_persig_size);
3771 SCLogDebug(
"STREAM SIG %"PRIu64
"/%"PRIu64, det_ctx->stream_persig_cnt, det_ctx->stream_persig_size);
3779 #ifdef PROFILE_RULES
3780 SCProfilingRuleThreadCleanup(det_ctx);
3789 if (det_ctx->
de_ctx != NULL) {
3830 for (uint32_t x = 0; x < fb->
size; x++) {
3841 DetectEngineThreadCtxDeinitGlobalKeywords(det_ctx);
3842 if (det_ctx->
de_ctx != NULL) {
3843 DetectEngineThreadCtxDeinitKeywords(det_ctx->
de_ctx, det_ctx);
3867 if (det_ctx == NULL) {
3876 DetectEngineThreadCtxFree(det_ctx);
3881 static uint32_t DetectKeywordCtxHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
3888 return (uint32_t)hash;
3891 static char DetectKeywordCtxCompareFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
3895 const char *name1 = ctx1->
name;
3896 const char *name2 = ctx2->
name;
3897 return (strcmp(name1, name2) == 0 && ctx1->
data == ctx2->
data);
3900 static void DetectKeywordCtxFreeFunc(
void *ptr)
3923 BUG_ON(
de_ctx == NULL || InitFunc == NULL || FreeFunc == NULL);
3927 DetectKeywordCtxHashFunc, DetectKeywordCtxCompareFunc, DetectKeywordCtxFreeFunc);
4012 const char *
name,
void *(*InitFunc)(
void *),
void *data,
void (*FreeFunc)(
void *))
4015 BUG_ON(InitFunc == NULL || FreeFunc == NULL);
4021 while (item != NULL) {
4022 if (strcmp(
name, item->
name) == 0) {
4072 if (master->
list == NULL) {
4131 static bool DetectEngineMultiTenantEnabledWithLock(
void)
4141 bool enabled = DetectEngineMultiTenantEnabledWithLock();
4156 static int DetectEngineMultiTenantLoadTenant(uint32_t tenant_id,
const char *filename,
int loader_id)
4161 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
4164 if (
SCStatFn(filename, &st) != 0) {
4165 SCLogError(
"failed to stat file %s", filename);
4171 SCLogError(
"tenant %u already registered", tenant_id);
4178 SCLogError(
"failed to properly setup yaml %s", filename);
4214 static int DetectEngineMultiTenantReloadTenant(uint32_t tenant_id,
const char *filename,
int reload_cnt)
4217 if (old_de_ctx == NULL) {
4218 SCLogError(
"tenant detect engine not found");
4222 if (filename == NULL)
4226 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u.reload.%d", tenant_id, reload_cnt);
4237 SCLogError(
"failed to properly setup yaml %s", filename);
4242 if (new_de_ctx == NULL) {
4255 goto new_de_ctx_error;
4260 goto new_de_ctx_error;
4285 static void DetectLoaderFreeTenant(
void *
ctx)
4288 if (t->
yaml != NULL) {
4294 static int DetectLoaderFuncLoadTenant(
void *vctx,
int loader_id)
4299 if (DetectEngineMultiTenantLoadTenant(
ctx->tenant_id,
ctx->yaml, loader_id) != 0) {
4305 static int DetectLoaderSetupLoadTenant(uint32_t tenant_id,
const char *yaml)
4313 if (t->
yaml == NULL) {
4321 static int DetectLoaderFuncReloadTenant(
void *vctx,
int loader_id)
4327 if (DetectEngineMultiTenantReloadTenant(
ctx->tenant_id,
ctx->yaml,
ctx->reload_cnt) != 0) {
4333 static int DetectLoaderSetupReloadTenants(
const int reload_cnt)
4352 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4366 static int DetectLoaderSetupReloadTenant(uint32_t tenant_id,
const char *yaml,
int reload_cnt)
4369 if (old_de_ctx == NULL)
4381 if (t->
yaml == NULL) {
4391 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4398 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml);
4412 int r = DetectLoaderSetupReloadTenant(tenant_id, yaml, reload_cnt);
4426 int r = DetectLoaderSetupReloadTenants(reload_cnt);
4436 static int DetectEngineMultiTenantSetupLoadLivedevMappings(
4437 const SCConfNode *mappings_root_node,
bool failure_fatal)
4441 int mapping_cnt = 0;
4442 if (mappings_root_node != NULL) {
4445 if (tenant_id_node == NULL)
4448 if (device_node == NULL)
4451 uint32_t tenant_id = 0;
4453 tenant_id_node->
val) < 0) {
4456 tenant_id_node->
val);
4460 const char *dev = device_node->
val;
4479 SCLogConfig(
"device %s connected to tenant-id %u", dev, tenant_id);
4488 SCLogConfig(
"%d device - tenant-id mappings defined", mapping_cnt);
4495 static int DetectEngineMultiTenantSetupLoadVlanMappings(
4496 const SCConfNode *mappings_root_node,
bool failure_fatal)
4500 int mapping_cnt = 0;
4501 if (mappings_root_node != NULL) {
4504 if (tenant_id_node == NULL)
4507 if (vlan_id_node == NULL)
4510 uint32_t tenant_id = 0;
4512 tenant_id_node->
val) < 0) {
4515 tenant_id_node->
val);
4519 uint16_t vlan_id = 0;
4521 &vlan_id, 10, (uint16_t)strlen(vlan_id_node->
val), vlan_id_node->
val) < 0) {
4527 if (vlan_id == 0 || vlan_id >= 4095) {
4529 "of %s is invalid. Valid range 1-4094.",
4537 SCLogConfig(
"vlan %u connected to tenant-id %u", vlan_id, tenant_id);
4563 int failure_fatal = 0;
4564 (void)
SCConfGetBool(
"engine.init-failure-fatal", &failure_fatal);
4577 const char *handler = NULL;
4579 SCLogConfig(
"multi-tenant selector type %s", handler);
4581 if (strcmp(handler,
"vlan") == 0) {
4585 if ((
SCConfGetBool(
"vlan.use-for-tracking", &vlanbool)) == 1 && vlanbool == 0) {
4587 "can't use multi-detect selector 'vlan'");
4592 }
else if (strcmp(handler,
"direct") == 0) {
4594 }
else if (strcmp(handler,
"device") == 0) {
4597 SCLogWarning(
"multi-tenant 'device' mode not supported for IPS");
4604 "multi-detect.selector",
4611 SCLogConfig(
"multi-detect is enabled (multi tenancy). Selector: %s", handler);
4617 int mapping_cnt = DetectEngineMultiTenantSetupLoadVlanMappings(mappings_root_node,
4619 if (mapping_cnt == 0) {
4625 SCLogNotice(
"no tenant traffic mappings defined, "
4626 "tenants won't be used until mappings are added");
4628 if (failure_fatal) {
4629 SCLogError(
"no multi-detect mappings defined");
4637 int mapping_cnt = DetectEngineMultiTenantSetupLoadLivedevMappings(mappings_root_node,
4639 if (mapping_cnt == 0) {
4640 if (failure_fatal) {
4641 SCLogError(
"no multi-detect mappings defined");
4653 if (tenants_root_node != NULL) {
4654 const char *path = NULL;
4657 path = path_node->
val;
4663 if (id_node == NULL) {
4667 if (yaml_node == NULL) {
4671 uint32_t tenant_id = 0;
4673 &tenant_id, 10, (uint16_t)strlen(id_node->
val), id_node->
val) < 0) {
4681 char yaml_path[PATH_MAX] =
"";
4683 if (
PathMerge(yaml_path, PATH_MAX, path, yaml_node->
val) < 0)
4686 size_t r =
strlcpy(yaml_path, yaml_node->
val,
sizeof(yaml_path));
4687 if (r >=
sizeof(yaml_path))
4695 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
4697 SCLogError(
"failed to load yaml %s", yaml_path);
4701 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml_path);
4722 SCLogDebug(
"multi-detect not enabled (multi tenancy)");
4729 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *
p)
4733 uint32_t vlan_id = 0;
4753 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *
p)
4758 if (ld == NULL || det_ctx == NULL)
4765 static int DetectEngineTenantRegisterSelector(
4772 SCLogInfo(
"conflicting selector already set");
4779 if (
m->traffic_id == traffic_id) {
4780 SCLogInfo(
"traffic id already registered");
4801 SCLogDebug(
"tenant handler %u %u %u registered", selector, tenant_id, traffic_id);
4806 static int DetectEngineTenantUnregisterSelector(
4830 SCLogInfo(
"tenant handler %u %u %u unregistered", selector, tenant_id, traffic_id);
4844 return DetectEngineTenantRegisterSelector(
4855 return DetectEngineTenantUnregisterSelector(
TENANT_SELECTOR_VLAN, tenant_id, (uint32_t)vlan_id);
4870 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *
p)
4880 if (master->
list == NULL) {
4904 (*de_ctx)->ref_cnt--;
4912 if (instance == NULL)
4915 if (master->
list == NULL) {
4916 master->
list = instance;
4919 master->
list = instance;
4936 r = DetectEngineAddToList(
de_ctx);
4944 if (instance == NULL) {
4949 if (instance ==
de_ctx) {
4953 instance = instance->
next;
4958 if (instance ==
de_ctx) {
4966 if (instance == NULL) {
4972 instance->
next = NULL;
4990 ret = DetectEngineMoveToFreeListNoLock(master,
de_ctx);
5014 SCLogDebug(
"freeing detect engine %p", instance);
5036 DetectEngineMoveToFreeListNoLock(master, instance);
5043 static int reloads = 0;
5058 memset(prefix, 0,
sizeof(prefix));
5063 snprintf(prefix,
sizeof(prefix),
"detect-engine-reloads.%d", reloads++);
5090 if (old_de_ctx == NULL)
5092 SCLogDebug(
"get ref to old_de_ctx %p", old_de_ctx);
5106 if (new_de_ctx == NULL) {
5119 SCLogDebug(
"set up new_de_ctx %p", new_de_ctx);
5132 SCLogDebug(
"going to reload the threads to use new_de_ctx %p", new_de_ctx);
5137 DetectEngineReloadThreads(new_de_ctx);
5140 SCLogDebug(
"threads now run new_de_ctx %p", new_de_ctx);
5149 SCLogDebug(
"old_de_ctx should have been freed");
5155 #ifdef HAVE_MALLOC_TRIM
5166 static uint32_t TenantIdHash(
HashTable *h,
void *data, uint16_t data_len)
5172 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len)
5179 static void TenantIdFree(
void *d)
5181 DetectEngineThreadCtxFree(d);
5197 for ( ; list != NULL; list = list->
next) {
5208 if (stub_de_ctx == NULL) {
5210 if (stub_de_ctx == NULL) {
5215 if (master->
list == NULL) {
5216 master->
list = stub_de_ctx;
5219 master->
list = stub_de_ctx;
5225 DetectEngineReloadThreads(stub_de_ctx);
5235 SCLogDebug(
"old_de_ctx should have been freed");
5239 static int g_parse_metadata = 0;
5243 g_parse_metadata = 1;
5248 g_parse_metadata = 0;
5253 return g_parse_metadata;
5262 return "packet/stream payload";
5268 return "base64_data";
5271 return "post-match";
5279 return "max (internal)";
5298 for (; sm != NULL; sm = sm->
next) {
5304 *sigerror =
"md5-like keyword should not be used together with "
5305 "nocase, since the rule is automatically "
5306 "lowercased anyway which makes nocase redundant.";
5311 *sigerror =
"Invalid length for md5-like keyword (should "
5312 "be 32 characters long). This rule will therefore "
5319 if (!isxdigit(cd->
content[i])) {
5321 "Invalid md5-like string (should be string of hexadecimal characters)."
5322 "This rule will therefore never match.";
5339 for (; sm != NULL; sm = sm->
next) {
5345 bool changed =
false;
5348 if (isupper(cd->
content[u])) {
5367 SCLogError(
"no detection engine available for rate filter callback registration");
5404 static int DetectEngineInitYamlConf(
const char *conf)
5411 static void DetectEngineDeInitYamlConf(
void)
5417 static int DetectEngineTest01(
void)
5423 " - profile: medium\n"
5424 " - custom-values:\n"
5425 " toclient_src_groups: 2\n"
5426 " toclient_dst_groups: 2\n"
5427 " toclient_sp_groups: 2\n"
5428 " toclient_dp_groups: 3\n"
5429 " toserver_src_groups: 2\n"
5430 " toserver_dst_groups: 4\n"
5431 " toserver_sp_groups: 2\n"
5432 " toserver_dp_groups: 25\n"
5433 " - inspection-recursion-limit: 0\n";
5435 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5444 DetectEngineDeInitYamlConf();
5449 static int DetectEngineTest02(
void)
5455 " - profile: medium\n"
5456 " - custom-values:\n"
5457 " toclient_src_groups: 2\n"
5458 " toclient_dst_groups: 2\n"
5459 " toclient_sp_groups: 2\n"
5460 " toclient_dp_groups: 3\n"
5461 " toserver_src_groups: 2\n"
5462 " toserver_dst_groups: 4\n"
5463 " toserver_sp_groups: 2\n"
5464 " toserver_dp_groups: 25\n"
5465 " - inspection-recursion-limit:\n";
5467 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5477 DetectEngineDeInitYamlConf();
5482 static int DetectEngineTest03(
void)
5488 " - profile: medium\n"
5489 " - custom-values:\n"
5490 " toclient_src_groups: 2\n"
5491 " toclient_dst_groups: 2\n"
5492 " toclient_sp_groups: 2\n"
5493 " toclient_dp_groups: 3\n"
5494 " toserver_src_groups: 2\n"
5495 " toserver_dst_groups: 4\n"
5496 " toserver_sp_groups: 2\n"
5497 " toserver_dp_groups: 25\n";
5499 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5509 DetectEngineDeInitYamlConf();
5514 static int DetectEngineTest04(
void)
5520 " - profile: medium\n"
5521 " - custom-values:\n"
5522 " toclient_src_groups: 2\n"
5523 " toclient_dst_groups: 2\n"
5524 " toclient_sp_groups: 2\n"
5525 " toclient_dp_groups: 3\n"
5526 " toserver_src_groups: 2\n"
5527 " toserver_dst_groups: 4\n"
5528 " toserver_sp_groups: 2\n"
5529 " toserver_dp_groups: 25\n"
5530 " - inspection-recursion-limit: 10\n";
5532 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5541 DetectEngineDeInitYamlConf();
5546 static int DetectEngineTest08(
void)
5552 " - profile: custom\n"
5553 " - custom-values:\n"
5554 " toclient-groups: 23\n"
5555 " toserver-groups: 27\n";
5557 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5567 DetectEngineDeInitYamlConf();
5573 static int DetectEngineTest09(
void)
5579 " - profile: custom\n"
5580 " - custom-values:\n"
5581 " toclient-groups: BA\n"
5582 " toserver-groups: BA\n"
5583 " - inspection-recursion-limit: 10\n";
5585 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5595 DetectEngineDeInitYamlConf();
5602 static void *DetectEngineFailingThreadKeywordInit(
void *data)
5608 static void DetectEngineNoopThreadKeywordFree(
void *
ctx)
5616 static int DetectEngineThreadCtxInitKeywordFailTest(
void)
5633 DetectEngineFailingThreadKeywordInit, NULL, DetectEngineNoopThreadKeywordFree, 0);
5658 "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