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);
159 FlowSetNoPacketInspectionFlag(p->
flow);
165 DecodeSetNoPayloadInspectionFlag(p);
166 DecodeSetNoPacketInspectionFlag(p);
176 FlowSetNoPacketInspectionFlag(p->
flow);
181 DecodeSetNoPayloadInspectionFlag(p);
182 DecodeSetNoPacketInspectionFlag(p);
193 "flow actions not supported for %s, defaulting to \"drop-packet\"", option);
197 "flow actions not supported for %s, defaulting to \"pass-packet\"", option);
200 SCLogWarning(
"flow actions not supported for %s, defaulting to \"ignore\"", option);
219 const char *option,
const char *value_str)
222 if (strcmp(value_str,
"drop-flow") == 0) {
224 }
else if (strcmp(value_str,
"pass-flow") == 0) {
226 }
else if (strcmp(value_str,
"bypass") == 0) {
228 }
else if (strcmp(value_str,
"drop-packet") == 0) {
230 }
else if (strcmp(value_str,
"pass-packet") == 0) {
232 }
else if (strcmp(value_str,
"reject") == 0) {
234 }
else if (strcmp(value_str,
"ignore") == 0) {
236 }
else if (strcmp(value_str,
"auto") == 0) {
240 "\"%s\" is not a valid exception policy value. Valid options are drop-flow, "
241 "pass-flow, bypass, reject, drop-packet, pass-packet, ignore or auto.",
249 static enum ExceptionPolicy ExceptionPolicyPickAuto(
bool midstream_enabled,
bool support_flow)
262 static enum ExceptionPolicy ExceptionPolicyMasterParse(
const char *value)
264 enum ExceptionPolicy policy = ExceptionPolicyConfigValueParse(
"exception-policy", value);
269 g_eps_have_exception_policy =
true;
277 const char *option,
bool support_flow,
bool midstream)
280 if (g_eps_have_exception_policy) {
281 p = GetMasterExceptionPolicy();
284 p = ExceptionPolicyPickAuto(midstream, support_flow);
288 p = PickPacketAction(option, p);
290 SCLogConfig(
"%s: %s (defined via 'exception-policy' master switch)", option,
296 SCLogConfig(
"%s: %s (defined via 'built-in default' for %s-mode)", option,
305 const char *value_str = NULL;
307 if ((
ConfGet(option, &value_str) == 1) && value_str != NULL) {
308 if (strcmp(option,
"exception-policy") == 0) {
309 policy = ExceptionPolicyMasterParse(value_str);
311 policy = ExceptionPolicyConfigValueParse(option, value_str);
313 policy = ExceptionPolicyPickAuto(
false, support_flow);
316 policy = PickPacketAction(option, policy);
321 policy = ExceptionPolicyGetDefault(option, support_flow,
false);
330 const char *value_str = NULL;
332 if ((
ConfGet(
"stream.midstream-policy", &value_str)) == 1 && value_str != NULL) {
333 policy = ExceptionPolicyConfigValueParse(
"midstream-policy", value_str);
335 policy = ExceptionPolicyPickAuto(midstream_enabled,
true);
336 }
else if (midstream_enabled) {
339 "Error parsing stream.midstream-policy from config file. \"%s\" is "
340 "not a valid exception policy when midstream is enabled. Valid options "
341 "are pass-flow and ignore.",
348 "Error parsing stream.midstream-policy from config file. \"%s\" is "
349 "not a valid exception policy in IDS mode. See our documentation for a "
350 "list of all possible values.",
355 policy = ExceptionPolicyGetDefault(
"stream.midstream-policy",
true, midstream_enabled);
359 FatalErrorOnInit(
"Error parsing stream.midstream-policy from config file. \"%s\" is "
360 "not valid for this exception policy. See our documentation for a list of "
361 "all possible values.",
370 const char *default_str,
bool (*isExceptionPolicyValid)(
enum ExceptionPolicy))
375 if (isExceptionPolicyValid(i)) {
376 snprintf(setting->
eps_name[i],
sizeof(setting->
eps_name[i]),
"%s%s", default_str,
395 uint64_t g_eps_applayer_error_offset_ts = UINT64_MAX;
396 uint64_t g_eps_applayer_error_offset_tc = UINT64_MAX;
397 uint64_t g_eps_pcap_packet_loss = UINT64_MAX;
398 uint64_t g_eps_stream_ssn_memcap = UINT64_MAX;
399 uint64_t g_eps_stream_reassembly_memcap = UINT64_MAX;
400 uint64_t g_eps_flow_memcap = UINT64_MAX;
401 uint64_t g_eps_defrag_memcap = UINT64_MAX;
402 bool g_eps_is_alert_queue_fail_mode =
false;
407 if (strcmp(
name,
"simulate-applayer-error-at-offset-ts") == 0) {
413 g_eps_applayer_error_offset_ts =
offset;
414 }
else if (strcmp(
name,
"simulate-applayer-error-at-offset-tc") == 0) {
420 g_eps_applayer_error_offset_tc =
offset;
421 }
else if (strcmp(
name,
"simulate-packet-loss") == 0) {
423 uint64_t pkt_num = 0;
427 g_eps_pcap_packet_loss = pkt_num;
428 }
else if (strcmp(
name,
"simulate-packet-tcp-reassembly-memcap") == 0) {
430 uint64_t pkt_num = 0;
434 g_eps_stream_reassembly_memcap = pkt_num;
435 }
else if (strcmp(
name,
"simulate-packet-tcp-ssn-memcap") == 0) {
437 uint64_t pkt_num = 0;
441 g_eps_stream_ssn_memcap = pkt_num;
442 }
else if (strcmp(
name,
"simulate-packet-flow-memcap") == 0) {
444 uint64_t pkt_num = 0;
448 g_eps_flow_memcap = pkt_num;
449 }
else if (strcmp(
name,
"simulate-packet-defrag-memcap") == 0) {
451 uint64_t pkt_num = 0;
455 g_eps_defrag_memcap = pkt_num;
456 }
else if (strcmp(
name,
"simulate-alert-queue-realloc-failure") == 0) {
457 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)
#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)
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
#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]