From 1485bf2c42c3104696ec3a6c5e61ebe627a71c21 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 12 Feb 2020 15:02:41 +0000 Subject: [Rework] Move local IPs check --- src/libutil/addr.c | 23 +++++++++-------------- src/libutil/addr.h | 20 ++++++++++++++------ 2 files changed, 23 insertions(+), 20 deletions(-) (limited to 'src/libutil') diff --git a/src/libutil/addr.c b/src/libutil/addr.c index c0cb2d19d..4a540fefc 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -16,10 +16,6 @@ #include "config.h" #include "addr.h" #include "util.h" -/* - * TODO: fix this cross dependency! - */ -#include "libserver/maps/map_helpers.h" #include "logger.h" #include "cryptobox.h" #include "unix-std.h" @@ -32,7 +28,7 @@ #include #endif -static struct rspamd_radix_map_helper *local_addrs; +static void *local_addrs; enum { RSPAMD_IPV6_UNDEFINED = 0, @@ -1879,8 +1875,7 @@ rspamd_inet_address_port_equal (gconstpointer a, gconstpointer b) #endif gboolean -rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr, - gboolean check_laddrs) +rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr) { if (addr == NULL) { return FALSE; @@ -1904,23 +1899,23 @@ rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr, return TRUE; } } - - if (check_laddrs && local_addrs) { - if (rspamd_match_radix_map_addr (local_addrs, addr) != NULL) { - return TRUE; - } - } } return FALSE; } -struct rspamd_radix_map_helper ** +void ** rspamd_inet_library_init (void) { return &local_addrs; } +void * +rspamd_inet_library_get_lib_ctx (void) +{ + return local_addrs; +} + void rspamd_inet_library_destroy (void) { diff --git a/src/libutil/addr.h b/src/libutil/addr.h index 6a33ad7ec..c0910ad03 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -44,10 +44,19 @@ extern "C" { */ typedef struct rspamd_inet_addr_s rspamd_inet_addr_t; -struct rspamd_radix_map_helper; - -struct rspamd_radix_map_helper **rspamd_inet_library_init (void); - +/** + * Returns pointer storage for global singleton (map for local addresses) + * @return + */ +void **rspamd_inet_library_init (void); +/** + * Returns local addresses singleton + * @return + */ +void *rspamd_inet_library_get_lib_ctx (void); +/** + * Cleanup library (currently it does nothing) + */ void rspamd_inet_library_destroy (void); /** @@ -323,8 +332,7 @@ gboolean rspamd_inet_address_port_equal (gconstpointer a, gconstpointer b); /** * Returns TRUE if an address belongs to some local address */ -gboolean rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr, - gboolean check_laddrs); +gboolean rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr); /** * Returns size of storage required to store a complete IP address -- cgit v1.2.3