diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-01 14:55:49 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-01 14:55:49 +0100 |
commit | 9ae0493f954ac0186541aa567b55adbb436b33db (patch) | |
tree | ea9868cf9fac72f4b65aa88b3362118e86e9743f /src | |
parent | cae34de6089bbe596b6c1025103db9e47add431e (diff) | |
download | rspamd-9ae0493f954ac0186541aa567b55adbb436b33db.tar.gz rspamd-9ae0493f954ac0186541aa567b55adbb436b33db.zip |
Add routine to find rspamd_inet_addr in radix trie.
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/radix.c | 19 | ||||
-rw-r--r-- | src/libutil/radix.h | 9 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/libutil/radix.c b/src/libutil/radix.c index 99e25d0ba..40cccb46b 100644 --- a/src/libutil/radix.c +++ b/src/libutil/radix.c @@ -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 */ diff --git a/src/libutil/radix.h b/src/libutil/radix.h index 52dc96952..f89d30103 100644 --- a/src/libutil/radix.h +++ b/src/libutil/radix.h @@ -82,6 +82,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 */ void radix32tree_traverse (radix_tree_t *tree, |