]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add routine to find rspamd_inet_addr in radix trie.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 1 Oct 2014 13:55:49 +0000 (14:55 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 1 Oct 2014 13:55:49 +0000 (14:55 +0100)
src/libutil/radix.c
src/libutil/radix.h

index 99e25d0ba1c6741ceccf98bdfd2e26e584f89b5b..40cccb46b2f9dfc7c5484a95f7f4293e11a50a0d 100644 (file)
@@ -868,6 +868,25 @@ radix_tree_destroy_compressed (radix_compressed_t *tree)
        g_slice_free1 (sizeof (*tree), tree);
 }
 
+uintptr_t
+radix_find_compressed_addr (radix_compressed_t *tree, rspamd_inet_addr_t *addr)
+{
+       if (addr == NULL) {
+               return RADIX_NO_VALUE;
+       }
+
+       if (addr->af == AF_INET) {
+               return radix_find_compressed (tree, (guint8 *)&addr->addr.s4.sin_addr,
+                               sizeof (addr->addr.s4.sin_addr));
+       }
+       else if (addr->af == AF_INET6) {
+               return radix_find_compressed (tree, (guint8 *)&addr->addr.s6.sin6_addr,
+                               sizeof (addr->addr.s6.sin6_addr));
+       }
+
+       return RADIX_NO_VALUE;
+}
+
 /*
  * vi:ts=4
  */
index 52dc96952d83cda74472c293028f3da333e817aa..f89d30103a865d3a79893466b97017d47da4bfe5 100644 (file)
@@ -81,6 +81,15 @@ uintptr_t radix32tree_find (radix_tree_t *tree, guint32 key);
  */
 uintptr_t radix32_tree_find_addr (radix_tree_t *tree, rspamd_inet_addr_t *addr);
 
+/**
+ * Find specified address in tree (works for any address)
+ * @param tree
+ * @param addr
+ * @return
+ */
+uintptr_t radix_find_compressed_addr (radix_compressed_t *tree,
+               rspamd_inet_addr_t *addr);
+
 /**
  * Traverse via the whole tree calling specified callback
  */