From 75a7cd3c722e1abca14fc375bec8ab30c34ab284 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Wed, 16 Nov 2011 02:10:31 +0100 Subject: conntrackd: remove cache_data_get_object and replace by direct pointer We now include one pointer to the object in the extra section. This is required to generalize this code for the expectation support. We consume 4-8 bytes extra, but we will not need more changes to support expectations which is a good idea. --- include/cache.h | 1 - src/cache.c | 5 ----- src/sync-alarm.c | 10 +++++----- src/sync-ftfw.c | 19 +++++++------------ src/sync-notrack.c | 14 +++++++------- 5 files changed, 19 insertions(+), 30 deletions(-) diff --git a/include/cache.h b/include/cache.h index 65f7e3a..abebb97 100644 --- a/include/cache.h +++ b/include/cache.h @@ -147,7 +147,6 @@ void cache_del(struct cache *c, struct cache_object *obj); struct cache_object *cache_find(struct cache *c, void *ptr, int *pos); void cache_stats(const struct cache *c, int fd); void cache_stats_extended(const struct cache *c, int fd); -struct cache_object *cache_data_get_object(struct cache *c, void *data); void *cache_get_extra(struct cache_object *); void cache_iterate(struct cache *c, void *data, int (*iterate)(void *data1, void *data2)); void cache_iterate_limit(struct cache *c, void *data, uint32_t from, uint32_t steps, int (*iterate)(void *data1, void *data2)); diff --git a/src/cache.c b/src/cache.c index f515ba0..7c41e54 100644 --- a/src/cache.c +++ b/src/cache.c @@ -303,11 +303,6 @@ struct cache_object *cache_find(struct cache *c, void *ptr, int *id) return ((struct cache_object *) hashtable_find(c->h, ptr, *id)); } -struct cache_object *cache_data_get_object(struct cache *c, void *data) -{ - return (struct cache_object *)((char*)data - c->extra_offset); -} - void *cache_get_extra(struct cache_object *obj) { return (char*)obj + obj->cache->extra_offset; diff --git a/src/sync-alarm.c b/src/sync-alarm.c index 03481fd..acaf5e6 100644 --- a/src/sync-alarm.c +++ b/src/sync-alarm.c @@ -29,6 +29,7 @@ struct cache_alarm { struct queue_node qnode; + struct cache_object *obj; struct alarm_block alarm; }; @@ -50,6 +51,7 @@ static void cache_alarm_add(struct cache_object *obj, void *data) struct cache_alarm *ca = data; queue_node_init(&ca->qnode, Q_ELEM_OBJ); + ca->obj = obj; init_alarm(&ca->alarm, obj, refresher); add_alarm(&ca->alarm, random() % CONFIG(refresh) + 1, @@ -131,15 +133,13 @@ static int tx_queue_xmit(struct queue_node *n, const void *data) break; case Q_ELEM_OBJ: { struct cache_alarm *ca; - struct cache_object *obj; int type; ca = (struct cache_alarm *)n; - obj = cache_data_get_object(STATE(mode)->internal->ct.data, ca); - type = object_status_to_network_type(obj); - net = obj->cache->ops->build_msg(obj, type); + type = object_status_to_network_type(ca->obj); + net = ca->obj->cache->ops->build_msg(ca->obj, type); multichannel_send(STATE_SYNC(channel), net); - cache_object_put(obj); + cache_object_put(ca->obj); break; } } diff --git a/src/sync-ftfw.c b/src/sync-ftfw.c index c7cc4aa..fa76c0c 100644 --- a/src/sync-ftfw.c +++ b/src/sync-ftfw.c @@ -55,12 +55,14 @@ static int say_hello_back; struct cache_ftfw { struct queue_node qnode; + struct cache_object *obj; uint32_t seq; }; static void cache_ftfw_add(struct cache_object *obj, void *data) { struct cache_ftfw *cn = data; + cn->obj = obj; /* These nodes are not inserted in the list */ queue_node_init(&cn->qnode, Q_ELEM_OBJ); } @@ -302,13 +304,11 @@ static int rs_queue_empty(struct queue_node *n, const void *data) } case Q_ELEM_OBJ: { struct cache_ftfw *cn; - struct cache_object *obj; cn = (struct cache_ftfw *) n; if (h == NULL) { queue_del(n); - obj = cache_data_get_object(STATE(mode)->internal->ct.data, cn); - cache_object_put(obj); + cache_object_put(cn->obj); return 0; } if (before(cn->seq, h->from)) @@ -318,8 +318,7 @@ static int rs_queue_empty(struct queue_node *n, const void *data) dp("queue: deleting from queue (seq=%u)\n", cn->seq); queue_del(n); - obj = cache_data_get_object(STATE(mode)->internal->ct.data, cn); - cache_object_put(obj); + cache_object_put(cn->obj); break; } } @@ -465,11 +464,9 @@ static void rs_queue_purge_full(void) } case Q_ELEM_OBJ: { struct cache_ftfw *cn; - struct cache_object *obj; cn = (struct cache_ftfw *)n; - obj = cache_data_get_object(STATE(mode)->internal->ct.data, cn); - cache_object_put(obj); + cache_object_put(cn->obj); break; } } @@ -511,14 +508,12 @@ static int tx_queue_xmit(struct queue_node *n, const void *data) } case Q_ELEM_OBJ: { struct cache_ftfw *cn; - struct cache_object *obj; int type; struct nethdr *net; cn = (struct cache_ftfw *)n; - obj = cache_data_get_object(STATE(mode)->internal->ct.data, cn); - type = object_status_to_network_type(obj); - net = obj->cache->ops->build_msg(obj, type); + type = object_status_to_network_type(cn->obj); + net = cn->obj->cache->ops->build_msg(cn->obj, type); nethdr_set_hello(net); dp("tx_list sq: %u fl:%u len:%u\n", diff --git a/src/sync-notrack.c b/src/sync-notrack.c index a8cc6bf..06ad1f0 100644 --- a/src/sync-notrack.c +++ b/src/sync-notrack.c @@ -34,12 +34,14 @@ static struct alarm_block alive_alarm; struct cache_notrack { struct queue_node qnode; + struct cache_object *obj; }; static void cache_notrack_add(struct cache_object *obj, void *data) { struct cache_notrack *cn = data; queue_node_init(&cn->qnode, Q_ELEM_OBJ); + cn->obj = obj; } static void cache_notrack_del(struct cache_object *obj, void *data) @@ -191,19 +193,17 @@ static int tx_queue_xmit(struct queue_node *n, const void *data2) break; } case Q_ELEM_OBJ: { - struct cache_ftfw *cn; - struct cache_object *obj; + struct cache_notrack *cn; int type; struct nethdr *net; - cn = (struct cache_ftfw *)n; - obj = cache_data_get_object(STATE(mode)->internal->ct.data, cn); - type = object_status_to_network_type(obj);; - net = obj->cache->ops->build_msg(obj, type); + cn = (struct cache_notrack *)n; + type = object_status_to_network_type(cn->obj); + net = cn->obj->cache->ops->build_msg(cn->obj, type); multichannel_send(STATE_SYNC(channel), net); queue_del(n); - cache_object_put(obj); + cache_object_put(cn->obj); break; } } -- cgit v1.2.3