if (ctx->secure_ip != NULL) {
rspamd_config_radix_from_ucl (ctx->cfg, ctx->secure_ip,
"Allow unauthenticated requests from these addresses",
- &ctx->secure_map, NULL);
+ &ctx->secure_map,
+ NULL,
+ worker);
}
ctx->lang_det = ctx->cfg->lang_det;
if (ctx->update_map != NULL) {
rspamd_config_radix_from_ucl (worker->srv->cfg, ctx->update_map,
"Allow fuzzy updates from specified addresses",
- &ctx->update_ips, NULL);
+ &ctx->update_ips, NULL, worker);
}
if (ctx->skip_map != NULL) {
rspamd_kv_list_read,
rspamd_kv_list_fin,
rspamd_kv_list_dtor,
- (void **)&ctx->skip_hashes)) == NULL) {
+ (void **)&ctx->skip_hashes,
+ worker)) == NULL) {
msg_warn_config ("cannot load hashes list from %s",
ucl_object_tostring (ctx->skip_map));
}
if (ctx->blocked_map != NULL) {
rspamd_config_radix_from_ucl (worker->srv->cfg, ctx->blocked_map,
"Block fuzzy requests from the specific IPs",
- &ctx->blocked_ips, NULL);
+ &ctx->blocked_ips,
+ NULL,
+ worker);
}
/* Create radix trees */
if (ctx->ratelimit_whitelist_map != NULL) {
rspamd_config_radix_from_ucl (worker->srv->cfg, ctx->ratelimit_whitelist_map,
"Skip ratelimits from specific ip addresses/networks",
- &ctx->ratelimit_whitelist, NULL);
+ &ctx->ratelimit_whitelist,
+ NULL,
+ worker);
}
/* Ratelimits */
ctx->resolver = rspamd_dns_resolver_init (worker->srv->logger,
ctx->event_loop,
worker->srv->cfg);
- rspamd_map_watch (worker->srv->cfg, ctx->event_loop, ctx->resolver, worker, 0);
+ rspamd_map_watch (worker->srv->cfg, ctx->event_loop,
+ ctx->resolver, worker, RSPAMD_MAP_WATCH_WORKER);
/* Get peer pipe */
memset (&srv_cmd, 0, sizeof (srv_cmd));
const ucl_object_t *obj,
const gchar *description,
struct rspamd_radix_map_helper **target,
- GError **err);
+ GError **err,
+ struct rspamd_worker *worker);
/**
* Adds new settings id to be preprocessed
rspamd_ucl_read_cb,
rspamd_ucl_fin_cb,
rspamd_ucl_dtor_cb,
- (void **)pcbdata) != NULL;
+ (void **)pcbdata,
+ NULL) != NULL;
}
/*
gboolean
rspamd_config_radix_from_ucl (struct rspamd_config *cfg,
- const ucl_object_t *obj,
- const gchar *description,
- struct rspamd_radix_map_helper **target,
- GError **err)
+ const ucl_object_t *obj,
+ const gchar *description,
+ struct rspamd_radix_map_helper **target,
+ GError **err,
+ struct rspamd_worker *worker)
{
ucl_type_t type;
ucl_object_iter_t it = NULL;
rspamd_radix_read,
rspamd_radix_fin,
rspamd_radix_dtor,
- (void **)target) == NULL) {
- g_set_error (err, g_quark_from_static_string ("rspamd-config"),
+ (void **)target,
+ worker) == NULL) {
+ g_set_error (err,
+ g_quark_from_static_string ("rspamd-config"),
EINVAL, "bad map definition %s for %s", str,
ucl_object_key (obj));
return FALSE;
rspamd_radix_read,
rspamd_radix_fin,
rspamd_radix_dtor,
- (void **)target) == NULL) {
- g_set_error (err, g_quark_from_static_string ("rspamd-config"),
+ (void **)target,
+ worker) == NULL) {
+ g_set_error (err,
+ g_quark_from_static_string ("rspamd-config"),
EINVAL, "bad map object for %s", ucl_object_key (obj));
return FALSE;
}
json_config_read_cb,
json_config_fin_cb,
json_config_dtor_cb,
- (void **)pjb)) {
+ (void **)pjb, NULL)) {
msg_err ("cannot add map for configuration %s", cfg->dynamic_conf);
}
}
ev_timer_start (ctx->event_loop, &cbd.save_stats_event);
rspamd_map_watch (worker->srv->cfg, ctx->event_loop,
- ctx->resolver, worker, TRUE);
+ ctx->resolver, worker,
+ RSPAMD_MAP_WATCH_PRIMARY_CONTROLLER);
if (prrd != NULL) {
if (ctx->cfg->rrd_file && worker->index == 0) {
}
else {
rspamd_map_watch (worker->srv->cfg, ctx->event_loop,
- ctx->resolver, worker, FALSE);
+ ctx->resolver, worker, RSPAMD_MAP_WATCH_SCANNER);
}
}
\ No newline at end of file
rspamd_config_radix_from_ucl (cfg,
cfg->debug_ip_map,
"IP addresses for which debug logs are enabled",
- &logger->debug_ip, NULL);
+ &logger->debug_ip,
+ NULL,
+ NULL);
}
else if (logger->debug_ip) {
rspamd_map_helper_destroy_radix (logger->debug_ip);
struct ev_loop *event_loop,
struct rspamd_dns_resolver *resolver,
struct rspamd_worker *worker,
- gboolean active_http)
+ enum rspamd_map_watch_type how)
{
GList *cur = cfg->maps;
struct rspamd_map *map;
struct rspamd_map_backend *bk;
guint i;
+ g_assert (how > RSPAMD_MAP_WATCH_MIN && how < RSPAMD_MAP_WATCH_MAX);
+
/* First of all do synced read of data */
while (cur) {
map = cur->data;
map->event_loop = event_loop;
map->r = resolver;
- map->wrk = worker;
- if (active_http) {
- map->active_http = active_http;
+ if (map->wrk == NULL && how != RSPAMD_MAP_WATCH_WORKER) {
+ /* Generic scanner map */
+ map->wrk = worker;
+
+ if (how == RSPAMD_MAP_WATCH_PRIMARY_CONTROLLER) {
+ map->active_http = TRUE;
+ }
+ else {
+ map->active_http = FALSE;
+ }
+ }
+ else if (map->wrk != NULL && map->wrk == worker) {
+ /* Map is bound to a specific worker */
+ map->active_http = TRUE;
+ }
+ else {
+ /* Skip map for this worker as irrelevant */
+ cur = g_list_next (cur);
+ continue;
}
if (!map->active_http) {
map_cb_t read_callback,
map_fin_cb_t fin_callback,
map_dtor_t dtor,
- void **user_data)
+ void **user_data,
+ struct rspamd_worker *worker)
{
struct rspamd_map *map;
struct rspamd_map_backend *bk;
map->locked =
rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (gint));
map->backends = g_ptr_array_sized_new (1);
+ map->wrk = worker;
rspamd_mempool_add_destructor (cfg->cfg_pool, rspamd_ptr_array_free_hard,
map->backends);
g_ptr_array_add (map->backends, bk);
map_cb_t read_callback,
map_fin_cb_t fin_callback,
map_dtor_t dtor,
- void **user_data)
+ void **user_data,
+ struct rspamd_worker *worker)
{
ucl_object_iter_t it = NULL;
const ucl_object_t *cur, *elt;
if (ucl_object_type (obj) == UCL_STRING) {
/* Just a plain string */
return rspamd_map_add (cfg, ucl_object_tostring (obj), description,
- read_callback, fin_callback, dtor, user_data);
+ read_callback, fin_callback, dtor, user_data, worker);
}
map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_map));
map->locked =
rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (gint));
map->backends = g_ptr_array_new ();
+ map->wrk = worker;
rspamd_mempool_add_destructor (cfg->cfg_pool, rspamd_ptr_array_free_hard,
map->backends);
map->poll_timeout = cfg->map_timeout;
map_cb_t read_callback,
map_fin_cb_t fin_callback,
map_dtor_t dtor,
- void **user_data);
+ void **user_data,
+ struct rspamd_worker *worker);
/**
* Add map from ucl
map_cb_t read_callback,
map_fin_cb_t fin_callback,
map_dtor_t dtor,
- void **user_data);
+ void **user_data,
+ struct rspamd_worker *worker);
+
+enum rspamd_map_watch_type {
+ RSPAMD_MAP_WATCH_MIN = 9,
+ RSPAMD_MAP_WATCH_PRIMARY_CONTROLLER,
+ RSPAMD_MAP_WATCH_SCANNER,
+ RSPAMD_MAP_WATCH_WORKER,
+ RSPAMD_MAP_WATCH_MAX
+};
/**
* Start watching of maps by adding events to libevent event loop
struct ev_loop *event_loop,
struct rspamd_dns_resolver *resolver,
struct rspamd_worker *worker,
- gboolean active_http);
+ enum rspamd_map_watch_type how);
/**
* Preloads maps where all backends are file
if (cfg->local_addrs) {
rspamd_config_radix_from_ucl (cfg, cfg->local_addrs,
"Local addresses",
- ctx->local_addrs, NULL);
+ ctx->local_addrs,
+ NULL,
+ NULL);
}
if (cfg->ssl_ca_path) {
rspamd_radix_read,
rspamd_radix_fin,
rspamd_radix_dtor,
- (void **)&map->data.radix)) == NULL) {
+ (void **)&map->data.radix,
+ NULL)) == NULL) {
msg_warn_config ("invalid radix map %s", map_line);
lua_pushnil (L);
rspamd_radix_read,
rspamd_radix_fin,
rspamd_radix_dtor,
- (void **)&map->data.radix)) == NULL) {
+ (void **)&map->data.radix,
+ NULL)) == NULL) {
msg_err_config ("invalid radix map static");
lua_pushnil (L);
ucl_object_unref (fake_obj);
rspamd_radix_read,
rspamd_radix_fin,
rspamd_radix_dtor,
- (void **)&map->data.radix)) == NULL) {
+ (void **)&map->data.radix,
+ NULL)) == NULL) {
msg_err_config ("invalid radix map static");
lua_pushnil (L);
ucl_object_unref (fake_obj);
rspamd_kv_list_read,
rspamd_kv_list_fin,
rspamd_kv_list_dtor,
- (void **)&map->data.hash)) == NULL) {
+ (void **)&map->data.hash,
+ NULL)) == NULL) {
msg_warn_config ("invalid set map %s", map_line);
lua_pushnil (L);
return 1;
rspamd_kv_list_read,
rspamd_kv_list_fin,
rspamd_kv_list_dtor,
- (void **)&map->data.hash)) == NULL) {
+ (void **)&map->data.hash,
+ NULL)) == NULL) {
msg_warn_config ("invalid hash map %s", map_line);
lua_pushnil (L);
lua_map_read,
lua_map_fin,
lua_map_dtor,
- (void **)&map->data.cbdata)) == NULL) {
+ (void **)&map->data.cbdata,
+ NULL)) == NULL) {
if (cbidx != -1) {
luaL_unref (L, LUA_REGISTRYINDEX, cbidx);
rspamd_kv_list_read,
rspamd_kv_list_fin,
rspamd_kv_list_dtor,
- (void **)&map->data.hash)) == NULL) {
+ (void **)&map->data.hash,
+ NULL)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
rspamd_kv_list_read,
rspamd_kv_list_fin,
rspamd_kv_list_dtor,
- (void **)&map->data.hash)) == NULL) {
+ (void **)&map->data.hash,
+ NULL)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
rspamd_radix_read,
rspamd_radix_fin,
rspamd_radix_dtor,
- (void **)&map->data.radix)) == NULL) {
+ (void **)&map->data.radix,
+ NULL)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
rspamd_regexp_list_read_single,
rspamd_regexp_list_fin,
rspamd_regexp_list_dtor,
- (void **) &map->data.re_map)) == NULL) {
+ (void **) &map->data.re_map,
+ NULL)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
rspamd_regexp_list_read_multiple,
rspamd_regexp_list_fin,
rspamd_regexp_list_dtor,
- (void **) &map->data.re_map)) == NULL) {
+ (void **) &map->data.re_map,
+ NULL)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
rspamd_glob_list_read_single,
rspamd_regexp_list_fin,
rspamd_regexp_list_dtor,
- (void **) &map->data.re_map)) == NULL) {
+ (void **) &map->data.re_map,
+ NULL)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
rspamd_glob_list_read_multiple,
rspamd_regexp_list_fin,
rspamd_regexp_list_dtor,
- (void **) &map->data.re_map)) == NULL) {
+ (void **) &map->data.re_map,
+ NULL)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
rspamd_config_get_module_opt (cfg, "dkim", "whitelist")) != NULL) {
rspamd_config_radix_from_ucl (cfg, value, "DKIM whitelist",
- &dkim_module_ctx->whitelist_ip, NULL);
+ &dkim_module_ctx->whitelist_ip, NULL, NULL);
}
if ((value =
rspamd_kv_list_read,
rspamd_kv_list_fin,
rspamd_kv_list_dtor,
- (void **)&dkim_module_ctx->dkim_domains)) {
+ (void **)&dkim_module_ctx->dkim_domains,
+ NULL)) {
msg_warn_config ("cannot load dkim domains list from %s",
ucl_object_tostring (value));
}
rspamd_kv_list_read,
rspamd_kv_list_fin,
rspamd_kv_list_dtor,
- (void **)&dkim_module_ctx->dkim_domains)) {
+ (void **)&dkim_module_ctx->dkim_domains,
+ NULL)) {
msg_warn_config ("cannot load dkim domains list from %s",
ucl_object_tostring (value));
}
rspamd_kv_list_read,
rspamd_kv_list_fin,
rspamd_kv_list_dtor,
- (void **)&rule->skip_map);
+ (void **)&rule->skip_map,
+ NULL);
}
if ((value = ucl_object_lookup (obj, "headers")) != NULL) {
rspamd_config_get_module_opt (cfg, "fuzzy_check",
"whitelist")) != NULL) {
rspamd_config_radix_from_ucl (cfg, value, "Fuzzy whitelist",
- &fuzzy_module_ctx->whitelist, NULL);
+ &fuzzy_module_ctx->whitelist,
+ NULL,
+ NULL);
}
else {
fuzzy_module_ctx->whitelist = NULL;
rspamd_config_get_module_opt (cfg, "spf", "whitelist")) != NULL) {
rspamd_config_radix_from_ucl (cfg, value, "SPF whitelist",
- &spf_module_ctx->whitelist_ip, NULL);
+ &spf_module_ctx->whitelist_ip, NULL, NULL);
}
cb_id = rspamd_symcache_add_symbol (cfg->cache,
rspamd_worker_init_controller (worker, NULL);
}
else {
- rspamd_map_watch (worker->srv->cfg, ctx->event_loop, ctx->resolver,
- worker, 0);
+ if (ctx->has_self_scan) {
+ rspamd_map_watch (worker->srv->cfg, ctx->event_loop, ctx->resolver,
+ worker, RSPAMD_MAP_WATCH_SCANNER);
+ }
+ else {
+ rspamd_map_watch (worker->srv->cfg, ctx->event_loop, ctx->resolver,
+ worker, RSPAMD_MAP_WATCH_WORKER);
+ }
}
rspamd_lua_run_postloads (ctx->cfg->lua_state, ctx->cfg, ctx->event_loop,
}
else {
rspamd_map_watch (worker->srv->cfg, ctx->event_loop, ctx->resolver,
- worker, 0);
+ worker, RSPAMD_MAP_WATCH_SCANNER);
}
rspamd_lua_run_postloads (ctx->cfg->lua_state, ctx->cfg, ctx->event_loop,