aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-05-12 20:15:19 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-05-12 20:15:19 +0100
commit985a09cc101b06c3fb14e3bc33400ae1628f4b6e (patch)
tree1cbc5dad44dbf35bf4879d9799d91fb8a6040574
parent6a183f820fd4db594a7a9730aa084a8216827fd4 (diff)
downloadrspamd-985a09cc101b06c3fb14e3bc33400ae1628f4b6e.tar.gz
rspamd-985a09cc101b06c3fb14e3bc33400ae1628f4b6e.zip
[Feature] Allow to specify different timeouts/retransmits for fuzzy rules
-rw-r--r--src/plugins/fuzzy_check.c45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index a14c4f7b9..bd45fd8d0 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -50,7 +50,7 @@
#define DEFAULT_SYMBOL "R_FUZZY_HASH"
-#define DEFAULT_IO_TIMEOUT 500
+#define DEFAULT_IO_TIMEOUT 1.0
#define DEFAULT_RETRANSMITS 3
#define DEFAULT_MAX_ERRORS 4
#define DEFAULT_REVIVE_TIME 60
@@ -79,6 +79,7 @@ struct fuzzy_rule {
GPtrArray *fuzzy_headers;
GString *hash_key;
GString *shingles_key;
+ gdouble io_timeout;
struct rspamd_cryptobox_keypair *local_key;
struct rspamd_cryptobox_pubkey *peer_key;
double max_score;
@@ -88,6 +89,7 @@ struct fuzzy_rule {
gboolean no_share;
gboolean no_subject;
gint learn_condition_cb;
+ guint32 retransmits;
struct rspamd_hash_map_helper *skip_map;
struct fuzzy_ctx *ctx;
gint lua_id;
@@ -101,13 +103,13 @@ struct fuzzy_ctx {
const gchar *default_symbol;
struct rspamd_radix_map_helper *whitelist;
struct rspamd_keypair_cache *keypairs_cache;
- guint32 io_timeout;
- guint32 retransmits;
guint max_errors;
gdouble revive_time;
+ gdouble io_timeout;
gint check_mime_part_ref; /* Lua callback */
gint process_rule_ref; /* Lua callback */
gint cleanup_rules_ref;
+ guint32 retransmits;
gboolean enabled;
};
@@ -419,6 +421,20 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj,
rule->max_score = ucl_obj_todouble (value);
}
+ if ((value = ucl_object_lookup (obj, "retransmits")) != NULL) {
+ rule->retransmits = ucl_obj_toint (value);
+ }
+ else {
+ rule->retransmits = fuzzy_module_ctx->retransmits;
+ }
+
+ if ((value = ucl_object_lookup (obj, "timeout")) != NULL) {
+ rule->io_timeout = ucl_obj_todouble (value);
+ }
+ else {
+ rule->io_timeout = fuzzy_module_ctx->io_timeout;
+ }
+
if ((value = ucl_object_lookup (obj, "symbol")) != NULL) {
rule->symbol = ucl_obj_tostring (value);
}
@@ -1054,7 +1070,7 @@ fuzzy_check_module_config (struct rspamd_config *cfg, bool validate)
if ((value =
rspamd_config_get_module_opt (cfg, "fuzzy_check", "timeout")) != NULL) {
- fuzzy_module_ctx->io_timeout = ucl_obj_todouble (value) * 1000;
+ fuzzy_module_ctx->io_timeout = ucl_obj_todouble (value);
}
else {
fuzzy_module_ctx->io_timeout = DEFAULT_IO_TIMEOUT;
@@ -2543,12 +2559,13 @@ fuzzy_check_timer_callback (gint fd, short what, void *arg)
}
}
- if (session->retransmits >= session->rule->ctx->retransmits) {
- msg_err_task ("got IO timeout with server %s(%s), after %d retransmits",
+ if (session->retransmits >= session->rule->retransmits) {
+ msg_err_task ("got IO timeout with server %s(%s), after %d/%d retransmits",
rspamd_upstream_name (session->server),
rspamd_inet_address_to_string_pretty (
rspamd_upstream_addr_cur (session->server)),
- session->retransmits);
+ session->retransmits,
+ session->rule->retransmits);
rspamd_upstream_fail (session->server, TRUE, "timeout");
if (session->item) {
@@ -2671,14 +2688,15 @@ fuzzy_controller_timer_callback (gint fd, short what, void *arg)
task = session->task;
- if (session->retransmits >= session->rule->ctx->retransmits) {
+ if (session->retransmits >= session->rule->retransmits) {
rspamd_upstream_fail (session->server, TRUE, "timeout");
msg_err_task_check ("got IO timeout with server %s(%s), "
- "after %d retransmits",
+ "after %d/%d retransmits",
rspamd_upstream_name (session->server),
rspamd_inet_address_to_string_pretty (
rspamd_upstream_addr_cur (session->server)),
- session->retransmits);
+ session->retransmits,
+ session->rule->retransmits);
if (session->session) {
rspamd_session_remove_event (session->session, fuzzy_lua_fin,
@@ -3169,7 +3187,7 @@ register_fuzzy_client_call (struct rspamd_task *task,
fuzzy_check_io_callback,
session);
rspamd_ev_watcher_start (session->event_loop, &session->ev,
- ((double)rule->ctx->io_timeout) / 1000.0);
+ rule->io_timeout);
rspamd_session_add_event (task->s, fuzzy_io_fin, session, M);
session->item = rspamd_symcache_get_cur_item (task);
@@ -3295,8 +3313,7 @@ register_fuzzy_controller_call (struct rspamd_http_connection_entry *entry,
EV_WRITE,
fuzzy_controller_io_callback,
s);
- rspamd_ev_watcher_start (s->event_loop, &s->ev,
- ((double)rule->ctx->io_timeout) / 1000.0);
+ rspamd_ev_watcher_start (s->event_loop, &s->ev, rule->io_timeout);
(*saved)++;
ret = 1;
@@ -3650,7 +3667,7 @@ fuzzy_check_send_lua_learn (struct fuzzy_rule *rule,
fuzzy_controller_io_callback,
s);
rspamd_ev_watcher_start (s->event_loop, &s->ev,
- ((double)rule->ctx->io_timeout) / 1000.0);
+ rule->io_timeout);
rspamd_session_add_event (task->s,
fuzzy_lua_fin,