aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/radix.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-01 11:09:37 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-01 11:09:37 +0100
commitfcaf800bd6cddb56c1cd88044346996d1f8854ee (patch)
tree2a77eadcfb5a8d24ad8c08f1bcc131502d777485 /src/libutil/radix.c
parentb45bc487b77ad51e3cf25ad9f0b19334c821cc6f (diff)
downloadrspamd-fcaf800bd6cddb56c1cd88044346996d1f8854ee.tar.gz
rspamd-fcaf800bd6cddb56c1cd88044346996d1f8854ee.zip
[Feature] Suppress duplicate warning on very large radix tries
Diffstat (limited to 'src/libutil/radix.c')
-rw-r--r--src/libutil/radix.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/libutil/radix.c b/src/libutil/radix.c
index a42be7032..3ea6c6b8c 100644
--- a/src/libutil/radix.c
+++ b/src/libutil/radix.c
@@ -42,6 +42,7 @@ struct radix_tree_compressed {
rspamd_mempool_t *pool;
struct btrie *tree;
size_t size;
+ guint duplicates;
gboolean own_pool;
};
@@ -68,6 +69,7 @@ radix_insert_compressed (radix_compressed_t * tree,
gsize masklen,
uintptr_t value)
{
+ static const guint max_duplicates = 32;
guint keybits = keylen * NBBY;
uintptr_t old;
gchar ip_str[INET6_ADDRSTRLEN + 1];
@@ -85,23 +87,29 @@ radix_insert_compressed (radix_compressed_t * tree,
(gconstpointer)value);
if (ret != BTRIE_OKAY) {
- memset (ip_str, 0, sizeof (ip_str));
+ tree->duplicates++;
- if (keybits == 32) {
- msg_err_radix ("cannot insert %p, key: %s/%d, duplicate value",
- (gpointer)value,
- inet_ntop (AF_INET, key, ip_str, sizeof (ip_str) - 1),
- (gint)(keybits - masklen));
+ if (tree->duplicates == max_duplicates) {
+ msg_err_radix ("maximum duplicates limit reached: %d, "
+ "suppress further errors", max_duplicates);
}
- else if (keybits == 128) {
- msg_err_radix ("cannot insert %p, key: [%s]/%d, duplicate value",
- (gpointer)value,
- inet_ntop (AF_INET6, key, ip_str, sizeof (ip_str) - 1),
- (gint)(keybits - masklen));
- }
- else {
- msg_err_radix ("cannot insert %p with mask %z, key: %*xs, duplicate value",
- (gpointer)value, keybits - masklen, (int)keylen, key);
+ else if (tree->duplicates < max_duplicates) {
+ memset (ip_str, 0, sizeof (ip_str));
+
+ if (keybits == 32) {
+ msg_err_radix ("cannot insert %p, key: %s/%d, duplicate value",
+ (gpointer) value,
+ inet_ntop (AF_INET, key, ip_str, sizeof (ip_str) - 1),
+ (gint) (keybits - masklen));
+ } else if (keybits == 128) {
+ msg_err_radix ("cannot insert %p, key: [%s]/%d, duplicate value",
+ (gpointer) value,
+ inet_ntop (AF_INET6, key, ip_str, sizeof (ip_str) - 1),
+ (gint) (keybits - masklen));
+ } else {
+ msg_err_radix ("cannot insert %p with mask %z, key: %*xs, duplicate value",
+ (gpointer) value, keybits - masklen, (int) keylen, key);
+ }
}
}
else {
@@ -124,6 +132,7 @@ radix_create_compressed (void)
tree->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
tree->size = 0;
+ tree->duplicates = 0;
tree->tree = btrie_init (tree->pool);
tree->own_pool = TRUE;
@@ -138,6 +147,7 @@ radix_create_compressed_with_pool (rspamd_mempool_t *pool)
tree = rspamd_mempool_alloc (pool, sizeof (*tree));
tree->pool = pool;
tree->size = 0;
+ tree->duplicates = 0;
tree->tree = btrie_init (tree->pool);
tree->own_pool = FALSE;
@@ -393,5 +403,5 @@ radix_get_info (radix_compressed_t *tree)
return NULL;
}
- return btrie_stats (tree->tree);
+ return btrie_stats (tree->tree, tree->duplicates);
}