};
static const guint64 rspamd_fuzzy_storage_magic = 0x291a3253eb1b3ea5ULL;
-KHASH_SET_INIT_INT(fuzzy_key_forbidden_ids);
-
+KHASH_SET_INIT_INT(fuzzy_key_ids_set);
struct rspamd_fuzzy_storage_ctx {
guint64 magic;
gint lua_pre_handler_cbref;
gint lua_post_handler_cbref;
gint lua_blacklist_cbref;
- khash_t(fuzzy_key_forbidden_ids) *default_forbidden_ids;
+ khash_t(fuzzy_key_ids_set) *default_forbidden_ids;
+ /* Ids that should not override other ids */
+ khash_t(fuzzy_key_ids_set) *weak_ids;
};
enum fuzzy_cmd_type {
struct rspamd_cryptobox_pubkey *pk;
struct fuzzy_key_stat *stat;
khash_t(fuzzy_key_flag_stat) *flags_stat;
- khash_t(fuzzy_key_forbidden_ids) *forbidden_ids;
+ khash_t(fuzzy_key_ids_set) *forbidden_ids;
};
struct rspamd_updates_cbdata {
}
if (key->forbidden_ids) {
- kh_destroy(fuzzy_key_forbidden_ids, key->forbidden_ids);
+ kh_destroy(fuzzy_key_ids_set, key->forbidden_ids);
}
g_free (key);
{
khiter_t k;
- k = kh_get(fuzzy_key_forbidden_ids, session->ctx->default_forbidden_ids, session->reply.rep.v1.flag);
+ k = kh_get(fuzzy_key_ids_set, session->ctx->default_forbidden_ids, session->reply.rep.v1.flag);
if (k != kh_end(session->ctx->default_forbidden_ids)) {
/* Hash is from a forbidden flag by default */
if (session->reply.rep.v1.prob > 0 && session->key && session->key->forbidden_ids) {
khiter_t k;
- k = kh_get(fuzzy_key_forbidden_ids, session->key->forbidden_ids, session->reply.rep.v1.flag);
+ k = kh_get(fuzzy_key_ids_set, session->key->forbidden_ids, session->reply.rep.v1.flag);
if (k != kh_end (session->key->forbidden_ids)) {
/* Hash is from a forbidden flag for this key */
}
}
+ if (session->ctx->weak_ids && kh_get(fuzzy_key_ids_set, session->ctx->weak_ids, cmd->flag) != kh_end(session->ctx->weak_ids)) {
+ /* Flag command as weak */
+ cmd->version |= RSPAMD_FUZZY_FLAG_WEAK;
+ }
+
if (session->worker->index == 0 || session->ctx->peer_fd == -1) {
/* Just add to the queue */
up_cmd.is_shingle = is_shingle;
{
enum rspamd_fuzzy_epoch ret = RSPAMD_FUZZY_EPOCH_MAX;
- switch (cmd->version) {
+ switch (cmd->version & RSPAMD_FUZZY_VERSION_MASK) {
case 4:
if (cmd->shingles_count > 0) {
if (r >= sizeof (struct rspamd_fuzzy_shingle_cmd)) {
}
static gboolean
- fuzzy_parse_forbidden_ids (rspamd_mempool_t *pool,
+fuzzy_parse_ids (rspamd_mempool_t *pool,
const ucl_object_t *obj,
gpointer ud,
struct rspamd_rcl_section *section,
GError **err)
{
struct rspamd_rcl_struct_parser *pd = (struct rspamd_rcl_struct_parser *)ud;
- struct rspamd_fuzzy_storage_ctx *ctx;
+ khash_t(fuzzy_key_ids_set) *target;
- ctx = (struct rspamd_fuzzy_storage_ctx *)pd->user_struct;
+ target = (khash_t(fuzzy_key_ids_set) *)pd->user_struct;
if (ucl_object_type (obj) == UCL_ARRAY) {
const ucl_object_t *cur;
if (ucl_object_toint_safe (cur, &id)) {
int r;
- kh_put(fuzzy_key_forbidden_ids, ctx->default_forbidden_ids, id, &r);
+ kh_put(fuzzy_key_ids_set, target, id, &r);
}
else {
return FALSE;
}
else if (ucl_object_type (obj) == UCL_INT) {
int r;
- kh_put(fuzzy_key_forbidden_ids, ctx->default_forbidden_ids, ucl_object_toint (obj), &r);
+ kh_put(fuzzy_key_ids_set, target, ucl_object_toint (obj), &r);
return TRUE;
}
const ucl_object_t *forbidden_ids = ucl_object_lookup (extensions, "forbidden_ids");
if (forbidden_ids && ucl_object_type (forbidden_ids) == UCL_ARRAY) {
- key->forbidden_ids = kh_init(fuzzy_key_forbidden_ids);
+ key->forbidden_ids = kh_init(fuzzy_key_ids_set);
while ((cur = ucl_object_iterate (forbidden_ids, &it, true)) != NULL) {
if (ucl_object_type(cur) == UCL_INT || ucl_object_type(cur) == UCL_FLOAT) {
int id = ucl_object_toint(cur);
int r;
- kh_put(fuzzy_key_forbidden_ids, key->forbidden_ids, id, &r);
+ kh_put(fuzzy_key_ids_set, key->forbidden_ids, id, &r);
}
}
}
ctx->leaky_bucket_burst = NAN;
ctx->leaky_bucket_rate = NAN;
ctx->delay = NAN;
- ctx->default_forbidden_ids = kh_init(fuzzy_key_forbidden_ids);
+ ctx->default_forbidden_ids = kh_init(fuzzy_key_ids_set);
+ ctx->weak_ids = kh_init(fuzzy_key_ids_set);
rspamd_rcl_register_worker_option (cfg,
type,
rspamd_rcl_register_worker_option (cfg,
type,
"forbidden_ids",
- fuzzy_parse_forbidden_ids,
- ctx,
+ fuzzy_parse_ids,
+ ctx->default_forbidden_ids,
0,
0,
"Deny specific flags by default");
+ rspamd_rcl_register_worker_option (cfg,
+ type,
+ "weak_ids",
+ fuzzy_parse_ids,
+ ctx->weak_ids,
+ 0,
+ 0,
+ "Treat these flags as weak (i.e. they do not overwrite strong flags)");
+
rspamd_rcl_register_worker_option (cfg,
type,
"keypair_cache_size",
}
if (ctx->default_forbidden_ids) {
- kh_destroy(fuzzy_key_forbidden_ids, ctx->default_forbidden_ids);
+ kh_destroy(fuzzy_key_ids_set, ctx->default_forbidden_ids);
+ }
+
+ if (ctx->weak_ids) {
+ kh_destroy(fuzzy_key_ids_set, ctx->weak_ids);
}
REF_RELEASE (ctx->cfg);