From: Joel Cornett Date: Wed, 30 Mar 2016 20:31:24 +0000 (-0400) Subject: added flow->reset() without session cleanup, more prune reasons X-Git-Tag: 3.0.0-233~474^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b27435dc977bc87534aef3ab5e32d28d6ffcb168;p=thirdparty%2Fsnort3.git added flow->reset() without session cleanup, more prune reasons --- diff --git a/src/flow/flow.cc b/src/flow/flow.cc index f814b9bd5..f2830d94d 100644 --- a/src/flow/flow.cc +++ b/src/flow/flow.cc @@ -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(); diff --git a/src/flow/flow.h b/src/flow/flow.h index cbb1ac47f..f85b6b4eb 100644 --- a/src/flow/flow.h +++ b/src/flow/flow.h @@ -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); diff --git a/src/flow/flow_cache.cc b/src/flow/flow_cache.cc index c67da350a..04c3b6dba 100644 --- a/src/flow/flow_cache.cc +++ b/src/flow/flow_cache.cc @@ -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; } diff --git a/src/flow/flow_cache.h b/src/flow/flow_cache.h index fdc148519..0913bd12e 100644 --- a/src/flow/flow_cache.h +++ b/src/flow/flow_cache.h @@ -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(); diff --git a/src/flow/flow_control.cc b/src/flow/flow_control.cc index 593fe8de0..5e3d08617 100644 --- a/src/flow/flow_control.cc +++ b/src/flow/flow_control.cc @@ -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(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(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 //------------------------------------------------------------------------- diff --git a/src/flow/flow_control.h b/src/flow/flow_control.h index 75399efa8..c8e4366d3 100644 --- a/src/flow/flow_control.h +++ b/src/flow/flow_control.h @@ -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*); diff --git a/src/flow/prune_stats.h b/src/flow/prune_stats.h index c56bd9913..a9fd9c4ea 100644 --- a/src/flow/prune_stats.h +++ b/src/flow/prune_stats.h @@ -34,6 +34,8 @@ enum class PruneReason : uint8_t TIMEOUT, EXCESS, UNI, + PREEMPTIVE, + MEMCAP, USER, MAX }; diff --git a/src/memory/prune_handler.cc b/src/memory/prune_handler.cc index 037d1837d..967b940d5 100644 --- a/src/memory/prune_handler.cc +++ b/src/memory/prune_handler.cc @@ -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 diff --git a/src/stream/stream.h b/src/stream/stream.h index 450c11b23..d615938d0 100644 --- a/src/stream/stream.h +++ b/src/stream/stream.h @@ -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 */