summaryrefslogtreecommitdiff
path: root/include/cache.h
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2009-01-15 23:19:57 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2009-01-15 23:19:57 +0100
commit50339f96638eed35dac2b673b64cc6f1eb96406c (patch)
tree20dbb60fd3c41994da7cd7ad8888185c681fadb1 /include/cache.h
parentb28224b0326636ff5832b38817b7720f48070ee7 (diff)
downloadconntrack-tools-50339f96638eed35dac2b673b64cc6f1eb96406c.tar.gz
conntrack-tools-50339f96638eed35dac2b673b64cc6f1eb96406c.zip
src: rework of the hash-cache infrastructure
Currently, the caching system is implemented in a two layer architecture: hashtable (inner layer) and cache (upper layer). This patch reworks the hash-cache infrastructure to solve some initial design problems to make it more flexible, the main strong points of this patch are: * Memory handling is done in the cache layer, not in the inner hashtable layer. This removes one of the main dependencies between the hashtable and the cache classes. * Remove excessive encapsulation: the former cache used to hide a lot of details of the inner hashtable implementation. * Fix over-hashing of some operations: lookup-delete-add required three hash calculations. Similarly, the update-or-add operation required two hash calculations. Now, we calculate the hash once and re-use the value how many times as we need. This patch simplifies the caching system. As a result, we save ~130 lines of code. Small code means and less complexity means less chance to have bugs. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include/cache.h')
-rw-r--r--include/cache.h43
1 files changed, 27 insertions, 16 deletions
diff --git a/include/cache.h b/include/cache.h
index ebed70a..dcd6bcd 100644
--- a/include/cache.h
+++ b/include/cache.h
@@ -3,6 +3,8 @@
#include <stdint.h>
#include <stddef.h>
+#include "hash.h"
+#include "alarm.h"
/* cache features */
enum {
@@ -22,14 +24,20 @@ enum {
#define CACHE_MAX_FEATURE __CACHE_MAX_FEATURE
struct cache;
-struct us_conntrack;
+struct cache_object {
+ struct hashtable_node hashnode;
+ struct nf_conntrack *ct;
+ struct cache *cache;
+ struct alarm_block alarm;
+ char data[0];
+};
struct cache_feature {
size_t size;
- void (*add)(struct us_conntrack *u, void *data);
- void (*update)(struct us_conntrack *u, void *data);
- void (*destroy)(struct us_conntrack *u, void *data);
- int (*dump)(struct us_conntrack *u, void *data, char *buf, int type);
+ void (*add)(struct cache_object *obj, void *data);
+ void (*update)(struct cache_object *obj, void *data);
+ void (*destroy)(struct cache_object *obj, void *data);
+ int (*dump)(struct cache_object *obj, void *data, char *buf, int type);
};
extern struct cache_feature lifetime_feature;
@@ -48,6 +56,7 @@ struct cache {
unsigned int *feature_offset;
struct cache_extra *extra;
unsigned int extra_offset;
+ size_t object_size;
/* statistics */
struct {
@@ -77,9 +86,9 @@ struct cache {
struct cache_extra {
unsigned int size;
- void (*add)(struct us_conntrack *u, void *data);
- void (*update)(struct us_conntrack *u, void *data);
- void (*destroy)(struct us_conntrack *u, void *data);
+ void (*add)(struct cache_object *obj, void *data);
+ void (*update)(struct cache_object *obj, void *data);
+ void (*destroy)(struct cache_object *obj, void *data);
};
struct nf_conntrack;
@@ -87,16 +96,18 @@ struct nf_conntrack;
struct cache *cache_create(const char *name, unsigned int features, struct cache_extra *extra);
void cache_destroy(struct cache *e);
-struct us_conntrack *cache_add(struct cache *c, struct nf_conntrack *ct);
-struct us_conntrack *cache_update(struct cache *c, struct nf_conntrack *ct);
-struct us_conntrack *cache_update_force(struct cache *c, struct nf_conntrack *ct);
-int cache_del(struct cache *c, struct nf_conntrack *ct);
-int __cache_del_timer(struct cache *c, struct us_conntrack *u, int timeout);
-struct us_conntrack *cache_find(struct cache *c, struct nf_conntrack *ct);
-int cache_test(struct cache *c, struct nf_conntrack *ct);
+struct cache_object *cache_object_new(struct cache *c, struct nf_conntrack *ct);
+void cache_object_free(struct cache_object *obj);
+
+int cache_add(struct cache *c, struct cache_object *obj, int id);
+void cache_update(struct cache *c, struct cache_object *obj, int id, struct nf_conntrack *ct);
+struct cache_object *cache_update_force(struct cache *c, struct nf_conntrack *ct);
+void cache_del(struct cache *c, struct cache_object *obj);
+int cache_del_timer(struct cache *c, struct cache_object *obj, int timeout);
+struct cache_object *cache_find(struct cache *c, struct nf_conntrack *ct, int *pos);
void cache_stats(const struct cache *c, int fd);
void cache_stats_extended(const struct cache *c, int fd);
-struct us_conntrack *cache_get_conntrack(struct cache *, void *);
+struct cache_object *cache_data_get_object(struct cache *c, void *data);
void *cache_get_extra(struct cache *, void *);
void cache_iterate(struct cache *c, void *data, int (*iterate)(void *data1, void *data2));