From 47071d2ef7539d89ec5bd6e24f65318dbdfb8281 Mon Sep 17 00:00:00 2001
From: Gurvinder Singh <gurvindersinghdahiya@gmail.com>
Date: Fri, 5 Feb 2010 11:19:08 +0100
Subject: [PATCH] bug 78

---
 src/app-layer-detect-proto.c |    6 +++---
 src/stream-tcp-reassemble.c  |   12 +++++++++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c
index de115b2..da1da4d 100644
--- a/src/app-layer-detect-proto.c
+++ b/src/app-layer-detect-proto.c
@@ -250,7 +250,7 @@ void AppLayerDetectProtoThreadInit(void) {
 }
 
 uint16_t AppLayerDetectGetProto(AlpProtoDetectCtx *ctx, AlpProtoDetectThreadCtx *tctx, uint8_t *buf, uint16_t buflen, uint8_t flags) {
-    //printf("AppLayerDetectGetProto: start\n");
+    SCEnter();
     //PrintRawDataFp(stdout, buf, buflen);
 
     //if (buflen < INSPECT_BYTES)
@@ -276,7 +276,7 @@ uint16_t AppLayerDetectGetProto(AlpProtoDetectCtx *ctx, AlpProtoDetectThreadCtx
 
     uint16_t proto;
     uint32_t cnt = mpm_table[dir->mpm_ctx.mpm_type].Scan(&dir->mpm_ctx, &tdir->mpm_ctx, &tdir->pmq, buf, scanlen);
-    //printf("AppLayerDetectGetProto: scan cnt %" PRIu32 "\n", cnt);
+    SCLogDebug("scan cnt %" PRIu32 "", cnt);
     if (cnt == 0) {
         proto = ALPROTO_UNKNOWN;
         goto end;
@@ -347,7 +347,7 @@ end:
             break;
     }
 #endif
-    return proto;
+    SCReturnInt(proto);
 }
 
 int AppLayerHandleMsg(AlpProtoDetectThreadCtx *dp_ctx, StreamMsg *smsg)
diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c
index 7102d58..9d6b152 100644
--- a/src/stream-tcp-reassemble.c
+++ b/src/stream-tcp-reassemble.c
@@ -1147,6 +1147,7 @@ int StreamTcpReassembleHandleSegmentHandleData(TcpSession *ssn,
 static void StreamTcpSetupMsg(TcpSession *ssn, TcpStream *stream, Packet *p,
                               StreamMsg *smsg)
 {
+    SCEnter();
     if (stream->ra_base_seq == stream->isn) {
         smsg->flags = STREAM_START;
     } else if (ssn->state > TCP_ESTABLISHED) {
@@ -1161,14 +1162,22 @@ static void StreamTcpSetupMsg(TcpSession *ssn, TcpStream *stream, Packet *p,
         COPY_PORT(p->flow->sp,smsg->data.src_port);
         COPY_PORT(p->flow->dp,smsg->data.dst_port);
 
-        smsg->flags |= STREAM_TOSERVER;
     } else {
         COPY_ADDRESS(&p->flow->dst,&smsg->data.src_ip);
         COPY_ADDRESS(&p->flow->src,&smsg->data.dst_ip);
         COPY_PORT(p->flow->dp,smsg->data.src_port);
         COPY_PORT(p->flow->sp,smsg->data.dst_port);
 
+    }
+
+    /* As we are opposing the stream to handle the ACK, we need to update the
+       smsg direction accordingly too */
+    if (stream == &ssn->client) {
+        smsg->flags |= STREAM_TOSERVER;
+        SCLogDebug("stream mesage is to_server");
+    } else {
         smsg->flags |= STREAM_TOCLIENT;
+        SCLogDebug("stream mesage is to_client");
     }
 
     smsg->data.data_len = 0;
@@ -1176,6 +1185,7 @@ static void StreamTcpSetupMsg(TcpSession *ssn, TcpStream *stream, Packet *p,
     if (smsg->flow != NULL) {
         smsg->flow->use_cnt++;
     }
+    SCReturn;
 }
 
 /** \brief Check the minimum size limits for reassembly.
-- 
1.6.0.4

