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);
108 static inline void InspectionBufferApplyTransformsInternal(
154 FatalError(
"failed to register inspect engine %s: %s",
name, strerror(errno));
156 new_engine->
sm_list = (uint16_t)sm_list;
161 if (g_pkt_inspect_engines == NULL) {
162 g_pkt_inspect_engines = new_engine;
165 while (t->
next != NULL) {
169 t->
next = new_engine;
176 static void AppLayerInspectEngineRegisterInternal(
const char *
name,
AppProto alproto, uint32_t dir,
191 (progress < 0 || progress >= SHRT_MAX) || (Callback == NULL)) {
195 SCLogError(
"Invalid arguments: must register "
196 "GetData with DetectEngineInspectBufferGeneric");
199 SCLogError(
"Invalid arguments: must register "
200 "GetData with DetectEngineInspectMultiBufferGeneric");
212 AppLayerInspectEngineRegisterInternal(
222 new_engine->
dir = direction;
223 new_engine->
sm_list = (uint16_t)sm_list;
225 new_engine->
progress = (int16_t)progress;
233 if (g_app_inspect_engines == NULL) {
234 g_app_inspect_engines = new_engine;
237 while (t->
next != NULL) {
241 t->
next = new_engine;
255 if (t->
sm_list == sm_list && t->
alproto == alproto && t_direction == dir &&
263 AppLayerInspectEngineRegisterInternal(
name, alproto, dir, progress, Callback, GetData, NULL);
267 static void DetectAppLayerInspectEngineCopy(
269 int sm_list,
int new_list,
282 new_engine->
sm_list = (uint16_t)new_list;
286 new_engine->
v2 = t->
v2;
293 while (list->
next != NULL) {
297 list->
next = new_engine;
319 new_engine->
v2 = t->
v2;
324 list->
next = new_engine;
333 static void DetectPktInspectEngineCopy(
335 int sm_list,
int new_list,
346 new_engine->
sm_list = (uint16_t)new_list;
349 new_engine->
v1 = t->
v1;
356 while (list->
next != NULL) {
360 list->
next = new_engine;
379 new_engine->
v1 = t->
v1;
385 while (list->
next != NULL) {
389 list->
next = new_engine;
421 FatalError(
"failed to register inspect engine %s: %s",
name, strerror(errno));
423 new_engine->
sm_list = (uint16_t)sm_list;
425 new_engine->
dir = direction;
434 while (list->
next != NULL) {
438 list->
next = new_engine;
457 new_engine->
sm_list = (uint16_t)new_list;
463 new_engine->
v1 = t->
v1;
468 while (list->
next != NULL) {
472 list->
next = new_engine;
494 new_engine->
v1 = t->
v1;
500 while (list->
next != NULL) {
504 list->
next = new_engine;
516 static void AppendStreamInspectEngine(
519 bool prepend =
false;
528 new_engine->
mpm =
true;
531 new_engine->
dir = direction;
532 new_engine->
stream =
true;
535 new_engine->
smd = stream;
543 }
else if (prepend) {
550 while (a->
next != NULL) {
554 a->
next = new_engine;
557 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
564 bool prepend =
false;
587 new_engine->
mpm =
true;
593 new_engine->
smd = smd;
594 new_engine->
v1 = u->
v1;
600 }
else if (prepend) {
605 while (a->
next != NULL) {
609 a->
next = new_engine;
617 bool prepend =
false;
627 new_engine->
mpm =
true;
632 new_engine->
smd = smd;
633 new_engine->
v1 = e->
v1;
639 }
else if (prepend) {
644 while (a->
next != NULL) {
648 a->
next = new_engine;
654 const int mpm_list,
const int files_id, uint8_t *last_id,
bool *head_is_mpm)
668 SCLogDebug(
"app engine: t %p t->id %u => alproto:%s files:%s", t, t->
id,
676 bool prepend =
false;
681 new_engine->
mpm =
true;
688 new_engine->
smd = smd;
691 new_engine->
v2 = t->
v2;
697 if (new_engine->
sm_list == files_id) {
699 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
702 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
710 if (new_engine->
sm_list == files_id) {
712 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
714 new_engine->
id = ++(*last_id);
715 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
721 while (a->
next != NULL) {
729 a->
next = new_engine;
730 if (new_engine->
sm_list == files_id) {
732 SCLogDebug(
"sid %u: engine %p/%u is FILE ENGINE", s->
id, new_engine, new_engine->
id);
734 new_engine->
id = ++(*last_id);
735 SCLogDebug(
"sid %u: engine %p/%u %s", s->
id, new_engine, new_engine->
id,
740 SCLogDebug(
"sid %u: engine %p/%u added", s->
id, new_engine, new_engine->
id);
753 bool head_is_mpm =
false;
767 u != NULL; u = u->
next) {
769 AppendFrameInspectEngine(
de_ctx, u, s, smd, mpm_list);
778 AppendPacketInspectEngine(
de_ctx, e, s, smd, mpm_list);
787 AppendAppInspectEngine(
788 de_ctx, t, s, smd, mpm_list, files_id, &last_id, &head_is_mpm);
801 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
803 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
805 AppendStreamInspectEngine(s, stream, 0, last_id + 1);
806 AppendStreamInspectEngine(s, stream, 1, last_id + 1);
820 iter->
sm_list == mpm_list ?
"MPM" :
"");
871 for (
int i = 0; i < arrays; i++) {
872 if (bufs[i] == ie->
smd) {
878 bufs[arrays++] = ie->
smd;
888 for (
int i = 0; i < arrays; i++) {
889 if (bufs[i] == e->
smd) {
895 bufs[arrays++] = e->
smd;
905 for (
int i = 0; i < arrays; i++) {
906 if (bufs[i] == u->
smd) {
912 bufs[arrays++] = u->
smd;
918 for (
int i = 0; i < engines; i++) {
940 static int g_buffer_type_reg_closed = 0;
944 return g_buffer_type_id;
947 static uint32_t DetectBufferTypeHashNameFunc(
HashListTable *ht,
void *data, uint16_t datalen)
956 static uint32_t DetectBufferTypeHashIdFunc(
HashListTable *ht,
void *data, uint16_t datalen)
959 uint32_t hash = map->
id;
964 static char DetectBufferTypeCompareNameFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
969 char r = (strcmp(map1->
name, map2->
name) == 0);
974 static char DetectBufferTypeCompareIdFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
978 return map1->
id == map2->
id;
981 static void DetectBufferTypeFreeFunc(
void *data)
994 SCLogError(
"%s allocates transform option memory but has no free routine",
1004 static int DetectBufferTypeInit(
void)
1006 BUG_ON(g_buffer_type_hash);
1008 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
1009 if (g_buffer_type_hash == NULL)
1015 static void DetectBufferTypeFree(
void)
1017 if (g_buffer_type_hash == NULL)
1021 g_buffer_type_hash = NULL;
1024 static int DetectBufferTypeAdd(
const char *
string)
1026 BUG_ON(
string == NULL || strlen(
string) >= 32);
1033 map->
id = g_buffer_type_id++;
1043 memset(&map, 0,
sizeof(map));
1052 BUG_ON(g_buffer_type_reg_closed);
1053 if (g_buffer_type_hash == NULL)
1054 DetectBufferTypeInit();
1058 return DetectBufferTypeAdd(
name);
1066 BUG_ON(g_buffer_type_reg_closed);
1071 SCLogDebug(
"%p %s -- %d supports multi instance", exists,
name, exists->
id);
1076 BUG_ON(g_buffer_type_reg_closed);
1080 exists->
frame =
true;
1081 SCLogDebug(
"%p %s -- %d supports frame inspection", exists,
name, exists->
id);
1086 BUG_ON(g_buffer_type_reg_closed);
1091 SCLogDebug(
"%p %s -- %d supports packet inspection", exists,
name, exists->
id);
1096 BUG_ON(g_buffer_type_reg_closed);
1106 BUG_ON(g_buffer_type_reg_closed);
1111 SCLogDebug(
"%p %s -- %d supports transformations", exists,
name, exists->
id);
1127 memset(&map, 0,
sizeof(map));
1137 memset(&lookup, 0,
sizeof(lookup));
1147 return res ? res->
name : NULL;
1152 BUG_ON(
string == NULL || strlen(
string) >= 32);
1168 const int direction,
const AppProto alproto,
const uint8_t frame_type)
1175 const int buffer_id = DetectEngineBufferTypeAdd(
de_ctx,
name);
1176 if (buffer_id < 0) {
1205 return DetectEngineBufferTypeAdd(
de_ctx,
name);
1213 BUG_ON(desc == NULL || strlen(desc) >= 128);
1244 exists->
frame =
true;
1245 SCLogDebug(
"%p %s -- %d supports frame inspection", exists,
name, exists->
id);
1253 SCLogDebug(
"%p %s -- %d supports packet inspection", exists,
name, exists->
id);
1269 SCLogDebug(
"%p %s -- %d supports transformations", exists,
name, exists->
id);
1311 BUG_ON(g_buffer_type_reg_closed);
1327 bool (*ValidateCallback)(
const Signature *,
const char **sigerror))
1329 BUG_ON(g_buffer_type_reg_closed);
1382 SCLogError(
"Rule buffer cannot be reset after base64_data.");
1387 SCLogError(
"no matches following transform(s)");
1395 SCLogError(
"previous sticky buffer has no matches");
1405 if ((uint32_t)list == b->
id) {
1406 SCLogDebug(
"found buffer %p for list %d", b, list);
1409 SCLogDebug(
"sm_init was true for %p list %d", b, list);
1428 SCLogError(
"failed to expand rule buffer array");
1452 SCLogError(
"previous transforms not consumed "
1453 "(list: %u, transform_cnt %u)",
1458 SCLogDebug(
"buffer %d has transform(s) registered: %d",
1462 if (new_list == -1) {
1474 SCLogError(
"failed to expand rule buffer array");
1487 SCLogDebug(
"new list after applying transforms: %u", new_list);
1510 for (uint32_t x = 0; x <= mbuffer->
max; x++) {
1530 if (!buffer->
init) {
1551 if (local_id >= fb->
size) {
1552 uint32_t old_size = fb->
size;
1553 uint32_t new_size = local_id + 1;
1554 uint32_t grow_by = new_size - old_size;
1555 SCLogDebug(
"size is %u, need %u, so growing by %u", old_size, new_size, grow_by);
1563 SCLogDebug(
"ptr %p to_zero %p", ptr, to_zero);
1566 fb->
size = new_size;
1572 #ifdef DEBUG_VALIDATION
1573 buffer->multi =
true;
1578 static inline void InspectionBufferApplyTransformsInternal(
1596 InspectionBufferApplyTransformsInternal(buffer, transforms);
1601 memset(buffer, 0,
sizeof(*buffer));
1602 buffer->
buf =
SCCalloc(initial_size,
sizeof(uint8_t));
1603 if (buffer->
buf != NULL) {
1604 buffer->
size = initial_size;
1611 #ifdef DEBUG_VALIDATION
1623 const uint8_t *data,
const uint32_t data_len)
1625 #ifdef DEBUG_VALIDATION
1633 InspectionBufferApplyTransformsInternal(buffer, transforms);
1639 #ifdef DEBUG_VALIDATION
1643 if (buffer->
inspect == NULL) {
1645 if (det_ctx && list_id != -1)
1658 InspectionBufferSetupInternal(det_ctx, list_id, buffer, data, data_len);
1666 InspectionBufferSetupInternal(det_ctx, list_id, buffer, data, data_len);
1667 InspectionBufferApplyTransformsInternal(buffer, transforms);
1672 if (buffer->
buf != NULL) {
1675 memset(buffer, 0,
sizeof(*buffer));
1687 uint32_t new_size = (buffer->
size == 0) ? 4096 : buffer->
size;
1688 while (new_size < min_size) {
1695 buffer->
size = new_size;
1716 uint32_t copy_size =
MIN(buf_len, buffer->
size);
1717 memcpy(buffer->
buf, buf, copy_size);
1743 const uint8_t *content, uint16_t content_len,
const char **namestr)
1769 const int size = g_buffer_type_id;
1773 DetectBufferTypeCompareNameFunc, DetectBufferTypeFreeFunc);
1776 HashListTableInit(256, DetectBufferTypeHashIdFunc, DetectBufferTypeCompareIdFunc,
1788 memcpy(copy, map,
sizeof(*copy));
1794 SCLogDebug(
"name %s id %d mpm %s packet %s -- %s. "
1795 "Callbacks: Setup %p Validate %p",
1796 map->
name, map->
id, map->
mpm ?
"true" :
"false", map->
packet ?
"true" :
"false",
1803 DetectAppLayerInspectEngineCopyListToDetectCtx(
de_ctx);
1805 DetectFrameInspectEngineCopyListToDetectCtx(
de_ctx);
1807 DetectPktInspectEngineCopyListToDetectCtx(
de_ctx);
1849 while (framemlist) {
1860 BUG_ON(g_buffer_type_hash == NULL);
1862 g_buffer_type_reg_closed = 1;
1873 SCLogError(
"buffer '%s' does not support transformations", base_map->
name);
1880 memset(&t, 0,
sizeof(t));
1881 for (
int i = 0; i < transform_cnt; i++) {
1884 t.
cnt = transform_cnt;
1887 memset(&lookup_map, 0,
sizeof(lookup_map));
1905 map->
mpm = base_map->
mpm;
1912 }
else if (map->
packet) {
1922 SCLogDebug(
"buffer %s registered with id %d, parent %d", map->name, map->id, map->parent_id);
1925 DetectFrameInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1926 }
else if (map->packet) {
1927 DetectPktInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1929 DetectAppLayerInspectEngineCopy(
de_ctx, map->parent_id, map->id, &map->transforms);
1935 static int DetectEngineInspectRulePacketMatches(
1939 Packet *p, uint8_t *_alert_flags)
1947 SCLogDebug(
"running match functions, sm %p", smd);
1965 static int DetectEngineInspectRulePayloadMatches(
1987 SCLogDebug(
"no match in stream, fall back to packet payload");
1995 SCLogDebug(
"SIG_FLAG_REQUIRE_STREAM_ONLY, so no match");
2013 uint8_t *alert_flags)
2019 SCLogDebug(
"sid %u: e %p Callback returned no match", s->
id, e);
2022 SCLogDebug(
"sid %u: e %p Callback returned true", s->
id, e);
2041 e->
sm_list = (uint16_t)list_id;
2050 while (a->
next != NULL) {
2062 if (DetectEnginePktInspectionAppend(
2065 SCLogDebug(
"sid %u: DetectEngineInspectRulePayloadMatches appended", s->
id);
2069 if (DetectEnginePktInspectionAppend(
2072 SCLogDebug(
"sid %u: DetectEngineInspectRulePacketMatches appended", s->
id);
2154 uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
2157 SCLogDebug(
"running match functions, sm %p", smd);
2163 AppLayerTxMatch(det_ctx, f,
flags, alstate, txv, s, smd->
ctx);
2197 void *alstate,
void *txv, uint64_t tx_id)
2199 const int list_id = engine->
sm_list;
2200 SCLogDebug(
"running inspect on %d", list_id);
2214 f,
flags, txv, list_id);
2224 const uint8_t *data = buffer->
inspect;
2229 ci_flags |= buffer->
flags;
2248 AppLayerInspectEngineRegisterInternal(
2251 alproto, tx_min_progress);
2256 const Signature *s,
Flow *f, uint8_t
flags,
void *alstate,
void *txv, uint64_t tx_id)
2258 uint32_t local_id = 0;
2266 det_ctx, transforms, f,
flags, txv, engine->
sm_list, local_id);
2268 if (buffer == NULL || buffer->
inspect == NULL)
2280 if (local_id == 0) {
2307 const int list_id = engine->
sm_list;
2308 SCLogDebug(
"running inspect on %d", list_id);
2326 ci_flags |= buffer->
flags;
2353 for (
int i = 0; i < no_of_detect_tvs; i++) {
2354 if (detect_tvs[i]) {
2357 SCLogDebug(
"Injecting pkt for tv %s[i=%d] %d", detect_tvs[i]->
name, i, count++);
2369 SCLogDebug(
"leaving: thread notification count = %d", count);
2377 static void InjectPackets(
2385 for (
int i = 0; i < no_of_detect_tvs; i++) {
2386 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) != 1) {
2387 if (detect_tvs[i]->inq != NULL) {
2424 if (no_of_detect_tvs == 0) {
2434 memset(detect_tvs, 0x00, (no_of_detect_tvs *
sizeof(
ThreadVars *)));
2459 if (new_det_ctx[i] == NULL) {
2461 "failure in live rule swap. Let's get out of here");
2465 SCLogDebug(
"live rule swap created new det_ctx - %p and de_ctx "
2466 "- %p\n", new_det_ctx[i], new_de_ctx);
2471 BUG_ON(i != no_of_detect_tvs);
2484 SCLogDebug(
"swapping new det_ctx - %p with older one - %p",
2495 SCLogDebug(
"Live rule swap has swapped %d old det_ctx's with new ones, "
2496 "along with the new de_ctx", no_of_detect_tvs);
2498 InjectPackets(detect_tvs, new_det_ctx, no_of_detect_tvs);
2502 uint32_t threads_done = 0;
2504 for (i = 0; i < no_of_detect_tvs; i++) {
2506 threads_done = no_of_detect_tvs;
2510 if (
SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) == 1) {
2511 SCLogDebug(
"new_det_ctx - %p used by detect engine", new_det_ctx[i]);
2514 TmThreadsCaptureBreakLoop(detect_tvs[i]);
2517 if (threads_done < no_of_detect_tvs) {
2528 if (i != no_of_detect_tvs) {
2541 for (i = 0; i < no_of_detect_tvs; i++) {
2542 SCLogDebug(
"Freeing old_det_ctx - %p used by detect",
2552 for (i = 0; i < no_of_detect_tvs; i++) {
2553 if (new_det_ctx[i] != NULL)
2579 if (prefix != NULL) {
2583 int failure_fatal = 0;
2584 if (
ConfGetBool(
"engine.init-failure-fatal", (
int *)&failure_fatal) != 1) {
2585 SCLogDebug(
"ConfGetBool could not load the value.");
2597 SCLogDebug(
"Unable to alloc SpmGlobalThreadCtx.");
2609 if (DetectEngineCtxLoadConf(
de_ctx) == -1) {
2618 DetectBufferTypeSetupDetectEngine(
de_ctx);
2666 if (prefix == NULL || strlen(prefix) == 0)
2704 #ifdef PROFILE_RULES
2705 if (
de_ctx->profile_ctx != NULL) {
2706 SCProfilingRuleDestroyCtx(
de_ctx->profile_ctx);
2707 de_ctx->profile_ctx = NULL;
2747 DetectEngineCtxFreeThreadKeywordData(
de_ctx);
2749 DetectEngineCtxFreeFailedSigs(
de_ctx);
2769 DetectBufferTypeFreeDetectEngine(
de_ctx);
2795 const char *max_uniq_toclient_groups_str = NULL;
2796 const char *max_uniq_toserver_groups_str = NULL;
2797 const char *sgh_mpm_context = NULL;
2798 const char *de_ctx_profile = NULL;
2800 (void)
ConfGet(
"detect.profile", &de_ctx_profile);
2801 (void)
ConfGet(
"detect.sgh-mpm-context", &sgh_mpm_context);
2806 if (de_ctx_custom != NULL) {
2808 if (de_ctx_profile == NULL) {
2809 if (opt->
val && strcmp(opt->
val,
"profile") == 0) {
2810 de_ctx_profile = opt->head.tqh_first->
val;
2814 if (sgh_mpm_context == NULL) {
2815 if (opt->
val && strcmp(opt->
val,
"sgh-mpm-context") == 0) {
2816 sgh_mpm_context = opt->head.tqh_first->
val;
2822 if (de_ctx_profile != NULL) {
2823 if (strcmp(de_ctx_profile,
"low") == 0 ||
2824 strcmp(de_ctx_profile,
"lowest") == 0) {
2826 }
else if (strcmp(de_ctx_profile,
"medium") == 0) {
2828 }
else if (strcmp(de_ctx_profile,
"high") == 0 ||
2829 strcmp(de_ctx_profile,
"highest") == 0) {
2831 }
else if (strcmp(de_ctx_profile,
"custom") == 0) {
2834 SCLogError(
"invalid value for detect.profile: '%s'. "
2835 "Valid options: low, medium, high and custom.",
2840 SCLogDebug(
"Profile for detection engine groups is \"%s\"", de_ctx_profile);
2842 SCLogDebug(
"Profile for detection engine groups not provided "
2843 "at suricata.yaml. Using default (\"medium\").");
2847 if (sgh_mpm_context == NULL || strcmp(sgh_mpm_context,
"auto") == 0) {
2857 if (strcmp(sgh_mpm_context,
"single") == 0) {
2859 }
else if (strcmp(sgh_mpm_context,
"full") == 0) {
2863 "invalid conf value for detect-engine.sgh-mpm-context-"
2888 (void)
ConfGet(
"detect.custom-values.toclient-groups",
2889 &max_uniq_toclient_groups_str);
2890 (void)
ConfGet(
"detect.custom-values.toserver-groups",
2891 &max_uniq_toserver_groups_str);
2893 if (de_ctx_custom != NULL) {
2895 if (opt->
val && strcmp(opt->
val,
"custom-values") == 0) {
2896 if (max_uniq_toclient_groups_str == NULL) {
2898 (opt->head.tqh_first,
"toclient-sp-groups");
2900 if (max_uniq_toclient_groups_str == NULL) {
2902 (opt->head.tqh_first,
"toclient-groups");
2904 if (max_uniq_toserver_groups_str == NULL) {
2906 (opt->head.tqh_first,
"toserver-dp-groups");
2908 if (max_uniq_toserver_groups_str == NULL) {
2910 (opt->head.tqh_first,
"toserver-groups");
2915 if (max_uniq_toclient_groups_str != NULL) {
2917 (uint16_t)strlen(max_uniq_toclient_groups_str),
2918 (
const char *)max_uniq_toclient_groups_str) <= 0) {
2922 "toclient-groups failed, using %u",
2930 if (max_uniq_toserver_groups_str != NULL) {
2932 (uint16_t)strlen(max_uniq_toserver_groups_str),
2933 (
const char *)max_uniq_toserver_groups_str) <= 0) {
2937 "toserver-groups failed, using %u",
2957 if (
ConfGetInt(
"detect.inspection-recursion-limit", &value) == 1)
2959 if (value >= 0 && value <= INT_MAX) {
2965 ConfNode *insp_recursion_limit_node = NULL;
2966 char *insp_recursion_limit = NULL;
2968 if (de_ctx_custom != NULL) {
2971 if (opt->
val && strcmp(opt->
val,
"inspection-recursion-limit") != 0)
2975 if (insp_recursion_limit_node == NULL) {
2977 "entry for detect-engine:inspection-recursion-limit");
2980 insp_recursion_limit = insp_recursion_limit_node->
val;
2981 SCLogDebug(
"Found detect-engine.inspection-recursion-limit - %s:%s",
2982 insp_recursion_limit_node->
name, insp_recursion_limit_node->
val);
2986 if (insp_recursion_limit != NULL) {
2988 0, (
const char *)insp_recursion_limit) < 0) {
2990 "detect-engine.inspection-recursion-limit: %s "
3003 SCLogDebug(
"de_ctx->inspection_recursion_limit: %d",
3008 if (
ConfGetInt(
"detect.stream-tx-log-limit", &value) == 1) {
3009 if (value >= 0 && value <= UINT8_MAX) {
3012 SCLogWarning(
"Invalid value for detect-engine.stream-tx-log-limit: must be between 0 "
3013 "and 255, will default to 4");
3016 int guess_applayer = 0;
3017 if ((
ConfGetBool(
"detect.guess-applayer-tx", &guess_applayer)) == 1) {
3018 if (guess_applayer == 1) {
3025 const char *ports = NULL;
3026 (void)
ConfGet(
"detect.grouping.tcp-priority-ports", &ports);
3028 SCLogConfig(
"grouping: tcp-priority-ports %s", ports);
3030 (void)
ConfGet(
"detect.grouping.tcp-whitelist", &ports);
3033 "grouping: tcp-priority-ports from legacy 'tcp-whitelist' setting: %s", ports);
3035 ports =
"53, 80, 139, 443, 445, 1433, 3306, 3389, 6666, 6667, 8080";
3036 SCLogConfig(
"grouping: tcp-priority-ports (default) %s", ports);
3041 "for detect.grouping.tcp-priority-ports",
3045 for ( ; x != NULL; x = x->
next) {
3048 "for detect.grouping.tcp-priority-ports: only single ports allowed",
3057 (void)
ConfGet(
"detect.grouping.udp-priority-ports", &ports);
3059 SCLogConfig(
"grouping: udp-priority-ports %s", ports);
3061 (void)
ConfGet(
"detect.grouping.udp-whitelist", &ports);
3064 "grouping: udp-priority-ports from legacy 'udp-whitelist' setting: %s", ports);
3066 ports =
"53, 135, 5060";
3067 SCLogConfig(
"grouping: udp-priority-ports (default) %s", ports);
3072 "for detect.grouping.udp-priority-ports",
3078 "for detect.grouping.udp-priority-ports: only single ports allowed",
3087 const char *pf_setting = NULL;
3088 if (
ConfGet(
"detect.prefilter.default", &pf_setting) == 1 && pf_setting) {
3089 if (strcasecmp(pf_setting,
"mpm") == 0) {
3091 }
else if (strcasecmp(pf_setting,
"auto") == 0) {
3100 SCLogConfig(
"prefilter engines: MPM and keywords");
3129 SCLogError(
"setting up thread local detect ctx");
3138 SCLogError(
"setting up thread local detect ctx "
3139 "for keyword \"%s\" failed",
3177 SCLogError(
"setting up thread local detect ctx");
3189 SCLogError(
"setting up thread local detect ctx "
3190 "for keyword \"%s\" failed",
3220 uint32_t map_array_size = 0;
3221 uint32_t map_cnt = 0;
3222 uint32_t max_tenant_id = 0;
3228 "set using multi-detect.selector");
3241 mt_det_ctxs_hash =
HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree);
3242 if (mt_det_ctxs_hash == NULL) {
3247 SCLogInfo(
"no tenants left, or none registered yet");
3258 map_array_size = map_cnt + 1;
3260 map_array =
SCCalloc(map_array_size,
sizeof(*map_array));
3261 if (map_array == NULL)
3268 if (map_cnt >= map_array_size) {
3280 list = master->
list;
3285 if (mt_det_ctx == NULL)
3287 if (
HashTableAdd(mt_det_ctxs_hash, mt_det_ctx, 0) != 0) {
3296 mt_det_ctxs_hash = NULL;
3308 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromVlanId;
3312 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromLivedev;
3316 det_ctx->
TenantGetId = DetectEngineTenantGetIdFromPcap;
3323 if (map_array != NULL)
3325 if (mt_det_ctxs_hash != NULL)
3405 DetectEngineThreadCtxInitKeywords(
de_ctx, det_ctx);
3406 DetectEngineThreadCtxInitGlobalKeywords(det_ctx);
3407 #ifdef PROFILE_RULES
3408 SCProfilingRuleThreadSetup(
de_ctx->profile_ctx, det_ctx);
3445 if (det_ctx->
de_ctx == NULL) {
3495 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3502 *data = (
void *)det_ctx;
3526 if (det_ctx->
de_ctx == NULL) {
3558 if (DetectEngineThreadCtxInitForMT(
tv, det_ctx) !=
TM_ECODE_OK) {
3571 SCLogDebug(
"PACKET PKT_STREAM_ADD: %"PRIu64, det_ctx->pkt_stream_add_cnt);
3573 SCLogDebug(
"PAYLOAD MPM %"PRIu64
"/%"PRIu64, det_ctx->payload_mpm_cnt, det_ctx->payload_mpm_size);
3574 SCLogDebug(
"STREAM MPM %"PRIu64
"/%"PRIu64, det_ctx->stream_mpm_cnt, det_ctx->stream_mpm_size);
3576 SCLogDebug(
"PAYLOAD SIG %"PRIu64
"/%"PRIu64, det_ctx->payload_persig_cnt, det_ctx->payload_persig_size);
3577 SCLogDebug(
"STREAM SIG %"PRIu64
"/%"PRIu64, det_ctx->stream_persig_cnt, det_ctx->stream_persig_size);
3585 #ifdef PROFILE_RULES
3586 SCProfilingRuleThreadCleanup(det_ctx);
3595 if (det_ctx->
de_ctx != NULL) {
3635 for (uint32_t x = 0; x < fb->
size; x++) {
3646 DetectEngineThreadCtxDeinitGlobalKeywords(det_ctx);
3647 if (det_ctx->
de_ctx != NULL) {
3648 DetectEngineThreadCtxDeinitKeywords(det_ctx->
de_ctx, det_ctx);
3668 if (det_ctx == NULL) {
3677 DetectEngineThreadCtxFree(det_ctx);
3682 static uint32_t DetectKeywordCtxHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
3691 static char DetectKeywordCtxCompareFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
3695 const char *name1 = ctx1->
name;
3696 const char *name2 = ctx2->
name;
3697 return (strcmp(name1, name2) == 0 && ctx1->
data == ctx2->
data);
3700 static void DetectKeywordCtxFreeFunc(
void *ptr)
3723 BUG_ON(
de_ctx == NULL || InitFunc == NULL || FreeFunc == NULL);
3727 DetectKeywordCtxHashFunc, DetectKeywordCtxCompareFunc, DetectKeywordCtxFreeFunc);
3812 void *(*InitFunc)(
void *),
void *data,
void (*FreeFunc)(
void *))
3815 BUG_ON(InitFunc == NULL || FreeFunc == NULL);
3821 while (item != NULL) {
3822 if (strcmp(
name, item->
name) == 0) {
3872 if (master->
list == NULL) {
3948 static int DetectEngineMultiTenantLoadTenant(uint32_t tenant_id,
const char *filename,
int loader_id)
3953 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
3956 if (
SCStatFn(filename, &st) != 0) {
3957 SCLogError(
"failed to stat file %s", filename);
3963 SCLogError(
"tenant %u already registered", tenant_id);
3970 SCLogError(
"failed to properly setup yaml %s", filename);
4007 static int DetectEngineMultiTenantReloadTenant(uint32_t tenant_id,
const char *filename,
int reload_cnt)
4010 if (old_de_ctx == NULL) {
4011 SCLogError(
"tenant detect engine not found");
4015 if (filename == NULL)
4019 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u.reload.%d", tenant_id, reload_cnt);
4030 SCLogError(
"failed to properly setup yaml %s", filename);
4035 if (new_de_ctx == NULL) {
4048 goto new_de_ctx_error;
4053 goto new_de_ctx_error;
4078 static void DetectLoaderFreeTenant(
void *
ctx)
4081 if (t->
yaml != NULL) {
4087 static int DetectLoaderFuncLoadTenant(
void *vctx,
int loader_id)
4092 if (DetectEngineMultiTenantLoadTenant(
ctx->tenant_id,
ctx->yaml, loader_id) != 0) {
4098 static int DetectLoaderSetupLoadTenant(uint32_t tenant_id,
const char *yaml)
4106 if (t->
yaml == NULL) {
4114 static int DetectLoaderFuncReloadTenant(
void *vctx,
int loader_id)
4120 if (DetectEngineMultiTenantReloadTenant(
ctx->tenant_id,
ctx->yaml,
ctx->reload_cnt) != 0) {
4126 static int DetectLoaderSetupReloadTenants(
const int reload_cnt)
4145 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4159 static int DetectLoaderSetupReloadTenant(uint32_t tenant_id,
const char *yaml,
int reload_cnt)
4162 if (old_de_ctx == NULL)
4174 if (t->
yaml == NULL) {
4184 loader_id, DetectLoaderFuncReloadTenant, t, DetectLoaderFreeTenant);
4191 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml);
4205 int r = DetectLoaderSetupReloadTenant(tenant_id, yaml, reload_cnt);
4219 int r = DetectLoaderSetupReloadTenants(reload_cnt);
4229 static int DetectEngineMultiTenantSetupLoadLivedevMappings(
const ConfNode *mappings_root_node,
4234 int mapping_cnt = 0;
4235 if (mappings_root_node != NULL) {
4238 if (tenant_id_node == NULL)
4241 if (device_node == NULL)
4244 uint32_t tenant_id = 0;
4246 tenant_id_node->
val) < 0) {
4249 tenant_id_node->
val);
4253 const char *dev = device_node->
val;
4272 SCLogConfig(
"device %s connected to tenant-id %u", dev, tenant_id);
4281 SCLogConfig(
"%d device - tenant-id mappings defined", mapping_cnt);
4288 static int DetectEngineMultiTenantSetupLoadVlanMappings(
const ConfNode *mappings_root_node,
4293 int mapping_cnt = 0;
4294 if (mappings_root_node != NULL) {
4297 if (tenant_id_node == NULL)
4300 if (vlan_id_node == NULL)
4303 uint32_t tenant_id = 0;
4305 tenant_id_node->
val) < 0) {
4308 tenant_id_node->
val);
4312 uint16_t vlan_id = 0;
4314 &vlan_id, 10, (uint16_t)strlen(vlan_id_node->
val), vlan_id_node->
val) < 0) {
4320 if (vlan_id == 0 || vlan_id >= 4095) {
4322 "of %s is invalid. Valid range 1-4094.",
4330 SCLogConfig(
"vlan %u connected to tenant-id %u", vlan_id, tenant_id);
4356 int failure_fatal = 0;
4357 (void)
ConfGetBool(
"engine.init-failure-fatal", &failure_fatal);
4360 (void)
ConfGetBool(
"multi-detect.enabled", &enabled);
4370 const char *handler = NULL;
4371 if (
ConfGet(
"multi-detect.selector", &handler) == 1) {
4372 SCLogConfig(
"multi-tenant selector type %s", handler);
4374 if (strcmp(handler,
"vlan") == 0) {
4378 if ((
ConfGetBool(
"vlan.use-for-tracking", &vlanbool)) == 1 && vlanbool == 0) {
4380 "can't use multi-detect selector 'vlan'");
4385 }
else if (strcmp(handler,
"direct") == 0) {
4387 }
else if (strcmp(handler,
"device") == 0) {
4390 SCLogWarning(
"multi-tenant 'device' mode not supported for IPS");
4397 "multi-detect.selector",
4404 SCLogConfig(
"multi-detect is enabled (multi tenancy). Selector: %s", handler);
4410 int mapping_cnt = DetectEngineMultiTenantSetupLoadVlanMappings(mappings_root_node,
4412 if (mapping_cnt == 0) {
4418 SCLogNotice(
"no tenant traffic mappings defined, "
4419 "tenants won't be used until mappings are added");
4421 if (failure_fatal) {
4422 SCLogError(
"no multi-detect mappings defined");
4430 int mapping_cnt = DetectEngineMultiTenantSetupLoadLivedevMappings(mappings_root_node,
4432 if (mapping_cnt == 0) {
4433 if (failure_fatal) {
4434 SCLogError(
"no multi-detect mappings defined");
4446 if (tenants_root_node != NULL) {
4447 const char *path = NULL;
4450 path = path_node->
val;
4456 if (id_node == NULL) {
4460 if (yaml_node == NULL) {
4464 uint32_t tenant_id = 0;
4466 &tenant_id, 10, (uint16_t)strlen(id_node->
val), id_node->
val) < 0) {
4474 char yaml_path[PATH_MAX] =
"";
4478 strlcpy(yaml_path, yaml_node->
val,
sizeof(yaml_path));
4485 snprintf(prefix,
sizeof(prefix),
"multi-detect.%u", tenant_id);
4487 SCLogError(
"failed to load yaml %s", yaml_path);
4491 int r = DetectLoaderSetupLoadTenant(tenant_id, yaml_path);
4512 SCLogDebug(
"multi-detect not enabled (multi tenancy)");
4519 static uint32_t DetectEngineTenantGetIdFromVlanId(
const void *
ctx,
const Packet *p)
4523 uint32_t vlan_id = 0;
4543 static uint32_t DetectEngineTenantGetIdFromLivedev(
const void *
ctx,
const Packet *p)
4548 if (ld == NULL || det_ctx == NULL)
4555 static int DetectEngineTenantRegisterSelector(
4562 SCLogInfo(
"conflicting selector already set");
4569 if (
m->traffic_id == traffic_id) {
4570 SCLogInfo(
"traffic id already registered");
4591 SCLogDebug(
"tenant handler %u %u %u registered", selector, tenant_id, traffic_id);
4596 static int DetectEngineTenantUnregisterSelector(
4620 SCLogInfo(
"tenant handler %u %u %u unregistered", selector, tenant_id, traffic_id);
4634 return DetectEngineTenantRegisterSelector(
4645 return DetectEngineTenantUnregisterSelector(
TENANT_SELECTOR_VLAN, tenant_id, (uint32_t)vlan_id);
4660 static uint32_t DetectEngineTenantGetIdFromPcap(
const void *
ctx,
const Packet *p)
4670 if (master->
list == NULL) {
4693 BUG_ON((*de_ctx)->ref_cnt == 0);
4694 (*de_ctx)->ref_cnt--;
4702 if (instance == NULL)
4705 if (master->
list == NULL) {
4706 master->
list = instance;
4709 master->
list = instance;
4726 r = DetectEngineAddToList(
de_ctx);
4734 if (instance == NULL) {
4739 if (instance ==
de_ctx) {
4743 instance = instance->
next;
4748 if (instance ==
de_ctx) {
4756 if (instance == NULL) {
4762 instance->
next = NULL;
4780 ret = DetectEngineMoveToFreeListNoLock(master,
de_ctx);
4804 SCLogDebug(
"freeing detect engine %p", instance);
4826 DetectEngineMoveToFreeListNoLock(master, instance);
4833 static int reloads = 0;
4848 memset(prefix, 0,
sizeof(prefix));
4853 snprintf(prefix,
sizeof(prefix),
"detect-engine-reloads.%d", reloads++);
4880 if (old_de_ctx == NULL)
4882 SCLogDebug(
"get ref to old_de_ctx %p", old_de_ctx);
4896 if (new_de_ctx == NULL) {
4908 SCLogDebug(
"set up new_de_ctx %p", new_de_ctx);
4917 SCLogDebug(
"going to reload the threads to use new_de_ctx %p", new_de_ctx);
4919 DetectEngineReloadThreads(new_de_ctx);
4920 SCLogDebug(
"threads now run new_de_ctx %p", new_de_ctx);
4929 SCLogDebug(
"old_de_ctx should have been freed");
4933 #ifdef HAVE_MALLOC_TRIM
4944 static uint32_t TenantIdHash(
HashTable *h,
void *data, uint16_t data_len)
4950 static char TenantIdCompare(
void *d1, uint16_t d1_len,
void *d2, uint16_t d2_len)
4957 static void TenantIdFree(
void *d)
4959 DetectEngineThreadCtxFree(d);
4975 for ( ; list != NULL; list = list->
next) {
4986 if (stub_de_ctx == NULL) {
4988 if (stub_de_ctx == NULL) {
4993 if (master->
list == NULL) {
4994 master->
list = stub_de_ctx;
4997 master->
list = stub_de_ctx;
5003 DetectEngineReloadThreads(stub_de_ctx);
5013 SCLogDebug(
"old_de_ctx should have been freed");
5017 static int g_parse_metadata = 0;
5021 g_parse_metadata = 1;
5026 g_parse_metadata = 0;
5031 return g_parse_metadata;
5040 return "packet/stream payload";
5046 return "base64_data";
5049 return "post-match";
5057 return "max (internal)";
5073 static int DetectEngineInitYamlConf(
const char *conf)
5080 static void DetectEngineDeInitYamlConf(
void)
5086 static int DetectEngineTest01(
void)
5092 " - profile: medium\n"
5093 " - custom-values:\n"
5094 " toclient_src_groups: 2\n"
5095 " toclient_dst_groups: 2\n"
5096 " toclient_sp_groups: 2\n"
5097 " toclient_dp_groups: 3\n"
5098 " toserver_src_groups: 2\n"
5099 " toserver_dst_groups: 4\n"
5100 " toserver_sp_groups: 2\n"
5101 " toserver_dp_groups: 25\n"
5102 " - inspection-recursion-limit: 0\n";
5104 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5113 DetectEngineDeInitYamlConf();
5118 static int DetectEngineTest02(
void)
5124 " - profile: medium\n"
5125 " - custom-values:\n"
5126 " toclient_src_groups: 2\n"
5127 " toclient_dst_groups: 2\n"
5128 " toclient_sp_groups: 2\n"
5129 " toclient_dp_groups: 3\n"
5130 " toserver_src_groups: 2\n"
5131 " toserver_dst_groups: 4\n"
5132 " toserver_sp_groups: 2\n"
5133 " toserver_dp_groups: 25\n"
5134 " - inspection-recursion-limit:\n";
5136 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5146 DetectEngineDeInitYamlConf();
5151 static int DetectEngineTest03(
void)
5157 " - profile: medium\n"
5158 " - custom-values:\n"
5159 " toclient_src_groups: 2\n"
5160 " toclient_dst_groups: 2\n"
5161 " toclient_sp_groups: 2\n"
5162 " toclient_dp_groups: 3\n"
5163 " toserver_src_groups: 2\n"
5164 " toserver_dst_groups: 4\n"
5165 " toserver_sp_groups: 2\n"
5166 " toserver_dp_groups: 25\n";
5168 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5178 DetectEngineDeInitYamlConf();
5183 static int DetectEngineTest04(
void)
5189 " - profile: medium\n"
5190 " - custom-values:\n"
5191 " toclient_src_groups: 2\n"
5192 " toclient_dst_groups: 2\n"
5193 " toclient_sp_groups: 2\n"
5194 " toclient_dp_groups: 3\n"
5195 " toserver_src_groups: 2\n"
5196 " toserver_dst_groups: 4\n"
5197 " toserver_sp_groups: 2\n"
5198 " toserver_dp_groups: 25\n"
5199 " - inspection-recursion-limit: 10\n";
5201 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5210 DetectEngineDeInitYamlConf();
5215 static int DetectEngineTest08(
void)
5221 " - profile: custom\n"
5222 " - custom-values:\n"
5223 " toclient-groups: 23\n"
5224 " toserver-groups: 27\n";
5226 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5236 DetectEngineDeInitYamlConf();
5242 static int DetectEngineTest09(
void)
5248 " - profile: custom\n"
5249 " - custom-values:\n"
5250 " toclient-groups: BA\n"
5251 " toserver-groups: BA\n"
5252 " - inspection-recursion-limit: 10\n";
5254 FAIL_IF(DetectEngineInitYamlConf(conf) == -1);
5264 DetectEngineDeInitYamlConf();
#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 ConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
struct DetectEngineThreadCtx_::@94 multi_inspect
@ DETECT_EVENT_TOO_MANY_BUFFERS
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)
#define PKT_PSEUDO_LOG_FLUSH
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 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
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.
struct DetectEngineThreadCtx_::@93 inspect
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
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.
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)
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)
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)
@ ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE
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
uint16_t base64_decode_max_len
#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.
struct DetectEnginePktInspectionEngine::@80 v1
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)
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
ConfNode * ConfNodeLookupChild(const ConfNode *node, const char *name)
Lookup a child configuration node by name.
struct PacketQueue_ * stream_pq
#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)
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)
struct DetectEngineFrameInspectionEngine::@81 v1
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...
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.
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
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
uint8_t guess_applayer_log_limit
int HashListTableRemove(HashListTable *ht, void *data, uint16_t datalen)
DetectEngineTransforms transforms
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.
@ ENGINE_SGH_MPM_FACTORY_CONTEXT_FULL
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.
struct DetectEngineAppInspectionEngine_::@77 v2
HashListTable * buffer_type_hash_id
DetectEngineCtx * DetectEngineGetByTenantId(uint32_t tenant_id)
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.
#define SIG_FLAG_REQUIRE_PACKET
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.