]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
added flow->reset() without session cleanup, more prune reasons
authorJoel Cornett <joel.cornett@gmail.com>
Wed, 30 Mar 2016 20:31:24 +0000 (16:31 -0400)
committerJoel Cornett <joel.cornett@gmail.com>
Tue, 5 Apr 2016 19:26:04 +0000 (15:26 -0400)
src/flow/flow.cc
src/flow/flow.h
src/flow/flow_cache.cc
src/flow/flow_cache.h
src/flow/flow_control.cc
src/flow/flow_control.h
src/flow/prune_stats.h
src/memory/prune_handler.cc
src/stream/stream.h

index f814b9bd52a458ffba619d3cdf5b4ad99479b722..f2830d94df752f9f2a8ff315375a7096a94289d8 100644 (file)
@@ -85,10 +85,16 @@ void Flow::term()
         delete bitop;
 }
 
-void Flow::reset()
+void Flow::reset(bool do_cleanup)
 {
     if ( session )
-        session->cleanup();
+    {
+        if ( do_cleanup )
+            session->cleanup();
+
+        else
+            session->clear();
+    }
 
     free_application_data();
 
index cbb1ac47f3d0348190badc90e6848abaf88b8448..f85b6b4ebc03761ee9077d825237bdc55b57b3ba 100644 (file)
@@ -143,7 +143,7 @@ public:
     void init(PktType);
     void term();
 
-    void reset();
+    void reset(bool do_cleanup = true);
     void restart(bool freeAppData = true);
     void clear(bool freeAppData = true);
 
index c67da350aa64538920793ca041ccb92d23f19b70..04c3b6dbae2633003a461cc3ac16a4c703e81ce4 100644 (file)
@@ -150,9 +150,9 @@ Flow* FlowCache::get(const FlowKey* key)
     return flow;
 }
 
-int FlowCache::release(Flow* flow, PruneReason reason)
+int FlowCache::release(Flow* flow, PruneReason reason, bool do_cleanup)
 {
-    flow->reset();
+    flow->reset(do_cleanup);
     prune_stats.update(reason);
     return remove(flow);
 }
@@ -270,7 +270,7 @@ unsigned FlowCache::prune_excess(const Flow* save_me)
     return pruned;
 }
 
-bool FlowCache::prune_one(PruneReason reason)
+bool FlowCache::prune_one(PruneReason reason, bool do_cleanup)
 {
     // so we don't prune the current flow (assume current == MRU)
     if ( hash_table->get_count() <= 1 )
@@ -280,7 +280,7 @@ bool FlowCache::prune_one(PruneReason reason)
     assert(flow);
 
     flow->ssn_state.session_flags |= SSNFLAG_PRUNED;
-    release(flow, reason);
+    release(flow, reason, false);
 
     return true;
 }
index fdc148519f8830751beca538b1bc564a59249ef6..0913bd12ec019a98bfc5343952feb69635378ddd 100644 (file)
@@ -47,12 +47,12 @@ public:
     Flow* find(const FlowKey*);
     Flow* get(const FlowKey*);
 
-    int release(Flow*, PruneReason = PruneReason::USER);
+    int release(Flow*, PruneReason = PruneReason::USER, bool do_cleanup = true);
 
     unsigned prune_unis();
     unsigned prune_stale(uint32_t thetime, const Flow* save_me);
     unsigned prune_excess(const Flow* save_me);
-    bool prune_one(PruneReason);
+    bool prune_one(PruneReason, bool do_cleanup);
     unsigned timeout(unsigned num_flows, time_t cur_time);
 
     unsigned purge();
index 593fe8de0fca48efe9c7cd3abef0d1e674b55120..5e3d08617517e1acb762d3d6e48b01c0f6618275 100644 (file)
@@ -265,10 +265,10 @@ void FlowControl::prune_flows(PktType proto, const Packet* p)
 }
 
 // hole for memory manager/prune handler
-bool FlowControl::prune_one(PruneReason reason)
+bool FlowControl::prune_one(PruneReason reason, bool do_cleanup)
 {
     auto cache = get_cache(last_pkt_type);
-    return cache ? cache->prune_one(reason) : false;
+    return cache ? cache->prune_one(reason, do_cleanup) : false;
 }
 
 void FlowControl::timeout_flows(uint32_t flowCount, time_t cur_time)
@@ -296,6 +296,19 @@ void FlowControl::timeout_flows(uint32_t flowCount, time_t cur_time)
     Active::resume();
 }
 
+void FlowControl::preemptive_cleanup(const Packet* p)
+{
+    if ( !memory::MemoryCap::over_threshold() )
+        return;
+
+    DebugFormat(DEBUG_FLOW, "doing preemptive cleanup for packet of type %d",
+            static_cast<int>(p->type()));
+
+    // FIXIT-H J we want to associate this prune with an appropriate prune reason
+    // FIXIT-L J do we want to accumulate preemptive prune counts?
+    prune_flows(p->type(), p);
+}
+
 //-------------------------------------------------------------------------
 // packet foo
 //-------------------------------------------------------------------------
@@ -517,19 +530,6 @@ unsigned FlowControl::process(Flow* flow, Packet* p)
     return news;
 }
 
-void FlowControl::preemptive_cleanup(const Packet* p)
-{
-    if ( !memory::MemoryCap::over_threshold() )
-        return;
-
-    DebugFormat(DEBUG_FLOW, "doing preemptive cleanup for packet of type %d",
-            static_cast<int>(p->type()));
-
-    // FIXIT-H J we want to associate this prune with an appropriate prune reason
-    // FIXIT-L J do we want to accumulate preemptive prune counts?
-    prune_flows(p->type(), p);
-}
-
 //-------------------------------------------------------------------------
 // ip
 //-------------------------------------------------------------------------
index 75399efa8dc087d5fa5300738f919b66b16759a8..c8e4366d3d832e9a041d9cc7a00fe9d595c5f111 100644 (file)
@@ -70,7 +70,7 @@ public:
     void delete_flow(Flow*, PruneReason);
     void purge_flows(PktType);
     void prune_flows(PktType, const Packet*);
-    bool prune_one(PruneReason);
+    bool prune_one(PruneReason, bool do_cleanup);
     void timeout_flows(uint32_t flowCount, time_t cur_time);
 
     char expected_flow(Flow*, Packet*);
index c56bd991341be78e6e5553609c04e343a9b61372..a9fd9c4ea300975bb6a411aea1e21c8c77b82f4a 100644 (file)
@@ -34,6 +34,8 @@ enum class PruneReason : uint8_t
     TIMEOUT,
     EXCESS,
     UNI,
+    PREEMPTIVE,
+    MEMCAP,
     USER,
     MAX
 };
index 037d1837d2b043293d31ec4a2d036eec1298ceb7..967b940d5cf8aad1321eaa1ded0db6699d6aba31 100644 (file)
@@ -31,7 +31,7 @@ void prune_handler()
 {
     // assert(flow_con);
     if ( flow_con )
-        flow_con->prune_one(PruneReason::USER);
+        flow_con->prune_one(PruneReason::MEMCAP, false);
 }
 
 } // namespace memory
index 450c11b23e2b22217fb6d98dc835f0e17d442e83..d615938d0b7eda65530e7dfc23e4a46bf65ce09d 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "main/snort_types.h"
 #include "stream/stream_api.h"
-#include "normalize/norm.h"
+#include "network_inspectors/normalize/norm.h"
 #include "flow/session.h"
 
 #define STREAM_DEFAULT_SSN_TIMEOUT  30        /* seconds to timeout a session */