From: Victor Julien Date: Tue, 17 Dec 2013 15:19:16 +0000 (+0100) Subject: stream: pass TcpSession to StreamTcpReassembleProcessAppLayer X-Git-Tag: suricata-2.0rc1~217 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d08a3ff26bb4af70db11d3246c563489b76dfe7;p=thirdparty%2Fsuricata.git stream: pass TcpSession to StreamTcpReassembleProcessAppLayer Preparation for removing flow pointer from StreamMsg. Instead of getting the ssn indirectly through StreamMsg->flow, we pass it directly as all callers have it already. --- diff --git a/src/app-layer.c b/src/app-layer.c index ad4c21aaeb..490df796dc 100644 --- a/src/app-layer.c +++ b/src/app-layer.c @@ -351,11 +351,20 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, SCReturnInt(r); } -int AppLayerHandleTCPMsg(StreamMsg *smsg) +/** + * \brief Attach a stream message to the TCP session for inspection + * in the detection engine. + * + * \param dp_ctx Thread app layer detect context + * \param smsg Stream message + * + * \retval 0 ok + * \retval -1 error + */ +int AppLayerHandleTCPMsg(StreamMsg *smsg, TcpSession *ssn) { SCEnter(); - TcpSession *ssn; StreamMsg *cur; #ifdef PRINT @@ -368,7 +377,6 @@ int AppLayerHandleTCPMsg(StreamMsg *smsg) SCLogDebug("smsg %p", smsg); BUG_ON(smsg->flow == NULL); - ssn = smsg->flow->protoctx; if (ssn != NULL) { SCLogDebug("storing smsg %p in the tcp session", smsg); diff --git a/src/app-layer.h b/src/app-layer.h index aabcc2d25a..a5e49d94c1 100644 --- a/src/app-layer.h +++ b/src/app-layer.h @@ -55,7 +55,7 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, * \retval 0 On success. * \retval -1 On failure. */ -int AppLayerHandleTCPMsg(StreamMsg *smsg); +int AppLayerHandleTCPMsg(StreamMsg *smsg, TcpSession *ssn); /** * \brief Handles an udp chunk. diff --git a/src/flow-timeout.c b/src/flow-timeout.c index ae815126b3..56c3832cdb 100644 --- a/src/flow-timeout.c +++ b/src/flow-timeout.c @@ -563,7 +563,7 @@ static inline void FlowForceReassemblyForHash(void) stt->ra_ctx, ssn, &ssn->server, reassemble_p, NULL); FlowDeReference(&reassemble_p->flow); - if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx, ssn) < 0) { SCLogDebug("shutdown flow timeout " "StreamTcpReassembleProcessAppLayer() erroring " "over something"); @@ -581,7 +581,7 @@ static inline void FlowForceReassemblyForHash(void) stt->ra_ctx, ssn, &ssn->client, reassemble_p, NULL); FlowDeReference(&reassemble_p->flow); - if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx, ssn) < 0) { SCLogDebug("shutdown flow timeout " "StreamTcpReassembleProcessAppLayer() erroring " "over something"); diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c index 6962530254..b942281f6a 100644 --- a/src/stream-tcp-reassemble.c +++ b/src/stream-tcp-reassemble.c @@ -3393,7 +3393,7 @@ int StreamTcpReassembleHandleSegmentUpdateACK (ThreadVars *tv, * \retval 0 ok * \retval -1 error */ -int StreamTcpReassembleProcessAppLayer(TcpReassemblyThreadCtx *ra_ctx) +int StreamTcpReassembleProcessAppLayer(TcpReassemblyThreadCtx *ra_ctx, TcpSession *ssn) { SCEnter(); @@ -3417,7 +3417,7 @@ int StreamTcpReassembleProcessAppLayer(TcpReassemblyThreadCtx *ra_ctx) /* Handle the stream msg. No need to use locking, flow is * already locked at this point. Don't break out of the * loop if we encounter an error. */ - if (AppLayerHandleTCPMsg(smsg) != 0) + if (AppLayerHandleTCPMsg(smsg, ssn) != 0) r = -1; } @@ -5281,7 +5281,7 @@ static int StreamTcpReassembleTest28 (void) { } /* Process stream smsgs we may have in queue */ - if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs (3): "); goto end; } @@ -5365,7 +5365,7 @@ static int StreamTcpReassembleTest29 (void) { } /* Process stream smsgs we may have in queue */ - if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs\n"); goto end; } @@ -5450,7 +5450,7 @@ static int StreamTcpReassembleTest30 (void) { } /* Process stream smsgs we may have in queue */ - if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs\n"); goto end; } @@ -5474,7 +5474,7 @@ static int StreamTcpReassembleTest30 (void) { } /* Process stream smsgs we may have in queue */ - if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs\n"); goto end; } @@ -6867,7 +6867,7 @@ static int StreamTcpReassembleTest40 (void) { } /* Process stream smsgs we may have in queue */ - if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs (4): "); goto end; } @@ -6914,7 +6914,7 @@ static int StreamTcpReassembleTest40 (void) { "been sent (8): "); goto end; /* Process stream smsgs we may have in queue */ - } else if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + } else if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs (9): "); goto end; } @@ -6953,7 +6953,7 @@ static int StreamTcpReassembleTest40 (void) { "been sent (12): "); goto end; /* Process stream smsgs we may have in queue */ - } else if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + } else if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs (13): "); goto end; } @@ -6993,7 +6993,7 @@ static int StreamTcpReassembleTest40 (void) { /* Process stream smsgs we may have in queue */ } - if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs (17): "); goto end; } @@ -7130,7 +7130,7 @@ static int StreamTcpReassembleTest43 (void) { printf("there should be a stream smsgs in the queue (6): "); goto end; /* Process stream smsgs we may have in queue */ - } else if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + } else if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs (7): "); goto end; } @@ -7184,7 +7184,7 @@ static int StreamTcpReassembleTest43 (void) { " been unpaused now (12): "); goto end; /* Process stream smsgs we may have in queue */ - } else if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + } else if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs (13): "); goto end; } @@ -7572,7 +7572,7 @@ static int StreamTcpReassembleTest47 (void) { } /* Process stream smsgs we may have in queue */ - if (StreamTcpReassembleProcessAppLayer(ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(ra_ctx, &ssn) < 0) { printf("failed in processing stream smsgs\n"); goto end; } diff --git a/src/stream-tcp-reassemble.h b/src/stream-tcp-reassemble.h index 888a050330..17a1f9913f 100644 --- a/src/stream-tcp-reassemble.h +++ b/src/stream-tcp-reassemble.h @@ -84,7 +84,7 @@ int StreamTcpReassembleInlineAppLayer(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, TcpSession *ssn, TcpStream *stream, Packet *p); -int StreamTcpReassembleProcessAppLayer(TcpReassemblyThreadCtx *); +int StreamTcpReassembleProcessAppLayer(TcpReassemblyThreadCtx *, TcpSession *); void StreamTcpCreateTestPacket(uint8_t *, uint8_t, uint8_t, uint8_t); diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 97178d66b1..03d61c1d32 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -4374,7 +4374,7 @@ int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt, } /* Process stream smsgs we may have in queue */ - if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx) < 0) { + if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx, ssn) < 0) { goto error; }