Go to the documentation of this file.
37 static bool g_eps_have_exception_policy =
false;
53 return is_json ?
"drop_flow" :
"drop-flow";
55 return is_json ?
"drop_packet" :
"drop-packet";
57 return is_json ?
"pass_packet" :
"pass-packet";
59 return is_json ?
"pass_flow" :
"pass-flow";
77 switch (drop_reason) {
99 switch (target_flag) {
101 return "defrag_memcap";
103 return "stream_memcap";
105 return "stream_reassembly_memcap";
107 return "flow_memcap";
109 return "stream_midstream";
111 return "app_layer_error";
119 switch (target_flag) {
167 FlowSetNoPayloadInspectionFlag(
p->
flow);
173 DecodeSetNoPayloadInspectionFlag(
p);
174 DecodeSetNoPacketInspectionFlag(
p);
188 DecodeSetNoPayloadInspectionFlag(
p);
189 DecodeSetNoPacketInspectionFlag(
p);
200 "flow actions not supported for %s, defaulting to \"drop-packet\"", option);
204 "flow actions not supported for %s, defaulting to \"pass-packet\"", option);
207 SCLogWarning(
"flow actions not supported for %s, defaulting to \"ignore\"", option);
227 const char *option,
const char *value_str)
230 if (strcmp(value_str,
"drop-flow") == 0) {
232 }
else if (strcmp(value_str,
"pass-flow") == 0) {
234 }
else if (strcmp(value_str,
"bypass") == 0) {
236 }
else if (strcmp(value_str,
"drop-packet") == 0) {
238 }
else if (strcmp(value_str,
"pass-packet") == 0) {
240 }
else if (strcmp(value_str,
"reject") == 0) {
242 }
else if (strcmp(value_str,
"rejectboth") == 0) {
244 }
else if (strcmp(value_str,
"ignore") == 0) {
246 }
else if (strcmp(value_str,
"auto") == 0) {
250 "\"%s\" is not a valid exception policy value. Valid options are drop-flow, "
251 "pass-flow, bypass, reject, drop-packet, pass-packet, ignore or auto.",
259 static enum ExceptionPolicy ExceptionPolicyPickAuto(
bool midstream_enabled,
bool support_flow)
272 static enum ExceptionPolicy ExceptionPolicyMasterParse(
const char *value)
274 enum ExceptionPolicy policy = ExceptionPolicyConfigValueParse(
"exception-policy", value);
279 g_eps_have_exception_policy =
true;
287 const char *option,
bool support_flow,
bool midstream)
290 if (g_eps_have_exception_policy) {
291 p = GetMasterExceptionPolicy();
294 p = ExceptionPolicyPickAuto(midstream, support_flow);
298 p = PickPacketAction(option,
p);
300 SCLogConfig(
"%s: %s (defined via 'exception-policy' master switch)", option,
306 SCLogConfig(
"%s: %s (defined via 'built-in default' for %s-mode)", option,
315 const char *value_str = NULL;
317 if ((
SCConfGet(option, &value_str) == 1) && value_str != NULL) {
318 if (strcmp(option,
"exception-policy") == 0) {
319 policy = ExceptionPolicyMasterParse(value_str);
321 policy = ExceptionPolicyConfigValueParse(option, value_str);
323 policy = ExceptionPolicyPickAuto(
false, support_flow);
326 policy = PickPacketAction(option, policy);
331 policy = ExceptionPolicyGetDefault(option, support_flow,
false);
340 const char *value_str = NULL;
342 if ((
SCConfGet(
"stream.midstream-policy", &value_str)) == 1 && value_str != NULL) {
343 policy = ExceptionPolicyConfigValueParse(
"midstream-policy", value_str);
345 policy = ExceptionPolicyPickAuto(midstream_enabled,
true);
346 }
else if (midstream_enabled) {
349 "Error parsing stream.midstream-policy from config file. \"%s\" is "
350 "not a valid exception policy when midstream is enabled. Valid options "
351 "are pass-flow and ignore.",
358 "Error parsing stream.midstream-policy from config file. \"%s\" is "
359 "not a valid exception policy in IDS mode. See our documentation for a "
360 "list of all possible values.",
365 policy = ExceptionPolicyGetDefault(
"stream.midstream-policy",
true, midstream_enabled);
369 FatalErrorOnInit(
"Error parsing stream.midstream-policy from config file. \"%s\" is "
370 "not valid for this exception policy. See our documentation for a list of "
371 "all possible values.",
380 const char *default_str,
bool (*isExceptionPolicyValid)(
enum ExceptionPolicy))
385 if (isExceptionPolicyValid(i)) {
386 snprintf(setting->
eps_name[i],
sizeof(setting->
eps_name[i]),
"%s%s", default_str,
394 #ifndef QA_SIMULATION
405 uint64_t g_eps_applayer_error_offset_ts = UINT64_MAX;
406 uint64_t g_eps_applayer_error_offset_tc = UINT64_MAX;
407 uint64_t g_eps_pcap_packet_loss = UINT64_MAX;
408 uint64_t g_eps_stream_ssn_memcap = UINT64_MAX;
409 uint64_t g_eps_stream_reassembly_memcap = UINT64_MAX;
410 uint64_t g_eps_flow_memcap = UINT64_MAX;
411 uint64_t g_eps_defrag_memcap = UINT64_MAX;
412 bool g_eps_is_alert_queue_fail_mode =
false;
417 if (strcmp(
name,
"simulate-applayer-error-at-offset-ts") == 0) {
423 g_eps_applayer_error_offset_ts =
offset;
424 }
else if (strcmp(
name,
"simulate-applayer-error-at-offset-tc") == 0) {
430 g_eps_applayer_error_offset_tc =
offset;
431 }
else if (strcmp(
name,
"simulate-packet-loss") == 0) {
433 uint64_t pkt_num = 0;
437 g_eps_pcap_packet_loss = pkt_num;
438 }
else if (strcmp(
name,
"simulate-packet-tcp-reassembly-memcap") == 0) {
440 uint64_t pkt_num = 0;
444 g_eps_stream_reassembly_memcap = pkt_num;
445 }
else if (strcmp(
name,
"simulate-packet-tcp-ssn-memcap") == 0) {
447 uint64_t pkt_num = 0;
451 g_eps_stream_ssn_memcap = pkt_num;
452 }
else if (strcmp(
name,
"simulate-packet-flow-memcap") == 0) {
454 uint64_t pkt_num = 0;
458 g_eps_flow_memcap = pkt_num;
459 }
else if (strcmp(
name,
"simulate-packet-defrag-memcap") == 0) {
461 uint64_t pkt_num = 0;
465 g_eps_defrag_memcap = pkt_num;
466 }
else if (strcmp(
name,
"simulate-alert-queue-realloc-failure") == 0) {
467 g_eps_is_alert_queue_fail_mode =
true;
@ PKT_DROP_REASON_DEFRAG_MEMCAP
void ExceptionPolicyApply(Packet *p, enum ExceptionPolicy policy, enum PacketDropReason drop_reason)
int ExceptionSimulationCommandLineParser(const char *name, const char *arg)
@ EXCEPTION_POLICY_PASS_FLOW
void PacketBypassCallback(Packet *p)
@ EXCEPTION_POLICY_REJECT_BOTH
enum ExceptionPolicy g_eps_master_switch
@ PKT_DROP_REASON_STREAM_MEMCAP
@ PKT_DROP_REASON_FLOW_MEMCAP
uint64_t PcapPacketCntGet(const Packet *p)
@ EXCEPTION_POLICY_DROP_PACKET
int ParseSizeStringU64(const char *size, uint64_t *res)
StatsCounterId StatsRegisterCounter(const char *name, StatsThreadContext *stats)
Registers a normal, unqualified counter.
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
#define EXCEPTION_TARGET_FLAG_APPLAYER_ERROR
@ PKT_DROP_REASON_STREAM_REASSEMBLY
@ EXCEPTION_POLICY_BYPASS_FLOW
@ EXCEPTION_POLICY_NOT_SET
enum ExceptionPolicy ExceptionPolicyParse(const char *option, bool support_flow)
const char * ExceptionPolicyTargetFlagToString(uint8_t target_flag)
#define EXCEPTION_POLICY_MAX
#define EXCEPTION_TARGET_FLAG_DEFRAG_MEMCAP
enum ExceptionPolicy ExceptionPolicyTargetPolicy(uint8_t target_flag)
@ EXCEPTION_POLICY_PASS_PACKET
@ PKT_DROP_REASON_APPLAYER_ERROR
void ExceptionPolicySetStatsCounters(ThreadVars *tv, ExceptionPolicyCounters *counter, ExceptionPolicyStatsSetts *setting, enum ExceptionPolicy conf_policy, const char *default_str, bool(*isExceptionPolicyValid)(enum ExceptionPolicy))
Per thread variable structure.
@ EXCEPTION_POLICY_DROP_FLOW
#define SCLogWarning(...)
Macro used to log WARNING messages.
enum ExceptionPolicy ExceptionPolicyMidstreamParse(bool midstream_enabled)
#define EXCEPTION_TARGET_FLAG_REASSEMBLY_MEMCAP
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define EXCEPTION_TARGET_FLAG_MIDSTREAM
enum ExceptionPolicy StreamTcpReassemblyMemcapGetExceptionPolicy(void)
#define ACTION_REJECT_BOTH
enum ExceptionPolicy AppLayerErrorGetExceptionPolicy(void)
enum ExceptionPolicy FlowGetMemcapExceptionPolicy(void)
uint8_t applied_exception_policy
@ EXCEPTION_POLICY_REJECT
void StreamTcpDisableAppLayer(Flow *f)
#define EXCEPTION_TARGET_FLAG_SESSION_MEMCAP
#define FatalErrorOnInit(...)
Fatal error IF we're starting up, and configured to consider errors to be fatal errors.
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
const char * ExceptionPolicyEnumToString(enum ExceptionPolicy policy, bool is_json)
enum ExceptionPolicy StreamMidstreamGetExceptionPolicy(void)
enum ExceptionPolicy StreamTcpSsnMemcapGetExceptionPolicy(void)
void PacketDrop(Packet *p, const uint8_t action, enum PacketDropReason r)
issue drop action
int EngineModeIsIPS(void)
#define EXCEPTION_TARGET_FLAG_FLOW_MEMCAP
void SetMasterExceptionPolicy(void)
#define FLOW_ACTION_BY_EXCEPTION_POLICY
@ PKT_DROP_REASON_STREAM_MIDSTREAM
enum ExceptionPolicy DefragGetMemcapExceptionPolicy(void)
StatsCounterId eps_id[EXCEPTION_POLICY_MAX]
char eps_name[EXCEPTION_POLICY_MAX][EXCEPTION_POLICY_COUNTER_MAX_LEN]