aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-14 11:03:31 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-14 11:03:31 +0000
commit61330ef453ae1eb997b2567928587d3c71daf87f (patch)
tree2e70276811cb3b5fc5aa3ecfd2487d22faafb9f6 /src
parent5468736cc812d942b34795cfb6e29ac43739aa0d (diff)
downloadrspamd-61330ef453ae1eb997b2567928587d3c71daf87f.tar.gz
rspamd-61330ef453ae1eb997b2567928587d3c71daf87f.zip
Add routines to use rspamd_inet_addr_t in hash tables
Diffstat (limited to 'src')
-rw-r--r--src/libutil/addr.c30
-rw-r--r--src/libutil/addr.h11
2 files changed, 41 insertions, 0 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index 2b5ca9854..1da69e114 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -25,6 +25,7 @@
#include "addr.h"
#include "util.h"
#include "logger.h"
+#include "xxhash.h"
#include "unix-std.h"
/* pwd and grp */
@@ -1276,3 +1277,32 @@ rspamd_inet_address_get_af (const rspamd_inet_addr_t *addr)
return addr->af;
}
+
+
+guint
+rspamd_inet_address_hash (gconstpointer a)
+{
+ const rspamd_inet_addr_t *addr = a;
+ XXH64_state_t st;
+
+ XXH64_reset (&st, rspamd_hash_seed ());
+ XXH64_update (&st, &addr->af, sizeof (addr->af));
+
+
+ if (addr->u.un) {
+ XXH64_update (&st, addr->u.un, sizeof (*addr->u.un));
+ }
+ else {
+ XXH64_update (&st, &addr->u.in.addr, addr->slen);
+ }
+
+ return XXH64_digest (&st);
+}
+
+gboolean
+rspamd_inet_address_equal (gconstpointer a, gconstpointer b)
+{
+ const rspamd_inet_addr_t *a1 = a, *a2 = b;
+
+ return rspamd_inet_address_compare (a1, a2) == 0;
+}
diff --git a/src/libutil/addr.h b/src/libutil/addr.h
index d686fa52a..fa2e4e65b 100644
--- a/src/libutil/addr.h
+++ b/src/libutil/addr.h
@@ -249,4 +249,15 @@ gint rspamd_inet_address_compare_ptr (gconstpointer a1,
*/
rspamd_inet_addr_t *rspamd_inet_address_copy (const rspamd_inet_addr_t *addr);
+/**
+ * Returns hash for inet address
+ */
+guint rspamd_inet_address_hash (gconstpointer a);
+
+
+/**
+ * Returns true if two address are equal
+ */
+gboolean rspamd_inet_address_equal (gconstpointer a, gconstpointer b);
+
#endif /* ADDR_H_ */