Go to the documentation of this file.
95 #define DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT 3000
102 static uint32_t TenantIdHash(
HashTable *h,
void *
data, uint16_t data_len);
103 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len);
104 static void TenantIdFree(
void *d);
105 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *p);
106 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *p);
107 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *p);
109 static bool DetectEngineMultiTenantEnabledWithLock(
void);
141 return "packet_filter";
175 FatalError(
"failed to register inspect engine %s: %s",
name, strerror(errno));
177 new_engine->
sm_list = (uint16_t)sm_list;
182 if (g_pkt_inspect_engines == NULL) {
183 g_pkt_inspect_engines = new_engine;
186 while (t->
next != NULL) {
190 t->
next = new_engine;
197 static void AppLayerInspectEngineRegisterInternal(
const char *
name,
AppProto alproto, uint32_t dir,
213 (progress < 0 || progress >= SHRT_MAX) || (Callback == NULL)) {
217 SCLogError(
"Invalid arguments: must register "
218 "GetData with DetectEngineInspectBufferGeneric");
221 SCLogError(
"Invalid arguments: must register "
222 "GetData with DetectEngineInspectBufferGeneric");
225 SCLogError(
"Invalid arguments: must register "
226 "GetData with DetectEngineInspectMultiBufferGeneric");
238 AppLayerInspectEngineRegisterInternal(
239 name,
ALPROTO_DOH2, dir, progress, Callback, GetData, GetDataSingle, GetMultiData);
248 new_engine->
dir = direction;
249 new_engine->
sm_list = (uint16_t)sm_list;
251 new_engine->
progress = (int16_t)progress;
261 if (g_app_inspect_engines == NULL) {
262 g_app_inspect_engines = new_engine;
265 while (t->
next != NULL) {
269 t->
next = new_engine;
283 if (t->
sm_list == sm_list && t->
alproto == alproto && t_direction == dir &&
291 AppLayerInspectEngineRegisterInternal(
292 name, alproto, dir, progress, Callback, GetData, NULL, NULL);
305 if (t->
sm_list == sm_list && t->
alproto == alproto && t_direction == dir &&
314 AppLayerInspectEngineRegisterInternal(
315 name, alproto, dir, progress, Callback, NULL, GetData, NULL);
319 static void DetectAppLayerInspectEngineCopy(
321 int sm_list,
int new_list,
334 new_engine->
sm_list = (uint16_t)new_list;
338 new_engine->
v2 = t->
v2;
345 while (list->
next != NULL) {
349 list->
next = new_engine;
371 new_engine->
v2 = t->
v2;
376 list->
next = new_engine;
385 static void DetectPktInspectEngineCopy(
387 int sm_list,
int new_list,
398 new_engine->
sm_list = (uint16_t)new_list;
401 new_engine->
v1 = t->
v1;
408 while (list->
next != NULL) {
412 list->
next = new_engine;
431 new_engine->
v1 = t->
v1;
437 while (list->
next != NULL) {
441 list->
next = new_engine;
473 FatalError(
"failed to register inspect engine %s: %s",
name, strerror(errno));
475 new_engine->
sm_list = (uint16_t)sm_list;
477 new_engine->
dir = direction;
486 while (list->
next != NULL) {
490 list->
next = new_engine;
509 new_engine->
sm_list = (uint16_t)new_list;
515 new_engine->
v1 = t->
v1;
520 while (list->
next != NULL) {
524 list->
next = new_engine;
546 new_engine->
v1 = t->
v1;
552 while (list->
next != NULL) {
556 list->
next = new_engine;
568 static void AppendStreamInspectEngine(
571 bool prepend =
false;
580 new_engine->
mpm =
true;
583 new_engine->
dir = direction;
584 new_engine->
stream =
true;
587 new_engine->
smd = stream;
595 }
else if (prepend) {
602 while (a->
next != NULL) {
606 a->
next = new_engine;
609 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
616 bool prepend =
false;
639 new_engine->
mpm =
true;
645 new_engine->
smd = smd;
646 new_engine->
v1 = u->
v1;
652 }
else if (prepend) {
657 while (a->
next != NULL) {
661 a->
next = new_engine;
669 bool prepend =
false;
679 new_engine->
mpm =
true;
684 new_engine->
smd = smd;
685 new_engine->
v1 = e->
v1;
691 }
else if (prepend) {
696 while (a->
next != NULL) {
700 a->
next = new_engine;
706 const int mpm_list,
const int files_id, uint8_t *last_id,
bool *head_is_mpm)
720 SCLogDebug(
"app engine: t %p t->id %u => alproto:%s files:%s", t, t->
id,
728 bool prepend =
false;
733 new_engine->
mpm =
true;
740 new_engine->
smd = smd;
743 new_engine->
v2 = t->
v2;
749 if (new_engine->
sm_list == files_id) {
751 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
754 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
762 if (new_engine->
sm_list == files_id) {
764 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
766 new_engine->
id = ++(*last_id);
767 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
773 while (a->
next != NULL) {
781 a->
next = new_engine;
782 if (new_engine->
sm_list == files_id) {
784 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
786 new_engine->
id = ++(*last_id);
787 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
792 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
805 bool head_is_mpm =
false;
820 u != NULL; u = u->
next) {
822 AppendFrameInspectEngine(
de_ctx, u, s, smd, mpm_list);
831 AppendPacketInspectEngine(
de_ctx, e, s, smd, mpm_list);
849 AppendAppInspectEngine(
850 de_ctx, t, s, smd, mpm_list, files_id, &last_id, &head_is_mpm);
884 AppendAppInspectEngine(
de_ctx, &t, s, NULL, mpm_list, files_id, &last_id, &head_is_mpm);
894 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
896 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
898 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
899 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
913 iter->
sm_list == mpm_list ?
"MPM" :
"");
964 for (
int i = 0; i < arrays; i++) {
965 if (bufs[i] == ie->
smd) {
971 bufs[arrays++] = ie->
smd;
981 for (
int i = 0; i < arrays; i++) {
982 if (bufs[i] == e->
smd) {
988 bufs[arrays++] = e->
smd;
998 for (
int i = 0; i < arrays; i++) {
999 if (bufs[i] == u->
smd) {
1005 bufs[arrays++] = u->
smd;
1011 for (
int i = 0; i < engines; i++) {
1012 if (bufs[i] == NULL)
1033 static int g_buffer_type_reg_closed = 0;
1037 return g_buffer_type_id;
1053 static uint32_t DetectBufferTypeHashNameFunc(
HashListTable *ht,
void *data, uint16_t datalen)
1077 static uint32_t DetectBufferTypeHashIdFunc(
HashListTable *ht,
void *data, uint16_t datalen)
1080 uint32_t hash = map->
id;
1085 static char DetectBufferTypeCompareNameFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
1090 char r = (strcmp(map1->
name, map2->
name) == 0);
1103 SCLogDebug(
"%s: transform ids match; checking specialized data", map1->
name);
1112 SCLogDebug(
"identity data: only one is null");
1137 static char DetectBufferTypeCompareIdFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
1141 return map1->
id == map2->
id;
1144 static void DetectBufferTypeFreeFunc(
void *data)
1158 SCLogError(
"%s allocates transform option memory but has no free routine",
1168 static int DetectBufferTypeInit(
void)
1170 BUG_ON(g_buffer_type_hash);
1172 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
1173 if (g_buffer_type_hash == NULL)
1179 static void DetectBufferTypeFree(
void)
1181 if (g_buffer_type_hash == NULL)
1185 g_buffer_type_hash = NULL;
1188 static int DetectBufferTypeAdd(
const char *
string)
1190 BUG_ON(
string == NULL || strlen(
string) >= 64);
1197 map->
id = g_buffer_type_id++;
1207 memset(&map, 0,
sizeof(map));
1216 BUG_ON(g_buffer_type_reg_closed);
1217 if (g_buffer_type_hash == NULL)
1218 DetectBufferTypeInit();
1222 return DetectBufferTypeAdd(
name);
1230 BUG_ON(g_buffer_type_reg_closed);
1235 SCLogDebug(
"%p %s -- %d supports multi instance", exists,
name, exists->
id);
1240 BUG_ON(g_buffer_type_reg_closed);
1244 exists->
frame =
true;
1245 SCLogDebug(
"%p %s -- %d supports frame inspection", exists,
name, exists->
id);
1250 BUG_ON(g_buffer_type_reg_closed);
1255 SCLogDebug(
"%p %s -- %d supports packet inspection", exists,
name, exists->
id);
1260 BUG_ON(g_buffer_type_reg_closed);
1270 BUG_ON(g_buffer_type_reg_closed);
1275 SCLogDebug(
"%p %s -- %d supports transformations", exists,
name, exists->
id);
1291 memset(&map, 0,
sizeof(map));
1301 memset(&lookup, 0,
sizeof(lookup));
1311 return res ? res->
name : NULL;
1316 BUG_ON(
string == NULL || strlen(
string) >= 32);
1332 const int direction,
const AppProto alproto,
const uint8_t frame_type)
1339 const int buffer_id = DetectEngineBufferTypeAdd(
de_ctx,
name);
1340 if (buffer_id < 0) {
1369 return DetectEngineBufferTypeAdd(
de_ctx,
name);
1377 BUG_ON(desc == NULL || strlen(desc) >= 128);
1408 exists->
frame =
true;
1409 SCLogDebug(
"%p %s -- %d supports frame inspection", exists,
name, exists->
id);
1417 SCLogDebug(
"%p %s -- %d supports packet inspection", exists,
name, exists->
id);
1433 SCLogDebug(
"%p %s -- %d supports transformations", exists,
name, exists->
id);
1475 BUG_ON(g_buffer_type_reg_closed);
1491 const char *
name,
bool (*ValidateCallback)(
const Signature *,
const char **sigerror,
1494 BUG_ON(g_buffer_type_reg_closed);
1541 const uint8_t *content, uint16_t content_len,
const char **namestr)
1567 const int size = g_buffer_type_id;
1571 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
1574 HashListTableInit(256, DetectBufferTypeHashIdFunc, DetectBufferTypeCompareIdFunc,
1586 memcpy(copy, map,
sizeof(*copy));
1592 SCLogDebug(
"name %s id %d mpm %s packet %s -- %s. "
1593 "Callbacks: Setup %p Validate %p",
1594 map->
name, map->
id, map->
mpm ?
"true" :
"false", map->
packet ?
"true" :
"false",
1601 DetectAppLayerInspectEngineCopyListToDetectCtx(
de_ctx);
1603 DetectFrameInspectEngineCopyListToDetectCtx(
de_ctx);
1605 DetectPktInspectEngineCopyListToDetectCtx(
de_ctx);
1647 while (framemlist) {
1658 BUG_ON(g_buffer_type_hash == NULL);
1660 g_buffer_type_reg_closed = 1;
1671 SCLogError(
"buffer '%s' does not support transformations", base_map->
name);
1678 memset(&t, 0,
sizeof(t));
1679 for (
int i = 0; i < transform_cnt; i++) {
1682 t.
cnt = transform_cnt;
1685 memset(&lookup_map, 0,
sizeof(lookup_map));
1691 DetectBufferAddTransformData(&lookup_map);
1708 map->
mpm = base_map->
mpm;
1715 }
else if (map->
packet) {
1725 SCLogDebug(
"buffer %s registered with id %d, parent %d", map->name, map->id, map->parent_id);
1728 DetectFrameInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1729 }
else if (map->packet) {
1730 DetectPktInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1732 DetectAppLayerInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1738 static int DetectEngineInspectRulePacketMatches(
1742 Packet *p, uint8_t *_alert_flags)
1750 SCLogDebug(
"running match functions, sm %p", smd);
1768 static int DetectEngineInspectRulePayloadMatches(
1790 SCLogDebug(
"no match in stream, fall back to packet payload");
1798 SCLogDebug(
"SIG_FLAG_REQUIRE_STREAM_ONLY, so no match");
1816 uint8_t *alert_flags)
1822 SCLogDebug(
"sid %u: e %p Callback returned no match", s->
id, e);
1825 SCLogDebug(
"sid %u: e %p Callback returned true", s->
id, e);
1844 e->
sm_list = (uint16_t)list_id;
1853 while (a->
next != NULL) {
1865 if (DetectEnginePktInspectionAppend(
1868 SCLogDebug(
"sid %u: DetectEngineInspectRulePayloadMatches appended", s->
id);
1872 if (DetectEnginePktInspectionAppend(
1875 SCLogDebug(
"sid %u: DetectEngineInspectRulePacketMatches appended", s->
id);
1957 uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
1960 SCLogDebug(
"running match functions, sm %p", smd);
1966 AppLayerTxMatch(det_ctx, f,
flags, alstate, txv, s, smd->
ctx);
1999 void *alstate,
void *txv, uint64_t tx_id)
2001 const int list_id = engine->
sm_list;
2002 SCLogDebug(
"running inspect on %d", list_id);
2026 const uint8_t *data = buffer->
inspect;
2031 ci_flags |= buffer->
flags;
2060 void *alstate,
void *txv, uint64_t tx_id)
2062 const int list_id = engine->
sm_list;
2063 SCLogDebug(
"running inspect on %d", list_id);
2077 f,
flags, txv, list_id);
2087 const uint8_t *data = buffer->
inspect;
2092 ci_flags |= buffer->
flags;
2111 AppLayerInspectEngineRegisterInternal(
name, alproto, dir, progress,
2122 if (buffer->
inspect == NULL) {
2123 const uint8_t *b = NULL;
2126 if (!GetBuf(txv, flow_flags, &b, &b_len))
2139 if (buffer == NULL) {
2146 const uint8_t *data = NULL;
2147 uint32_t data_len = 0;
2149 if (!GetBuf(det_ctx, txv, flow_flags, index, &data, &data_len)) {
2160 const Signature *s,
Flow *f, uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
2162 uint32_t local_id = 0;
2172 if (buffer == NULL || buffer->
inspect == NULL)
2184 if (local_id == 0) {
2211 const int list_id = engine->
sm_list;
2212 SCLogDebug(
"running inspect on %d", list_id);
2230 ci_flags |= buffer->
flags;
2257 for (
int i = 0; i < no_of_detect_tvs; i++) {
2258 if (detect_tvs[i]) {
2261 SCLogDebug(
"Injecting pkt for tv %s[i=%d] %d", detect_tvs[i]->
name, i, count++);
2273 SCLogDebug(
"leaving: thread notification count = %d", count);
2281 static void InjectPackets(
2289 for (
int i = 0; i < no_of_detect_tvs; i++) {
2290 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) != 1) {
2291 if (detect_tvs[i]->inq != NULL) {
2328 if (no_of_detect_tvs == 0) {
2338 memset(detect_tvs, 0x00, (no_of_detect_tvs *
sizeof(
ThreadVars *)));
2363 if (new_det_ctx[i] == NULL) {
2365 "failure in live rule swap. Let's get out of here");
2369 SCLogDebug(
"live rule swap created new det_ctx - %p and de_ctx "
2370 "- %p\n", new_det_ctx[i], new_de_ctx);
2375 BUG_ON(i != no_of_detect_tvs);
2388 SCLogDebug(
"swapping new det_ctx - %p with older one - %p",
2399 SCLogDebug(
"Live rule swap has swapped %d old det_ctx's with new ones, "
2400 "along with the new de_ctx", no_of_detect_tvs);
2402 InjectPackets(detect_tvs, new_det_ctx, no_of_detect_tvs);
2406 uint32_t threads_done = 0;
2408 for (i = 0; i < no_of_detect_tvs; i++) {
2410 threads_done = no_of_detect_tvs;
2414 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) == 1) {
2415 SCLogDebug(
"new_det_ctx - %p used by detect engine", new_det_ctx[i]);
2418 TmThreadsCaptureBreakLoop(detect_tvs[i]);
2421 if (threads_done < no_of_detect_tvs) {
2432 if (i != no_of_detect_tvs) {
2445 for (i = 0; i < no_of_detect_tvs; i++) {
2446 SCLogDebug(
"Freeing old_det_ctx - %p used by detect",
2456 for (i = 0; i < no_of_detect_tvs; i++) {
2457 if (new_det_ctx[i] != NULL)
2465 int sgh_mpm_caching = 0;
2466 if (
SCConfGetBool(
"detect.sgh-mpm-caching", &sgh_mpm_caching) != 1) {
2469 return (
bool)sgh_mpm_caching;
2478 char yamlpath[] =
"detect.sgh-mpm-caching-path";
2479 const char *strval = NULL;
2480 if (
SCConfGet(yamlpath, &strval) == 1 && strval != NULL) {
2484 static bool notified =
false;
2486 SCLogInfo(
"%s has no path specified, using %s", yamlpath, SGH_CACHE_DIR);
2489 return SGH_CACHE_DIR;
2512 if (prefix != NULL) {
2516 int failure_fatal = 0;
2517 if (
SCConfGetBool(
"engine.init-failure-fatal", (
int *)&failure_fatal) != 1) {
2518 SCLogDebug(
"ConfGetBool could not load the value.");
2541 SCLogDebug(
"Unable to alloc SpmGlobalThreadCtx.");
2553 if (DetectEngineCtxLoadConf(
de_ctx) == -1) {
2562 DetectBufferTypeSetupDetectEngine(
de_ctx);
2610 if (prefix == NULL || strlen(prefix) == 0)
2648 #ifdef PROFILE_RULES
2649 if (
de_ctx->profile_ctx != NULL) {
2650 SCProfilingRuleDestroyCtx(
de_ctx->profile_ctx);
2651 de_ctx->profile_ctx = NULL;
2694 DetectEngineCtxFreeThreadKeywordData(
de_ctx);
2696 DetectEngineCtxFreeFailedSigs(
de_ctx);
2716 DetectBufferTypeFreeDetectEngine(
de_ctx);
2745 const char *max_uniq_toclient_groups_str = NULL;
2746 const char *max_uniq_toserver_groups_str = NULL;
2747 const char *sgh_mpm_context = NULL;
2748 const char *de_ctx_profile = NULL;
2750 (void)
SCConfGet(
"detect.profile", &de_ctx_profile);
2751 (void)
SCConfGet(
"detect.sgh-mpm-context", &sgh_mpm_context);
2756 if (de_ctx_custom != NULL) {
2758 if (de_ctx_profile == NULL) {
2759 if (opt->
val && strcmp(opt->
val,
"profile") == 0) {
2760 de_ctx_profile = opt->head.tqh_first->
val;
2764 if (sgh_mpm_context == NULL) {
2765 if (opt->
val && strcmp(opt->
val,
"sgh-mpm-context") == 0) {
2766 sgh_mpm_context = opt->head.tqh_first->
val;
2772 if (de_ctx_profile != NULL) {
2773 if (strcmp(de_ctx_profile,
"low") == 0 ||
2774 strcmp(de_ctx_profile,
"lowest") == 0) {
2776 }
else if (strcmp(de_ctx_profile,
"medium") == 0) {
2778 }
else if (strcmp(de_ctx_profile,
"high") == 0 ||
2779 strcmp(de_ctx_profile,
"highest") == 0) {
2781 }
else if (strcmp(de_ctx_profile,
"custom") == 0) {
2784 SCLogError(
"invalid value for detect.profile: '%s'. "
2785 "Valid options: low, medium, high and custom.",
2790 SCLogDebug(
"Profile for detection engine groups is \"%s\"", de_ctx_profile);
2792 SCLogDebug(
"Profile for detection engine groups not provided "
2793 "at suricata.yaml. Using default (\"medium\").");
2797 if (sgh_mpm_context == NULL || strcmp(sgh_mpm_context,
"auto") == 0) {
2807 if (strcmp(sgh_mpm_context,
"single") == 0) {
2809 }
else if (strcmp(sgh_mpm_context,
"full") == 0) {
2813 "invalid conf value for detect-engine.sgh-mpm-context-"
2838 (void)
SCConfGet(
"detect.custom-values.toclient-groups", &max_uniq_toclient_groups_str);
2839 (void)
SCConfGet(
"detect.custom-values.toserver-groups", &max_uniq_toserver_groups_str);
2841 if (de_ctx_custom != NULL) {
2843 if (opt->
val && strcmp(opt->
val,
"custom-values") == 0) {
2844 if (max_uniq_toclient_groups_str == NULL) {
2846 opt->head.tqh_first,
"toclient-sp-groups");
2848 if (max_uniq_toclient_groups_str == NULL) {
2850 opt->head.tqh_first,
"toclient-groups");
2852 if (max_uniq_toserver_groups_str == NULL) {
2854 opt->head.tqh_first,
"toserver-dp-groups");
2856 if (max_uniq_toserver_groups_str == NULL) {
2858 opt->head.tqh_first,
"toserver-groups");
2863 if (max_uniq_toclient_groups_str != NULL) {
2865 (uint16_t)strlen(max_uniq_toclient_groups_str),
2866 (
const char *)max_uniq_toclient_groups_str) <= 0) {
2870 "toclient-groups failed, using %u",
2878 if (max_uniq_toserver_groups_str != NULL) {
2880 (uint16_t)strlen(max_uniq_toserver_groups_str),
2881 (
const char *)max_uniq_toserver_groups_str) <= 0) {
2885 "toserver-groups failed, using %u",
2905 if (
SCConfGetInt(
"detect.inspection-recursion-limit", &value) == 1) {
2906 if (value >= 0 && value <= INT_MAX) {
2912 SCConfNode *insp_recursion_limit_node = NULL;
2913 char *insp_recursion_limit = NULL;
2915 if (de_ctx_custom != NULL) {
2918 if (opt->
val && strcmp(opt->
val,
"inspection-recursion-limit") != 0)
2922 if (insp_recursion_limit_node == NULL) {
2924 "entry for detect-engine:inspection-recursion-limit");
2927 insp_recursion_limit = insp_recursion_limit_node->
val;
2928 SCLogDebug(
"Found detect-engine.inspection-recursion-limit - %s:%s",
2929 insp_recursion_limit_node->
name, insp_recursion_limit_node->
val);
2933 if (insp_recursion_limit != NULL) {
2935 0, (
const char *)insp_recursion_limit) < 0) {
2937 "detect-engine.inspection-recursion-limit: %s "
2950 SCLogDebug(
"de_ctx->inspection_recursion_limit: %d",
2955 if (
SCConfGetInt(
"detect.stream-tx-log-limit", &value) == 1) {
2956 if (value >= 0 && value <= UINT8_MAX) {
2959 SCLogWarning(
"Invalid value for detect-engine.stream-tx-log-limit: must be between 0 "
2960 "and 255, will default to 4");
2963 int guess_applayer = 0;
2964 if ((
SCConfGetBool(
"detect.guess-applayer-tx", &guess_applayer)) == 1) {
2965 if (guess_applayer == 1) {
2972 const char *ports = NULL;
2973 (void)
SCConfGet(
"detect.grouping.tcp-priority-ports", &ports);
2975 SCLogConfig(
"grouping: tcp-priority-ports %s", ports);
2977 (void)
SCConfGet(
"detect.grouping.tcp-whitelist", &ports);
2980 "grouping: tcp-priority-ports from legacy 'tcp-whitelist' setting: %s", ports);
2982 ports =
"53, 80, 139, 443, 445, 1433, 3306, 3389, 6666, 6667, 8080";
2983 SCLogConfig(
"grouping: tcp-priority-ports (default) %s", ports);
2988 "for detect.grouping.tcp-priority-ports",
2992 for ( ; x != NULL; x = x->
next) {
2995 "for detect.grouping.tcp-priority-ports: only single ports allowed",
3004 (void)
SCConfGet(
"detect.grouping.udp-priority-ports", &ports);
3006 SCLogConfig(
"grouping: udp-priority-ports %s", ports);
3008 (void)
SCConfGet(
"detect.grouping.udp-whitelist", &ports);
3011 "grouping: udp-priority-ports from legacy 'udp-whitelist' setting: %s", ports);
3013 ports =
"53, 135, 5060";
3014 SCLogConfig(
"grouping: udp-priority-ports (default) %s", ports);
3019 "for detect.grouping.udp-priority-ports",
3025 "for detect.grouping.udp-priority-ports: only single ports allowed",
3034 const char *pf_setting = NULL;
3035 if (
SCConfGet(
"detect.prefilter.default", &pf_setting) == 1 && pf_setting) {
3036 if (strcasecmp(pf_setting,
"mpm") == 0) {
3038 }
else if (strcasecmp(pf_setting,
"auto") == 0) {
3047 SCLogConfig(
"prefilter engines: MPM and keywords");
3067 SCLogError(
"setting up thread local detect ctx");
3076 SCLogError(
"setting up thread local detect ctx "
3077 "for keyword \"%s\" failed",
3115 SCLogError(
"setting up thread local detect ctx");
3127 SCLogError(
"setting up thread local detect ctx "
3128 "for keyword \"%s\" failed",
3159 uint32_t map_array_size = 0;
3160 uint32_t map_cnt = 0;
3161 uint32_t max_tenant_id = 0;
3166 "set using multi-detect.selector");
3180 HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree);
3181 if (mt_det_ctxs_hash == NULL) {
3186 SCLogInfo(
"no tenants left, or none registered yet");
3197 map_array_size = map_cnt + 1;
3199 map_array =
SCCalloc(map_array_size,
sizeof(*map_array));
3200 if (map_array == NULL)
3207 if (map_cnt >= map_array_size) {
3219 list = master->
list;
3224 if (mt_det_ctx == NULL)
3226 if (
HashTableAdd(mt_det_ctxs_hash, mt_det_ctx, 0) != 0) {
3235 mt_det_ctxs_hash = NULL;
3247 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromVlanId;
3251 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromLivedev;
3255 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromPcap;
3262 if (map_array != NULL)
3264 if (mt_det_ctxs_hash != NULL)
3337 DetectEngineThreadCtxInitKeywords(
de_ctx, det_ctx);
3338 DetectEngineThreadCtxInitGlobalKeywords(det_ctx);
3339 #ifdef PROFILE_RULES
3340 SCProfilingRuleThreadSetup(
de_ctx->profile_ctx, det_ctx);
3377 if (det_ctx->
de_ctx == NULL) {
3431 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3440 *data = (
void *)det_ctx;
3464 if (det_ctx->
de_ctx == NULL) {
3489 if (mt && DetectEngineMultiTenantEnabledWithLock()) {
3490 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3503 SCLogDebug(
"PACKET PKT_STREAM_ADD: %"PRIu64, det_ctx->pkt_stream_add_cnt);
3505 SCLogDebug(
"PAYLOAD MPM %"PRIu64
"/%"PRIu64, det_ctx->payload_mpm_cnt, det_ctx->payload_mpm_size);
3506 SCLogDebug(
"STREAM MPM %"PRIu64
"/%"PRIu64, det_ctx->stream_mpm_cnt, det_ctx->stream_mpm_size);
3508 SCLogDebug(
"PAYLOAD SIG %"PRIu64
"/%"PRIu64, det_ctx->payload_persig_cnt, det_ctx->payload_persig_size);
3509 SCLogDebug(
"STREAM SIG %"PRIu64
"/%"PRIu64, det_ctx->stream_persig_cnt, det_ctx->stream_persig_size);
3517 #ifdef PROFILE_RULES
3518 SCProfilingRuleThreadCleanup(det_ctx);
3527 if (det_ctx->
de_ctx != NULL) {
3566 for (uint32_t x = 0; x < fb->
size; x++) {
3577 DetectEngineThreadCtxDeinitGlobalKeywords(det_ctx);
3578 if (det_ctx->
de_ctx != NULL) {
3579 DetectEngineThreadCtxDeinitKeywords(det_ctx->
de_ctx, det_ctx);
3605 if (det_ctx == NULL) {
3614 DetectEngineThreadCtxFree(det_ctx);
3619 static uint32_t DetectKeywordCtxHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
3626 return (uint32_t)hash;
3629 static char DetectKeywordCtxCompareFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
3633 const char *name1 = ctx1->
name;
3634 const char *name2 = ctx2->
name;
3635 return (strcmp(name1, name2) == 0 && ctx1->
data == ctx2->
data);
3638 static void DetectKeywordCtxFreeFunc(
void *ptr)
3661 BUG_ON(
de_ctx == NULL || InitFunc == NULL || FreeFunc == NULL);
3665 DetectKeywordCtxHashFunc, DetectKeywordCtxCompareFunc, DetectKeywordCtxFreeFunc);
3750 void *(*InitFunc)(
void *),
void *data,
void (*FreeFunc)(
void *))
3753 BUG_ON(InitFunc == NULL || FreeFunc == NULL);
3759 while (item != NULL) {
3760 if (strcmp(
name, item->
name) == 0) {
3810 if (master->
list == NULL) {
3869 static bool DetectEngineMultiTenantEnabledWithLock(
void)
3879 bool enabled = DetectEngineMultiTenantEnabledWithLock();
3894 static int DetectEngineMultiTenantLoadTenant(uint32_t tenant_id,
const char *filename,
int loader_id)
3899 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
3902 if (
SCStatFn(filename, &st) != 0) {
3903 SCLogError(
"failed to stat file %s", filename);
3909 SCLogError(
"tenant %u already registered", tenant_id);
3916 SCLogError(
"failed to properly setup yaml %s", filename);
3953 static int DetectEngineMultiTenantReloadTenant(uint32_t tenant_id,
const char *filename,
int reload_cnt)
3956 if (old_de_ctx == NULL) {
3957 SCLogError(
"tenant detect engine not found");
3961 if (filename == NULL)
3965 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u.reload.%d", tenant_id, reload_cnt);
3976 SCLogError(
"failed to properly setup yaml %s", filename);
3981 if (new_de_ctx == NULL) {
3994 goto new_de_ctx_error;
3999 goto new_de_ctx_error;
4024 static void DetectLoaderFreeTenant(
void *
ctx)
4027 if (t->
yaml != NULL) {
4033 static int DetectLoaderFuncLoadTenant(
void *vctx,
int loader_id)
4038 if (DetectEngineMultiTenantLoadTenant(
ctx->tenant_id,
ctx->yaml, loader_id) != 0) {
4044 static int DetectLoaderSetupLoadTenant(uint32_t tenant_id,
const char *yaml)
4052 if (t->
yaml == NULL) {
4060 static int DetectLoaderFuncReloadTenant(
void *vctx,
int loader_id)
4066 if (DetectEngineMultiTenantReloadTenant(
ctx->tenant_id,
ctx->yaml,
ctx->reload_cnt) != 0) {
4072 static int DetectLoaderSetupReloadTenants(
const int reload_cnt)
4091 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4105 static int DetectLoaderSetupReloadTenant(uint32_t tenant_id,
const char *yaml,
int reload_cnt)
4108 if (old_de_ctx == NULL)
4120 if (t->
yaml == NULL) {
4130 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4137 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml);
4151 int r = DetectLoaderSetupReloadTenant(tenant_id, yaml, reload_cnt);
4165 int r = DetectLoaderSetupReloadTenants(reload_cnt);
4175 static int DetectEngineMultiTenantSetupLoadLivedevMappings(
4176 const SCConfNode *mappings_root_node,
bool failure_fatal)
4180 int mapping_cnt = 0;
4181 if (mappings_root_node != NULL) {
4184 if (tenant_id_node == NULL)
4187 if (device_node == NULL)
4190 uint32_t tenant_id = 0;
4192 tenant_id_node->
val) < 0) {
4195 tenant_id_node->
val);
4199 const char *dev = device_node->
val;
4218 SCLogConfig(
"device %s connected to tenant-id %u", dev, tenant_id);
4227 SCLogConfig(
"%d device - tenant-id mappings defined", mapping_cnt);
4234 static int DetectEngineMultiTenantSetupLoadVlanMappings(
4235 const SCConfNode *mappings_root_node,
bool failure_fatal)
4239 int mapping_cnt = 0;
4240 if (mappings_root_node != NULL) {
4243 if (tenant_id_node == NULL)
4246 if (vlan_id_node == NULL)
4249 uint32_t tenant_id = 0;
4251 tenant_id_node->
val) < 0) {
4254 tenant_id_node->
val);
4258 uint16_t vlan_id = 0;
4260 &vlan_id, 10, (uint16_t)strlen(vlan_id_node->
val), vlan_id_node->
val) < 0) {
4266 if (vlan_id == 0 || vlan_id >= 4095) {
4268 "of %s is invalid. Valid range 1-4094.",
4276 SCLogConfig(
"vlan %u connected to tenant-id %u", vlan_id, tenant_id);
4302 int failure_fatal = 0;
4303 (void)
SCConfGetBool(
"engine.init-failure-fatal", &failure_fatal);
4316 const char *handler = NULL;
4317 if (
SCConfGet(
"multi-detect.selector", &handler) == 1) {
4318 SCLogConfig(
"multi-tenant selector type %s", handler);
4320 if (strcmp(handler,
"vlan") == 0) {
4324 if ((
SCConfGetBool(
"vlan.use-for-tracking", &vlanbool)) == 1 && vlanbool == 0) {
4326 "can't use multi-detect selector 'vlan'");
4331 }
else if (strcmp(handler,
"direct") == 0) {
4333 }
else if (strcmp(handler,
"device") == 0) {
4336 SCLogWarning(
"multi-tenant 'device' mode not supported for IPS");
4343 "multi-detect.selector",
4350 SCLogConfig(
"multi-detect is enabled (multi tenancy). Selector: %s", handler);
4356 int mapping_cnt = DetectEngineMultiTenantSetupLoadVlanMappings(mappings_root_node,
4358 if (mapping_cnt == 0) {
4364 SCLogNotice(
"no tenant traffic mappings defined, "
4365 "tenants won't be used until mappings are added");
4367 if (failure_fatal) {
4368 SCLogError(
"no multi-detect mappings defined");
4376 int mapping_cnt = DetectEngineMultiTenantSetupLoadLivedevMappings(mappings_root_node,
4378 if (mapping_cnt == 0) {
4379 if (failure_fatal) {
4380 SCLogError(
"no multi-detect mappings defined");
4392 if (tenants_root_node != NULL) {
4393 const char *path = NULL;
4396 path = path_node->
val;
4402 if (id_node == NULL) {
4406 if (yaml_node == NULL) {
4410 uint32_t tenant_id = 0;
4412 &tenant_id, 10, (uint16_t)strlen(id_node->
val), id_node->
val) < 0) {
4420 char yaml_path[PATH_MAX] =
"";
4424 strlcpy(yaml_path, yaml_node->
val,
sizeof(yaml_path));
4431 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
4433 SCLogError(
"failed to load yaml %s", yaml_path);
4437 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml_path);
4458 SCLogDebug(
"multi-detect not enabled (multi tenancy)");
4465 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *p)
4469 uint32_t vlan_id = 0;
4489 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *p)
4494 if (ld == NULL || det_ctx == NULL)
4501 static int DetectEngineTenantRegisterSelector(
4508 SCLogInfo(
"conflicting selector already set");
4515 if (
m->traffic_id == traffic_id) {
4516 SCLogInfo(
"traffic id already registered");
4537 SCLogDebug(
"tenant handler %u %u %u registered", selector, tenant_id, traffic_id);
4542 static int DetectEngineTenantUnregisterSelector(
4566 SCLogInfo(
"tenant handler %u %u %u unregistered", selector, tenant_id, traffic_id);
4580 return DetectEngineTenantRegisterSelector(
4591 return DetectEngineTenantUnregisterSelector(
TENANT_SELECTOR_VLAN, tenant_id, (uint32_t)vlan_id);
4606 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *p)
4616 if (master->
list == NULL) {
4640 (*de_ctx)->ref_cnt--;
4648 if (instance == NULL)
4651 if (master->
list == NULL) {
4652 master->
list = instance;
4655 master->
list = instance;
4672 r = DetectEngineAddToList(
de_ctx);
4680 if (instance == NULL) {
4685 if (instance ==
de_ctx) {
4689 instance = instance->
next;
4694 if (instance ==
de_ctx) {
4702 if (instance == NULL) {
4708 instance->
next = NULL;
4726 ret = DetectEngineMoveToFreeListNoLock(master,
de_ctx);
4750 SCLogDebug(
"freeing detect engine %p", instance);
4772 DetectEngineMoveToFreeListNoLock(master, instance);
4779 static int reloads = 0;
4794 memset(prefix, 0,
sizeof(prefix));
4799 snprintf(prefix,
sizeof(prefix),
"detect-engine-reloads.%d", reloads++);
4826 if (old_de_ctx == NULL)
4828 SCLogDebug(
"get ref to old_de_ctx %p", old_de_ctx);
4842 if (new_de_ctx == NULL) {
4854 SCLogDebug(
"set up new_de_ctx %p", new_de_ctx);
4867 SCLogDebug(
"going to reload the threads to use new_de_ctx %p", new_de_ctx);
4869 DetectEngineReloadThreads(new_de_ctx);
4870 SCLogDebug(
"threads now run new_de_ctx %p", new_de_ctx);
4879 SCLogDebug(
"old_de_ctx should have been freed");
4883 #ifdef HAVE_MALLOC_TRIM
4894 static uint32_t TenantIdHash(
HashTable *h,
void *data, uint16_t data_len)
4900 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len)
4907 static void TenantIdFree(
void *d)
4909 DetectEngineThreadCtxFree(d);
4925 for ( ; list != NULL; list = list->
next) {
4936 if (stub_de_ctx == NULL) {
4938 if (stub_de_ctx == NULL) {
4943 if (master->
list == NULL) {
4944 master->
list = stub_de_ctx;
4947 master->
list = stub_de_ctx;
4953 DetectEngineReloadThreads(stub_de_ctx);
4963 SCLogDebug(
"old_de_ctx should have been freed");
4967 static int g_parse_metadata = 0;
4971 g_parse_metadata = 1;
4976 g_parse_metadata = 0;
4981 return g_parse_metadata;
4990 return "packet/stream payload";
4996 return "base64_data";
4999 return "post-match";
5007 return "max (internal)";
5026 for (; sm != NULL; sm = sm->
next) {
5032 *sigerror =
"md5-like keyword should not be used together with "
5033 "nocase, since the rule is automatically "
5034 "lowercased anyway which makes nocase redundant.";
5039 *sigerror =
"Invalid length for md5-like keyword (should "
5040 "be 32 characters long). This rule will therefore "
5047 if (!isxdigit(cd->
content[i])) {
5049 "Invalid md5-like string (should be string of hexadecimal characters)."
5050 "This rule will therefore never match.";
5096 static int DetectEngineInitYamlConf(
const char *conf)
5103 static void DetectEngineDeInitYamlConf(
void)
5109 static int DetectEngineTest01(
void)
5115 " - profile: medium\n"
5116 " - custom-values:\n"
5117 " toclient_src_groups: 2\n"
5118 " toclient_dst_groups: 2\n"
5119 " toclient_sp_groups: 2\n"
5120 " toclient_dp_groups: 3\n"
5121 " toserver_src_groups: 2\n"
5122 " toserver_dst_groups: 4\n"
5123 " toserver_sp_groups: 2\n"
5124 " toserver_dp_groups: 25\n"
5125 " - inspection-recursion-limit: 0\n";
5127 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5136 DetectEngineDeInitYamlConf();
5141 static int DetectEngineTest02(
void)
5147 " - profile: medium\n"
5148 " - custom-values:\n"
5149 " toclient_src_groups: 2\n"
5150 " toclient_dst_groups: 2\n"
5151 " toclient_sp_groups: 2\n"
5152 " toclient_dp_groups: 3\n"
5153 " toserver_src_groups: 2\n"
5154 " toserver_dst_groups: 4\n"
5155 " toserver_sp_groups: 2\n"
5156 " toserver_dp_groups: 25\n"
5157 " - inspection-recursion-limit:\n";
5159 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5169 DetectEngineDeInitYamlConf();
5174 static int DetectEngineTest03(
void)
5180 " - profile: medium\n"
5181 " - custom-values:\n"
5182 " toclient_src_groups: 2\n"
5183 " toclient_dst_groups: 2\n"
5184 " toclient_sp_groups: 2\n"
5185 " toclient_dp_groups: 3\n"
5186 " toserver_src_groups: 2\n"
5187 " toserver_dst_groups: 4\n"
5188 " toserver_sp_groups: 2\n"
5189 " toserver_dp_groups: 25\n";
5191 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5201 DetectEngineDeInitYamlConf();
5206 static int DetectEngineTest04(
void)
5212 " - profile: medium\n"
5213 " - custom-values:\n"
5214 " toclient_src_groups: 2\n"
5215 " toclient_dst_groups: 2\n"
5216 " toclient_sp_groups: 2\n"
5217 " toclient_dp_groups: 3\n"
5218 " toserver_src_groups: 2\n"
5219 " toserver_dst_groups: 4\n"
5220 " toserver_sp_groups: 2\n"
5221 " toserver_dp_groups: 25\n"
5222 " - inspection-recursion-limit: 10\n";
5224 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5233 DetectEngineDeInitYamlConf();
5238 static int DetectEngineTest08(
void)
5244 " - profile: custom\n"
5245 " - custom-values:\n"
5246 " toclient-groups: 23\n"
5247 " toserver-groups: 27\n";
5249 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5259 DetectEngineDeInitYamlConf();
5265 static int DetectEngineTest09(
void)
5271 " - profile: custom\n"
5272 " - custom-values:\n"
5273 " toclient-groups: BA\n"
5274 " toserver-groups: BA\n"
5275 " - inspection-recursion-limit: 10\n";
5277 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5287 DetectEngineDeInitYamlConf();
#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)
void DetectAppLayerMpmMultiRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionMultiBufferGetDataPtr GetData, AppProto alproto, int tx_min_progress)
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)
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)
void AlertQueueFree(DetectEngineThreadCtx *det_ctx)
void SCProfilingSghThreadSetup(SCProfileSghDetectCtx *ctx, DetectEngineThreadCtx *det_ctx)
int DetectParseDupSigHashInit(DetectEngineCtx *de_ctx)
Initializes the hash table that is used to cull duplicate sigs.
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
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
@ ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE
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)
#define PKT_PSEUDO_LOG_FLUSH
void MpmFactoryDeRegisterAllMpmCtxProfiles(DetectEngineCtx *de_ctx)
@ DETECT_TABLE_APP_FILTER
uint16_t counter_match_list
DetectEngineTenantMapping * tenant_mapping_list
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
struct DetectEngineAppInspectionEngine_ * next
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 DetectAppLayerInspectEngineRegisterSingle(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionSingleBufferGetDataPtr GetData)
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define SIG_FLAG_INIT_NEED_FLUSH
void SCClassSCConfInit(DetectEngineCtx *de_ctx)
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,...
InspectEngineFuncPtr Callback
int PathMerge(char *out_buf, size_t buf_size, const char *const dir, const char *const fname)
@ DETECT_TABLE_PACKET_PRE_STREAM
void PacketEnqueue(PacketQueue *q, Packet *p)
DetectFileDataCfg * filedata_config
struct HtpBodyChunk_ * next
void DetectBufferTypeSupportsFrames(const char *name)
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
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t flags)
get the progress value for a tx/protocol
AppLayerDecoderEvents * decoder_events
void *(* InitFunc)(void *)
InspectionBufferGetDataPtr GetData
DetectBufferMpmRegistry * pkt_mpms_list
void TmThreadContinueDetectLoaderThreads(void)
Unpauses all threads present in tv_root.
@ DETECT_SM_LIST_THRESHOLD
void DetectBufferTypeRegisterSetupCallback(const char *name, void(*SetupCallback)(const DetectEngineCtx *, Signature *))
int SCConfYamlHandleInclude(SCConfNode *parent, const char *filename)
Include a file in the configuration.
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its 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 *))
struct DetectEngineFrameInspectionEngine::@94 v1
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
uint16_t lua_blocked_function_errors
void ** global_keyword_ctxs_array
DetectEngineCtx * DetectEngineGetCurrent(void)
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.
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)
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 SCSigSignatureOrderingModuleCleanup(DetectEngineCtx *de_ctx)
De-registers all the signature ordering functions registered.
const char * DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
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
void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
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::
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.
struct DetectEngineThreadCtx_::@110 multi_inspect
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)
uint32_t DetectEngineGetVersion(void)
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
void SigCleanSignatures(DetectEngineCtx *de_ctx)
@ ENGINE_SGH_MPM_FACTORY_CONTEXT_FULL
void * HashListTableLookup(HashListTable *ht, void *data, uint16_t datalen)
uint16_t lua_instruction_limit_errors
#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)
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
#define KEYWORD_PROFILING_START
struct DetectEnginePktInspectionEngine::@93 v1
HashTable * non_pf_engine_names
int PrefilterMultiGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
DetectEngineFrameInspectionEngine * frame_inspect
void DetectBufferTypeCloseRegistration(void)
const DetectEngineTransforms * transforms
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
void HashTableFree(HashTable *ht)
Free a HashTable and all its contents.
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 counter_alerts_suppressed
uint16_t base64_decode_max_len
@ SIGNATURE_HOOK_TYPE_APP
#define PKT_SET_SRC(p, src_val)
void SCConfInit(void)
Initialize the configuration system.
void SCConfDump(void)
Dump configuration to stdout.
@ TENANT_SELECTOR_UNKNOWN
#define HashListTableGetListNext(hb)
@ 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.
bool(* TransformValidate)(const uint8_t *content, uint16_t content_len, void *context)
uint16_t counter_alerts_overflow
bool(* ValidateCallback)(const struct Signature_ *, const char **sigerror, const struct DetectBufferType_ *)
int DetectEngineMoveToFreeList(DetectEngineCtx *de_ctx)
#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 DetectLoadersInit(void)
struct TmSlot_ * tm_slots
const char * DetectEngineBufferTypeGetDescriptionById(const DetectEngineCtx *de_ctx, const int id)
#define SCMutexUnlock(mut)
@ DETECT_SM_LIST_BASE64_DATA
#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)
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
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)
void PatternMatchThreadPrepare(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher)
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
union SignatureHook_::@95 t
uint32_t hashlittle_safe(const void *key, size_t length, uint32_t initval)
int SigGroupCleanup(DetectEngineCtx *de_ctx)
uint16_t lua_memory_limit_errors
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
void SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc fn, void *arg)
Register a callback when a rate_filter has been applied to an alert.
int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml)
Load a tenant and wait for loading to complete.
void TmModuleDetectLoaderRegister(void)
TransformIdData xform_id[DETECT_TRANSFORMS_MAX]
DetectEngineCtx * DetectEngineCtxInit(void)
void RuleMatchCandidateTxArrayFree(DetectEngineThreadCtx *det_ctx)
void DetectEngineInitializeFastPatternList(DetectEngineCtx *de_ctx)
#define DE_STATE_FLAG_BASE
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)
DetectBufferMpmRegistry * frame_mpms_list
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
struct TenantLoaderCtx_ TenantLoaderCtx
uint16_t max_uniq_toserver_groups
const DetectBufferType * DetectEngineBufferTypeGetById(const DetectEngineCtx *de_ctx, const int id)
struct LiveDevice_ * livedev
InspectionBufferPktInspectFunc Callback
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)
bool DetectEngineBufferTypeSupportsMpmGetById(const DetectEngineCtx *de_ctx, const int id)
const char * DetectSigmatchListEnumToString(enum DetectSigmatchListEnum type)
#define SCRealloc(ptr, sz)
void SRepReloadComplete(void)
Increment effective reputation version after a rule/reputation reload is complete.
#define SIG_FLAG_INIT_STATE_MATCH
struct PacketQueue_ * stream_pq
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)
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
struct DetectEngineAppInspectionEngine_::@90 v2
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.
int MpmStoreInit(DetectEngineCtx *de_ctx)
Initializes the MpmStore mpm hash table to be used by the detection engine context.
DetectBufferMpmRegistry * app_mpms_list
@ SIG_PROP_FLOW_ACTION_FLOW_IF_STATEFUL
DetectEngineCtx * DetectEngineCtxInitStubForMT(void)
void DetectBufferTypeSupportsMpm(const char *name)
void HashListTableFree(HashListTable *ht)
HashListTable * buffer_type_hash_name
struct DetectEngineCtx_ * next
@ DETECT_ENGINE_TYPE_DD_STUB
void DetectEngineBumpVersion(void)
void AppLayerDecoderEventsSetEventRaw(AppLayerDecoderEvents **sevents, uint8_t event)
Set an app layer decoder event.
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...
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.
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
const char * DetectBufferTypeGetDescriptionByName(const char *name)
struct DetectEngineThreadCtx_::@109 inspect
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.
int DetectAddressMapInit(DetectEngineCtx *de_ctx)
void InjectPacketsForFlush(ThreadVars **detect_tvs, int no_of_detect_tvs)
SignatureInitDataBuffer * buffers
DetectEngineAppInspectionEngine * app_inspect_engines
int filemagic_thread_ctx_id
int global_keyword_ctxs_size
SigJsonContent * json_content
void PrefilterInit(DetectEngineCtx *de_ctx)
void * DetectThreadCtxGetGlobalKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
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
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
void InspectionBufferSetupAndApplyTransforms(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
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)
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.
@ DETECT_ENGINE_TYPE_MT_STUB
void ThresholdCacheThreadFree(void)
uint16_t vlan_id[VLAN_MAX_LAYERS]
struct SignatureHook_::@95::@96 app
int DetectEngineReload(const SCInstance *suri)
Reload the detection engine.
bool DetectEngineBufferRunValidateCallback(const DetectEngineCtx *de_ctx, const int id, const Signature *s, const char **sigerror)
void(* SetupCallback)(const struct DetectEngineCtx_ *, struct Signature_ *)
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
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)
void SRepDestroy(DetectEngineCtx *de_ctx)
MpmConfig *(* ConfigInit)(void)
uint16_t StatsRegisterAvgCounter(const char *name, struct ThreadVars_ *tv)
Registers a counter, whose value holds the average of all the values assigned to it.
@ 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 DetectAppLayerMultiRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectionMultiBufferGetDataPtr GetData, int priority)
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.
#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
@ TENANT_SELECTOR_LIVEDEV
AppProto alproto
application level protocol
uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
Registers a normal, unqualified counter.
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)
void DetectPortCleanupList(const DetectEngineCtx *de_ctx, DetectPort *head)
Free a DetectPort list and each of its members.
void(* TransformId)(const uint8_t **data, uint32_t *length, void *context)
@ DETECT_SM_LIST_SUPPRESS
InspectionBuffer * inspection_buffers
#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
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)
uint16_t counter_mpm_list
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)
int DetectRegisterThreadCtxGlobalFuncs(const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *))
Register Thread keyword context Funcs (Global)
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)
int DetectEngineBufferTypeGetByIdTransforms(DetectEngineCtx *de_ctx, const int id, TransformData *transforms, int transform_cnt)
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