aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/addr.c23
-rw-r--r--src/libutil/addr.h3
-rw-r--r--src/libutil/util.c20
-rw-r--r--src/libutil/util.h8
4 files changed, 52 insertions, 2 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index f301c724e..d8dec0b97 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 <grp.h>
#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 36f9910fd..b2075f7f0 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 a3b89131c..994f475b9 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 <openssl/rand.h>
@@ -1979,12 +1980,30 @@ 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)
{
if (ctx != NULL) {
@@ -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 ab1d205c1..28a6827b2 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