From ba7e8012af25dd35b33477a94c8e0edce8249c69 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sun, 20 Dec 2009 15:36:53 +0100 Subject: [PATCH] Add some debugging and simplify locking for app layer slightly. --- src/app-layer-htp.c | 7 ++++++- src/app-layer-parser.c | 20 +++++++++++--------- src/flow.c | 16 ++++++++-------- src/tm-threads.c | 8 ++++---- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index b0f80fb8bf..fa3e850233 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -114,9 +114,13 @@ static int HTPHandleRequestData(Flow *f, void *htp_state, HtpState *hstate = (HtpState *)htp_state; /* Open the HTTP connection on receiving the first request */ - if (! (hstate->flags & HTP_FLAG_STATE_OPEN)) { + if (!(hstate->flags & HTP_FLAG_STATE_OPEN)) { + SCLogDebug("opening htp handle"); + htp_connp_open(hstate->connp, NULL, f->sp, NULL, f->dp, 0); hstate->flags |= HTP_FLAG_STATE_OPEN; + } else { + SCLogDebug("using existing htp handle"); } if (htp_connp_req_data(hstate->connp, 0, input, input_len) == @@ -136,6 +140,7 @@ static int HTPHandleRequestData(Flow *f, void *htp_state, { htp_connp_close(hstate->connp, 0); hstate->flags |= HTP_FLAG_STATE_CLOSED; + SCLogDebug("stream eof encountered, closing htp handle"); } SCReturnInt(1); diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index a6d165e603..603f961bf9 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -719,6 +719,8 @@ int AppLayerParse(Flow *f, uint8_t proto, uint8_t flags, uint8_t *input, AppLayerParserState *parser_state = NULL; if (flags & STREAM_TOSERVER) { + SCLogDebug("to_server msg"); + parser_state = &parser_state_store->to_server; if (!(parser_state->flags & APP_LAYER_PARSER_USE)) { parser_idx = p->to_server; @@ -730,6 +732,8 @@ int AppLayerParse(Flow *f, uint8_t proto, uint8_t flags, uint8_t *input, parser_idx = parser_state->cur_parser; } } else { + SCLogDebug("to_client msg"); + parser_state = &parser_state_store->to_client; if (!(parser_state->flags & APP_LAYER_PARSER_USE)) { parser_idx = p->to_client; @@ -774,30 +778,23 @@ int AppLayerParse(Flow *f, uint8_t proto, uint8_t flags, uint8_t *input, /* set the packets to no inspection and reassembly for the TLS sessions */ if (parser_state->flags & APP_LAYER_PARSER_NO_INSPECTION) { - if (need_lock == TRUE) SCMutexLock(&f->m); + FlowSetNoPayloadInspectionFlag(f); - if (need_lock == TRUE) SCMutexUnlock(&f->m); /* Set the no reassembly flag for both the stream in this TcpSession */ if (parser_state->flags & APP_LAYER_PARSER_NO_REASSEMBLY) { - if (need_lock == TRUE) SCMutexLock(&f->m); StreamTcpSetSessionNoReassemblyFlag(ssn, flags & STREAM_TOCLIENT ? 1 : 0); StreamTcpSetSessionNoReassemblyFlag(ssn, flags & STREAM_TOSERVER ? 1 : 0); - if (need_lock == TRUE) SCMutexUnlock(&f->m); } + if (need_lock == TRUE) SCMutexUnlock(&f->m); } SCReturnInt(0); error: if (ssn != NULL) { - char src[16]; - char dst[16]; - char dst6[46]; - char src6[46]; - /* Clear the app layer protocol state memory and the given function also * cleans the parser state memory */ AppLayerParserCleanupState(ssn); @@ -808,6 +805,8 @@ error: StreamTcpSetSessionNoReassemblyFlag(ssn, flags & STREAM_TOSERVER ? 1 : 0); if (f->src.family == AF_INET) { + char src[16]; + char dst[16]; inet_ntop(AF_INET, (const void*)&f->src.addr_data32[0], src, sizeof (src)); inet_ntop(AF_INET, (const void*)&f->dst.addr_data32[0], dst, @@ -820,6 +819,9 @@ error: f->proto, src, dst, f->sp, f->dp); } else { + char dst6[46]; + char src6[46]; + inet_ntop(AF_INET6, (const void*)&f->src.addr_data32, src6, sizeof (src6)); inet_ntop(AF_INET6, (const void*)&f->dst.addr_data32, dst6, diff --git a/src/flow.c b/src/flow.c index f553712ed0..e8a9837c2c 100644 --- a/src/flow.c +++ b/src/flow.c @@ -106,22 +106,22 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts) { int mr = SCMutexTrylock(&q->mutex_q); if (mr != 0) { - SCLogDebug("Trylock failed!\n"); + SCLogDebug("trylock failed"); if (mr == EBUSY) - SCLogDebug("Was locked!\n"); + SCLogDebug("was locked"); if (mr == EINVAL) - SCLogDebug("Bad mutex value!\n"); + SCLogDebug("bad mutex value"); return 0; } Flow *f = q->top; if (f == NULL) { SCMutexUnlock(&q->mutex_q); - SCLogDebug("top was null!\n"); + SCLogDebug("top is null"); return 0; } if (SCMutexTrylock(&f->m) != 0) { - SCLogDebug("cant lock 1!\n"); + SCLogDebug("cant lock 1"); SCMutexUnlock(&q->mutex_q); return 0; } @@ -131,7 +131,7 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts) if (SCMutexTrylock(&f->fb->m) != 0) { SCMutexUnlock(&f->m); - SCLogDebug("cant lock 2!\n"); + SCLogDebug("cant lock 2"); return 0; } @@ -186,7 +186,7 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts) if ((f->lastts.tv_sec + timeout) >= ts->tv_sec) { SCMutexUnlock(&f->fb->m); SCMutexUnlock(&f->m); - SCLogDebug("timeout check failed!\n"); + SCLogDebug("timeout check failed"); return 0; } @@ -196,7 +196,7 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts) SCLogDebug("timed out but use_cnt > 0: %"PRIu16", %p, proto %"PRIu8"", f->use_cnt, f, f->proto); SCMutexUnlock(&f->fb->m); SCMutexUnlock(&f->m); - SCLogDebug("it is in one of the threads!\n"); + SCLogDebug("it is in one of the threads"); return 0; } diff --git a/src/tm-threads.c b/src/tm-threads.c index 003bca83b9..3c0ae4bc76 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -830,7 +830,7 @@ void TmThreadKillThreads(void) { int cnt = 0; while (1) { if (TmThreadsCheckFlag(tv, THV_CLOSED)) { - SCLogDebug("signalled the thread %" PRId32 " times\n", cnt); + SCLogDebug("signalled the thread %" PRId32 " times", cnt); break; } @@ -842,14 +842,14 @@ void TmThreadKillThreads(void) { usleep(100); } - SCLogDebug("signalled tv->inq->id %" PRIu32 "\n", tv->inq->id); + SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id); } if (tv->cond != NULL ) { int cnt = 0; while (1) { if (TmThreadsCheckFlag(tv, THV_CLOSED)) { - SCLogDebug("signalled the thread %" PRId32 " times\n", cnt); + SCLogDebug("signalled the thread %" PRId32 " times", cnt); break; } @@ -863,7 +863,7 @@ void TmThreadKillThreads(void) { /* join it */ pthread_join(tv->t, NULL); - SCLogDebug("thread %s stopped\n", tv->name); + SCLogDebug("thread %s stopped", tv->name); tv = tv->next; }