]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1189 in SNORT/snort3 from more_perf to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Tue, 17 Apr 2018 15:06:22 +0000 (11:06 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Tue, 17 Apr 2018 15:06:22 +0000 (11:06 -0400)
Squashed commit of the following:

commit ec308cd55b2e2e32ae4db3eb969b5fd38e7bb63f
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Mon Apr 16 16:49:26 2018 -0400

    stream_tcp: switch to splitter max

commit 783c405bb721e48352db0a9e00946722c037231a
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Sat Apr 14 07:46:20 2018 -0400

    spell check: fix memeory and indicies typos

commit 9aa84591ec853873196ca1bb5dc85fddd043081a
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Fri Apr 13 21:41:02 2018 -0400

    build: fix various warnings:

    file_decomp_pdf.cc: unreachable code return
    decompress/file_decomp_pdf.cc: implicit fallthrough
    stream.cc: warning: potential memory leaks
    memory_manager.cc: dangling references

commit f07b179baae636ec9be6307fe3bbb0295aeba387
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Thu Apr 12 09:27:50 2018 -0400

    stream: be selective about flow creation for scans

commit cdf528691f7aaeebb40a0b686ae46b7ff4651579
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Wed Apr 11 21:25:31 2018 -0400

    http_inspect: patch around regression failures until a permanent solution is implemented

commit 7f57541f3e4d1c1aaf44807c358b858f9ede043c
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Fri Apr 6 17:17:56 2018 -0400

    stream_tcp: tweak seglist cursor handling

commit 417992054439d839d3651fc5adf1b08d836cd1d4
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Wed Apr 11 07:41:35 2018 -0400

    port_scan: include open ports with alerts instead of separate

commit cf2e7d2ac36b3cf70ee8c7a55f932029755ddccb
Author: Russ Combs <rucombs@cisco.com>
Date:   Sat Mar 31 12:41:53 2018 -0400

    stream: remove usused ignore_any_rules from tcp and udp

commit f5843c4d2ad6a439003afde1830c41900bc492bf
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Thu Apr 5 17:00:27 2018 -0400

    stream: respect tcp require_3whs

commit c9bb1eb11d3060515bc26e8a393a1c963f47ae9c
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Thu Apr 5 11:44:15 2018 -0400

    stream: refactor flow control for new PktTypes

commit c9c5d239de87e9aa45925fde906d842f3ad2c33d
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Tue Apr 10 11:12:06 2018 -0400

    search_engine: revert default detect_raw_tcp to false

commit f0556f01cf98bfd8fef7494177ae6b33fde52b38
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Thu Apr 5 09:57:27 2018 -0400

    framework: remove bogus PktType for ARP and just use proto bits instead

commit f84ee2cb693c94e243180b2f3a715cc564d2d329
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Thu Apr 5 09:31:53 2018 -0400

    framework: align PktType and proto bits

commit f1f54c0fd3188460b1cb2e203cfb3c4789ed8e8a
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Mon Apr 2 06:14:05 2018 -0400

    memory: disable with -DNO_MEM_MGR

commit 6d070a4e8f17ae96f519cb833e356aaa7c3e6145
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Mon Apr 2 06:13:42 2018 -0400

    profile: disable with -DNO_PROFILER

commit a7ddf1395e9c9e69eb2b5d72077c40cb5e7aac19
Author: Russ Combs <rucombs@cisco.com>
Date:   Sat Mar 31 13:04:24 2018 -0400

    zhash: cleanup cruftiness

89 files changed:
extra/src/inspectors/data_log/data_log.cc
extra/src/inspectors/dpx/dpx.cc
extra/src/inspectors/reg_test/reg_test.cc
extra/src/ips_options/ips_pkt_num/ips_pkt_num.cc
src/codecs/ip/cd_tcp.cc
src/codecs/link/cd_arp.cc
src/decompress/file_decomp_pdf.cc
src/detection/detection_engine.cc
src/file_api/file_flows.cc
src/file_api/file_log.cc
src/flow/flow.cc
src/flow/flow.h
src/flow/flow_control.cc
src/flow/flow_control.h
src/flow/session.h
src/framework/codec.h
src/framework/decode_data.h
src/framework/inspector.cc
src/framework/inspector.h
src/hash/zhash.cc
src/hash/zhash.h
src/ips_options/ips_flowbits.cc
src/main/modules.cc
src/main/snort_config.h
src/managers/inspector_manager.cc
src/memory/memory_manager.cc
src/network_inspectors/appid/appid_inspector.cc
src/network_inspectors/appid/ips_appid_option.cc
src/network_inspectors/appid/thirdparty_appid_utils.cc
src/network_inspectors/arp_spoof/arp_spoof.cc
src/network_inspectors/binder/bind_module.cc
src/network_inspectors/binder/binder.cc
src/network_inspectors/normalize/normalize.cc
src/network_inspectors/packet_capture/packet_capture.cc
src/network_inspectors/perf_monitor/perf_module.h
src/network_inspectors/perf_monitor/perf_monitor.cc
src/network_inspectors/port_scan/port_scan.cc
src/network_inspectors/port_scan/ps_detect.cc
src/network_inspectors/port_scan/ps_detect.h
src/network_inspectors/reputation/reputation_inspect.cc
src/profiler/profiler_defs.h
src/protocols/packet.cc
src/protocols/packet.h
src/protocols/tcp.h
src/service_inspectors/back_orifice/back_orifice.cc
src/service_inspectors/dce_rpc/dce_http_proxy.cc
src/service_inspectors/dce_rpc/dce_http_server.cc
src/service_inspectors/dce_rpc/dce_smb.cc
src/service_inspectors/dce_rpc/dce_tcp.cc
src/service_inspectors/dce_rpc/dce_udp.cc
src/service_inspectors/dnp3/dnp3.cc
src/service_inspectors/dnp3/dnp3_reassembly.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/telnet.cc
src/service_inspectors/gtp/gtp_inspect.cc
src/service_inspectors/http2_inspect/http2_api.cc
src/service_inspectors/http_inspect/http_api.cc
src/service_inspectors/http_inspect/http_stream_splitter_reassemble.cc
src/service_inspectors/imap/imap.cc
src/service_inspectors/modbus/modbus.cc
src/service_inspectors/pop/pop.cc
src/service_inspectors/rpc_decode/rpc_decode.cc
src/service_inspectors/sip/sip.cc
src/service_inspectors/smtp/smtp.cc
src/service_inspectors/ssh/ssh.cc
src/service_inspectors/ssl/ssl_inspector.cc
src/service_inspectors/wizard/wizard.cc
src/stream/base/stream_base.cc
src/stream/base/stream_module.h
src/stream/file/stream_file.cc
src/stream/icmp/stream_icmp.cc
src/stream/ip/stream_ip.cc
src/stream/libtcp/tcp_segment_descriptor.cc
src/stream/tcp/stream_tcp.cc
src/stream/tcp/tcp_module.cc
src/stream/tcp/tcp_reassembler.cc
src/stream/tcp/tcp_reassembler.h
src/stream/tcp/tcp_session.cc
src/stream/tcp/tcp_stream_config.cc
src/stream/tcp/tcp_stream_config.h
src/stream/udp/stream_udp.cc
src/stream/udp/stream_udp.h
src/stream/udp/udp_module.cc
src/stream/user/stream_user.cc
tools/snort2lua/config_states/config_no_option.cc
tools/snort2lua/preprocessor_states/pps_stream5_tcp.cc
tools/snort2lua/preprocessor_states/pps_stream5_udp.cc

index 0d7a19cda6fdb2613009bc402e93a2e8e37a6ca4..ba6a2d0a96079c9c8e7d63c8e0747ac64c4078a7 100644 (file)
@@ -235,7 +235,7 @@ static const InspectApi dl_api
         mod_dtor
     },
     IT_PASSIVE,
-    (uint16_t)PktType::NONE,
+    PROTO_BIT__NONE,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index 028cc2fbd0fefd9a928db0f73ac0ae5a7c5fb048..c3a541b4b19675c9e8415c435205a0a99c1821b4 100644 (file)
@@ -180,7 +180,7 @@ static const InspectApi dpx_api
         mod_dtor
     },
     IT_NETWORK,
-    (uint16_t)PktType::UDP,
+    PROTO_BIT__UDP,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index 14a8d59b72b8e202579f51a18089896ee16b2439..226c1422a4673ab4d80f2edf1165720832b388de 100644 (file)
@@ -288,7 +288,7 @@ static const InspectApi rti_api
         mod_dtor
     },
     IT_PACKET,
-    (uint16_t)PktType::TCP | (uint16_t)PktType::UDP | (uint16_t)PktType::PDU,
+    PROTO_BIT__ANY_PDU,
     nullptr, // buffers
     s_name,  // service
     reg_test_init, // pinit
index 5c5b179d79e81c76598398ae24962808a42cdc5e..4f706ce20dc2eb20f3897eb04af66c323eb6f093 100644 (file)
@@ -76,7 +76,7 @@ bool PktNumOption::operator==(const IpsOption& ips) const
 
 IpsOption::EvalStatus PktNumOption::eval(Cursor&, Packet*)
 {
-    ProfileContext profile(pkt_num_perf_stats);
+    Profile profile(pkt_num_perf_stats);
 
     if ( config.eval(get_packet_number()) )
         return MATCH;
index be454f427148fa5ba9c1a8b367ac2e6248054982..36338402844a66d82025cb49d371a3ddea2b5a23 100644 (file)
@@ -130,7 +130,7 @@ private:
         const uint8_t* const end,
         const int expected_len);
 
-    void DecodeTCPOptions(const uint8_t*, uint32_t, CodecData&);
+    void DecodeTCPOptions(const uint8_t*, uint32_t, CodecData&, DecodeData&);
     void TCPMiscTests(const tcp::TCPHdr* const tcph,
         const DecodeData& snort,
         const CodecData& codec);
@@ -265,8 +265,10 @@ bool TcpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snort)
     uint16_t tcp_opt_len = (uint16_t)(tcph->hlen() - tcp::TCP_MIN_HEADER_LEN);
 
     if (tcp_opt_len > 0)
-        DecodeTCPOptions((const uint8_t*)(raw.data + tcp::TCP_MIN_HEADER_LEN), tcp_opt_len, codec);
-
+    {
+        const uint8_t* opts = (const uint8_t*)(raw.data + tcp::TCP_MIN_HEADER_LEN);
+        DecodeTCPOptions(opts, tcp_opt_len, codec, snort);
+    }
     int dsize = raw.len - tcph->hlen();
     if (dsize < 0)
         dsize = 0;
@@ -344,7 +346,8 @@ bool TcpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snort)
  *
  * Returns: void function
  */
-void TcpCodec::DecodeTCPOptions(const uint8_t* start, uint32_t o_len, CodecData& codec)
+void TcpCodec::DecodeTCPOptions(
+    const uint8_t* start, uint32_t o_len, CodecData& codec, DecodeData& snort)
 {
     const uint8_t* const end_ptr = start + o_len; /* points to byte after last option */
     const tcp::TcpOption* opt = reinterpret_cast<const tcp::TcpOption*>(start);
@@ -396,6 +399,7 @@ void TcpCodec::DecodeTCPOptions(const uint8_t* start, uint32_t o_len, CodecData&
                     /* LOG INVALID WINDOWSCALE alert */
                     codec_event(codec, DECODE_TCPOPT_WSCALE_INVALID);
                 }
+                snort.decode_flags |= DECODE_WSCALE;
             }
             break;
 
index 13587ba7f805afb5d4a79be40e05c9caf69bfa6f..60eb3d1b12c4e8bb1cbe8e6c355584be1841409f 100644 (file)
@@ -55,7 +55,6 @@ public:
 
     void get_protocol_ids(std::vector<ProtocolId>& v) override;
     bool decode(const RawData&, CodecData&, DecodeData&) override;
-    void format(bool reverse, uint8_t* raw_pkt, DecodeData& snort) override;
 };
 } // anonymous namespace
 
@@ -65,7 +64,7 @@ void ArpCodec::get_protocol_ids(std::vector<ProtocolId>& v)
     v.push_back(ProtocolId::ETHERTYPE_REVARP);
 }
 
-bool ArpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snort)
+bool ArpCodec::decode(const RawData& raw, CodecData& codec, DecodeData&)
 {
     if (raw.len < arp::ETHERARP_HDR_LEN)
     {
@@ -75,16 +74,10 @@ bool ArpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snort)
 
     codec.proto_bits |= PROTO_BIT__ARP;
     codec.lyr_len = arp::ETHERARP_HDR_LEN;
-    snort.set_pkt_type(PktType::ARP);
 
     return true;
 }
 
-void ArpCodec::format(bool /*reverse*/, uint8_t* /*raw_pkt*/, DecodeData& snort)
-{
-    snort.set_pkt_type(PktType::ARP);
-}
-
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
index 241d985ac1f58fd0f6878d35231ddfd09977210f..5ae26b1168de1fc2ba09ebb67353f24e9a389282 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "file_decomp_pdf.h"
 
+#include <cassert>
+
 #include "main/thread.h"
 #include "utils/util.h"
 
@@ -601,6 +603,7 @@ static inline fd_status_t Handle_State_IND_OBJ(fd_session_t* SessionPtr, uint8_t
             return( File_Decomp_Error );
         }
     }
+    // fallthrough
 
     case ( P_OBJ_EOL ):
     {
@@ -1134,7 +1137,8 @@ fd_status_t File_Decomp_PDF(fd_session_t* SessionPtr)
         } // switch()
     } // while()
 
-    return( File_Decomp_OK );
+    // can not reach this point
+    assert(false);
 }
 
 //--------------------------------------------------------------------------
index 275dde47c6e91ff4233b0c543765cc00fc70625e..0b4a6f1dc667b3f8e48c7bb889988d64f1c40940 100644 (file)
@@ -289,7 +289,8 @@ bool DetectionEngine::offload(Packet* p)
 {
     ContextSwitcher* sw = Snort::get_switcher();
 
-    if ( p->type() != PktType::PDU or (p->dsize < SnortConfig::get_conf()->offload_limit) or !sw->can_hold() )
+    if ( p->type() != PktType::PDU or (p->dsize < SnortConfig::get_conf()->offload_limit) or
+        !sw->can_hold() )
     {
         fp_local(p);
         return false;
index a4df7afa43d043474fe50b2063cf8c5b90558e7b..6f8a8ddc4c9a3891a99a9c7f0e9c45977f309999 100644 (file)
@@ -332,7 +332,7 @@ static const InspectApi file_inspect_api =
         mod_dtor
     },
     IT_PASSIVE,
-    (uint16_t)PktType::NONE,
+    PROTO_BIT__NONE,
     nullptr,
     "file",
     file_init,
index e65ed3568bd4f21b51100bb89fde7377b433ee37..d91e1daa46fd31f4bc793ee6874997ce84215aa5 100644 (file)
@@ -312,7 +312,7 @@ static const InspectApi fl_api
         mod_dtor
     },
     IT_PASSIVE,
-    (uint16_t)PktType::NONE,
+    PROTO_BIT__NONE,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index 9526a91e39fef82289e9fbf167b68bd9511d8f0c..dc241b002c7c7683e45ef78a771fdbd6782b42f0 100644 (file)
@@ -328,7 +328,7 @@ void Flow::set_direction(Packet* p)
     {
         if (ip_api->get_src()->fast_eq4(client_ip))
         {
-            if ( !(p->proto_bits & (PROTO_BIT__TCP | PROTO_BIT__UDP)) )
+            if ( p->type() != PktType::TCP and p->type() != PktType::UDP )
                 p->packet_flags |= PKT_FROM_CLIENT;
 
             else if (p->ptrs.sp == client_port)
@@ -339,7 +339,7 @@ void Flow::set_direction(Packet* p)
         }
         else if (ip_api->get_dst()->fast_eq4(client_ip))
         {
-            if ( !(p->proto_bits & (PROTO_BIT__TCP | PROTO_BIT__UDP)) )
+            if ( p->type() != PktType::TCP and p->type() != PktType::UDP )
                 p->packet_flags |= PKT_FROM_SERVER;
 
             else if (p->ptrs.dp == client_port)
@@ -353,7 +353,7 @@ void Flow::set_direction(Packet* p)
     {
         if (ip_api->get_src()->fast_eq6(client_ip))
         {
-            if ( !(p->proto_bits & (PROTO_BIT__TCP | PROTO_BIT__UDP)) )
+            if ( p->type() != PktType::TCP and p->type() != PktType::UDP )
                 p->packet_flags |= PKT_FROM_CLIENT;
 
             else if (p->ptrs.sp == client_port)
@@ -364,7 +364,7 @@ void Flow::set_direction(Packet* p)
         }
         else if (ip_api->get_dst()->fast_eq6(client_ip))
         {
-            if ( !(p->proto_bits & (PROTO_BIT__TCP | PROTO_BIT__UDP)) )
+            if ( p->type() != PktType::TCP and p->type() != PktType::UDP )
                 p->packet_flags |= PKT_FROM_SERVER;
 
             else if (p->ptrs.dp == client_port)
index 6370a13019e74ea10e6cd87066c352e9e31b6149..7da690ea4bf9c5bbf169908416852c89fe2626ea 100644 (file)
@@ -224,7 +224,7 @@ public:
     { return (ssn_state.session_flags & SSNFLAG_PROXIED) != 0; }
 
     bool is_stream()
-    { return (to_utype(pkt_type) & to_utype(PktType::STREAM)) != 0; }
+    { return pkt_type == PktType::TCP or pkt_type == PktType::PDU; }
 
     void block()
     { ssn_state.session_flags |= SSNFLAG_BLOCK; }
@@ -311,7 +311,7 @@ public:  // FIXIT-M privatize if possible
     BitOp* bitop;
     FlowHAState* ha_state;
 
-    uint8_t ip_proto; // FIXIT-M do we need both of these?
+    uint8_t ip_proto;
     PktType pkt_type; // ^^
 
     // these fields are always set; not zeroed
index 3ae234884d67b5e4a080534c2d427768d2085e32..ae3c2170e820af885636a3f1ed770fc62fc6be5d 100644 (file)
@@ -47,47 +47,18 @@ FlowControl::~FlowControl()
 {
     DetectionEngine de;
 
-    delete ip_cache;
-    delete icmp_cache;
-    delete tcp_cache;
-    delete udp_cache;
-    delete user_cache;
-    delete file_cache;
+    for ( int i = 0; i < to_utype(PktType::MAX); ++i )
+    {
+        delete proto[i].cache;
+        snort_free(proto[i].mem);
+    }
     delete exp_cache;
-
-    snort_free(ip_mem);
-    snort_free(icmp_mem);
-    snort_free(tcp_mem);
-    snort_free(udp_mem);
-    snort_free(user_mem);
-    snort_free(file_mem);
 }
 
 //-------------------------------------------------------------------------
 // count foo
 //-------------------------------------------------------------------------
 
-static THREAD_LOCAL PegCount ip_count = 0;
-static THREAD_LOCAL PegCount icmp_count = 0;
-static THREAD_LOCAL PegCount tcp_count = 0;
-static THREAD_LOCAL PegCount udp_count = 0;
-static THREAD_LOCAL PegCount user_count = 0;
-static THREAD_LOCAL PegCount file_count = 0;
-
-PegCount FlowControl::get_flows(PktType type)
-{
-    switch ( type )
-    {
-    case PktType::IP:   return ip_count;
-    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::FILE: return file_count;
-    default:            return 0;
-    }
-}
-
 PegCount FlowControl::get_total_prunes(PktType type) const
 {
     auto cache = get_cache(type);
@@ -102,69 +73,22 @@ PegCount FlowControl::get_prunes(PktType type, PruneReason reason) const
 
 void FlowControl::clear_counts()
 {
-    ip_count = icmp_count = 0;
-    tcp_count = udp_count = 0;
-    user_count = file_count = 0;
-
-    FlowCache* cache;
-
-    if ( (cache = get_cache(PktType::IP)) )
-        cache->reset_stats();
-
-    if ( (cache = get_cache(PktType::ICMP)) )
-        cache->reset_stats();
-
-    if ( (cache = get_cache(PktType::TCP)) )
-        cache->reset_stats();
-
-    if ( (cache = get_cache(PktType::UDP)) )
-        cache->reset_stats();
-
-    if ( (cache = get_cache(PktType::PDU)) )
-        cache->reset_stats();
+    for ( int i = 0; i < to_utype(PktType::MAX); ++i )
+    {
+        if ( proto[i].cache )
+            proto[i].cache->reset_stats();
 
-    if ( (cache = get_cache(PktType::FILE)) )
-        cache->reset_stats();
+        proto[i].num_flows = 0;
+    }
 }
 
 //-------------------------------------------------------------------------
 // cache foo
 //-------------------------------------------------------------------------
 
-inline FlowCache* FlowControl::get_cache (PktType type)
-{
-    switch ( type )
-    {
-    case PktType::IP:   return ip_cache;
-    case PktType::ICMP: return icmp_cache;
-    case PktType::TCP:  return tcp_cache;
-    case PktType::UDP:  return udp_cache;
-    case PktType::PDU:  return user_cache;
-    case PktType::FILE: return file_cache;
-    default:            return nullptr;
-    }
-}
-
-// FIXIT-L duplication of non-const method above
-inline const FlowCache* FlowControl::get_cache (PktType type) const
-{
-    switch ( type )
-    {
-    case PktType::IP:   return ip_cache;
-    case PktType::ICMP: return icmp_cache;
-    case PktType::TCP:  return tcp_cache;
-    case PktType::UDP:  return udp_cache;
-    case PktType::PDU:  return user_cache;
-    case PktType::FILE: return file_cache;
-    default:            return nullptr;
-    }
-}
-
 Flow* FlowControl::find_flow(const FlowKey* key)
 {
-    FlowCache* cache = get_cache(key->pkt_type);
-
-    if ( cache )
+    if ( auto cache = get_cache(key->pkt_type) )
         return cache->find(key);
 
     return nullptr;
@@ -172,12 +96,10 @@ Flow* FlowControl::find_flow(const FlowKey* key)
 
 Flow* FlowControl::new_flow(const FlowKey* key)
 {
-    FlowCache* cache = get_cache(key->pkt_type);
-
-    if ( !cache )
-        return nullptr;
+    if ( auto cache = get_cache(key->pkt_type) )
+        return cache->get(key);
 
-    return cache->get(key);
+    return nullptr;
 }
 
 // FIXIT-L cache* can be put in flow so that lookups by
@@ -189,25 +111,19 @@ void FlowControl::delete_flow(const FlowKey* key)
     if ( !cache )
         return;
 
-    Flow* flow = cache->find(key);
-
-    if ( flow )
+    if ( auto flow = cache->find(key) )
         cache->release(flow, PruneReason::HA);
 }
 
 void FlowControl::delete_flow(Flow* flow, PruneReason reason)
 {
-    FlowCache* cache = get_cache(flow->pkt_type);
-
-    if ( cache )
+    if ( auto cache = get_cache(flow->pkt_type) )
         cache->release(flow, reason);
 }
 
 void FlowControl::purge_flows (PktType type)
 {
-    FlowCache* cache = get_cache(type);
-
-    if ( cache )
+    if ( auto cache = get_cache(type) )
         cache->purge();
 }
 
@@ -394,13 +310,95 @@ static void init_roles(Packet* p, Flow* flow)
     default:
         break;
     }
+    if ( flow->ssn_state.direction == FROM_CLIENT )
+        p->packet_flags |= PKT_FROM_CLIENT;
+    else
+        p->packet_flags |= PKT_FROM_SERVER;
+}
+
+//-------------------------------------------------------------------------
+// proto
+//-------------------------------------------------------------------------
+
+void FlowControl::init_proto(
+    PktType type, const FlowConfig& fc, InspectSsnFunc get_ssn)
+{
+    if ( !fc.max_sessions || !get_ssn )
+        return;
+
+    auto& con = proto[to_utype(type)];
+
+    con.cache = new FlowCache(fc);
+    con.mem = (Flow*)snort_calloc(fc.max_sessions, sizeof(Flow));
+
+    for ( unsigned i = 0; i < fc.max_sessions; ++i )
+        con.cache->push(con.mem + i);
+
+    con.get_ssn = get_ssn;
+    types.push_back(type);
+}
+
+// FIXIT-P apply more filtering logic here, eg require_3whs
+// delegate to stream inspectors but that requires binding
+// can't use session because goal is to avoid instantiation
+static bool want_flow(PktType type, Packet* p)
+{
+    if ( type != PktType::TCP )
+        return true;
+
+    if ( p->ptrs.tcph->is_rst() )
+        // guessing direction based on ports is misleading
+        return false;
+
+    if ( !p->ptrs.tcph->is_syn_only() or SnortConfig::get_conf()->track_on_syn() or
+        (p->ptrs.decode_flags & DECODE_WSCALE) )
+        return true;
+
+    p->packet_flags |= PKT_FROM_CLIENT;
+    return false;
+}
+
+bool FlowControl::process(PktType type, Packet* p)
+{
+    auto& con = proto[to_utype(type)];
+
+    if ( !con.cache )
+        return false;
+
+    FlowKey key;
+    set_key(&key, p);
+    Flow* flow = con.cache->find(&key);
+
+    if ( !flow )
+    {
+        if ( !want_flow(type, p) )
+            return true;
+
+        flow = con.cache->get(&key);
+
+        if ( !flow )
+            return true;
+    }
+    if ( !flow->session )
+    {
+        flow->init(type);
+        flow->session = con.get_ssn(flow);
+    }
+
+    con.num_flows += process(flow, p);
+
+    // FIXIT-M refactor to unlink_uni immediately after session
+    // is processed by inspector manager (all flows)
+    if ( flow->next && is_bidirectional(flow) )
+        con.cache->unlink_uni(flow);
+
+    return true;
 }
 
 unsigned FlowControl::process(Flow* flow, Packet* p)
 {
     unsigned news = 0;
 
-    assert ( flow );
     flow->previous_ssn_state = flow->ssn_state;
 
     p->flow = flow;
@@ -408,6 +406,7 @@ unsigned FlowControl::process(Flow* flow, Packet* p)
 
     last_pkt_type = p->type();
     preemptive_cleanup();
+
     flow->set_direction(p);
     flow->session->precheck(p);
 
@@ -433,8 +432,6 @@ unsigned FlowControl::process(Flow* flow, Packet* p)
         ++news;
     }
 
-    flow->set_direction(p);
-
     // This requires the packet direction to be set
     if ( p->proto_bits & PROTO_BIT__MPLS )
         flow->set_mpls_layer_per_dir(p);
@@ -485,272 +482,6 @@ unsigned FlowControl::process(Flow* flow, Packet* p)
     return news;
 }
 
-//-------------------------------------------------------------------------
-// ip
-//-------------------------------------------------------------------------
-
-void FlowControl::init_ip(
-    const FlowConfig& fc, InspectSsnFunc get_ssn)
-{
-    if ( !fc.max_sessions || !get_ssn )
-        return;
-
-    ip_cache = new FlowCache(fc);
-    ip_mem = (Flow*)snort_calloc(fc.max_sessions, sizeof(Flow));
-
-    for ( unsigned i = 0; i < fc.max_sessions; ++i )
-        ip_cache->push(ip_mem + i);
-
-    get_ip = get_ssn;
-    types.push_back(PktType::IP);
-}
-
-void FlowControl::process_ip(Packet* p)
-{
-    if ( !ip_cache )
-        return;
-
-    FlowKey key;
-    set_key(&key, p);
-    Flow* flow = ip_cache->get(&key);
-
-    if ( !flow )
-        return;
-
-    if ( !flow->session )
-    {
-        flow->init(PktType::IP);
-        flow->session = get_ip(flow);
-    }
-
-    ip_count += process(flow, p);
-
-    if ( flow->next && is_bidirectional(flow) )
-        ip_cache->unlink_uni(flow);
-}
-
-//-------------------------------------------------------------------------
-// icmp
-//-------------------------------------------------------------------------
-
-void FlowControl::init_icmp(
-    const FlowConfig& fc, InspectSsnFunc get_ssn)
-{
-    if ( !fc.max_sessions || !get_ssn )
-        return;
-
-    icmp_cache = new FlowCache(fc);
-    icmp_mem = (Flow*)snort_calloc(fc.max_sessions, sizeof(Flow));
-
-    for ( unsigned i = 0; i < fc.max_sessions; ++i )
-        icmp_cache->push(icmp_mem + i);
-
-    get_icmp = get_ssn;
-    types.push_back(PktType::ICMP);
-}
-
-void FlowControl::process_icmp(Packet* p)
-{
-    if ( !icmp_cache )
-    {
-        process_ip(p);
-        return;
-    }
-
-    FlowKey key;
-    set_key(&key, p);
-    Flow* flow = icmp_cache->get(&key);
-
-    if ( !flow )
-        return;
-
-    if ( !flow->session )
-    {
-        flow->init(PktType::ICMP);
-        flow->session = get_icmp(flow);
-    }
-
-    icmp_count += process(flow, p);
-
-    if ( flow->next && is_bidirectional(flow) )
-        icmp_cache->unlink_uni(flow);
-}
-
-//-------------------------------------------------------------------------
-// tcp
-//-------------------------------------------------------------------------
-
-void FlowControl::init_tcp(
-    const FlowConfig& fc, InspectSsnFunc get_ssn)
-{
-    if ( !fc.max_sessions || !get_ssn )
-        return;
-
-    tcp_cache = new FlowCache(fc);
-    tcp_mem = (Flow*)snort_calloc(fc.max_sessions, sizeof(Flow));
-
-    for ( unsigned i = 0; i < fc.max_sessions; ++i )
-        tcp_cache->push(tcp_mem + i);
-
-    get_tcp = get_ssn;
-    types.push_back(PktType::TCP);
-}
-
-void FlowControl::process_tcp(Packet* p)
-{
-    if ( !tcp_cache )
-        return;
-
-    FlowKey key;
-    set_key(&key, p);
-    Flow* flow = tcp_cache->get(&key);
-
-    if ( !flow )
-        return;
-
-    if ( !flow->session )
-    {
-        flow->init(PktType::TCP);
-        flow->session = get_tcp(flow);
-    }
-
-    tcp_count += process(flow, p);
-
-    // FIXIT-M refactor to unlink_uni immediately after session
-    // is processed by inspector manager (all flows)
-    if ( flow->next && is_bidirectional(flow) )
-        tcp_cache->unlink_uni(flow);
-}
-
-//-------------------------------------------------------------------------
-// udp
-//-------------------------------------------------------------------------
-
-void FlowControl::init_udp(
-    const FlowConfig& fc, InspectSsnFunc get_ssn)
-{
-    if ( !fc.max_sessions || !get_ssn )
-        return;
-
-    udp_cache = new FlowCache(fc);
-    udp_mem = (Flow*)snort_calloc(fc.max_sessions, sizeof(Flow));
-
-    for ( unsigned i = 0; i < fc.max_sessions; ++i )
-        udp_cache->push(udp_mem + i);
-
-    get_udp = get_ssn;
-    types.push_back(PktType::UDP);
-}
-
-void FlowControl::process_udp(Packet* p)
-{
-    if ( !udp_cache )
-        return;
-
-    FlowKey key;
-    set_key(&key, p);
-    Flow* flow = udp_cache->get(&key);
-
-    if ( !flow )
-        return;
-
-    if ( !flow->session )
-    {
-        flow->init(PktType::UDP);
-        flow->session = get_udp(flow);
-    }
-
-    udp_count += process(flow, p);
-
-    if ( flow->next && is_bidirectional(flow) )
-        udp_cache->unlink_uni(flow);
-}
-
-//-------------------------------------------------------------------------
-// user
-//-------------------------------------------------------------------------
-
-void FlowControl::init_user(
-    const FlowConfig& fc, InspectSsnFunc get_ssn)
-{
-    if ( !fc.max_sessions || !get_ssn )
-        return;
-
-    user_cache = new FlowCache(fc);
-    user_mem = (Flow*)snort_calloc(fc.max_sessions, sizeof(Flow));
-
-    for ( unsigned i = 0; i < fc.max_sessions; ++i )
-        user_cache->push(user_mem + i);
-
-    get_user = get_ssn;
-    types.push_back(PktType::PDU);
-}
-
-void FlowControl::process_user(Packet* p)
-{
-    if ( !user_cache )
-        return;
-
-    FlowKey key;
-    set_key(&key, p);
-    Flow* flow = user_cache->get(&key);
-
-    if ( !flow )
-        return;
-
-    if ( !flow->session )
-    {
-        flow->init(PktType::PDU);
-        flow->session = get_user(flow);
-    }
-
-    user_count += process(flow, p);
-
-    if ( flow->next && is_bidirectional(flow) )
-        user_cache->unlink_uni(flow);
-}
-
-//-------------------------------------------------------------------------
-// file
-//-------------------------------------------------------------------------
-
-void FlowControl::init_file(
-    const FlowConfig& fc, InspectSsnFunc get_ssn)
-{
-    if ( !fc.max_sessions || !get_ssn )
-        return;
-
-    file_cache = new FlowCache(fc);
-    file_mem = (Flow*)snort_calloc(fc.max_sessions, sizeof(Flow));
-
-    for ( unsigned i = 0; i < fc.max_sessions; ++i )
-        file_cache->push(file_mem + i);
-
-    get_file = get_ssn;
-    types.push_back(PktType::FILE);
-}
-
-void FlowControl::process_file(Packet* p)
-{
-    if ( !file_cache )
-        return;
-
-    FlowKey key;
-    set_key(&key, p);
-    Flow* flow = file_cache->get(&key);
-
-    if ( !flow )
-        return;
-
-    if ( !flow->session )
-    {
-        flow->init(PktType::FILE);
-        flow->session = get_file(flow);
-    }
-
-    file_count += process(flow, p);
-}
-
 //-------------------------------------------------------------------------
 // expected
 //-------------------------------------------------------------------------
index 3966c4ff220e0859c5cdc77ae5dc44444d02936d..e9a03d4ef58b5d6c33d6b7ad4d9e06ea0bd46959 100644 (file)
@@ -52,22 +52,12 @@ public:
     ~FlowControl();
 
 public:
-    void process_ip(snort::Packet*);
-    void process_icmp(snort::Packet*);
-    void process_tcp(snort::Packet*);
-    void process_udp(snort::Packet*);
-    void process_user(snort::Packet*);
-    void process_file(snort::Packet*);
+    bool process(PktType, snort::Packet*);
 
     snort::Flow* find_flow(const snort::FlowKey*);
     snort::Flow* new_flow(const snort::FlowKey*);
 
-    void init_ip(const FlowConfig&, snort::InspectSsnFunc);
-    void init_icmp(const FlowConfig&, snort::InspectSsnFunc);
-    void init_tcp(const FlowConfig&, snort::InspectSsnFunc);
-    void init_udp(const FlowConfig&, snort::InspectSsnFunc);
-    void init_user(const FlowConfig&, snort::InspectSsnFunc);
-    void init_file(const FlowConfig&, snort::InspectSsnFunc);
+    void init_proto(PktType, const FlowConfig&, snort::InspectSsnFunc);
     void init_exp(uint32_t max);
 
     void delete_flow(const snort::FlowKey*);
@@ -92,15 +82,20 @@ public:
         const snort::SfIp *dstIP, uint16_t dstPort,
         SnortProtocolId snort_protocol_id, snort::FlowData*);
 
-    PegCount get_flows(PktType);
+    PegCount get_flows(PktType pt)
+    { return proto[to_utype(pt)].num_flows; }
+
     PegCount get_total_prunes(PktType) const;
     PegCount get_prunes(PktType, PruneReason) const;
 
     void clear_counts();
 
 private:
-    FlowCache* get_cache(PktType);
-    const FlowCache* get_cache(PktType) const;
+    FlowCache* get_cache(PktType pt)
+    { return proto[to_utype(pt)].cache; }
+
+    const FlowCache* get_cache(PktType pt) const
+    { return proto[to_utype(pt)].cache; }
 
     void set_key(snort::FlowKey*, snort::Packet*);
 
@@ -108,27 +103,13 @@ private:
     void preemptive_cleanup();
 
 private:
-    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
-    snort::Flow* ip_mem = nullptr;
-    snort::Flow* icmp_mem = nullptr;
-    snort::Flow* tcp_mem = nullptr;
-    snort::Flow* udp_mem = nullptr;
-    snort::Flow* user_mem = nullptr;
-    snort::Flow* file_mem = nullptr;
-
-    snort::InspectSsnFunc get_ip = nullptr;
-    snort::InspectSsnFunc get_icmp = nullptr;
-    snort::InspectSsnFunc get_tcp = nullptr;
-    snort::InspectSsnFunc get_udp = nullptr;
-    snort::InspectSsnFunc get_user = nullptr;
-    snort::InspectSsnFunc get_file = nullptr;
+    struct
+    {
+        FlowCache* cache = nullptr;
+        snort::Flow* mem = nullptr;
+        snort::InspectSsnFunc get_ssn = nullptr;
+        PegCount num_flows = 0;
+    } proto[to_utype(PktType::MAX)];
 
     class ExpectCache* exp_cache = nullptr;
     PktType last_pkt_type = PktType::NONE;
index 5e905ebbbfe6ae1163dc916cb08f4a609bdda521..22b95cf4269aba05f61ec777f0cab0820a3a347b 100644 (file)
@@ -23,6 +23,7 @@
 // Session is an abstract base class for the various protocol subclasses.
 // the subclasses do the actual work of tracking, reassembly, etc.
 
+#include <cassert>
 #include "stream/stream.h"
 
 namespace snort
@@ -59,7 +60,7 @@ public:
     virtual void flush_talker(snort::Packet*, bool /*final_flush */ = false) { }
     virtual void flush_listener(snort::Packet*, bool /*final_flush */ = false) { }
 
-    virtual void set_splitter(bool /*c2s*/, snort::StreamSplitter*) { }
+    virtual void set_splitter(bool /*c2s*/, snort::StreamSplitter*) { assert(false); }
     virtual snort::StreamSplitter* get_splitter(bool /*c2s*/) { return nullptr; }
 
     virtual void set_extra_data(snort::Packet*, uint32_t /*flag*/) { }
index 7434e760e0784b2c1ee0a88ec21a0fc523c8fdc8..4a89ace1f8114ce3f05bb435dc2e81ab77eb752e 100644 (file)
@@ -126,7 +126,7 @@ struct CodecData
     /* Reset before each decode of packet begins */
 
     /*  Codec specific fields.  These fields are only relevant to codecs. */
-    uint16_t proto_bits;    /* protocols contained within this packet
+    uint32_t proto_bits;    /* protocols contained within this packet
                                  -- will be propogated to Snort++ Packet struct*/
     uint16_t codec_flags;   /* flags used while decoding */
     uint8_t ip_layer_cnt;
index 0b1da80cfd4ef620ee659f0ef9f5c02889b02afa..2b7208257e47d60d291471ce28a623213a45755c 100644 (file)
@@ -44,21 +44,41 @@ struct ICMPHdr;
 /* NOTE: if A protocol is added, update DecodeFlags! */
 enum class PktType : std::uint8_t
 {
-    NONE=     0x00,
-    IP =      0x01,
-    TCP =     0x02,
-    UDP =     0x04,
-    ICMP =    0x08,
-    ARP =     0x10,
-    PDU  =    0x20,
-    FILE =    0x40,
-    STREAM =  0x22,
-    ANY_IP =  0x0F,
-    ANY_SSN = 0x6F,
-    ANY =     0x7F,
-//  FREE =    0x80,
+    NONE, IP, TCP, UDP, ICMP, PDU, FILE, MAX
 };
 
+// the first several of these bits must map to PktType
+// eg PROTO_BIT__IP == BIT(PktType::IP), etc.
+#define PROTO_BIT__NONE             0x00000
+#define PROTO_BIT__IP               0x00001
+#define PROTO_BIT__TCP              0x00002
+#define PROTO_BIT__UDP              0x00004
+#define PROTO_BIT__ICMP             0x00008
+#define PROTO_BIT__PDU              0x00010
+#define PROTO_BIT__FILE             0x00020
+#define PROTO_BIT__ARP              0x00040
+#define PROTO_BIT__TEREDO           0x00080
+#define PROTO_BIT__GTP              0x00100
+#define PROTO_BIT__MPLS             0x00200
+#define PROTO_BIT__VLAN             0x00400
+#define PROTO_BIT__ETH              0x00800
+#define PROTO_BIT__TCP_EMBED_ICMP   0x01000
+#define PROTO_BIT__UDP_EMBED_ICMP   0x02000
+#define PROTO_BIT__ICMP_EMBED_ICMP  0x04000
+#define PROTO_BIT__ICMP_EMBED_OTHER 0x08000
+#define PROTO_BIT__IP6_EXT          0x10000
+#define PROTO_BIT__OTHER            0x20000
+#define PROTO_BIT__ALL              0x3FFFF
+
+#define PROTO_BIT__ICMP_EMBED \
+    (PROTO_BIT__TCP_EMBED_ICMP | PROTO_BIT__UDP_EMBED_ICMP | \
+    PROTO_BIT__ICMP_EMBED_ICMP | PROTO_BIT__ICMP_EMBED_OTHER)
+
+#define PROTO_BIT__ANY_IP   (PROTO_BIT__IP | PROTO_BIT__TCP | PROTO_BIT__UDP | PROTO_BIT__ICMP)
+#define PROTO_BIT__ANY_PDU  (PROTO_BIT__TCP | PROTO_BIT__UDP | PROTO_BIT__PDU)
+#define PROTO_BIT__ANY_SSN  (PROTO_BIT__ANY_IP | PROTO_BIT__PDU | PROTO_BIT__FILE)
+#define PROTO_BIT__ANY_TYPE (PROTO_BIT__ANY_SSN | PROTO_BIT__ARP)
+
 enum DecodeFlags : std::uint16_t
 {
     DECODE_ERR_CKSUM_IP =   0x0001,  // error flags
@@ -79,32 +99,10 @@ enum DecodeFlags : std::uint16_t
     DECODE_C2S =            0x0100,  // user - client to server
     DECODE_SOF =            0x0200,  // user - start of flow
     DECODE_EOF =            0x0400,  // user - end of flow
-    DECODE_GTP =            0x0800,  // gtp encap
-};
+    DECODE_GTP =            0x0800,
 
-// FIXIT-L make this an enum!!
-#define PROTO_BIT__NONE     0x0000
-#define PROTO_BIT__IP       0x0001
-#define PROTO_BIT__ARP      0x0002
-#define PROTO_BIT__TCP      0x0004
-#define PROTO_BIT__UDP      0x0008
-#define PROTO_BIT__ICMP     0x0010
-#define PROTO_BIT__TEREDO   0x0020
-#define PROTO_BIT__GTP      0x0040
-#define PROTO_BIT__MPLS     0x0080
-#define PROTO_BIT__VLAN     0x0100
-#define PROTO_BIT__ETH      0x0200
-#define PROTO_BIT__TCP_EMBED_ICMP  0x0400
-#define PROTO_BIT__UDP_EMBED_ICMP  0x0800
-#define PROTO_BIT__ICMP_EMBED_ICMP 0x1000
-#define PROTO_BIT__ICMP_EMBED_OTHER 0x2000
-#define PROTO_BIT__ICMP_EMBED \
-    (PROTO_BIT__TCP_EMBED_ICMP | PROTO_BIT__UDP_EMBED_ICMP | \
-    PROTO_BIT__ICMP_EMBED_ICMP | PROTO_BIT__ICMP_EMBED_OTHER)
-#define PROTO_BIT__IP6_EXT  0x4000
-#define PROTO_BIT__FREE     0x0000 /* No proto bits free */
-#define PROTO_BIT__OTHER    0x8000  // FIXIT-L delete this after porting is still unused
-#define PROTO_BIT__ALL      0xffff
+    DECODE_WSCALE =         0x1000,
+};
 
 struct DecodeData
 {
index 68f704122012cc149976a1e9e18de6d8e8311348..5e5df13f88771fda05d254c96f869378a633caac 100644 (file)
@@ -101,7 +101,7 @@ StreamSplitter* Inspector::get_splitter(bool to_server)
 
 bool Inspector::likes(Packet* p)
 {
-    if ( !((uint16_t)p->type() & api->proto_bits) )
+    if ( !(BIT((uint16_t)p->type()) & api->proto_bits) )
         return false;
 
     if ( p->is_tcp() && api->type == IT_SERVICE )
index a18ad9898da9fa6f8fc6734e8cd813753a0eb42e..130577b5f213638556b992c78298d0b22b55fc94 100644 (file)
@@ -189,7 +189,7 @@ struct InspectApi
 {
     BaseApi base;
     InspectorType type;
-    uint16_t proto_bits;
+    uint32_t proto_bits;
 
     const char** buffers;  // null terminated list of exported buffers
     const char* service;   // nullptr when type != IT_SERVICE
index 00054dc4e0e6abccc66746e3d7b7d680511ea077..ecd77fe6d2145ade62278cf63fb7f7ac53bb16a6 100644 (file)
@@ -197,15 +197,14 @@ void ZHash::move_to_front(ZHashNode* node)
     }
 }
 
-ZHashNode* ZHash::find_node_row(const void* key, int* rindex)
+ZHashNode* ZHash::find_node_row(const void* key, int& row)
 {
     unsigned hashkey = hashfcn->hash_fcn(
         hashfcn, (const unsigned char*)key, keysize);
 
     // Modulus is slow; use a table size that is a power of 2.
     int index = hashkey & (nrows - 1);
-
-    *rindex = index;
+    row = index;
 
     for ( ZHashNode* node=table[index]; node; node=node->next )  // UNINITUSE
     {
@@ -313,8 +312,8 @@ void* ZHash::pop()
 
 void* ZHash::get(const void* key, bool *new_node)
 {
-    int index = 0;
-    ZHashNode* node = find_node_row(key, &index);
+    int row;
+    ZHashNode* node = find_node_row(key, row);
 
     if ( node )
         return node->data;
@@ -324,9 +323,9 @@ void* ZHash::get(const void* key, bool *new_node)
     if ( !node )
         return nullptr;
 
-    memcpy(node->key,key,keysize);
+    memcpy(node->key, key, keysize);
 
-    node->rindex = index;
+    node->rindex = row;
     link_node (node);
     glink_node(node);
 
@@ -340,8 +339,8 @@ void* ZHash::get(const void* key, bool *new_node)
 
 void* ZHash::find(const void* key)
 {
-    int rindex = 0;
-    ZHashNode* node = find_node_row(key, &rindex);
+    int row;
+    ZHashNode* node = find_node_row(key, row);
 
     if ( node )
         return node->data;
@@ -410,8 +409,8 @@ bool ZHash::remove()
 
 bool ZHash::remove(const void* key)
 {
-    int row = 0;
-    ZHashNode* node = find_node_row(key, &row);
+    int row;
+    ZHashNode* node = find_node_row(key, row);
     return remove(node);
 }
 
index 711f353cd35d623868fa83063ce5fec86e04e90f..a271a29e9f13fb5c19bcfe63208b0532ea72e096 100644 (file)
@@ -56,7 +56,7 @@ public:
 
 private:
     ZHashNode* get_free_node();
-    ZHashNode* find_node_row(const void*, int*);
+    ZHashNode* find_node_row(const void*, int&);
 
     void glink_node(ZHashNode*);
     void gunlink_node(ZHashNode*);
index 508b32c101497a7a4ea4348c93ddfdc9ad0d5226..21e40abed16c2904e47e6b54385b7d092dc5bd85 100644 (file)
@@ -405,10 +405,7 @@ static IpsOption::EvalStatus check_flowbits(
     BitOp* bitop = get_flow_bitop(p);
 
     if (!bitop)
-    {
-        assert(false);
         return IpsOption::NO_MATCH;
-    }
 
     switch (type)
     {
index 16da1cdc40402712b7d1c22dbb4252ed12378f40..b6c9a8af54d9112893dc88a191ede1ca6ce26440 100644 (file)
@@ -239,7 +239,7 @@ static const Parameter search_engine_params[] =
     { "max_queue_events", Parameter::PT_INT, "2:100", "5",  // upper bound is MAX_EVENT_MATCH
       "maximum number of matching fast pattern states to queue per packet" },
 
-    { "detect_raw_tcp", Parameter::PT_BOOL, nullptr, "true",
+    { "detect_raw_tcp", Parameter::PT_BOOL, nullptr, "false",
       "detect on TCP payload before reassembly" },
 
     { "search_method", Parameter::PT_DYNAMIC, (void*)&get_search_methods, "ac_bnfa",
index 5b904ed48bb70d4c1f94c4fa3e92ba89c917aa35..31c4f33aea4dfa2f8c55666122dc45d7a7bc2c57 100644 (file)
@@ -72,6 +72,7 @@ enum RunFlag
     RUN_FLAG__PIGLET              = 0x01000000,
 #endif
     RUN_FLAG__MEM_CHECK           = 0x02000000,
+    RUN_FLAG__TRACK_ON_SYN        = 0x04000000,
 };
 
 enum OutputFlag
@@ -650,6 +651,9 @@ public:
         return get_conf()->enable_packet_trace;
     }
 
+    bool track_on_syn() const
+    { return (run_flags & RUN_FLAG__TRACK_ON_SYN) != 0; }
+
     // Use this to access current thread's conf from other units
     static void set_conf(SnortConfig*);
 
index b0bfab1a7ac2b57890485342afcfce8f12d96f19..5c0e8773e11278187215a2e2aade9b931fbcd1ac 100644 (file)
@@ -573,7 +573,7 @@ InspectSsnFunc InspectorManager::get_session(uint16_t proto)
 {
     for ( auto* p : s_handlers )
     {
-        if ( p->api.type == IT_STREAM && p->api.proto_bits == proto && !p->init )
+        if ( p->api.type == IT_STREAM and p->api.proto_bits == proto and !p->init )
             return p->api.ssn;
     }
     return nullptr;
@@ -753,18 +753,18 @@ static void instantiate_binder(SnortConfig* sc, FrameworkPolicy* fp)
         const char* t = api.base.name;
         m->add(s, t);
 
-        tcp = tcp || (api.proto_bits & (unsigned)PktType::TCP);
-        udp = udp || (api.proto_bits & (unsigned)PktType::UDP);
-        pdu = pdu || (api.proto_bits & (unsigned)PktType::PDU);
+        tcp = tcp or (api.proto_bits & PROTO_BIT__TCP);
+        udp = udp or (api.proto_bits & PROTO_BIT__UDP);
+        pdu = pdu or (api.proto_bits & PROTO_BIT__PDU);
     }
     if ( tcp or pdu )
-        m->add((unsigned)PktType::TCP, wiz_id);
+        m->add(PROTO_BIT__TCP, wiz_id);
 
     if ( udp )
-        m->add((unsigned)PktType::UDP, wiz_id);
+        m->add(PROTO_BIT__UDP, wiz_id);
 
     if ( tcp or udp or pdu )
-        m->add((unsigned)PktType::PDU, wiz_id);
+        m->add(PROTO_BIT__PDU, wiz_id);
 
     const InspectApi* api = get_plugin(bind_id);
     InspectorManager::instantiate(api, m, sc);
@@ -902,7 +902,14 @@ static inline void execute(
         if ( !p->flow && (ppc.api.type == IT_SERVICE) )
             break;
 
-        if ( (unsigned)p->type() & ppc.api.proto_bits )
+        // FIXIT-L ideally we could eliminate PktType and just use
+        // proto_bits but things like teredo need to be fixed up.
+        if ( p->type() == PktType::NONE )
+        {
+            if ( p->proto_bits & ppc.api.proto_bits )
+                (*prep)->handler->eval(p);
+        }
+        else if ( BIT((unsigned)p->type()) & ppc.api.proto_bits )
             (*prep)->handler->eval(p);
     }
 }
index e7152ffd8f9ee3914ac591ccaf47bed8aeeb45e1..61193dad221e0542690deab27fc18638d0c1ad7d 100644 (file)
@@ -193,6 +193,7 @@ THREAD_LOCAL bool Interface<Allocator, Cap>::in_allocation_call = false;
 
 // these don't have to be visible to operate as replacements
 
+#ifndef NO_MEM_MGR
 void* operator new(size_t n)
 {
     auto p = memory::Interface<>::allocate(n);
@@ -232,6 +233,7 @@ SO_PUBLIC void operator delete(void* p, size_t) noexcept
 void operator delete[](void* p, size_t) noexcept;
 SO_PUBLIC void operator delete[](void* p, size_t) noexcept
 { ::operator delete[](p); }
+#endif
 
 // -----------------------------------------------------------------------------
 // unit tests
@@ -451,6 +453,8 @@ TEST_CASE( "memory manager interface", "[memory]" )
             CHECK( CapSpy::update_deallocations_arg == memory::Metadata::calculate_total_size(n) );
         }
     }
+    AllocatorSpy::pool = nullptr;
+    AllocatorSpy::deallocate_arg = nullptr;
 }
 
 #endif
index 7b18b96183295eef0254b6203b23bbdbbf57b971..f56832372cd07569255d6b2c5911b6136d754905 100644 (file)
@@ -255,7 +255,7 @@ const InspectApi appid_inspector_api =
         mod_dtor
     },
     IT_CONTROL,
-    (uint16_t)PktType::ANY_IP,
+    PROTO_BIT__ANY_IP,
     nullptr, // buffers
     nullptr, // service
     appid_inspector_pinit,
index 40a9659612e8b7d5e9c7861541b8e5dcdeefbf7c..dcf9d8b40ee45f3721b945b823a746523e023cae 100644 (file)
@@ -155,7 +155,9 @@ IpsOption::EvalStatus AppIdIpsOption::eval(Cursor&, Packet* p)
 {
     AppId app_ids[NUM_ID_TYPES];
 
-    assert(p->flow);
+    if ( !p->flow )
+        return NO_MATCH;
+
     Profile profile(appidRuleOptionPerfStats);
 
     if ( !opt_data.ids_mapped )
index add725b44abe11a9420a9aabffaf868bc5e2f2b4..0642f1752879c42d615efab24b727217fbda1d4f 100644 (file)
@@ -322,7 +322,7 @@ static void ProcessThirdPartyResults(AppIdSession& asd, int confidence,  AppId*
 
                 hsession->update_host((const uint8_t*)attribute_data->spdyRequestHost,
                     strlen(attribute_data->spdyRequestHost));
-                // FIXIT-M do we need to free this memeory and set to null
+                // FIXIT-M do we need to free this memory and set to null
                 // attribute_data->spdyRequestHost = nullptr;
                 hsession->set_field_offset(REQ_HOST_FID, attribute_data->spdyRequestHostOffset);
                 hsession->set_field_end_offset(REQ_HOST_FID,
@@ -341,7 +341,7 @@ static void ProcessThirdPartyResults(AppIdSession& asd, int confidence,  AppId*
 
                 hsession->update_uri((const uint8_t*)attribute_data->spdyRequestPath,
                     strlen(attribute_data->spdyRequestPath));
-                // FIXIT-M do we need to free this memeory and set to null
+                // FIXIT-M do we need to free this memory and set to null
                 //attribute_data->spdyRequestPath = nullptr;
                 hsession->set_field_offset(REQ_URI_FID, attribute_data->spdyRequestPathOffset);
                 hsession->set_field_end_offset(REQ_URI_FID, attribute_data->spdyRequestPathEndOffset);
@@ -363,7 +363,7 @@ static void ProcessThirdPartyResults(AppIdSession& asd, int confidence,  AppId*
                     attribute_data->httpRequestHostLen);
                 hsession->set_field_offset(REQ_HOST_FID, attribute_data->httpRequestHostOffset);
                 hsession->set_field_end_offset(REQ_HOST_FID, attribute_data->httpRequestHostEndOffset);
-                // FIXIT-M do we need to free this memeory and set to null
+                // FIXIT-M do we need to free this memory and set to null
                 //attribute_data->httpRequestHost = nullptr;
                 if (appidDebug->is_active())
                     LogMessage("AppIdDbg %s HTTP host (%u-%u) is %s\n",
index 23ae2d686cc9441d4c9c96f878d4e49e27dd66d9..2386964abba8e79e23ebd023cc011c30f05b8841 100644 (file)
@@ -142,7 +142,8 @@ void ArpSpoof::eval(Packet* p)
     Profile profile(arpPerfStats);
 
     // precondition - what we registered for
-    assert(p->type() == PktType::ARP);
+    assert(p->proto_bits & PROTO_BIT__ARP);
+
     const uint8_t* dst_mac_addr;
     const uint8_t* src_mac_addr;
 
@@ -269,7 +270,7 @@ static const InspectApi as_api =
         mod_dtor
     },
     IT_NETWORK,
-    (uint16_t)PktType::ARP,
+    PROTO_BIT__ARP,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index 4fe3495208252c5010449b50ccc0d1c63075237f..368a53edbc47d8db2655d22cde2fdb405d9981da 100644 (file)
@@ -208,12 +208,12 @@ bool BinderModule::set(const char* fqn, Value& v, SnortConfig*)
 
     else if ( v.is("proto") )
     {
-        const PktType mask[] =
+        const unsigned mask[] =
         {
-            PktType::ANY, PktType::IP, PktType::ICMP, PktType::TCP, PktType::UDP,
-            PktType::PDU, PktType::FILE
+            PROTO_BIT__ANY_TYPE, PROTO_BIT__IP, PROTO_BIT__ICMP,
+            PROTO_BIT__TCP, PROTO_BIT__UDP, PROTO_BIT__PDU, PROTO_BIT__FILE
         };
-        work->when.protos = (unsigned)mask[v.get_long()];
+        work->when.protos = mask[v.get_long()];
     }
     else if ( v.is("ports") )
     {
index 7afe29f8cf994280371a249a780f8d428c99ab15..e118a39f6af9144cfa45180c0a011475fe00bf17 100644 (file)
@@ -68,7 +68,7 @@ Binding::Binding()
     when.src_ports.set();
     when.dst_ports.set();
 
-    when.protos = (unsigned)PktType::ANY;
+    when.protos = PROTO_BIT__ANY_TYPE;
     when.vlans.set();
     when.ifaces.reset();
 
@@ -141,7 +141,7 @@ inline bool Binding::check_addr(const Flow* flow) const
 
 inline bool Binding::check_proto(const Flow* flow) const
 {
-    if ( when.protos & (unsigned)flow->pkt_type )
+    if ( when.protos & BIT((unsigned)flow->pkt_type) )
         return true;
 
     return false;
@@ -893,7 +893,7 @@ static const InspectApi bind_api =
         mod_dtor
     },
     IT_BINDER,
-    (uint16_t)PktType::ANY,
+    PROTO_BIT__ANY_TYPE,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index dc76b0e5ae91365eba22a87d326c6cefa9a57054..76cdf62fde3302d42f40525658b9d59aec628162 100644 (file)
@@ -293,7 +293,7 @@ static const InspectApi no_api =
         mod_dtor
     },
     IT_PACKET,
-    (uint16_t)PktType::ANY_IP,
+    PROTO_BIT__ANY_IP,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index 94b7ffb9772e1197121357e8e4175c4858607a5d..866f873a5e28745679c496c641e0460a3de313f6 100644 (file)
@@ -196,7 +196,7 @@ static const InspectApi pc_api =
         mod_dtor
     },
     IT_PROBE,
-    (uint16_t)PktType::ANY,
+    PROTO_BIT__ANY_TYPE,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index e849ff18d8beab202c02123b0b64ed55826a506c..7b134368c3d602bea20ced401ec9de0ba1082a6c 100644 (file)
@@ -58,7 +58,7 @@ enum class PerfOutput
 
 struct ModuleConfig
 {
-    // state optimized for run time using indicies
+    // state optimized for run time using indices
     // can't be determined until all modules have loaded (PerfMonitor::configure)
     snort::Module* ptr;
     IndexVec pegs;
index 3bbdc50252766ddbeb5a1fbd47de0f0050933053..212c65a5912fa5a599616cb52157aab19a578e3c 100644 (file)
@@ -381,7 +381,7 @@ static const InspectApi pm_api =
         mod_dtor
     },
     IT_PROBE,
-    (uint16_t)PktType::ANY,
+    PROTO_BIT__ANY_TYPE,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index 0ed7f93ecf770b1af95497515703af53d0375294..b3c56ddc6fef5e9786f79fcadcf66afc43b9294c 100644 (file)
@@ -82,10 +82,10 @@ static void make_open_port_info(Packet* p, PS_PROTO* proto)
     char a1[INET6_ADDRSTRLEN];
     ip1->ntop(a1, sizeof(a1));
 
-    buf.len = safe_snprintf((char*)buf.data, sizeof(buf.data),
+    buf.len += safe_snprintf((char*)buf.data+buf.len, sizeof(buf.data)-buf.len,
         "Scanned IP: %s\n"
         "Port Count: %d\n"
-        "Ports:",
+        "Open Ports:",
         a1,
         proto->open_ports_cnt);
 
@@ -97,6 +97,8 @@ static void make_open_port_info(Packet* p, PS_PROTO* proto)
     buf.len += safe_snprintf((char*)buf.data + buf.len, sizeof(buf.data) - buf.len, "\n");
 }
 
+#if 0
+// FIXIT-L add open port for port sweeps
 static void make_open_port_info(Packet* p, uint16_t port)
 {
     DataBuffer& buf = DetectionEngine::get_alt_buffer(p);
@@ -108,12 +110,17 @@ static void make_open_port_info(Packet* p, uint16_t port)
         "Open Port: %hu\n",
         p->ptrs.ip_api.get_src()->ntop(ip_str), port);
 }
+#endif
 
 static void PortscanAlertTcp(Packet* p, PS_PROTO* proto)
 {
     assert(proto);
-    bool portsweep = false;
 
+    if ( proto->open_ports_cnt and proto->alerts != PS_ALERT_PORTSWEEP and
+        proto->alerts != PS_ALERT_PORTSWEEP_FILTERED )
+    {
+        make_open_port_info(p, proto);
+    }
     switch (proto->alerts)
     {
     case PS_ALERT_ONE_TO_ONE:
@@ -126,7 +133,6 @@ static void PortscanAlertTcp(Packet* p, PS_PROTO* proto)
 
     case PS_ALERT_PORTSWEEP:
         DetectionEngine::queue_event(GID_PORT_SCAN, PSNG_TCP_PORTSWEEP);
-        portsweep = true;
         break;
 
     case PS_ALERT_DISTRIBUTED:
@@ -143,7 +149,6 @@ static void PortscanAlertTcp(Packet* p, PS_PROTO* proto)
 
     case PS_ALERT_PORTSWEEP_FILTERED:
         DetectionEngine::queue_event(GID_PORT_SCAN, PSNG_TCP_PORTSWEEP_FILTERED);
-        portsweep = true;
         break;
 
     case PS_ALERT_DISTRIBUTED_FILTERED:
@@ -153,13 +158,6 @@ static void PortscanAlertTcp(Packet* p, PS_PROTO* proto)
     default:
         return;
     }
-
-    //  Only log open ports for portsweeps after the alert has been generated.
-    if (proto->open_ports_cnt and !portsweep)
-    {
-        make_open_port_info(p, proto);
-        DetectionEngine::queue_event(GID_PORT_SCAN, PSNG_OPEN_PORT);
-    }
 }
 
 static void PortscanAlertUdp(Packet*, PS_PROTO* proto)
@@ -270,34 +268,25 @@ static void PortscanAlertIcmp(Packet*, PS_PROTO* proto)
 static void PortscanAlert(PS_PKT* ps_pkt, PS_PROTO* proto, int proto_type)
 {
     Packet* p = ps_pkt->pkt;
+    make_port_scan_info(p, proto);
 
-    if (proto->alerts == PS_ALERT_OPEN_PORT)
+    switch (proto_type)
     {
-        make_open_port_info(p, p->ptrs.sp);
-        DetectionEngine::queue_event(GID_PORT_SCAN, PSNG_OPEN_PORT);
-    }
-    else
-    {
-        make_port_scan_info(p, proto);
-
-        switch (proto_type)
-        {
-        case PS_PROTO_TCP:
-            PortscanAlertTcp(p, proto);
-            break;
+    case PS_PROTO_TCP:
+        PortscanAlertTcp(p, proto);
+        break;
 
-        case PS_PROTO_UDP:
-            PortscanAlertUdp(p, proto);
-            break;
+    case PS_PROTO_UDP:
+        PortscanAlertUdp(p, proto);
+        break;
 
-        case PS_PROTO_ICMP:
-            PortscanAlertIcmp(p, proto);
-            break;
+    case PS_PROTO_ICMP:
+        PortscanAlertIcmp(p, proto);
+        break;
 
-        case PS_PROTO_IP:
-            PortscanAlertIp(p, proto);
-            break;
-        }
+    case PS_PROTO_IP:
+        PortscanAlertIp(p, proto);
+        break;
     }
 }
 
@@ -504,7 +493,7 @@ static const InspectApi sp_api =
         mod_dtor
     },
     IT_PROBE,
-    (uint16_t)PktType::ANY_IP,
+    PROTO_BIT__ANY_IP,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index 0910a6e2a77dacadd99dd1d2c7f3c327c3c99d9f..dfb1a0d6a906ea2b0a74e90970d4a52c92eeba5c 100644 (file)
@@ -538,11 +538,6 @@ static int ps_update_open_ports(PS_PROTO* proto, unsigned short port)
     {
         proto->open_ports[iCtr] = port;
         proto->open_ports_cnt++;
-
-        if (proto->alerts == PS_ALERT_GENERATED)
-        {
-            proto->alerts = PS_ALERT_OPEN_PORT;
-        }
     }
 
     return 0;
@@ -649,22 +644,14 @@ void PortScan::ps_tracker_update_tcp(PS_PKT* ps_pkt, PS_TRACKER* scanner,
             !(p->packet_flags & PKT_STREAM_EST))
         {
             if (scanned)
-            {
                 ps_update_open_ports(&scanned->proto, p->ptrs.sp);
-            }
-
-            if (scanner)
-            {
-                if (scanner->proto.alerts == PS_ALERT_GENERATED)
-                    scanner->proto.alerts = PS_ALERT_OPEN_PORT;
-            }
         }
     }
     /*
     ** Stream didn't create a session on the SYN packet,
     ** so check specifically for SYN here.
     */
-    else if (p->ptrs.tcph && (p->ptrs.tcph->th_flags == TH_SYN))
+    else if ( p->ptrs.tcph and p->ptrs.tcph->is_syn_only() )
     {
         /* No session established, packet only has SYN.  SYN only
         ** packet always from client, so use dp.
@@ -686,7 +673,7 @@ void PortScan::ps_tracker_update_tcp(PS_PKT* ps_pkt, PS_TRACKER* scanner,
     ** so check specifically for SYN & ACK here.  Clear based
     ** on the 'completion' of three-way handshake.
     */
-    else if (p->ptrs.tcph && (p->ptrs.tcph->th_flags == (TH_SYN|TH_ACK)))
+    else if ( p->ptrs.tcph and p->ptrs.tcph->is_syn_ack() )
     {
         if (scanned)
         {
index 5eb5146555600a9bbc3c23ac35ee27903db1424a..e06ff785f13fa616dd6e9f363c518694366de4b1 100644 (file)
@@ -61,7 +61,6 @@ struct Packet;
 #define PS_ALERT_ONE_TO_ONE_DECOY_FILTERED 6
 #define PS_ALERT_DISTRIBUTED_FILTERED      7
 #define PS_ALERT_PORTSWEEP_FILTERED        8
-#define PS_ALERT_OPEN_PORT                 9
 
 #define PS_ALERT_GENERATED                 255
 
index ce8e75f44063e2eb37919a2209f6cc24181d517c..d6a5e508a86c214408388abe819ae39ecae6093d 100644 (file)
@@ -411,7 +411,7 @@ const InspectApi reputation_api =
         mod_dtor
     },
     IT_NETWORK,
-    (uint16_t)PktType::ANY_IP,
+    PROTO_BIT__ANY_IP,
     nullptr, // buffers
     nullptr, // service
     reputation_init, // pinit
index 629b74826ec610df320585810d79fefd49c771f3..d84db1742d3bd2875ef2add5b9396a7fed6a5477 100644 (file)
@@ -82,7 +82,7 @@ private:
     MemoryContext memory;
 };
 
-class SO_PUBLIC ProfileExclude
+class ProfileExclude
 {
 public:
     ProfileExclude(ProfileStats& stats) : ProfileExclude(stats.time, stats.memory) { }
@@ -95,6 +95,45 @@ private:
 
 using get_profile_stats_fn = ProfileStats* (*)(const char*);
 
+class NoMemContext
+{
+public:
+    NoMemContext(ProfileStats& stats) :
+        time(stats.time) { }
+
+private:
+    TimeContext time;
+};
+
+class NoMemExclude
+{
+public:
+    NoMemExclude(ProfileStats& stats) : NoMemExclude(stats.time, stats.memory) { }
+    NoMemExclude(TimeProfilerStats& time, MemoryTracker&) : time(time) { }
+
+private:
+    TimeExclude time;
+};
+
+class ProfileDisabled
+{
+public:
+    ProfileDisabled(ProfileStats&) { }
+    ProfileDisabled(TimeProfilerStats&, MemoryTracker&) { }
+};
+
+#ifdef NO_PROFILER
+using Profile = ProfileDisabled;
+using NoProfile = ProfileDisabled;
+#else
+#ifdef NO_MEM_MGR
+using Profile = NoMemContext;
+using NoProfile = NoMemExclude;
+#else
 using Profile = ProfileContext;
+using NoProfile = ProfileExclude;
+#endif
+#endif
+
 }
 #endif
index 6160c4b349609b4fca7ffd6bd521a2ad1334f6db..219abcbf05ee507a568fb27c490b5412fa6cbfd0 100644 (file)
@@ -150,9 +150,6 @@ const char* Packet::get_type() const
     case PktType::UDP:
         return "UDP";
 
-    case PktType::ARP:
-        return "ARP";
-
     case PktType::PDU:
     case PktType::FILE:
         if ( proto_bits & PROTO_BIT__TCP )
@@ -165,6 +162,9 @@ const char* Packet::get_type() const
         return "Error";
 
     case PktType::NONE:
+        if ( proto_bits & PROTO_BIT__ARP )
+            return "ARP";
+
         if ( num_layers > 0 )
             return PacketManager::get_proto_name(layers[num_layers-1].prot_id);
 
index 510dcd23553ae1dce3cbb0761f383235df5d3ddd..b57199195dc7cf0a7eac095ed266b73dd968af6f 100644 (file)
@@ -117,8 +117,8 @@ struct SO_PUBLIC Packet
 
     uint32_t packet_flags;      /* special flags for the packet */
     uint32_t xtradata_mask;
+    uint32_t proto_bits;        /* protocols contained within this packet */
 
-    uint16_t proto_bits;        /* protocols contained within this packet */
     uint16_t alt_dsize;         /* size for detection (iff PKT_DETECT_LIMIT) */
 
     uint8_t num_layers;         /* index into layers for next encap */
index 2813e1e607f3f6f1f649f0ab6d58172f673912d1..e46972643c4761b58f71307047d43546ca59212a 100644 (file)
@@ -121,7 +121,6 @@ struct TCPHdr
     inline bool is_syn() const
     { return (th_flags & TH_SYN); }
 
-    // FIXIT-L should other flags (e.g. RST, FIN) be included in check for syn only?
     inline bool is_syn_only() const
     { return (th_flags & (TH_SYN | TH_ACK)) == TH_SYN; }
 
index 41c965a0263d07d394db1993a6d6a853879e3e88..7bfbb83a83823e2a408883e1ade43aca8e3b42a4 100644 (file)
@@ -544,7 +544,7 @@ static const InspectApi bo_api =
         mod_dtor
     },
     IT_NETWORK,
-    (uint16_t)PktType::UDP,
+    PROTO_BIT__UDP,
     nullptr, // buffers
     nullptr, // service
     bo_init,
index c7a875c5fd8f32864360a80554253f605bf74419..ed7f299714ced44bd41a51202072c835ff20fb32 100644 (file)
@@ -117,7 +117,7 @@ const InspectApi dce_http_proxy_api =
         mod_proxy_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr,  // buffers
     "dce_http_proxy",
     nullptr, // pinit
index cc5565f178de87a1c025639c046dfa78dc2ff994..7377565d02e376996fa9b0753f801ac9468ea427 100644 (file)
@@ -113,7 +113,7 @@ const InspectApi dce_http_server_api =
         mod_server_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr,  // buffers
     "dce_http_server",
     nullptr, // pinit
index e7c861605bdf249d7c279adfe28ae6e2f459b22b..bd332c4c3dc115b54d786a639a7467a9146ea215 100644 (file)
@@ -458,7 +458,7 @@ const snort::InspectApi dce2_smb_api =
         mod_dtor
     },
     snort::IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr,  // buffers
     "netbios-ssn",
     dce2_smb_init,
index a3b3de17c472733aed34b5d28d43fa1222dd6ed4..bdf0302372915400f8dc0b3237cf744076749f84 100644 (file)
@@ -224,7 +224,7 @@ const InspectApi dce2_tcp_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr,  // buffers
     DCE_RPC_SERVICE_NAME,
     dce2_tcp_init,
index 805ccad887fd543e6b3f79d81b0bef012e779247..c1efa946ae2cf37209b2a3d41855392961668437 100644 (file)
@@ -215,7 +215,7 @@ const InspectApi dce2_udp_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::UDP,
+    PROTO_BIT__UDP,
     nullptr,  // buffers
     DCE_RPC_SERVICE_NAME,
     dce2_udp_init,
index e8f05ef0d7544ce39165f6460b2f6c3b638c6fbf..a3fb73d78b99a498571188008dc0bd9fdc9192ff 100644 (file)
@@ -318,7 +318,7 @@ const InspectApi dnp3_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU | (uint16_t)PktType::UDP,
+    PROTO_BIT__UDP | PROTO_BIT__PDU,
     nullptr,  // buffers
     "dnp3",
     dnp3_init,
index d62d68da1f5bd0c189abc93dacf65b392fdcce8c..160683dae6fb92ea2f3158068a4f3412af115656 100644 (file)
@@ -412,7 +412,7 @@ bool dnp3_full_reassembly(dnp3ProtoConf& config, dnp3_session_data_t* session, P
         if ((ret == true) && (packet->is_udp()))
         {
             {
-                ProfileExclude profile_exclude(dnp3_perf_stats);
+                NoProfile exclude(dnp3_perf_stats);
                 DetectionEngine::detect(packet);
             }
 
index 3603ee928f8b7fb8f9a43b7ab801f9a69b230926..138a4ce6a7bdb2f394ddbb0cd87385afb8605c05 100644 (file)
@@ -1040,7 +1040,7 @@ const InspectApi dns_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::TCP | (uint16_t)PktType::UDP | (uint16_t)PktType::PDU,
+    PROTO_BIT__ANY_PDU,
     nullptr, // buffers
     "dns",
     dns_init,
index 1ca6abeef01f820c2e5c640d0301fa785f883002..9a3b7c89e0925cdb222cfbbfff01c12a7d3b2bc2 100644 (file)
@@ -96,7 +96,7 @@ static int SnortFTP(
     ret = check_ftp(FTPsession, p, iInspectMode);
     if ( ret == FTPP_SUCCESS )
     {
-        ProfileExclude exclude(ftpPerfStats);
+        NoProfile exclude(ftpPerfStats);
 
         // FIXIT-L ideally do_detection will look at the cmd & param buffers
         // or the rsp & msg buffers.  We should call it from inside check_ftp
@@ -419,7 +419,7 @@ static const InspectApi fc_api =
         mod_dtor
     },
     IT_PASSIVE,
-    (uint16_t)PktType::NONE,
+    PROTO_BIT__NONE,
     nullptr, // buffers
     "ftp",
     nullptr, // init,
@@ -474,7 +474,7 @@ static const InspectApi fs_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr, // buffers
     "ftp",
     fs_init,
index 6480163dcf6b3652d9babfeeb85b6b6ac66ac510..1b38df0d7b1ee58218933695053271a2579a7e9b 100644 (file)
@@ -320,7 +320,7 @@ const InspectApi fd_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr, // buffers
     fd_svc_name,
     fd_init,
index 281b6d1915424743d81c3fd25c3499f5d4ffdd81..2a48a515de7fc3c0aa00b9b2b2a23e453bf9f070 100644 (file)
@@ -84,14 +84,14 @@ static int SnortTelnet(TELNET_PROTO_CONF* telnet_config, TELNET_SESSION* Telnets
 
         if ( ret == FTPP_SUCCESS || ret == FTPP_NORMALIZED )
         {
-            ProfileExclude exclude(telnetPerfStats);
+            NoProfile exclude(telnetPerfStats);
             do_detection(p);
         }
     }
 
     else
     {
-        ProfileExclude exclude(telnetPerfStats);
+        NoProfile exclude(telnetPerfStats);
         do_detection(p);
     }
 
@@ -315,7 +315,7 @@ const InspectApi tn_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr, // buffers
     "telnet",
     tn_init,
index d9f9a70272d95f9240c42873eebea6e4060ba37a..56c02e98e76f53e3e7fa0e67c72b0d1a7c5982fe 100644 (file)
@@ -241,7 +241,7 @@ static const InspectApi gtp_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::UDP,
+    PROTO_BIT__UDP,
     nullptr,
     "gtp",
     gtp_init,
index 72573f5aeafd12098f7ca68c1868591074d4340b..e53f77e405afcf99212a7bad8a1990580509cc16 100644 (file)
@@ -58,7 +58,7 @@ const InspectApi Http2Api::http2_api =
         Http2Api::http2_mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     classic_buffer_names,
     "http2",
     Http2Api::http2_init,
index 87ea17d61672b885400971fbfd7835336f01b812..6d924ae085effdb3a013d369155e19e7c51f39d1 100644 (file)
@@ -73,7 +73,7 @@ const InspectApi HttpApi::http_api =
         HttpApi::http_mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     classic_buffer_names,
     "http",
     HttpApi::http_init,
index 30480a349337a41ea5eb3d0f314dd0193d450d80..1ea14bdaf9bdcc5f1fc11c9b4a8ad098057a1489 100644 (file)
@@ -298,6 +298,10 @@ const snort::StreamBuffer HttpStreamSplitter::reassemble(snort::Flow* flow, unsi
         else
         {
 #ifdef REG_TEST
+           // FIXIT-M: known case: if session clears w/o a flush point,
+           // stream_tcp will flush to paf max which could be well below what
+           // has been scanned so far.  since no flush point was specified,
+           // NHI should just deal with what it gets.
             assert(false);
 #endif
             return http_buf;
index 482a218fe6494dff9ca28cbc55abf2822c027b02..4e625d99e716dcc27d0cdec441f851779844ecaf 100644 (file)
@@ -798,7 +798,7 @@ const InspectApi imap_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr, // buffers
     "imap",
     imap_init,
index faa97149d7d8f6f74de3e4133e40b151784a4b27..5efbf55c4a297c217ec884d932c493f77ccc4d7f 100644 (file)
@@ -160,7 +160,7 @@ static const InspectApi modbus_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr,
     "modbus",
     modbus_init,
index 861a821396f592c320ece4233727d2c87a5a12d9..e9b172530cadcd4958331ab9dc2934a43224bf35 100644 (file)
@@ -737,7 +737,7 @@ const InspectApi pop_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr, // buffers
     "pop3",
     pop_init,
index 1d52596cbd8c6390103b67127e56a14b0ac7477e..82605f038075fa9c51d5755ad5efa4d2f1fec7cd 100644 (file)
@@ -931,7 +931,7 @@ static const InspectApi rd_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr, // buffers
     "sunrpc",
     rd_init,
index 0a6c510d6940a3507324c736e48a7fa338ec56af..137428fa8fca4b647d04b68cef7e37dca8ad54d8 100644 (file)
@@ -368,7 +368,7 @@ const InspectApi sip_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU | (uint16_t)PktType::UDP,
+    PROTO_BIT__UDP | PROTO_BIT__PDU,
     nullptr, // buffers
     "sip",
     sip_init,
index 668c9edd8676d0a40f664687feb0a1ea395b1124..04075a0ef43a345000b0ec4b344b3585714f009e 100644 (file)
@@ -1555,7 +1555,7 @@ const InspectApi smtp_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr,                // buffers
     "smtp",
     smtp_init,
index 139170d775ea4cc352c2c360062507e9f967c0c2..7df875080d7fdc242978483974a4ef06eb20153d 100644 (file)
@@ -814,7 +814,7 @@ const InspectApi ssh_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr, // buffers
     "ssh",
     ssh_init,
index 0e0567a733f73db84857441c38d1865b023351b5..524d2ee6e4c17476f868d9d673127aaebc0633f7 100644 (file)
@@ -496,7 +496,7 @@ const InspectApi ssl_api =
         mod_dtor
     },
     IT_SERVICE,
-    (uint16_t)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr, // buffers
     "ssl",
     ssl_init,
index eff7e1dd4a93292215ddc64b4cb9ea2cbcd8f251..b918e084ace0994a4724be3ea16312b23eeb20d4 100644 (file)
@@ -356,7 +356,7 @@ static const InspectApi wiz_api =
         mod_dtor
     },
     IT_WIZARD,
-    (uint16_t)PktType::TCP | (uint16_t)PktType::UDP | (uint16_t)PktType::PDU,
+    PROTO_BIT__ANY_PDU,
     nullptr, // buffers
     nullptr, // service
     nullptr, // init
index 2eb5ff0f461387f7b204bcaa57e5a087ea4952e8..d4d182c1217c82665ff9a15d06dac1129804d11f 100644 (file)
 #include "config.h"
 #endif
 
+#include <functional>
+
 #include "flow/flow_control.h"
 #include "flow/prune_stats.h"
+#include "main/snort_config.h"
 #include "managers/inspector_manager.h"
 #include "profiler/profiler_defs.h"
 #include "protocols/packet.h"
+#include "protocols/tcp.h"
 #include "stream/flush_bucket.h"
 
 #include "stream_ha.h"
@@ -138,6 +142,7 @@ class StreamBase : public Inspector
 public:
     StreamBase(const StreamModuleConfig*);
 
+    bool configure(SnortConfig*) override;
     void show(SnortConfig*) override;
 
     void tinit() override;
@@ -162,33 +167,33 @@ void StreamBase::tinit()
 
     if ( config.ip_cfg.max_sessions )
     {
-        if ( (f = InspectorManager::get_session((uint16_t)PktType::IP)) )
-            flow_con->init_ip(config.ip_cfg, f);
+        if ( (f = InspectorManager::get_session(PROTO_BIT__IP)) )
+            flow_con->init_proto(PktType::IP, config.ip_cfg, f);
     }
     if ( config.icmp_cfg.max_sessions )
     {
-        if ( (f = InspectorManager::get_session((uint16_t)PktType::ICMP)) )
-            flow_con->init_icmp(config.icmp_cfg, f);
+        if ( (f = InspectorManager::get_session(PROTO_BIT__ICMP)) )
+            flow_con->init_proto(PktType::ICMP, config.icmp_cfg, f);
     }
     if ( config.tcp_cfg.max_sessions )
     {
-        if ( (f = InspectorManager::get_session((uint16_t)PktType::TCP)) )
-            flow_con->init_tcp(config.tcp_cfg, f);
+        if ( (f = InspectorManager::get_session(PROTO_BIT__TCP)) )
+            flow_con->init_proto(PktType::TCP, config.tcp_cfg, f);
     }
     if ( config.udp_cfg.max_sessions )
     {
-        if ( (f = InspectorManager::get_session((uint16_t)PktType::UDP)) )
-            flow_con->init_udp(config.udp_cfg, f);
+        if ( (f = InspectorManager::get_session(PROTO_BIT__UDP)) )
+            flow_con->init_proto(PktType::UDP, config.udp_cfg, f);
     }
     if ( config.user_cfg.max_sessions )
     {
-        if ( (f = InspectorManager::get_session((uint16_t)PktType::PDU)) )
-            flow_con->init_user(config.user_cfg, f);
+        if ( (f = InspectorManager::get_session(PROTO_BIT__PDU)) )
+            flow_con->init_proto(PktType::PDU, config.user_cfg, f);
     }
     if ( config.file_cfg.max_sessions )
     {
-        if ( (f = InspectorManager::get_session((uint16_t)PktType::FILE)) )
-            flow_con->init_file(config.file_cfg, f);
+        if ( (f = InspectorManager::get_session(PROTO_BIT__FILE)) )
+            flow_con->init_proto(PktType::FILE, config.file_cfg, f);
     }
     uint32_t max = config.tcp_cfg.max_sessions + config.udp_cfg.max_sessions
         + config.user_cfg.max_sessions;
@@ -205,6 +210,12 @@ void StreamBase::tterm()
     FlushBucket::clear();
 }
 
+bool StreamBase::configure(SnortConfig* sc)
+{
+    config.track_on_syn = sc->track_on_syn();
+    return true;
+}
+
 void StreamBase::show(SnortConfig*)
 {
     // FIXIT-L SSN print
@@ -220,41 +231,46 @@ void StreamBase::eval(Packet* p)
 
     switch ( p->type() )
     {
-    case PktType::IP:
-        if ( p->has_ip() and
-            ((p->ptrs.decode_flags & DECODE_FRAG) or !config.ip_frags_only) )
-            flow_con->process_ip(p);
+    case PktType::NONE:
         break;
 
-    case PktType::ICMP:
-        if ( p->ptrs.icmph )
-            flow_con->process_icmp(p);
+    case PktType::IP:
+        if ( p->has_ip() and ((p->ptrs.decode_flags & DECODE_FRAG) or !config.ip_frags_only) )
+            flow_con->process(PktType::IP, p);
         break;
 
     case PktType::TCP:
         if ( p->ptrs.tcph )
-            flow_con->process_tcp(p);
+            flow_con->process(PktType::TCP, p);
         break;
 
     case PktType::UDP:
         if ( p->ptrs.decode_flags & DECODE_FRAG )
-            flow_con->process_ip(p);
+            flow_con->process(PktType::IP, p);
 
         if ( p->ptrs.udph )
-            flow_con->process_udp(p);
+            flow_con->process(PktType::UDP, p);
+        break;
+
+    case PktType::ICMP:
+        if ( p->ptrs.icmph )
+        {
+            if ( !flow_con->process(PktType::ICMP, p) )
+                flow_con->process(PktType::IP, p);
+        }
         break;
 
     case PktType::PDU:
-        flow_con->process_user(p);
+        flow_con->process(PktType::PDU, p);
         break;
 
     case PktType::FILE:
-        flow_con->process_file(p);
+        flow_con->process(PktType::FILE, p);
         break;
 
-    default:
+    case PktType::MAX:
         break;
-    }
+    };
 }
 
 #if 0
@@ -308,7 +324,7 @@ static const InspectApi base_api =
         mod_dtor
     },
     IT_STREAM,
-    (unsigned)PktType::ANY_SSN,
+    PROTO_BIT__ANY_SSN,
     nullptr, // buffers
     nullptr, // service
     nullptr, // init
index 1439a363d697fa40ffb0240a54f004aac67b4bac..aeb316b48226abf1af194b34d4826012af7c3156 100644 (file)
@@ -74,6 +74,7 @@ struct StreamModuleConfig
 
     int footprint;
     bool ip_frags_only;
+    bool track_on_syn;
 };
 
 class StreamModule : public snort::Module
index 36c17c8155a664fdf537bd833fa98659f60f321e..b893de2b3ef1908672b1bd7071de12a6652b3c25 100644 (file)
@@ -96,7 +96,7 @@ static const InspectApi sfile_api =
         mod_dtor
     },
     IT_STREAM,
-    (unsigned)PktType::FILE,
+    PROTO_BIT__FILE,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index e501d6a18a45a2fa3ea44d57fe83e81c2d1d4c3c..4e38967cfdbc5ad55d5d8b6a10c2510e03f9cc65 100644 (file)
@@ -133,7 +133,7 @@ static const InspectApi icmp_api =
         mod_dtor
     },
     IT_STREAM,
-    (unsigned)PktType::ICMP,
+    PROTO_BIT__ICMP,
     nullptr, // buffers
     nullptr, // service
     nullptr, // init
index d30f6bc36fe3b75f6f3284b5be62599bc58f23fb..460b38d156caf312ab13281fb20a2903432fc85e 100644 (file)
@@ -178,7 +178,7 @@ static const InspectApi ip_api =
         mod_dtor
     },
     IT_STREAM,
-    (unsigned)PktType::IP,
+    PROTO_BIT__IP,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index 39c75fd70be91e37e5758a2bd22a34a1de8146ae..2aa2c9c0e48191a508c55f66f551b33dfd9b3545 100644 (file)
@@ -110,6 +110,9 @@ bool TcpSegmentDescriptor::has_wscale()
 
     DebugMessage(DEBUG_STREAM_STATE, "Checking for wscale...\n");
 
+    if ( !(pkt->ptrs.decode_flags & DECODE_WSCALE) )
+        return false;
+
     return ( init_wscale(&wscale) & TF_WSCALE ) != TF_NONE;
 }
 
index ce7bdaf76a9fb88ce34b09dcad511e5004325ced..f7929a98c89326361355cf2e3ea90da1b2f69161 100644 (file)
@@ -146,7 +146,7 @@ static const InspectApi tcp_api =
         mod_dtor
     },
     IT_STREAM,
-    (unsigned)PktType::TCP,
+    PROTO_BIT__TCP,
     nullptr,  // buffers
     nullptr,  // service
     nullptr,  // init
index f56660c6e2c117b9292e00d12bec80cb6107eb3d..f81a06c5398d1f4e40097e565555edf49c3ed039 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "tcp_module.h"
 
+#include "main/snort_config.h"
 #include "profiler/profiler_defs.h"
 
 using namespace snort;
@@ -153,9 +154,6 @@ static const Parameter s_params[] =
     { "flush_factor", Parameter::PT_INT, "0:", "0",
       "flush upon seeing a drop in segment size after given number of non-decreasing segments" },
 
-    { "ignore_any_rules", Parameter::PT_BOOL, nullptr, "false",
-      "process TCP content rules w/o ports only if rules with ports are present" },
-
     { "max_window", Parameter::PT_INT, "0:1073725440", "0",
       "maximum allowed TCP window" },
 
@@ -291,9 +289,6 @@ bool StreamTcpModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("flush_factor") )
         config->flush_factor = v.get_long();
 
-    else if ( v.is("ignore_any_rules") )
-        config->flags |= STREAM_CONFIG_IGNORE_ANY;
-
     else if ( v.is("max_bytes") )
         config->max_queued_bytes = v.get_long();
 
@@ -354,8 +349,10 @@ bool StreamTcpModule::begin(const char* fqn, int, SnortConfig*)
     return true;
 }
 
-bool StreamTcpModule::end(const char*, int, SnortConfig*)
+bool StreamTcpModule::end(const char*, int, SnortConfig* sc)
 {
+    if ( config->hs_timeout >= 0 )
+        sc->run_flags |= RUN_FLAG__TRACK_ON_SYN;
     return true;
 }
 
index fb819fd1f0cbf340e17c6be0080bab6de0590e0e..69b24d1a990dd8376143854387b9b29efe7c790b 100644 (file)
@@ -106,6 +106,16 @@ bool TcpReassembler::flush_data_ready(TcpReassemblerState& trs)
     return ( get_pending_segment_count(trs, 2) > 1 );  // FIXIT-L return false?
 }
 
+bool TcpReassembler::next_no_gap(TcpSegmentNode& tsn)
+{
+    return tsn.next and (tsn.next->seq == tsn.seq + tsn.payload_size);
+}
+
+void TcpReassembler::update_next(TcpReassemblerState& trs, TcpSegmentNode& tsn)
+{
+    trs.sos.seglist.next = next_no_gap(tsn) ?  tsn.next : nullptr;
+}
+
 int TcpReassembler::delete_reassembly_segment(TcpReassemblerState& trs, TcpSegmentNode* tsn)
 {
     int ret;
@@ -136,7 +146,7 @@ int TcpReassembler::delete_reassembly_segment(TcpReassemblerState& trs, TcpSegme
     }
 
     if (trs.sos.seglist.next == tsn)
-        trs.sos.seglist.next = nullptr;
+        update_next(trs, *tsn);
 
     tsn->term( );
     trs.sos.seg_count--;
@@ -467,7 +477,7 @@ int TcpReassembler::flush_data_segments(
         trs.flush_count++;
         segs++;
 
-        trs.sos.seglist.next = tsn->next;
+        update_next(trs, *tsn);
 
         if ( SEQ_EQ(tsn->seq + bytes_to_copy, to_seq) )
             break;
@@ -630,7 +640,7 @@ int TcpReassembler::_flush_to_seq(
             tcpStats.rebuilt_packets++;
             tcpStats.rebuilt_bytes += flushed_bytes;
 
-            ProfileExclude profile_exclude(s5TcpFlushPerfStats);
+            NoProfile exclude(s5TcpFlushPerfStats);
             Snort::inspect(pdu);
         }
         else
@@ -723,7 +733,7 @@ int TcpReassembler::do_zero_byte_flush(TcpReassemblerState& trs, Packet* p, uint
         trs.flush_count++;
 
         show_rebuilt_packet(trs, pdu);
-        ProfileExclude profile_exclude(s5TcpFlushPerfStats);
+        NoProfile profile_exclude(s5TcpFlushPerfStats);
         Snort::inspect(pdu);
 
         if ( trs.tracker->splitter )
@@ -743,12 +753,12 @@ uint32_t TcpReassembler::get_q_footprint(TcpReassemblerState& trs)
     if ( !trs.tracker )
         return 0;
 
-    trs.sos.seglist.next = trs.sos.seglist.head;
     footprint = trs.tracker->r_win_base - trs.sos.seglist_base_seq;
 
     if ( footprint )
     {
         sequenced = get_q_sequenced(trs);
+
         if ( trs.tracker->fin_seq_status == TcpStreamTracker::FIN_WITH_SEQ_ACKED )
             --footprint;
     }
@@ -762,33 +772,42 @@ uint32_t TcpReassembler::get_q_footprint(TcpReassemblerState& trs)
 
 uint32_t TcpReassembler::get_q_sequenced(TcpReassemblerState& trs)
 {
-    TcpSegmentNode* tsn = trs.tracker ? trs.sos.seglist.head : nullptr;
-    TcpSegmentNode* base = nullptr;
-
-    if ( !tsn || ( trs.sos.session->flow->two_way_traffic() &&
-        SEQ_LT(trs.tracker->r_win_base, tsn->seq) ) )
-        return 0;
+    TcpSegmentNode* tsn;
 
-    while ( tsn->next && ( tsn->next->seq == tsn->seq + tsn->payload_size ) )
+    if ( trs.sos.seglist.next )
+        tsn = trs.sos.seglist.next;
+    else
     {
-        if ( !tsn->buffered && !base )
-            base = tsn;
-        tsn = tsn->next;
-    }
+        trs.sos.seglist.next = trs.sos.seglist.head;
+        tsn = trs.tracker ? trs.sos.seglist.next : nullptr;  // FIXIT-H why check tracker here?
 
-    if ( !tsn->buffered && !base )
-        base = tsn;
+        if ( !tsn or (trs.sos.session->flow->two_way_traffic() and
+            SEQ_LT(trs.tracker->r_win_base, tsn->seq)) )
+        {
+            if ( trs.sos.seglist.next )
+                trs.sos.seglist.next = trs.sos.seglist.next->prev;
+            return 0;
+        }
+    }
 
-    int32_t len = 0;
+    uint32_t len = 0;
+    const uint32_t limit = trs.tracker->splitter->get_max_pdu();
 
-    if ( base )
+    while ( len < limit and next_no_gap(*tsn) )
     {
-        trs.sos.seglist.next = base;
-        trs.sos.seglist_base_seq = base->seq;
-        len = tsn->seq + tsn->payload_size - base->seq;
+        if ( tsn->buffered )
+            trs.sos.seglist.next = tsn->next;
+        else
+            len += tsn->payload_size;
+
+        tsn = tsn->next;
     }
+    if ( !tsn->buffered )
+        len += tsn->payload_size;
+
+    trs.sos.seglist_base_seq = trs.sos.seglist.next->seq;
 
-    return ( len > 0 ) ? len : 0;
+    return len;
 }
 
 // FIXIT-L flush_stream() calls should be replaced with calls to
index 8a9ffcf54014a638d812fe66504eb27db5e27c26..b59a2105ecd3dc407fad266e4792db8c0f0183f1 100644 (file)
@@ -90,6 +90,9 @@ protected:
     void fallback(TcpReassemblerState&);
     int32_t flush_pdu_ackd(TcpReassemblerState&, uint32_t* flags);
     int purge_to_seq(TcpReassemblerState&, uint32_t flush_seq);
+
+    bool next_no_gap(TcpSegmentNode&);
+    void update_next(TcpReassemblerState&, TcpSegmentNode&);
 };
 
 #endif
index 5b589888105d39c764eb9b570f23f634e569052f..5ed6fa6774be1327b92c6df7a805607312aa8447 100644 (file)
@@ -81,8 +81,7 @@ TcpSession::TcpSession(Flow* flow)
 
 TcpSession::~TcpSession()
 {
-    if (tcp_init)
-        clear_session(true, false, false);
+    clear_session(true, false, false);
 }
 
 bool TcpSession::setup(Packet* p)
@@ -139,6 +138,9 @@ void TcpSession::restart(Packet* p)
 
 void TcpSession::clear_session(bool free_flow_data, bool flush_segments, bool restart, Packet* p)
 {
+    if ( !tcp_init )
+        return;
+
     assert(!p or p->flow == flow);
     DetectionEngine::onload(flow);
 
index 00a8e69b3ee7d22d6fde4f95c36472ba00ac49c5..7c0cab21f6c09409c61d56b4b47c59b7981f5dd7 100644 (file)
@@ -62,9 +62,6 @@ void TcpStreamConfig::show_config(TcpStreamConfig* config)
     if ( config->flags )
     {
         LogMessage("    Options:\n");
-        if (config->flags & STREAM_CONFIG_IGNORE_ANY)
-            LogMessage("        Ignore Any -> Any Rules: YES\n");
-
         if (config->flags & STREAM_CONFIG_NO_ASYNC_REASSEMBLY)
             LogMessage("        Don't queue packets on one-sided sessions: YES\n");
     }
index 8f3ddd56828f2b10e3d90aa96f788008249b8106..6b753ac1e6bf1b0edc085235455ceea792a0d987 100644 (file)
 #include "stream/tcp/tcp_defs.h"
 #include "time/packet_time.h"
 
-#define STREAM_CONFIG_STATEFUL_INSPECTION      0x00000001
-#define STREAM_CONFIG_LOG_STREAMS              0x00000004
-#define STREAM_CONFIG_REASS_CLIENT             0x00000008
-#define STREAM_CONFIG_REASS_SERVER             0x00000010
-#define STREAM_CONFIG_ASYNC                    0x00000020
-#define STREAM_CONFIG_SHOW_PACKETS             0x00000040
-#define STREAM_CONFIG_MIDSTREAM_DROP_NOALERT   0x00000080
-#define STREAM_CONFIG_IGNORE_ANY               0x00000100
-#define STREAM_CONFIG_STATIC_FLUSHPOINTS       0x00000200
-#define STREAM_CONFIG_IPS                      0x00000400
-#define STREAM_CONFIG_NO_ASYNC_REASSEMBLY      0x00000800
+#define STREAM_CONFIG_SHOW_PACKETS             0x00000001
+#define STREAM_CONFIG_NO_ASYNC_REASSEMBLY      0x00000002
 
 #define STREAM_DEFAULT_SSN_TIMEOUT  30
 
index 15506550a0b0d105a057f45775c92d70a1ac86f6..1f031b619d3889af1456b5c1bdc4fc0bc883449e 100644 (file)
@@ -37,7 +37,6 @@ using namespace snort;
 StreamUdpConfig::StreamUdpConfig()
 {
     session_timeout = 30;
-    ignore_any = false;
 }
 
 static void udp_show(StreamUdpConfig* pc)
@@ -45,9 +44,6 @@ static void udp_show(StreamUdpConfig* pc)
     LogMessage("Stream UDP config:\n");
     LogMessage("    Timeout: %d seconds\n", pc->session_timeout);
 
-    const char* opt = (pc->ignore_any) ? "YES" : "NO";
-    LogMessage("    Ignore Any -> Any Rules: %s\n", opt);
-
 #ifdef REG_TEST
     LogMessage("    UDP Session Size: %zu\n", sizeof(UdpSession));
 #endif
@@ -149,7 +145,7 @@ static const InspectApi udp_api =
         mod_dtor
     },
     IT_STREAM,
-    (unsigned)PktType::UDP,
+    PROTO_BIT__UDP,
     nullptr, // buffers
     nullptr, // service
     nullptr, // init
index a21ed9c5cafd29648e93b88e70c9fb165ff41e4d..aa119346163fe1f8676525e72934ea00922d0fef 100644 (file)
@@ -29,7 +29,6 @@ class Inspector;
 struct StreamUdpConfig
 {
     uint32_t session_timeout;
-    bool ignore_any;
 
     StreamUdpConfig();
 };
index 2395a9eb5e88782582445d1ba83390ea403ff8db..687ed6aae319841f1fe705cc123c0cc42dd085b2 100644 (file)
@@ -38,9 +38,6 @@ static const Parameter s_params[] =
     { "session_timeout", Parameter::PT_INT, "1:86400", "30",
       "session tracking timeout" },
 
-    { "ignore_any_rules", Parameter::PT_BOOL, nullptr, "false",
-      "process UDP content rules w/o ports only if rules with ports are present" },
-
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
@@ -67,9 +64,6 @@ bool StreamUdpModule::set(const char*, Value& v, SnortConfig*)
     if ( v.is("session_timeout") )
         config->session_timeout = v.get_long();
 
-    else if ( v.is("ignore_any_rules") )
-        config->ignore_any = v.get_bool();
-
     else
         return false;
 
index 5a8a215f72aa43467372f6cbd288a9e4a2d407af..4fd919dfb6d1f4e74b3d04325303540d20bf89c1 100644 (file)
@@ -131,7 +131,7 @@ static const InspectApi user_api =
         mod_dtor
     },
     IT_STREAM,
-    (unsigned)PktType::PDU,
+    PROTO_BIT__PDU,
     nullptr, // buffers
     nullptr, // service
     nullptr, // pinit
index 911e8431876b59cb027eadd4a727ada0ede4cfc0..20bb1fe7f0e7cd0f0b90018ed7a0ca1b24025a1a 100644 (file)
@@ -83,6 +83,8 @@ static ConversionState* config_false_no_opt_ctor(Converter& c)
     return new DeadCode(c);
 }
 
+#if 0
+// currently unused - for future reference
 template<const std::string* snort_option,
 const std::string* lua_table>
 static ConversionState* config_false_no_opt_ctor(Converter& c)
@@ -92,6 +94,7 @@ static ConversionState* config_false_no_opt_ctor(Converter& c)
     c.get_table_api().close_table();
     return new DeadCode(c);
 }
+#endif
 } // namespace
 
 /*************************************************
index 88c9445a87fa5ec28799abbfaf37923f6680f7e5..fc8f054e678aafc3db800b84373db29bf4cbc3d7 100644 (file)
@@ -304,7 +304,7 @@ bool StreamTcp::convert(std::istringstream& data_stream)
             tmpval = parse_small_segments(arg_stream);
 
         else if (keyword == "ignore_any_rules")
-            tmpval = table_api.add_option("ignore_any_rules", true);
+            table_api.add_deleted_comment("ignore_any_rules");
 
         else if (keyword == "ports")
             tmpval = parse_ports(arg_stream);
index 3652206190c11a1d641c176e67f6484c397c14ff..956a4f79e2c9ceb67de99b1ebacb93d2bd973562 100644 (file)
@@ -54,7 +54,7 @@ bool StreamUdp::convert(std::istringstream& data_stream)
             continue;
 
         if (keyword == "ignore_any_rules")
-            tmpval = table_api.add_option("ignore_any_rules", true);
+            table_api.add_deleted_comment("ignore_any_rules");
 
         else if (keyword == "timeout")
         {