summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2009-01-15 23:19:58 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2009-01-15 23:19:58 +0100
commit8dce3504fde7da933dc6e7ecfeb99b4b45125f32 (patch)
tree9d12a1e54caf8a6718eb2ad5187e4e13c3791d3e
parent50339f96638eed35dac2b673b64cc6f1eb96406c (diff)
cache: add status field to store the object status
This patch adds the status field to the cache object. This avoids the (ab)use of the alarm to check if an entry is active or dead. This is the first step to possibly move the alarm to the cache_extra memory space of the ftfw (which is the only use by now). Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/cache.h8
-rw-r--r--include/network.h1
-rw-r--r--src/cache.c10
-rw-r--r--src/cache_iterators.c2
-rw-r--r--src/network.c13
5 files changed, 30 insertions, 4 deletions
diff --git a/include/cache.h b/include/cache.h
index dcd6bcd..fd8e05f 100644
--- a/include/cache.h
+++ b/include/cache.h
@@ -23,11 +23,19 @@ enum {
};
#define CACHE_MAX_FEATURE __CACHE_MAX_FEATURE
+enum {
+ C_OBJ_NONE = 0, /* not in the cache */
+ C_OBJ_NEW, /* just added to the cache */
+ C_OBJ_ALIVE, /* in the cache, alive */
+ C_OBJ_DEAD /* still in the cache, but dead */
+};
+
struct cache;
struct cache_object {
struct hashtable_node hashnode;
struct nf_conntrack *ct;
struct cache *cache;
+ int status;
struct alarm_block alarm;
char data[0];
};
diff --git a/include/network.h b/include/network.h
index 619ce3e..f02d920 100644
--- a/include/network.h
+++ b/include/network.h
@@ -30,6 +30,7 @@ int nethdr_size(int len);
void nethdr_set(struct nethdr *net, int type);
void nethdr_set_ack(struct nethdr *net);
void nethdr_set_ctl(struct nethdr *net);
+int object_status_to_network_type(int status);
#define NETHDR_DATA(x) \
(struct netattr *)(((char *)x) + NETHDR_SIZ)
diff --git a/src/cache.c b/src/cache.c
index 621a3f4..c46498b 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -196,6 +196,7 @@ struct cache_object *cache_object_new(struct cache *c, struct nf_conntrack *ct)
return NULL;
}
memcpy(obj->ct, ct, nfct_sizeof(ct));
+ obj->status = C_OBJ_NONE;
return obj;
}
@@ -225,6 +226,7 @@ static int __add(struct cache *c, struct cache_object *obj, int id)
c->extra->add(obj, ((char *) obj) + c->extra_offset);
c->stats.active++;
+ obj->status = C_OBJ_NEW;
return 0;
}
@@ -260,6 +262,7 @@ void cache_update(struct cache *c, struct cache_object *obj, int id,
c->extra->update(obj, ((char *) obj) + c->extra_offset);
c->stats.upd_ok++;
+ obj->status = C_OBJ_ALIVE;
}
static void __del(struct cache *c, struct cache_object *obj)
@@ -285,7 +288,7 @@ void cache_del(struct cache *c, struct cache_object *obj)
* kill an entry was previously deleted via
* __cache_del_timer.
*/
- if (!alarm_pending(&obj->alarm)) {
+ if (obj->status != C_OBJ_DEAD) {
c->stats.del_ok++;
c->stats.active--;
}
@@ -301,7 +304,7 @@ cache_update_force(struct cache *c, struct nf_conntrack *ct)
obj = cache_find(c, ct, &id);
if (obj) {
- if (!alarm_pending(&obj->alarm)) {
+ if (obj->status != C_OBJ_DEAD) {
cache_update(c, obj, id, ct);
return obj;
} else {
@@ -333,7 +336,8 @@ int cache_del_timer(struct cache *c, struct cache_object *obj, int timeout)
cache_object_free(obj);
return 1;
}
- if (!alarm_pending(&obj->alarm)) {
+ if (obj->status != C_OBJ_DEAD) {
+ obj->status = C_OBJ_DEAD;
add_alarm(&obj->alarm, timeout, 0);
/*
* increase stats even if this entry was not really
diff --git a/src/cache_iterators.c b/src/cache_iterators.c
index 4773889..ab6a461 100644
--- a/src/cache_iterators.c
+++ b/src/cache_iterators.c
@@ -51,7 +51,7 @@ static int do_dump(void *data1, struct hashtable_node *n)
* specific and it breaks conntrackd modularity. Probably
* there's a nicer way to do this but until I come up with it...
*/
- if (CONFIG(flags) & CTD_SYNC_FTFW && alarm_pending(&obj->alarm))
+ if (CONFIG(flags) & CTD_SYNC_FTFW && obj->status == C_OBJ_DEAD)
return 0;
/* do not show cached timeout, this may confuse users */
diff --git a/src/network.c b/src/network.c
index 598195f..320cdea 100644
--- a/src/network.c
+++ b/src/network.c
@@ -177,3 +177,16 @@ int mcast_track_is_seq_set()
{
return local_seq_set;
}
+
+#include "cache.h"
+
+static int status2type[] = {
+ [C_OBJ_NEW] = NET_T_STATE_NEW,
+ [C_OBJ_ALIVE] = NET_T_STATE_UPD,
+ [C_OBJ_DEAD] = NET_T_STATE_DEL,
+};
+
+int object_status_to_network_type(int status)
+{
+ return status2type[status];
+}