path: root/src/sync-notrack.c
diff options
authorPablo Neira Ayuso <>2009-01-15 23:19:57 +0100
committerPablo Neira Ayuso <>2009-01-15 23:19:57 +0100
commit50339f96638eed35dac2b673b64cc6f1eb96406c (patch)
tree20dbb60fd3c41994da7cd7ad8888185c681fadb1 /src/sync-notrack.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 <>
Diffstat (limited to 'src/sync-notrack.c')
1 files changed, 9 insertions, 10 deletions
diff --git a/src/sync-notrack.c b/src/sync-notrack.c
index 700e272..2d3783e 100644
--- a/src/sync-notrack.c
+++ b/src/sync-notrack.c
@@ -18,7 +18,6 @@
#include "conntrackd.h"
#include "sync.h"
-#include "us-conntrack.h"
#include "queue.h"
#include "debug.h"
#include "network.h"
@@ -36,13 +35,13 @@ struct cache_notrack {
struct list_head tx_list;
-static void cache_notrack_add(struct us_conntrack *u, void *data)
+static void cache_notrack_add(struct cache_object *obj, void *data)
struct cache_notrack *cn = data;
-static void cache_notrack_del(struct us_conntrack *u, void *data)
+static void cache_notrack_del(struct cache_object *obj, void *data)
struct cache_notrack *cn = data;
@@ -89,8 +88,8 @@ static void notrack_kill(void)
static int do_cache_to_tx(void *data1, void *data2)
- struct us_conntrack *u = data2;
- struct cache_notrack *cn = cache_get_extra(STATE_SYNC(internal), u);
+ struct cache_object *obj = data2;
+ struct cache_notrack *cn = cache_get_extra(STATE_SYNC(internal), obj);
if (!list_empty(&cn->tx_list))
return 0;
@@ -164,10 +163,10 @@ static int tx_queue_xmit(void *data1, const void *data2)
return 0;
-static int tx_list_xmit(struct list_head *i, struct us_conntrack *u, int type)
+static int tx_list_xmit(struct list_head *i, struct cache_object *obj, int type)
int ret;
- struct nethdr *net = BUILD_NETMSG(u->ct, type);
+ struct nethdr *net = BUILD_NETMSG(obj->ct, type);
@@ -186,10 +185,10 @@ static void notrack_run(void)
/* send conntracks in the tx_list */
list_for_each_entry_safe(cn, tmp, &tx_list, tx_list) {
- struct us_conntrack *u;
+ struct cache_object *obj;
- u = cache_get_conntrack(STATE_SYNC(internal), cn);
- tx_list_xmit(&cn->tx_list, u, NET_T_STATE_UPD);
+ obj = cache_data_get_object(STATE_SYNC(internal), cn);
+ tx_list_xmit(&cn->tx_list, obj, NET_T_STATE_UPD);