]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #628 in SNORT/snort3 from misc_perf to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Tue, 20 Sep 2016 20:46:36 +0000 (16:46 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Tue, 20 Sep 2016 20:46:36 +0000 (16:46 -0400)
Squashed commit of the following:

commit 7b11ea83413f1af8f0f5a847a0177637deca1d45
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Sep 16 17:32:17 2016 -0400

    Refactored BitOp related.  Only instantiate on demand.  Move accessor out of stream_api
    for better encapsulation in ips_flowbits.  Eliminate useless methods.

    Added stream.ip_frags_only so we can avoid processing non-ICMP-TCP-UDP-frags where not
    needed.  This avoids creating flows etc.  Beware - appID wants flows for everything
    at the moment.

    Fixed double counting of ip session timeouts and prunes as well as
    double counting of udp session timeouts.

    Changed stale pruning to prune 1 at a time to resolve excessive latency caused
    by pruning.  Timeouts are pruned one at a time too, although it remains to be
    seen if this is adequate for idle timeouts where connection events are concerned.

    Changed default cache sizes to match 2.X.

    FlowControl::max_flows() and FlowControl::prune_flows() no longer used; deleted.

    Shutdown purging was being counted as prunes in stream_tcp.  This is fixed but
    still need to fix stream.user prunes which includes shutdown stuff.

    Added a crude total and max to packet latency stats to calculate average packet time
    a la 2.X.  Still only totals about half of runtime so needs to be revisited.  It is not
    supposed to include stuff like decode so it may be ok.

    Fixed stream_tcp to close a scan session immediately (was timing out).  So a SYN
    that gets a RST results in closed and getting cleared.

    Fixed some annoying legacy naming issues.  So inspector data on a flow is now
    flow_data instead of application_data.  Also C-style functions like
    get_x_from_y() are now simply C++-style get_x().

    Cleanup default conf.

72 files changed:
extra/src/inspectors/http_server/hi_main.cc
lua/snort.lua
src/codecs/ip/cd_tcp.cc
src/detection/detect.cc
src/file_api/file_flows.cc
src/flow/expect_cache.cc
src/flow/flow.cc
src/flow/flow.h
src/flow/flow_cache.cc
src/flow/flow_cache.h
src/flow/flow_config.h
src/flow/flow_control.cc
src/flow/flow_control.h
src/ips_options/ips_flowbits.cc
src/ips_options/ips_flowbits.h
src/latency/latency_module.cc
src/latency/latency_stats.h
src/latency/packet_latency.cc
src/main/snort.cc
src/network_inspectors/appid/appid_api.cc
src/network_inspectors/appid/appid_session.cc
src/network_inspectors/appid/test/external_apis.cc
src/network_inspectors/appid/test/external_apis.h
src/network_inspectors/appid/test/mpse.cc
src/network_inspectors/binder/binder.cc
src/network_inspectors/binder/test/binder_test.cc
src/network_inspectors/reputation/reputation_inspect.cc
src/packet_io/active.cc
src/service_inspectors/dce_rpc/dce_smb.cc
src/service_inspectors/dce_rpc/dce_tcp.cc
src/service_inspectors/dnp3/dnp3.cc
src/service_inspectors/dnp3/ips_dnp3_data.cc
src/service_inspectors/dnp3/ips_dnp3_func.cc
src/service_inspectors/dnp3/ips_dnp3_ind.cc
src/service_inspectors/dnp3/ips_dnp3_obj.cc
src/service_inspectors/dns/dns.cc
src/service_inspectors/ftp_telnet/ftp.cc
src/service_inspectors/ftp_telnet/ftp_data.cc
src/service_inspectors/ftp_telnet/ftpp_si.cc
src/service_inspectors/ftp_telnet/telnet.cc
src/service_inspectors/gtp/gtp.cc
src/service_inspectors/gtp/ips_gtp_info.cc
src/service_inspectors/gtp/ips_gtp_type.cc
src/service_inspectors/gtp/ips_gtp_version.cc
src/service_inspectors/http_inspect/http_inspect.cc
src/service_inspectors/http_inspect/http_stream_splitter_reassemble.cc
src/service_inspectors/http_inspect/http_stream_splitter_scan.cc
src/service_inspectors/imap/imap.cc
src/service_inspectors/modbus/ips_modbus_func.cc
src/service_inspectors/modbus/ips_modbus_unit.cc
src/service_inspectors/modbus/modbus.cc
src/service_inspectors/modbus/modbus_decode.cc
src/service_inspectors/pop/pop.cc
src/service_inspectors/rpc_decode/rpc_decode.cc
src/service_inspectors/sip/sip.cc
src/service_inspectors/sip/sip_dialog.cc
src/service_inspectors/smtp/smtp.cc
src/service_inspectors/ssh/ssh.cc
src/service_inspectors/ssl/ssl_inspector.cc
src/stream/base/stream_base.cc
src/stream/base/stream_module.cc
src/stream/base/stream_module.h
src/stream/icmp/icmp_session.cc
src/stream/ip/ip_session.cc
src/stream/libtcp/tcp_stream_session.h
src/stream/stream_api.cc
src/stream/stream_api.h
src/stream/tcp/tcp_session.cc
src/stream/tcp/tcp_state_syn_sent.cc
src/stream/udp/udp_session.cc
src/utils/bitop.h
src/utils/bitop_test.cc

index 742ffe2867a59b92d58229842e45aec3ff40799a..8f75795f3a358590f24472095d9a2097379f8a46 100644 (file)
@@ -146,15 +146,13 @@ HttpFlowData::~HttpFlowData()
 HttpSessionData* SetNewHttpSessionData(Packet* p, void*)
 {
     HttpFlowData* fd = new HttpFlowData;
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     return &fd->session;
 }
 
 static HttpSessionData* get_session_data(Flow* flow)
 {
-    HttpFlowData* fd = (HttpFlowData*)flow->get_application_data(
-        HttpFlowData::flow_id);
-
+    HttpFlowData* fd = (HttpFlowData*)flow->get_flow_data(HttpFlowData::flow_id);
     return fd ? &fd->session : NULL;
 }
 
index da5fde5280b1bb460eb540884d5496d8093e7071..2980ee45bbbf1c7d2378760e7ab3be2c83d03912 100644 (file)
@@ -69,6 +69,7 @@ back_orifice = { }
 dnp3 = { }
 dns = { }
 gtp_inspect = default_gtp
+http_inspect = { }
 imap = { }
 smtp = { }
 pop = { }
@@ -80,10 +81,6 @@ ssh = { }
 ssl = { }
 telnet = { }
 
--- use http_inspect or new_http_inspect (incomplete)
-http_inspect = { }
---new_http_inspect = { }
-
 ftp_server = default_ftp_server
 ftp_client = { }
 ftp_data = { }
index f3424ae98b6f14205919586b30096eac4ac17fda..3a36f210f233e74719bf6e3cbc63966eb429c875 100644 (file)
@@ -241,9 +241,8 @@ bool TcpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snort)
         }
 
         if ( sfvar_ip_in(SynToMulticastDstIp, snort.ip_api.get_dst()) )
-        {
             codec_event(codec, DECODE_SYN_TO_MULTICAST);
-        }
+
         if ( (tcph->th_flags & TH_RST) )
             codec_event(codec, DECODE_TCP_SYN_RST);
 
index 4aec779b3b459ffb9aa70991c1eafccc55906202..8da04fa0d3f87b96641ad5fecefbe2b04ccaf939 100644 (file)
@@ -107,7 +107,11 @@ void snort_inspect(Packet* p)
 
         check_tags_flag = 1;
 
-        /* Check for normally closed session */
+        // clear closed sessions here after inspection since non-stream
+        // inspectors may depend on flow information
+        // FIXIT-H but this result in double clearing?  should normal
+        // clear_session() calls be deleted from stream?  this is a
+        // performance hit on short-lived flows
         stream.check_session_closed(p);
 
         /*
index 7fcd20850ff8973d86341a1138ce4e24398a3671..e65d85b0079e6a39f0183ea5b1217edc24a035d9 100644 (file)
@@ -55,7 +55,7 @@ unsigned FileFlows::flow_id = 0;
 
 FileFlows* FileFlows::get_file_flows(Flow* flow)
 {
-    FileFlows* fd = (FileFlows*) flow->get_application_data(FileFlows::flow_id);
+    FileFlows* fd = (FileFlows*) flow->get_flow_data(FileFlows::flow_id);
 
     if (fd)
         return fd;
@@ -63,7 +63,7 @@ FileFlows* FileFlows::get_file_flows(Flow* flow)
     if (FileService::is_file_service_enabled())
     {
         fd = new FileFlows(flow);
-        flow->set_application_data(fd);
+        flow->set_flow_data(fd);
     }
 
     return fd;
index 3246a37ff99fc35790f3c243ff3fc1fe536d13b9..d2e7c0ae436b4cf62bfaa97361a97c13a9fd1e70 100644 (file)
@@ -432,7 +432,7 @@ char ExpectCache::process_expected(Packet* p, Flow* lws)
     while ((fd = head->data))
     {
         head->data = fd->next;
-        lws->set_application_data(fd);
+        lws->set_flow_data(fd);
         ++realized;
         fd->handle_expected(p);
     }
index 8c5dbcb6031c8c5818dc3a913b3dffef8e75d9d9..c2fdce289637485e29be6a834f9a8ebdd72c15cf 100644 (file)
 #include "flow/ha.h"
 #include "flow/session.h"
 #include "ips_options/ips_flowbits.h"
-#include "utils/bitop.h"
-#include "utils/util.h"
 #include "protocols/packet.h"
 #include "sfip/sf_ip.h"
+#include "utils/bitop.h"
+#include "utils/util.h"
 
 unsigned FlowData::flow_id = 0;
 
@@ -60,15 +60,15 @@ Flow::~Flow()
 void Flow::init(PktType type)
 {
     pkt_type = type;
-
-    // FIXIT-M getFlowbitSizeInBytes() should be attribute of ??? (or eliminate)
-    bitop = new BitOp(getFlowbitSizeInBytes());
+    bitop = nullptr;
 
     if ( HighAvailabilityManager::active() )
     {
         ha_state = new FlowHAState;
         previous_ssn_state = ssn_state;
     }
+    mpls_client.length = 0;
+    mpls_server.length = 0;
 }
 
 void Flow::term()
@@ -76,7 +76,16 @@ void Flow::term()
     if ( session )
         delete session;
 
-    free_application_data();
+    free_flow_data();
+
+    if ( mpls_client.length )
+        delete[] mpls_client.start;
+
+    if ( mpls_server.length )
+        delete[] mpls_server.start;
+
+    if ( bitop )
+        delete bitop;
 
     if ( ssn_client )
         ssn_client->rem_ref();
@@ -90,21 +99,26 @@ void Flow::term()
     if ( gadget )
         gadget->rem_ref();
 
-    if ( bitop )
-        delete bitop;
-
     if ( ha_state )
         delete ha_state;
+}
 
-    if ( clientMplsLyr.length )
+inline void Flow::clean()
+{
+    if ( mpls_client.length )
     {
-        delete[] clientMplsLyr.start;
-        clientMplsLyr.length = 0;
+        delete[] mpls_client.start;
+        mpls_client.length = 0;
     }
-    if ( serverMplsLyr.length )
+    if ( mpls_server.length )
     {
-        delete[] serverMplsLyr.start;
-        serverMplsLyr.length = 0;
+        delete[] mpls_server.start;
+        mpls_server.length = 0;
+    }
+    if ( bitop )
+    {
+        delete bitop;
+        bitop = nullptr;
     }
 }
 
@@ -119,18 +133,8 @@ void Flow::reset(bool do_cleanup)
             session->clear();
     }
 
-    free_application_data();
-
-    if ( clientMplsLyr.length )
-    {
-        delete[] clientMplsLyr.start;
-        clientMplsLyr.length = 0;
-    }
-    if ( serverMplsLyr.length )
-    {
-        delete[] serverMplsLyr.start;
-        serverMplsLyr.length = 0;
-    }
+    free_flow_data();
+    clean();
 
     // FIXIT-M cleanup() winds up calling clear()
     if ( ssn_client )
@@ -152,33 +156,20 @@ void Flow::reset(bool do_cleanup)
     if ( data )
         clear_data();
 
-    constexpr size_t offset = offsetof(Flow, appDataList);
-    // FIXIT-L need a struct to zero here to make future proof
-    memset((uint8_t*)this+offset, 0, sizeof(Flow)-offset);
-
-    bitop->reset();
-
     if ( ha_state )
         ha_state->reset();
+
+    constexpr size_t offset = offsetof(Flow, flow_data);
+    // FIXIT-L need a struct to zero here to make future proof
+    memset((uint8_t*)this+offset, 0, sizeof(Flow)-offset);
 }
 
-void Flow::restart(bool free_flow_data)
+void Flow::restart(bool dump_flow_data)
 {
-    if ( free_flow_data )
-        free_application_data();
+    if ( dump_flow_data )
+        free_flow_data();
 
-    if ( clientMplsLyr.length )
-    {
-        delete[] clientMplsLyr.start;
-        clientMplsLyr.length = 0;
-    }
-    if ( serverMplsLyr.length )
-    {
-        delete[] serverMplsLyr.start;
-        serverMplsLyr.length = 0;
-    }
-
-    bitop->reset();
+    clean();
 
     ssn_state.ignore_direction = 0;
     ssn_state.session_flags = SSNFLAG_NONE;
@@ -188,9 +179,9 @@ void Flow::restart(bool free_flow_data)
     previous_ssn_state = ssn_state;
 }
 
-void Flow::clear(bool free_flow_data)
+void Flow::clear(bool dump_flow_data)
 {
-    restart(free_flow_data);
+    restart(dump_flow_data);
     set_state(FlowState::SETUP);
 
     if ( ssn_client )
@@ -210,45 +201,45 @@ void Flow::clear(bool free_flow_data)
         clear_gadget();
 }
 
-int Flow::set_application_data(FlowData* fd)
+int Flow::set_flow_data(FlowData* fd)
 {
-    FlowData* appData = get_application_data(fd->get_id());
-    assert(appData != fd);
+    FlowData* old = get_flow_data(fd->get_id());
+    assert(old != fd);
 
-    if (appData)
-        free_application_data(appData);
+    if (old)
+        free_flow_data(old);
 
     fd->prev = nullptr;
-    fd->next = appDataList;
+    fd->next = flow_data;
 
-    if ( appDataList )
-        appDataList->prev = fd;
+    if ( flow_data )
+        flow_data->prev = fd;
 
-    appDataList = fd;
+    flow_data = fd;
     return 0;
 }
 
-FlowData* Flow::get_application_data(unsigned id)
+FlowData* Flow::get_flow_data(unsigned id)
 {
-    FlowData* appData = appDataList;
+    FlowData* fd = flow_data;
 
-    while (appData)
+    while (fd)
     {
-        if (appData->get_id() == id)
-            return appData;
+        if (fd->get_id() == id)
+            return fd;
 
-        appData = appData->next;
+        fd = fd->next;
     }
     return nullptr;
 }
 
-void Flow::free_application_data(FlowData* fd)
+void Flow::free_flow_data(FlowData* fd)
 {
-    if ( fd == appDataList )
+    if ( fd == flow_data )
     {
-        appDataList = fd->next;
-        if ( appDataList )
-            appDataList->prev = nullptr;
+        flow_data = fd->next;
+        if ( flow_data )
+            flow_data->prev = nullptr;
     }
     else if ( !fd->next )
     {
@@ -262,39 +253,39 @@ void Flow::free_application_data(FlowData* fd)
     delete fd;
 }
 
-void Flow::free_application_data(uint32_t proto)
+void Flow::free_flow_data(uint32_t proto)
 {
-    FlowData* fd = get_application_data(proto);
+    FlowData* fd = get_flow_data(proto);
 
     if ( fd )
-        free_application_data(fd);
+        free_flow_data(fd);
 }
 
-void Flow::free_application_data()
+void Flow::free_flow_data()
 {
-    FlowData* appData = appDataList;
+    FlowData* fd = flow_data;
 
-    while (appData)
+    while (fd)
     {
-        FlowData* tmp = appData;
-        appData = appData->next;
+        FlowData* tmp = fd;
+        fd = fd->next;
         delete tmp;
     }
-    appDataList = nullptr;
+    flow_data = nullptr;
 }
 
 void Flow::call_handlers(Packet* p, bool eof)
 {
-    FlowData* appData = appDataList;
+    FlowData* fd = flow_data;
 
-    while (appData)
+    while (fd)
     {
         if ( eof )
-            appData->handle_eof(p);
+            fd->handle_eof(p);
         else
-            appData->handle_retransmit(p);
+            fd->handle_retransmit(p);
 
-        appData = appData->next;
+        fd = fd->next;
     }
 }
 
@@ -375,27 +366,9 @@ void Flow::set_direction(Packet* p)
     }
 }
 
-static constexpr int TCP_HZ = 100;
-
-static inline uint64_t CalcJiffies(const Packet* p)
-{
-    uint64_t ret = 0;
-    uint64_t sec = (uint64_t)p->pkth->ts.tv_sec * TCP_HZ;
-    uint64_t usec = (p->pkth->ts.tv_usec / (1000000UL/TCP_HZ));
-
-    ret = sec + usec;
-
-    return ret;
-}
-
 void Flow::set_expire(const Packet* p, uint32_t timeout)
 {
-    expire_time = CalcJiffies(p) + (timeout * TCP_HZ);
-}
-
-int Flow::get_expire(const Packet* p)
-{
-    return ( CalcJiffies(p) > expire_time );
+    expire_time = (uint64_t)p->pkth->ts.tv_sec + timeout;
 }
 
 bool Flow::expired(const Packet* p)
@@ -403,9 +376,7 @@ bool Flow::expired(const Packet* p)
     if ( !expire_time )
         return false;
 
-    uint64_t pkttime = CalcJiffies(p);
-
-    if ( (int)(pkttime - expire_time) > 0 )
+    if ( (uint64_t)p->pkth->ts.tv_sec > expire_time )
         return true;
 
     return false;
@@ -472,22 +443,22 @@ void Flow::set_mpls_layer_per_dir(Packet* p)
 
     if ( p->packet_flags & PKT_FROM_CLIENT )
     {
-        if ( !clientMplsLyr.length )
+        if ( !mpls_client.length )
         {
-            clientMplsLyr.length = mpls_lyr->length;
-            clientMplsLyr.prot_id = mpls_lyr->prot_id;
-            clientMplsLyr.start = new uint8_t[mpls_lyr->length];
-            memcpy((void *)clientMplsLyr.start, mpls_lyr->start, mpls_lyr->length);
+            mpls_client.length = mpls_lyr->length;
+            mpls_client.prot_id = mpls_lyr->prot_id;
+            mpls_client.start = new uint8_t[mpls_lyr->length];
+            memcpy((void *)mpls_client.start, mpls_lyr->start, mpls_lyr->length);
         }
     }
     else
     {
-        if ( !serverMplsLyr.length )
+        if ( !mpls_server.length )
         {
-            serverMplsLyr.length = mpls_lyr->length;
-            serverMplsLyr.prot_id = mpls_lyr->prot_id;
-            serverMplsLyr.start = new uint8_t[mpls_lyr->length];
-            memcpy((void *)serverMplsLyr.start, mpls_lyr->start, mpls_lyr->length);
+            mpls_server.length = mpls_lyr->length;
+            mpls_server.prot_id = mpls_lyr->prot_id;
+            mpls_server.start = new uint8_t[mpls_lyr->length];
+            memcpy((void *)mpls_server.start, mpls_lyr->start, mpls_lyr->length);
         }
     }
 }
@@ -495,7 +466,7 @@ void Flow::set_mpls_layer_per_dir(Packet* p)
 Layer Flow::get_mpls_layer_per_dir(bool client)
 {
     if ( client )
-        return clientMplsLyr;
+        return mpls_client;
     else
-        return serverMplsLyr;
+        return mpls_server;
 }
index e3576ba620033f6d06ace83720f689c6f06de090..a0819b61c26ddeabadec1838b901b7490d96e329 100644 (file)
@@ -29,7 +29,6 @@
 
 #include <assert.h>
 
-#include "utils/bitop.h"
 #include "sfip/sfip_t.h"
 #include "flow/flow_key.h"
 #include "framework/inspector.h"
@@ -156,23 +155,22 @@ public:
     void term();
 
     void reset(bool do_cleanup = true);
-    void restart(bool free_flow_data = true);
-    void clear(bool free_flow_data = true);
-
-    int set_application_data(FlowData*);
-    FlowData* get_application_data(uint32_t proto);
-    void free_application_data(uint32_t proto);
-    void free_application_data(FlowData*);
-    void free_application_data();
-    void set_application_ids(AppId serviceAppId, AppId clientAppId,
-            AppId payloadAppId, AppId miscAppId);
-    void get_application_ids(AppId& serviceAppId, AppId& clientAppId,
-            AppId& payloadAppId, AppId& miscAppId);
+    void restart(bool dump_flow_data = true);
+    void clear(bool dump_flow_data = true);
+
+    int set_flow_data(FlowData*);
+    FlowData* get_flow_data(uint32_t proto);
+    void free_flow_data(uint32_t proto);
+    void free_flow_data(FlowData*);
+    void free_flow_data();
+
+    void set_application_ids(AppId service, AppId client, AppId payload, AppId misc);
+    void get_application_ids(AppId& service, AppId& client, AppId& payload, AppId& misc);
+
     void call_handlers(Packet* p, bool eof = false);
     void markup_packet_flags(Packet*);
     void set_direction(Packet*);
     void set_expire(const Packet*, uint32_t timeout);
-    int get_expire(const Packet*);
     bool expired(const Packet*);
     void set_ttl(Packet*, bool client);
     void set_mpls_layer_per_dir(Packet*);
@@ -294,11 +292,15 @@ public:
     }
 
 public:  // FIXIT-M privatize if possible
+    // fields are organized by initialization and size to minimize
+    // void space and allow for memset of tail end of struct
+
     // these fields are const after initialization
     const FlowKey* key;
     class Session* session;
     class BitOp* bitop;
     class FlowHAState* ha_state;
+
     uint8_t ip_proto; // FIXIT-M do we need both of these?
     PktType pkt_type; // ^^
 
@@ -306,24 +308,30 @@ public:  // FIXIT-M privatize if possible
     Flow* prev, * next;
     Inspector* ssn_client;
     Inspector* ssn_server;
+
     long last_data_seen;
+    Layer mpls_client, mpls_server;
 
     // everything from here down is zeroed
-    FlowData* appDataList;
+    FlowData* flow_data;
     Inspector* clouseau;  // service identifier
     Inspector* gadget;    // service handler
     Inspector* data;
     const char* service;
-    Layer clientMplsLyr, serverMplsLyr;
 
-    unsigned policy_id;
-
-    FlowState flow_state;
+    uint64_t expire_time;
 
     sfip_t client_ip; // FIXIT-L family and bits should be changed to uint16_t
     sfip_t server_ip; // or uint8_t to reduce sizeof from 24 to 20
 
-    uint64_t expire_time;
+    LwState ssn_state;
+    LwState previous_ssn_state;
+
+    // FIXIT-L: if appid is only consumer of this move to appid
+    AppId application_ids[APP_PROTOID_MAX];
+
+    FlowState flow_state;
+    unsigned policy_id;
 
     int32_t iface_in;
     int32_t iface_out;
@@ -340,12 +348,8 @@ public:  // FIXIT-M privatize if possible
     uint8_t  response_count;
     bool disable_inspect;
 
-    // FIXIT-L: if appid is only consumer of this move to appid
-    AppId application_ids[APP_PROTOID_MAX];
-
-public:
-    LwState ssn_state;
-    LwState previous_ssn_state;
+private:
+    void clean();
 };
 
 #endif
index 95858cb0245252506f95f23d2c6149fa5dc1e696..ea7af7add8295c1da1c900d8e0a3503749a4d9f6 100644 (file)
@@ -31,6 +31,7 @@
 #include "main/snort_debug.h"
 #include "packet_io/active.h"
 #include "time/packet_time.h"
+#include "utils/stats.h"
 
 #define SESSION_CACHE_FLAG_PURGING  0x01
 
 
 FlowCache::FlowCache (const FlowConfig& cfg) : config(cfg)
 {
-    cleanup_flows = cfg.max_sessions * cfg.cleanup_pct / 100;
-    if ( cleanup_flows == 0 )
-        cleanup_flows = 1;
-
-    assert(cleanup_flows <= cfg.max_sessions);
-    assert(cleanup_flows > 0);
-
     hash_table = new ZHash(config.max_sessions, sizeof(FlowKey));
     hash_table->set_keyops(FlowKey::hash, FlowKey::compare);
 
@@ -307,7 +301,7 @@ unsigned FlowCache::timeout(unsigned num_flows, time_t thetime)
     if ( !flow )
         flow = static_cast<Flow*>(hash_table->first());
 
-    while ( flow and retired < num_flows )
+    while ( flow and (retired < num_flows) )
     {
         if ( flow->last_data_seen + config.nominal_timeout > thetime )
             break;
@@ -340,7 +334,6 @@ unsigned FlowCache::purge()
 
     while ( auto flow = static_cast<Flow*>(hash_table->first()) )
     {
-        flow->ssn_state.session_flags |= SSNFLAG_PRUNED;
         release(flow, PruneReason::PURGE);
         ++retired;
     }
index 3d6445cd7122839cd929b8cdbdc4a19af9eb5005..f62e69ae37c82b5ac3d7ffb51fab2c8008428bdb 100644 (file)
@@ -76,8 +76,8 @@ private:
     int remove(Flow*);
 
 private:
+    const unsigned cleanup_flows = 1;
     const FlowConfig& config;
-    unsigned cleanup_flows;
     unsigned uni_count;
     uint32_t flags;
 
index 453d3a3b5a0d59ad743ec8d0e9d3ec7b31df787a..3d8216e127bf95e24cb92f692820180cd022ade7 100644 (file)
@@ -28,7 +28,6 @@ struct FlowConfig
     unsigned max_sessions = 0;
     unsigned pruning_timeout = 0;
     unsigned nominal_timeout = 0;
-    unsigned cleanup_pct = 0;
 };
 
 #endif
index 2a2ea03bf3906cf4421ff3c7af11b6af94aecf68..1433e242cb3ef3eb7460598480edc334de116a64 100644 (file)
 #include "session.h"
 
 FlowControl::FlowControl()
-{
-    ip_cache = nullptr;
-    icmp_cache = nullptr;
-    tcp_cache = nullptr;
-    udp_cache = nullptr;
-    user_cache = nullptr;
-    file_cache = nullptr;
-    exp_cache = nullptr;
-
-    ip_mem = icmp_mem = nullptr;
-    tcp_mem = udp_mem = nullptr;
-    user_mem = file_mem = nullptr;
-
-    get_ip = get_icmp = nullptr;
-    get_tcp = get_udp = nullptr;
-    get_user = get_file = nullptr;
-
-    last_pkt_type = PktType::NONE;
-}
+{ }
 
 FlowControl::~FlowControl()
 {
@@ -90,16 +72,6 @@ static THREAD_LOCAL PegCount udp_count = 0;
 static THREAD_LOCAL PegCount user_count = 0;
 static THREAD_LOCAL PegCount file_count = 0;
 
-uint32_t FlowControl::max_flows(PktType type)
-{
-    FlowCache* cache = get_cache(type);
-
-    if ( cache )
-        return cache->get_max_flows();
-
-    return 0;
-}
-
 PegCount FlowControl::get_flows(PktType type)
 {
     switch ( type )
@@ -108,7 +80,7 @@ PegCount FlowControl::get_flows(PktType type)
     case PktType::ICMP: return icmp_count;
     case PktType::TCP:  return tcp_count;
     case PktType::UDP:  return udp_count;
-    case PktType::PDU: return user_count;
+    case PktType::PDU:  return user_count;
     case PktType::FILE: return file_count;
     default:            return 0;
     }
@@ -238,24 +210,6 @@ void FlowControl::purge_flows (PktType type)
         cache->purge();
 }
 
-void FlowControl::prune_flows(PktType type, const Packet* p)
-{
-    if ( !p )
-        return;
-
-    FlowCache* cache = get_cache(type);
-
-    if ( !cache )
-        return;
-
-    // smack the older timed out flows
-    if ( !cache->prune_stale(p->pkth->ts.tv_sec, p->flow) )
-    {
-        // if no luck, try the memcap
-        cache->prune_excess(p->flow);
-    }
-}
-
 // hole for memory manager/prune handler
 bool FlowControl::prune_one(PruneReason reason, bool do_cleanup)
 {
@@ -263,27 +217,19 @@ bool FlowControl::prune_one(PruneReason reason, bool do_cleanup)
     return cache ? cache->prune_one(reason, do_cleanup) : false;
 }
 
-void FlowControl::timeout_flows(uint32_t flowCount, time_t cur_time)
+void FlowControl::timeout_flows(time_t cur_time)
 {
-    Active::suspend();
-
-    if ( ip_cache )
-        ip_cache->timeout(flowCount, cur_time);
-
-    //if ( icmp_cache )
-    //icmp_cache does not need cleaning
-
-    if ( tcp_cache )
-        tcp_cache->timeout(flowCount, cur_time);
+    if ( !types.size() )
+        return;
 
-    if ( udp_cache )
-        udp_cache->timeout(flowCount, cur_time);
+    Active::suspend();
+    FlowCache* fc = get_cache(types[next]);
 
-    if ( user_cache )
-        user_cache->timeout(flowCount, cur_time);
+    if ( ++next >= types.size() )
+        next = 0;
 
-    if ( file_cache )
-        file_cache->timeout(flowCount, cur_time);
+    if ( fc )
+        fc->timeout(1, cur_time);
 
     Active::resume();
 }
@@ -547,6 +493,7 @@ void FlowControl::init_ip(
         ip_cache->push(ip_mem + i);
 
     get_ip = get_ssn;
+    types.push_back(PktType::IP);
 }
 
 void FlowControl::process_ip(Packet* p)
@@ -590,6 +537,7 @@ void FlowControl::init_icmp(
         icmp_cache->push(icmp_mem + i);
 
     get_icmp = get_ssn;
+    types.push_back(PktType::ICMP);
 }
 
 void FlowControl::process_icmp(Packet* p)
@@ -636,6 +584,7 @@ void FlowControl::init_tcp(
         tcp_cache->push(tcp_mem + i);
 
     get_tcp = get_ssn;
+    types.push_back(PktType::TCP);
 }
 
 void FlowControl::process_tcp(Packet* p)
@@ -679,6 +628,7 @@ void FlowControl::init_udp(
         udp_cache->push(udp_mem + i);
 
     get_udp = get_ssn;
+    types.push_back(PktType::UDP);
 }
 
 void FlowControl::process_udp(Packet* p)
@@ -722,6 +672,7 @@ void FlowControl::init_user(
         user_cache->push(user_mem + i);
 
     get_user = get_ssn;
+    types.push_back(PktType::PDU);
 }
 
 void FlowControl::process_user(Packet* p)
@@ -765,6 +716,7 @@ void FlowControl::init_file(
         file_cache->push(file_mem + i);
 
     get_file = get_ssn;
+    types.push_back(PktType::FILE);
 }
 
 void FlowControl::process_file(Packet* p)
index 82f69519bf28654209fd02afe79635370c552e7b..6ea36bdefea7752fe5419061f0b20c63bc2beb17 100644 (file)
@@ -26,6 +26,7 @@
 // processed.  flows are pruned as needed to process new flows.
 
 #include <cstdint>
+#include <vector>
 
 #include "flow/flow_config.h"
 #include "framework/counts.h"
@@ -69,9 +70,9 @@ public:
     void delete_flow(const FlowKey*);
     void delete_flow(Flow*, PruneReason);
     void purge_flows(PktType);
-    void prune_flows(PktType, const Packet*);
     bool prune_one(PruneReason, bool do_cleanup);
-    void timeout_flows(uint32_t flowCount, time_t cur_time);
+
+    void timeout_flows(time_t cur_time);
 
     char expected_flow(Flow*, Packet*);
     bool is_expected(Packet*);
@@ -86,8 +87,6 @@ public:
         const sfip_t *dstIP, uint16_t dstPort,
         PktType, int16_t appId, FlowData*);
 
-    uint32_t max_flows(PktType);
-
     PegCount get_flows(PktType);
     PegCount get_total_prunes(PktType) const;
     PegCount get_prunes(PktType, PruneReason) const;
@@ -104,30 +103,33 @@ private:
     void preemptive_cleanup();
 
 private:
-    FlowCache* ip_cache;
-    FlowCache* icmp_cache;
-    FlowCache* tcp_cache;
-    FlowCache* udp_cache;
-    FlowCache* user_cache;
-    FlowCache* file_cache;
+    FlowCache* ip_cache = nullptr;
+    FlowCache* icmp_cache = nullptr;
+    FlowCache* tcp_cache = nullptr;
+    FlowCache* udp_cache = nullptr;
+    FlowCache* user_cache = nullptr;
+    FlowCache* file_cache = nullptr;
 
     // preallocated arrays
-    Flow* ip_mem;
-    Flow* icmp_mem;
-    Flow* tcp_mem;
-    Flow* udp_mem;
-    Flow* user_mem;
-    Flow* file_mem;
-
-    InspectSsnFunc get_ip;
-    InspectSsnFunc get_icmp;
-    InspectSsnFunc get_tcp;
-    InspectSsnFunc get_udp;
-    InspectSsnFunc get_user;
-    InspectSsnFunc get_file;
-
-    class ExpectCache* exp_cache;
-    PktType last_pkt_type;
+    Flow* ip_mem = nullptr;
+    Flow* icmp_mem = nullptr;
+    Flow* tcp_mem = nullptr;
+    Flow* udp_mem = nullptr;
+    Flow* user_mem = nullptr;
+    Flow* file_mem = nullptr;
+
+    InspectSsnFunc get_ip = nullptr;
+    InspectSsnFunc get_icmp = nullptr;
+    InspectSsnFunc get_tcp = nullptr;
+    InspectSsnFunc get_udp = nullptr;
+    InspectSsnFunc get_user = nullptr;
+    InspectSsnFunc get_file = nullptr;
+
+    class ExpectCache* exp_cache = nullptr;
+    PktType last_pkt_type = PktType::NONE;
+
+    std::vector<PktType> types;
+    unsigned next = 0;
 };
 
 #endif
index cc58cde571bcfe21fad0918184b66e68ecc3926e..6e6c4f5f43035ed4feba630dc590e953dbc58fcb 100644 (file)
@@ -141,9 +141,15 @@ typedef struct _FLOWBITS_GRP
     BitOp* GrpBitOp;
 } FLOWBITS_GRP;
 
+static std::forward_list<const FLOWBITS_OP*> op_list;
+
+static SFGHASH* flowbits_hash = NULL;
 static SFGHASH* flowbits_grp_hash = NULL;
+static SF_QUEUE* flowbits_bit_queue = NULL;
 
-static std::forward_list<const FLOWBITS_OP*> op_list;
+static unsigned flowbits_count = 0;
+static unsigned flowbits_grp_count = 0;
+static int flowbits_toggle = 1;
 
 static int check_flowbits(
     uint8_t type, uint8_t evalType, uint16_t* ids, uint16_t num_ids,
@@ -269,6 +275,19 @@ int FlowBitsOption::eval(Cursor&, Packet* p)
 // helper methods
 //-------------------------------------------------------------------------
 
+static inline BitOp* get_flow_bitop(const Packet* p)
+{
+    Flow* flow = p->flow;
+
+    if (!flow)
+        return NULL;
+
+    if ( !flow->bitop )
+        flow->bitop = new BitOp(flowbits_count);
+
+    return flow->bitop;
+}
+
 static inline int clear_group_bit(BitOp* bitop, char* group)
 {
     if ( !group )
@@ -391,15 +410,15 @@ static int check_flowbits(
     uint8_t type, uint8_t evalType, uint16_t* ids, uint16_t num_ids, char* group, Packet* p)
 {
     int rval = DETECTION_OPTION_NO_MATCH;
-    BitOp* bitop;
     Flowbits_eval eval = (Flowbits_eval)evalType;
     int result = 0;
     int i;
 
-    bitop = stream.get_flow_bitop(p);
+    BitOp* bitop = get_flow_bitop(p);
+
     if (!bitop)
     {
-        DebugMessage(DEBUG_FLOWBITS, "No FLOWBITS_DATA");
+        assert(false);
         return rval;
     }
 
@@ -509,25 +528,6 @@ static int check_flowbits(
 // public methods
 //-------------------------------------------------------------------------
 
-static SFGHASH* flowbits_hash = NULL;
-static SF_QUEUE* flowbits_bit_queue = NULL;
-static uint16_t flowbits_count = 0;
-static uint16_t flowbits_grp_count = 0;
-static int flowbits_toggle = 1;
-
-// FIXIT-P consider allocating flowbits on session on demand instead of
-// preallocating.
-
-unsigned int getFlowbitSize()
-{
-    return flowbits_count;
-}
-
-unsigned int getFlowbitSizeInBytes()
-{
-    return flowbits_count ? (flowbits_count + 7) >> 3 : 1;
-}
-
 void FlowbitResetCounts()
 {
     SFGHASH_NODE* n;
@@ -605,7 +605,7 @@ static FLOWBITS_OBJECT* getFlowBitItem(char* flowbitName, FLOWBITS_OP* flowbits)
             if ( !flowbits_count )
             {
                 ParseError("The number of flowbit IDs in the current ruleset exceeds "
-                    "the maximum number of IDs that are allowed (65535).");
+                    "the maximum number of IDs that are allowed (%u).", flowbits_count-1);
             }
         }
 
@@ -981,14 +981,12 @@ static void init_groups()
     if ( !flowbits_hash or !flowbits_grp_hash )
         return;
 
-    unsigned size = getFlowbitSizeInBytes();
-
     for ( SFGHASH_NODE* n = sfghash_findfirst(flowbits_grp_hash);
         n != NULL;
         n= sfghash_findnext(flowbits_grp_hash) )
     {
         FLOWBITS_GRP* fbg = (FLOWBITS_GRP*)n->data;
-        fbg->GrpBitOp = new BitOp(size);
+        fbg->GrpBitOp = new BitOp(flowbits_count);
         fbg->GrpBitOp->reset();
     }
 
index b0dd766aff6087c2a9177749b1af578ca9c25d28..f5e52d8aa208441f4faf19e2a9360795b74c35cf 100644 (file)
@@ -23,9 +23,5 @@
 void FlowbitResetCounts();
 int FlowBits_SetOperation(void*);
 
-void setFlowbitSize(unsigned);
-unsigned int getFlowbitSize();
-unsigned int getFlowbitSizeInBytes();
-
 #endif
 
index c38c30ff3a4a4a13aa7e219d49ccbd1fcda8eb8a..0cc4fb3262a468cdcb93a16e28c561e751a524e5 100644 (file)
@@ -95,11 +95,13 @@ THREAD_LOCAL LatencyStats latency_stats;
 
 static const PegInfo latency_pegs[] =
 {
-    { "total_packets", "total packets monitored" },
-    { "packet_timeouts", "packets that timed out" },
-    { "total_rule_evals", "total rule evals monitored" },
-    { "rule_eval_timeouts", "rule evals that timed out" },
-    { "rule_tree_enables", "rule tree re-enables" },
+    { "total packets", "total packets monitored" },
+    { "total usecs", "total usecs elapsed" },
+    { "max usecs", "maximum usecs elapsed" },
+    { "packet timeouts", "packets that timed out" },
+    { "total rule evals", "total rule evals monitored" },
+    { "rule eval timeouts", "rule evals that timed out" },
+    { "rule tree enables", "rule tree re-enables" },
     { nullptr, nullptr }
 };
 
index 9b317e3165636bdfc2303e1bc8b9ca2c229ee9f7..4762b24bd055a31b4dd9f90cd0c61e8fb1830e02 100644 (file)
@@ -27,6 +27,8 @@
 struct LatencyStats
 {
     PegCount total_packets;
+    PegCount total_usecs;
+    PegCount max_usecs;
     PegCount packet_timeouts;
     PegCount total_rule_evals;
     PegCount rule_eval_timeouts;
index ebf12cc02d13518e581aba2224a3a73bd3ef784b..4c171bab4fe2161ecb4645886e6db32590afa57f 100644 (file)
@@ -29,6 +29,7 @@
 #include "protocols/packet.h"
 #include "sfip/sf_ip.h"
 #include "time/clock_defs.h"
+#include "utils/stats.h"
 
 #include "latency_config.h"
 #include "latency_timer.h"
@@ -44,6 +45,8 @@
 #include "catch/catch.hpp"
 #endif
 
+static THREAD_LOCAL uint64_t elapsed = 0;
+
 namespace packet_latency
 {
 // -----------------------------------------------------------------------------
@@ -84,7 +87,7 @@ static inline std::ostream& operator<<(std::ostream& os, const Event& e)
     using std::chrono::duration_cast;
     using std::chrono::microseconds;
 
-    os << "latency: packet timed out";
+    os << "latency: packet " << pc.total_from_daq << " timed out";
     if ( e.fastpathed )
         os << " (fastpathed)";
 
@@ -155,6 +158,11 @@ inline bool Impl<Clock>::pop(const Packet* p)
             event_handler.handle(e);
     }
 
+    // FIXIT-H this is fugly and inefficient
+    using std::chrono::duration_cast;
+    using std::chrono::microseconds;
+    elapsed = clock_usecs(duration_cast<microseconds>(timer.elapsed()).count());
+
     timers.pop_back();
     return timed_out;
 }
@@ -236,6 +244,12 @@ void PacketLatency::pop(const Packet* p)
     {
         if ( packet_latency::get_impl().pop(p) )
             ++latency_stats.packet_timeouts;
+
+        // FIXIT-L the timer is still running so this max is slightly larger than logged
+        if ( elapsed > latency_stats.max_usecs )
+            latency_stats.max_usecs = elapsed;
+
+        latency_stats.total_usecs += elapsed;
     }
 }
 
index 6f01719edb9ca569cba61e6ccd756e36f9397fc0..0963d1dcbf3207de636b6ced7c0771ab38af16ab 100644 (file)
@@ -602,7 +602,9 @@ void Snort::capture_packet()
 void Snort::thread_idle()
 {
     if ( flow_con )
-        flow_con->timeout_flows(16384, time(NULL));
+        // FIXIT-M batch here or loop vs looping over idle?
+        flow_con->timeout_flows(time(NULL));
+
     perf_monitor_idle_process();
     aux_counts.idle++;
     HighAvailabilityManager::process_receive();
@@ -852,9 +854,7 @@ DAQ_Verdict Snort::packet_callback(
     PacketManager::encode_reset();
 
     if ( flow_con ) // FIXIT-M always instantiate
-    {
-        flow_con->timeout_flows(4, pkthdr->ts.tv_sec);
-    }
+        flow_con->timeout_flows(pkthdr->ts.tv_sec);
 
     HighAvailabilityManager::process_receive();
 
index 87554efab269b7c82d0e6ce588a4abc522f8b8d0..c28ab3b2278fd64dbc13eece590272ad437618c5 100644 (file)
@@ -147,7 +147,7 @@ bool AppIdApi::is_ssl_session_decrypted(AppIdSession* session)
 
 AppIdSession* AppIdApi::get_appid_data(Flow* flow)
 {
-    AppIdSession* session = (AppIdSession*) flow->get_application_data(AppIdSession::flow_id);
+    AppIdSession* session = (AppIdSession*) flow->get_flow_data(AppIdSession::flow_id);
 
     return (session && session->common.fsf_type.flow_type == APPID_SESSION_TYPE_NORMAL) ?
            session : nullptr;
@@ -492,7 +492,7 @@ char* AppIdApi::get_netbios_name(AppIdSession* session)
 uint32_t AppIdApi::produce_ha_state(void* lwssn, uint8_t* buf)
 {
     AppIdSessionHA* appHA = (AppIdSessionHA*)buf;
-    AppIdSession* session = (AppIdSession*)(((Flow*)lwssn)->get_application_data(AppIdSession::flow_id));
+    AppIdSession* session = (AppIdSession*)(((Flow*)lwssn)->get_flow_data(AppIdSession::flow_id));
 
     // FIXIT - getFlowType should be a class member
     if (session && get_flow_type(session) != APPID_FLOW_TYPE_NORMAL)
@@ -529,13 +529,13 @@ uint32_t AppIdApi::consume_ha_state(void* lwssn, const uint8_t* buf, uint8_t, Ip
     AppIdSessionHA* appHA = (AppIdSessionHA*)buf;
     if (appHA->flags & APPID_HA_FLAGS_APP)
     {
-        AppIdSession* session = (AppIdSession*)(((Flow*)lwssn)->get_application_data(
+        AppIdSession* session = (AppIdSession*)(((Flow*)lwssn)->get_flow_data(
             AppIdSession::flow_id));
 
         if (!session)
         {
             session = new AppIdSession(proto, ip);
-            ((Flow*)lwssn)->set_application_data(session);
+            ((Flow*)lwssn)->set_flow_data(session);
             if (session->serviceAppId == APP_ID_FTP_CONTROL)
             {
                 session->setAppIdFlag(APPID_SESSION_CLIENT_DETECTED |
index 7e5a87b2c14a2b58771ca590bd7f7c8d9fab7378..e0364c4861623892f496fbd618eab1828b08f697 100644 (file)
@@ -424,7 +424,7 @@ AppIdSession* AppIdSession::allocate_session(const Packet* p, IpProtocol proto,
     data->flow = p->flow;
     data->stats.firstPktsecond = p->pkth->ts.tv_sec;
 
-    p->flow->set_application_data(data);
+    p->flow->set_flow_data(data);
     return data;
 }
 
@@ -1604,7 +1604,7 @@ void AppIdSession::do_application_discovery(Packet* p)
     if( is_packet_ignored(p) )
         return;
 
-    AppIdSession* session = (AppIdSession*) p->flow->get_application_data(AppIdSession::flow_id);
+    AppIdSession* session = (AppIdSession*) p->flow->get_flow_data(AppIdSession::flow_id);
     if (session)
     {
         if (session->common.fsf_type.flow_type == APPID_SESSION_TYPE_IGNORE)
@@ -1655,11 +1655,11 @@ void AppIdSession::do_application_discovery(Packet* p)
                 APPID_SESSION_BIDIRECTIONAL_CHECKED)
             {
                 // FIXIT-M: This _dpd call needs to be convert to correct snort++ call
-                // static THREAD_LOCAL APPID_SESSION_STRUCT_FLAG ignore_fsf {
-                // APPID_SESSION_TYPE_IGNORE };
+                // static THREAD_LOCAL APPID_SESSION_STRUCT_FLAG ignore_fsf
+                // { APPID_SESSION_TYPE_IGNORE };
+
+                // p->flow->set_flow_data(PP_APP_ID, &ignore_fsf, nullptr);
 
-                // _dpd.sessionAPI->set_application_data(p->flow, PP_APP_ID, &ignore_fsf,
-                //     nullptr);
                 if (app_id_debug_session_flag)
                     LogMessage("AppIdDbg %s not monitored\n", app_id_debug_session);
             }
@@ -1681,7 +1681,7 @@ void AppIdSession::do_application_discovery(Packet* p)
                 else
                     tmp_session->common.initiator_port = 0;
                 tmp_session->common.policyId = appIdPolicyId;
-                p->flow->set_application_data(tmp_session);
+                p->flow->set_flow_data(tmp_session);
                 if (app_id_debug_session_flag)
                     LogMessage("AppIdDbg %s unknown monitoring\n", app_id_debug_session);
             }
index 930d09719f1855dc6758334d7b5b43d7514b4b6d..e68cf3770980c7fb5e159e05fb7455dbdf178db1 100644 (file)
@@ -173,12 +173,12 @@ void enable_preproc_all_ports(struct _SnortConfig*, uint32_t, uint32_t)
 {
 }
 
-void* get_application_data(void*, uint32_t)
+void* get_flow_data(void*, uint32_t)
 {
     return pAppIdData;
 }
 
-int set_application_data(void*, uint32_t, AppIdSession* data, StreamAppDataFree)
+int set_flow_data(void*, uint32_t, AppIdSession* data, StreamAppDataFree)
 {
     pAppIdData = data;
 
index 923d1a49668866da2f6325bbf6f48e69fa7cb31a..7c2c540d2d9a648933b866e2f83f6e2b39fee02e 100644 (file)
@@ -53,8 +53,8 @@ int16_t findProtocolReference(const char* app);
 
 // Session APIs
 void enable_preproc_all_ports(SnortConfig*, uint32_t appId, uint32_t flags);
-void* get_application_data(void* stream_session, uint32_t protocol);
-int set_application_data(void* scbptr, uint32_t protocol, void* data, StreamAppDataFree);
+void* get_flow_data(void* stream_session, uint32_t protocol);
+int set_flow_data(void* scbptr, uint32_t protocol, void* data, StreamAppDataFree);
 uint32_t get_packet_direction(Packet*);
 uint32_t get_session_flags(void* ssnptr);
 sfaddr_t* get_session_ip_address(void* scbptr, uint32_t direction);
index ef86ec8b1ba2bff57748def8d1def2ff75166ba1..bd3db5b04dbfc8d7b2e0f35ab462e601178a9fbc 100644 (file)
@@ -34,7 +34,6 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
-#include "bitop.h"
 #include "bnfa_search.h"
 #include "acsmx.h"
 #include "acsmx2.h"
@@ -464,17 +463,6 @@ int mpsePrepPatternsWithSnortConf(struct _SnortConfig* sc, void* pvoid,
     return retv;
 }
 
-void mpseSetRuleMask(void* pvoid, BITOP* rm)
-{
-    MPSE* p = (MPSE*)pvoid;
-
-    switch ( p->method )
-    {
-    default:
-        return;
-    }
-}
-
 int mpsePrintInfo(void* pvoid)
 {
     MPSE* p = (MPSE*)pvoid;
index e49034e9c69a0f3227ca0aaebf2181b15e283a1e..831a9aebed8d5a6d28001dc488c3c371702372c7 100644 (file)
@@ -207,7 +207,7 @@ static void set_session(Flow* flow)
 
 static void set_service(Flow* flow, const HostAttributeEntry* host)
 {
-    stream.set_application_protocol_id_from_host_entry(flow, host, FROM_SERVER);
+    stream.set_application_protocol_id(flow, host, FROM_SERVER);
 }
 
 static Inspector* get_gadget(Flow* flow)
index 2ed484df58d45b4b105db3ccb07cb674184264af..f7c37d73a04d44e225df84c4967099a9f606a71a 100644 (file)
@@ -90,7 +90,7 @@ unsigned THREAD_LOCAL Inspector::slot = 0;
 void ParseError(const char*, ...) { }
 void LogMessage(const char*,...) { }
 
-void Stream::set_application_protocol_id_from_host_entry(Flow*, HostAttributeEntry const*, int) { }
+void Stream::set_application_protocol_id(Flow*, HostAttributeEntry const*, int) { }
 void Stream::set_splitter(Flow*, bool, class StreamSplitter*) { }
 const char* get_protocol_name(uint16_t) { return ""; }
 int16_t FindProtocolReference(const char*) { return 0; }
@@ -118,7 +118,7 @@ TEST(binder, exec)
     memset(conf,0,sizeof(SnortConfig));
     snort_conf = (SnortConfig*)conf;
     Flow* flow = new Flow;
-    constexpr size_t offset = offsetof(Flow, appDataList);
+    constexpr size_t offset = offsetof(Flow, flow_data);
     memset((uint8_t*)flow+offset, 0, sizeof(Flow)-offset);
 
     s_inspector = new MyInspector();
index 06eeaf4842b7d1c2f8d7aabe000a8bdefb997dd6..229278e193581784b7088b0d3d477accac356259 100644 (file)
@@ -87,13 +87,13 @@ unsigned ReputationFlowData::flow_id = 0;
 static ReputationData* SetNewReputationData(Flow* flow)
 {
     ReputationFlowData* fd = new ReputationFlowData;
-    flow->set_application_data(fd);
+    flow->set_flow_data(fd);
     return &fd->session;
 }
 
 static ReputationData* get_session_data(Flow* flow)
 {
-    ReputationFlowData* fd = (ReputationFlowData*)flow->get_application_data(
+    ReputationFlowData* fd = (ReputationFlowData*)flow->get_flow_data(
         ReputationFlowData::flow_id);
 
     return fd ? &fd->session : nullptr;
index 1b8a75673f9b1fa20254cf507f9a8486243bda69..600a687c72b4aab75bd02dea8925241eee2e4634 100644 (file)
@@ -40,7 +40,7 @@ THREAD_LOCAL Active::ActiveAction Active::active_action = Active::ACT_PASS;
 THREAD_LOCAL Active::ActiveAction Active::delayed_active_action = Active::ACT_PASS;
 
 THREAD_LOCAL int Active::active_tunnel_bypass = 0;
-THREAD_LOCAL bool Active::active_suspend = 0;
+THREAD_LOCAL bool Active::active_suspend = false;
 
 THREAD_LOCAL uint8_t Active::s_attempts = 0;
 THREAD_LOCAL uint64_t Active::s_injects = 0;
index a93fdb67fedd7ffff7d42665d522654c3fd1f47f..4c6f3127c598f9584e6e0f92941f9298873bd18b 100644 (file)
@@ -1660,18 +1660,15 @@ unsigned Dce2SmbFlowData::flow_id = 0;
 
 DCE2_SmbSsnData* get_dce2_smb_session_data(Flow* flow)
 {
-    Dce2SmbFlowData* fd = (Dce2SmbFlowData*)flow->get_application_data(
-        Dce2SmbFlowData::flow_id);
-
+    Dce2SmbFlowData* fd = (Dce2SmbFlowData*)flow->get_flow_data(Dce2SmbFlowData::flow_id);
     return fd ? &fd->dce2_smb_session : nullptr;
 }
 
 static DCE2_SmbSsnData* set_new_dce2_smb_session(Packet* p)
 {
     Dce2SmbFlowData* fd = new Dce2SmbFlowData;
-
     memset(&fd->dce2_smb_session,0,sizeof(DCE2_SmbSsnData));
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     return(&fd->dce2_smb_session);
 }
 
index 604d781796625234d97907716cbac137818994a3..45c7828d37c0af8e0e7568a9538982acd48a79c6 100644 (file)
@@ -61,9 +61,7 @@ unsigned Dce2TcpFlowData::flow_id = 0;
 
 DCE2_TcpSsnData* get_dce2_tcp_session_data(Flow* flow)
 {
-    Dce2TcpFlowData* fd = (Dce2TcpFlowData*)flow->get_application_data(
-        Dce2TcpFlowData::flow_id);
-
+    Dce2TcpFlowData* fd = (Dce2TcpFlowData*)flow->get_flow_data(Dce2TcpFlowData::flow_id);
     return fd ? &fd->dce2_tcp_session : nullptr;
 }
 
@@ -72,7 +70,7 @@ static DCE2_TcpSsnData* set_new_dce2_tcp_session(Packet* p)
     Dce2TcpFlowData* fd = new Dce2TcpFlowData;
 
     memset(&fd->dce2_tcp_session,0,sizeof(DCE2_TcpSsnData));
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     return(&fd->dce2_tcp_session);
 }
 
index fd0f27ae69490a99d478a820b0bf3ed7a6bb8b65..e8a5150760d52e87b4f063536efdda2d6d1225b1 100644 (file)
@@ -36,17 +36,14 @@ unsigned Dnp3FlowData::flow_id = 0;
 
 static dnp3_session_data_t* get_session_data(Flow* flow)
 {
-    Dnp3FlowData* fd = (Dnp3FlowData*)flow->get_application_data(
-        Dnp3FlowData::flow_id);
-
+    Dnp3FlowData* fd = (Dnp3FlowData*)flow->get_flow_data(Dnp3FlowData::flow_id);
     return fd ? &fd->dnp3_session : nullptr;
 }
 
 static dnp3_session_data_t* set_new_dnp3_session(Packet* p)
 {
     Dnp3FlowData* fd = new Dnp3FlowData;
-
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     return(&fd->dnp3_session);
 }
 
index 677473a81d6b19b2d593639427b71c34c4e35533..277181deaad566fe2018ae184dbc7d9980f2a982 100644 (file)
@@ -72,8 +72,7 @@ int Dnp3DataOption::eval(Cursor& c, Packet* p)
     if ((p->has_tcp_data() && !p->is_full_pdu()) || !p->flow || !p->dsize)
         return DETECTION_OPTION_NO_MATCH;
 
-    Dnp3FlowData* fd = (Dnp3FlowData*)p->flow->get_application_data(
-        Dnp3FlowData::flow_id);
+    Dnp3FlowData* fd = (Dnp3FlowData*)p->flow->get_flow_data(Dnp3FlowData::flow_id);
 
     if (!fd)
         return DETECTION_OPTION_NO_MATCH;
index 2a571a52bab79ebd38a2febe16dafe5ac8365984..00fa7e247a64d295ba5ee6d909fa747a6ee08d13 100644 (file)
@@ -79,8 +79,7 @@ int Dnp3FuncOption::eval(Cursor&, Packet* p)
     if ((p->has_tcp_data() && !p->is_full_pdu()) || !p->flow || !p->dsize)
         return DETECTION_OPTION_NO_MATCH;
 
-    Dnp3FlowData* fd = (Dnp3FlowData*)p->flow->get_application_data(
-        Dnp3FlowData::flow_id);
+    Dnp3FlowData* fd = (Dnp3FlowData*)p->flow->get_flow_data(Dnp3FlowData::flow_id);
 
     if (!fd)
         return DETECTION_OPTION_NO_MATCH;
index 9f0585f6f1effa2bc02b5cb7625467a14b701ea0..276944f77cdd2fe5652fd561c0594a69438c7b6b 100644 (file)
@@ -80,8 +80,7 @@ int Dnp3IndOption::eval(Cursor&, Packet* p)
     if ((p->has_tcp_data() && !p->is_full_pdu()) || !p->flow || !p->dsize)
         return DETECTION_OPTION_NO_MATCH;
 
-    Dnp3FlowData* fd = (Dnp3FlowData*)p->flow->get_application_data(
-        Dnp3FlowData::flow_id);
+    Dnp3FlowData* fd = (Dnp3FlowData*)p->flow->get_flow_data(Dnp3FlowData::flow_id);
 
     if (!fd)
         return DETECTION_OPTION_NO_MATCH;
index e63d76e15e25f7a3284916c130ed1385b970295c..910315a7362e772f0176fb7d7e5aa5e56b690536 100644 (file)
@@ -112,8 +112,7 @@ int Dnp3ObjOption::eval(Cursor&, Packet* p)
     if ((p->has_tcp_data() && !p->is_full_pdu()) || !p->flow || !p->dsize)
         return DETECTION_OPTION_NO_MATCH;
 
-    Dnp3FlowData* fd = (Dnp3FlowData*)p->flow->get_application_data(
-        Dnp3FlowData::flow_id);
+    Dnp3FlowData* fd = (Dnp3FlowData*)p->flow->get_flow_data(Dnp3FlowData::flow_id);
 
     if (!fd)
         return DETECTION_OPTION_NO_MATCH;
index 2af9ca68b17297447f3dde6de70ce7b2d7502978..3b5ad91a62834e178d8a9d7ea03018cc9fef52b7 100644 (file)
@@ -79,7 +79,7 @@ static DNSData* SetNewDNSData(Packet* p)
 
     fd = new DnsFlowData;
 
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     return &fd->session;
 }
 
@@ -107,9 +107,7 @@ static DNSData* get_dns_session_data(Packet* p, bool from_server)
         return &udpSessionData;
     }
 
-    fd = (DnsFlowData*)((p->flow)->get_application_data(
-        DnsFlowData::flow_id));
-
+    fd = (DnsFlowData*)((p->flow)->get_flow_data(DnsFlowData::flow_id));
     return fd ? &fd->session : NULL;
 }
 
index 25afbdc5bab243fd37c4b34d902b53d9702eb466..e781d8c266dd35617269dd997b1bfa2f6e22a196 100644 (file)
@@ -138,7 +138,7 @@ static int snort_ftp(Packet* p)
 
     if (p->flow)
     {
-        FtpFlowData* fd = (FtpFlowData*)p->flow->get_application_data(FtpFlowData::flow_id);
+        FtpFlowData* fd = (FtpFlowData*)p->flow->get_flow_data(FtpFlowData::flow_id);
         ft_ssn = fd ? &fd->session.ft_ssn : nullptr;
 
         if (ft_ssn != NULL)
@@ -171,7 +171,7 @@ static int snort_ftp(Packet* p)
             {
                 /* XXX - Not FTP or Telnet */
                 assert(false);
-                p->flow->free_application_data(FtpFlowData::flow_id);
+                p->flow->free_flow_data(FtpFlowData::flow_id);
                 return 0;
             }
         }
index 59a884ce38bb0a522004748f8e0067f75dcc870a..1eb04fe410899542a3c03573f7f6ceda00be8213 100644 (file)
@@ -82,7 +82,7 @@ static int SnortFTPData(Packet* p)
         return -1;
 
     FtpDataFlowData* fd = (FtpDataFlowData*)
-        p->flow->get_application_data(FtpFlowData::flow_id);
+        p->flow->get_flow_data(FtpFlowData::flow_id);
 
     FTP_DATA_SESSION* data_ssn = fd ? &fd->session : nullptr;
 
@@ -100,7 +100,7 @@ static int SnortFTPData(Packet* p)
         /* FTP-Data session is in limbo, we need to lookup the control session
          * to figure out what to do. */
 
-        FtpFlowData* fd = (FtpFlowData*)stream.get_application_data_from_key(
+        FtpFlowData* fd = (FtpFlowData*)stream.get_flow_data(
             &data_ssn->ftp_key, FtpFlowData::flow_id);
 
         FTP_SESSION* ftp_ssn = fd ? &fd->session : NULL;
index 9c182a90b8ca91d17cc173d6b9aa13409a843829..9080c3eb3fe6a0118d546c4119d1d4a8bddbf6dc 100644 (file)
@@ -101,7 +101,7 @@ static int TelnetStatefulsessionInspection(Packet* p,
 
         SiInput->pproto = FTPP_SI_PROTO_TELNET;
 
-        p->flow->set_application_data(fd);
+        p->flow->set_flow_data(fd);
 
         *Telnetsession = Newsession;
         return FTPP_SUCCESS;
@@ -421,7 +421,7 @@ static int FTPStatefulsessionInspection(
             Newsession->client_conf = ClientConf;
             Newsession->server_conf = ServerConf;
 
-            p->flow->set_application_data(fd);
+            p->flow->set_flow_data(fd);
 
             *Ftpsession = Newsession;
             SiInput->pproto = FTPP_SI_PROTO_FTP;
index 1da8a91d8c5998a8d0735f0c445a32c5225f01ed..b3f6816e028402ae2e657638361e5e7b5b87af6b 100644 (file)
@@ -111,7 +111,7 @@ static int snort_telnet(TELNET_PROTO_CONF* GlobalConf, Packet* p)
     if (p->flow)
     {
         TelnetFlowData* fd = (TelnetFlowData*)
-            p->flow->get_application_data(FtpFlowData::flow_id);
+            p->flow->get_flow_data(FtpFlowData::flow_id);
 
         ft_ssn = fd ? &fd->session.ft_ssn : nullptr;
 
@@ -140,7 +140,7 @@ static int snort_telnet(TELNET_PROTO_CONF* GlobalConf, Packet* p)
             else
             {
                 assert(false);
-                p->flow->free_application_data(FtpFlowData::flow_id);
+                p->flow->free_flow_data(FtpFlowData::flow_id);
                 return 0;
             }
         }
index f2180e74c8a19529a39dba8c10cab35e6b7e9c3b..10fe59ca8a2eec0942a219180029d155cfdb5e2e 100644 (file)
@@ -87,7 +87,7 @@ static inline int GTP_Process(Packet* p, GTP_Roptions* pRopts)
 static GTP_Roptions* GTPGetNewSession(Packet* packetp)
 {
     GtpFlowData* gfd = new GtpFlowData;
-    packetp->flow->set_application_data(gfd);
+    packetp->flow->set_flow_data(gfd);
 
     GTP_Roptions* pRopts = &gfd->ropts;
     gtp_stats.sessions++;
@@ -99,7 +99,7 @@ static GTP_Roptions* GTPGetNewSession(Packet* packetp)
 void GTPmain(Packet* packetp)
 {
     /* Attempt to get a previously allocated GTP block. */
-    GtpFlowData* gfd = (GtpFlowData*)packetp->flow->get_application_data(GtpFlowData::flow_id);
+    GtpFlowData* gfd = (GtpFlowData*)packetp->flow->get_flow_data(GtpFlowData::flow_id);
     GTP_Roptions* pRopts = gfd ? &gfd->ropts : nullptr;
 
     if ( !pRopts )
index 8edfcfb8e3a8e71a799dc29ea4cfe00db7f9bf4f..fe78c5831281d0a78620cabb8f56794e72eef1b6 100644 (file)
@@ -105,7 +105,7 @@ int GtpInfoOption::eval(Cursor& c, Packet* p)
     if ( !p or !p->flow )
         return DETECTION_OPTION_NO_MATCH;
 
-    GtpFlowData* gfd = (GtpFlowData*)p->flow->get_application_data(GtpFlowData::flow_id);
+    GtpFlowData* gfd = (GtpFlowData*)p->flow->get_flow_data(GtpFlowData::flow_id);
 
     if ( !gfd or !gfd->ropts.gtp_infoElements )
         return DETECTION_OPTION_NO_MATCH;
index baf6a926cd915e95a13c816782b83243e91d299c..b02c9228efe7fec748ea37828c2b8b4eba9c58a7 100644 (file)
@@ -105,7 +105,7 @@ int GtpTypeOption::eval(Cursor&, Packet* p)
     if ( !p or !p->flow )
         return DETECTION_OPTION_NO_MATCH;
 
-    GtpFlowData* gfd = (GtpFlowData*)p->flow->get_application_data(GtpFlowData::flow_id);
+    GtpFlowData* gfd = (GtpFlowData*)p->flow->get_flow_data(GtpFlowData::flow_id);
 
     if ( !gfd )
         return DETECTION_OPTION_NO_MATCH;
index b2f53f304a9333509878af60199d6cb153e2248e..b4388cf7684a69947611dbee7730f76b1316d239 100644 (file)
@@ -84,7 +84,7 @@ int GtpVersionOption::eval(Cursor&, Packet* p)
     if ( !p or !p->flow )
         return DETECTION_OPTION_NO_MATCH;
 
-    GtpFlowData* gfd = (GtpFlowData*)p->flow->get_application_data(GtpFlowData::flow_id);
+    GtpFlowData* gfd = (GtpFlowData*)p->flow->get_flow_data(GtpFlowData::flow_id);
 
     if ( gfd and version == gfd->ropts.gtp_version )
         return DETECTION_OPTION_MATCH;
index e653bdaf99b1ab4e49e5710a26a67f803dde6153..1c6d7c933d918df5640fad3e19d5883f6e5b5c55 100644 (file)
@@ -126,8 +126,7 @@ bool HttpInspect::get_fp_buf(InspectionBuffer::Type ibt, Packet*, InspectionBuff
 const Field& HttpInspect::process(const uint8_t* data, const uint16_t dsize, Flow* const flow,
     SourceId source_id, bool buf_owner) const
 {
-    HttpFlowData* session_data = (HttpFlowData*)flow->get_application_data(
-        HttpFlowData::http_flow_id);
+    HttpFlowData* session_data = (HttpFlowData*)flow->get_flow_data(HttpFlowData::http_flow_id);
     assert(session_data != nullptr);
 
     HttpModule::increment_peg_counts(PEG_INSPECT);
@@ -196,7 +195,7 @@ void HttpInspect::clear(Packet* p)
     latest_section = nullptr;
 
     HttpFlowData* session_data =
-        (HttpFlowData*)p->flow->get_application_data(HttpFlowData::http_flow_id);
+        (HttpFlowData*)p->flow->get_flow_data(HttpFlowData::http_flow_id);
 
     if (session_data == nullptr)
         return;
index 6240488d885c4f58beea825e7b59eeddb41bd31a..4b14f0ae24ae1e30df24a2d379853c030fc19dd8 100644 (file)
@@ -207,8 +207,7 @@ const StreamBuffer* HttpStreamSplitter::reassemble(Flow* flow, unsigned total, u
 
     assert(total <= MAX_OCTETS);
 
-    HttpFlowData* session_data = (HttpFlowData*)flow->get_application_data(
-        HttpFlowData::http_flow_id);
+    HttpFlowData* session_data = (HttpFlowData*)flow->get_flow_data(HttpFlowData::http_flow_id);
     assert(session_data != nullptr);
 
 #ifdef REG_TEST
index c5acc658c3fe0e8965536e288a3bb85e238764f2..5f795fb60e4e4bda11132789f8393abde4aea5ff 100644 (file)
@@ -85,11 +85,11 @@ StreamSplitter::Status HttpStreamSplitter::scan(Flow* flow, const uint8_t* data,
     // This is the session state information we share with HttpInspect and store with stream. A
     // session is defined by a TCP connection. Since scan() is the first to see a new TCP
     // connection the new flow data object is created here.
-    HttpFlowData* session_data = (HttpFlowData*)flow->get_application_data(
-        HttpFlowData::http_flow_id);
+    HttpFlowData* session_data = (HttpFlowData*)flow->get_flow_data(HttpFlowData::http_flow_id);
+
     if (session_data == nullptr)
     {
-        flow->set_application_data(session_data = new HttpFlowData);
+        flow->set_flow_data(session_data = new HttpFlowData);
         HttpModule::increment_peg_counts(PEG_FLOW);
     }
 
@@ -205,9 +205,7 @@ StreamSplitter::Status HttpStreamSplitter::scan(Flow* flow, const uint8_t* data,
 
 bool HttpStreamSplitter::finish(Flow* flow)
 {
-    HttpFlowData* session_data = (HttpFlowData*)flow->get_application_data(
-        HttpFlowData::http_flow_id);
-
+    HttpFlowData* session_data = (HttpFlowData*)flow->get_flow_data(HttpFlowData::http_flow_id);
     assert(session_data != nullptr);
 
 #ifdef REG_TEST
index f992c8c9a292ad3af3dc03eff18d10202cc8313b..8d88c6e363305e9651a6f75e060aefa4f14cd5ba 100644 (file)
@@ -159,9 +159,7 @@ ImapFlowData::~ImapFlowData()
 unsigned ImapFlowData::flow_id = 0;
 static IMAPData* get_session_data(Flow* flow)
 {
-    ImapFlowData* fd = (ImapFlowData*)flow->get_application_data(
-        ImapFlowData::flow_id);
-
+    ImapFlowData* fd = (ImapFlowData*)flow->get_flow_data(ImapFlowData::flow_id);
     return fd ? &fd->session : NULL;
 }
 
@@ -170,7 +168,7 @@ static IMAPData* SetNewIMAPData(IMAP_PROTO_CONF* config, Packet* p)
     IMAPData* imap_ssn;
     ImapFlowData* fd = new ImapFlowData;
 
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     imap_ssn = &fd->session;
 
     imapstats.sessions++;
index db48c5f8cfa34ff1748923143ac7e28118eab2d8..0d9c9272454fda45f9f6d49d53483640669605ab 100644 (file)
@@ -131,7 +131,7 @@ int ModbusFuncOption::eval(Cursor&, Packet* p)
         return DETECTION_OPTION_NO_MATCH;
 
     ModbusFlowData* mfd =
-        (ModbusFlowData*)p->flow->get_application_data(ModbusFlowData::flow_id);
+        (ModbusFlowData*)p->flow->get_flow_data(ModbusFlowData::flow_id);
 
     if ( mfd and func == mfd->ssn_data.func )
         return DETECTION_OPTION_MATCH;
index e128b354d03dae6e53218b4dd8177357126b686a..a521015a3f2044eb17b5ec8ecbc2dac2a3e6008b 100644 (file)
@@ -83,7 +83,7 @@ int ModbusUnitOption::eval(Cursor&, Packet* p)
         return DETECTION_OPTION_NO_MATCH;
 
     ModbusFlowData* mfd =
-        (ModbusFlowData*)p->flow->get_application_data(ModbusFlowData::flow_id);
+        (ModbusFlowData*)p->flow->get_flow_data(ModbusFlowData::flow_id);
 
     if ( mfd and unit == mfd->ssn_data.unit )
         return DETECTION_OPTION_MATCH;
index 83af926cd917122a2af4ccffc675572c857f8e25..e7b0faf317e088b0d9134138742ea2c10391433a 100644 (file)
@@ -75,7 +75,7 @@ void Modbus::eval(Packet* p)
     assert(p->has_tcp_data());
 
     ModbusFlowData* mfd =
-        (ModbusFlowData*)p->flow->get_application_data(ModbusFlowData::flow_id);
+        (ModbusFlowData*)p->flow->get_flow_data(ModbusFlowData::flow_id);
 
     if ( !p->is_full_pdu() )
     {
@@ -93,7 +93,7 @@ void Modbus::eval(Packet* p)
     if ( !mfd )
     {
         mfd = new ModbusFlowData;
-        p->flow->set_application_data(mfd);
+        p->flow->set_flow_data(mfd);
         modbus_stats.sessions++;
     }
 
index 4dbe62e5cbf5ac0c6889eed1f147fada9196feee..c04d89607f7b4361d225daf475541ec8b4618093 100644 (file)
@@ -406,7 +406,7 @@ bool ModbusDecode(Packet* p)
         return false;
 
     ModbusFlowData* mfd =
-        (ModbusFlowData*)p->flow->get_application_data(ModbusFlowData::flow_id);
+        (ModbusFlowData*)p->flow->get_flow_data(ModbusFlowData::flow_id);
 
     /* Lay the header struct over the payload */
     header = (modbus_header_t*)p->data;
index 6ad2721658b9df48b3cc8731fc2b8590102ab564..bf5fbda39d21b2e28808475df884afaa36721de9 100644 (file)
@@ -118,9 +118,7 @@ PopFlowData::~PopFlowData()
 unsigned PopFlowData::flow_id = 0;
 static POPData* get_session_data(Flow* flow)
 {
-    PopFlowData* fd = (PopFlowData*)flow->get_application_data(
-        PopFlowData::flow_id);
-
+    PopFlowData* fd = (PopFlowData*)flow->get_flow_data(PopFlowData::flow_id);
     return fd ? &fd->session : NULL;
 }
 
@@ -129,7 +127,7 @@ static POPData* SetNewPOPData(POP_PROTO_CONF* config, Packet* p)
     POPData* pop_ssn;
     PopFlowData* fd = new PopFlowData;
 
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     pop_ssn = &fd->session;
 
     popstats.sessions++;
index aa7fe7815dd8c5310f6eeafe97965e3a58047dd4..fdca04384c3783de2d96092e7aeb4ba5d6aca938 100644 (file)
@@ -656,7 +656,7 @@ static RpcSsnData* RpcSsnDataNew(Packet* p)
     RpcSsnData* rsdata = &fd->session;
     rsdata->active = 1;
 
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
 
     DebugFormat(DEBUG_RPC, "STATEFUL: Created new session: " "%p\n", (void*) rsdata);
     return rsdata;
@@ -985,8 +985,7 @@ void RpcDecode::eval(Packet* p)
 
     if ( p->flow )
     {
-        RpcFlowData* fd = (RpcFlowData*)p->flow->get_application_data(
-            RpcFlowData::flow_id);
+        RpcFlowData* fd = (RpcFlowData*)p->flow->get_flow_data(RpcFlowData::flow_id);
 
         if ( fd )
             rsdata = &fd->session;
index 9a740ecbb6a30ab45bdd9f86bc25b0558a915def..d8e5abec6f8919ebe47ac5932d6b2c8cffb3e737 100644 (file)
@@ -74,16 +74,14 @@ static SIPData* SetNewSIPData(Packet* p, SIP_PROTO_CONF* config)
         MaxSessionsAlerted = 0;
     }
     SipFlowData* fd = new SipFlowData;
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     numSessions++;
     return &fd->session;
 }
 
 SIPData* get_sip_session_data(Flow* flow)
 {
-    SipFlowData* fd = (SipFlowData*)flow->get_application_data(
-        SipFlowData::flow_id);
-
+    SipFlowData* fd = (SipFlowData*)flow->get_flow_data(SipFlowData::flow_id);
     return fd ? &fd->session : NULL;
 }
 
index 47122c8fdb8d66a7650d45ff1866336fded90d7b..07022c9419dabd898ece79f02ac1ae47a0e406e3 100644 (file)
@@ -408,7 +408,7 @@ static int SIP_ignoreChannels(SIP_DialogData* dialog, Packet* p, SIP_PROTO_CONF*
             sfip_to_str(&mdataB->maddress), mdataB->mport);
 
         /* Call into Streams to mark data channel as something to ignore. */
-        FlowData* fd = stream.get_application_data_from_ip_port(
+        FlowData* fd = stream.get_flow_data(
             PktType::UDP, IpProtocol::UDP, &mdataA->maddress,mdataA->mport,
             &mdataB->maddress, mdataB->mport, 0, 0, p->pkth->address_space_id,
             SipFlowData::flow_id);
index 0d2ce75966e242d7349967bb04df6ae7079720e4..25cc4955469a8bb72e2043af60210d4301aa4fb4 100644 (file)
@@ -200,9 +200,7 @@ SmtpFlowData::~SmtpFlowData()
 unsigned SmtpFlowData::flow_id = 0;
 static SMTPData* get_session_data(Flow* flow)
 {
-    SmtpFlowData* fd = (SmtpFlowData*)flow->get_application_data(
-        SmtpFlowData::flow_id);
-
+    SmtpFlowData* fd = (SmtpFlowData*)flow->get_flow_data(SmtpFlowData::flow_id);
     return fd ? &fd->session : NULL;
 }
 
@@ -211,7 +209,7 @@ static SMTPData* SetNewSMTPData(SMTP_PROTO_CONF* config, Packet* p)
     SMTPData* smtp_ssn;
     SmtpFlowData* fd = new SmtpFlowData;
 
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     smtp_ssn = &fd->session;
 
     smtpstats.sessions++;
index 8d722e32eaf6496678a44000407d2c5c7a12e3f5..2a7988ff993d7c066ce82b6b3c295bbcc0e3f480 100644 (file)
@@ -64,15 +64,13 @@ unsigned SshFlowData::flow_id = 0;
 static SSHData* SetNewSSHData(Packet* p)
 {
     SshFlowData* fd = new SshFlowData;
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     return &fd->session;
 }
 
 static SSHData* get_session_data(Flow* flow)
 {
-    SshFlowData* fd = (SshFlowData*)flow->get_application_data(
-        SshFlowData::flow_id);
-
+    SshFlowData* fd = (SshFlowData*)flow->get_flow_data(SshFlowData::flow_id);
     return fd ? &fd->session : NULL;
 }
 
index 94993d3fdd2cbd969cc8ee02e8631a15467b4d82..d921c7ea69f785cba9203d02d9202a1aaf31286a 100644 (file)
@@ -85,15 +85,13 @@ const PegInfo ssl_peg_names[] =
 static SSLData* SetNewSSLData(Packet* p)
 {
     SslFlowData* fd = new SslFlowData;
-    p->flow->set_application_data(fd);
+    p->flow->set_flow_data(fd);
     return &fd->session;
 }
 
 SSLData* get_ssl_session_data(Flow* flow)
 {
-    SslFlowData* fd = (SslFlowData*)flow->get_application_data(
-        SslFlowData::flow_id);
-
+    SslFlowData* fd = (SslFlowData*)flow->get_flow_data(SslFlowData::flow_id);
     return fd ? &fd->session : NULL;
 }
 
index de1b41dfbb26b125aa88a3a337f3c48055a8290f..fe63d3a00bf78e62c82bcc686c0c7d37ed991cf2 100644 (file)
@@ -229,7 +229,8 @@ void StreamBase::eval(Packet* p)
     switch ( p->type() )
     {
     case PktType::IP:
-        if ( p->has_ip() )
+        if ( p->has_ip() and
+            ((p->ptrs.decode_flags & DECODE_FRAG) or !config->ip_frags_only) )
             flow_con->process_ip(p);
         break;
 
index d874347a43f75776470d7063dd7e63baeb65d331..8237ffaca1462493b1f932610e2921792ddc7e33 100644 (file)
@@ -42,16 +42,13 @@ static const Parameter name[] = \
     { "idle_timeout", Parameter::PT_INT, "1:", idle, \
       "maximum inactive time before retiring session tracker" }, \
  \
-    { "cleanup_pct", Parameter::PT_INT, "1:100", cleanup, \
-      "percent of cache to clean when max_sessions is reached" }, \
-\
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr } \
 }
 
 CACHE_PARAMS(ip_params,    "16384",  "30", "180", "5");
-CACHE_PARAMS(icmp_params,  "32768",  "30", "180", "5");
-CACHE_PARAMS(tcp_params,  "131072",  "30", "180", "5");
-CACHE_PARAMS(udp_params,   "65536",  "30", "180", "5");
+CACHE_PARAMS(icmp_params,  "65536",  "30", "180", "5");
+CACHE_PARAMS(tcp_params,  "262144",  "30", "180", "5");
+CACHE_PARAMS(udp_params,  "131072",  "30", "180", "5");
 CACHE_PARAMS(user_params,   "1024",  "30", "180", "5");
 CACHE_PARAMS(file_params,    "128",  "30", "180", "5");
 
@@ -61,6 +58,9 @@ CACHE_PARAMS(file_params,    "128",  "30", "180", "5");
 
 static const Parameter s_params[] =
 {
+    { "ip_frags_only", Parameter::PT_BOOL, nullptr, "false",
+      "don't process non-frag flows" },
+
     CACHE_TABLE("ip_cache",   "ip",   ip_params),
     CACHE_TABLE("icmp_cache", "icmp", icmp_params),
     CACHE_TABLE("tcp_cache",  "tcp",  tcp_params),
@@ -93,7 +93,12 @@ bool StreamModule::set(const char* fqn, Value& v, SnortConfig*)
 {
     FlowConfig* fc = nullptr;
 
-    if ( strstr(fqn, "ip_cache") )
+    if ( v.is("ip_frags_only") )
+    {
+        config.ip_frags_only = v.get_bool();
+        return true;
+    }
+    else if ( strstr(fqn, "ip_cache") )
         fc = &config.ip_cfg;
 
     else if ( strstr(fqn, "icmp_cache") )
@@ -123,9 +128,6 @@ bool StreamModule::set(const char* fqn, Value& v, SnortConfig*)
     else if ( v.is("idle_timeout") )
         fc->nominal_timeout = v.get_long();
 
-    else if ( v.is("cleanup_pct") )
-        fc->cleanup_pct = v.get_long();
-
     else
         return false;
 
index 30be7656a8f600a531992880ad8806145d5c93e2..ebfb9f0aef80ebdcd9cd9a2bdcc63c62434462da 100644 (file)
@@ -65,6 +65,7 @@ struct StreamModuleConfig
     FlowConfig udp_cfg;
     FlowConfig user_cfg;
     FlowConfig file_cfg;
+    bool ip_frags_only;
 };
 
 class StreamModule : public Module
index 2e5a8d42ac611f01f6e41db6e3df5cd67be51349..f397f022b4253ec1ce4bb68e2a049a5e076aadaa 100644 (file)
@@ -62,6 +62,7 @@ static void IcmpSessionCleanup(Flow* ssn)
 {
     if (ssn->ssn_state.session_flags & SSNFLAG_PRUNED)
         icmpStats.prunes++;
+
     else if (ssn->ssn_state.session_flags & SSNFLAG_TIMEDOUT)
         icmpStats.timeouts++;
 
index 34390a12b7db1f3552d5bf84b351980ee8ef9648..eb3607a6d8e0e8181776ca2167431998e8ab620d 100644 (file)
@@ -74,11 +74,7 @@ static void IpSessionCleanup(Flow* lws, FragTracker* tracker)
 
     if ( lws->ssn_state.session_flags & SSNFLAG_TIMEDOUT )
         ip_stats.timeouts++;
-    else if ( lws->ssn_state.session_flags & SSNFLAG_PRUNED )
-        ip_stats.prunes++;
 
-    if ( lws->ssn_state.session_flags & SSNFLAG_TIMEDOUT )
-        ip_stats.timeouts++;
     else if ( lws->ssn_state.session_flags & SSNFLAG_PRUNED )
         ip_stats.prunes++;
 
index 4428d90ceb0f3754bd6f799fb675420e30420271..84b4dd94add62bfef96a27a02b871fb597067762 100644 (file)
@@ -72,7 +72,8 @@ public:
     void SwapPacketHeaderFoo();
 
     virtual void update_perf_base_state(char) { }
-    virtual void clear_session(bool free_flow_data, bool flush_segments, bool restart, Packet* p = nullptr) = 0;
+    virtual void clear_session(
+        bool free_flow_data, bool flush_segments, bool restart, Packet* p = nullptr) = 0;
 
     // FIXIT-L these 2 function names convey no meaning afaict... figure out
     // why are they called and name appropriately...
@@ -94,8 +95,12 @@ public:
 
     virtual void flush() { }
 
-    virtual TcpStreamTracker::TcpState get_talker_state() { return TcpStreamTracker::TCP_MAX_STATES; }
-    virtual TcpStreamTracker::TcpState get_listener_state() { return TcpStreamTracker::TCP_MAX_STATES; }
+    virtual TcpStreamTracker::TcpState get_talker_state()
+    { return TcpStreamTracker::TCP_MAX_STATES; }
+
+    virtual TcpStreamTracker::TcpState get_listener_state()
+    { return TcpStreamTracker::TCP_MAX_STATES; }
+
     virtual void init_new_tcp_session(TcpSegmentDescriptor&);
     virtual void update_timestamp_tracking(TcpSegmentDescriptor&) { }
     virtual void update_session_on_syn_ack();
@@ -117,9 +122,7 @@ public:
     }
 
     void set_pkt_action_flag(uint32_t flag)
-    {
-        pkt_action_mask |= flag;
-    }
+    { pkt_action_mask |= flag; }
 
     virtual void update_paws_timestamps(TcpSegmentDescriptor&) { }
     virtual void check_for_repeated_syn(TcpSegmentDescriptor&) { }
index e735bfb436934ed5143e7f0588ba5e1106b368c5..a424760ca62892f740081e32e8ef75702758a57a 100644 (file)
@@ -31,7 +31,6 @@
 #include "main/snort_config.h"
 #include "main/snort_debug.h"
 #include "main/snort_debug.h"
-#include "utils/util.h"
 #include "flow/flow_control.h"
 #include "flow/flow_cache.h"
 #include "flow/ha.h"
@@ -52,6 +51,8 @@
 #include "protocols/vlan.h"
 #include "target_based/snort_protocols.h"
 #include "target_based/sftarget_hostentry.h"
+#include "utils/bitop.h"
+#include "utils/util.h"
 
 #ifdef UNIT_TEST
 #include "catch/catch.hpp"
@@ -86,7 +87,7 @@ void Stream::delete_session(const FlowKey* key)
 // key foo
 //-------------------------------------------------------------------------
 
-Flow* Stream::get_session_ptr_from_ip_port(
+Flow* Stream::get_session_ptr(
     PktType type, IpProtocol proto,
     const sfip_t* srcIP, uint16_t srcPort,
     const sfip_t* dstIP, uint16_t dstPort,
@@ -125,14 +126,14 @@ FlowKey* Stream::get_session_key(Packet* p)
 // app data foo
 //-------------------------------------------------------------------------
 
-FlowData* Stream::get_application_data_from_key(
+FlowData* Stream::get_flow_data(
     const FlowKey* key, unsigned flow_id)
 {
     Flow* flow = get_session(key);
-    return flow->get_application_data(flow_id);
+    return flow->get_flow_data(flow_id);
 }
 
-FlowData* Stream::get_application_data_from_ip_port(
+FlowData* Stream::get_flow_data(
     PktType type, IpProtocol proto,
     const sfip_t* srcIP, uint16_t srcPort,
     const sfip_t* dstIP, uint16_t dstPort,
@@ -141,7 +142,7 @@ FlowData* Stream::get_application_data_from_ip_port(
 {
     Flow* flow;
 
-    flow = get_session_ptr_from_ip_port(
+    flow = get_session_ptr(
         type, proto,
         srcIP, srcPort, dstIP, dstPort,
         vlan, mplsId, addressSpaceID);
@@ -149,7 +150,7 @@ FlowData* Stream::get_application_data_from_ip_port(
     if (!flow)
         return NULL;
 
-    return flow->get_application_data(flow_id);
+    return flow->get_flow_data(flow_id);
 }
 
 //-------------------------------------------------------------------------
@@ -313,16 +314,6 @@ void Stream::drop_session(const Packet* p)
 // misc support
 //-------------------------------------------------------------------------
 
-BitOp* Stream::get_flow_bitop(const Packet* p)
-{
-    Flow* flow = p->flow;
-
-    if (!flow)
-        return NULL;
-
-    return flow->bitop;
-}
-
 void Stream::init_active_response(const Packet* p, Flow* flow)
 {
     if ( !flow )
@@ -349,7 +340,7 @@ int Stream::set_application_protocol_id_expected(
         srcIP, srcPort, dstIP, dstPort, protocol, appId, fd);
 }
 
-void Stream::set_application_protocol_id_from_host_entry(
+void Stream::set_application_protocol_id(
     Flow* flow, const HostAttributeEntry* host_entry, int /*direction*/)
 {
     int16_t application_protocol;
@@ -411,7 +402,7 @@ int16_t Stream::get_application_protocol_id(Flow* flow)
     host_entry = SFAT_LookupHostEntryByIP(&flow->server_ip);
     if (host_entry)
     {
-        set_application_protocol_id_from_host_entry(flow, host_entry, FROM_SERVER);
+        set_application_protocol_id(flow, host_entry, FROM_SERVER);
 
         if (flow->ssn_state.application_protocol != 0)
         {
@@ -422,7 +413,7 @@ int16_t Stream::get_application_protocol_id(Flow* flow)
     host_entry = SFAT_LookupHostEntryByIP(&flow->client_ip);
     if (host_entry)
     {
-        set_application_protocol_id_from_host_entry(flow, host_entry, FROM_CLIENT);
+        set_application_protocol_id(flow, host_entry, FROM_CLIENT);
 
         if (flow->ssn_state.application_protocol != 0)
         {
@@ -560,7 +551,7 @@ static void active_response(Packet* p, Flow* lwssn)
     else
         lwssn->session_state |= STREAM_STATE_DROP_SERVER;
 
-    if ( (lwssn->response_count < max) && lwssn->get_expire(p) )
+    if ( (lwssn->response_count < max) && lwssn->expired(p) )
     {
         uint32_t delay = snort_conf->min_interval;
         EncodeFlags flags =
@@ -618,8 +609,11 @@ bool Stream::ignored_session(Flow* flow, Packet* p)
     return false;
 }
 
-static int StreamExpireSession(Flow* lwssn)
+static int StreamExpire(Packet* p, Flow* lwssn)
 {
+    if ( !lwssn->expired(p) )
+        return 0;
+
     if ( HighAvailabilityManager::in_standby(lwssn) )
         return 1;
 
@@ -629,17 +623,6 @@ static int StreamExpireSession(Flow* lwssn)
     return 1;
 }
 
-static int StreamExpire(Packet* p, Flow* lwssn)
-{
-    if ( lwssn->expired(p) )
-    {
-        /* Expiration time has passed. */
-        return StreamExpireSession(lwssn);
-    }
-
-    return 0;
-}
-
 bool Stream::expired_session(Flow* flow, Packet* p)
 {
     if ( (flow->session_state & STREAM_STATE_TIMEDOUT)
index cd4817cfa3c684518d7fcae3b72fca400202a9e5..de32ce04b669343dc22d969fa253eca0443ad524 100644 (file)
@@ -162,9 +162,6 @@ public:
         Flow*, Packet* p, uint32_t gid, uint32_t sid,
         uint32_t eventId, uint32_t eventSecond);
 
-    // Get pointer to Flowbits data
-    static BitOp* get_flow_bitop(const Packet*);
-
     // Get reassembly direction for given session
     static char get_reassembly_direction(Flow*);
 
@@ -202,13 +199,13 @@ public:
 
     // Get pointer to application data for a flow based on the lookup tuples for cases where
     // Snort does not have an active packet that is relevant.
-    static FlowData* get_application_data_from_ip_port(
+    static FlowData* get_flow_data(
         PktType type, IpProtocol proto,
         const sfip_t *a1, uint16_t p1, const sfip_t *a2, uint16_t p2,
         uint16_t vlanId, uint32_t mplsId, uint16_t addrSpaceId, unsigned flow_id);
 
     // Get pointer to application data for a flow using the FlowKey as the lookup criteria
-     static FlowData* get_application_data_from_key(const FlowKey*, unsigned flow_id);
+     static FlowData* get_flow_data(const FlowKey*, unsigned flow_id);
 
     // -- extra data methods
     uint32_t reg_xtra_data_cb(LogFunction);
@@ -221,7 +218,7 @@ public:
 
     // Get pointer to a session flow instance for a flow based on the lookup tuples for
     // cases where Snort does not have an active packet that is relevant.
-     static Flow* get_session_ptr_from_ip_port(
+     static Flow* get_session_ptr(
         PktType type, IpProtocol proto,
         const sfip_t *a1, uint16_t p1, const sfip_t *a2, uint16_t p2,
         uint16_t vlanId, uint32_t mplsId, uint16_t addrSpaceId);
@@ -237,7 +234,7 @@ public:
 
     void update_direction(Flow*, char dir, const sfip_t* ip, uint16_t port);
 
-    static void set_application_protocol_id_from_host_entry(
+    static void set_application_protocol_id(
         Flow*, const struct HostAttributeEntry*, int direction);
 
     static bool is_midstream(Flow* flow)
index b77d971fa6f488ba1a58e3da20018b4407558c11..a337efb753882d836ae52e0c32780c8ba42061c5 100644 (file)
@@ -160,14 +160,14 @@ void TcpSession::clear_session(bool free_flow_data, bool flush_segments, bool re
 {
     if ( client->reassembler )
     {
-        if( flush_segments )
+        if ( flush_segments )
             client->reassembler->flush_queued_segments(flow, true, p);
         client->reassembler->purge_segment_list();
     }
 
     if ( server->reassembler )
     {
-        if( flush_segments )
+        if ( flush_segments )
             server->reassembler->flush_queued_segments(flow, true, p);
         server->reassembler->purge_segment_list();
     }
@@ -179,14 +179,15 @@ void TcpSession::clear_session(bool free_flow_data, bool flush_segments, bool re
     else
         return;
 
-    if (flow->get_session_flags() & SSNFLAG_PRUNED)
+    if ( flow->get_session_flags() & SSNFLAG_PRUNED )
         tcpStats.prunes++;
-    else if (flow->get_session_flags() & SSNFLAG_TIMEDOUT)
+
+    else if ( flow->get_session_flags() & SSNFLAG_TIMEDOUT )
         tcpStats.timeouts++;
 
     update_perf_base_state(TcpStreamTracker::TCP_CLOSED);
 
-    if( restart )
+    if ( restart )
     {
         flow->restart(free_flow_data);
         paf_reset(&client->paf_state);
@@ -234,8 +235,9 @@ void TcpSession::update_perf_base_state(char newState)
             if ( ( session_flags & SSNFLAG_COUNTED_INITIALIZE )
                 && !( session_flags & SSNFLAG_COUNTED_CLOSING ) )
             {
-                assert(tcpStats.sessions_initializing);
-                tcpStats.sessions_initializing--;
+                //assert(tcpStats.sessions_initializing);
+                if ( tcpStats.sessions_initializing )  // FIXIT-L eliminate / fix underflow
+                    tcpStats.sessions_initializing--;
             }
         }
         break;
@@ -248,7 +250,7 @@ void TcpSession::update_perf_base_state(char newState)
 
             if ( session_flags & SSNFLAG_COUNTED_ESTABLISH )
             {
-                assert(tcpStats.sessions_established);
+                //assert(tcpStats.sessions_established);
                 tcpStats.sessions_established--;
 
                 if (perfmon_config  && (perfmon_config->perf_flags & PERF_FLOWIP))
@@ -257,8 +259,9 @@ void TcpSession::update_perf_base_state(char newState)
             }
             else if ( session_flags & SSNFLAG_COUNTED_INITIALIZE )
             {
-                assert(tcpStats.sessions_initializing);
-                tcpStats.sessions_initializing--;
+                //assert(tcpStats.sessions_initializing);
+                if ( tcpStats.sessions_initializing )  // FIXIT-L eliminate / fix underflow
+                    tcpStats.sessions_initializing--;
             }
         }
         break;
@@ -266,13 +269,14 @@ void TcpSession::update_perf_base_state(char newState)
     case TcpStreamTracker::TCP_CLOSED:
         if ( session_flags & SSNFLAG_COUNTED_CLOSING )
         {
-            assert(tcpStats.sessions_closing);
+            //assert(tcpStats.sessions_closing);
             tcpStats.sessions_closing--;
         }
         else if ( session_flags & SSNFLAG_COUNTED_ESTABLISH )
         {
-            assert(tcpStats.sessions_established);
-            tcpStats.sessions_established--;
+            //assert(tcpStats.sessions_established);
+            if ( tcpStats.sessions_established )  // FIXIT-L eliminate / fix underflow
+                tcpStats.sessions_established--;
 
             if ( perfmon_config && ( perfmon_config->perf_flags & PERF_FLOWIP ) )
                 perf_flow_ip->update_state(&flow->client_ip,
@@ -280,8 +284,9 @@ void TcpSession::update_perf_base_state(char newState)
         }
         else if ( session_flags & SSNFLAG_COUNTED_INITIALIZE )
         {
-            assert(tcpStats.sessions_initializing);
-            tcpStats.sessions_initializing--;
+            //assert(tcpStats.sessions_initializing);
+            if ( tcpStats.sessions_initializing )  // FIXIT-L eliminate / fix underflow
+                tcpStats.sessions_initializing--;
         }
         break;
 
@@ -649,7 +654,7 @@ void TcpSession::update_session_on_rst(TcpSegmentDescriptor& tsd, bool flush)
         flush_talker(tsd.get_pkt());
         set_splitter(true, nullptr);
         set_splitter(false, nullptr);
-        flow->free_application_data();
+        flow->free_flow_data();
     }
 
     talker->update_on_rst_sent( );
@@ -831,12 +836,17 @@ TcpStreamTracker::TcpState TcpSession::get_listener_state()
 void TcpSession::check_for_repeated_syn(TcpSegmentDescriptor& tsd)
 {
     uint32_t action = ACTION_NOTHING;
-    if (!SEQ_EQ(tsd.get_seg_seq(), talker->get_iss())
-        && listener->normalizer->packet_dropper(tsd, NORM_TCP_BLOCK))
+
+    if ( !SEQ_EQ(tsd.get_seg_seq(), talker->get_iss()) and
+        listener->normalizer->packet_dropper(tsd, NORM_TCP_BLOCK) )
+    {
         action = ACTION_BAD_PKT;
-    else if (talker->get_tcp_state() >= TcpStreamTracker::TCP_ESTABLISHED)
+    }
+    else if ( talker->get_tcp_state() >= TcpStreamTracker::TCP_ESTABLISHED and
+        talker->get_tcp_state() < TcpStreamTracker::TCP_CLOSED )
+    {
         action = listener->normalizer->handle_repeated_syn(tsd);
-
+    }
     if (action != ACTION_NOTHING)
     {
         /* got a bad SYN on the session, alert! */
index 708d67b138beef6787dad546a4f68988b458f20d..7e1c754123342a679cceb8c88681261320bec6b2 100644 (file)
@@ -145,8 +145,10 @@ bool TcpStateSynSent::rst_recv(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
     if ( trk.update_on_rst_recv(tsd) )
     {
         trk.session->update_session_on_rst(tsd, false);
-        trk.session->update_perf_base_state(TcpStreamTracker::TCP_CLOSING);
+        trk.set_tcp_state(TcpStreamTracker::TCP_CLOSED);
+        trk.session->update_perf_base_state(TcpStreamTracker::TCP_CLOSED);
         trk.session->set_pkt_action_flag(ACTION_RST);
+        tsd.get_pkt()->flow->session_state |= STREAM_STATE_CLOSED;
     }
     else
     {
index 87d6fd39623c4034c9f770eb6b7784a8da859c77..4e398405358bc8d2e3eb1583dc6dbe6fc70ab4a3 100644 (file)
@@ -61,6 +61,7 @@ static void UdpSessionCleanup(Flow* lwssn)
 {
     if (lwssn->ssn_state.session_flags & SSNFLAG_PRUNED)
         udpStats.prunes++;
+
     else if (lwssn->ssn_state.session_flags & SSNFLAG_TIMEDOUT)
         udpStats.timeouts++;
 
@@ -198,8 +199,7 @@ int UdpSession::process(Packet* p)
         UdpSessionCleanup(flow);
         flow->restart();
         flow->ssn_state.session_flags |= SSNFLAG_SEEN_SENDER;
-        udpStats.created++; // FIXIT-M is this correct? will mess with calc of current sessions
-        udpStats.timeouts++;
+        udpStats.created++;
         UdpHAManager::process_deletion(flow);
     }
 
index 53125263bbad831008cf4ca9e604e1e5c23daa1c..db5d05246f60821910aee76e686d555b601b0400 100644 (file)
@@ -59,8 +59,10 @@ private:
 // -----------------------------------------------------------------------------
 
 inline BitOp::BitOp(size_t len) :
-    bit_buf(new uint8_t[len]()), buf_size(len)
-{ }
+    buf_size(len ? (len + 7) >> 3 : 1)
+{
+    bit_buf = new uint8_t[len]();
+}
 
 inline BitOp::~BitOp()
 { delete[] bit_buf; }
@@ -68,7 +70,6 @@ inline BitOp::~BitOp()
 inline uint8_t BitOp::mask(size_t bit) const
 { return (uint8_t)(0x80 >> (bit & 7)); }
 
-// FIXIT-L ops that don't need to be inlined can probably be put into a .cc file
 // Reset the bit buffer so that it can be reused
 inline void BitOp::reset()
 { memset(bit_buf, 0, buf_size); }
index 63af4275cded5783c84b304f372a5b2b7fe11629..dd92281cdf9198dace2d5d40bd17c364abb249be 100644 (file)
@@ -12,7 +12,7 @@ static bool t_bitop_buffer_zero(BitOp& bitop)
 
 TEST_CASE( "bitop", "[bitop]" )
 {
-    BitOp bitop(3);
+    BitOp bitop(24);
 
     SECTION( "zero-initialized" )
     {