|
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.
|