Go to the documentation of this file.
87 static inline void DetectRulePacketRules(
ThreadVars *
const tv,
126 DetectRunInspectIPOnly(th_v,
de_ctx, det_ctx, pflow, p);
129 DetectRunGetRuleGroup(
de_ctx, p, pflow, &scratch);
132 if (scratch.
sgh == NULL) {
133 SCLogDebug(
"no sgh for this packet, nothing to match against");
138 DetectRunPrefilterPkt(th_v,
de_ctx, det_ctx, p, &scratch);
142 DetectRulePacketRules(th_v,
de_ctx, det_ctx, p, pflow, &scratch);
147 if (p->
proto == IPPROTO_TCP) {
160 DetectRunFrames(th_v,
de_ctx, det_ctx, p, pflow, &scratch);
169 }
else if (p->
proto == IPPROTO_UDP) {
170 DetectRunFrames(th_v,
de_ctx, det_ctx, p, pflow, &scratch);
174 DetectRunTx(th_v,
de_ctx, det_ctx, p, pflow, &scratch);
184 DetectRunPostRules(th_v,
de_ctx, det_ctx, p, pflow, &scratch);
186 DetectRunCleanup(det_ctx, p, pflow);
199 SCLogDebug(
"running match functions, sm %p", smd);
230 }
else if (p->
proto == 0) {
231 if (!(PacketIsIPv4(p) || PacketIsIPv6(p))) {
240 int proto = PacketGetIPProto(p);
241 if (
proto == IPPROTO_TCP) {
245 const uint16_t port = dir ? p->
dp : p->
sp;
250 SCLogDebug(
"TCP list %p, port %u, direction %s, sghport %p, sgh %p", list, port,
251 dir ?
"toserver" :
"toclient", sghport, sgh);
252 }
else if (
proto == IPPROTO_UDP) {
254 uint16_t port = dir ? p->
dp : p->
sp;
258 SCLogDebug(
"UDP list %p, port %u, direction %s, sghport %p, sgh %p", list, port,
259 dir ?
"toserver" :
"toclient", sghport, sgh);
290 final_ptr = nonmpm_ptr;
295 nonmpm = *nonmpm_ptr;
309 if (
likely(
id != previous_id)) {
315 final_ptr = nonmpm_ptr;
321 }
else if (mpm > nonmpm) {
326 if (
likely(
id != previous_id)) {
336 nonmpm = *nonmpm_ptr;
342 while (--m_cnt != 0) {
353 final_ptr = ++nonmpm_ptr;
368 nonmpm = *nonmpm_ptr;
374 while (final_cnt-- > 0) {
379 if (
likely(
id != previous_id)) {
393 static inline void DetectPrefilterBuildNonPrefilterList(
401 if ((rule_mask & mask) == rule_mask &&
402 (rule_alproto == 0 || AppProtoEquals(rule_alproto, alproto))) {
415 if ((p->
proto == IPPROTO_TCP) && PacketIsTCP(p) && (PacketGetTCP(p)->th_flags &
TH_SYN)) {
422 SCLogDebug(
"sgh non_pf ptr %p cnt %u (syn %p/%u, other %p/%u)",
434 DetectPostInspectFileFlagsUpdate(
Flow *f,
const SigGroupHead *sgh, uint8_t direction)
439 SCLogDebug(
"requesting disabling all file features for flow");
443 SCLogDebug(
"requesting disabling filestore for flow");
447 if (!(sgh->
flags & SIG_GROUP_HEAD_HAVEFILEMAGIC)) {
448 SCLogDebug(
"requesting disabling magic for flow");
453 SCLogDebug(
"requesting disabling md5 for flow");
457 SCLogDebug(
"requesting disabling sha1 for flow");
461 SCLogDebug(
"requesting disabling sha256 for flow");
465 SCLogDebug(
"requesting disabling filesize for flow");
469 if (flow_file_flags != 0) {
485 SCLogDebug(
"STREAMTCP_STREAM_FLAG_DISABLE_RAW ssn.client");
490 DetectPostInspectFileFlagsUpdate(pflow,
500 SCLogDebug(
"STREAMTCP_STREAM_FLAG_DISABLE_RAW ssn.server");
505 DetectPostInspectFileFlagsUpdate(pflow,
510 static inline void DetectRunGetRuleGroup(
518 bool use_flow_sgh =
false;
521 if (PacketGetIPProto(p) == pflow->
proto) {
525 SCLogDebug(
"sgh = pflow->sgh_toserver; => %p", sgh);
529 SCLogDebug(
"sgh = pflow->sgh_toclient; => %p", sgh);
535 if (!(use_flow_sgh)) {
548 DetectRunPostGetFirstRuleGroup(p, pflow, sgh);
576 SCLogDebug(
"testing against \"ip-only\" signatures");
598 static inline bool DetectRunInspectRuleHeader(
const Packet *p,
const Flow *f,
const Signature *s,
599 const uint32_t sflags,
const uint8_t s_proto_flags)
608 const bool fv = f->
flowvar != NULL;
610 SCLogDebug(
"skipping sig as the flow has no flowvars and sig "
611 "has SIG_FLAG_REQUIRE_FLOWVAR flag set.");
651 SCLogDebug(
"port-less protocol and sig needs ports");
657 if (PacketIsIPv4(p)) {
660 }
else if (PacketIsIPv6(p)) {
667 if (PacketIsIPv4(p)) {
670 }
else if (PacketIsIPv6(p)) {
682 static inline void DetectRunPrefilterPkt(
690 DetectPrefilterSetNonPrefilterList(p, det_ctx, scratch);
699 DetectPrefilterBuildNonPrefilterList(det_ctx, scratch->
pkt_mask, scratch->
alproto);
713 DetectPrefilterMergeSort(
de_ctx, det_ctx);
728 static inline void DetectRulePacketRules(
745 (uint64_t)match_cnt);
756 uint32_t sflags, next_sflags = 0;
758 next_s = *match_array++;
759 next_sflags = next_s->
flags;
761 while (match_cnt--) {
763 uint8_t alert_flags = 0;
768 sflags = next_sflags;
770 next_s = *match_array++;
771 next_sflags = next_s->
flags;
795 if (SigDsizePrefilter(p, s, sflags))
806 if (DetectRunInspectRuleHeader(p, pflow, s, sflags, s_proto_flags) ==
false) {
817 DetectRunPostMatch(
tv, det_ctx, p, s);
836 if (pflow->
proto != IPPROTO_UDP) {
839 txd->guessed_applayer_logged++;
845 DetectVarProcessList(det_ctx, pflow, p);
846 DetectReplaceFree(det_ctx);
858 uint8_t flow_flags = 0;
859 bool app_decoder_events =
false;
878 det_ctx->pkt_stream_add_cnt++;
887 flow_flags = STREAM_TOSERVER;
890 flow_flags = STREAM_TOCLIENT;
896 flow_flags |= STREAM_EOF;
927 (p->
proto == IPPROTO_UDP) ||
932 alproto = FlowGetAppProtocol(pflow);
939 SCLogDebug(
"packet doesn't have established flag set (proto %d)", p->
proto);
950 static inline void DetectRunPostRules(
999 FatalError(
"failed to allocate %" PRIu64
" bytes",
1003 SCLogDebug(
"array initialized to %u elements (%"PRIu64
" bytes)",
1015 const uint32_t need)
1026 uint32_t new_size = needed;
1029 FatalError(
"failed to expand to %" PRIu64
" bytes",
1035 SCLogDebug(
"array expanded from %u to %u elements (%"PRIu64
" bytes -> %"PRIu64
" bytes)",
1048 DetectRunTxSortHelper(
const void *a,
const void *b)
1052 if (s1->
id == s0->
id) {
1059 return s0->
id > s1->
id ? 1 : -1;
1063 #define TRACE_SID_TXS(sid,txs,...) \
1065 char _trace_buf[2048]; \
1066 snprintf(_trace_buf, sizeof(_trace_buf), __VA_ARGS__); \
1067 SCLogNotice("%p/%"PRIu64"/%u: %s", txs->tx_ptr, txs->tx_id, sid, _trace_buf); \
1070 #define TRACE_SID_TXS(sid,txs,...)
1079 tx_ptr = SCDoH2GetDnsTx(tx_ptr, flow_flags);
1084 }
else if (engine_alproto != alproto) {
1108 const uint8_t in_flow_flags,
1112 uint32_t *stored_flags,
1116 const uint8_t flow_flags = in_flow_flags;
1117 const int direction = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1118 uint32_t inspect_flags = stored_flags ? *stored_flags : 0;
1119 int total_matches = 0;
1120 uint16_t file_no_match = 0;
1121 bool retval =
false;
1122 bool mpm_before_progress =
false;
1123 bool mpm_in_progress =
false;
1125 TRACE_SID_TXS(s->
id, tx,
"starting %s", direction ?
"toclient" :
"toserver");
1128 if (
likely(stored_flags == NULL)) {
1130 if (DetectRunInspectRuleHeader(p, f, s, s->
flags, s->
proto.
flags) ==
false) {
1147 TRACE_SID_TXS(s->
id, tx,
"engine %p inspect_flags %x", engine, inspect_flags);
1148 if (!(inspect_flags &
BIT_U32(engine->
id)) &&
1149 direction == engine->
dir)
1152 if (tx_ptr == NULL) {
1156 engine = engine->
next;
1166 SCLogDebug(
"tx progress %d < engine progress %d",
1173 "engine->mpm: t->tx_progress %u > engine->progress %u, so set "
1174 "mpm_before_progress",
1176 mpm_before_progress =
true;
1179 "engine->mpm: t->tx_progress %u == engine->progress %u, so set "
1182 mpm_in_progress =
true;
1190 TRACE_SID_TXS(s->
id, tx,
"stream skipped, stored result %d used instead", match);
1195 de_ctx, det_ctx, engine, s, f, flow_flags, alstate, tx_ptr, tx->
tx_id);
1200 TRACE_SID_TXS(s->
id, tx,
"stream ran, store result %d for next tx (if any)", match);
1205 engine = engine->
next;
1212 engine = engine->
next;
1224 if (engine->
mpm && mpm_before_progress) {
1230 engine = engine->
next;
1231 }
while (engine != NULL);
1232 TRACE_SID_TXS(s->
id, tx,
"inspect_flags %x, total_matches %u, engine %p",
1233 inspect_flags, total_matches, engine);
1235 if (engine == NULL && total_matches) {
1242 *stored_flags = inspect_flags;
1243 TRACE_SID_TXS(s->
id, tx,
"continue inspect flags %08x", inspect_flags);
1250 if (file_no_match) {
1261 inspect_flags, flow_flags, file_no_match);
1265 "mpm won't trigger for it anymore");
1269 "we may have to revisit anyway");
1271 inspect_flags, flow_flags, file_no_match);
1275 "mpm will revisit it");
1276 }
else if (inspect_flags != 0 || file_no_match != 0) {
1279 inspect_flags, flow_flags, file_no_match);
1288 NULL, 0, NULL, NULL, 0, 0, 0, 0, 0, \
1296 void *alstate,
const uint64_t tx_id,
void *tx_ptr,
const int tx_end_state,
1297 const uint8_t flow_flags)
1305 bool updated = (flow_flags & STREAM_TOSERVER) ? txd->updated_ts : txd->updated_tc;
1306 if (!updated && tx_progress < tx_end_state && ((flow_flags & STREAM_EOF) == 0)) {
1310 uint64_t detect_flags =
1311 (flow_flags & STREAM_TOSERVER) ? txd->detect_flags_ts : txd->detect_flags_tc;
1313 SCLogDebug(
"%"PRIu64
" tx already fully inspected for %s. Flags %016"PRIx64,
1314 tx_id, flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient",
1320 SCLogDebug(
"%" PRIu64
" tx should not be inspected in direction %s. Flags %016" PRIx64,
1321 tx_id, flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", detect_flags);
1326 const int dir_int = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1336 .de_state = tx_dir_state,
1337 .detect_flags = detect_flags,
1338 .prefilter_flags = prefilter_flags,
1339 .prefilter_flags_orig = prefilter_flags,
1340 .tx_progress = tx_progress,
1341 .tx_end_state = tx_end_state,
1346 static inline void StoreDetectFlags(
DetectTransaction *tx,
const uint8_t flow_flags,
1347 const uint8_t ipproto,
const AppProto alproto,
const uint64_t detect_flags)
1350 if (
likely(txd != NULL)) {
1351 if (flow_flags & STREAM_TOSERVER) {
1352 txd->detect_flags_ts = detect_flags;
1354 txd->detect_flags_tc = detect_flags;
1361 static inline void RuleMatchCandidateMergeStateRules(
1379 uint32_t j = *array_idx;
1388 uint32_t k = *array_idx;
1410 if (s->
num <= s0->
id) {
1441 const uint8_t flow_flags = scratch->
flow_flags;
1443 void *
const alstate = f->
alstate;
1444 const uint8_t ipproto = f->
proto;
1455 AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, tx_id_min, total_txs, &state);
1456 if (ires.tx_ptr == NULL)
1460 alstate, ires.tx_id, ires.tx_ptr, tx_end_state, flow_flags);
1462 SCLogDebug(
"%p/%"PRIu64
" no transaction to inspect",
1468 tx_id_min = tx.
tx_id + 1;
1470 bool do_sort =
false;
1471 uint32_t array_idx = 0;
1481 SCLogDebug(
"%p/%"PRIu64
" rules added from prefilter: %u candidates",
1485 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
1486 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
1500 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
1501 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
1507 uint32_t x = array_idx;
1509 RuleMatchCandidateMergeStateRules(det_ctx, &array_idx);
1513 const uint32_t old = array_idx;
1518 if (have_new_file) {
1519 SCLogDebug(
"%p/%"PRIu64
" destate: need to consider new file",
1526 for (; tx_store != NULL; tx_store = tx_store->
next) {
1532 store_cnt++, state_cnt++)
1549 do_sort |= (old && old != array_idx);
1555 DetectRunTxSortHelper);
1567 for (uint32_t i = 0; i < array_idx; i++) {
1574 for (uint32_t i = 0; i < array_idx; i++) {
1584 while ((i + 1) < array_idx &&
1586 SCLogDebug(
"%p/%" PRIu64
" inspecting SKIP NEXT: sid %u (%u), flags %08x",
1591 SCLogDebug(
"%p/%"PRIu64
" inspecting: sid %u (%u), flags %08x",
1594 if (inspect_flags) {
1596 SCLogDebug(
"%p/%"PRIu64
" inspecting: sid %u (%u), flags %08x ALREADY COMPLETE",
1602 if (inspect_flags) {
1612 const int r = DetectRunTxInspectRule(
tv,
de_ctx, det_ctx, p, f, flow_flags,
1613 alstate, &tx, s, inspect_flags, can, scratch);
1616 DetectRunPostMatch(
tv, det_ctx, p, s);
1622 DetectVarProcessList(det_ctx, p->
flow, p);
1632 uint64_t new_detect_flags = 0;
1636 SCLogDebug(
"%p/%"PRIu64
" tx is done for direction %s. Flag %016"PRIx64,
1638 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient",
1644 SCLogDebug(
"%p/%"PRIu64
" updated prefilter flags %016"PRIx64
" "
1645 "(was: %016"PRIx64
") for direction %s. Flag %016"PRIx64,
1647 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient",
1650 if (new_detect_flags != 0 &&
1655 SCLogDebug(
"%p/%"PRIu64
" Storing new flags %016"PRIx64
" (was %016"PRIx64
")",
1658 StoreDetectFlags(&tx, flow_flags, ipproto, alproto, new_detect_flags);
1679 SCLogDebug(
"pcap_cnt %" PRIu64
": %s: skip frame inspection for TCP w/o APP UPDATE",
1684 if (frames_container == NULL) {
1689 frames = &frames_container->
toserver;
1691 frames = &frames_container->
toclient;
1694 for (uint32_t idx = 0; idx < frames->
cnt; idx++) {
1697 if (frame == NULL) {
1702 uint32_t array_idx = 0;
1710 SCLogDebug(
"%p/%" PRIi64
" rules added from prefilter: %u candidates", frame, frame->
id,
1715 if (!(RuleMatchCandidateTxArrayHasSpace(
1716 det_ctx, total_rules))) {
1717 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
1732 uint32_t x = array_idx;
1743 SCLogDebug(
"%p/%" PRIi64
" rule %u (%u) added from 'match' list", frame, frame->
id,
1747 SCLogDebug(
"%p/%" PRIi64
" rules added from 'match' list: %u", frame, frame->
id,
1752 for (uint32_t i = 0; i < array_idx; i++) {
1759 while ((i + 1) < array_idx &&
1763 SCLogDebug(
"%p/%" PRIi64
" inspecting: sid %u (%u)", frame, frame->
id, s->
id, s->
num);
1766 SCLogDebug(
"%p/%" PRIi64
" Start sid %u", frame, frame->
id, s->
id);
1770 bool r = DetectRunInspectRuleHeader(p, f, s, s->
flags, s->
proto.
flags);
1775 DetectRunPostMatch(
tv, det_ctx, p, s);
1780 "%p/%" PRIi64
" sig %u (%u) matched", frame, frame->
id, s->
id, s->
num);
1787 DetectVarProcessList(det_ctx, p->
flow, p);
1798 "frame->inspect_progress: %" PRIu64
" -> not updated", frame->
inspect_progress);
1801 SCLogDebug(
"%p/%" PRIi64
" rules inspected, running cleanup", frame, frame->
id);
1832 SCLogDebug(
"p->pcap %"PRIu64
": no detection on packet, "
1833 "PKT_NOPACKET_INSPECTION is set", p->
pcap_cnt);
1846 (void)DetectRun(
tv,
de_ctx, det_ctx, p);
1877 if (det_ctx == NULL) {
1878 printf(
"ERROR: Detect has no thread ctx\n");
1884 SCLogDebug(
"Detect Engine using new det_ctx - %p",
1895 if (tenant_id > 0 && tenant_id < det_ctx->mt_det_ctxs_cnt) {
1898 if (det_ctx == NULL)
1906 SCLogDebug(
"MT de_ctx %p det_ctx %p (tenant %u)",
de_ctx, det_ctx, tenant_id);
1917 DetectFlow(
tv,
de_ctx, det_ctx, p);
1919 DetectNoFlow(
tv,
de_ctx, det_ctx, p);
1922 #ifdef PROFILE_RULES
1925 gettimeofday(&
ts, NULL);
1926 if (
ts.tv_sec != det_ctx->rule_perf_last_sync) {
1927 SCProfilingRuleThreatAggregate(det_ctx);
1928 det_ctx->rule_perf_last_sync =
ts.tv_sec;
1942 DetectPostInspectFileFlagsUpdate(f, NULL , STREAM_TOSERVER);
1943 DetectPostInspectFileFlagsUpdate(f, NULL , STREAM_TOCLIENT);
1954 DetectFlow(
tv,
de_ctx, det_ctx, p);
1956 DetectNoFlow(
tv,
de_ctx, det_ctx, p);
#define PKT_IS_TOCLIENT(p)
uint32_t non_pf_syn_store_cnt
bool PacketCheckAction(const Packet *p, const uint8_t a)
#define FLOWFILE_NO_MD5_TS
SignatureNonPrefilterStore * non_pf_store_ptr
void RulesDumpTxMatchArray(const DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, const Packet *p, const uint64_t tx_id, const uint32_t rule_cnt, const uint32_t pkt_prefilter_cnt)
#define SIG_GROUP_HEAD_HAVEFILEMD5
#define FLOWFILE_NO_MD5_TC
PrefilterEngine * tx_engines
struct AppLayerTxData * tx_data_ptr
#define DE_STATE_CHUNK_SIZE
#define FLOWFILE_NO_SIZE_TS
uint64_t inspect_progress
uint16_t alert_queue_size
#define FLOWFILE_NO_SIZE_TC
DetectMatchAddressIPv6 * addr_src_match6
SigTableElmt * sigmatch_table
#define PACKET_ALERT_FLAG_TX
struct SigGroupHead_ * decoder_event_sgh
int FlowGetPacketDirection(const Flow *f, const Packet *p)
determine the direction of the packet compared to the flow
DetectEngineLookupFlow flow_gh[FLOW_STATES]
#define DE_STATE_FLAG_SIG_CANT_MATCH
uint16_t counter_match_list
struct DetectEngineAppInspectionEngine_ * next
#define DETECT_PROTO_IPV6
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
uint32_t rule_id_array_cnt
Container for matching data for a signature group.
#define SIG_GROUP_HEAD_HAVEFILESIZE
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
#define KEYWORD_PROFILING_SET_LIST(ctx, list)
int DetectAddressMatchIPv4(const DetectMatchAddressIPv4 *addrs, uint16_t addrs_cnt, const Address *a)
Match a packets address against a signatures addrs array.
InspectEngineFuncPtr Callback
#define FLOW_SGH_TOCLIENT
void AppLayerParserSetTransactionInspectId(const Flow *f, AppLayerParserState *pstate, void *alstate, const uint8_t flags, bool tag_txs_as_inspected)
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto, const AppProto alproto)
struct HtpBodyChunk_ * next
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t flags)
get the progress value for a tx/protocol
#define FLOWFILE_NO_MAGIC_TS
#define ICMPV4_DEST_UNREACH_IS_VALID(p)
#define SIG_GROUP_HEAD_HAVEFILESHA1
#define FLOW_TC_APP_UPDATED
main detection engine ctx
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
struct DetectRunScratchpad DetectRunScratchpad
#define APP_LAYER_TX_SKIP_INSPECT_FLAG
struct DetectEngineAppInspectionEngine_::@79 v2
DetectEngineStateDirection dir_state[2]
Frame * FrameGetByIndex(Frames *frames, const uint32_t idx)
#define FLOW_PKT_TOSERVER
#define APP_LAYER_TX_INSPECTED_FLAG
#define SIG_GROUP_HEAD_HAVERAWSTREAM
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
struct SigGroupHead_ * sh
#define PKT_NOPAYLOAD_INSPECTION
#define PACKET_PROFILING_DETECT_END(p, id)
TmEcode Detect(ThreadVars *tv, Packet *p, void *data)
Detection engine thread wrapper.
#define FLOW_PKT_TOCLIENT_IPONLY_SET
bool DetectRunFrameInspectRule(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p, const Frames *frames, const Frame *frame)
#define KEYWORD_PROFILING_START
uint16_t counter_fnonmpm_list
void DisableDetectFlowFileFlags(Flow *f)
disable file features we don't need Called if we have no detection engine.
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
uint16_t counter_nonmpm_list
void DetectRunPrefilterFrame(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, const Frames *frames, const Frame *frame, const AppProto alproto)
PacketEngineEvents events
DetectEngineFrameInspectionEngine * frame_inspect
const uint64_t prefilter_flags_orig
void PacketCreateMask(Packet *p, SignatureMask *mask, AppProto alproto, bool app_decoder_events)
#define SIG_FLAG_APPLAYER
#define KEYWORD_PROFILING_END(ctx, type, m)
HashTable * mt_det_ctxs_hash
bool DetectEnginePktInspectionRun(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p, uint8_t *alert_flags)
const struct SigGroupHead_ * sgh_toserver
uint16_t counter_alerts_suppressed
void DetectRunStoreStateTx(const SigGroupHead *sgh, Flow *f, void *tx, uint64_t tx_id, const Signature *s, uint32_t inspect_flags, uint8_t flow_flags, const uint16_t file_no_match)
AppLayerParserState * alparser
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
#define FLOWFILE_NO_SHA1_TC
@ DETECT_SM_LIST_POSTMATCH
RuleMatchCandidateTx * tx_candidates
DetectMatchAddressIPv4 * addr_src_match4
uint16_t counter_alerts_overflow
#define PKT_IS_TOSERVER(p)
void Prefilter(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, const uint8_t flags, const SignatureMask mask)
#define DEBUG_VALIDATE_PACKET(p)
#define FLOWFILE_NO_STORE_TS
uint32_t tx_candidates_size
#define FLOW_PKT_TOSERVER_IPONLY_SET
#define FRAME_FLAG_TX_ID_SET
#define PKT_PSEUDO_STREAM_END
#define STREAM_FLAGS_FOR_PACKET(p)
struct SigGroupHead_ * sgh[256]
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
Per thread variable structure.
struct DeStateStore_ * next
#define FLOWFILE_NO_SHA256_TS
#define DETECT_ENGINE_INSPECT_SIG_MATCH
#define PKT_DETECT_HAS_STREAMDATA
bool StreamReassembleRawHasDataReady(TcpSession *ssn, Packet *p)
does the stream engine have data to inspect?
const char * PktSrcToString(enum PktSrcEnum pkt_src)
#define PACKET_ALERT_FLAG_TX_GUESSED
Port structure for detection engine.
DetectEngineAppInspectionEngine * app_inspect
const struct SigGroupHead_ * sgh_toclient
#define SIG_FLAG_REQUIRE_FLOWVAR
uint64_t raw_stream_progress
void FileUpdateFlowFileFlags(Flow *f, uint16_t set_file_flags, uint8_t direction)
set a flow's file flags
void AlertQueueAppend(DetectEngineThreadCtx *det_ctx, const Signature *s, Packet *p, uint64_t tx_id, uint8_t alert_flags)
Append signature to local packet alert queue for later preprocessing.
void RuleMatchCandidateTxArrayFree(DetectEngineThreadCtx *det_ctx)
FramesContainer * AppLayerFramesGetContainer(Flow *f)
#define APP_LAYER_TX_PREFILTER_MASK
void FlowSetIPOnlyFlag(Flow *f, int direction)
Set the IPOnly scanned flag for 'direction'.
#define FLOW_TOSERVER_IPONLY_SET
#define RULE_PROFILING_END(a, b, c, p)
#define RULE_PROFILING_START(p)
#define SCReturnPtr(x, type)
DetectEngineStateDirection * de_state
Data structures and function prototypes for keeping state for the detection engine.
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
void RulesDumpMatchArray(const DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, const Packet *p)
uint16_t addr_dst_match6_cnt
#define FLOW_PKT_TOCLIENT
PrefilterEngine * frame_engines
#define PACKET_ALERT_NOTX
#define APP_LAYER_PARSER_NO_INSPECTION
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH
#define DETECT_ENGINE_STATE_FLAG_FILE_NEW
#define SCRealloc(ptr, sz)
#define FLOWFILE_NO_SHA256_TC
#define DETECT_ENGINE_INSPECT_SIG_MATCH_MORE_FILES
struct AppLayerTxData AppLayerTxData
#define DETECT_PROTO_IPV4
int DetectAddressMatchIPv6(const DetectMatchAddressIPv6 *addrs, uint16_t addrs_cnt, const Address *a)
Match a packets address against a signatures addrs array.
void DetectEngineStateResetTxs(Flow *f)
Reset de state for active tx' To be used on detect engine reload.
#define FLOWFILE_NO_MAGIC_TC
SignatureNonPrefilterStore * non_pf_other_store_array
#define FLOW_TOCLIENT_IPONLY_SET
#define APP_LAYER_TX_RESERVED_FLAGS
uint32_t non_pf_other_store_cnt
uint8_t app_update_direction
uint64_t frame_inspect_progress
uint32_t profile_match_logging_threshold
#define FLOW_TS_APP_UPDATED
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
#define FLOWFILE_NO_STORE_TC
SigIntId * non_pf_id_array
uint16_t addr_src_match6_cnt
void StreamReassembleRawUpdateProgress(TcpSession *ssn, Packet *p, const uint64_t progress)
update stream engine after detection
void StatsAddUI64(ThreadVars *tv, uint16_t id, uint64_t x)
Adds a value of type uint64_t to the local counter.
#define FLOWFILE_NO_SHA1_TS
const bool app_decoder_events
#define PACKET_PROFILING_DETECT_START(p, id)
#define PACKET_ALERT_FLAG_FRAME
uint32_t non_pf_store_cnt
#define FLOW_SGH_TOSERVER
#define SGH_PROFILING_RECORD(det_ctx, sgh)
void PacketAlertFinalize(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
Check the threshold of the sigs that match, set actions, break on pass action This function iterate t...
DetectMatchAddressIPv6 * addr_dst_match6
DeStateStoreItem store[DE_STATE_CHUNK_SIZE]
uint8_t guess_applayer_log_limit
void InspectionBufferClean(DetectEngineThreadCtx *det_ctx)
#define TRACE_SID_TXS(sid, txs,...)
#define FLOW_PKT_ESTABLISHED
#define STREAMTCP_FLAG_APP_LAYER_DISABLED
void IPOnlyMatchPacket(ThreadVars *tv, const DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineIPOnlyCtx *io_ctx, Packet *p)
Match a packet against the IP Only detection engine contexts.
SignatureNonPrefilterStore * non_pf_syn_store_array
#define PKT_NOPACKET_INSPECTION
void * DetectGetInnerTx(void *tx_ptr, AppProto alproto, AppProto engine_alproto, uint8_t flow_flags)
#define DE_STATE_FLAG_FULL_INSPECT
#define STREAMTCP_STREAM_FLAG_DISABLE_RAW
AppLayerGetTxIterTuple(* AppLayerGetTxIteratorFunc)(const uint8_t ipproto, const AppProto alproto, void *alstate, uint64_t min_tx_id, uint64_t max_tx_id, AppLayerGetTxIterState *state)
tx iterator prototype
#define DE_STATE_FLAG_FILE_INSPECT
#define FLOW_NOPACKET_INSPECTION
DetectEngineIPOnlyCtx io_ctx
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
DetectMatchAddressIPv4 * addr_dst_match4
uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
get 'disruption' flags: GAP/DEPTH/PASS
uint16_t addr_src_match4_cnt
uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
void GenericVarFree(GenericVar *gv)
uint16_t addr_dst_match4_cnt
AppProto alproto
application level protocol
#define SIG_GROUP_HEAD_HAVEFILESHA256
uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
#define PACKET_ALERT_FLAG_STATE_MATCH
bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
#define DEBUG_VALIDATE_BUG_ON(exp)
const uint64_t detect_flags
uint16_t counter_mpm_list
const SigGroupHead * SigMatchSignaturesGetSgh(const DetectEngineCtx *de_ctx, const Packet *p)
Get the SigGroupHead for a packet.
void DetectRunPrefilterTx(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, const uint8_t ipproto, const uint8_t flow_flags, const AppProto alproto, void *alstate, DetectTransaction *tx)
run prefilter engines on a transaction
void RuleMatchCandidateTxArrayInit(DetectEngineThreadCtx *det_ctx, uint32_t size)
DetectPort * DetectPortLookupGroup(DetectPort *dp, uint16_t port)
Function that find the group matching port in a group head.
uint32_t(* TenantGetId)(const void *, const Packet *p)
int DetectProtoContainsProto(const DetectProto *dp, int proto)
see if a DetectProto contains a certain proto