|
From: <jsa...@us...> - 2008-06-03 00:13:05
|
Revision: 1251
http://como.svn.sourceforge.net/como/?rev=1251&view=rev
Author: jsanjuas
Date: 2008-06-02 17:13:00 -0700 (Mon, 02 Jun 2008)
Log Message:
-----------
. removed a bunch of useless macros from module.h
. added a new macro to module.h that expands to a module's allocator
. flowtable conforms to the new "use malloc if null allocator" rule
Modified Paths:
--------------
src/branches/2.0/include/como.h
src/branches/2.0/include/module.h
src/branches/2.0/lib/flowtable.c
src/branches/2.0/modules/autofocus/capture.c
src/branches/2.0/modules/topaddr/capture.c
src/branches/2.0/modules/topaddr/export.c
src/branches/2.0/modules/topaddr_csharp/capture.c
src/branches/2.0/modules/tophwaddr/capture.c
src/branches/2.0/modules/tophwaddr/export.c
src/branches/2.0/modules/tuple/capture.c
Modified: src/branches/2.0/include/como.h
===================================================================
--- src/branches/2.0/include/como.h 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/include/como.h 2008-06-03 00:13:00 UTC (rev 1251)
@@ -29,7 +29,6 @@
*
* $Id$
*/
-
#ifndef _COMO_COMO_H
#define _COMO_COMO_H
@@ -79,6 +78,7 @@
#include "eventloop.h"
#include "pool.h"
#include "shmem.h"
+#include "module.h"
void setproctitle_init(int argc, char **argv);
void setproctitle(const char *format, ...);
Modified: src/branches/2.0/include/module.h
===================================================================
--- src/branches/2.0/include/module.h 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/include/module.h 2008-06-03 00:13:00 UTC (rev 1251)
@@ -32,9 +32,6 @@
#ifndef _COMO_MODULE_H
#define _COMO_MODULE_H
-
-#include <string.h> /* memcpy */
-
#include "como.h"
#include "como-build.h"
@@ -42,171 +39,8 @@
#include "comotypes.h"
#include "comofunc.h"
-/*
- * Some useful macros to write modules
- */
-#ifdef ENABLE_SHARED_MODULES
-# define MODULE(name) module_cb_t callbacks
-#else
-# define MODULE(name) module_cb_t g_ ## name ## _module
-#endif
+#define MDL_MEM (mdl_alc(self))
-
-
-/*
- * FLOWDESC/EFLOWDESC are supposed to be defined by individual
- * modules as the type to be used for flow descriptors. If so,
- * here we define an F()/EF() macro to cast a pointer to
- * (FLOWDESC/EFLOWDESC *) to make the writing of modules more
- * convenient.
- */
-#define F(x) ((FLOWDESC *)(((char *) x) + sizeof(rec_t)))
-#define EF(x) ((EFLOWDESC *)(((char *) x) + sizeof(rec_t)))
-
-/*
- * One more indirection is needed within compare_fn()
- */
-#define CMPEF(x) ((EFLOWDESC *)((*(char **) x) + sizeof(rec_t)))
-
-/*
- * CONFIG is defined by each individual module and stored
- * somewhere in the module_t data structure (opaque to modules).
- * we use CONFIG() to retrieve the state from that structure
- */
-//#define CONFIG(x) (((module_t *) (x))->config)
-
-/*
- * ESTATE is defined by each individual module and stored
- * somewhere in the module_t data structure (opaque to modules).
- * we use ESTATE() to retrieve the state from that structure
- */
-
-//#define ESTATE(x) (((module_t *) (x))->estate)
-
-/*
- * FSTATE is defined by each individual module and stored
- * somewhere in the module_t data structure (opaque to modules).
- * we use FSTATE() to retrieve the state from that structure
- */
-//#define FSTATE(x) (((module_t *) (x))->fstate)
-
-/*
- * Macros to copy integers from host to network byte order.
- * They advance the buffer pointer of the proper amount as well.
- * This macros are supposed to be used by store()
- */
-/*
-#define PUTH8(x, val) { \
- uint8_t v = val; \
- memcpy(x, &v, sizeof(v)); \
- x = ((char *)x) + 1; \
-}
-
-#define PUTH16(x, val) { \
- uint16_t v = htons(val); \
- memcpy(x, &v, sizeof(v)); \
- x = ((char *)x) + 2; \
-}
-
-#define PUTH32(x, val) { \
- uint32_t v = htonl(val); \
- memcpy(x, &v, sizeof(v)); \
- x = ((char *)x) + 4; \
-}
-
-#define PUTH64(x, val) { \
- uint64_t v = HTONLL(val); \
- memcpy(x, &v, sizeof(v)); \
- x = ((char *)x) + 8; \
-}
-*/
-/*
- * Macros to copy integers directly in network byte order
- * They advance the buffer pointer of the proper amount as well.
- * This macros are supposed to be used by store()
- */
-/*
-#define PUTN8(x, val) PUTH8(x, val)
-
-#define PUTN16(x, val) { \
- uint16_t v = val; \
- memcpy(x, &v, sizeof(v)); \
- x = ((char *)x) + 2; \
-}
-
-#define PUTN32(x, val) { \
- uint32_t v = val; \
- memcpy(x, &v, sizeof(v)); \
- x = ((char *)x) + 4; \
-}
-
-#define PUTN64(x, val) { \
- uint64_t v = val; \
- memcpy(x, &v, sizeof(v)); \
- x = ((char *)x) + 8; \
-}
-*/
-
-/*
- * Macros to read values from a buf and convert them from network
- * to host byte order. They advance the buffer pointer of the proper
- * amount as well. This macros are supposed to be used by the
- * print()/replay()/load() callbacks
- */
-/*
-#define GETH8(x, val) { \
- memcpy(val, x, 1); \
- x = ((char *)x) + 1; \
-}
-
-#define GETH16(x, val) { \
- memcpy(val, x, 2); \
- *val = ntohs(*val); \
- x = ((char *)x) + 2; \
-}
-
-#define GETH32(x, val) { \
- memcpy(val, x, 4); \
- *val = ntohl(*val); \
- x = ((char *)x) + 4; \
-}
-
-#define GETH64(x, val) { \
- memcpy(val, x, 8); \
- *val = NTOHLL(*val); \
- x = ((char *)x) + 8; \
-}
-*/
-
-/*
- * Macros to read values from a buf and keep them in network byte order.
- * They advance the buffer pointer of the proper amount as well.
- * This macros are supposed to be used by the print()/replay()/load()
- * callbacks.
- */
-/*
-#define GETN8(x, val) GETH8(x, val)
-
-#define GETN16(x, val) { \
- memcpy(val, x, 2); \
- x = ((char *)x) + 2; \
-}
-
-#define GETN32(x, val) { \
- memcpy(val, x, 4); \
- x = ((char *)x) + 4; \
-}
-
-#define GETN64(x, val) { \
- memcpy(val, x, 8); \
- x = ((char *)x) + 8; \
-}
-*/
-
-#ifndef MAX
-#define MAX(a,b) (((a) > (b))? (a) : (b))
-#endif
-
#endif /* _COMO_MODULE_H */
Modified: src/branches/2.0/lib/flowtable.c
===================================================================
--- src/branches/2.0/lib/flowtable.c 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/lib/flowtable.c 2008-06-03 00:13:00 UTC (rev 1251)
@@ -203,7 +203,9 @@
flowtable_t *ftable;
int numBuckets;
- assert(alc != NULL);
+ if (alc == NULL)
+ alc = como_alc();
+
ftable = alc_calloc(alc, 1, sizeof(flowtable_t));
ftable->alc = alc;
Modified: src/branches/2.0/modules/autofocus/capture.c
===================================================================
--- src/branches/2.0/modules/autofocus/capture.c 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/modules/autofocus/capture.c 2008-06-03 00:13:00 UTC (rev 1251)
@@ -65,17 +65,16 @@
ca_state_t *
ca_init(mdl_t *self, timestamp_t ivl)
{
- alc_t *alc = mdl_alc(self);
config_t *config = mdl_get_config(self, config_t);
ca_state_t *st = mdl_malloc(self, sizeof(ca_state_t));
uhash_initialize(&st->hfunc);
if (config->use_srcs)
- st->table = flowtable_new(alc, 2048, NULL,
+ st->table = flowtable_new(MDL_MEM, 2048, NULL,
(flow_match_fn) pkt_belongs_to_tuple_BY_SRC, NULL);
else
- st->table = flowtable_new(alc, 2048, NULL,
+ st->table = flowtable_new(MDL_MEM, 2048, NULL,
(flow_match_fn) pkt_belongs_to_tuple_BY_DST, NULL);
return st;
Modified: src/branches/2.0/modules/topaddr/capture.c
===================================================================
--- src/branches/2.0/modules/topaddr/capture.c 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/modules/topaddr/capture.c 2008-06-03 00:13:00 UTC (rev 1251)
@@ -62,14 +62,13 @@
ca_state_t *
ca_init(mdl_t *self, timestamp_t ivl)
{
- alc_t *alc = mdl_alc(self);
topaddr_config_t *cfg = mdl_get_config(self, topaddr_config_t);
ca_state_t *st = mdl_malloc(self, sizeof(ca_state_t));
uhash_initialize(&st->hfunc);
st->use_dst = cfg->use_dst;
- st->table = flowtable_new(alc, 2048, NULL,
+ st->table = flowtable_new(MDL_MEM, 2048, NULL,
cfg->use_dst ?
(flow_match_fn) BY_DST_pkt_belongs_to_record :
(flow_match_fn) BY_SRC_pkt_belongs_to_record,
Modified: src/branches/2.0/modules/topaddr/export.c
===================================================================
--- src/branches/2.0/modules/topaddr/export.c 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/modules/topaddr/export.c 2008-06-03 00:13:00 UTC (rev 1251)
@@ -69,7 +69,7 @@
reinitialize_state(mdl_t *self, ex_state_t *st)
{
st->nrec = 0;
- st->table = flowtable_new(mdl_alc(self), 2048, NULL, (flow_match_fn)
+ st->table = flowtable_new(MDL_MEM, 2048, NULL, (flow_match_fn)
tuple_matches_record, NULL);
}
@@ -79,7 +79,6 @@
ex_state_t *
ex_init(mdl_t *self)
{
- alc_t *alc = mdl_alc(self);
ex_state_t *st = mdl_malloc(self, sizeof(ex_state_t));
st->current_ivl = 0;
uhash_initialize(&st->hfunc);
Modified: src/branches/2.0/modules/topaddr_csharp/capture.c
===================================================================
--- src/branches/2.0/modules/topaddr_csharp/capture.c 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/modules/topaddr_csharp/capture.c 2008-06-03 00:13:00 UTC (rev 1251)
@@ -62,15 +62,13 @@
ca_state_t *
ca_init(mdl_t *self, timestamp_t ivl)
{
- alc_t *alc = mdl_alc(self);
topaddr_config_t *cfg = mdl_get_config(self, topaddr_config_t);
ca_state_t *st = mdl_malloc(self, sizeof(ca_state_t));
uhash_initialize(&st->hfunc);
st->use_dst = cfg->use_dst;
- st->table = flowtable_new(alc, 2048, NULL,
- cfg->use_dst ?
+ st->table = flowtable_new(MDL_MEM, 2048, NULL, cfg->use_dst ?
(flow_match_fn) BY_DST_pkt_belongs_to_record :
(flow_match_fn) BY_SRC_pkt_belongs_to_record,
NULL);
Modified: src/branches/2.0/modules/tophwaddr/capture.c
===================================================================
--- src/branches/2.0/modules/tophwaddr/capture.c 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/modules/tophwaddr/capture.c 2008-06-03 00:13:00 UTC (rev 1251)
@@ -63,15 +63,13 @@
ca_state_t *
ca_init(mdl_t *self, timestamp_t ivl)
{
- alc_t *alc = mdl_alc(self);
tophwaddr_config_t *cfg = mdl_get_config(self, tophwaddr_config_t);
ca_state_t *st = mdl_malloc(self, sizeof(ca_state_t));
uhash_initialize(&st->hfunc);
st->use_dst = cfg->use_dst;
- st->table = flowtable_new(alc, 2048, NULL,
- cfg->use_dst ?
+ st->table = flowtable_new(MDL_MEM, 2048, NULL, cfg->use_dst ?
(flow_match_fn) BY_DST_pkt_belongs_to_record :
(flow_match_fn) BY_SRC_pkt_belongs_to_record,
NULL);
Modified: src/branches/2.0/modules/tophwaddr/export.c
===================================================================
--- src/branches/2.0/modules/tophwaddr/export.c 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/modules/tophwaddr/export.c 2008-06-03 00:13:00 UTC (rev 1251)
@@ -67,7 +67,7 @@
reinitialize_state(mdl_t *self, ex_state_t *st)
{
st->nrec = 0;
- st->table = flowtable_new(mdl_alc(self), 2048, NULL, (flow_match_fn)
+ st->table = flowtable_new(MDL_MEM, 2048, NULL, (flow_match_fn)
tuple_matches_record, NULL);
}
@@ -77,7 +77,6 @@
ex_state_t *
ex_init(mdl_t *self)
{
- alc_t *alc = mdl_alc(self);
tophwaddr_config_t *cfg = mdl_get_config(self, tophwaddr_config_t);
ex_state_t *st = mdl_malloc(self, sizeof(ex_state_t));
st->current_ivl = 0;
Modified: src/branches/2.0/modules/tuple/capture.c
===================================================================
--- src/branches/2.0/modules/tuple/capture.c 2008-06-02 23:36:26 UTC (rev 1250)
+++ src/branches/2.0/modules/tuple/capture.c 2008-06-03 00:13:00 UTC (rev 1251)
@@ -67,12 +67,11 @@
ca_state_t *
ca_init(mdl_t *self, timestamp_t ivl)
{
- alc_t *alc = mdl_alc(self);
config_t *config = mdl_get_config(self, config_t);
ca_state_t *st = mdl_malloc(self, sizeof(ca_state_t));
uhash_initialize(&st->hfunc);
- st->table = flowtable_new(alc, 2048, NULL,
+ st->table = flowtable_new(MDL_MEM, 2048, NULL,
(flow_match_fn) pkt_belongs_to_record, NULL);
return st;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|