]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream-tcp: use flags field to store inline info
authorEric Leblond <eric@regit.org>
Fri, 12 May 2017 18:22:35 +0000 (20:22 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 6 Jun 2017 14:26:31 +0000 (16:26 +0200)
src/stream-tcp-inline.c
src/stream-tcp-inline.h
src/stream-tcp-util.c
src/stream-tcp.c
src/stream-tcp.h

index 3c1909fb73cee050c088ee0995820db221c99265..d79723dd5141631330623e41678415c199a4b2ef 100644 (file)
 #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
  *
index ad37d25143522ade6a1f75be7144d1b1127cec33..0f4e7fddacc48e6268312a6355f423250d0c2133 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "stream-tcp-private.h"
 
-int StreamTcpInlineMode(void);
 int StreamTcpInlineSegmentCompare(TcpStream *, Packet *, TcpSegment *);
 void StreamTcpInlineSegmentReplacePacket(TcpStream *, Packet *, TcpSegment *);
 
index a41a5d415e2f6af5ae406edf55728c62c68b0f39..b10b94ddc20a4d62ebf97aef36a399e9f2634db3 100644 (file)
@@ -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)
index 0f205756a94b2b75981d847681fe32c094cca6e8..32d95ea71da4d47beccdac730dbaaf9155bd75d8 100644 (file)
@@ -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) {
index 620059d92ba4aea078ff8f4f66ef83c9aca49a47..24d41e96409ff62567f2f2e52a57cd485d864dc0 100644 (file)
@@ -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);