Skip to content

Commit

Permalink
threshold: add by_flow support for global thresholds
Browse files Browse the repository at this point in the history
Allow rate_filter and thresholds from the global config to specify
tracking "by_flow".
  • Loading branch information
victorjulien committed Mar 2, 2024
1 parent f028db7 commit aa462a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/detect-engine-threshold.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ static int ThresholdHandlePacketSuppress(Packet *p,
}
break;
case TRACK_RULE:
case TRACK_FLOW:
default:
SCLogError("track mode %d is not supported", td->track);
break;
Expand Down
10 changes: 8 additions & 2 deletions src/util-threshold-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ static FILE *g_ut_threshold_fp = NULL;
#define DETECT_BASE_REGEX "^\\s*(event_filter|threshold|rate_filter|suppress)\\s*gen_id\\s*(\\d+)\\s*,\\s*sig_id\\s*(\\d+)\\s*(.*)\\s*$"

#define DETECT_THRESHOLD_REGEX \
"^,\\s*type\\s*(limit|both|threshold)\\s*,\\s*track\\s*(by_dst|by_src|by_both|by_rule)\\s*," \
"^,\\s*type\\s*(limit|both|threshold)\\s*,\\s*track\\s*(by_dst|by_src|by_both|by_rule|by_" \
"flow)\\s*," \
"\\s*count\\s*(\\d+)\\s*,\\s*seconds\\s*(\\d+)\\s*$"

/* TODO: "apply_to" */
#define DETECT_RATE_REGEX "^,\\s*track\\s*(by_dst|by_src|by_both|by_rule)\\s*,\\s*count\\s*(\\d+)\\s*,\\s*seconds\\s*(\\d+)\\s*,\\s*new_action\\s*(alert|drop|pass|log|sdrop|reject)\\s*,\\s*timeout\\s*(\\d+)\\s*$"
#define DETECT_RATE_REGEX \
"^,\\s*track\\s*(by_dst|by_src|by_both|by_rule|by_flow)\\s*,\\s*count\\s*(\\d+)\\s*,\\s*" \
"seconds\\s*(\\d+)\\s*,\\s*new_action\\s*(alert|drop|pass|log|sdrop|reject)\\s*,\\s*" \
"timeout\\s*(\\d+)\\s*$"

/*
* suppress has two form:
Expand Down Expand Up @@ -796,6 +800,8 @@ static int ParseThresholdRule(const DetectEngineCtx *de_ctx, char *rawstr, uint3
}
else if (strcasecmp(th_track,"by_rule") == 0)
parsed_track = TRACK_RULE;
else if (strcasecmp(th_track, "by_flow") == 0)
parsed_track = TRACK_FLOW;
else {
SCLogError("Invalid track parameter %s in %s", th_track, rawstr);
goto error;
Expand Down

0 comments on commit aa462a8

Please sign in to comment.