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) {
166 FlowSetNoPayloadInspectionFlag(p->
flow);
172 DecodeSetNoPayloadInspectionFlag(p);
173 DecodeSetNoPacketInspectionFlag(p);
187 DecodeSetNoPayloadInspectionFlag(p);
188 DecodeSetNoPacketInspectionFlag(p);
199 "flow actions not supported for %s, defaulting to \"drop-packet\"", option);
203 "flow actions not supported for %s, defaulting to \"pass-packet\"", option);
206 SCLogWarning(
"flow actions not supported for %s, defaulting to \"ignore\"", option);
226 const char *option,
const char *value_str)
229 if (strcmp(value_str,
"drop-flow") == 0) {
231 }
else if (strcmp(value_str,
"pass-flow") == 0) {
233 }
else if (strcmp(value_str,
"bypass") == 0) {
235 }
else if (strcmp(value_str,
"drop-packet") == 0) {
237 }
else if (strcmp(value_str,
"pass-packet") == 0) {
239 }
else if (strcmp(value_str,
"reject") == 0) {
241 }
else if (strcmp(value_str,
"rejectboth") == 0) {
243 }
else if (strcmp(value_str,
"ignore") == 0) {
245 }
else if (strcmp(value_str,
"auto") == 0) {
249 "\"%s\" is not a valid exception policy value. Valid options are drop-flow, "
250 "pass-flow, bypass, reject, drop-packet, pass-packet, ignore or auto.",
258 static enum ExceptionPolicy ExceptionPolicyPickAuto(
bool midstream_enabled,
bool support_flow)
271 static enum ExceptionPolicy ExceptionPolicyMasterParse(
const char *value)
273 enum ExceptionPolicy policy = ExceptionPolicyConfigValueParse(
"exception-policy", value);
278 g_eps_have_exception_policy =
true;
286 const char *option,
bool support_flow,
bool midstream)
289 if (g_eps_have_exception_policy) {
290 p = GetMasterExceptionPolicy();
293 p = ExceptionPolicyPickAuto(midstream, support_flow);
297 p = PickPacketAction(option, p);
299 SCLogConfig(
"%s: %s (defined via 'exception-policy' master switch)", option,
305 SCLogConfig(
"%s: %s (defined via 'built-in default' for %s-mode)", option,
314 const char *value_str = NULL;
316 if ((
SCConfGet(option, &value_str) == 1) && value_str != NULL) {
317 if (strcmp(option,
"exception-policy") == 0) {
318 policy = ExceptionPolicyMasterParse(value_str);
320 policy = ExceptionPolicyConfigValueParse(option, value_str);
322 policy = ExceptionPolicyPickAuto(
false, support_flow);
325 policy = PickPacketAction(option, policy);
330 policy = ExceptionPolicyGetDefault(option, support_flow,
false);
339 const char *value_str = NULL;
341 if ((
SCConfGet(
"stream.midstream-policy", &value_str)) == 1 && value_str != NULL) {
342 policy = ExceptionPolicyConfigValueParse(
"midstream-policy", value_str);
344 policy = ExceptionPolicyPickAuto(midstream_enabled,
true);
345 }
else if (midstream_enabled) {
348 "Error parsing stream.midstream-policy from config file. \"%s\" is "
349 "not a valid exception policy when midstream is enabled. Valid options "
350 "are pass-flow and ignore.",
357 "Error parsing stream.midstream-policy from config file. \"%s\" is "
358 "not a valid exception policy in IDS mode. See our documentation for a "
359 "list of all possible values.",
364 policy = ExceptionPolicyGetDefault(
"stream.midstream-policy",
true, midstream_enabled);
368 FatalErrorOnInit(
"Error parsing stream.midstream-policy from config file. \"%s\" is "
369 "not valid for this exception policy. See our documentation for a list of "
370 "all possible values.",
379 const char *default_str,
bool (*isExceptionPolicyValid)(
enum ExceptionPolicy))
384 if (isExceptionPolicyValid(i)) {
385 snprintf(setting->
eps_name[i],
sizeof(setting->
eps_name[i]),
"%s%s", default_str,
404 uint64_t g_eps_applayer_error_offset_ts = UINT64_MAX;
405 uint64_t g_eps_applayer_error_offset_tc = UINT64_MAX;
406 uint64_t g_eps_pcap_packet_loss = UINT64_MAX;
407 uint64_t g_eps_stream_ssn_memcap = UINT64_MAX;
408 uint64_t g_eps_stream_reassembly_memcap = UINT64_MAX;
409 uint64_t g_eps_flow_memcap = UINT64_MAX;
410 uint64_t g_eps_defrag_memcap = UINT64_MAX;
411 bool g_eps_is_alert_queue_fail_mode =
false;
416 if (strcmp(
name,
"simulate-applayer-error-at-offset-ts") == 0) {
422 g_eps_applayer_error_offset_ts =
offset;
423 }
else if (strcmp(
name,
"simulate-applayer-error-at-offset-tc") == 0) {
429 g_eps_applayer_error_offset_tc =
offset;
430 }
else if (strcmp(
name,
"simulate-packet-loss") == 0) {
432 uint64_t pkt_num = 0;
436 g_eps_pcap_packet_loss = pkt_num;
437 }
else if (strcmp(
name,
"simulate-packet-tcp-reassembly-memcap") == 0) {
439 uint64_t pkt_num = 0;
443 g_eps_stream_reassembly_memcap = pkt_num;
444 }
else if (strcmp(
name,
"simulate-packet-tcp-ssn-memcap") == 0) {
446 uint64_t pkt_num = 0;
450 g_eps_stream_ssn_memcap = pkt_num;
451 }
else if (strcmp(
name,
"simulate-packet-flow-memcap") == 0) {
453 uint64_t pkt_num = 0;
457 g_eps_flow_memcap = pkt_num;
458 }
else if (strcmp(
name,
"simulate-packet-defrag-memcap") == 0) {
460 uint64_t pkt_num = 0;
464 g_eps_defrag_memcap = pkt_num;
465 }
else if (strcmp(
name,
"simulate-alert-queue-realloc-failure") == 0) {
466 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
@ 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)
#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)
@ 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]