]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3160: Dead code
authorRuss Combs (rucombs) <rucombs@cisco.com>
Tue, 23 Nov 2021 21:34:24 +0000 (21:34 +0000)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Tue, 23 Nov 2021 21:34:24 +0000 (21:34 +0000)
Merge in SNORT/snort3 from ~RUCOMBS/snort3:dead_code to master

Squashed commit of the following:

commit 4822f91965a6219c28d2786d02a1d302a23cd2db
Author: russ <rucombs@cisco.com>
Date:   Wed Nov 10 09:00:16 2021 -0500

    utils: reduce flex generation of unused js normalizer code

commit be2f17d4a46e4461094d7bf1a4c6ace4aad49471
Author: russ <rucombs@cisco.com>
Date:   Tue Nov 9 22:51:29 2021 -0500

    appid: exclude stubs from coverage

commit 787e0ab1671fc9c3f7aebf6f022731acdcd5e43f
Author: russ <rucombs@cisco.com>
Date:   Tue Nov 9 16:00:05 2021 -0500

    stream_user: refactor, remove cruft

commit 87c9afe6b700e32ffdb11a3f14d7e716cefe76d1
Author: russ <rucombs@cisco.com>
Date:   Tue Nov 9 12:47:58 2021 -0500

    rna: refactor unit test stubs

commit 7b18a15516928e54df078a95e23d2c728d23519e
Author: russ <rucombs@cisco.com>
Date:   Tue Nov 9 12:44:47 2021 -0500

    search_engines: remove unused test code

commit 6428b1fe7286fafd5b263fd26cc93714687cad3c
Author: russ <rucombs@cisco.com>
Date:   Mon Nov 8 15:20:25 2021 -0500

    reputation: remove unused sfrt code

commit 192adfc363122d0e192bb4c931521542829b5035
Author: russ <rucombs@cisco.com>
Date:   Mon Nov 8 14:07:55 2021 -0500

    piglets: refactor support code

commit c75c67c9979d58f32101aa041fbc2212e4a9429d
Author: russ <rucombs@cisco.com>
Date:   Mon Nov 8 13:36:14 2021 -0500

    alert_sf_socket: remove obselete logger

commit c8681a19ffd3c9184d7670a19f3ad7be55255f70
Author: russ <rucombs@cisco.com>
Date:   Mon Nov 8 11:57:24 2021 -0500

    build: remove config.h from headers

commit 5b102d96778edb30a10767f6d9e07d0fc859352a
Author: russ <rucombs@cisco.com>
Date:   Mon Nov 8 07:05:33 2021 -0500

    unified2: remove cruft

commit a42e9e174445af49633dcbcfec39cef73a53f7d2
Author: russ <rucombs@cisco.com>
Date:   Sun Nov 7 05:47:39 2021 -0500

    stream_tcp: remove unused unit test code

commit bb40e0e171418955f025d1db6485f1e08a6dc9c2
Author: russ <rucombs@cisco.com>
Date:   Fri Nov 5 15:24:11 2021 -0400

    build: remove unreachable code

188 files changed:
doc/devel/style.txt
src/actions/act_react.cc
src/actions/act_reject.cc
src/codecs/ip/cd_udp.cc
src/connectors/file_connector/file_connector_module.cc
src/connectors/tcp_connector/tcp_connector_module.cc
src/decompress/file_oleheader.cc
src/dump_config/text_config_output.cc
src/file_api/file_log.cc
src/file_api/file_module.cc
src/flow/ha_module.cc
src/flow/session.h
src/flow/test/flow_cache_test.cc
src/flow/test/flow_control_test.cc
src/flow/test/flow_stash_test.cc
src/flow/test/session_test.cc
src/host_tracker/host_cache_allocator.cc
src/host_tracker/host_cache_module.cc
src/host_tracker/host_tracker_module.cc
src/host_tracker/test/CMakeLists.txt
src/ips_options/ips_ack.cc
src/ips_options/ips_asn1.cc
src/ips_options/ips_base64.cc
src/ips_options/ips_ber_data.cc
src/ips_options/ips_ber_skip.cc
src/ips_options/ips_bufferlen.cc
src/ips_options/ips_byte_extract.cc
src/ips_options/ips_byte_jump.cc
src/ips_options/ips_byte_math.cc
src/ips_options/ips_byte_test.cc
src/ips_options/ips_classtype.cc
src/ips_options/ips_content.cc
src/ips_options/ips_cvs.cc
src/ips_options/ips_detection_filter.cc
src/ips_options/ips_dsize.cc
src/ips_options/ips_enable.cc
src/ips_options/ips_file_type.cc
src/ips_options/ips_flags.cc
src/ips_options/ips_flow.cc
src/ips_options/ips_flowbits.cc
src/ips_options/ips_fragbits.cc
src/ips_options/ips_fragoffset.cc
src/ips_options/ips_gid.cc
src/ips_options/ips_hash.cc
src/ips_options/ips_icmp_id.cc
src/ips_options/ips_icmp_seq.cc
src/ips_options/ips_icode.cc
src/ips_options/ips_id.cc
src/ips_options/ips_ip_proto.cc
src/ips_options/ips_ipopts.cc
src/ips_options/ips_isdataat.cc
src/ips_options/ips_itype.cc
src/ips_options/ips_metadata.cc
src/ips_options/ips_msg.cc
src/ips_options/ips_pcre.cc
src/ips_options/ips_priority.cc
src/ips_options/ips_reference.cc
src/ips_options/ips_regex.cc
src/ips_options/ips_rem.cc
src/ips_options/ips_replace.cc
src/ips_options/ips_rev.cc
src/ips_options/ips_rpc.cc
src/ips_options/ips_sd_pattern.cc
src/ips_options/ips_seq.cc
src/ips_options/ips_service.cc
src/ips_options/ips_sid.cc
src/ips_options/ips_so.cc
src/ips_options/ips_soid.cc
src/ips_options/ips_tag.cc
src/ips_options/ips_target.cc
src/ips_options/ips_tos.cc
src/ips_options/ips_ttl.cc
src/ips_options/ips_vba_data.cc
src/ips_options/ips_vba_data.h
src/ips_options/ips_window.cc
src/ips_options/test/ips_regex_test.cc
src/loggers/CMakeLists.txt
src/loggers/alert_csv.cc
src/loggers/alert_fast.cc
src/loggers/alert_full.cc
src/loggers/alert_json.cc
src/loggers/alert_sf_socket.cc [deleted file]
src/loggers/alert_syslog.cc
src/loggers/log_codecs.cc
src/loggers/log_hext.cc
src/loggers/log_pcap.cc
src/loggers/loggers.cc
src/loggers/unified2.cc
src/lua/CMakeLists.txt
src/lua/lua_script.h [new file with mode: 0644]
src/lua/lua_util.h
src/main/modules.cc
src/managers/event_manager.cc
src/managers/script_manager.cc
src/memory/memory_module.cc
src/network_inspectors/appid/client_plugins/test/client_plugins_mock.h
src/network_inspectors/appid/detector_plugins/test/detector_plugins_mock.h
src/network_inspectors/appid/detector_plugins/test/detector_sip_test.cc
src/network_inspectors/appid/ips_appid_option.cc
src/network_inspectors/appid/test/CMakeLists.txt
src/network_inspectors/appid/test/log_message_mock.h
src/network_inspectors/arp_spoof/arp_module.cc
src/network_inspectors/normalize/norm_module.cc
src/network_inspectors/packet_capture/capture_module.cc
src/network_inspectors/packet_tracer/packet_tracer_module.cc
src/network_inspectors/perf_monitor/perf_module.cc
src/network_inspectors/port_scan/ps_module.cc
src/network_inspectors/reputation/reputation_module.cc
src/network_inspectors/rna/rna_module.cc
src/network_inspectors/rna/test/CMakeLists.txt
src/network_inspectors/rna/test/rna_flow_stubs.cc [moved from src/network_inspectors/rna/test/rna_flow_mock.cc with 100% similarity]
src/network_inspectors/rna/test/rna_module_mock.h
src/network_inspectors/rna/test/rna_module_stubs.h [new file with mode: 0644]
src/network_inspectors/rna/test/rna_module_test.cc
src/piglet/piglet_runner.cc
src/protocols/arp.h
src/search_engines/test/search_tool_test.cc
src/service_inspectors/cip/cip_module.cc
src/service_inspectors/cip/ips_cip_attribute.cc
src/service_inspectors/cip/ips_cip_class.cc
src/service_inspectors/cip/ips_cip_connpathclass.cc
src/service_inspectors/cip/ips_cip_enipcommand.cc
src/service_inspectors/cip/ips_cip_instance.cc
src/service_inspectors/cip/ips_cip_service.cc
src/service_inspectors/cip/ips_cip_status.cc
src/service_inspectors/dce_rpc/dce_tcp_module.cc
src/service_inspectors/dce_rpc/ips_dce_iface.cc
src/service_inspectors/dce_rpc/ips_dce_opnum.cc
src/service_inspectors/dnp3/dnp3_module.cc
src/service_inspectors/dnp3/ips_dnp3_func.cc
src/service_inspectors/dnp3/ips_dnp3_ind.cc
src/service_inspectors/ftp_telnet/ftp_module.cc
src/service_inspectors/ftp_telnet/telnet_module.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/http2_inspect/http2_huffman_state_machine.cc
src/service_inspectors/http2_inspect/http2_module.cc
src/service_inspectors/http2_inspect/http2_utils.cc
src/service_inspectors/http2_inspect/http2_utils.h
src/service_inspectors/http_inspect/http_buffer_info.cc
src/service_inspectors/http_inspect/http_module.cc
src/service_inspectors/http_inspect/ips_http.cc
src/service_inspectors/iec104/ips_iec104_apci_type.cc
src/service_inspectors/iec104/ips_iec104_asdu_func.cc
src/service_inspectors/imap/imap_module.cc
src/service_inspectors/modbus/ips_modbus_func.cc
src/service_inspectors/modbus/ips_modbus_unit.cc
src/service_inspectors/netflow/netflow_module.cc
src/service_inspectors/pop/pop_module.cc
src/service_inspectors/s7commplus/ips_s7comm_func.cc
src/service_inspectors/s7commplus/ips_s7comm_opcode.cc
src/service_inspectors/sip/ips_sip_method.cc
src/service_inspectors/sip/ips_sip_stat_code.cc
src/service_inspectors/sip/sip_module.cc
src/service_inspectors/smtp/smtp_module.cc
src/service_inspectors/ssh/ssh_module.cc
src/service_inspectors/ssl/ips_ssl_state.cc
src/service_inspectors/ssl/ips_ssl_version.cc
src/service_inspectors/ssl/ssl_module.cc
src/service_inspectors/ssl/ssl_splitter.cc
src/sfip/sf_ipvar.cc
src/sfrt/CMakeLists.txt
src/sfrt/sfrt.cc [deleted file]
src/sfrt/sfrt.h
src/sfrt/sfrt_dir.cc [deleted file]
src/sfrt/sfrt_dir.h [deleted file]
src/sfrt/sfrt_flat.cc
src/sfrt/sfrt_flat.h
src/sfrt/sfrt_flat_dir.cc
src/sfrt/sfrt_flat_dir.h
src/sfrt/sfrt_test.cc [deleted file]
src/side_channel/side_channel_module.cc
src/stream/base/stream_module.cc
src/stream/file/file_module.cc
src/stream/icmp/icmp_module.cc
src/stream/tcp/ips_stream_reassemble.cc
src/stream/tcp/ips_stream_size.cc
src/stream/tcp/tcp_module.cc
src/stream/tcp/tcp_state_closed.cc
src/stream/tcp/tcp_state_handler.cc
src/stream/tcp/tcp_state_none.cc
src/stream/tcp/test/stream_tcp_test_utils.cc
src/stream/udp/udp_module.cc
src/stream/user/stream_user.cc
src/stream/user/user_module.cc
src/stream/user/user_session.h
src/utils/js_tokenizer.l

index 24738ebff301da31baa9474a14c6fe1cd8bc39a7..f1e124a818f8ecc440391948d929e6f62f3e3c62 100644 (file)
@@ -285,9 +285,8 @@ yet firm so feedback is welcome to get something we can live with.
 * All .cc files should include config.h with the standard block shown below
   immediately following the initial comment blocks and before anything else.
   This presents a consistent view of all included header files as well as
-  access to any other configure-time definitions. No .h files should include
-  config.h unless they are guaranteed to be local header files (never
-  installed).
+  access to any other configure-time definitions. To avoid issues, no .h files
+  should include config.h, even if not installed.
 
     #ifdef HAVE_CONFIG_H
     #include "config.h"
index 4582062cc4cfb40532c5a013949d04deae350f39..acac4a9e3c218280258055ca3899849a21ed141f 100644 (file)
@@ -281,10 +281,8 @@ bool ReactModule::begin(const char*, int, SnortConfig*)
 
 bool ReactModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("page") )
-        return getpage(v.get_string());
-
-    return true;
+    assert(v.is("page"));
+    return getpage(v.get_string());
 }
 
 std::string ReactModule::get_data()
index d1a2b2a49cf77267704b0f7672495b0c2adbcfad..b1a02f32b181e2f8655fe64f3856024db0642c3a 100644 (file)
@@ -250,9 +250,6 @@ bool RejectModule::set(const char*, Value& v, SnortConfig*)
         flags |= unr[v.get_uint8()];
     }
 
-    else
-        return false;
-
     return true;
 }
 
index 371f654a6bd7c2fe2c6729b9d66d10389de93e32..930045fa56764dee0b5727bb623738e99f2809f5 100644 (file)
@@ -219,8 +219,6 @@ bool UdpModule::set(const char*, Value& v, SnortConfig*)
         v.get_bits(ports);
         config->set_geneve_ports(ports);
     }
-    else
-        return false;
 
     return true;
 }
index a18b654ad7d828cb7543c944fadc8710e0a6a768..05cd55296d13260f5fc4bca176cd885a7f0a7f41 100644 (file)
@@ -86,30 +86,22 @@ bool FileConnectorModule::set(const char*, Value& v, SnortConfig*)
         config->text_format = ( v.get_uint8() == 1 );
 
     else if ( v.is("direction") )
+    {
         switch ( v.get_uint8() )
         {
         case 0:
-        {
             config->direction = Connector::CONN_RECEIVE;
             break;
-        }
         case 1:
-        {
             config->direction = Connector::CONN_TRANSMIT;
             break;
-        }
         case 2:
-        {
             config->direction = Connector::CONN_DUPLEX;
             break;
-        }
         default:
             return false;
         }
-
-    else
-        return false;
-
+    }
     return true;
 }
 
index fe486f930dc8d0d00c5c0004472b63b9fa541a77..1a961b67f08f9f5d34189baf62023e0205fd6352 100644 (file)
@@ -86,25 +86,19 @@ bool TcpConnectorModule::set(const char*, Value& v, SnortConfig*)
         config->base_port = v.get_uint16();
 
     else if ( v.is("setup") )
+    {
         switch ( v.get_uint8() )
         {
         case 0:
-        {
             config->setup = TcpConnectorConfig::CALL;
             break;
-        }
         case 1:
-        {
             config->setup = TcpConnectorConfig::ANSWER;
             break;
-        }
         default:
             return false;
         }
-
-    else
-        return false;
-
+    }
     return true;
 }
 
index fb72c0f2b172ba8d1b078101616a141d7e5338ac..605e521514253040b179aad342366c6ed9fe53a7 100644 (file)
 
 // file_oleheader.cc author Amarnath Nayak amarnaya@cisco.com
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "file_oleheader.h"
 
 unsigned char hdr_sig[8] = { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 };
index 7d567779009069ce9316f567396e0d33b182a505..6d728d32dab579246573d958611903157848f21b 100644 (file)
 //--------------------------------------------------------------------------
 // text_config_output.cc author Serhii Vlasiuk <svlasiuk@cisco.com>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "text_config_output.h"
 
 #include <iomanip>
index ada718e8e12cd7bb0b8b35160c4e0834f57dd4ae..a95ae0f3f12e72110fdf23589e569ac104d72dee 100644 (file)
@@ -266,9 +266,6 @@ bool FileLogModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("log_sys_time") )
         config.log_sys_time = v.get_bool();
 
-    else
-        return false;
-
     return true;
 }
 
index bb94996de0fbb6e6e8fe48e98b6a513db4beb6f3..931578a9c821c6042214cd508cd6ce5eb40b8d2a 100644 (file)
@@ -455,9 +455,6 @@ bool FileIdModule::set(const char*, Value& v, SnortConfig*)
             return false;
         }
     }
-    else
-        return false;
-
     return true;
 }
 
index 379ed4c2be79c103f1f897cb012b3359d9f4cd87..a4af327a8f50f99d09a711b05c1b96d88cec9d32 100644 (file)
@@ -145,8 +145,6 @@ bool HighAvailabilityModule::set(const char*, Value& v, SnortConfig*)
     {
         convert_milliseconds_to_timeval(v.get_uint32(), &config->min_sync_interval);
     }
-    else
-        return false;
 
     return true;
 }
index 22146ceeab8e4c9a77da4dbaa79492235586bc91..c846dd6e02439544022225b1a8a2872febc223ce 100644 (file)
@@ -71,7 +71,7 @@ public:
     virtual void set_extra_data(snort::Packet*, uint32_t /*flag*/) { }
 
     virtual bool is_sequenced(uint8_t /*dir*/) { return true; }
-    virtual bool are_packets_missing(uint8_t /*dir*/) { return true; }
+    virtual bool are_packets_missing(uint8_t /*dir*/) { return false; }
     virtual bool are_client_segments_queued() { return false; }
 
     virtual void disable_reassembly(snort::Flow*) { }
index 080faaa5b1d99ef5d0dad966b735eb1397d5da8a..dc9276aaa1c6f72cfabc640d13600f72d85871a4 100644 (file)
@@ -1,4 +1,4 @@
-
+//--------------------------------------------------------------------------
 // Copyright (C) 2019-2021 Cisco and/or its affiliates. All rights reserved.
 //
 // This program is free software; you can redistribute it and/or modify it
index 44467fa8155f5b6c855bd48deca280e92dd360bb..d828b1596f628a23805b58a6f16a0136322010fb 100644 (file)
@@ -1,4 +1,4 @@
-
+//--------------------------------------------------------------------------
 // Copyright (C) 2019-2021 Cisco and/or its affiliates. All rights reserved.
 //
 // This program is free software; you can redistribute it and/or modify it
index f9a87c6bb2b7151f2aaed4690f09cbb39a75585b..2262e595d68d384f41ca9a7cb3a9525105d9043e 100644 (file)
 
 // flow_stash_test.cc author Shravan Rangaraju <shrarang@cisco.com>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <string>
 
 #include "flow/flow_stash.h"
index 66eec1a653e394b5b93cbc86ce6ac78bc478d35c..45ab0b3266eaa9dd307c5c245982c34e949d6175 100644 (file)
@@ -62,8 +62,7 @@ TEST(session_test, seesion_class_test)
     ssn->set_extra_data(nullptr, 1);
 
     CHECK(true == ssn->is_sequenced(1));
-    CHECK(true == ssn->are_packets_missing(1));
-
+    CHECK(false == ssn->are_packets_missing(1));
 
     CHECK(SSN_DIR_NONE == ssn->get_reassembly_direction());
     CHECK(SSN_MISSING_NONE == ssn->missing_in_reassembled(1));
index 8f1ae12e844e122aaedecb5a87326b0175baeb2c..bd151d75f3f082e0050ec06e1e0966bc66061f32 100644 (file)
 
 // host_cache_allocator.cc author Silviu Minut <sminut@cisco.com>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #ifndef HOST_CACHE_ALLOCATOR_CC
 #define HOST_CACHE_ALLOCATOR_CC
 
index 8987ee20bbf63cf32a47f0242870f1840e0dc719..903066dec98d630c0ed4db38ad735466c3b85d05 100644 (file)
@@ -362,8 +362,6 @@ bool HostCacheModule::set(const char*, Value& v, SnortConfig*)
     }
     else if ( v.is("memcap") )
         memcap = v.get_size();
-    else
-        return false;
 
     return true;
 }
index ab6b426c627f12039314c486583671e9047092ee..080cf411d277bc829fcdb59db66af4db02f7b469 100644 (file)
@@ -63,6 +63,7 @@ bool HostTrackerModule::set(const char*, Value& v, SnortConfig*)
 
     else if ( v.is("port") )
         host_cache[addr]->update_service_port(app, v.get_uint16());
+
     else if ( v.is("proto") )
     {
         const IpProtocol mask[] =
@@ -70,9 +71,6 @@ bool HostTrackerModule::set(const char*, Value& v, SnortConfig*)
         host_cache[addr]->update_service_proto(app, mask[v.get_uint8()]);
     }
 
-    else
-        return false;
-
     return true;
 }
 
index c743a6aa49569f973e2ec9745c1d8d6eb7806f72..8e91de0b45178ac7f377bd0ca0906c8e1098f360 100644 (file)
@@ -3,7 +3,7 @@ add_cpputest( host_cache_test
     SOURCES
         ../host_cache.cc
         ../host_tracker.cc
-        ../../network_inspectors/rna/test/rna_flow_mock.cc
+        ../../network_inspectors/rna/test/rna_flow_stubs.cc
         ../../sfip/sf_ip.cc
 )
 
@@ -15,7 +15,7 @@ add_cpputest( host_cache_module_test
         ../../framework/module.cc
         ../../framework/value.cc
         ../../hash/lru_cache_shared.cc
-        ../../network_inspectors/rna/test/rna_flow_mock.cc
+        ../../network_inspectors/rna/test/rna_flow_stubs.cc
         ../../sfip/sf_ip.cc
         $<TARGET_OBJECTS:catch_tests>
     LIBS
@@ -26,7 +26,7 @@ add_cpputest( host_cache_module_test
 add_cpputest( host_tracker_test
     SOURCES
         ../host_tracker.cc
-        ../../network_inspectors/rna/test/rna_flow_mock.cc
+        ../../network_inspectors/rna/test/rna_flow_stubs.cc
         ../../sfip/sf_ip.cc
 )
 
@@ -38,7 +38,7 @@ add_cpputest( host_tracker_module_test
         ../../framework/module.cc
         ../../framework/parameter.cc
         ../../framework/value.cc
-        ../../network_inspectors/rna/test/rna_flow_mock.cc
+        ../../network_inspectors/rna/test/rna_flow_stubs.cc
         ../../sfip/sf_ip.cc
         $<TARGET_OBJECTS:catch_tests>
     LIBS
@@ -48,12 +48,12 @@ add_cpputest( host_tracker_module_test
 add_cpputest( host_cache_allocator_ht_test
     SOURCES
         ../host_tracker.cc
-        ../../network_inspectors/rna/test/rna_flow_mock.cc
+        ../../network_inspectors/rna/test/rna_flow_stubs.cc
         ../../sfip/sf_ip.cc
 )
 
 add_cpputest( host_cache_allocator_test
     SOURCES
         ../host_tracker.cc
-        ../../network_inspectors/rna/test/rna_flow_mock.cc
+        ../../network_inspectors/rna/test/rna_flow_stubs.cc
 )
index 0a4e5c019e21a99684501e9bcc99e322bd97953c..3f4d92a079b0fa40b87d72eedbc6a4d343de366d 100644 (file)
@@ -130,9 +130,7 @@ bool AckModule::begin(const char*, int, SnortConfig*)
 
 bool AckModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index 31eee19275d216619a4071432fbdbe4b28f27660..b9cb456a593d9ff85abf4325b146d0975c810795 100644 (file)
@@ -241,9 +241,6 @@ bool Asn1Module::set(const char*, Value& v, SnortConfig*)
         data.offset_type = REL_OFFSET;
         data.offset = v.get_int32();
     }
-    else
-        return false;
-
     return true;
 }
 
index 7084bd4b5afc15b2fef1201183f1563579dd87fc..fc9ccdac12da37423c5acf36ef74693a34f63fde 100644 (file)
@@ -211,9 +211,6 @@ bool B64DecodeModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("relative") )
         data.flags |= BASE64DECODE_RELATIVE_FLAG;
 
-    else
-        return false;
-
     return true;
 }
 
index 2b4279981d3d9f79e4cbecd1f0b87efa9176179d..554d09ef39750efcd743b690152ee4a807993c2a 100644 (file)
@@ -142,11 +142,8 @@ bool BerDataModule::begin(const char*, int, SnortConfig*)
 
 bool BerDataModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("~type") )
-        type = v.get_uint32();
-    else
-        return false;
-
+    assert(v.is("~type"));
+    type = v.get_uint32();
     return true;
 }
 
index 772e5173aeb008d261d25803a119df5af8e3a4d5..742199badd5deb38a74d2f9546816c8bd89a5955 100644 (file)
@@ -161,9 +161,6 @@ bool BerSkipModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("optional") )
         optional = true;
 
-    else
-        return false;
-
     return true;
 }
 
index 1fa95ede0ceae2d1a82fd516721bc3b403070d9e..21ee5870d7c11ffb0bca6f1079fe38058fdc070c 100644 (file)
@@ -141,9 +141,6 @@ bool LenModule::set(const char*, Value& v, SnortConfig*)
     if ( v.is("relative") )
         relative = true;
 
-    else
-        return false;
-
     return true;
 }
 
index 7e3b1330af034c09022eeaeec65d784fe6856ac1..05a7ead42e8679c68cbeb60ae300e2ea89015091 100644 (file)
@@ -368,9 +368,6 @@ bool ExtractModule::set(const char*, Value& v, SnortConfig*)
     else if (v.is("bitmask"))
         data.bitmask_val = v.get_uint32();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -1030,20 +1027,6 @@ TEST_CASE("ExtractModule::set", "[ips_byte_extract]")
         CHECK(obj.set(nullptr, v, nullptr));
         CHECK_THAT(obj.data, ByteExtractDataEquals(expected));
     }
-    SECTION("invalid set")
-    {
-        Value v(1023.0);
-        Parameter p{
-            "error", Parameter::PT_INT, "nan", nullptr,
-            "not an option"};
-        v.set(&p);
-        ByteExtractData expected;
-        INITIALIZE(expected, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, nullptr);
-
-        CHECK(!obj.set(nullptr, v, nullptr));
-        CHECK_THAT(obj.data, ByteExtractDataEquals(expected));
-    }
-
     delete[] obj.data.name;
 }
 
index fc02f806ad39401a950c4d1afb9021dc1e44186f..e4404812773d20bf5d31da379c85e1e7a8a9f5bb 100644 (file)
@@ -483,9 +483,6 @@ bool ByteJumpModule::set(const char*, Value& v, SnortConfig*)
     else if (v.is("bitmask"))
         data.bitmask_val = v.get_uint32();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -899,11 +896,6 @@ TEST_CASE("ByteJumpModule test", "[ips_byte_jump]")
     {
         Value value(false);
 
-        SECTION("All params incorrect")
-        {
-            REQUIRE(module_jump.set(nullptr, value, nullptr) == false);
-        }
-
         SECTION("Case param \"~count\"")
         {
             Parameter param("~count", snort::Parameter::Type::PT_BOOL,
index 2a66ee2e5bcb6e47ea2a46cfb381865a7c073e1b..4869212fa21130b1eee06e5a9196166ff4dd2e0c 100644 (file)
@@ -392,9 +392,6 @@ bool ByteMathModule::set(const char*, Value& v, SnortConfig*)
     else if (v.is("result"))
         data.result_name = snort_strdup(v.get_string());
 
-    else
-        return false;
-
     return true;
 }
 
@@ -1437,18 +1434,6 @@ TEST_CASE("ByteMathModule::set invalid", "[ips_byte_math]")
     ByteMathModule obj;
     obj.begin(nullptr, 0, nullptr);
 
-    SECTION("invalid parameter")
-    {
-        Value v(1023.0);
-        Parameter p{"error", Parameter::PT_INT, "nan", nullptr,
-            "not an option"};
-        v.set(&p);
-        ByteMathData expected;
-        INITIALIZE(expected, 0, 0, 0, 0, 0, BM_PLUS, 0, 0, 0, 0, 0, 0, 0);
-
-        CHECK(!obj.set(nullptr, v, nullptr));
-        CHECK_THAT(obj.data, ByteMathDataEquals(expected));
-    }
     SECTION("rvalue = 0")
     {
         Value v("0");
index eb8be8f82b9df4e87da73ddb7734db961617153c..6bcced7aa9877e8b8092377c99252a675b863d11 100644 (file)
@@ -550,9 +550,6 @@ bool ByteTestModule::set(const char*, Value& v, SnortConfig*)
     else if (v.is("bitmask"))
         data.bitmask_val = v.get_uint32();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -972,11 +969,6 @@ TEST_CASE("ByteTestModule test", "[ips_byte_test]")
     {
         Value value(false);
 
-        SECTION("All params incorrect")
-        {
-            REQUIRE(module_test.set(nullptr, value, nullptr) == false);
-        }
-
         SECTION("Case param \"~count\"")
         {
             Parameter param("~count", snort::Parameter::Type::PT_BOOL,
index fb76cad392294b40294a22e6d675551659084b4a..3f7164be88f622c5892b572b67ece0f31fa03ddd 100644 (file)
@@ -61,9 +61,7 @@ public:
 
 bool ClassTypeModule::set(const char*, Value& v, SnortConfig* sc)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     type = get_classification(sc, v.get_string());
 
     if ( !type and sc->dump_rule_info() )
index 56017c866efbf9c0ede2cf05148d96120b7cfa6b..ff284357fbf51ee473a44430ec2d81b846834239 100644 (file)
@@ -723,9 +723,6 @@ bool ContentModule::set(const char*, Value& v, SnortConfig*)
         cd->pmd.fp_length = v.get_uint16();
         cd->pmd.set_fast_pattern();
     }
-    else
-        return false;
-
     return true;
 }
 
index 56554eaeeecf30833f79e4c48bb417e437c4f4f4..51973a0a4e5414491a3933fb1f5df80deeefbf25 100644 (file)
@@ -56,8 +56,6 @@ static THREAD_LOCAL ProfileStats cvsPerfStats;
 #define CVS_COMMAND_DELIMITER  '\n'
 #define CVS_COMMAND_SEPARATOR  ' '
 
-#define CVS_CONF_INVALID_ENTRY_STR  "invalid-entry"
-
 #define CVS_NO_ALERT  0
 #define CVS_ALERT     1
 
@@ -72,10 +70,10 @@ typedef enum _CvsTypes
     CVS_END_OF_ENUM
 } CvsTypes;
 
-typedef struct _CvsRuleOption
+struct CvsRuleOption
 {
-    CvsTypes type;
-} CvsRuleOption;
+    CvsTypes type = CVS_INVALID_ENTRY;
+};
 
 /* represents a CVS command with argument */
 typedef struct _CvsCommand
@@ -374,7 +372,7 @@ static void CvsGetEOL(const uint8_t* ptr, const uint8_t* end,
 
 static const Parameter s_params[] =
 {
-    { CVS_CONF_INVALID_ENTRY_STR, Parameter::PT_IMPLIED, nullptr, nullptr,
+    { "invalid-entry", Parameter::PT_IMPLIED, nullptr, nullptr,
       "looks for an invalid Entry string" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
@@ -388,9 +386,6 @@ class CvsModule : public Module
 public:
     CvsModule() : Module(s_name, s_help, s_params) { }
 
-    bool begin(const char*, int, SnortConfig*) override;
-    bool set(const char*, Value&, SnortConfig*) override;
-
     ProfileStats* get_profile() const override
     { return &cvsPerfStats; }
 
@@ -398,24 +393,9 @@ public:
     { return DETECT; }
 
 public:
-    CvsRuleOption data = {};
+    CvsRuleOption data;
 };
 
-bool CvsModule::begin(const char*, int, SnortConfig*)
-{
-    memset(&data, 0, sizeof(data));
-    return true;
-}
-
-bool CvsModule::set(const char*, Value& v, SnortConfig*)
-{
-    if ( !v.is(CVS_CONF_INVALID_ENTRY_STR) )
-        return false;
-
-    data.type = CVS_INVALID_ENTRY;
-    return true;
-}
-
 //-------------------------------------------------------------------------
 // api methods
 //-------------------------------------------------------------------------
index 346198b9e2e0b3c5a88987577a4c04912f1d49bb..17a857453faa87e895499c3f4e0e7c290e580ee8 100644 (file)
@@ -91,9 +91,6 @@ bool DetectionFilterModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("seconds") )
         thdx.seconds = v.get_uint32();
 
-    else
-        return false;
-
     return true;
 }
 
index db82530eed997c4b54ebfafd654e0a219671cbcd..2c59e3def4041ced8becec5a99b1786af17ebd72 100644 (file)
@@ -136,9 +136,7 @@ bool DsizeModule::begin(const char*, int, SnortConfig*)
 
 bool DsizeModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index 25a4afa4071e2a6f1cf498a0f0d7186323ad4b14..062d753a0b6d054aa65cabceb83283d5ad87c902 100644 (file)
@@ -72,9 +72,7 @@ bool EnableModule::begin(const char*, int, SnortConfig* sc)
 
 bool EnableModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~enable") )
-        return false;
-
+    assert(v.is("~enable"));
     enable = IpsPolicy::Enable(v.get_uint8());
     return true;
 }
index a0f2507596bc0e51512d77df6c0bd1ae8d8e27de..49a996066e24d22d5449fa02b745dece784531f4 100644 (file)
@@ -148,9 +148,7 @@ bool FileTypeModule::begin(const char*, int, SnortConfig*)
 
 bool FileTypeModule::set(const char*, Value& v, SnortConfig* sc)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     v.set_first_token();
     std::string tok;
 
index 84faf28d33ae161341b14cfbd497aae7a3c23105..9f4e2998c480634b1e769122d3aa29c99154ce81 100644 (file)
@@ -371,9 +371,6 @@ bool FlagsModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("~mask_flags") )
         flags_parse_mask(v.get_string(), &data);
 
-    else
-        return false;
-
     return true;
 }
 
index fb10c97045baaedb5abbe2865f4293e7454d4fbf..6408418acbe54767f2c57cf119c91795e212741d 100644 (file)
@@ -358,9 +358,6 @@ bool FlowModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("only_frag") )
         data.only_reassembled |= ONLY_FRAG;
 
-    else
-        return false;
-
     return true;
 }
 
index af40bb4c77fc91da33c880caf62bccdb1e2ea267..e1d95a48b53777f7589aa7d9f9e8aa5f0f24c992 100644 (file)
@@ -487,9 +487,6 @@ bool FlowbitsModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("~bits") )
         bits = v.get_string();
 
-    else
-        return false;
-
     return true;
 }
 
index d5678bfca5f62ef7952094d9fb144b8fda649ed5..42ee6eb041f47dbe28a86c64627344ad0179743d 100644 (file)
@@ -380,11 +380,8 @@ bool FragBitsModule::begin(const char*, int, SnortConfig*)
 // which is the string of command line arguments
 bool FragBitsModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("~flags") )
-        fragBitsData.parse_fragbits(v.get_string());
-    else
-        return false;
-
+    assert(v.is("~flags"));
+    fragBitsData.parse_fragbits(v.get_string());
     return true;
 }
 
index 2df0c681e7d875b096744ef60e466a972652e72b..fbae6b56fae5b42903c84fdd541030b6d04dfc7a 100644 (file)
@@ -133,9 +133,7 @@ bool FragOffsetModule::begin(const char*, int, SnortConfig*)
 
 bool FragOffsetModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index 56565346ae802d469ab59ddb42bbafe11cb25108..8b98de5853afa64083c5bdd0e223eceee003dd3e 100644 (file)
@@ -60,9 +60,7 @@ public:
 
 bool GidModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     gid = v.get_uint32();
     return true;
 }
index 7e47ff6c584399799213764b4a04a07b914efe3e..214a5ad45afe36fae5a885cc2e84e37af102c6c6 100644 (file)
@@ -337,9 +337,6 @@ bool HashModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("length") )
         hmd->length = v.get_uint16();
 
-    else
-        return false;
-
     return true;
 }
 
index acacc8c5a315cc2f50ef392af48afe7f8e8c46e4..12f9d22bbf7330fcb6e74ca6a831afb640ec8369 100644 (file)
@@ -162,9 +162,7 @@ bool IcmpIdModule::begin(const char*, int, SnortConfig*)
 
 bool IcmpIdModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index da6e9584eb3473578900000f74cf9c25ab64c8e0..147cbc2dabec6b48e30fb865af280e38b7f861bf 100644 (file)
@@ -163,9 +163,7 @@ bool IcmpSeqModule::begin(const char*, int, SnortConfig*)
 
 bool IcmpSeqModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index c6c8d93554811b2f76a44c69ba5bea355f94cd98..947cab3212018ba9898ee8bea51f2808fdbb952c 100644 (file)
@@ -134,9 +134,7 @@ bool IcodeModule::begin(const char*, int, SnortConfig*)
 
 bool IcodeModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index b63fb7b4481ce3030eef2a99c8854a2df994afe3..b59cfd52ce34e2ab66aeaed71299ef3bc454e8b2 100644 (file)
@@ -132,9 +132,7 @@ bool IpIdModule::begin(const char*, int, SnortConfig*)
 
 bool IpIdModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index ab3ae6a8701aa162e42bdbc83ecbca530db2c48f..5fe150eadc8045fd2727a06a89f54cbdce7eadb8 100644 (file)
@@ -247,12 +247,8 @@ bool IpProtoModule::begin(const char*, int, SnortConfig*)
 
 bool IpProtoModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("~proto") )
-        ip_proto_parse(v.get_string(), &data);
-
-    else
-        return false;
-
+    assert(v.is("~proto"));
+    ip_proto_parse(v.get_string(), &data);
     return true;
 }
 
index f98594c9dedba4f44b8a88cf4fea4514073300bf..d05015ce9eba81a248353bdc5387d3f2c64ab8de 100644 (file)
@@ -220,12 +220,8 @@ bool IpOptModule::begin(const char*, int, SnortConfig*)
 
 bool IpOptModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("~opt") )
-        ipopts_parse(v.get_string(), &data);
-
-    else
-        return false;
-
+    assert(v.is("~opt"));
+    ipopts_parse(v.get_string(), &data);
     return true;
 }
 
index a6ad8f58f05749714ae33bae036b01bd8c908e46..0c5c572ecef4d781ce54e14e25987f4d06df8a8f 100644 (file)
@@ -260,9 +260,6 @@ bool IsDataAtModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("relative") )
         data.flags |= ISDATAAT_RELATIVE_FLAG;
 
-    else
-        return false;
-
     return true;
 }
 
index 0d81a1237bc09514e0347372d41a76a2caef1c2e..89b7040ce05d6afdc6236a9da47b8b0297162d9a 100644 (file)
@@ -134,9 +134,7 @@ bool ItypeModule::begin(const char*, int, SnortConfig*)
 
 bool ItypeModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index 714418bdb562f348915b9341a429d0a3c6cd4552..68fab67f98362278ae556fac26389c6af17b71a5 100644 (file)
@@ -69,8 +69,7 @@ bool MetadataModule::begin(const char*, int, SnortConfig*)
 
 bool MetadataModule::set(const char*, Value& v, SnortConfig* sc)
 {
-    if ( !v.is("*") )
-        return false;
+    assert(v.is("*"));
 
     if ( !match and !sc->metadata_filter.empty() )
         match = strstr(v.get_string(), sc->metadata_filter.c_str()) != nullptr;
index 6f23f93658aee464af2a638fbe0116ac00570111..7164ea7eda8187864c3fcc5d1c587a9b0e83ce3f 100644 (file)
@@ -61,9 +61,7 @@ public:
 
 bool MsgModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     msg = v.get_string();
     return true;
 }
index b51f0540aa679449deb3379e4bce4ec5c6534dc7..4b4465b7e25b06fe178660e825232fe50c6f51fa 100644 (file)
@@ -716,15 +716,11 @@ bool PcreModule::begin(const char* name, int v, SnortConfig* sc)
 
 bool PcreModule::set(const char* name, Value& v, SnortConfig* sc)
 {
-    if ( v.is("~re") )
-    {
-        re = v.get_string();
+    assert(v.is("~re"));
+    re = v.get_string();
 
-        if( mod_regex )
-            mod_regex = mod_regex->set(name, v, sc) ? mod_regex : nullptr;
-    }
-    else
-        return false;
+    if( mod_regex )
+        mod_regex = mod_regex->set(name, v, sc) ? mod_regex : nullptr;
 
     return true;
 }
index dd36434c8e61d866f83a13f169d683287d3bf6aa..894a924ac95cdbf316eeb9d8dfb0fd1d11fc0d5d 100644 (file)
@@ -60,9 +60,7 @@ public:
 
 bool PriorityModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     priority = v.get_int32();
     return true;
 }
index f519ee6106c454a63efa74f14f92b3834576db53..c842cff37d20d7e5b48c17984de3d3d03f3315ea 100644 (file)
@@ -72,8 +72,7 @@ bool ReferenceModule::begin(const char*, int, SnortConfig* sc)
 
 bool ReferenceModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~ref") )
-        return false;
+    assert(v.is("~ref"));
 
     const char* ref = v.get_string();
     const char* sep = strchr(ref, ',');
index a97188e7d47b125c8fda6558b1e27acf11ca4bbf..d0492b7a91a2b140b0cd4bbfe9d125a201d8e7f2 100644 (file)
@@ -366,15 +366,11 @@ bool RegexModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("fast_pattern") )
         config.pmd.set_fast_pattern();
 
-
     else if ( v.is("nocase") )
     {
         config.pmd.mpse_flags |= HS_FLAG_CASELESS;
         config.pmd.set_no_case();
     }
-    else
-        return false;
-
     return true;
 }
 
index 7fdcab1c84d1ff93227655191ae62c215c220600..92cc8b901e6cb071b7a34572464c48eb644fc287 100644 (file)
@@ -48,20 +48,11 @@ class RemModule : public Module
 {
 public:
     RemModule() : Module(s_name, s_help, s_params) { }
-    bool set(const char*, Value&, SnortConfig*) override;
 
     Usage get_usage() const override
     { return DETECT; }
 };
 
-bool RemModule::set(const char*, Value& v, SnortConfig*)
-{
-    if ( !v.is("~") )
-        return false;
-
-    return true;
-}
-
 //-------------------------------------------------------------------------
 // api methods
 //-------------------------------------------------------------------------
index fd7645029582da28621d64d4f58de2e0eff8fa3a..5f56cd8e2527ffd65cf7a3bcc8cb0d85b8b19e97 100644 (file)
@@ -216,12 +216,8 @@ bool ReplModule::begin(const char*, int, SnortConfig*)
 
 bool ReplModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("~") )
-        replace_parse(v.get_string(), data);
-
-    else
-        return false;
-
+    assert(v.is("~"));
+    replace_parse(v.get_string(), data);
     return true;
 }
 
index c0cb8eb9f71635075024c7ee946789c9f2540d1c..47f205308cc72bf6e71f823ada6817689940dea6 100644 (file)
@@ -60,9 +60,7 @@ public:
 
 bool RevModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     rev = v.get_uint32();
     return true;
 }
index 829afcca32bbeb88f77e369daf93351cec897699..7e66eed5ccc0606725c336d25ebcdf57da6580f1 100644 (file)
@@ -275,9 +275,6 @@ bool RpcModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("~proc") )
         return set(v, data.procedure, RPC_CHECK_PROCEDURE);
 
-    else
-        return false;
-
     return true;
 }
 
index f6c81bcb7453cb230173e41d497b02fd17fc0709..544e2d03404cb338289547d0fc38ba380d0e4fc3 100644 (file)
@@ -326,6 +326,12 @@ private:
 
 bool SdPatternModule::begin(const char*, int, SnortConfig*)
 {
+    if ( hs_valid_platform() != HS_SUCCESS )
+    {
+        ParseError("This host does not support Hyperscan.");
+        return false;
+    }
+
     config = SdPatternConfig();
     return true;
 }
@@ -341,11 +347,14 @@ bool SdPatternModule::set(const char*, Value& v, SnortConfig*)
     }
     else if ( v.is("threshold") )
         config.threshold = v.get_uint32();
-    else
-        return false;
 
-    // Check if built-in pattern should be used.
+    return true;
+}
+
+bool SdPatternModule::end(const char*, int, SnortConfig*)
+{
     IpsPolicy* p = get_ips_policy();
+
     if (config.pii == "credit_card")
     {
         config.pii = SD_CREDIT_PATTERN_ALL;
@@ -366,17 +375,6 @@ bool SdPatternModule::set(const char*, Value& v, SnortConfig*)
         config.forced_boundary = true;
     }
 
-    return true;
-}
-
-bool SdPatternModule::end(const char*, int, SnortConfig*)
-{
-    if ( hs_valid_platform() != HS_SUCCESS )
-    {
-        ParseError("This host does not support Hyperscan.");
-        return false;
-    }
-
     hs_compile_error_t* err = nullptr;
 
     if ( hs_compile(config.pii.c_str(), HS_FLAG_DOTALL|HS_FLAG_SOM_LEFTMOST, HS_MODE_BLOCK,
index 0c0f22199bedd0dacaea9860e88b4d3ee848bf00..9376aa9813a705ef15a734b020dbe40a5c73df00 100644 (file)
@@ -133,9 +133,7 @@ bool SeqModule::begin(const char*, int, SnortConfig*)
 
 bool SeqModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index 512e59a81e126d082b4c957fe0a60c496e012e4d..446bb5de36955d66c507208a444e1b054da24f47 100644 (file)
@@ -73,9 +73,7 @@ bool ServiceModule::begin(const char*, int, SnortConfig* sc)
 
 bool ServiceModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("*") )
-        return false;
-
+    assert(v.is("*"));
     std::string svc = v.get_string();
 
     for ( const auto& p : services )
@@ -87,7 +85,6 @@ bool ServiceModule::set(const char*, Value& v, SnortConfig*)
         }
     }
     services.emplace_back(svc);
-
     return true;
 }
 
index 4925288449447e38eb314c2527d6b539df1fa3c8..3c35dd39d3fcb8851ed4c4d3b4976bb1fc526c92 100644 (file)
@@ -60,9 +60,7 @@ public:
 
 bool SidModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     sid = v.get_uint32();
     return true;
 }
index 8ce631bdb9c9a1906483de996c0ae91af5761b96..ddc00226190ee8797d7197901a4c6cc0ab4a3a26 100644 (file)
@@ -166,9 +166,6 @@ bool SoModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("relative") )
         relative_flag = true;
 
-    else
-        return false;
-
     return true;
 }
 
index 81360277a31d024e93c7bec886628041bb7dc65d..4b19024ceea2fc581bb08824e04f80a784769e92 100644 (file)
@@ -61,9 +61,7 @@ public:
 
 bool SoidModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     soid = v.get_string();
     return true;
 }
index 84f2c07b2edf480d9987f2a7fbc71b03441beb27..e96ac30551e3a071d8421ae3f952e62dfc2cd5a9 100644 (file)
@@ -137,9 +137,6 @@ bool TagModule::set(const char*, Value& v, SnortConfig*)
         tag->tag_metric |= TAG_METRIC_BYTES;
         tag->tag_bytes = v.get_uint32();
     }
-    else
-        return false;
-
     return true;
 }
 
index 7eede1e34ddd7fa224c19ee6813d4a3f57d762dd..18a294344edffb611cf3607741d39804ddf65dee 100644 (file)
@@ -60,12 +60,9 @@ public:
 
 bool TargetModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     assert(v.get_uint8() <= TARGET_MAX);
     target = static_cast<Target>(v.get_uint8() + 1);
-
     return true;
 }
 
index 7886942a222b3a9c18fce927920becaf5439c9cf..c8a7d6d7a93a71f2ad614360baa7abd42a449f8a 100644 (file)
@@ -136,9 +136,7 @@ bool TosModule::begin(const char*, int, SnortConfig*)
 
 bool TosModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index b8e21e1a5c90bfc56b567d36556abb315c115b9f..2f1fddf5fb14988ab75173845a26c8d87cd7a7ba 100644 (file)
@@ -134,9 +134,7 @@ bool TtlModule::begin(const char*, int, SnortConfig*)
 
 bool TtlModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index 6305bf06a25b14f17325549eb9e6810de2539ff1..b5c784fd76230783c5dccf63f3ebc9fd54776ffe 100644 (file)
@@ -1,4 +1,3 @@
-
 //--------------------------------------------------------------------------
 // Copyright (C) 2021 Cisco and/or its affiliates. All rights reserved.
 //
 //--------------------------------------------------------------------------
 // ips_vba_data.cc author Amarnath Nayak <amarnaya@cisco.com>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "ips_vba_data.h"
 
 #include "framework/module.h"
index 534899b7f6ce3e0dc41236f4707433b45a0e5723..d75acaaec93b13bb7cb952d08dccebcef219a118 100644 (file)
 //--------------------------------------------------------------------------
 // ips_vba_data.h author Amarnath Nayak <amarnaya@cisco.com>
 
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 #include "detection/detection_engine.h"
 #include "framework/cursor.h"
 #include "framework/ips_option.h"
index 3726e440aece6bc840348d1439c4ea7f9c0dfa55..0c57d8132a3696c6e45792426695fc274c9eaf99 100644 (file)
@@ -133,9 +133,7 @@ bool WindowModule::begin(const char*, int, SnortConfig*)
 
 bool WindowModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return data.validate(v.get_string(), RANGE);
 }
 
index d782c6ed1586878c94c4274d3f73caf562aa1e78..8f901883e28e0585247de95151b564b43adacdae 100644 (file)
@@ -232,16 +232,6 @@ TEST(ips_regex_module, config_pass)
     CHECK(mod->set(ips_regex->name, vb, nullptr));
 }
 
-TEST(ips_regex_module, config_fail_name)
-{
-    Value vs("lazy");
-    Parameter bad { "bad", Parameter::PT_STRING, nullptr, nullptr, "bad" };
-    vs.set(&bad);
-    CHECK(!mod->set(ips_regex->name, vs, nullptr));
-    expect = 1;
-    end = false;
-}
-
 TEST(ips_regex_module, config_fail_regex)
 {
     Value vs("\"/[[:fubar:]]/\"");
index 9090e6ebaea0f7bcc89f3368af576401a879fd28..f06ed096614888242a15be85813b652d7be925c3 100644 (file)
@@ -1,7 +1,6 @@
 
 set (LOGGER_SOURCES
     alert_luajit.cc
-    alert_sf_socket.cc
     log_codecs.cc
     loggers.cc
     loggers.h
index 6ac046a7b35a57bae37d24e6fdc9e8b3af021811..87dfe53ab196aeb3d7c1f28b806a1c559b352d65 100644 (file)
@@ -563,9 +563,6 @@ bool CsvModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("separator") )
         sep = v.get_string();
 
-    else
-        return false;
-
     return true;
 }
 
index 136807f8eb1ced5392c70337fe2e23310163daf9..b0f62b5e211faa1fe1fdcd9d03fbdd7e9bc36210 100644 (file)
@@ -120,9 +120,6 @@ bool FastModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("limit") )
         limit = v.get_size() * 1024 * 1024;
 
-    else
-        return false;
-
     return true;
 }
 
index 22018b17874ec896317c3f1363aa8928bc4a9cb1..8e63f4aff16f97b152b76de9577dc90e578b4e5d 100644 (file)
@@ -100,9 +100,6 @@ bool FullModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("limit") )
         limit = v.get_size() * 1024 * 1024;
 
-    else
-        return false;
-
     return true;
 }
 
index 283a2e581e9a204b167471f76f786c6936c1da3b..3c3596758cd5e25256f629fcb34eb201b6e0fc3b 100644 (file)
@@ -758,9 +758,6 @@ bool JsonModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("separator") )
         sep = v.get_string();
 
-    else
-        return false;
-
     return true;
 }
 
diff --git a/src/loggers/alert_sf_socket.cc b/src/loggers/alert_sf_socket.cc
deleted file mode 100644 (file)
index 5151a33..0000000
+++ /dev/null
@@ -1,419 +0,0 @@
-//--------------------------------------------------------------------------
-// Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2003-2013 Sourcefire, Inc.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License Version 2 as published
-// by the Free Software Foundation.  You may not use, modify or distribute
-// this program under any other version of the GNU General Public License.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-//--------------------------------------------------------------------------
-
-/* We use some Linux only socket capabilities */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#include "detection/treenodes.h"
-#include "events/event.h"
-#include "framework/logger.h"
-#include "framework/module.h"
-#include "hash/ghash.h"
-#include "log/messages.h"
-#include "main/snort_config.h"
-#include "managers/event_manager.h"
-#include "parser/parser.h"
-#include "protocols/packet.h"
-#include "target_based/snort_protocols.h"
-#include "utils/util.h"
-#include "utils/util_cstring.h"
-
-using namespace snort;
-using namespace std;
-
-struct SfSock
-{
-    int connected;
-    int sock;
-    struct sockaddr_un addr;
-};
-
-struct RuleId
-{
-    unsigned gid;
-    unsigned sid;
-};
-
-static THREAD_LOCAL SfSock context;
-
-typedef vector<RuleId> RuleVector;
-
-#define s_name "alert_sfsocket"
-
-//-------------------------------------------------------------------------
-// alert_sfsocket module
-//-------------------------------------------------------------------------
-
-static const Parameter rule_params[] =
-{
-    { "gid", Parameter::PT_INT, "1:max32", "1",
-      "rule generator ID" },
-
-    { "sid", Parameter::PT_INT, "1:max32", "1",
-      "rule signature ID" },
-
-    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
-};
-
-static const Parameter s_params[] =
-{
-    { "file", Parameter::PT_STRING, nullptr, nullptr,
-      "name of unix socket file" },
-
-    { "rules", Parameter::PT_LIST, rule_params, nullptr,
-      "name of unix socket file" },
-
-    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
-};
-
-#define s_help \
-    "output event over socket"
-
-class SfSocketModule : public Module
-{
-public:
-    SfSocketModule() : Module(s_name, s_help, s_params) { }
-
-    bool set(const char*, Value&, SnortConfig*) override;
-    bool begin(const char*, int, SnortConfig*) override;
-    bool end(const char*, int, SnortConfig*) override;
-
-    Usage get_usage() const override
-    { return GLOBAL; }
-
-public:
-    string file;
-    RuleVector rulez;
-    RuleId rule = {};
-};
-
-bool SfSocketModule::set(const char*, Value& v, SnortConfig*)
-{
-    if ( v.is("file") )
-        file = v.get_string();
-
-    else if ( v.is("gid") )
-        rule.gid = v.get_uint32();
-
-    else if ( v.is("sid") )
-        rule.sid = v.get_uint32();
-
-    return true;
-}
-
-bool SfSocketModule::begin(const char*, int, SnortConfig*)
-{
-    file.erase();
-    rule.gid = rule.sid = 1;
-    return true;
-}
-
-bool SfSocketModule::end(const char* fqn, int, SnortConfig*)
-{
-    if ( !strcmp(fqn, "alert_sfsocket.rules") )
-        rulez.emplace_back(rule);
-
-    return true;
-}
-
-//-------------------------------------------------------------------------
-// socket stuff
-
-static int AlertSFSocket_Connect()
-{
-    /* check sock value */
-    if (context.sock == -1)
-        FatalError("AlertSFSocket: Invalid socket\n");
-
-    if (connect(context.sock, (sockaddr*)&context.addr, sizeof(context.addr)) == -1)
-    {
-        if (errno == ECONNREFUSED || errno == ENOENT)
-        {
-            LogMessage("WARNING: AlertSFSocket: Unable to connect to socket: "
-                "%s.\n", get_error(errno));
-            return 1;
-        }
-        else
-        {
-            FatalError("AlertSFSocket: Unable to connect to socket "
-                "(%i): %s\n", errno, get_error(errno));
-        }
-    }
-    return 0;
-}
-
-static void sock_init(const char* args)
-{
-    if ( (context.sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0 )
-        FatalError("Unable to create socket: %s\n", get_error(errno));
-
-    std::string name;
-    get_instance_file(name, args);
-
-    memset(&context.addr, 0, sizeof(context.addr));
-    context.addr.sun_family = AF_UNIX;
-    SnortStrncpy(context.addr.sun_path, name.c_str(), sizeof(context.addr.sun_path));
-
-    if (AlertSFSocket_Connect() == 0)
-        context.connected = 1;
-}
-
-static void send_sar(uint8_t* data, unsigned len)
-{
-    int tries = 0;
-
-    do
-    {
-        tries++;
-        /* connect as needed */
-        if (!context.connected)
-        {
-            if (AlertSFSocket_Connect() != 0)
-                break;
-            context.connected = 1;
-        }
-
-        /* send request */
-        if (send(context.sock, data, len, 0) == len)
-        {
-            /* success */
-            return;
-        }
-        /* send failed */
-        if (errno == ENOBUFS)
-        {
-            LogMessage("ERROR: AlertSFSocket: out of buffer space\n");
-            break;
-        }
-        else if (errno == ECONNRESET)
-        {
-            context.connected = 0;
-            LogMessage("WARNING: AlertSFSocket: connection reset, will attempt "
-                "to reconnect.\n");
-        }
-        else if (errno == ECONNREFUSED)
-        {
-            LogMessage("WARNING: AlertSFSocket: connection refused, "
-                "will attempt to reconnect.\n");
-            context.connected = 0;
-        }
-        else if (errno == ENOTCONN)
-        {
-            LogMessage("WARNING: AlertSFSocket: not connected, "
-                "will attempt to reconnect.\n");
-            context.connected = 0;
-        }
-        else
-        {
-            LogMessage("ERROR: AlertSFSocket: unhandled error '%i' in send(): "
-                "%s\n", errno, get_error(errno));
-            context.connected = 0;
-        }
-    }
-    while (tries <= 1);
-    LogMessage("ERROR: AlertSFSocket: Alert not sent\n");
-}
-
-//-------------------------------------------------------------------------
-// sig stuff
-
-/* search for an OptTreeNode by sid in specific policy*/
-// FIXIT-L wow - OptTreeNode_Search should be encapsulated somewhere ...
-// (actually, the whole reason for doing this needs to be rethought)
-static OptTreeNode* OptTreeNode_Search(uint32_t, uint32_t sid)
-{
-    GHashNode* hashNode;
-
-    if (sid == 0)
-        return nullptr;
-
-    const SnortConfig* sc = SnortConfig::get_conf();
-
-    for (hashNode = sc->otn_map->find_first();
-        hashNode;
-        hashNode = sc->otn_map->find_next())
-    {
-        OptTreeNode* otn = (OptTreeNode*)hashNode->data;
-        RuleTreeNode* rtn = getRuntimeRtnFromOtn(otn);
-
-        if ( rtn and is_network_protocol(rtn->snort_protocol_id) )
-        {
-            if (otn->sigInfo.sid == sid)
-                return otn;
-        }
-    }
-
-    return nullptr;
-}
-
-//-------------------------------------------------------------------------
-// sar stuff
-
-struct SnortActionRequest
-{
-    uint32_t event_id;
-    uint32_t tv_sec;
-    uint32_t gid;
-    uint32_t sid;
-    uint32_t src_ip;
-    uint32_t dest_ip;
-    uint16_t sport;
-    uint16_t dport;
-    IpProtocol ip_proto;
-};
-
-static void load_sar(Packet* packet, const Event& event, SnortActionRequest& sar)
-{
-    if ( !packet || !packet->ptrs.ip_api.is_ip() )
-        return;
-
-    // for now, only support ip4
-    if ( !packet->ptrs.ip_api.is_ip4() )
-        return;
-
-    /* construct the action request */
-    sar.event_id = event.get_event_id();
-    sar.tv_sec = packet->pkth->ts.tv_sec;
-    sar.gid = event.sig_info->gid;
-    sar.sid = event.sig_info->sid;
-
-    // when ip6 is supported:
-    // * suggest TLV format where T == family, L is implied by
-    //   T (and not sent), and V is just the address octets in
-    //   network order
-    // * if T is made the 1st octet of struct, bytes to read
-    //   can be determined by reading 1 byte
-    // * addresses could be moved to end of struct in uint8_t[32]
-    //   and only 1st 8 used for ip4
-    sar.src_ip =  ntohl(packet->ptrs.ip_api.get_src()->get_ip4_value());
-    sar.dest_ip = ntohl(packet->ptrs.ip_api.get_dst()->get_ip4_value());
-    sar.ip_proto = packet->get_ip_proto_next();
-
-    if (packet->is_tcp() || packet->is_udp())
-    {
-        sar.sport = packet->ptrs.sp;
-        sar.dport = packet->ptrs.dp;
-    }
-    else
-    {
-        sar.sport = 0;
-        sar.dport = 0;
-    }
-}
-
-//-------------------------------------------------------------------------
-
-class SfSocketLogger : public Logger
-{
-public:
-    SfSocketLogger(SfSocketModule*);
-
-    void configure(RuleId&);
-
-    void open() override;
-    void close() override;
-
-    void alert(Packet*, const char* msg, const Event&) override;
-
-private:
-    string file;
-};
-
-SfSocketLogger::SfSocketLogger(SfSocketModule* m)
-{
-    file = m->file;
-
-    for ( auto r : m->rulez )
-        configure(r);
-}
-
-void SfSocketLogger::configure(RuleId& r)
-{
-    OptTreeNode* otn = OptTreeNode_Search(r.gid, r.sid);
-
-    if ( !otn )
-        ParseError("Unable to find OptTreeNode for %u:%u", r.gid, r.sid);
-
-    else
-        EventManager::add_output(&otn->outputFuncs, this);
-}
-
-void SfSocketLogger::open()
-{
-    sock_init(file.c_str());
-}
-
-void SfSocketLogger::close()
-{
-    ::close(context.sock);
-    context.sock = -1;
-}
-
-void SfSocketLogger::alert(Packet* packet, const char*, const Event& event)
-{
-    SnortActionRequest sar;
-    load_sar(packet, event, sar);
-    send_sar((uint8_t*)&sar, sizeof(sar));
-}
-
-//-------------------------------------------------------------------------
-
-static Module* mod_ctor()
-{ return new SfSocketModule; }
-
-static void mod_dtor(Module* m)
-{ delete m; }
-
-static Logger* sf_sock_ctor(Module* mod)
-{ return new SfSocketLogger((SfSocketModule*)mod); }
-
-static void sf_sock_dtor(Logger* p)
-{ delete p; }
-
-static LogApi sf_sock_api
-{
-    {
-        PT_LOGGER,
-        sizeof(LogApi),
-        LOGAPI_VERSION,
-        0,
-        API_RESERVED,
-        API_OPTIONS,
-        s_name,
-        s_help,
-        mod_ctor,
-        mod_dtor
-    },
-    OUTPUT_TYPE_FLAG__NONE,
-    sf_sock_ctor,
-    sf_sock_dtor
-};
-
-const BaseApi* alert_sf_socket[] =
-{
-    &sf_sock_api.base,
-    nullptr
-};
-
index aa2a06462ae2559516c6a61e8473f45b2ed34a06..3dcfbb3013f49e746127a17ae3748c4882cdcd4c 100644 (file)
@@ -171,9 +171,6 @@ bool SyslogModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("options") )
         options = get_options(v.get_string());
 
-    else
-        return false;
-
     return true;
 }
 
index 2a169498378d42bdb33b1b430e5c7e3901c03fb4..e2dd6d2574302c027a8580a7f5fc9368390481e8 100644 (file)
@@ -88,9 +88,6 @@ bool LogCodecModule::set(const char*, Value& v, SnortConfig*)
         if ( v.get_bool() )
             flags |= ALERT_FLAG_MSG;
     }
-    else
-        return false;
-
     return true;
 }
 
index 3d76cecb06e402e8b616ede3ce40932d16240582..4df68f6f84defce8d9ed191fb47e383be5179de2 100644 (file)
@@ -238,9 +238,6 @@ bool HextModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("width") )
         width = v.get_uint32();
 
-    else
-        return false;
-
     return true;
 }
 
index 70557f39ef02e7ac14711262107cdff2fac232cd..65676bd8e4ee6afa364951a53bcc0609fc2654e0 100644 (file)
@@ -102,12 +102,8 @@ public:
 
 bool TcpdumpModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("limit") )
-        limit = v.get_size() * 1024 * 1024;
-
-    else
-        return false;
-
+    assert(v.is("limit"));
+    limit = v.get_size() * 1024 * 1024;
     return true;
 }
 
index 461c6c139e2fd1c0b76980622820d2280f8dcea9..07bd431c4af8174b10a9170d5f665edd045ab6fd 100644 (file)
@@ -30,8 +30,6 @@ using namespace snort;
 // to ensure PacketManager::log_protocols() is built into Snort++
 extern const BaseApi* log_codecs[];
 
-extern const BaseApi* alert_sf_socket[];
-
 #ifdef STATIC_LOGGERS
 extern const BaseApi* alert_csv[];
 extern const BaseApi* alert_fast[];
@@ -49,7 +47,6 @@ void load_loggers()
 {
     // loggers
     PluginManager::load_plugins(log_codecs);
-    PluginManager::load_plugins(alert_sf_socket);
 
 #ifdef STATIC_LOGGERS
     // alerters
index 490813363ef3ce9161490d975dd2dcbdad094797..030bfc579171532ce689d19e5c8e8803f7cfb55e 100644 (file)
@@ -344,31 +344,14 @@ static void _Unified2LogPacketAlert(
     logheader.sensor_id = 0;
     logheader.linktype = u2.base_proto;
 
-    if (event != nullptr)
-    {
-        logheader.event_id = htonl(event->get_event_reference());
-        logheader.event_second = htonl(event->ref_time.tv_sec);
-    }
-    else
-    {
-        logheader.event_id = 0;
-        logheader.event_second = 0;
-    }
+    logheader.event_id = htonl(event->get_event_reference());
+    logheader.event_second = htonl(event->ref_time.tv_sec);
 
-    if ( p and p->pkth )
-    {
-        logheader.packet_second = htonl((uint32_t)p->pkth->ts.tv_sec);
-        logheader.packet_microsecond = htonl((uint32_t)p->pkth->ts.tv_usec);
-        pkt_length = ( p->is_rebuilt() ) ? p->dsize : p->pktlen;
-        logheader.packet_length = htonl(pkt_length + u2h_len);
-        write_len += pkt_length + u2h_len;
-    }
-    else
-    {
-        logheader.packet_second = 0;
-        logheader.packet_microsecond = 0;
-        logheader.packet_length = 0;
-    }
+    logheader.packet_second = htonl((uint32_t)p->pkth->ts.tv_sec);
+    logheader.packet_microsecond = htonl((uint32_t)p->pkth->ts.tv_usec);
+    pkt_length = ( p->is_rebuilt() ) ? p->dsize : p->pktlen;
+    logheader.packet_length = htonl(pkt_length + u2h_len);
+    write_len += pkt_length + u2h_len;
 
     if ( config->limit && (u2.current + write_len) > config->limit )
         Unified2RotateFile(config);
@@ -832,9 +815,6 @@ bool U2Module::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("legacy_events") )
         legacy_events = v.get_bool();
 
-    else
-        return false;
-
     return true;
 }
 
index a2c5ae62ecf912375ced16b4b09da92ec6596a5c..b26b4acc3d58ac1a9d74e9c35b7ceb7519bc0313 100644 (file)
@@ -1,15 +1,22 @@
 
+if ( ENABLE_PIGLET )
+    set(PIGLET_FILES
+        lua_arg.h
+        lua_iface.h
+        lua_ref.cc
+        lua_ref.h
+        lua_table.h
+        lua_util.cc
+        lua_util.h
+    )
+endif ()
+
 add_library (lua OBJECT
     lua.cc
     lua.h
-    lua_ref.cc
-    lua_ref.h
-    lua_iface.h
-    lua_util.cc
-    lua_util.h
-    lua_table.h
+    lua_script.h
     lua_stack.h
-    lua_arg.h
+    ${PIGLET_FILES}
 )
 
 target_include_directories(lua PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/src/lua/lua_script.h b/src/lua/lua_script.h
new file mode 100644 (file)
index 0000000..06ee6a5
--- /dev/null
@@ -0,0 +1,40 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2015-2021 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation.  You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//--------------------------------------------------------------------------
+// lua_script.h author Joel Cornett <jocornet@cisco.com>
+
+#ifndef LUA_SCRIPT_H
+#define LUA_SCRIPT_H
+
+#include <string>
+
+#include <lua.hpp>
+
+#define LUA_DIR_SEP '/'
+#define SCRIPT_DIR_VARNAME "SCRIPT_DIR"
+
+namespace Lua
+{
+inline void set_script_dir(
+    lua_State* L, const std::string& varname, const std::string& path)
+{
+    std::string dir = path.substr(0, path.rfind(LUA_DIR_SEP));
+    lua_pushlstring(L, dir.c_str(), dir.size());
+    lua_setglobal(L, varname.c_str());
+}
+}
+#endif
index 050c7d95e7863b1628e790d61f27cd047a66975d..e89ca2657c9d20d2468808d28d155158012558a6 100644 (file)
 #ifndef LUA_UTIL_H
 #define LUA_UTIL_H
 
-#include <string>
-
 #include <lua.hpp>
 
-#define LUA_DIR_SEP '/'
-#define SCRIPT_DIR_VARNAME "SCRIPT_DIR"
-
 namespace Lua
 {
 const char* fmt_expected_message(const char* type);
 const char* fmt_range_message(unsigned min, unsigned max);
-
-inline void set_script_dir(
-    lua_State* L, const std::string& varname, const std::string& path)
-{
-    std::string dir = path.substr(0, path.rfind(LUA_DIR_SEP));
-    lua_pushlstring(L, dir.c_str(), dir.size());
-    lua_setglobal(L, varname.c_str());
-}
 }
 #endif
index f0b1b9a6b041d9be5e32cf94c04976d1fdce7b7f..cd5b9f0390566ec7324eee4d080a23e1db16683e 100644 (file)
@@ -100,6 +100,7 @@ class EventQueueModule : public Module
 public:
     EventQueueModule() : Module("event_queue", event_queue_help, event_queue_params) { }
     bool set(const char*, Value&, SnortConfig*) override;
+    bool end(const char*, int, SnortConfig*) override;
 
     Usage get_usage() const override
     { return CONTEXT; }
@@ -125,8 +126,12 @@ bool EventQueueModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("process_all_events") )
         eq->process_all_events = v.get_bool();
 
-    else
-        return false;
+    return true;
+}
+
+bool EventQueueModule::end(const char*, int, SnortConfig* sc)
+{
+    EventQueueConfig* eq = sc->event_queue_config;
 
     if ( eq->max_events < eq->log_events )
         eq->max_events = eq->log_events;
@@ -313,9 +318,6 @@ bool SearchEngineModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("queue_limit") )
         fp->set_queue_limit(v.get_uint32());
 
-    else
-        return false;
-
     return true;
 }
 
@@ -545,9 +547,6 @@ bool ClassificationsModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("text") )
         text = v.get_string();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -609,9 +608,6 @@ bool ReferencesModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("url") )
         url = v.get_string();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -693,9 +689,6 @@ bool AlertsModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("tunnel_verdicts") )
         sc->set_tunnel_verdicts(v.get_string());
 
-    else
-        return false;
-
     return true;
 }
 
@@ -818,9 +811,6 @@ bool OutputModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("obfuscate") )
         v.update_mask(sc->output_flags, OUTPUT_FLAG__OBFUSCATE);
 
-    else
-        return false;
-
     return true;
 }
 
@@ -896,9 +886,6 @@ bool ActiveModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("min_interval") )
         sc->min_interval = v.get_uint8();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -1015,9 +1002,6 @@ bool AttributeTableModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("max_metadata_services") )
         sc->max_metadata_services = v.get_uint8();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -1103,9 +1087,6 @@ bool NetworkModule::set(const char*, Value& v, SnortConfig* sc)
     else if (v.is("max_ip_layers"))
         sc->max_ip_layers = v.get_uint8();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -1188,9 +1169,6 @@ bool InspectionModule::set(const char*, Value& v, SnortConfig* sc)
         return true;
     }
 
-    else
-        return false;
-
     return true;
 }
 //-------------------------------------------------------------------------
@@ -1370,9 +1348,6 @@ bool IpsModule::set(const char* fqn, Value& v, SnortConfig* sc)
     else if ( v.is("with") )
         with = v.get_string();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -1506,9 +1481,6 @@ bool ProcessModule::set(const char*, Value& v, SnortConfig* sc)
     else if (v.is("name"))
         name = v.get_string();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -1641,9 +1613,6 @@ bool SuppressModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("ip") )
         thdx.ip_address = sfip_var_from_string(v.get_string(), "suppress");
 
-    else
-        return false;
-
     return true;
 }
 
@@ -1756,9 +1725,6 @@ bool EventFilterModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("type") )
         thdx.type = v.get_uint8();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -1892,9 +1858,6 @@ bool RateFilterModule::set(const char*, Value& v, SnortConfig*)
                     v.get_string());
     }
 
-    else
-        return false;
-
     return true;
 }
 
@@ -2002,9 +1965,6 @@ bool HostsModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("port") )
         service.port = v.get_uint16();
 
-    else
-        return false;
-
     return true;
 }
 
index b25ce9520ec08b254167b848b7c75ca34e807003..c44106cb3d43bc24409aaa87cf397ee5ce996fd1 100644 (file)
@@ -68,8 +68,7 @@ bool EventManager::log_enabled = true;
 
 void EventManager::add_plugin(const LogApi* api)
 {
-    // can't assert - alert_sf_socket operates differently
-    //assert(api->flags & (OUTPUT_TYPE_FLAG__ALERT | OUTPUT_TYPE_FLAG__LOG));
+    assert(api->flags & (OUTPUT_TYPE_FLAG__ALERT | OUTPUT_TYPE_FLAG__LOG));
     s_outputs.emplace_back(new Output(api));
 }
 
index fb8a922da9c8c60d6b50ec19185448994fecb306..d6deb2aed219a33ed5bad3210fc19787b4e4e5bf 100644 (file)
@@ -31,7 +31,7 @@
 #include "helpers/directory.h"
 #include "log/messages.h"
 #include "lua/lua.h"
-#include "lua/lua_util.h"
+#include "lua/lua_script.h"
 
 #ifdef PIGLET
 #include "piglet/piglet_manager.h"
index 844f1577122c921d39a3517fd1a3febf185b40d9..b1a3da9c734f3deea2c58406d8893885a88d753a 100644 (file)
@@ -84,9 +84,6 @@ bool MemoryModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("threshold") )
         sc->memory->threshold = v.get_uint8();
 
-    else
-        return false;
-
     return true;
 }
 
index d696eaecee8f3d92942288083285b551cdf247db..373b760d925b3912804ebfe9c181d5f2050fd914 100644 (file)
 //--------------------------------------------------------------------------
 // client_plugins_mock.h author author Sreeja Athirkandathil Narayanan <sathirka@cisco.com>
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 #define APPID_UT_ID 1492
 
 namespace snort
index cf2cd45515ba0d378f4eeb8eb408a441d3b77491..0e5bc048df46e0bf2ce7956c504f3935c395484d 100644 (file)
@@ -28,9 +28,11 @@ namespace snort
 {
 // Stubs for messages
 void ErrorMessage(const char*,...) { }
+// LCOV_EXCL_START
 void WarningMessage(const char*,...) { }
 void LogMessage(const char*,...) { }
 void ParseWarning(WarningGroup, const char*, ...) { }
+// LCOV_EXCL_STOP
 
 // Stubs for appid sessions
 FlowData::FlowData(unsigned, Inspector*) { }
@@ -42,16 +44,20 @@ Packet::~Packet() = default;
 
 Inspector::Inspector() = default;
 Inspector::~Inspector() = default;
+// LCOV_EXCL_START
 bool Inspector::likes(Packet*) { return true; }
 bool Inspector::get_buf(const char*, Packet*, InspectionBuffer&) { return true; }
 class StreamSplitter* Inspector::get_splitter(bool) { return nullptr; }
+// LCOV_EXCL_STOP
 
 // Stubs for search_tool.cc
 SearchTool::~SearchTool() = default;
+// LCOV_EXCL_START
 void SearchTool::add(const char*, unsigned, int, bool) { }
 void SearchTool::add(const char*, unsigned, void*, bool) { }
 void SearchTool::add(const uint8_t*, unsigned, int, bool) { }
 void SearchTool::add(const uint8_t*, unsigned, void*, bool) { }
+// LCOV_EXCL_STOP
 void SearchTool::prep() { }
 
 // Stubs for util.cc
@@ -75,9 +81,11 @@ char* snort_strdup(const char* str)
     return p;
 }
 }
+// LCOV_EXCL_START
 DiscoveryFilter::~DiscoveryFilter(){}
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
 void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+// LCOV_EXCL_STOP
 
 #ifndef SIP_UNIT_TEST
 class AppIdInspector : public snort::Inspector
@@ -85,11 +93,13 @@ class AppIdInspector : public snort::Inspector
 public:
     AppIdInspector(AppIdModule&) { }
     ~AppIdInspector() override = default;
-    void eval(Packet*) override { }
     bool configure(snort::SnortConfig*) override;
+// LCOV_EXCL_START
+    void eval(Packet*) override { }
     void show(const SnortConfig*) const override { }
     void tinit() override { }
     void tterm() override { }
+// LCOV_EXCL_STOP
 private:
     AppIdContext* ctxt = nullptr;
 };
@@ -100,6 +110,8 @@ AppIdConfig::~AppIdConfig() = default;
 AppIdModule::AppIdModule()
     : Module("a", "b") { }
 AppIdModule::~AppIdModule() = default;
+
+// LCOV_EXCL_START
 bool AppIdModule::begin(const char*, int, snort::SnortConfig*)
 {
     return false;
@@ -137,6 +149,7 @@ snort::ProfileStats* AppIdModule::get_profile() const
 
 void AppIdModule::set_trace(const Trace*) const { }
 const TraceOption* AppIdModule::get_trace_options() const { return nullptr; }
+// LCOV_EXCL_STOP
 
 // Stubs for inspectors
 unsigned AppIdSession::inspector_id = 0;
@@ -167,6 +180,7 @@ AppIdHttpSession::~AppIdHttpSession()
 }
 
 // Stubs for AppIdPegCounts
+// LCOV_EXCL_START
 void AppIdPegCounts::update_service_count(AppId, bool) { }
 void AppIdPegCounts::update_client_count(AppId, bool) { }
 void AppIdPegCounts::inc_user_count(AppId) { }
@@ -214,6 +228,7 @@ void ServiceDiscovery::reload() {}
 
 int ServiceDiscovery::add_service_port(AppIdDetector*, const ServiceDetectorPort&)
 { return 0; }
+// LCOV_EXCL_STOP
 
 OdpContext::OdpContext(const AppIdConfig&, snort::SnortConfig*)
 { }
index f8ce42d74ff406313fc08c621a5252d2c00f3de8..77cafe1c63df366764c237fda3053df95346e5c0 100644 (file)
@@ -70,7 +70,7 @@ SearchTool::SearchTool(const char*, bool)
 {
     mpsegrp = &mpse_group;
 }
-void SearchTool::reload() { }
+void SearchTool::reload() { }  // LCOV_EXCL_LINE
 int SearchTool::find_all(const char*, unsigned, MpseMatch, bool, void*)
 {
     // Seg-fault will be observed if this is called without initializing pattern matchers
@@ -86,12 +86,16 @@ bool AppIdInspector::configure(snort::SnortConfig*)
     ctxt = &context;
     return true;
 }
+
+// LCOV_EXCL_START
 void AppIdInspector::eval(Packet*) { }
 void AppIdInspector::show(const SnortConfig*) const { }
 void AppIdInspector::tinit() { }
 void AppIdInspector::tterm() { }
 void AppIdInspector::tear_down(SnortConfig*) { }
 AppIdContext& AppIdInspector::get_ctxt() const { return *ctxt; }
+// LCOV_EXCL_STOP
+
 AppIdInspector::~AppIdInspector() = default;
 
 void AppIdContext::create_odp_ctxt()
@@ -127,11 +131,17 @@ AppIdSession* AppIdSession::allocate_session(snort::Packet const*, IpProtocol,
 
 void AppIdSession::publish_appid_event(AppidChangeBits&, const Packet&, bool, uint32_t) { }
 AppIdDiscovery::~AppIdDiscovery() = default;
+
+// LCOV_EXCL_START
 void ApplicationDescriptor::set_id(const Packet&, AppIdSession&, AppidSessionDirection,
     AppId, AppidChangeBits&) { }
 void ClientDiscovery::initialize(AppIdInspector&) { }
 void ClientDiscovery::reload() { }
+// LCOV_EXCL_STOP
+
 void AppIdDiscovery::register_detector(const string&, AppIdDetector*, IpProtocol) { }
+
+// LCOV_EXCL_START
 void AppIdDiscovery::add_pattern_data(AppIdDetector*, snort::SearchTool&, int,
     unsigned char const*, unsigned int, unsigned int) { }
 void AppIdDiscovery::register_tcp_pattern(AppIdDetector*, unsigned char const*, unsigned int,
@@ -139,13 +149,17 @@ void AppIdDiscovery::register_tcp_pattern(AppIdDetector*, unsigned char const*,
 void AppIdDiscovery::register_udp_pattern(AppIdDetector*, unsigned char const*, unsigned int,
     int, unsigned int) { }
 int AppIdDiscovery::add_service_port(AppIdDetector*, ServiceDetectorPort const&) { return 0; }
-void AppIdModule::reset_stats() {}
+void AppIdModule::reset_stats() { }
+// LCOV_EXCL_STOP
+
 DnsPatternMatchers::~DnsPatternMatchers() = default;
 EfpCaPatternMatchers::~EfpCaPatternMatchers() = default;
 SslPatternMatchers::~SslPatternMatchers() = default;
 HttpPatternMatchers::~HttpPatternMatchers() = default;
 
 ClientDetector::ClientDetector() { }
+
+// LCOV_EXCL_START
 void ClientDetector::register_appid(int, unsigned int, OdpContext&) { }
 int AppIdDetector::initialize(AppIdInspector&) { return 1; }
 void AppIdDetector::reload() { }
@@ -155,12 +169,13 @@ void AppIdDetector::add_payload(AppIdSession&, int) { }
 void AppIdDetector::add_app(snort::Packet const&, AppIdSession&, AppidSessionDirection, int,
     int, char const*, AppidChangeBits&) { }
 void memory::MemoryCap::update_deallocations(size_t) { }
+// LCOV_EXCL_STOP
 
 SipEvent::SipEvent(snort::Packet const* p, SIPMsg const*, SIP_DialogData const*) { this->p = p; }
 SipEvent::~SipEvent() = default;
 bool SipEvent::is_invite() const { return false; }
 bool SipEvent::is_dialog_established() const { return false; }
-int SipPatternMatchers::get_client_from_ua(char const*, unsigned int, int&, char*&) { return 0; }
+int SipPatternMatchers::get_client_from_ua(char const*, unsigned int, int&, char*&) { return 0; }  // LCOV_EXCL_LINE
 void SipEventHandler::service_handler(SipEvent&, AppIdSession&, AppidChangeBits&) { }
 SipUdpClientDetector* SipEventHandler::client = &cd;
 
index 0ff614c1038c01c0b44e1336c2360dfecde5ad41..127416710ab8211e75ab471dfda8619d09ff86e7 100644 (file)
@@ -195,8 +195,7 @@ bool AppIdOptionModule::begin(const char*, int, SnortConfig*)
 
 bool AppIdOptionModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
+    assert(v.is("~"));
 
     v.set_first_token();
     string tok;
index c5dca9c250385065d8fe08a98baad898eee50bf7..a56750e6c06e83baab37ee537f9e0722cc5816ec 100644 (file)
@@ -48,7 +48,7 @@ add_cpputest( appid_efp_process_event_handler_test
 add_cpputest( tp_lib_handler_test
     SOURCES
         tp_lib_handler_test.cc
-        ../../../network_inspectors/rna/test/rna_flow_mock.cc
+        ../../../network_inspectors/rna/test/rna_flow_stubs.cc
         ../tp_lib_handler.cc
     LIBS
         dl
index a5646c699567a4640c464c8a8a936937de36c5a4..030204ffffbb8f9caef0a2e7c9d4948de6d4d9a4 100644 (file)
@@ -1,10 +1,6 @@
 #ifndef LOG_MESSAGE_MOCK
 #define LOG_MESSAGE_MOCK
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 #include <cstdarg>
 
 using namespace std;
index 9f5804a292de2844c82c7cffeb7bf2743f27ebc6..a459a154b82deaf196100e07c2dc58d09a5c0edf 100644 (file)
@@ -100,9 +100,6 @@ bool ArpSpoofModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("mac") )
         v.get_mac(host.mac_addr);
 
-    else
-        return false;
-
     return true;
 }
 
index c4ef1a67238161bd9e33aaf0432ae7c157256383..3f22443bca7450c1c4433b5fa8ae2e513e4b90e9 100644 (file)
@@ -321,9 +321,6 @@ bool NormalizeModule::set(const char* fqn, Value& v, SnortConfig* sc)
     else if ( v.is("icmp6") )
         Norm_Set(&config, NORM_ICMP6, v.get_bool());
 
-    else
-        return false;
-
     return true;
 }
 
index b4f4d179b25fccde2bf929293372432a0dbeefc8..5bf1cce94a420ac84e7948c10c11d097e28a817c 100644 (file)
@@ -153,9 +153,6 @@ bool CaptureModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("group") )
         config.group = v.get_int16();
 
-    else
-        return false;
-
     return true;
 }
 
index 7b0302bbea83cfa1b81025bb2686967907d00954..ee7a88a99b877160074e32733357bafa7a55e2a0 100644 (file)
@@ -184,9 +184,6 @@ bool PacketTracerModule::set(const char *, Value &v, SnortConfig*)
                 return false;
         }
     }
-    else
-        return false;
-
     return true;
 }
 
index fe901aca98981ff97e528ad4afc9ccfbb5697841..f3286daa750a13068745a847e23823b6896c50f0 100644 (file)
@@ -313,9 +313,6 @@ bool PerfMonModule::set(const char*, Value& v, SnortConfig*)
     {
         return true;
     }
-    else
-        return false;
-
     return true;
 }
 
index 05333fff3c4c29f72514b71312fd93a00f799f75..5054a30012db2574d0025ead4ac7a2edb1f08feb 100644 (file)
@@ -320,9 +320,6 @@ bool PortScanModule::set(const char* fqn, Value& v, SnortConfig*)
     else if ( v.is("icmp_window") )
         config->icmp_window = v.get_uint32();
 
-    else
-        return false;
-
     return true;
 }
 
index 3f97ed91c22a741c8e8d548c5c7ed361770b6a9f..c713318d381a19c29f026f73480e9eb0d5a2fc95 100644 (file)
@@ -144,9 +144,6 @@ bool ReputationModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("allowlist") )
         conf->allowlist_path = v.get_string();
 
-    else
-        return false;
-
     return true;
 }
 
index 73567cb109116304e804a651a592fda6f52d6b31..1ef7a7f915316e5425285efe98a0348a29094906 100644 (file)
@@ -510,9 +510,6 @@ bool RnaModule::set(const char* fqn, Value& v, SnortConfig*)
         else
             return false;
     }
-    else
-        return false;
-
     return true;
 }
 
@@ -666,9 +663,6 @@ TEST_CASE("RNA module", "[rna_module]")
         Value v1("rna.conf");
         v1.set(Parameter::find(rna_params, "rna_conf_path"));
         CHECK(mod.set(nullptr, v1, nullptr) == true);
-
-        Value v3("dummy");
-        CHECK(mod.set(nullptr, v3, nullptr) == false);
         CHECK(mod.end("rna", 0, &sc) == true);
 
         RnaModuleConfig* rc = mod.get_config();
index 0be3be0edd077c8ca4e471b0b6cc9618bc35610a..dfc6e9102e3a0297c6615067b86d18c4a7c86d24 100644 (file)
@@ -3,6 +3,8 @@ add_cpputest( rna_module_test
         ../../../framework/parameter.cc
         ../../../host_tracker/host_cache.cc
         ../rna_fingerprint.cc
+        rna_module_mock.h
+        rna_module_stubs.h
         $<TARGET_OBJECTS:catch_tests>
     LIBS
         ${DNET_LIBRARIES}
index 75eed5935595933eed59f2c2818a3f40d38d5c75..033948abf306e2eb0589d010dfc13c28167c587e 100644 (file)
@@ -28,49 +28,9 @@ THREAD_LOCAL ProfileStats rna_perf_stats;
 
 namespace snort
 {
-Module* ModuleManager::get_module(const char*)
-{ return nullptr; }
-
-char* snort_strdup(const char* s)
-{ return strdup(s); }
-
 Module::Module(const char*, const char*, const Parameter*, bool) {}
-void Module::sum_stats(bool) {}
-void Module::show_stats() {}
-void Module::reset_stats() {}
-PegCount Module::get_global_count(char const*) const
-{ return 0; }
-void Module::show_interval_stats(std::vector<unsigned int, std::allocator<unsigned int> >&, FILE*)
-{}
-void LogMessage(const char*,...) {}
-void WarningMessage(const char*,...) {}
-SnortConfig::SnortConfig(SnortConfig const*) {}
-SnortConfig::~SnortConfig() = default;
-time_t packet_time() { return 0; }
-
-// tcp fingerprint functions
-bool TcpFpProcessor::push(const TcpFingerprint&) { return true; }
-void TcpFpProcessor::make_tcp_fp_tables(TCP_FP_MODE) { }
-const TcpFingerprint* TcpFpProcessor::get_tcp_fp(const FpTcpKey&, uint8_t, TCP_FP_MODE) const
-{ return nullptr; }
-const TcpFingerprint* TcpFpProcessor::get(const Packet*, RNAFlow*) const
-{ return nullptr; }
-TcpFpProcessor* get_tcp_fp_processor() { return nullptr; }
-void set_tcp_fp_processor(TcpFpProcessor*) { }
-
-TcpFingerprint::TcpFingerprint(const RawFingerprint&) { }
 bool TcpFingerprint::operator==(const TcpFingerprint&) const { return true; }
 
-UaFpProcessor::~UaFpProcessor() = default;
-void UaFpProcessor::make_mpse(SnortConfig*) { }
-void UaFpProcessor::push(RawFingerprint const&) { }
-
-void UdpFpProcessor::push(RawFingerprint const&) { }
-
-SmbFingerprint::SmbFingerprint(const RawFingerprint&) { }
-bool SmbFingerprint::operator==(const SmbFingerprint&) const { return true; }
-bool SmbFpProcessor::push(SmbFingerprint const&) { return true; }
-
 // inspector
 class RnaInspector
 {
@@ -104,26 +64,9 @@ private:
 
 } // end of namespace snort
 
-void snort::main_broadcast_command(snort::AnalyzerCommand*, ControlConn*) {}
-
 static ControlConn s_ctrlcon(1, true);
 ControlConn::ControlConn(int, bool) {}
 ControlConn::~ControlConn() {}
-ControlConn* ControlConn::query_from_lua(const lua_State*) { return &s_ctrlcon; }
-bool ControlConn::respond(const char*, ...) { return true; }
-
-HostCacheMac* get_host_cache_mac() { return nullptr; }
-
-DataPurgeAC::~DataPurgeAC() = default;
-bool DataPurgeAC::execute(Analyzer&, void**) { return true;}
-
-void set_host_cache_mac(HostCacheMac*) { }
-
-Inspector* InspectorManager::get_inspector(const char*, bool, const SnortConfig*)
-{
-    return nullptr;
-}
-
-void HostTracker::remove_flows() { }
 
 #endif
+
diff --git a/src/network_inspectors/rna/test/rna_module_stubs.h b/src/network_inspectors/rna/test/rna_module_stubs.h
new file mode 100644 (file)
index 0000000..6c9a7b8
--- /dev/null
@@ -0,0 +1,87 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2020-2021 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation.  You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//--------------------------------------------------------------------------
+
+// rna_module_stubs.h author Masud Hasan <mashasan@cisco.com>
+
+#ifndef RNA_MODULE_TEST_H
+#define RNA_MODULE_TEST_H
+
+namespace snort
+{
+Module* ModuleManager::get_module(const char*)
+{ return nullptr; }
+
+char* snort_strdup(const char* s)
+{ return strdup(s); }
+
+void Module::sum_stats(bool) {}
+void Module::show_stats() {}
+void Module::reset_stats() {}
+PegCount Module::get_global_count(char const*) const
+{ return 0; }
+void Module::show_interval_stats(std::vector<unsigned int, std::allocator<unsigned int> >&, FILE*)
+{}
+void LogMessage(const char*,...) {}
+void WarningMessage(const char*,...) {}
+SnortConfig::SnortConfig(SnortConfig const*) {}
+SnortConfig::~SnortConfig() = default;
+time_t packet_time() { return 0; }
+
+// tcp fingerprint functions
+bool TcpFpProcessor::push(const TcpFingerprint&) { return true; }
+void TcpFpProcessor::make_tcp_fp_tables(TCP_FP_MODE) { }
+const TcpFingerprint* TcpFpProcessor::get_tcp_fp(const FpTcpKey&, uint8_t, TCP_FP_MODE) const
+{ return nullptr; }
+const TcpFingerprint* TcpFpProcessor::get(const Packet*, RNAFlow*) const
+{ return nullptr; }
+TcpFpProcessor* get_tcp_fp_processor() { return nullptr; }
+void set_tcp_fp_processor(TcpFpProcessor*) { }
+
+TcpFingerprint::TcpFingerprint(const RawFingerprint&) { }
+
+UaFpProcessor::~UaFpProcessor() = default;
+void UaFpProcessor::make_mpse(SnortConfig*) { }
+void UaFpProcessor::push(RawFingerprint const&) { }
+
+void UdpFpProcessor::push(RawFingerprint const&) { }
+
+SmbFingerprint::SmbFingerprint(const RawFingerprint&) { }
+bool SmbFingerprint::operator==(const SmbFingerprint&) const { return true; }
+bool SmbFpProcessor::push(SmbFingerprint const&) { return true; }
+}
+
+void snort::main_broadcast_command(snort::AnalyzerCommand*, ControlConn*) {}
+
+ControlConn* ControlConn::query_from_lua(const lua_State*) { return &s_ctrlcon; }
+bool ControlConn::respond(const char*, ...) { return true; }
+
+HostCacheMac* get_host_cache_mac() { return nullptr; }
+
+DataPurgeAC::~DataPurgeAC() = default;
+bool DataPurgeAC::execute(Analyzer&, void**) { return true;}
+
+void set_host_cache_mac(HostCacheMac*) { }
+
+Inspector* InspectorManager::get_inspector(const char*, bool, const SnortConfig*)
+{
+    return nullptr;
+}
+
+void HostTracker::remove_flows() { }
+
+#endif
index 8d1238ddb1020a34e7b40ca3992317d79efe208b..60711e6034f39dd86497e437eb87e8e99eb78acc 100644 (file)
@@ -25,6 +25,7 @@
 #include "../rna_module.cc"
 
 #include "rna_module_mock.h"
+#include "rna_module_stubs.h"
 
 // To avoid warnings between catch.hpp and UtestMacros.h macro definitions,
 // since rna_module.cc has both catch and cpputest tests
index b9fbe32a0346d8f16d49a6e988530729b9a11967..3469c29628d5f99ff264062d6bb26b95543f7ac8 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "lua/lua.h"
 #include "lua/lua_table.h"
-#include "lua/lua_util.h"
+#include "lua/lua_script.h"
 
 #include "piglet_api.h"
 #include "piglet_manager.h"
index ef40e4d484d345bf843a1cb228f3accc1d2538cc..46580a9c7b85732196e8f058e80ae2bbef79fe98 100644 (file)
@@ -1,4 +1,3 @@
-
 //--------------------------------------------------------------------------
 // Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
 //
index 451a11e13476d3b3ac758a7b533c8df801a12338..c28d64e4fc9de29dafbcab22e20aa293c6b26cc6 100644 (file)
@@ -113,41 +113,8 @@ int Mpse::search_all(
     return _search(T, n, match, context, current_state);
 }
 
-void Mpse::search(MpseBatch& batch, MpseType mpse_type)
-{
-    _search(batch, mpse_type);
-}
-
-void Mpse::_search(MpseBatch& batch, MpseType mpse_type)
-{
-    int start_state;
-
-    for ( auto& item : batch.items )
-    {
-        if (item.second.done)
-            continue;
-
-        item.second.error = false;
-        item.second.matches = 0;
-
-        for ( auto& so : item.second.so )
-        {
-            start_state = 0;
-            switch (mpse_type)
-            {
-                case MPSE_TYPE_NORMAL:
-                    item.second.matches += so->normal_mpse->search(item.first.buf, item.first.len,
-                            batch.mf, batch.context, &start_state);
-                    break;
-                case MPSE_TYPE_OFFLOAD:
-                    item.second.matches += so->offload_mpse->search(item.first.buf, item.first.len,
-                            batch.mf, batch.context, &start_state);
-                    break;
-            }
-        }
-        item.second.done = true;
-    }
-}
+void Mpse::search(MpseBatch&, MpseType) { }
+void Mpse::_search(MpseBatch&, MpseType) { }
 
 }
 
index ce4d76dd4d550c2bcc4332d2ff8c006f94fb5e18..298abc9dcc1be2696df9f036d8cc77a52db49559 100644 (file)
@@ -113,9 +113,6 @@ bool CipModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("max_unconnected_messages") )
         conf->max_unconnected_messages = v.get_uint32();
 
-    else
-        return false;
-
     return true;
 }
 
index b176694905b70e8ea7afb3984b50787020ea361e..a3bd448d61fb1f3daf266424948121d6d2bd6793 100644 (file)
@@ -149,9 +149,7 @@ bool CipAttributeModule::begin(const char*, int, SnortConfig*)
 
 bool CipAttributeModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return cip_attr.validate(v.get_string(), RANGE);
 }
 
index 0d03b6dedf63f25a08e05ed34febc776130a09a8..a0384593d0a79298ee75f00c0daa43641d886713 100644 (file)
@@ -148,9 +148,7 @@ bool CipClassModule::begin(const char*, int, SnortConfig*)
 
 bool CipClassModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return cip_class.validate(v.get_string(), RANGE);
 }
 
index 2ba69b0d3e634500acfb871520567877dde95e1d..b1da5a54566916c84f3131113f6e71d82fb5b129 100644 (file)
@@ -149,9 +149,7 @@ bool CipConnpathclassModule::begin(const char*, int, SnortConfig*)
 
 bool CipConnpathclassModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return cip_cpc.validate(v.get_string(), RANGE);
 }
 
index c576a9dfdd4b6a8ad6c7a0392c2b4817dd57aaac..467ee8c477df315b94c3635162f1248aa10edf15 100644 (file)
@@ -142,9 +142,7 @@ bool CipEnipCommandModule::begin(const char*, int, SnortConfig*)
 
 bool CipEnipCommandModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return cip_enip_cmd.validate(v.get_string(), RANGE);
 }
 
index 2e31a4d876fbb954dd64241a038eb7a0b7e35835..224a364d6a59c0dc876610b250b4b3d53550f20f 100644 (file)
@@ -149,9 +149,7 @@ bool CipInstanceModule::begin(const char*, int, SnortConfig*)
 
 bool CipInstanceModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return cip_inst.validate(v.get_string(), RANGE);
 }
 
index 7b5e373eaa504374738ce5be18c7da18e83ef1d1..97af706ad6156fe2d43d1984d691138c887396a6 100644 (file)
@@ -153,9 +153,7 @@ bool CipServiceModule::begin(const char*, int, SnortConfig*)
 
 bool CipServiceModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return cip_serv.validate(v.get_string(), RANGE);
 }
 
index 495f66586d50c544b93a2c1ebbe0df6a2baee2dd..c4dcd021b20b0b92d3f55419831b3663f8eb2c12 100644 (file)
@@ -148,9 +148,7 @@ bool CipStatusModule::begin(const char*, int, SnortConfig*)
 
 bool CipStatusModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~range") )
-        return false;
-
+    assert(v.is("~range"));
     return cip_status.validate(v.get_string(), RANGE);
 }
 
index 04d9cd3ec69a751a3b47b6df239bd255c40d9f10..0b1c1bd6a5d0b1ca44cebc89a59c9a02383841b2 100644 (file)
@@ -146,10 +146,7 @@ ProfileStats* Dce2TcpModule::get_profile() const
 
 bool Dce2TcpModule::set(const char*, Value& v, SnortConfig*)
 {
-    if (dce2_set_co_config(v,config.common))
-        return true;
-
-    return false;
+    return dce2_set_co_config(v,config.common);
 }
 
 void Dce2TcpModule::get_data(dce2TcpProtoConf& dce2_tcp_config)
index 5bc1917cedca1d1c60d63046d5766a0d271183dc..bd70959c9729340583b643476b182ccebbc55a2e 100644 (file)
@@ -474,9 +474,6 @@ bool Dce2IfaceModule::set(const char*, Value& v, SnortConfig*)
         token = DCE2_PruneWhiteSpace(token);
         return DCE2_ParseIface(token, &uuid);
     }
-    else
-        return false;
-
     return true;
 }
 
index 00b8a85ed0421cd6ab19c8a93862980400a94ba1..75d6d69ac534fe056f46a518772757c8cb9cf6b7 100644 (file)
@@ -489,27 +489,21 @@ bool Dce2OpnumModule::begin(const char*, int, SnortConfig*)
 
 bool Dce2OpnumModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
+    assert(v.is("~"));
 
-    if (v.get_string())
-    {
-        std::string tok (v.get_string());
-        if ( tok[0] == '"' )
-            tok.erase(0, 1);
+    std::string tok (v.get_string());
 
-        if ( tok[tok.length()-1] == '"' )
-            tok.erase(tok.length()-1, 1);
+    if ( tok[0] == '"' )
+        tok.erase(0, 1);
 
-        char* s = snort_strdup(tok.c_str());
-        DCE2_Ret status = DCE2_OpnumParse(s, &opnum);
-        snort_free(s);
+    if ( tok[tok.length()-1] == '"' )
+        tok.erase(tok.length()-1, 1);
 
-        if (status == DCE2_RET__SUCCESS)
-            return true;
-    }
+    char* s = snort_strdup(tok.c_str());
+    DCE2_Ret status = DCE2_OpnumParse(s, &opnum);
+    snort_free(s);
 
-    return false;
+    return (status == DCE2_RET__SUCCESS);
 }
 
 ProfileStats* Dce2OpnumModule::get_profile() const
index 5ef2a6e15cdf8004f784064f9068bcbda68a67bc..a8e431b44589c776f163ce26f13fa49992cb9638 100644 (file)
@@ -86,12 +86,8 @@ ProfileStats* Dnp3Module::get_profile() const
 
 bool Dnp3Module::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("check_crc") )
-        config.check_crc = v.get_bool();
-
-    else
-        return false;
-
+    assert(v.is("check_crc"));
+    config.check_crc = v.get_bool();
     return true;
 }
 
index 163731ea977211097bb7ebe9360c4248da521f19..c9f582fb7e0ccf43515b397c734783316a2b084e 100644 (file)
@@ -140,8 +140,7 @@ ProfileStats* Dnp3FuncModule::get_profile() const
 
 bool Dnp3FuncModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~"))
-        return false;
+    assert(v.is("~"));
 
     long n;
 
index 7e5ad10a60de082881aa783d869828f5f26c3dab..051cd228c2e1382d3b8b692edef5bf0db34238e8 100644 (file)
@@ -137,11 +137,9 @@ public:
 
 bool Dnp3IndModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
+    assert(v.is("~"));
 
     flags = 0;
-
     v.set_first_token();
     std::string tok;
 
index dd4703a233e73426db382c794c60d7cf78ee6b69..f089757b06eceac647107d06d9910cf98e5d156b 100644 (file)
@@ -120,9 +120,6 @@ bool FtpClientModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("telnet_cmds") )
         conf->telnet_cmds = v.get_bool();
 
-    else
-        return false;
-
     return true;
 }
 
@@ -470,9 +467,6 @@ bool FtpServerModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("telnet_cmds") )
         conf->telnet_cmds = v.get_bool();
 
-    else
-        return false;
-
     return true;
 }
 
index 4d130760b7865e207ca6b5474f788a6fc080daf1..2e1344e943c066461c2aca6de486a664b9f61ded 100644 (file)
@@ -109,9 +109,6 @@ bool TelnetModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("normalize") )
         conf->normalize = v.get_bool();
 
-    else
-        return false;
-
     return true;
 }
 
index 4e845ac23549ca9a938895949019e55a19589489..88f453dbdf208373fa55db5a5428ec7cdd2f2703 100644 (file)
@@ -193,9 +193,7 @@ bool GtpInfoModule::set_types(const char* name)
 
 bool GtpInfoModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     long n;
 
     if ( v.strtol(n) )
index cbe0389be53df60c0b5f5f16ed343cb871456b99..163e25f158195fc9fe8b5c5d0366c482ada8866a 100644 (file)
@@ -191,9 +191,7 @@ bool GtpTypeModule::set_types(const char* name)
 
 bool GtpTypeModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     v.set_first_token();
     std::string tok;
 
index 70929b755dc89abcdc338f13edb8e480bb637e2f..ecb3116b31af40d58751ffbd206935082c8cc9ad 100644 (file)
@@ -125,9 +125,7 @@ public:
 
 bool GtpVersionModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     version = v.get_uint8();
     return true;
 }
index 436a2aebbbeae78313b0674a07c06397ad418eab..6669551338c9b3731a7602ffc607c52b7e67c0fe 100644 (file)
 //--------------------------------------------------------------------------
 // http2_huffman_state_machine.cc author Maya Dagon <mdagon@cisco.com>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "http2_huffman_state_machine.h"
 
 const HuffmanEntry huffman_decode[HUFFMAN_LOOKUP_MAX+1] [UINT8_MAX+1] =
index 299cfe4076ebae52f757c62a105841df3d0e9048..62bfeca5ff96e572b6093937599835a6abcb98a7 100644 (file)
@@ -99,10 +99,6 @@ bool Http2Module::set(const char*, Value& val, SnortConfig*)
         params->show_scan = val.get_bool();
     }
 #endif
-    else
-    {
-        return false;
-    }
     return true;
 }
 
index aa641afc55964c4600bf80fcb50e6e2af4ef626b..dcd2d41862b374e2ceaf474920f6fdaef98abc6d 100644 (file)
 //--------------------------------------------------------------------------
 // http2_utils.cc author Maya Dagon <mdagon@cisco.com>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "http2_utils.h"
 
 #include <cassert>
index 8e3b7921af46f074ec62941ea988d9c2eb714ec9..5effceac43360b2e4df9fed8f4590d7bca1cf752 100644 (file)
 #ifndef HTTP2_UTILS_H
 #define HTTP2_UTILS_H
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 #include "main/snort_types.h"
 #include "service_inspectors/http_inspect/http_common.h"
 
index 74de314be8cba6090dc07280e771e5dc102089a4..809c4dd89eaff329d4dc5e3ebee60ab3bc92ca75 100644 (file)
 //--------------------------------------------------------------------------
 // http_buffer_info.cc author Brandon Stultz <brastult@cisco.com>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "hash/hash_key_operations.h"
 #include "http_buffer_info.h"
 
index f8da39760ee565bbb5e5e59612a05f1a4ca510c9..a9794f68df4fcf8a59805911565e99dde59cfbd4 100755 (executable)
@@ -417,10 +417,6 @@ bool HttpModule::set(const char*, Value& val, SnortConfig*)
         params->show_scan = val.get_bool();
     }
 #endif
-    else
-    {
-        return false;
-    }
     return true;
 }
 
index 38d911ce161ae87c23f32f449dfb46007fa867bf..067d17209c57a5b9958fbb6d9d2783c4f792f368 100644 (file)
@@ -163,10 +163,6 @@ bool HttpCursorModule::set(const char*, Value& v, SnortConfig*)
         para_list.fragment = true;
         sub_id = UC_FRAGMENT;
     }
-    else
-    {
-        return false;
-    }
     return true;
 }
 
index 168d9dfc4ddb10b1194357f974b5d2498847ad81..066adadfee94290916508c9e3206eabba1e5bf88 100644 (file)
@@ -185,27 +185,14 @@ public:
 
 bool Iec104ApciTypeModule::set(const char*, Value& v, SnortConfig*)
 {
-    if (!v.is("~"))
-    {
-        return false;
-    }
-
+    assert(v.is("~"));
     long n;
 
     if (v.strtol(n))
-    {
         apci_type = static_cast<uint8_t>(n);
-    }
 
     else if (get_apci_type(v.get_string(), n))
-    {
         apci_type = static_cast<uint8_t>(n);
-    }
-
-    else
-    {
-        return false;
-    }
 
     return true;
 }
index 2e2fd39620ebf55f1a1da679b0d1fdfb5e79d264..7e2ee68e422378377bbf7808d314ac84d64744dd 100644 (file)
@@ -258,27 +258,14 @@ public:
 
 bool Iec104AsduFuncModule::set(const char*, Value& v, SnortConfig*)
 {
-    if (!v.is("~"))
-    {
-        return false;
-    }
-
+    assert(v.is("~"));
     long n;
 
     if (v.strtol(n))
-    {
         func = static_cast<uint8_t>(n);
-    }
 
     else if (get_func(v.get_string(), n))
-    {
         func = static_cast<uint8_t>(n);
-    }
-
-    else
-    {
-        return false;
-    }
 
     return true;
 }
index 169332a5f13a32cef0b46135751546600eeef7ce..0e889aa72dac40fb45e412417e044618be3ead61 100644 (file)
@@ -122,9 +122,6 @@ bool ImapModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("uu_decode_depth") )
         config->decode_conf.set_uu_depth(mime_value);
 
-    else
-        return false;
-
     return true;
 }
 
index 3df06c476fd9f42a9a5f926c0a0c3ca6a1ae9bd5..f4d118aabee753e06c808a895fe6a637f893018a 100644 (file)
@@ -176,9 +176,7 @@ public:
 
 bool ModbusFuncModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     long n;
 
     if ( v.strtol(n) )
@@ -187,9 +185,6 @@ bool ModbusFuncModule::set(const char*, Value& v, SnortConfig*)
     else if ( get_func(v.get_string(), n) )
         func = (uint8_t)n;
 
-    else
-        return false;
-
     return true;
 }
 
index eee9eccbee2ef5ec1d112aa67e02fdd993f0b5b3..da082193a271107b9722763fc9bf29079f05c7a4 100644 (file)
@@ -128,9 +128,7 @@ public:
 
 bool ModbusUnitModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     unit = v.get_uint8();
     return true;
 }
index 304919599b3e04899f58b68594e50b6dbc1d2ce1..b21f499385b058eaff397ad09853243773a822f8 100644 (file)
@@ -193,9 +193,6 @@ bool NetflowModule::set(const char*, Value& v, SnortConfig*)
     {
         rule_cfg.create_service = v.get_bool();
     }
-    else
-        return false;
-
     return true;
 }
 
index 23836abcf07a1e5324bf74e7476424e4a5849e73..336984a89cbcdbc6a961a7cd5fbc87fd518f48ef 100644 (file)
@@ -121,9 +121,6 @@ bool PopModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("uu_decode_depth") )
         config->decode_conf.set_uu_depth(mime_value);
 
-    else
-        return false;
-
     return true;
 }
 
index 21d9d3a0313595a9e5e1e44fd1e68debcef40638..cbb433bd1546732a7e4953e147a4d86217de2973 100644 (file)
@@ -170,9 +170,7 @@ public:
 
 bool S7commplusFuncModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     long n;
 
     if ( v.strtol(n) )
@@ -181,9 +179,6 @@ bool S7commplusFuncModule::set(const char*, Value& v, SnortConfig*)
     else if ( get_func(v.get_string(), n) )
         func = static_cast<uint16_t>(n);
 
-    else
-        return false;
-
     return true;
 }
 
index fb3bd8f473515c9216465c7bc7d01ac7df9f75a3..65ac4de1b2b3c8b66fd7cab1dfd424039ef3688b 100644 (file)
@@ -162,9 +162,7 @@ public:
 
 bool S7commplusOpcodeModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( !v.is("~") )
-        return false;
-
+    assert(v.is("~"));
     long n;
 
     if ( v.strtol(n) )
@@ -173,9 +171,6 @@ bool S7commplusOpcodeModule::set(const char*, Value& v, SnortConfig*)
     else if ( get_opcode(v.get_string(), n) )
         opcode = (uint8_t)n;
 
-    else
-        return false;
-
     return true;
 }
 
index be79fd9751e9fb7a7c13edd9a71f7d24d19c4687..7a047d4213c4db6f066ddf24f93894ec000425c5 100644 (file)
@@ -174,28 +174,24 @@ bool SipMethodModule::begin(const char*, int, SnortConfig*)
 
 bool SipMethodModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("*method") )
+    assert(v.is("*method"));
+    const char* tok = v.get_string();
+
+    if (tok[0] == '!')
     {
-        const char* tok = v.get_string();
-
-        if (tok[0] == '!')
-        {
-            negated = true;
-            tok++;
-        }
-        else
-            negated = false;
-
-        /*Only one method is allowed with !*/
-        if ( negated && (!methods.empty()) )
-            ParseError("Only one method is allowed with ! for sip_method");
-
-        std::string key = tok;
-        std::transform(key.begin(), key.end(), key.begin(), ::toupper);
-        methods[key] = negated;
+        negated = true;
+        tok++;
     }
     else
-        return false;
+        negated = false;
+
+    /*Only one method is allowed with !*/
+    if ( negated && (!methods.empty()) )
+        ParseError("Only one method is allowed with ! for sip_method");
+
+    std::string key = tok;
+    std::transform(key.begin(), key.end(), key.begin(), ::toupper);
+    methods[key] = negated;
 
     return true;
 }
index db70b924c2f54283f0cdf48116f70d7f8c5f3dff..f1fe426a0708f43c084ef4d2cb52dfb046bb6a9c 100644 (file)
@@ -162,25 +162,20 @@ bool SipStatCodeModule::begin(const char*, int, SnortConfig*)
 
 bool SipStatCodeModule::set(const char*, Value& v, SnortConfig*)
 {
-    if (num_tokens < SIP_NUM_STAT_CODE_MAX)
+    assert(v.is("*code"));
+
+    if (num_tokens >= SIP_NUM_STAT_CODE_MAX)
+        return false;
+
+    uint16_t statCode = v.get_uint16();
+
+    if ( (statCode >= NUM_OF_RESPONSE_TYPES) && (statCode < MIN_STAT_CODE) )
     {
-        if ( v.is("*code") )
-        {
-            uint16_t statCode = v.get_uint16();
-
-            if ( (statCode >= NUM_OF_RESPONSE_TYPES) && (statCode < MIN_STAT_CODE) )
-            {
-                ParseError("Status code specified is not a single digit or a 3 digit number");
-                return false;
-            }
-            ssod.stat_codes[num_tokens] = statCode;
-            num_tokens++;
-        }
-        else
-            return false;
-    }
-    else
+        ParseError("Status code specified is not a single digit or a 3 digit number");
         return false;
+    }
+    ssod.stat_codes[num_tokens] = statCode;
+    num_tokens++;
 
     return true;
 }
index b7d20d6ecc21074acffb60569ddef3da15c41371..b43245779bf2293bc100319b4431f0aa3b620f34 100644 (file)
@@ -234,9 +234,6 @@ bool SipModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("methods") )
         sip_methods = v.get_string();
 
-    else
-        return false;
-
     return true;
 }
 
index 8cb8eb786e76ef4c2f13ea596148f72fd6ad5ba2..49e572af5b5660ecd1b57681ebd1a1ac22c328ee 100644 (file)
@@ -333,9 +333,6 @@ bool SmtpModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("xlink2state") )
         config->xlink2state = (SMTPXlinkState)v.get_uint8();
 
-    else
-        return false;
-
     return true;
 }
 
index 747987876d7f0944e287e81481b51f01f85aaf28..2b60de5811ee8f39905152446166324692a93aab 100644 (file)
@@ -115,9 +115,6 @@ bool SshModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("max_server_version_len") )
         conf->MaxServerVersionLen = v.get_uint8();
 
-    else
-        return false;
-
     return true;
 }
 
index ffeb0cc7e74f1d924e4d6c8083e785b6ffeefe1c..22f4d625be96f3dac3a5f580a410d9250e5e25ec 100644 (file)
@@ -219,9 +219,6 @@ bool SslStateModule::set(const char*, Value& v, SnortConfig*)
         ssod.flags |= SSL_UNKNOWN_FLAG;
         ssod.mask |= SSL_UNKNOWN_FLAG;
     }
-    else
-        return false;
-
     return true;
 }
 
index 57ba78dfac6ab5ea3cfdb9d55ae03f7a65eec32c..538ebcca520b72a15c64affa678159f6f2ec426c 100644 (file)
@@ -220,9 +220,6 @@ bool SslVersionModule::set(const char*, Value& v, SnortConfig*)
         svod.flags |= SSL_VER_TLS12_FLAG;
         svod.mask |= SSL_VER_TLS12_FLAG;
     }
-    else
-        return false;
-
     return true;
 }
 
index a6737c193ba210ca94a2c6b9504e738d6967793e..ce818453c9232d1aa9e336f69316c830e6a4b99c 100644 (file)
@@ -90,9 +90,6 @@ bool SslModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("max_heartbeat_length") )
         conf->max_heartbeat_len = v.get_uint16();
 
-    else
-        return false;
-
     return true;
 }
 
index f9f13d93091baa10fb89fb2534e39cabe82cdaf8..30381a38bdb224ffd90385ffb4b1bf291cb42154 100644 (file)
 
 // ssl_splitter.cc author Steven Baigal <sbaigal@cisco.com>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "ssl_splitter.h"
 
 #include <arpa/inet.h>
index 698dca2ba6d68e6a1f3cdfa11eb9d5824792c2d4..28ad4b28b92dd88803df3795d185c950aa64c581 100644 (file)
@@ -546,9 +546,6 @@ static SfIpRet sfvar_add_node(sfip_var_t* var, sfip_node_t* node, int negated)
     ++*count;
 
     return SFIP_SUCCESS;
-
-    // FIXIT-L Insert new node into routing table
-    // sfrt_add(node->ip,
 }
 
 sfip_var_t* sfvar_create_alias(const sfip_var_t* alias_from, const char* alias_to)
index 6e73dc72ff1ecd09d46e8596f7a9fba36a7ab64f..aa451148f928dcfd7fa3f4f39e278029a85b2a77 100644 (file)
@@ -1,17 +1,8 @@
 
-if ( ENABLE_UNIT_TESTS )
-    set(TEST_FILES sfrt_test.cc)
-endif()
-
 add_library ( sfrt OBJECT
-    sfrt.cc
-    sfrt.h
-    sfrt_dir.cc
-    sfrt_dir.h
     sfrt_flat.cc
     sfrt_flat.h
     sfrt_flat_dir.cc
     sfrt_flat_dir.h
-    ${TEST_FILES}
 )
 
diff --git a/src/sfrt/sfrt.cc b/src/sfrt/sfrt.cc
deleted file mode 100644 (file)
index 55ccb3f..0000000
+++ /dev/null
@@ -1,600 +0,0 @@
-//--------------------------------------------------------------------------
-// Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2006-2013 Sourcefire, Inc.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License Version 2 as published
-// by the Free Software Foundation.  You may not use, modify or distribute
-// this program under any other version of the GNU General Public License.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-//--------------------------------------------------------------------------
-
-/*
- * sfrt.cc author Adam Keeton <akeeton@sourcefire.com>
- * Thu July 20 10:16:26 EDT 2006
- *
- * Route implements two different routing table lookup mechanisms.  The table
- * lookups have been adapted to return a void pointer so any information can
- * be associated with each CIDR block.
- *
- * As of this writing, the two methods used are Stefan Nilsson and Gunnar
- * Karlsson's LC-trie, and a multibit-trie method similar to Gupta et-al.'s
- * DIR-n-m.  Presently, the LC-trie is used primarily for testing purposes as
- * the current implementation does not allow for fast dynamic inserts.
- *
- * The intended use is for a user to optionally specify large IP blocks and
- * then more specific information will be written into the routing tables
- * from RNA.  Ideally, information will only move from less specific to more
- * specific.  If a more general information is to overwrite existing entries,
- * the table should be freed and rebuilt.
- *
- *
- * Implementation:
- *
- * The routing tables associate an index into a "data" table with each CIDR.
- * Each entry in the data table stores a pointer to actual data.  This
- * implementation was chosen so each routing entry only needs one word to
- * either index the data array, or point to another table.
- *
- * Inserts are performed by specifying a CIDR and a pointer to its associated
- * data.  Since a new routing table entry may overwrite previous entries,
- * a flag selects whether the insert favors the most recent or favors the most
- * specific.  Favoring most specific should be the default behavior.  If
- * the user wishes to overwrite routing entries with more general data, the
- * table should be flushed, rather than using favor-most-recent.
- *
- * Before modifying the routing or data tables, the insert function performs a
- * lookup on the CIDR-to-be-inserted.  If no entry or an entry *of differing
- * bit length* is found, the data is inserted into the data table, and its
- * index is used for the new routing table entry.  If an entry is found that
- * is as specific as the new CIDR, the index stored points to where the new
- * data is written into the data table.
- *
- * If more specific CIDR blocks overwrote the data table, then the more
- * general routing table entries that were not overwritten will be referencing
- * the wrong data.  Alternatively, less specific entries can only overwrite
- * existing routing table entries if favor-most-recent inserts are used.
- *
- * Because there is no quick way to clean the data-table if a user wishes to
- * use a favor-most-recent insert for more general data, the user should flush
- * the table with sfrt_free and create one anew.  Alternatively, a small
- * memory leak occurs with the data table, as it will be storing pointers that
- * no routing table entry cares about.
- *
- *
- * The API calls that should be used are:
- *  sfrt_new    - create new table
- *  sfrt_insert - insert entry
- *  sfrt_lookup - lookup entry
- *  sfrt_free   - free table
-*/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "sfrt.h"
-
-#include "sfip/sf_cidr.h"
-#include "utils/util.h"
-
-using namespace snort;
-
-const char* rt_error_messages[] =
-{
-    "Success",
-    "Insert Failure",
-    "Policy Table Exceeded",
-    "Dir Insert Failure",
-    "Dir Lookup Failure",
-    "Memory Allocation Failure"
-};
-
-static inline int allocateTableIndex(table_t* table);
-
-/* Create new lookup table
- * @param   table_type Type of table. Uses the types enumeration in route.h
- * @param   ip_type    IPv4 or IPv6. Uses the types enumeration in route.h
- * @param   data_size  Max number of unique data entries
- *
- * Returns the new table. */
-table_t* sfrt_new(char table_type, char ip_type, long data_size, uint32_t mem_cap)
-{
-    table_t* table = (table_t*)snort_alloc(sizeof(table_t));
-
-    /* If this limit is exceeded, there will be no way to distinguish
-     * between pointers and indices into the data table.  Only
-     * applies to DIR-n-m. */
-#if SIZEOF_LONG_INT == 8
-    if (data_size >= 0x800000000000000)
-#else
-    if (data_size >= 0x8000000)
-#endif
-    {
-        snort_free(table);
-        return nullptr;
-    }
-
-    /* mem_cap is specified in megabytes, but internally uses bytes. Convert */
-    mem_cap *= 1024*1024;
-
-    /* Maximum allowable number of stored entries */
-    table->max_size = data_size;
-    table->lastAllocatedIndex = 0;
-
-    table->data = (GENERIC*)snort_calloc(sizeof(GENERIC) * table->max_size);
-    table->allocated = sizeof(table_t) + sizeof(GENERIC) * table->max_size;
-
-    table->ip_type = ip_type;
-    table->table_type = table_type;
-
-    /* This will point to the actual table lookup algorithm */
-    table->rt = nullptr;
-    table->rt6 = nullptr;
-
-    /* index 0 will be used for failed lookups, so set this to 1 */
-    table->num_ent = 1;
-
-    switch (table_type)
-    {
-    /* Setup DIR-n-m table */
-    case DIR_24_8:
-    case DIR_16x2:
-    case DIR_16_8x2:
-    case DIR_16_4x4:
-    case DIR_8x4:
-    case DIR_4x8:
-    case DIR_2x16:
-    case DIR_16_4x4_16x5_4x4:
-    case DIR_16x7_4x4:
-    case DIR_16x8:
-    case DIR_8x16:
-        table->insert = sfrt_dir_insert;
-        table->lookup = sfrt_dir_lookup;
-        table->free = sfrt_dir_free;
-        table->usage = sfrt_dir_usage;
-        table->print = sfrt_dir_print;
-        table->remove = sfrt_dir_remove;
-
-        break;
-
-    default:
-        snort_free(table->data);
-        snort_free(table);
-        return nullptr;
-    }
-
-    /* Allocate the user-specified DIR-n-m table */
-    switch (table_type)
-    {
-    case DIR_24_8:
-        table->rt = sfrt_dir_new(mem_cap, 2, 24,8);
-        break;
-    case DIR_16x2:
-        table->rt = sfrt_dir_new(mem_cap, 2, 16,16);
-        break;
-    case DIR_16_8x2:
-        table->rt = sfrt_dir_new(mem_cap, 3, 16,8,8);
-        break;
-    case DIR_16_4x4:
-        table->rt = sfrt_dir_new(mem_cap, 5, 16,4,4,4,4);
-        break;
-    case DIR_8x4:
-        table->rt = sfrt_dir_new(mem_cap, 4, 8,8,8,8);
-        break;
-    /* There is no reason to use 4x8 except for benchmarking and
-     * comparison purposes. */
-    case DIR_4x8:
-        table->rt = sfrt_dir_new(mem_cap, 8, 4,4,4,4,4,4,4,4);
-        break;
-    /* There is no reason to use 2x16 except for benchmarking and
-     * comparison purposes. */
-    case DIR_2x16:
-        table->rt = sfrt_dir_new(mem_cap, 16,
-            2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2);
-        break;
-    case DIR_16_4x4_16x5_4x4:
-        table->rt = sfrt_dir_new(mem_cap, 5, 16,4,4,4,4);
-        table->rt6 = sfrt_dir_new(mem_cap, 14, 16,4,4,4,4,16,16,16,16,16,4,4,4,4);
-        break;
-    case DIR_16x7_4x4:
-        table->rt = sfrt_dir_new(mem_cap, 5, 16,4,4,4,4);
-        table->rt6 = sfrt_dir_new(mem_cap, 11, 16,16,16,16,16,16,16,4,4,4,4);
-        break;
-    case DIR_16x8:
-        table->rt = sfrt_dir_new(mem_cap, 2, 16,16);
-        table->rt6 = sfrt_dir_new(mem_cap, 8, 16,16,16,16,16,16,16,16);
-        break;
-    case DIR_8x16:
-        table->rt = sfrt_dir_new(mem_cap, 4, 16,8,4,4);
-        table->rt6 = sfrt_dir_new(mem_cap, 16,
-            8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8);
-        break;
-    }
-
-    if ((!table->rt) || (!table->rt6))
-    {
-        if (table->rt)
-            table->free(table->rt);
-        if (table->rt6)
-            table->free(table->rt6);
-        snort_free(table->data);
-        snort_free(table);
-        return nullptr;
-    }
-
-    return table;
-}
-
-/* Free lookup table */
-void sfrt_free(table_t* table)
-{
-    if (!table)
-    {
-        /* What are you calling me for? */
-        return;
-    }
-
-    if (!table->data)
-    {
-        /* This really really should not have happened */
-    }
-    else
-    {
-        snort_free(table->data);
-    }
-
-    if (!table->rt)
-    {
-        /* This should not have happened either */
-    }
-    else
-    {
-        table->free(table->rt);
-    }
-
-    if (!table->rt6)
-    {
-        /* This should not have happened either */
-    }
-    else
-    {
-        table->free(table->rt6);
-    }
-
-    snort_free(table);
-}
-
-/* Perform a lookup on value contained in "ip" */
-GENERIC sfrt_lookup(const SfIp* ip, table_t* table)
-{
-    tuple_t tuple;
-    const uint32_t* addr;
-    int numAddrDwords;
-    void* rt ;
-
-    if (!ip || !table || !table->lookup)
-        return nullptr;
-
-    if (ip->is_ip4())
-    {
-        addr = ip->get_ip4_ptr();
-        numAddrDwords = 1;
-        rt = table->rt;
-    }
-    else
-    {
-        addr = ip->get_ip6_ptr();
-        numAddrDwords = 4;
-        rt = table->rt6;
-    }
-
-    if (!rt)
-        return nullptr;
-
-    tuple = table->lookup(addr, numAddrDwords, rt);
-
-    if (tuple.index >= table->max_size)
-        return nullptr;
-
-    return table->data[tuple.index];
-}
-
-void sfrt_cleanup(table_t* table, sfrt_iterator_callback cleanup_func)
-{
-    uint32_t index, count;
-
-    if (!table)
-        return;
-
-    for (index = 0, count = 0;
-        index < table->max_size;
-        index++)
-    {
-        if (table->data[index])
-        {
-            cleanup_func(table->data[index]);
-
-            /* cleanup_func is supposed to free memory associated with this
-             * table->data[index].  Set that to null.
-             */
-            table->data[index] = nullptr;
-
-            if (++count == table->num_ent)
-                break;
-        }
-    }
-}
-
-GENERIC sfrt_search(const SfIp* ip, unsigned char len, table_t* table)
-{
-    const uint32_t* addr;
-    int numAddrDwords;
-    tuple_t tuple;
-    void* rt;
-
-    if ((ip == nullptr) || (table == nullptr) || (len == 0))
-        return nullptr;
-
-    if (ip->is_ip4())
-    {
-        addr = ip->get_ip4_ptr();
-        numAddrDwords = 1;
-        rt = table->rt;
-    }
-    else if (ip->is_ip6())
-    {
-        addr = ip->get_ip6_ptr();
-        numAddrDwords = 4;
-        rt = table->rt6;
-    }
-    else
-        return nullptr;
-
-    // FIXIT-RC IPv6 not yet supported by sfrt?
-    if (table->ip_type == IPv6)
-        return nullptr;
-
-    if ( (table->ip_type == IPv4 && len > 32) ||
-        (table->ip_type == IPv6 && len > 128) )
-    {
-        return nullptr;
-    }
-
-    tuple = table->lookup(addr, numAddrDwords, rt);
-
-    if (tuple.length != len)
-        return nullptr;
-
-    return table->data[tuple.index];
-}
-
-/* Insert "ip", of length "len", into "table", and have it point to "ptr" */
-int sfrt_insert(SfCidr* cidr, unsigned char len, GENERIC ptr,
-    int behavior, table_t* table)
-{
-    const uint32_t* addr;
-    const SfIp* ip;
-    int numAddrDwords;
-    int index;
-    int newIndex = 0;
-    int res;
-    tuple_t tuple;
-    void* rt;
-
-    if (!cidr)
-    {
-        return RT_INSERT_FAILURE;
-    }
-
-    if (len == 0)
-        return RT_INSERT_FAILURE;
-
-    if (!table || !table->insert || !table->data || !table->lookup)
-    {
-        return RT_INSERT_FAILURE;
-    }
-
-    if ( (table->ip_type == IPv4 && len > 32) ||
-        (table->ip_type == IPv6 && len > 128) )
-    {
-        return RT_INSERT_FAILURE;
-    }
-
-    /* Check if we can reuse an existing data table entry by
-     * seeing if there is an existing entry with the same length. */
-    ip = cidr->get_addr();
-    if (ip->is_ip4())
-    {
-        if (len < 96)
-            return RT_INSERT_FAILURE;
-        len -= 96;
-        addr = ip->get_ip4_ptr();
-        numAddrDwords = 1;
-        rt = table->rt;
-    }
-    else if (ip->is_ip6())
-    {
-        addr = ip->get_ip6_ptr();
-        numAddrDwords = 4;
-        rt = table->rt6;
-    }
-    else
-        return RT_INSERT_FAILURE;
-
-    tuple = table->lookup(addr, numAddrDwords, rt);
-
-    if (tuple.length != len)
-    {
-        if ( table->num_ent >= table->max_size)
-        {
-            return RT_POLICY_TABLE_EXCEEDED;
-        }
-
-        index = newIndex = allocateTableIndex(table);
-        if (!index)
-            return RT_POLICY_TABLE_EXCEEDED;
-    }
-    else
-    {
-        index = tuple.index;
-    }
-
-    /* The actual value that is looked-up is an index
-     * into the data table. */
-    res = table->insert(addr, numAddrDwords, len, index, behavior, rt);
-
-    if ((res == RT_SUCCESS) && newIndex)
-    {
-        table->num_ent++;
-        table->data[ index ] = ptr;
-    }
-
-    return res;
-}
-/** Pretty print table
- * Pretty print sfrt table.
- * @param table - routing table.
- */
-void sfrt_print(table_t* table)
-{
-    if (!table || !table->print )
-    {
-        return;
-    }
-
-    if (table->rt)
-        table->print(table->rt);
-    if (table->rt6)
-        table->print(table->rt6);
-}
-
-uint32_t sfrt_num_entries(table_t* table)
-{
-    if (!table || !table->rt || !table->allocated)
-    {
-        return 0;
-    }
-
-    /* There is always a root node, so subtract 1 for it */
-    return table->num_ent - 1;
-}
-
-uint32_t sfrt_usage(table_t* table)
-{
-    uint32_t usage;
-    if (!table || !table->rt || !table->allocated || !table->usage)
-    {
-        return 0;
-    }
-
-    usage = table->allocated + table->usage(table->rt);
-
-    if (table->rt6)
-    {
-        usage += table->usage(table->rt6);
-    }
-
-    return usage;
-}
-
-/** Remove subnet from sfrt table.
- * Remove subnet identified by ip/len and return associated data.
- * @param ip - IP address
- * @param len - length of netmask
- * @param ptr - void ** that is set to value associated with subnet
- * @param behavior - RT_FAVOR_SPECIFIC or RT_FAVOR_TIME
- * @note - For RT_FAVOR_TIME behavior, if partial subnet is removed then table->data[x] is nulled. Any remaining entries
- * will then point to null data. This can cause hung or crosslinked data. RT_FAVOR_SPECIFIC does not have this drawback.
- * hung or crosslinked entries.
- */
-int sfrt_remove(SfCidr* cidr, unsigned char len, GENERIC* ptr,
-    int behavior, table_t* table)
-{
-    const uint32_t* addr;
-    const SfIp* ip;
-    int numAddrDwords;
-    int index;
-    void* rt;
-
-    if (!cidr)
-    {
-        return RT_REMOVE_FAILURE;
-    }
-
-    if (len == 0)
-        return RT_REMOVE_FAILURE;
-
-    if (!table || !table->data || !table->remove || !table->lookup )
-        return RT_REMOVE_FAILURE;
-
-    if ( (table->ip_type == IPv4 && len > 32) ||
-        (table->ip_type == IPv6 && len > 128) )
-    {
-        return RT_REMOVE_FAILURE;
-    }
-
-    ip = cidr->get_addr();
-    if (ip->is_ip4())
-    {
-        if (len < 96)
-            return RT_REMOVE_FAILURE;
-        len -= 96;
-        addr = ip->get_ip4_ptr();
-        numAddrDwords = 1;
-        rt = table->rt;
-    }
-    else if (ip->is_ip6())
-    {
-        addr = ip->get_ip6_ptr();
-        numAddrDwords = 4;
-        rt = table->rt6;
-    }
-    else
-        return RT_REMOVE_FAILURE;
-
-    /* The actual value that is looked-up is an index
-     * into the data table. */
-    index = table->remove(addr, numAddrDwords, len, behavior, rt);
-
-    /* Remove value into policy table. See TBD in function header*/
-    if (index)
-    {
-        *ptr = table->data[ index ];
-        table->data[ index ] = nullptr;
-        table->num_ent--;
-    }
-
-    return RT_SUCCESS;
-}
-
-/**allocate first unused index value. With delete operation, index values can be non-contiguous.
- * Index 0 is error in this function but this is valid entry in table->data that is used
- * for failure case. Calling function must check for 0 and take appropriate error action.
- */
-static inline int allocateTableIndex(table_t* table)
-{
-    uint32_t index;
-
-    // 0 is special index for failed entries.
-    for (index = table->lastAllocatedIndex+1;
-        index != table->lastAllocatedIndex;
-        index = (index+1) % table->max_size)
-    {
-        if (index && !table->data[index])
-        {
-            table->lastAllocatedIndex = index;
-            return index;
-        }
-    }
-    return 0;
-}
-
index 5e6ee447cd3d12f5414717077845095fdbc1c80f..f1dd644b7e71b260f0eb358098c774de32906a2b 100644 (file)
@@ -40,10 +40,12 @@ struct tuple_t
     word length;
 };
 
-#include "sfrt/sfrt_dir.h"
-
 enum types
 {
+#if 0
+    // supporting code for these types (and RT_FAVOR_* below) is
+    // disabled since it is not used. not deleting in case we need
+    // switch types at some point. see sfrt_*.cc.
     DIR_24_8,
     DIR_16x2,
     DIR_16_8x2,
@@ -54,6 +56,7 @@ enum types
     DIR_16_4x4_16x5_4x4,
     DIR_16x7_4x4,
     DIR_16x8,
+#endif
     DIR_8x16,
     IPv4,
     IPv6
@@ -72,64 +75,12 @@ enum return_codes
 
 enum
 {
+#if 0
     RT_FAVOR_TIME,
     RT_FAVOR_SPECIFIC,
+#endif
     RT_FAVOR_ALL
 };
 
-extern const char* rt_error_messages[];
-
-typedef int (* table_insert)(
-    const uint32_t* addr, int numAddrDwords, int len, word index, int behavior, GENERIC);
-
-typedef word (* table_remove)(
-    const uint32_t* addr, int numAddrDwords, int len, int behavior, GENERIC);
-
-typedef tuple_t (* table_lookup)(const uint32_t* addr, int numAddrDwords, GENERIC);
-
-typedef uint32_t (* table_usage)(GENERIC);
-typedef void (* table_print)(GENERIC);
-typedef void (* table_free)(GENERIC);
-
-// Master table struct.  Abstracts DIR and LC-trie methods
-struct table_t
-{
-    GENERIC* data;               // data table. Each IP points to an entry here
-    uint32_t num_ent;            // Number of entries in the policy table
-    uint32_t max_size;           // Max size of policies array
-    uint32_t lastAllocatedIndex; // Index allocated last. Search for unused index
-                                 // starts from this value and then wraps around at max_size.
-    char ip_type;                // Only IPs of this family will be used
-    char table_type;
-    uint32_t allocated;
-
-    void* rt;                    // Actual "routing" table
-    void* rt6;                   // Actual "routing" table
-
-    table_insert insert;
-    table_remove remove;
-    table_lookup lookup;
-    table_usage usage;
-    table_print print;
-    table_free free;
-};
-
-// Abstracted routing table API
-table_t* sfrt_new(char type, char ip_type, long data_size, uint32_t mem_cap);
-void sfrt_free(table_t*);
-
-GENERIC sfrt_lookup(const snort::SfIp*, table_t*);
-GENERIC sfrt_search(const snort::SfIp*, unsigned char len, table_t*);
-
-typedef void (* sfrt_iterator_callback)(void*);
-void sfrt_cleanup(table_t*, sfrt_iterator_callback);
-
-int sfrt_insert(snort::SfCidr*, unsigned char len, GENERIC, int behavior, table_t*);
-int sfrt_remove(snort::SfCidr*, unsigned char len, GENERIC*, int behavior, table_t*);
-
-uint32_t sfrt_usage(table_t*);
-void sfrt_print(table_t*);
-uint32_t sfrt_num_entries(table_t*);
-
 #endif
 
diff --git a/src/sfrt/sfrt_dir.cc b/src/sfrt/sfrt_dir.cc
deleted file mode 100644 (file)
index 3fc9660..0000000
+++ /dev/null
@@ -1,766 +0,0 @@
-//--------------------------------------------------------------------------
-// Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2006-2013 Sourcefire, Inc.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License Version 2 as published
-// by the Free Software Foundation.  You may not use, modify or distribute
-// this program under any other version of the GNU General Public License.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-//--------------------------------------------------------------------------
-
-/*
- * @file    sfdir.c
- * @author  Adam Keeton <akeeton@sourcefire.com>
- * @date    Thu July 20 10:16:26 EDT 2006
- *
- * The implementation uses an multibit-trie that is similar to Gupta et-al's
- * DIR-n-m.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "sfrt.h"  // FIXIT-L these includes are circular
-#include "sfrt_dir.h"
-
-#include <cstdarg>
-
-#include "utils/util.h"
-
-typedef struct
-{
-    const uint32_t* addr;
-    int bits;
-} IPLOOKUP;
-
-/* Create new "sub" table of 2^width entries */
-static dir_sub_table_t* _sub_table_new(dir_table_t* root, uint32_t dimension,
-    uint32_t prefill, uint32_t bit_length)
-{
-    int width = root->dimensions[dimension];
-    int len = 1 << width;
-    int index;
-    dir_sub_table_t* sub;
-
-    /* Check if creating this node will exceed the memory cap.
-     * The symbols in the conditional (other than cap), come from the
-     * allocs below. */
-    if ( root->mem_cap < ( root->allocated +
-        sizeof(dir_sub_table_t) +
-        sizeof(word) * len + len ) ||
-        bit_length > 128)
-    {
-        return nullptr;
-    }
-
-    /* Set up the initial prefilled "sub table" */
-    sub = (dir_sub_table_t*)snort_alloc(sizeof(dir_sub_table_t));
-
-    /* This keeps the width readily available rather than recalculating it
-     * from the number of entries during an insert or lookup */
-    sub->width = width;
-
-    /* need 2^sub->width entries */
-    sub->num_entries = len;
-    sub->entries = (word*)snort_alloc(sizeof(word) * sub->num_entries);
-
-    /* A "length" needs to be stored with each entry above.  The length refers
-     * to how specific the insertion that set the entry was.  It is necessary
-     * so that the entry is not overwritten by less general routing
-     * information if "RT_FAVOR_SPECIFIC" insertions are being performed. */
-    sub->lengths = (uint8_t*)snort_alloc(sub->num_entries);
-
-    /* Can't use memset here since prefill is multibyte */
-    for (index = 0; index < sub->num_entries; index++)
-    {
-        sub->entries[index] = prefill;
-        sub->lengths[index] = (uint8_t)bit_length;
-    }
-
-    sub->cur_num = 0;
-
-    if (prefill)
-        sub->filledEntries = sub->num_entries;
-    else
-        sub->filledEntries = 0;
-
-    root->allocated += sizeof(dir_sub_table_t) + sizeof(word) * sub->num_entries +
-        sub->num_entries;
-
-    root->cur_num++;
-
-    return sub;
-}
-
-/* Create new dir-n-m root table with 'count' depth */
-dir_table_t* sfrt_dir_new(uint32_t mem_cap, int count,...)
-{
-    dir_table_t* table = (dir_table_t*)snort_alloc(sizeof(dir_table_t));
-
-    table->allocated = 0;
-    table->dimensions = (int*)snort_alloc(sizeof(int)*count);
-    table->dim_size = count;
-
-    va_list ap;
-    va_start(ap, count);
-
-    for (int index=0; index < count; index++)
-        table->dimensions[index] = va_arg(ap, int);
-
-    va_end(ap);
-
-    table->mem_cap = mem_cap;
-
-    table->cur_num = 0;
-
-    table->sub_table = _sub_table_new(table, 0, 0, 0);
-
-    if (!table->sub_table)
-    {
-        snort_free(table->dimensions);
-        snort_free(table);
-        return nullptr;
-    }
-
-    table->allocated += sizeof(dir_table_t) + sizeof(int)*count;
-
-    return table;
-}
-
-/* Traverse "sub" tables, freeing each */
-static void _sub_table_free(uint32_t* allocated, dir_sub_table_t* sub)
-{
-    int index;
-
-    sub->cur_num--;
-
-    for (index=0; index < sub->num_entries; index++)
-    {
-        /* The following condition will only be true if
-         * this entry is a pointer  */
-        if ( !sub->lengths[index] && sub->entries[index] )
-        {
-            _sub_table_free(allocated, (dir_sub_table_t*)sub->entries[index]);
-        }
-    }
-
-    if (sub->entries)
-    {
-        /* This probably does not need to be checked
-         * since if it was not allocated, we would have errored out
-         * in _sub_table_new */
-        snort_free(sub->entries);
-
-        *allocated -= sizeof(word) * sub->num_entries;
-    }
-
-    if (sub->lengths)
-    {
-        /* This probably does not need to be checked
-         * since if it was not allocated, we would have errored out
-         * in _sub_table_new */
-        snort_free(sub->lengths);
-
-        *allocated -= sub->num_entries;
-    }
-
-    snort_free(sub);
-
-    *allocated -= sizeof(dir_sub_table_t);
-}
-
-/* Free the DIR-n-m structure */
-void sfrt_dir_free(void* tbl)
-{
-    dir_table_t* table = (dir_table_t*)tbl;
-
-    if (!table)
-    {
-        return;
-    }
-
-    if (table->sub_table)
-    {
-        _sub_table_free(&table->allocated, table->sub_table);
-    }
-
-    if (table->dimensions)
-    {
-        snort_free(table->dimensions);
-    }
-
-    snort_free(table);
-}
-
-static inline void _dir_fill_all(uint32_t* allocated, uint32_t index, uint32_t fill,
-    word length, uint32_t val, dir_sub_table_t* table)
-{
-    /* Fill entries */
-    for (; index < fill; index++)
-    {
-        /* Before overwriting this entry, verify there's not an existing
-         * pointer ... otherwise free it to avoid a huge memory leak. */
-        if (table->entries[index])
-        {
-            if (!table->lengths[index])
-            {
-                _sub_table_free(allocated, (dir_sub_table_t*)table->entries[index]);
-            }
-        }
-        else
-        {
-            table->filledEntries++;
-        }
-
-        table->entries[index] = val;
-        table->lengths[index] = (uint8_t)length;
-    }
-}
-
-static inline void _dir_fill_less_specific(int index, int fill,
-    word length, uint32_t val, dir_sub_table_t* table)
-{
-    /* Fill entries */
-    for (; index < fill; index++)
-    {
-        /* If we encounter a pointer, and we're inserting at this level, we
-         * automatically know that this entry refers to more specific
-         * information.  However, there might only be one more specific entry
-         * in the entire block, meaning the rest must be filled.
-         *
-         * For instance, imagine a 24-8 with 1.2.3/24 -> A and 1.2.3.4/32 -> B
-         * There will be a pointer at 1.2.3 in the first table. The second
-         * table needs to have 255 entries pointing A, and 1 entry pointing to
-         * B.
-         *
-         * Therefore, recurse to this next level. */
-
-        if ( !table->lengths[index] && table->entries[index])
-        {
-            dir_sub_table_t* next = (dir_sub_table_t*)table->entries[index];
-            _dir_fill_less_specific(0, 1 << next->width, length, val, next);
-        }
-        else if (length >= (word)table->lengths[index])
-        {
-            if (!table->entries[index])
-            {
-                table->filledEntries++;
-            }
-            table->entries[index] = val;
-            table->lengths[index] = (char)length;
-        }
-    }
-}
-
-/*Remove entries all this level and discard any more specific entries.
- *
- * @note RT_FAVOR_TIME behavior can cause hung or crosslinked entries if part of a subnet
- * (which was added) are deleted. Same issue is there when a more general subnet overwrites
- * a specific subnet. table->data[] entry for more specific subnet is not cleared.
- *
- * @note RT_FAVOR_TIME can cause orphaned table->data[] entries if the entire subnet
- * is replaced by more specific subnets.
- */
-static inline uint32_t _dir_remove_all(uint32_t* allocated, uint32_t index, uint32_t fill,
-    word length, dir_sub_table_t* table)
-{
-    uint32_t valueIndex = 0;
-
-    /* Fill entries */
-    for (; index < fill; index++)
-    {
-        /* Before overwriting this entry, verify there's not an existing
-         * pointer ... otherwise free it to avoid a huge memory leak. */
-        if (table->entries[index])
-        {
-            if (!table->lengths[index])
-            {
-                _sub_table_free(allocated, (dir_sub_table_t*)table->entries[index]);
-            }
-
-            if (length == (word)table->lengths[index])
-            {
-                valueIndex = table->entries[index];
-            }
-
-            table->filledEntries--;
-
-            //zero value here works since sfrt uses 0 for failed entries.
-            table->entries[index] = 0;
-            table->lengths[index] = 0;
-        }
-    }
-
-    return valueIndex;
-}
-
-/**Remove entries which match in address/length in all subtables.
- * @note RT_FAVOR_SPECIFIC can cause orphaned table->data[] entries if the entire subnet
- * is replaced by more specific subnets.
- */
-static inline uint32_t _dir_remove_less_specific(uint32_t* allocated, int index, int fill,
-    word length, dir_sub_table_t* table)
-{
-    uint32_t valueIndexRet = 0;
-
-    for (; index < fill; index++)
-    {
-        if ( !table->lengths[index] && table->entries[index])
-        {
-            dir_sub_table_t* next = (dir_sub_table_t*)table->entries[index];
-            uint32_t valueIndex = _dir_remove_less_specific(allocated, 0, 1 << next->width, length, next);
-            if (valueIndex)
-            {
-                valueIndexRet = valueIndex;
-            }
-
-            if (!next->filledEntries)    //table can be collapsed.
-            {
-                _sub_table_free(allocated, next);
-                table->entries[index] = 0;
-                table->lengths[index] = 0;
-                table->filledEntries--;
-            }
-        }
-        else if (length == (word)table->lengths[index])
-        {
-            if (table->entries[index])
-            {
-                table->filledEntries--;
-                valueIndexRet = table->entries[index];
-            }
-            table->entries[index] = 0;
-            table->lengths[index] = 0;
-        }
-    }
-
-    return valueIndexRet;
-}
-
-/* Sub table insertion
- * This is called by dir_insert and recursively to find the the sub table
- * that should house the value "ptr"
- * @param ip        IP address structure
- * @param cur_len   Number of bits of the IP left at this depth
- * @param length    Number of bits of the IP used to specify this CIDR
- * @param ptr       Information to be associated with this IP range
- * @param master_table    The table that describes all, returned by dir_new */
-static int _dir_sub_insert(IPLOOKUP* ip, int length, int cur_len, GENERIC ptr,
-    int current_depth, int behavior,
-    dir_sub_table_t* sub_table, dir_table_t* root_table)
-{
-    word index;
-    {
-        uint32_t local_index, i;
-        /* need to handle bits usage across multiple 32bit vals within IPv6. */
-        if (ip->bits < 32)
-        {
-            i=0;
-        }
-        else if (ip->bits < 64)
-        {
-            i=1;
-        }
-        else if (ip->bits < 96)
-        {
-            i=2;
-        }
-        else
-        {
-            i=3;
-        }
-        local_index = ip->addr[i] << (ip->bits % 32);
-        index = local_index >> (sizeof(local_index) * 8 - sub_table->width);
-    }
-
-    /* Check if this is the last table to traverse to */
-    if (sub_table->width >= cur_len)
-    {
-        /* Calculate how many entries need to be filled
-         * in this table. If the table is 24 bits wide, and the entry
-         * is 20 bytes long, 2^4 entries need to be filled. */
-        uint32_t fill = 1 << (sub_table->width - cur_len);
-
-        index = (index >> (sub_table->width - cur_len)) <<
-            (sub_table->width - cur_len);
-
-        fill += index;
-
-        /* Favor most recent CIDR */
-        if (behavior == RT_FAVOR_TIME)
-        {
-            _dir_fill_all(&root_table->allocated, index, fill, length,
-                (word)ptr, sub_table);
-        }
-        /* Fill over less specific CIDR */
-        else
-        {
-            _dir_fill_less_specific(index, fill, length, (word)ptr, sub_table);
-        }
-    }
-    /* Need to traverse to a sub-table */
-    else
-    {
-        dir_sub_table_t* next_sub =
-            (dir_sub_table_t*)sub_table->entries[index];
-
-        /* Check if we need to alloc a new sub table.
-         * If next_sub was 0/null, there's no entry at this index
-         * If the length is non-zero, there is an entry */
-        if (!next_sub || sub_table->lengths[index])
-        {
-            if ( root_table->dim_size <= current_depth )
-            {
-                return RT_INSERT_FAILURE;
-            }
-
-            sub_table->entries[index] =
-                (word)_sub_table_new(root_table, current_depth+1,
-                (word)next_sub, sub_table->lengths[index]);
-
-            if (!next_sub)
-            {
-                sub_table->filledEntries++;
-            }
-
-            sub_table->cur_num++;
-
-            sub_table->lengths[index] = 0;
-
-            next_sub = (dir_sub_table_t*)sub_table->entries[index];
-
-            if (!next_sub)
-            {
-                return MEM_ALLOC_FAILURE;
-            }
-        }
-        /* Recurse to next level.  Rightshift off appropriate number of
-         * bits and update the length accordingly. */
-        ip->bits += sub_table->width;
-        return (_dir_sub_insert(ip, length,
-               cur_len - sub_table->width, ptr, current_depth+1,
-               behavior, next_sub, root_table));
-    }
-
-    return RT_SUCCESS;
-}
-
-/* Insert entry into DIR-n-m tables */
-int sfrt_dir_insert(const uint32_t* addr, int /* numAddrDwords */, int len, word data_index,
-    int behavior, void* table)
-{
-    dir_table_t* root = (dir_table_t*)table;
-    uint32_t h_addr[4];
-    IPLOOKUP iplu;
-    iplu.addr = h_addr;
-    iplu.bits = 0;
-
-    /* Validate arguments */
-    if (!root || !root->sub_table)
-    {
-        return DIR_INSERT_FAILURE;
-    }
-
-    h_addr[0] = ntohl(addr[0]);
-    if (len > 96)
-    {
-        h_addr[1] = ntohl(addr[1]);
-        h_addr[2] = ntohl(addr[2]);
-        h_addr[3] = ntohl(addr[3]);
-    }
-    else if (len > 64)
-    {
-        h_addr[1] = ntohl(addr[1]);
-        h_addr[2] = ntohl(addr[2]);
-        h_addr[3] = 0;
-    }
-    else if (len > 32)
-    {
-        h_addr[1] = ntohl(addr[1]);
-        h_addr[2] = 0;
-        h_addr[3] = 0;
-    }
-    else
-    {
-        h_addr[1] = 0;
-        h_addr[2] = 0;
-        h_addr[3] = 0;
-    }
-
-    /* Find the sub table in which to insert */
-    return _dir_sub_insert(&iplu, len, len, (GENERIC)data_index,
-        0, behavior, root->sub_table, root);
-}
-
-/* Traverse sub tables looking for match
-   Called by dir_lookup and recursively */
-static tuple_t _dir_sub_lookup(IPLOOKUP* ip, dir_sub_table_t* table)
-{
-    word index;
-    {
-        uint32_t local_index, i;
-        /* need to handle bits usage across multiple 32bit vals within IPv6. */
-        if (ip->bits < 32 )
-        {
-            i=0;
-        }
-        else if (ip->bits < 64)
-        {
-            i=1;
-        }
-        else if (ip->bits < 96)
-        {
-            i=2;
-        }
-        else
-        {
-            i=3;
-        }
-        local_index = ip->addr[i] << (ip->bits % 32);
-        index = local_index >> (sizeof(local_index) * 8 - table->width);
-    }
-
-    if ( !table->entries[index] || table->lengths[index] )
-    {
-        tuple_t ret;
-        ret.index = table->entries[index];
-        ret.length = (word)table->lengths[index];
-
-        return ret;
-    }
-
-    ip->bits += table->width;
-    return _dir_sub_lookup(ip, (dir_sub_table_t*)table->entries[index]);
-}
-
-/* Lookup information associated with the value "ip" */
-tuple_t sfrt_dir_lookup(const uint32_t* addr, int numAddrDwords, void* tbl)
-{
-    dir_table_t* root = (dir_table_t*)tbl;
-    uint32_t h_addr[4];
-    int i;
-    IPLOOKUP iplu;
-    iplu.addr = h_addr;
-    iplu.bits = 0;
-
-    if (!root || !root->sub_table || numAddrDwords < 1)
-    {
-        tuple_t ret = { 0, 0 };
-
-        return ret;
-    }
-
-    for (i= 0 ; i < numAddrDwords; i++)
-        h_addr[i] = ntohl(addr[i]);
-
-    return _dir_sub_lookup(&iplu, root->sub_table);
-}
-
-uint32_t sfrt_dir_usage(void* table)
-{
-    if (!table)
-    {
-        return 0;
-    }
-
-    return ((dir_table_t*)(table))->allocated;
-}
-
-static void _sub_table_print(dir_sub_table_t* sub, uint32_t level, dir_table_t* table)
-{
-    int index;
-
-    char label[100];
-
-    memset(label, ' ', sizeof(label));
-    label[level*5] = '\0';
-
-    printf("%sCurrent Nodes: %d, Filled Entries: %d, table Width: %d\n", label, sub->cur_num,
-        sub->filledEntries, sub->width);
-    for (index=0; index < sub->num_entries; index++)
-    {
-        if (sub->lengths[index] || sub->entries[index])
-            printf("%sIndex: %d, Length: %d, dataIndex: %u\n", label, index, sub->lengths[index],
-                (uint32_t)sub->entries[index]);
-
-        if ( !sub->lengths[index] && sub->entries[index] )
-        {
-            _sub_table_print((dir_sub_table_t*)sub->entries[index], level+1, table);
-        }
-    }
-}
-
-/* Print a table.
- * Prints a table and its subtable. This is used for debugging purpose only.
- * @param table The table that describes all, returned by dir_new
- */
-void sfrt_dir_print(void* tbl)
-{
-    dir_table_t* table = (dir_table_t*)tbl;
-
-    if (!table)
-    {
-        return;
-    }
-
-    printf ("Nodes in use: %d\n", table->cur_num);
-    if (table->sub_table)
-    {
-        _sub_table_print(table->sub_table, 1, table);
-    }
-}
-
-/* Sub table removal
- * Recursive function to drill down to subnet table and remove entries.
- * @param ip        IP address structure
- * @param length    Number of bits of the IP used to specify this CIDR
- * @param cur_len   Number of bits of the IP left at this depth
- * @param current_depth Number of levels down from root_table.
- * @param behavior  RT_FAVOR_SPECIFIC or RT_FAVOR_TIME
- * @param root_table  The table that describes all, returned by dir_new
- * @returns index of entry removed. Returns 0, which is a valid index, as failure code.
- * Calling function should treat 0 index as failure case.*/
-
-static int _dir_sub_remove(IPLOOKUP* ip, int length, int cur_len,
-    int current_depth, int behavior,
-    dir_sub_table_t* sub_table, dir_table_t* root_table)
-{
-    word index;
-    uint32_t valueIndex = 0;
-
-    {
-        uint32_t local_index, i;
-        /* need to handle bits usage across multiple 32bit vals within IPv6. */
-        if (ip->bits < 32)
-        {
-            i=0;
-        }
-        else if (ip->bits < 64)
-        {
-            i=1;
-        }
-        else if (ip->bits < 96)
-        {
-            i=2;
-        }
-        else
-        {
-            i=3;
-        }
-        local_index = ip->addr[i] << (ip->bits % 32);
-        index = local_index >> (sizeof(local_index) * 8 - sub_table->width);
-    }
-
-    /* Check if this is the last table to traverse to */
-    if (sub_table->width >= cur_len)
-    {
-        /* Calculate how many entries need to be removed (filled with 0)
-         * in this table. If the table is 24 bits wide, and the entry
-         * is 20 bytes long, 2^4 entries need to be filled. */
-        uint32_t fill = 1 << (sub_table->width - cur_len);
-
-        index = (index >> (sub_table->width - cur_len)) <<
-            (sub_table->width - cur_len);
-
-        fill += index;
-
-        /* Remove and overwrite without considering CIDR specificity*/
-        if (behavior == RT_FAVOR_TIME)
-        {
-            valueIndex = _dir_remove_all(&root_table->allocated, index, fill, length, sub_table);
-        }
-        /* Remove and overwrite only less specific CIDR */
-        else
-        {
-            valueIndex = _dir_remove_less_specific(&root_table->allocated, index, fill, length,
-                sub_table);
-        }
-    }
-    else
-    {
-        /* traverse to a next sub-table down*/
-
-        dir_sub_table_t* next_sub = (dir_sub_table_t*)sub_table->entries[index];
-
-        /*subtable was never added. */
-        if (!next_sub || sub_table->lengths[index])
-        {
-            return 0;
-        }
-        /* Recurse to next level.  Rightshift off appropriate number of
-         * bits and update the length accordingly. */
-        ip->bits += sub_table->width;
-        valueIndex = _dir_sub_remove(ip, length,
-            cur_len - sub_table->width, current_depth+1,
-            behavior, next_sub, root_table);
-        if (!next_sub->filledEntries)
-        {
-            _sub_table_free(&root_table->allocated, next_sub);
-            sub_table->entries[index] = 0;
-            sub_table->lengths[index] = 0;
-            sub_table->filledEntries--;
-            root_table->cur_num--;
-        }
-    }
-
-    return valueIndex;
-}
-
-/* Remove entry into DIR-n-m tables
- * @return index to data or 0 on failure. Calling function should check for 0 since
- * this is valid index for failed operation.
- */
-word sfrt_dir_remove(const uint32_t* addr, int /* numAddrDwords */, int len, int behavior, void* table)
-{
-    dir_table_t* root = (dir_table_t*)table;
-    uint32_t h_addr[4];
-    IPLOOKUP iplu;
-    iplu.addr = h_addr;
-    iplu.bits = 0;
-
-    /* Validate arguments */
-    if (!root || !root->sub_table)
-    {
-        return 0;
-    }
-
-    h_addr[0] = ntohl(addr[0]);
-    if (len > 96)
-    {
-        h_addr[1] = ntohl(addr[1]);
-        h_addr[2] = ntohl(addr[2]);
-        h_addr[3] = ntohl(addr[3]);
-    }
-    else if (len > 64)
-    {
-        h_addr[1] = ntohl(addr[1]);
-        h_addr[2] = ntohl(addr[2]);
-        h_addr[3] = 0;
-    }
-    else if (len > 32)
-    {
-        h_addr[1] = ntohl(addr[1]);
-        h_addr[2] = 0;
-        h_addr[3] = 0;
-    }
-    else
-    {
-        h_addr[1] = 0;
-        h_addr[2] = 0;
-        h_addr[3] = 0;
-    }
-
-    /* Find the sub table in which to remove */
-    return _dir_sub_remove(&iplu, len, len, 0, behavior, root->sub_table, root);
-}
-
diff --git a/src/sfrt/sfrt_dir.h b/src/sfrt/sfrt_dir.h
deleted file mode 100644 (file)
index 70ec503..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-//--------------------------------------------------------------------------
-// Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2006-2013 Sourcefire, Inc.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License Version 2 as published
-// by the Free Software Foundation.  You may not use, modify or distribute
-// this program under any other version of the GNU General Public License.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-//--------------------------------------------------------------------------
-
-/*
- * @file    sfdir.h
- * @author  Adam Keeton <akeeton@sourcefire.com>
- * @date    Thu July 20 10:16:26 EDT 2006
- *
- */
-
-#ifndef SFRT_DIR_H
-#define SFRT_DIR_H
-
- // The implementation uses an multibit-trie that is similar to Gupta et-al's
- // DIR-n-m.
-
-#include <cstdint>
-
-/*******************************************************************/
-/* DIR-n-m data structures
- * Each table in the DIR-n-m method is represented by a
- * dir_sub_table_t.  They are managed by a dir_table_t. */
-typedef struct
-{
-    word* entries;
-    uint8_t* lengths;
-    int num_entries; /* Number of entries in this table */
-    int width;       /* width of this table. */
-                     /* While one determines the other, this way fewer
-                      * calculations are needed at runtime, since both
-                      * are used. */
-    int cur_num;     /* Present number of used nodes */
-
-    /** number of entries filled including children sub_tables. This is used
-     * for freeing sub_tables when all entries are freed by delete operation.
-     */
-    int filledEntries;
-} dir_sub_table_t;
-
-/* Master data structure for the DIR-n-m derivative */
-typedef struct
-{
-    int* dimensions;    /* DIR-n-m will consist of any number of arbitrarily
-                         * long tables. This variable keeps track of the
-                         * dimensions */
-    int dim_size;       /* And this variable keeps track of 'dimensions''s
-                         * dimensions! */
-    uint32_t mem_cap;  /* User-defined maximum memory that can be allocated
-                         * for the DIR-n-m derivative */
-
-    int cur_num;        /* Present number of used nodes */
-
-    uint32_t allocated;
-
-    dir_sub_table_t* sub_table;
-} dir_table_t;
-
-/******************************************************************
-   DIR-n-m functions, these are not intended to be called directly */
-dir_table_t* sfrt_dir_new(uint32_t mem_cap, int count,...);
-void sfrt_dir_free(void*);
-tuple_t sfrt_dir_lookup(const uint32_t* addr, int numAddrDwords, void* table);
-int sfrt_dir_insert(const uint32_t* addr, int numAddrDwords, int len, word data_index,
-    int behavior, void* table);
-uint32_t sfrt_dir_usage(void* table);
-void sfrt_dir_print(void* table);
-word sfrt_dir_remove(const uint32_t* addr, int numAddrDwords, int len, int behavior, void* table);
-
-#endif /* SFRT_DIR_H */
-
index 58eb49f573b682beb99ea7879377529a7ddae76b..21b4c8d1418c18b99a1829498981620d9525fb2d 100644 (file)
@@ -106,6 +106,7 @@ table_flat_t* sfrt_flat_new(char table_flat_type, char ip_type,  long data_size,
     /* Allocate the user-specified DIR-n-m table */
     switch (table_flat_type)
     {
+#if 0
     case DIR_24_8:
         table->rt = sfrt_dir_flat_new(mem_cap, 2, 24, 8);
         break;
@@ -144,6 +145,7 @@ table_flat_t* sfrt_flat_new(char table_flat_type, char ip_type,  long data_size,
         table->rt = sfrt_dir_flat_new(mem_cap, 2, 16,16);
         table->rt6 = sfrt_dir_flat_new(mem_cap, 8, 16,16,16,16,16,16,16,16);
         break;
+#endif
     case DIR_8x16:
         table->rt = sfrt_dir_flat_new(mem_cap, 4, 16,8,4,4);
         table->rt6 = sfrt_dir_flat_new(mem_cap, 16,
@@ -151,65 +153,12 @@ table_flat_t* sfrt_flat_new(char table_flat_type, char ip_type,  long data_size,
         break;
     }
 
-    if ((!table->rt) || (!table->rt6))
-    {
-        if (table->rt)
-            sfrt_dir_flat_free(table->rt);
-        if (table->rt6)
-            sfrt_dir_flat_free(table->rt6);
-        segment_free(table->data);
-        segment_free(table_ptr);
-        return nullptr;
-    }
+    assert(table->rt);
+    assert(table->rt6);
 
     return table;
 }
 
-/* Free lookup table */
-void sfrt_flat_free(TABLE_PTR table_ptr)
-{
-    table_flat_t* table;
-    uint8_t* base;
-
-    if (!table_ptr)
-    {
-        /* What are you calling me for? */
-        return;
-    }
-
-    base = (uint8_t*)segment_basePtr();
-    table = (table_flat_t*)(&base[table_ptr]);
-
-    if (!table->data)
-    {
-        /* This really really should not have happened */
-    }
-    else
-    {
-        segment_free(table->data);
-    }
-
-    if (!table->rt)
-    {
-        /* This should not have happened either */
-    }
-    else
-    {
-        sfrt_dir_flat_free(table->rt);
-    }
-
-    if (!table->rt6)
-    {
-        /* This should not have happened either */
-    }
-    else
-    {
-        sfrt_dir_flat_free(table->rt6);
-    }
-
-    segment_free(table_ptr);
-}
-
 /* Perform a lookup on value contained in "ip" */
 GENERIC sfrt_flat_lookup(const SfIp* ip, table_flat_t* table)
 {
index 87625f4876db371306e4884f162e2a64f58bcdbc..ae6c8705b9fe801027b9bffc670546fbbcf52977 100644 (file)
@@ -72,7 +72,6 @@ typedef struct
 /* Abstracted routing table API */
 table_flat_t* sfrt_flat_new(char table_flat_type, char ip_type,
     long data_size, uint32_t mem_cap);
-void sfrt_flat_free(TABLE_PTR table);
 
 GENERIC sfrt_flat_lookup(const snort::SfIp* ip, table_flat_t* table);
 GENERIC sfrt_flat_dir8x_lookup(const snort::SfIp* ip, table_flat_t* table);
index d6da9a3c168c9dc7477a86ad3bc51bb5360b179b..e21160deba2ca085a787f7b689edf14b4e2fd597 100644 (file)
@@ -159,6 +159,7 @@ TABLE_PTR sfrt_dir_flat_new(uint32_t mem_cap, int count,...)
     return table_ptr;
 }
 
+#if 0
 /* Traverse "sub" tables, freeing each */
 static void _sub_table_flat_free(uint32_t* allocated, SUB_TABLE_PTR sub_ptr)
 {
@@ -197,28 +198,6 @@ static void _sub_table_flat_free(uint32_t* allocated, SUB_TABLE_PTR sub_ptr)
     *allocated -= sizeof(dir_sub_table_flat_t);
 }
 
-/* Free the DIR-n-m structure */
-void sfrt_dir_flat_free(TABLE_PTR tbl_ptr)
-{
-    dir_table_flat_t* table;
-    uint8_t* base;
-
-    if (!tbl_ptr)
-    {
-        return;
-    }
-
-    base = (uint8_t*)segment_basePtr();
-    table = (dir_table_flat_t*)(&base[tbl_ptr]);
-
-    if (table->sub_table)
-    {
-        _sub_table_flat_free(&table->allocated, table->sub_table);
-    }
-
-    segment_free(tbl_ptr);
-}
-
 static inline void _dir_fill_all(uint32_t* allocated, uint32_t index, uint32_t fill,
     word length, uint32_t val, SUB_TABLE_PTR sub_ptr)
 {
@@ -280,6 +259,7 @@ static inline void _dir_fill_less_specific(int index, int fill,
         }
     }
 }
+#endif
 
 static inline int64_t _dir_update_info(int index, int fill,
     word length, uint32_t val, SUB_TABLE_PTR sub_ptr, updateEntryInfoFunc updateEntry, INFO* data)
@@ -401,6 +381,7 @@ static int _dir_sub_insert(IPLOOKUP* ip, int length, int cur_len, INFO ptr,
 
         fill += index;
 
+#if 0
         /* Favor most recent CIDR */
         if (behavior == RT_FAVOR_TIME)
         {
@@ -413,6 +394,8 @@ static int _dir_sub_insert(IPLOOKUP* ip, int length, int cur_len, INFO ptr,
             _dir_fill_less_specific(index, fill, length, (word)ptr, sub_ptr);
         }
         else if (behavior == RT_FAVOR_ALL)
+#endif
+        assert(behavior == RT_FAVOR_ALL);
         {
             int64_t bytesAllocated;
 
index c6a5a54b400579e8de1925f2c30a2594066d02db..65afcaada206464829e25f786259bcd55fd9e33c 100644 (file)
@@ -69,7 +69,6 @@ typedef struct
 /******************************************************************
    DIR-n-m functions, these are not intended to be called directly */
 TABLE_PTR sfrt_dir_flat_new(uint32_t mem_cap, int count,...);
-void sfrt_dir_flat_free(TABLE_PTR);
 tuple_flat_t sfrt_dir_flat_lookup(const uint32_t* addr, int numAddrDwords, TABLE_PTR table);
 int sfrt_dir_flat_insert(const uint32_t* addr, int numAddrDwords, int len, word data_index,
                     int behavior, TABLE_PTR, updateEntryInfoFunc updateEntry, INFO *data);
diff --git a/src/sfrt/sfrt_test.cc b/src/sfrt/sfrt_test.cc
deleted file mode 100644 (file)
index 96ada73..0000000
+++ /dev/null
@@ -1,252 +0,0 @@
-//--------------------------------------------------------------------------
-// Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2009-2013 Sourcefire, Inc.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License Version 2 as published
-// by the Free Software Foundation.  You may not use, modify or distribute
-// this program under any other version of the GNU General Public License.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-//--------------------------------------------------------------------------
-// sfrt_test.cc author Hui Cao <hcao@sourcefire.com>
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "catch/snort_catch.h"
-#include "sfip/sf_cidr.h"
-#include "utils/util.h"
-
-#include "sfrt.h"
-
-using namespace snort;
-
-#define NUM_IPS 32
-#define NUM_DATA 4
-
-typedef struct
-{
-    const char* ip_str;
-    int value;
-} IP_entry;
-
-static IP_entry ip_lists[] =
-{
-// __STRDUMP_DISABLE__
-    { "192.168.0.1",4 },
-    { "2.16.0.1", 100 },
-    { "12.16.0.1", 500 },
-    { "19.16.0.1", 12345 },
-    { "12.16.0.2", 567890 },
-    { "12.168.0.1", 456 },
-    { "12.178.0.1", 123456 },
-    { "192.168.0.11", 345667 },
-    { "192.16.0.17/16", 345667 },
-    { "192.168.0.12", 10 },
-    { "::FFFF:129.144.52.38", 120 },
-    { "ffee:ddcc:bbaa:9988:7766:5544:3322:1100/32", 121 },
-    { "1001:db8:85a3::/29", 122 },
-    { "255.255.255.255", 0 }
-// __STRDUMP_ENABLE__
-};
-
-//---------------------------------------------------------------
-
-static int s_debug = 0;
-
-/* Add one ip, then delete that IP*/
-static void test_sfrt_remove_after_insert()
-{
-    table_t* dir;
-    unsigned num_entries;
-    unsigned index;
-
-    num_entries = sizeof(ip_lists)/sizeof(ip_lists[0]);
-    if ( s_debug )
-        printf("Number of entries: %u \n",num_entries);
-
-    dir = sfrt_new(DIR_16_4x4_16x5_4x4, IPv6, num_entries + 1, 200);
-
-    CHECK(dir != nullptr); // "sfrt_new()"
-
-    for (index=0; index<num_entries; index++)
-    {
-        SfCidr ip;
-        SfIp ip2;
-        int val;
-        int* result = nullptr;
-
-        IP_entry* ip_entry =  &(ip_lists[index]);
-
-        /*Parse IP*/
-        ip.set(ip_entry->ip_str);
-        char* ip2_str = snort_strdup(ip_entry->ip_str);
-        char* p = strchr(ip2_str, '/');
-        if (p)
-            *p = '\0';
-        ip2.set(ip2_str);
-        snort_free(ip2_str);
-
-        if ( s_debug )
-        {
-            SfIpString ip_str;
-            printf("Insert IP addr: %s, family: %d\n", ip.get_addr()->ntop(ip_str), ip.get_family());
-        }
-        CHECK(sfrt_insert(&ip, ip.get_bits(), &(ip_entry->value), RT_FAVOR_TIME, dir) ==
-            RT_SUCCESS); // "sfrt_insert()"
-
-        if ( s_debug )
-        {
-            SfIpString ip_str;
-            printf("Lookup IP addr: %s, family: %d\n", ip2.ntop(ip_str), ip2.get_family());
-        }
-        result = (int*)sfrt_lookup(&ip2, dir);
-        if ( s_debug )
-        {
-            if (result)
-                printf("value input: %d, output: %d\n", ip_entry->value, *result);
-            else
-                printf("value input: %d, output: nullptr\n", ip_entry->value);
-        }
-
-        CHECK(result != nullptr); // "sfrt_lookup()"
-
-        if ( s_debug )
-        {
-            SfIpString ip_str;
-            printf("IP addr: %s, family: %d\n", ip.get_addr()->ntop(ip_str), ip.get_family());
-            printf("value input: %d, output: %d\n", ip_entry->value, *result);
-        }
-
-        CHECK(sfrt_remove(&ip, ip.get_bits(), (void**)&result, RT_FAVOR_TIME, dir) == RT_SUCCESS);
-        CHECK(result != nullptr); //sfrt_remove()"
-
-        val = *result;
-        if ( s_debug )
-            printf("value expected: %d, actual: %d\n", ip_entry->value, val);
-
-        CHECK(val == ip_entry->value); //sfrt_remove(): value return"
-        CHECK(sfrt_lookup(ip.get_addr(), dir) == nullptr); // "sfrt_lookup(): value return"
-    }
-
-    if ( s_debug )
-    {
-        printf("Usage: %u bytes\n", sfrt_usage(dir));
-        printf("Number of entries: %u \n", sfrt_num_entries(dir));
-    }
-
-    sfrt_free(dir);
-}
-
-/*Add all IPs, then delete all of them*/
-static void test_sfrt_remove_after_insert_all()
-{
-    table_t* dir;
-    unsigned num_entries;
-    unsigned index;
-
-    num_entries = sizeof(ip_lists)/sizeof(ip_lists[0]);
-
-    if ( s_debug )
-        printf("Number of entries: %u \n",num_entries);
-
-    dir = sfrt_new(DIR_16_4x4_16x5_4x4, IPv6, num_entries + 1, 200);
-
-    CHECK(dir != nullptr); // "sfrt_new()"
-
-    /*insert all entries*/
-    for (index=0; index<num_entries; index++)
-    {
-        SfCidr ip;
-        SfIp ip2;
-        int* result;
-
-        IP_entry* ip_entry =  &(ip_lists[index]);
-        /*Parse IP*/
-        ip.set(ip_entry->ip_str);
-        char* ip2_str = snort_strdup(ip_entry->ip_str);
-        char* p = strchr(ip2_str, '/');
-        if (p)
-            *p = '\0';
-        ip2.set(ip2_str);
-        snort_free(ip2_str);
-
-        CHECK(sfrt_insert(&ip, ip.get_bits(), &(ip_entry->value), RT_FAVOR_TIME, dir) ==
-            RT_SUCCESS); // "sfrt_insert()"
-
-        result = (int*)sfrt_lookup(ip.get_addr(), dir);
-
-        if ( s_debug )
-            printf("value input: %d, output: %d\n", ip_entry->value, result ? *result : -1);
-
-        CHECK(result != nullptr); // "sfrt_lookup()"
-    }
-
-    if ( s_debug )
-    {
-        printf("Usage: %u bytes\n", sfrt_usage(dir));
-        printf("Number of entries: %u \n", sfrt_num_entries(dir));
-    }
-
-    /*remove all entries*/
-    for (index=0; index<num_entries; index++)
-    {
-        SfCidr ip;
-        int val;
-        int* result = nullptr;
-
-        IP_entry* ip_entry =  &(ip_lists[index]);
-        /*Parse IP*/
-        ip.set(ip_entry->ip_str);
-
-        CHECK(sfrt_remove(&ip, ip.get_bits(), (void**)&result, RT_FAVOR_TIME, dir) == RT_SUCCESS);
-
-        REQUIRE(result != nullptr);
-
-        val = *result;
-        if ( s_debug )
-            printf("value expected: %d, actual: %d\n", ip_entry->value, val);
-
-        CHECK(val == ip_entry->value); //sfrt_remove(): value return"
-        CHECK(!sfrt_lookup(ip.get_addr(), dir));
-
-        /*check the next entry still exist*/
-        if (index + 1 < num_entries)
-        {
-            ip_entry =  &(ip_lists[index + 1]);
-            /*Parse IP*/
-            ip.set(ip_entry->ip_str);
-            CHECK(sfrt_lookup(ip.get_addr(), dir)); // "sfrt_lookup(): value return"
-        }
-    }
-
-    if ( s_debug )
-    {
-        printf("Usage: %u bytes\n", sfrt_usage(dir));
-        printf("Number of entries: %u \n", sfrt_num_entries(dir));
-    }
-
-    sfrt_free(dir);
-}
-
-TEST_CASE("sfrt", "[sfrt]")
-{
-    SECTION("remove after insert")
-    {
-        test_sfrt_remove_after_insert();
-    }
-    SECTION("remove after insert all")
-    {
-        test_sfrt_remove_after_insert_all();
-    }
-}
-
index 274f975b6ef0b242ed043795203b78cfbe492db3..99563be32d0652532a50572afbdba7fc10745eed 100644 (file)
@@ -106,8 +106,6 @@ bool SideChannelModule::set(const char*, Value& v, SnortConfig*)
             config->ports = new PortBitSet;
         v.get_bits(*(config->ports) );
     }
-    else
-        return false;
 
     return true;
 }
index 72da087b949180151d6f205cf37dbc52b2c296d9..e3812a3e11e95763c3d32444e016d0deaf7ac9b2 100644 (file)
@@ -208,6 +208,7 @@ bool StreamModule::set(const char* fqn, Value& v, SnortConfig* c)
 
     if ( v.is("idle_timeout") )
         config.flow_cache_cfg.proto[to_utype(type)].nominal_timeout = v.get_uint32();
+
     else if ( v.is("cap_weight") )
         config.flow_cache_cfg.proto[to_utype(type)].cap_weight = v.get_uint16();
 
index e98f3fceace1c3ad0b5d4659a377ca84e4dd89ba..158dfef66588ae7735f6e315fc5158a0e90bd7a6 100644 (file)
@@ -50,12 +50,8 @@ bool StreamFileModule::begin(const char*, int, SnortConfig*)
 
 bool StreamFileModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("upload") )
-        upload = v.get_bool();
-
-    else
-        return false;
-
+    assert(v.is("upload"));
+    upload = v.get_bool();
     return true;
 }
 
index f4f9b421b1d0e023de51e77e8ebab2cff2338d8b..bb16f39a3486c23f59ee15e5adf960fbf4567943 100644 (file)
@@ -61,12 +61,8 @@ StreamIcmpConfig* StreamIcmpModule::get_data()
 
 bool StreamIcmpModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("session_timeout") )
-        config->session_timeout = v.get_uint32();
-
-    else
-        return false;
-
+    assert(v.is("session_timeout"));
+    config->session_timeout = v.get_uint32();
     return true;
 }
 
index 23d9713ea43a91aca467bff881278c70c42bfc3d..42653be4bba7f9bdd419f26ccbd0d416496e2591 100644 (file)
@@ -222,9 +222,6 @@ bool ReassembleModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("fastpath") )
         srod.fastpath = 1;
 
-    else
-        return false;
-
     return true;
 }
 
index b63ca422987843d800f7f4ba9d6e19047b30be13..ce3cd5f5a67e0cf47a29585a1a2743a2aed08d7b 100644 (file)
@@ -207,9 +207,6 @@ bool SizeModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("~direction") )
         direction = v.get_uint8();
 
-    else
-        return false;
-
     return true;
 }
 
index e0037fdf570479439c0399f394caa7baa31f0b87..36511a81320edeceeeb6a092ece0d14078ba87a0 100644 (file)
@@ -359,8 +359,6 @@ bool StreamTcpModule::set(const char*, Value& v, SnortConfig*)
         else
             config->flags &= ~STREAM_CONFIG_NO_REASSEMBLY;
     }
-    else
-        return false;
 
     return true;
 }
index 3aeb2f6577762ac95ff9fd5ef5bafd1249db6a7d..f9e43ca89540920b67665776f98e9ac34383e80a 100644 (file)
@@ -149,202 +149,3 @@ bool TcpStateClosed::do_post_sm_packet_actions(TcpSegmentDescriptor& tsd, TcpStr
     return true;
 }
 
-#if 0  // FIXIT-M unit tests need work
-#include "tcp_normalizers.h"
-#include "tcp_reassemblers.h"
-
-TEST_CASE("TCP State Closed", "[tcp_closed_state][stream_tcp]")
-{
-    // initialization code here
-    Flow* flow = new Flow;
-    TcpStreamTracker* ctrk = new TcpStreamTracker(true);
-    TcpStreamTracker* strk = new TcpStreamTracker(false);
-    TcpEventLogger* tel = new TcpEventLogger;
-    TcpSession* session = new TcpSession(flow);
-    TcpStateMachine* tsm =  new TcpStateMachine;
-    TcpStateHandler* tsh = new TcpStateClosed(*tsm, *session);
-    ctrk->normalizer = TcpNormalizerFactory::create(StreamPolicy::OS_LINUX, session, ctrk, strk);
-    strk->normalizer = TcpNormalizerFactory::create(StreamPolicy::OS_LINUX, session, strk, ctrk);
-    ctrk->reassembler = TcpReassemblerFactory::create(session, ctrk, StreamPolicy::OS_LINUX,
-        false);
-    strk->reassembler = TcpReassemblerFactory::create(session, strk, StreamPolicy::OS_LINUX, true);
-
-    SECTION("syn_packet")
-    {
-        Packet* pkt = get_syn_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("syn_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK(TcpStreamTracker::TCP_SYN_SENT_EVENT == ctrk->get_tcp_event() );
-            //CHECK( ( ctrk->get_iss() == 9050 ) );
-            //CHECK( ( ctrk->get_snd_una() == 9051 ) );
-            //CHECK( ( ctrk->get_snd_nxt() == 9050 ) );
-            //CHECK( ( ctrk->get_snd_wnd() == 8192 ) );
-        }
-
-        SECTION("syn_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("syn_ack_packet")
-    {
-        Packet* pkt = get_syn_ack_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("syn_ack_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        SECTION("syn_ack_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("ack_packet")
-    {
-        Packet* pkt = get_ack_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("ack_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        SECTION("ack_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("data_seg_packet")
-    {
-        Packet* pkt = get_data_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("data_seg_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        SECTION("data_seg_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("fin_packet")
-    {
-        Packet* pkt = get_fin_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("fin_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        SECTION("fin_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("rst_packet")
-    {
-        Packet* pkt = get_rst_packet(flow);
-        REQUIRE( ( pkt != nullptr  ));
-
-        SECTION("rst_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ));
-        }
-
-        SECTION("rst_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    delete flow;
-    delete tsh;
-    delete ctrk;
-    delete strk;
-}
-
-#endif
-
index b40e4f90c237ce03da135c8240c99bc3e6457bc3..a9de1b71a1278ad5ccc3a3d3a70235c40b434de7 100644 (file)
@@ -95,182 +95,3 @@ bool TcpStateHandler::eval(TcpSegmentDescriptor& tsd, TcpStreamTracker& tracker)
     return false;
 }
 
-// FIXIT-RC get the unit test working again
-#ifdef UNIT_TEST_FOO
-
-SCENARIO("TCP State Handler Base Class", "[state_handlers][stream_tcp]")
-{
-    // initialization code here
-    Flow* flow = new Flow;
-    TcpStateHandler* tsh = new TcpStateHandler;
-    TcpStreamTracker* client_tracker = new TcpStreamTracker(true);
-    TcpStreamTracker* server_tracker = new TcpStreamTracker(false);
-    TcpEventLogger tel;
-
-    GIVEN("a SYN Packet")
-    {
-        Packet* pkt = get_syn_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        WHEN("SYN is sent")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            client_tracker->set_tcp_event(TcpStreamTracker::TCP_SYN_SENT_EVENT);
-            tsh->eval(*tsd, *client_tracker);
-            THEN("Event should be TCP_SYN_SENT_EVENT")
-            {
-                CHECK( ( tsh->get_tcp_event() == client_tracker->get_tcp_event() ) );
-            }
-            delete tsd;
-        }
-
-        SECTION("SYN is received")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            server_tracker->set_tcp_event(TcpStreamTracker::TCP_SYN_RECV_EVENT);
-            tsh->eval(*tsd, *server_tracker);
-            CHECK( ( tsh->get_tcp_event() == server_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        delete pkt;
-    }
-
-    SECTION("syn_ack_packet")
-    {
-        Packet* pkt = get_syn_ack_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("syn_ack_sent")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            client_tracker->set_tcp_event(TcpStreamTracker::TCP_SYN_ACK_SENT_EVENT);
-            tsh->eval(*tsd, *client_tracker);
-            CHECK( ( tsh->get_tcp_event() == client_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        SECTION("syn_ack_recv")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            server_tracker->set_tcp_event(TcpStreamTracker::TCP_SYN_ACK_RECV_EVENT);
-            tsh->eval(*tsd, *server_tracker);
-            CHECK( ( tsh->get_tcp_event() == server_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        delete pkt;
-    }
-
-    SECTION("ack_packet")
-    {
-        Packet* pkt = get_ack_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("ack_sent")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            client_tracker->set_tcp_event(TcpStreamTracker::TCP_ACK_SENT_EVENT);
-            tsh->eval(*tsd, *client_tracker);
-            CHECK( ( tsh->get_tcp_event() == client_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        SECTION("ack_recv")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            server_tracker->set_tcp_event(TcpStreamTracker::TCP_ACK_RECV_EVENT);
-            tsh->eval(*tsd, *server_tracker);
-            CHECK( ( tsh->get_tcp_event() == server_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        delete pkt;
-    }
-
-    SECTION("data_seg_packet")
-    {
-        Packet* pkt = get_data_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("data_seg_sent")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            client_tracker->set_tcp_event(TcpStreamTracker::TCP_DATA_SEG_SENT_EVENT);
-            tsh->eval(*tsd, *client_tracker);
-            CHECK( ( tsh->get_tcp_event() == client_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        SECTION("data_seg_recv")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            server_tracker->set_tcp_event(TcpStreamTracker::TCP_DATA_SEG_RECV_EVENT);
-            tsh->eval(*tsd, *server_tracker);
-            CHECK( ( tsh->get_tcp_event() == server_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        delete pkt;
-    }
-
-    SECTION("fin_packet")
-    {
-        Packet* pkt = get_fin_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("fin_sent")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            client_tracker->set_tcp_event(TcpStreamTracker::TCP_FIN_SENT_EVENT);
-            tsh->eval(*tsd, *client_tracker);
-            CHECK( ( tsh->get_tcp_event() == client_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        SECTION("fin_recv")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            server_tracker->set_tcp_event(TcpStreamTracker::TCP_FIN_RECV_EVENT);
-            tsh->eval(*tsd, *server_tracker);
-            CHECK( ( tsh->get_tcp_event() == server_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        delete pkt;
-    }
-
-    SECTION("rst_packet")
-    {
-        Packet* pkt = get_rst_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("rst_sent")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            client_tracker->set_tcp_event(TcpStreamTracker::TCP_RST_SENT_EVENT);
-            tsh->eval(*tsd, *client_tracker);
-            CHECK( ( tsh->get_tcp_event() == client_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        SECTION("rst_recv")
-        {
-            TcpSegmentDescriptor* tsd = new TcpSegmentDescriptor(flow, pkt, tel);
-            server_tracker->set_tcp_event(TcpStreamTracker::TCP_RST_RECV_EVENT);
-            tsh->eval(*tsd, *server_tracker);
-            CHECK( ( tsh->get_tcp_event() == server_tracker->get_tcp_event() ) );
-            delete tsd;
-        }
-
-        delete pkt;
-    }
-
-    delete flow;
-    delete tsh;
-    delete client_tracker;
-    delete server_tracker;
-}
-
-#endif
-
index 57e4c74918ebdc4ca3fae1477ca82d945b829e98..179cce4646009e1c89fd5b043d3661696e103abd 100644 (file)
@@ -228,203 +228,3 @@ bool TcpStateNone::rst_recv(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
     return true;
 }
 
-#if 0  // FIXIT-M unit tests need work
-#include "tcp_normalizers.h"
-#include "tcp_reassemblers.h"
-
-TEST_CASE("TCP State None", "[tcp_none_state][stream_tcp]")
-{
-    // initialization code here
-    Flow* flow = new Flow;
-    TcpStreamTracker* ctrk = new TcpStreamTracker(true);
-    TcpStreamTracker* strk = new TcpStreamTracker(false);
-    TcpEventLogger* tel = new TcpEventLogger;
-    TcpSession* session = new TcpSession(flow);
-    TcpStateMachine* tsm =  new TcpStateMachine;
-    TcpStateHandler* tsh = new TcpStateNone(*tsm, *session);
-
-    ctrk->normalizer = TcpNormalizerFactory::create(StreamPolicy::OS_LINUX, session, ctrk, strk);
-    strk->normalizer = TcpNormalizerFactory::create(StreamPolicy::OS_LINUX, session, strk, ctrk);
-    ctrk->reassembler = TcpReassemblerFactory::create(session, ctrk, StreamPolicy::OS_LINUX,
-        false);
-    strk->reassembler = TcpReassemblerFactory::create(session, strk, StreamPolicy::OS_LINUX, true);
-
-    SECTION("syn_packet")
-    {
-        Packet* pkt = get_syn_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("syn_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK(TcpStreamTracker::TCP_SYN_SENT_EVENT == ctrk->get_tcp_event() );
-            //CHECK( ( ctrk->get_iss() == 9050 ) );
-            //CHECK( ( ctrk->get_snd_una() == 9051 ) );
-            //CHECK( ( ctrk->get_snd_nxt() == 9050 ) );
-            //CHECK( ( ctrk->get_snd_wnd() == 8192 ) );
-        }
-
-        SECTION("syn_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("syn_ack_packet")
-    {
-        Packet* pkt = get_syn_ack_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("syn_ack_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        SECTION("syn_ack_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("ack_packet")
-    {
-        Packet* pkt = get_ack_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("ack_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        SECTION("ack_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("data_seg_packet")
-    {
-        Packet* pkt = get_data_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("data_seg_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        SECTION("data_seg_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("fin_packet")
-    {
-        Packet* pkt = get_fin_packet(flow);
-        REQUIRE( ( pkt != nullptr ) );
-
-        SECTION("fin_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        SECTION("fin_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    SECTION("rst_packet")
-    {
-        Packet* pkt = get_rst_packet(flow);
-        REQUIRE( ( pkt != nullptr  ));
-
-        SECTION("rst_sent")
-        {
-            flow->ssn_state.direction = FROM_CLIENT;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ));
-        }
-
-        SECTION("rst_recv")
-        {
-            flow->ssn_state.direction = FROM_SERVER;
-            TcpSegmentDescriptor tsd(flow, pkt, tel);
-            ctrk->set_tcp_event(tsd);
-            ctrk->set_require_3whs(false);
-            tsh->eval(tsd, *ctrk);
-            CHECK( ( tsh->get_tcp_event() == ctrk->get_tcp_event() ) );
-        }
-
-        delete pkt;
-    }
-
-    delete flow;
-    delete tsh;
-    delete ctrk;
-    delete strk;
-}
-
-#endif
-
index f2d9b3c6c6a961e3a94a4286993e0186428cb650..3e2891a787224dcfd39696865c11470da6fd91ea 100644 (file)
@@ -119,44 +119,3 @@ Packet* get_syn_ack_packet(Flow* flow)
     return pkt;
 }
 
-Packet* get_ack_packet(Flow* flow)
-{
-    Packet* pkt = init_packet(flow, PKT_FROM_CLIENT);
-
-    pkt->pkt = cooked_ack;
-    pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_ack + 34 );
-
-    return pkt;
-}
-
-Packet* get_fin_packet(Flow* flow)
-{
-    Packet* pkt = init_packet(flow, PKT_FROM_CLIENT);
-
-    pkt->pkt = cooked_fin;
-    pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_fin + 34 );
-
-    return pkt;
-}
-
-Packet* get_rst_packet(Flow* flow)
-{
-    Packet* pkt = init_packet(flow, PKT_FROM_CLIENT);
-
-    pkt->pkt = cooked_rst;
-    pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_rst + 34 );
-
-    return pkt;
-}
-
-Packet* get_data_packet(Flow* flow)
-{
-    Packet* pkt = init_packet(flow, PKT_FROM_CLIENT);
-
-    pkt->pkt = cooked_data;
-    pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_data + 34 );
-    pkt->dsize = 42;
-
-    return pkt;
-}
-
index 2fe77b43f9a9811c84720a948f54599806c19ed4..006394342538b25c91f9547ad310328ee15c62a5 100644 (file)
@@ -61,12 +61,8 @@ StreamUdpConfig* StreamUdpModule::get_data()
 
 bool StreamUdpModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("session_timeout") )
-        config->session_timeout = v.get_uint32();
-
-    else
-        return false;
-
+    assert(v.is("session_timeout"));
+    config->session_timeout = v.get_uint32();
     return true;
 }
 
index 99babfc9992447d71862f95107a49868b80141fa..2c187f78ba4aa822b89af43b19589b6698e5ecf7 100644 (file)
@@ -21,6 +21,8 @@
 #include "config.h"
 #endif
 
+#include <cassert>
+
 #include "stream_user.h"
 
 #include "log/messages.h"
@@ -69,9 +71,7 @@ StreamUser::~StreamUser()
 
 void StreamUser::show(const SnortConfig*) const
 {
-    if ( !config )
-        return;
-
+    assert(config);
     ConfigLogger::log_value("session_timeout", config->session_timeout);
 }
 
index 9a1b8bd7ca7042715fbe584e9a60219b81476699..105c7ae6067ed37cc544b1335e8ee36d72535ecc 100644 (file)
@@ -44,15 +44,10 @@ static const Parameter s_params[] =
 };
 
 StreamUserModule::StreamUserModule() : Module(MOD_NAME, MOD_HELP, s_params)
-{
-    config = nullptr;
-}
+{ config = nullptr; }
 
 StreamUserModule::~StreamUserModule()
-{
-    if ( config )
-        delete config;
-}
+{ delete config; }
 
 StreamUserConfig* StreamUserModule::get_data()
 {
@@ -76,9 +71,8 @@ const TraceOption* StreamUserModule::get_trace_options() const
 
 bool StreamUserModule::set(const char*, Value& v, SnortConfig*)
 {
-    if ( v.is("session_timeout") )
-        config->session_timeout = v.get_uint32();
-
+    assert(v.is("session_timeout"));
+    config->session_timeout = v.get_uint32();
     return true;
 }
 
index 5f836e1179db9693f27793d1d412b99de1fae0c9..46ababbfe3e648887b88f1f701366069b0c13bd2 100644 (file)
@@ -87,15 +87,6 @@ public:
     snort::StreamSplitter* get_splitter(bool c2s) override;
     void restart(snort::Packet*) override;
 
-    bool is_sequenced(uint8_t /*dir*/) override
-    { return true; }
-
-    bool are_packets_missing(uint8_t /*dir*/) override
-    { return false; }
-
-    uint8_t missing_in_reassembled(uint8_t /*dir*/) override
-    { return SSN_MISSING_NONE; }
-
 private:
     void start(snort::Packet*, snort::Flow*);
     void update(snort::Packet*, snort::Flow*);
@@ -107,13 +98,6 @@ private:
     int update_alert(
         snort::Packet*, uint32_t gid, uint32_t sid, uint32_t event_id, uint32_t event_second) override;
 
-    void flush_client(snort::Packet*) override { }
-    void flush_server(snort::Packet*) override { }
-    void flush_talker(snort::Packet*, bool /*final_flush */ = false) override { }
-    void flush_listener(snort::Packet*, bool /*final_flush */ = false) override { }
-
-    void set_extra_data(snort::Packet*, uint32_t /* flag */) override { }
-
     uint8_t get_reassembly_direction() override;
 
 public:
index 649f78abdc3191ac09d453deda5c2822260e19d2..8191d3dde6b9c3fd9d13ec1d829348066ff1c74b 100644 (file)
@@ -26,8 +26,9 @@
 %option c++
 
 %option batch
-
 %option never-interactive
+%option noinput nounput
+%option noyy_push_state noyy_pop_state noyy_top_state
 
 %{
 
@@ -42,6 +43,7 @@
 #include "utils/js_identifier_ctx.h"
 #include "utils/util_cstring.h"
 
+#define YY_NO_UNPUT
 #define YY_USER_ACTION                                      \
     {                                                       \
         debug_logf(5, http_trace, TRACE_JS_PROC, nullptr,   \