From 9e1470d81c79677b689a0fc4b570d20232953dad Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 17 Mar 2016 10:08:00 +0100 Subject: [PATCH] stream-tcp: StreamTcpUTAddPayload unittest helper --- src/stream-tcp-reassemble.h | 2 ++ src/stream-tcp-util.c | 17 +++++++++++++++++ src/stream-tcp-util.h | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/stream-tcp-reassemble.h b/src/stream-tcp-reassemble.h index b6e798ce0b..0dcea133bf 100644 --- a/src/stream-tcp-reassemble.h +++ b/src/stream-tcp-reassemble.h @@ -88,6 +88,8 @@ void StreamTcpReassemblePause (TcpSession *, char ); void StreamTcpReassembleUnPause (TcpSession *, char ); int StreamTcpCheckStreamContents(uint8_t *, uint16_t , TcpStream *); +int StreamTcpReassembleHandleSegmentHandleData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, + TcpSession *ssn, TcpStream *stream, Packet *p); int StreamTcpReassembleInsertSegment(ThreadVars *, TcpReassemblyThreadCtx *, TcpStream *, TcpSegment *, Packet *); TcpSegment* StreamTcpGetSegment(ThreadVars *, TcpReassemblyThreadCtx *, uint16_t); diff --git a/src/stream-tcp-util.c b/src/stream-tcp-util.c index b58db5c283..bdd5d7327f 100644 --- a/src/stream-tcp-util.c +++ b/src/stream-tcp-util.c @@ -84,6 +84,23 @@ void StreamTcpUTClearStream(TcpStream *s) StreamTcpStreamCleanup(s); } +/** \brief wrapper for StreamTcpReassembleHandleSegmentHandleData */ +int StreamTcpUTAddPayload(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, TcpSession *ssn, TcpStream *stream, uint32_t seq, uint8_t *payload, uint16_t len) +{ + Packet *p = UTHBuildPacketReal(payload, len, IPPROTO_TCP, "1.1.1.1", "2.2.2.2", 1024, 80); + if (p == NULL) { + return -1; + } + p->tcph->th_seq = htonl(seq); + p->tcph->th_ack = htonl(31); + + if (StreamTcpReassembleHandleSegmentHandleData(tv, ra_ctx, ssn, stream, p) < 0) + return -1; + + UTHFreePacket(p); + return 0; +} + int StreamTcpUTAddSegmentWithPayload(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, TcpStream *stream, uint32_t seq, uint8_t *payload, uint16_t len) { TcpSegment *s = StreamTcpGetSegment(tv, ra_ctx, len); diff --git a/src/stream-tcp-util.h b/src/stream-tcp-util.h index 72f2b4fcb9..8067d5ac4c 100644 --- a/src/stream-tcp-util.h +++ b/src/stream-tcp-util.h @@ -39,7 +39,7 @@ void StreamTcpUTClearStream(TcpStream *); int StreamTcpUTAddSegmentWithByte(ThreadVars *, TcpReassemblyThreadCtx *, TcpStream *, uint32_t, uint8_t, uint16_t); int StreamTcpUTAddSegmentWithPayload(ThreadVars *, TcpReassemblyThreadCtx *, TcpStream *, uint32_t, uint8_t *, uint16_t); - +int StreamTcpUTAddPayload(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, TcpSession *ssn, TcpStream *stream, uint32_t seq, uint8_t *payload, uint16_t len); void StreamTcpUtilRegisterTests(void);