summaryrefslogtreecommitdiff
path: root/src/hash.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2009-07-17 13:36:05 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2009-07-17 13:36:05 +0200
commita1d03b775376aa8545ec9a0e89381b659e4d28ed (patch)
treedbce19e61288f5a4d31154e55a1e53553416bc72 /src/hash.c
parent9406f29b89f6727c3db5485d109466701393b4d4 (diff)
downloadconntrack-tools-a1d03b775376aa8545ec9a0e89381b659e4d28ed.tar.gz
conntrack-tools-a1d03b775376aa8545ec9a0e89381b659e4d28ed.zip
conntrackd: add iterators with limited steps in hash and cache types
This patch adds cache_iterate_limit() and hashtable_iterate_limit() that allows to limit the iteration to given a number of states. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/hash.c')
-rw-r--r--src/hash.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/hash.c b/src/hash.c
index 9c9ea5b..fe6a047 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
struct hashtable *
hashtable_create(int hashsize, int limit,
@@ -111,21 +112,29 @@ int hashtable_flush(struct hashtable *table)
return 0;
}
-int hashtable_iterate(struct hashtable *table, void *data,
- int (*iterate)(void *data1, struct hashtable_node *n))
+int
+hashtable_iterate_limit(struct hashtable *table, void *data,
+ uint32_t from, uint32_t steps,
+ int (*iterate)(void *data1, void *n))
{
uint32_t i;
struct list_head *e, *tmp;
struct hashtable_node *n;
- for (i=0; i < table->hashsize; i++) {
+ for (i=from; i < table->hashsize && i < from+steps; i++) {
list_for_each_safe(e, tmp, &table->members[i]) {
n = list_entry(e, struct hashtable_node, head);
if (iterate(data, n) == -1)
return -1;
}
}
- return 0;
+ return i;
+}
+
+int hashtable_iterate(struct hashtable *table, void *data,
+ int (*iterate)(void *data1, void *n))
+{
+ return hashtable_iterate_limit(table, data, 0, UINT_MAX, iterate);
}
unsigned int hashtable_counter(const struct hashtable *table)