-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flow/output: log triggered exception policy - v1 #12683
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,15 @@ enum ExceptionPolicy { | |
* "tcp.reassembly_exception_policy.drop_packet" + 1 */ | ||
#define EXCEPTION_POLICY_COUNTER_MAX_LEN 45 | ||
|
||
/** exception policy flags */ | ||
#define EXCEPTION_DEFRAG_MEMCAP BIT_U16(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually just 0, the other bit should start at offset 0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙇🏽♀️ |
||
#define EXCEPTION_SESSION_MEMCAP BIT_U16(2) | ||
#define EXCEPTION_REASSEMBLY_MEMCAP BIT_U16(3) | ||
#define EXCEPTION_FLOW_MEMCAP BIT_U16(4) | ||
#define EXCEPTION_MIDSTREAM BIT_U16(5) | ||
#define EXCEPTION_APPLAYER_ERROR BIT_U16(6) | ||
/** 6 - 15 free */ | ||
|
||
typedef struct ExceptionPolicyCounters_ { | ||
/* Follows enum order */ | ||
uint16_t eps_id[EXCEPTION_POLICY_MAX]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* Copyright (C) 2022-2024 Open Information Security Foundation | ||
/* Copyright (C) 2022-2025 Open Information Security Foundation | ||
* | ||
* You can copy, redistribute or modify this Program under the terms of | ||
* the GNU General Public License version 2 as published by the Free | ||
|
@@ -19,14 +19,18 @@ | |
* \file | ||
*/ | ||
|
||
#include "util-exception-policy.h" | ||
#include "suricata-common.h" | ||
#include "suricata.h" | ||
#include "packet.h" | ||
#include "util-exception-policy.h" | ||
#include "util-misc.h" | ||
#include "stream-tcp-reassemble.h" | ||
#include "action-globals.h" | ||
#include "conf.h" | ||
#include "flow.h" | ||
#include "stream-tcp.h" | ||
#include "defrag-hash.h" | ||
#include "app-layer-parser.h" | ||
|
||
enum ExceptionPolicy g_eps_master_switch = EXCEPTION_POLICY_NOT_SET; | ||
/** true if exception policy was defined in config */ | ||
|
@@ -61,14 +65,73 @@ void SetMasterExceptionPolicy(void) | |
g_eps_master_switch = ExceptionPolicyParse("exception-policy", true); | ||
} | ||
|
||
static enum ExceptionPolicy GetMasterExceptionPolicy(void) | ||
enum ExceptionPolicy GetMasterExceptionPolicy(void) | ||
{ | ||
return g_eps_master_switch; | ||
} | ||
|
||
static uint16_t ExceptionPolicyFlag(enum PacketDropReason drop_reason) | ||
{ | ||
switch (drop_reason) { | ||
case PKT_DROP_REASON_DEFRAG_MEMCAP: | ||
return EXCEPTION_DEFRAG_MEMCAP; | ||
case PKT_DROP_REASON_STREAM_MEMCAP: | ||
return EXCEPTION_SESSION_MEMCAP; | ||
case PKT_DROP_REASON_STREAM_REASSEMBLY: | ||
return EXCEPTION_REASSEMBLY_MEMCAP; | ||
case PKT_DROP_REASON_FLOW_MEMCAP: | ||
return EXCEPTION_FLOW_MEMCAP; | ||
case PKT_DROP_REASON_STREAM_MIDSTREAM: | ||
return EXCEPTION_MIDSTREAM; | ||
case PKT_DROP_REASON_APPLAYER_ERROR: | ||
return EXCEPTION_APPLAYER_ERROR; | ||
default: | ||
return BIT_U16(0); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then use that |
||
return BIT_U16(0); | ||
} | ||
|
||
const char *ExceptionPolicyTargetFlagToString(uint16_t target_flag) | ||
{ | ||
if (target_flag & EXCEPTION_DEFRAG_MEMCAP) | ||
return "defrag_memcap"; | ||
if (target_flag & EXCEPTION_SESSION_MEMCAP) | ||
return "stream_memcap"; | ||
if (target_flag & EXCEPTION_REASSEMBLY_MEMCAP) | ||
return "stream_reassembly_memcap"; | ||
if (target_flag & EXCEPTION_FLOW_MEMCAP) | ||
return "flow_memcap"; | ||
if (target_flag & EXCEPTION_MIDSTREAM) | ||
return "stream_midstream"; | ||
if (target_flag & EXCEPTION_APPLAYER_ERROR) | ||
return "app_layer_error"; | ||
return "ignore"; | ||
} | ||
|
||
enum ExceptionPolicy ExceptionPolicyTargetPolicy(uint16_t target_flag) | ||
{ | ||
if (target_flag & EXCEPTION_DEFRAG_MEMCAP) | ||
return DefragGetMemcapExceptionPolicy(); | ||
if (target_flag & EXCEPTION_SESSION_MEMCAP) | ||
return StreamTcpSsnMemcapGetExceptionPolicy(); | ||
if (target_flag & EXCEPTION_REASSEMBLY_MEMCAP) | ||
return StreamTcpReassemblyMemcapGetExceptionPolicy(); | ||
if (target_flag & EXCEPTION_FLOW_MEMCAP) | ||
return FlowGetMemcapExceptionPolicy(); | ||
if (target_flag & EXCEPTION_MIDSTREAM) | ||
return StreamMidstreamGetExceptionPolicy(); | ||
if (target_flag & EXCEPTION_APPLAYER_ERROR) | ||
return AppLayerErrorGetExceptionPolicy(); | ||
return EXCEPTION_POLICY_NOT_SET; | ||
} | ||
|
||
void ExceptionPolicyApply(Packet *p, enum ExceptionPolicy policy, enum PacketDropReason drop_reason) | ||
{ | ||
SCLogDebug("start: pcap_cnt %" PRIu64 ", policy %u", p->pcap_cnt, policy); | ||
if (p->flow) { | ||
p->flow->flags |= FLOW_TRIGGERED_EXCEPTION_POLICY; | ||
p->flow->applied_exception_policy |= ExceptionPolicyFlag(drop_reason); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when would we have more than one? Or should this be a simple assignment instead? In fact, if it is possible that this is already set, what do that mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should it maybe be a counter, then?
This did cross my mind, but I wasn't sure this was a reasonable concern, as I didn't recall seeing such a scenario. (although probably because I didn't look for such situations when creating most tests/checks) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for now, going with a different approach (inspired by the exception policy counters struct) |
||
switch (policy) { | ||
case EXCEPTION_POLICY_AUTO: | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by putting this between 2 pointers we're essentially use 8 bytes for this, which is a lot for something from which we just use 6 bits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't realize that. >__<'