Go to the documentation of this file.
49 #define DETECT_PGSCORE_RULE_PORT_PRIORITIZED 111
50 #define DETECT_PGSCORE_RULE_MPM_FAST_PATTERN 99
51 #define DETECT_PGSCORE_RULE_MPM_NEGATED 77
52 #define DETECT_PGSCORE_RULE_NO_MPM 55
53 #define DETECT_PGSCORE_RULE_SYN_ONLY 33
85 if (s->id == sid && s->gid == gid)
197 static bool SignatureInspectsBuffers(
const Signature *s)
228 if (SignatureInspectsBuffers(s)) {
236 for (; sm != NULL; sm = sm->
next) {
247 for ( ; sm != NULL; sm = sm->
next) {
263 SCLogDebug(
"IP-ONLY (%" PRIu32
"): source %s, dest %s", s->
id,
286 if (SignatureInspectsBuffers(s)) {
301 for ( ; sm != NULL; sm = sm->
next) {
309 SCLogDebug(
"%u: not PD-only: flowbit settings other than 'set'", s->
id);
314 SCLogDebug(
"%u: not PD-only: flow settings other than toserver/toclient", s->
id);
367 if (SignatureInspectsBuffers(s)) {
373 for ( ;sm != NULL; sm = sm->
next) {
380 for ( ;sm != NULL; sm = sm->
next) {
393 SCLogDebug(
"DE-ONLY (%" PRIu32
"): source %s, dest %s", s->
id,
401 #define MASK_TCP_INITDEINIT_FLAGS (TH_SYN|TH_RST|TH_FIN)
402 #define MASK_TCP_UNUSUAL_FLAGS (TH_URG|TH_ECN|TH_CWR)
408 bool app_decoder_events)
424 if (p->
events.
cnt > 0 || app_decoder_events != 0 ||
431 const TCPHdr *tcph = PacketGetTCP(p);
446 static int SignatureCreateMask(
Signature *s)
470 SCLogDebug(
"SIG_FLAG_REQUIRE_FLOWVAR set as sig has "
471 "flowbit isset option.");
476 SCLogDebug(
"sig requires flow to be able to manipulate "
483 SCLogDebug(
"sig requires flow to be able to manipulate "
492 SCLogDebug(
"sig requires SIG_MASK_REQUIRE_FLAGS_INITDEINIT");
496 SCLogDebug(
"sig requires SIG_MASK_REQUIRE_FLAGS_UNUSUAL");
567 static bool RuleInspectsPayloadHasNoMpm(
const Signature *s)
574 static int RuleGetMpmPatternSize(
const Signature *s)
587 static bool RuleMpmIsNegated(
const Signature *s)
603 const int add_rules,
const int add_mpm_stats)
605 uint32_t prefilter_cnt = 0;
606 uint32_t mpm_cnt = 0;
607 uint32_t nonmpm_cnt = 0;
608 uint32_t mpm_depth_cnt = 0;
609 uint32_t mpm_endswith_cnt = 0;
610 uint32_t negmpm_cnt = 0;
611 uint32_t any5_cnt = 0;
612 uint32_t payload_no_mpm_cnt = 0;
613 uint32_t syn_cnt = 0;
615 uint32_t mpms_min = 0;
616 uint32_t mpms_max = 0;
625 } mpm_stats[max_buffer_type_id];
626 memset(mpm_stats, 0x00,
sizeof(mpm_stats));
630 uint32_t mpm_sizes[max_buffer_type_id][256];
631 memset(mpm_sizes, 0,
sizeof(mpm_sizes));
632 uint32_t alproto_mpm_bufs[
g_alproto_max][max_buffer_type_id];
633 memset(alproto_mpm_bufs, 0,
sizeof(alproto_mpm_bufs));
636 if (sgh->
init == NULL)
639 json_t *js = json_object();
643 json_object_set_new(js,
"id", json_integer(sgh->
id));
645 json_t *js_array = json_array();
647 for (uint32_t x = 0; x < sgh->
init->
sig_cnt; x++) {
677 SCLogDebug(
"SGH %p Non-MPM inspecting only packets. Rule %u", sgh, s->
id);
684 SCLogDebug(
"SGH %p Non-MPM toserver and to 'any'. Rule %u", sgh, s->
id);
687 SCLogDebug(
"SGH %p Non-MPM toclient and to 'any'. Rule %u", sgh, s->
id);
700 mpm_sizes[mpm_list][size]++;
701 alproto_mpm_bufs[s->
alproto][mpm_list]++;
708 if (dp->
port == 0 && dp->
port2 == 65535) {
709 SCLogDebug(
"SGH %p toserver 1byte fast_pattern to ANY. Rule %u", sgh, s->
id);
711 SCLogDebug(
"SGH %p toserver 1byte fast_pattern to port(s) %u-%u. Rule %u", sgh, dp->
port, dp->
port2, s->
id);
715 if (sp->
port == 0 && sp->
port2 == 65535) {
716 SCLogDebug(
"SGH %p toclient 1byte fast_pattern to ANY. Rule %u", sgh, s->
id);
718 SCLogDebug(
"SGH %p toclient 1byte fast_pattern to port(s) %u-%u. Rule %u", sgh, sp->
port, sp->
port2, s->
id);
732 BUG_ON(mpm_list >= max_buffer_type_id);
733 mpm_stats[mpm_list].total += w;
734 mpm_stats[mpm_list].cnt++;
735 if (mpm_stats[mpm_list].min == 0 || w < mpm_stats[mpm_list].min)
736 mpm_stats[mpm_list].min = w;
737 if (w > mpm_stats[mpm_list].max)
738 mpm_stats[mpm_list].max = w;
745 if (w < 10 && any == 5) {
761 if (RuleInspectsPayloadHasNoMpm(s)) {
762 SCLogDebug(
"SGH %p No MPM. Payload inspecting. Rule %u", sgh, s->
id);
763 payload_no_mpm_cnt++;
769 json_t *js_sig = json_object();
772 json_object_set_new(js_sig,
"sig_id", json_integer(s->
id));
773 json_array_append_new(js_array, js_sig);
777 json_object_set_new(js,
"rules", js_array);
779 json_t *stats = json_object();
780 json_object_set_new(stats,
"total", json_integer(sgh->
init->
sig_cnt));
782 json_t *types = json_object();
783 json_object_set_new(types,
"mpm", json_integer(mpm_cnt));
784 json_object_set_new(types,
"non_mpm", json_integer(nonmpm_cnt));
785 json_object_set_new(types,
"mpm_depth", json_integer(mpm_depth_cnt));
786 json_object_set_new(types,
"mpm_endswith", json_integer(mpm_endswith_cnt));
787 json_object_set_new(types,
"negated_mpm", json_integer(negmpm_cnt));
788 json_object_set_new(types,
"payload_but_no_mpm", json_integer(payload_no_mpm_cnt));
789 json_object_set_new(types,
"prefilter", json_integer(prefilter_cnt));
790 json_object_set_new(types,
"syn", json_integer(syn_cnt));
791 json_object_set_new(types,
"any5", json_integer(any5_cnt));
792 json_object_set_new(stats,
"types", types);
795 if (alstats[i] > 0) {
796 json_t *app = json_object();
797 json_object_set_new(app,
"total", json_integer(alstats[i]));
799 for (
int y = 0; y < max_buffer_type_id; y++) {
800 if (alproto_mpm_bufs[i][y] == 0)
809 json_object_set_new(app,
name, json_integer(alproto_mpm_bufs[i][y]));
813 json_object_set_new(stats, proto_name, app);
818 json_t *mpm_js = json_object();
820 for (
int i = 0; i < max_buffer_type_id; i++) {
821 if (mpm_stats[i].
cnt > 0) {
823 json_t *mpm_sizes_array = json_array();
824 for (
int y = 0; y < 256; y++) {
825 if (mpm_sizes[i][y] == 0)
828 json_t *e = json_object();
829 json_object_set_new(e,
"size", json_integer(y));
830 json_object_set_new(e,
"count", json_integer(mpm_sizes[i][y]));
831 json_array_append_new(mpm_sizes_array, e);
834 json_t *buf = json_object();
835 json_object_set_new(buf,
"total", json_integer(mpm_stats[i].
cnt));
836 json_object_set_new(buf,
"avg_strength", json_integer(mpm_stats[i].total / mpm_stats[i].
cnt));
837 json_object_set_new(buf,
"min_strength", json_integer(mpm_stats[i].min));
838 json_object_set_new(buf,
"max_strength", json_integer(mpm_stats[i].max));
840 json_object_set_new(buf,
"sizes", mpm_sizes_array);
848 json_object_set_new(mpm_js,
name, buf);
852 json_object_set_new(stats,
"mpm", mpm_js);
854 json_object_set_new(js,
"stats", stats);
856 json_object_set_new(js,
"score", json_integer(sgh->
init->
score));
862 const int add_rules,
const int add_mpm_stats)
864 json_t *js = json_object();
869 for (p = 0; p < 256; p++) {
870 if (p == IPPROTO_TCP || p == IPPROTO_UDP) {
871 const char *
name = (p == IPPROTO_TCP) ?
"tcp" :
"udp";
873 json_t *tcp = json_object();
875 json_t *ts_array = json_array();
878 while (list != NULL) {
879 json_t *port = json_object();
880 json_object_set_new(port,
"port", json_integer(list->
port));
881 json_object_set_new(port,
"port2", json_integer(list->
port2));
884 RulesGroupPrintSghStats(
de_ctx, list->
sh, add_rules, add_mpm_stats);
885 json_object_set_new(port,
"rulegroup", tcp_ts);
886 json_array_append_new(ts_array, port);
890 json_object_set_new(tcp,
"toserver", ts_array);
892 json_t *tc_array = json_array();
895 while (list != NULL) {
896 json_t *port = json_object();
897 json_object_set_new(port,
"port", json_integer(list->
port));
898 json_object_set_new(port,
"port2", json_integer(list->
port2));
901 RulesGroupPrintSghStats(
de_ctx, list->
sh, add_rules, add_mpm_stats);
902 json_object_set_new(port,
"rulegroup", tcp_tc);
903 json_array_append_new(tc_array, port);
907 json_object_set_new(tcp,
"toclient", tc_array);
909 json_object_set_new(js,
name, tcp);
910 }
else if (p == IPPROTO_ICMP || p == IPPROTO_ICMPV6) {
911 const char *
name = (p == IPPROTO_ICMP) ?
"icmpv4" :
"icmpv6";
912 json_t *o = json_object();
914 json_t *
ts = json_object();
915 json_t *group_ts = RulesGroupPrintSghStats(
917 json_object_set_new(
ts,
"rulegroup", group_ts);
918 json_object_set_new(o,
"toserver",
ts);
921 json_t *tc = json_object();
922 json_t *group_tc = RulesGroupPrintSghStats(
924 json_object_set_new(tc,
"rulegroup", group_tc);
925 json_object_set_new(o,
"toclient", tc);
927 json_object_set_new(js,
name, o);
931 const char *filename =
"rule_group.json";
933 char log_path[PATH_MAX] =
"";
935 snprintf(log_path,
sizeof(log_path),
"%s/%s", log_dir, filename);
937 FILE *fp = fopen(log_path,
"w");
942 char *js_s = json_dumps(js,
949 json_object_clear(js);
952 fprintf(fp,
"%s\n", js_s);
964 for ( ; s != NULL; s = s->
next) {
969 for (
int p = 0; p < 256; p++) {
970 if (p == IPPROTO_TCP || p == IPPROTO_UDP) {
995 for (p = 0; p < 256; p++) {
996 if (p == IPPROTO_TCP || p == IPPROTO_UDP)
998 if (sgh_ts[p] == NULL)
1004 if (lookup_sgh == NULL) {
1005 SCLogDebug(
"proto group %d sgh %p is the original", p, sgh_ts[p]);
1014 SCLogDebug(
"proto group %d sgh %p is a copy", p, sgh_ts[p]);
1017 sgh_ts[p] = lookup_sgh;
1021 SCLogPerf(
"OTHER %s: %u proto groups, %u unique SGH's, %u copies",
1022 "toserver",
cnt, own, ref);
1027 for (p = 0; p < 256; p++) {
1028 if (p == IPPROTO_TCP || p == IPPROTO_UDP)
1030 if (sgh_tc[p] == NULL)
1036 if (lookup_sgh == NULL) {
1037 SCLogDebug(
"proto group %d sgh %p is the original", p, sgh_tc[p]);
1047 SCLogDebug(
"proto group %d sgh %p is a copy", p, sgh_tc[p]);
1050 sgh_tc[p] = lookup_sgh;
1054 SCLogPerf(
"OTHER %s: %u proto groups, %u unique SGH's, %u copies",
1055 "toclient",
cnt, own, ref);
1057 for (p = 0; p < 256; p++) {
1058 if (p == IPPROTO_TCP || p == IPPROTO_UDP)
1071 if (ipproto == IPPROTO_UDP)
1099 if (!(p->
port == 0 && p->
port2 == 65535)) {
1101 if (RuleInspectsPayloadHasNoMpm(s)) {
1102 SCLogDebug(
"Rule %u MPM has 1 byte fast_pattern. Prioritizing SGH's.", s->
id);
1105 }
else if (RuleMpmIsNegated(s)) {
1106 SCLogDebug(
"Rule %u MPM is negated. Prioritizing SGH's.", s->
id);
1112 RuleGetMpmPatternSize(s) == 1) {
1113 SCLogDebug(
"Rule %u No MPM. Payload inspecting. Prioritizing SGH's.", s->
id);
1117 SCLogDebug(
"Rule %u Needs SYN, so inspected often. Prioritizing SGH's.", s->
id);
1126 static int SortCompare(
const void *a,
const void *b)
1153 static inline void SortGroupList(
1154 uint32_t *groups,
DetectPort **list,
int (*CompareFunc)(
const void *,
const void *))
1172 x->sh->id = idx + 1;
1175 x->
next = x->prev = x->last = NULL;
1182 qsort(array, idx,
sizeof(
DetectPort *), SortCompare);
1186 for (
int i = 0; i < idx; i++) {
1191 if (new_list == NULL) {
1208 SCLogDebug(
"item:= [%u:%u]; score: %d; sig_cnt: %d", tmp->port, tmp->port2,
1209 tmp->sh->init->score, tmp->sh->init->sig_cnt);
1227 DetectPort **newhead, uint32_t unique_groups,
1228 int (*CompareFunc)(
const void *,
const void *))
1231 uint32_t groups = 0;
1236 tmplist = port_list;
1237 SortGroupList(&groups, &tmplist, SortCompare);
1238 uint32_t left = unique_groups;
1245 DetectPort *tmplist2 = NULL, *tmplist2_tail = NULL;
1247 for (gr = tmplist; gr != NULL;) {
1256 if (joingr == NULL) {
1258 if (joingr == NULL) {
1261 SCLogDebug(
"joingr => %u-%u", joingr->port, joingr->port2);
1262 joingr->next = NULL;
1273 if (tmplist2 == NULL) {
1277 tmplist2_tail->
next = gr;
1289 if (joingr != NULL) {
1290 SCLogDebug(
"appending joingr %p %u:%u", joingr, joingr->port, joingr->port2);
1292 if (tmplist2 == NULL) {
1296 tmplist2_tail->
next = joingr;
1304 *newhead = tmplist2;
1312 #define UNDEFINED_PORT 0
1313 #define RANGE_PORT 1
1314 #define SINGLE_PORT 2
1333 static inline uint32_t SetUniquePortPoints(
1334 const DetectPort *p, uint8_t *unique_list, uint32_t size_list)
1369 static inline void SetFinalUniquePortPoints(
1370 const uint8_t *unique_list,
const uint32_t size_unique_arr,
UniquePortPoint *final_arr)
1372 for (uint32_t i = 0, j = 0; i < (UINT16_MAX + 1); i++) {
1375 final_arr[j].
port = (uint16_t)i;
1376 final_arr[j++].
single =
false;
1378 final_arr[j].
port = (uint16_t)i;
1379 final_arr[j++].
single =
true;
1406 if (final_unique_points == NULL)
1408 SetFinalUniquePortPoints(unique_list, size_list, final_unique_points);
1410 if (size_list == 1) {
1412 de_ctx, final_unique_points[0].port, final_unique_points[0].port, &it->
tree, list);
1416 uint16_t port = p1 ? p1->
port : 0;
1417 uint16_t port2 = p2->
port;
1418 for (uint32_t i = 1; i < size_list; i++) {
1424 }
else if (p1 && p1->
single) {
1426 if ((port2 > port + 1)) {
1428 de_ctx, port + 1, port2 - 1, &it->
tree, list);
1436 if ((port2 >= port + 1)) {
1443 if ((port2 > port + 1)) {
1454 if (port == p2->
port) {
1459 if (i + 1 < size_list) {
1460 p2 = &final_unique_points[i + 1];
1466 SCFree(final_unique_points);
1477 uint32_t size_unique_port_arr = 0;
1481 uint8_t *unique_port_points = (uint8_t *)
SCCalloc(UINT16_MAX + 1,
sizeof(uint8_t));
1482 if (unique_port_points == NULL)
1508 "w/o direction specified, disabling for toclient direction",
1536 size_unique_port_arr =
1537 SetUniquePortPoints(tmp2, unique_port_points, size_unique_port_arr);
1560 SCLogDebug(
"Port was not inserted in the tree");
1567 if (CreatePortList(
de_ctx, unique_port_points, size_unique_port_arr, it, &list) < 0)
1571 SCFree(unique_port_points);
1582 CreateGroupedPortList(
de_ctx, list, &newlist, groupmax, SortCompare);
1593 for (iter = list ; iter != NULL; iter = iter->
next) {
1599 if (lookup_sgh == NULL) {
1600 SCLogDebug(
"port group %p sgh %p is the original", iter, iter->
sh);
1610 SCLogDebug(
"port group %p sgh %p is a copy", iter, iter->
sh);
1613 iter->
sh = lookup_sgh;
1619 for (iter = list ; iter != NULL; iter = iter->
next) {
1620 SCLogInfo(
"PORT %u-%u %p (sgh=%s, prioritized=%s/%d)",
1627 SCLogPerf(
"%s %s: %u port groups, %u unique SGH's, %u copies",
1628 ipproto == 6 ?
"TCP" :
"UDP",
1635 if (unique_port_points != NULL)
1636 SCFree(unique_port_points);
1649 if (SignatureIsPDOnly(
de_ctx, s) == 1) {
1656 }
else if (iponly == 2) {
1659 }
else if (SignatureIsDEOnly(
de_ctx, s) == 1) {
1665 bool has_buffer_frame_engine =
false;
1666 bool has_buffer_packet_engine =
false;
1667 bool has_buffer_app_engine =
false;
1673 has_buffer_packet_engine =
true;
1675 has_buffer_frame_engine =
true;
1677 has_buffer_app_engine =
true;
1681 if (has_buffer_packet_engine) {
1683 }
else if (has_buffer_frame_engine || has_buffer_app_engine) {
1685 }
else if (has_pmatch) {
1695 }
else if (has_match) {
1718 uint32_t cnt_iponly = 0;
1719 uint32_t cnt_payload = 0;
1720 uint32_t cnt_applayer = 0;
1721 uint32_t cnt_deonly = 0;
1724 SCLogDebug(
"building signature grouping structure, stage 1: "
1725 "preprocessing rules...");
1740 SCLogDebug(
"Signature %"PRIu32
" is considered \"PD only\"", s->
id);
1742 SCLogDebug(
"Signature %"PRIu32
" is considered \"IP only\"", s->
id);
1744 }
else if (SignatureIsInspectingPayload(
de_ctx, s) == 1) {
1745 SCLogDebug(
"Signature %"PRIu32
" is considered \"Payload inspecting\"", s->
id);
1748 SCLogDebug(
"Signature %"PRIu32
" is considered \"Decoder Event only\"", s->
id);
1751 SCLogDebug(
"Signature %"PRIu32
" is considered \"Applayer inspecting\"", s->
id);
1771 if (copresent && colen == 1) {
1781 if (RuleMpmIsNegated(s)) {
1785 SignatureCreateMask(s);
1803 prefilter_list =
MIN(prefilter_list, sm->
type);
1813 if (sm->
type == prefilter_list) {
1838 SCLogInfo(
"tenant id %d: %" PRIu32
" signatures processed. %" PRIu32
" are IP-only "
1839 "rules, %" PRIu32
" are inspecting packet payload, %" PRIu32
1840 " inspect application layer, %" PRIu32
" are decoder event only",
1844 SCLogInfo(
"%" PRIu32
" signatures processed. %" PRIu32
" are IP-only "
1845 "rules, %" PRIu32
" are inspecting packet payload, %" PRIu32
1846 " inspect application layer, %" PRIu32
" are decoder event only",
1847 de_ctx->
sig_cnt, cnt_iponly, cnt_payload, cnt_applayer, cnt_deonly);
1849 SCLogConfig(
"building signature grouping structure, stage 1: "
1850 "preprocessing rules... complete");
1868 SCLogDebug(
"adding signature %"PRIu32
" to the decoder event sgh", s->
id);
1883 SCLogDebug(
"building signature grouping structure, stage 2: "
1884 "building source address lists...");
1894 RulesGroupByIPProto(
de_ctx);
1902 DetectEngineAddDecoderEventSig(
de_ctx, s);
1924 DetectEngineBuildDecoderEventSgh(
de_ctx);
1932 SCLogDebug(
"cleaning up signature grouping structure...");
1939 for (
int p = 0; p < 256; p++) {
1965 SCLogDebug(
"cleaning up signature grouping structure... complete");
1978 for (sig = 0; sig < sgh->sig_cnt; sig++) {
1979 printf(
"%" PRIu32
" ", sgh->match_array[sig]->
id);
1986 if (sgh == NULL || sgh->
init == NULL) {
2036 int dump_grouping = 0;
2037 (void)
ConfGetBool(
"detect.profiling.grouping.dump-to-disk", &dump_grouping);
2039 if (dump_grouping) {
2041 (void)
ConfGetBool(
"detect.profiling.grouping.include-rules", &add_rules);
2042 int add_mpm_stats = 0;
2043 (void)
ConfGetBool(
"detect.profiling.grouping.include-mpm-stats", &add_mpm_stats);
2045 RulesDumpGrouping(
de_ctx, add_rules, add_mpm_stats);
2078 for (; s != NULL; s = s->
next) {
2100 while (sm != NULL) {
2116 while (sm != NULL) {
2165 SigInitStandardMpmFactoryContexts(
de_ctx);
2168 FatalError(
"initializing the detection engine failed");
2172 FatalError(
"initializing the detection engine failed");
2176 FatalError(
"initializing the detection engine failed");
2179 FatalError(
"initializing the detection engine failed");
2187 FatalError(
"initializing the detection engine failed");
2190 if (SigMatchPrepare(
de_ctx) != 0) {
2191 FatalError(
"initializing the detection engine failed");
2200 if (
ConfGetInt(
"detect.profiling.inspect-logging-threshold", &v) == 1)
2203 #ifdef PROFILE_RULES
2204 SCProfilingRuleInitCounters(
de_ctx);
#define HashListTableGetListData(hb)
#define DETECT_FLOW_FLAG_TOCLIENT
int ConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
void DetectEngineResetMaxSigId(DetectEngineCtx *de_ctx)
bool DetectEngineBufferTypeSupportsPacketGetById(const DetectEngineCtx *de_ctx, const int id)
#define SIG_MASK_REQUIRE_REAL_PKT
#define MASK_TCP_UNUSUAL_FLAGS
int DetectFlagsSignatureNeedsSynOnlyPackets(const Signature *s)
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
SigTableElmt * sigmatch_table
void SigMatchFree(DetectEngineCtx *de_ctx, SigMatch *sm)
free a SigMatch
void(* Free)(DetectEngineCtx *, void *)
struct SigGroupHead_ * decoder_event_sgh
int DetectPortHashInit(DetectEngineCtx *de_ctx)
Initializes the hash table in the detection engine context to hold the DetectPort hash.
DetectEngineLookupFlow flow_gh[FLOW_STATES]
#define FILE_SIG_NEED_SHA1
int SigPrepareStage4(DetectEngineCtx *de_ctx)
finalize preparing sgh's
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
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.
Container for matching data for a signature group.
const char * DetectListToHumanString(int list)
#define SIG_FLAG_INIT_FLOW
void SigFree(DetectEngineCtx *, Signature *)
void DumpPatterns(DetectEngineCtx *de_ctx)
int SigGroupHeadBuildNonPrefilterArray(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
build an array of rule id's for sigs with no prefilter Also updated de_ctx::non_pf_store_cnt_max to t...
void DetectPortFree(const DetectEngineCtx *de_ctx, DetectPort *dp)
Free a DetectPort and its members.
uint16_t max_uniq_toclient_groups
void MpmStoreReportStats(const DetectEngineCtx *de_ctx)
bool src_contains_negation
void IPOnlyDeinit(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx)
Deinitialize the IP Only detection engine context.
struct HtpBodyChunk_ * next
void SCPortIntervalFindOverlappingRanges(DetectEngineCtx *de_ctx, const uint16_t port, const uint16_t port2, const struct PI *head, DetectPort **list)
Callee function to find all overlapping port ranges as asked by the detection engine during Stage 2 o...
#define PORT_SIGGROUPHEAD_COPY
@ DETECT_SM_LIST_DYNAMIC_START
uint32_t PatternStrength(uint8_t *pat, uint16_t patlen)
Predict a strength value for patterns.
int DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx)
int DetectSetFastPatternAndItsId(DetectEngineCtx *de_ctx)
Figure out the FP and their respective content ids for all the sigs in the engine.
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
void SCProfilingSghInitCounters(DetectEngineCtx *de_ctx)
Register the keyword profiling counters.
main detection engine ctx
int DetectFlagsSignatureNeedsSynPackets(const Signature *s)
HashListTableBucket * HashListTableGetListHead(HashListTable *ht)
void SigGroupHeadSetProtoAndDirection(SigGroupHead *sgh, uint8_t ipproto, int dir)
#define SIGMATCH_DEONLY_COMPAT
const char * DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
void DetectMpmInitializeBuiltinMpms(DetectEngineCtx *de_ctx)
#define SIG_FLAG_REQUIRE_STREAM
bool rule_engine_analysis_set
struct DetectPort_ * next
DetectPort * tcp_priorityports
HashListTable * dport_hash_table
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
enum DetectEnginePrefilterSetting prefilter_setting
#define JSON_ESCAPE_SLASH
struct SigGroupHead_ * sh
DetectPort * udp_priorityports
#define DETECT_FLOWBITS_CMD_ISSET
#define PKT_NOPAYLOAD_INSPECTION
void SigCleanSignatures(DetectEngineCtx *de_ctx)
void DetectPortPrintList(DetectPort *head)
Helper function used to print the list of ports present in this DetectPort list.
int SigPrepareStage1(DetectEngineCtx *de_ctx)
Preprocess signature, classify ip-only, etc, build sig array.
#define DETECT_PGSCORE_RULE_SYN_ONLY
#define SIG_FLAG_TOCLIENT
void SigGroupHeadSetupFiles(const DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Set the need hash flag in the sgh.
int SignatureIsFilesizeInspecting(const Signature *s)
Check if a signature contains the filesize keyword.
AppLayerDecoderEvents * app_layer_events
PacketEngineEvents events
void EngineAnalysisAddAllRulePatterns(DetectEngineCtx *de_ctx, const Signature *s)
add all patterns on our stats hash Used to fill the hash later used by DumpPatterns()
void DetectPortPrint(DetectPort *dp)
Helper function that print the DetectPort info.
void PacketCreateMask(Packet *p, SignatureMask *mask, AppProto alproto, bool app_decoder_events)
#define SIG_FLAG_APPLAYER
int SigGroupHeadHashInit(DetectEngineCtx *de_ctx)
Initializes the hash table in the detection engine context to hold the SigGroupHeads.
#define FILE_SIG_NEED_MD5
int SignatureIsFileSha256Inspecting(const Signature *s)
Check if a signature contains the filesha256 keyword.
int DetectEngineMultiTenantEnabled(void)
#define HashListTableGetListNext(hb)
@ DETECT_APP_LAYER_PROTOCOL
@ DETECT_SM_LIST_POSTMATCH
DetectPort * DetectPortCopySingle(DetectEngineCtx *de_ctx, DetectPort *src)
Function that return a copy of DetectPort src sigs.
#define SIG_FLAG_TOSERVER
int DetectPortParse(const DetectEngineCtx *de_ctx, DetectPort **head, const char *str)
Function for parsing port strings.
int SigAddressCleanupStage1(DetectEngineCtx *de_ctx)
int SCPortIntervalInsert(DetectEngineCtx *de_ctx, SCPortIntervalTree *it, const DetectPort *p)
Function to insert a node in the interval tree.
int SigGroupHeadBuildMatchArray(DetectEngineCtx *de_ctx, SigGroupHead *sgh, uint32_t max_idx)
Create an array with all the internal ids of the sigs that this sig group head will check for.
#define DETECT_CONTENT_ENDS_WITH
void IPOnlyInit(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx)
Setup the IP Only detection engine context.
#define SIG_MASK_REQUIRE_ENGINE_EVENT
Signature * SigFindSignatureBySidGid(DetectEngineCtx *de_ctx, uint32_t sid, uint32_t gid)
Find a specific signature by sid and gid.
#define DetectEngineGetMaxSigId(de_ctx)
#define DETECT_FLOW_FLAG_TOSERVER
#define FILE_SIG_NEED_MAGIC
#define SIG_MASK_REQUIRE_FLOW
IPOnlyCIDRItem * cidr_dst
#define DETECT_CONTENT_DEPTH
struct SigGroupHead_ * sgh[256]
#define SIG_MASK_REQUIRE_FLAGS_INITDEINIT
void SCProfilingPrefilterInitCounters(DetectEngineCtx *de_ctx)
Register the prefilter profiling counters.
SigMatchData * SigMatchList2DataArray(SigMatch *head)
convert SigMatch list to SigMatchData array
#define PKT_DETECT_HAS_STREAMDATA
#define DETECT_CONTENT_NEGATED
#define SCLogWarning(...)
Macro used to log WARNING messages.
void DetectContentPropagateLimits(Signature *s)
Port structure for detection engine.
SigGroupHeadInitData * init
#define DETECT_PGSCORE_RULE_NO_MPM
IPOnlyCIDRItem * cidr_src
void IPOnlyPrepare(DetectEngineCtx *de_ctx)
Build the radix trees from the lists of parsed addresses in CIDR format the result should be 4 radix ...
int SigGroupCleanup(DetectEngineCtx *de_ctx)
#define DETECT_PGSCORE_RULE_MPM_FAST_PATTERN
#define SIG_FLAG_REQUIRE_FLOWVAR
#define FILE_SIG_NEED_SHA256
void IPOnlyPrint(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx)
Print stats of the IP Only engine.
uint16_t max_uniq_toserver_groups
void IPOnlyAddSignature(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx, Signature *s)
Add a signature to the lists of Addresses in CIDR format (sorted) this step is necessary to build the...
SignatureInitData * init_data
int SigGroupHeadAppendSig(const DetectEngineCtx *de_ctx, SigGroupHead **sgh, const Signature *s)
Add a Signature to a SigGroupHead.
struct SigGroupHead_ ** sgh_array
bool dst_contains_negation
void SigGroupHeadFree(const DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Free a SigGroupHead and its members.
#define SIG_MASK_REQUIRE_PAYLOAD
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
int SignatureIsFileSha1Inspecting(const Signature *s)
Check if a signature contains the filesha1 keyword.
SCPortIntervalTree * SCPortIntervalTreeInit(void)
Function to initialize the interval tree.
void IPOnlyCIDRListFree(IPOnlyCIDRItem *tmphead)
This function free a IPOnlyCIDRItem list.
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
#define SIG_FLAG_INIT_STATE_MATCH
bool DetectEngineBufferTypeSupportsFramesGetById(const DetectEngineCtx *de_ctx, const int id)
void EngineAnalysisRules2(const DetectEngineCtx *de_ctx, const Signature *s)
void SigGroupHeadSetSigCnt(SigGroupHead *sgh, uint32_t max_idx)
Updates the SigGroupHead->sig_cnt with the total count of all the Signatures present in this SigGroup...
int DetectMpmPrepareFrameMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for applayer buffers that are in "single or "shared" mode.
int DetectEnginePktInspectionSetup(Signature *s)
#define SIG_MASK_REQUIRE_NO_PAYLOAD
void SigGroupHeadStore(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
int SigPrepareStage3(DetectEngineCtx *de_ctx)
struct DetectPort_ * prev
#define MASK_TCP_INITDEINIT_FLAGS
const char * DetectListToString(int list)
uint32_t profile_match_logging_threshold
int DetectMpmPreparePktMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for applayer buffers that are in "single or "shared" mode.
void SigGroupHeadHashFree(DetectEngineCtx *de_ctx)
Frees the hash table - DetectEngineCtx->sgh_hash_table, allocated by SigGroupHeadHashInit() function.
#define SIG_MASK_REQUIRE_FLAGS_UNUSUAL
int SigGroupHeadHashAdd(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Adds a SigGroupHead to the detection engine context SigGroupHead hash table.
int SigPrepareStage2(DetectEngineCtx *de_ctx)
Fill the global src group head, with the sigs included.
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
SignatureInitDataBuffer * buffers
const char * ConfigGetLogDirectory(void)
struct HtpBodyChunk_ * next
SigGroupHead * SigGroupHeadHashLookup(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Used to lookup a SigGroupHead hash from the detection engine context SigGroupHead hash table.
#define DETECT_PGSCORE_RULE_PORT_PRIORITIZED
int SignatureIsFilestoring(const Signature *s)
Check if a signature contains the filestore keyword.
int SignatureIsIPOnly(DetectEngineCtx *de_ctx, const Signature *s)
Test is a initialized signature is IP only.
bool(* SupportsPrefilter)(const Signature *s)
int DetectMpmPrepareBuiltinMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for builtin buffers that are in "single or "shared" mode.
a single match condition for a signature
void SigGroupHeadInitDataFree(SigGroupHeadInitData *sghid)
int SignatureIsFileMd5Inspecting(const Signature *s)
Check if a signature contains the filemd5 keyword.
#define DETECT_PGSCORE_RULE_MPM_NEGATED
void SignatureSetType(DetectEngineCtx *de_ctx, Signature *s)
void SCProfilingKeywordInitCounters(DetectEngineCtx *de_ctx)
Register the keyword profiling counters.
int DetectPortHashAdd(DetectEngineCtx *de_ctx, DetectPort *dp)
Adds a DetectPort to the detection engine context DetectPort hash table.
void PrefilterSetupRuleGroup(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
void SigParseApplyDsizeToContent(Signature *s)
Apply dsize as depth to content matches in the rule.
struct UniquePortPoint_ UniquePortPoint
DetectEngineTransforms transforms
DetectEngineIPOnlyCtx io_ctx
DetectUintData_u16 DetectU16Data
void DetectPortHashFree(DetectEngineCtx *de_ctx)
Frees the hash table - DetectEngineCtx->sgh_hash_table, allocated by DetectPortInit() function.
DetectPort * DetectPortHashLookup(DetectEngineCtx *de_ctx, DetectPort *dp)
Used to lookup a DetectPort hash from the detection engine context DetectPort hash table.
int SignatureIsFilemagicInspecting(const Signature *s)
Check if a signature contains the filemagic keyword.
int DetectMpmPrepareAppMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for applayer buffers that are in "single or "shared" mode.
#define SIGMATCH_IPONLY_COMPAT
void DetectPortCleanupList(const DetectEngineCtx *de_ctx, DetectPort *head)
Free a DetectPort list and each of its members.
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
#define DEBUG_VALIDATE_BUG_ON(exp)
int DetectEngineAppInspectionEngine2Signature(DetectEngineCtx *de_ctx, Signature *s)
#define SIG_FLAG_PREFILTER
void SCPortIntervalTreeFree(DetectEngineCtx *de_ctx, SCPortIntervalTree *it)
Function to free an entire interval tree.
int VarNameStoreActivate(void)
#define SIG_FLAG_FILESTORE
#define FILE_SIG_NEED_SIZE
#define DETECT_FLOWBITS_CMD_SET
int SigGroupHeadCopySigs(DetectEngineCtx *de_ctx, SigGroupHead *src, SigGroupHead **dst)
Copies the bitarray holding the sids from the source SigGroupHead to the destination SigGroupHead.
#define SIG_FLAG_REQUIRE_PACKET