summaryrefslogtreecommitdiffstats
path: root/src/cache_timer.c
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 /src/cache_timer.c
parentb28224b0326636ff5832b38817b7720f48070ee7 (diff)
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 'src/cache_timer.c')
-rw-r--r--src/cache_timer.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/cache_timer.c b/src/cache_timer.c
index 44482b7..a9e3e3d 100644
--- a/src/cache_timer.c
+++ b/src/cache_timer.c
@@ -18,7 +18,6 @@
#include "cache.h"
#include "conntrackd.h"
-#include "us-conntrack.h"
#include "alarm.h"
#include "debug.h"
@@ -26,45 +25,46 @@
static void timeout(struct alarm_block *a, void *data)
{
- struct us_conntrack *u = data;
+ struct cache_object *obj = data;
- debug_ct(u->ct, "expired timeout");
- cache_del(u->cache, u->ct);
+ debug_ct(obj->ct, "expired timeout");
+ cache_del(obj->cache, obj);
+ cache_object_free(obj);
}
-static void timer_add(struct us_conntrack *u, void *data)
+static void timer_add(struct cache_object *obj, void *data)
{
- struct alarm_block *alarm = data;
+ struct alarm_block *a = data;
- init_alarm(alarm, u, timeout);
- add_alarm(alarm, CONFIG(cache_timeout), 0);
+ init_alarm(a, obj, timeout);
+ add_alarm(a, CONFIG(cache_timeout), 0);
}
-static void timer_update(struct us_conntrack *u, void *data)
+static void timer_update(struct cache_object *obj, void *data)
{
- struct alarm_block *alarm = data;
- add_alarm(alarm, CONFIG(cache_timeout), 0);
+ struct alarm_block *a = data;
+ add_alarm(a, CONFIG(cache_timeout), 0);
}
-static void timer_destroy(struct us_conntrack *u, void *data)
+static void timer_destroy(struct cache_object *obj, void *data)
{
- struct alarm_block *alarm = data;
- del_alarm(alarm);
+ struct alarm_block *a = data;
+ del_alarm(a);
}
-static int timer_dump(struct us_conntrack *u, void *data, char *buf, int type)
+static int timer_dump(struct cache_object *obj, void *data, char *buf, int type)
{
struct timeval tv, tmp;
- struct alarm_block *alarm = data;
+ struct alarm_block *a = data;
if (type == NFCT_O_XML)
return 0;
- if (!alarm_pending(alarm))
+ if (!alarm_pending(a))
return 0;
gettimeofday(&tv, NULL);
- timersub(&alarm->tv, &tv, &tmp);
+ timersub(&a->tv, &tv, &tmp);
return sprintf(buf, " [expires in %lds]", tmp.tv_sec);
}