]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1836 in SNORT/snort3 from ~DAVMCPHE/snort3:stream_tcp_tsm_tsan_pa...
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 13 Nov 2019 00:04:27 +0000 (19:04 -0500)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 13 Nov 2019 00:04:27 +0000 (19:04 -0500)
Squashed commit of the following:

commit bc8abc4b89ad76dbf294cc5e09c4d643d19607d8
Author: davis mcpherson <davmcphe@cisco.com>
Date:   Wed Nov 6 11:40:38 2019 -0500

    stream_tcp: initialize tcp state machine instance in the stream_tcp plugin init method to ensure
    it is created before the packet threads are started.  in addition the state machine is deleted
    in the stream_tcp plugin term method to free up allocated memory before snort exits.

src/stream/libtcp/tcp_state_machine.cc
src/stream/libtcp/tcp_state_machine.h
src/stream/tcp/stream_tcp.cc
src/stream/tcp/tcp_stream_state_machine.cc
src/stream/tcp/tcp_stream_state_machine.h

index a8bbdd6533d6ec9554d256428e02811fa255ce2a..43943617f199426b55015a9910521f8f752f038a 100644 (file)
@@ -40,7 +40,7 @@ TcpStateMachine::~TcpStateMachine()
 void TcpStateMachine::register_state_handler(TcpStreamTracker::TcpState state,
     TcpStateHandler& handler)
 {
-    delete tcp_state_handlers[ state ];
+    assert( !tcp_state_handlers[ state ]);
     tcp_state_handlers[ state ] = &handler;
 }
 
index 9812dabfc7f4894a86ae3c98e254e79d45706e27..d32ceb944adfc14b335b28ac52892d70acf5f4ff 100644 (file)
@@ -16,7 +16,7 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 
-// tcp_state_machine.h author davis mcpherson <davmcphe@@cisco.com>
+// tcp_state_machine.h author davis mcpherson <davmcphe@cisco.com>
 // Created on: Jul 29, 2015
 
 #ifndef TCP_STATE_MACHINE_H
index 8dedb1960d66e9e22f42b1e2945779068e0d949d..847b33ec57dbf65f650399c01554a6d93daae91d 100644 (file)
@@ -27,6 +27,7 @@
 #include "tcp_ha.h"
 #include "tcp_module.h"
 #include "tcp_session.h"
+#include "tcp_stream_state_machine.h"
 
 using namespace snort;
 
@@ -42,7 +43,6 @@ public:
 
     void show(SnortConfig*) override;
     bool configure(SnortConfig*) override;
-
     void tinit() override;
     void tterm() override;
 
@@ -55,14 +55,10 @@ public:
 StreamTcp::StreamTcp (TcpStreamConfig* c) : config(c) {}
 
 StreamTcp::~StreamTcp()
-{
-    delete config;
-}
+{ delete config; }
 
 void StreamTcp::show(SnortConfig*)
-{
-    TcpStreamConfig::show_config(config);
-}
+{ TcpStreamConfig::show_config(config); }
 
 bool StreamTcp::configure(SnortConfig* sc)
 {
@@ -111,14 +107,16 @@ static Inspector* tcp_ctor(Module* m)
 }
 
 static void tcp_dtor(Inspector* p)
-{
-    delete p;
-}
+{ delete p; }
+
+static void stream_tcp_pinit()
+{ TcpStreamStateMachine::initialize(); }
+
+static void stream_tcp_pterm()
+{ TcpStreamStateMachine::finalize(); }
 
 static Session* tcp_ssn(Flow* lws)
-{
-    return new TcpSession(lws);
-}
+{ return new TcpSession(lws); }
 
 static const InspectApi tcp_api =
 {
@@ -138,8 +136,8 @@ static const InspectApi tcp_api =
     PROTO_BIT__TCP,
     nullptr,  // buffers
     nullptr,  // service
-    nullptr,  // init
-    nullptr,  // term
+    stream_tcp_pinit,  // pinit
+    stream_tcp_pterm,  // pterm
     nullptr,  // tinit,
     nullptr,  // tterm,
     tcp_ctor,
index b4b652877a3f6db3fbf8e1b33c522869ec4e919e..cd87ba076781c96ca3ea271337892d4b0b684605 100644 (file)
@@ -16,7 +16,7 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 
-// tcp_stream_state_machine.cc author davis mcpherson <davmcphe@@cisco.com>
+// tcp_stream_state_machine.cc author davis mcpherson <davmcphe@cisco.com>
 // Created on: Apr 1, 2016
 
 #ifdef HAVE_CONFIG_H
 #include "tcp_state_last_ack.h"
 #include "tcp_state_time_wait.h"
 
+TcpStreamStateMachine* TcpStreamStateMachine::tsm = nullptr;
+
+TcpStateMachine* TcpStreamStateMachine::initialize()
+{
+    assert(!tsm);
+    TcpStreamStateMachine::tsm = new TcpStreamStateMachine();
+    return TcpStreamStateMachine::tsm;
+}
+
+void TcpStreamStateMachine::finalize()
+{
+    delete TcpStreamStateMachine::tsm;
+    TcpStreamStateMachine::tsm = nullptr;
+}
+
 TcpStreamStateMachine::TcpStreamStateMachine()
 {
     // initialize stream tracker state machine with handler for each state...
@@ -54,4 +69,3 @@ TcpStreamStateMachine::TcpStreamStateMachine()
     new TcpStateLastAck(*this);
     new TcpStateTimeWait(*this);
 }
-
index 45ccda06c1eb9f9b6ec17f545e9ef0e807a787f9..40dacb8d1a52e12f27528c4a48df5407d29e2731 100644 (file)
@@ -16,7 +16,7 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 
-// tcp_stream_state_machine.h author davis mcpherson <davmcphe@@cisco.com>
+// tcp_stream_state_machine.h author davis mcpherson <davmcphe@cisco.com>
 // Created on: Apr 1, 2016
 
 #ifndef TCP_STREAM_STATE_MACHINE_H
 class TcpStreamStateMachine: public TcpStateMachine
 {
 public:
-    static TcpStateMachine* get_instance( )
-    {
-        static TcpStreamStateMachine tsm;
-        return &tsm;
-    }
+    static TcpStateMachine* initialize();
+    static void finalize();
+
+    static TcpStateMachine* get_instance()
+    { return TcpStreamStateMachine::tsm; }
 
 private:
     TcpStreamStateMachine();
+
+    static TcpStreamStateMachine* tsm;
+
 };
 #endif