Go to the documentation of this file.
50 memset(&g_tag_signature, 0x00,
sizeof(g_tag_signature));
55 g_tag_signature.
rev = 1;
56 g_tag_signature.
prio = 2;
58 memset(&g_tag_pa, 0x00,
sizeof(g_tag_pa));
61 g_tag_pa.
s = &g_tag_signature;
83 if (!(PacketIsIPv4(
p) || PacketIsIPv6(
p))) {
100 if (ret == 0 || ret == 2) {
107 }
while (smd != NULL);
123 if (ret == 0 || ret == 2) {
130 }
while (smd != NULL);
148 for (uint16_t i = 0; i <
p->
alerts.
cnt; i++) {
158 static inline void RuleActionToFlow(
const uint8_t action,
Flow *f,
const bool fw_rule)
170 SCLogDebug(
"not setting %s flow already set to %s",
187 SCLogDebug(
"replaced FLOW_ACTION_ACCEPT with FLOW_ACTION_DROP");
191 SCLogDebug(
"not setting %s flow already set to %s",
258 }
else if (pa->
action != 0) {
274 FatalError(
"failed to allocate %" PRIu64
" bytes for the alert queue",
299 SCLogDebug(
"Alert queue size expanded: %u elements, bytes: %" PRIuMAX
"",
310 if (
unlikely(g_eps_is_alert_queue_fail_mode))
319 new_cap = UINT16_MAX;
323 return AlertQueueExpandDo(det_ctx, new_cap);
326 static inline int PacketAlertSetContext(
336 SCLogDebug(
"signature %p, content index %u", s, i);
337 if (current_json == NULL) {
340 if (current_json == NULL) {
348 current_json->
next = NULL;
354 current_json->
next = next_json;
355 current_json = next_json;
356 current_json->
next = NULL;
366 SCLogDebug(
"json content %u, value '%s' (%p)", (
unsigned int)i,
384 pa.
flags = alert_flags;
388 PacketAlertSetContext(det_ctx, &pa, s);
401 p->
alerts.
drop = PacketAlertSet(det_ctx, s, tx_id, alert_flags);
402 SCLogDebug(
"sid %u: set PacketAlert drop action. s->iid %" PRIu32
"", s->
id, s->
iid);
408 if (pos == AlertQueueExpand(det_ctx)) {
414 det_ctx->
alert_queue[pos] = PacketAlertSet(det_ctx, s, tx_id, alert_flags);
416 SCLogDebug(
"packet %" PRIu64
": appending sid %" PRIu32
", s->iid %" PRIu32
" to alert queue",
428 static int AlertQueueSortHelperFirewall(
const void *a,
const void *b)
433 if (pa1->
iid == pa0->
iid) {
441 return pa0->
iid < pa1->
iid ? -1 : 1;
447 static int AlertQueueSortHelper(
const void *a,
const void *b)
451 if (pa1->
iid == pa0->
iid) {
459 return pa0->
iid < pa1->
iid ? -1 : 1;
467 static inline void FlowApplySignatureActions(
493 SCLogDebug(
"packet %" PRIu64
" sid %u action %02x alert_flags %02x (set "
494 "PACKET_ALERT_FLAG_APPLY_ACTION_TO_FLOW)",
514 int res = PacketAlertHandle(
de_ctx, det_ctx, s,
p, pa);
547 SCLogDebug(
"packet %" PRIu64
": FLOW_ACTION_DROP set by firewall by sid %u",
554 SCLogDebug(
"packet %" PRIu64
": FLOW_ACTION_PASS set by firewall by sid %u",
591 static inline void PacketAlertFinalizeProcessQueue(
599 have_fw_rules ? AlertQueueSortHelperFirewall : AlertQueueSortHelper);
602 bool alerted =
false;
603 bool dropped =
false;
604 bool skip_td =
false;
605 bool skip_fw =
false;
606 bool fw_accept_packet =
false;
607 bool fw_accept_flow =
false;
614 SCLogDebug(
"(list) %s sid %u: action %02x scope %u iid %u detect_table %u",
619 uint8_t skip_table_id = 0;
620 bool skip_table =
false;
638 SCLogDebug(
"Skipping firewall signature after a drop.");
657 fw_accept_packet =
true;
659 fw_accept_flow =
true;
664 if (pre_alert_cnt < p->alerts.cnt)
677 if (have_fw_rules && skip_td) {
681 int res = PacketAlertHandle(
de_ctx, det_ctx, s,
p, pa);
700 bool skip_action_set =
false;
704 skip_action_set =
true;
708 skip_action_set =
true;
714 if (!skip_action_set) {
716 FlowApplySignatureActions(
p, pa, s, pa->
flags);
722 PacketApplySignatureActions(
p, s, pa);
728 SCLogDebug(
"sid:%u: skipping alert because of thresholding (res=%d) or NOALERT (%02x)",
734 SCLogDebug(
"appending sid %" PRIu32
" alert to Packet::alerts at pos %u; action:%02x",
742 SCLogDebug(
"sid:%u: is a pass rule, so break out of loop", s->
id);
764 }
else if (fw_accept_packet) {
766 if (
p->
flow && fw_accept_flow) {
768 SCLogDebug(
"packet %" PRIu64
": FLOW_ACTION_ACCEPT set from firewall",
776 if (alerted &&
p->
flow != NULL) {
804 PacketAlertFinalizeProcessQueue(
de_ctx, det_ctx,
p);
bool PacketCheckAction(const Packet *p, const uint8_t a)
@ PKT_DROP_REASON_RULES_THRESHOLD
uint16_t alert_queue_size
void FlowSetHasAlertsFlag(Flow *f)
Set flag to indicate that flow has alerts.
uint16_t firewall_discarded
#define FLOW_ACTION_BY_FIREWALL
const struct Signature_ * s
void AlertQueueFree(DetectEngineThreadCtx *det_ctx)
SigTableElmt * sigmatch_table
#define PACKET_ALERT_FLAG_STATE_MATCH
@ PKT_DROP_REASON_FW_RULES
#define KEYWORD_PROFILING_SET_LIST(ctx, list)
uint64_t PcapPacketCntGet(const Packet *p)
@ DETECT_TABLE_PACKET_PRE_STREAM
const char * ActionScopeToString(enum ActionScope s)
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
@ DETECT_SM_LIST_THRESHOLD
main detection engine ctx
#define ACTION_REJECT_ANY
void CaptureHooksOnPacketWithAlerts(const Packet *p)
#define ACTION_DROP_REJECT
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
bool EngineModeIsFirewall(void)
#define KEYWORD_PROFILING_START
#define KEYWORD_PROFILING_END(ctx, type, m)
#define SIG_FLAG_FIREWALL
void AlertQueueInit(DetectEngineThreadCtx *det_ctx)
SignaturePropertyFlowAction
struct PacketContextData * json_info
#define PKT_PSEUDO_STREAM_END
@ PKT_DROP_REASON_FW_FLOW_PRE_HOOK
@ DETECT_TABLE_PACKET_PRE_FLOW
#define PACKET_ALERT_FLAG_APPLY_ACTION_TO_FLOW
#define PKT_ALERT_CTX_USED
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.
uint16_t alert_queue_capacity
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
const struct SignatureProperties signature_properties[SIG_TYPE_MAX]
#define PACKET_ALERT_NOTX
#define PACKET_ALERT_FLAG_APPLY_ACTION_TO_PACKET
void PacketAlertFinalize(const 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...
#define PACKET_ALERT_FLAG_STREAM_MATCH
void TagHandlePacket(const DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
Search tags for src and dst. Update entries of the tag, remove if necessary.
#define PACKET_ALERT_FLAG_FRAME
#define SCRealloc(ptr, sz)
@ SIG_PROP_FLOW_ACTION_FLOW_IF_STATEFUL
struct PacketContextData * next
@ PKT_DROP_REASON_FW_STREAM_PRE_HOOK
const DetectThresholdData * SigGetThresholdTypeIter(const Signature *sig, const SigMatchData **psm, int list)
Return next DetectThresholdData for signature.
#define FLOW_ACTION_ACCEPT
PacketAlert * alert_queue
#define PACKET_ALERT_FLAG_RATE_FILTER_MODIFIED
SigJsonContent * json_content
void PacketAlertTagInit(void)
void PacketDrop(Packet *p, const uint8_t action, enum PacketDropReason r)
issue drop action
int FlowHasAlerts(const Flow *f)
Check if flow has alerts.
uint16_t packet_alert_max
@ SIG_PROP_FLOW_ACTION_FLOW
int PacketAlertThreshold(const DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectThresholdData *td, Packet *p, const Signature *s, PacketAlert *pa)
Make the threshold logic for signatures.
@ DETECT_SM_LIST_SUPPRESS
#define DEBUG_VALIDATE_BUG_ON(exp)
enum SignaturePropertyFlowAction flow_action
char json_content[SIG_JSON_CONTENT_ITEM_LEN]