From 7a17b4acf5029573013336435720d50346bb5243 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Fri, 12 May 2017 20:22:35 +0200 Subject: [PATCH] stream-tcp: use flags field to store inline info --- src/stream-tcp-inline.c | 14 -------------- src/stream-tcp-inline.h | 1 - src/stream-tcp-util.c | 6 ++---- src/stream-tcp.c | 37 ++++++++++++++++++++++++------------- src/stream-tcp.h | 2 ++ 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/stream-tcp-inline.c b/src/stream-tcp-inline.c index 3c1909fb73..d79723dd51 100644 --- a/src/stream-tcp-inline.c +++ b/src/stream-tcp-inline.c @@ -33,20 +33,6 @@ #include "util-unittest.h" #include "util-unittest-helper.h" -/** defined in stream-tcp-reassemble.c */ -extern int stream_inline; - -/** - * \brief See if stream engine is operating in inline mode - * - * \retval 0 no - * \retval 1 yes - */ -int StreamTcpInlineMode(void) -{ - return stream_inline; -} - /** * \brief Compare the shared data portion of two segments * diff --git a/src/stream-tcp-inline.h b/src/stream-tcp-inline.h index ad37d25143..0f4e7fddac 100644 --- a/src/stream-tcp-inline.h +++ b/src/stream-tcp-inline.h @@ -26,7 +26,6 @@ #include "stream-tcp-private.h" -int StreamTcpInlineMode(void); int StreamTcpInlineSegmentCompare(TcpStream *, Packet *, TcpSegment *); void StreamTcpInlineSegmentReplacePacket(TcpStream *, Packet *, TcpSegment *); diff --git a/src/stream-tcp-util.c b/src/stream-tcp-util.c index a41a5d415e..b10b94ddc2 100644 --- a/src/stream-tcp-util.c +++ b/src/stream-tcp-util.c @@ -40,8 +40,6 @@ /* unittest helper functions */ -extern int stream_inline; - void StreamTcpUTInit(TcpReassemblyThreadCtx **ra_ctx) { StreamTcpInitConfig(TRUE); @@ -52,11 +50,11 @@ void StreamTcpUTDeinit(TcpReassemblyThreadCtx *ra_ctx) { StreamTcpReassembleFreeThreadCtx(ra_ctx); StreamTcpFreeConfig(TRUE); - stream_inline = 0; + stream_config.flags &= ~STREAMTCP_INIT_FLAG_INLINE; } void StreamTcpUTInitInline(void) { - stream_inline = 1; + stream_config.flags |= STREAMTCP_INIT_FLAG_INLINE; } void StreamTcpUTSetupSession(TcpSession *ssn) diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 0f205756a9..32d95ea71d 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -115,9 +115,6 @@ static uint64_t ssn_pool_cnt = 0; /** counts ssns, protected by ssn_pool_mutex * uint64_t StreamTcpReassembleMemuseGlobalCounter(void); SC_ATOMIC_DECLARE(uint64_t, st_memuse); -/* stream engine running in "inline" mode. */ -int stream_inline = 0; - void StreamTcpInitMemuse(void) { SC_ATOMIC_INIT(st_memuse); @@ -309,7 +306,8 @@ static void StreamTcpSessionPoolCleanup(void *s) */ int StreamTcpInlineDropInvalid(void) { - return (stream_inline && (stream_config.flags & STREAMTCP_INIT_FLAG_DROP_INVALID)); + return ((stream_config.flags & STREAMTCP_INIT_FLAG_INLINE) + && (stream_config.flags & STREAMTCP_INIT_FLAG_DROP_INVALID)); } /** \brief To initialize the stream global configuration data @@ -405,24 +403,24 @@ void StreamTcpInitConfig(char quiet) * backward compatibility */ if (strcmp(temp_stream_inline_str, "auto") == 0) { if (EngineModeIsIPS()) { - stream_inline = 1; - } else { - stream_inline = 0; + stream_config.flags |= STREAMTCP_INIT_FLAG_INLINE; } } else if (ConfGetBool("stream.inline", &inl) == 1) { - stream_inline = inl; + if (inl) { + stream_config.flags |= STREAMTCP_INIT_FLAG_INLINE; + } } } else { /* default to 'auto' */ if (EngineModeIsIPS()) { - stream_inline = 1; - } else { - stream_inline = 0; + stream_config.flags |= STREAMTCP_INIT_FLAG_INLINE; } } if (!quiet) { - SCLogConfig("stream.\"inline\": %s", stream_inline ? "enabled" : "disabled"); + SCLogConfig("stream.\"inline\": %s", + stream_config.flags & STREAMTCP_INIT_FLAG_INLINE + ? "enabled" : "disabled"); } int bypass = 0; @@ -5898,7 +5896,8 @@ int StreamTcpSegmentForEach(const Packet *p, uint8_t flag, StreamSegmentCallback /* for IDS, return ack'd segments. For IPS all. */ TcpSegment *seg = stream->seg_list; for (; seg != NULL && - (stream_inline || SEQ_LT(seg->seq, stream->last_ack));) + ((stream_config.flags & STREAMTCP_INIT_FLAG_INLINE) + || SEQ_LT(seg->seq, stream->last_ack));) { const uint8_t *seg_data; uint32_t seg_datalen; @@ -5920,6 +5919,18 @@ int StreamTcpBypassEnabled(void) return (stream_config.flags & STREAMTCP_INIT_FLAG_BYPASS); } +/** + * \brief See if stream engine is operating in inline mode + * + * \retval 0 no + * \retval 1 yes + */ +int StreamTcpInlineMode(void) +{ + return (stream_config.flags & STREAMTCP_INIT_FLAG_INLINE) ? 1 : 0; +} + + void TcpSessionSetReassemblyDepth(TcpSession *ssn, uint32_t size) { if (size > ssn->reassembly_depth || size == 0) { diff --git a/src/stream-tcp.h b/src/stream-tcp.h index 620059d92b..24d41e9640 100644 --- a/src/stream-tcp.h +++ b/src/stream-tcp.h @@ -36,6 +36,7 @@ #define STREAMTCP_INIT_FLAG_CHECKSUM_VALIDATION BIT_U8(0) #define STREAMTCP_INIT_FLAG_DROP_INVALID BIT_U8(1) #define STREAMTCP_INIT_FLAG_BYPASS BIT_U8(2) +#define STREAMTCP_INIT_FLAG_INLINE BIT_U8(3) /*global flow data*/ typedef struct TcpStreamCnf_ { @@ -213,6 +214,7 @@ void StreamTcpStreamCleanup(TcpStream *stream); /* check if bypass is enabled */ int StreamTcpBypassEnabled(void); int StreamTcpInlineDropInvalid(void); +int StreamTcpInlineMode(void); int TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, const void *tcp_ssn);