summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cache.h6
-rw-r--r--src/Makefile.am2
-rw-r--r--src/cache.c3
-rw-r--r--src/cache_iterators.c6
-rw-r--r--src/cache_lifetime.c65
-rw-r--r--src/stats-mode.c4
-rw-r--r--src/sync-alarm.c4
-rw-r--r--src/sync-ftfw.c4
-rw-r--r--src/sync-notrack.c4
9 files changed, 18 insertions, 80 deletions
diff --git a/include/cache.h b/include/cache.h
index 5e96dd3..1fd3881 100644
--- a/include/cache.h
+++ b/include/cache.h
@@ -12,10 +12,7 @@ enum {
TIMER_FEATURE = 0,
TIMER = (1 << TIMER_FEATURE),
- LIFETIME_FEATURE = 2,
- LIFETIME = (1 << LIFETIME_FEATURE),
-
- WRITE_THROUGH_FEATURE = 3,
+ WRITE_THROUGH_FEATURE = 1,
WRITE_THROUGH = (1 << WRITE_THROUGH_FEATURE),
__CACHE_MAX_FEATURE
@@ -36,6 +33,7 @@ struct cache_object {
struct cache *cache;
int status;
int refcnt;
+ long lifetime;
char data[0];
};
diff --git a/src/Makefile.am b/src/Makefile.am
index 64ed2b5..8ba09e1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,7 +14,7 @@ conntrackd_SOURCES = alarm.c main.c run.c hash.c queue.c rbtree.c \
local.c log.c mcast.c netlink.c vector.c \
filter.c fds.c event.c \
cache.c cache_iterators.c \
- cache_lifetime.c cache_timer.c cache_wt.c \
+ cache_timer.c cache_wt.c \
sync-mode.c sync-alarm.c sync-ftfw.c sync-notrack.c \
traffic_stats.c stats-mode.c \
network.c cidr.c \
diff --git a/src/cache.c b/src/cache.c
index a5f37dd..71825e1 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
static uint32_t
__hash4(const struct nf_conntrack *ct, const struct hashtable *table)
@@ -94,7 +95,6 @@ static int compare(const void *data1, const void *data2)
struct cache_feature *cache_feature[CACHE_MAX_FEATURE] = {
[TIMER_FEATURE] = &timer_feature,
- [LIFETIME_FEATURE] = &lifetime_feature,
[WRITE_THROUGH_FEATURE] = &writethrough_feature,
};
@@ -249,6 +249,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->lifetime = time(NULL);
obj->status = C_OBJ_NEW;
obj->refcnt++;
return 0;
diff --git a/src/cache_iterators.c b/src/cache_iterators.c
index 4bf518a..3a1ec72 100644
--- a/src/cache_iterators.c
+++ b/src/cache_iterators.c
@@ -26,6 +26,7 @@
#include <sched.h>
#include <errno.h>
#include <string.h>
+#include <time.h>
struct __dump_container {
int fd;
@@ -75,6 +76,11 @@ static int do_dump(void *data1, struct hashtable_node *n)
data += obj->cache->features[i]->size;
}
}
+ if (container->type != NFCT_O_XML) {
+ long tm = time(NULL);
+ size += sprintf(buf+size, " [active since %lds]",
+ tm - obj->lifetime);
+ }
size += sprintf(buf+size, "\n");
if (send(container->fd, buf, size, 0) == -1) {
if (errno != EPIPE)
diff --git a/src/cache_lifetime.c b/src/cache_lifetime.c
deleted file mode 100644
index 639d8c1..0000000
--- a/src/cache_lifetime.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * (C) 2006 by Pablo Neira Ayuso <pablo@netfilter.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <stdio.h>
-#include "cache.h"
-#include <sys/time.h>
-#include <time.h>
-#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
-
-static void lifetime_add(struct cache_object *obj, void *data)
-{
- long *lifetime = data;
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
-
- *lifetime = tv.tv_sec;
-}
-
-static void lifetime_update(struct cache_object *obj, void *data)
-{
-}
-
-static void lifetime_destroy(struct cache_object *obj, void *data)
-{
-}
-
-static int lifetime_dump(struct cache_object *obj,
- void *data,
- char *buf,
- int type)
-{
- long *lifetime = data;
- struct timeval tv;
-
- if (type == NFCT_O_XML)
- return 0;
-
- gettimeofday(&tv, NULL);
-
- return sprintf(buf, " [active since %lds]", tv.tv_sec - *lifetime);
-}
-
-struct cache_feature lifetime_feature = {
- .size = sizeof(long),
- .add = lifetime_add,
- .update = lifetime_update,
- .destroy = lifetime_destroy,
- .dump = lifetime_dump
-};
diff --git a/src/stats-mode.c b/src/stats-mode.c
index b742c0c..226a6b8 100644
--- a/src/stats-mode.c
+++ b/src/stats-mode.c
@@ -37,9 +37,7 @@ static int init_stats(void)
}
memset(state.stats, 0, sizeof(struct ct_stats_state));
- STATE_STATS(cache) = cache_create("stats",
- LIFETIME,
- NULL);
+ STATE_STATS(cache) = cache_create("stats", NO_FEATURES, NULL);
if (!STATE_STATS(cache)) {
dlog(LOG_ERR, "can't allocate memory for the "
"external cache");
diff --git a/src/sync-alarm.c b/src/sync-alarm.c
index a2f17ac..1815447 100644
--- a/src/sync-alarm.c
+++ b/src/sync-alarm.c
@@ -154,8 +154,8 @@ static void alarm_xmit(void)
}
struct sync_mode sync_alarm = {
- .internal_cache_flags = LIFETIME,
- .external_cache_flags = TIMER | LIFETIME,
+ .internal_cache_flags = NO_FEATURES,
+ .external_cache_flags = TIMER,
.internal_cache_extra = &cache_alarm_extra,
.recv = alarm_recv,
.enqueue = alarm_enqueue,
diff --git a/src/sync-ftfw.c b/src/sync-ftfw.c
index fd6c350..91ce25d 100644
--- a/src/sync-ftfw.c
+++ b/src/sync-ftfw.c
@@ -561,8 +561,8 @@ static void ftfw_enqueue(struct cache_object *obj, int type)
}
struct sync_mode sync_ftfw = {
- .internal_cache_flags = LIFETIME,
- .external_cache_flags = LIFETIME,
+ .internal_cache_flags = NO_FEATURES,
+ .external_cache_flags = NO_FEATURES,
.internal_cache_extra = &cache_ftfw_extra,
.init = ftfw_init,
.kill = ftfw_kill,
diff --git a/src/sync-notrack.c b/src/sync-notrack.c
index 3b547ee..7bd4351 100644
--- a/src/sync-notrack.c
+++ b/src/sync-notrack.c
@@ -173,8 +173,8 @@ static void notrack_enqueue(struct cache_object *obj, int query)
}
struct sync_mode sync_notrack = {
- .internal_cache_flags = LIFETIME,
- .external_cache_flags = LIFETIME,
+ .internal_cache_flags = NO_FEATURES,
+ .external_cache_flags = NO_FEATURES,
.internal_cache_extra = &cache_notrack_extra,
.local = notrack_local,
.recv = notrack_recv,