From: Vsevolod Stakhov Date: Sun, 3 Jan 2016 17:00:56 +0000 (+0000) Subject: Add local addrs extension available in the conviguration X-Git-Tag: 1.1.0~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4b315188ef4f1cb1999872defd1d1f558dbc2e0;p=thirdparty%2Frspamd.git Add local addrs extension available in the conviguration --- diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 96c4fb10b8..1dfd3419e2 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -221,6 +221,7 @@ struct rspamd_config { gchar *pid_file; /**< name of pid file */ gchar *temp_dir; /**< dir for temp files */ gchar *control_socket_path; /**< path to the control socket */ + gchar *local_addrs; /**< tree of local addresses */ #ifdef WITH_GPERF_TOOLS gchar *profile_path; #endif diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 07d9ae44dd..32651dd20d 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -681,6 +681,9 @@ rspamd_config_post_load (struct rspamd_config *cfg, gboolean validate_cache) /* Init re cache */ rspamd_re_cache_init (cfg->re_cache, cfg); + /* Config other libraries */ + rspamd_config_libs (cfg->libs_ctx, cfg); + /* Validate cache */ if (validate_cache) { return rspamd_symbols_cache_validate (cfg->cache, cfg, FALSE); diff --git a/src/libutil/addr.c b/src/libutil/addr.c index f301c724e3..d8dec0b979 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -26,7 +26,7 @@ #include "util.h" #include "logger.h" #include "xxhash.h" - +#include "radix.h" #include "unix-std.h" /* pwd and grp */ #ifdef HAVE_PWD_H @@ -37,6 +37,7 @@ #include #endif +static radix_compressed_t *local_addrs; enum { RSPAMD_IPV6_UNDEFINED = 0, @@ -1355,7 +1356,27 @@ rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr) return TRUE; } } + + if (local_addrs) { + if (radix_find_compressed_addr (local_addrs, addr) != RADIX_NO_VALUE) { + return TRUE; + } + } } return FALSE; } + +void ** +rspamd_inet_library_init (void) +{ + return (void **)&local_addrs; +} + +void +rspamd_inet_library_destroy (void) +{ + if (local_addrs != NULL) { + radix_destroy_compressed (local_addrs); + } +} diff --git a/src/libutil/addr.h b/src/libutil/addr.h index 36f9910fdc..b2075f7f0d 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -46,6 +46,9 @@ */ typedef struct rspamd_inet_addr_s rspamd_inet_addr_t; +void **rspamd_inet_library_init (void); +void rspamd_inet_library_destroy (void); + /** * Create new inet address structure based on the address familiy and opaque init pointer * @param af diff --git a/src/libutil/util.c b/src/libutil/util.c index a3b89131cc..994f475b9b 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -32,6 +32,7 @@ #include "xxhash.h" #include "ottery.h" #include "cryptobox.h" +#include "libutil/map.h" #ifdef HAVE_OPENSSL #include @@ -1979,11 +1980,29 @@ rspamd_init_libs (void) ctx->libmagic = magic_open (MAGIC_MIME|MAGIC_NO_CHECK_COMPRESS| MAGIC_NO_CHECK_ELF|MAGIC_NO_CHECK_TAR); magic_load (ctx->libmagic, NULL); + ctx->local_addrs = rspamd_inet_library_init (); REF_INIT_RETAIN (ctx, rspamd_deinit_libs); return ctx; } +void +rspamd_config_libs (struct rspamd_external_libs_ctx *ctx, + struct rspamd_config *cfg) +{ + g_assert (ctx != NULL); + g_assert (cfg != NULL); + + if (cfg->local_addrs) { + if (!rspamd_map_add (cfg, cfg->local_addrs, + "Local addresses", rspamd_radix_read, rspamd_radix_fin, + (void **) ctx->local_addrs)) { + radix_add_generic_iplist (cfg->local_addrs, + (radix_compressed_t **)ctx->local_addrs); + } + } +} + void rspamd_deinit_libs (struct rspamd_external_libs_ctx *ctx) { @@ -2000,6 +2019,7 @@ rspamd_deinit_libs (struct rspamd_external_libs_ctx *ctx) EVP_cleanup (); ERR_free_strings (); #endif + rspamd_inet_library_destroy (); } } diff --git a/src/libutil/util.h b/src/libutil/util.h index ab1d205c10..28a6827b22 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -393,7 +393,13 @@ struct rspamd_external_libs_ctx; /** * Initialize rspamd libraries */ -struct rspamd_external_libs_ctx* rspamd_init_libs (void); +struct rspamd_external_libs_ctx* rspamd_init_libs (); + +/** + * Configure libraries + */ +void rspamd_config_libs (struct rspamd_external_libs_ctx *ctx, + struct rspamd_config *cfg); /** * Destroy external libraries context diff --git a/src/rspamd.h b/src/rspamd.h index a2a442a1f2..6126b17a76 100644 --- a/src/rspamd.h +++ b/src/rspamd.h @@ -191,6 +191,7 @@ struct controller_session { struct rspamd_external_libs_ctx { magic_t libmagic; + void **local_addrs; ref_entry_t ref; };