You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
(22) |
Apr
(54) |
May
(218) |
Jun
(86) |
Jul
(20) |
Aug
(44) |
Sep
(90) |
Oct
(133) |
Nov
(125) |
Dec
(2) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(2) |
Feb
(3) |
Mar
(8) |
Apr
(19) |
May
(35) |
Jun
(10) |
Jul
(12) |
Aug
(6) |
Sep
(14) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
| 2008 |
Jan
(4) |
Feb
(7) |
Mar
(2) |
Apr
|
May
(13) |
Jun
(10) |
Jul
(4) |
Aug
(2) |
Sep
|
Oct
(4) |
Nov
(1) |
Dec
|
|
From: <jsa...@us...> - 2008-11-03 11:28:11
|
Revision: 1268
http://como.svn.sourceforge.net/como/?rev=1268&view=rev
Author: jsanjuas
Date: 2008-11-03 11:28:06 +0000 (Mon, 03 Nov 2008)
Log Message:
-----------
build process does not fail if mono is not available
Modified Paths:
--------------
src/branches/2.0/modules/template-como_module.sh
Modified: src/branches/2.0/modules/template-como_module.sh
===================================================================
--- src/branches/2.0/modules/template-como_module.sh 2008-10-30 11:05:16 UTC (rev 1267)
+++ src/branches/2.0/modules/template-como_module.sh 2008-11-03 11:28:06 UTC (rev 1268)
@@ -70,7 +70,8 @@
echo "Entering build dir"
cd $FULL_BUILD_DIR
-cmake -D MODULE=$MODULE $FULL_MODULE_DIR
+cmake -D MODULE=$MODULE $FULL_MODULE_DIR || \
+ { echo Skipping $MODULE: build dependencies not met; exit; }
echo Building module
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-10-30 11:05:19
|
Revision: 1267
http://como.svn.sourceforge.net/como/?rev=1267&view=rev
Author: jsanjuas
Date: 2008-10-30 11:05:16 +0000 (Thu, 30 Oct 2008)
Log Message:
-----------
more flex-generated code compilation issues resolved
Modified Paths:
--------------
src/branches/2.0/base/CMakeLists.txt
Modified: src/branches/2.0/base/CMakeLists.txt
===================================================================
--- src/branches/2.0/base/CMakeLists.txt 2008-10-21 14:12:56 UTC (rev 1266)
+++ src/branches/2.0/base/CMakeLists.txt 2008-10-30 11:05:16 UTC (rev 1267)
@@ -171,18 +171,18 @@
SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/query-syntax.c GENERATED)
#
-# Some versions of flex (at least 2.5.33) produce code with comparisons between
-# signed and unsigned vars. This, combined with -Wall and -Werror, prevents CoMo
-# from building. We add -Wno-sign-compare to gcc flags to work around this.
+# Some versions of flex (at least 2.5.33) produce code that -Wall does not like.
+# This, combined with -Werror, prevents CoMo from building. We add gcc flags to
+# work around this.
#
# (see bug #1468610 for the flex project at http://sf.net/projects/flex)
#
-SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/filter-lexic.c COMPILE_FLAGS -Wno-sign-compare)
-SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/filter-syntax.c COMPILE_FLAGS -Wno-sign-compare)
-SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/config-lexic.c COMPILE_FLAGS -Wno-sign-compare)
-SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/config-syntax.c COMPILE_FLAGS -Wno-sign-compare)
-SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/query-lexic.c COMPILE_FLAGS -Wno-sign-compare)
-SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/query-syntax.c COMPILE_FLAGS -Wno-sign-compare)
+SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/filter-lexic.c COMPILE_FLAGS "-Wno-sign-compare -Wno-unused")
+SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/filter-syntax.c COMPILE_FLAGS "-Wno-sign-compare -Wno-unused")
+SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/config-lexic.c COMPILE_FLAGS "-Wno-sign-compare -Wno-unused")
+SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/config-syntax.c COMPILE_FLAGS "-Wno-sign-compare -Wno-unused")
+SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/query-lexic.c COMPILE_FLAGS "-Wno-sign-compare -Wno-unused")
+SET_SOURCE_FILES_PROPERTIES(${COMO_BINARY_DIR}/base/query-syntax.c COMPILE_FLAGS "-Wno-sign-compare -Wno-unused")
#
# Include binary directory to include filter-lexic.c and filter-syntax.c
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-10-21 14:13:02
|
Revision: 1266
http://como.svn.sourceforge.net/como/?rev=1266&view=rev
Author: jsanjuas
Date: 2008-10-21 14:12:56 +0000 (Tue, 21 Oct 2008)
Log Message:
-----------
removing bash specific syntax from module build script
Modified Paths:
--------------
src/branches/2.0/modules/template-como_module.sh
Modified: src/branches/2.0/modules/template-como_module.sh
===================================================================
--- src/branches/2.0/modules/template-como_module.sh 2008-10-10 10:50:06 UTC (rev 1265)
+++ src/branches/2.0/modules/template-como_module.sh 2008-10-21 14:12:56 UTC (rev 1266)
@@ -74,7 +74,7 @@
echo Building module
-if [ "$ACTION" == "build" ]
+if [ "$ACTION" != "install" ]
then
make
else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-10-10 11:22:19
|
Revision: 1265
http://como.svn.sourceforge.net/como/?rev=1265&view=rev
Author: jsanjuas
Date: 2008-10-10 10:50:06 +0000 (Fri, 10 Oct 2008)
Log Message:
-----------
. bug fix on child process death handler
. implemented the '-e' switch which makes como exit as soon as capture finishes
. many ipc notices degraded to debug messages
Modified Paths:
--------------
src/branches/2.0/base/capture.c
src/branches/2.0/base/export.c
src/branches/2.0/base/ipc.c
src/branches/2.0/base/supervisor.c
src/branches/2.0/base/util-process.c
src/branches/2.0/include/comopriv.h
Modified: src/branches/2.0/base/capture.c
===================================================================
--- src/branches/2.0/base/capture.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/capture.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -1822,7 +1822,10 @@
mdl_t *mdl = array_at(como_ca.mdls, mdl_t *, idx);
mdl_icapture_t *ic = mdl_get_icapture(mdl);
ipc_send(ic->export, CA_EX_DONE, NULL, 0);
+ break; /* for now there is only 1 export */
}
+
+ exit(0);
}
capture_profiler_notify(CP_END_SNIFFERS);
Modified: src/branches/2.0/base/export.c
===================================================================
--- src/branches/2.0/base/export.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/export.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -383,6 +383,9 @@
ie->running_state = EX_MDL_STATE_FLUSHED;
}
+
+ ipc_finish(1);
+ exit(0);
/*
* we are done
Modified: src/branches/2.0/base/ipc.c
===================================================================
--- src/branches/2.0/base/ipc.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/ipc.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -60,6 +60,7 @@
#include <sys/types.h>
#include <sys/select.h>
+#define LOG_DEBUG_DISABLE
#define LOG_DOMAIN "IPC"
#include "como.h"
@@ -303,7 +304,7 @@
assert(s_me->fd == -1);
s_me->fd = ipc_create_socket(s_me, TRUE);
if (s_me->fd != -1) {
- notice("Listening connections on %s@%s.\n", s_me->name, s_me->at);
+ debug("Listening connections on %s@%s.\n", s_me->name, s_me->at);
}
return s_me->fd;
}
@@ -369,7 +370,7 @@
dst->connected = 1;
- notice("Connected to peer %s@%s.\n", dst->name, dst->at);
+ debug("Connected to peer %s@%s.\n", dst->name, dst->at);
/* add to existing list of destinations */
ipc_peer_list_insert_head(&s_peers, dst);
@@ -532,14 +533,14 @@
if (s_on_connect != NULL) {
ic = s_on_connect((ipc_peer_t *) x, s_user_data);
if (ic == IPC_CLOSE || ic == IPC_ERR) {
- notice("Connection from peer %s on fd %d refused by "
+ debug("Connection from peer %s on fd %d refused by "
"on_connect handler.\n", x->name, fd);
ipc_peer_destroy(x); /* calls close */
return ic;
}
}
ipc_peer_list_insert_head(&s_peers, x);
- notice("New connection from peer %s on fd %d\n", x->name, fd);
+ debug("New connection from peer %s on fd %d\n", x->name, fd);
return IPC_OK;
}
@@ -554,7 +555,7 @@
ic = s_handlers[msg.type]((ipc_peer_t *) x, buf, msg.len, swap,
s_user_data);
if (ic == IPC_CLOSE || ic == IPC_ERR) {
- notice("Closing connection to peer %s on fd %d\n", x->name, fd);
+ debug("Closing connection to peer %s on fd %d\n", x->name, fd);
ipc_peer_list_remove(&s_peers, x);
ipc_peer_destroy(x); /* calls close */
}
@@ -564,7 +565,7 @@
//free(buf);
return ic;
} else {
- notice("Unhandled IPC message type %hd.\n", msg.type);
+ debug("Unhandled IPC message type %hd.\n", msg.type);
//free(buf);
return IPC_OK;
Modified: src/branches/2.0/base/supervisor.c
===================================================================
--- src/branches/2.0/base/supervisor.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/supervisor.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -206,12 +206,12 @@
if (ca_done && st_done && !ex_started) { /* CA && ST done, can go for EX */
ipc_peer_full_t *ex;
- pid_t pid;
debug("CA and ST initialized, starting export\n");
ex = ipc_peer_child(COMO_EX, 0);
- pid = start_child(ex, export_main, como_su->memmap, NULL, node0);
- if (pid < 0) {
+ como_su->ex_pid = start_child(ex, export_main, como_su->memmap,
+ NULL, node0);
+ if (como_su->ex_pid < 0) {
warn("Can't start EXPORT\n");
}
ex_started = 1;
@@ -294,7 +294,32 @@
static void
defchld(UNUSED int si_code)
{
- handle_children();
+ pid_t pid;
+ int ret;
+
+ /*
+ * we need to collect as many children as
+ * possible, since only one signal may be
+ * received for many defuncts.
+ */
+ for(;;) {
+ ret = handle_children(&pid);
+ if (ret == -1)
+ break;
+
+ /* if CA and EX have exited, we are done, we may want to exit */
+ if (pid == s_como_su->ca_pid)
+ s_como_su->ca_pid = 0;
+ if (pid == s_como_su->ex_pid)
+ s_como_su->ex_pid = 0;
+
+ if (como_config->exit_when_done == 1 &&
+ s_como_su->ca_pid == 0 &&
+ s_como_su->ex_pid == 0) {
+ msg("Done, exiting..\n");
+ exit(0);
+ }
+ }
}
/*
@@ -1073,8 +1098,9 @@
if (main_node->sniffers_count > 0) {
/* start the CAPTURE process */
ca = ipc_peer_child(COMO_CA, 0);
- pid = start_child(ca, capture_main, como_su->memmap, NULL, main_node);
- if (pid < 0)
+ como_su->ca_pid = start_child(ca, capture_main, como_su->memmap,
+ NULL, main_node);
+ if (como_su->ca_pid < 0)
error("Can't start CAPTURE\n");
}
Modified: src/branches/2.0/base/util-process.c
===================================================================
--- src/branches/2.0/base/util-process.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/util-process.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -37,6 +37,7 @@
#include <sys/types.h> /* fork */
#include <sys/wait.h> /* wait3() */
+#define LOG_DEBUG_DISABLE
#include "como.h"
#include "comopriv.h"
#include "ipc.h"
@@ -155,10 +156,11 @@
*
* Waits for children that have terminate and reports on the
* exit status with logmsg and returning 1 if the process didn't
- * terminate with an EXIT_SUCCESS and 0 otherwise.
+ * terminate with an EXIT_SUCCESS and 0 otherwise. If there was
+ * nothing to do, returns -1.
*/
int
-handle_children()
+handle_children(pid_t *ret_pid)
{
int j;
ipc_peer_t * who = NULL;
@@ -166,9 +168,11 @@
int statbuf;
pid = wait3(&statbuf, WNOHANG, NULL);
+ *ret_pid = pid;
+
if (pid <= 0) {
debug("handle_children -- nothing to do\n", pid);
- return 0;
+ return -1;
}
debug("handle_children (pid=%d)\n", pid);
Modified: src/branches/2.0/include/comopriv.h
===================================================================
--- src/branches/2.0/include/comopriv.h 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/include/comopriv.h 2008-10-10 10:50:06 UTC (rev 1265)
@@ -198,7 +198,7 @@
pid_t start_child (ipc_peer_full_t * child, mainloop_fn mainloop,
memmap_t * shmemmap, FILE *client_stream, como_node_t * node);
-int handle_children ();
+int handle_children (pid_t *pid);
void sighdlr_exit(int);
@@ -460,6 +460,8 @@
ipc_peer_t * ex; /* EXPORT */
ipc_peer_t * st; /* STORAGE */
ipc_peer_t * qu; /* QUERY, for use only in inline mode */
+ pid_t ca_pid;
+ pid_t ex_pid;
pid_t su_pid;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-10-09 15:04:36
|
Revision: 1264
http://como.svn.sourceforge.net/como/?rev=1264&view=rev
Author: jsanjuas
Date: 2008-10-09 15:04:34 +0000 (Thu, 09 Oct 2008)
Log Message:
-----------
bitmaps can now clear bits
Modified Paths:
--------------
src/branches/2.0/lib/bitmap.c
Modified: src/branches/2.0/lib/bitmap.c
===================================================================
--- src/branches/2.0/lib/bitmap.c 2008-08-20 16:48:58 UTC (rev 1263)
+++ src/branches/2.0/lib/bitmap.c 2008-10-09 15:04:34 UTC (rev 1264)
@@ -179,6 +179,40 @@
}
/*
+ * -- clear_bit
+ *
+ * Clear a bit in the bitmap, and maintain the counter of zeros.
+ */
+void
+clear_bit(bitmap_t *bm, uint32_t key)
+{
+ int bit = key & (bm->nbits - 1);
+ int where = which_byte(bit);
+ int what = which_bit(bit);
+
+#ifndef BUILD_FOR_ARM
+ int old;
+
+ /*
+ * x86 asm test and clear operation
+ */
+ asm volatile("btrl %2, %1\n\tsbbl %0, %0\n\t"
+ : "=r" (old), "=m" (bm->map[where])
+ : "r" (what));
+
+ if (old)
+ bm->zeros++;
+#else
+ XXX untested
+ if (1 == (map[where] & (1 << what))) {
+ bm->zeros++;
+ map[where] &= ~(1 << what);
+ }
+#endif
+}
+
+
+/*
* -- get_bit
*
* Get a bit of the bitmap.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-08-20 16:49:02
|
Revision: 1263
http://como.svn.sourceforge.net/como/?rev=1263&view=rev
Author: jsanjuas
Date: 2008-08-20 16:48:58 +0000 (Wed, 20 Aug 2008)
Log Message:
-----------
bugfix
Modified Paths:
--------------
src/branches/2.0/modules/tuple/query.c
Modified: src/branches/2.0/modules/tuple/query.c
===================================================================
--- src/branches/2.0/modules/tuple/query.c 2008-08-14 22:32:50 UTC (rev 1262)
+++ src/branches/2.0/modules/tuple/query.c 2008-08-20 16:48:58 UTC (rev 1263)
@@ -188,8 +188,8 @@
getprotoname(rec->proto),
src, (uint) ntohs(rec->src_port),
dst, (uint) ntohs(rec->dst_port),
- rec->bytes * rec->sampling,
- rec->pkts * rec->sampling);
+ (uint64_t) rec->bytes * rec->sampling,
+ (uint64_t) rec->pkts * rec->sampling);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ia...@us...> - 2008-08-14 22:32:53
|
Revision: 1262
http://como.svn.sourceforge.net/como/?rev=1262&view=rev
Author: iannak1
Date: 2008-08-14 22:32:50 +0000 (Thu, 14 Aug 2008)
Log Message:
-----------
Fixed compiler warning with gcc 4.2.3
Added "sessions" module to track flows using a timeout for termination.
Modified Paths:
--------------
src/trunk/modules/CMakeLists.txt
src/trunk/modules/apps.c
src/trunk/modules/assoc.c
src/trunk/modules/autofocus.c
src/trunk/modules/dhcp.c
src/trunk/modules/ewma.c
src/trunk/modules/frames.c
src/trunk/modules/ssid.c
src/trunk/modules/superaddr.c
src/trunk/modules/topaddr.c
src/trunk/modules/tophwaddr.c
src/trunk/modules/topports.c
src/trunk/modules/traffic.c
src/trunk/modules/tuple.c
src/trunk/modules/unknown-ports.c
src/trunk/modules/worm-signature.c
Added Paths:
-----------
src/trunk/modules/sessions.c
Modified: src/trunk/modules/CMakeLists.txt
===================================================================
--- src/trunk/modules/CMakeLists.txt 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/CMakeLists.txt 2008-08-14 22:32:50 UTC (rev 1262)
@@ -16,6 +16,7 @@
pattern-search
protocol
scanner-detector
+ sessions
ssid
superaddr
topaddr
Modified: src/trunk/modules/apps.c
===================================================================
--- src/trunk/modules/apps.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/apps.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -299,9 +299,9 @@
#define GNUPLOTFOOTER "e\n"
-#define PRETTYFMT "%.24s " /* 24 char to skip \n in asctime() */
-#define GNUPLOTFMT "%ld "
-#define PLAINFMT "%12ld "
+static char prettyfmt[] = "%.24s "; /* 24 char to skip \n in asctime() */
+static char gnuplotfmt[] = "%ld ";
+static char plainfmt[] = "%12ld ";
static char *
print(void * self, char *buf, size_t *len, char * const args[])
@@ -321,16 +321,16 @@
int n, j;
/* default is pretty printing */
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
- fmt = PLAINFMT;
+ fmt = plainfmt;
} else if (!strcmp(args[n], "format=pretty")) {
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
} else if (!strcmp(args[n], "format=gnuplot")) {
- fmt = GNUPLOTFMT;
+ fmt = gnuplotfmt;
isrelative = 0;
} else if (!strcmp(args[n], "isrelative")) {
isrelative = 1;
@@ -344,24 +344,24 @@
}
}
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, "%-24s", "Date");
for (j = 0; j < cf->classes; j++)
*len += sprintf(s + *len, "%-10s ", cf->names[j]);
*len += sprintf(s + *len, "\n");
- } else if (fmt == GNUPLOTFMT && isrelative) {
+ } else if (fmt == gnuplotfmt && isrelative) {
*len = sprintf(s, GNUPLOTHDR, "Percentage", "100",
2 * cf->classes, cf->names[cf->classes-1]);
for (j = cf->classes - 1; j > 0; j--)
*len += sprintf(s + *len, GNUPLOTLINE, 2*j, cf->names[j-1]);
*len += sprintf(s + *len, "\n");
- } else if (fmt == GNUPLOTFMT) {
+ } else if (fmt == gnuplotfmt) {
*len = sprintf(s, GNUPLOTHDR, "Mbps", "*",
2 * cf->classes, cf->names[cf->classes - 1]);
for (j = cf->classes - 1; j > 0; j--)
*len += sprintf(s + *len, GNUPLOTLINE, 2*j, cf->names[j-1]);
*len += sprintf(s + *len, "\n");
- } else if (fmt == PLAINFMT) {
+ } else if (fmt == plainfmt) {
*len = 0;
}
@@ -374,7 +374,7 @@
if (buf == NULL && args == NULL) {
/* no footer */
*len = 0;
- if (fmt == GNUPLOTFMT)
+ if (fmt == gnuplotfmt)
*len = sprintf(s, GNUPLOTFOOTER);
return s;
}
@@ -399,17 +399,17 @@
values[i].pkts /= granularity;
}
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, fmt, asctime(localtime(&ts)));
for (i = 0; i < cf->classes; i++)
*len += sprintf(s + *len, "%8llu %8u ",
values[i].bytes, values[i].pkts);
- } else if (fmt == PLAINFMT) {
+ } else if (fmt == plainfmt) {
*len = sprintf(s, fmt, ts) ;
for (i = 0; i < cf->classes; i++)
*len += sprintf(s + *len, "%8llu %8u ",
values[i].bytes, values[i].pkts);
- } else if (fmt == GNUPLOTFMT && isrelative) {
+ } else if (fmt == gnuplotfmt && isrelative) {
/*
* we plot the percentage of traffic that we can
* map to each application.
@@ -437,7 +437,7 @@
/* for the last value to be 100 */
*len += sprintf(s + *len, "%u %u ", 100, 100);
- } else if (fmt == GNUPLOTFMT && !isrelative) {
+ } else if (fmt == gnuplotfmt && !isrelative) {
/*
* we do not need relative values but the absolute
* contribution of each application
Modified: src/trunk/modules/assoc.c
===================================================================
--- src/trunk/modules/assoc.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/assoc.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -277,9 +277,10 @@
#define PRETTYHDR \
"Date Mode AP pkts_down \
Client pkts_up\n"
-#define PRETTYFMT "%.24s %14s %s %9u %s %9u\n"
-#define PLAINFMT "%d %s %s %u %s %u\n"
+static char prettyfmt[] = "%.24s %14s %s %9u %s %9u\n";
+static char plainfmt[] = "%d %s %s %u %s %u\n";
+
static char *
print(void * self, char *buf, size_t *len, char * const args[])
{
@@ -298,13 +299,13 @@
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAINFMT;
+ fmt = plainfmt;
return s;
}
}
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
return s;
}
@@ -319,11 +320,11 @@
pkts_ul = ntohl(x->pkts_upload);
pkts_dl = ntohl(x->pkts_download);
- pretty_mac(x->ap, buff1, sizeof(buff1), fmt == PRETTYFMT);
- pretty_mac(x->client, buff2, sizeof(buff2), fmt == PRETTYFMT);
+ pretty_mac(x->ap, buff1, sizeof(buff1), fmt == prettyfmt);
+ pretty_mac(x->client, buff2, sizeof(buff2), fmt == prettyfmt);
/* print according to the requested format */
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, fmt, asctime(localtime(&t)), \
x->adhoc ? "Ad-Hoc" : "Infrastructure",
buff1, pkts_dl, buff2, pkts_ul);
Modified: src/trunk/modules/autofocus.c
===================================================================
--- src/trunk/modules/autofocus.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/autofocus.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -503,12 +503,6 @@
#define PRETTY_HDR_DSTS \
"\tTimestamp\t\t\t\tDestination IP\t\t\t\tTraffic\n"
-#define PRETTY_FMT \
- "\t%u\t\t\t\t%s/%d\t\t\t\t%llu\n"
-
-#define PLAIN_FMT \
- "\t%u\t\t\t\t%s/%d\t\t\t\t%llu\n"
-
#define HTML_HDR \
"<html>\n" \
"<head>\n" \
@@ -546,10 +540,6 @@
"</table>\n" \
"</body></html>\n"
-#define HTML_FMT \
-"<tr><td>%d</td>" \
-"<td>%s/%d</td>" \
-"<td>%llu</td></tr>\n"
#define HTML_FMT2 \
"<tr><tr><td><br></td></tr>" \
@@ -565,6 +555,9 @@
" <td>Traffic (bytes)</td>\n" \
" </tr>\n"
+static char prettyfmt[] = "\t%u\t\t\t\t%s/%d\t\t\t\t%llu\n";
+static char plainfmt[] = "\t%u\t\t\t\t%s/%d\t\t\t\t%llu\n";
+static char htmlfmt[] = "<tr><td>%d</td><td>%s/%d</td><td>%llu</td></tr>\n";
/*
* -- print
@@ -603,22 +596,22 @@
else
*len = sprintf(s, PRETTY_HDR_SRCS);
- fmt = PRETTY_FMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAIN_FMT;
+ fmt = plainfmt;
} else if (!strcmp(args[n], "format=html")) {
*len = sprintf(s, HTML_HDR);
*len += sprintf(s + *len, HTML_TITLE, what[config->use_dst]);
- fmt = HTML_FMT;
+ fmt = htmlfmt;
} else if (!strcmp(args[n], "format=sidebox")) {
*len = sprintf(s, HTML_HDR);
*len += sprintf(s + *len, SIDEBOX_TITLE,
what[config->use_dst]);
- fmt = HTML_FMT;
+ fmt = htmlfmt;
}
}
count = 0; /* reset count */
@@ -628,7 +621,7 @@
/* last call of print */
if (buf == NULL && args == NULL) {
*len = 0;
- if (fmt == HTML_FMT)
+ if (fmt == htmlfmt)
*len = sprintf(s, HTML_FOOTER);
count = 0; /* reset count */
last_ts = 0; /* reset timestamp */
@@ -654,11 +647,11 @@
bytes = NTOHLL(record->bytes);
/* fill up each type of output */
- if (fmt == PLAIN_FMT)
+ if (fmt == plainfmt)
*len += sprintf(s + *len, fmt, ts, inet_ntoa(addr), mask, bytes);
- else if (fmt == PRETTY_FMT)
+ else if (fmt == prettyfmt)
*len += sprintf(s + *len, fmt, ts, inet_ntoa(addr), mask, bytes);
- else if (fmt == HTML_FMT) {
+ else if (fmt == htmlfmt) {
if (count == 1)
*len += sprintf(s + *len, HTML_FMT2, count, inet_ntoa(addr),
mask, bytes);
Modified: src/trunk/modules/dhcp.c
===================================================================
--- src/trunk/modules/dhcp.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/dhcp.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -244,8 +244,9 @@
#define PRETTYHDR \
"Date Timestamp Client IP MAC Address\n"
-#define PRETTYFMT "%.24s %12d.%06d %15s %19s\n"
+static char prettyfmt[] = "%.24s %12d.%06d %15s %19s\n";
+
static char *
print(void * self, char *buf, size_t *len, char * const args[])
{
@@ -260,7 +261,7 @@
if (buf == NULL && args != NULL) {
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
return s;
}
@@ -285,7 +286,7 @@
}
/* print according to the requested format */
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, fmt,
asctime(localtime(&t)), TS2SEC(ts), TS2USEC(ts),
inet_ntoa(yiaddr), mac);
Modified: src/trunk/modules/ewma.c
===================================================================
--- src/trunk/modules/ewma.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/ewma.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -269,8 +269,6 @@
#define PRETTYHDR "Date Packets Bytes Connx\n"
-#define PRETTYFMT "%.24s %d.%1u %d.%1u %d.%1u\n"
-#define PLAINFMT "%12ld %d.%1u %d.%1u %d.%1u\n"
#define HTMLHDR \
"<html>\n" \
@@ -312,11 +310,6 @@
" <td><b>Connx</b></td>\n" \
" </tr>\n"
-#define HTMLFMT \
- "<tr><td><a href=%s target=_top>%s</a></td>" \
- "<td>%d.%1u</td>" \
- "<td>%d.%1u</td>" \
- "<td>%d.%1u</td></tr>\n"
#define HTMLFOOTER_ALERTS \
"</table>\n"
@@ -324,6 +317,11 @@
#define HTMLFOOTER \
"</body></html>\n"
+static char prettyfmt[] = "%.24s %d.%1u %d.%1u %d.%1u\n";
+static char plainfmt[] = "%12ld %d.%1u %d.%1u %d.%1u\n";
+static char htmlfmt[] = "<tr><td><a href=%s target=_top>%s</a></td>" \
+ "<td>%d.%1u</td><td>%d.%1u</td><td>%d.%1u</td></tr>\n";
+
static char *
print(void * self, char *buf, size_t *len, char * const args[])
{
@@ -342,20 +340,20 @@
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAINFMT;
+ fmt = plainfmt;
} else if (!strcmp(args[n], "format=html")) {
*len = sprintf(s, HTMLHDR);
*len += sprintf(s + *len, HTMLTITLE);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
} else if (!strcmp(args[n], "format=sidebox")) {
*len = sprintf(s, HTMLHDR);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
} else if (!strncmp(args[n], "url=", 4)) {
url = args[n] + 4;
} else if (!strncmp(args[n], "urlargs=", 8)) {
@@ -378,7 +376,7 @@
if (buf == NULL && args == NULL) {
*len = alerts > 0 ? 0 : sprintf(s, STR_NOALERTS);
- if (fmt == HTMLFMT) {
+ if (fmt == htmlfmt) {
if (alerts > 0) {
*len += sprintf(s + *len, HTMLFOOTER_ALERTS);
}
@@ -391,7 +389,7 @@
*len = 0;
if (alerts == 0) {
- if (fmt == HTMLFMT)
+ if (fmt == htmlfmt)
*len = sprintf(s, HTML_ALERTS);
alerts = 1;
}
@@ -403,10 +401,10 @@
((int32_t) (ntohl(c) >> 8)), ((uint8_t) (ntohl(c) & 0xff))
/* print according to the requested format */
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, fmt, asctime(gmtime(&ts)), print_ch(x->ch_pkts),
print_ch(x->ch_bytes), print_ch(x->ch_connx));
- } else if (fmt == HTMLFMT) {
+ } else if (fmt == htmlfmt) {
char timestr[30];
char tmp[2048] = "#";
Modified: src/trunk/modules/frames.c
===================================================================
--- src/trunk/modules/frames.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/frames.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -141,9 +141,6 @@
"ctrl (frames, bytes) " \
"data (frames, bytes)\n"
-#define GNUPLOTFMT "%ld %llu %llu %llu %llu %llu %llu %llu %llu %llu\n"
-#define PRETTYFMT \
- "%.24s %12d.%06d %-5llu %-20llu %-5llu %-20llu %-5llu %-20llu\n"
#define GNUPLOTHDR \
"set terminal postscript eps color solid lw 1 \"Helvetica\" 14;" \
@@ -162,6 +159,10 @@
#define GNUPLOTFOOTER "e\n"
+static char gnuplotfmt[] = "%ld %llu %llu %llu %llu %llu %llu %llu %llu %llu\n";
+static char prettyfmt[] =
+ "%.24s %12d.%06d %-5llu %-20llu %-5llu %-20llu %-5llu %-20llu\n";
+
static char *
print(void * self, char *buf, size_t *len, char * const args[])
{
@@ -176,13 +177,13 @@
if (buf == NULL && args != NULL) {
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=gnuplot")) {
*len = sprintf(s, GNUPLOTHDR);
- fmt = GNUPLOTFMT;
+ fmt = gnuplotfmt;
} else if (!strncmp(args[n], "granularity=", 10)) {
char * val = index(args[n], '=') + 1;
@@ -197,7 +198,7 @@
if (buf == NULL && args == NULL) {
*len = 0;
- if (fmt == GNUPLOTFMT)
+ if (fmt == gnuplotfmt)
*len = sprintf(s, GNUPLOTFOOTER);
return s;
}
@@ -207,12 +208,12 @@
t = (time_t) TS2SEC(ts);
/* print according to the requested format */
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, fmt, asctime(localtime(&t)), TS2SEC(ts), TS2USEC(ts),
NTOHLL(x->mgmtpkts), NTOHLL(x->mgmtbytes), NTOHLL(x->ctrlpkts),
NTOHLL(x->ctrlbytes), NTOHLL(x->datapkts),
NTOHLL(x->databytes));
- } else if (fmt == GNUPLOTFMT) {
+ } else if (fmt == gnuplotfmt) {
*len = sprintf(s, fmt, (long int)t, NTOHLL(x->mgmtpkts),
NTOHLL(x->ctrlpkts), NTOHLL(x->datapkts), NTOHLL(x->mgmtbytes),
NTOHLL(x->ctrlbytes), NTOHLL(x->databytes));
Added: src/trunk/modules/sessions.c
===================================================================
--- src/trunk/modules/sessions.c (rev 0)
+++ src/trunk/modules/sessions.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -0,0 +1,656 @@
+/*
+ * Copyright (c) 2004-2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id: tuple.c 976 2006-10-30 19:01:52Z jsanjuas $
+ */
+
+/*
+ * Session tracker.
+ *
+ * This module tracks all sessions (defined by the usual 5 tuple).
+ * It uses a timeout approach to decide when to terminate a session.
+ * Any packet can start a session. Sessions are reported ordered by
+ * last packet timestamp.
+ *
+ */
+
+#include <stdio.h>
+#include <time.h>
+#include "comofunc.h"
+#include "module.h"
+
+#define FLOWDESC struct _tuple_stat
+FLOWDESC {
+ timestamp_t start_ts;
+ timestamp_t last_ts;
+ n32_t src_ip;
+ n32_t dst_ip;
+ n16_t src_port;
+ n16_t dst_port;
+ uint8_t proto;
+ char padding;
+ uint16_t sampling;
+ uint64_t bytes;
+ uint64_t pkts;
+};
+
+#define EFLOWDESC struct _session
+EFLOWDESC {
+ timestamp_t start_ts;
+ timestamp_t last_ts;
+ n32_t src_ip;
+ n32_t dst_ip;
+ n16_t src_port;
+ n16_t dst_port;
+ uint8_t proto;
+ char padding;
+ uint16_t sampling;
+ uint64_t bytes;
+ uint64_t pkts;
+};
+
+#define CONFIGDESC struct _tuple_config
+CONFIGDESC {
+ /*
+ * packet description and templates for the
+ * replay() callback or to know if we can process
+ * the packets from given sniffer
+ */
+ int compact;
+ uint32_t mask;
+ uint32_t timeout;
+};
+
+static timestamp_t
+init(void * self, char *args[])
+{
+ CONFIGDESC * config;
+ int i;
+ pkt_t * pkt;
+ metadesc_t *inmd, *outmd;
+
+ config = mem_mdl_malloc(self, sizeof(CONFIGDESC));
+ config->compact = 0;
+ config->mask = ~0;
+ config->timeout = 60;
+
+ /*
+ * process input arguments
+ */
+ for (i = 0; args && args[i]; i++) {
+ char * x;
+
+ if (strstr(args[i], "compact")) {
+ config->compact = 1;
+ } else if (strstr(args[i], "mask")) {
+ x = index(args[i], '=') + 1;
+ config->mask <<= atoi(x);
+ } else if (strstr(args[i], "timeout")) {
+ x = index(args[i], '=') + 1;
+ config->timeout = atoi(x);
+ }
+ }
+
+ /*
+ * our input stream needs to contain the port numbers and
+ * a packet length. for the timestamp, we use a default value of
+ * one second or whatever we receive from configuration
+ */
+
+ /* setup indesc */
+ inmd = metadesc_define_in(self, 0);
+
+ pkt = metadesc_tpl_add(inmd, "none:none:~ip:none");
+ IP(proto) = 0xff;
+ N16(IP(len)) = 0xff;
+ N32(IP(src_ip)) = 0xffffffff;
+ N32(IP(dst_ip)) = 0xffffffff;
+
+ pkt = metadesc_tpl_add(inmd, "none:none:~ip:~tcp");
+ IP(proto) = 0xff;
+ N16(IP(len)) = 0xff;
+ N32(IP(src_ip)) = 0xffffffff;
+ N32(IP(dst_ip)) = 0xffffffff;
+ N16(TCP(src_port)) = 0xffff;
+ N16(TCP(dst_port)) = 0xffff;
+
+ pkt = metadesc_tpl_add(inmd, "none:none:~ip:~udp");
+ IP(proto) = 0xff;
+ N16(IP(len)) = 0xff;
+ N32(IP(src_ip)) = 0xffffffff;
+ N32(IP(dst_ip)) = 0xffffffff;
+ N16(UDP(src_port)) = 0xffff;
+ N16(UDP(dst_port)) = 0xffff;
+
+ /* setup outdesc */
+ outmd = metadesc_define_out(self, 0);
+ outmd->flags = META_PKT_LENS_ARE_AVERAGED;
+
+ pkt = metadesc_tpl_add(outmd, "~nf:none:~ip:none");
+ N16(NF(sampling)) = 0xffff;
+ N32(NF(duration)) = 0xffffffff;
+ N32(NF(pktcount)) = 0xffffffff;
+ IP(proto) = 0xff;
+ N16(IP(len)) = 0xff;
+ N32(IP(src_ip)) = 0xffffffff;
+ N32(IP(dst_ip)) = 0xffffffff;
+
+ pkt = metadesc_tpl_add(outmd, "~nf:none:~ip:~tcp");
+ N16(NF(sampling)) = 0xffff;
+ N32(NF(duration)) = 0xffffffff;
+ N32(NF(pktcount)) = 0xffffffff;
+ IP(proto) = 0xff;
+ N16(IP(len)) = 0xff;
+ N32(IP(src_ip)) = 0xffffffff;
+ N32(IP(dst_ip)) = 0xffffffff;
+ N16(TCP(src_port)) = 0xffff;
+ N16(TCP(dst_port)) = 0xffff;
+
+ pkt = metadesc_tpl_add(outmd, "~nf:none:~ip:~udp");
+ N16(NF(sampling)) = 0xffff;
+ N32(NF(duration)) = 0xffffffff;
+ N32(NF(pktcount)) = 0xffffffff;
+ IP(proto) = 0xff;
+ N16(IP(len)) = 0xff;
+ N32(IP(src_ip)) = 0xffffffff;
+ N32(IP(dst_ip)) = 0xffffffff;
+ N16(UDP(src_port)) = 0xffff;
+ N16(UDP(dst_port)) = 0xffff;
+
+ CONFIG(self) = config;
+ return TIME2TS(1, 0);
+}
+
+
+static uint32_t
+hash(void * self, pkt_t *pkt)
+{
+ uint sport, dport;
+
+ if (isTCP) {
+ sport = N16(TCP(src_port));
+ dport = N16(TCP(dst_port));
+ } else if (isUDP) {
+ sport = N16(UDP(src_port));
+ dport = N16(UDP(dst_port));
+ } else {
+ sport = dport = 0;
+ }
+
+ return (N32(IP(src_ip)) ^ N32(IP(dst_ip)) ^ (sport << 3) ^ (dport << 3));
+}
+
+static int
+match(void * self, pkt_t *pkt, void *fh)
+{
+ FLOWDESC *x = F(fh);
+ uint sport, dport;
+
+ if (isTCP) {
+ sport = N16(TCP(src_port));
+ dport = N16(TCP(dst_port));
+ } else if (isUDP) {
+ sport = N16(UDP(src_port));
+ dport = N16(UDP(dst_port));
+ } else {
+ sport = dport = 0;
+ }
+
+ return (
+ N32(IP(src_ip)) == N32(x->src_ip) &&
+ N32(IP(dst_ip)) == N32(x->dst_ip) &&
+ sport == N16(x->src_port) && dport == N16(x->dst_port) &&
+ IP(proto) == x->proto
+ );
+}
+
+static int
+update(void * self, pkt_t *pkt, void *fh, int isnew)
+{
+ FLOWDESC *x = F(fh);
+
+ if (isnew) {
+ x->start_ts = pkt->ts;
+ x->bytes = 0;
+ x->pkts = 0;
+ x->proto = IP(proto);
+ x->src_ip = IP(src_ip);
+ x->dst_ip = IP(dst_ip);
+
+ if (isTCP) {
+ x->src_port = TCP(src_port);
+ x->dst_port = TCP(dst_port);
+ } else if (isUDP) {
+ x->src_port = UDP(src_port);
+ x->dst_port = UDP(dst_port);
+ } else {
+ N16(x->src_port) = N16(x->dst_port) = 0;
+ }
+ }
+
+ x->last_ts = pkt->ts;
+ if (COMO(type) == COMOTYPE_NF) {
+ x->last_ts +=
+ TIME2TS(H32(NF(duration)) / 1000, (H32(NF(duration))%1000)*1000);
+ x->sampling = H16(NF(sampling));
+ x->bytes += H32(NF(pktcount)) * COMO(len);
+ x->pkts += (uint64_t) H32(NF(pktcount));
+ } else if (COMO(type) == COMOTYPE_SFLOW) {
+ x->sampling = (uint16_t) H32(SFLOW(sampling_rate));
+ x->bytes += (uint64_t) COMO(len) * (uint64_t) H32(SFLOW(sampling_rate));
+ x->pkts += (uint64_t) H32(SFLOW(sampling_rate));
+ } else {
+ x->sampling = 1;
+ x->bytes += H16(IP(len));
+ x->pkts++;
+ }
+
+ return 0;
+}
+
+static int
+compare(const void *efh1, const void *efh2)
+{
+ return CMPEF(efh1)->last_ts < CMPEF(efh2)->last_ts ? -1 : 1;
+}
+
+static int
+ematch(void *self, void *efh, void *fh)
+{
+ FLOWDESC *x = F(fh);
+ EFLOWDESC *ex = EF(efh);
+
+ return (
+ N32(x->src_ip) == N32(ex->src_ip) &&
+ N32(x->dst_ip) == N32(ex->dst_ip) &&
+ N16(x->src_port) == N16(ex->src_port) &&
+ N16(x->dst_port) == N16(ex->dst_port) &&
+ x->proto == ex->proto
+ );
+}
+
+static int
+export(void * self, void *efh, void *fh, int isnew)
+{
+ FLOWDESC *x = F(fh);
+ EFLOWDESC *ex = EF(efh);
+
+ if (isnew) {
+ bcopy(x, ex, sizeof(EFLOWDESC));
+ } else {
+ ex->pkts += x->pkts;
+ ex->bytes += x->bytes;
+ ex->last_ts = x->last_ts;
+ }
+
+ return 0;
+}
+
+static int
+action(void *self, void *efh, timestamp_t ivl,
+ timestamp_t current_time, int count)
+{
+ CONFIGDESC * config = CONFIG(self);
+ EFLOWDESC *ex = EF(efh);
+
+ if (efh == NULL)
+ return ACT_GO; /* always process all records */
+
+ /*
+ * if the flow has not seen any packets in the last
+ * config->timeout seconds, store it and discard the record
+ */
+ if (TS2SEC(current_time - ex->last_ts) > config->timeout)
+ return (ACT_STORE | ACT_DISCARD);
+
+ return ACT_GO;
+}
+
+static ssize_t
+store(void * self, void *efh, char *buf)
+{
+ FLOWDESC *x = F(efh);
+
+ PUTH64(buf, x->start_ts);
+ PUTH64(buf, x->last_ts);
+ PUTN32(buf, N32(x->src_ip));
+ PUTN32(buf, N32(x->dst_ip));
+ PUTN16(buf, N16(x->src_port));
+ PUTN16(buf, N16(x->dst_port));
+ PUTH8(buf, x->proto);
+ PUTH8(buf, x->padding);
+ PUTH16(buf, x->sampling);
+ PUTH64(buf, x->bytes);
+ PUTH64(buf, x->pkts);
+
+ return sizeof(FLOWDESC);
+}
+
+static size_t
+load(void * self, char * buf, size_t len, timestamp_t * ts)
+{
+ if (len < sizeof(FLOWDESC)) {
+ *ts = 0;
+ return 0;
+ }
+
+ *ts = NTOHLL(((FLOWDESC *)buf)->start_ts);
+ return sizeof(FLOWDESC);
+}
+
+
+#define PRETTYHDR \
+ "Start " \
+ "Duration " \
+ "Proto Source IP:Port Destination IP:Port " \
+ "Bytes Packets\n"
+
+#define HTMLHDR \
+ "<html>\n" \
+ "<head>\n" \
+ " <style type=\"text/css\">\n" \
+ " body { font-family: \"lucida sans unicode\", verdana, arial;\n" \
+ " font-size: 9pt; margin: 0; padding: 0;}\n" \
+ " table, tr, td {background-color: #eee;\n" \
+ " font-family: \"lucida sans unicode\", verdana, arial;\n" \
+ " font-size: 9pt;}\n" \
+ " a, a:visited { color: #475677; text-decoration: none;}\n" \
+ " .netviewbar{ \n" \
+ " color :#FFF; width :100%%; padding :2px; text-align:center;}\n" \
+ " .netview {\n" \
+ " top: 0px; width: 98%%; vertical-align:top;\n" \
+ " margin: 2; padding-left: 5px;\n" \
+ " padding-right: 5px; text-align:left;}\n" \
+ " .nvtitle {\n" \
+ " font-weight: bold; font-size: 9pt; padding-bottom: 3px;\n" \
+ " color: #475677;}\n" \
+ " </style>\n" \
+ "</head>\n" \
+ "<body>\n" \
+ "<div class=nvtitle style=\"border-top: 1px solid;\">" \
+ "Active connections</div>\n" \
+ "<table class=netview>\n" \
+ " <tr class=nvtitle>\n" \
+ " <td>Start Time</td>\n" \
+ " <td>Duration</td>\n" \
+ " <td>Protocol</td>\n" \
+ " <td>Source IP:Port</td>\n" \
+ " <td>Destination IP:Port</td>\n" \
+ " <td>Bytes</td>\n" \
+ " <td>Packets</td>\n" \
+ " </tr>\n"
+
+#define HTMLFOOTER \
+ "</table>\n" \
+ "</body></html>\n"
+
+static char plainfmt[] =
+ "%10u.%06d %3d.%06d %3d %15s %5u %15s %5u %8llu %8llu\n";
+static char prettyfmt[] =
+ "%s.%06d %3d.%06d %5s %15s %5u %15s %5u %8llu %8llu\n";
+static char htmlfmt[] =
+ "<tr><td>%s.%06d</td><td>%d.%06d</td><td>%s</td>"
+ "<td>%15s:%u</td><td>%15s:%u</td>"
+ "<td>%llu</td><td>%llu</td></tr>\n";
+
+static char *
+print(void * self, char *buf, size_t *len, char * const args[])
+{
+ static char s[2048];
+ static char * fmt;
+ CONFIGDESC * config = CONFIG(self);
+ char src[20], dst[20];
+ struct in_addr saddr, daddr;
+ FLOWDESC *x;
+ timestamp_t start_ts, last_ts;
+ uint start_sec, start_usec;
+ uint duration_sec, duration_usec;
+
+
+ if (buf == NULL && args != NULL) {
+ int n;
+
+ *len = sprintf(s, PRETTYHDR);
+ fmt = prettyfmt;
+
+ /* first call of print, process the arguments and return */
+ for (n = 0; args[n]; n++) {
+ if (!strcmp(args[n], "format=html")) {
+ *len = sprintf(s, HTMLHDR);
+ fmt = htmlfmt;
+ } else if (!strcmp(args[n], "format=plain")) {
+ *len = 0;
+ fmt = plainfmt;
+ }
+ }
+
+ return s;
+ }
+
+ if (buf == NULL && args == NULL) {
+ *len = 0;
+ if (fmt == htmlfmt)
+ *len = sprintf(s, HTMLFOOTER);
+ return s;
+ }
+
+ x = (FLOWDESC *) buf;
+ start_ts = NTOHLL(x->start_ts);
+ last_ts = NTOHLL(x->last_ts);
+
+ start_sec = TS2SEC(start_ts);
+ start_usec = TS2USEC(x->start_ts);
+ duration_sec = TS2SEC(last_ts - start_ts);
+ duration_usec = TS2USEC(last_ts - start_ts);
+
+ /* get IP addresses */
+ saddr.s_addr = N32(x->src_ip) & htonl(config->mask);
+ daddr.s_addr = N32(x->dst_ip) & htonl(config->mask);
+ sprintf(src, "%s", inet_ntoa(saddr));
+ sprintf(dst, "%s", inet_ntoa(daddr));
+
+ if (fmt == plainfmt) {
+ *len = sprintf(s, fmt, start_sec, start_usec,
+ duration_sec, duration_usec, x->proto,
+ src, (uint) H16(x->src_port),
+ dst, (uint) H16(x->dst_port),
+ NTOHLL(x->bytes) * ntohs(x->sampling),
+ NTOHLL(x->pkts) * ntohs(x->sampling));
+ } else {
+ char datestr[30];
+ struct tm * timeptr;
+ time_t t = (time_t) start_sec;
+
+ timeptr = gmtime(&t);
+ strftime(datestr, sizeof(datestr), "%b %e %Y %T", timeptr);
+
+ *len = sprintf(s, fmt,
+ datestr, start_usec, duration_sec, duration_usec,
+ getprotoname(x->proto),
+ src, (uint) H16(x->src_port),
+ dst, (uint) H16(x->dst_port),
+ NTOHLL(x->bytes) * ntohs(x->sampling),
+ NTOHLL(x->pkts) * ntohs(x->sampling));
+ }
+ return s;
+};
+
+
+static int
+replay(void * self, char *buf, char *out, size_t * len, int pleft)
+{
+ CONFIGDESC * config = CONFIG(self);
+ FLOWDESC * x;
+ timestamp_t pkt_ts, inter_ts;
+ uint32_t pkt_duration;
+ size_t outlen;
+ uint64_t nbytes, npkts;
+ int pktsz, paysz;
+
+ if (buf == NULL) {
+ *len = 0;
+ return 0; /* nothing to do */
+ }
+
+ /*
+ * generate packets as long as we have space in the output
+ * buffer. the packets will all be equal with the same timestamps
+ * and a packet length equal to the average packet lengths.
+ */
+ x = (FLOWDESC *) buf;
+ nbytes = NTOHLL(x->bytes);
+ npkts = NTOHLL(x->pkts);
+
+ /* initialize packet left count */
+ if (pleft == 0)
+ pleft = npkts;
+
+ /* fill the output buffer */
+ outlen = 0;
+ paysz = sizeof(struct _como_nf) + sizeof(struct _como_iphdr) +
+ sizeof(struct _como_udphdr);
+ pktsz = sizeof(pkt_t) + paysz;
+ while (outlen + pktsz < *len && pleft > 0) {
+ pkt_t * pkt;
+ uint32_t plen;
+ int pcount;
+
+ pkt = (pkt_t *) (out + outlen);
+ pkt->payload = (char *) pkt + sizeof(pkt_t);
+
+#ifdef BUILD_FOR_ARM
+ COMOX(caplen, paysz);
+ COMOX(type, COMOTYPE_NF);
+ COMOX(l2type, LINKTYPE_NONE);
+ COMOX(l3type, ETHERTYPE_IP);
+ COMOX(l3ofs, sizeof(struct _como_nf));
+ COMOX(l4type, x->proto);
+ COMOX(l4ofs, COMO(l3ofs) + sizeof(struct _como_iphdr));
+ COMOX(l7ofs, COMO(l4ofs) + sizeof(struct _como_udphdr));
+
+ NFX(sampling, x->sampling);
+ IPX(version, 0x4);
+ IPX(ihl, 0x5);
+ IPX(proto, x->proto);
+ IPX(len, htons((uint16_t) COMO(len)));
+ IPX(src_ip, x->src_ip);
+ IPX(dst_ip, x->dst_ip);
+
+ UDP(src_port, x->src_port);
+ UDP(dst_port, x->dst_port);
+#else
+ COMO(caplen) = paysz;
+ COMO(type) = COMOTYPE_NF;
+ COMO(l2type) = LINKTYPE_NONE;
+ COMO(l3type) = ETHERTYPE_IP;
+ COMO(l3ofs) = sizeof(struct _como_nf);
+ COMO(l4type) = x->proto;
+ COMO(l4ofs) = COMO(l3ofs) + sizeof(struct _como_iphdr);
+ COMO(l7ofs) = COMO(l4ofs) + sizeof(struct _como_udphdr);
+
+ N16(NF(sampling)) = x->sampling;
+
+ IP(version) = 0x4;
+ IP(ihl) = 0x5;
+ IP(proto) = x->proto;
+ N16(IP(len)) = htons((uint16_t) COMO(len));
+ IP(src_ip) = x->src_ip;
+ IP(dst_ip) = x->dst_ip;
+
+ UDP(src_port) = x->src_port;
+ UDP(dst_port) = x->dst_port;
+#endif
+
+ pcount = 1;
+ plen = nbytes / npkts;
+ if (pleft == 1)
+ plen += nbytes % npkts;
+
+ if (config->compact && pleft != 1) {
+ /*
+ * in compact mode we need to make sure we generate a number
+ * of packets with the correct size taking into account that
+ * the first packet will always weigh more (i.e. NF(pktcount)).
+ * therefore we need n packets with size bytes/pkts and 1 last
+ * packet with size "bytes/pkts + bytes%pkts" to carry the
+ * leftovers.
+ *
+ */
+ pcount = pleft;
+ if (nbytes % npkts != 0)
+ pcount--;
+ }
+
+ inter_ts = NTOHLL(x->last_ts) - NTOHLL(x->start_ts);
+ inter_ts /= (uint64_t) npkts;
+ pkt_ts = NTOHLL(x->start_ts) + (npkts - pleft) * inter_ts;
+ pkt_duration = TS2SEC(inter_ts * (pcount - 1)) * 1000 +
+ TS2MSEC(inter_ts * (pcount - 1));
+
+#ifdef BUILD_FOR_ARM
+ COMOX(ts, pkt_ts);
+ COMOX(len, plen);
+ NFX(pktcount, htonl(pcount));
+ NFX(duration, htonl(pduration));
+#else
+ COMO(ts) = pkt_ts;
+ COMO(len) = plen;
+ N32(NF(pktcount)) = htonl(pcount);
+ N32(NF(duration)) = htonl(pkt_duration);
+#endif
+
+ pleft -= pcount;
+ outlen += pktsz;
+ }
+
+ *len = outlen;
+ return pleft;
+}
+
+MODULE(tuple) = {
+ ca_recordsize: sizeof(FLOWDESC),
+ ex_recordsize: sizeof(FLOWDESC),
+ st_recordsize: sizeof(FLOWDESC),
+ capabilities: {has_flexible_flush: 0, 0},
+ init: init,
+ check: NULL,
+ hash: hash,
+ match: match,
+ update: update,
+ flush: NULL,
+ ematch: ematch,
+ export: export,
+ compare: compare,
+ action: action,
+ store: store,
+ load: load,
+ print: print,
+ replay: replay,
+ formats: "plain pretty html"
+};
Modified: src/trunk/modules/ssid.c
===================================================================
--- src/trunk/modules/ssid.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/ssid.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -211,9 +211,10 @@
#define PRETTYHDR \
"Date Signal (dbm) Noise (dbm) Channel \
Samples WEP MAC SSID\n"
-#define PRETTYFMT "%.24s %-15d %-15d %-10d %-10d %-5s %s %-32s\n"
-#define PLAINFMT "%12ld %1d %2d %2d %2d %2d\n"
+static char prettyfmt[] = "%.24s %-15d %-15d %-10d %-10d %-5s %s %-32s\n";
+static char plainfmt[] = "%12ld %1d %2d %2d %2d %2d\n";
+
static char *
print(void * self, char *buf, size_t *len, char * const args[])
{
@@ -232,13 +233,13 @@
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAINFMT;
+ fmt = plainfmt;
return s;
}
}
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
return s;
}
@@ -255,7 +256,7 @@
noise = (int32_t)ntohl(x->noise) / x->samples;
/* print according to the requested format */
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
char * wepmode = x->wepmode? "Y": "N";
char bssid[64];
Modified: src/trunk/modules/superaddr.c
===================================================================
--- src/trunk/modules/superaddr.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/superaddr.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -372,12 +372,7 @@
#define PRETTY_HDR_DST_SRCS \
"\tTimestamp\t\t\t\tDestination IP\t\t\t\t#Sources\n"
-#define PRETTY_FMT \
- "\t%u\t\t\t\t%s\t\t\t\t%u\n"
-#define PLAIN_FMT \
- "\t%u\t\t\t\t%s\t\t\t\t%u\n"
-
#define HTML_HDR \
"<html>\n" \
"<head>\n" \
@@ -415,11 +410,6 @@
"</table>\n" \
"</body></html>\n"
-#define HTML_FMT \
- "<tr><td>%d</td>" \
-"<td>%s</td>" \
-"<td>%u</td></tr>\n"
-
#define HTML_FMT2 \
"<tr><tr><td><br></td></tr>" \
"<td>%d</td>" \
@@ -439,8 +429,6 @@
"set format x \"%%H:%%M\";" \
"plot \"-\" using 1:2 with lines lt 4\n"
-#define GNUPLOT_FMT "%u %u\n"
-
#define GNUPLOT_FOOTER "e\n"
#define SIDEBOX_TITLE \
@@ -451,6 +439,10 @@
" <td>%s</td>\n" \
" </tr>\n"
+static char prettyfmt[] = "\t%u\t\t\t\t%s\t\t\t\t%u\n";
+static char plainfmt[] = "\t%u\t\t\t\t%s\t\t\t\t%u\n";
+static char gnuplotfmt[] = "%u %u\n";
+static char htmlfmt[] = "<tr><td>%d</td><td>%s</td><td>%u</td></tr>\n";
/*
* -- print
@@ -488,28 +480,28 @@
else
*len = sprintf(s, PRETTY_HDR_SRC_DSTS);
- fmt = PRETTY_FMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAIN_FMT;
+ fmt = plainfmt;
} else if (!strcmp(args[n], "format=html")) {
*len = sprintf(s, HTML_HDR);
*len += sprintf(s + *len, HTML_TITLE, what1[config->use_dst],
what2[config->use_dst],
what3[config->use_dst]);
- fmt = HTML_FMT;
+ fmt = htmlfmt;
} else if (!strcmp(args[n], "format=gnuplot")) {
*len = sprintf(s, GNUPLOT_HDR, what3[config->use_dst]);
- fmt = GNUPLOT_FMT;
+ fmt = gnuplotfmt;
} else if (!strcmp(args[n], "format=sidebox")) {
*len = sprintf(s, HTML_HDR);
*len += sprintf(s + *len, SIDEBOX_TITLE,
what2[config->use_dst],
what3[config->use_dst]);
- fmt = HTML_FMT;
+ fmt = htmlfmt;
}
}
count = 0; /* reset count */
@@ -519,9 +511,9 @@
/* last call of print */
if (buf == NULL && args == NULL) {
*len = 0;
- if (fmt == HTML_FMT)
+ if (fmt == htmlfmt)
*len = sprintf(s, HTML_FOOTER);
- if (fmt == GNUPLOT_FMT)
+ if (fmt == gnuplotfmt)
*len = sprintf(s, GNUPLOT_FOOTER);
count = 0; /* reset count */
last_ts = 0; /* reset timestamp */
@@ -549,11 +541,11 @@
count++;
super_addrs++;
- if (fmt == PLAIN_FMT)
+ if (fmt == plainfmt)
*len = sprintf(s, fmt, ts, inet_ntoa(addr), meter);
- else if (fmt == PRETTY_FMT)
+ else if (fmt == prettyfmt)
*len = sprintf(s, fmt, ts, inet_ntoa(addr), meter);
- else if (fmt == HTML_FMT) {
+ else if (fmt == htmlfmt) {
if (count == 1)
*len = sprintf(s, HTML_FMT2, count, inet_ntoa(addr), meter);
else
Modified: src/trunk/modules/topaddr.c
===================================================================
--- src/trunk/modules/topaddr.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/topaddr.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -255,10 +255,6 @@
#define PRETTYHDR \
"Date %-15s Bytes Packets \n"
-#define PRETTYFMT "%.24s %d %15s %10llu %8u\n"
-
-#define PLAINFMT "%12u %d %15s %10llu %8u\n"
-
#define HTMLHDR \
"<html>\n" \
"<head>\n" \
@@ -297,10 +293,6 @@
"</table>\n" \
"</body></html>\n"
-#define HTMLFMT \
- "<tr><td>%d</td><td><a href=%s target=_new>%15s</a></td>" \
- "<td>%.2f%c</td><td>%.2f%c</td></tr>\n"
-
#define SIDEBOXTITLE \
"<table class=netview>\n" \
" <tr class=nvtitle>\n" \
@@ -310,6 +302,12 @@
" <td>pps</td>\n" \
" </tr>\n"
+static char prettyfmt[] = "%.24s %d %15s %10llu %8u\n";
+static char plainfmt[] = "%12u %d %15s %10llu %8u\n";
+static char htmlfmt[] =
+ "<tr><td>%d</td><td><a href=%s target=_new>%15s</a></td>"
+ "<td>%.2f%c</td><td>%.2f%c</td></tr>\n";
+
static char *
print(void * self, char *buf, size_t *len, char * const args[])
{
@@ -332,22 +330,22 @@
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR, what[config->use_dst]);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAINFMT;
+ fmt = plainfmt;
} else if (!strcmp(args[n], "format=html")) {
*len = sprintf(s, HTMLHDR);
*len += sprintf(s + *len, HTMLTITLE, config->topn,
what[config->use_dst]);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
} else if (!strcmp(args[n], "format=sidebox")) {
*len = sprintf(s, HTMLHDR);
*len += sprintf(s + *len, SIDEBOXTITLE);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
} else if (!strncmp(args[n], "url=", 4)) {
url = args[n] + 4;
} else if (!strncmp(args[n], "urlargs=", 8)) {
@@ -371,7 +369,7 @@
if (buf == NULL && args == NULL) {
*len = 0;
- if (fmt == HTMLFMT)
+ if (fmt == htmlfmt)
*len = sprintf(s, HTMLFOOTER);
count = 0; /* reset count */
last_ts = 0; /* reset timestamp */
@@ -389,10 +387,10 @@
addr.s_addr = x->addr & htonl(config->mask);
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, fmt, asctime(localtime(&ts)), count, inet_ntoa(addr),
NTOHLL(x->bytes), ntohl(x->pkts));
- } else if (fmt == HTMLFMT) {
+ } else if (fmt == htmlfmt) {
float bps, pps;
char bunit = ' ';
char punit = ' ';
Modified: src/trunk/modules/tophwaddr.c
===================================================================
--- src/trunk/modules/tophwaddr.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/tophwaddr.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -261,10 +261,6 @@
#define PRETTYHDR \
"Date %-15s Bytes Packets \n"
-#define PRETTYFMT "%.24s %d %15s %10llu %8u\n"
-
-#define PLAINFMT "%12u %d %15s %10llu %8u\n"
-
#define HTMLHDR \
"<html>\n" \
"<head>\n" \
@@ -303,10 +299,6 @@
"</table>\n" \
"</body></html>\n"
-#define HTMLFMT \
- "<tr><td>%d</td><td><a href=%s target=_new>%15s</a></td>" \
- "<td>%.2f%c</td><td>%.2f%c</td></tr>\n"
-
#define SIDEBOXTITLE \
"<table class=netview>\n" \
" <tr class=nvtitle>\n" \
@@ -316,6 +308,13 @@
" <td>pps</td>\n" \
" </tr>\n"
+static char prettyfmt[] = "%.24s %d %15s %10llu %8u\n";
+static char plainfmt[] = "%12u %d %15s %10llu %8u\n";
+static char htmlfmt[] =
+ "<tr><td>%d</td><td><a href=%s target=_new>%15s</a></td>"
+ "<td>%.2f%c</td><td>%.2f%c</td></tr>\n";
+
+
static char *
print(void * self, char *buf, size_t *len, char * const args[])
{
@@ -337,22 +336,22 @@
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR, what[config->use_dst]);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAINFMT;
+ fmt = plainfmt;
} else if (!strcmp(args[n], "format=html")) {
*len = sprintf(s, HTMLHDR);
*len += sprintf(s + *len, HTMLTITLE, config->topn,
what[config->use_dst]);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
} else if (!strcmp(args[n], "format=sidebox")) {
*len = sprintf(s, HTMLHDR);
*len += sprintf(s + *len, SIDEBOXTITLE);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
} else if (!strncmp(args[n], "url=", 4)) {
url = args[n] + 4;
} else if (!strncmp(args[n], "urlargs=", 8)) {
@@ -376,7 +375,7 @@
if (buf == NULL && args == NULL) {
*len = 0;
- if (fmt == HTMLFMT)
+ if (fmt == htmlfmt)
*len = sprintf(s, HTMLFOOTER);
count = 0; /* reset count */
last_ts = 0; /* reset timestamp */
@@ -392,11 +391,11 @@
last_ts = ts;
count++;
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, fmt, asctime(localtime(&ts)), count,
ether_ntoa((struct ether_addr *) &x->addr),
NTOHLL(x->bytes), ntohl(x->pkts));
- } else if (fmt == HTMLFMT) {
+ } else if (fmt == htmlfmt) {
float bps, pps;
char bunit = ' ';
char punit = ' ';
Modified: src/trunk/modules/topports.c
===================================================================
--- src/trunk/modules/topports.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/topports.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -327,10 +327,6 @@
#define PRETTYHDR \
"Date Port Name Bytes Packets \n"
-#define PRETTYFMT "%.24s %5u/%s %s %10llu %8u\n"
-
-#define PLAINFMT "%u %u %s %s %llu %u\n"
-
#define HTMLHDR \
"<html>\n" \
"<head>\n" \
@@ -375,8 +371,10 @@
"</table>\n" \
"</body></html>\n"
-#define HTMLFMT \
- "<tr><td>%d</td><td>%5u/%s</td><td>%s</td><td>%.2f</td></tr>\n"
+static char prettyfmt[] = "%.24s %5u/%s %s %10llu %8u\n";
+static char plainfmt[] = "%u %u %s %s %llu %u\n";
+static char htmlfmt[] =
+ "<tr><td>%d</td><td>%5u/%s</td><td>%s</td><td>%.2f</td></tr>\n";
static char *
print(void * self, char *buf, size_t *len, char * const args[])
@@ -397,22 +395,22 @@
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
pn = 1;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAINFMT;
+ fmt = plainfmt;
} else if (!strcmp(args[n], "format=html")) {
*len = sprintf(s, HTMLHDR);
*len += sprintf(s + *len, HTMLTITLE, config->topn);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
} else if (!strcmp(args[n], "format=sidebox")) {
*len = sprintf(s, HTMLHDR);
*len += sprintf(s + *len, SIDEBOXHDR);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
}
}
@@ -421,7 +419,7 @@
if (buf == NULL && args == NULL) {
*len = 0;
- if (fmt == HTMLFMT)
+ if (fmt == htmlfmt)
*len = sprintf(s, HTMLFOOTER);
return s;
}
@@ -439,10 +437,10 @@
name = "Unknown";
/* read each field of the record */
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, fmt, asctime(localtime(&ts)),
port, getprotoname(proto), name, bytes, pkts);
- } else if (fmt == HTMLFMT) {
+ } else if (fmt == htmlfmt) {
float mbps = ((float) bytes * 8 / (float) config->meas_ivl) / 1000000;
*len = sprintf(s, fmt, pn, port, getprotoname(proto), name, mbps);
pn++;
Modified: src/trunk/modules/traffic.c
===================================================================
--- src/trunk/modules/traffic.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/traffic.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -153,11 +153,6 @@
#define PRETTYHDR \
"Date Timestamp Input Output\n"
-#define PRETTYFMT "%.24s %12d.%06d %8llu %8u\n"
-#define PLAINFMT "%12ld %16llu %12llu %12u\n"
-
-#define GNUPLOTFMT "%ld %u %u\n"
-
#define GNUPLOTHDR \
"set terminal postscript eps color solid lw 1 \"Helvetica\" 14;" \
"set grid;" \
@@ -174,6 +169,10 @@
#define GNUPLOTFOOTER "e\n"
+static char prettyfmt[] = "%.24s %12d.%06d %8llu %8u\n";
+static char plainfmt[] = "%12ld %16llu %12llu %12u\n";
+static char gnuplotfmt[] = "%ld %u %u\n";
+
static char *
print(void * self, char *buf, size_t *len, char * const args[])
{
@@ -192,15 +191,15 @@
if (buf == NULL && args != NULL) {
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAINFMT;
+ fmt = plainfmt;
} else if (!strcmp(args[n], "format=gnuplot")) {
- fmt = GNUPLOTFMT;
+ fmt = gnuplotfmt;
} else if (!strcmp(args[n], "use-bytes")) {
use_bytes = 1;
} else if (!strncmp(args[n], "granularity=", 10)) {
@@ -213,7 +212,7 @@
}
}
- if (fmt == GNUPLOTFMT) {
+ if (fmt == gnuplotfmt) {
*len = sprintf(s, GNUPLOTHDR, use_bytes? "Mbps" : "packets/sec");
}
@@ -222,7 +221,7 @@
if (buf == NULL && args == NULL) {
*len = 0;
- if (fmt == GNUPLOTFMT)
+ if (fmt == gnuplotfmt)
*len = sprintf(s, GNUPLOTFOOTER);
return s;
}
@@ -244,10 +243,10 @@
count[1] /= granularity;
/* print according to the requested format */
- if (fmt == PRETTYFMT) {
+ if (fmt == prettyfmt) {
*len = sprintf(s, fmt, asctime(localtime(&t)),
TS2SEC(ts), TS2USEC(ts), count[0], count[1]);
- } else if (fmt == GNUPLOTFMT) {
+ } else if (fmt == gnuplotfmt) {
if (use_bytes) {
float mbps_in = 8.0 * (float) count[0] / 1000000.0;
float mbps_out = 8.0 * (float) count[1] / 1000000.0;
Modified: src/trunk/modules/tuple.c
===================================================================
--- src/trunk/modules/tuple.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/tuple.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -341,7 +341,6 @@
return sizeof(FLOWDESC);
}
-#define PLAINFMT "%10u.%06d %3d.%06d %3d %15s %5u %15s %5u %8llu %8llu\n"
#define PRETTYHDR \
"Start " \
@@ -349,8 +348,6 @@
"Proto Source IP:Port Destination IP:Port " \
"Bytes Packets\n"
-#define PRETTYFMT "%s.%06d %3d.%06d %5s %15s %5u %15s %5u %8llu %8llu\n"
-
#define HTMLHDR \
"<html>\n" \
"<head>\n" \
@@ -390,12 +387,15 @@
"</table>\n" \
"</body></html>\n"
-#define HTMLFMT \
- "<tr><td>%s.%06d</td><td>%d.%06d</td><td>%s</td>" \
- "<td>%15s:%u</td><td>%15s:%u</td>" \
- "<td>%llu</td><td>%llu</td></tr>\n"
+static char plainfmt[] =
+ "%10u.%06d %3d.%06d %3d %15s %5u %15s %5u %8llu %8llu\n";
+static char prettyfmt[] =
+ "%s.%06d %3d.%06d %5s %15s %5u %15s %5u %8llu %8llu\n";
+static char htmlfmt[] =
+ "<tr><td>%s.%06d</td><td>%d.%06d</td><td>%s</td>"
+ "<td>%15s:%u</td><td>%15s:%u</td>"
+ "<td>%llu</td><td>%llu</td></tr>\n";
-
static char *
print(void * self, char *buf, size_t *len, char * const args[])
{
@@ -414,16 +414,16 @@
int n;
*len = sprintf(s, PRETTYHDR);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=html")) {
*len = sprintf(s, HTMLHDR);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
} else if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAINFMT;
+ fmt = plainfmt;
}
}
@@ -432,7 +432,7 @@
if (buf == NULL && args == NULL) {
*len = 0;
- if (fmt == HTMLFMT)
+ if (fmt == htmlfmt)
*len = sprintf(s, HTMLFOOTER);
return s;
}
@@ -452,7 +452,7 @@
sprintf(src, "%s", inet_ntoa(saddr));
sprintf(dst, "%s", inet_ntoa(daddr));
- if (fmt == PLAINFMT) {
+ if (fmt == plainfmt) {
*len = sprintf(s, fmt, start_sec, start_usec,
duration_sec, duration_usec, x->proto,
src, (uint) H16(x->src_port),
Modified: src/trunk/modules/unknown-ports.c
===================================================================
--- src/trunk/modules/unknown-ports.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/unknown-ports.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -305,9 +305,6 @@
#define PRETTYHDR \
"Date Port Name Bytes Packets \n"
-#define PRETTYFMT "%5u/%s %8u %5u%c %5u\n"
-#define PLAINFMT "%u/%s %u %u%c %u\n"
-
#define HTMLHDR \
"<html>\n" \
"<head>\n" \
@@ -346,8 +343,10 @@
"</table>\n" \
"</body></html>\n"
-#define HTMLFMT \
- "<tr><td>%u/%s</td><td>%u</td><td>%u%c</td><td>%u</td></tr>\n"
+static char prettyfmt[] = "%5u/%s %8u %5u%c %5u\n";
+static char plainfmt[] = "%u/%s %u %u%c %u\n";
+static char htmlfmt[] =
+ "<tr><td>%u/%s</td><td>%u</td><td>%u%c</td><td>%u</td></tr>\n";
static char *
print(void * self, char *buf, size_t *len, char * const args[])
@@ -368,22 +367,22 @@
/* by default, pretty print */
*len = sprintf(s, PRETTYHDR);
- fmt = PRETTYFMT;
+ fmt = prettyfmt;
/* first call of print, process the arguments and return */
for (n = 0; args[n]; n++) {
if (!strcmp(args[n], "format=plain")) {
*len = 0;
- fmt = PLAINFMT;
+ fmt = plainfmt;
} else if (!strcmp(args[n], "format=html")) {
*len = sprintf(s, HTMLHDR);
*len += sprintf(s + *len, HTMLTITLE);
*len += sprintf(s + *len, SIDEBOXHDR);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
} else if (!strcmp(args[n], "format=sidebox")) {
*len = sprintf(s, HTMLHDR);
*len += sprintf(s + *len, SIDEBOXHDR);
- fmt = HTMLFMT;
+ fmt = htmlfmt;
}
}
@@ -391,7 +390,7 @@
}
if (buf == NULL && args == NULL) {
- if (fmt == HTMLFMT)
+ if (fmt == htmlfmt)
*len = sprintf(s, HTMLFOOTER);
return s;
}
@@ -414,9 +413,9 @@
unit = 'K';
}
- if (fmt == PRETTYFMT)
+ if (fmt == prettyfmt)
*len += sprintf(s + *len, "%.24s ", asctime(localtime(&ts)));
- else if (fmt == PLAINFMT)
+ else if (fmt == plainfmt)
*len += sprintf(s + *len, "%u ", (uint) ts);
*len += sprintf(s + *len, fmt, ntohs(tp[i].port),
Modified: src/trunk/modules/worm-signature.c
===================================================================
--- src/trunk/modules/worm-signature.c 2008-07-03 00:08:22 UTC (rev 1261)
+++ src/trunk/modules/worm-signature.c 2008-08-14 22:32:50 UTC (rev 1262)
@@ -557,7 +557,7 @@
int stored;
/* format for print callback */
- char * format;
+ int format;
/* total signatures */
int total_sig;
@@ -1370,10 +1370,10 @@
/* Print MACROS */
-#define DATAHEX "0"
-#define DATABIN "1"
-#define DATASNORT "2"
-#define GNUPLOTFMT "3"
+#define DATAHEX 0
+#define DATABIN 1
+#define DATASNORT 2
+#define GNUPLOTFMT 3
#define GNUPLOTHDR \
"set terminal postscript eps color solid lw 1 \"Helvetica\" 14;" \
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: Josep S. <jsa...@gm...> - 2008-07-07 19:05:11
|
Hi, tv_zero makes select() return immediately, so there is no obvious deadlock possibility here. What makes select() block indefinitely is passing a null timeout value, which is exactly what this commit fixes :) Regards, Josep On Thu, Jul 3, 2008 at 2:23 AM, Marco Canini <mar...@fa...> wrote: > Does using tv_zero here conduce to a deadlock? > > jsa...@us... wrote: >> >> Revision: 1261 >> http://como.svn.sourceforge.net/como/?rev=1261&view=rev >> Author: jsanjuas >> Date: 2008-07-02 17:08:22 -0700 (Wed, 02 Jul 2008) >> >> Log Message: >> ----------- >> fixing previous commit >> >> Modified Paths: >> -------------- >> src/branches/2.0/base/capture.c >> >> Modified: src/branches/2.0/base/capture.c >> =================================================================== >> --- src/branches/2.0/base/capture.c 2008-07-02 22:52:05 UTC (rev 1260) >> +++ src/branches/2.0/base/capture.c 2008-07-03 00:08:22 UTC (rev 1261) >> @@ -1686,6 +1686,7 @@ >> sniffer_t *sniff; >> sniffer_list_t *sniffers; >> int messages_recvd = 0; >> + struct timeval tv_zero = { 0, 0 }; >> log_set_program("CA"); >> @@ -1832,7 +1833,9 @@ >> * if we just received some messages, don't sleep as we want >> * to immediately check if we have more of them. >> */ >> - if (active_sniff > 0 && ! messages_recvd) >> + if (messages_recvd) >> + event_loop_set_timeout(como_ca.el, &tv_zero); >> + else if (active_sniff > 0) >> event_loop_set_timeout(como_ca.el, &timeout); >> #ifdef LOADSHED >> >> >> This was sent by the SourceForge.net collaborative development platform, >> the world's largest Open Source development site. >> >> ------------------------------------------------------------------------- >> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! >> Studies have shown that voting for your favorite open source project, >> along with a healthy diet, reduces your potential for chronic lameness >> and boredom. Vote Now at http://www.sourceforge.net/community/cca08 >> _______________________________________________ >> Como-commits mailing list >> Com...@li... >> https://lists.sourceforge.net/lists/listinfo/como-commits >> > > > -- > Marco Canini > |
|
From: Marco C. <mar...@fa...> - 2008-07-03 09:23:19
|
Does using tv_zero here conduce to a deadlock? jsa...@us... wrote: > Revision: 1261 > http://como.svn.sourceforge.net/como/?rev=1261&view=rev > Author: jsanjuas > Date: 2008-07-02 17:08:22 -0700 (Wed, 02 Jul 2008) > > Log Message: > ----------- > fixing previous commit > > Modified Paths: > -------------- > src/branches/2.0/base/capture.c > > Modified: src/branches/2.0/base/capture.c > =================================================================== > --- src/branches/2.0/base/capture.c 2008-07-02 22:52:05 UTC (rev 1260) > +++ src/branches/2.0/base/capture.c 2008-07-03 00:08:22 UTC (rev 1261) > @@ -1686,6 +1686,7 @@ > sniffer_t *sniff; > sniffer_list_t *sniffers; > int messages_recvd = 0; > + struct timeval tv_zero = { 0, 0 }; > > log_set_program("CA"); > > @@ -1832,7 +1833,9 @@ > * if we just received some messages, don't sleep as we want > * to immediately check if we have more of them. > */ > - if (active_sniff > 0 && ! messages_recvd) > + if (messages_recvd) > + event_loop_set_timeout(como_ca.el, &tv_zero); > + else if (active_sniff > 0) > event_loop_set_timeout(como_ca.el, &timeout); > > #ifdef LOADSHED > > > This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > _______________________________________________ > Como-commits mailing list > Com...@li... > https://lists.sourceforge.net/lists/listinfo/como-commits > -- Marco Canini |
|
From: <jsa...@us...> - 2008-07-03 00:08:24
|
Revision: 1261
http://como.svn.sourceforge.net/como/?rev=1261&view=rev
Author: jsanjuas
Date: 2008-07-02 17:08:22 -0700 (Wed, 02 Jul 2008)
Log Message:
-----------
fixing previous commit
Modified Paths:
--------------
src/branches/2.0/base/capture.c
Modified: src/branches/2.0/base/capture.c
===================================================================
--- src/branches/2.0/base/capture.c 2008-07-02 22:52:05 UTC (rev 1260)
+++ src/branches/2.0/base/capture.c 2008-07-03 00:08:22 UTC (rev 1261)
@@ -1686,6 +1686,7 @@
sniffer_t *sniff;
sniffer_list_t *sniffers;
int messages_recvd = 0;
+ struct timeval tv_zero = { 0, 0 };
log_set_program("CA");
@@ -1832,7 +1833,9 @@
* if we just received some messages, don't sleep as we want
* to immediately check if we have more of them.
*/
- if (active_sniff > 0 && ! messages_recvd)
+ if (messages_recvd)
+ event_loop_set_timeout(como_ca.el, &tv_zero);
+ else if (active_sniff > 0)
event_loop_set_timeout(como_ca.el, &timeout);
#ifdef LOADSHED
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-07-02 22:52:10
|
Revision: 1260
http://como.svn.sourceforge.net/como/?rev=1260&view=rev
Author: jsanjuas
Date: 2008-07-02 15:52:05 -0700 (Wed, 02 Jul 2008)
Log Message:
-----------
capture frees shared memory faster by reading all pending ipc messages at once
Modified Paths:
--------------
src/branches/2.0/base/capture.c
Modified: src/branches/2.0/base/capture.c
===================================================================
--- src/branches/2.0/base/capture.c 2008-06-30 21:00:32 UTC (rev 1259)
+++ src/branches/2.0/base/capture.c 2008-07-02 22:52:05 UTC (rev 1260)
@@ -665,7 +665,6 @@
* we can't use info from como_ca->mdls here, because these tuples
* may come from a module that has been recently removed.
*/
-
t = tuples_first(&msg->tuples);
while (t != NULL) {
t2 = t;
@@ -1686,6 +1685,7 @@
int max_sniffer_id;
sniffer_t *sniff;
sniffer_list_t *sniffers;
+ int messages_recvd = 0;
log_set_program("CA");
@@ -1804,9 +1804,7 @@
int n_ready, max_fd;
batch_t *batch;
- int active_sniff;
- int i;
- int touched;
+ int active_sniff, i, touched;
capture_profiler_notify(CP_START_SNIFFERS);
@@ -1829,9 +1827,13 @@
capture_profiler_notify(CP_END_SNIFFERS);
capture_profiler_notify(CP_START_SELECT);
- /* wait for messages, sniffers or up to the polling interval */
- if (active_sniff > 0)
- event_loop_set_timeout(como_ca.el, &timeout);
+ /*
+ * wait for messages, sniffers or up to the polling interval.
+ * if we just received some messages, don't sleep as we want
+ * to immediately check if we have more of them.
+ */
+ if (active_sniff > 0 && ! messages_recvd)
+ event_loop_set_timeout(como_ca.el, &timeout);
#ifdef LOADSHED
ls_select_start(&como_ca);
@@ -1849,6 +1851,8 @@
profiler_start_tsctimer(como_stats->ca_loop_timer);
+ messages_recvd = 0;
+
for (i = 0; n_ready > 0 && i < max_fd; i++) {
if (!FD_ISSET(i, &r))
@@ -1864,6 +1868,7 @@
}
n_ready--;
+ messages_recvd = 1;
}
if (FD_ISSET(i, &ipc_fds)) {
@@ -1882,12 +1887,16 @@
}
n_ready--;
+ messages_recvd = 1;
}
}
if (como_ca.ready != TRUE)
continue; /* don't go any further until ready */
+ if (messages_recvd)
+ continue; /* try to get more messages before advancing */
+
/* check resources usage occupied by capture clients */
if (s_cabuf.clients_count > 0) {
wait_for_clients = cabuf_cl_res_mgmt(wait_for_clients,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-06-30 21:00:39
|
Revision: 1259
http://como.svn.sourceforge.net/como/?rev=1259&view=rev
Author: jsanjuas
Date: 2008-06-30 14:00:32 -0700 (Mon, 30 Jun 2008)
Log Message:
-----------
fix to apps module
Modified Paths:
--------------
src/branches/2.0/modules/apps/data.h
Modified: src/branches/2.0/modules/apps/data.h
===================================================================
--- src/branches/2.0/modules/apps/data.h 2008-06-06 23:52:07 UTC (rev 1258)
+++ src/branches/2.0/modules/apps/data.h 2008-06-30 21:00:32 UTC (rev 1259)
@@ -36,14 +36,14 @@
#define PORT_MAX 65536
como_tuple struct apps_tuple {
- double bytes[PORT_MAX];
- double pkts[PORT_MAX];
+ double bytes[CLASSES_MAX];
+ double pkts[CLASSES_MAX];
};
como_record struct apps_record {
timestamp_t ts;
- uint32_t bytes[PORT_MAX];
- uint64_t pkts[PORT_MAX];
+ uint32_t bytes[CLASSES_MAX];
+ uint64_t pkts[CLASSES_MAX];
};
como_config struct apps_config {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-06-06 23:52:17
|
Revision: 1258
http://como.svn.sourceforge.net/como/?rev=1258&view=rev
Author: jsanjuas
Date: 2008-06-06 16:52:07 -0700 (Fri, 06 Jun 2008)
Log Message:
-----------
renaming como.c to util-safe.c
Modified Paths:
--------------
src/branches/2.0/base/CMakeLists.txt
Added Paths:
-----------
src/branches/2.0/base/util-safe.c
Removed Paths:
-------------
src/branches/2.0/base/como.c
Modified: src/branches/2.0/base/CMakeLists.txt
===================================================================
--- src/branches/2.0/base/CMakeLists.txt 2008-06-06 23:04:57 UTC (rev 1257)
+++ src/branches/2.0/base/CMakeLists.txt 2008-06-06 23:52:07 UTC (rev 1258)
@@ -12,7 +12,6 @@
array.c
asn.c
capture.c
- como.c
config.c
eventloop.c
export.c
@@ -40,6 +39,7 @@
supervisor.c
util-io.c
util-process.c
+ util-safe.c
util-timers.c
${COMO_SOURCE_DIR}/lib/uhash.c
${COMO_SOURCE_DIR}/lib/flowtable.c
Deleted: src/branches/2.0/base/como.c
===================================================================
--- src/branches/2.0/base/como.c 2008-06-06 23:04:57 UTC (rev 1257)
+++ src/branches/2.0/base/como.c 2008-06-06 23:52:07 UTC (rev 1258)
@@ -1,223 +0,0 @@
-/*
- * Copyright (c) 2004-2006, Intel Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the distribution.
- * * Neither the name of Intel Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id:como.c 1032 2006-11-14 13:29:01Z m_canini $
- */
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <string.h> /* strlen strcpy strncat memset */
-
-/* Required for symlink deletion */
-#include <errno.h>
-#include <signal.h> // signal...
-#include <unistd.h>
-
-#include "como.h"
-#include "comopriv.h"
-#include "storage.h" // mainloop
-#include "ipc.h" // ipc_listen()
-
-
-/**
- * -- safe__malloc
- *
- * Not to be called directly, but through safe_malloc()
- *
- * simple wrapper to malloc that handles errors
- * and returns only if the malloc call succeded. it
- * forces a termination, otherwise.
- *
- */
-void *
-safe__malloc(size_t sz, const char * file, int line)
-{
- void * v;
-
- v = malloc(sz);
- if (v == NULL) {
- error("malloc failed: %u bytes (%s:%d): %s\n",
- sz, file, line, strerror(errno));
- }
-
- return v;
-}
-
-
-/**
- * -- safe__calloc
- *
- * Not to be called directly, but through safe_calloc()
- *
- * simple interface to calloc that handles errors
- * and returns only if the calloc call succeded. it
- * forces a termination, otherwise.
- *
- */
-void *
-safe__calloc(size_t n, size_t sz, const char * file, int line)
-{
- void * v;
-
- v = calloc(n, sz);
- if (v == NULL) {
- error("calloc failed: %u * %u bytes (%s:%d): %s\n",
- n, sz, file, line, strerror(errno));
- }
-
- return v;
-}
-
-
-/**
- * -- safe__realloc
- *
- * Not to be called directly, but through safe_realloc()
- *
- * simple interface to realloc that handles errors
- * and returns only if the realloc call succeded. it
- * forces a termination, otherwise.
- *
- */
-void *
-safe__realloc(void * ptr, size_t sz, const char * file, const int line)
-{
- void * v;
-
- v = realloc(ptr, sz);
- if (v == NULL) {
- error("realloc failed: %u bytes (%s:%d): %s\n",
- sz, file, line, strerror(errno));
- }
-
- return v;
-}
-
-
-/**
- * -- safe__strdup
- *
- * Not to be called directly, but through safe_strdup()
- *
- * simple interface to strdup() that handles errors
- * and returns only if the call succeded. it
- * forces a termination, otherwise.
- *
- */
-char *
-safe__strdup(const char * str, const char * file, const int line)
-{
- char * v;
-
- if (str == NULL)
- return NULL;
-
- v = strdup(str);
- if (v == NULL) {
- error("strdup failed (%s:%d): %s\n",
- file, line, strerror(errno));
- }
-
- return v;
-}
-
-
-/*
- * -- safe__freedup
- *
- * Not to be called directly, but through safe_freedup()
- *
- * Makes a malloc'ed copy of src into *dst,
- * freeing the previous one if any
- */
-char *
-safe__freedup(char **dst, char *src, const char * file, const int line)
-{
- if (*dst)
- free(*dst);
- *dst = safe__strdup(src, file, line);
- return *dst;
-}
-
-
-int
-safe__fileno(FILE *stream, const char *file, const int line)
-{
- int i = fileno(stream);
- if (i < 1)
- error("fileno failed (%s:%d): %s\n",
- file, line, strerror(errno));
- if (fflush(stream) < 0) /* user will be using the fd, so first flush */
- error("fileno failed (%s:%d) - can't flush stream: %s\n",
- file, line, strerror(errno));
- return i;
-}
-
-
-char *
-safe__asprintf(const char * file, const int line, char *fmt, ...)
-{
- char *str;
- va_list ap;
- va_start(ap, fmt);
- vasprintf(&str, fmt, ap);
- if (str == NULL) {
- error("vasprintf failed (%s:%d): %s\n",
- file, line, strerror(errno));
- }
- va_end(ap);
- return str;
-}
-
-char *
-como_basename(const char * path)
-{
- return basename(path); /* GNU version of basename */
-}
-
-
-alc_t *
-como_alc()
-{
- static alc_t alc = {
- malloc: (alc_malloc_fn) safe__malloc,
- calloc: (alc_calloc_fn) safe__calloc,
- free: (alc_free_fn) free,
- data: NULL
- };
-
- return &alc;
-}
-
Copied: src/branches/2.0/base/util-safe.c (from rev 1256, src/branches/2.0/base/como.c)
===================================================================
--- src/branches/2.0/base/util-safe.c (rev 0)
+++ src/branches/2.0/base/util-safe.c 2008-06-06 23:52:07 UTC (rev 1258)
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2004-2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id:como.c 1032 2006-11-14 13:29:01Z m_canini $
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <string.h> /* strlen strcpy strncat memset */
+
+/* Required for symlink deletion */
+#include <errno.h>
+#include <signal.h> // signal...
+#include <unistd.h>
+
+#include "como.h"
+#include "comopriv.h"
+#include "storage.h" // mainloop
+#include "ipc.h" // ipc_listen()
+
+
+/**
+ * -- safe__malloc
+ *
+ * Not to be called directly, but through safe_malloc()
+ *
+ * simple wrapper to malloc that handles errors
+ * and returns only if the malloc call succeded. it
+ * forces a termination, otherwise.
+ *
+ */
+void *
+safe__malloc(size_t sz, const char * file, int line)
+{
+ void * v;
+
+ v = malloc(sz);
+ if (v == NULL) {
+ error("malloc failed: %u bytes (%s:%d): %s\n",
+ sz, file, line, strerror(errno));
+ }
+
+ return v;
+}
+
+
+/**
+ * -- safe__calloc
+ *
+ * Not to be called directly, but through safe_calloc()
+ *
+ * simple interface to calloc that handles errors
+ * and returns only if the calloc call succeded. it
+ * forces a termination, otherwise.
+ *
+ */
+void *
+safe__calloc(size_t n, size_t sz, const char * file, int line)
+{
+ void * v;
+
+ v = calloc(n, sz);
+ if (v == NULL) {
+ error("calloc failed: %u * %u bytes (%s:%d): %s\n",
+ n, sz, file, line, strerror(errno));
+ }
+
+ return v;
+}
+
+
+/**
+ * -- safe__realloc
+ *
+ * Not to be called directly, but through safe_realloc()
+ *
+ * simple interface to realloc that handles errors
+ * and returns only if the realloc call succeded. it
+ * forces a termination, otherwise.
+ *
+ */
+void *
+safe__realloc(void * ptr, size_t sz, const char * file, const int line)
+{
+ void * v;
+
+ v = realloc(ptr, sz);
+ if (v == NULL) {
+ error("realloc failed: %u bytes (%s:%d): %s\n",
+ sz, file, line, strerror(errno));
+ }
+
+ return v;
+}
+
+
+/**
+ * -- safe__strdup
+ *
+ * Not to be called directly, but through safe_strdup()
+ *
+ * simple interface to strdup() that handles errors
+ * and returns only if the call succeded. it
+ * forces a termination, otherwise.
+ *
+ */
+char *
+safe__strdup(const char * str, const char * file, const int line)
+{
+ char * v;
+
+ if (str == NULL)
+ return NULL;
+
+ v = strdup(str);
+ if (v == NULL) {
+ error("strdup failed (%s:%d): %s\n",
+ file, line, strerror(errno));
+ }
+
+ return v;
+}
+
+
+/*
+ * -- safe__freedup
+ *
+ * Not to be called directly, but through safe_freedup()
+ *
+ * Makes a malloc'ed copy of src into *dst,
+ * freeing the previous one if any
+ */
+char *
+safe__freedup(char **dst, char *src, const char * file, const int line)
+{
+ if (*dst)
+ free(*dst);
+ *dst = safe__strdup(src, file, line);
+ return *dst;
+}
+
+
+int
+safe__fileno(FILE *stream, const char *file, const int line)
+{
+ int i = fileno(stream);
+ if (i < 1)
+ error("fileno failed (%s:%d): %s\n",
+ file, line, strerror(errno));
+ if (fflush(stream) < 0) /* user will be using the fd, so first flush */
+ error("fileno failed (%s:%d) - can't flush stream: %s\n",
+ file, line, strerror(errno));
+ return i;
+}
+
+
+char *
+safe__asprintf(const char * file, const int line, char *fmt, ...)
+{
+ char *str;
+ va_list ap;
+ va_start(ap, fmt);
+ vasprintf(&str, fmt, ap);
+ if (str == NULL) {
+ error("vasprintf failed (%s:%d): %s\n",
+ file, line, strerror(errno));
+ }
+ va_end(ap);
+ return str;
+}
+
+char *
+como_basename(const char * path)
+{
+ return basename(path); /* GNU version of basename */
+}
+
+
+alc_t *
+como_alc()
+{
+ static alc_t alc = {
+ malloc: (alc_malloc_fn) safe__malloc,
+ calloc: (alc_calloc_fn) safe__calloc,
+ free: (alc_free_fn) free,
+ data: NULL
+ };
+
+ return &alc;
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-06-06 23:04:59
|
Revision: 1257
http://como.svn.sourceforge.net/como/?rev=1257&view=rev
Author: jsanjuas
Date: 2008-06-06 16:04:57 -0700 (Fri, 06 Jun 2008)
Log Message:
-----------
. Created a signal handler that just calls exit (using exit as a signal handler may result in awkward exit codes.)
. Removed prototype for spawn_child
. Fix to storage that registered sighandlers twice.
Modified Paths:
--------------
src/branches/2.0/base/capture.c
src/branches/2.0/base/export.c
src/branches/2.0/base/storage.c
src/branches/2.0/base/supervisor.c
src/branches/2.0/base/util-process.c
src/branches/2.0/include/comopriv.h
Modified: src/branches/2.0/base/capture.c
===================================================================
--- src/branches/2.0/base/capture.c 2008-06-06 22:37:57 UTC (rev 1256)
+++ src/branches/2.0/base/capture.c 2008-06-06 23:04:57 UTC (rev 1257)
@@ -1701,8 +1701,8 @@
/* register handlers for signals */
signal(SIGPIPE, SIG_IGN);
- signal(SIGINT, exit);
- signal(SIGTERM, exit);
+ signal(SIGINT, sighdlr_exit);
+ signal(SIGTERM, sighdlr_exit);
signal(SIGHUP, SIG_IGN);
atexit(cleanup);
Modified: src/branches/2.0/base/export.c
===================================================================
--- src/branches/2.0/base/export.c 2008-06-06 22:37:57 UTC (rev 1256)
+++ src/branches/2.0/base/export.c 2008-06-06 23:04:57 UTC (rev 1257)
@@ -483,7 +483,6 @@
return IPC_OK;
}
-
/*
* -- export_main
*
@@ -519,9 +518,9 @@
#endif
/* register handlers for signals */
- signal(SIGPIPE, exit);
- signal(SIGINT, exit);
- signal(SIGTERM, exit);
+ signal(SIGPIPE, sighdlr_exit);
+ signal(SIGINT, sighdlr_exit);
+ signal(SIGTERM, sighdlr_exit);
signal(SIGHUP, SIG_IGN); /* ignore SIGHUP */
/* register handlers for IPC messages */
Modified: src/branches/2.0/base/storage.c
===================================================================
--- src/branches/2.0/base/storage.c 2008-06-06 22:37:57 UTC (rev 1256)
+++ src/branches/2.0/base/storage.c 2008-06-06 23:04:57 UTC (rev 1257)
@@ -1801,9 +1801,9 @@
log_set_program("ST");
/* register handlers for signals */
- signal(SIGPIPE, exit);
- signal(SIGINT, exit);
- signal(SIGTERM, exit);
+ signal(SIGPIPE, sighdlr_exit);
+ signal(SIGINT, sighdlr_exit);
+ signal(SIGTERM, sighdlr_exit);
signal(SIGHUP, SIG_IGN); /* ignore SIGHUP */
if (como_config->inline_mode)
@@ -1823,12 +1823,6 @@
/* if needed, wait for debugger */
DEBUGGER_WAIT_ATTACH("st");
- /* register handlers for signals */
- signal(SIGPIPE, exit);
- signal(SIGINT, exit);
- signal(SIGTERM, exit);
- signal(SIGHUP, SIG_IGN); /* ignore SIGHUP */
-
/* run */
como_st_run();
Modified: src/branches/2.0/base/supervisor.c
===================================================================
--- src/branches/2.0/base/supervisor.c 2008-06-06 22:37:57 UTC (rev 1256)
+++ src/branches/2.0/base/supervisor.c 2008-06-06 23:04:57 UTC (rev 1257)
@@ -651,8 +651,8 @@
memmap_stats_t *mem_stats;
/* catch some signals */
- signal(SIGINT, exit); /* catch SIGINT to clean up */
- signal(SIGTERM, exit); /* catch SIGTERM to clean up */
+ signal(SIGINT, sighdlr_exit); /* catch SIGINT to clean up */
+ signal(SIGTERM, sighdlr_exit); /* catch SIGTERM to clean up */
signal(SIGCHLD, defchld); /* catch SIGCHLD (defunct children) */
signal(SIGHUP, set_reconfigure_flag); /* catch SIGHUP to update cfg */
Modified: src/branches/2.0/base/util-process.c
===================================================================
--- src/branches/2.0/base/util-process.c 2008-06-06 22:37:57 UTC (rev 1256)
+++ src/branches/2.0/base/util-process.c 2008-06-06 23:04:57 UTC (rev 1257)
@@ -222,4 +222,14 @@
return 1;
}
+/*
+ * -- sighdlr_exit
+ *
+ * Signal handler that just calls exit.
+ */
+void
+sighdlr_exit(UNUSED int i)
+{
+ exit(0);
+}
Modified: src/branches/2.0/include/comopriv.h
===================================================================
--- src/branches/2.0/include/comopriv.h 2008-06-06 22:37:57 UTC (rev 1256)
+++ src/branches/2.0/include/comopriv.h 2008-06-06 23:04:57 UTC (rev 1257)
@@ -199,8 +199,7 @@
pid_t start_child (ipc_peer_full_t * child, mainloop_fn mainloop,
memmap_t * shmemmap, FILE *client_stream, como_node_t * node);
int handle_children ();
-pid_t spawn_child (ipc_peer_full_t * child, const char *descr,
- const char * path, ...);
+void sighdlr_exit(int);
#define GR_LOSTSYNC ((void *) -1)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-06-06 22:37:58
|
Revision: 1256
http://como.svn.sourceforge.net/como/?rev=1256&view=rev
Author: jsanjuas
Date: 2008-06-06 15:37:57 -0700 (Fri, 06 Jun 2008)
Log Message:
-----------
removing some unnecessary code or code fragmentation
Modified Paths:
--------------
src/branches/2.0/base/como.c
src/branches/2.0/base/supervisor.c
src/branches/2.0/base/util-process.c
Modified: src/branches/2.0/base/como.c
===================================================================
--- src/branches/2.0/base/como.c 2008-06-06 19:46:06 UTC (rev 1255)
+++ src/branches/2.0/base/como.c 2008-06-06 22:37:57 UTC (rev 1256)
@@ -51,33 +51,6 @@
#include "ipc.h" // ipc_listen()
-ipc_peer_full_t *COMO_SU;
-ipc_peer_full_t *COMO_CA;
-ipc_peer_full_t *COMO_EX;
-ipc_peer_full_t *COMO_ST;
-ipc_peer_full_t *COMO_QU;
-
-
-void
-como_init(const char * program, int argc, char ** argv)
-{
- log_set_program(program);
- if (!isatty(fileno(stderr))) {
- log_set_use_color(FALSE);
- }
-
-#if defined(linux) || defined(__APPLE__)
- /* linux/Mac OS X does not support setproctitle. we have our own. */
- setproctitle_init(argc, argv);
-#endif
-
- COMO_SU = ipc_peer_new(COMO_SU_CLASS, "su", "SUPERVISOR");
- COMO_CA = ipc_peer_new(COMO_CA_CLASS, "ca", "CAPTURE");
- COMO_EX = ipc_peer_new(COMO_EX_CLASS, "ex", "EXPORT");
- COMO_ST = ipc_peer_new(COMO_ST_CLASS, "st", "STORAGE");
- COMO_QU = ipc_peer_new(COMO_QU_CLASS, "qu", "QUERY");
-}
-
/**
* -- safe__malloc
*
Modified: src/branches/2.0/base/supervisor.c
===================================================================
--- src/branches/2.0/base/supervisor.c 2008-06-06 19:46:06 UTC (rev 1255)
+++ src/branches/2.0/base/supervisor.c 2008-06-06 22:37:57 UTC (rev 1256)
@@ -61,6 +61,12 @@
int s_saved_argc;
char **s_saved_argv;
+ipc_peer_full_t *COMO_SU;
+ipc_peer_full_t *COMO_CA;
+ipc_peer_full_t *COMO_EX;
+ipc_peer_full_t *COMO_ST;
+ipc_peer_full_t *COMO_QU;
+
/*
* -- launch_inline_query
*
@@ -963,12 +969,25 @@
pid_t pid;
int i;
+ log_set_program("SU");
+ if (!isatty(fileno(stderr)))
+ log_set_use_color(FALSE);
+
+#if defined(linux) || defined(__APPLE__)
+ /* linux/Mac OS X does not support setproctitle. we have our own. */
+ setproctitle_init(argc, argv);
+#endif
+
+ COMO_SU = ipc_peer_new(COMO_SU_CLASS, "su", "SUPERVISOR");
+ COMO_CA = ipc_peer_new(COMO_CA_CLASS, "ca", "CAPTURE");
+ COMO_EX = ipc_peer_new(COMO_EX_CLASS, "ex", "EXPORT");
+ COMO_ST = ipc_peer_new(COMO_ST_CLASS, "st", "STORAGE");
+ COMO_QU = ipc_peer_new(COMO_QU_CLASS, "qu", "QUERY");
+
como_su = safe_malloc(sizeof(como_su_t));
como_su->su_pid = getpid();
como_su->workdir = mkdtemp(strdup("/tmp/comoXXXXXX"));
s_como_su = como_su;
-
- como_init("SU", argc, argv);
/*
* parse command line and configuration files
Modified: src/branches/2.0/base/util-process.c
===================================================================
--- src/branches/2.0/base/util-process.c 2008-06-06 19:46:06 UTC (rev 1255)
+++ src/branches/2.0/base/util-process.c 2008-06-06 22:37:57 UTC (rev 1256)
@@ -223,75 +223,3 @@
}
-pid_t
-spawn_child(ipc_peer_full_t * child, const char * descr, const char * path, ...)
-{
- pid_t pid;
- va_list va;
- int argc = 1;
- const char *arg;
- int i, p[2];
- char c;
-
- va_start(va, path);
- arg = va_arg(va, const char *);
- while (arg != NULL) {
- arg = va_arg(va, const char *);
- argc++;
- }
- va_end(va);
-
- /*
- * set a pipe which will be used to tell child it may start.
- * this avoids a race condition when the child exists before
- * SU has registered it.
- */
- pipe(p);
-
- debug("spawn_child -- forking\n");
- pid = fork();
- if (pid == -1) { /* fork() failure */
- warn("fork() failed: %s\n", strerror(errno));
- close(p[0]);
- close(p[1]);
- return -1;
- }
- else if (pid == 0) { /* child process */
- char * argv[argc + 1];
-
- close(p[1]);
-
- debug("child: waiting for start signal\n");
- como_read(p[0], &c, 1);
- close(p[0]);
- debug("child: starting\n");
-
- argv[0] = (char *)path;
- i = 1;
- va_start(va, path);
- while (i < argc) {
- argv[i] = va_arg(va, char *);
- i++;
- }
- va_end(va);
- argv[i] = NULL;
-
- i = execv(path, argv);
- assert(i == -1);
- error("Can't execute %s at %s: %s\n", descr, path, strerror(errno));
- }
-
- close(p[0]);
-
- i = s_children;
- s_child_info[i].who = child;
- s_child_info[i].pid = pid;
- s_children++;
-
- como_write(p[1], &c, 1); /* child registered, may start */
- close(p[1]);
-
- return pid;
-}
-
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-06-06 19:46:16
|
Revision: 1255
http://como.svn.sourceforge.net/como/?rev=1255&view=rev
Author: jsanjuas
Date: 2008-06-06 12:46:06 -0700 (Fri, 06 Jun 2008)
Log Message:
-----------
merged shmem_create into supervisor and removed unused code.
Modified Paths:
--------------
src/branches/2.0/base/CMakeLists.txt
src/branches/2.0/base/shmem.c
src/branches/2.0/base/supervisor.c
src/branches/2.0/include/como.h
src/branches/2.0/include/comopriv.h
Removed Paths:
-------------
src/branches/2.0/include/shmem.h
Modified: src/branches/2.0/base/CMakeLists.txt
===================================================================
--- src/branches/2.0/base/CMakeLists.txt 2008-06-04 23:32:23 UTC (rev 1254)
+++ src/branches/2.0/base/CMakeLists.txt 2008-06-06 19:46:06 UTC (rev 1255)
@@ -32,7 +32,6 @@
radio.c
services.c
setproctitle.c
- shmem.c
shobj.c
sniffers.c
socket.c
Modified: src/branches/2.0/base/shmem.c
===================================================================
--- src/branches/2.0/base/shmem.c 2008-06-04 23:32:23 UTC (rev 1254)
+++ src/branches/2.0/base/shmem.c 2008-06-06 19:46:06 UTC (rev 1255)
@@ -62,278 +62,9 @@
#ifndef MAP_NOSYNC
#define MAP_NOSYNC 0
#endif
-#ifndef SHM_R
-#define SHM_R 0400
-#endif
-#ifndef SHM_W
-#define SHM_W 0200
-#endif
/* Not all systems seem to have MAP_FAILED defined, but it should always
* just be (void *)-1. */
#ifndef MAP_FAILED
#define MAP_FAILED ((void *)-1)
#endif
-
-struct shmem {
- void * base; /* base real address */
- void * usable; /* base usable address */
- size_t reqsize; /* requested segment size */
- size_t realsize; /* actual segment size */
- char * filename; /* NULL if anonymous */
- int shmid; /* shmem ID returned from shmget() */
-};
-
-
-shmem_t *
-shmem_create(size_t reqsize, const char * filename)
-{
- shmem_t *new_m;
-
- new_m = como_new0(shmem_t);
- new_m->reqsize = reqsize;
-
- if (filename == NULL) {
- /* Anonymous shared memory */
- new_m->reqsize = reqsize;
- new_m->realsize = reqsize +
- ALIGN_DEFAULT(sizeof(size_t)); /* room for metadata */
- new_m->filename = NULL;
-
- new_m->base = mmap(NULL, new_m->realsize, PROT_READ|PROT_WRITE,
- MAP_ANON|MAP_NOSYNC|MAP_SHARED, -1, 0);
- if (new_m->base == (void *)MAP_FAILED) {
- goto error;
- }
-
- /* store the real size in the metadata */
- *((size_t *) new_m->base) = new_m->realsize;
- /* metadata isn't usable */
- new_m->usable = new_m->base + ALIGN_DEFAULT(sizeof(size_t));
-
- notice("allocated %lu of mapped memory\n", reqsize);
- } else {
- /* Name-based shared memory */
- int fd;
- ssize_t r;
- struct shmid_ds shmbuf;
- key_t shmkey;
-
- new_m->realsize = reqsize;
- new_m->filename = safe_strdup(filename);
-
- fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600);
- if (fd < 0) {
- goto error;
- }
-
- /* ftok() (on solaris at least) requires that the file actually
- * exist before calling ftok(). */
- shmkey = ftok(filename, 1);
- if (shmkey == (key_t)-1) {
- goto error;
- }
-
- new_m->shmid = shmget(shmkey, new_m->realsize,
- SHM_R | SHM_W | IPC_CREAT | IPC_EXCL);
- if (new_m->shmid < 0) {
- goto error;
- }
-
- new_m->base = shmat(new_m->shmid, NULL, 0);
- if (new_m->base == (void *)-1) {
- goto error;
- }
- new_m->usable = new_m->base;
-
- if (shmctl(new_m->shmid, IPC_STAT, &shmbuf) == -1) {
- goto error;
- }
- shmbuf.shm_perm.uid = getuid();
- shmbuf.shm_perm.gid = getgid();
- if (shmctl(new_m->shmid, IPC_SET, &shmbuf) == -1) {
- goto error;
- }
-
- r = write(fd, &reqsize, sizeof(reqsize));
- if (r == -1) {
- goto error;
- }
- r = close(fd);
- if (r == -1) {
- goto error;
- }
- }
-
- return new_m;
-error:
- warn("shmem_create(): %s\n", strerror(errno));
- free(new_m);
- return NULL;
-}
-
-
-int
-shmem_remove(const char * filename)
-{
- int fd;
- key_t shmkey;
- int shmid;
-
- /* Presume that the file already exists; just open for writing */
- fd = open(filename, O_WRONLY);
- if (fd < 0) {
- goto error;
- }
-
- /* ftok() (on solaris at least) requires that the file actually
- * exist before calling ftok(). */
- shmkey = ftok(filename, 1);
- if (shmkey == (key_t)-1) {
- goto error;
- }
-
- close(fd);
- fd = -1;
-
- if ((shmid = shmget(shmkey, 0, SHM_R | SHM_W)) < 0) {
- goto error;
- }
-
- /* Indicate that the segment is to be destroyed as soon
- * as all processes have detached. This also disallows any
- * new attachments to the segment. */
- if (shmctl(shmid, IPC_RMID, NULL) == -1) {
- goto error;
- }
- return unlink(filename);
-
-error:
- debug("shmem_remove(): %s\n", strerror(errno));
- if (fd != -1)
- close(fd);
- /* ensure the file has been removed anyway. */
- unlink(filename);
- return -1;
-}
-
-int
-shmem_destroy(shmem_t * m)
-{
- /* anonymous shared memory */
- if (m->filename == NULL) {
- if (munmap(m->base, m->realsize) == -1) {
- warn("munmap(): %s\n", strerror(errno));
- return -1;
- }
- free(m);
- return 0;
- } else {
- /* name-based shared memory */
- /* Indicate that the segment is to be destroyed as soon
- * as all processes have detached. This also disallows any
- * new attachments to the segment. */
- if (shmctl(m->shmid, IPC_RMID, NULL) == -1) {
- warn("shmctl(): %s\n", strerror(errno));
- return -1;
- }
- if (shmdt(m->base) == -1) {
- warn("shmdt(): %s\n", strerror(errno));
- return -1;
- }
- free(m);
- return unlink(m->filename);
- }
-}
-
-
-shmem_t *
-shmem_attach(const char * filename, void *base_addr)
-{
- shmem_t *new_m;
- int fd; /* file where metadata is stored */
- ssize_t r;
- key_t shmkey;
-
- if (filename == NULL) {
- /* It doesn't make sense to attach to a segment if you don't know
- * the filename. */
- return NULL;
- }
-
- new_m = como_new0(shmem_t);
-
- fd = open(filename, O_RDWR);
- if (fd < 0) {
- goto error;
- }
-
- r = read(fd, &(new_m->reqsize), sizeof(new_m->reqsize));
- if (r == -1) {
- goto error;
- }
- r = close(fd);
- if (r == -1) {
- goto error;
- }
-
- new_m->filename = safe_strdup(filename);
- shmkey = ftok(filename, 1);
- if (shmkey == (key_t)-1) {
- goto error;
- }
-
- new_m->shmid = shmget(shmkey, 0, SHM_R | SHM_W);
- if (new_m->shmid == -1) {
- goto error;
- }
-
- new_m->base = shmat(new_m->shmid, base_addr, 0);
- if (new_m->base == (void *)-1) {
- debug("shmat() error - %s\n", strerror(errno));
- goto error;
- }
-
- new_m->usable = new_m->base;
- new_m->realsize = new_m->reqsize;
-
- return new_m;
-error:
- warn("shmem_attach(): %s\n", strerror(errno));
- free(new_m);
- return NULL;
-}
-
-
-int
-shmem_detach(shmem_t * m)
-{
- /* It doesn't make sense to detach from an anonymous memory segment. */
- if (m->filename != NULL) {
- if (shmdt(m->base) == -1) {
- warn("shmdt(): %s\n", strerror(errno));
- return -1;
- }
- }
-
- return 0;
-}
-
-void *
-shmem_baseaddr(const shmem_t * m)
-{
- return m->usable;
-}
-
-size_t
-shmem_size(const shmem_t * m)
-{
- return m->reqsize;
-}
-
-const char *
-shmem_filename(const shmem_t * m)
-{
- return m->filename;
-}
-
Modified: src/branches/2.0/base/supervisor.c
===================================================================
--- src/branches/2.0/base/supervisor.c 2008-06-04 23:32:23 UTC (rev 1254)
+++ src/branches/2.0/base/supervisor.c 2008-06-06 19:46:06 UTC (rev 1255)
@@ -40,7 +40,9 @@
#include <assert.h>
#include <sys/stat.h> /* mkdir */
#include <sys/types.h> /* mkdir */
+#include <sys/mman.h> /* mmap */
+
#define LOG_DEBUG_DISABLE
#include "como.h"
#include "comopriv.h"
@@ -710,7 +712,7 @@
dd, hh, mm, ss,
(unsigned int)mem_stats->usage/(1024*1024),
(unsigned int)mem_stats->peak/(1024*1024),
- shmem_size(como_su->shmem)/(1024*1024),
+ como_su->shmem_size / (1024 * 1024),
como_stats->table_queue,
como_stats->pkts,
como_stats->drops,
@@ -911,7 +913,38 @@
}
}
+#ifndef MAP_NOSYNC
+#define MAP_NOSYNC 0
+#endif
+/* Not all systems seem to have MAP_FAILED defined, but it should always
+ * just be (void *)-1. */
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
/*
+ * -- shmem_create
+ *
+ * Creates a shared memory region
+ *
+ */
+void *
+shmem_create(size_t size)
+{
+ void *mem;
+
+ mem = mmap(NULL, size, PROT_READ|PROT_WRITE,
+ MAP_ANON|MAP_NOSYNC|MAP_SHARED, -1, 0);
+
+ if (mem == (void *)MAP_FAILED)
+ error("shmem_create(): %s\n", strerror(errno));
+ else
+ notice("allocated %lu of mapped memory\n", size);
+
+ return mem;
+}
+
+/*
* -- main
*
* set up the data structures. basically open the config file,
@@ -975,9 +1008,9 @@
* Initialize the shared memory region.
* CAPTURE and QUERY processes will be able to see it.
*/
- como_su->shmem = shmem_create(como_config->shmem_size, NULL);
- como_su->memmap = memmap_create(shmem_baseaddr(como_su->shmem),
- shmem_size(como_su->shmem), 2048);
+ como_su->shmem_size = como_config->shmem_size;
+ como_su->shmem = shmem_create(como_config->shmem_size);
+ como_su->memmap = memmap_create(como_su->shmem, como_su->shmem_size, 2048);
memmap_alc_init(como_su->memmap, &como_su->shalc);
/* allocate statistics into shared memory */
Modified: src/branches/2.0/include/como.h
===================================================================
--- src/branches/2.0/include/como.h 2008-06-04 23:32:23 UTC (rev 1254)
+++ src/branches/2.0/include/como.h 2008-06-06 19:46:06 UTC (rev 1255)
@@ -76,7 +76,6 @@
#include "comofunc.h"
#include "log.h"
#include "pool.h"
-#include "shmem.h"
#include "module.h"
void setproctitle_init(int argc, char **argv);
Modified: src/branches/2.0/include/comopriv.h
===================================================================
--- src/branches/2.0/include/comopriv.h 2008-06-04 23:32:23 UTC (rev 1254)
+++ src/branches/2.0/include/comopriv.h 2008-06-06 19:46:06 UTC (rev 1255)
@@ -399,8 +399,6 @@
ex_init_fn init;
ex_export_fn export;
- shmem_t * shmem;
-
void * state;
int running_state;
@@ -450,8 +448,10 @@
array_t * nodes; /* node information */
- shmem_t * shmem; /* main shared memory used to store
+ void * shmem; /* main shared memory used to store
capture data structures, stats */
+ size_t shmem_size;
+
memmap_t * memmap;
alc_t shalc;
Deleted: src/branches/2.0/include/shmem.h
===================================================================
--- src/branches/2.0/include/shmem.h 2008-06-04 23:32:23 UTC (rev 1254)
+++ src/branches/2.0/include/shmem.h 2008-06-06 19:46:06 UTC (rev 1255)
@@ -1,17 +0,0 @@
-#ifndef SHMEM_H_
-#define SHMEM_H_
-
-typedef struct shmem shmem_t;
-
-shmem_t * shmem_create (size_t reqsize, const char * filename);
-int shmem_destroy (shmem_t * m);
-shmem_t * shmem_attach (const char * filename, void *base_addr);
-int shmem_detach (shmem_t * m);
-void * shmem_baseaddr (const shmem_t * m);
-size_t shmem_size (const shmem_t * m);
-const char * shmem_filename (const shmem_t * m);
-
-int shmem_remove (const char *filename);
-
-
-#endif /*SHMEM_H_*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-06-04 23:32:27
|
Revision: 1254
http://como.svn.sourceforge.net/como/?rev=1254&view=rev
Author: jsanjuas
Date: 2008-06-04 16:32:23 -0700 (Wed, 04 Jun 2008)
Log Message:
-----------
fixed the readme, updated the todo list, updated some (c) notices.
Modified Paths:
--------------
src/branches/2.0/DESCRIPTION
src/branches/2.0/LICENSE
src/branches/2.0/README
src/branches/2.0/TODO.txt
Modified: src/branches/2.0/DESCRIPTION
===================================================================
--- src/branches/2.0/DESCRIPTION 2008-06-04 23:17:20 UTC (rev 1253)
+++ src/branches/2.0/DESCRIPTION 2008-06-04 23:32:23 UTC (rev 1254)
@@ -28,7 +28,7 @@
. Steven Smith
. Davide Vercelli
-Copyright (c) 2004-2006 Intel Corporation
+Copyright (c) 2004-2008 Intel Corporation
All rights reserved.
NOTES:
Modified: src/branches/2.0/LICENSE
===================================================================
--- src/branches/2.0/LICENSE 2008-06-04 23:17:20 UTC (rev 1253)
+++ src/branches/2.0/LICENSE 2008-06-04 23:32:23 UTC (rev 1254)
@@ -1,4 +1,4 @@
-Copyright (c) 2004-2007, Intel Corporation
+Copyright (c) 2004-2008, Intel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or
Modified: src/branches/2.0/README
===================================================================
--- src/branches/2.0/README 2008-06-04 23:17:20 UTC (rev 1253)
+++ src/branches/2.0/README 2008-06-04 23:32:23 UTC (rev 1254)
@@ -7,33 +7,27 @@
Compiling CoMo
==================
+The CoMo build process is as follows. First, the core system must
+be compiled and installed. Afterwards, the modules can be built
+and installed.
+
CoMo requires CMake 2.2-patch 3 or higher to compile.
Visit http://www.cmake.org to get cmake.
-Use a separate build dir to build CoMo, not the source dir (example below).
-To get debugging, pass -DCMAKE_BUILD_TYPE=debug
-To get release, pass -DCMAKE_BUILD_TYPE=release
-
Short example:
# tar -xvzf como-x.y.tar.gz
-# mkdir build-como
-# cd build-como
-# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/como ../como-x.y
+# cd build-x.y
# make
-
-Installing CoMo
-=================
-
-It is also possible to install the CoMo using:
-
# make install
+# make modules
+# make modules-install
This will install the CoMo binary, the plug-in modules and the man page.
An example configuration file is created in `/usr/local/etc/como/como.conf`.
--------------------------------------------------------------------------
-Copyright (c) 2004-2006 Intel Corporation
+Copyright (c) 2004-2008 Intel Corporation
All rights reserved.
Modified: src/branches/2.0/TODO.txt
===================================================================
--- src/branches/2.0/TODO.txt 2008-06-04 23:17:20 UTC (rev 1253)
+++ src/branches/2.0/TODO.txt 2008-06-04 23:32:23 UTC (rev 1254)
@@ -21,7 +21,6 @@
* Modules:
-autofocus
supersources
multiple pattern search
@@ -29,8 +28,6 @@
* Configuration
- Do more error checking.
- - Fix example.conf
- - argsfile keyword
- specify that a module has to run ondemand
* Features
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-06-04 23:17:23
|
Revision: 1253
http://como.svn.sourceforge.net/como/?rev=1253&view=rev
Author: jsanjuas
Date: 2008-06-04 16:17:20 -0700 (Wed, 04 Jun 2008)
Log Message:
-----------
. storage is forked again instead of exec'ed
. merged libcomo within base (sepparation no longer necessary)
. changed msg()s in storage to debug()s
. storage-path config keyword now unnecessary
Modified Paths:
--------------
src/branches/2.0/CMakeLists.txt
src/branches/2.0/base/CMakeLists.txt
src/branches/2.0/base/config-lexic.l
src/branches/2.0/base/config-syntax.y
src/branches/2.0/base/config.c
src/branches/2.0/base/query-ondemand.c
src/branches/2.0/base/storage.c
src/branches/2.0/base/supervisor.c
src/branches/2.0/como.conf.cmake
src/branches/2.0/include/comopriv.h
src/branches/2.0/include/comotypes.h
Added Paths:
-----------
src/branches/2.0/base/alc.c
src/branches/2.0/base/array.c
src/branches/2.0/base/como.c
src/branches/2.0/base/eventloop.c
src/branches/2.0/base/hash.c
src/branches/2.0/base/ipc.c
src/branches/2.0/base/log.c
src/branches/2.0/base/mdl.c
src/branches/2.0/base/memory.c
src/branches/2.0/base/pool.c
src/branches/2.0/base/setproctitle.c
src/branches/2.0/base/shmem.c
src/branches/2.0/base/shobj.c
src/branches/2.0/base/socket.c
src/branches/2.0/base/storage-client.c
src/branches/2.0/base/util-io.c
Removed Paths:
-------------
src/branches/2.0/libcomo/
Modified: src/branches/2.0/CMakeLists.txt
===================================================================
--- src/branches/2.0/CMakeLists.txt 2008-06-04 21:37:13 UTC (rev 1252)
+++ src/branches/2.0/CMakeLists.txt 2008-06-04 23:17:20 UTC (rev 1253)
@@ -239,7 +239,6 @@
ADD_SUBDIRECTORY(sniffers)
ADD_SUBDIRECTORY(base)
ADD_SUBDIRECTORY(services)
-ADD_SUBDIRECTORY(libcomo)
ADD_SUBDIRECTORY(lib)
#ADD_SUBDIRECTORY(man)
Modified: src/branches/2.0/base/CMakeLists.txt
===================================================================
--- src/branches/2.0/base/CMakeLists.txt 2008-06-04 21:37:13 UTC (rev 1252)
+++ src/branches/2.0/base/CMakeLists.txt 2008-06-04 23:17:20 UTC (rev 1253)
@@ -7,26 +7,39 @@
INCLUDE_DIRECTORIES(${COMO_SOURCE_DIR}/loadshed)
ENDIF(ENABLE_LOADSHED)
-SET(STORAGE_SRCS
- storage.c
-)
-
SET(COMO_SRCS
+ alc.c
+ array.c
asn.c
capture.c
+ como.c
config.c
+ eventloop.c
export.c
+ hash.c
headerinfo.c
ieee80211frames.c
+ ipc.c
+ log.c
+ mdl.c
+ memory.c
metadesc.c
pktmeta.c
- query.c
+ pool.c
query-comms.c
query-ondemand.c
+ query.c
radio.c
services.c
+ setproctitle.c
+ shmem.c
+ shobj.c
sniffers.c
+ socket.c
+ storage-client.c
+ storage.c
supervisor.c
+ util-io.c
util-process.c
util-timers.c
${COMO_SOURCE_DIR}/lib/uhash.c
@@ -182,8 +195,6 @@
#
ADD_EXECUTABLE(como ${COMO_SRCS})
-ADD_EXECUTABLE(como-storage ${STORAGE_SRCS})
-
#
# Make sure modules can see como's symbols
#
@@ -218,11 +229,8 @@
TARGET_LINK_LIBRARIES(como m)
-TARGET_LINK_LIBRARIES(como comolib)
TARGET_LINK_LIBRARIES(como comomdl)
-TARGET_LINK_LIBRARIES(como-storage comolib)
-
IF(LINUX)
TARGET_LINK_LIBRARIES(como dl)
ENDIF(LINUX)
@@ -250,4 +258,4 @@
# Installation
#
INSTALL_TARGETS(${INST_BINDIR} como)
-INSTALL_TARGETS(${INST_BINDIR} como-storage)
+
Copied: src/branches/2.0/base/alc.c (from rev 1249, src/branches/2.0/libcomo/alc.c)
===================================================================
--- src/branches/2.0/base/alc.c (rev 0)
+++ src/branches/2.0/base/alc.c 2008-06-04 23:17:20 UTC (rev 1253)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2004-2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id:como.c 1032 2006-11-14 13:29:01Z m_canini $
+ */
+
+#include <string.h>
+
+#define LOG_DOMAIN "ALC"
+#include "como.h"
+
+char *
+alc_strdup(alc_t * alc, const char * s)
+{
+ char * o;
+
+ size_t l;
+ l = strlen(s);
+ o = alc_malloc(alc, l + 1);
+ strcpy(o, s);
+
+ return o;
+}
Copied: src/branches/2.0/base/array.c (from rev 1250, src/branches/2.0/libcomo/array.c)
===================================================================
--- src/branches/2.0/base/array.c (rev 0)
+++ src/branches/2.0/base/array.c 2008-06-04 23:17:20 UTC (rev 1253)
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+/* Based on eglib's ptr array */
+/*
+ * Pointer Array
+ *
+ * Author:
+ * Aaron Bockover (abo...@no...)
+ *
+ * (C) 2006 Novell, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <string.h>
+
+#include "como.h"
+#include "comopriv.h"
+
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+
+static void
+array_grow(array_t * array, int length)
+{
+ int off = array->data - array->base;
+ int new_length = array->len + length + (off / array->element_size);
+
+ if (new_length <= array->size) {
+ return;
+ }
+
+ array->size = 1;
+
+ while (array->size < new_length) {
+ array->size <<= 1;
+ }
+
+ array->size = MAX(array->size, 16);
+ array->base = safe_realloc(array->base, array->size * array->element_size);
+ array->data = array->base + off;
+}
+
+array_t *
+array_new(size_t element_size)
+{
+ return array_sized_new(element_size, 0);
+}
+
+array_t *
+array_sized_new(size_t element_size, int reserved_size)
+{
+ array_t *array = como_new0(array_t);
+
+ array->element_size = element_size;
+
+ if (reserved_size > 0) {
+ array_grow(array, reserved_size);
+ }
+
+ return (array_t *) array;
+}
+
+void **
+array_free(array_t * array, int free_seg)
+{
+ void **data = NULL;
+
+ if (array == NULL) {
+ return NULL;
+ }
+ if (free_seg) {
+ free(array->base);
+ } else {
+ if (array->data != array->base) {
+ memmove(array->base, array->data,
+ array->len * array->element_size);
+ }
+ data = array->base;
+ }
+
+ free(array);
+
+ return data;
+}
+
+void
+array_add(array_t * array, void *data)
+{
+ void *x;
+ array_grow(array, 1);
+ x = array->data + (array->len * array->element_size);
+ memcpy(x, data, array->element_size);
+ array->len++;
+}
+
+void
+array_sort(array_t * array, cmp_fn cmpFn)
+{
+ qsort(array->data, array->len, array->element_size, cmpFn);
+}
+
+void
+array_clear(array_t * array, int reserved_size, int zero_seg)
+{
+ if (zero_seg) {
+ memset(array->data, 0, array->len * array->element_size);
+ }
+
+ if (reserved_size > array->size) {
+ array_grow(array, reserved_size - array->size);
+ }
+ array->data = array->base;
+ array->len = 0;
+}
+
+void *
+array_shift_(array_t * array)
+{
+ void *x;
+ x = array->data;
+ array->data += array->element_size;
+ array->len--;
+ return x;
+}
+
+void
+array_remove(array_t *array, int position)
+{
+ void *src, *dst;
+ size_t len;
+
+ len = array->element_size * (array->len - position - 1);
+ dst = array->data + (position * array->element_size);
+ src = array->data + ((position + 1) * array->element_size);
+
+ memmove(dst, src, len);
+ array->len--;
+}
+
Copied: src/branches/2.0/base/como.c (from rev 1250, src/branches/2.0/libcomo/como.c)
===================================================================
--- src/branches/2.0/base/como.c (rev 0)
+++ src/branches/2.0/base/como.c 2008-06-04 23:17:20 UTC (rev 1253)
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2004-2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id:como.c 1032 2006-11-14 13:29:01Z m_canini $
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <string.h> /* strlen strcpy strncat memset */
+
+/* Required for symlink deletion */
+#include <errno.h>
+#include <signal.h> // signal...
+#include <unistd.h>
+
+#include "como.h"
+#include "comopriv.h"
+#include "storage.h" // mainloop
+#include "ipc.h" // ipc_listen()
+
+
+ipc_peer_full_t *COMO_SU;
+ipc_peer_full_t *COMO_CA;
+ipc_peer_full_t *COMO_EX;
+ipc_peer_full_t *COMO_ST;
+ipc_peer_full_t *COMO_QU;
+
+
+void
+como_init(const char * program, int argc, char ** argv)
+{
+ log_set_program(program);
+ if (!isatty(fileno(stderr))) {
+ log_set_use_color(FALSE);
+ }
+
+#if defined(linux) || defined(__APPLE__)
+ /* linux/Mac OS X does not support setproctitle. we have our own. */
+ setproctitle_init(argc, argv);
+#endif
+
+ COMO_SU = ipc_peer_new(COMO_SU_CLASS, "su", "SUPERVISOR");
+ COMO_CA = ipc_peer_new(COMO_CA_CLASS, "ca", "CAPTURE");
+ COMO_EX = ipc_peer_new(COMO_EX_CLASS, "ex", "EXPORT");
+ COMO_ST = ipc_peer_new(COMO_ST_CLASS, "st", "STORAGE");
+ COMO_QU = ipc_peer_new(COMO_QU_CLASS, "qu", "QUERY");
+}
+
+/**
+ * -- safe__malloc
+ *
+ * Not to be called directly, but through safe_malloc()
+ *
+ * simple wrapper to malloc that handles errors
+ * and returns only if the malloc call succeded. it
+ * forces a termination, otherwise.
+ *
+ */
+void *
+safe__malloc(size_t sz, const char * file, int line)
+{
+ void * v;
+
+ v = malloc(sz);
+ if (v == NULL) {
+ error("malloc failed: %u bytes (%s:%d): %s\n",
+ sz, file, line, strerror(errno));
+ }
+
+ return v;
+}
+
+
+/**
+ * -- safe__calloc
+ *
+ * Not to be called directly, but through safe_calloc()
+ *
+ * simple interface to calloc that handles errors
+ * and returns only if the calloc call succeded. it
+ * forces a termination, otherwise.
+ *
+ */
+void *
+safe__calloc(size_t n, size_t sz, const char * file, int line)
+{
+ void * v;
+
+ v = calloc(n, sz);
+ if (v == NULL) {
+ error("calloc failed: %u * %u bytes (%s:%d): %s\n",
+ n, sz, file, line, strerror(errno));
+ }
+
+ return v;
+}
+
+
+/**
+ * -- safe__realloc
+ *
+ * Not to be called directly, but through safe_realloc()
+ *
+ * simple interface to realloc that handles errors
+ * and returns only if the realloc call succeded. it
+ * forces a termination, otherwise.
+ *
+ */
+void *
+safe__realloc(void * ptr, size_t sz, const char * file, const int line)
+{
+ void * v;
+
+ v = realloc(ptr, sz);
+ if (v == NULL) {
+ error("realloc failed: %u bytes (%s:%d): %s\n",
+ sz, file, line, strerror(errno));
+ }
+
+ return v;
+}
+
+
+/**
+ * -- safe__strdup
+ *
+ * Not to be called directly, but through safe_strdup()
+ *
+ * simple interface to strdup() that handles errors
+ * and returns only if the call succeded. it
+ * forces a termination, otherwise.
+ *
+ */
+char *
+safe__strdup(const char * str, const char * file, const int line)
+{
+ char * v;
+
+ if (str == NULL)
+ return NULL;
+
+ v = strdup(str);
+ if (v == NULL) {
+ error("strdup failed (%s:%d): %s\n",
+ file, line, strerror(errno));
+ }
+
+ return v;
+}
+
+
+/*
+ * -- safe__freedup
+ *
+ * Not to be called directly, but through safe_freedup()
+ *
+ * Makes a malloc'ed copy of src into *dst,
+ * freeing the previous one if any
+ */
+char *
+safe__freedup(char **dst, char *src, const char * file, const int line)
+{
+ if (*dst)
+ free(*dst);
+ *dst = safe__strdup(src, file, line);
+ return *dst;
+}
+
+
+int
+safe__fileno(FILE *stream, const char *file, const int line)
+{
+ int i = fileno(stream);
+ if (i < 1)
+ error("fileno failed (%s:%d): %s\n",
+ file, line, strerror(errno));
+ if (fflush(stream) < 0) /* user will be using the fd, so first flush */
+ error("fileno failed (%s:%d) - can't flush stream: %s\n",
+ file, line, strerror(errno));
+ return i;
+}
+
+
+char *
+safe__asprintf(const char * file, const int line, char *fmt, ...)
+{
+ char *str;
+ va_list ap;
+ va_start(ap, fmt);
+ vasprintf(&str, fmt, ap);
+ if (str == NULL) {
+ error("vasprintf failed (%s:%d): %s\n",
+ file, line, strerror(errno));
+ }
+ va_end(ap);
+ return str;
+}
+
+char *
+como_basename(const char * path)
+{
+ return basename(path); /* GNU version of basename */
+}
+
+
+alc_t *
+como_alc()
+{
+ static alc_t alc = {
+ malloc: (alc_malloc_fn) safe__malloc,
+ calloc: (alc_calloc_fn) safe__calloc,
+ free: (alc_free_fn) free,
+ data: NULL
+ };
+
+ return &alc;
+}
+
Modified: src/branches/2.0/base/config-lexic.l
===================================================================
--- src/branches/2.0/base/config-lexic.l 2008-06-04 21:37:13 UTC (rev 1252)
+++ src/branches/2.0/base/config-lexic.l 2008-06-04 23:17:20 UTC (rev 1253)
@@ -100,7 +100,6 @@
db-path { dbg_return(TOK_DBPATH); }
librarydir { dbg_return(TOK_LIBDIR); }
-storage-path { dbg_return(TOK_STORAGEPATH); }
memsize { dbg_return(TOK_MEMSIZE); }
query-port { dbg_return(TOK_QUERY_PORT); }
Modified: src/branches/2.0/base/config-syntax.y
===================================================================
--- src/branches/2.0/base/config-syntax.y 2008-06-04 21:37:13 UTC (rev 1252)
+++ src/branches/2.0/base/config-syntax.y 2008-06-04 23:17:20 UTC (rev 1253)
@@ -93,7 +93,7 @@
%token TOK_TYPE TOK_COMMENT TOK_SNIFFER TOK_FILESIZE TOK_MODULE TOK_DESCRIPTION
%token TOK_SOURCE TOK_OUTPUT TOK_FILTER TOK_HASHSIZE TOK_STREAMSIZE TOK_ARGS
%token TOK_ONDEMAND TOK_END TOK_NEWLINE TOK_EQUALS TOK_COMMA
-%token TOK_STORAGEPATH TOK_ASNFILE TOK_SHEDMETHOD TOK_ALIAS TOK_VIRTUAL_NODE
+%token TOK_ASNFILE TOK_SHEDMETHOD TOK_ALIAS TOK_VIRTUAL_NODE
%token TOK_SOURCE_MODULE TOK_MINSRATE TOK_LEFTARROW
%token <string> TOK_STRING
%token <number> TOK_NUMBER
@@ -118,7 +118,6 @@
keyword: /* a global keyword */
TOK_DBPATH TOK_STRING { cfg->db_path = $2; }
| TOK_LIBDIR TOK_STRING { cfg->libdir = $2; }
- | TOK_STORAGEPATH TOK_STRING { cfg->storage_path = $2; }
| TOK_MEMSIZE TOK_NUMBER { set_memsize($2, cfg); }
| TOK_ASNFILE TOK_STRING { cfg->asn_file = $2; }
Modified: src/branches/2.0/base/config.c
===================================================================
--- src/branches/2.0/base/config.c 2008-06-04 21:37:13 UTC (rev 1252)
+++ src/branches/2.0/base/config.c 2008-06-04 23:17:20 UTC (rev 1253)
@@ -458,10 +458,6 @@
break;
}
- case 't': /* path to storage */
- cfg->storage_path = safe_strdup(optarg);
- break;
-
case '?': /* unknown */
error("unrecognized cmdline option (%s)\n\n" USAGE "\n",
argv[optind], argv[0]);
@@ -659,7 +655,6 @@
array_free(cfg->vnode_defs, 1);
free(cfg->como_executable_full_path); /* free strings */
- free(cfg->storage_path);
free(cfg->mono_path);
free(cfg->db_path);
free(cfg->libdir);
Copied: src/branches/2.0/base/eventloop.c (from rev 1252, src/branches/2.0/libcomo/eventloop.c)
===================================================================
--- src/branches/2.0/base/eventloop.c (rev 0)
+++ src/branches/2.0/base/eventloop.c 2008-06-04 23:17:20 UTC (rev 1253)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2004-2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id:eventloop.c 1010 2006-11-13 14:49:11Z m_canini $
+ *
+ */
+
+#include <string.h>
+#include <sys/select.h>
+#include <errno.h>
+
+#include "como.h"
+#include "comopriv.h"
+
+struct event_loop {
+ fd_set fds;
+ int max_fd;
+ struct timeval *timeoutptr;
+ struct timeval timeout;
+};
+
+
+event_loop_t *
+event_loop_new()
+{
+ event_loop_t *el = safe_malloc(sizeof(event_loop_t));
+
+ memset(el, 0, sizeof(event_loop_t));
+ FD_ZERO(&el->fds);
+
+ return el;
+}
+
+
+/*
+ * -- event_loop_add
+ *
+ * add a file descriptor to the interesting range;
+ * return max_fd value or -1 if failed.
+ */
+int
+event_loop_add(event_loop_t * el, int i)
+{
+ if (i < 0)
+ return -1;
+
+ FD_SET(i, &el->fds);
+ el->max_fd = (i >= el->max_fd) ? i + 1 : el->max_fd;
+
+ return el->max_fd;
+}
+
+
+/*
+ * -- event_loop_del
+ *
+ * delete a file descriptor to the interesting range;
+ * return max_fd value or -1 if failed.
+ */
+int
+event_loop_del(event_loop_t * el, int i)
+{
+ if (i < 0)
+ return -1;
+
+ FD_CLR(i, &el->fds);
+ if (i < el->max_fd - 1)
+ return el->max_fd;
+
+ /* we deleted the highest fd, so need to recompute the max */
+ for (i = el->max_fd - 1; i >= 0; i--)
+ if (FD_ISSET(i, &el->fds))
+ break;
+ el->max_fd = i + 1;
+
+ return el->max_fd;
+}
+
+
+
+void
+event_loop_set_timeout(event_loop_t * el, struct timeval * timeout)
+{
+ el->timeout = *timeout;
+ el->timeoutptr = &el->timeout;
+}
+
+
+int
+event_loop_select(event_loop_t * el, fd_set * ready, int * max_fd)
+{
+ int n;
+
+ *ready = el->fds;
+ n = select(el->max_fd, ready, NULL, NULL, el->timeoutptr);
+ if (n < 0 && errno != EINTR) {
+ error("Failed on select(): %s\n", strerror(errno));
+ }
+ el->timeoutptr = NULL;
+ *max_fd = el->max_fd;
+
+ return n;
+}
+
Copied: src/branches/2.0/base/hash.c (from rev 1250, src/branches/2.0/libcomo/hash.c)
===================================================================
--- src/branches/2.0/base/hash.c (rev 0)
+++ src/branches/2.0/base/hash.c 2008-06-04 23:17:20 UTC (rev 1253)
@@ -0,0 +1,1050 @@
+/*
+ * Copyright (c) 2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+/*
+ * This file is derived from Tcl (http://tcl.sourceforge.net/)
+ * which holds the following copyright notice and license:
+ *
+ * This software is copyrighted by the Regents of the University of
+ * California, Sun Microsystems, Inc., Scriptics Corporation, ActiveState
+ * Corporation and other parties. The following terms apply to all files
+ * associated with the software unless explicitly disclaimed in
+ * individual files.
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ *
+ * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
+ * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
+ * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
+ * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
+ * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS.
+ *
+ * GOVERNMENT USE: If you are acquiring this software on behalf of the
+ * U.S. government, the Government shall have only "Restricted Rights"
+ * in the software and related documentation as defined in the Federal
+ * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
+ * are acquiring the software on behalf of the Department of Defense, the
+ * software shall be classified as "Commercial Computer Software" and the
+ * Government shall have only "Restricted Rights" as defined in Clause
+ * 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
+ * authors grant the U.S. Government and others acting in its behalf
+ * permission to use and distribute the software in accordance with the
+ * terms specified in this license.
+ */
+
+/* Portions are:
+ *
+ * Copyright (C) 2002 Red Hat, Inc.
+ * Copyright (c) 1991-1993 The Regents of the University of California.
+ * Copyright (c) 1994 Sun Microsystems, Inc.
+ *
+ * Licensed under the Academic Free License version 2.1
+ */
+
+#include <string.h>
+#include <assert.h>
+
+#include "como.h"
+#include "comopriv.h"
+
+/*
+ * When there are this many entries per bucket, on average, rebuild
+ * the hash table to make it larger.
+ */
+
+#define REBUILD_MULTIPLIER 3
+
+/*
+ * The following macro takes a preliminary integer hash value and
+ * produces an index into a hash tables bucket list. The idea is
+ * to make it so that preliminary values that are arbitrarily similar
+ * will end up in different buckets. The hash function was taken
+ * from a random-number generator.
+ */
+
+#define RANDOM_INDEX(tablePtr, i) \
+ (((((long) (i))*1103515245) >> (tablePtr)->downShift) & (tablePtr)->mask)
+
+/*
+ * Structure definition for an entry in a hash table. No-one outside
+ * Tcl should access any of these fields directly; use the macros
+ * defined below.
+ */
+
+typedef struct hash_entry_t {
+ struct hash_entry_t *nextPtr; /* Pointer to next entry in this
+ * hash bucket, or NULL for end of
+ * chain. */
+ hash_t *tablePtr; /* Pointer to table containing entry. */
+ unsigned int hash; /* Hash value. */
+ void *key; /* Key. */
+ void *value; /* Entry value. */
+} hash_entry_t;
+
+/*
+ * Structure definition for a hash table.
+ */
+
+#define SMALL_HASH_TABLE 4
+struct hash_t {
+ hash_entry_t **buckets; /* Pointer to bucket array. Each
+ * element points to first entry in
+ * bucket's hash chain, or NULL. */
+ hash_entry_t *staticBuckets[SMALL_HASH_TABLE];
+ /* Bucket array used for small tables
+ * (to avoid mallocs and frees). */
+ int numBuckets; /* Total number of buckets allocated
+ * at **bucketPtr. */
+ int numEntries; /* Total number of entries present
+ * in table. */
+ int rebuildSize; /* Enlarge table when numEntries gets
+ * to be this large. */
+ int downShift; /* Shift count used in hashing
+ * function. Designed to use high-
+ * order bits of randomized keys. */
+ int mask; /* Mask value used in hashing
+ * function. */
+ int keyType; /* Type of keys used in this table.
+ * It's either TCL_CUSTOM_KEYS,
+ * HASHKEYS_STRING, HASHKEYS_ULONG,
+ * or an integer giving the number of
+ * ints that is the size of the key.
+ */
+ hash_key_fn hashKeyFn;
+ compare_hash_keys_fn compareKeysFn;
+ destroy_notify_fn keyDestroyFn;
+ destroy_notify_fn valueDestroyFn;
+ alc_t *alc; /* Allocator of the hash table. */
+};
+
+/*
+ * Hash iterator
+ */
+typedef struct hash_real_iter_t {
+ hash_t *table; /* Pointer to table containing entry. */
+ hash_entry_t **bucket; /* Pointer to bucket that points to
+ * first entry in this entry's chain:
+ * used for deleting the entry.
+ */
+ hash_entry_t *entry; /* Current hash entry */
+ hash_entry_t *next_entry; /* Next entry to be iterated onto in current
+ * bucket
+ */
+ int next_bucket; /* index of next bucket */
+ int n_entries_on_init; /* used to detect table resize since
+ * initialization
+ */
+} hash_real_iter_t;
+
+/*
+ * Prototypes for the string hash key methods.
+ */
+
+static unsigned int string_hash(const void *keyPtr);
+
+/*
+ * Procedure prototypes for static procedures in this file:
+ */
+
+static void rebuild_table(hash_t * tablePtr);
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * hash_new --
+ *
+ * Given storage for a hash table, set up the fields to prepare
+ * the hash table for use.
+ *
+ * Arguments:
+ * tablePtr - Pointer to table record, which is supplied by the caller.
+ * keyType - Type of keys to use in table: HASHKEYS_STRING,
+ * HASHKEYS_ULONG, or an integer >= 2.
+ * typePtr - Pointer to structure which defines the behaviour of this
+ * table.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * TablePtr is now ready to be passed to hash_lookup and
+ * hash_insert.
+ *
+ *----------------------------------------------------------------------
+ */
+
+hash_t *
+hash_new(alc_t * alc, int keyType, hash_key_fn hashKeyFn,
+ compare_hash_keys_fn compareKeysFn)
+{
+ return hash_new_full(alc, keyType, hashKeyFn, compareKeysFn, NULL, NULL);
+}
+
+hash_t *
+hash_new_full(alc_t * alc, int keyType, hash_key_fn hashKeyFn,
+ compare_hash_keys_fn compareKeysFn,
+ destroy_notify_fn keyDestroyFn, destroy_notify_fn valueDestroyFn)
+{
+ hash_t *tablePtr;
+
+ if (alc == NULL)
+ alc = como_alc();
+
+ tablePtr = alc_new0(alc, hash_t);
+
+#if (SMALL_HASH_TABLE != 4)
+#error "SMALL_HASH_TABLE must be 4!"
+#endif
+
+ tablePtr->buckets = tablePtr->staticBuckets;
+ tablePtr->staticBuckets[0] = tablePtr->staticBuckets[1] = 0;
+ tablePtr->staticBuckets[2] = tablePtr->staticBuckets[3] = 0;
+ tablePtr->numBuckets = SMALL_HASH_TABLE;
+ tablePtr->numEntries = 0;
+ tablePtr->rebuildSize = SMALL_HASH_TABLE * REBUILD_MULTIPLIER;
+ tablePtr->downShift = 28;
+ tablePtr->mask = 3;
+ tablePtr->keyType = keyType;
+ tablePtr->alc = alc;
+ tablePtr->hashKeyFn = hashKeyFn;
+ tablePtr->compareKeysFn = compareKeysFn;
+
+ if (keyType == HASHKEYS_STRING) {
+ if (hashKeyFn == NULL) {
+ tablePtr->hashKeyFn = string_hash;
+ }
+
+ if (compareKeysFn == NULL) {
+ tablePtr->compareKeysFn = (compare_hash_keys_fn) strcmp;
+ }
+ }
+
+ tablePtr->keyDestroyFn = keyDestroyFn;
+ tablePtr->valueDestroyFn = valueDestroyFn;
+
+ return tablePtr;
+}
+
+
+int
+hash_size(hash_t * tablePtr)
+{
+ return tablePtr->numEntries;
+}
+
+
+static hash_entry_t *
+hash_lookup_internal(hash_t * tablePtr, void *key)
+{
+ hash_entry_t *hPtr;
+ unsigned int hash;
+ int i;
+
+ if (tablePtr->hashKeyFn) {
+ hash = tablePtr->hashKeyFn(key);
+ i = hash & tablePtr->mask;
+ } else {
+ hash = (unsigned int) key;
+ i = RANDOM_INDEX(tablePtr, hash);
+ }
+
+ /*
+ * Search all of the entries in the appropriate bucket.
+ */
+ if (tablePtr->compareKeysFn) {
+ compare_hash_keys_fn compareKeysFn = tablePtr->compareKeysFn;
+ for (hPtr = tablePtr->buckets[i]; hPtr != NULL; hPtr = hPtr->nextPtr) {
+ if (hash != (unsigned int) hPtr->hash) {
+ continue;
+ }
+ if (compareKeysFn(key, hPtr->key) == 0) {
+ return hPtr;
+ }
+ }
+ } else {
+ for (hPtr = tablePtr->buckets[i]; hPtr != NULL; hPtr = hPtr->nextPtr) {
+ if (hash != (unsigned int) hPtr->hash) {
+ continue;
+ }
+ if (key == hPtr->key) {
+ return hPtr;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * hash_lookup_string --
+ *
+ * Given a hash table find the entry with a matching key.
+ *
+ * Arguments:
+ * tablePtr - Table in which to lookup entry.
+ * key - Key to use to find matching entry.
+ *
+ * Results:
+ * The return value is the value of the matching entry in the
+ * hash table, or NULL if there was no matching entry.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void *
+hash_lookup_string(hash_t * tablePtr, const char *key)
+{
+ hash_entry_t *hPtr;
+
+ assert(tablePtr->keyType == HASHKEYS_STRING);
+
+ hPtr = hash_lookup_internal(tablePtr, (void *) key);
+
+ return (hPtr) ? hPtr->value : NULL;
+}
+
+void *
+hash_lookup_ulong(hash_t * tablePtr, unsigned long key)
+{
+ hash_entry_t *hPtr;
+
+ assert(tablePtr->keyType == HASHKEYS_ULONG);
+
+ hPtr = hash_lookup_internal(tablePtr, (void *) key);
+
+ return (hPtr) ? hPtr->value : NULL;
+}
+
+void *
+hash_lookup(hash_t * tablePtr, void *key)
+{
+ hash_entry_t *hPtr;
+
+ assert(tablePtr->keyType == HASHKEYS_POINTER);
+
+ hPtr = hash_lookup_internal(tablePtr, key);
+
+ return (hPtr) ? hPtr->value : NULL;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * hash_insert_internal --
+ *
+ * Given a hash table with string keys, and a string key, find
+ * the entry with a matching key. If there is no matching entry,
+ * then create a new entry that does match.
+ *
+ * Arguments:
+ * tablePtr - Table in which to lookup entry.
+ * key - Key to use to find or create matching entry.
+ * value - Value associated to Key.
+ *
+ * Results:
+ * If this is a newly-created entry, then the functions returns 1;
+ * otherwise returns 0.
+ *
+ * Side effects:
+ * A new entry may be added to the hash table.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+hash_insert_internal(hash_t * tablePtr, void *key, void *value)
+{
+ hash_entry_t *hPtr;
+ unsigned int hash;
+ int i;
+
+ if (tablePtr->hashKeyFn) {
+ hash = tablePtr->hashKeyFn(key);
+ i = hash & tablePtr->mask;
+ } else {
+ hash = (unsigned int) key;
+ i = RANDOM_INDEX(tablePtr, hash);
+ }
+
+ /*
+ * Search all of the entries in the appropriate bucket.
+ */
+
+ if (tablePtr->compareKeysFn) {
+ compare_hash_keys_fn compareKeysFn = tablePtr->compareKeysFn;
+ for (hPtr = tablePtr->buckets[i]; hPtr != NULL; hPtr = hPtr->nextPtr) {
+ if (hash != (unsigned int) hPtr->hash) {
+ continue;
+ }
+ if (compareKeysFn(key, hPtr->key) == 0) {
+ if (tablePtr->valueDestroyFn && value != hPtr->value)
+ tablePtr->valueDestroyFn(hPtr->value);
+
+ hPtr->value = value;
+ return 0;
+ }
+ }
+ } else {
+ for (hPtr = tablePtr->buckets[i]; hPtr != NULL; hPtr = hPtr->nextPtr) {
+ if (hash != (unsigned int) hPtr->hash) {
+ continue;
+ }
+ if (key == hPtr->key) {
+ if (tablePtr->valueDestroyFn && value != hPtr->value)
+ tablePtr->valueDestroyFn(hPtr->value);
+
+ hPtr->value = value;
+ return 0;
+ }
+ }
+ }
+
+ /*
+ * Entry not found. Add a new one to the bucket.
+ */
+ hPtr = alc_calloc(tablePtr->alc, 1, sizeof(hash_entry_t));
+ hPtr->key = key;
+ hPtr->value = value;
+ hPtr->tablePtr = tablePtr;
+ hPtr->hash = hash;
+ hPtr->nextPtr = tablePtr->buckets[i];
+ tablePtr->buckets[i] = hPtr;
+ tablePtr->numEntries++;
+
+ /*
+ * If the table has exceeded a decent size, rebuild it with many
+ * more buckets.
+ */
+
+ if (tablePtr->numEntries >= tablePtr->rebuildSize) {
+ rebuild_table(tablePtr);
+ }
+ return 1;
+}
+
+int
+hash_insert_string(hash_t * tablePtr, const char *key, void *value)
+{
+ assert(tablePtr->keyType == HASHKEYS_STRING);
+
+ return hash_insert_internal(tablePtr, (void *) key, value);
+}
+
+int
+hash_insert_ulong(hash_t * tablePtr, unsigned long key, void *value)
+{
+ assert(tablePtr->keyType == HASHKEYS_ULONG);
+
+ return hash_insert_internal(tablePtr, (void *) key, value);
+}
+
+int
+hash_insert(hash_t * tablePtr, void *key, void *value)
+{
+ assert(tablePtr->keyType == HASHKEYS_POINTER);
+
+ return hash_insert_internal(tablePtr, key, value);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * hash_remove --
+ *
+ * Remove a single entry from a hash table.
+ *
+ * Arguments:
+ * tablePtr - Table in which to remove entry.
+ * key - Key to use to find matching entry.
+ *
+ * Results:
+ * Returns 1 if the entry existed and was removed; otherwise 0.
+ *
+ * Side effects:
+ * The entry given by entryPtr is deleted from its table and
+ * should never again be used by the caller.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+hash_remove_entry_internal(hash_t * tablePtr, hash_entry_t ** bucketPtr,
+ hash_entry_t * entryPtr)
+{
+ if (*bucketPtr == entryPtr) {
+ *bucketPtr = entryPtr->nextPtr;
+ } else {
+ hash_entry_t *prevPtr;
+
+ for (prevPtr = *bucketPtr;; prevPtr = prevPtr->nextPtr) {
+ if (prevPtr == NULL) {
+ /* malformed bucket chain in hash_remove */
+ assert_not_reached();
+ }
+ if (prevPtr->nextPtr == entryPtr) {
+ prevPtr->nextPtr = entryPtr->nextPtr;
+ break;
+ }
+ }
+ }
+
+ tablePtr->numEntries--;
+
+ if (tablePtr->keyDestroyFn)
+ tablePtr->keyDestroyFn(entryPtr->key);
+ if (tablePtr->valueDestroyFn)
+ tablePtr->valueDestroyFn(entryPtr->value);
+
+ alc_free(tablePtr->alc, entryPtr);
+
+ return 1;
+}
+
+static int
+hash_remove_internal(hash_t * tablePtr, void *key)
+{
+ hash_entry_t *entryPtr;
+ hash_entry_t **bucketPtr;
+ int i;
+
+ entryPtr = hash_lookup_internal(tablePtr, key);
+ if (entryPtr == NULL)
+ return 0;
+
+ if (tablePtr->hashKeyFn) {
+ i = ((unsigned int) entryPtr->hash) & tablePtr->mask;
+ } else {
+ i = RANDOM_INDEX(tablePtr, entryPtr->hash);
+ }
+
+ bucketPtr = &(tablePtr->buckets[i]);
+
+ return hash_remove_entry_internal(tablePtr, bucketPtr, entryPtr);
+}
+
+int
+hash_remove_string(hash_t * tablePtr, const char *key)
+{
+ assert(tablePtr->keyType == HASHKEYS_STRING);
+
+ return hash_remove_internal(tablePtr, (void *) key);
+}
+
+int
+hash_remove_ulong(hash_t * tablePtr, unsigned long key)
+{
+ assert(tablePtr->keyType == HASHKEYS_ULONG);
+
+ return hash_remove_internal(tablePtr, (void *) key);
+}
+
+int
+hash_remove(hash_t * tablePtr, void *key)
+{
+ assert(tablePtr->keyType == HASHKEYS_POINTER);
+
+ return hash_remove_internal(tablePtr, key);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * hash_destroy --
+ *
+ * Free up everything associated with a hash table except for
+ * the record for the table itself.
+ *
+ * Arguments:
+ * tablePtr - Table to delete.
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The hash table is no longer useable.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+hash_destroy(hash_t * tablePtr)
+{
+ hash_entry_t *hPtr, *nextPtr;
+ int i;
+
+ /*
+ * Free up all the entries in the table.
+ */
+ for (i = 0; i < tablePtr->numBuckets; i++) {
+ hPtr = tablePtr->buckets[i];
+ while (hPtr != NULL) {
+ nextPtr = hPtr->nextPtr;
+
+ if (tablePtr->keyDestroyFn)
+ tablePtr->keyDestroyFn(hPtr->key);
+ if (tablePtr->valueDestroyFn)
+ tablePtr->valueDestroyFn(hPtr->value);
+
+ alc_free(tablePtr->alc, hPtr);
+ hPtr = nextPtr;
+ }
+ }
+
+ /*
+ * Free up the bucket array, if it was dynamically allocated.
+ */
+ if (tablePtr->buckets != tablePtr->staticBuckets) {
+ alc_free(tablePtr->alc, tablePtr->buckets);
+ }
+
+ alc_free(tablePtr->alc, tablePtr);
+}
+
+/**
+ * Initializes a hash table iterator. To iterate over all entries in a
+ * hash table, use the following code (the printf assumes a hash
+ * from strings to strings obviously):
+ *
+ * @code
+ * hash_iter_t iter;
+ *
+ * hash_iter_init (table, &iter);
+ * while (hash_iter_next (&iter))
+ * {
+ * printf ("The first key is %s and value is %s\n",
+ * hash_iter_get_string_key (&iter),
+ * hash_iter_get_value (&iter));
+ * }
+ *
+ *
+ * @endcode
+ *
+ * The iterator is initialized pointing "one before" the first hash
+ * entry. The first call to hash_iter_next() moves it onto
+ * the first valid entry or returns 0 if the hash table is
+ * empty. Subsequent calls move to the next valid entry or return
+ * 0 if there are no more entries.
+ *
+ * Note that it is guaranteed to be safe to remove a hash entry during
+ * iteration, but it is not safe to add a hash entry.
+ *
+ * @param table the hash table to iterate over.
+ * @param iter the iterator to initialize.
+ */
+void
+hash_iter_init(hash_t * table, hash_iter_t * iter)
+{
+ hash_real_iter_t *real;
+
+ assert(sizeof(hash_iter_t) == sizeof(hash_real_iter_t));
+
+ real = (hash_real_iter_t *) iter;
+
+ real->table = table;
+ real->bucket = NULL;
+ real->entry = NULL;
+ real->next_entry = NULL;
+ real->next_bucket = 0;
+ real->n_entries_on_init = table->numEntries;
+}
+
+/**
+ * Move the hash iterator forward one step, to the next hash entry.
+ * The documentation for hash_iter_init() explains in more
+ * detail.
+ *
+ * @param iter the iterator to move forward.
+ * @returns 0 if there are no more entries to move to.
+ */
+int
+hash_iter_next(hash_iter_t * iter)
+{
+ hash_real_iter_t *real;
+
+ assert(sizeof(hash_iter_t) == sizeof(hash_real_iter_t));
+
+ real = (hash_real_iter_t *) iter;
+
+ /* if this assertion failed someone probably added hash entries
+ * during iteration, which is bad.
+ */
+ assert(real->n_entries_on_init >= real->table->numEntries);
+
+ /* Remember that real->entry may have been deleted */
+
+ while (real->next_entry == NULL) {
+ if (real->next_bucket >= real->table->numBuckets) {
+ /* invalidate iter and return false */
+ real->entry = NULL;
+ real->table = NULL;
+ real->bucket = NULL;
+ return 0;
+ }
+
+ real->bucket = &(real->table->buckets[real->next_bucket]);
+ real->next_entry = *(real->bucket);
+ real->next_bucket += 1;
+ }
+
+ assert(real->next_entry != NULL);
+ assert(real->bucket != NULL);
+
+ real->entry = real->next_entry;
+ real->next_entry = real->entry->nextPtr;
+
+ return 1;
+}
+
+/**
+ * Removes the current entry from the hash table.
+ * If a key_free_function or value_free_function
+ * was provided to hash_table_new(),
+ * frees the key and/or value for this entry.
+ *
+ * @param iter the hash table iterator.
+ */
+void
+hash_iter_remove_entry(hash_iter_t * iter)
+{
+ hash_real_iter_t *real;
+
+ real = (hash_real_iter_t *) iter;
+
+ assert(real->table != NULL);
+ assert(real->entry != NULL);
+ assert(real->bucket != NULL);
+
+ hash_remove_entry_internal(real->table, real->bucket, real->entry);
+
+ real->entry = NULL; /* make it crash if you try to use this entry */
+}
+
+/**
+ * Gets the value of the current entry.
+ *
+ * @param iter the hash table iterator.
+ */
+void *
+hash_iter_get_value(hash_iter_t * iter)
+{
+ hash_real_iter_t *real;
+
+ real = (hash_real_iter_t *) iter;
+
+ assert(real->table != NULL);
+ assert(real->entry != NULL);
+
+ return real->entry->value;
+}
+
+/**
+ * Sets the value of the current entry.
+ * If the hash table has a value_free_function
+ * it will be used to free the previous value.
+ * The hash table will own the passed-in value
+ * (it will not be copied).
+ *
+ * @param iter the hash table iterator.
+ * @param value the new value.
+ */
+void
+hash_iter_set_value(hash_iter_t * iter, void *value)
+{
+ hash_real_iter_t *real;
+
+ real = (hash_real_iter_t *) iter;
+
+ assert(real->table != NULL);
+ assert(real->entry != NULL);
+
+ if (real->table->valueDestroyFn && value != real->entry->value)
+ real->table->valueDestroyFn(real->entry->value);
+
+ real->entry->value = value;
+}
+
+/**
+ * Gets the key for the current entry.
+ * Only works for hash tables of type #HASHKEYS_POINTER.
+ *
+ * @param iter the hash table iterator.
+ */
+void *
+hash_iter_get_key(hash_iter_t * iter)
+{
+ hash_real_iter_t *real;
+
+ real = (hash_real_iter_t *) iter;
+
+ assert(real->table != NULL);
+ assert(real->entry != NULL);
+
+ return real->entry->key;
+}
+
+/**
+ * Gets the key for the current entry.
+ * Only works for hash tables of type #HASHKEYS_ULONG.
+ *
+ * @param iter the hash table iterator.
+ */
+unsigned long
+hash_iter_get_ulong_key(hash_iter_t * iter)
+{
+ hash_real_iter_t *real;
+
+ real = (hash_real_iter_t *) iter;
+
+ assert(real->table != NULL);
+ assert(real->entry != NULL);
+
+ return (unsigned long) real->entry->key;
+}
+
+/**
+ * Gets the key for the current entry.
+ * Only works for hash tables of type #HASHKEYS_STRING
+ * @param iter the hash table iterator.
+ */
+const char *
+hash_iter_get_string_key(hash_iter_t * iter)
+{
+ hash_real_iter_t *real;
+
+ real = (hash_real_iter_t *) iter;
+
+ assert(real->table != NULL);
+ assert(real->entry != NULL);
+
+ return real->entry->key;
+}
+
+#if 0
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_HashStats --
+ *
+ * Return statistics describing the layout of the hash table
+ * in its hash buckets.
+ *
+ * Results:
+ * The return value is a malloc-ed string containing information
+ * about tablePtr. It is the caller's responsibility to free
+ * this string.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+const char *
+Tcl_HashStats(tablePtr)
+hash_t *tablePtr; /* Table for which to produce stats. */
+{
+#define NUM_COUNTERS 10
+ int count[NUM_COUNTERS], overflow, i, j;
+ double average, tmp;
+ hash_entry_t *hPtr;
+ char *result, *p;
+
+ /*
+ * Compute a histogram of bucket usage.
+ */
+
+ for (i = 0; i < NUM_COUNTERS; i++) {
+ count[i] = 0;
+ }
+ overflow = 0;
+ average = 0.0;
+ for (i = 0; i < tablePtr->numBuckets; i++) {
+ j = 0;
+ for (hPtr = tablePtr->buckets[i]; hPtr != NULL; hPtr = hPtr->nextPtr) {
+ j++;
+ }
+ if (j < NUM_COUNTERS) {
+ count[j]++;
+ } else {
+ overflow++;
+ }
+ tmp = j;
+ average += (tmp + 1.0) * (tmp / tablePtr->numEntries) / 2.0;
+ }
+
+ /*
+ * Print out the histogram and a few other pieces of information.
+ */
+
+ result = (char *) ckalloc((unsigned) ((NUM_COUNTERS * 60) + 300));
+ sprintf(result, "%d entries in table, %d buckets\n",
+ tablePtr->numEntries, tablePtr->numBuckets);
+ p = result + strlen(result);
+ for (i = 0; i < NUM_COUNTERS; i++) {
+ sprintf(p, "number of buckets with %d entries: %d\n", i, count[i]);
+ p += strlen(p);
+ }
+ sprintf(p, "number of buckets with %d or more entries: %d\n",
+ NUM_COUNTERS, overflow);
+ p += strlen(p);
+ sprintf(p, "average search distance for entry: %.1f", average);
+ return result;
+}
+#endif
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * string_alloc --
+ *
+ * Allocate space for a hash_entry_t containing the string key.
+ *
+ * Results:
+ * The return value is a pointer to the created entry.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static unsigned int
+string_hash(const void *str)
+{
+ const char *p = (const char *) str;
+ unsigned int h = *p;
+
+ if (h)
+ for (p += 1; *p != '\0'; p++)
+ h = (h << 5) - h + *p;
+
+ return h;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * rebuild_table --
+ *
+ * This procedure is invoked when the ratio of entries to hash
+ * buckets becomes too large. It creates a new table with a
+ * larger bucket array and moves all of the entries into the
+ * new table.
+ *
+ * Arguments:
+ * tablePtr - Table to enlarge.
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Memory gets reallocated and entries get re-hashed to new
+ * buckets.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+rebuild_table(hash_t * tablePtr)
+{
+ int oldSize, count, i;
+ hash_entry_t **oldBuckets;
+ hash_entry_t **oldChainPtr, **newChainPtr;
+ hash_entry_t *hPtr;
+ void *key;
+
+ oldSize = tablePtr->numBuckets;
+ oldBuckets = tablePtr->buckets;
+
+ /*
+ * Allocate and initialize the new bucket array, and set up
+ * hashing constants for new array size.
+ */
+
+ tablePtr->numBuckets *= 4;
+ tablePtr->buckets = alc_calloc(tablePtr->alc, tablePtr->numBuckets,
+ sizeof(hash_entry_t *));
+
+ for (count = tablePtr->numBuckets, newChainPtr = tablePtr->buckets;
+ count > 0; count--, newChainPtr++) {
+ *newChainPtr = NULL;
+ }
+ tablePtr->rebuildSize *= 4;
+ tablePtr->downShift -= 2;
+ tablePtr->mask = (tablePtr->mask << 2) + 3;
+
+ /*
+ * Rehash all of the existing entries into the new bucket array.
+ */
+
+ for (oldChainPtr = oldBuckets; oldSize > 0; oldSize--, oldChainPtr++) {
+ for (hPtr = *oldChainPtr; hPtr != NULL; hPtr = *oldChainPtr) {
+ *oldChainPtr = hPtr->nextPtr;
+
+ key = hPtr->key;
+
+ if (tablePtr->hashKeyFn) {
+ i = ((unsigned int) hPtr->hash) & tablePtr->mask;
+ } else {
+ i = RANDOM_INDEX(tablePtr, hPtr->hash);
+ }
+ hPtr->nextPtr = tablePtr->buckets[i];
+ tablePtr->buckets[i] = hPtr;
+ }
+ }
+
+ /*
+ * Free up the old bucket array, if it was dynamically allocated.
+ */
+
+ if (oldBuckets != tablePtr->staticBuckets) {
+ alc_free(tablePtr->alc, oldBuckets);
+ }
+}
Copied: src/branches/2.0/base/ipc.c (from rev 1250, src/branches/2.0/libcomo/ipc.c)
===================================================================
--- src/branches/2.0/base/ipc.c (rev 0)
+++ src/branches/2.0/base/ipc.c 2008-06-04 23:17:20 UTC (rev 1253)
@@ -0,0 +1,697 @@
+/*
+ * Copyright (c) 2005-2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id:ipc.c 1032 2006-11-14 13:29:01Z m_canini $
+ */
+
+/*
+ * Inter process communications.
+ *
+ * This set of functions enable communications between processes.
+ * Each process initializes the IPC engine using the ipc_register()
+ * call to register the s_handlers for all IPC messages of interest.
+ *
+ * Each message carries a type to identify the handler and an id
+ * to identify the senders. Several types have been defined.
+ * All communications are asynchronous.
+ *
+ * Several additional helper functions have been provided to allow
+ * processes to send/receive complex data structures.
+ *
+ * Exception handling is managed by the individual processes
+ * in the s_handlers.
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <stdio.h>
+#include <string.h> /* strlen */
+#include <errno.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/time.h> /* FD_SET */
+#include <sys/types.h>
+#include <sys/select.h>
+
+#define LOG_DOMAIN "IPC"
+
+#include "como.h"
+#include "comopriv.h"
+#include "ipc.h"
+
+#define IPC_CONNECT 0
+
+#include "ipc_peer_list.h"
+
+
+#define SIZEOF_IPC_PEER_CODE 4
+#define SIZEOF_IPC_PEER_NAME 12
+
+struct ipc_peer_full_t {
+ uint8_t class;
+ uint8_t parent_class;
+ uint16_t id;
+ char code[SIZEOF_IPC_PEER_CODE];
+ char name[SIZEOF_IPC_PEER_NAME];
+ char * at;
+ int fd;
+ int swap:1;
+ int connected:1;
+ int _res:6;
+ ipc_peer_list_entry_t next;
+};
+
+/*
+ * IPC messages exchanged between processes.
+ */
+typedef struct PACKED ipc_msg {
+ ipc_type type; /* message type */
+ ipc_peer_t sender; /* sender */
+ uint32_t len; /* payload length */
+ uint8_t data[0]; /* payload */
+} ipc_msg_t;
+
+
+typedef struct PACKED ipc_connect_msg {
+ char code[SIZEOF_IPC_PEER_CODE]; /* code of connecting peer */
+ char name[SIZEOF_IPC_PEER_NAME]; /* name of connecting peer */
+} ipc_connect_msg_t;
+
+
+static ipc_peer_full_t * s_me;
+static void * s_user_data;
+
+/*
+ * IPC peers.
+ * information about connected peers.
+ */
+
+static ipc_peer_list_t s_peers;
+
+/*
+ * IPC messages s_handlers.
+ * if NULL, the message is ignored.
+ */
+/* TODO: replace with hash table */
+static ipc_handler_fn s_handlers[65536] = {0};
+static ipc_on_connect_fn s_on_connect;
+
+ipc_peer_full_t *
+ipc_peer_new(uint8_t class, const char * code, const char * name)
+{
+ ipc_peer_full_t *p;
+ p = como_new0(ipc_peer_full_t);
+ p->class = class;
+ snprintf(p->code, SIZEOF_IPC_PEER_CODE, code);
+ snprintf(p->name, SIZEOF_IPC_PEER_NAME, name);
+ return p;
+}
+
+
+void
+ipc_peer_destroy(ipc_peer_full_t * p)
+{
+ if (p == NULL)
+ return;
+ free(p->at);
+ if (p->fd != -1) {
+ debug("ipc_peer_destroy -- closing fd %d\n", p->fd);
+ close(p->fd);
+ }
+ free(p);
+}
+
+
+ipc_peer_full_t *
+ipc_peer_at(const ipc_peer_full_t * p, const char * at)
+{
+ ipc_peer_full_t *p2;
+ p2 = como_new(ipc_peer_full_t);
+ *p2 = *p;
+ p2->fd = -1;
+ p2->at = safe_strdup(at);
+ p2->swap = 0;
+ memset(&p2->next, 0, sizeof(p2->next));
+ return p2;
+}
+
+
+/*
+ * -- ipc_peer_get_fd
+ *
+ * get the socket descriptor from a peer
+ *
+ */
+int
+ipc_peer_get_fd(const ipc_peer_t * p_)
+{
+ ipc_peer_full_t * p = (ipc_peer_full_t *) p_;
+
+ return p->fd;
+}
+
+
+const char *
+ipc_peer_get_name(const ipc_peer_t * p_)
+{
+ ipc_peer_full_t * p = (ipc_peer_full_t *) p_;
+
+ return p->name;
+}
+
+
+const char *
+ipc_peer_get_code(const ipc_peer_t * p_)
+{
+ ipc_peer_full_t * p = (ipc_peer_full_t *) p_;
+
+ return p->code;
+}
+
+
+ipc_peer_full_t *
+ipc_peer_child(const ipc_peer_full_t * kind, uint16_t id)
+{
+ ipc_peer_full_t *p;
+ p = como_new(ipc_peer_full_t);
+ *p = *kind;
+ p->parent_class = s_me->class;
+ p->id = id;
+ p->at = safe_strdup(s_me->at);
+ p->fd = -1;
+ memset(&p->next, 0, sizeof(p->next));
+ return p;
+}
+
+
+static char *
+ipc_peer_connection_point(const ipc_peer_full_t * p)
+{
+ char *cp;
+ assert(p->at != NULL);
+ if (p->at[0] == '/') {
+ if (p->parent_class == 0 && p->id != 0) {
+ asprintf(&cp, "%s/%s.sock", p->at, p->name);
+ } else {
+ asprintf(&cp, "%s/%s-%d.sock", p->at, p->name, p->id);
+ }
+ } else {
+ cp = strdup(p->at);
+ }
+ return cp;
+}
+
+static inline void
+swap_msg(ipc_msg_t * msg)
+{
+ msg->type = SWAP16(msg->type);
+ msg->sender.id = SWAP16(msg->sender.id);
+ msg->len = SWAP32(msg->len);
+}
+
+
+static inline ipc_peer_full_t *
+lookup_peer(int fd)
+{
+ ipc_peer_full_t *x;
+ ipc_peer_list_foreach(x, &s_peers) {
+ if (x->fd == fd)
+ return x;
+ }
+ return NULL;
+}
+
+
+static int
+ipc_create_socket(const ipc_peer_full_t * p, int is_server)
+{
+ int fd;
+ char *cp;
+
+ cp = ipc_peer_connection_point(p);
+
+ fd = create_socket(cp, is_server);
+
+ free(cp);
+ return fd;
+}
+
+
+static int
+ipc_destroy_socket(const ipc_peer_full_t * p)
+{
+ int r;
+ char *cp;
+
+ cp = ipc_peer_connection_point(p);
+ r = destroy_socket(cp);
+ free(cp);
+
+ return r;
+}
+
+
+void
+ipc_init(ipc_peer_full_t * me, ipc_on_connect_fn on_connect, void * user_data)
+{
+ memset(s_handlers, 0, sizeof(s_handlers));
+
+ s_me = me;
+ s_me->fd = -1;
+ s_on_connect = on_connect;
+ s_user_data = user_data;
+}
+
+/*
+ * -- ipc_listen
+ *
+ * create a socket, bind it to a unix socket whose
+ * name depends on the process. then, register a handler
+ * for ...
[truncated message content] |
|
From: <jsa...@us...> - 2008-06-04 21:37:17
|
Revision: 1252
http://como.svn.sourceforge.net/como/?rev=1252&view=rev
Author: jsanjuas
Date: 2008-06-04 14:37:13 -0700 (Wed, 04 Jun 2008)
Log Message:
-----------
merged eventloop.h inside comofunc.h, now eventloop_t is opaque outside eventloop.c
Modified Paths:
--------------
src/branches/2.0/base/capture.c
src/branches/2.0/base/export.c
src/branches/2.0/base/storage.c
src/branches/2.0/base/supervisor.c
src/branches/2.0/include/como.h
src/branches/2.0/include/comofunc.h
src/branches/2.0/include/comopriv.h
src/branches/2.0/libcomo/eventloop.c
Removed Paths:
-------------
src/branches/2.0/include/eventloop.h
Modified: src/branches/2.0/base/capture.c
===================================================================
--- src/branches/2.0/base/capture.c 2008-06-03 00:13:00 UTC (rev 1251)
+++ src/branches/2.0/base/capture.c 2008-06-04 21:37:13 UTC (rev 1252)
@@ -807,7 +807,7 @@
s_cabuf.clients[id] = NULL;
s_cabuf.clients_count--;
fd = ipc_peer_get_fd(cl->peer);
- event_loop_del(&como_ca->el, fd);
+ event_loop_del(como_ca->el, fd);
FD_CLR(fd, &s_cabuf.clients_fds);
close(fd);
@@ -1527,7 +1527,7 @@
* del_fd() deals with invalid fd.
*/
if (sniff->priv->fd != -1)
- event_loop_del(&como_ca->el, sniff->priv->fd);
+ event_loop_del(como_ca->el, sniff->priv->fd);
/* inactive and frozen sniffers can be ignored */
@@ -1556,7 +1556,7 @@
if (sniff->flags & SNIFF_SELECT) {
sniff->priv->fd = sniff->fd;
- event_loop_add(&como_ca->el, sniff->priv->fd);
+ event_loop_add(como_ca->el, sniff->priv->fd);
}
}
@@ -1772,15 +1772,15 @@
}
/* initialize select()able file descriptors */
- event_loop_init(&como_ca.el);
+ como_ca.el = event_loop_new();
FD_ZERO(&ipc_fds);
/* ensure we handle messages from SUPERVISOR */
- event_loop_add(&como_ca.el, supervisor_fd);
+ event_loop_add(como_ca.el, supervisor_fd);
FD_SET(supervisor_fd, &ipc_fds);
/* accept connections from EXPORT process(es) and CAPTURE CLIENTS */
- event_loop_add(&como_ca.el, como_ca.accept_fd);
+ event_loop_add(como_ca.el, como_ca.accept_fd);
/* initialize the timers */
ca_init_timers();
@@ -1801,7 +1801,7 @@
for (;;) {
fd_set r;
- int n_ready;
+ int n_ready, max_fd;
batch_t *batch;
int active_sniff;
@@ -1831,12 +1831,12 @@
/* wait for messages, sniffers or up to the polling interval */
if (active_sniff > 0)
- event_loop_set_timeout(&como_ca.el, &timeout);
+ event_loop_set_timeout(como_ca.el, &timeout);
#ifdef LOADSHED
ls_select_start(&como_ca);
#endif
- n_ready = event_loop_select(&como_ca.el, &r);
+ n_ready = event_loop_select(como_ca.el, &r, &max_fd);
#ifdef LOADSHED
ls_select_end(&como_ca);
#endif
@@ -1849,7 +1849,7 @@
profiler_start_tsctimer(como_stats->ca_loop_timer);
- for (i = 0; n_ready > 0 && i < como_ca.el.max_fd; i++) {
+ for (i = 0; n_ready > 0 && i < max_fd; i++) {
if (!FD_ISSET(i, &r))
continue;
@@ -1859,7 +1859,7 @@
if (x < 0) {
warn("Failed on accept(): %s\n", strerror(errno));
} else {
- event_loop_add(&como_ca.el, x);
+ event_loop_add(como_ca.el, x);
FD_SET(x, &ipc_fds);
}
Modified: src/branches/2.0/base/export.c
===================================================================
--- src/branches/2.0/base/export.c 2008-06-03 00:13:00 UTC (rev 1251)
+++ src/branches/2.0/base/export.c 2008-06-04 21:37:13 UTC (rev 1252)
@@ -82,7 +82,7 @@
typedef struct _como_ex como_ex_t;
struct _como_ex {
- event_loop_t el;
+ event_loop_t * el;
char * st_dir;
int use_shmem;
hash_t *mdls; /* mdl name to mdl */
@@ -462,7 +462,9 @@
tset = next;
}
- /* TODO free state of the module */
+ /* free state of the module */
+ pool_clear(ie->mem);
+ pool_destroy(ie->mem);
/*
* close output file
@@ -540,10 +542,10 @@
/* ipc_register(IPC_EXIT, ex_ipc_exit);*/
/* listen to the parent */
- event_loop_init(&como_ex.el);
+ como_ex.el = event_loop_new();
supervisor_fd = ipc_peer_get_fd(parent);
- event_loop_add(&como_ex.el, supervisor_fd);
+ event_loop_add(como_ex.el, supervisor_fd);
/*
* wait for the debugger to attach
@@ -552,13 +554,13 @@
storage_fd = ipc_connect(COMO_ST);
debug("storage_fd = %d\n", storage_fd);
- event_loop_add(&como_ex.el, storage_fd);
+ event_loop_add(como_ex.el, storage_fd);
capture_fd = ipc_connect(COMO_CA);
/* save whether we're using shmem */
como_ex.use_shmem = (shmemmap != NULL);
- event_loop_add(&como_ex.el, capture_fd);
+ event_loop_add(como_ex.el, capture_fd);
/* allocate the timers */
ex_init_timers();
@@ -569,11 +571,9 @@
* tables to see if any action is required.
*/
for (;;) {
+ int n_ready, i, ipcr, max_fd;
+ struct timeval tv_zero;
fd_set r;
- int n_ready;
- int i;
- int ipcr;
- struct timeval tv_zero;
tv_zero.tv_sec = 0;
tv_zero.tv_usec = 0;
@@ -586,7 +586,7 @@
profiler_start_tsctimer(como_stats->ex_full_timer);
- n_ready = event_loop_select(&como_ex.el, &r);
+ n_ready = event_loop_select(como_ex.el, &r, &max_fd);
if (n_ready < 0) {
if (errno == EINTR) {
continue;
@@ -596,7 +596,7 @@
profiler_start_tsctimer(como_stats->ex_loop_timer);
- for (i = 0; n_ready > 0 && i < como_ex.el.max_fd; i++) {
+ for (i = 0; n_ready > 0 && i < max_fd; i++) {
if (!FD_ISSET(i, &r))
continue;
@@ -604,7 +604,7 @@
if (ipcr == IPC_EOF) {
/* EOF reading from a socket. */
debug("EOF from fd %d\n", i);
- event_loop_del(&como_ex.el, i);
+ event_loop_del(como_ex.el, i);
} else if (ipcr != IPC_OK) {
/* an error. close the socket */
warn("error on IPC handle from %d (%d)\n", i, ipcr);
@@ -626,7 +626,7 @@
* must not lock, because we have work to do
*/
if (como_ex.queue_len > 0)
- event_loop_set_timeout(&como_ex.el, &tv_zero);
+ event_loop_set_timeout(como_ex.el, &tv_zero);
profiler_end_tsctimer(como_stats->ex_loop_timer);
profiler_end_tsctimer(como_stats->ex_full_timer);
Modified: src/branches/2.0/base/storage.c
===================================================================
--- src/branches/2.0/base/storage.c 2008-06-03 00:13:00 UTC (rev 1251)
+++ src/branches/2.0/base/storage.c 2008-06-04 21:37:13 UTC (rev 1252)
@@ -216,7 +216,7 @@
off_t maxfilesize;
int supervisor_fd;
int accept_fd;
- event_loop_t el;
+ event_loop_t * el;
};
/*
@@ -1711,42 +1711,38 @@
ipc_register(S_SEEK, (ipc_handler_fn) handle_seek);
ipc_register(S_INFORM, (ipc_handler_fn) handle_inform);
- event_loop_add(&s_como_st.el, s_como_st.accept_fd);
+ event_loop_add(s_como_st.el, s_como_st.accept_fd);
ipc_register(SU_ANY_EXIT, handle_shutdown);
/* listen to SUPERVISOR */
- event_loop_add(&s_como_st.el, s_como_st.supervisor_fd);
+ event_loop_add(s_como_st.el, s_como_st.supervisor_fd);
/*
* The real main loop.
*/
for (;;) {
- fd_set r;
+ int n_ready, i, ipcr, max_fd;
struct timeval last;
-
timestamp_t elapsed;
- int n_ready;
- int i;
- int ipcr;
+ fd_set r;
/*
* use a timeout if we have files open. this way the
* scheduler starts when clients are idle too.
*/
if (s_como_st.client_count > 0) {
- event_loop_set_timeout(&s_como_st.el, &to);
+ event_loop_set_timeout(s_como_st.el, &to);
}
gettimeofday(&last, 0);
- n_ready = event_loop_select(&s_como_st.el, &r);
- if (n_ready < 0) {
- continue;
- }
+ n_ready = event_loop_select(s_como_st.el, &r, &max_fd);
+ if (n_ready < 0)
+ continue;
- for (i = 0; n_ready > 0 && i < s_como_st.el.max_fd; i++) {
+ for (i = 0; n_ready > 0 && i < max_fd; i++) {
if (!FD_ISSET(i, &r))
continue;
@@ -1755,11 +1751,10 @@
if (i == s_como_st.accept_fd) {
int x = accept(i, NULL, NULL);
- if (x < 0) {
+ if (x < 0)
warn("Failed on accept(): %s\n", strerror(errno));
- } else {
- event_loop_add(&s_como_st.el, x);
- }
+ else
+ event_loop_add(s_como_st.el, x);
continue;
}
@@ -1771,7 +1766,7 @@
case IPC_EOF:
case IPC_CLOSE:
close(i);
- event_loop_del(&s_como_st.el, i);
+ event_loop_del(s_como_st.el, i);
break;
}
}
Modified: src/branches/2.0/base/supervisor.c
===================================================================
--- src/branches/2.0/base/supervisor.c 2008-06-03 00:13:00 UTC (rev 1251)
+++ src/branches/2.0/base/supervisor.c 2008-06-04 21:37:13 UTC (rev 1252)
@@ -654,10 +654,10 @@
/* register handlers for IPC */
ipc_register(QU_SU_DONE, (ipc_handler_fn) qu_su_ipc_done);
- event_loop_init(&como_su->el);
+ como_su->el = event_loop_new();
/* accept connections from other processes */
- event_loop_add(&como_su->el, como_su->accept_fd);
+ event_loop_add(como_su->el, como_su->accept_fd);
FD_ZERO(&nodes_fds);
@@ -670,7 +670,7 @@
node = &array_at(como_su->nodes, como_node_t, i);
if (!como_config->inline_mode && como_node_listen(node) != -1) {
- event_loop_add(&como_su->el, node->query_fd);
+ event_loop_add(como_su->el, node->query_fd);
FD_SET(node->query_fd, &nodes_fds);
}
}
@@ -687,11 +687,11 @@
struct timeval to = {1, 0};
int secs, dd, hh, mm, ss;
struct timeval now;
- int n_ready;
+ int n_ready, max_fd;
fd_set r;
- event_loop_set_timeout(&como_su->el, &to);
+ event_loop_set_timeout(como_su->el, &to);
/*
* user interface. just one line...
@@ -718,11 +718,11 @@
real_node->mdls->len);
}
- n_ready = event_loop_select(&como_su->el, &r);
+ n_ready = event_loop_select(como_su->el, &r, &max_fd);
if (! como_config->inline_mode)
fprintf(stderr, "%78s\r", ""); /* clean the line */
- for (i = 0; n_ready > 0 && i < como_su->el.max_fd; i++) {
+ for (i = 0; n_ready > 0 && i < max_fd; i++) {
if (!FD_ISSET(i, &r))
continue;
@@ -733,7 +733,7 @@
if (x < 0) {
warn("accept() failed: %s\n", strerror(errno));
} else {
- event_loop_add(&como_su->el, x);
+ event_loop_add(como_su->el, x);
}
} else if (FD_ISSET(i, &nodes_fds)) {
como_node_t *node = como_node_lookup_by_fd(como_su->nodes, i);
@@ -748,7 +748,7 @@
warn("error on IPC handle from %d\n", i);
case IPC_CLOSE:
case IPC_EOF:
- event_loop_del(&como_su->el, i);
+ event_loop_del(como_su->el, i);
break;
}
}
Modified: src/branches/2.0/include/como.h
===================================================================
--- src/branches/2.0/include/como.h 2008-06-03 00:13:00 UTC (rev 1251)
+++ src/branches/2.0/include/como.h 2008-06-04 21:37:13 UTC (rev 1252)
@@ -75,7 +75,6 @@
#include "ipc.h"
#include "comofunc.h"
#include "log.h"
-#include "eventloop.h"
#include "pool.h"
#include "shmem.h"
#include "module.h"
Modified: src/branches/2.0/include/comofunc.h
===================================================================
--- src/branches/2.0/include/comofunc.h 2008-06-03 00:13:00 UTC (rev 1251)
+++ src/branches/2.0/include/comofunc.h 2008-06-04 21:37:13 UTC (rev 1252)
@@ -280,4 +280,16 @@
#define assert_not_reached() \
error("%s:%d should not be reached.\n", __FILE__, __LINE__)
+/*
+ * eventloop.c
+ */
+typedef struct event_loop event_loop_t;
+
+event_loop_t * event_loop_new(void);
+int event_loop_add(event_loop_t * el, int i);
+int event_loop_del(event_loop_t * el, int i);
+void event_loop_set_timeout(event_loop_t * el, struct timeval * timeout);
+int event_loop_select(event_loop_t * el, fd_set * ready, int * max_fd);
+void event_loop_destroy(event_loop_t * el);
+
#endif /* _COMO_FUNC_H */
Modified: src/branches/2.0/include/comopriv.h
===================================================================
--- src/branches/2.0/include/comopriv.h 2008-06-03 00:13:00 UTC (rev 1251)
+++ src/branches/2.0/include/comopriv.h 2008-06-04 21:37:13 UTC (rev 1252)
@@ -287,7 +287,7 @@
int sniffers_count;
// capbuf
- event_loop_t el;
+ event_loop_t * el;
int ready;
timestamp_t min_flush_ivl;
memmap_t * shmemmap;
@@ -443,7 +443,7 @@
*/
typedef struct como_su como_su_t;
struct como_su {
- event_loop_t el;
+ event_loop_t * el;
int accept_fd;
array_t * nodes; /* node information */
Deleted: src/branches/2.0/include/eventloop.h
===================================================================
--- src/branches/2.0/include/eventloop.h 2008-06-03 00:13:00 UTC (rev 1251)
+++ src/branches/2.0/include/eventloop.h 2008-06-04 21:37:13 UTC (rev 1252)
@@ -1,17 +0,0 @@
-#ifndef EVENTLOOP_H_
-#define EVENTLOOP_H_
-
-typedef struct event_loop {
- fd_set fds;
- int max_fd;
- struct timeval *timeoutptr;
- struct timeval timeout;
-} event_loop_t;
-
-void event_loop_init (event_loop_t * el);
-int event_loop_add (event_loop_t * el, int i);
-int event_loop_del (event_loop_t * el, int i);
-void event_loop_set_timeout (event_loop_t * el, struct timeval * timeout);
-int event_loop_select (event_loop_t * el, fd_set * ready);
-
-#endif /*EVENTLOOP_H_*/
Modified: src/branches/2.0/libcomo/eventloop.c
===================================================================
--- src/branches/2.0/libcomo/eventloop.c 2008-06-03 00:13:00 UTC (rev 1251)
+++ src/branches/2.0/libcomo/eventloop.c 2008-06-04 21:37:13 UTC (rev 1252)
@@ -36,12 +36,25 @@
#include <errno.h>
#include "como.h"
+#include "comopriv.h"
-void
-event_loop_init(event_loop_t * el)
+struct event_loop {
+ fd_set fds;
+ int max_fd;
+ struct timeval *timeoutptr;
+ struct timeval timeout;
+};
+
+
+event_loop_t *
+event_loop_new()
{
+ event_loop_t *el = safe_malloc(sizeof(event_loop_t));
+
memset(el, 0, sizeof(event_loop_t));
FD_ZERO(&el->fds);
+
+ return el;
}
@@ -100,7 +113,7 @@
int
-event_loop_select(event_loop_t * el, fd_set * ready)
+event_loop_select(event_loop_t * el, fd_set * ready, int * max_fd)
{
int n;
@@ -110,6 +123,7 @@
error("Failed on select(): %s\n", strerror(errno));
}
el->timeoutptr = NULL;
+ *max_fd = el->max_fd;
return n;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <jsa...@us...> - 2008-06-02 23:36:32
|
Revision: 1250
http://como.svn.sourceforge.net/como/?rev=1250&view=rev
Author: jsanjuas
Date: 2008-06-02 16:36:26 -0700 (Mon, 02 Jun 2008)
Log Message:
-----------
. now data structures shall use standard malloc/free if passed a null allocator
. removing unnecessary alc_t's from several funcs of config and supervisor
. decoupling memory.c and shmem.c
. protecting define _GNU_SOURCEs with ifdefs
. reverting to clearer safe_* notation for safe_calloc and such
Modified Paths:
--------------
src/branches/2.0/base/CMakeLists.txt
src/branches/2.0/base/capture.c
src/branches/2.0/base/config-lexic.l
src/branches/2.0/base/config-syntax.y
src/branches/2.0/base/config.c
src/branches/2.0/base/export.c
src/branches/2.0/base/filter-lexic.l
src/branches/2.0/base/filter-syntax.y
src/branches/2.0/base/metadesc.c
src/branches/2.0/base/ppbuf.c
src/branches/2.0/base/query-comms.c
src/branches/2.0/base/query-lexic.l
src/branches/2.0/base/query-ondemand.c
src/branches/2.0/base/query-syntax.y
src/branches/2.0/base/query.c
src/branches/2.0/base/storage.c
src/branches/2.0/base/supervisor.c
src/branches/2.0/base/util-timers.c
src/branches/2.0/include/comofunc.h
src/branches/2.0/include/comopriv.h
src/branches/2.0/include/os.h
src/branches/2.0/lib/bitmap.c
src/branches/2.0/lib/flowtable.c
src/branches/2.0/lib/heap.c
src/branches/2.0/libcomo/array.c
src/branches/2.0/libcomo/como.c
src/branches/2.0/libcomo/hash.c
src/branches/2.0/libcomo/ipc.c
src/branches/2.0/libcomo/log.c
src/branches/2.0/libcomo/memory.c
src/branches/2.0/libcomo/shmem.c
src/branches/2.0/libcomo/shobj.c
src/branches/2.0/libcomo/socket.c
src/branches/2.0/libcomo/storage-client.c
src/branches/2.0/loadshed/feats.c
src/branches/2.0/loadshed/loadshed.c
src/branches/2.0/loadshed/ls-profiling.c
src/branches/2.0/misc/gen-csclass.c
src/branches/2.0/misc/gen-csglue.c
src/branches/2.0/misc/gen-serial.c
src/branches/2.0/misc/structmagic.c
src/branches/2.0/mono/proxy-mono.c
src/branches/2.0/services/status.c
src/branches/2.0/sniffers/sniffer-como.c
src/branches/2.0/sniffers/sniffer-flowtools.c
src/branches/2.0/sniffers/sniffer-netflow.c
Modified: src/branches/2.0/base/CMakeLists.txt
===================================================================
--- src/branches/2.0/base/CMakeLists.txt 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/CMakeLists.txt 2008-06-02 23:36:26 UTC (rev 1250)
@@ -244,6 +244,8 @@
TARGET_LINK_LIBRARIES(como ${MONO_LIBS})
ENDIF(MONO_FOUND)
+TARGET_LINK_LIBRARIES(como ${APR_LIBS})
+
#
# Installation
#
Modified: src/branches/2.0/base/capture.c
===================================================================
--- src/branches/2.0/base/capture.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/capture.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -179,7 +179,7 @@
if (size < i) {
size = i;
- which = como_realloc(which, i);
+ which = safe_realloc(which, i);
}
bzero(which, i);
@@ -300,7 +300,7 @@
ntuples++;
}
- msg = como_malloc(sz + sizeof(msg_process_ser_tuples_t));
+ msg = safe_malloc(sz + sizeof(msg_process_ser_tuples_t));
strcpy(msg->mdl_name, mdl->name);
msg->ntuples = ntuples;
msg->tuple_mem = ic->tuple_mem;
@@ -909,7 +909,7 @@
cl = como_new0(cabuf_cl_t);
cl->peer = peer;
cl->ref_mask = (1LL << (uint64_t) (id + 1)); /* id 0 -> mask 2 */
- cl->sniff_usage = como_calloc(como_ca->sniffers_count , sizeof(float));
+ cl->sniff_usage = safe_calloc(como_ca->sniffers_count , sizeof(float));
cl->sampling = alc_new0(&como_ca->shalc, int); /* sampling rate is kept
into shared memory */
@@ -1756,7 +1756,7 @@
}
- como_ca.first_ref_pkts = como_calloc(sizeof(void *),
+ como_ca.first_ref_pkts = safe_calloc(sizeof(void *),
(max_sniffer_id + 1));
/* initialize the capture buffer */
Modified: src/branches/2.0/base/config-lexic.l
===================================================================
--- src/branches/2.0/base/config-lexic.l 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/config-lexic.l 2008-06-02 23:36:26 UTC (rev 1250)
@@ -83,7 +83,7 @@
if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
error("reading cfg: imports nested too deeply\n");
- str = como_strdup(yytext + 1); /* remove "s */
+ str = safe_strdup(yytext + 1); /* remove "s */
str[strlen(str) - 1] = '\0';
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
@@ -164,7 +164,7 @@
}
\"[^"]*\" { /* string literal */
- yclval.string = como_strdup(yytext + 1);
+ yclval.string = safe_strdup(yytext + 1);
yclval.string[strlen(yclval.string) - 1] = '\0';
dbg_return(TOK_STRING);
}
Modified: src/branches/2.0/base/config-syntax.y
===================================================================
--- src/branches/2.0/base/config-syntax.y 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/config-syntax.y 2008-06-02 23:36:26 UTC (rev 1250)
@@ -66,7 +66,6 @@
void config_lexic_init();
/* global variables */
-alc_t *alc;
static mdl_def_t mdl;
static virtual_node_def_t vnode;
static como_config_t *cfg; /* result */
@@ -139,11 +138,11 @@
virtual_node_def:
TOK_VIRTUAL_NODE TOK_STRING
{
- initialize_virtual_node_def(&vnode, alc);
+ initialize_virtual_node_def(&vnode);
vnode.name = $2;
}
virtual_node_keywords
- TOK_END { define_virtual_node(&vnode, cfg, alc); }
+ TOK_END { define_virtual_node(&vnode, cfg); }
;
virtual_node_keywords:
@@ -171,7 +170,7 @@
;
module_def: /* beware: actions in mid-rule */
- TOK_MODULE { initialize_module_def(&mdl, alc); }
+ TOK_MODULE { initialize_module_def(&mdl); }
TOK_STRING { mdl.name = $3; }
optional_module_keywords
TOK_END { define_module(&mdl, cfg); }
@@ -242,28 +241,28 @@
r = stat(path, &st);
if (r != 0) {
warn(GFC_ERROR_STR, path);
- return como_strdup("");
+ return safe_strdup("");
}
fd = open(path, O_RDONLY);
if (fd < 0) {
warn(GFC_ERROR_STR, path);
- return como_strdup("");
+ return safe_strdup("");
}
- buffer = como_malloc(st.st_size);
+ buffer = safe_malloc(st.st_size);
r = como_read(fd, buffer, st.st_size);
if (r != st.st_size) {
free(buffer);
warn(GFC_ERROR_STR, path);
- return como_strdup("");
+ return safe_strdup("");
}
r = close(fd);
if (r < 0) {
free(buffer);
warn(GFC_ERROR_STR, path);
- return como_strdup("");
+ return safe_strdup("");
}
return buffer;
}
@@ -282,7 +281,7 @@
}
como_config_t *
-parse_config_file(char *f, alc_t *my_alc, como_config_t *my_cfg)
+parse_config_file(char *f, como_config_t *my_cfg)
{
mode = PARSING_FILE;
what = f;
@@ -290,7 +289,6 @@
config_lexic_init();
cfg = my_cfg;
- alc = my_alc;
ycin = fopen(f, "r");
if (ycin == NULL)
@@ -301,7 +299,7 @@
}
como_config_t *
-parse_config_string(char *str, alc_t *my_alc, como_config_t *my_cfg)
+parse_config_string(char *str, como_config_t *my_cfg)
{
void *buffer;
@@ -311,7 +309,6 @@
config_lexic_init();
cfg = my_cfg;
- alc = my_alc;
buffer = yc_scan_string(str);
ycparse();
Modified: src/branches/2.0/base/config.c
===================================================================
--- src/branches/2.0/base/config.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/config.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -64,35 +64,34 @@
* values.
*/
void
-initialize_module_def(mdl_def_t *mdl, alc_t *alc)
+initialize_module_def(mdl_def_t *mdl)
{
bzero(mdl, sizeof(mdl_def_t));
- mdl->args = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ mdl->args = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
mdl->streamsize = 128 * 1024 * 1024;
- mdl->filter = como_strdup("all");
+ mdl->filter = safe_strdup("all");
#ifdef LOADSHED
mdl->minimum_srate = 0;
#endif
}
static void
-destroy_sniffer_def(sniffer_def_t *d, alc_t *alc)
+destroy_sniffer_def(sniffer_def_t *d)
{
- alc_free(alc, d->name);
- alc_free(alc, d->device);
+ free(d->name);
+ free(d->device);
if (d->args)
- alc_free(alc, d->args);
+ free(d->args);
}
void
-initialize_virtual_node_def(virtual_node_def_t *vnode, UNUSED alc_t *alc)
+initialize_virtual_node_def(virtual_node_def_t *vnode)
{
bzero(vnode, sizeof(virtual_node_def_t));
}
void
-define_virtual_node(virtual_node_def_t *vnode, UNUSED como_config_t *cfg,
- alc_t *alc)
+define_virtual_node(virtual_node_def_t *vnode, UNUSED como_config_t *cfg)
{
int ok = 1;
@@ -125,7 +124,7 @@
/* if not ok, output error notice and return */
if (ok == 0) {
warn("(ignoring virtual node definition)\n");
- destroy_virtual_node_def(vnode, alc);
+ destroy_virtual_node_def(vnode);
return;
}
@@ -134,41 +133,41 @@
}
void
-destroy_virtual_node_def(virtual_node_def_t *vnode, alc_t *alc)
+destroy_virtual_node_def(virtual_node_def_t *vnode)
{
- alc_free(alc, vnode->name);
- alc_free(alc, vnode->location);
- alc_free(alc, vnode->type);
- alc_free(alc, vnode->filter);
- alc_free(alc, vnode->source);
+ free(vnode->name);
+ free(vnode->location);
+ free(vnode->type);
+ free(vnode->filter);
+ free(vnode->source);
}
static void
-free_hash_entries(hash_t *h, alc_t *alc)
+free_hash_entries(hash_t *h)
{
hash_iter_t it;
hash_iter_init(h, &it); /* destroy the args */
while(hash_iter_next(&it)) {
- alc_free(alc, (void *)hash_iter_get_string_key(&it));
- alc_free(alc, (void *)hash_iter_get_value(&it));
+ free((void *)hash_iter_get_string_key(&it));
+ free((void *)hash_iter_get_value(&it));
hash_iter_remove_entry(&it);
}
}
static void
-destroy_module_def(mdl_def_t *d, alc_t *alc)
+destroy_module_def(mdl_def_t *d)
{
- free_hash_entries(d->args, alc);
+ free_hash_entries(d->args);
hash_destroy(d->args);
- alc_free(alc, d->name);
- alc_free(alc, d->mdlname);
- alc_free(alc, d->output);
- alc_free(alc, d->filter);
- alc_free(alc, d->descr);
+ free(d->name);
+ free(d->mdlname);
+ free(d->output);
+ free(d->filter);
+ free(d->descr);
#ifdef LOADSHED
- alc_free(alc, d->shed_method);
+ free(d->shed_method);
#endif
}
@@ -181,14 +180,14 @@
define_module(mdl_def_t *mdl, como_config_t *cfg)
{
if (mdl->output == NULL)
- mdl->output = como_strdup(mdl->name);
+ mdl->output = safe_strdup(mdl->name);
if (mdl->mdlname == NULL)
- mdl->mdlname = como_strdup(mdl->name);
+ mdl->mdlname = safe_strdup(mdl->name);
if (mdl->descr == NULL)
- mdl->descr = como_strdup("");
+ mdl->descr = safe_strdup("");
#ifdef LOADSHED
if (mdl->shed_method == NULL)
- mdl->shed_method = como_strdup("");
+ mdl->shed_method = safe_strdup("");
#endif
array_add(cfg->mdl_defs, mdl);
@@ -323,7 +322,7 @@
* Parse the command line and config files.
*/
como_config_t *
-configure(int argc, char **argv, alc_t *alc, como_config_t *cfg)
+configure(int argc, char **argv, como_config_t *cfg)
{
static const char *opts = "hi:St:q:c:C:D:L:p:m:vx:s:e";
int i, c, cfg_item_count = 0;
@@ -335,18 +334,18 @@
cfg->sniffer_defs = array_new(sizeof(sniffer_def_t));
cfg->vnode_defs = array_new(sizeof(virtual_node_def_t));
- cfg->como_executable_full_path = como_strdup(argv[0]);
+ cfg->como_executable_full_path = safe_strdup(argv[0]);
/*
* set some defaults
*/
cfg->query_port = 44444;
set_memsize(B2MB(64), cfg);
- cfg->db_path = como_strdup(DEFAULT_DBDIR);
+ cfg->db_path = safe_strdup(DEFAULT_DBDIR);
cfg->filesize = 128 * 1024 * 1024;
- cfg->libdir = como_strdup(DEFAULT_LIBDIR);
- cfg->query_args = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
- cfg->query_alias = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ cfg->libdir = safe_strdup(DEFAULT_LIBDIR);
+ cfg->query_args = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
+ cfg->query_alias = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
optind = 1; /* force getopt to start from 1st arg */
@@ -377,11 +376,11 @@
break;
case 'D': /* db-path */
- cfg->db_path = como_strdup(optarg);
+ cfg->db_path = safe_strdup(optarg);
break;
case 'L': /* libdir */
- cfg->libdir = como_strdup(optarg);
+ cfg->libdir = safe_strdup(optarg);
break;
case 'p':
@@ -392,9 +391,9 @@
{
char *name, *device, *args;
- name = como_strdup(strtok(optarg, ","));
- device = como_strdup(strtok(NULL, ","));
- args = como_strdup(strtok(NULL, ""));
+ name = safe_strdup(strtok(optarg, ","));
+ device = safe_strdup(strtok(NULL, ","));
+ args = safe_strdup(strtok(NULL, ""));
if (name && device)
define_sniffer(name, device, args, cfg);
@@ -419,7 +418,7 @@
case 'i': /* run inline: also silent & exit when done */
cfg->inline_mode = 1;
- cfg->inline_module = como_strdup(optarg);
+ cfg->inline_module = safe_strdup(optarg);
cfg->silent_mode = 1;
cfg->exit_when_done = 1;
break;
@@ -430,7 +429,7 @@
case 'q': { /* query args for inline mode */
char *str, *strbak;
- strbak = str = como_strdup(optarg);
+ strbak = str = safe_strdup(optarg);
while (str != NULL) {
char *k, *v;
@@ -451,8 +450,8 @@
str = s2 + 1;
}
- hash_insert_string(cfg->query_args, como_strdup(k),
- como_strdup(v));
+ hash_insert_string(cfg->query_args, safe_strdup(k),
+ safe_strdup(v));
}
free(strbak);
@@ -460,7 +459,7 @@
}
case 't': /* path to storage */
- cfg->storage_path = como_strdup(optarg);
+ cfg->storage_path = safe_strdup(optarg);
break;
case '?': /* unknown */
@@ -489,10 +488,10 @@
for (i = 0; i < cfg_item_count; i++) { /* parse config items here */
switch (cfg_items[i].type) {
case CFG_ITEM_FILE:
- parse_config_file(cfg_items[i].info, alc, cfg);
+ parse_config_file(cfg_items[i].info, cfg);
break;
case CFG_ITEM_STRING:
- parse_config_string(cfg_items[i].info, alc, cfg);
+ parse_config_string(cfg_items[i].info, cfg);
break;
}
}
@@ -503,7 +502,7 @@
bzero(&mdl, sizeof(mdl));
- buf = como_strdup(argv[optind]);
+ buf = safe_strdup(argv[optind]);
s = strchr(buf, ':');
if (s != NULL) {
@@ -511,8 +510,8 @@
args = s + 1;
}
- initialize_module_def(&mdl, alc);
- mdl.name = como_strdup(buf);
+ initialize_module_def(&mdl);
+ mdl.name = safe_strdup(buf);
while (args != NULL) { /* parse the arguments */
char *s1, *s2;
@@ -529,8 +528,8 @@
if (s2 != NULL)
*s2 = '\0'; /* null-terminate value */
- hash_insert_string(mdl.args, como_strdup(args),
- como_strdup(s1 + 1));
+ hash_insert_string(mdl.args, safe_strdup(args),
+ safe_strdup(s1 + 1));
if (s2)
args = s2 + 1;
@@ -635,24 +634,24 @@
* Free a configuration.
*/
void
-destroy_config(como_config_t *cfg, alc_t *alc)
+destroy_config(como_config_t *cfg)
{
int i;
for (i = 0; i < cfg->sniffer_defs->len; i++) { /* free sniff defs */
sniffer_def_t *def = &array_at(cfg->sniffer_defs, sniffer_def_t, i);
- destroy_sniffer_def(def, alc);
+ destroy_sniffer_def(def);
}
for (i = 0; i < cfg->mdl_defs->len; i++) { /* free mdl defs */
mdl_def_t *def = &array_at(cfg->mdl_defs, mdl_def_t, i);
- destroy_module_def(def, alc);
+ destroy_module_def(def);
}
for (i = 0; i < cfg->vnode_defs->len; i++) { /* free vnode defs */
virtual_node_def_t *def = &array_at(cfg->vnode_defs,
virtual_node_def_t, i);
- destroy_virtual_node_def(def, alc);
+ destroy_virtual_node_def(def);
}
array_free(cfg->sniffer_defs, 1); /* free the arrays themselves */
@@ -672,9 +671,9 @@
free(cfg->inline_module);
- free_hash_entries(cfg->query_args, alc);
+ free_hash_entries(cfg->query_args);
hash_destroy(cfg->query_args);
- free_hash_entries(cfg->query_alias, alc);
+ free_hash_entries(cfg->query_alias);
hash_destroy(cfg->query_alias);
}
Modified: src/branches/2.0/base/export.c
===================================================================
--- src/branches/2.0/base/export.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/export.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -145,7 +145,7 @@
/*
* open output file
*/
- str = como_asprintf("%s/%s", como_ex->st_dir, mdl->name);
+ str = safe_asprintf("%s/%s", como_ex->st_dir, mdl->name);
ie->cs_writer = csopen(str, CS_WRITER, (off_t) mdl->streamsize,
(ipc_peer_t *) COMO_ST);
if (ie->cs_writer < 0) {
@@ -254,7 +254,7 @@
debug("handle_ca_ex_process_shm_tuples -- recv'd %d tuples in shared mem\n",
msg->ntuples);
- tset = como_malloc(sizeof(tupleset_t));
+ tset = safe_malloc(sizeof(tupleset_t));
tset->tuples = msg->tuples;
tset->ntuples = msg->ntuples;
@@ -307,7 +307,7 @@
void **tuples;
size_t i;
- tuples = como_calloc(tset->ntuples, sizeof(void *));
+ tuples = safe_calloc(tset->ntuples, sizeof(void *));
debug("handle_ca_ex_process_shm_tuples -- building tuple array\n");
i = 0;
@@ -509,7 +509,7 @@
como_ex.mdls = hash_new(como_alc(), HASHKEYS_STRING, NULL, NULL);
tupleset_queue_init(&como_ex.queue);
- como_ex.st_dir = como_asprintf("%s/%s", como_config->db_path, node->name);
+ como_ex.st_dir = safe_asprintf("%s/%s", como_config->db_path, node->name);
#ifdef MONO_SUPPORT
/* initialize mono */
Modified: src/branches/2.0/base/filter-lexic.l
===================================================================
--- src/branches/2.0/base/filter-lexic.l 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/filter-lexic.l 2008-06-02 23:36:26 UTC (rev 1250)
@@ -114,12 +114,12 @@
}
{IPADDR} {
/* Copy the dots and numbers notation string */
- yflval.string = como_strdup(yytext);
+ yflval.string = safe_strdup(yytext);
dbg_return(IPADDR);
}
{MACADDR} {
/* Copy the dots and numbers notation string */
- yflval.string = como_strdup(yytext);
+ yflval.string = safe_strdup(yytext);
dbg_return(MACADDR);
}
{NETMASK} {
Modified: src/branches/2.0/base/filter-syntax.y
===================================================================
--- src/branches/2.0/base/filter-syntax.y 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/filter-syntax.y 2008-06-02 23:36:26 UTC (rev 1250)
@@ -221,7 +221,7 @@
char *
append_string(char *dest, char *src)
{
- dest = (char *)como_realloc(dest, strlen(dest) + strlen(src) + 1);
+ dest = (char *)safe_realloc(dest, strlen(dest) + strlen(src) + 1);
strcat(dest, src);
return dest;
}
@@ -238,11 +238,11 @@
{
treenode_t *t;
- t = (treenode_t *)como_malloc(sizeof(treenode_t));
+ t = (treenode_t *)safe_malloc(sizeof(treenode_t));
t->type = type;
if (t->type == Tpred) {
t->pred_type = pred_type;
- t->data = (nodedata_t *)como_malloc(sizeof(nodedata_t));
+ t->data = (nodedata_t *)safe_malloc(sizeof(nodedata_t));
switch(t->pred_type) {
case Tip:
asprintf(&(t->string), "%d ip %d/%d",
@@ -321,15 +321,15 @@
listnode_t *laux;
if (!list) {
- list = (listnode_t *)como_malloc(sizeof(listnode_t));
+ list = (listnode_t *)safe_malloc(sizeof(listnode_t));
list->next = NULL;
list->prev = NULL;
- list->string = como_strdup(s);
+ list->string = safe_strdup(s);
}
else {
if (strcmp(s, list->string) <= 0) {
- laux = (listnode_t *)como_malloc(sizeof(listnode_t));
- laux->string = como_strdup(s);
+ laux = (listnode_t *)safe_malloc(sizeof(listnode_t));
+ laux->string = safe_strdup(s);
laux->next = list;
laux->prev = list->prev;
list->prev = laux;
@@ -415,7 +415,7 @@
case Tand:
list = list_make(NULL, Tand, tree->left);
list = list_merge(list, list_make(NULL, Tand, tree->right));
- s = como_strdup("(");
+ s = safe_strdup("(");
for (laux = list; laux->next; laux = laux->next) {
s = append_string(s, laux->string);
s = append_string(s, " && ");
@@ -433,7 +433,7 @@
case Tor:
list = list_make(NULL, Tor, tree->left);
list = list_merge(list, list_make(NULL, Tor, tree->right));
- s = como_strdup("(");
+ s = safe_strdup("(");
for (laux = list; laux->next; laux = laux->next) {
s = append_string(s, laux->string);
s = append_string(s, " || ");
@@ -449,11 +449,11 @@
} while (laux);
break;
case Tnot:
- s = como_strdup("!");
+ s = safe_strdup("!");
s = append_string(s, tree_to_string(tree->left));
break;
case Tpred:
- s = como_strdup(tree->string);
+ s = safe_strdup(tree->string);
break;
}
Modified: src/branches/2.0/base/metadesc.c
===================================================================
--- src/branches/2.0/base/metadesc.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/metadesc.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -168,7 +168,7 @@
const headerinfo_t *hi;
layer_t l;
const char d[] = ":";
- char *protos_copy = como_strdup(protos);
+ char *protos_copy = safe_strdup(protos);
char *t, *s;
t = s = protos_copy;
@@ -475,7 +475,7 @@
for (outit = out; outit != NULL; outit = outit->_next) {
affinity = metadesc_try_match_pair(outit, init);
if (affinity > 0) {
- res = como_realloc(res, (matches_count + 1) *
+ res = safe_realloc(res, (matches_count + 1) *
sizeof(metadesc_match_t));
res[matches_count].in = init;
@@ -483,7 +483,7 @@
res[matches_count].affinity = affinity;
matches_count++;
} else {
- incomps = como_realloc(incomps, (incomps_count + 1) *
+ incomps = safe_realloc(incomps, (incomps_count + 1) *
sizeof(metadesc_incompatibility_t));
incomps[incomps_count].in = init;
incomps[incomps_count].out = outit;
@@ -562,7 +562,7 @@
layers[L2] = NULL;
for (l = L3; l <= L4; l++)
- layers[l] = como_calloc(md->_tpl_count, sizeof(int));
+ layers[l] = safe_calloc(md->_tpl_count, sizeof(int));
/*
* Iterate over the template list and keep the information of used
Modified: src/branches/2.0/base/ppbuf.c
===================================================================
--- src/branches/2.0/base/ppbuf.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/ppbuf.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -65,7 +65,7 @@
ppbuf = como_new0(ppbuf_t);
ppbuf->size = size;
- ppbuf->pp = como_calloc(size, sizeof(pkt_t *));
+ ppbuf->pp = safe_calloc(size, sizeof(pkt_t *));
ppbuf->id = sniff->priv->id;
ppbuf->sniffer = sniff;
Modified: src/branches/2.0/base/query-comms.c
===================================================================
--- src/branches/2.0/base/query-comms.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query-comms.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -360,19 +360,19 @@
switch (*name) {
case 'm':
if_have_kw("module") {
- q->module = como_strdup(value);
+ q->module = safe_strdup(value);
insert_arg = FALSE;
}
break;
case 'f':
if_have_kw("filter") {
char *v = value[0] != '\0' ? value : "all";
- q->filter_str = como_strdup(v);
+ q->filter_str = safe_strdup(v);
parse_filter(v, NULL, &(q->filter_cmp));
insert_arg = FALSE;
}
else if_have_kw("format") {
- q->format = como_strdup(value);
+ q->format = safe_strdup(value);
insert_arg = FALSE;
}
break;
@@ -381,7 +381,7 @@
q->start = atoi(value);
insert_arg = FALSE;
} else if_have_kw("source") {
- q->source = como_strdup(value);
+ q->source = safe_strdup(value);
insert_arg = FALSE;
} else if_have_kw("status") {
q->mode = QMODE_SERVICE;
Modified: src/branches/2.0/base/query-lexic.l
===================================================================
--- src/branches/2.0/base/query-lexic.l 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query-lexic.l 2008-06-02 23:36:26 UTC (rev 1250)
@@ -56,7 +56,7 @@
= { return TOK_EQUALS; }
" " { return TOK_SPACE; }
-{URICHAR}+ { yqlval.string = como_strdup(yytext); return TOK_STRING; }
+{URICHAR}+ { yqlval.string = safe_strdup(yytext); return TOK_STRING; }
.|\n
Modified: src/branches/2.0/base/query-ondemand.c
===================================================================
--- src/branches/2.0/base/query-ondemand.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query-ondemand.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -68,7 +68,7 @@
if (input[i] == '\\' || input[i] == '"')
final_len++;
- output = como_malloc(final_len + 1);
+ output = safe_malloc(final_len + 1);
for (i = j = 0; i < s; i++) {
if (input[i] == '\\' || input[i] == '"')
@@ -125,7 +125,7 @@
if (req->filter_str == NULL)
req->filter_str = "all";
- buffer = como_malloc(10 * 1024);
+ buffer = safe_malloc(10 * 1024);
sprintf(buffer, "module \"%s\" source \"%s\" filter \"%s\"",
req->module, mdl_code, req->filter_str);
@@ -152,7 +152,7 @@
my_argv[i++] = "-i"; /* do an inline execution of the mdl */
- buffer = como_malloc(8 * 1024);
+ buffer = safe_malloc(8 * 1024);
sprintf(buffer, "%s?format=%s", req->module, req->format);
hash_iter_init(req->args, &it);
@@ -165,7 +165,7 @@
my_argv[i++] = buffer;
my_argv[i++] = "-s"; /* with the appropriate input sniffer */
- my_argv[i++] = como_asprintf("como,http://localhost:%d/%s"
+ my_argv[i++] = safe_asprintf("como,http://localhost:%d/%s"
"?format=como&start=%d&end=%d&wait=%s",
como_config->query_port,
req->source,
Modified: src/branches/2.0/base/query-syntax.y
===================================================================
--- src/branches/2.0/base/query-syntax.y 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query-syntax.y 2008-06-02 23:36:26 UTC (rev 1250)
@@ -100,17 +100,17 @@
fullpath:
slashes relpath {
- $$ = como_asprintf("/%s", $2);
+ $$ = safe_asprintf("/%s", $2);
free($2);
}
| slashes {
- $$ = como_asprintf("/");
+ $$ = safe_asprintf("/");
}
;
relpath:
relpath slashes TOK_STRING {
- $$ = como_asprintf("%s/%s", $1, $3);
+ $$ = safe_asprintf("%s/%s", $1, $3);
free($1);
free($3);
}
@@ -143,12 +143,12 @@
}
| TOK_STRING TOK_EQUALS { /* value is not there */
ast.keyvals[ast.nkeyvals].key = $1;
- ast.keyvals[ast.nkeyvals].val = como_strdup("");
+ ast.keyvals[ast.nkeyvals].val = safe_strdup("");
ast.nkeyvals++;
}
| TOK_STRING {
ast.keyvals[ast.nkeyvals].key = $1;
- ast.keyvals[ast.nkeyvals].val = como_strdup("");
+ ast.keyvals[ast.nkeyvals].val = safe_strdup("");
ast.nkeyvals++;
}
| { /* tolerate missing key=val */ }
@@ -159,7 +159,7 @@
$$ = $1;
}
| value TOK_EQUALS TOK_STRING {
- $$ = como_asprintf("%s=%s", $1, $3);
+ $$ = safe_asprintf("%s=%s", $1, $3);
free($1);
free($3);
}
Modified: src/branches/2.0/base/query.c
===================================================================
--- src/branches/2.0/base/query.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -166,7 +166,7 @@
req->source = node->source; /* from the virtual node's source */
if (req->filter_str)
- req->filter_str = como_asprintf("(%s) and (%s)", req->filter_str,
+ req->filter_str = safe_asprintf("(%s) and (%s)", req->filter_str,
node->filter);
else
req->filter_str = node->filter;
@@ -206,9 +206,9 @@
* if necessary first get the default format
*/
if (req->format == NULL)
- req->format = como_strdup(iq->dflt_format);
+ req->format = safe_strdup(iq->dflt_format);
if (req->format == NULL) /* mdl has no default */
- req->format = como_strdup("plain");
+ req->format = safe_strdup("plain");
/*
* set the qu_format
@@ -478,7 +478,7 @@
uint8_t *sbuf;
void *mdlrec;
qreq_t req = *qreq;
- int client_fd = como_fileno(client_stream);
+ int client_fd = safe_fileno(client_stream);
if (req.mode == QMODE_SERVICE) {
service_fn service = service_lookup(req.service);
@@ -534,7 +534,7 @@
*/
storage_fd = ipc_connect(COMO_ST);
- dbname = como_asprintf("%s/%s/%s", como_config->db_path, node->name,
+ dbname = safe_asprintf("%s/%s/%s", como_config->db_path, node->name,
req.mdl->name);
debug("opening file for reading (%s)\n", dbname);
mode = req.wait ? CS_READER : CS_READER_NOBLOCK;
@@ -700,7 +700,7 @@
int supervisor_fd, ret, errcode;
qreq_t req;
char *errstr, *httpstr;
- int client_fd = como_fileno(client_stream);
+ int client_fd = safe_fileno(client_stream);
query_initialize(parent, &supervisor_fd);
ret = query_recv(&req, client_fd, como_stats->ts);
@@ -742,7 +742,7 @@
*/
if (req.mode == QMODE_MODULE) {
httpstr = NULL;
- httpstr = como_asprintf("HTTP/1.0 200 OK\r\nContent-Type: %s\r\n\r\n",
+ httpstr = safe_asprintf("HTTP/1.0 200 OK\r\nContent-Type: %s\r\n\r\n",
req.qu_format->content_type);
if (como_write(client_fd, httpstr, strlen(httpstr)) < 0)
error("sending data to the client");
@@ -763,11 +763,11 @@
int supervisor_fd, errcode;
char *errstr, *to_http;
qreq_t req;
- int client_fd = como_fileno(client_stream);
+ int client_fd = safe_fileno(client_stream);
query_initialize(parent, &supervisor_fd);
- to_http = como_asprintf("GET /%s HTTP/1.0\r\n\r\n",
+ to_http = safe_asprintf("GET /%s HTTP/1.0\r\n\r\n",
como_config->inline_module);
/*
Modified: src/branches/2.0/base/storage.c
===================================================================
--- src/branches/2.0/base/storage.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/storage.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -30,7 +30,9 @@
* $Id$
*/
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -1405,7 +1407,7 @@
}
/* finally, prepare to extend the file */
- buf = como_calloc(1, ext);
+ buf = safe_calloc(1, ext);
if (write(bs->wfd, buf, ext) < 0) {
free(buf);
warn("id: %d,%s; write to extend file failed: %s\n",
@@ -1817,7 +1819,7 @@
exit(EXIT_FAILURE);
}
- location = como_strdup(argv[1]);
+ location = safe_strdup(argv[1]);
como_init("ST", argc, argv);
if (atoi(argv[3])) /* inline mode */
Modified: src/branches/2.0/base/supervisor.c
===================================================================
--- src/branches/2.0/base/supervisor.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/supervisor.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -97,7 +97,7 @@
size_t sz;
sz = mdl_sersize(mdl);
- buf = sbuf = como_malloc(sz);
+ buf = sbuf = safe_malloc(sz);
mdl_serialize(&sbuf, mdl);
@@ -379,24 +379,24 @@
* the array of working modules.
*/
static mdl_t *
-como_node_init_mdl(como_node_t * node, mdl_def_t * def, alc_t * alc)
+como_node_init_mdl(como_node_t * node, mdl_def_t * def)
{
static int s_mdl_ids = 0;
mdl_isupervisor_t *is;
- mdl_t *mdl = alc_new0(alc, mdl_t);
+ mdl_t *mdl = safe_malloc(sizeof(mdl_t));
mdl->id = s_mdl_ids++;
if (mdl->id > MDL_ID_MAX)
error("the system currently supports %d mdls\n", MDL_ID_MAX);
- mdl->name = alc_strdup(alc, def->name);
- mdl->mdlname = alc_strdup(alc, def->mdlname);
+ mdl->name = safe_strdup(def->name);
+ mdl->mdlname = safe_strdup(def->mdlname);
mdl->streamsize = def->streamsize;
- mdl->filter = alc_strdup(alc, def->filter);
- mdl->description = alc_strdup(alc, def->descr);
+ mdl->filter = safe_strdup(def->filter);
+ mdl->description = safe_strdup(def->descr);
#ifdef LOADSHED
- mdl->shed_method = alc_strdup(alc, def->shed_method);
+ mdl->shed_method = safe_strdup(def->shed_method);
mdl->minimum_srate = def->minimum_srate;
#endif
@@ -428,12 +428,12 @@
* array of definitions.
*/
static void
-como_node_init_mdls(como_node_t * node, array_t * mdl_defs, alc_t * alc)
+como_node_init_mdls(como_node_t * node, array_t * mdl_defs)
{
int i;
for (i = 0; i < mdl_defs->len; i++) {
mdl_def_t *def = &array_at(mdl_defs, mdl_def_t, i);
- como_node_init_mdl(node, def, alc);
+ como_node_init_mdl(node, def);
}
}
@@ -454,7 +454,6 @@
{
hash_t *current_modules, *newcfg_modules, *new_modules, *rem_modules;
como_config_t new_cfg;
- alc_t *alc = como_su->alc;
como_node_t *node;
hash_iter_t it;
ipc_type t;
@@ -463,24 +462,24 @@
node = &array_at(como_su->nodes, como_node_t, 0);
/* re-run the config routines */
- configure(s_saved_argc, s_saved_argv, s_como_su->alc, &new_cfg);
+ configure(s_saved_argc, s_saved_argv, &new_cfg);
/* load module names from current cfg into a hash */
- current_modules = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ current_modules = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
for (i = 0; i < como_config->mdl_defs->len; i++) {
mdl_def_t *def = &array_at(como_config->mdl_defs, mdl_def_t, i);
hash_insert_string(current_modules, def->name, def);
}
/* load module names from the new cfg info a hash */
- newcfg_modules = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ newcfg_modules = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
for (i = 0; i < new_cfg.mdl_defs->len; i++) {
mdl_def_t *def = &array_at(new_cfg.mdl_defs, mdl_def_t, i);
hash_insert_string(newcfg_modules, def->name, def);
}
/* find new modules */
- new_modules = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ new_modules = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
hash_iter_init(newcfg_modules, &it);
while(hash_iter_next(&it)) {
mdl_def_t *def = hash_iter_get_value(&it);
@@ -490,7 +489,7 @@
continue;
/* new module */
- mdl = como_node_init_mdl(node, def, alc);
+ mdl = como_node_init_mdl(node, def);
if (mdl == NULL)
continue;
@@ -501,7 +500,7 @@
}
/* find modules to be removed */
- rem_modules = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ rem_modules = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
hash_iter_init(current_modules, &it);
while(hash_iter_next(&it)) {
mdl_def_t *def = hash_iter_get_value(&it);
@@ -579,7 +578,7 @@
size_t sz;
sz = sersize_string(name);
- buffer = como_malloc(sz);
+ buffer = safe_malloc(sz);
ptr = buffer;
serialize_string(&ptr, name);
@@ -602,7 +601,7 @@
size_t sz;
sz = sersize_string(name);
- buffer = como_malloc(sz);
+ buffer = safe_malloc(sz);
ptr = buffer;
serialize_string(&ptr, name);
@@ -622,7 +621,7 @@
hash_destroy(newcfg_modules);
hash_destroy(new_modules);
hash_destroy(rem_modules);
- destroy_config(&new_cfg, alc);
+ destroy_config(&new_cfg);
}
@@ -798,7 +797,7 @@
}
s->cb = cb;
- s->device = como_strdup(def->device);
+ s->device = safe_strdup(def->device);
/* check that the sniffer is consistent with the sniffers already
* configured */
@@ -839,9 +838,9 @@
char **argv2;
int i;
- argv2 = como_calloc(argc + 1, sizeof(char *));
+ argv2 = safe_calloc(argc + 1, sizeof(char *));
for (i = 0; i <= argc; i++) /* <= is correct, must copy final NULL */
- argv2[i] = como_strdup(argv[i]);
+ argv2[i] = safe_strdup(argv[i]);
*out_argc = argc;
*out_argv = argv2;
@@ -867,18 +866,18 @@
node.kind = COMO_NODE_REAL;
node.id = 0;
- node.name = como_strdup("CoMo Node");
- node.location = como_strdup(cfg->location);
- node.type = como_strdup(cfg->type);
+ node.name = safe_strdup("CoMo Node");
+ node.location = safe_strdup(cfg->location);
+ node.type = safe_strdup(cfg->type);
node.query_port = cfg->query_port;
node.mdls = array_new(sizeof(mdl_t *));
if (node.location == NULL)
- node.location = como_strdup("Unknown");
+ node.location = safe_strdup("Unknown");
if (node.type == NULL)
- node.type = como_strdup("Unknown");
+ node.type = safe_strdup("Unknown");
- str = como_asprintf("%s/%s", como_config->db_path, node.name);
+ str = safe_asprintf("%s/%s", como_config->db_path, node.name);
if (mkdir(str, 0700) == -1 && errno != EEXIST)
error("cannot create db dir `%s'\n", str);
free(str);
@@ -896,17 +895,17 @@
node.real_node_id = 0;
node.id = i + 1;
- node.name = como_strdup(def->name);
- node.location = como_strdup(def->location);
- node.type = como_strdup(def->type);
+ node.name = safe_strdup(def->name);
+ node.location = safe_strdup(def->location);
+ node.type = safe_strdup(def->type);
node.query_port = def->query_port;
- node.source = como_strdup(def->source);
- node.filter = como_strdup(def->filter);
+ node.source = safe_strdup(def->source);
+ node.filter = safe_strdup(def->filter);
if (node.location == NULL)
- node.location = como_strdup("Unknown");
+ node.location = safe_strdup("Unknown");
if (node.type == NULL)
- node.type = como_strdup("Unknown");
+ node.type = safe_strdup("Unknown");
array_add(como_su->nodes, &node);
}
@@ -926,17 +925,10 @@
{
static como_config_t cfg;
como_su_t *como_su;
- alc_t alc;
como_node_t *main_node;
int i;
- /* create a global pool */
- pool_t *pool = pool_create();
-
- pool_alc_init(pool, &alc);
- como_su = alc_new0(&alc, como_su_t);
- como_su->pool = pool;
- como_su->alc = &alc;
+ como_su = safe_malloc(sizeof(como_su_t));
como_su->su_pid = getpid();
como_su->workdir = mkdtemp(strdup("/tmp/comoXXXXXX"));
s_como_su = como_su;
@@ -947,13 +939,13 @@
* parse command line and configuration files
*/
copy_args(argc, argv, &s_saved_argc, &s_saved_argv);
- como_config = configure(s_saved_argc, s_saved_argv, &alc, &cfg);
+ como_config = configure(s_saved_argc, s_saved_argv, &cfg);
if (como_config->silent_mode)
log_set_level(LOG_LEVEL_WARNING); /* disable most UI messages */
if (como_config->inline_mode) { /* use temporary storage */
- char *template = como_asprintf("%s/XXXXXX", como_su->workdir);
+ char *template = safe_asprintf("%s/XXXXXX", como_su->workdir);
como_config->db_path = como_config->db_path = mkdtemp(template);
}
@@ -982,7 +974,8 @@
* CAPTURE and QUERY processes will be able to see it.
*/
como_su->shmem = shmem_create(como_config->shmem_size, NULL);
- como_su->memmap = memmap_create(como_su->shmem, 2048);
+ como_su->memmap = memmap_create(shmem_baseaddr(como_su->shmem),
+ shmem_size(como_su->shmem), 2048);
memmap_alc_init(como_su->memmap, &como_su->shalc);
/* allocate statistics into shared memory */
@@ -1003,7 +996,7 @@
if (n->kind != COMO_NODE_REAL)
continue;
como_node_init_sniffers(n, como_config->sniffer_defs, &como_su->shalc);
- como_node_init_mdls(n, como_config->mdl_defs, como_su->alc);
+ como_node_init_mdls(n, como_config->mdl_defs);
}
if (como_config->inline_mode && main_node->mdls->len == 0) {
Modified: src/branches/2.0/base/util-timers.c
===================================================================
--- src/branches/2.0/base/util-timers.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/util-timers.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -70,7 +70,7 @@
ctimer_t * t;
t = como_new0(ctimer_t);
- t->name = como_strdup(name);
+ t->name = safe_strdup(name);
t->min = ~0;
return t;
}
Modified: src/branches/2.0/include/comofunc.h
===================================================================
--- src/branches/2.0/include/comofunc.h 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/include/comofunc.h 2008-06-02 23:36:26 UTC (rev 1250)
@@ -89,26 +89,25 @@
*/
void define_sniffer(char *name, char *device, char *args, como_config_t *cfg);
void define_module(mdl_def_t *mdl, como_config_t *cfg);
-void define_virtual_node(virtual_node_def_t *vnode, como_config_t *cfg,
- alc_t *alc);
-void initialize_module_def(mdl_def_t *mdl, alc_t *alc);
-void initialize_virtual_node_def(virtual_node_def_t *vnode, alc_t *alc);
+void define_virtual_node(virtual_node_def_t *vnode, como_config_t *cfg);
+void initialize_module_def(mdl_def_t *mdl);
+void initialize_virtual_node_def(virtual_node_def_t *vnode);
void set_filesize(int64_t size, como_config_t *cfg);
void set_memsize(int64_t size, como_config_t *cfg);
void set_queryport(int64_t port, como_config_t *cfg);
-como_config_t *configure(int argc, char **argv, alc_t *alc, como_config_t *cfg);
+como_config_t *configure(int argc, char **argv, como_config_t *cfg);
mdl_def_t * config_get_module_def_by_name(como_config_t *cfg, char *name);
char *config_resolve_alias(como_config_t *cfg, char *name);
-void destroy_config(como_config_t *cfg, alc_t *alc);
-void destroy_virtual_node_def(virtual_node_def_t *cfg, alc_t *alc);
+void destroy_config(como_config_t *cfg);
+void destroy_virtual_node_def(virtual_node_def_t *cfg);
/*
* config-syntax.y
*/
-como_config_t * parse_config_file(char *file, alc_t *alc, como_config_t *cfg);
-como_config_t * parse_config_string(char *str, alc_t *alc, como_config_t *cfg);
+como_config_t * parse_config_file(char *file, como_config_t *cfg);
+como_config_t * parse_config_string(char *str, como_config_t *cfg);
/*
* filter-syntax.c
Modified: src/branches/2.0/include/comopriv.h
===================================================================
--- src/branches/2.0/include/comopriv.h 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/include/comopriv.h 2008-06-02 23:36:26 UTC (rev 1250)
@@ -45,32 +45,32 @@
*/
void como_init(const char * progname, int argc, char ** argv);
-#define como_malloc(sz) \
-como__malloc(sz, __FILE__, __LINE__)
+#define safe_malloc(sz) \
+safe__malloc(sz, __FILE__, __LINE__)
-#define como_calloc(n,sz) \
-como__calloc(n, sz, __FILE__, __LINE__)
+#define safe_calloc(n,sz) \
+safe__calloc(n, sz, __FILE__, __LINE__)
-#define como_realloc(ptr,sz) \
-como__realloc(ptr, sz, __FILE__, __LINE__)
+#define safe_realloc(ptr,sz) \
+safe__realloc(ptr, sz, __FILE__, __LINE__)
-#define como_strdup(str) \
-como__strdup(str, __FILE__, __LINE__)
+#define safe_strdup(str) \
+safe__strdup(str, __FILE__, __LINE__)
-#define como_dup(dst,src) \
-como__dup(dst, src, __FILE__, __LINE__)
+#define safe_dup(dst,src) \
+safe__dup(dst, src, __FILE__, __LINE__)
-#define como_fileno(stream) \
-como__fileno(stream, __FILE__, __LINE__)
+#define safe_fileno(stream) \
+safe__fileno(stream, __FILE__, __LINE__)
-#define como_asprintf(fmt...) \
-como__asprintf(__FILE__, __LINE__, fmt)
+#define safe_asprintf(fmt...) \
+safe__asprintf(__FILE__, __LINE__, fmt)
#define como_new(type) \
-((type *) como_malloc(sizeof(type)))
+((type *) safe_malloc(sizeof(type)))
#define como_new0(type) \
-((type *) como_calloc(1, sizeof(type)))
+((type *) safe_calloc(1, sizeof(type)))
char * como_basename (const char * path);
@@ -128,14 +128,14 @@
CCA_ACK_BATCH,
};
-void * como__malloc (size_t sz, const char * file, int line);
-void * como__calloc (size_t n, size_t sz, const char * file, int line);
-void * como__realloc (void * ptr, size_t sz, const char * file,
+void * safe__malloc (size_t sz, const char * file, int line);
+void * safe__calloc (size_t n, size_t sz, const char * file, int line);
+void * safe__realloc (void * ptr, size_t sz, const char * file,
const int line);
-char * como__strdup (const char * str, const char * file, const int line);
-char * como__dup (char **dst, char *src, const char * file, const int line);
-int como__fileno (FILE* stream, const char * file, const int line);
-char * como__asprintf (const char * file, const int line, char *fmt, ...);
+char * safe__strdup (const char * str, const char * file, const int line);
+char * safe__dup (char **dst, char *src, const char * file, const int line);
+int safe__fileno (FILE* stream, const char * file, const int line);
+char * safe__asprintf (const char * file, const int line, char *fmt, ...);
/*
* memory.c
@@ -147,7 +147,8 @@
size_t peak; /* peak usage */
} memmap_stats_t;
-memmap_t * memmap_create (shmem_t * shmem, uint32_t entries);
+memmap_t * memmap_create (void * baseaddr, size_t size,
+ uint32_t entries);
void memmap_alc_init (memmap_t * m, alc_t * alc);
memmap_stats_t * memmap_stats_location (memmap_t * m);
size_t memmap_usage (memmap_t * m);
@@ -447,10 +448,6 @@
array_t * nodes; /* node information */
- pool_t * pool; /* the pool used to allocate this
- structure */
- alc_t * alc; /* the pool's allocator */
-
shmem_t * shmem; /* main shared memory used to store
capture data structures, stats */
memmap_t * memmap;
Modified: src/branches/2.0/include/os.h
===================================================================
--- src/branches/2.0/include/os.h 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/include/os.h 2008-06-02 23:36:26 UTC (rev 1250)
@@ -50,7 +50,9 @@
/*** ***/
#ifdef linux
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* Required to use asprintf in Linux */
+#endif
/*
* EPROGUNAVAIL is not defined in Linux
*/
Modified: src/branches/2.0/lib/bitmap.c
===================================================================
--- src/branches/2.0/lib/bitmap.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/lib/bitmap.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -117,9 +117,9 @@
{
bitmap_t *bm;
- bm = como_malloc(sizeof(bitmap_t));
+ bm = safe_malloc(sizeof(bitmap_t));
_initialize_bitmap(bm, max_elements);
- bm->map = como_malloc(bm->bytes); /* no need to bzero */
+ bm->map = safe_malloc(bm->bytes); /* no need to bzero */
return bm;
}
Modified: src/branches/2.0/lib/flowtable.c
===================================================================
--- src/branches/2.0/lib/flowtable.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/lib/flowtable.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -602,7 +602,7 @@
* Print out the histogram and a few other pieces of information.
*/
- result = (char *) como_malloc((NUM_COUNTERS * 60) + 300);
+ result = (char *) safe_malloc((NUM_COUNTERS * 60) + 300);
sprintf(result, "%d entries in table, %d buckets\n",
ftable->numEntries, ftable->numBuckets);
p = result + strlen(result);
Modified: src/branches/2.0/lib/heap.c
===================================================================
--- src/branches/2.0/lib/heap.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/lib/heap.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -63,11 +63,11 @@
return NULL;
}
- h = (heap_t*) como_malloc(sizeof(heap_t));
+ h = (heap_t*) safe_malloc(sizeof(heap_t));
h->cmp = cmp;
h->size = size;
h->maxsize = 0; /* dynamic heap. no max size set */
- h->array = como_malloc(h->size * sizeof(void*));
+ h->array = safe_malloc(h->size * sizeof(void*));
h->first_free = 0; /* the heap is empty */
return h;
@@ -106,7 +106,7 @@
if (h->maxsize == 0) {
/* dynamic heap. double its size */
h->size <<= 1;
- h->array = como_realloc(h->array, h->size * sizeof(void*));
+ h->array = safe_realloc(h->array, h->size * sizeof(void*));
} else {
/* return an error and let the caller decide */
errno = ENOSPC;
Modified: src/branches/2.0/libcomo/array.c
===================================================================
--- src/branches/2.0/libcomo/array.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/array.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -86,7 +86,7 @@
}
array->size = MAX(array->size, 16);
- array->base = como_realloc(array->base, array->size * array->element_size);
+ array->base = safe_realloc(array->base, array->size * array->element_size);
array->data = array->base + off;
}
Modified: src/branches/2.0/libcomo/como.c
===================================================================
--- src/branches/2.0/libcomo/como.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/como.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -30,7 +30,9 @@
* $Id:como.c 1032 2006-11-14 13:29:01Z m_canini $
*/
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -77,9 +79,9 @@
}
/**
- * -- como__malloc
+ * -- safe__malloc
*
- * Not to be called directly, but through como_malloc()
+ * Not to be called directly, but through safe_malloc()
*
* simple wrapper to malloc that handles errors
* and returns only if the malloc call succeded. it
@@ -87,7 +89,7 @@
*
*/
void *
-como__malloc(size_t sz, const char * file, int line)
+safe__malloc(size_t sz, const char * file, int line)
{
void * v;
@@ -102,9 +104,9 @@
/**
- * -- como__calloc
+ * -- safe__calloc
*
- * Not to be called directly, but through como_calloc()
+ * Not to be called directly, but through safe_calloc()
*
* simple interface to calloc that handles errors
* and returns only if the calloc call succeded. it
@@ -112,7 +114,7 @@
*
*/
void *
-como__calloc(size_t n, size_t sz, const char * file, int line)
+safe__calloc(size_t n, size_t sz, const char * file, int line)
{
void * v;
@@ -127,9 +129,9 @@
/**
- * -- como__realloc
+ * -- safe__realloc
*
- * Not to be called directly, but through como_realloc()
+ * Not to be called directly, but through safe_realloc()
*
* simple interface to realloc that handles errors
* and returns only if the realloc call succeded. it
@@ -137,7 +139,7 @@
*
*/
void *
-como__realloc(void * ptr, size_t sz, const char * file, const int line)
+safe__realloc(void * ptr, size_t sz, const char * file, const int line)
{
void * v;
@@ -152,9 +154,9 @@
/**
- * -- como__strdup
+ * -- safe__strdup
*
- * Not to be called directly, but through como_strdup()
+ * Not to be called directly, but through safe_strdup()
*
* simple interface to strdup() that handles errors
* and returns only if the call succeded. it
@@ -162,7 +164,7 @@
*
*/
char *
-como__strdup(const char * str, const char * file, const int line)
+safe__strdup(const char * str, const char * file, const int line)
{
char * v;
@@ -180,25 +182,25 @@
/*
- * -- como__dup
+ * -- safe__freedup
*
- * Not to be called directly, but through como_dup()
+ * Not to be called directly, but through safe_freedup()
*
* Makes a malloc'ed copy of src into *dst,
* freeing the previous one if any
*/
char *
-como__dup(char **dst, char *src, const char * file, const int line)
+safe__freedup(char **dst, char *src, const char * file, const int line)
{
if (*dst)
free(*dst);
- *dst = como__strdup(src, file, line);
+ *dst = safe__strdup(src, file, line);
return *dst;
}
int
-como__fileno(FILE *stream, const char *file, const int line)
+safe__fileno(FILE *stream, const char *file, const int line)
{
int i = fileno(stream);
if (i < 1)
@@ -212,14 +214,14 @@
char *
-como__asprintf(const char * file, const int line, char *fmt, ...)
+safe__asprintf(const char * file, const int line, char *fmt, ...)
{
char *str;
va_list ap;
va_start(ap, fmt);
vasprintf(&str, fmt, ap);
if (str == NULL) {
- error("asprintf failed (%s:%d): %s\n",
+ error("vasprintf failed (%s:%d): %s\n",
file, line, strerror(errno));
}
va_end(ap);
@@ -237,8 +239,8 @@
como_alc()
{
static alc_t alc = {
- malloc: (alc_malloc_fn) como__malloc,
- calloc: (alc_calloc_fn) como__calloc,
+ malloc: (alc_malloc_fn) safe__malloc,
+ calloc: (alc_calloc_fn) safe__calloc,
free: (alc_free_fn) free,
data: NULL
};
Modified: src/branches/2.0/libcomo/hash.c
===================================================================
--- src/branches/2.0/libcomo/hash.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/hash.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -89,6 +89,7 @@
#include <assert.h>
#include "como.h"
+#include "comopriv.h"
/*
* When there are this many entries per bucket, on average, rebuild
@@ -230,7 +231,9 @@
{
hash_t *tablePtr;
- assert(alc != NULL);
+ if (alc == NULL)
+ alc = como_alc();
+
tablePtr = alc_new0(alc, hash_t);
#if (SMALL_HASH_TABLE != 4)
Modified: src/branches/2.0/libcomo/ipc.c
===================================================================
--- src/branches/2.0/libcomo/ipc.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/ipc.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -48,7 +48,9 @@
* in the s_handlers.
*/
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
#include <stdio.h>
#include <string.h> /* strlen */
#include <errno.h>
@@ -154,7 +156,7 @@
p2 = como_new(ipc_peer_full_t);
*p2 = *p;
p2->fd = -1;
- p2->at = como_strdup(at);
+ p2->at = safe_strdup(at);
p2->swap = 0;
memset(&p2->next, 0, sizeof(p2->next));
return p2;
@@ -202,7 +204,7 @@
*p = *kind;
p->parent_class = s_me->class;
p->id = id;
- p->at = como_strdup(s_me->at);
+ p->at = safe_strdup(s_me->at);
p->fd = -1;
memset(&p->next, 0, sizeof(p->next));
return p;
@@ -350,7 +352,7 @@
int r;
if (dst->at == NULL) {
- dst->at = como_strdup(s_me->at);
+ dst->at = safe_strdup(s_me->at);
}
dst->fd = ipc_create_socket(dst, FALSE);
Modified: src/branches/2.0/libcomo/log.c
===================================================================
--- src/branches/2.0/libcomo/log.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/log.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -196,16 +196,16 @@
if (h == NULL) {
s_log.handlers_count++;
if (s_log.handlers != &s_initial_handler) {
- s_log.handlers = como_realloc(s_log.handlers, s_log.handlers_count *
+ s_log.handlers = safe_realloc(s_log.handlers, s_log.handlers_count *
sizeof(log_handler_t));
} else {
- s_log.handlers = como_malloc(s_log.handlers_count *
+ s_log.handlers = safe_malloc(s_log.handlers_count *
sizeof(log_handler_t));
s_log.handlers[0] = s_initial_handler;
}
h = &s_log.handlers[s_log.handlers_count - 1];
}
- h->domain = como_strdup(domain);
+ h->domain = safe_strdup(domain);
h->user_fn = user_fn;
h->user_data = user_data;
}
@@ -245,7 +245,7 @@
s_log.buf_len += 4 - s_log.buf_len % 4;
}
}
- s_log.buf = como_realloc(s_log.buf, s_log.buf_len);
+ s_log.buf = safe_realloc(s_log.buf, s_log.buf_len);
len = 1 + vsnprintf(s_log.buf, s_log.buf_len, format, ap);
}
Modified: src/branches/2.0/libcomo/memory.c
===================================================================
--- src/branches/2.0/libcomo/memory.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/memory.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -320,37 +320,33 @@
*
*/
memmap_t *
-memmap_create(shmem_t * shmem, uint32_t entries)
+memmap_create(void * baseaddr, size_t size, uint32_t entries)
{
- void *x;
memmap_state_t *mem;
memmap_t *map;
memblock_t *m;
size_t ctrl;
- size_t size;
/*
* we put the memmap state structure at the beginning of the
* chunk, followed by the memory block that contains the actual
* allocated space.
*/
- x = shmem_baseaddr(shmem);
- size = shmem_size(shmem);
/* size of control structures */
ctrl = sizeof(memmap_state_t) + (sizeof(memmap_t) * (1 + entries));
- memset(x, 0, ctrl);
+ memset(baseaddr, 0, ctrl);
- mem = (memmap_state_t *) x;
- x += sizeof(memmap_state_t);
+ mem = (memmap_state_t *) baseaddr;
+ baseaddr += sizeof(memmap_state_t);
map = &mem->map[0];
- x += sizeof(memmap_t) * (1 + entries);
+ baseaddr += sizeof(memmap_t) * (1 + entries);
/* initially the map has only a big block */
- m = (memblock_t *) x;
+ m = (memblock_t *) baseaddr;
m->size = size - ctrl - sizeof(memblock_t);
m->_magic = MY_MAGIC;
m->next = NULL;
Modified: src/branches/2.0/libcomo/shmem.c
===================================================================
--- src/branches/2.0/libcomo/shmem.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/shmem.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -120,7 +120,7 @@
key_t shmkey;
new_m->realsize = reqsize;
- new_m->filename = como_strdup(filename);
+ new_m->filename = safe_strdup(filename);
fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600);
if (fd < 0) {
@@ -277,7 +277,7 @@
goto error;
}
- new_m->filename = como_strdup(filename);
+ new_m->filename = safe_strdup(filename);
shmkey = ftok(filename, 1);
if (shmkey == (key_t)-1) {
goto error;
Modified: src/branches/2.0/libcomo/shobj.c
===================================================================
--- src/branches/2.0/libcomo/shobj.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/shobj.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -29,7 +29,9 @@
*
* $Id$
*/
+#ifndef _GNU_SOURCE
...
[truncated message content] |
|
From: <jsa...@us...> - 2008-05-30 17:50:45
|
Revision: 1249
http://como.svn.sourceforge.net/como/?rev=1249&view=rev
Author: jsanjuas
Date: 2008-05-30 10:50:39 -0700 (Fri, 30 May 2008)
Log Message:
-----------
explanation of new features added to template cfg file
Modified Paths:
--------------
src/branches/2.0/como.conf.cmake
Modified: src/branches/2.0/como.conf.cmake
===================================================================
--- src/branches/2.0/como.conf.cmake 2008-05-29 22:34:45 UTC (rev 1248)
+++ src/branches/2.0/como.conf.cmake 2008-05-30 17:50:39 UTC (rev 1249)
@@ -6,6 +6,9 @@
# /* and */ as delimiters.
# Long lines can be split with a \ at the end of the line.
+# Configuration files can be nested:
+#import "filename.conf"
+
# Directory where the output data of all modules reside.
# Default: @DEFAULT_DBDIR@
@@ -139,7 +142,7 @@
# memsize 1024 # private memory in bytes (default: 0)
# streamsize 10GB # stream size on disk (default: 256MB)
# args "name" = "value"# arguments to be passed to the module.
-# args-file "path/to/file" # specify a file from where to read arguments.
+# args "name" <- "file"# load the argument from a file.
# running "on-demand" # specify running mode (default: normal)
# shed-method "pkt" # specify the load shedding method
# # (default: pkt, options: pkt/flow)
@@ -252,7 +255,7 @@
end
#module "pattern_search"
-# args "pattern" = "GET /"
+# args "pattern" <- "/path/to/file/pattern.txt"
#end
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-05-29 22:34:47
|
Revision: 1248
http://como.svn.sourceforge.net/como/?rev=1248&view=rev
Author: jsanjuas
Date: 2008-05-29 15:34:45 -0700 (Thu, 29 May 2008)
Log Message:
-----------
. adding support for loading an arg to a module from a file
. adding support for nested config files with the import keyword
. minor cosmetics, updating the todo list
Modified Paths:
--------------
src/branches/2.0/TODO.txt
src/branches/2.0/base/config-lexic.l
src/branches/2.0/base/config-syntax.y
src/branches/2.0/libcomo/util-io.c
Modified: src/branches/2.0/TODO.txt
===================================================================
--- src/branches/2.0/TODO.txt 2008-05-29 19:16:14 UTC (rev 1247)
+++ src/branches/2.0/TODO.txt 2008-05-29 22:34:45 UTC (rev 1248)
@@ -75,10 +75,8 @@
- Examine the utility of the following includes, which right now CoMo2.0 can compile without
- heap.h (companion of unused heap.c)
macutils.h (companion of unused macutils.c)
mempool.h (companion of unused mempool.c)
- pattern_search.h (companion of unused pattern_search.c)
ptr_array.h (companion of unused ptr_array.c)
- Remove commented code or old structs in include/*.h
Modified: src/branches/2.0/base/config-lexic.l
===================================================================
--- src/branches/2.0/base/config-lexic.l 2008-05-29 19:16:14 UTC (rev 1247)
+++ src/branches/2.0/base/config-lexic.l 2008-05-29 22:34:45 UTC (rev 1248)
@@ -46,11 +46,15 @@
#define dbg_return(x) return x
#endif
+#define MAX_INCLUDE_DEPTH 10
+YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+int include_stack_ptr;
int ycline;
void config_lexic_init(void)
{
ycline = 1;
+ include_stack_ptr = 0;
}
%}
@@ -62,6 +66,7 @@
%option nounput
%s comment
+%s import
%%
@@ -71,6 +76,28 @@
<comment>\n ycline++; /* and newlines */
<comment>"*"+"/" BEGIN(INITIAL);
+import BEGIN(import);
+<import>\"[^"]*\" {
+ char *str;
+
+ if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
+ error("reading cfg: imports nested too deeply\n");
+
+ str = como_strdup(yytext + 1); /* remove "s */
+ str[strlen(str) - 1] = '\0';
+
+ include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
+ yyin = fopen(str, "r" );
+ if (yyin == NULL)
+ error("reading cfg: cannot open imported " \
+ "file `%s' for reading\n", str);
+
+ yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
+
+ BEGIN(INITIAL);
+ }
+<import>[ \t]* /* skip spaces */
+
db-path { dbg_return(TOK_DBPATH); }
librarydir { dbg_return(TOK_LIBDIR); }
storage-path { dbg_return(TOK_STORAGEPATH); }
@@ -91,7 +118,6 @@
hashsize { dbg_return(TOK_HASHSIZE); }
streamsize { dbg_return(TOK_STREAMSIZE); }
args { dbg_return(TOK_ARGS); }
-args-file { dbg_return(TOK_ARGSFILE); }
on-demand { dbg_return(TOK_ONDEMAND); }
end { dbg_return(TOK_END); }
= { dbg_return(TOK_EQUALS); }
@@ -104,6 +130,8 @@
shed-method { dbg_return(TOK_SHEDMETHOD); }
min_srate { dbg_return(TOK_MINSRATE); }
+"<-" { dbg_return(TOK_LEFTARROW); }
+
{DIGIT}*"."{DIGIT}+ {
yclval.fpnumber = atof(yytext);
dbg_return(TOK_FPNUMBER);
@@ -154,4 +182,14 @@
warn("line %d: junk `%s' found\n", ycline, yctext);
}
+<<EOF>> {
+ include_stack_ptr--;
+ if (include_stack_ptr < 0)
+ yyterminate();
+ else {
+ yy_delete_buffer(YY_CURRENT_BUFFER);
+ yy_switch_to_buffer(include_stack[include_stack_ptr]);
+ }
+ }
+
%%
Modified: src/branches/2.0/base/config-syntax.y
===================================================================
--- src/branches/2.0/base/config-syntax.y 2008-05-29 19:16:14 UTC (rev 1247)
+++ src/branches/2.0/base/config-syntax.y 2008-05-29 22:34:45 UTC (rev 1248)
@@ -38,7 +38,11 @@
#define YYDEBUG 1
#define YYFPRINTF fwarn
-#include <strings.h> /* bzero */
+#include <strings.h> /* bzero */
+#include <sys/types.h> /* stat, open */
+#include <sys/stat.h> /* stat, open */
+#include <unistd.h> /* stat */
+#include <fcntl.h> /* open */
#define LOG_DOMAIN "CONFIG"
#include "como.h"
@@ -58,6 +62,7 @@
int mode;
char *what;
+static char *get_file_contents();
void config_lexic_init();
/* global variables */
@@ -88,9 +93,9 @@
%token TOK_DBPATH TOK_LIBDIR TOK_MEMSIZE TOK_QUERY_PORT TOK_NAME TOK_LOCATION
%token TOK_TYPE TOK_COMMENT TOK_SNIFFER TOK_FILESIZE TOK_MODULE TOK_DESCRIPTION
%token TOK_SOURCE TOK_OUTPUT TOK_FILTER TOK_HASHSIZE TOK_STREAMSIZE TOK_ARGS
-%token TOK_ARGSFILE TOK_ONDEMAND TOK_END TOK_NEWLINE TOK_EQUALS TOK_COMMA
+%token TOK_ONDEMAND TOK_END TOK_NEWLINE TOK_EQUALS TOK_COMMA
%token TOK_STORAGEPATH TOK_ASNFILE TOK_SHEDMETHOD TOK_ALIAS TOK_VIRTUAL_NODE
-%token TOK_SOURCE_MODULE TOK_MINSRATE
+%token TOK_SOURCE_MODULE TOK_MINSRATE TOK_LEFTARROW
%token <string> TOK_STRING
%token <number> TOK_NUMBER
%token <fpnumber> TOK_FPNUMBER
@@ -188,21 +193,20 @@
| TOK_HASHSIZE TOK_NUMBER { mdl.hashsize = $2; }
| TOK_STREAMSIZE TOK_NUMBER { mdl.streamsize = $2; }
| TOK_SHEDMETHOD TOK_STRING {
- #ifdef LOADSHED
- mdl.shed_method = $2;
- #endif
- }
+ #ifdef LOADSHED
+ mdl.shed_method = $2;
+ #endif
+ }
| TOK_MINSRATE TOK_NUMBER {
- #ifdef LOADSHED
- mdl.minimum_srate = $2;
- #endif
- }
+ #ifdef LOADSHED
+ mdl.minimum_srate = $2;
+ #endif
+ }
| TOK_MINSRATE TOK_FPNUMBER {
- #ifdef LOADSHED
- mdl.minimum_srate = $2;
- #endif
- }
- /*| TOK_ARGSFILE TOK_STRING (TODO) */
+ #ifdef LOADSHED
+ mdl.minimum_srate = $2;
+ #endif
+ }
| TOK_ONDEMAND { mdl.ondemand = 1; }
| error TOK_NEWLINE { report_parse_error(); }
;
@@ -210,13 +214,60 @@
args_list: args_list TOK_COMMA arg | arg
;
-arg: TOK_STRING TOK_EQUALS TOK_STRING { hash_insert_string(mdl.args, $1, $3); }
+arg:
+ TOK_STRING TOK_EQUALS TOK_STRING {
+ hash_insert_string(mdl.args, $1, $3);
+ }
+ | TOK_STRING TOK_LEFTARROW TOK_STRING {
+ hash_insert_string(mdl.args, $1, get_file_contents($3));
+ free($3);
+ }
;
%%
#include "config-lexic.c"
+static char *
+get_file_contents(char *path)
+{
+ struct stat st;
+ char *buffer;
+ int r, fd;
+
+ #define GFC_ERROR_STR \
+ "could not read file `%s' (referenced by configuration file " \
+ "or command line)\n"
+
+ r = stat(path, &st);
+ if (r != 0) {
+ warn(GFC_ERROR_STR, path);
+ return como_strdup("");
+ }
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ warn(GFC_ERROR_STR, path);
+ return como_strdup("");
+ }
+
+ buffer = como_malloc(st.st_size);
+ r = como_read(fd, buffer, st.st_size);
+ if (r != st.st_size) {
+ free(buffer);
+ warn(GFC_ERROR_STR, path);
+ return como_strdup("");
+ }
+
+ r = close(fd);
+ if (r < 0) {
+ free(buffer);
+ warn(GFC_ERROR_STR, path);
+ return como_strdup("");
+ }
+ return buffer;
+}
+
void ycerror(char *fmt, ...)
{
extern int ycline;
Modified: src/branches/2.0/libcomo/util-io.c
===================================================================
--- src/branches/2.0/libcomo/util-io.c 2008-05-29 19:16:14 UTC (rev 1247)
+++ src/branches/2.0/libcomo/util-io.c 2008-05-29 22:34:45 UTC (rev 1248)
@@ -34,7 +34,7 @@
/*
* -- como_read
*
- * keeps writing until complete.
+ * keeps reading until complete.
*/
ssize_t
como_read(int fd, void * buf, size_t count)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-05-29 19:16:18
|
Revision: 1247
http://como.svn.sourceforge.net/como/?rev=1247&view=rev
Author: jsanjuas
Date: 2008-05-29 12:16:14 -0700 (Thu, 29 May 2008)
Log Message:
-----------
. sniffers flowtools and netflow compile again
. recovered heap_t from unused_code
Modified Paths:
--------------
src/branches/2.0/base/CMakeLists.txt
src/branches/2.0/lib/CMakeLists.txt
src/branches/2.0/sniffers/CMakeLists.txt
src/branches/2.0/sniffers/sniffer-flowtools.c
src/branches/2.0/sniffers/sniffer-netflow.c
Added Paths:
-----------
src/branches/2.0/lib/heap.c
Removed Paths:
-------------
src/branches/2.0/lib/unused_code/heap.c
Modified: src/branches/2.0/base/CMakeLists.txt
===================================================================
--- src/branches/2.0/base/CMakeLists.txt 2008-05-29 17:39:54 UTC (rev 1246)
+++ src/branches/2.0/base/CMakeLists.txt 2008-05-29 19:16:14 UTC (rev 1247)
@@ -219,7 +219,7 @@
TARGET_LINK_LIBRARIES(como m)
TARGET_LINK_LIBRARIES(como comolib)
-#TARGET_LINK_LIBRARIES(como comomdl)
+TARGET_LINK_LIBRARIES(como comomdl)
TARGET_LINK_LIBRARIES(como-storage comolib)
Modified: src/branches/2.0/lib/CMakeLists.txt
===================================================================
--- src/branches/2.0/lib/CMakeLists.txt 2008-05-29 17:39:54 UTC (rev 1246)
+++ src/branches/2.0/lib/CMakeLists.txt 2008-05-29 19:16:14 UTC (rev 1247)
@@ -13,6 +13,7 @@
protoname.c
bitmap.c
pattern_search.c
+ heap.c
)
ADD_LIBRARY(comomdl STATIC ${COMOMDL_SRCS})
Copied: src/branches/2.0/lib/heap.c (from rev 1244, src/branches/2.0/lib/unused_code/heap.c)
===================================================================
--- src/branches/2.0/lib/heap.c (rev 0)
+++ src/branches/2.0/lib/heap.c 2008-05-29 19:16:14 UTC (rev 1247)
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2004-2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#include <stdlib.h> /* malloc */
+#include <string.h> /* memset */
+#include <inttypes.h> /* uintN_t */
+#include <errno.h> /* error values */
+
+#include "como.h"
+#include "comopriv.h"
+#include "heap.h"
+
+/*
+ * this is defined here to hide it from other files.
+ * other files just know the typedef (heap_t).
+ */
+struct _heap_t {
+ heap_compare cmp; /* compare callback function */
+ uint32_t size; /* current heap size */
+ uint32_t maxsize; /* heap max size. dynamic if set to 0 */
+ uint32_t first_free; /* first free element */
+ void **array; /* array with all elements */
+};
+
+
+heap_t *
+heap_init(heap_compare cmp, uint32_t size)
+{
+ heap_t *h;
+
+ if (cmp == NULL) {
+ /* callback compare() is mandatory */
+ errno = EINVAL;
+ return NULL;
+ }
+
+ h = (heap_t*) como_malloc(sizeof(heap_t));
+ h->cmp = cmp;
+ h->size = size;
+ h->maxsize = 0; /* dynamic heap. no max size set */
+ h->array = como_malloc(h->size * sizeof(void*));
+ h->first_free = 0; /* the heap is empty */
+
+ return h;
+}
+
+#define _HEAP_LEFT(x) (((x) << 1) + 1)
+#define _HEAP_RIGHT(x) (((x) << 1) + 2)
+#define _HEAP_VALID_POS(x,max) ((x)<(max)?(x):0)
+#define _HEAP_SWAP(a,b,tmp) {tmp = a; a = b; b = tmp;}
+
+#define HEAP_LEFT(h,x) (_HEAP_VALID_POS(_HEAP_LEFT(x),h->first_free))
+#define HEAP_RIGHT(h,x) (_HEAP_VALID_POS(_HEAP_RIGHT(x),h->first_free))
+#define HEAP_FATHER(x) (((x) - 1) >> 1)
+#define HEAP_SWAP(h,a,b,tmp) _HEAP_SWAP(h->array[(a)],h->array[(b)],tmp)
+#define HEAP_A_GT_B(h,a,b) (h->cmp(h->array[(a)], h->array[(b)]))
+
+
+/*
+ * -- heap_insert
+ *
+ * inserts a new element in the heap. if the heap is full tries to
+ * scale it up unless a fixed size is set. It returns 0 on success and
+ * a value errno in case of failure.
+ *
+ */
+int
+heap_insert(heap_t *h, void *elem)
+{
+ /* first of all put the new element at the end */
+ uint32_t curr = h->first_free;
+
+ if (curr == h->size) {
+ /*
+ * heap is full.
+ */
+ if (h->maxsize == 0) {
+ /* dynamic heap. double its size */
+ h->size <<= 1;
+ h->array = como_realloc(h->array, h->size * sizeof(void*));
+ } else {
+ /* return an error and let the caller decide */
+ errno = ENOSPC;
+ return errno;
+ }
+ }
+
+ /* restore the heap property */
+ h->array[curr] = elem;
+ h->first_free++;
+
+ while (curr > 0) {
+ void *tmp;
+ uint32_t father = HEAP_FATHER(curr);
+
+ if (HEAP_A_GT_B(h, father, curr))
+ break;
+
+ HEAP_SWAP(h, curr, father, tmp);
+ curr = father;
+ }
+
+ return 0;
+}
+
+int
+heap_extract(heap_t *h, void **elem)
+{
+ uint32_t curr = 0;
+ void *tmp;
+
+ if (h->first_free == 0) {
+ errno = ENOENT;
+ return errno; /* heap is empty */
+ }
+
+ *elem = h->array[0];
+
+ h->array[0] = NULL;
+ HEAP_SWAP(h, 0, h->first_free - 1, tmp);
+ h->first_free--;
+
+ /*
+ * LEFT and RIGHT should return 0 if > h->nelem
+ */
+ while (1) {
+ uint32_t greatest, lson, rson;
+
+ lson = HEAP_LEFT(h, curr);
+ rson = HEAP_RIGHT(h, curr);
+
+ if (lson == 0 && rson == 0) /* no more children */
+ break;
+
+ if (lson == 0 || rson == 0)
+ greatest = lson + rson;
+ else
+ greatest = HEAP_A_GT_B(h, lson, rson) ? lson : rson;
+
+ if (HEAP_A_GT_B(h, curr, greatest))
+ break;
+
+ HEAP_SWAP(h, curr, greatest, tmp);
+ curr = greatest;
+ }
+
+ return 0;
+}
+
+void *
+heap_root(heap_t *h)
+{
+ return h->first_free ? h->array[0] : NULL;
+}
+
+void
+heap_setsize(heap_t *h, int size)
+{
+ h->maxsize = h->size = size;
+ h->array = realloc(h->array, h->size * sizeof(void*));
+}
+
+void
+heap_close(heap_t *h)
+{
+ if (h->size > 0)
+ free(h->array);
+ free(h);
+}
+
+void
+heap_clear(heap_t *h, int zero_seg)
+{
+ if (zero_seg > 0) {
+ memset(h->array, 0, h->first_free * sizeof(void*));
+ }
+ h->first_free = 0;
+}
+
Deleted: src/branches/2.0/lib/unused_code/heap.c
===================================================================
--- src/branches/2.0/lib/unused_code/heap.c 2008-05-29 17:39:54 UTC (rev 1246)
+++ src/branches/2.0/lib/unused_code/heap.c 2008-05-29 19:16:14 UTC (rev 1247)
@@ -1,205 +0,0 @@
-/*
- * Copyright (c) 2004-2006, Intel Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the distribution.
- * * Neither the name of Intel Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id$
- */
-
-#include <stdlib.h> /* malloc */
-#include <string.h> /* memset */
-#include <inttypes.h> /* uintN_t */
-#include <errno.h> /* error values */
-
-#include "corlib.h"
-
-/*
- * this is defined here to hide it from other files.
- * other files just know the typedef (heap_t).
- */
-struct _heap_t {
- heap_compare cmp; /* compare callback function */
- uint32_t size; /* current heap size */
- uint32_t maxsize; /* heap max size. dynamic if set to 0 */
- uint32_t first_free; /* first free element */
- void **array; /* array with all elements */
-};
-
-
-heap_t *
-heap_init(heap_compare cmp, uint32_t size)
-{
- heap_t *h;
-
- if (cmp == NULL) {
- /* callback compare() is mandatory */
- errno = EINVAL;
- return NULL;
- }
-
- h = (heap_t*) lib_malloc(sizeof(heap_t));
- h->cmp = cmp;
- h->size = size;
- h->maxsize = 0; /* dynamic heap. no max size set */
- h->array = lib_malloc(h->size * sizeof(void*));
- h->first_free = 0; /* the heap is empty */
-
- return h;
-}
-
-#define _HEAP_LEFT(x) (((x) << 1) + 1)
-#define _HEAP_RIGHT(x) (((x) << 1) + 2)
-#define _HEAP_VALID_POS(x,max) ((x)<(max)?(x):0)
-#define _HEAP_SWAP(a,b,tmp) {tmp = a; a = b; b = tmp;}
-
-#define HEAP_LEFT(h,x) (_HEAP_VALID_POS(_HEAP_LEFT(x),h->first_free))
-#define HEAP_RIGHT(h,x) (_HEAP_VALID_POS(_HEAP_RIGHT(x),h->first_free))
-#define HEAP_FATHER(x) (((x) - 1) >> 1)
-#define HEAP_SWAP(h,a,b,tmp) _HEAP_SWAP(h->array[(a)],h->array[(b)],tmp)
-#define HEAP_A_GT_B(h,a,b) (h->cmp(h->array[(a)], h->array[(b)]))
-
-/*
- * -- heap_insert
- *
- * inserts a new element in the heap. if the heap is full tries to
- * scale it up unless a fixed size is set. It returns 0 on success and
- * a value errno in case of failure.
- *
- */
-int
-heap_insert(heap_t *h, void *elem)
-{
- /* first of all put the new element at the end */
- uint32_t curr = h->first_free;
-
- if (curr == h->size) {
- /*
- * heap is full.
- */
- if (h->maxsize == 0) {
- /* dynamic heap. double its size */
- h->size <<= 1;
- h->array = lib_realloc(h->array, h->size * sizeof(void*));
- } else {
- /* return an error and let the caller decide */
- errno = ENOSPC;
- return errno;
- }
- }
-
- /* restore the heap property */
- h->array[curr] = elem;
- h->first_free++;
-
- while (curr > 0) {
- void *tmp;
- uint32_t father = HEAP_FATHER(curr);
-
- if (HEAP_A_GT_B(h, father, curr))
- break;
-
- HEAP_SWAP(h, curr, father, tmp);
- curr = father;
- }
-
- return 0;
-}
-
-int
-heap_extract(heap_t *h, void **elem)
-{
- uint32_t curr = 0;
- void *tmp;
-
- if (h->first_free == 0) {
- errno = ENOENT;
- return errno; /* heap is empty */
- }
-
- *elem = h->array[0];
-
- h->array[0] = NULL;
- HEAP_SWAP(h, 0, h->first_free - 1, tmp);
- h->first_free--;
-
- /*
- * LEFT and RIGHT should return 0 if > h->nelem
- */
- while (1) {
- uint32_t greatest, lson, rson;
-
- lson = HEAP_LEFT(h, curr);
- rson = HEAP_RIGHT(h, curr);
-
- if (lson == 0 && rson == 0) /* no more children */
- break;
-
- if (lson == 0 || rson == 0)
- greatest = lson + rson;
- else
- greatest = HEAP_A_GT_B(h, lson, rson) ? lson : rson;
-
- if (HEAP_A_GT_B(h, curr, greatest))
- break;
-
- HEAP_SWAP(h, curr, greatest, tmp);
- curr = greatest;
- }
-
- return 0;
-}
-
-void *
-heap_root(heap_t *h)
-{
- return h->first_free ? h->array[0] : NULL;
-}
-
-void
-heap_setsize(heap_t *h, int size)
-{
- h->maxsize = h->size = size;
- h->array = lib_realloc(h->array, h->size * sizeof(void*));
-}
-
-void
-heap_close(heap_t *h)
-{
- if (h->size > 0)
- free(h->array);
- free(h);
-}
-
-void
-heap_clear(heap_t *h, int zero_seg)
-{
- if (zero_seg > 0) {
- memset(h->array, 0, h->first_free * sizeof(void*));
- }
- h->first_free = 0;
-}
-
Modified: src/branches/2.0/sniffers/CMakeLists.txt
===================================================================
--- src/branches/2.0/sniffers/CMakeLists.txt 2008-05-29 17:39:54 UTC (rev 1246)
+++ src/branches/2.0/sniffers/CMakeLists.txt 2008-05-29 19:16:14 UTC (rev 1247)
@@ -31,14 +31,14 @@
ENDIF(PCAP_FOUND)
# flow-tools support
-# IF(FTLIB_FOUND)
-# SET(SNIFFERS
-# ${SNIFFERS}
-# flowtools
-# netflow
-# )
-# INCLUDE_DIRECTORIES(${FTLIB_INCLUDE_DIR})
-# ENDIF(FTLIB_FOUND)
+IF(FTLIB_FOUND)
+ SET(SNIFFERS
+ ${SNIFFERS}
+ flowtools
+ netflow
+ )
+ INCLUDE_DIRECTORIES(${FTLIB_INCLUDE_DIR})
+ENDIF(FTLIB_FOUND)
# DAG support
IF(DAG_FOUND)
Modified: src/branches/2.0/sniffers/sniffer-flowtools.c
===================================================================
--- src/branches/2.0/sniffers/sniffer-flowtools.c 2008-05-29 17:39:54 UTC (rev 1246)
+++ src/branches/2.0/sniffers/sniffer-flowtools.c 2008-05-29 19:16:14 UTC (rev 1247)
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2006, Intel Corporation
+ * Copyright (c) 2004-2008, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
@@ -40,6 +40,7 @@
#include "sniffers.h"
#include "como.h"
+#include "comopriv.h"
#include "comotypes.h"
#include "heap.h"
@@ -175,7 +176,7 @@
else
pkts--;
} else if (flow->pkts_left * COMO(len) > flow->bytes_left) {
- panicx("incorrect flow - pkts: %d, len: %d, bytes: %d < %d",
+ error("incorrect flow - pkts: %d, len: %d, bytes: %d < %d",
flow->pkts_left, COMO(len), flow->bytes_left,
flow->pkts_left * COMO(len));
}
@@ -311,17 +312,17 @@
/* TODO: GLOB_APPEND ? */
ret = glob(me->device, GLOB_ERR | GLOB_TILDE, NULL, &me->in);
if (ret != 0) {
- logmsg(LOGWARN, "sniffer-flowtools: error matching %s: %s\n",
+ warn("sniffer-flowtools: error matching %s: %s\n",
me->device, strerror(errno));
}
return -1; /* no files to process */
}
- logmsg(LOGSNIFFER, "opening file %s\n", me->in.gl_pathv[me->curfile]);
+ msg("opening file %s\n", me->in.gl_pathv[me->curfile]);
me->fd = open(me->in.gl_pathv[me->curfile], O_RDONLY);
if (me->fd < 0) {
- logmsg(LOGWARN, "sniffer-flowtools: opening %s: %s\n",
+ warn("sniffer-flowtools: opening %s: %s\n",
me->in.gl_pathv[me->curfile], strerror(errno));
return -1;
}
@@ -329,7 +330,7 @@
/* init flowtools library */
ret = ftio_init(&me->ftio, me->fd, FT_IO_FLAG_READ);
if (ret < 0) {
- logmsg(LOGWARN, "sniffer-flowtools: initializing %s: %s\n",
+ warn("sniffer-flowtools: initializing %s: %s\n",
me->in.gl_pathv[me->curfile], strerror(errno));
return -1;
}
@@ -364,7 +365,7 @@
me->sniff.fd = me->fd;
fr = (struct fts3rec_v5 *) ftio_read(&me->ftio);
if (fr == NULL) {
- logmsg(LOGWARN, "error reading flowtools file: %s\n"
+ warn("error reading flowtools file: %s\n"
"moving to next file in the directory\n",
strerror(errno));
}
@@ -394,7 +395,7 @@
* check that the information in the flow record is valid
*/
if (fr->dPkts == 0 || fr->dOctets == 0) {
- logmsg(LOGSNIFFER, "invalid flow record (pkts: %d, bytes: %d)\n",
+ msg("invalid flow record (pkts: %d, bytes: %d)\n",
fr->dPkts, fr->dOctets);
/* read next record and try again */
fr = (struct fts3rec_v5 *) ftio_read(&me->ftio);
@@ -406,7 +407,7 @@
}
/* build a new flow record */
- flow = safe_calloc(1, sizeof(struct _flowinfo));
+ flow = como_calloc(1, sizeof(struct _flowinfo));
flow->pkts_left = fr->dPkts;
flow->bytes_left = fr->dOctets;
flow->increment = netflow2ts(fr, fr->Last) - netflow2ts(fr, fr->First);
@@ -450,11 +451,11 @@
*
*/
static sniffer_t *
-sniffer_init(const char * device, const char * args)
+sniffer_init(const char * device, const char * args, alc_t * alc)
{
struct flowtools_me *me;
- me = safe_calloc(1, sizeof(struct flowtools_me));
+ me = alc_new0(alc, struct flowtools_me);
me->sniff.max_pkts = 8192;
me->sniff.flags = SNIFF_FILE | SNIFF_SELECT | SNIFF_SHBUF;
@@ -544,15 +545,15 @@
}
-static void
-sniffer_setup_metadesc(sniffer_t * s)
+static metadesc_t *
+sniffer_setup_metadesc(sniffer_t * s, alc_t *alc)
{
struct flowtools_me *me = (struct flowtools_me *) s;
metadesc_t *outmd;
pkt_t *pkt;
/* setup output descriptor */
- outmd = metadesc_define_sniffer_out(s, 0);
+ outmd = metadesc_new(NULL, alc, 0);
//outmd = metadesc_define_sniffer_out(src, 1, "sampling_rate");
outmd->ts_resolution = TIME2TS(me->timescale, 0);
@@ -590,6 +591,8 @@
N32(IP(dst_ip)) = 0xffffffff;
N16(UDP(src_port)) = 0xffff;
N16(UDP(dst_port)) = 0xffff;
+
+ return outmd;
}
@@ -613,13 +616,13 @@
*/
ret = glob(me->device, GLOB_ERR | GLOB_TILDE, NULL, &me->in);
if (ret != 0) {
- logmsg(LOGWARN, "sniffer-flowtools: error matching %s: %s\n",
+ warn("sniffer-flowtools: error matching %s: %s\n",
me->device, strerror(errno));
return -1;
}
if (me->in.gl_pathc == 0) {
- logmsg(LOGWARN, "sniffer-flowtools: no files match %s\n", me->device);
+ warn("sniffer-flowtools: no files match %s\n", me->device);
return -1;
}
@@ -686,8 +689,12 @@
* of flows in the heap.
*/
while (me->max_ts - me->min_ts < me->window) {
+ /*
if (me->sniff.flags & (SNIFF_INACTIVE | SNIFF_COMPLETE))
break;
+ */
+ if (s->priv->state == SNIFFER_COMPLETED)
+ break;
if (!flowtools_read(me)) {
/*
@@ -701,22 +708,25 @@
/* we don't have files to process anymore. write a
* message and sleep for 10 mins.
*/
- logmsg(LOGSNIFFER, "sniffing from %s\n"
+ msg("sniffing from %s\n"
" no more files to read, but want more\n"
" going to sleep for 10minutes\n",
me->device);
me->sniff.polling = TIME2TS(600, 0);
- me->sniff.flags = SNIFF_TOUCHED | SNIFF_FILE | SNIFF_POLL;
+ s->priv->state = SNIFFER_COMPLETED;
+ s->priv->touched = 1;
return 0;
}
- me->sniff.flags = SNIFF_TOUCHED | SNIFF_FILE | SNIFF_COMPLETE;
+ s->priv->touched = 1;
+ s->priv->state = SNIFFER_COMPLETED;
break;
} else if (me->sniff.flags & SNIFF_POLL) {
/*
* we have a new file but still in polling mode.
* switch to select() mode to run faster.
*/
- me->sniff.flags = SNIFF_TOUCHED | SNIFF_FILE | SNIFF_SELECT;
+ me->sniff.flags = SNIFF_FILE | SNIFF_SELECT;
+ s->priv->touched = 1;
}
}
@@ -739,7 +749,7 @@
update_pkt(flow, me);
- ppbuf_capture(me->sniff.ppbuf, pkt);
+ ppbuf_capture(me->sniff.ppbuf, pkt, &me->sniff);
/* update the minimum timestamp from the root of the heap */
flow = heap_root(me->heap);
@@ -804,7 +814,7 @@
static void
-sniffer_finish(sniffer_t * s)
+sniffer_finish(sniffer_t * s, UNUSED alc_t *alc)
{
struct flowtools_me *me = (struct flowtools_me *) s;
Modified: src/branches/2.0/sniffers/sniffer-netflow.c
===================================================================
--- src/branches/2.0/sniffers/sniffer-netflow.c 2008-05-29 17:39:54 UTC (rev 1246)
+++ src/branches/2.0/sniffers/sniffer-netflow.c 2008-05-29 19:16:14 UTC (rev 1247)
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, Intel Corporation
+ * Copyright (c) 2006-2008, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
@@ -47,7 +47,7 @@
#include "comoendian.h"
#include "comotypes.h"
#include "comopriv.h"
-#include "corlib.h"
+#include "heap.h"
#include "capbuf.c"
@@ -177,7 +177,7 @@
else
pkts--;
} else if (flow->pkts_left * COMO(len) > flow->bytes_left) {
- panicx("incorrect flow - pkts: %d, len: %d, bytes: %d < %d",
+ error("incorrect flow - pkts: %d, len: %d, bytes: %d < %d",
flow->pkts_left, COMO(len), flow->bytes_left,
flow->pkts_left * COMO(len));
}
@@ -314,13 +314,13 @@
* check that the information in the flow record is valid
*/
if (fr->dPkts == 0 || fr->dOctets == 0) {
- logmsg(V_LOGSNIFFER, "invalid flow record (pkts: %d, bytes: %d)\n",
+ warn("invalid flow record (pkts: %d, bytes: %d)\n",
fr->dPkts, fr->dOctets);
return netflow2ts(fr, fr->Last);
}
/* build a new flow record */
- flow = safe_calloc(1, sizeof(struct _flowinfo));
+ flow = como_calloc(1, sizeof(struct _flowinfo));
flow->pkts_left = fr->dPkts;
flow->bytes_left = fr->dOctets;
flow->increment = netflow2ts(fr, fr->Last) - netflow2ts(fr, fr->First);
@@ -363,7 +363,7 @@
{
ftche_t *ftche;
- ftche = safe_calloc(1, sizeof(ftche_t));
+ ftche = como_calloc(1, sizeof(ftche_t));
ftche->heap = heap_init(flow_cmp, 32);
ftche->min_ts = ~0;
ftche->max_ts = 0;
@@ -401,21 +401,19 @@
MSG_DONTWAIT,
(struct sockaddr *) &agent, &addr_len);
if (ftpdu.bused <= 0) {
- if (errno != EAGAIN) {
- logmsg(LOGWARN, "sniffer-netflow: recvfrom: %s\n",
- strerror(errno));
- }
+ if (errno != EAGAIN)
+ warn("sniffer-netflow: recvfrom: %s\n", strerror(errno));
return -1;
}
/* verify integrity, get version */
if (ftpdu_verify(&ftpdu) < 0) {
- logmsg(LOGWARN, "sniffer-netflow: PDU corrupted\n");
+ warn("sniffer-netflow: PDU corrupted\n");
return 0;
}
if (ftpdu.ftv.d_version != 5) {
- logmsg(LOGWARN, "sniffer-netflow: NetFlow V5 required!\n");
+ warn("sniffer-netflow: NetFlow V5 required!\n");
return 0;
}
@@ -433,7 +431,7 @@
/* verify sequence number */
if (ftpdu_check_seq(&ftpdu, &ftche->ftseq) < 0) {
- logmsg(LOGSNIFFER, "sniffer-netflow: PDU with wrong sequence number:"
+ warn("sniffer-netflow: PDU with wrong sequence number. "
"expected: %lu got: %lu lost %lu\n",
ftche->ftseq.seq_exp, ftche->ftseq.seq_rcv,
ftche->ftseq.seq_lost);
@@ -464,11 +462,11 @@
*
*/
static sniffer_t *
-sniffer_init(const char * device, const char * args)
+sniffer_init(const char * device, const char * args, UNUSED alc_t *alc)
{
struct netflow_me *me;
- me = safe_calloc(1, sizeof(struct netflow_me));
+ me = como_calloc(1, sizeof(struct netflow_me));
me->sniff.max_pkts = 8192;
me->sniff.flags = SNIFF_SELECT | SNIFF_SHBUF;
@@ -552,15 +550,15 @@
}
-static void
-sniffer_setup_metadesc(sniffer_t * s)
+static metadesc_t *
+sniffer_setup_metadesc(sniffer_t * s, alc_t *alc)
{
struct netflow_me *me = (struct netflow_me *) s;
metadesc_t *outmd;
pkt_t *pkt;
/* setup output descriptor */
- outmd = metadesc_define_sniffer_out(s, 0);
+ outmd = metadesc_new(NULL, alc, 0);
//outmd = metadesc_define_sniffer_out(src, 1, "sampling_rate");
outmd->ts_resolution = TIME2TS(me->timescale, 0);
@@ -598,6 +596,8 @@
N32(IP(dst_ip)) = 0xffffffff;
N16(UDP(src_port)) = 0xffff;
N16(UDP(dst_port)) = 0xffff;
+
+ return outmd;
}
@@ -619,8 +619,7 @@
/* create a socket */
me->sniff.fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (me->sniff.fd < 0) {
- logmsg(LOGWARN, "sniffer-netflow: can't create socket: %s\n",
- strerror(errno));
+ warn("sniffer-netflow: can't create socket: %s\n", strerror(errno));
goto error;
}
@@ -635,8 +634,7 @@
if (bindinfo) {
loc_addr.sin_addr = *((struct in_addr *) bindinfo->h_addr);
} else {
- logmsg(LOGWARN,
- "sniffer-netflow: unresolved ip address %s: %s\n",
+ warn("sniffer-netflow: unresolved ip address %s: %s\n",
me->device, strerror(h_errno));
goto error;
}
@@ -645,13 +643,12 @@
/* unicast bind -- no multicast support */
if (bind(me->sniff.fd, (struct sockaddr *) &loc_addr,
sizeof(loc_addr)) < 0) {
- logmsg(LOGWARN, "sniffer-netflow: can't bind socket: %s\n",
- strerror(errno));
+ warn("sniffer-netflow: can't bind socket: %s\n", strerror(errno));
goto error;
}
/* initialize the hash table for demuxing exporters */
- me->ftch = hash_new_full(allocator_safe(), HASHKEYS_ULONG, NULL, NULL,
+ me->ftch = hash_new_full(como_alc(), HASHKEYS_ULONG, NULL, NULL,
NULL, (destroy_notify_fn) ftche_destroy);
return 0;
@@ -731,7 +728,7 @@
update_pkt(flow, me, ftche);
- ppbuf_capture(me->sniff.ppbuf, pkt);
+ ppbuf_capture(me->sniff.ppbuf, pkt, &me->sniff);
/* update the minimum timestamp from the root of the heap */
flow = heap_root(ftche->heap);
@@ -791,7 +788,7 @@
static void
-sniffer_finish(sniffer_t * s)
+sniffer_finish(sniffer_t * s, UNUSED alc_t *alc)
{
struct netflow_me *me = (struct netflow_me *) s;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jsa...@us...> - 2008-05-29 17:40:41
|
Revision: 1246
http://como.svn.sourceforge.net/como/?rev=1246&view=rev
Author: jsanjuas
Date: 2008-05-29 10:39:54 -0700 (Thu, 29 May 2008)
Log Message:
-----------
ported module pattern search to 2.0
fixed default cfg file
adding default formats for other mdls
enabled necessary logging in query
Modified Paths:
--------------
src/branches/2.0/base/query.c
src/branches/2.0/como.conf.cmake
src/branches/2.0/modules/apps/query.c
src/branches/2.0/modules/build_modules.sh
src/branches/2.0/modules/trace/query.c
Added Paths:
-----------
src/branches/2.0/modules/pattern_search/
src/branches/2.0/modules/pattern_search/capture.c
src/branches/2.0/modules/pattern_search/data.h
src/branches/2.0/modules/pattern_search/init.c
src/branches/2.0/modules/pattern_search/query.c
Modified: src/branches/2.0/base/query.c
===================================================================
--- src/branches/2.0/base/query.c 2008-05-29 00:25:39 UTC (rev 1245)
+++ src/branches/2.0/base/query.c 2008-05-29 17:39:54 UTC (rev 1246)
@@ -42,7 +42,7 @@
#include <err.h>
#include <errno.h> /* errno */
-#define LOG_DISABLE
+#define LOG_DEBUG_DISABLE
#include "como.h"
#include "comopriv.h"
#include "storage.h"
Modified: src/branches/2.0/como.conf.cmake
===================================================================
--- src/branches/2.0/como.conf.cmake 2008-05-29 00:25:39 UTC (rev 1245)
+++ src/branches/2.0/como.conf.cmake 2008-05-29 17:39:54 UTC (rev 1246)
@@ -199,55 +199,51 @@
# default: unused
module "traffic"
- source "trafficCC" # implemented by trafficCC.so
+ source "traffic" # implemented by traffic.so
description "Packet/Bytes counter"
args "interval" = "1"
# args "interface=1"
end
module "flowcount"
- source "flowcountCC"
+ source "flowcount"
description "Flow counter"
# aggregate flows using the 5-tuple
args "flowdef" = "src_ip|dst_ip|proto|src_port|dst_port"
end
module "protocol"
- source "protocolCC"
+ source "protocol"
description "Protocol breakdown"
end
module "topaddr"
- source "topaddrCC"
+ source "topaddr"
description "Popular destination IP Addresses"
args "use-dst" = "1"
on-demand
end
#module "tophwaddr"
-# source "tophwaddrCC"
+# source "tophwaddr"
# description "Popular destination HW Addresses"
# args "use-dst"
#end
module "topports"
- source "topportsCC"
+ source "topports"
description "Top destination port numbers in bytes"
args "interval" = "5", "topn" = "10"
end
module "trace"
- source "traceCC"
+ source "trace"
description "Packet trace"
streamsize 1GB
end
-#module "trafficCCS"
-# source "trafficCCS"
-#end
-
module "tuple"
- source "tupleCC"
+ source "tuple"
end
module "apps"
@@ -255,7 +251,11 @@
dns=udp 53,tcp 53"
end
+#module "pattern_search"
+# args "pattern" = "GET /"
+#end
+
# The ethtypes module computes the number of packets and bytes divided by
# ethertype. Each individual ethertype has to be specified in the
# configuration. The packets have an ethertype which is not declared in the
@@ -274,7 +274,7 @@
# default: IP,IPv6,ARP
/*
module "ethtypes"
- source "ethtypesCC"
+ source "ethtypes"
description "Ethertypes breakdown"
args "interval" = "60"
args "ethtypes" = "IP=0x0800,
Modified: src/branches/2.0/modules/apps/query.c
===================================================================
--- src/branches/2.0/modules/apps/query.c 2008-05-29 00:25:39 UTC (rev 1245)
+++ src/branches/2.0/modules/apps/query.c 2008-05-29 17:39:54 UTC (rev 1246)
@@ -46,6 +46,8 @@
{ FORMAT_GNUPLOT, "gnuplot", "text/plain" },
QUERY_FORMATS_END
+DEFAULT_FORMAT = "pretty";
+
struct qstate {
uint64_t aggr_pkts[CLASSES_MAX];
uint64_t aggr_bytes[CLASSES_MAX];
Modified: src/branches/2.0/modules/build_modules.sh
===================================================================
--- src/branches/2.0/modules/build_modules.sh 2008-05-29 00:25:39 UTC (rev 1245)
+++ src/branches/2.0/modules/build_modules.sh 2008-05-29 17:39:54 UTC (rev 1246)
@@ -4,7 +4,7 @@
# passed as the first argument. CoMo must be already installed in the system.
#
-MODULES="apps autofocus ethtypes flowcount protocol topaddr topaddr_csharp tophwaddr topports trace traffic traffic_csharp tuple"
+MODULES="apps autofocus ethtypes flowcount pattern_search protocol topaddr topaddr_csharp tophwaddr topports trace traffic traffic_csharp tuple"
if [ $# != 2 ]
then
Added: src/branches/2.0/modules/pattern_search/capture.c
===================================================================
--- src/branches/2.0/modules/pattern_search/capture.c (rev 0)
+++ src/branches/2.0/modules/pattern_search/capture.c 2008-05-29 17:39:54 UTC (rev 1246)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2004-2008, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id: capture.c 1226 2008-01-31 17:52:13Z jsanjuas $
+ */
+
+#include <string.h> /* memcpy */
+
+#include "pattern_search.h"
+#include "module.h"
+#include "data.h"
+
+void *
+ca_init(mdl_t *self, timestamp_t ts)
+{
+ config_t *cfg = mdl_get_config(self, config_t);
+ pattern_search_t *psearch;
+
+ psearch = (pattern_search_t *) mdl_malloc(self, sizeof(pattern_search_t));
+ pattern_search_initialize(psearch, cfg->pattern);
+
+ return psearch;
+}
+
+void
+capture(mdl_t *self, pkt_t *pkt, pattern_search_t *s, double srate)
+{
+ config_t *cfg;
+ record_t *r;
+ int len;
+
+ if (! pattern_search(s, COMO(payload), COMO(caplen), NULL))
+ return;
+
+ cfg = mdl_get_config(self, config_t);
+ r = mdl_alloc_tuple(self, record_t);
+
+ r->ts = COMO(ts);
+ len = (COMO(caplen) > cfg->snaplen) ? cfg->snaplen : COMO(caplen);
+ memcpy(r->buf, pkt, sizeof(pkt_t));
+ ((pkt_t *) r->buf)->payload = NULL;
+ ((pkt_t *) r->buf)->caplen = len;
+ memcpy(r->buf + sizeof(pkt_t), COMO(payload), len);
+ r->len = len + sizeof(pkt_t);
+}
+
Added: src/branches/2.0/modules/pattern_search/data.h
===================================================================
--- src/branches/2.0/modules/pattern_search/data.h (rev 0)
+++ src/branches/2.0/modules/pattern_search/data.h 2008-05-29 17:39:54 UTC (rev 1246)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2004-2006, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id: data.h 1211 2007-09-26 15:01:49Z jsanjuas $
+ */
+
+#include "como.h"
+
+#define BUFSIZE 2048
+
+como_tuple como_record struct record {
+ timestamp_t ts;
+ int len;
+ uint8_t buf[BUFSIZE];
+};
+
+como_config struct config {
+ uint32_t snaplen; /* bytes to capture in each packet */
+ char * pattern;
+};
+
+typedef struct record record_t;
+typedef struct config config_t;
+
+#define SNAPLEN_MAX (BUFSIZE - sizeof(pkt_t))
+
Added: src/branches/2.0/modules/pattern_search/init.c
===================================================================
--- src/branches/2.0/modules/pattern_search/init.c (rev 0)
+++ src/branches/2.0/modules/pattern_search/init.c 2008-05-29 17:39:54 UTC (rev 1246)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2004-2008, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id: init.c 1211 2007-09-26 15:01:49Z jsanjuas $
+ */
+
+#include "module.h"
+#include "data.h"
+
+config_t *
+init(mdl_t * self, hash_t * args)
+{
+ config_t *config;
+ int i;
+ /* pkt_t *pkt;
+ metadesc_t *inmd, *outmd; */
+ char *val;
+
+ config = mdl_alloc_config(self, config_t);
+ config->snaplen = SNAPLEN_MAX;
+
+ /* get config args */
+ if ((val = hash_lookup_string(args, "snaplen"))) {
+ config->snaplen = atoi(val); /* set the snaplen */
+ if (config->snaplen > SNAPLEN_MAX)
+ config->snaplen = SNAPLEN_MAX;
+ }
+
+ if ((val = hash_lookup_string(args, "pattern")))
+ config->pattern = val;
+
+ /* setup indesc */
+ /*inmd = metadesc_define_in(self, 0);
+ inmd->ts_resolution = TIME2TS(1, 0);
+
+ pkt = metadesc_tpl_add(inmd, "none:none:none:none");*/
+
+ /* setup outdesc */
+ /*outmd = metadesc_define_out(self, 0);
+
+ pkt = metadesc_tpl_add(outmd, "any:any:any:any");
+ COMO(caplen) = config->snaplen;*/
+
+ self->flush_ivl = TIME2TS(1, 0);
+
+ return config;
+}
+
Added: src/branches/2.0/modules/pattern_search/query.c
===================================================================
--- src/branches/2.0/modules/pattern_search/query.c (rev 0)
+++ src/branches/2.0/modules/pattern_search/query.c 2008-05-29 17:39:54 UTC (rev 1246)
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2004-2008, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id: query.c 1211 2007-09-26 15:01:49Z jsanjuas $
+ */
+
+#include <sys/types.h>
+#include <string.h> /* bcopy */
+#include <stdio.h> /* fprintf, stderr */
+
+#include "module.h"
+#include "data.h"
+#include "stdpkt.h" /* ethernet headers, etc. */
+#include "pcap.h" /* bpf_int32, etc. */
+#include "printpkt.h"
+
+#define PRETTYFMT 0
+#define PCAPFMT 1
+
+enum {
+ FORMAT_PRETTY,
+ FORMAT_PCAP
+};
+
+QUERY_FORMATS_BEGIN
+ { FORMAT_PRETTY, "pretty", "text/plain" },
+ { FORMAT_PCAP, "pcap", "application/binary" },
+QUERY_FORMATS_END
+
+DEFAULT_FORMAT = "pretty";
+
+char buffer[65536];
+
+void *
+qu_init(mdl_t *self, int format_id, hash_t *args)
+{
+ size_t len;
+
+ if (format_id == FORMAT_PCAP) {
+ len = print_pcap_file_header(buffer);
+ mdl_write(self, buffer, len);
+ }
+
+ return NULL;
+}
+
+void
+qu_finish(mdl_t *self, int format_id, void *state)
+{
+ /* nothing to do here */
+}
+
+void
+print_rec(mdl_t *self, int format_id, record_t *r, void * state)
+{
+ pkt_t *pkt = (pkt_t *) r->buf;
+ size_t len = 0;
+
+ /*
+ * we need to fix pkt->payload before using the pkt, as
+ * the pointer has changed. Using pointers inside the records
+ * does not work unless we can correct them.
+ */
+ pkt->payload = (char *)&r->buf[sizeof(pkt_t)];
+
+ switch(format_id) {
+ case FORMAT_PCAP:
+ len = print_pkt_pcap(pkt, buffer);
+ break;
+ case FORMAT_PRETTY:
+ len = print_pkt_pretty(pkt, buffer, PRINTPKT_L2 | PRINTPKT_L3);
+ len += sprintf(buffer + len, "\n");
+ break;
+ }
+
+ mdl_write(self, buffer, len);
+}
+
+
+void
+replay(mdl_t * self, record_t *r, void *state)
+{
+ mdl_write(self, (char *)r->buf, r->len);
+}
+
Modified: src/branches/2.0/modules/trace/query.c
===================================================================
--- src/branches/2.0/modules/trace/query.c 2008-05-29 00:25:39 UTC (rev 1245)
+++ src/branches/2.0/modules/trace/query.c 2008-05-29 17:39:54 UTC (rev 1246)
@@ -53,6 +53,8 @@
{ FORMAT_PCAP, "pcap", "application/binary" },
QUERY_FORMATS_END
+DEFAULT_FORMAT = "pretty";
+
char buffer[65536];
void *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|