]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixed prune count capture
authorRuss Combs <rucombs@cisco.com>
Sun, 9 Nov 2014 12:02:58 +0000 (07:02 -0500)
committerRuss Combs <rucombs@cisco.com>
Sun, 9 Nov 2014 12:02:58 +0000 (07:02 -0500)
14 files changed:
ChangeLog
src/flow/flow_control.cc
src/flow/flow_control.h
src/main/snort.cc
src/managers/inspector_manager.cc
src/managers/inspector_manager.h
src/network_inspectors/port_scan/port_scan.cc
src/stream/base/stream_base.cc
src/stream/icmp/icmp_session.cc
src/stream/icmp/stream_icmp.cc
src/stream/tcp/stream_tcp.cc
src/stream/tcp/tcp_session.cc
src/stream/udp/stream_udp.cc
src/stream/udp/udp_session.cc

index d15a25dd011b8af0bbe444ea397cf849ebca0a84..ca0adf3ebbe0169fb699ec8e4ed97d40eb638170 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+128
+-- fixed RangeCheck
+-- doc tweaks, defined peg count
+-- ensure fp_length / fp_offset are applied correctly
+-- allow \a\b\f\n\r\t\v in content strings
+-- fixed capture for prune counts
+
 127
 -- REG_TEST out logging tcp options for rebuilt packets to match snort bug
 -- tweaked S5_TRACE output for consistency
 -- added stream_tcp.segs_split peg
 -- snort2lua patch
 -- changed from 2.10 to 3.0
--- fixed RangeCheck
--- doc tweaks, defined peg count
--- ensure fp_length / fp_offset are applied correctly
--- allow \a\b\f\n\r\t\v in content strings
 
 126
 -- pulled latest from tom
index 05881f09601fdcee456207f3864cecce191ef1b4..c8b453b61c978c2fefde94eec28080c14a19a026 100644 (file)
@@ -70,10 +70,27 @@ static THREAD_LOCAL PegCount udp_count = 0;
 static THREAD_LOCAL PegCount icmp_count = 0;
 static THREAD_LOCAL PegCount ip_count = 0;
 
-PegCount FlowControl::get_flow_count(uint8_t proto)
+uint32_t FlowControl::max_flows(uint8_t proto)
+{
+    FlowCache* cache = get_cache(proto);
+
+    if ( cache )
+        return cache->get_max_flows();
+
+    return 0;
+}
+
+PegCount FlowControl::get_prunes (uint8_t proto)
+{
+    FlowCache* cache = get_cache(proto);
+    return cache ? cache->get_prunes() : 0;
+}
+
+PegCount FlowControl::get_flows(uint8_t proto)
 {
     switch ( proto )
     {
+    // FIXIT should be using an enum for these
     case IPPROTO_TCP:  return tcp_count;
     case IPPROTO_UDP:  return udp_count;
     case IPPROTO_ICMP: return icmp_count;
@@ -82,10 +99,24 @@ PegCount FlowControl::get_flow_count(uint8_t proto)
     }
 }
 
-void FlowControl::clear_flow_counts()
+void FlowControl::clear_counts()
 {
     tcp_count = udp_count = 0;
     icmp_count = ip_count = 0;
+
+    FlowCache* cache;
+
+    if ( (cache = get_cache(IPPROTO_IP)) )
+        cache->reset_prunes();
+
+    if ( (cache = get_cache(IPPROTO_ICMP)) )
+        cache->reset_prunes();
+
+    if ( (cache = get_cache(IPPROTO_TCP)) )
+        cache->reset_prunes();
+
+    if ( (cache = get_cache(IPPROTO_UDP)) )
+        cache->reset_prunes();
 }
 
 //-------------------------------------------------------------------------
@@ -189,32 +220,6 @@ void FlowControl::timeout_flows(uint32_t flowCount, time_t cur_time)
     Active_Resume();
 }
 
-uint32_t FlowControl::max_flows(uint8_t proto)
-{
-    FlowCache* cache = get_cache(proto);
-
-    if ( cache )
-        return cache->get_max_flows();
-
-    return 0;
-}
-
-void FlowControl::get_prunes (uint8_t proto, PegCount& prunes)
-{
-    FlowCache* cache = get_cache(proto);
-
-    if ( cache )
-        prunes = cache->get_prunes();
-}
-
-void FlowControl::reset_prunes (uint8_t proto)
-{
-    FlowCache* cache = get_cache(proto);
-
-    if ( cache )
-        cache->reset_prunes();
-}
-
 //-------------------------------------------------------------------------
 // packet foo
 //-------------------------------------------------------------------------
index 20c5b91c555c5aad26b2fb5655b258ad9be58a69..8d6f29fd2fcf00c88825fea411701db32c19eecc 100644 (file)
@@ -77,11 +77,10 @@ public:
         FlowData*);
 
     uint32_t max_flows(uint8_t proto);
-    void get_prunes(uint8_t proto, PegCount&);
-    void reset_prunes(uint8_t proto);
 
-    PegCount get_flow_count(uint8_t);
-    void clear_flow_counts();
+    PegCount get_prunes(uint8_t);
+    PegCount get_flows(uint8_t);
+    void clear_counts();
 
 private:
     class FlowCache* get_cache(uint8_t);
index 63f3888df8fa1fa4c569ca823195acc2cced32e8..04a8e66229cc7f1704795313cd9395e2841fbb87 100644 (file)
@@ -983,8 +983,9 @@ void snort_thread_term()
 #ifdef PPM_MGR
     ppm_sum_stats();
 #endif
-    InspectorManager::thread_term(snort_conf);
+    InspectorManager::thread_stop(snort_conf);
     ModuleManager::accumulate(snort_conf);
+    InspectorManager::thread_term(snort_conf);
     ActionManager::thread_term(snort_conf);
 
     IpsManager::clear_options();
index d6ee0c51baed33b02f836f2d77109e4ef75ab0f1..c79c9fcef0630b55b694ba248412c6d32e6829b6 100644 (file)
@@ -484,7 +484,7 @@ void InspectorManager::thread_init(SnortConfig* sc)
     }
 }
 
-void InspectorManager::thread_term(SnortConfig* sc)
+void InspectorManager::thread_stop(SnortConfig*)
 {
     // pin->tterm() only called for default policy
     set_default_policy();
@@ -499,7 +499,10 @@ void InspectorManager::thread_term(SnortConfig* sc)
                 p->pp_class.init = true;
             }
     }
+}
 
+void InspectorManager::thread_term(SnortConfig* sc)
+{
     for ( auto* p : sc->framework_config->clist )
     {
         if ( p->api.tterm )
index e5129488a113577f1fa04d75591bedf08f629b04..bbf5e18ea5008dc5aaee73c8d834e914a4ac9b41 100644 (file)
@@ -62,6 +62,7 @@ public:
     static void print_config(SnortConfig*);
 
     static void thread_init(SnortConfig*);
+    static void thread_stop(SnortConfig*);
     static void thread_term(SnortConfig*);
 
     static void release_policy(FrameworkPolicy*);
index 5d719a4e01c12a10012cefc1adbfd4b50e64fe7d..363ac0062d9f276646061c2ab7b6852c3fb7f71d 100644 (file)
@@ -1017,7 +1017,7 @@ static const InspectApi sp_api =
     sp_ctor,
     sp_dtor,
     nullptr, // ssn
-    sp_reset
+    sp_reset // FIXIT-L only inspector using this, eliminate?
 };
 
 #ifdef BUILDING_SO
index 7b44b325f8bb817de0147f82bb85b31190e1a708..7e5e0776b65d603174be7426b5a19b06a265500f 100644 (file)
@@ -61,10 +61,17 @@ const unsigned session_peg_count = array_size(session_pegs);
 
 struct BaseStats
 {
-    PegCount tcp;
-    PegCount udp;
-    PegCount icmp;
-    PegCount ip;
+    PegCount tcp_flows;
+    PegCount tcp_prunes;
+
+    PegCount udp_flows;
+    PegCount udp_prunes;
+
+    PegCount icmp_flows;
+    PegCount icmp_prunes;
+
+    PegCount ip_flows;
+    PegCount ip_prunes;
 };
 
 static BaseStats g_stats;
@@ -73,17 +80,28 @@ static THREAD_LOCAL BaseStats t_stats;
 static const char* const base_pegs[] =
 {
     "tcp flows",
+    "tcp prunes",
     "udp flows",
+    "udp prunes",
     "icmp flows",
-    "ip flows"
+    "icmp prunes",
+    "ip flows",
+    "ip prunes"
 };
 
 void base_sum()
 {   
-    t_stats.tcp = flow_con->get_flow_count(IPPROTO_TCP);
-    t_stats.udp = flow_con->get_flow_count(IPPROTO_UDP);
-    t_stats.icmp = flow_con->get_flow_count(IPPROTO_ICMP);
-    t_stats.ip = flow_con->get_flow_count(IPPROTO_IP);
+    t_stats.tcp_flows = flow_con->get_flows(IPPROTO_TCP);
+    t_stats.tcp_prunes = flow_con->get_prunes(IPPROTO_TCP);
+
+    t_stats.udp_flows = flow_con->get_flows(IPPROTO_UDP);
+    t_stats.udp_prunes = flow_con->get_prunes(IPPROTO_UDP);
+
+    t_stats.icmp_flows = flow_con->get_flows(IPPROTO_ICMP);
+    t_stats.icmp_prunes = flow_con->get_prunes(IPPROTO_ICMP);
+
+    t_stats.ip_flows = flow_con->get_flows(IPPROTO_IP);
+    t_stats.ip_prunes = flow_con->get_prunes(IPPROTO_IP);
 
     sum_stats((PegCount*)&g_stats, (PegCount*)&t_stats,
         array_size(base_pegs));
@@ -97,7 +115,7 @@ void base_stats()
 
 void base_reset()
 {
-    flow_con->clear_flow_counts();
+    flow_con->clear_counts();
     memset(&t_stats, 0, sizeof(t_stats));
 }
 
@@ -188,9 +206,6 @@ void StreamBase::tterm()
     flow_con->purge_flows(IPPROTO_UDP);
     flow_con->purge_flows(IPPROTO_ICMP);
     flow_con->purge_flows(IPPROTO_IP);
-
-    delete flow_con;
-    flow_con = nullptr;
 }
 
 void StreamBase::show(SnortConfig*)
@@ -270,6 +285,12 @@ static void base_dtor(Inspector* p)
     delete p;
 }
 
+void base_tterm()
+{
+    delete flow_con;
+    flow_con = nullptr;
+}
+
 static const InspectApi base_api =
 {
     {
@@ -288,7 +309,7 @@ static const InspectApi base_api =
     nullptr, // init
     nullptr, // term
     nullptr, // tinit
-    nullptr, // tterm
+    base_tterm,
     base_ctor,
     base_dtor,
     nullptr, // ssn
index 9957e9e501756f0e142a1667513df3ef0af62948..43af19929f0eb003fdbc7b52857842fd233016b2 100644 (file)
@@ -259,22 +259,3 @@ void IcmpSession::update_direction(char dir, const sfip_t *ip, uint16_t)
     icmp_responder_ip = tmpIp;
 }
 
-//-------------------------------------------------------------------------
-// api related methods
-//-------------------------------------------------------------------------
-
-#if 0
-void icmp_stats()
-{
-    // FIXIT-L move these to the actual owner
-    // FIXIT-L need to get these before delete flow_con
-    //flow_con->get_prunes(IPPROTO_UDP, icmpStats.prunes);
-}
-#endif
-
-void icmp_reset()
-{
-    memset(&icmpStats, 0, sizeof(icmpStats));
-    flow_con->reset_prunes(IPPROTO_ICMP);
-}
-
index cec590c8b580dfef79caaad34b0545c6a3617b29..fc380af90625ff1d2fda996d5dd306c0776c5fbb 100644 (file)
@@ -132,7 +132,7 @@ static const InspectApi icmp_api =
     icmp_ctor,
     icmp_dtor,
     icmp_ssn,
-    icmp_reset
+    nullptr, // reset
 };
 
 const BaseApi* nin_stream_icmp = &icmp_api.base;
index 129e9d526b3fa1e1a6069c95b1bafd74eaa2b71a..cb56868a46ae69312cce5c4414883102b5e67232 100644 (file)
@@ -150,7 +150,7 @@ static const InspectApi tcp_api =
     tcp_ctor,
     tcp_dtor,
     tcp_ssn,
-    tcp_reset
+    nullptr   // reset
 };
 
 const BaseApi* nin_stream_tcp = &tcp_api.base;
index 12ff0fb4a3c26e4a9c09184a9eefe7ba87c96db2..be2e2d392325071a26b37394d3bad1d200a675dc 100644 (file)
@@ -101,7 +101,6 @@ THREAD_LOCAL ProfileStats s5TcpProcessRebuiltPerfStats;
 struct TcpStats
 {
     PegCount sessions;
-    PegCount prunes;
     PegCount timeouts;
     PegCount resyns;
     PegCount discards;
@@ -130,7 +129,6 @@ struct TcpStats
 const char* tcp_pegs[] =
 {
     "sessions",
-    "prunes",
     "timeouts",
     "resyns",
     "discards",
@@ -6850,11 +6848,6 @@ midstream_pickup_allowed:
 // tcp module stuff
 //-------------------------------------------------------------------------
 
-void tcp_reset()
-{
-    flow_con->reset_prunes(IPPROTO_TCP);
-}
-
 void tcp_show(StreamTcpConfig* tcp_config)
 {
     Stream5PrintTcpConfig(tcp_config);
index 1b4dd44e0f9ef23c69e776fb068f7a78439ef597..b22c3f880ab3b1fe742588aaf0547a0d5bd0810c 100644 (file)
@@ -147,7 +147,7 @@ static const InspectApi udp_api =
     udp_ctor,
     udp_dtor,
     udp_ssn,
-    udp_reset
+    nullptr  // reset
 };
 
 const BaseApi* nin_stream_udp = &udp_api.base;
index df8644005e3b0ec39bb5465f0e32e9f560ec5bb6..076053a80264ef9a3c76616c731dfd774513c004 100644 (file)
@@ -220,20 +220,3 @@ int UdpSession::process(Packet *p)
     return 0;
 }
 
-//-------------------------------------------------------------------------
-// api related methods
-//-------------------------------------------------------------------------
-
-#if 0
-void udp_stats()
-{
-    // FIXIT-L need to get these before delete flow_con
-    //flow_con->get_prunes(IPPROTO_UDP, udpStats.prunes);
-}
-#endif
-
-void udp_reset()
-{
-    flow_con->reset_prunes(IPPROTO_UDP);
-}
-