First batch of fixes for new debug and logging API usage.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent 8069fc759b
commit f4acd5a27e

@ -17,8 +17,6 @@
#include "alert-unified2-alert.h" #include "alert-unified2-alert.h"
#include "decode-ipv4.h" #include "decode-ipv4.h"
#define DEBUG
/*prototypes*/ /*prototypes*/
int Unified2Alert (ThreadVars *, Packet *, void *, PacketQueue *); int Unified2Alert (ThreadVars *, Packet *, void *, PacketQueue *);
int Unified2AlertThreadInit(ThreadVars *, void *, void **); int Unified2AlertThreadInit(ThreadVars *, void *, void **);

@ -1042,7 +1042,7 @@ int PerfOutputCounterFileIface()
fprintf(perf_op_ctx->fp, "%-25s | %-25s | %-" PRIu64 "\n", fprintf(perf_op_ctx->fp, "%-25s | %-25s | %-" PRIu64 "\n",
pc->name->cname, pc->name->tm_name, *ui64_cvalue); pc->name->cname, pc->name->tm_name, *ui64_cvalue);
#ifdef DEBUG #ifdef DEBUG
printf("%-10" PRIuMAX " %-10" PRIu16 " %-10s %-" PRIu64 "\n", pc->name->tid, pc->id, printf("%-10" PRIuMAX " %-10" PRIu16 " %-10s %-" PRIu64 "\n", (uintmax_t)pc->name->tid, pc->id,
pc->name->cname, *ui64_cvalue); pc->name->cname, *ui64_cvalue);
#endif #endif
pc = pc->next; pc = pc->next;

@ -6,6 +6,7 @@
#include "decode-events.h" #include "decode-events.h"
#include "util-unittest.h" #include "util-unittest.h"
#include "util-debug.h"
void DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq) void DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
{ {
@ -20,9 +21,7 @@ void DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *p
if (ethh == NULL) if (ethh == NULL)
return; return;
#ifdef DEBUG SCDebug("p %p pkt %p ether type %04x", p, pkt, ntohs(ethh->eth_type));
printf("DecodeEthernet: p %p pkt %p ether type %04x\n", p, pkt, ntohs(ethh->eth_type));
#endif
if (ntohs(ethh->eth_type) == ETHERNET_TYPE_IP) { if (ntohs(ethh->eth_type) == ETHERNET_TYPE_IP) {
//printf("DecodeEthernet ip4\n"); //printf("DecodeEthernet ip4\n");

@ -408,7 +408,7 @@ void DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
#ifdef DEBUG #ifdef DEBUG
if (IPV6_EXTHDR_ISSET_FH(p)) { if (IPV6_EXTHDR_ISSET_FH(p)) {
printf("IPV6 FRAG - HDRLEN: %" PRIuMAX " NH: %" PRIu32 " OFFSET: %" PRIu32 " ID: %" PRIu32 "\n", printf("IPV6 FRAG - HDRLEN: %" PRIuMAX " NH: %" PRIu32 " OFFSET: %" PRIu32 " ID: %" PRIu32 "\n",
IPV6_EXTHDR_GET_FH_HDRLEN(p), IPV6_EXTHDR_GET_FH_NH(p), (uintmax_t)IPV6_EXTHDR_GET_FH_HDRLEN(p), IPV6_EXTHDR_GET_FH_NH(p),
IPV6_EXTHDR_GET_FH_OFFSET(p), IPV6_EXTHDR_GET_FH_ID(p)); IPV6_EXTHDR_GET_FH_OFFSET(p), IPV6_EXTHDR_GET_FH_ID(p));
} }
if (IPV6_EXTHDR_ISSET_RH(p)) { if (IPV6_EXTHDR_ISSET_RH(p)) {

@ -4,6 +4,7 @@
#include "eidps-common.h" #include "eidps-common.h"
#include "decode.h" #include "decode.h"
#include "util-debug.h"
void DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq) void DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
{ {
@ -16,7 +17,7 @@ void DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
case IPPROTO_IPV6: case IPPROTO_IPV6:
return DecodeIPV6(tv, dtv, p, pkt, len, pq); return DecodeIPV6(tv, dtv, p, pkt, len, pq);
default: default:
printf("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.\n", p->tunnel_proto); SCInfo("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.", p->tunnel_proto);
break; break;
} }
} }

@ -71,6 +71,9 @@
#include "runmodes.h" #include "runmodes.h"
#include "util-debug.h" #include "util-debug.h"
#include "util-debug.h"
#include "util-error.h"
/* /*
* we put this here, because we only use it here in main. * we put this here, because we only use it here in main.
*/ */
@ -249,6 +252,9 @@ int main(int argc, char **argv)
char *conf_filename = NULL; char *conf_filename = NULL;
int dump_config = 0; int dump_config = 0;
/* initialize the logging subsys */
SCLogInitLogModule(NULL);
/* Initialize the configuration module. */ /* Initialize the configuration module. */
ConfInit(); ConfInit();

@ -9,7 +9,6 @@
*/ */
#include "eidps-common.h" #include "eidps-common.h"
#include "debug.h"
#include "decode.h" #include "decode.h"
#include "threads.h" #include "threads.h"
#include "tm-modules.h" #include "tm-modules.h"
@ -26,6 +25,8 @@
#include "flow-private.h" #include "flow-private.h"
#include "util-unittest.h" #include "util-unittest.h"
#include "util-debug.h"
//#define FLOW_DEFAULT_HASHSIZE 262144 //#define FLOW_DEFAULT_HASHSIZE 262144
#define FLOW_DEFAULT_HASHSIZE 65536 #define FLOW_DEFAULT_HASHSIZE 65536
//#define FLOW_DEFAULT_MEMCAP 128 * 1024 * 1024 /* 128 MB */ //#define FLOW_DEFAULT_MEMCAP 128 * 1024 * 1024 /* 128 MB */
@ -170,8 +171,8 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts)
} }
} }
DEBUGPRINT("got lock, now check: %" PRId64 "+%" PRIu32 "=(%" PRId64 ") < %" PRId64 "", f->lastts.tv_sec, SCDebug("got lock, now check: %" PRIdMAX "+%" PRIu32 "=(%" PRIdMAX ") < %" PRIdMAX "", (intmax_t)f->lastts.tv_sec,
timeout, f->lastts.tv_sec + timeout, ts->tv_sec); timeout, (intmax_t)f->lastts.tv_sec + timeout, (intmax_t)ts->tv_sec);
/* do the timeout check */ /* do the timeout check */
if ((f->lastts.tv_sec + timeout) >= ts->tv_sec) { if ((f->lastts.tv_sec + timeout) >= ts->tv_sec) {
@ -183,15 +184,12 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts)
/** never prune a flow that is used by a packet or stream msg /** never prune a flow that is used by a packet or stream msg
* we are currently processing in one of the threads */ * we are currently processing in one of the threads */
if (f->use_cnt > 0) { if (f->use_cnt > 0) {
printf("FlowPrune: timed out but use_cnt > 0: %"PRIu16", %p, proto %"PRIu8"\n", f->use_cnt, f, f->proto); SCDebug("timed out but use_cnt > 0: %"PRIu16", %p, proto %"PRIu8"", f->use_cnt, f, f->proto);
mutex_unlock(&f->fb->m); mutex_unlock(&f->fb->m);
mutex_unlock(&f->m); mutex_unlock(&f->m);
return 0; return 0;
} }
//printf("timed out %" PRIuMAX "+%" PRIu32 "=(%" PRIuMAX ") < %" PRIuMAX ": %p, proto %"PRIu8"\n", (uintmax_t)f->lastts.tv_sec,
// timeout, (uintmax_t)(f->lastts.tv_sec + timeout), (uintmax_t)ts->tv_sec, f, f->proto);
/* remove from the hash */ /* remove from the hash */
if (f->hprev) if (f->hprev)
f->hprev->hnext = f->hnext; f->hprev->hnext = f->hnext;
@ -515,7 +513,7 @@ void *FlowManagerThread(void *td)
/* Get the time */ /* Get the time */
memset(&ts, 0, sizeof(ts)); memset(&ts, 0, sizeof(ts));
TimeGet(&ts); TimeGet(&ts);
DEBUGPRINT("ts %" PRId64 "", ts.tv_sec); SCDebug("ts %" PRIdMAX "", (intmax_t)ts.tv_sec);
/* see if we still have enough spare flows */ /* see if we still have enough spare flows */
FlowUpdateSpareFlows(); FlowUpdateSpareFlows();
@ -525,21 +523,21 @@ void *FlowManagerThread(void *td)
/* prune closing list */ /* prune closing list */
nowcnt = FlowPruneFlows(&flow_close_q[i], &ts); nowcnt = FlowPruneFlows(&flow_close_q[i], &ts);
if (nowcnt) { if (nowcnt) {
DEBUGPRINT("Pruned %" PRIu32 " closing flows...\n", nowcnt); SCDebug("Pruned %" PRIu32 " closing flows...", nowcnt);
closing_cnt += nowcnt; closing_cnt += nowcnt;
} }
/* prune new list */ /* prune new list */
nowcnt = FlowPruneFlows(&flow_new_q[i], &ts); nowcnt = FlowPruneFlows(&flow_new_q[i], &ts);
if (nowcnt) { if (nowcnt) {
DEBUGPRINT("Pruned %" PRIu32 " new flows...\n", nowcnt); SCDebug("Pruned %" PRIu32 " new flows...", nowcnt);
new_cnt += nowcnt; new_cnt += nowcnt;
} }
/* prune established list */ /* prune established list */
nowcnt = FlowPruneFlows(&flow_est_q[i], &ts); nowcnt = FlowPruneFlows(&flow_est_q[i], &ts);
if (nowcnt) { if (nowcnt) {
DEBUGPRINT("Pruned %" PRIu32 " established flows...\n", nowcnt); SCDebug("Pruned %" PRIu32 " established flows...", nowcnt);
established_cnt += nowcnt; established_cnt += nowcnt;
} }
} }

@ -146,6 +146,7 @@ static inline void SCLogPrintToStream(FILE *fd, char *msg)
if (fprintf(fd, "%s", msg) < 0) if (fprintf(fd, "%s", msg) < 0)
printf("Error writing to stream using fprintf\n"); printf("Error writing to stream using fprintf\n");
fflush(fd);
return; return;
} }

@ -3,8 +3,7 @@
#include "eidps-common.h" #include "eidps-common.h"
#include "detect.h" #include "detect.h"
#include "threads.h" #include "threads.h"
#include "util-debug.h"
//#define DEBUG
static struct timeval current_time = { 0,0 }; static struct timeval current_time = { 0,0 };
static pthread_mutex_t current_time_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t current_time_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -12,10 +11,12 @@ static char live = TRUE;
void TimeModeSetLive(void) { void TimeModeSetLive(void) {
live = TRUE; live = TRUE;
SCDebug("live time mode enabled");
} }
void TimeModeSetOffline (void) { void TimeModeSetOffline (void) {
live = FALSE; live = FALSE;
SCDebug("offline time mode enabled");
} }
void TimeSet(struct timeval *tv) { void TimeSet(struct timeval *tv) {
@ -29,10 +30,8 @@ void TimeSet(struct timeval *tv) {
current_time.tv_sec = tv->tv_sec; current_time.tv_sec = tv->tv_sec;
current_time.tv_usec = tv->tv_usec; current_time.tv_usec = tv->tv_usec;
#ifdef DEBUG SCDebug("time set to %" PRIuMAX " sec, %" PRIuMAX " usec",
printf("TimeSet: time set to %" PRIuMAX " sec, %" PRIuMAX " usec\n",
(uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec); (uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec);
#endif
mutex_unlock(&current_time_mutex); mutex_unlock(&current_time_mutex);
} }
@ -50,9 +49,7 @@ void TimeGet(struct timeval *tv) {
mutex_unlock(&current_time_mutex); mutex_unlock(&current_time_mutex);
} }
#ifdef DEBUG SCDebug("time we got is %" PRIuMAX " sec, %" PRIuMAX " usec",
printf("TimeGet: time we got is %" PRIuMAX " sec, %" PRIuMAX " usec\n",
(uintmax_t)tv->tv_sec, (uintmax_t)tv->tv_usec); (uintmax_t)tv->tv_sec, (uintmax_t)tv->tv_usec);
#endif
} }

Loading…
Cancel
Save