Go to the documentation of this file.
94 #define DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT 3000
101 static uint32_t TenantIdHash(
HashTable *h,
void *
data, uint16_t data_len);
102 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len);
103 static void TenantIdFree(
void *d);
104 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *p);
105 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *p);
106 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *p);
137 FatalError(
"failed to register inspect engine %s", name);
149 FatalError(
"failed to register inspect engine %s: %s", name, strerror(errno));
151 new_engine->
sm_list = (uint16_t)sm_list;
156 if (g_pkt_inspect_engines == NULL) {
157 g_pkt_inspect_engines = new_engine;
160 while (t->
next != NULL) {
164 t->
next = new_engine;
171 static void AppLayerInspectEngineRegisterInternal(
const char *name,
AppProto alproto, uint32_t dir,
180 FatalError(
"failed to register inspect engine %s", name);
186 (progress < 0 || progress >= SHRT_MAX) || (Callback == NULL)) {
190 SCLogError(
"Invalid arguments: must register "
191 "GetData with DetectEngineInspectBufferGeneric");
194 SCLogError(
"Invalid arguments: must register "
195 "GetData with DetectEngineInspectMultiBufferGeneric");
207 AppLayerInspectEngineRegisterInternal(
208 name,
ALPROTO_DOH2, dir, progress, Callback, GetData, GetMultiData);
217 new_engine->
dir = direction;
218 new_engine->
sm_list = (uint16_t)sm_list;
220 new_engine->
progress = (int16_t)progress;
228 if (g_app_inspect_engines == NULL) {
229 g_app_inspect_engines = new_engine;
232 while (t->
next != NULL) {
236 t->
next = new_engine;
243 AppLayerInspectEngineRegisterInternal(name, alproto, dir, progress, Callback, GetData, NULL);
247 static void DetectAppLayerInspectEngineCopy(
249 int sm_list,
int new_list,
262 new_engine->
sm_list = (uint16_t)new_list;
266 new_engine->
v2 = t->
v2;
273 while (list->
next != NULL) {
277 list->
next = new_engine;
299 new_engine->
v2 = t->
v2;
304 list->
next = new_engine;
313 static void DetectPktInspectEngineCopy(
315 int sm_list,
int new_list,
326 new_engine->
sm_list = (uint16_t)new_list;
329 new_engine->
v1 = t->
v1;
336 while (list->
next != NULL) {
340 list->
next = new_engine;
359 new_engine->
v1 = t->
v1;
365 while (list->
next != NULL) {
369 list->
next = new_engine;
384 FatalError(
"failed to register inspect engine %s", name);
401 FatalError(
"failed to register inspect engine %s: %s", name, strerror(errno));
403 new_engine->
sm_list = (uint16_t)sm_list;
405 new_engine->
dir = direction;
414 while (list->
next != NULL) {
418 list->
next = new_engine;
437 new_engine->
sm_list = (uint16_t)new_list;
443 new_engine->
v1 = t->
v1;
448 while (list->
next != NULL) {
452 list->
next = new_engine;
474 new_engine->
v1 = t->
v1;
480 while (list->
next != NULL) {
484 list->
next = new_engine;
496 static void AppendStreamInspectEngine(
499 bool prepend =
false;
508 new_engine->
mpm =
true;
511 new_engine->
dir = direction;
512 new_engine->
stream =
true;
515 new_engine->
smd = stream;
523 }
else if (prepend) {
530 while (a->
next != NULL) {
534 a->
next = new_engine;
537 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
544 bool prepend =
false;
567 new_engine->
mpm =
true;
573 new_engine->
smd = smd;
574 new_engine->
v1 = u->
v1;
580 }
else if (prepend) {
585 while (a->
next != NULL) {
589 a->
next = new_engine;
597 bool prepend =
false;
607 new_engine->
mpm =
true;
612 new_engine->
smd = smd;
613 new_engine->
v1 = e->
v1;
619 }
else if (prepend) {
624 while (a->
next != NULL) {
628 a->
next = new_engine;
634 const int mpm_list,
const int files_id, uint8_t *last_id,
bool *head_is_mpm)
648 SCLogDebug(
"app engine: t %p t->id %u => alproto:%s files:%s", t, t->
id,
656 bool prepend =
false;
661 new_engine->
mpm =
true;
668 new_engine->
smd = smd;
670 new_engine->
v2 = t->
v2;
676 if (new_engine->
sm_list == files_id) {
678 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
681 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
689 if (new_engine->
sm_list == files_id) {
691 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
693 new_engine->
id = ++(*last_id);
694 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
700 while (a->
next != NULL) {
708 a->
next = new_engine;
709 if (new_engine->
sm_list == files_id) {
711 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
713 new_engine->
id = ++(*last_id);
714 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
719 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
732 bool head_is_mpm =
false;
746 u != NULL; u = u->
next) {
748 AppendFrameInspectEngine(
de_ctx, u, s, smd, mpm_list);
757 AppendPacketInspectEngine(
de_ctx, e, s, smd, mpm_list);
766 AppendAppInspectEngine(
767 de_ctx, t, s, smd, mpm_list, files_id, &last_id, &head_is_mpm);
780 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
782 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
784 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
785 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
799 iter->
sm_list == mpm_list ?
"MPM" :
"");
850 for (
int i = 0; i < arrays; i++) {
851 if (bufs[i] == ie->
smd) {
857 bufs[arrays++] = ie->
smd;
867 for (
int i = 0; i < arrays; i++) {
868 if (bufs[i] == e->
smd) {
874 bufs[arrays++] = e->
smd;
884 for (
int i = 0; i < arrays; i++) {
885 if (bufs[i] == u->
smd) {
891 bufs[arrays++] = u->
smd;
897 for (
int i = 0; i < engines; i++) {
919 static int g_buffer_type_reg_closed = 0;
923 return g_buffer_type_id;
926 static uint32_t DetectBufferTypeHashNameFunc(
HashListTable *ht,
void *data, uint16_t datalen)
935 static uint32_t DetectBufferTypeHashIdFunc(
HashListTable *ht,
void *data, uint16_t datalen)
938 uint32_t hash = map->
id;
943 static char DetectBufferTypeCompareNameFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
948 char r = (strcmp(map1->
name, map2->
name) == 0);
953 static char DetectBufferTypeCompareIdFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
957 return map1->
id == map2->
id;
960 static void DetectBufferTypeFreeFunc(
void *data)
973 SCLogError(
"%s allocates transform option memory but has no free routine",
983 static int DetectBufferTypeInit(
void)
985 BUG_ON(g_buffer_type_hash);
987 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
988 if (g_buffer_type_hash == NULL)
994 static void DetectBufferTypeFree(
void)
996 if (g_buffer_type_hash == NULL)
1000 g_buffer_type_hash = NULL;
1003 static int DetectBufferTypeAdd(
const char *
string)
1005 BUG_ON(
string == NULL || strlen(
string) >= 32);
1012 map->
id = g_buffer_type_id++;
1022 memset(&map, 0,
sizeof(map));
1031 BUG_ON(g_buffer_type_reg_closed);
1032 if (g_buffer_type_hash == NULL)
1033 DetectBufferTypeInit();
1037 return DetectBufferTypeAdd(name);
1045 BUG_ON(g_buffer_type_reg_closed);
1050 SCLogDebug(
"%p %s -- %d supports multi instance", exists, name, exists->
id);
1055 BUG_ON(g_buffer_type_reg_closed);
1059 exists->
frame =
true;
1060 SCLogDebug(
"%p %s -- %d supports frame inspection", exists, name, exists->
id);
1065 BUG_ON(g_buffer_type_reg_closed);
1070 SCLogDebug(
"%p %s -- %d supports packet inspection", exists, name, exists->
id);
1075 BUG_ON(g_buffer_type_reg_closed);
1080 SCLogDebug(
"%p %s -- %d supports mpm", exists, name, exists->
id);
1085 BUG_ON(g_buffer_type_reg_closed);
1090 SCLogDebug(
"%p %s -- %d supports transformations", exists, name, exists->
id);
1106 memset(&map, 0,
sizeof(map));
1116 memset(&lookup, 0,
sizeof(lookup));
1126 return res ? res->
name : NULL;
1131 BUG_ON(
string == NULL || strlen(
string) >= 32);
1147 const int direction,
const AppProto alproto,
const uint8_t frame_type)
1154 const int buffer_id = DetectEngineBufferTypeAdd(
de_ctx, name);
1155 if (buffer_id < 0) {
1184 return DetectEngineBufferTypeAdd(
de_ctx, name);
1192 BUG_ON(desc == NULL || strlen(desc) >= 128);
1223 exists->
frame =
true;
1224 SCLogDebug(
"%p %s -- %d supports frame inspection", exists, name, exists->
id);
1232 SCLogDebug(
"%p %s -- %d supports packet inspection", exists, name, exists->
id);
1240 SCLogDebug(
"%p %s -- %d supports mpm", exists, name, exists->
id);
1248 SCLogDebug(
"%p %s -- %d supports transformations", exists, name, exists->
id);
1290 BUG_ON(g_buffer_type_reg_closed);
1306 bool (*ValidateCallback)(
const Signature *,
const char **sigerror))
1308 BUG_ON(g_buffer_type_reg_closed);
1361 SCLogError(
"Rule buffer cannot be reset after base64_data.");
1366 SCLogError(
"no matches following transform(s)");
1374 SCLogError(
"previous sticky buffer has no matches");
1384 if ((uint32_t)list == b->
id) {
1385 SCLogDebug(
"found buffer %p for list %d", b, list);
1388 SCLogDebug(
"sm_init was true for %p list %d", b, list);
1407 SCLogError(
"failed to expand rule buffer array");
1431 SCLogError(
"previous transforms not consumed "
1432 "(list: %u, transform_cnt %u)",
1437 SCLogDebug(
"buffer %d has transform(s) registered: %d",
1441 if (new_list == -1) {
1453 SCLogError(
"failed to expand rule buffer array");
1466 SCLogDebug(
"new list after applying transforms: %u", new_list);
1489 for (uint32_t x = 0; x <= mbuffer->
max; x++) {
1509 if (!buffer->
init) {
1530 if (local_id >= fb->
size) {
1531 uint32_t old_size = fb->
size;
1532 uint32_t new_size = local_id + 1;
1533 uint32_t grow_by = new_size - old_size;
1534 SCLogDebug(
"size is %u, need %u, so growing by %u", old_size, new_size, grow_by);
1542 SCLogDebug(
"ptr %p to_zero %p", ptr, to_zero);
1545 fb->
size = new_size;
1551 #ifdef DEBUG_VALIDATION
1552 buffer->multi =
true;
1559 memset(buffer, 0,
sizeof(*buffer));
1560 buffer->
buf =
SCCalloc(initial_size,
sizeof(uint8_t));
1561 if (buffer->
buf != NULL) {
1562 buffer->
size = initial_size;
1569 #ifdef DEBUG_VALIDATION
1581 const uint8_t *data,
const uint32_t data_len)
1583 #ifdef DEBUG_VALIDATION
1598 #ifdef DEBUG_VALIDATION
1602 if (buffer->
inspect == NULL) {
1604 if (det_ctx && list_id != -1)
1616 if (buffer->
buf != NULL) {
1619 memset(buffer, 0,
sizeof(*buffer));
1631 uint32_t new_size = (buffer->
size == 0) ? 4096 : buffer->
size;
1632 while (new_size < min_size) {
1639 buffer->
size = new_size;
1660 uint32_t copy_size =
MIN(buf_len, buffer->
size);
1661 memcpy(buffer->
buf, buf, copy_size);
1687 const uint8_t *content, uint16_t content_len,
const char **namestr)
1728 const int size = g_buffer_type_id;
1732 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
1735 HashListTableInit(256, DetectBufferTypeHashIdFunc, DetectBufferTypeCompareIdFunc,
1747 memcpy(copy, map,
sizeof(*copy));
1753 SCLogDebug(
"name %s id %d mpm %s packet %s -- %s. "
1754 "Callbacks: Setup %p Validate %p",
1755 map->
name, map->
id, map->
mpm ?
"true" :
"false", map->
packet ?
"true" :
"false",
1762 DetectAppLayerInspectEngineCopyListToDetectCtx(
de_ctx);
1764 DetectFrameInspectEngineCopyListToDetectCtx(
de_ctx);
1766 DetectPktInspectEngineCopyListToDetectCtx(
de_ctx);
1808 while (framemlist) {
1819 BUG_ON(g_buffer_type_hash == NULL);
1821 g_buffer_type_reg_closed = 1;
1832 SCLogError(
"buffer '%s' does not support transformations", base_map->
name);
1839 memset(&t, 0,
sizeof(t));
1840 for (
int i = 0; i < transform_cnt; i++) {
1843 t.
cnt = transform_cnt;
1846 memset(&lookup_map, 0,
sizeof(lookup_map));
1864 map->
mpm = base_map->
mpm;
1871 }
else if (map->
packet) {
1881 SCLogDebug(
"buffer %s registered with id %d, parent %d", map->name, map->id, map->parent_id);
1884 DetectFrameInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1885 }
else if (map->packet) {
1886 DetectPktInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1888 DetectAppLayerInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1894 static int DetectEngineInspectRulePacketMatches(
1898 Packet *p, uint8_t *_alert_flags)
1906 SCLogDebug(
"running match functions, sm %p", smd);
1924 static int DetectEngineInspectRulePayloadMatches(
1946 SCLogDebug(
"no match in stream, fall back to packet payload");
1954 SCLogDebug(
"SIG_FLAG_REQUIRE_STREAM_ONLY, so no match");
1972 uint8_t *alert_flags)
1978 SCLogDebug(
"sid %u: e %p Callback returned no match", s->
id, e);
1981 SCLogDebug(
"sid %u: e %p Callback returned true", s->
id, e);
2000 e->
sm_list = (uint16_t)list_id;
2009 while (a->
next != NULL) {
2021 if (DetectEnginePktInspectionAppend(
2024 SCLogDebug(
"sid %u: DetectEngineInspectRulePayloadMatches appended", s->
id);
2028 if (DetectEnginePktInspectionAppend(
2031 SCLogDebug(
"sid %u: DetectEngineInspectRulePacketMatches appended", s->
id);
2113 uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
2116 SCLogDebug(
"running match functions, sm %p", smd);
2122 AppLayerTxMatch(det_ctx, f,
flags, alstate, txv, s, smd->
ctx);
2156 void *alstate,
void *txv, uint64_t tx_id)
2158 const int list_id = engine->
sm_list;
2159 SCLogDebug(
"running inspect on %d", list_id);
2173 f,
flags, txv, list_id);
2180 const uint8_t *data = buffer->
inspect;
2185 ci_flags |= buffer->
flags;
2204 AppLayerInspectEngineRegisterInternal(
2207 alproto, tx_min_progress);
2212 const Signature *s,
Flow *f, uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
2214 uint32_t local_id = 0;
2222 det_ctx, transforms, f,
flags, txv, engine->
sm_list, local_id);
2224 if (buffer == NULL || buffer->
inspect == NULL)
2255 const int list_id = engine->
sm_list;
2256 SCLogDebug(
"running inspect on %d", list_id);
2274 ci_flags |= buffer->
flags;
2292 static void InjectPackets(
ThreadVars **detect_tvs,
2294 int no_of_detect_tvs)
2298 for (
int i = 0; i < no_of_detect_tvs; i++) {
2299 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) != 1) {
2300 if (detect_tvs[i]->inq != NULL) {
2337 if (no_of_detect_tvs == 0) {
2347 memset(detect_tvs, 0x00, (no_of_detect_tvs *
sizeof(
ThreadVars *)));
2372 if (new_det_ctx[i] == NULL) {
2374 "failure in live rule swap. Let's get out of here");
2378 SCLogDebug(
"live rule swap created new det_ctx - %p and de_ctx "
2379 "- %p\n", new_det_ctx[i], new_de_ctx);
2384 BUG_ON(i != no_of_detect_tvs);
2397 SCLogDebug(
"swapping new det_ctx - %p with older one - %p",
2408 SCLogDebug(
"Live rule swap has swapped %d old det_ctx's with new ones, "
2409 "along with the new de_ctx", no_of_detect_tvs);
2411 InjectPackets(detect_tvs, new_det_ctx, no_of_detect_tvs);
2415 uint32_t threads_done = 0;
2417 for (i = 0; i < no_of_detect_tvs; i++) {
2419 threads_done = no_of_detect_tvs;
2423 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) == 1) {
2424 SCLogDebug(
"new_det_ctx - %p used by detect engine", new_det_ctx[i]);
2427 TmThreadsCaptureBreakLoop(detect_tvs[i]);
2430 if (threads_done < no_of_detect_tvs) {
2441 if (i != no_of_detect_tvs) {
2454 for (i = 0; i < no_of_detect_tvs; i++) {
2455 SCLogDebug(
"Freeing old_det_ctx - %p used by detect",
2465 for (i = 0; i < no_of_detect_tvs; i++) {
2466 if (new_det_ctx[i] != NULL)
2492 if (prefix != NULL) {
2496 int failure_fatal = 0;
2497 if (
ConfGetBool(
"engine.init-failure-fatal", (
int *)&failure_fatal) != 1) {
2498 SCLogDebug(
"ConfGetBool could not load the value.");
2510 SCLogDebug(
"Unable to alloc SpmGlobalThreadCtx.");
2522 if (DetectEngineCtxLoadConf(
de_ctx) == -1) {
2531 DetectBufferTypeSetupDetectEngine(
de_ctx);
2579 if (prefix == NULL || strlen(prefix) == 0)
2617 #ifdef PROFILE_RULES
2618 if (
de_ctx->profile_ctx != NULL) {
2619 SCProfilingRuleDestroyCtx(
de_ctx->profile_ctx);
2620 de_ctx->profile_ctx = NULL;
2660 DetectEngineCtxFreeThreadKeywordData(
de_ctx);
2662 DetectEngineCtxFreeFailedSigs(
de_ctx);
2682 DetectBufferTypeFreeDetectEngine(
de_ctx);
2708 const char *max_uniq_toclient_groups_str = NULL;
2709 const char *max_uniq_toserver_groups_str = NULL;
2710 const char *sgh_mpm_context = NULL;
2711 const char *de_ctx_profile = NULL;
2713 (void)
ConfGet(
"detect.profile", &de_ctx_profile);
2714 (void)
ConfGet(
"detect.sgh-mpm-context", &sgh_mpm_context);
2719 if (de_ctx_custom != NULL) {
2721 if (de_ctx_profile == NULL) {
2722 if (opt->
val && strcmp(opt->
val,
"profile") == 0) {
2723 de_ctx_profile = opt->head.tqh_first->
val;
2727 if (sgh_mpm_context == NULL) {
2728 if (opt->
val && strcmp(opt->
val,
"sgh-mpm-context") == 0) {
2729 sgh_mpm_context = opt->head.tqh_first->
val;
2735 if (de_ctx_profile != NULL) {
2736 if (strcmp(de_ctx_profile,
"low") == 0 ||
2737 strcmp(de_ctx_profile,
"lowest") == 0) {
2739 }
else if (strcmp(de_ctx_profile,
"medium") == 0) {
2741 }
else if (strcmp(de_ctx_profile,
"high") == 0 ||
2742 strcmp(de_ctx_profile,
"highest") == 0) {
2744 }
else if (strcmp(de_ctx_profile,
"custom") == 0) {
2747 SCLogError(
"invalid value for detect.profile: '%s'. "
2748 "Valid options: low, medium, high and custom.",
2753 SCLogDebug(
"Profile for detection engine groups is \"%s\"", de_ctx_profile);
2755 SCLogDebug(
"Profile for detection engine groups not provided "
2756 "at suricata.yaml. Using default (\"medium\").");
2760 if (sgh_mpm_context == NULL || strcmp(sgh_mpm_context,
"auto") == 0) {
2770 if (strcmp(sgh_mpm_context,
"single") == 0) {
2772 }
else if (strcmp(sgh_mpm_context,
"full") == 0) {
2776 "invalid conf value for detect-engine.sgh-mpm-context-"
2801 (void)
ConfGet(
"detect.custom-values.toclient-groups",
2802 &max_uniq_toclient_groups_str);
2803 (void)
ConfGet(
"detect.custom-values.toserver-groups",
2804 &max_uniq_toserver_groups_str);
2806 if (de_ctx_custom != NULL) {
2808 if (opt->
val && strcmp(opt->
val,
"custom-values") == 0) {
2809 if (max_uniq_toclient_groups_str == NULL) {
2811 (opt->head.tqh_first,
"toclient-sp-groups");
2813 if (max_uniq_toclient_groups_str == NULL) {
2815 (opt->head.tqh_first,
"toclient-groups");
2817 if (max_uniq_toserver_groups_str == NULL) {
2819 (opt->head.tqh_first,
"toserver-dp-groups");
2821 if (max_uniq_toserver_groups_str == NULL) {
2823 (opt->head.tqh_first,
"toserver-groups");
2828 if (max_uniq_toclient_groups_str != NULL) {
2830 (uint16_t)strlen(max_uniq_toclient_groups_str),
2831 (
const char *)max_uniq_toclient_groups_str) <= 0) {
2835 "toclient-groups failed, using %u",
2843 if (max_uniq_toserver_groups_str != NULL) {
2845 (uint16_t)strlen(max_uniq_toserver_groups_str),
2846 (
const char *)max_uniq_toserver_groups_str) <= 0) {
2850 "toserver-groups failed, using %u",
2869 if (
ConfGetInt(
"detect.inspection-recursion-limit", &value) == 1)
2871 if (value >= 0 && value <= INT_MAX) {
2877 ConfNode *insp_recursion_limit_node = NULL;
2878 char *insp_recursion_limit = NULL;
2880 if (de_ctx_custom != NULL) {
2883 if (opt->
val && strcmp(opt->
val,
"inspection-recursion-limit") != 0)
2887 if (insp_recursion_limit_node == NULL) {
2889 "entry for detect-engine:inspection-recursion-limit");
2892 insp_recursion_limit = insp_recursion_limit_node->
val;
2893 SCLogDebug(
"Found detect-engine.inspection-recursion-limit - %s:%s",
2894 insp_recursion_limit_node->
name, insp_recursion_limit_node->
val);
2898 if (insp_recursion_limit != NULL) {
2900 0, (
const char *)insp_recursion_limit) < 0) {
2902 "detect-engine.inspection-recursion-limit: %s "
2918 SCLogDebug(
"de_ctx->inspection_recursion_limit: %d",
2923 if (
ConfGetInt(
"detect.stream-tx-log-limit", &value) == 1) {
2924 if (value >= 0 && value <= UINT8_MAX) {
2927 SCLogWarning(
"Invalid value for detect-engine.stream-tx-log-limit: must be between 0 "
2928 "and 255, will default to 4");
2934 const char *ports = NULL;
2935 (void)
ConfGet(
"detect.grouping.tcp-priority-ports", &ports);
2937 SCLogConfig(
"grouping: tcp-priority-ports %s", ports);
2939 (void)
ConfGet(
"detect.grouping.tcp-whitelist", &ports);
2942 "grouping: tcp-priority-ports from legacy 'tcp-whitelist' setting: %s", ports);
2944 ports =
"53, 80, 139, 443, 445, 1433, 3306, 3389, 6666, 6667, 8080";
2945 SCLogConfig(
"grouping: tcp-priority-ports (default) %s", ports);
2950 "for detect.grouping.tcp-priority-ports",
2954 for ( ; x != NULL; x = x->
next) {
2957 "for detect.grouping.tcp-priority-ports: only single ports allowed",
2966 (void)
ConfGet(
"detect.grouping.udp-priority-ports", &ports);
2968 SCLogConfig(
"grouping: udp-priority-ports %s", ports);
2970 (void)
ConfGet(
"detect.grouping.udp-whitelist", &ports);
2973 "grouping: udp-priority-ports from legacy 'udp-whitelist' setting: %s", ports);
2975 ports =
"53, 135, 5060";
2976 SCLogConfig(
"grouping: udp-priority-ports (default) %s", ports);
2981 "for detect.grouping.udp-priority-ports",
2987 "for detect.grouping.udp-priority-ports: only single ports allowed",
2996 const char *pf_setting = NULL;
2997 if (
ConfGet(
"detect.prefilter.default", &pf_setting) == 1 && pf_setting) {
2998 if (strcasecmp(pf_setting,
"mpm") == 0) {
3000 }
else if (strcasecmp(pf_setting,
"auto") == 0) {
3009 SCLogConfig(
"prefilter engines: MPM and keywords");
3038 SCLogError(
"setting up thread local detect ctx");
3047 SCLogError(
"setting up thread local detect ctx "
3048 "for keyword \"%s\" failed",
3086 SCLogError(
"setting up thread local detect ctx");
3098 SCLogError(
"setting up thread local detect ctx "
3099 "for keyword \"%s\" failed",
3129 uint32_t map_array_size = 0;
3130 uint32_t map_cnt = 0;
3131 uint32_t max_tenant_id = 0;
3137 "set using multi-detect.selector");
3150 mt_det_ctxs_hash =
HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree);
3151 if (mt_det_ctxs_hash == NULL) {
3156 SCLogInfo(
"no tenants left, or none registered yet");
3167 map_array_size = map_cnt + 1;
3169 map_array =
SCCalloc(map_array_size,
sizeof(*map_array));
3170 if (map_array == NULL)
3177 if (map_cnt >= map_array_size) {
3189 list = master->
list;
3194 if (mt_det_ctx == NULL)
3196 if (
HashTableAdd(mt_det_ctxs_hash, mt_det_ctx, 0) != 0) {
3205 mt_det_ctxs_hash = NULL;
3217 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromVlanId;
3221 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromLivedev;
3225 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromPcap;
3232 if (map_array != NULL)
3234 if (mt_det_ctxs_hash != NULL)
3315 DetectEngineThreadCtxInitKeywords(
de_ctx, det_ctx);
3316 DetectEngineThreadCtxInitGlobalKeywords(det_ctx);
3317 #ifdef PROFILE_RULES
3318 SCProfilingRuleThreadSetup(
de_ctx->profile_ctx, det_ctx);
3355 if (det_ctx->
de_ctx == NULL) {
3405 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3412 *data = (
void *)det_ctx;
3436 if (det_ctx->
de_ctx == NULL) {
3468 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3481 SCLogDebug(
"PACKET PKT_STREAM_ADD: %"PRIu64, det_ctx->pkt_stream_add_cnt);
3483 SCLogDebug(
"PAYLOAD MPM %"PRIu64
"/%"PRIu64, det_ctx->payload_mpm_cnt, det_ctx->payload_mpm_size);
3484 SCLogDebug(
"STREAM MPM %"PRIu64
"/%"PRIu64, det_ctx->stream_mpm_cnt, det_ctx->stream_mpm_size);
3486 SCLogDebug(
"PAYLOAD SIG %"PRIu64
"/%"PRIu64, det_ctx->payload_persig_cnt, det_ctx->payload_persig_size);
3487 SCLogDebug(
"STREAM SIG %"PRIu64
"/%"PRIu64, det_ctx->stream_persig_cnt, det_ctx->stream_persig_size);
3495 #ifdef PROFILE_RULES
3496 SCProfilingRuleThreadCleanup(det_ctx);
3505 if (det_ctx->
de_ctx != NULL) {
3545 for (uint32_t x = 0; x < fb->
size; x++) {
3556 DetectEngineThreadCtxDeinitGlobalKeywords(det_ctx);
3557 if (det_ctx->
de_ctx != NULL) {
3558 DetectEngineThreadCtxDeinitKeywords(det_ctx->
de_ctx, det_ctx);
3578 if (det_ctx == NULL) {
3587 DetectEngineThreadCtxFree(det_ctx);
3592 static uint32_t DetectKeywordCtxHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
3595 const char *name =
ctx->name;
3596 uint64_t hash =
StringHashDjb2((
const uint8_t *)name, strlen(name)) + (ptrdiff_t)
ctx->data;
3601 static char DetectKeywordCtxCompareFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
3605 const char *name1 = ctx1->
name;
3606 const char *name2 = ctx2->
name;
3607 return (strcmp(name1, name2) == 0 && ctx1->
data == ctx2->
data);
3610 static void DetectKeywordCtxFreeFunc(
void *ptr)
3633 BUG_ON(
de_ctx == NULL || InitFunc == NULL || FreeFunc == NULL);
3637 DetectKeywordCtxHashFunc, DetectKeywordCtxCompareFunc, DetectKeywordCtxFreeFunc);
3722 void *(*InitFunc)(
void *),
void *data,
void (*FreeFunc)(
void *))
3725 BUG_ON(InitFunc == NULL || FreeFunc == NULL);
3731 while (item != NULL) {
3732 if (strcmp(name, item->
name) == 0) {
3782 if (master->
list == NULL) {
3858 static int DetectEngineMultiTenantLoadTenant(uint32_t tenant_id,
const char *filename,
int loader_id)
3863 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
3866 if (
SCStatFn(filename, &st) != 0) {
3867 SCLogError(
"failed to stat file %s", filename);
3873 SCLogError(
"tenant %u already registered", tenant_id);
3880 SCLogError(
"failed to properly setup yaml %s", filename);
3917 static int DetectEngineMultiTenantReloadTenant(uint32_t tenant_id,
const char *filename,
int reload_cnt)
3920 if (old_de_ctx == NULL) {
3921 SCLogError(
"tenant detect engine not found");
3925 if (filename == NULL)
3929 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u.reload.%d", tenant_id, reload_cnt);
3940 SCLogError(
"failed to properly setup yaml %s", filename);
3945 if (new_de_ctx == NULL) {
3958 goto new_de_ctx_error;
3963 goto new_de_ctx_error;
3988 static void DetectLoaderFreeTenant(
void *
ctx)
3991 if (t->
yaml != NULL) {
3997 static int DetectLoaderFuncLoadTenant(
void *vctx,
int loader_id)
4002 if (DetectEngineMultiTenantLoadTenant(
ctx->tenant_id,
ctx->yaml, loader_id) != 0) {
4008 static int DetectLoaderSetupLoadTenant(uint32_t tenant_id,
const char *yaml)
4016 if (t->
yaml == NULL) {
4024 static int DetectLoaderFuncReloadTenant(
void *vctx,
int loader_id)
4030 if (DetectEngineMultiTenantReloadTenant(
ctx->tenant_id,
ctx->yaml,
ctx->reload_cnt) != 0) {
4036 static int DetectLoaderSetupReloadTenants(
const int reload_cnt)
4055 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4069 static int DetectLoaderSetupReloadTenant(uint32_t tenant_id,
const char *yaml,
int reload_cnt)
4072 if (old_de_ctx == NULL)
4084 if (t->
yaml == NULL) {
4094 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4101 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml);
4115 int r = DetectLoaderSetupReloadTenant(tenant_id, yaml, reload_cnt);
4129 int r = DetectLoaderSetupReloadTenants(reload_cnt);
4139 static int DetectEngineMultiTenantSetupLoadLivedevMappings(
const ConfNode *mappings_root_node,
4144 int mapping_cnt = 0;
4145 if (mappings_root_node != NULL) {
4148 if (tenant_id_node == NULL)
4151 if (device_node == NULL)
4154 uint32_t tenant_id = 0;
4156 tenant_id_node->
val) < 0) {
4159 tenant_id_node->
val);
4163 const char *dev = device_node->
val;
4182 SCLogConfig(
"device %s connected to tenant-id %u", dev, tenant_id);
4191 SCLogConfig(
"%d device - tenant-id mappings defined", mapping_cnt);
4198 static int DetectEngineMultiTenantSetupLoadVlanMappings(
const ConfNode *mappings_root_node,
4203 int mapping_cnt = 0;
4204 if (mappings_root_node != NULL) {
4207 if (tenant_id_node == NULL)
4210 if (vlan_id_node == NULL)
4213 uint32_t tenant_id = 0;
4215 tenant_id_node->
val) < 0) {
4218 tenant_id_node->
val);
4222 uint16_t vlan_id = 0;
4224 &vlan_id, 10, (uint16_t)strlen(vlan_id_node->
val), vlan_id_node->
val) < 0) {
4230 if (vlan_id == 0 || vlan_id >= 4095) {
4232 "of %s is invalid. Valid range 1-4094.",
4240 SCLogConfig(
"vlan %u connected to tenant-id %u", vlan_id, tenant_id);
4266 int failure_fatal = 0;
4267 (void)
ConfGetBool(
"engine.init-failure-fatal", &failure_fatal);
4270 (void)
ConfGetBool(
"multi-detect.enabled", &enabled);
4280 const char *handler = NULL;
4281 if (
ConfGet(
"multi-detect.selector", &handler) == 1) {
4282 SCLogConfig(
"multi-tenant selector type %s", handler);
4284 if (strcmp(handler,
"vlan") == 0) {
4288 if ((
ConfGetBool(
"vlan.use-for-tracking", &vlanbool)) == 1 && vlanbool == 0) {
4290 "can't use multi-detect selector 'vlan'");
4295 }
else if (strcmp(handler,
"direct") == 0) {
4297 }
else if (strcmp(handler,
"device") == 0) {
4300 SCLogWarning(
"multi-tenant 'device' mode not supported for IPS");
4307 "multi-detect.selector",
4314 SCLogConfig(
"multi-detect is enabled (multi tenancy). Selector: %s", handler);
4320 int mapping_cnt = DetectEngineMultiTenantSetupLoadVlanMappings(mappings_root_node,
4322 if (mapping_cnt == 0) {
4328 SCLogNotice(
"no tenant traffic mappings defined, "
4329 "tenants won't be used until mappings are added");
4331 if (failure_fatal) {
4332 SCLogError(
"no multi-detect mappings defined");
4340 int mapping_cnt = DetectEngineMultiTenantSetupLoadLivedevMappings(mappings_root_node,
4342 if (mapping_cnt == 0) {
4343 if (failure_fatal) {
4344 SCLogError(
"no multi-detect mappings defined");
4356 if (tenants_root_node != NULL) {
4357 const char *path = NULL;
4360 path = path_node->
val;
4366 if (id_node == NULL) {
4370 if (yaml_node == NULL) {
4374 uint32_t tenant_id = 0;
4376 &tenant_id, 10, (uint16_t)strlen(id_node->
val), id_node->
val) < 0) {
4384 char yaml_path[PATH_MAX] =
"";
4388 strlcpy(yaml_path, yaml_node->
val,
sizeof(yaml_path));
4395 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
4397 SCLogError(
"failed to load yaml %s", yaml_path);
4401 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml_path);
4422 SCLogDebug(
"multi-detect not enabled (multi tenancy)");
4429 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *p)
4433 uint32_t vlan_id = 0;
4453 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *p)
4458 if (ld == NULL || det_ctx == NULL)
4465 static int DetectEngineTenantRegisterSelector(
4472 SCLogInfo(
"conflicting selector already set");
4479 if (
m->traffic_id == traffic_id) {
4480 SCLogInfo(
"traffic id already registered");
4501 SCLogDebug(
"tenant handler %u %u %u registered", selector, tenant_id, traffic_id);
4506 static int DetectEngineTenantUnregisterSelector(
4530 SCLogInfo(
"tenant handler %u %u %u unregistered", selector, tenant_id, traffic_id);
4544 return DetectEngineTenantRegisterSelector(
4555 return DetectEngineTenantUnregisterSelector(
TENANT_SELECTOR_VLAN, tenant_id, (uint32_t)vlan_id);
4570 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *p)
4580 if (master->
list == NULL) {
4603 BUG_ON((*de_ctx)->ref_cnt == 0);
4604 (*de_ctx)->ref_cnt--;
4612 if (instance == NULL)
4615 if (master->
list == NULL) {
4616 master->
list = instance;
4619 master->
list = instance;
4636 r = DetectEngineAddToList(
de_ctx);
4644 if (instance == NULL) {
4649 if (instance ==
de_ctx) {
4653 instance = instance->
next;
4658 if (instance ==
de_ctx) {
4666 if (instance == NULL) {
4672 instance->
next = NULL;
4690 ret = DetectEngineMoveToFreeListNoLock(master,
de_ctx);
4714 SCLogDebug(
"freeing detect engine %p", instance);
4736 DetectEngineMoveToFreeListNoLock(master, instance);
4743 static int reloads = 0;
4758 memset(prefix, 0,
sizeof(prefix));
4763 snprintf(prefix,
sizeof(prefix),
"detect-engine-reloads.%d", reloads++);
4790 if (old_de_ctx == NULL)
4792 SCLogDebug(
"get ref to old_de_ctx %p", old_de_ctx);
4806 if (new_de_ctx == NULL) {
4818 SCLogDebug(
"set up new_de_ctx %p", new_de_ctx);
4827 SCLogDebug(
"going to reload the threads to use new_de_ctx %p", new_de_ctx);
4829 DetectEngineReloadThreads(new_de_ctx);
4830 SCLogDebug(
"threads now run new_de_ctx %p", new_de_ctx);
4839 SCLogDebug(
"old_de_ctx should have been freed");
4843 #ifdef HAVE_MALLOC_TRIM
4854 static uint32_t TenantIdHash(
HashTable *h,
void *data, uint16_t data_len)
4860 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len)
4867 static void TenantIdFree(
void *d)
4869 DetectEngineThreadCtxFree(d);
4885 for ( ; list != NULL; list = list->
next) {
4896 if (stub_de_ctx == NULL) {
4898 if (stub_de_ctx == NULL) {
4903 if (master->
list == NULL) {
4904 master->
list = stub_de_ctx;
4907 master->
list = stub_de_ctx;
4913 DetectEngineReloadThreads(stub_de_ctx);
4923 SCLogDebug(
"old_de_ctx should have been freed");
4927 static int g_parse_metadata = 0;
4931 g_parse_metadata = 1;
4936 g_parse_metadata = 0;
4941 return g_parse_metadata;
4950 return "packet/stream payload";
4956 return "base64_data";
4959 return "post-match";
4967 return "max (internal)";
4983 static int DetectEngineInitYamlConf(
const char *conf)
4990 static void DetectEngineDeInitYamlConf(
void)
4996 static int DetectEngineTest01(
void)
5002 " - profile: medium\n"
5003 " - custom-values:\n"
5004 " toclient_src_groups: 2\n"
5005 " toclient_dst_groups: 2\n"
5006 " toclient_sp_groups: 2\n"
5007 " toclient_dp_groups: 3\n"
5008 " toserver_src_groups: 2\n"
5009 " toserver_dst_groups: 4\n"
5010 " toserver_sp_groups: 2\n"
5011 " toserver_dp_groups: 25\n"
5012 " - inspection-recursion-limit: 0\n";
5014 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5023 DetectEngineDeInitYamlConf();
5028 static int DetectEngineTest02(
void)
5034 " - profile: medium\n"
5035 " - custom-values:\n"
5036 " toclient_src_groups: 2\n"
5037 " toclient_dst_groups: 2\n"
5038 " toclient_sp_groups: 2\n"
5039 " toclient_dp_groups: 3\n"
5040 " toserver_src_groups: 2\n"
5041 " toserver_dst_groups: 4\n"
5042 " toserver_sp_groups: 2\n"
5043 " toserver_dp_groups: 25\n"
5044 " - inspection-recursion-limit:\n";
5046 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5056 DetectEngineDeInitYamlConf();
5061 static int DetectEngineTest03(
void)
5067 " - profile: medium\n"
5068 " - custom-values:\n"
5069 " toclient_src_groups: 2\n"
5070 " toclient_dst_groups: 2\n"
5071 " toclient_sp_groups: 2\n"
5072 " toclient_dp_groups: 3\n"
5073 " toserver_src_groups: 2\n"
5074 " toserver_dst_groups: 4\n"
5075 " toserver_sp_groups: 2\n"
5076 " toserver_dp_groups: 25\n";
5078 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5088 DetectEngineDeInitYamlConf();
5093 static int DetectEngineTest04(
void)
5099 " - profile: medium\n"
5100 " - custom-values:\n"
5101 " toclient_src_groups: 2\n"
5102 " toclient_dst_groups: 2\n"
5103 " toclient_sp_groups: 2\n"
5104 " toclient_dp_groups: 3\n"
5105 " toserver_src_groups: 2\n"
5106 " toserver_dst_groups: 4\n"
5107 " toserver_sp_groups: 2\n"
5108 " toserver_dp_groups: 25\n"
5109 " - inspection-recursion-limit: 10\n";
5111 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5120 DetectEngineDeInitYamlConf();
5125 static int DetectEngineTest08(
void)
5131 " - profile: custom\n"
5132 " - custom-values:\n"
5133 " toclient-groups: 23\n"
5134 " toserver-groups: 27\n";
5136 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5146 DetectEngineDeInitYamlConf();
5152 static int DetectEngineTest09(
void)
5158 " - profile: custom\n"
5159 " - custom-values:\n"
5160 " toclient-groups: BA\n"
5161 " toserver-groups: BA\n"
5162 " - inspection-recursion-limit: 10\n";
5164 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5174 DetectEngineDeInitYamlConf();
#define HashListTableGetListData(hb)
#define DE_STATE_ID_FILE_INSPECT
@ DETECT_EVENT_TOO_MANY_BUFFERS
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 ConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
void DetectEngineResetMaxSigId(DetectEngineCtx *de_ctx)
int DetectEngineMTApply(void)
void SCProfilingKeywordDestroyCtx(DetectEngineCtx *de_ctx)
#define PACKET_ALERT_FLAG_STREAM_MATCH
bool DetectEngineBufferTypeSupportsPacketGetById(const DetectEngineCtx *de_ctx, const int id)
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
DetectEngineThreadCtx * DetectEngineThreadCtxInitForReload(ThreadVars *tv, DetectEngineCtx *new_de_ctx, int mt)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
int SCRunmodeGet(void)
Get the current run mode.
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.
SigTableElmt * sigmatch_table
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
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)
void MpmFactoryDeRegisterAllMpmCtxProfiles(DetectEngineCtx *de_ctx)
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)
int ConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
enum DetectEngineType type
void DetectEnginePruneFreeList(void)
int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exclusive)
Load signatures.
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
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)
uint32_t non_pf_store_cnt_max
void PacketEnqueue(PacketQueue *q, Packet *p)
DetectFileDataCfg * filedata_config
struct HtpBodyChunk_ * next
void DetectBufferTypeSupportsFrames(const char *name)
#define TM_FLAG_DETECT_TM
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 DetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t flags)
get the progress value for a tx/protocol
AppLayerDecoderEvents * decoder_events
uint8_t stream_tx_log_limit
InspectionBuffer *(* InspectionMultiBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id, const uint32_t local_id)
void *(* InitFunc)(void *)
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
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 *))
InspectionBuffer *(* InspectionBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id)
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)
int ConfYamlLoadFileWithPrefix(const char *filename, const char *prefix)
Load configuration from a YAML file, insert in tree at 'prefix'.
uint16_t lua_blocked_function_errors
void ** global_keyword_ctxs_array
DetectEngineCtx * DetectEngineGetCurrent(void)
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.
struct DetectEngineAppInspectionEngine_::@79 v2
int DetectEngineAddToMaster(DetectEngineCtx *de_ctx)
int ConfYamlHandleInclude(ConfNode *parent, const char *filename)
Include a file in the configuration.
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
void ConfDump(void)
Dump configuration to stdout.
struct DetectEngineTenantMapping_ * next
void DetectEngineSetEvent(DetectEngineThreadCtx *det_ctx, uint8_t e)
void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
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.
DetectPort * udp_priorityports
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)
void SigCleanSignatures(DetectEngineCtx *de_ctx)
void * HashListTableLookup(HashListTable *ht, void *data, uint16_t datalen)
uint16_t lua_instruction_limit_errors
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
#define SIG_FLAG_TOCLIENT
bool DetectBufferIsPresent(const Signature *s, const uint32_t buf_id)
#define KEYWORD_PROFILING_START
uint16_t counter_fnonmpm_list
#define DETECT_TRANSFORMS_MAX
uint16_t counter_nonmpm_list
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
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)
int DetectBufferTypeGetByName(const char *name)
#define KEYWORD_PROFILING_END(ctx, type, m)
void DetectBufferTypeSupportsPacket(const char *name)
InspectionBufferFrameInspectFunc Callback
int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen)
int SigGroupHeadHashInit(DetectEngineCtx *de_ctx)
Initializes the hash table in the detection engine context to hold the SigGroupHeads.
void SCRConfDeInitContext(DetectEngineCtx *de_ctx)
Releases de_ctx resources related to Reference Config API.
HashTable * mt_det_ctxs_hash
size_t strlcpy(char *dst, const char *src, size_t siz)
bool DetectEnginePktInspectionRun(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p, uint8_t *alert_flags)
void DetectAppLayerMpmRegisterByParentId(DetectEngineCtx *de_ctx, const int id, const int parent_id, DetectEngineTransforms *transforms)
copy a mpm engine from parent_id, add in transforms
void AlertQueueInit(DetectEngineThreadCtx *det_ctx)
void DetectAppLayerMultiRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectionMultiBufferGetDataPtr GetData, int priority, int tx_min_progress)
uint16_t counter_alerts_suppressed
#define PKT_SET_SRC(p, src_val)
@ TENANT_SELECTOR_UNKNOWN
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
void InspectionBufferInit(InspectionBuffer *buffer, uint32_t initial_size)
int DetectEngineMultiTenantEnabled(void)
#define HashListTableGetListNext(hb)
@ DETECT_SM_LIST_POSTMATCH
void ConfNodeRemove(ConfNode *node)
Remove (and SCFree) the provided configuration node.
#define SIG_FLAG_TOSERVER
void InspectionBufferSetupMultiEmpty(InspectionBuffer *buffer)
setup the buffer empty
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)
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)
bool(* TransformValidate)(const uint8_t *content, uint16_t content_len, void *context)
uint16_t counter_alerts_overflow
void DetectBufferTypeRegisterValidateCallback(const char *name, bool(*ValidateCallback)(const Signature *, const char **sigerror))
int DetectEngineMoveToFreeList(DetectEngineCtx *de_ctx)
#define PASS
Pass the test.
SpmGlobalThreadCtx * SpmInitGlobalThreadCtx(uint8_t matcher)
void SCProfilingPrefilterDestroyCtx(DetectEngineCtx *de_ctx)
void DetectMpmInitializePktMpms(DetectEngineCtx *de_ctx)
@ ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE
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.
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
void SCClassConfDeinit(DetectEngineCtx *de_ctx)
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
DetectEngineFrameInspectionEngine * frame_inspect_engines
DetectEngineCtx * free_list
SigMatch * DetectBufferGetLastSigMatch(const Signature *s, const uint32_t buf_id)
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
void PatternMatchThreadPrepare(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher)
int ConfYamlLoadString(const char *string, size_t len)
Load configuration from a YAML string.
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.
DetectEngineAppInspectionEngine * app_inspect
bool(* ValidateCallback)(const struct Signature_ *, const char **sigerror)
struct ThreadVars_ * next
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
int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml)
Load a tenant and wait for loading to complete.
void TmModuleDetectLoaderRegister(void)
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)
int SignatureInitDataBufferCheckExpand(Signature *s)
check if buffers array still has space left, expand if not
struct LiveDevice_ * livedev
InspectionBufferPktInspectFunc Callback
SignatureInitData * init_data
enum DetectEngineSyncState state
SpmThreadCtx * SpmMakeThreadCtx(const SpmGlobalThreadCtx *global_thread_ctx)
struct SCProfileKeywordDetectCtx_ * profile_keyword_ctx
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 ConfCreateContextBackup(void)
Creates a backup of the conf_hash hash_table used by the conf API.
void SCProfilingPrefilterThreadCleanup(DetectEngineThreadCtx *det_ctx)
int32_t byte_extract_max_local_id
@ SIG_PROP_FLOW_ACTION_PACKET
const struct SignatureProperties signature_properties[SIG_TYPE_MAX]
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 * InspectionBufferCheckAndExpand(InspectionBuffer *buffer, uint32_t min_size)
make sure that the buffer has at least 'min_size' bytes Expand the buffer if necessary
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)
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
@ ENGINE_SGH_MPM_FACTORY_CONTEXT_FULL
ConfNode * ConfNodeLookupChild(const ConfNode *node, const char *name)
Lookup a child configuration node by name.
#define DETECT_SM_LIST_NOTSET
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)
void SCReferenceConfInit(DetectEngineCtx *de_ctx)
InspectionBufferGetPktDataPtr GetData
@ DETECT_ENGINE_TYPE_NORMAL
void InspectionBufferCopy(InspectionBuffer *buffer, uint8_t *buf, uint32_t buf_len)
void * FlowWorkerGetDetectCtxPtr(void *flow_worker)
bool DetectEngineBufferTypeSupportsMultiInstanceGetById(const DetectEngineCtx *de_ctx, const int id)
struct DetectEngineThreadCtx_::@96 multi_inspect
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.
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 InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
void DetectEngineBumpVersion(void)
void AppLayerDecoderEventsSetEventRaw(AppLayerDecoderEvents **sevents, uint8_t event)
Set an app layer decoder event.
struct DetectEngineFrameInspectionEngine * next
void(* Transform)(InspectionBuffer *, void *context)
SignatureInitDataBuffer * curbuf
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
#define DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT
void ConfRestoreContextBackup(void)
Restores the backup of the hash_table present in backup_conf_hash back to conf_hash.
uint8_t PatternMatchDefaultMatcher(void)
Function to return the multi pattern matcher algorithm to be used by the engine, based on the mpm-alg...
struct DetectEngineFrameInspectionEngine::@83 v1
int DetectEngineTenantRegisterPcapFile(uint32_t tenant_id)
void InspectionBufferSetupMulti(InspectionBuffer *buffer, const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
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
SigIntId * non_pf_id_array
const char * DetectBufferTypeGetDescriptionByName(const char *name)
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
void InspectionBufferTruncate(InspectionBuffer *buffer, uint32_t buf_len)
void DetectEngineFreeFastPatternList(DetectEngineCtx *de_ctx)
void DetectBufferTypeSupportsTransformations(const char *name)
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
int DetectAddressMapInit(DetectEngineCtx *de_ctx)
void ConfInit(void)
Initialize the configuration system.
SignatureInitDataBuffer * buffers
DetectEngineAppInspectionEngine * app_inspect_engines
int filemagic_thread_ctx_id
int global_keyword_ctxs_size
void PrefilterInit(DetectEngineCtx *de_ctx)
void * DetectThreadCtxGetGlobalKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
#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 InspectionBufferSetup(DetectEngineThreadCtx *det_ctx, const int list_id, InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
void ** keyword_ctxs_array
int base64_decoded_len_max
int HashListTableRemove(HashListTable *ht, void *data, uint16_t datalen)
DetectEngineTransforms transforms
struct DetectEnginePktInspectionEngine::@82 v1
a single match condition for a signature
const DetectEngineTransforms * transforms
void InspectionBufferClean(DetectEngineThreadCtx *det_ctx)
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 PmqFree(PrefilterRuleStore *pmq)
Cleanup and free a Pmq.
InspectionBuffer * InspectionBufferMultipleForListGet(DetectEngineThreadCtx *det_ctx, const int list_id, const uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
@ DETECT_ENGINE_TYPE_MT_STUB
void ConfDeInit(void)
De-initializes the configuration system.
void ThresholdCacheThreadFree(void)
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)
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)
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)
DetectEngineTransforms transforms
void SCClassConfInit(DetectEngineCtx *de_ctx)
#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 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)
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 uint32_t stream_start_offset, const uint8_t flags, const enum DetectContentInspectionType inspection_mode)
wrapper around DetectEngineContentInspectionInternal to return true/false only
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)
uint32_t base64_decode_max_len
void InspectionBufferFree(InspectionBuffer *buffer)
void DetectPortCleanupList(const DetectEngineCtx *de_ctx, DetectPort *head)
Free a DetectPort list and each of its members.
@ 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.
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
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)
uint32_t tenant_array_size
struct DetectEngineTenantMapping_ * tenant_array
volatile uint8_t suricata_ctl_flags
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.
struct DetectEngineThreadCtx_::@95 inspect
#define SIG_FLAG_REQUIRE_PACKET
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.