diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-01 17:35:47 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-01 17:35:47 +0100 |
commit | 6f8fa405cf5d394491b987d824f5e1b74c14a4c8 (patch) | |
tree | 461a516b628265e9e4767f890f13766218535b41 | |
parent | ebdf58dc0aed1014374dc56c0b28fe76f3b0c0b1 (diff) | |
download | rspamd-6f8fa405cf5d394491b987d824f5e1b74c14a4c8.tar.gz rspamd-6f8fa405cf5d394491b987d824f5e1b74c14a4c8.zip |
Rework parsing of ip lists.
-rw-r--r-- | src/controller.c | 2 | ||||
-rw-r--r-- | src/fuzzy_storage.c | 2 | ||||
-rw-r--r-- | src/libserver/cfg_file.h | 6 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 10 | ||||
-rw-r--r-- | src/libutil/logger.c | 2 | ||||
-rw-r--r-- | src/libutil/radix.c | 10 | ||||
-rw-r--r-- | src/libutil/radix.h | 7 | ||||
-rw-r--r-- | src/plugins/dkim_check.c | 16 | ||||
-rw-r--r-- | src/plugins/fuzzy_check.c | 2 | ||||
-rw-r--r-- | src/plugins/spf.c | 2 |
10 files changed, 29 insertions, 30 deletions
diff --git a/src/controller.c b/src/controller.c index da0a8c31c..5b2915ef4 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1645,7 +1645,7 @@ start_controller_worker (struct rspamd_worker *worker) if (!add_map (worker->srv->cfg, ctx->secure_ip, "Allow webui access from the specified IP", read_radix_list, fin_radix_list, (void **)&ctx->secure_map)) { - if (!rspamd_config_parse_ip_list (ctx->secure_ip, + if (!radix_add_generic_iplist (ctx->secure_ip, &ctx->secure_map)) { msg_warn ("cannot load or parse ip list from '%s'", ctx->secure_ip); diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 153009435..fec7a13c2 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -1058,7 +1058,7 @@ start_fuzzy (struct rspamd_worker *worker) if (!add_map (worker->srv->cfg, ctx->update_map, "Allow fuzzy updates from specified addresses", read_radix_list, fin_radix_list, (void **)&ctx->update_ips)) { - if (!rspamd_config_parse_ip_list (ctx->update_map, + if (!radix_add_generic_iplist (ctx->update_map, &ctx->update_ips)) { msg_warn ("cannot load or parse ip list from '%s'", ctx->update_map); diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 7e3d60db8..c08fe0c80 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -476,12 +476,6 @@ struct rspamd_classifier_config * rspamd_config_find_classifier ( struct rspamd_config *cfg, const gchar *name); -/* - * Parse input `ip_list` to radix tree `tree`. Now supports only IPv4 addresses. - */ -gboolean rspamd_config_parse_ip_list (const gchar *ip_list, - radix_compressed_t **tree); - void rspamd_ucl_add_conf_macros (struct ucl_parser *parser, struct rspamd_config *cfg); diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index aecef53d4..f7285d5ed 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -1004,16 +1004,6 @@ rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data) } } -gboolean -rspamd_config_parse_ip_list (const gchar *ip_list, radix_compressed_t **tree) -{ - if (*tree == NULL) { - *tree = radix_create_compressed (); - } - - return (rspamd_radix_add_iplist (ip_list, ",; ", *tree) > 0); -} - /* * vi:ts=4 */ diff --git a/src/libutil/logger.c b/src/libutil/logger.c index 5db081b61..f25c1fe75 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -342,7 +342,7 @@ rspamd_set_logger (struct rspamd_config *cfg, "IP addresses for which debug logs are enabled", read_radix_list, fin_radix_list, (void **)&rspamd->logger->debug_ip)) { - rspamd_config_parse_ip_list (rspamd->cfg->debug_ip_map, + radix_add_generic_iplist (rspamd->cfg->debug_ip_map, &rspamd->logger->debug_ip); } } diff --git a/src/libutil/radix.c b/src/libutil/radix.c index c8aaaf946..c58125003 100644 --- a/src/libutil/radix.c +++ b/src/libutil/radix.c @@ -962,6 +962,16 @@ rspamd_radix_add_iplist (const gchar *list, const gchar *separators, return res; } +gboolean +radix_add_generic_iplist (const gchar *ip_list, radix_compressed_t **tree) +{ + if (*tree == NULL) { + *tree = radix_create_compressed (); + } + + return (rspamd_radix_add_iplist (ip_list, ",; ", *tree) > 0); +} + /* * vi:ts=4 */ diff --git a/src/libutil/radix.h b/src/libutil/radix.h index abe2a2899..b17731fd7 100644 --- a/src/libutil/radix.h +++ b/src/libutil/radix.h @@ -130,4 +130,11 @@ radix_compressed_t *radix_create_compressed (void); gint rspamd_radix_add_iplist (const gchar *list, const gchar *separators, radix_compressed_t *tree); +/** + * Generic version of @see rspamd_radix_add_iplist. This function creates tree + * if `tree` is NULL. + */ +gboolean radix_add_generic_iplist (const gchar *ip_list, + radix_compressed_t **tree); + #endif diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 075d23c88..bc687065e 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -59,7 +59,7 @@ struct dkim_ctx { const gchar *symbol_allow; rspamd_mempool_t *dkim_pool; - radix_tree_t *whitelist_ip; + radix_compressed_t *whitelist_ip; GHashTable *dkim_domains; guint strict_multiplier; guint time_jitter; @@ -106,7 +106,7 @@ dkim_module_config (struct rspamd_config *cfg) guint cache_size, cache_expire; gboolean got_trusted = FALSE; - dkim_module_ctx->whitelist_ip = radix_tree_create (); + dkim_module_ctx->whitelist_ip = radix_create_compressed (); if ((value = rspamd_config_get_module_opt (cfg, "dkim", "symbol_reject")) != NULL) { @@ -158,8 +158,8 @@ dkim_module_config (struct rspamd_config *cfg) if (!add_map (cfg, ucl_obj_tostring (value), "DKIM whitelist", read_radix_list, fin_radix_list, (void **)&dkim_module_ctx->whitelist_ip)) { - msg_warn ("cannot load whitelist from %s", - ucl_obj_tostring (value)); + radix_add_generic_iplist (ucl_obj_tostring (value), + &dkim_module_ctx->whitelist_ip); } } if ((value = @@ -234,7 +234,7 @@ gint dkim_module_reconfig (struct rspamd_config *cfg) { rspamd_mempool_delete (dkim_module_ctx->dkim_pool); - radix_tree_free (dkim_module_ctx->whitelist_ip); + radix_destroy_compressed (dkim_module_ctx->whitelist_ip); if (dkim_module_ctx->dkim_domains) { g_hash_table_destroy (dkim_module_ctx->dkim_domains); } @@ -368,10 +368,8 @@ dkim_symbol_callback (struct rspamd_task *task, void *unused) if (hlist != NULL) { /* Check whitelist */ msg_debug ("dkim signature found"); - if (task->from_addr.af == AF_INET || - radix32tree_find (dkim_module_ctx->whitelist_ip, - ntohl (task->from_addr.addr.s4.sin_addr.s_addr)) == - RADIX_NO_VALUE) { + if (radix_find_compressed_addr (dkim_module_ctx->whitelist_ip, + &task->from_addr) == RADIX_NO_VALUE) { /* Parse signature */ msg_debug ("create dkim signature"); /* diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 323246f71..5a53695ee 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -486,7 +486,7 @@ fuzzy_check_module_config (struct rspamd_config *cfg) if (!add_map (cfg, ucl_obj_tostring (value), "Fuzzy whitelist", read_radix_list, fin_radix_list, (void **)&fuzzy_module_ctx->whitelist)) { - rspamd_config_parse_ip_list (ucl_obj_tostring (value), + radix_add_generic_iplist (ucl_obj_tostring (value), &fuzzy_module_ctx->whitelist); } } diff --git a/src/plugins/spf.c b/src/plugins/spf.c index e435da36d..9e1721879 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -140,7 +140,7 @@ spf_module_config (struct rspamd_config *cfg) if (!add_map (cfg, ucl_obj_tostring (value), "SPF whitelist", read_radix_list, fin_radix_list, (void **)&spf_module_ctx->whitelist_ip)) { - rspamd_config_parse_ip_list (ucl_obj_tostring (value), + radix_add_generic_iplist (ucl_obj_tostring (value), &spf_module_ctx->whitelist_ip); } } |