Go to the documentation of this file.
37 static bool g_eps_have_exception_policy =
false;
51 return is_json ?
"drop_flow" :
"drop-flow";
53 return is_json ?
"drop_packet" :
"drop-packet";
55 return is_json ?
"pass_packet" :
"pass-packet";
57 return is_json ?
"pass_flow" :
"pass-flow";
75 switch (drop_reason) {
97 switch (target_flag) {
99 return "defrag_memcap";
101 return "stream_memcap";
103 return "stream_reassembly_memcap";
105 return "flow_memcap";
107 return "stream_midstream";
109 return "app_layer_error";
117 switch (target_flag) {
158 FlowSetNoPayloadInspectionFlag(p->
flow);
164 DecodeSetNoPayloadInspectionFlag(p);
165 DecodeSetNoPacketInspectionFlag(p);
179 DecodeSetNoPayloadInspectionFlag(p);
180 DecodeSetNoPacketInspectionFlag(p);
191 "flow actions not supported for %s, defaulting to \"drop-packet\"", option);
195 "flow actions not supported for %s, defaulting to \"pass-packet\"", option);
198 SCLogWarning(
"flow actions not supported for %s, defaulting to \"ignore\"", option);
217 const char *option,
const char *value_str)
220 if (strcmp(value_str,
"drop-flow") == 0) {
222 }
else if (strcmp(value_str,
"pass-flow") == 0) {
224 }
else if (strcmp(value_str,
"bypass") == 0) {
226 }
else if (strcmp(value_str,
"drop-packet") == 0) {
228 }
else if (strcmp(value_str,
"pass-packet") == 0) {
230 }
else if (strcmp(value_str,
"reject") == 0) {
232 }
else if (strcmp(value_str,
"ignore") == 0) {
234 }
else if (strcmp(value_str,
"auto") == 0) {
238 "\"%s\" is not a valid exception policy value. Valid options are drop-flow, "
239 "pass-flow, bypass, reject, drop-packet, pass-packet, ignore or auto.",
247 static enum ExceptionPolicy ExceptionPolicyPickAuto(
bool midstream_enabled,
bool support_flow)
260 static enum ExceptionPolicy ExceptionPolicyMasterParse(
const char *value)
262 enum ExceptionPolicy policy = ExceptionPolicyConfigValueParse(
"exception-policy", value);
267 g_eps_have_exception_policy =
true;
275 const char *option,
bool support_flow,
bool midstream)
278 if (g_eps_have_exception_policy) {
279 p = GetMasterExceptionPolicy();
282 p = ExceptionPolicyPickAuto(midstream, support_flow);
286 p = PickPacketAction(option, p);
288 SCLogConfig(
"%s: %s (defined via 'exception-policy' master switch)", option,
294 SCLogConfig(
"%s: %s (defined via 'built-in default' for %s-mode)", option,
303 const char *value_str = NULL;
305 if ((
SCConfGet(option, &value_str) == 1) && value_str != NULL) {
306 if (strcmp(option,
"exception-policy") == 0) {
307 policy = ExceptionPolicyMasterParse(value_str);
309 policy = ExceptionPolicyConfigValueParse(option, value_str);
311 policy = ExceptionPolicyPickAuto(
false, support_flow);
314 policy = PickPacketAction(option, policy);
319 policy = ExceptionPolicyGetDefault(option, support_flow,
false);
328 const char *value_str = NULL;
330 if ((
SCConfGet(
"stream.midstream-policy", &value_str)) == 1 && value_str != NULL) {
331 policy = ExceptionPolicyConfigValueParse(
"midstream-policy", value_str);
333 policy = ExceptionPolicyPickAuto(midstream_enabled,
true);
334 }
else if (midstream_enabled) {
337 "Error parsing stream.midstream-policy from config file. \"%s\" is "
338 "not a valid exception policy when midstream is enabled. Valid options "
339 "are pass-flow and ignore.",
346 "Error parsing stream.midstream-policy from config file. \"%s\" is "
347 "not a valid exception policy in IDS mode. See our documentation for a "
348 "list of all possible values.",
353 policy = ExceptionPolicyGetDefault(
"stream.midstream-policy",
true, midstream_enabled);
357 FatalErrorOnInit(
"Error parsing stream.midstream-policy from config file. \"%s\" is "
358 "not valid for this exception policy. See our documentation for a list of "
359 "all possible values.",
368 const char *default_str,
bool (*isExceptionPolicyValid)(
enum ExceptionPolicy))
373 if (isExceptionPolicyValid(i)) {
374 snprintf(setting->
eps_name[i],
sizeof(setting->
eps_name[i]),
"%s%s", default_str,
393 uint64_t g_eps_applayer_error_offset_ts = UINT64_MAX;
394 uint64_t g_eps_applayer_error_offset_tc = UINT64_MAX;
395 uint64_t g_eps_pcap_packet_loss = UINT64_MAX;
396 uint64_t g_eps_stream_ssn_memcap = UINT64_MAX;
397 uint64_t g_eps_stream_reassembly_memcap = UINT64_MAX;
398 uint64_t g_eps_flow_memcap = UINT64_MAX;
399 uint64_t g_eps_defrag_memcap = UINT64_MAX;
400 bool g_eps_is_alert_queue_fail_mode =
false;
405 if (strcmp(
name,
"simulate-applayer-error-at-offset-ts") == 0) {
411 g_eps_applayer_error_offset_ts =
offset;
412 }
else if (strcmp(
name,
"simulate-applayer-error-at-offset-tc") == 0) {
418 g_eps_applayer_error_offset_tc =
offset;
419 }
else if (strcmp(
name,
"simulate-packet-loss") == 0) {
421 uint64_t pkt_num = 0;
425 g_eps_pcap_packet_loss = pkt_num;
426 }
else if (strcmp(
name,
"simulate-packet-tcp-reassembly-memcap") == 0) {
428 uint64_t pkt_num = 0;
432 g_eps_stream_reassembly_memcap = pkt_num;
433 }
else if (strcmp(
name,
"simulate-packet-tcp-ssn-memcap") == 0) {
435 uint64_t pkt_num = 0;
439 g_eps_stream_ssn_memcap = pkt_num;
440 }
else if (strcmp(
name,
"simulate-packet-flow-memcap") == 0) {
442 uint64_t pkt_num = 0;
446 g_eps_flow_memcap = pkt_num;
447 }
else if (strcmp(
name,
"simulate-packet-defrag-memcap") == 0) {
449 uint64_t pkt_num = 0;
453 g_eps_defrag_memcap = pkt_num;
454 }
else if (strcmp(
name,
"simulate-alert-queue-realloc-failure") == 0) {
455 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)
enum ExceptionPolicy g_eps_master_switch
@ PKT_DROP_REASON_STREAM_MEMCAP
@ PKT_DROP_REASON_FLOW_MEMCAP
@ EXCEPTION_POLICY_DROP_PACKET
int ParseSizeStringU64(const char *size, uint64_t *res)
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
uint16_t eps_id[EXCEPTION_POLICY_MAX]
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)
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)
@ PKT_DROP_REASON_STREAM_MIDSTREAM
uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
Registers a normal, unqualified counter.
enum ExceptionPolicy DefragGetMemcapExceptionPolicy(void)
char eps_name[EXCEPTION_POLICY_MAX][EXCEPTION_POLICY_COUNTER_MAX_LEN]