]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4263: Public enemy 1
authorRuss Combs (rucombs) <rucombs@cisco.com>
Wed, 8 May 2024 21:55:15 +0000 (21:55 +0000)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Wed, 8 May 2024 21:55:15 +0000 (21:55 +0000)
Merge in SNORT/snort3 from ~RUCOMBS/snort3:public_enemy_1 to master

Squashed commit of the following:

commit 7f8f2135c33fd2de3495a8edcfd22b5f60de89fd
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed May 8 14:22:49 2024 -0400

    build: fix coverity warnings

commit 2c700829076b77e7d2773d102a2a62d4d3b531b1
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed May 8 13:42:06 2024 -0400

    build: fix bogus cppcheck warnings

commit eb7b28eea14ea6e8c5152945c6204cc37bad8196
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Apr 12 10:06:47 2024 -0400

    framework: bump api version to 20

commit c9a5baeeb2e3a7954b492179faac32b2696876ab
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Apr 8 13:37:48 2024 -0400

    snort: remove deprecated features:

    Config:

    string binder[].when.zones: deprecated alias for groups
    string binder[].when.src_zone: deprecated alias for src_groups
    string binder[].when.dst_zone: deprecated alias for dst_groups
    enum dce_smb.smb_file_inspection: deprecated (not used): file inspection controlled by smb_file_depth { 'off' | 'on' | 'only' }
    int sip.max_requestName_len = 20: deprecated - use max_request_name_len instead { 0:65535 }

    Builtins:

    129:5 (stream_tcp) bad segment, adjusted size <= 0 (deprecated)

commit 641cad2638d6eb1bd0a57982d1354b829ee08147
Author: Russ Combs <rucombs@cisco.com>
Date:   Thu Apr 4 10:11:54 2024 -0400

    pig_pen: use Module::usage directly

commit 0a6d7eccebac6e1d0d2b478094f31f296103371e
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Mar 19 10:21:58 2024 -0400

    mpse: add modules for pegs and perf profiling; remove _search

commit 818d4709d70430595e73ee6301f35a376f5e8d78
Author: Russ Combs <rucombs@cisco.com>
Date:   Thu Mar 14 11:20:49 2024 -0400

    framework: improve exported header comments

commit a53c0249b7047c26328a5bbd14e0bc706df88214
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Mar 11 08:39:57 2024 -0400

    plugins: add missing error messages when an so fails to load

commit 1c7fd7e717d06231565cff00a73e4a5937749638
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Mar 6 10:44:29 2024 -0500

    flow: move StreamFlowIntf to stream_flow.h

commit b4f969f4072a45b12acd3a36808746414af707c0
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Mar 6 09:03:10 2024 -0500

    framework: generate preprocessor output for validation

commit 14e9886e9018a11a8f98ec95d88c127aed2e6f6e
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Mar 4 09:56:53 2024 -0500

    doc: add versioning information to the developer guide

commit f1074aaa9c79b9e1a91616f9e0da533e872c8f2b
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Feb 28 08:46:20 2024 -0500

    host_cache: do not install private header

commit c8d50a4ba02f527efe6ca89e5ad07991c9bd18c9
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Feb 26 09:26:31 2024 -0500

    api: refactor base API

commit 1c9fe59accaf77c84ba6a627be66072d02f0d87f
Author: Russ Combs <rucombs@cisco.com>
Date:   Thu Feb 15 12:08:06 2024 -0500

    inspector: eval override is optional for passive inspectors

commit 48859035f007a5bcdc17b2e9be05da11742338d6
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Feb 13 16:22:08 2024 -0500

    plugins: add warning for invalid plugin types

commit ef2b94f2ba3a46efdd3455359bfeba51a4fcd87f
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Jan 24 04:26:46 2024 -0500

    plugins: bump base API and all plugin API version numbers

commit 4636922ef31cdf8544ee5a62bba313f9577bfd19
Author: Russ Combs <rucombs@cisco.com>
Date:   Thu Nov 30 09:47:40 2023 -0500

    detection: refactor headers

commit b70ee339aa490d7562bab85418a4e2ab89ec6129
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Dec 12 12:37:39 2023 -0500

    ips: tweak check for offload enable

commit 047ec75da346b7d1199ef9122147ad89921468da
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Nov 27 14:56:29 2023 -0500

    build: fix LTO ODR issues with anonymous namespaces

commit eb975151c97018a8ede37115df312aa4ac29d66d
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Nov 13 12:04:34 2023 -0500

    inspector: use thread local slot for best perf on Linux

commit 0565783cbf6e2ffd65aeb0934040ec57464ce60a
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Nov 8 14:29:34 2023 -0500

    extract: move extract methods to detection/

commit eaae3dc988df37c0312a218259ccdbb1d86a165d
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Nov 7 11:36:20 2023 -0500

    stats: change shutdown Mbits/sec from mebibits to megabits

commit ade482affc30c629dac43626d21d92b0488cd4dc
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Oct 9 11:12:14 2023 -0400

    appid: remove cruft left behind by f49fbbef

commit 1d36b3fe208ffdee2dd997746f9b6b3c251d3305
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Oct 4 10:00:28 2023 -0400

    tag: tweak enable toggle

commit eebe7edb5f6947b81fc89604c1bf0261a0e070d1
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Sep 26 14:09:23 2023 -0400

    packet_tracer: eliminate SO_PUBLIC THREAD_LOCALs

commit 9ffcfdbebae661f6fc2c8c655996a9f37634cc26
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Sep 5 11:43:26 2023 -0400

    profiler: eliminate SO_PUBLIC THREAD_LOCALs for _WIN64

    This degrades performance so it is done only for Windows where SO_PUBLIC
    THREAD_LOCALs are not supported.

commit eac23069203da078d6deab67e13bad052c8f6731
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Aug 8 09:31:33 2023 -0400

    style: remove trailing spaces

commit 2d6882a33443d50c5f66495a1b62bb75bf4b6bb6
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Sep 20 14:45:16 2023 -0400

    ssl: support dynamic build of inspector and ips options

commit e3dcb79941b03815867bd439885850270f754616
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Sep 19 16:16:24 2023 -0400

    ips_options: fix dynamic build of some options

commit 6991df8ab3e4c8d0d07b23436fa06695c244ca17
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Sep 15 12:50:57 2023 -0400

    profiler: move implementation class to profiler_impl.h

commit c67e74c070809c9eb9571c73637b40b71572ea62
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Sep 15 12:50:16 2023 -0400

    numa: do not install implementation (private) header

commit ec030aa7b77ad940ea1056078555dee9499e2098
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Sep 15 12:47:05 2023 -0400

    reputation: move private defines out of installed header

commit e3c5f4653fae5882d333dcbf12b796e3fc6f191c
Author: Russ Combs <rucombs@cisco.com>
Date:   Thu Sep 14 09:55:34 2023 -0400

    thread: move THREAD_LOCAL definition to snort_types.h

commit 2759519051f3972de590540f75c84b5ac1b5b3de
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Sep 13 10:01:15 2023 -0400

    utils: refactor out non-public code

commit c3145c20f7ea175d046a0f676fa42533f679a469
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Sep 12 14:29:14 2023 -0400

    stats: stats.h is for internal use only, do not install

commit 92dbe63fb04b96264cf67feab80bd100370f99a2
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Sep 12 11:47:08 2023 -0400

    flow: split ExpectFlow into a separate header

commit 1366ef1571ae0cb9729ec75c3c8b81144f53c4eb
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Sep 11 15:36:59 2023 -0400

    src/: relocate packet_tracer, packet_constraints, and file_policy.

commit 7e3263c4db9f1b8dabf3c11014d124eff0a43ae9
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Sep 11 12:44:57 2023 -0400

    rna: refactor headers for better encapsulation

commit 39a74682069842d8777720a42be6592d0361aa53
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Sep 8 13:47:01 2023 -0400

    file: do not install internal headers

commit 7c532a3410df1a631fa3494360f06b4d3db008bf
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Sep 8 10:50:01 2023 -0400

    log: refactor out app implementation stuff into log_errors.h

commit 274d08bb2b2e6a8701d213d089d670345eb5d15f
Author: Russ Combs <rucombs@cisco.com>
Date:   Thu Sep 7 15:07:56 2023 -0400

    active, host_tracker, profiler, stats, stream: refactor installed headers to exclude implementation like counts and perf stats

commit 52915f8e0fc136fe52ce42570458e523beba36e9
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Sep 6 14:44:07 2023 -0400

    detection: refactor detection_util.*

    Split detection_util.{h,cc} into detection_buf.h and event_trace.{h,cc}.

commit 76797daae3fcb788c7aa7e2c53a25456916c0522
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Sep 6 11:38:36 2023 -0400

    helpers/, utils/: reorganize to meet original intent

    helpers/: C++ utility classes
    utils/: C-style functions and defines

commit d648be932b8d4c10cc144c5a597c3c9aab157e96
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Aug 30 11:59:53 2023 -0400

    codecs: PacketManager::max_layers is not THREAD_LOCAL

commit 4826653a3bce0fc4043ab0cd4d2e933eae718b06
Author: Russ Combs <rucombs@cisco.com>
Date:   Wed Aug 30 11:30:31 2023 -0400

    inspectors: remove redundant slot variable

commit a08cc0edab6893917e3c6d1b2629d5a775ce4086
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Aug 29 15:39:50 2023 -0400

    build: eliminate SO_PUBLIC THREAD_LOCALs

commit 4dd23f34df05dfbd40f23016fbd57185079256ed
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Aug 28 13:57:31 2023 -0400

    event_filter, suppress:  keep antiquated dynamic array support private (use std::vector instead)

commit 8f65203a02be32128af0be21590b7d69b979889e
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Aug 28 12:15:21 2023 -0400

    stream: delete obsolete / unused methods

commit bd5770d0faa26e785180278879105ea05bdee44b
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Aug 25 15:07:15 2023 -0400

    tcp: move SEQ_* macros to tcp header

commit 511797508566d0d7c5da7c13afbedda531cdd49b
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Aug 25 13:22:13 2023 -0400

    style: miscellaneous cleanup

... and 18 more commits

627 files changed:
doc/devel/CMakeLists.txt
doc/devel/snort_devel.txt
doc/devel/versions.txt [new file with mode: 0644]
doc/user/concepts.txt
doc/user/perf_monitor.txt
src/actions/CMakeLists.txt
src/actions/act_alert.cc
src/actions/act_block.cc
src/actions/act_drop.cc
src/actions/act_file_id.cc
src/actions/act_log.cc
src/actions/act_pass.cc
src/actions/act_react.cc
src/actions/act_reject.cc
src/actions/act_replace.cc
src/actions/actions.cc [deleted file]
src/actions/actions_module.cc
src/actions/ips_actions.cc
src/codecs/ip/cd_tcp.cc
src/codecs/misc/cd_default.cc
src/codecs/misc/test/geneve_codec_test.cc
src/connectors/file_connector/test/file_connector_module_test.cc
src/connectors/file_connector/test/file_connector_test.cc
src/connectors/tcp_connector/tcp_connector.cc
src/connectors/tcp_connector/test/tcp_connector_module_test.cc
src/connectors/tcp_connector/test/tcp_connector_test.cc
src/control/control.h
src/control/control_mgmt.cc
src/decompress/file_decomp.cc
src/decompress/file_decomp_pdf.cc
src/decompress/file_olefile.h
src/decompress/test/file_olefile_test.cc
src/detection/CMakeLists.txt
src/detection/context_switcher.cc
src/detection/context_switcher.h
src/detection/detect.cc
src/detection/detect.h
src/detection/detect_trace.cc
src/detection/detect_trace.h
src/detection/detection_buf.h [moved from src/detection/detection_util.h with 72% similarity]
src/detection/detection_continuation.h
src/detection/detection_engine.cc
src/detection/detection_engine.h
src/detection/detection_module.cc
src/detection/detection_module.h
src/detection/detection_options.cc
src/detection/event_trace.cc [moved from src/detection/detection_util.cc with 92% similarity]
src/detection/event_trace.h [new file with mode: 0644]
src/detection/extract.cc [moved from src/ips_options/extract.cc with 100% similarity]
src/detection/extract.h [moved from src/ips_options/extract.h with 92% similarity]
src/detection/fp_create.cc
src/detection/fp_detect.cc
src/detection/fp_detect.h
src/detection/fp_utils.cc
src/detection/ips_context.h
src/detection/regex_offload.cc
src/detection/rules.h
src/detection/signature.cc
src/detection/tag.cc
src/detection/tag.h
src/detection/treenodes.h
src/events/CMakeLists.txt
src/events/event.cc
src/events/event.h
src/file_api/CMakeLists.txt
src/file_api/file_cache.cc
src/file_api/file_capture.cc
src/file_api/file_config.cc
src/file_api/file_flows.cc
src/file_api/file_flows.h
src/file_api/file_inspect.cc [new file with mode: 0644]
src/file_api/file_inspect.h [new file with mode: 0644]
src/file_api/file_lib.cc
src/file_api/file_lib.h
src/file_api/file_log.cc
src/file_api/file_module.h
src/file_api/file_policy.cc [moved from src/framework/file_policy.cc with 99% similarity]
src/file_api/file_policy.h [moved from src/framework/file_policy.h with 100% similarity]
src/file_api/file_stats.cc
src/file_api/file_stats.h
src/filters/detection_filter.cc
src/filters/sfrf.cc
src/filters/sfrf.h
src/filters/sfrf_test.cc
src/filters/sfthd.cc
src/flow/CMakeLists.txt
src/flow/expect_cache.cc
src/flow/expect_cache.h
src/flow/expect_flow.h [new file with mode: 0644]
src/flow/flow.h
src/flow/flow_cache.cc
src/flow/flow_cache.h
src/flow/flow_control.cc
src/flow/flow_data.h
src/flow/flow_key.h
src/flow/flow_stash.cc
src/flow/flow_stash.h
src/flow/ha.h
src/flow/ha_module.h
src/flow/stash_item.h
src/flow/stream_flow.h [new file with mode: 0644]
src/flow/test/flow_cache_test.cc
src/flow/test/flow_control_test.cc
src/flow/test/flow_stash_test.cc
src/flow/test/flow_stubs.h
src/framework/CMakeLists.txt
src/framework/act_info.h [moved from src/actions/actions.h with 61% similarity]
src/framework/base_api.h
src/framework/codec.cc
src/framework/codec.h
src/framework/connector.h
src/framework/counts.h
src/framework/cursor.cc
src/framework/cursor.h
src/framework/endianness.h
src/framework/inspector.cc
src/framework/inspector.h
src/framework/ips_action.cc [new file with mode: 0644]
src/framework/ips_action.h
src/framework/ips_info.h [new file with mode: 0644]
src/framework/ips_option.cc
src/framework/ips_option.h
src/framework/logger.h
src/framework/module.cc
src/framework/module.h
src/framework/mpse.cc
src/framework/mpse.h
src/framework/mpse_batch.cc
src/framework/mpse_batch.h
src/framework/pdu_section.h
src/framework/pig_pen.cc [new file with mode: 0644]
src/framework/pig_pen.h [new file with mode: 0644]
src/framework/plug_gen.sh [new file with mode: 0755]
src/framework/plugins.h [new file with mode: 0644]
src/framework/policy_selector.h
src/framework/range.cc
src/framework/so_rule.h
src/framework/test/CMakeLists.txt
src/framework/test/api_def.cc [new file with mode: 0644]
src/framework/test/data_bus_test.cc
src/framework/value.h
src/hash/CMakeLists.txt
src/hash/ghash.h
src/hash/hash_key_operations.cc
src/hash/test/ghash_test.cc
src/hash/test/xhash_test.cc
src/hash/xhash.h
src/helpers/CMakeLists.txt
src/helpers/ber.cc [moved from src/utils/util_ber.cc with 99% similarity]
src/helpers/ber.h [moved from src/utils/util_ber.h with 95% similarity]
src/helpers/boyer_moore.cc [moved from src/utils/boyer_moore.cc with 100% similarity]
src/helpers/boyer_moore.h [moved from src/utils/boyer_moore.h with 100% similarity]
src/helpers/buffer_data.h
src/helpers/dev_notes.txt
src/helpers/event_gen.h [moved from src/utils/event_gen.h with 100% similarity]
src/helpers/grouped_list.h [moved from src/utils/grouped_list.h with 100% similarity]
src/helpers/hyper_search.cc
src/helpers/infractions.h [moved from src/utils/infractions.h with 100% similarity]
src/helpers/memcap_allocator.h [moved from src/utils/memcap_allocator.h with 100% similarity]
src/helpers/primed_allocator.h [moved from src/utils/primed_allocator.h with 100% similarity]
src/helpers/streambuf.cc [moved from src/utils/streambuf.cc with 100% similarity]
src/helpers/streambuf.h [moved from src/utils/streambuf.h with 100% similarity]
src/helpers/test/CMakeLists.txt
src/helpers/test/boyer_moore_test.cc [moved from src/utils/test/boyer_moore_test.cc with 100% similarity]
src/helpers/test/grouped_list_test.cc [moved from src/utils/test/grouped_list_test.cc with 99% similarity]
src/helpers/test/memcap_allocator_test.cc [moved from src/utils/test/memcap_allocator_test.cc with 100% similarity]
src/helpers/test/streambuf_test.cc [moved from src/utils/test/streambuf_test.cc with 99% similarity]
src/helpers/utf.cc [moved from src/utils/util_utf.cc with 99% similarity]
src/helpers/utf.h [moved from src/utils/util_utf.h with 100% similarity]
src/host_tracker/CMakeLists.txt
src/host_tracker/cache_allocator.h
src/host_tracker/host_cache.h
src/host_tracker/host_cache_module.cc
src/host_tracker/host_cache_segmented.h
src/host_tracker/host_tracker.cc
src/host_tracker/host_tracker.h
src/host_tracker/host_tracker_module.cc
src/host_tracker/host_tracker_stats.h [new file with mode: 0644]
src/host_tracker/test/host_cache_allocator_ht_test.cc
src/host_tracker/test/host_cache_module_test.cc
src/host_tracker/test/host_tracker_module_test.cc
src/ips_options/CMakeLists.txt
src/ips_options/ips_ack.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_data.cc
src/ips_options/ips_file_meta.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_js_data.cc
src/ips_options/ips_luajit.cc
src/ips_options/ips_metadata.cc
src/ips_options/ips_msg.cc
src/ips_options/ips_options.cc
src/ips_options/ips_pcre.cc
src/ips_options/ips_pkt_data.cc
src/ips_options/ips_priority.cc
src/ips_options/ips_raw_data.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_window.cc
src/ips_options/test/CMakeLists.txt
src/ips_options/test/ips_regex_test.cc
src/js_norm/js_enum.h
src/js_norm/js_norm.h
src/js_norm/js_normalizer.h
src/js_norm/js_pdf_norm.h
src/js_norm/test/CMakeLists.txt
src/js_norm/test/pdf_tokenizer_benchmark.cc
src/latency/latency_stats.h
src/latency/rule_latency.cc
src/log/CMakeLists.txt
src/log/log.cc
src/log/log.h
src/log/log_errors.h [new file with mode: 0644]
src/log/log_stats.cc [new file with mode: 0644]
src/log/log_stats.h [new file with mode: 0644]
src/log/log_text.cc
src/log/log_text.h
src/log/messages.cc
src/log/messages.h
src/loggers/alert_csv.cc
src/loggers/alert_fast.cc
src/loggers/alert_full.cc
src/loggers/alert_json.cc
src/loggers/alert_luajit.cc
src/loggers/alert_syslog.cc
src/loggers/alert_talos.cc
src/loggers/alert_unixsock.cc
src/loggers/log_codecs.cc
src/loggers/log_pcap.cc
src/loggers/unified2.cc
src/main.cc
src/main/CMakeLists.txt
src/main/analyzer.cc
src/main/analyzer.h
src/main/help.cc
src/main/modules.cc
src/main/modules.h
src/main/numa.h [moved from src/utils/util_numa.h with 93% similarity]
src/main/policy.cc
src/main/process.cc [moved from src/helpers/process.cc with 61% similarity]
src/main/process.h [moved from src/helpers/process.h with 77% similarity]
src/main/snort.cc
src/main/snort.h
src/main/snort_config.cc
src/main/snort_config.h
src/main/snort_module.cc
src/main/snort_module.h
src/main/snort_types.h
src/main/swapper.h
src/main/test/distill_verdict_stubs.h
src/main/thread.h
src/main/thread_config.cc
src/managers/CMakeLists.txt
src/managers/action_manager.cc
src/managers/action_manager.h
src/managers/codec_manager.cc
src/managers/codec_manager.h
src/managers/event_manager.h
src/managers/inspector_manager.cc
src/managers/inspector_manager.h
src/managers/ips_manager.cc
src/managers/module_manager.cc
src/managers/plugin_manager.cc
src/managers/policy_selector_manager.cc
src/managers/so_manager.cc
src/managers/test/get_inspector_stubs.h
src/managers/test/get_inspector_test.cc
src/memory/heap_interface.cc
src/memory/memory_cap.cc
src/memory/memory_overloads.cc
src/memory/test/memory_cap_test.cc
src/mime/CMakeLists.txt
src/mime/decode_b64.h
src/network_inspectors/CMakeLists.txt
src/network_inspectors/appid/app_info_table.h
src/network_inspectors/appid/appid_api.cc
src/network_inspectors/appid/appid_debug.h
src/network_inspectors/appid/appid_discovery.cc
src/network_inspectors/appid/appid_ha.cc
src/network_inspectors/appid/appid_http_event_handler.cc
src/network_inspectors/appid/appid_inspector.cc
src/network_inspectors/appid/appid_module.cc
src/network_inspectors/appid/appid_peg_counts.cc
src/network_inspectors/appid/appid_peg_counts.h
src/network_inspectors/appid/appid_session_api.cc
src/network_inspectors/appid/appid_session_api.h
src/network_inspectors/appid/appid_types.h
src/network_inspectors/appid/appid_utils/sf_mlmp.cc
src/network_inspectors/appid/client_plugins/client_app_bit.cc
src/network_inspectors/appid/client_plugins/client_app_bit_tracker.cc
src/network_inspectors/appid/client_plugins/eve_ca_patterns.cc
src/network_inspectors/appid/detector_plugins/http_url_patterns.cc
src/network_inspectors/appid/detector_plugins/ssl_patterns.cc
src/network_inspectors/appid/detector_plugins/test/detector_plugins_mock.h
src/network_inspectors/appid/host_port_app_cache.cc
src/network_inspectors/appid/ips_appid_option.cc
src/network_inspectors/appid/lua_detector_module.cc
src/network_inspectors/appid/lua_detector_module.h
src/network_inspectors/appid/service_plugins/alpn_patterns.cc
src/network_inspectors/appid/service_plugins/test/service_netbios_test.cc [deleted file]
src/network_inspectors/appid/service_plugins/test/service_plugin_mock.h
src/network_inspectors/appid/test/appid_api_test.cc
src/network_inspectors/appid/test/appid_discovery_test.cc
src/network_inspectors/appid/test/appid_http_session_test.cc
src/network_inspectors/appid/test/appid_session_api_test.cc
src/network_inspectors/appid/test/tp_lib_handler_test.cc
src/network_inspectors/appid/tp_appid_module_api.cc
src/network_inspectors/appid/tp_appid_module_api.h
src/network_inspectors/appid/tp_appid_utils.cc
src/network_inspectors/arp_spoof/arp_spoof.cc
src/network_inspectors/binder/bind_module.cc
src/network_inspectors/binder/binder.cc
src/network_inspectors/binder/binding.cc
src/network_inspectors/binder/binding.h
src/network_inspectors/normalize/norm_stats.h
src/network_inspectors/packet_capture/packet_capture.cc
src/network_inspectors/packet_tracer/CMakeLists.txt [deleted file]
src/network_inspectors/perf_monitor/cpu_tracker.cc
src/network_inspectors/perf_monitor/json_formatter.cc
src/network_inspectors/perf_monitor/perf_module.cc
src/network_inspectors/perf_monitor/perf_module.h
src/network_inspectors/perf_monitor/perf_monitor.cc
src/network_inspectors/perf_monitor/perf_monitor.h
src/network_inspectors/perf_monitor/perf_tracker.cc
src/network_inspectors/perf_monitor/text_formatter.cc
src/network_inspectors/port_scan/port_scan.cc
src/network_inspectors/port_scan/ps_detect.cc
src/network_inspectors/port_scan/ps_module.cc
src/network_inspectors/reputation/reputation_commands.cc
src/network_inspectors/reputation/reputation_common.h
src/network_inspectors/reputation/reputation_config.h
src/network_inspectors/reputation/reputation_inspect.cc
src/network_inspectors/reputation/reputation_module.h
src/network_inspectors/rna/CMakeLists.txt
src/network_inspectors/rna/data_purge_cmd.cc
src/network_inspectors/rna/rna_fingerprint_ua.cc
src/network_inspectors/rna/rna_fingerprint_udp.cc
src/network_inspectors/rna/rna_flow.h
src/network_inspectors/rna/rna_inspector.cc
src/network_inspectors/rna/rna_logger.cc
src/network_inspectors/rna/rna_logger.h
src/network_inspectors/rna/rna_logger_event.h [new file with mode: 0644]
src/network_inspectors/rna/rna_module.cc
src/network_inspectors/rna/rna_tracker.h [new file with mode: 0644]
src/network_inspectors/rna/test/rna_module_stubs.h
src/packet_io/CMakeLists.txt
src/packet_io/active.cc
src/packet_io/active.h
src/packet_io/active_counts.h [new file with mode: 0644]
src/packet_io/packet_constraints.cc [moved from src/framework/packet_constraints.cc with 99% similarity]
src/packet_io/packet_constraints.h [moved from src/framework/packet_constraints.h with 100% similarity]
src/packet_io/packet_tracer.cc [moved from src/network_inspectors/packet_tracer/packet_tracer.cc with 91% similarity]
src/packet_io/packet_tracer.h [moved from src/network_inspectors/packet_tracer/packet_tracer.h with 83% similarity]
src/packet_io/packet_tracer_module.cc [moved from src/network_inspectors/packet_tracer/packet_tracer_module.cc with 100% similarity]
src/packet_io/packet_tracer_module.h [moved from src/network_inspectors/packet_tracer/packet_tracer_module.h with 100% similarity]
src/packet_io/sfdaq_instance.cc
src/packet_io/sfdaq_module.h
src/parser/cmd_line.cc
src/parser/config_file.cc
src/parser/parse_rule.cc
src/parser/parse_utils.h
src/parser/parser.cc
src/parser/parser.h
src/payload_injector/payload_injector.cc
src/payload_injector/test/payload_injector_test.cc
src/policy_selectors/address_space_selector/address_space_selector.cc
src/policy_selectors/address_space_selector/address_space_selector_module.h
src/policy_selectors/tenant_selector/tenant_selector.cc
src/ports/port_object2.h
src/ports/port_utils.h
src/profiler/CMakeLists.txt
src/profiler/profiler.cc
src/profiler/profiler.h
src/profiler/profiler_defs.h
src/profiler/profiler_impl.h [new file with mode: 0644]
src/profiler/profiler_module.cc
src/profiler/time_profiler.cc
src/profiler/time_profiler_defs.h
src/protocols/ip.h
src/protocols/layer.h
src/protocols/mpls.h
src/protocols/packet.cc
src/protocols/packet.h
src/protocols/packet_manager.cc
src/protocols/packet_manager.h
src/protocols/protocol_ids.h
src/protocols/ssl.h
src/protocols/tcp.h
src/protocols/test/decode_err_len_test.cc
src/protocols/test/get_geneve_opt_test.cc
src/pub_sub/dns_events.cc
src/search_engines/ac_bnfa.cc
src/search_engines/ac_full.cc
src/search_engines/acsmx2.cc
src/search_engines/bnfa_search.cc
src/search_engines/hyperscan.cc
src/search_engines/pat_stats.h
src/search_engines/search_tool.cc
src/search_engines/test/CMakeLists.txt
src/search_engines/test/hyper_tool_test.cc
src/search_engines/test/hyperscan_test.cc
src/search_engines/test/mpse_test_stubs.cc
src/search_engines/test/mpse_test_stubs.h
src/service_inspectors/CMakeLists.txt
src/service_inspectors/back_orifice/back_orifice.cc
src/service_inspectors/cip/cip.cc
src/service_inspectors/cip/cip.h
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_enipreq.cc
src/service_inspectors/cip/ips_cip_eniprsp.cc
src/service_inspectors/cip/ips_cip_instance.cc
src/service_inspectors/cip/ips_cip_req.cc
src/service_inspectors/cip/ips_cip_rsp.cc
src/service_inspectors/cip/ips_cip_service.cc
src/service_inspectors/cip/ips_cip_status.cc
src/service_inspectors/dce_rpc/dce_common.cc
src/service_inspectors/dce_rpc/dce_expected_session.cc
src/service_inspectors/dce_rpc/dce_http_proxy.cc
src/service_inspectors/dce_rpc/dce_http_proxy_module.h
src/service_inspectors/dce_rpc/dce_http_server.cc
src/service_inspectors/dce_rpc/dce_http_server_module.h
src/service_inspectors/dce_rpc/dce_smb.h
src/service_inspectors/dce_rpc/dce_smb2.cc
src/service_inspectors/dce_rpc/dce_smb2_commands.cc
src/service_inspectors/dce_rpc/dce_smb2_commands.h
src/service_inspectors/dce_rpc/dce_smb2_utils.cc
src/service_inspectors/dce_rpc/dce_smb_module.cc
src/service_inspectors/dce_rpc/dce_smb_utils.cc
src/service_inspectors/dce_rpc/dce_tcp.cc
src/service_inspectors/dce_rpc/ips_dce_iface.cc
src/service_inspectors/dce_rpc/ips_dce_opnum.cc
src/service_inspectors/dce_rpc/ips_dce_stub_data.cc
src/service_inspectors/dce_rpc/smb_message.cc
src/service_inspectors/dnp3/dnp3.cc
src/service_inspectors/dnp3/dnp3_reassembly.cc
src/service_inspectors/dnp3/ips_dnp3_data.cc
src/service_inspectors/dnp3/ips_dnp3_func.cc
src/service_inspectors/dnp3/ips_dnp3_ind.cc
src/service_inspectors/dnp3/ips_dnp3_obj.cc
src/service_inspectors/dns/dns_module.h
src/service_inspectors/ftp_telnet/CMakeLists.txt
src/service_inspectors/ftp_telnet/ft_main.cc
src/service_inspectors/ftp_telnet/ftp.cc
src/service_inspectors/ftp_telnet/ftp_data.cc
src/service_inspectors/ftp_telnet/ftpp_si.h
src/service_inspectors/ftp_telnet/ftpp_ui_config.h
src/service_inspectors/ftp_telnet/kmap.cc [moved from src/utils/kmap.cc with 99% similarity]
src/service_inspectors/ftp_telnet/kmap.h [moved from src/utils/kmap.h with 89% similarity]
src/service_inspectors/ftp_telnet/pp_ftp.cc
src/service_inspectors/ftp_telnet/pp_telnet.cc
src/service_inspectors/gtp/gtp.h
src/service_inspectors/gtp/gtp_inspect.cc
src/service_inspectors/gtp/gtp_parser.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_flow_data.h
src/service_inspectors/http2_inspect/http2_hpack.h
src/service_inspectors/http2_inspect/http2_hpack_int_decode.h
src/service_inspectors/http2_inspect/http2_push_promise_frame.h
src/service_inspectors/http2_inspect/http2_start_line.h
src/service_inspectors/http2_inspect/ips_http2.h
src/service_inspectors/http_inspect/http_event.h
src/service_inspectors/http_inspect/http_flow_data.h
src/service_inspectors/http_inspect/http_inspect.cc
src/service_inspectors/http_inspect/http_msg_request.cc
src/service_inspectors/http_inspect/http_msg_section.h
src/service_inspectors/http_inspect/ips_http_buffer.h
src/service_inspectors/http_inspect/ips_http_num_hdrs.h
src/service_inspectors/http_inspect/ips_http_param.cc
src/service_inspectors/http_inspect/ips_http_param.h
src/service_inspectors/http_inspect/ips_http_test.h
src/service_inspectors/http_inspect/ips_http_version.h
src/service_inspectors/http_inspect/test/http_module_test.cc
src/service_inspectors/http_inspect/test/http_uri_norm_test.cc
src/service_inspectors/iec104/iec104.cc
src/service_inspectors/iec104/iec104_decode.cc
src/service_inspectors/iec104/iec104_paf.cc
src/service_inspectors/iec104/iec104_parse_apdu.cc
src/service_inspectors/iec104/iec104_parse_information_object_elements.cc
src/service_inspectors/iec104/iec104_trace.h
src/service_inspectors/iec104/ips_iec104_apci_type.cc
src/service_inspectors/iec104/ips_iec104_asdu_func.cc
src/service_inspectors/mms/ips_mms_data.cc
src/service_inspectors/mms/ips_mms_func.cc
src/service_inspectors/mms/mms.cc
src/service_inspectors/mms/mms_decode.cc
src/service_inspectors/mms/mms_splitter.cc
src/service_inspectors/mms/util_tpkt.h
src/service_inspectors/modbus/ips_modbus_data.cc
src/service_inspectors/modbus/ips_modbus_func.cc
src/service_inspectors/modbus/ips_modbus_unit.cc
src/service_inspectors/modbus/modbus.cc
src/service_inspectors/modbus/modbus_decode.cc
src/service_inspectors/modbus/modbus_paf.cc
src/service_inspectors/netflow/CMakeLists.txt
src/service_inspectors/netflow/netflow.cc
src/service_inspectors/rpc_decode/rpc_decode.cc
src/service_inspectors/s7commplus/ips_s7comm_content.cc
src/service_inspectors/s7commplus/ips_s7comm_func.cc
src/service_inspectors/s7commplus/ips_s7comm_opcode.cc
src/service_inspectors/s7commplus/s7comm.cc
src/service_inspectors/s7commplus/s7comm_decode.cc
src/service_inspectors/s7commplus/s7comm_paf.cc
src/service_inspectors/service_inspectors.cc
src/service_inspectors/sip/ips_sip.cc
src/service_inspectors/sip/ips_sip_method.cc
src/service_inspectors/sip/ips_sip_stat_code.cc
src/service_inspectors/sip/sip.cc
src/service_inspectors/sip/sip_config.h
src/service_inspectors/sip/sip_dialog.cc
src/service_inspectors/sip/sip_module.cc
src/service_inspectors/sip/sip_parser.cc
src/service_inspectors/smtp/smtp.cc
src/service_inspectors/smtp/smtp_paf.cc
src/service_inspectors/smtp/smtp_util.cc
src/service_inspectors/smtp/smtp_xlink2state.cc
src/service_inspectors/ssh/ssh.cc
src/service_inspectors/ssl/CMakeLists.txt
src/service_inspectors/ssl/ips_ssl_state.cc
src/service_inspectors/ssl/ips_ssl_version.cc
src/service_inspectors/ssl/ssl_inspector.cc
src/service_inspectors/wizard/curse_book.h
src/service_inspectors/wizard/dce_curse.h
src/service_inspectors/wizard/mms_curse.h
src/service_inspectors/wizard/s7commplus_curse.h
src/sfip/sf_ip.cc
src/sfip/sf_ip.h
src/side_channel/side_channel.h
src/side_channel/test/side_channel_module_test.cc
src/stream/CMakeLists.txt
src/stream/base/stream_ha.cc
src/stream/ip/ip_defrag.cc
src/stream/paf.cc
src/stream/paf.h
src/stream/paf_stats.h [new file with mode: 0644]
src/stream/stream.cc
src/stream/stream.h
src/stream/tcp/ips_stream_reassemble.cc
src/stream/tcp/ips_stream_size.cc
src/stream/tcp/tcp_defs.h
src/stream/tcp/tcp_event_logger.cc
src/stream/tcp/tcp_event_logger.h
src/stream/tcp/tcp_module.cc
src/stream/tcp/tcp_module.h
src/stream/tcp/tcp_normalizer.cc
src/stream/tcp/tcp_normalizer.h
src/stream/tcp/tcp_reassembler.cc
src/stream/tcp/tcp_segment_descriptor.cc
src/stream/tcp/tcp_segment_descriptor.h
src/stream/tcp/tcp_segment_node.cc
src/stream/tcp/tcp_session.cc
src/stream/tcp/tcp_state_listen.cc
src/stream/tcp/tcp_state_none.cc
src/stream/tcp/tcp_stream_session.cc
src/stream/tcp/tcp_trace.cc
src/stream/tcp/tcp_trace.h
src/stream/test/stream_splitter_test.cc
src/stream/udp/CMakeLists.txt
src/stream/udp/udp_session.h
src/stream/user/user_session.cc
src/target_based/host_attributes.cc
src/time/packet_time.cc
src/trace/trace.h
src/trace/trace_api.cc
src/trace/trace_config.cc
src/trace/trace_module.cc
src/trace/trace_parser.h
src/trace/trace_swap.cc
src/utils/CMakeLists.txt
src/utils/bits.h [moved from src/framework/bits.h with 100% similarity]
src/utils/chunk.cc [moved from src/helpers/chunk.cc with 100% similarity]
src/utils/chunk.h [moved from src/helpers/chunk.h with 100% similarity]
src/utils/dev_notes.txt
src/utils/stats.cc
src/utils/stats.h
src/utils/test/CMakeLists.txt [deleted file]
src/utils/util.cc
src/utils/util.h
src/utils/util_cstring.h
src/utils/util_jsnorm.cc

index a00ba6e599794cab973ec2f4059f7e7409d20000..23a52d046cd3e922330b3e8ead44746fda9bc299 100644 (file)
@@ -4,6 +4,7 @@ set (
     snort_devel.txt
     extending.txt
     style.txt
+    versions.txt
 )
 
 foreach ( file_name ${UNBUILT_SOURCES} )
index b6d39e80207e3ce471bb78bbf0eda2caf5057413..4ab84110045e9c960231bcc5ead8f5751739beda 100644 (file)
@@ -10,6 +10,10 @@ include::version.txt[]
 
 toc::[]
 
+== Versions
+
+include::versions.txt[]
+
 == Extending Snort
 
 include::extending.txt[]
diff --git a/doc/devel/versions.txt b/doc/devel/versions.txt
new file mode 100644 (file)
index 0000000..72e38fc
--- /dev/null
@@ -0,0 +1,67 @@
+
+=== Versions
+
+Snort 3 does not follow semantic versioning (major.minor.patch) because
+<non-technical reasons>.
+
+The Snort 3 version is of the form 3.A.R.B where:
+
+* 3 is fixed for now.
+
+* A is bumped when the API changes as defined in framework/snort_api.h.
+
+* R is bumped for each regular release (nominally every 2 weeks).
+
+* B is the build number supplied at the time of build and is always zero
+  for github releases.
+
+Some background on plugin versions is required to fully explain the
+significance of A.
+
+There are several Snort 3 plugin types defined in these headers:
+
+* framework/codec.h
+* framework/connector.h
+* framework/inspector.h
+* framework/ips_action.h
+* framework/ips_option.h
+* framework/logger.h
+* framework/mpse.h
+* framework/policy_selector.h
+* framework/so_rule.h
+
+Each of the above has its own version number that pertains specifically to the file
+in which it is defined. In addition, these plugins have a common part defined in:
+
+* framework/base_api.h.
+
+The above file specifies a version number for the common part shared by all plugins
+which includes all the other files found in framework/snort_api.h.
+
+These API version numbers are not included in the Snort 3 version but, if any
+of them changes, indicating a change to the plugin API, then A is bumped to
+indicate that a new version of the API exists. So A will be bumped for any of
+the following:
+
+* base API version change
+* plugin API version change
+* DAQ version change
+
+There are many other exported features apart from those included directly in
+framework/snort_api.h and if you use them, you must rebuild your plugins with
+each new release. If you just use the snort_api.h includes, you will only need
+to rebuild your plugins if A changes.
+
+For the best security efficacy and stability, there is no requirement to
+maintain backward compatibility, so you may need to tweak code when you
+rebuild your plugin.  Developers will not change the APIs without good reason,
+but existing code will be changed as needed and these changes may break your
+plugin.
+
+That said, if you want to reduce the number of times you release plugins, you
+can study the change set to see if it affects you. Due to the complexity of
+Snort and the API, this is possible but cannot be recommended.
+
+As of this writing the version is 3.1.85 and this will be merged with the 3.2.0
+release. The significance of the A component prior to 3.2.0 is not well defined.
+
index e4448878665c1a7bc4af23b13add541cad99d4f8..63d350c24cca5e220289ccc8f09d2db93f5e5486 100644 (file)
@@ -60,8 +60,8 @@ objectives, including:
 * IpsOption - for detection in Snort rules
 * IpsAction - for custom actions
 * Logger - for handling events
-* Mpse - for fast pattern matching
-* So - for dynamic rules
+* MPSE - for fast pattern matching
+* SO - for dynamic rules
 
 The power of plugins is that they have a very focused purpose and can be
 created with relative ease.  For example, you can extend the rule language
index 9b520241d75268b2bac3580708d28d4282af348a..3501c5adb642dcde8846361b8d1fcc77eff57d45 100644 (file)
@@ -14,7 +14,7 @@ perf_monitor supports several trackers for monitoring such data:
 The base tracker is used to gather running statistics about Snort and its
 running modules. All Snort modules gather, at the very least, counters for the
 number of packets reaching it. Most supplement these counts with those for
-domain specific functions, such as http_inspect’s number of GET requests seen.
+domain specific functions, such as the number of GET requests seen by http_inspect.
 
 Statistics are gathered live and can be reported at regular intervals. The stats
 reported correspond only to the interval in question and are reset at the
index 7dde1c9f4c3cc83dde620df92a783f0dfd8d4296..ce97ca611c4b49f9243e6a9c6fc43bc6d4207442 100644 (file)
@@ -1,26 +1,21 @@
 
-set ( ACTIONS_INCLUDES
-    actions.h
-)
-
 set (IPS_ACTION_SOURCES
-    actions.cc
     actions_module.cc
     actions_module.h
     ips_actions.cc
     ips_actions.h
+)
+
+set( PLUGIN_LIST
     act_alert.cc
     act_block.cc
     act_drop.cc
     act_file_id.cc
     act_log.cc
     act_pass.cc
+    act_react.cc
     act_reject.cc
     act_replace.cc
-)
-
-set( PLUGIN_LIST
-    act_react.cc
     )
 
 if (STATIC_IPS_ACTIONS)
@@ -35,11 +30,15 @@ else (STATIC_IPS_ACTIONS)
         ${IPS_ACTION_SOURCES}
     )
 
+    add_dynamic_module(act_alert ips_actions act_alert.cc actions_module.cc)
+    add_dynamic_module(act_block ips_actions act_block.cc actions_module.cc)
+    add_dynamic_module(act_drop ips_actions act_drop.cc actions_module.cc)
+    add_dynamic_module(act_file_id ips_actions act_file_id.cc actions_module.cc)
+    add_dynamic_module(act_log ips_actions act_log.cc actions_module.cc)
+    add_dynamic_module(act_pass ips_actions act_pass.cc actions_module.cc)
     add_dynamic_module(act_react ips_actions act_react.cc actions_module.cc)
+    add_dynamic_module(act_reject ips_actions act_reject.cc actions_module.cc)
+    add_dynamic_module(act_replace ips_actions act_replace.cc actions_module.cc)
 
 endif (STATIC_IPS_ACTIONS)
 
-install (FILES ${ACTIONS_INCLUDES}
-    DESTINATION "${INCLUDE_INSTALL_PATH}/actions"
-)
-
index d46302d8552eec60a511be93172280e9df01fb0d..90af5eecb0785f412ea87f5bb562111b5e2e9a02 100644 (file)
 #include "config.h"
 #endif
 
-#include "actions/actions_module.h"
 #include "framework/ips_action.h"
 #include "framework/module.h"
 #include "protocols/packet.h"
 
-#include "actions.h"
+#include "actions_module.h"
 
 using namespace snort;
 
@@ -55,12 +54,12 @@ class AlertAction : public IpsAction
 public:
     AlertAction() : IpsAction(action_name, nullptr) { }
 
-    void exec(Packet*, const OptTreeNode* otn) override;
+    void exec(Packet*, const ActInfo&) override;
 };
 
-void AlertAction::exec(Packet* p, const OptTreeNode* otn)
+void AlertAction::exec(Packet* p, const ActInfo& ai)
 {
-    Actions::alert(p, otn);
+    alert(p, ai);
     ++alert_stats.alert;
 }
 
@@ -120,7 +119,11 @@ static ActionApi alert_api
     alert_dtor
 };
 
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
 const BaseApi* act_alert[] =
+#endif
 {
     &alert_api.base,
     nullptr
index 7e9e0d5df69d7c3f30449322ec028398be9804bf..e341831dcd7980baca42debee6accd90c6420a4e 100644 (file)
 #include "config.h"
 #endif
 
-#include "actions/actions_module.h"
 #include "framework/ips_action.h"
 #include "framework/module.h"
 #include "packet_io/active.h"
 #include "protocols/packet.h"
 
-#include "actions.h"
+#include "actions_module.h"
 
 using namespace snort;
 
@@ -56,16 +55,16 @@ class BlockAction : public IpsAction
 public:
     BlockAction() : IpsAction(action_name, nullptr) { }
 
-    void exec(Packet*, const OptTreeNode* otn) override;
+    void exec(Packet*, const ActInfo&) override;
     bool drops_traffic() override { return true; }
 };
 
-void BlockAction::exec(Packet* p, const OptTreeNode* otn)
+void BlockAction::exec(Packet* p, const ActInfo& ai)
 {
     p->active->block_session(p);
     p->active->set_drop_reason("ips");
 
-    Actions::alert(p, otn);
+    alert(p, ai);
     ++block_stats.block;
 }
 
@@ -125,7 +124,11 @@ static ActionApi block_api
     block_dtor
 };
 
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
 const BaseApi* act_block[] =
+#endif
 {
     &block_api.base,
     nullptr
index ae69f6e3e65f323f953976ed9611b8a5af8e3e7d..6ab2c220075ccc3cc3474934b845e36641152faf 100644 (file)
 #include "config.h"
 #endif
 
-#include "actions/actions_module.h"
 #include "framework/ips_action.h"
 #include "framework/module.h"
 #include "packet_io/active.h"
 #include "protocols/packet.h"
 
-#include "actions.h"
+#include "actions_module.h"
 
 using namespace snort;
 
@@ -56,16 +55,16 @@ class DropAction : public IpsAction
 public:
     DropAction() : IpsAction(action_name, nullptr) { }
 
-    void exec(Packet*, const OptTreeNode* otn) override;
+    void exec(Packet*, const ActInfo&) override;
     bool drops_traffic() override { return true; }
 };
 
-void DropAction::exec(Packet* p, const OptTreeNode* otn)
+void DropAction::exec(Packet* p, const ActInfo& ai)
 {
     p->active->drop_packet(p);
     p->active->set_drop_reason("ips");
 
-    Actions::alert(p, otn);
+    alert(p, ai);
     ++drop_stats.drop;
 }
 
@@ -126,7 +125,11 @@ static ActionApi drop_api
     drop_dtor
 };
 
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
 const BaseApi* act_drop[] =
+#endif
 {
     &drop_api.base,
     nullptr
index 70386fbee0cb1d47cf614f13b022cf807400940c..061332d2124bb7af63dedfe22b02d09320b89a6e 100644 (file)
 #include "config.h"
 #endif
 
-#include "actions.h"
-#include "actions/actions_module.h"
-#include "detection/detect.h"
 #include "file_api/file_flows.h"
-#include "file_api/file_identifier.h"
+#include "file_api/file_lib.h"
+#include "framework/ips_action.h"
 #include "managers/action_manager.h"
 #include "parser/parser.h"
-#include "utils/stats.h"
+
+#include "actions_module.h"
 
 using namespace snort;
 
@@ -59,21 +58,25 @@ class File_IdAction : public IpsAction
 {
 public:
     File_IdAction() : IpsAction(action_name, nullptr) { }
-    void exec(Packet*, const OptTreeNode* otn) override;
+    void exec(Packet*, const ActInfo&) override;
 };
 
-void File_IdAction::exec(Packet* p, const OptTreeNode* otn)
+void File_IdAction::exec(Packet* p, const ActInfo& ai)
 {
     if (!p->flow)
       return;
+
     FileFlows* files = FileFlows::get_file_flows(p->flow, false);
+
     if (!files)
         return;
+
     FileContext* file = files->get_current_file_context();
+
     if (!file)
         return;
-    file->set_file_type(otn->sigInfo.file_id);
 
+    file->set_file_type(get_file_id(ai));
     ++file_id_stats.file_id;
 }
 
@@ -134,7 +137,11 @@ static ActionApi file_id_api
     file_id_dtor
 };
 
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
 const BaseApi* act_file_id[] =
+#endif
 {
     &file_id_api.base,
     nullptr
index 8b6689c7535e74ea25b2dde1163f0da73786abfa..dc2a20db32ceba3ccdd803be45fb77a204ac94e8 100644 (file)
 #include "config.h"
 #endif
 
-#include "actions/actions_module.h"
+#include <cassert>
+
 #include "framework/ips_action.h"
 #include "framework/module.h"
 #include "protocols/packet.h"
 
-#include "actions.h"
+#include "actions_module.h"
 
 using namespace snort;
 
@@ -55,14 +56,14 @@ class LogAction : public IpsAction
 public:
     LogAction() : IpsAction(action_name, nullptr) { }
 
-    void exec(Packet*, const OptTreeNode* otn) override;
+    void exec(Packet*, const ActInfo&) override;
 };
 
-void LogAction::exec(Packet* p, const OptTreeNode* otn)
+void LogAction::exec(Packet* p, const ActInfo& ai)
 {
-    if ( otn )
+    if ( log_it(ai) )
     {
-        Actions::log(p, otn);
+        log(p, ai);
         ++log_stats.log;
     }
 }
@@ -124,7 +125,11 @@ static ActionApi log_api
     log_dtor
 };
 
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
 const BaseApi* act_log[] =
+#endif
 {
     &log_api.base,
     nullptr
index 15987dbce5d8972385655b2200e68b6b922d7d78..94facf401118af2e79748ffec2d7ee7a2cdf4883 100644 (file)
 #include "config.h"
 #endif
 
-#include "actions/actions_module.h"
+#include <cassert>
+
 #include "framework/ips_action.h"
 #include "framework/module.h"
 #include "protocols/packet.h"
 
-#include "actions.h"
+#include "actions_module.h"
 
 using namespace snort;
 
@@ -55,14 +56,14 @@ class PassAction : public IpsAction
 public:
     PassAction() : IpsAction(action_name, nullptr) { }
 
-    void exec(Packet*, const OptTreeNode*) override;
+    void exec(Packet*, const ActInfo&) override;
 };
 
-void PassAction::exec(Packet* p, const OptTreeNode* otn)
+void PassAction::exec(Packet* p, const ActInfo& ai)
 {
-    if ( otn )
+    if ( log_it(ai) )
     {
-        Actions::pass();
+        pass();
         p->packet_flags |= PKT_PASS_RULE;
         ++pass_stats.pass;
     }
@@ -125,7 +126,11 @@ static ActionApi pass_api
     pass_dtor
 };
 
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
 const BaseApi* act_pass[] =
+#endif
 {
     &pass_api.base,
     nullptr
index 14ed536ce4373bf575f3b8ba5a52dac985ad95f4..73f4576b9f32a1d5c6d42f3d1bb271f85d6ee5a0 100644 (file)
@@ -62,8 +62,6 @@
 #include "utils/util.h"
 #include "utils/util_cstring.h"
 
-#include "actions.h"
-
 using namespace snort;
 using namespace HttpCommon;
 using namespace Http2Enums;
@@ -214,7 +212,7 @@ public:
     ~ReactAction() override
     { delete config; }
 
-    void exec(Packet*, const OptTreeNode* otn) override;
+    void exec(Packet*, const ActInfo&) override;
     bool drops_traffic() override { return true; }
 
 private:
@@ -222,12 +220,12 @@ private:
     ReactActiveAction react_act_action;
 };
 
-void ReactAction::exec(Packet* p, const OptTreeNode* otn)
+void ReactAction::exec(Packet* p, const ActInfo& ai)
 {
     p->active->drop_packet(p);
     p->active->set_drop_reason("ips");
 
-    Actions::alert(p, otn);
+    alert(p, ai);
     ++react_stats.react;
 }
 
index 28bc7d805f7a151ff688bbba2a7742ba8174c9c8..df830aec6c3bd7c143bdfdeca6c95cbedebe4d59 100644 (file)
@@ -55,8 +55,6 @@
 #include "packet_io/active.h"
 #include "profiler/profiler.h"
 
-#include "actions.h"
-
 using namespace snort;
 
 #define action_name "reject"
@@ -170,7 +168,7 @@ class RejectAction : public IpsAction
 public:
     RejectAction(uint32_t f = REJ_RST_BOTH);
 
-    void exec(Packet*, const OptTreeNode* otn) override;
+    void exec(Packet*, const ActInfo&) override;
 
 private:
     RejectActiveAction rej_act_action;
@@ -183,14 +181,14 @@ private:
 RejectAction::RejectAction(uint32_t f) : IpsAction(action_name, &rej_act_action) , rej_act_action(f)
 { }
 
-void RejectAction::exec(Packet* p, const OptTreeNode* otn)
+void RejectAction::exec(Packet* p, const ActInfo& ai)
 {
     p->active->set_delayed_action(Active::ACT_RESET, get_active_action());
     p->active->set_drop_reason("ips");
     p->active->reset_again();
     p->active->update_status(p);
 
-    Actions::alert(p, otn);
+    alert(p, ai);
     ++reject_stats.reject;
 }
 
@@ -341,7 +339,11 @@ static const ActionApi rej_api =
     rej_dtor
 };
 
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
 const BaseApi* act_reject[] =
+#endif
 {
     &rej_api.base,
     nullptr
index 14c24fa4d03e42bd655bdc78db8e0be397db7363..f49905963e199af91cf08b09e7afd9f016e7abc5 100644 (file)
@@ -28,8 +28,6 @@
 #include "packet_io/active.h"
 #include "protocols/packet.h"
 
-#include "actions.h"
-
 using namespace snort;
 
 #define action_name "rewrite"
@@ -113,17 +111,17 @@ class ReplaceAction : public IpsAction
 public:
     ReplaceAction() : IpsAction(action_name, &rep_act_action) { }
 
-    void exec(Packet*, const OptTreeNode* otn) override;
+    void exec(Packet*, const ActInfo&) override;
 
 private:
     ReplaceActiveAction rep_act_action;
 };
 
-void ReplaceAction::exec(Packet* p, const OptTreeNode* otn)
+void ReplaceAction::exec(Packet* p, const ActInfo& ai)
 {
     p->active->rewrite_packet(p);
 
-    Actions::alert(p, otn);
+    alert(p, ai);
     ++replace_stats.replace;
 }
 
@@ -184,7 +182,11 @@ static ActionApi rep_api
     rep_dtor
 };
 
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
 const BaseApi* act_replace[] =
+#endif
 {
     &rep_api.base,
     nullptr
diff --git a/src/actions/actions.cc b/src/actions/actions.cc
deleted file mode 100644 (file)
index 801150a..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-//--------------------------------------------------------------------------
-// Copyright (C) 2014-2024 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.
-//--------------------------------------------------------------------------
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "actions.h"
-
-#include "detection/detect.h"
-#include "managers/action_manager.h"
-#include "parser/parser.h"
-#include "utils/stats.h"
-
-using namespace snort;
-
-void Actions::pass()
-{
-    pc.pass_pkts++;
-}
-
-void Actions::log(Packet* p, const OptTreeNode* otn)
-{
-    RuleTreeNode* rtn = getRtnFromOtn(otn);
-    if (!rtn)
-        return;
-
-    CallLogFuncs(p, otn, rtn->listhead);
-}
-
-void Actions::alert(Packet* p, const OptTreeNode* otn)
-{
-    if (!otn)
-        return;
-
-    RuleTreeNode* rtn = getRtnFromOtn(otn);
-    if (!rtn)
-        return;
-
-    /* Call OptTreeNode specific output functions */
-    if (otn->outputFuncs)
-    {
-        ListHead lh = {};  // FIXIT-L use of ListHead for CallLogFuncs() is a little unwieldy here
-        lh.LogList = otn->outputFuncs;
-        CallLogFuncs(p, otn, &lh);
-    }
-    CallAlertFuncs(p, otn, rtn->listhead);
-    CallLogFuncs(p, otn, rtn->listhead);
-}
-
-std::string Actions::get_string(Actions::Type action)
-{
-    return ActionManager::get_action_string(action);
-}
-
-Actions::Type Actions::get_type(const char* s)
-{
-    return ActionManager::get_action_type(s);
-}
-
-Actions::Type Actions::get_max_types()
-{
-    return ActionManager::get_max_action_types();
-}
-
-bool Actions::is_valid_action(Actions::Type action)
-{
-    if ( action < get_max_types() )
-        return true;
-
-    return false;
-}
-
-std::string Actions::get_default_priorities(bool alert_before_pass)
-{
-    return ActionManager::get_action_priorities(alert_before_pass);
-}
index ddeb0e4e9de49d83d0ba60c9c679c1bcf79aff07..07d1a989800cc59090206b6037dfea16741763d0 100644 (file)
 #include "config.h"
 #endif
 
+#include "actions_module.h"
+
 #include <algorithm>
 #include <vector>
 
-#include "actions_module.h"
-#include "actions/actions.h"
 #include "log/messages.h"
 #include "managers/action_manager.h"
 #include "managers/module_manager.h"
index c5a955add33298d64af5ec7bd0bd3de76d4b0a52..d530b25d79ac688194c3f2a4c8260ca735c4d8ed 100644 (file)
 using namespace snort;
 
 #ifdef STATIC_IPS_ACTIONS
-extern const BaseApi* act_react[];
-#endif
 extern const BaseApi* act_alert[];
 extern const BaseApi* act_block[];
 extern const BaseApi* act_drop[];
 extern const BaseApi* act_file_id[];
 extern const BaseApi* act_log[];
 extern const BaseApi* act_pass[];
+extern const BaseApi* act_react[];
 extern const BaseApi* act_reject[];
 extern const BaseApi* act_replace[];
+#endif
 
 void load_actions()
 {
 #ifdef STATIC_IPS_ACTIONS
-    PluginManager::load_plugins(act_react);
-#endif
     PluginManager::load_plugins(act_alert);
     PluginManager::load_plugins(act_block);
     PluginManager::load_plugins(act_drop);
     PluginManager::load_plugins(act_file_id);
     PluginManager::load_plugins(act_log);
     PluginManager::load_plugins(act_pass);
+    PluginManager::load_plugins(act_react);
     PluginManager::load_plugins(act_reject);
     PluginManager::load_plugins(act_replace);
+#endif
 }
 
index 66adba2075d1c7e4cac5f8064c975505ff8cfd59..0412e6948739574c6cba312007a4806df331ec2d 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "codecs/codec_module.h"
 #include "framework/codec.h"
-#include "log/log.h"
 #include "log/log_text.h"
 #include "main/snort_config.h"
 #include "parser/parse_ip.h"
@@ -573,7 +572,7 @@ void TcpCodec::log(TextLog* const text_log, const uint8_t* raw_pkt,
     const tcp::TCPHdr* const tcph = reinterpret_cast<const tcp::TCPHdr*>(raw_pkt);
 
     /* print TCP flags */
-    CreateTCPFlagString(tcph, tcpFlags);
+    tcph->stringify_flags(tcpFlags);
     TextLog_Puts(text_log, tcpFlags); /* We don't care about the null */
 
     /* print other TCP info */
index f0f1530eeb88b2e6c53af0df97b047f20f3432da..dde34c5eb2772e9063b1a4d73088ed766c5fbc92 100644 (file)
@@ -75,9 +75,5 @@ static const CodecApi default_api =
     dtor, // dtor
 };
 
-const CodecApi* default_codec[] =
-{
-    &default_api,
-    nullptr
-};
+const CodecApi* default_codec = &default_api;
 
index 7082dfe73702b5349d81ce14d94b43c0003c1c39..7e1c1e628c24722a1ad221e85f60f9fbbc86b839 100644 (file)
@@ -27,7 +27,7 @@
 #include <CppUTestExt/MockSupport.h>
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 namespace snort
 {
index 63c3de64b046ea050fa57e78284fc84af8377d79..7bcf432dcf7e960a17c2bf503594fb91b436d804 100644 (file)
@@ -37,7 +37,7 @@ THREAD_LOCAL SimpleStats file_connector_stats;
 THREAD_LOCAL ProfileStats file_connector_perfstats;
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 namespace snort
 {
index 5c4a3ce5ef04bcaf2cee978ce0a0cdc8ca34cf69..f950401f40a9e93d03b7fee6ec849273f714195e 100644 (file)
@@ -51,7 +51,7 @@ Connector* connector_tb;
 Connector* connector_rb;
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 namespace snort
 {
index b3836d3b21b6d384eb9c3e845e69d721b7b6c043..aaaaf192909a21297eae138079832b45c8d6d4b9 100644 (file)
@@ -30,7 +30,6 @@
 #include <unistd.h>
 
 #include "log/messages.h"
-#include "main/thread.h"
 #include "profiler/profiler_defs.h"
 
 #include "tcp_connector_module.h"
index e944cbd4793039f21237a73040862647f56c42db..16342d9529b7fdd772104af9f4c6dfa3eafcbc9e 100644 (file)
@@ -37,7 +37,7 @@ THREAD_LOCAL SimpleStats tcp_connector_stats;
 THREAD_LOCAL ProfileStats tcp_connector_perfstats;
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 namespace snort
 {
index 0a1798e9d85f84544f6ffdbf30ba26e12551c361..76297a268fd5f3462365d85d6b62d4c465069350 100644 (file)
@@ -68,7 +68,7 @@ ConnectorCommon* connector_common;
 Connector* connector;
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 namespace snort
 {
index 25ef1e5ccc0879b23d414ae8589b926d8a956d25..b0814105e7885e7e4e31d298430973eb35d79c44 100644 (file)
@@ -90,7 +90,10 @@ private:
     static unsigned pending_cmds_count; //counter to serialize commands across control connections
 };
 
-#define LogRespond(cn, ...)       do { if (cn) cn->respond(__VA_ARGS__); else LogMessage(__VA_ARGS__); } while(0)
-#define LogfRespond(cn, fh, ...)  do { if (cn) cn->respond(__VA_ARGS__); else LogMessage(fh, __VA_ARGS__); } while(0)
+#define LogRespond(cn, ...) \
+    do { if (cn) cn->respond(__VA_ARGS__); else snort::LogMessage(__VA_ARGS__); } while(0)
+
+#define LogfRespond(cn, fh, ...) \
+    do { if (cn) cn->respond(__VA_ARGS__); else snort::LogMessage(fh, __VA_ARGS__); } while(0)
 
 #endif
index e4051693f9ad6a42b902505fd1799ce5771a5e5f..70e6e01d08191724ddccfe87d3837e621a39d028 100644 (file)
@@ -36,6 +36,7 @@
 #include "log/messages.h"
 #include "main/shell.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "utils/stats.h"
 #include "utils/util.h"
 #include "utils/util_cstring.h"
index 4609a0080282bfb4614950bea9a9f5cef0ec5b70..6dd941f1ceef36918ff74f5053562ff1a40ce097 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <cassert>
 
-#include "detection/detection_util.h"
 #include "utils/util.h"
 
 #include "file_decomp_pdf.h"
index 6c04d08c6bf250adea4c3fe5a3e59bd25251ce3c..99244e2255eb400cdeca8b2b680f17316906c31b 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <cassert>
 
-#include "main/thread.h"
 #include "utils/util.h"
 
 #ifdef UNIT_TEST
index 16b984596b7683a9ac6c925aec295f34528f3867..c35cea5031860d3516b46ccf1e999048032c7d7c 100644 (file)
 
 #include "detection/detection_engine.h"
 #include "helpers/literal_search.h"
+#include "helpers/utf.h"
 #include "ips_options/ips_vba_data.h"
 #include "trace/trace_api.h"
 #include "utils/util.h"
-#include "utils/util_utf.h"
 
 #define OLE_MAX_FILENAME_LEN_UTF16  64
 #define OLE_MAX_FILENAME_ASCII      32
index 5f246458680d5e9afb7e8eea8f013cabd24f811c..0abb17434ffbde20b0562af8fa60c15e9081f3d1 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "detection/detection_engine.h"
 #include "helpers/literal_search.h"
-#include "utils/util_utf.h"
+#include "helpers/utf.h"
 
 #include <CppUTest/CommandLineTestRunner.h>
 #include <CppUTest/TestHarness.h>
index 757c0260f28b1b7a362a718d4e6466f7deaad2bb..9c48fb2fcefa215962342ca4a790de1852a6ef91 100644 (file)
@@ -1,19 +1,13 @@
 
 set (DETECTION_INCLUDES
-    detect.h
+    detection_buf.h
     detection_engine.h
-    detection_options.h
-    detection_util.h
-    detect_trace.h
+    extract.h
     ips_context.h
     ips_context_chain.h
     ips_context_data.h
-    regex_offload.h
-    rule_option_types.h
-    rules.h
-    signature.h
-    treenodes.h
     pattern_match_data.h
+    rule_option_types.h
 )
 
 add_library (detection OBJECT
@@ -21,13 +15,18 @@ add_library (detection OBJECT
     context_switcher.cc
     context_switcher.h
     detect.cc
+    detect.h
+    detection_continuation.h
     detection_engine.cc
     detection_module.cc
     detection_module.h
     detection_options.cc
     detection_options.h
-    detection_util.cc
     detect_trace.cc
+    detect_trace.h
+    event_trace.cc
+    event_trace.h
+    extract.cc
     fp_config.cc
     fp_config.h
     fp_create.cc
@@ -42,15 +41,19 @@ add_library (detection OBJECT
     pcrm.cc
     pcrm.h
     regex_offload.cc
+    regex_offload.h
     rtn_checks.cc
     rtn_checks.h
     rules.cc
+    rules.h
     service_map.cc
     service_map.h
     sfrim.cc
     sfrim.h
     signature.cc
+    signature.h
     treenodes.cc
+    treenodes.h
     tag.cc
     tag.h
 )
index 41346c0bed34217b4ec8acec1683c1dee9f94c9c..a2caf6e1af12852631d991f469cde4eb012870b1 100644 (file)
@@ -74,7 +74,7 @@ void ContextSwitcher::start()
 
     debug_logf(detection_trace, TRACE_DETECTION_ENGINE, nullptr,
         "(wire) %" PRIu64 " cs::start %" PRIu64 " (i=%zu, b=%zu)\n",
-        get_packet_number(), c->context_num, idle.size(), busy.size());
+        pc.analyzed_pkts, c->context_num, idle.size(), busy.size());
 
     idle.pop_back();
 
@@ -98,7 +98,7 @@ void ContextSwitcher::stop()
 
     debug_logf(detection_trace, TRACE_DETECTION_ENGINE, nullptr,
         "(wire) %" PRIu64 " cs::stop %" PRIu64 " (i=%zu, b=%zu)\n",
-        get_packet_number(), c->context_num, idle.size(), busy.size());
+        pc.analyzed_pkts, c->context_num, idle.size(), busy.size());
 
     c->clear();
 
@@ -114,7 +114,7 @@ void ContextSwitcher::abort()
 {
     debug_logf(detection_trace, TRACE_DETECTION_ENGINE, nullptr,
         "(wire) %" PRIu64 " cs::abort (i=%zu, b=%zu)\n",
-        get_packet_number(), idle.size(), busy.size());
+        pc.analyzed_pkts, idle.size(), busy.size());
 
     busy.clear();
 
@@ -157,7 +157,7 @@ IpsContext* ContextSwitcher::interrupt()
     c->context_num = ++global_context_num;
     debug_logf(detection_trace, TRACE_DETECTION_ENGINE, nullptr,
         "%" PRIu64 " cs::interrupt %" PRIu64 " (i=%zu, b=%zu)\n",
-        busy.empty() ? get_packet_number() : busy.back()->packet_number,
+        busy.empty() ? pc.analyzed_pkts : busy.back()->packet_number,
         busy.empty() ? 0 : busy.back()->context_num, idle.size(), busy.size());
 
     idle.pop_back();
index aaeecd7d23fd86c7a2b8cdaab2d8cb56727da97d..cf63c563c7ca8539559fef4b54c53706c5af471c 100644 (file)
@@ -42,7 +42,7 @@
 #include <vector>
 
 #include "detection/ips_context_chain.h"
-#include "utils/primed_allocator.h"
+#include "helpers/primed_allocator.h"
 
 namespace snort
 {
index b043b855e1027c10ffba8ced70bef7bbaff9e865..395a199977f5b1dad876ae3b1e8d7a75aedb5dd9 100644 (file)
@@ -34,7 +34,6 @@
 #include "latency/packet_latency.h"
 #include "main/snort_config.h"
 #include "managers/event_manager.h"
-#include "managers/inspector_manager.h"
 #include "packet_io/active.h"
 #include "ports/port_object.h"
 #include "profiler/profiler_defs.h"
@@ -65,9 +64,7 @@ bool snort_log(Packet* p)
 
 void CallLogFuncs(Packet* p, ListHead* head, Event* event, const char* msg)
 {
-    event->update_event_id(p->context->conf->get_event_log_id());
-
-    DetectionEngine::set_check_tags(false);
+    DetectionEngine::set_check_tags(p, false);
     pc.log_pkts++;
 
     OutputSet* idx = head ? head->LogList : nullptr;
@@ -76,17 +73,10 @@ void CallLogFuncs(Packet* p, ListHead* head, Event* event, const char* msg)
 
 void CallLogFuncs(Packet* p, const OptTreeNode* otn, ListHead* head)
 {
-    Event event;
-
-    // FIXIT-L this and the same below should be refactored to not need const_cast
-    event.sig_info = const_cast<SigInfo*>(&otn->sigInfo);
-    event.ref_time.tv_sec = p->pkth->ts.tv_sec;
-    event.ref_time.tv_usec = p->pkth->ts.tv_usec;
-    event.update_event_id_and_ref(p->context->conf->get_event_log_id());
-    if (head and head->ruleListNode)
-        event.action_string = head->ruleListNode->name;
+    const char* act = (head and head->ruleListNode) ? head->ruleListNode->name : "";
+    Event event(p->pkth->ts.tv_sec, p->pkth->ts.tv_usec, otn->sigInfo, otn->buffer_setters, act);
 
-    DetectionEngine::set_check_tags(false);
+    DetectionEngine::set_check_tags(p, false);
     pc.log_pkts++;
 
     const uint8_t* data = nullptr;
@@ -118,15 +108,8 @@ void CallLogFuncs(Packet* p, const OptTreeNode* otn, ListHead* head)
 
 void CallAlertFuncs(Packet* p, const OptTreeNode* otn, ListHead* head)
 {
-    Event event;
-
-    event.sig_info = const_cast<SigInfo*>(&otn->sigInfo);
-    event.buffs_to_dump = otn->buffer_setters;
-    event.ref_time.tv_sec = p->pkth->ts.tv_sec;
-    event.ref_time.tv_usec = p->pkth->ts.tv_usec;
-    event.update_event_id_and_ref(p->context->conf->get_event_log_id());
-    if (head and head->ruleListNode)
-        event.action_string = head->ruleListNode->name;
+    const char* act = (head and head->ruleListNode) ? head->ruleListNode->name : "";
+    Event event(p->pkth->ts.tv_sec, p->pkth->ts.tv_usec, otn->sigInfo, otn->buffer_setters, act);
 
     pc.total_alert_pkts++;
 
@@ -151,19 +134,18 @@ void CallAlertFuncs(Packet* p, const OptTreeNode* otn, ListHead* head)
 */
 void check_tags(Packet* p)
 {
-    SigInfo info;
-    Event event(info);
-
-    if ( DetectionEngine::get_check_tags() and !(p->packet_flags & PKT_REBUILT_STREAM) )
+    if ( DetectionEngine::get_check_tags(p) and !(p->packet_flags & PKT_REBUILT_STREAM) )
     {
-        void* listhead = nullptr;
+        SigInfo info;
+        ListHead* listhead = nullptr;
+        struct timeval tv;
+        uint32_t id;
+        const char* act;
 
-        if (CheckTagList(p, event, &listhead))
+        if (CheckTagList(p, info, listhead, tv, id, act))
         {
-            /* if we find a match, we want to send the packet to the
-             * logging mechanism
-             */
-            CallLogFuncs(p, (ListHead*)listhead, &event, "Tagged Packet");
+            Event event(tv.tv_sec, tv.tv_usec, info, nullptr, act, id);
+            CallLogFuncs(p, listhead, &event, "Tagged Packet");
         }
     }
 }
index df7db7db92166bf63b2f113a049430d252b069b1..87d4e2501e3363a93264c26f3875927cb65d1ebb 100644 (file)
@@ -21,9 +21,7 @@
 #ifndef DETECT_H
 #define DETECT_H
 
-#include "detection/rules.h"
 #include "main/snort_types.h"
-#include "main/thread.h"
 
 namespace snort
 {
@@ -31,6 +29,9 @@ struct Packet;
 struct ProfileStats;
 }
 
+struct ListHead;
+struct OptTreeNode;
+
 extern THREAD_LOCAL snort::ProfileStats eventqPerfStats;
 
 // main loop hooks
@@ -38,7 +39,7 @@ bool snort_ignore(snort::Packet*);
 bool snort_log(snort::Packet*);
 
 // alerts
-void CallLogFuncs(snort::Packet*, ListHead*, struct Event*, const char*);
+void CallLogFuncs(snort::Packet*, ListHead*, class Event*, const char*);
 void CallLogFuncs(snort::Packet*, const OptTreeNode*, ListHead*);
 void CallAlertFuncs(snort::Packet*, const OptTreeNode*, ListHead*);
 
index c82349cfc60b68be5f2bf42bd294620873f9bba2..559d535affb953cdf8d69ee077af61e0cfb97580 100644 (file)
@@ -25,7 +25,6 @@
 #include "detect_trace.h"
 
 #include "log/log.h"
-#include "main/thread.h"
 #include "protocols/packet.h"
 #include "utils/stats.h"
 #include "utils/util.h"
index 8ce0df2aec3c3edfb839d526ae0f041ca6921218..63bd81054f4dd0031c2e324ede1e194aa47d178d 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "framework/cursor.h"
 #include "main/snort_types.h"
-#include "main/thread.h"
 
 namespace snort
 {
similarity index 72%
rename from src/detection/detection_util.h
rename to src/detection/detection_buf.h
index 7c44adef24a80b0e7569a2ea73b6fd2bc63a0511..38370db1a4df179a6685e5d30c1df817bf7553a8 100644 (file)
@@ -1,7 +1,5 @@
 //--------------------------------------------------------------------------
-// Copyright (C) 2014-2024 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2002-2013 Sourcefire, Inc.
-// Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+// Copyright (C) 2024-2023 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
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 
-#ifndef DETECTION_UTIL_H
-#define DETECTION_UTIL_H
+#ifndef DETECTION_BUF_H
+#define DETECTION_BUF_H
 
-// this is a legacy junk-drawer file that needs to be refactored
-// it provides file and alt data and event trace foo.
+// buffers used by DetectionEngine and IpsContext
 
 #include <cassert>
-
-#include "actions/actions.h"
-#include "main/snort_config.h"
+#include <cstdint>
 
 #define DECODE_BLEN 65535
 
@@ -71,16 +66,5 @@ struct MatchedBuffer
     unsigned size = 0;
 };
 
-// FIXIT-RC event trace should be placed in its own files
-void EventTrace_Init();
-void EventTrace_Term();
-
-void EventTrace_Log(const snort::Packet*, const OptTreeNode*, Actions::Type action);
-
-inline int EventTrace_IsEnabled(const snort::SnortConfig* sc)
-{
-    return ( sc->event_trace_max > 0 );
-}
-
 #endif
 
index 743a1fb7a43809e53e83ee7c35a8dfbd69ec0ac2..6aa0f549ef8fed987d4437ebbdd95cd43f438763 100644 (file)
 
 #include "framework/cursor.h"
 #include "framework/ips_option.h"
-#include "ips_options/extract.h"
+#include "helpers/grouped_list.h"
 #include "latency/rule_latency.h"
 #include "latency/rule_latency_state.h"
 #include "main/snort_config.h"
 #include "main/thread_config.h"
 #include "protocols/packet.h"
 #include "trace/trace_api.h"
-#include "utils/grouped_list.h"
 #include "utils/stats.h"
 
 #include "detection_options.h"
 #include "detect_trace.h"
+#include "extract.h"
 #include "ips_context.h"
 #include "rule_option_types.h"
 #include "treenodes.h"
index 6945abce6df784fc990c8186bde066090e55b310..163c8e41a5617aa759e9cab02896acc1c89dc4de 100644 (file)
 
 #include "detection_engine.h"
 
+#include "events/event_queue.h"
 #include "events/sfeventq.h"
 #include "filters/sfthreshold.h"
 #include "framework/endianness.h"
+#include "framework/ips_action.h"
 #include "helpers/ring.h"
 #include "latency/packet_latency.h"
 #include "main/analyzer.h"
 #include "main/snort_config.h"
-#include "main/thread.h"
 #include "managers/inspector_manager.h"
 #include "managers/mpse_manager.h"
 #include "packet_io/active.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "parser/parser.h"
 #include "profiler/profiler_defs.h"
 #include "protocols/packet.h"
@@ -45,8 +46,8 @@
 #include "utils/stats.h"
 
 #include "context_switcher.h"
+#include "detection_buf.h"
 #include "detection_module.h"
-#include "detection_util.h"
 #include "detect.h"
 #include "detect_trace.h"
 #include "fp_config.h"
 #include "ips_context_data.h"
 #include "regex_offload.h"
 
-static THREAD_LOCAL RegexOffload* offloader = nullptr;
-
 using namespace snort;
 
+static THREAD_LOCAL RegexOffload* offloader = nullptr;
+bool DetectionEngine::offload_enabled = false;
+
 //--------------------------------------------------------------------------
 // basic de
 //--------------------------------------------------------------------------
@@ -124,6 +126,9 @@ DetectionEngine::~DetectionEngine()
     }
 }
 
+void DetectionEngine::enable_offload()
+{ offload_enabled = true; }
+
 void DetectionEngine::reset()
 {
     IpsContext* c = Analyzer::get_switcher()->get_context();
@@ -180,7 +185,7 @@ Packet* DetectionEngine::set_next_packet(const Packet* parent, Flow* flow)
     {
         if ( flow )
             p->context->snapshot_flow(flow);
-        c->packet_number = get_packet_number();
+        c->packet_number = pc.analyzed_pkts;
         c->wire_packet = nullptr;
     }
 
@@ -221,7 +226,7 @@ Packet* DetectionEngine::set_next_packet(const Packet* parent, Flow* flow)
 
 void DetectionEngine::finish_inspect_with_latency(Packet* p)
 {
-    DetectionEngine::set_check_tags();
+    DetectionEngine::set_check_tags(p);
 
     // By checking tagging here, we make sure that we log the
     // tagged packet whether it generates an alert or not.
@@ -285,12 +290,6 @@ void DetectionEngine::finish_packet(Packet* p, bool flow_deletion)
         sw->complete();
 }
 
-uint8_t* DetectionEngine::get_buffer(unsigned& max)
-{
-    max = IpsContext::buf_size;
-    return Analyzer::get_switcher()->get_context()->buf;
-}
-
 uint8_t* DetectionEngine::get_next_buffer(unsigned& max)
 {
     max = IpsContext::buf_size;
@@ -404,11 +403,11 @@ IpsContext::ActiveRules DetectionEngine::get_detects(Packet* p)
 void DetectionEngine::set_detects(Packet* p, IpsContext::ActiveRules ar)
 { p->context->active_rules = ar; }
 
-void DetectionEngine::set_check_tags(bool enable)
-{ Analyzer::get_switcher()->get_context()->check_tags = enable; }
+void DetectionEngine::set_check_tags(Packet* p, bool enable)
+{ p->context->check_tags = enable; }
 
-bool DetectionEngine::get_check_tags()
-{ return Analyzer::get_switcher()->get_context()->check_tags; }
+bool DetectionEngine::get_check_tags(Packet* p)
+{ return p->context->check_tags; }
 
 //--------------------------------------------------------------------------
 // offload / onload
@@ -475,12 +474,12 @@ void DetectionEngine::idle()
         while ( offloader->count() )
         {
             debug_logf(detection_trace, TRACE_DETECTION_ENGINE, nullptr,
-                "(wire) %" PRIu64 " de::sleep\n", get_packet_number());
+                "(wire) %" PRIu64 " de::sleep\n", pc.analyzed_pkts);
 
             onload();
         }
         debug_logf(detection_trace, TRACE_DETECTION_ENGINE, nullptr,
-            "(wire) %" PRIu64 " de::idle (r=%d)\n", get_packet_number(),
+            "(wire) %" PRIu64 " de::idle (r=%d)\n", pc.analyzed_pkts,
             offloader->count());
 
         offloader->stop();
@@ -495,7 +494,7 @@ void DetectionEngine::onload(Flow* flow)
     while ( flow->is_suspended() )
     {
         debug_logf(detection_trace, TRACE_DETECTION_ENGINE, nullptr,
-            "(wire) %" PRIu64 " de::sleep\n", get_packet_number());
+            "(wire) %" PRIu64 " de::sleep\n", pc.analyzed_pkts);
 
         resume_ready_suspends(flow->context_chain); // FIXIT-M makes onload reentrant-safe
         onload();
@@ -647,9 +646,9 @@ bool DetectionEngine::inspect(Packet* p)
             if ( !all_disabled(p) )
             {
                 if ( PacketTracer::is_daq_activated() )
-                    PacketTracer::pt_timer_start();
+                    PacketTracer::restart_timer();
 
-                if ( detect(p, true) )
+                if ( detect(p, offload_enabled) )
                     return false; // don't finish out offloaded packets
             }
         }
index e86fc7c8b72598ac02cfc1b3f1906aa0a0d858d9..4c0a0460ce11e05d19523bbc05b60ce85d53dc3d 100644 (file)
 // packet (PDU), first call set_next_packet().  If rebuild is successful,
 // then instantiate a new DetectionEngine to detect that packet.
 
-#include "detection/detection_util.h"
+#include "detection/detection_buf.h"
 #include "detection/ips_context.h"
 #include "main/snort_types.h"
 
-struct DataPointer;
+struct OptTreeNode;
 struct Replacement;
 
 namespace snort
@@ -59,6 +59,7 @@ public:
     static Packet* set_next_packet(const Packet* parent = nullptr, Flow* flow = nullptr);
     static uint8_t* get_next_buffer(unsigned& max);
 
+    static void enable_offload();
     static bool offload(Packet*);
 
     static void onload(Flow*);
@@ -76,7 +77,7 @@ public:
     static uint8_t* get_buffer(unsigned& max);
     static inline DataPointer get_alt_buffer(const Packet*);
     static inline DataBuffer& acquire_alt_buffer(const Packet*);
-    static inline void reset_alt_buffer(Packet*);
+    static void inline reset_alt_buffer(Packet*);
 
     static void set_data(unsigned id, IpsContextData*);
     static IpsContextData* get_data(unsigned id);
@@ -89,7 +90,7 @@ public:
     static bool detect(Packet*, bool offload_ok = false);
     static bool inspect(Packet*);
 
-    static int queue_event(const struct OptTreeNode*);
+    static int queue_event(const OptTreeNode*);
     static int queue_event(unsigned gid, unsigned sid);
 
     static void disable_all(Packet*);
@@ -102,8 +103,8 @@ public:
     static IpsContext::ActiveRules get_detects(Packet*);
     static void set_detects(Packet*, IpsContext::ActiveRules);
 
-    static void set_check_tags(bool enable = true);
-    static bool get_check_tags();
+    static void set_check_tags(Packet*, bool enable = true);
+    static bool get_check_tags(Packet*);
 
     static void wait_for_context();
 
@@ -122,6 +123,7 @@ private:
     static void finish_packet(Packet*, bool flow_deletion = false);
 
 private:
+    static bool offload_enabled;
     IpsContext* context;
 };
 
index cad5d915959bb6488798f7774a6ff281568f6154..fc8e303f0254a7090d1a4e325bb2cf81d3654c30 100644 (file)
@@ -33,6 +33,7 @@
 #include "trace/trace.h"
 
 #include "detect_trace.h"
+#include "detection_engine.h"
 
 using namespace snort;
 
@@ -196,6 +197,9 @@ bool DetectionModule::end(const char* fqn, int idx, SnortConfig* sc)
     if ( sc->offload_threads and ThreadConfig::get_instance_max() != 1 )
         ParseError("You can not enable experimental offload with more than one packet thread.");
 
+    if ( sc->offload_limit < 99999 )
+        DetectionEngine::enable_offload();
+
     return true;
 }
 
index b972b2934c08916b72dc333bdbd62812f3f4eed3..98a8892bc505e55c8db724872ec4b44377a4e760 100644 (file)
@@ -23,6 +23,7 @@
 #define DETECTION_MODULE_H
 
 #include "framework/module.h"
+#include "utils/stats.h"
 
 namespace snort
 {
@@ -55,4 +56,5 @@ private:
 };
 }
 
-#endif // DETECTION_MODULE_H
+#endif
+
index 88f56aa5daf5d573ca867496049a7540341c7370..a5e9d7b68f63c3193e8856b035b8e3feebb57d0a 100644 (file)
@@ -40,7 +40,6 @@
 #include "hash/hash_defs.h"
 #include "hash/hash_key_operations.h"
 #include "hash/xhash.h"
-#include "ips_options/extract.h"
 #include "ips_options/ips_flowbits.h"
 #include "latency/packet_latency.h"
 #include "latency/rule_latency_state.h"
@@ -55,8 +54,8 @@
 #include "detection_continuation.h"
 #include "detection_engine.h"
 #include "detection_module.h"
-#include "detection_util.h"
 #include "detect_trace.h"
+#include "extract.h"
 #include "fp_create.h"
 #include "fp_detect.h"
 #include "ips_context.h"
@@ -697,7 +696,7 @@ int detection_option_node_evaluate(
         if ( continue_loop && rval == (int)IpsOption::MATCH && node->relative_children )
         {
             IpsOption* opt = (IpsOption*)node->option_data;
-            continue_loop = opt->retry(cursor, orig_cursor);
+            continue_loop = opt->retry(cursor);
         }
         else
             continue_loop = false;
similarity index 92%
rename from src/detection/detection_util.cc
rename to src/detection/event_trace.cc
index e3e57857c8d048bafb69098a511bd6c4bd84ee08..3df02c6834d5f2eb4f38fd4dca48baaa24c2cb8d 100644 (file)
 #include "config.h"
 #endif
 
-#include "detection_util.h"
+#include "event_trace.h"
 
-#include "actions/actions.h"
 #include "events/event.h"
+#include "framework/ips_action.h"
 #include "log/text_log.h"
 #include "protocols/packet.h"
 #include "utils/stats.h"
@@ -75,16 +75,16 @@ static void LogBuffer(const char* s, const uint8_t* p, unsigned n)
     }
 }
 
-void EventTrace_Log(const Packet* p, const OptTreeNode* otn, Actions::Type action)
+void EventTrace_Log(const Packet* p, const OptTreeNode* otn, IpsAction::Type action)
 {
-    std::string acts = Actions::get_string(action);
+    std::string acts = IpsAction::get_string(action);
 
     if ( !tlog )
         return;
 
     TextLog_Print(tlog,
         "\nEvt=%u, Gid=%u, Sid=%u, Rev=%u, Act=%s\n",
-        get_event_id(), otn->sigInfo.gid, otn->sigInfo.sid, otn->sigInfo.rev, acts.c_str());
+        Event::get_curr_seq_num(), otn->sigInfo.gid, otn->sigInfo.sid, otn->sigInfo.rev, acts.c_str());
 
     TextLog_Print(tlog,
         "Pkt=" STDu64 ", Sec=%lu.%6lu, Len=%u, Cap=%u\n",
diff --git a/src/detection/event_trace.h b/src/detection/event_trace.h
new file mode 100644 (file)
index 0000000..f81171f
--- /dev/null
@@ -0,0 +1,42 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2024 Cisco and/or its affiliates. All rights reserved.
+// Copyright (C) 2002-2013 Sourcefire, Inc.
+// Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+//
+// 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.
+//--------------------------------------------------------------------------
+
+#ifndef EVENT_TRACE_H
+#define EVENT_TRACE_H
+
+// facility for logging IPS events and packets regardless of filtering
+
+#include <cassert>
+
+#include "framework/ips_action.h"
+#include "main/snort_config.h"
+
+void EventTrace_Init();
+void EventTrace_Term();
+
+void EventTrace_Log(const snort::Packet*, const struct OptTreeNode*, snort::IpsAction::Type action);
+
+inline int EventTrace_IsEnabled(const snort::SnortConfig* sc)
+{
+    return ( sc->event_trace_max > 0 );
+}
+
+#endif
+
similarity index 92%
rename from src/ips_options/extract.h
rename to src/detection/extract.h
index bcc4610e6989c476a5d5e4649ca066b93ba5dd65..8cffd80d894eda1cd631c18b5cddc63c1e529117 100644 (file)
@@ -23,7 +23,6 @@
 #include "framework/cursor.h"
 #include "framework/endianness.h"
 #include "main/snort_types.h"
-#include "main/thread.h"
 #include "protocols/packet.h"
 
 #define ENDIAN_BIG    0x1
@@ -59,14 +58,14 @@ SO_PUBLIC int byte_extract(
     int endianness, int bytes_to_grab, const uint8_t* ptr,
     const uint8_t* start, const uint8_t* end, uint32_t* value);
 
-void set_cursor_bounds(const ByteData& settings, const Cursor& c,
+SO_PUBLIC void set_cursor_bounds(const ByteData& settings, const Cursor& c,
     const uint8_t*& start, const uint8_t*& ptr, const uint8_t*& end);
 
-int32_t data_extraction(const ByteData& settings, Packet* p,
+SO_PUBLIC int32_t data_extraction(const ByteData& settings, Packet* p,
     uint32_t& result_var, const uint8_t* start,
     const uint8_t* ptr, const uint8_t* end);
 
-int32_t extract_data(const ByteData& settings, const Cursor& c, Packet* p,
+SO_PUBLIC int32_t extract_data(const ByteData& settings, const Cursor& c, Packet* p,
     uint32_t& result_var);
 
 SO_PUBLIC void set_byte_order(uint8_t& order, uint8_t flag, const char* opt);
index b6b76c7b10296b938583f0d7c9c261f46518bdb6..46d81eb285cd537cc911b623bf305e2751acda3f 100644 (file)
@@ -39,6 +39,7 @@
 #include "hash/ghash.h"
 #include "hash/hash_defs.h"
 #include "hash/xhash.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
index b909af47f94874a2c0c199faae5d1340f3d609f5..28cd6fe75c36b0578f28d13754be1bbc4b053de5 100644 (file)
 
 #include <vector>
 
-#include "actions/actions.h"
 #include "events/event.h"
+#include "events/event_queue.h"
 #include "filters/rate_filter.h"
 #include "filters/sfthreshold.h"
+#include "framework/act_info.h"
 #include "framework/cursor.h"
+#include "framework/ips_action.h"
 #include "framework/mpse.h"
 #include "latency/packet_latency.h"
 #include "latency/rule_latency.h"
@@ -54,7 +56,7 @@
 #include "main/snort_config.h"
 #include "managers/action_manager.h"
 #include "packet_io/active.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "parser/parser.h"
 #include "profiler/profiler_defs.h"
 #include "protocols/icmp4.h"
 #include "utils/util.h"
 
 #include "context_switcher.h"
-#include "detect.h"
 #include "detect_trace.h"
+#include "detection_buf.h"
 #include "detection_continuation.h"
 #include "detection_engine.h"
 #include "detection_module.h"
 #include "detection_options.h"
-#include "detection_util.h"
+#include "event_trace.h"
 #include "fp_config.h"
 #include "fp_create.h"
 #include "fp_utils.h"
@@ -108,9 +110,7 @@ void populate_trace_data()
     if ( tr_len > 0 )
     {
         tr_context[tr_len-1] = ' ';
-        PacketTracer::daq_log("IPS+%" PRId64"++%s$",
-            TO_NSECS(pt_timer->get()),
-            tr_context);
+        PacketTracer::daq_log("IPS+%" PRId64"++%s$", PacketTracer::get_time(), tr_context);
 
         tr_len = 0;
         tr_context[0] = '\0';
@@ -128,14 +128,14 @@ static inline void init_match_info(const IpsContext* c)
 // called by fpLogEvent(), which does the filtering etc.
 // this handles the non-rule-actions (responses).
 static inline void fpLogOther(
-    Packet* p, const RuleTreeNode* rtn, const OptTreeNode* otn, Actions::Type action)
+    Packet* p, const RuleTreeNode* rtn, const OptTreeNode* otn, IpsAction::Type action)
 {
     if ( EventTrace_IsEnabled(p->context->conf) )
         EventTrace_Log(p, otn, action);
 
     if ( PacketTracer::is_active() )
     {
-        std::string act = Actions::get_string(action);
+        std::string act = IpsAction::get_string(action);
         PacketTracer::log("Event: %u:%u:%u, Action %s\n",
             otn->sigInfo.gid, otn->sigInfo.sid,
             otn->sigInfo.rev, act.c_str());
@@ -143,7 +143,7 @@ static inline void fpLogOther(
 
     if ( PacketTracer::is_daq_activated() )
     {
-        std::string act = Actions::get_string(action);
+        std::string act = IpsAction::get_string(action);
         tr_len += snprintf(tr_context+tr_len, sizeof(tr_context) - tr_len,
                       "gid:%u, sid:%u, rev:%u, action:%s, msg:%s\n",
                       otn->sigInfo.gid, otn->sigInfo.sid,
@@ -186,9 +186,9 @@ int fpLogEvent(const RuleTreeNode* rtn, const OptTreeNode* otn, Packet* p)
 
     // perform rate filtering tests - impacts action taken
     rateAction = RateFilter_Test(otn, p);
-    override = ( rateAction >= Actions::get_max_types() );
+    override = ( rateAction >= IpsAction::get_max_types() );
     if ( override )
-        rateAction -= Actions::get_max_types();
+        rateAction -= IpsAction::get_max_types();
 
     // internal events are no-ops
     if ( (rateAction < 0) && EventIsInternal(otn->sigInfo.gid) )
@@ -223,10 +223,10 @@ int fpLogEvent(const RuleTreeNode* rtn, const OptTreeNode* otn, Packet* p)
         **  that are drop rules.  We just don't want to see the alert.
         */
         IpsAction * act = get_ips_policy()->action[action];
-        act->exec(p);
+        ActInfo ai(otn, false);
+        act->exec(p, ai);
 
-        if ( p->active && p->flow &&
-            (p->active->get_action() >= Active::ACT_DROP) )
+        if ( p->active && p->flow && (p->active->get_action() >= Active::ACT_DROP) )
         {
             if ( p->active->can_partial_block_session() )
                 p->flow->flags.ips_pblock_event_suppressed = true;
@@ -247,20 +247,19 @@ int fpLogEvent(const RuleTreeNode* rtn, const OptTreeNode* otn, Packet* p)
     const SnortConfig* sc = p->context->conf;
 
     if ( (p->packet_flags & PKT_PASS_RULE) &&
-        (sc->get_eval_index(rtn->action) > sc->get_eval_index(Actions::get_type("pass"))) )
+        (sc->get_eval_index(rtn->action) > sc->get_eval_index(IpsAction::get_type("pass"))) )
     {
         fpLogOther(p, rtn, otn, rtn->action);
         return 1;
     }
 
     otn->state[get_instance_id()].alerts++;
+    uint16_t eseq = Event::get_next_seq_num();
+    IpsAction* act = get_ips_policy()->action[action];
+    ActInfo ai(otn);
 
-    incr_event_id();
-
-    IpsAction * act = get_ips_policy()->action[action];
-    act->exec(p, otn);
-    SetTags(p, otn, get_event_id());
-
+    act->exec(p, ai);
+    SetTags(p, otn, eseq);
     fpLogOther(p, rtn, otn, action);
 
     return 0;
@@ -642,7 +641,7 @@ static inline int fpFinalSelectEvent(OtnxMatchData* omd, Packet* p)
     {
         /* bail if were not dumping events in all the action groups,
          * and we've already got some events */
-        if (!p->context->conf->process_all_events() && (tcnt > 0))
+        if (!p->context->conf->event_queue_config->process_all_events && (tcnt > 0))
             return 1;
 
         if ( omd->matchInfo[i].iMatchCount )
@@ -1398,7 +1397,8 @@ static inline int fp_do_actions(OtnxMatchData* omd, Packet* p)
             const OptTreeNode* otn = omd->matchInfo[i].MatchArray[0];
             RuleTreeNode* rtn = getRtnFromOtn(otn);
             IpsAction* act = get_ips_policy()->action[rtn->action];
-            act->exec(p, otn);
+            ActInfo ai(otn);
+            act->exec(p, ai);
         }
     }
 
index fbcc7769420a526612d951fb1ce6669e956293c3..15cad2f459b9d2f5e34c5b71069f7ed6fd22ebfb 100644 (file)
@@ -29,7 +29,6 @@
 // rule groups are selected based on traffic and any fast pattern
 // matches trigger rule tree evaluation.
 
-#include "main/thread.h"
 #include "profiler/profiler_defs.h"
 #include "target_based/snort_protocols.h"
 
index 022aa63c0a8386834a846f2e49bf9ce451759aa3..4cfa1683f99b0858007aa2efde9e20b0196d3d0c 100644 (file)
@@ -39,6 +39,7 @@
 #include "ips_options/ips_flowbits.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "parser/parse_conf.h"
 #include "pattern_match_data.h"
 #include "ports/port_group.h"
index c869086123beb484fb557318c6306e35ed2df0fa..bffb6182e6c3ab750ee33887a4c991a52618b31e 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <list>
 
-#include "detection/detection_util.h"
+#include "detection/detection_buf.h"
 #include "framework/codec.h"
 #include "framework/mpse.h"
 #include "framework/mpse_batch.h"
index 9ec335928e075ade1f5c7bcba1e4b34a8a2ae22e..9acb6bc1b84eaeb60d3b7319915dc8eb6457dd4f 100644 (file)
@@ -38,7 +38,6 @@
 #include "latency/packet_latency.h"
 #include "latency/rule_latency.h"
 #include "main/snort_config.h"
-#include "main/thread.h"
 #include "main/thread_config.h"
 #include "managers/module_manager.h"
 #include "utils/stats.h"
index 8fec29f8f120efd3bfb7e18236868a0b729bc757..651fb22b7a6b462948beb9cc02aa9cb957070f6b 100644 (file)
@@ -27,7 +27,7 @@
 #include <map>
 #include <string>
 
-#include "actions/actions.h"
+#include "framework/ips_action.h"
 #include "main/policy.h"
 
 #define GID_DEFAULT          1
@@ -61,7 +61,7 @@ struct ListHead
 struct RuleListNode
 {
     ListHead* RuleList;   /* The rule list associated with this node */
-    Actions::Type mode;        /* the rule mode */
+    snort::IpsAction::Type mode;        /* the rule mode */
     unsigned evalIndex;        /* eval index for this rule set */
     char* name;           /* name of this rule list */
     RuleListNode* next;   /* the next RuleListNode */
@@ -94,7 +94,7 @@ public:
 private:
     RuleTreeNode* dup_rtn(RuleTreeNode*, IpsPolicy*);
     void update_rtn(snort::SnortConfig*, RuleTreeNode*, const RuleState&);
-    void apply(snort::SnortConfig*, OptTreeNode*, unsigned ips_num, const RuleState&);
+    void apply(snort::SnortConfig*, struct OptTreeNode*, unsigned ips_num, const RuleState&);
 
 private:
     std::map<RuleKey, RuleState> map;
index f7c4f4ff2ba30f1fc8573c733a404dc91a3c98d0..025d007be471e098f0b899ff756d292ded8d3cfe 100644 (file)
@@ -28,9 +28,9 @@
 
 #include "signature.h"
 
-#include "actions/actions.h"
 #include "framework/decode_data.h"
 #include "filters/sfthd.h"
+#include "framework/ips_action.h"
 #include "hash/hash_defs.h"
 #include "hash/ghash.h"
 #include "helpers/json_stream.h"
@@ -462,7 +462,7 @@ void dump_rule_state(const SnortConfig* sc)
             auto pid = snort::get_ips_policy(sc, i)->user_policy_id;
             json.put("policy", pid);
 
-            std::string action = Actions::get_string(rtn->action);
+            std::string action = IpsAction::get_string(rtn->action);
             json.put("action", action.c_str());
 
             const char* s = rtn->enabled() ? "yes" : "no";
index 8799e8426fabe4463594c11227fa37337c19a251..fee071abee7cca38569a6e3546d6f14de77355db 100644 (file)
@@ -98,7 +98,7 @@ struct TagNode
     uint16_t event_id;
     struct timeval event_time;
 
-    void* log_list;  // retain custom logging if any from triggering alert
+    struct ListHead* log_list;  // retain custom logging if any from triggering alert
 };
 
 /*  G L O B A L S  **************************************************/
@@ -114,16 +114,9 @@ static THREAD_LOCAL unsigned s_sessions = 0;
 // (consecutive) sessions to be captured.
 static const unsigned s_max_sessions = 1;
 
-
 /*  P R O T O T Y P E S  ********************************************/
-static TagNode* TagAlloc(XHash*);
 static void TagFree(XHash*, TagNode*);
 static int PruneTagCache(uint32_t, int);
-static int PruneTime(XHash* tree, uint32_t thetime);
-static void TagSession(const Packet*, TagData*, uint32_t, uint16_t, void*);
-static void TagHost(const Packet*, TagData*, uint32_t, uint16_t, void*);
-static void AddTagNode(const Packet*, TagData*, int, uint32_t, uint16_t, void*);
-static inline void SwapTag(TagNode*);
 
 class TagSessionCache : public XHash
 {
@@ -241,16 +234,7 @@ static TagNode* TagAlloc(
     return tag_node;
 }
 
-/**Frees allocated TagNode.
- *
- * @param hash - pointer to XHash that should point to either ssn_tag_cache_ptr
- * or host_tag_cache_ptr.
- * @param node - pointer to node to be freed
- */
-static void TagFree(
-    XHash* hash,
-    TagNode* node
-    )
+static void TagFree(XHash* hash, TagNode* node)
 {
     if (node == nullptr)
         return;
@@ -262,11 +246,6 @@ static void TagFree(
     tag_memory_usage -= memory_per_node(hash);
 }
 
-/**
- * swap the sips and dips, dp's and sp's
- *
- * @param np TagNode ptr
- */
 static inline void SwapTag(TagNode* np)
 {
     SfIp tip;
@@ -295,33 +274,8 @@ void CleanupTag()
     delete host_tag_cache;
 }
 
-static void TagSession(const Packet* p, TagData* tag, uint32_t time, uint16_t event_id, void* log_list)
-{
-    AddTagNode(p, tag, TAG_SESSION, time, event_id, log_list);
-}
-
-static void TagHost(const Packet* p, TagData* tag, uint32_t time, uint16_t event_id, void* log_list)
-{
-    int mode;
-
-    switch (tag->tag_direction)
-    {
-    case TAG_HOST_DST:
-        mode = TAG_HOST_DST;
-        break;
-    case TAG_HOST_SRC:
-        mode = TAG_HOST_SRC;
-        break;
-    default:
-        mode = TAG_HOST_SRC;
-        break;
-    }
-
-    AddTagNode(p, tag, mode, time, event_id, log_list);
-}
-
 static void AddTagNode(const Packet* p, TagData* tag, int mode, uint32_t now,
-    uint16_t event_id, void* log_list)
+    uint16_t event_id, ListHead* log_list)
 {
     TagNode* idx;  /* index pointer */
     TagNode* returned;
@@ -427,7 +381,33 @@ static void AddTagNode(const Packet* p, TagData* tag, int mode, uint32_t now,
     }
 }
 
-int CheckTagList(Packet* p, Event& event, void** log_list)
+static void TagSession(const Packet* p, TagData* tag, uint32_t time, uint16_t event_id, ListHead* log_list)
+{
+    AddTagNode(p, tag, TAG_SESSION, time, event_id, log_list);
+}
+
+static void TagHost(const Packet* p, TagData* tag, uint32_t time, uint16_t event_id, ListHead* log_list)
+{
+    int mode;
+
+    switch (tag->tag_direction)
+    {
+    case TAG_HOST_DST:
+        mode = TAG_HOST_DST;
+        break;
+    case TAG_HOST_SRC:
+        mode = TAG_HOST_SRC;
+        break;
+    default:
+        mode = TAG_HOST_SRC;
+        break;
+    }
+
+    AddTagNode(p, tag, mode, time, event_id, log_list);
+}
+
+int CheckTagList(
+    Packet* p, SigInfo& info, ListHead*& ret_list, struct timeval& ret_time, uint32_t& ret_id, const char*& ret_act)
 {
     TagNode idx;
     TagNode* returned = nullptr;
@@ -540,10 +520,16 @@ int CheckTagList(Packet* p, Event& event, void** log_list)
 
         if ( create_event )
         {
-            event.set_event(GID_TAG, TAG_LOG_PKT, 1, 1, 1, returned->event_id,
-                p->context->conf->get_event_log_id(), returned->event_time);
-
-            *log_list = returned->log_list;
+            info.gid = GID_TAG;
+            info.sid = TAG_LOG_PKT;
+            info.rev = 1;
+            info.class_id = 1;
+            info.priority = 1;
+
+            ret_time = returned->event_time;
+            ret_id = returned->event_id;
+            ret_list = returned->log_list;
+            ret_act = (ret_list and ret_list->ruleListNode) ? ret_list->ruleListNode->name : "";
         }
 
         if ( !returned->metric )
@@ -567,6 +553,30 @@ int CheckTagList(Packet* p, Event& event, void** log_list)
     return 0;
 }
 
+static int PruneTime(XHash* tree, uint32_t thetime)
+{
+    int pruned = 0;
+    TagNode* lru_node = nullptr;
+
+    while ((lru_node = (TagNode*)tree->get_lru_user_data()) != nullptr)
+    {
+        if ((lru_node->last_access + TAG_PRUNE_QUANTUM) < thetime)
+        {
+            if (tree->release_node(&lru_node->key) != HASH_OK)
+            {
+                LogMessage("WARNING: failed to remove tagNode from hash.\n");
+            }
+            pruned++;
+        }
+        else
+        {
+            break;
+        }
+    }
+
+    return pruned;
+}
+
 static int PruneTagCache(uint32_t thetime, int mustdie)
 {
     int pruned = 0;
@@ -599,30 +609,6 @@ static int PruneTagCache(uint32_t thetime, int mustdie)
     return pruned;
 }
 
-static int PruneTime(XHash* tree, uint32_t thetime)
-{
-    int pruned = 0;
-    TagNode* lru_node = nullptr;
-
-    while ((lru_node = (TagNode*)tree->get_lru_user_data()) != nullptr)
-    {
-        if ((lru_node->last_access + TAG_PRUNE_QUANTUM) < thetime)
-        {
-            if (tree->release_node(&lru_node->key) != HASH_OK)
-            {
-                LogMessage("WARNING: failed to remove tagNode from hash.\n");
-            }
-            pruned++;
-        }
-        else
-        {
-            break;
-        }
-    }
-
-    return pruned;
-}
-
 void SetTags(const Packet* p, const OptTreeNode* otn, uint16_t event_id)
 {
     if (otn != nullptr && otn->tag != nullptr)
@@ -630,7 +616,7 @@ void SetTags(const Packet* p, const OptTreeNode* otn, uint16_t event_id)
         if (otn->tag->tag_type != 0)
         {
             RuleTreeNode* rtn = getRtnFromOtn(otn);
-            void* log_list = rtn ? rtn->listhead : nullptr;
+            ListHead* log_list = rtn ? rtn->listhead : nullptr;
 
             switch (otn->tag->tag_type)
             {
index af661f79837528ff9f4327a694f5e07867a09fcb..c4f8168560608b620e9cadff9e530236ea267d1b 100644 (file)
@@ -34,8 +34,10 @@ namespace snort
 struct Packet;
 }
 
+class Event;
+struct ListHead;
 struct OptTreeNode;
-struct Event;
+struct SigInfo;
 
 #define GID_TAG       2
 #define TAG_LOG_PKT   1
@@ -64,7 +66,7 @@ struct TagData
 
 void InitTag();
 void CleanupTag();
-int CheckTagList(snort::Packet*, Event&, void**);
+int CheckTagList(snort::Packet*, SigInfo&, ListHead*&, struct timeval&, uint32_t& id, const char*& action);
 void SetTags(const snort::Packet*, const OptTreeNode*, uint16_t);
 
 #endif
index baaadbcf923ae7ca772bdabaf271a998faea396a..e6ac4986e3d90153f4620a3803c7c92b3227af25 100644 (file)
@@ -24,9 +24,9 @@
 
 #include <string>
 
-#include "actions/actions.h"
 #include "detection/signature.h"
 #include "detection/rule_option_types.h"
+#include "framework/ips_action.h"
 #include "framework/pdu_section.h"
 #include "main/policy.h"
 #include "main/snort_types.h"
@@ -136,7 +136,7 @@ struct RuleTreeNode
     // Multiple OTNs can reference this RTN with the same policy.
     unsigned int otnRefCount = 0; // FIXIT-L shared_ptr?
 
-    Actions::Type action = 0;
+    snort::IpsAction::Type action = 0;
 
     uint8_t flags = 0;
 
index c690af09fb2a43de11949c0c6c8c026f8174e6b9..ed56c8be8c5ca11e7f92a64c546cc283724bf0e8 100644 (file)
@@ -1,12 +1,12 @@
 
 set (INCLUDES
     event.h
-    event_queue.h
 )
 
 add_library (events OBJECT
     event.cc
     event_queue.cc
+    event_queue.h
     sfeventq.cc
     sfeventq.h
     ${INCLUDES}
index f2375bebfefb969be763d71acaef3e4c944498b9..30c4d08602548a55b751a3935a5baa5629b4a9b9 100644 (file)
 
 #include "detection/signature.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 
 using namespace snort;
 
 static THREAD_LOCAL uint16_t g_event_id;
+static SigInfo s_dummy;
 
-uint16_t get_event_id()
-{
-    return g_event_id;
-}
-
-void incr_event_id()
-{
-    g_event_id++;
-}
-
-static uint32_t calc_event_id(uint16_t id, uint16_t log_id)
+static uint32_t calc_event_id(uint16_t id)
 {
     // Use instance ID to make log_id unique per packet thread. Even if
     // it overflows, value will still be unique if there are less than
     // 65k threads.
+    uint16_t log_id = SnortConfig::get_conf()->get_event_log_id();
     log_id += snort::get_instance_id();
     return (id | (log_id << 16));
 }
 
-void Event::update_event_id(uint16_t log_id)
+uint16_t Event::get_curr_seq_num()
+{ return g_event_id; }
+
+uint16_t Event::get_next_seq_num()
+{ return ++g_event_id; }
+
+uint32_t Event::get_next_event_id()
 {
-    event_id = calc_event_id(g_event_id, log_id);
+    uint16_t eseq = get_next_seq_num();
+    return calc_event_id(eseq);
 }
 
-void Event::update_event_id_and_ref(uint16_t log_id)
+Event::Event() : sig_info(s_dummy) { }
+
+Event::Event(uint32_t sec, uint32_t usec, const SigInfo& si, const char** bufs, const char* act) :
+    sig_info(si)
 {
-    event_id = calc_event_id(g_event_id, log_id);
+    ts_sec = sec;
+    ts_usec = usec;
+
+    buffs_to_dump = bufs;
+    action = act;
+
+    event_id = calc_event_id(g_event_id);
     event_reference = event_id;
 }
 
-uint32_t Event::update_and_get_event_id(void)
+Event::Event(uint32_t sec, uint32_t usec, const SigInfo& si, const char** bufs, const char* act, uint32_t ref) :
+    sig_info(si)
 {
-    /* return event id based on g_event_id. */
-    incr_event_id();
+    ts_sec = sec;
+    ts_usec = usec;
+
+    buffs_to_dump = bufs;
+    action = act;
 
-    return calc_event_id(g_event_id,
-        SnortConfig::get_conf()->get_event_log_id());
+    event_id = get_next_event_id();
+    event_reference = calc_event_id(ref);
 }
 
-void Event::set_event(uint32_t gid, uint32_t sid, uint32_t rev,
-    uint32_t classification, uint32_t priority, uint16_t event_ref,
-    uint16_t log_id, const struct timeval& tv, const std::string& act)
+uint32_t Event::get_seconds() const
+{ return ts_sec; }
+
+void Event::get_timestamp(uint32_t& sec, uint32_t& usec) const
+{ sec = ts_sec; usec = ts_usec; }
+
+uint32_t Event::get_event_id() const
+{ return event_id; }
+
+uint32_t Event::get_event_reference() const
+{ return event_reference; }
+
+uint32_t Event::get_gid() const
+{ return sig_info.gid; }
+
+uint32_t Event::get_sid() const
+{ return sig_info.sid; }
+
+uint32_t Event::get_rev() const
+{ return sig_info.rev; }
+
+void Event::get_sig_ids(uint32_t& gid, uint32_t& sid, uint32_t& rev) const
 {
-    sig_info->gid = gid;
-    sig_info->sid = sid;
-    sig_info->rev = rev;
-    sig_info->class_id = classification;
-    sig_info->priority = priority;
-
-    event_id = update_and_get_event_id();
-
-    if (event_ref)
-        event_reference = calc_event_id(event_ref, log_id);
-    else
-        event_reference = event_id;
-
-    ref_time.tv_sec = tv.tv_sec;
-    ref_time.tv_usec = tv.tv_usec;
-    action_string = act;
+    gid = sig_info.gid;
+    sid = sig_info.sid;
+    rev = sig_info.rev;
+}
+
+const char* Event::get_msg() const
+{
+    if ( sig_info.message.empty() )
+        return nullptr;
+
+    return sig_info.message.c_str();
+}
+
+const char* Event::get_class_type() const
+{
+    if ( !sig_info.class_type or sig_info.class_type->text.empty() )
+        return nullptr;
+
+    return sig_info.class_type->text.c_str();
 }
 
+const char** Event::get_buffers() const
+{ return buffs_to_dump; }
+
+const char* Event::get_action() const
+{ return action; }
+
+uint32_t Event::get_class_id() const
+{ return sig_info.class_id; }
+
+uint32_t Event::get_priority() const
+{ return sig_info.priority; }
+
+bool Event::get_target(bool& src) const
+{
+    if ( sig_info.target == TARGET_SRC )
+    {
+        src = true;
+        return true;
+    }
+    else if ( sig_info.target == TARGET_DST )
+    {
+        src = false;
+        return true;
+    }
+    return false;
+}
+
+const SigInfo& Event::get_sig_info() const
+{ return sig_info; }
+
index 5290de9021cbf102e61cc4fa033f035365a4c94e..2bf8a58557116409340d4103a6d54d8351b85cf0 100644 (file)
@@ -1,7 +1,5 @@
 //--------------------------------------------------------------------------
 // Copyright (C) 2014-2024 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2002-2013 Sourcefire, Inc.
-// Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
 //
 // 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
 #ifndef EVENT_H
 #define EVENT_H
 
-#include "main/thread.h"
+#include "main/snort_types.h"
 
 struct SigInfo;
 
-/* we must use fixed size of 32 bits, because on-disk
- * format of savefiles uses 32-bit tv_sec (and tv_usec)
- */
-struct sf_timeval32
+class SO_PUBLIC Event
 {
-    uint32_t tv_sec;      /* seconds */
-    uint32_t tv_usec;     /* microseconds */
-};
+public:
+    Event();
+    Event(uint32_t sec, uint32_t usec, const SigInfo&, const char** buffers, const char* action);
+    Event(uint32_t sec, uint32_t usec, const SigInfo&, const char** buffers, const char* action, uint32_t ref);
 
-struct Event
-{
-    SigInfo* sig_info = nullptr;
-    struct sf_timeval32 ref_time = { 0, 0 };   /* reference time for the event reference */
-    const char* alt_msg = nullptr;
-    std::string action_string;
-    const char** buffs_to_dump = nullptr;
+    static uint16_t get_curr_seq_num();
+    static uint16_t get_next_seq_num();
+    static uint32_t get_next_event_id();
+
+    const SigInfo& get_sig_info() const;
+
+    uint32_t get_seconds() const;
+    void get_timestamp(uint32_t& sec, uint32_t& usec) const;
 
-    Event() = default;
-    Event(SigInfo& si)
-    { sig_info = &si; }
+    uint32_t get_event_id() const;
+    uint32_t get_event_reference() const;
 
-    uint32_t get_event_id() const { return event_id; }
-    void set_event_id(uint32_t id) { event_id = id; }
+    const char** get_buffers() const;
+    const char* get_action() const;
 
-    uint32_t get_event_reference() const { return event_reference; }
-    void set_event_reference(uint32_t ref) { event_reference = ref; }
+    uint32_t get_gid() const;
+    uint32_t get_sid() const;
+    uint32_t get_rev() const;
 
-    void update_event_id(uint16_t log_id);
-    void update_event_id_and_ref(uint16_t log_id);
-    SO_PUBLIC static uint32_t update_and_get_event_id();
+    void get_sig_ids(uint32_t& gid, uint32_t& sid, uint32_t& rev) const;
 
-    void set_event(uint32_t gid, uint32_t sid, uint32_t rev,
-        uint32_t classification, uint32_t priority, uint16_t event_ref,
-        uint16_t log_id, const struct timeval& tv, const std::string& act = "");
+    const char* get_msg() const;
+    const char* get_class_type() const;
 
+    uint32_t get_class_id() const;
+    uint32_t get_priority() const;
+
+    // returns false if not specified; otherwise src indicates target is source or dest
+    bool get_target(bool& src) const;
 
 private:
+    const SigInfo& sig_info;
+    const char* action = nullptr;
+    const char** buffs_to_dump = nullptr;
+
+    uint32_t ts_sec = 0;
+    uint32_t ts_usec = 0;
+
     uint32_t event_id = 0;
     uint32_t event_reference = 0; // reference to other events that have gone off,
                                   // such as in the case of tagged packets...
 };
 
-uint16_t get_event_id();
-void incr_event_id();
-
 #endif
 
index 32fa5969d6c59879b758ad71117529df4caca2cb..9336330bd7e29414c52ba8d56a4a1d8c66939011 100644 (file)
@@ -2,12 +2,8 @@
 set( FILE_API_INCLUDES
     file_api.h
     file_capture.h
-    file_config.h
     file_flows.h
-    file_identifier.h
     file_lib.h
-    file_module.h
-    file_segment.h
     file_service.h
 )
 
@@ -20,14 +16,22 @@ add_library ( file_api OBJECT
     file_cache.cc
     file_cache.h
     file_config.cc
+    file_config.h
     file_flows.cc
     file_identifier.cc
+    file_identifier.h
+    file_inspect.cc
+    file_inspect.h
     file_lib.cc
     file_log.cc
     file_mempool.cc
     file_mempool.h
     file_module.cc
+    file_module.h
+    file_policy.cc
+    file_policy.h
     file_segment.cc
+    file_segment.h
     file_service.cc
     file_stats.cc
     file_stats.h
index 0256594d309efb043f1dadfaea23166bd398af44..e47859090c09a164c61dc561bceda39cd76021de 100644 (file)
 #include "main/snort_config.h"
 #include "main/thread_config.h"
 #include "packet_io/active.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "time/packet_time.h"
 
 #include "file_flows.h"
+#include "file_module.h"
 #include "file_service.h"
 #include "file_stats.h"
 
index c3f1a49ece903d86e7a25583f8ebe4caec73c175..8beee355f0abdc7a658c76cd304cc4cb8b42e88c 100644 (file)
@@ -34,7 +34,9 @@
 
 #include <cassert>
 
+#include "log/log_stats.h"
 #include "log/messages.h"
+#include "main/thread.h"
 #include "utils/stats.h"
 #include "utils/util.h"
 
index 459adabb13cd40f8ede15efda2a6018294ff3160..0390f5e9cbc30bb0660c42b0a2fdd5ff05d696a7 100644 (file)
 
 #include "file_config.h"
 
-#include "main/snort_config.h"
 #include "managers/inspector_manager.h"
+#include "main/snort_config.h"
 #include "parser/parse_utils.h"
 
 #include "file_flows.h"
+#include "file_inspect.h"
 
 using namespace snort;
 
index c37e0e08f3370fd51925042b38dca338b0c22a72..0f47c2b54447009590d6ab9023fe83ad99791015 100644 (file)
@@ -32,8 +32,9 @@
 #include "detection/detection_engine.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "managers/inspector_manager.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "protocols/packet.h"
 #include "trace/trace_api.h"
 
@@ -78,7 +79,7 @@ static void populate_trace_data(FileContext* context)
 
     PacketTracer::daq_log("file+%" PRId64"+Matched policy id %u, identification %s, signature %s, capture %s+"
                 "File with ID %lu, name %s, type %s, size %lu, SHA %s detected. Verdict %s.$",
-                TO_NSECS(pt_timer->get()),
+                PacketTracer::get_time(),
                 context->get_policy_id(),
                 ((context->is_file_type_enabled() || context->get_file_type() || context->get_file_sig_sha256()) ? "<on>" : "<off>"),
                 ((context->is_file_signature_enabled() || context->get_file_sig_sha256()) ? "<on>" : "<off>"),
@@ -368,7 +369,7 @@ bool FileFlows::file_process(Packet* p, uint64_t file_id, const uint8_t* file_da
     }
 
     if (PacketTracer::is_daq_activated())
-        PacketTracer::pt_timer_start();
+        PacketTracer::restart_timer();
 
     if (!cacheable)
         context->set_not_cacheable();
@@ -460,7 +461,7 @@ bool FileFlows::file_process(Packet* p, const uint8_t* file_data, int data_size,
     }
 
     if (PacketTracer::is_daq_activated())
-        PacketTracer::pt_timer_start();
+        PacketTracer::restart_timer();
 
     context = find_main_file_context(position, direction, file_index);
 
@@ -518,120 +519,3 @@ void FileFlows::add_pending_file(uint64_t file_id)
     current_file_id = pending_file_id = file_id;
 }
 
-FileInspect::FileInspect(FileIdModule* fm)
-{
-    fm->load_config(config);
-}
-
-FileInspect:: ~FileInspect()
-{
-    if (config)
-        delete config;
-}
-
-bool FileInspect::configure(SnortConfig*)
-{
-    if (!config)
-        return true;
-
-    FileCache* file_cache = FileService::get_file_cache();
-    if (file_cache)
-    {
-        file_cache->set_block_timeout(config->file_block_timeout);
-        file_cache->set_lookup_timeout(config->file_lookup_timeout);
-        file_cache->set_max_files(config->max_files_cached);
-    }
-
-    return true;
-}
-
-static void file_config_show(const FileConfig* fc)
-{
-    if ( ConfigLogger::log_flag("enable_type", FileService::is_file_type_id_enabled()) )
-        ConfigLogger::log_value("type_depth", fc->file_type_depth);
-
-    if ( ConfigLogger::log_flag("enable_signature", FileService::is_file_signature_enabled()) )
-        ConfigLogger::log_value("signature_depth", fc->file_signature_depth);
-
-    if ( ConfigLogger::log_flag("block_timeout_lookup", fc->block_timeout_lookup) )
-        ConfigLogger::log_value("block_timeout", fc->file_block_timeout);
-
-    if ( ConfigLogger::log_flag("enable_capture", FileService::is_file_capture_enabled()) )
-    {
-        ConfigLogger::log_value("capture_memcap", fc->capture_memcap);
-        ConfigLogger::log_value("capture_max_size", fc->capture_max_size);
-        ConfigLogger::log_value("capture_min_size", fc->capture_min_size);
-        ConfigLogger::log_value("capture_block_size", fc->capture_block_size);
-    }
-
-    ConfigLogger::log_value("lookup_timeout", fc->file_lookup_timeout);
-    ConfigLogger::log_value("max_files_cached", fc->max_files_cached);
-    ConfigLogger::log_value("max_files_per_flow", fc->max_files_per_flow);
-    ConfigLogger::log_value("show_data_depth", fc->show_data_depth);
-
-    ConfigLogger::log_flag("trace_type", fc->trace_type);
-    ConfigLogger::log_flag("trace_signature", fc->trace_signature);
-    ConfigLogger::log_flag("trace_stream", fc->trace_stream);
-}
-
-void FileInspect::show(const SnortConfig*) const
-{
-    if ( config )
-        file_config_show(config);
-}
-
-static Module* mod_ctor()
-{ return new FileIdModule; }
-
-static void mod_dtor(Module* m)
-{ delete m; }
-
-static void file_init()
-{
-    FileFlows::init();
-}
-
-static void file_term()
-{
-}
-
-static Inspector* file_ctor(Module* m)
-{
-    FileIdModule* mod = (FileIdModule*)m;
-    return new FileInspect(mod);
-}
-
-static void file_dtor(Inspector* p)
-{
-    delete p;
-}
-
-static const InspectApi file_inspect_api =
-{
-    {
-        PT_INSPECTOR,
-        sizeof(InspectApi),
-        INSAPI_VERSION,
-        0,
-        API_RESERVED,
-        API_OPTIONS,
-        FILE_ID_NAME,
-        FILE_ID_HELP,
-        mod_ctor,
-        mod_dtor
-    },
-    IT_FILE,
-    PROTO_BIT__NONE,
-    nullptr,
-    "file",
-    file_init,
-    file_term,
-    nullptr, // tinit
-    nullptr, // tterm
-    file_ctor,
-    file_dtor,
-    nullptr, // ssn
-    nullptr  // reset
-};
-
-const BaseApi* sin_file_flow = &file_inspect_api.base;
index abd6ad13a31bbad38cee9518f80a1bda904a0f04..6cd9e3a2ce503fa84795e15f985426411e2364cf 100644 (file)
 // This provides a wrapper to manage several file contexts
 
 #include "flow/flow.h"
+#include "helpers/event_gen.h"
 #include "main/snort_types.h"
-#include "utils/event_gen.h"
 
 #include "file_api.h"
-#include "file_module.h"
 
 #include <map>
 
+static const uint32_t FILE_ID_GID = 150;
+
+enum FileSid
+{
+    EVENT__NONE = -1,
+    EVENT_FILE_DROPPED_OVER_LIMIT = 1,
+    EVENT__MAX_VALUE
+};
+
 using FileEventGen = EventGen<EVENT__MAX_VALUE, EVENT__NONE, FILE_ID_GID>;
 
+class FileInspect;
+
 namespace snort
 {
 class FileContext;
 class Flow;
 
-class FileInspect : public Inspector
-{
-public:
-    FileInspect(FileIdModule*);
-    ~FileInspect() override;
-    void eval(Packet*) override { }
-    bool configure(SnortConfig*) override;
-    void show(const SnortConfig*) const override;
-    FileConfig* config;
-};
-
 class SO_PUBLIC FileFlows : public FlowData
 {
 public:
 
-    FileFlows(Flow* f, FileInspect* inspect) : FlowData(file_flow_data_id, inspect), flow(f) { }
+    FileFlows(Flow* f, FileInspect* fi) : FlowData(file_flow_data_id, (Inspector*)fi), flow(f) { }
     ~FileFlows() override;
     std::mutex file_flow_context_mutex;
     static void init()
diff --git a/src/file_api/file_inspect.cc b/src/file_api/file_inspect.cc
new file mode 100644 (file)
index 0000000..02d488a
--- /dev/null
@@ -0,0 +1,155 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2023 Cisco and/or its affiliates. All rights reserved.
+// Copyright (C) 2012-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.
+//--------------------------------------------------------------------------
+/*
+ ** Author(s):  Hui Cao <huica@cisco.com>
+ **
+ ** NOTES
+ ** 8.15.15 - Initial Source Code. Hui Cao
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "file_inspect.h"
+
+#include "log/messages.h"
+
+#include "file_cache.h"
+#include "file_config.h"
+#include "file_flows.h"
+#include "file_module.h"
+#include "file_service.h"
+
+using namespace snort;
+
+FileInspect::FileInspect(FileIdModule* fm)
+{
+    fm->load_config(config);
+}
+
+FileInspect:: ~FileInspect()
+{
+    if (config)
+        delete config;
+}
+
+bool FileInspect::configure(SnortConfig*)
+{
+    if (!config)
+        return true;
+
+    FileCache* file_cache = FileService::get_file_cache();
+    if (file_cache)
+    {
+        file_cache->set_block_timeout(config->file_block_timeout);
+        file_cache->set_lookup_timeout(config->file_lookup_timeout);
+        file_cache->set_max_files(config->max_files_cached);
+    }
+
+    return true;
+}
+
+static void file_config_show(const FileConfig* fc)
+{
+    if ( ConfigLogger::log_flag("enable_type", FileService::is_file_type_id_enabled()) )
+        ConfigLogger::log_value("type_depth", fc->file_type_depth);
+
+    if ( ConfigLogger::log_flag("enable_signature", FileService::is_file_signature_enabled()) )
+        ConfigLogger::log_value("signature_depth", fc->file_signature_depth);
+
+    if ( ConfigLogger::log_flag("block_timeout_lookup", fc->block_timeout_lookup) )
+        ConfigLogger::log_value("block_timeout", fc->file_block_timeout);
+
+    if ( ConfigLogger::log_flag("enable_capture", FileService::is_file_capture_enabled()) )
+    {
+        ConfigLogger::log_value("capture_memcap", fc->capture_memcap);
+        ConfigLogger::log_value("capture_max_size", fc->capture_max_size);
+        ConfigLogger::log_value("capture_min_size", fc->capture_min_size);
+        ConfigLogger::log_value("capture_block_size", fc->capture_block_size);
+    }
+
+    ConfigLogger::log_value("lookup_timeout", fc->file_lookup_timeout);
+    ConfigLogger::log_value("max_files_cached", fc->max_files_cached);
+    ConfigLogger::log_value("max_files_per_flow", fc->max_files_per_flow);
+    ConfigLogger::log_value("show_data_depth", fc->show_data_depth);
+
+    ConfigLogger::log_flag("trace_type", fc->trace_type);
+    ConfigLogger::log_flag("trace_signature", fc->trace_signature);
+    ConfigLogger::log_flag("trace_stream", fc->trace_stream);
+}
+
+void FileInspect::show(const SnortConfig*) const
+{
+    if ( config )
+        file_config_show(config);
+}
+
+static Module* mod_ctor()
+{ return new FileIdModule; }
+
+static void mod_dtor(Module* m)
+{ delete m; }
+
+static void file_init()
+{
+    FileFlows::init();
+}
+
+static Inspector* file_ctor(Module* m)
+{
+    FileIdModule* mod = (FileIdModule*)m;
+    return new FileInspect(mod);
+}
+
+static void file_dtor(Inspector* p)
+{
+    delete p;
+}
+
+static const InspectApi file_inspect_api =
+{
+    {
+        PT_INSPECTOR,
+        sizeof(InspectApi),
+        INSAPI_VERSION,
+        0,
+        API_RESERVED,
+        API_OPTIONS,
+        FILE_ID_NAME,
+        FILE_ID_HELP,
+        mod_ctor,
+        mod_dtor
+    },
+    IT_FILE,
+    PROTO_BIT__NONE,
+    nullptr,
+    "file",
+    file_init,
+    nullptr,
+    nullptr, // tinit
+    nullptr, // tterm
+    file_ctor,
+    file_dtor,
+    nullptr, // ssn
+    nullptr  // reset
+};
+
+const BaseApi* sin_file_flow = &file_inspect_api.base;
+
diff --git a/src/file_api/file_inspect.h b/src/file_api/file_inspect.h
new file mode 100644 (file)
index 0000000..fa67abf
--- /dev/null
@@ -0,0 +1,40 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2015-2023 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.
+//--------------------------------------------------------------------------
+
+// author Hui Cao <huica@cisco.com>
+
+#ifndef FILE_INSPECT_H
+#define FILE_INSPECT_H
+
+// file processing configuration
+//
+#include "framework/inspector.h"
+
+class FileInspect : public snort::Inspector
+{
+public:
+    FileInspect(class FileIdModule*);
+    ~FileInspect() override;
+    void eval(snort::Packet*) override { }
+    bool configure(snort::SnortConfig*) override;
+    void show(const snort::SnortConfig*) const override;
+    class FileConfig* config;
+};
+
+#endif
+
index aca3b17c71c3bb2d8b9be592c40d19949962d2df..6891b346af79b20b9e535baebf461f726a3fe1db 100644 (file)
 #include <iostream>
 #include <iomanip>
 
-#include "hash/hashes.h"
+#include "detection/fp_detect.h"
 #include "framework/data_bus.h"
-#include "main/snort_config.h"
 #include "managers/inspector_manager.h"
-#include "packet_tracer/packet_tracer.h"
+#include "hash/hashes.h"
+#include "helpers/utf.h"
+#include "main/snort_config.h"
+#include "packet_io/packet_tracer.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 #include "pub_sub/intrinsic_event_ids.h"
 #include "utils/util.h"
-#include "utils/util_utf.h"
 
 #include "file_api.h"
+#include "file_cache.h"
 #include "file_capture.h"
 #include "file_config.h"
-#include "file_cache.h"
 #include "file_flows.h"
-#include "file_service.h"
+#include "file_inspect.h"
+#include "file_module.h"
 #include "file_segment.h"
+#include "file_service.h"
 #include "file_stats.h"
-#include "file_module.h"
-#include "detection/fp_detect.h"
 
 using namespace snort;
 
@@ -336,10 +337,11 @@ FileContext::~FileContext ()
 {
     if (file_signature_context)
         snort_free(file_signature_context);
+
     if (file_capture)
         stop_file_capture();
-    if (file_segments)
-        delete file_segments;
+
+    delete file_segments;
     InspectorManager::release(inspector);
 }
 
index 7f7faed1782cdd0f5cd0ab8b0f5e39ba3bfeb01e..bd0776b7c18c7137be89e3a8736bf91d13bf4869 100644 (file)
@@ -38,12 +38,12 @@ const std::string VerdictName[] =
 {"Unknown", "Log", "Stop", "Block", "Reset", "Pending", "Stop Capture", "INVALID"};
 
 class FileConfig;
+class FileInspect;
 class FileSegments;
 
 namespace snort
 {
 class FileCapture;
-class FileInspect;
 class Flow;
 
 class SO_PUBLIC FileInfo
index c2f499bd8b8f828de42129efc10af32218c79ea6..7e748432e308248d8c3c94aac4e3caf574d70fcb 100644 (file)
@@ -206,7 +206,6 @@ public:
     { }
 
     void show(const SnortConfig*) const override;
-    void eval(Packet*) override { }
 
     bool configure(SnortConfig*) override
     {
index 04e6f16c7ec12382f5b8bbc9015caf14ced32daf..4f38db385500d6a1d86cc3c32df6c7122593efa7 100644 (file)
 #include "framework/module.h"
 
 #include "file_config.h"
+#include "file_flows.h"
 #include "file_identifier.h"
 #include "trace/trace_api.h"
 #include "utils/util.h"
+
 //-------------------------------------------------------------------------
 // file_id module
 //-------------------------------------------------------------------------
 
-static const uint32_t FILE_ID_GID = 150;
-
 #define FILE_DEBUG(module_name, module_id, log_level, p, ...) \
     trace_logf(log_level, module_name , module_id, p, __VA_ARGS__)
 
@@ -80,12 +80,5 @@ private:
     std::string magic_file;
 };
 
-enum FileSid
-{
-    EVENT__NONE = -1,
-    EVENT_FILE_DROPPED_OVER_LIMIT = 1,
-    EVENT__MAX_VALUE
-};
-
 #endif
 
similarity index 99%
rename from src/framework/file_policy.cc
rename to src/file_api/file_policy.cc
index 121791e3585a0d63032b31a93042793e9fb7e05f..27e3bacadc11fc1ee4f9182d21126a7cd36af451 100644 (file)
@@ -22,7 +22,7 @@
 #include "config.h"
 #endif
 
-#include "framework/file_policy.h"
+#include "file_policy.h"
 
 #include "file_api/file_capture.h"
 #include "file_api/file_lib.h"
index 370f2e01ca9e7d063f33dbe4e7cf2db1f5033616..6635ceb23680e2e16b8ea76f88e9997f70a28bcf 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "file_stats.h"
 
+#include "log/log_stats.h"
 #include "log/messages.h"
 #include "utils/stats.h"
 #include "utils/util.h"
index 9eccf8af6c7b3afbb0ff18cd8bdb1160fba42306..e94da62b7cd62e704c9fd961c5593e5be242e664 100644 (file)
@@ -23,7 +23,6 @@
 #define FILE_STATS_H
 
 #include "framework/counts.h"
-#include "main/thread.h"
 
 #include "file_api.h"
 #include "file_config.h"
index ef137ef69a4fcb06197b4ac4c32c75bacc6d258c..4e5ee679cf31e34daa19ccfc15871c33fa6236c0 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "hash/xhash.h"
 #include "log/messages.h"
-#include "main/thread.h"
 #include "utils/util.h"
 
 #include "sfthd.h"
index d169cf1b09f81ab51868c0099e896cb5b21db32a..4904609f834db11569d8f851259d7c0c9b0ccde1 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "sfrf.h"
 
-#include "main/thread.h"
 #include "detection/rules.h"
 #include "framework/ips_action.h"
 #include "hash/ghash.h"
@@ -317,7 +316,7 @@ static int SFRF_TestObject(tSFRFConfigNode* cfgNode, const SfIp* ip, time_t curT
     // if the count were not incremented in such cases, the
     // threshold would never be exceeded.
     if ( !cfgNode->seconds && (dynNode->count > cfgNode->count)
-      && Actions::is_valid_action(cfgNode->newAction) )
+      && IpsAction::is_valid_action(cfgNode->newAction) )
     {
         IpsAction* act = get_ips_policy()->action[cfgNode->newAction];
         if ( act->drops_traffic() )
@@ -561,7 +560,7 @@ static int checkThreshold(tSFRFConfigNode* cfgNode, tSFRFTrackingNode* dynNode,
     dynNode->filterState = FS_ON;
     dynNode->overRate = 1;
 
-    return Actions::get_max_types() + cfgNode->newAction;
+    return IpsAction::get_max_types() + cfgNode->newAction;
 }
 
 static void updateDependentThresholds(RateFilterConfig* config, unsigned gid,
index 46ac8da539bbe65bf221590932451b33ee84b785..b0f3747f92f592bfa600c976cf3869ca70daaf6f 100644 (file)
@@ -25,8 +25,8 @@
 #include <ctime>
 #include <mutex>
 
-#include "actions/actions.h"
 #include "framework/counts.h"
+#include "framework/ips_action.h"
 #include "main/policy.h"
 #include "sfip/sf_ip.h"
 #include "sfip/sf_ipvar.h"
@@ -72,7 +72,11 @@ struct tSFRFConfigNode
     SFRF_TRACK tracking;
     unsigned count;
     unsigned seconds;
-    Actions::Type newAction;
+
+    // Action that replaces original rule action on reaching threshold
+    snort::IpsAction::Type newAction;
+
+    // Threshold action duration in seconds before reverting to original rule action
     unsigned timeout;
     sfip_var_t* applyTo;
 };
index 8112d9053057b1318ca742b7bf7b55243ff40718..316ecdef6c0a8d722373ceb4de4ac820571a308c 100644 (file)
@@ -558,7 +558,7 @@ static void Init(const SnortConfig* sc, unsigned cap)
         cfg.tracking = p->track;
         cfg.count = p->count;
         cfg.seconds = p->seconds;
-        cfg.newAction = (Actions::Type)RULE_NEW;
+        cfg.newAction = (IpsAction::Type)RULE_NEW;
         cfg.timeout = p->timeout;
         cfg.applyTo = p->ip ? sfip_var_from_string(p->ip, "sfrf_test") : nullptr;
 
@@ -599,8 +599,8 @@ static int EventTest(EventData* p)
     status = SFRF_TestThreshold(rfc, p->gid, p->sid, get_network_policy()->policy_id,
         &sip, &dip, curtime, op);
 
-    if ( status >= Actions::get_max_types() )
-        status -= Actions::get_max_types();
+    if ( status >= IpsAction::get_max_types() )
+        status -= IpsAction::get_max_types();
 
     return status;
 }
index c0bdcafe4f223904a69f1b60e5abcb099fad580f..a530ecd5fc9e6041d8f48174328ff48fd042dfb0 100644 (file)
@@ -36,7 +36,6 @@
 #include "hash/ghash.h"
 #include "hash/hash_defs.h"
 #include "hash/xhash.h"
-#include "main/thread.h"
 #include "sfip/sf_ipvar.h"
 #include "utils/sflsq.h"
 #include "utils/util.h"
@@ -361,7 +360,6 @@ static int sfthd_create_threshold_global(
     return 0;
 }
 
-
 /*!
 Add a permanent threshold object to the threshold table. Multiple
 objects may be defined for each gen_id and sig_id pair. Internally
index d8f5ec9ca5a2652e4921570dd709f22b9c424e0a..a1de6ff1c53a6033f44e1f45424f1d21ded89d8d 100644 (file)
@@ -1,6 +1,6 @@
 set (FLOW_INCLUDES
     deferred_trust.h
-    expect_cache.h
+    expect_flow.h
     flow.h
     flow_data.h
     flow_key.h
@@ -8,6 +8,7 @@ set (FLOW_INCLUDES
     ha.h
     session.h
     stash_item.h
+    stream_flow.h
 )
 
 add_library (flow OBJECT
@@ -16,6 +17,7 @@ add_library (flow OBJECT
     expect_cache.cc
     flow.cc
     flow_cache.cc
+    expect_cache.h
     flow_cache.h
     flow_config.h
     flow_control.cc
index 0fc7b586cfd49e7a4c0f688e0be98afe1a4291cb..53a6128192d2b1098d6d7f4438b50f52770acbb8 100644 (file)
 #endif
 
 #include "expect_cache.h"
+#include "expect_flow.h"
 
 #include "detection/ips_context.h"
 #include "hash/zhash.h"
+#include "packet_io/packet_tracer.h"
 #include "packet_io/sfdaq_instance.h"
-#include "packet_tracer/packet_tracer.h"
 #include "protocols/packet.h"
 #include "protocols/vlan.h"
 #include "pub_sub/expect_events.h"
index c14592c11898eecfd6f97a94c4e391e4ecee6b21..b61d2bf5acd3713d8faec998d9e3ba0d4acc13ab 100644 (file)
 // ExpectCache is used to track anticipated flows (like ftp data channels).
 // when the flow is found, it updated with the given info.
 
-//-------------------------------------------------------------------------
-// data structs
-// -- key has IP address and port pairs; one port must be zero (wild card)
-//    forming a 3-tuple
-// -- node struct is stored in hash table by key
-// -- each node struct has one or more list structs linked together
-// -- each list struct has a list of flow data
-// -- when a new expect is added, a new list struct is created if a new
-//    node is created or the last list struct of an existing node already
-//    has the same preproc id in the flow data list
-// -- when a new expect is added, the last list struct is used if the
-//    given preproc id is not already in the flow data list
-// -- nodes are preallocated and stored in hash table; if there is no node
-//    available when an expect is added, LRU nodes are pruned
-// -- list structs are also preallocated and stored in free list; if there
-//    is no list struct available when an expect is added, LRU nodes are
-//    pruned freeing up both nodes and list structs
-// -- the number of list structs per node is capped at MAX_LIST; once
-//    reached, requests to add new expects requiring new list structs fail
-// -- the number of data structs per list struct is not capped
-// -- example:  ftp preproc adds a new 3-tuple twice for 2 expected data
-//    channels -> new node with 2 list structs linked to it
-// -- example:  ftp preproc adds a new 3-tuple once and then another
-//    preproc expects the same 3-tuple -> new node with one list struct
-//    is created for ftp and the next request goes in that same list
-//    struct
-// -- new list structs are appended to node's list struct chain
-// -- matching expected sessions are pulled off from the head of the node's
-//    list struct chain
-//
-// FIXIT-M expiration is by node struct but should be by list struct, ie
-//    individual sessions, not all sessions to a given 3-tuple
-//    (this would make pruning a little harder unless we add linkage
-//    a la FlowCache)
-//-------------------------------------------------------------------------
-#include <vector>
 #include "flow/flow_key.h"
 #include "target_based/snort_protocols.h"
 
@@ -70,21 +34,9 @@ namespace snort
 {
 class Flow;
 class FlowData;
-struct Packet;
 
-struct SO_PUBLIC ExpectFlow
-{
-    struct ExpectFlow* next;
-    snort::FlowData* data;
-
-    ~ExpectFlow();
-    void clear();
-    int add_flow_data(snort::FlowData*);
-    snort::FlowData* get_flow_data(unsigned);
-    static std::vector<ExpectFlow*>* get_expect_flows();
-    static void reset_expect_flows();
-    static void handle_expected_flows(const snort::Packet*);
-};
+struct ExpectFlow;
+struct Packet;
 }
 
 class ExpectCache
diff --git a/src/flow/expect_flow.h b/src/flow/expect_flow.h
new file mode 100644 (file)
index 0000000..814d5b4
--- /dev/null
@@ -0,0 +1,91 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2023 Cisco and/or its affiliates. All rights reserved.
+// Copyright (C) 2013-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.
+//--------------------------------------------------------------------------
+
+// expect_cache.h author Russ Combs <rucombs@cisco.com>
+
+#ifndef EXPECT_FLOW_H
+#define EXPECT_FLOW_H
+
+// ExpectCache is used to track anticipated flows (like ftp data channels).
+// when the flow is found, it updated with the given info.
+
+//-------------------------------------------------------------------------
+// data structs
+// -- key has IP address and port pairs; one port must be zero (wild card)
+//    forming a 3-tuple
+// -- node struct is stored in hash table by key
+// -- each node struct has one or more list structs linked together
+// -- each list struct has a list of flow data
+// -- when a new expect is added, a new list struct is created if a new
+//    node is created or the last list struct of an existing node already
+//    has the same preproc id in the flow data list
+// -- when a new expect is added, the last list struct is used if the
+//    given preproc id is not already in the flow data list
+// -- nodes are preallocated and stored in hash table; if there is no node
+//    available when an expect is added, LRU nodes are pruned
+// -- list structs are also preallocated and stored in free list; if there
+//    is no list struct available when an expect is added, LRU nodes are
+//    pruned freeing up both nodes and list structs
+// -- the number of list structs per node is capped at MAX_LIST; once
+//    reached, requests to add new expects requiring new list structs fail
+// -- the number of data structs per list struct is not capped
+// -- example:  ftp preproc adds a new 3-tuple twice for 2 expected data
+//    channels -> new node with 2 list structs linked to it
+// -- example:  ftp preproc adds a new 3-tuple once and then another
+//    preproc expects the same 3-tuple -> new node with one list struct
+//    is created for ftp and the next request goes in that same list
+//    struct
+// -- new list structs are appended to node's list struct chain
+// -- matching expected sessions are pulled off from the head of the node's
+//    list struct chain
+//
+// FIXIT-M expiration is by node struct but should be by list struct, ie
+//    individual sessions, not all sessions to a given 3-tuple
+//    (this would make pruning a little harder unless we add linkage
+//    a la FlowCache)
+//-------------------------------------------------------------------------
+
+#include <vector>
+
+#include "main/snort_types.h"
+
+struct ExpectNode;
+
+namespace snort
+{
+class FlowData;
+struct Packet;
+
+struct SO_PUBLIC ExpectFlow
+{
+    struct ExpectFlow* next;
+    snort::FlowData* data;
+
+    ~ExpectFlow();
+    void clear();
+    int add_flow_data(snort::FlowData*);
+    snort::FlowData* get_flow_data(unsigned);
+    static std::vector<ExpectFlow*>* get_expect_flows();
+    static void reset_expect_flows();
+    static void handle_expected_flows(const snort::Packet*);
+};
+}
+
+#endif
+
index 84ebac467f39120d420bea4ab64e9cb2401f6b9b..379a29ed3b0f329f9876969d9d0ce67486ae4311 100644 (file)
@@ -39,7 +39,6 @@
 #include "framework/data_bus.h"
 #include "framework/decode_data.h"
 #include "framework/inspector.h"
-#include "network_inspectors/appid/application_ids.h"
 #include "protocols/layer.h"
 #include "sfip/sf_ip.h"
 #include "target_based/snort_protocols.h"
@@ -110,7 +109,6 @@ namespace snort
 {
 class FlowHAState;
 struct FlowKey;
-class IpsContext;
 struct Packet;
 
 typedef void (* StreamAppDataFree)(void*);
@@ -159,20 +157,6 @@ struct LwState
     char ignore_direction;
 };
 
-class SO_PUBLIC StreamFlowIntf
-{
-public:
-    virtual FlowData* get_stream_flow_data(const Flow* flow) = 0;
-    virtual void set_stream_flow_data(Flow* flow, FlowData* flow_data) = 0;
-    virtual void get_stream_id(const Flow* flow, int64_t& stream_id) = 0;
-    virtual void* get_hi_msg_section(const Flow* flow) = 0;
-    virtual void set_hi_msg_section(Flow* flow, void* section) = 0;
-    virtual AppId get_appid_from_stream(const Flow*) { return APP_ID_NONE; }
-    // Stream based flows should override this interface to return parent flow
-    // when child flow is passed as input
-    virtual Flow* get_stream_parent_flow(Flow* cflow) { return cflow; }
-};
-
 // this struct is organized by member size for compactness
 class SO_PUBLIC Flow
 {
@@ -474,7 +458,7 @@ public:  // FIXIT-M privatize if possible
     IpsContextChain context_chain;
     FlowData* current_flow_data = nullptr;
     FlowStats flowstats = {};
-    StreamFlowIntf* stream_intf = nullptr;
+    class StreamFlowIntf* stream_intf = nullptr;
 
     SfIp client_ip = {};
     SfIp server_ip = {};
index bee007c6270c73a24b40962a184fac8eb9a47a7d..7515ce89b06ee2eca75ba4791a59d129b4581957 100644 (file)
@@ -37,7 +37,7 @@
 #endif
 #include "main/thread_config.h"
 #include "packet_io/active.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "stream/base/stream_module.h"
 #include "stream/tcp/tcp_stream_session.h"
 #include "stream/tcp/tcp_trace.h"
index 20deac8827fe83ba0472f082b30c4b388c6e71ba..7066a56dac8b5fe062c476c312635d8e91905ecd 100644 (file)
 #include <memory>
 
 #include "framework/counts.h"
-#include "main/analyzer_command.h"
-#include "main/thread.h"
-
 #include "flow_config.h"
+#include "main/analyzer_command.h"
 #include "prune_stats.h"
 #include "filter_flow_critera.h"
 
index 3acc2202ae45523de346183bb383c2dd2280ac45..34f5a5012c748c9a9e28391935b1a4d19b2e6e01 100644 (file)
@@ -26,9 +26,8 @@
 
 #include "detection/detection_engine.h"
 #include "main/snort_config.h"
-#include "managers/inspector_manager.h"
 #include "packet_io/active.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "protocols/icmp4.h"
 #include "protocols/tcp.h"
 #include "protocols/udp.h"
index 12434e1a568dee69dccfb3bc20d6857fd1d6755b..5123db7b9570e38a5175c26da45e9b2efe77565b 100644 (file)
@@ -20,6 +20,9 @@
 #ifndef FLOW_DATA_H
 #define FLOW_DATA_H
 
+// FlowData is how inspectors maintain flow state
+// use Flow::set/get_flow_data() to attach to a flow
+
 #include "main/snort_types.h"
 
 namespace snort
@@ -30,7 +33,6 @@ struct Packet;
 class SO_PUBLIC FlowData
 {
 public:
-    FlowData(unsigned u, Inspector* = nullptr);
     virtual ~FlowData();
 
     unsigned get_id()
@@ -41,13 +43,13 @@ public:
 
     Inspector* get_handler() { return handler; }
 
-    // deprecated - do not implement
-    virtual size_t size_of() { return 0; }
-
     virtual void handle_expected(Packet*) { }
     virtual void handle_retransmit(Packet*) { }
     virtual void handle_eof(Packet*) { }
 
+protected:
+    FlowData(unsigned u, Inspector* = nullptr);
+
 public:  // FIXIT-L privatize
     FlowData* next;
     FlowData* prev;
index 5b25e8e7e9b53f17e777a4da37fd0d1104077332..f7bcb04bbd8fe6ec93bf25534d8228cc8e3fd5ae 100644 (file)
@@ -31,8 +31,6 @@
 #include "hash/hash_key_operations.h"
 #include "utils/cpp_macros.h"
 
-class HashKeyOperations;
-
 namespace snort
 {
 struct SfIp;
index fa26bf45befc0c769d274a4a6e376e23e48e3961..15a19fd51afb212329122f8c2409e47a84c4c93d 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <cassert>
 
+#include "main/snort_config.h"
 #include "pub_sub/auxiliary_ip_event.h"
 #include "pub_sub/stash_events.h"
 
index 077f022e6ae91486044d8f620e7d665a19471078..09f77d697e6402b59da2e657c8965a9b796841fa 100644 (file)
 #ifndef FLOW_STASH_H
 #define FLOW_STASH_H
 
+// a generic store for shared flow data
+
 #include <list>
 #include <map>
 #include <string>
 #include <unordered_map>
 
-#include "main/snort_config.h"
 #include "main/snort_types.h"
 #include "sfip/sf_ip.h"
 
@@ -52,7 +53,7 @@ public:
     void store(const std::string& key, std::string* val, unsigned pubid = 0, unsigned evid = 0);
     void store(const std::string& key, StashGenericObject* val, unsigned pubid = 0, unsigned evid = 0);
 
-    bool store(const snort::SfIp&, const SnortConfig* sc = nullptr);
+    bool store(const snort::SfIp&, const struct SnortConfig* = nullptr);
 
     std::list<snort::SfIp>& get_aux_ip_list()
     { return aux_ip_fifo; }
index 41c65b94ce3d644d0e806875a38bbb2afe490f68..9f44655846ba6e728ce2d5d1474f641715803806 100644 (file)
@@ -24,8 +24,8 @@
 
 #include <cassert>
 
-#include "framework/bits.h"
-#include "main/thread.h"
+#include "main/snort_types.h"
+#include "utils/bits.h"
 
 //-------------------------------------------------------------------------
 
index 284c0dfd87a952cc3a763683000d1ed68c48b8d6..0849efdaca7bef8c12ce30666f3061d8c2bdbb1b 100644 (file)
@@ -24,7 +24,6 @@
 #include <sys/time.h>
 
 #include "framework/module.h"
-#include "main/thread.h"
 
 #define HA_NAME "high_availability"
 #define HA_HELP "implement flow tracking high availability"
index ac31e9742236235ea3fa30555c10548d4636df9f..388c20b06e1c4d874850803d447b005502f95306 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef STASH_ITEM_H
 #define STASH_ITEM_H
 
+// stored in the FlowStash
+
 #include <cstdint>
 #include <string>
 
diff --git a/src/flow/stream_flow.h b/src/flow/stream_flow.h
new file mode 100644 (file)
index 0000000..3560ddb
--- /dev/null
@@ -0,0 +1,49 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2024 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.
+//--------------------------------------------------------------------------
+
+// stream_flow.h author Abhijit Pal <abhpal@cisco.com>
+
+#ifndef STREAM_FLOW_H
+#define STREAM_FLOW_H
+
+// for munged services like http2
+
+#include "network_inspectors/appid/application_ids.h"
+
+namespace snort
+{
+class Flow;
+class FlowData;
+
+class SO_PUBLIC StreamFlowIntf
+{
+public:
+    virtual FlowData* get_stream_flow_data(const Flow*) = 0;
+    virtual void set_stream_flow_data(Flow*, FlowData*) = 0;
+    virtual void get_stream_id(const Flow*, int64_t& stream_id) = 0;
+    virtual void* get_hi_msg_section(const Flow*) = 0;
+    virtual void set_hi_msg_section(Flow*, void* section) = 0;
+    virtual AppId get_appid_from_stream(const Flow*) { return APP_ID_NONE; }
+    // Stream based flows should override this interface to return parent flow
+    // when child flow is passed as input
+    virtual Flow* get_stream_parent_flow(Flow* cflow) { return cflow; }
+};
+
+}
+#endif
+
index 8425a2fe449e86c3c73c7a0fd841691f96b6a234..4ebbd223f7b88f748266e98181251e87a42031a3 100644 (file)
 #include "main/analyzer.h"
 #include "main/thread_config.h"
 #include "managers/inspector_manager.h"
+#include "main/policy.h"
+#include "main/snort_config.h"
+#include "main/thread_config.h"
 #include "packet_io/active.h"
+#include "packet_io/packet_tracer.h"
 #include "protocols/icmp4.h"
 #include "protocols/tcp.h"
 #include "protocols/udp.h"
 
 using namespace snort;
 
-THREAD_LOCAL bool Active::s_suspend = false;
-THREAD_LOCAL Active::ActiveSuspendReason Active::s_suspend_reason = Active::ASP_NONE;
-
 THREAD_LOCAL const Trace* stream_trace = nullptr;
 THREAD_LOCAL FlowControl* flow_con = nullptr;
 
-void Active::drop_packet(snort::Packet const*, bool) { }
 Analyzer* Analyzer::get_local_analyzer() { return nullptr; }
 void Analyzer::resume(uint64_t) { }
+
+void Active::drop_packet(snort::Packet const*, bool) { }
+void Active::suspend(ActiveSuspendReason) { }
+void Active::resume() { }
 void Active::set_drop_reason(char const*) { }
-ExpectCache::ExpectCache(uint32_t) { }
-ExpectCache::~ExpectCache() = default;
-bool ExpectCache::check(Packet*, Flow*) { return true; }
+
+DetectionEngine::DetectionEngine() = default;
+DetectionEngine::~DetectionEngine() = default;
 void DetectionEngine::disable_all(Packet*) { }
+
+const SnortConfig* SnortConfig::get_conf() { return nullptr; }
+
 Flow* HighAvailabilityManager::import(Packet&, FlowKey&) { return nullptr; }
 bool HighAvailabilityManager::in_standby(Flow*) { return false; }
-SfIpRet SfIp::set(void const*, int) { return SFIP_SUCCESS; }
-const SnortConfig* SnortConfig::get_conf() { return nullptr; }
+
 uint8_t TraceApi::get_constraints_generation() { return 0; }
 void TraceApi::filter(const Packet&) {}
+
 void ThreadConfig::preemptive_kick() {}
+unsigned ThreadConfig::get_instance_max() { return 0; }
+
+SfIpRet SfIp::set(void const*, int) { return SFIP_SUCCESS; }
 SfIpRet SfIp::set(void const*) { return SFIP_SUCCESS; }
 SfIpRet SfIp::pton(const int, const char* ) { return SFIP_SUCCESS; }
+
 const char* SfIp::ntop(char* buf, int) const
 { buf[0] = 0; return buf; }
-unsigned ThreadConfig::get_instance_max() { return 0; }
+
 bool ControlConn::respond(const char*, ...) { return true; }
+
 class TcpStreamTracker;
 const char* stream_tcp_state_to_str(const TcpStreamTracker&) { return "error"; }
+
 void LogMessage(const char*, ...) { }
+
 namespace snort
 {
 Flow::~Flow() = default;
@@ -104,6 +118,11 @@ uint32_t IpApi::id() const { return 0; }
 }
 }
 
+ExpectCache::ExpectCache(uint32_t) { }
+ExpectCache::~ExpectCache() = default;
+
+bool ExpectCache::check(Packet*, Flow*) { return true; }
+
 int ExpectCache::add_flow(const Packet*, PktType, IpProtocol, const SfIp*, uint16_t,
     const SfIp*, uint16_t, char, FlowData*, SnortProtocolId, bool, bool, bool, bool)
 {
index abcc797b37e56d4535c91284364dba19e97fea0f..98501336d49734a8c49b3498e6713114de9cdbd8 100644 (file)
@@ -29,9 +29,8 @@
 #include "detection/detection_engine.h"
 #include "main/policy.h"
 #include "main/snort_config.h"
-#include "managers/inspector_manager.h"
 #include "packet_io/active.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "protocols/icmp4.h"
 #include "protocols/packet.h"
 #include "protocols/tcp.h"
 
 using namespace snort;
 
-THREAD_LOCAL bool Active::s_suspend = false;
-THREAD_LOCAL Active::ActiveSuspendReason Active::s_suspend_reason = Active::ASP_NONE;
-
 void Active::drop_packet(snort::Packet const*, bool) { }
+void Active::suspend(ActiveSuspendReason) { }
+void Active::resume() { }
 void Active::set_drop_reason(char const*) { }
 FlowCache::FlowCache(const FlowCacheConfig& cfg) : config(cfg) { }
 FlowCache::~FlowCache() = default;
 Flow::~Flow() = default;
 DetectionEngine::DetectionEngine() { context = nullptr; }
 DetectionEngine::~DetectionEngine() = default;
-ExpectCache::~ExpectCache() = default;
 unsigned FlowCache::purge() { return 1; }
 unsigned FlowCache::get_flows_allocated() const { return 0; }
 Flow* FlowCache::find(const FlowKey*) { return nullptr; }
@@ -83,6 +80,7 @@ void Flow::set_direction(Packet*) { }
 void Flow::set_mpls_layer_per_dir(Packet*) { }
 void DetectionEngine::disable_all(Packet*) { }
 ExpectCache::ExpectCache(uint32_t) { }
+ExpectCache::~ExpectCache() = default;
 bool ExpectCache::check(Packet*, Flow*) { return true; }
 Flow* HighAvailabilityManager::import(Packet&, FlowKey&) { return nullptr; }
 
index b9071c999124a0f577dcbc35907f75a70c28377c..5c915bf53e8ce88b2a024b2d55e7b4cd3f350ea8 100644 (file)
@@ -25,6 +25,7 @@
 #include <string>
 
 #include "flow/flow_stash.h"
+#include "main/snort_config.h"
 #include "pub_sub/stash_events.h"
 #include "utils/util.h"
 
index b8d40ef733ae615b2d74e32d411e2efb8721a9f2..d544d3e3dbcb46b6e98b979eeb02392ded4683ea 100644 (file)
@@ -25,7 +25,7 @@
 #include "main/policy.h"
 #include "main/snort_config.h"
 #include "main/thread_config.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "protocols/layer.h"
 #include "protocols/packet.h"
 #include "stream/stream.h"
@@ -48,7 +48,7 @@ Packet::Packet(bool)
 Packet::~Packet()  = default;
 uint32_t Packet::get_flow_geneve_vni() const { return 0; }
 
-THREAD_LOCAL PacketTracer* s_pkt_trace = nullptr;
+THREAD_LOCAL PacketTracer* PacketTracer::s_pkt_trace = nullptr;
 
 PacketTracer::~PacketTracer() = default;
 void PacketTracer::log(const char*, ...) { }
index db2db7e33c6b828371289a495b128df69feca302..e58fb401dfc143a04a5a4092d80dfe30dbffc29c 100644 (file)
@@ -2,8 +2,8 @@ add_subdirectory(test)
 
 set (FRAMEWORK_INCLUDES
     base_api.h
-    bits.h
     codec.h
+    connector.h
     counts.h
     cursor.h
     data_bus.h
@@ -13,30 +13,32 @@ set (FRAMEWORK_INCLUDES
     ips_action.h
     ips_option.h
     logger.h
-    lua_api.h
     module.h
     mpse.h
     mpse_batch.h
-    packet_constraints.h
     parameter.h
+    pig_pen.h
     pdu_section.h
     policy_selector.h
+    plugins.h
     range.h
     so_rule.h
     value.h
-    connector.h
 )
 
 add_library ( framework OBJECT
     ${FRAMEWORK_INCLUDES}
+    act_info.h
     codec.cc
     cursor.cc
     data_bus.cc
-    file_policy.cc
     inspector.cc
+    ips_info.h
+    ips_action.cc
     ips_option.cc
-    packet_constraints.cc
+    lua_api.h
     parameter.cc
+    pig_pen.cc
     module.cc
     mpse.cc
     mpse_batch.cc
@@ -44,7 +46,9 @@ add_library ( framework OBJECT
     value.cc
 )
 
-install (FILES ${FRAMEWORK_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}/api_options.h
+install (FILES ${FRAMEWORK_INCLUDES}
+    ${CMAKE_CURRENT_BINARY_DIR}/api_options.h
+    ${CMAKE_CURRENT_BINARY_DIR}/snort_api.h
     DESTINATION "${INCLUDE_INSTALL_PATH}/framework"
 )
 
@@ -56,10 +60,23 @@ add_custom_command(
 
 add_custom_target(api_options ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/api_options.h)
 
+add_custom_command(
+    OUTPUT
+        ${CMAKE_CURRENT_BINARY_DIR}/snort_api.h
+    COMMAND
+        ${CMAKE_CURRENT_SOURCE_DIR}/plug_gen.sh ${CMAKE_CXX_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} > ${CMAKE_CURRENT_BINARY_DIR}/snort_api.h
+    DEPENDS
+        ${CMAKE_CURRENT_SOURCE_DIR}/plug_gen.sh
+        ${CMAKE_CURRENT_SOURCE_DIR}/plugins.h
+        ${CMAKE_CURRENT_BINARY_DIR}/api_options.h
+)
+
+add_custom_target(snort_api ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/snort_api.h)
+
 set_property(
     DIRECTORY
     PROPERTY
-    ADDITIONAL_MAKE_CLEAN_FILES api_options.h
+    ADDITIONAL_MAKE_CLEAN_FILES api_options.h snort_api.h
 )
 
 add_catch_test( parameter_test
similarity index 61%
rename from src/actions/actions.h
rename to src/framework/act_info.h
index 31c7f0ee6f252d9d568fffbedca1d04b76357795..03c8a8c5b12e65bde7de49f8a666fde02ea405cc 100644 (file)
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
+// act_info.h author Russ Combs <rucombs@cisco.com>
 
-#ifndef ACTIONS_H
-#define ACTIONS_H
+#ifndef ACT_INFO_H
+#define ACT_INFO_H
 
-// Define action types and provide hooks to apply a given action to a packet
-
-#include <cstdint>
-#include <string>
-
-#include "main/snort_types.h"
-
-struct OptTreeNode;
+// enables keeping OTN private
 
 namespace snort
 {
-struct Packet;
-}
+    class IpsAction;
+};
 
-class SO_PUBLIC Actions
+class ActInfo
 {
 public:
-    using Type = uint8_t;
-public:
-    static std::string get_string(Type);
-    static Type get_type(const char*);
-    static Type get_max_types();
-    static bool is_valid_action(Type);
-    static std::string get_default_priorities(bool alert_before_pass = false);
-
-    static void pass();
-    static void log(snort::Packet*, const OptTreeNode*);
-    static void alert(snort::Packet*, const OptTreeNode*);
+    ActInfo(const OptTreeNode* o, bool b = true)
+    { otn = o; log = b; }
+
+private:
+    friend class snort::IpsAction;
+
+    const struct OptTreeNode* otn;
+    bool log;
 };
+
 #endif
 
index d50853ef2076c6ecbfdfb27f098a41dce66bd7b1..09be4cb201cf7dde911eac319df888bce1d9516d 100644 (file)
 
 #include <cstdint>
 
-// this is the current version of the base api
-// must be prefixed to subtype version
-#define BASE_API_VERSION 19
-
 // set options to API_OPTIONS to ensure compatibility
 #ifndef API_OPTIONS
 #include "framework/api_options.h"
 #endif
 
+// the current version of the Snort API
+// must be prefixed to subtype version
+
+// depends on includes installed in framework/snort_api.h
+// see framework/plugins.h
+
+#define BASE_API_VERSION 20
+
 // set the reserved field to this to be future proof
 #define API_RESERVED 0
 
@@ -64,14 +68,14 @@ typedef void (* ModDelFunc)(Module*);
 struct BaseApi
 {
     PlugType type;
-    uint32_t size;
-    uint32_t api_version;
-    uint32_t version;
-    uint64_t reserved;
-    const char* options;
-    const char* name;
-    const char* help;
-    snort::ModNewFunc mod_ctor;
+    uint32_t size;          // sizeof(plugin-api)
+    uint32_t api_version;   // (BASE_API_VERSION << 16) | plugin-api-version)
+    uint32_t version;       // version of plugin
+    uint64_t reserved;      // zero
+    const char* options;    // API_OPTIONS
+    const char* name;       // plugin name
+    const char* help;       // short help text
+    ModNewFunc mod_ctor;
     ModDelFunc mod_dtor;
 };
 }
index ab76c8ab17032e258607a145c10f86b94a76d003..04f4b04d919822b29b6c3eaa8fdb2bd459cabb7b 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "codecs/codec_module.h"
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 
 #ifdef UNIT_TEST
 #include "catch/snort_catch.h"
index b4dc26ada8dc450b237e1f795f9c2b0e06584aee..d9f2bd777354b3ec1457b44c7e74e86cb995d1d1 100644 (file)
@@ -23,6 +23,9 @@
 // Codec is a type of plugin that provides protocol-specific encoding and
 // decoding.
 
+// the CDAPI_VERSION will change if anything in this file changes.
+// see also framework/base_api.h.
+
 #include <cstdint>
 #include <vector>
 
@@ -38,22 +41,10 @@ namespace snort
 {
 enum CodecSid : uint32_t;
 
-namespace ip
-{
-class IpApi;
-}
-namespace tcp
-{
-struct TCPHdr;
-}
-namespace udp
-{
-struct UDPHdr;
-}
-namespace icmp
-{
-struct ICMPHdr;
-}
+namespace ip { class IpApi; }
+namespace tcp { struct TCPHdr; }
+namespace udp { struct UDPHdr; }
+namespace icmp { struct ICMPHdr; }
 
 class Flow;
 
@@ -384,7 +375,7 @@ private:
 //-------------------------------------------------------------------------
 
 // this is the current version of the api
-#define CDAPI_VERSION ((BASE_API_VERSION << 16) | 1)
+#define CDAPI_VERSION ((BASE_API_VERSION << 16) | 2)
 
 typedef Codec* (* CdNewFunc)(Module*);
 typedef void (* CdDelFunc)(Codec*);
@@ -406,5 +397,5 @@ struct CodecApi
     CdDelFunc dtor;   // clean up instance data
 };
 }
-#endif /* FRAMEWORK_CODEC_H */
+#endif
 
index a4bd2886a1d07ceb91c1fe7bc65a496885584a21..3a03c388f6e975c79905b2227943834ded5ffbff 100644 (file)
@@ -23,6 +23,9 @@
 // Connector provides out-of-band communications among packet processing
 // threads, high-availability partners, and other threads.
 
+// the CONNECTOR_API_VERSION will change if anything in this file changes.
+// see also framework/base_api.h.
+
 #include <string>
 #include <vector>
 
@@ -32,7 +35,7 @@
 namespace snort
 {
 // this is the current version of the api
-#define CONNECTOR_API_VERSION ((BASE_API_VERSION << 16) | 0)
+#define CONNECTOR_API_VERSION ((BASE_API_VERSION << 16) | 1)
 
 //-------------------------------------------------------------------------
 // api for class
@@ -40,7 +43,6 @@ namespace snort
 // other methods are packet thread specific
 //-------------------------------------------------------------------------
 
-struct ConnectorApi;
 class ConnectorConfig;
 
 struct ConnectorMsg
index a67a2b78279ec085538688db5921223bece06c44..31763d8627f4682a7df7b29187a07563bf850593 100644 (file)
@@ -32,9 +32,9 @@ typedef uint64_t PegCount;
 enum CountType
 {
     END,   // sentinel value
-    SUM,   // tracks cumulative total number of items seen (eg #events)
-    NOW,   // gives snapshot of current number of items (eg current #sessions)
-    MAX,   // tracks maximum value seen (eg max #sessions)
+    SUM,   // running total: tracks cumulative total number of items seen (eg #events)
+    NOW,   // current level: gives snapshot of current number of items (eg current #sessions)
+    MAX,   // maximum level: tracks maximum value seen (eg max #sessions)
 };
 
 struct SimpleStats
index ca70efbb7a1e9eb336c69c362d638c47770554af..948fc7c8c65dc64cecba4644ff1dba218aa23d3e 100644 (file)
@@ -25,8 +25,8 @@
 
 #include "cursor.h"
 
+#include "detection/detection_buf.h"
 #include "detection/detection_engine.h"
-#include "detection/detection_util.h"
 #include "protocols/packet.h"
 #include "detection/ips_context.h"
 
index 39e55e5b3129081334df7f04516ea6221701ca83..7fe3e0a9f85b010db22b936d7f9ab91e0c5fd464 100644 (file)
@@ -22,8 +22,8 @@
 #ifndef CURSOR_H
 #define CURSOR_H
 
-// Cursor provides a formal way of using buffers when doing detection with
-// IpsOptions.
+// Cursor provides access to the current buffer pointer used by IpsOptions
+// during signature evaluation.
 
 #include <assert.h>
 #include <cstdint>
index 957433137ccabfcae237e91e2a4067dd94e15192..8088f71e3025a78211d27ab98cce5a90c77e0fd0 100644 (file)
@@ -25,7 +25,7 @@
 
 namespace snort
 {
-class SO_PUBLIC Endianness
+class Endianness
 {
 public:
     Endianness() = default;
index dc4466797c96152b7aa21c083378f5fff3efed80..f3eed842786e822f867e004f64926535f3d44803 100644 (file)
@@ -42,12 +42,14 @@ public:
 
 using namespace snort;
 
+#ifndef _WIN64
+unsigned THREAD_LOCAL Inspector::slot = 0;
+#endif
+
 //-------------------------------------------------------------------------
 // packet handler stuff
 //-------------------------------------------------------------------------
 
-unsigned THREAD_LOCAL Inspector::slot = 0;
-
 Inspector::Inspector()
 {
     unsigned max = ThreadConfig::get_instance_max();
@@ -120,10 +122,10 @@ bool Inspector::likes(Packet* p)
 }
 
 void Inspector::add_ref()
-{ ++ref_count[slot]; }
+{ ++ref_count[get_slot()]; }
 
 void Inspector::rem_ref()
-{ --ref_count[slot]; }
+{ --ref_count[get_slot()]; }
 
 void Inspector::add_global_ref()
 { ++ref_count[0]; }
@@ -145,10 +147,10 @@ void Inspector::copy_thread_storage(Inspector* ins)
 }
 
 void Inspector::set_thread_specific_data(void* tsd)
-{ thread_specific_data->data[slot] = tsd; }
+{ thread_specific_data->data[get_slot()] = tsd; }
 
 void* Inspector::get_thread_specific_data() const
-{ return thread_specific_data->data[slot]; }
+{ return thread_specific_data->data[get_slot()]; }
 
 static const char* InspectorTypeNames[IT_MAX] =
 {
index 7c36ad64170b35ff2a7622cd1577221865d64e6d..b446a24987e106c582ef29fbc3ec84514590a3f8 100644 (file)
 // decoding a packet and detection.  There are several types that operate
 // in different ways.  These correspond to Snort 2X preprocessors.
 
+// the INSAPI_VERSION will change if anything in this file changes.
+// see also framework/base_api.h.
+
 #include <atomic>
 #include <cstring>
 #include <memory>
 #include <vector>
 
 #include "framework/base_api.h"
-#include "main/thread.h"
 #include "target_based/snort_protocols.h"
 
 class Session;
@@ -41,7 +43,7 @@ struct SnortConfig;
 struct Packet;
 
 // this is the current version of the api
-#define INSAPI_VERSION ((BASE_API_VERSION << 16) | 0)
+#define INSAPI_VERSION ((BASE_API_VERSION << 16) | 1)
 
 struct InspectionBuffer
 {
@@ -109,7 +111,7 @@ public:
     // clear is a bookend to eval() for the active service inspector
     // clear is called when Snort is done with the previously eval'd
     // packet to release any thread-local or flow-based data
-    virtual void eval(Packet*) = 0;
+    virtual void eval(Packet*) { }
     virtual void clear(Packet*) { }
 
     // framework support
@@ -199,8 +201,12 @@ public:
     virtual const uint8_t* adjust_log_packet(Packet*, uint16_t&)
     { return nullptr; }
 
-public:
-    static THREAD_LOCAL unsigned slot;
+    static unsigned get_slot()
+#ifndef _WIN64
+    { return slot; }
+#else
+    { return get_instance_id(); }
+#endif
 
 protected:
     // main thread functions
@@ -215,6 +221,12 @@ private:
     const char* alias_name = nullptr;
     uint64_t network_policy_user_id = 0;
     bool network_policy_user_id_set = false;
+
+#ifndef _WIN64
+private:
+    friend class InspectorManager;
+    static THREAD_LOCAL unsigned slot;
+#endif
 };
 
 // at present there is no sequencing among like types except that appid
diff --git a/src/framework/ips_action.cc b/src/framework/ips_action.cc
new file mode 100644 (file)
index 0000000..d735c36
--- /dev/null
@@ -0,0 +1,100 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2024-2024 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.
+//--------------------------------------------------------------------------
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "ips_action.h"
+
+#include "detection/detect.h"
+#include "detection/treenodes.h"
+#include "managers/action_manager.h"
+#include "parser/parser.h"
+#include "utils/stats.h"
+
+#include "act_info.h"
+
+using namespace snort;
+
+namespace snort
+{
+
+std::string IpsAction::get_string(IpsAction::Type action)
+{ return ActionManager::get_action_string(action); }
+
+IpsAction::Type IpsAction::get_type(const char* s)
+{ return ActionManager::get_action_type(s); }
+
+IpsAction::Type IpsAction::get_max_types()
+{ return ActionManager::get_max_action_types(); }
+
+bool IpsAction::is_valid_action(IpsAction::Type action)
+{
+    if ( action < get_max_types() )
+        return true;
+
+    return false;
+}
+
+std::string IpsAction::get_default_priorities(bool alert_before_pass)
+{ return ActionManager::get_action_priorities(alert_before_pass); }
+
+bool IpsAction::log_it(const ActInfo& ai) const
+{ return ai.log; }
+
+uint64_t IpsAction::get_file_id(const ActInfo& ai) const
+{ return ai.otn->sigInfo.file_id; }
+
+void IpsAction::pass()
+{
+    pc.pass_pkts++;
+}
+
+void IpsAction::log(Packet* p, const ActInfo& ai)
+{
+    RuleTreeNode* rtn = getRtnFromOtn(ai.otn);
+
+    if (!rtn)
+        return;
+
+    CallLogFuncs(p, ai.otn, rtn->listhead);
+}
+
+void IpsAction::alert(Packet* p, const ActInfo& ai)
+{
+    if (!ai.otn or !log_it(ai))
+        return;
+
+    RuleTreeNode* rtn = getRtnFromOtn(ai.otn);
+    if (!rtn)
+        return;
+
+    /* Call OptTreeNode specific output functions */
+    if (ai.otn->outputFuncs)
+    {
+        ListHead lh = { };  // FIXIT-L use of ListHead for CallLogFuncs() is a little unwieldy here
+        lh.LogList = ai.otn->outputFuncs;
+        CallLogFuncs(p, ai.otn, &lh);
+    }
+    CallAlertFuncs(p, ai.otn, rtn->listhead);
+    CallLogFuncs(p, ai.otn, rtn->listhead);
+}
+
+} // snort
+
index ddf2d753f453cd9612572ffcf6e78762b5153281..f74adc1e14e7fbd4449018f9ff9650653fa5d333 100644 (file)
 // These can be used to execute external controls like updating an external
 // firewall.
 
+// the ACTAPI_VERSION will change if anything in this file changes.
+// see also framework/base_api.h.
+
+#include <cstdint>
+#include <string>
+
 #include "framework/base_api.h"
 #include "main/snort_types.h"
 #include "packet_io/active_action.h"
 
 // this is the current version of the api
-#define ACTAPI_VERSION ((BASE_API_VERSION << 16) | 1)
+#define ACTAPI_VERSION ((BASE_API_VERSION << 16) | 2)
 
 //-------------------------------------------------------------------------
 // api for class
 //-------------------------------------------------------------------------
 
-struct OptTreeNode;
+class ActInfo;
+
 namespace snort
 {
 struct Packet;
@@ -44,6 +51,8 @@ struct Packet;
 class SO_PUBLIC IpsAction
 {
 public:
+    using Type = uint8_t;
+
     enum IpsActionPriority : uint16_t
     {
         IAP_OTHER = 1,
@@ -62,9 +71,22 @@ public:
     const char* get_name() const { return name; }
     ActiveAction* get_active_action() const { return active_action; }
 
-    virtual void exec(Packet*, const OptTreeNode* otn = nullptr) = 0;
+    virtual void exec(Packet*, const ActInfo&) = 0;
     virtual bool drops_traffic() { return false; }
 
+    static std::string get_string(Type);
+    static Type get_type(const char*);
+    static Type get_max_types();
+    static bool is_valid_action(Type);
+    static std::string get_default_priorities(bool alert_before_pass = false);
+
+    bool log_it(const ActInfo&) const;
+    uint64_t get_file_id(const ActInfo&) const;
+
+    void pass();
+    void log(snort::Packet*, const ActInfo&);
+    void alert(snort::Packet*, const ActInfo&);
+
 protected:
     IpsAction(const char* s, ActiveAction* a)
     {
diff --git a/src/framework/ips_info.h b/src/framework/ips_info.h
new file mode 100644 (file)
index 0000000..00266eb
--- /dev/null
@@ -0,0 +1,47 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2024-2024 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.
+//--------------------------------------------------------------------------
+// ips_info.h author Russ Combs <rucombs@cisco.com>
+
+#ifndef IPS_INFO_H
+#define IPS_INFO_H
+
+// enables keeping OTN private
+
+namespace snort
+{
+    struct SnortConfig;
+    class IpsOption;
+};
+
+struct OptTreeNode;
+
+struct IpsInfo
+{
+public:
+    IpsInfo(OptTreeNode* o, snort::SnortConfig* s)
+    { otn = o; sc = s; }
+
+private:
+    friend class snort::IpsOption;
+
+    OptTreeNode* otn;
+    snort::SnortConfig* sc;
+};
+
+#endif
+
index d20c75b8188b8d080b4348a6af556a3064b2b1aa..6c79eebe9f38eac39a14b37398ed8d37de8e0cab 100644 (file)
 
 #include <cstring>
 
+#include "detection/rules.h"
+#include "detection/signature.h"
+#include "detection/treenodes.h"
+#include "filters/detection_filter.h"
+#include "filters/sfthd.h"
+#include "framework/ips_info.h"
 #include "hash/hash_key_operations.h"
+#include "main/snort_config.h"
+#include "managers/so_manager.h"
+#include "parser/parse_conf.h"
+#include "utils/util.h"
 
 using namespace snort;
 
+namespace snort
+{
 //-------------------------------------------------------------------------
 
 IpsOption::IpsOption(const char* s, option_type_t t)
@@ -55,6 +67,120 @@ section_flags IpsOption::get_pdu_section(bool) const
     return section_to_flag(PS_NONE);
 }
 
+//-------------------------------------------------------------------------
+// static / instantiator methods
+//-------------------------------------------------------------------------
+
+bool IpsOption::has_plugin(IpsInfo& info, const char* name)
+{ return otn_has_plugin(info.otn, name); }
+
+void IpsOption::set_priority(const IpsInfo& info, uint32_t pri)
+{ info.otn->sigInfo.priority = pri; }
+
+void IpsOption::set_classtype(IpsInfo& info, const char* type)
+{
+    const ClassType* ct = get_classification(info.sc, type);
+
+    if ( !ct and info.sc->dump_rule_info() )
+    {
+        add_classification(info.sc, type, type, 1);
+        ct = get_classification(info.sc, type);
+    }
+
+    info.otn->sigInfo.class_type = ct;
+
+    if ( ct )
+    {
+        info.otn->sigInfo.class_id = ct->id;
+        info.otn->sigInfo.priority = ct->priority;
+    }
+}
+
+void IpsOption::set_detection_filter(IpsInfo& info, bool track_src, uint32_t count, uint32_t seconds)
+{
+    THDX_STRUCT thdx = { };
+    thdx.type = THD_TYPE_DETECT;
+    thdx.tracking = (track_src ? THD_TRK_SRC : THD_TRK_DST);
+    thdx.count = count;
+    thdx.seconds = seconds;
+    info.otn->detection_filter = detection_filter_create(info.sc->detection_filter_config, &thdx);
+}
+
+void IpsOption::set_enabled(IpsInfo& info, Enable ie)
+{
+    if ( !info.sc->rule_states )
+        info.sc->rule_states = new RuleStateMap;
+
+    IpsPolicy::Enable e;
+
+    switch (ie)
+    {
+        case IpsOption::NO: e = IpsPolicy::DISABLED; break;
+        case IpsOption::INHERIT: e = IpsPolicy::INHERIT_ENABLE; break;
+        default: e = IpsPolicy::ENABLED; break;
+    }
+    info.otn->set_enabled(e);
+}
+
+void IpsOption::set_file_id(const IpsInfo& info, uint64_t fid)
+{ info.otn->sigInfo.file_id = fid; }
+
+void IpsOption::set_flowbits_check(IpsInfo& info)
+{ info.otn->set_flowbits_check(); }
+
+void IpsOption::set_stateless(IpsInfo& info)
+{ info.otn->set_stateless(); }
+
+void IpsOption::set_to_client(IpsInfo& info)
+{ info.otn->set_to_client(); }
+
+void IpsOption::set_to_server(IpsInfo& info)
+{ info.otn->set_to_server(); }
+
+void IpsOption::set_gid(const IpsInfo& info, uint32_t gid)
+{ info.otn->sigInfo.gid = gid; }
+
+void IpsOption::set_sid(const IpsInfo& info, uint32_t sid)
+{ info.otn->sigInfo.sid = sid; }
+
+void IpsOption::set_rev(const IpsInfo& info, uint32_t rev)
+{ info.otn->sigInfo.rev = rev; }
+
+void IpsOption::set_message(const IpsInfo& info, const char* msg)
+{ info.otn->sigInfo.message = msg; }
+
+void IpsOption::set_metadata_match(IpsInfo& info)
+{ info.otn->set_metadata_match(); }
+
+void IpsOption::set_tag(IpsInfo& info, TagData* td)
+{ info.otn->tag = td; }
+
+void IpsOption::set_target(const IpsInfo& info, bool src_ip)
+{ info.otn->sigInfo.target = (src_ip ? TARGET_SRC : TARGET_DST); }
+
+void IpsOption::add_reference(IpsInfo& info, const char* scheme, const char* id)
+{ ::add_reference(info.sc, info.otn, scheme, id); }
+
+void IpsOption::add_service(IpsInfo& info, const char* svc)
+{ add_service_to_otn(info.sc, info.otn, svc); }
+
+void IpsOption::set_soid(IpsInfo& info, const char* s)
+{ info.otn->soid = snort_strdup(s); }
+
+const char* IpsOption::get_soid(const IpsInfo& info)
+{ return info.otn->soid; }
+
+IpsOption::SoEvalFunc IpsOption::get_so_eval(IpsInfo& info, const char* name, void*& data)
+{ return SoManager::get_so_eval(info.otn->soid, name, &data, info.sc); }
+
+SnortProtocolId IpsOption::get_protocol_id(const IpsInfo& info)
+{ return info.otn->snort_protocol_id; }
+
+SoRules* IpsOption::get_so_rules(const IpsInfo& info)
+{ return info.sc->so_rules; }
+
+} // snort
+
 //-------------------------------------------------------------------------
 // UNIT TESTS
 //-------------------------------------------------------------------------
@@ -74,11 +200,6 @@ TEST_CASE("IpsOption test", "[ips_option]")
     StubIpsOption main_ips("ips_test",
         option_type_t::RULE_OPTION_TYPE_OTHER);
 
-    SECTION("buffer test")
-    {
-        REQUIRE(main_ips.get_buffer());  // only until api is updated
-    }
-
     SECTION("IpsOperator == test")
     {
         StubIpsOption case_diff_name("not_hello_world",
index 76499f337a00073b4240bafaad28dbc42f9995ee..1543f0ecf4fc4894f1932dcc85798383b5f521d2 100644 (file)
@@ -15,7 +15,7 @@
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
-// ips_manager.h author Russ Combs <rucombs@cisco.com>
+// ips_option.h author Russ Combs <rucombs@cisco.com>
 
 #ifndef IPS_OPTION_H
 #define IPS_OPTION_H
 // All IPS rule keywords are realized as IpsOptions instantiated when rules
 // are parsed.
 
+// the IPSAPI_VERSION will change if anything in this file changes.
+// see also framework/base_api.h.
+
+#include <cinttypes>
+
 #include "detection/rule_option_types.h"
 #include "framework/base_api.h"
+#include "framework/cursor.h"
+#include "framework/pdu_section.h"
 #include "main/snort_types.h"
 #include "target_based/snort_protocols.h"
 
-#include "pdu_section.h"
-
 //-------------------------------------------------------------------------
 // api for class
 // eval and action are packet thread specific
 //-------------------------------------------------------------------------
 
 class Cursor;
-struct OptTreeNode;
+struct IpsInfo;
 struct PatternMatchData;
+struct TagData;
+struct SoRules;
 
 namespace snort
 {
@@ -46,7 +53,7 @@ struct SnortConfig;
 class Module;
 
 // this is the current version of the api
-#define IPSAPI_VERSION ((BASE_API_VERSION << 16) | 0)
+#define IPSAPI_VERSION ((BASE_API_VERSION << 16) | 1)
 
 enum CursorActionType
 {
@@ -82,8 +89,7 @@ public:
     // packet threads
     virtual bool is_relative() { return false; }
 
-    // 2nd cursor is deprecated, do not use
-    virtual bool retry(Cursor&, const Cursor&) { return false; }
+    virtual bool retry(Cursor&) { return false; }
     virtual void action(Packet*) { }
 
     enum EvalStatus { NO_MATCH, MATCH, NO_ALERT, FAILED_BIT };
@@ -105,17 +111,54 @@ public:
     bool is_buffer_setter() const
     { return get_cursor_type() > CAT_ADJUST; }
 
-    const char* get_buffer()
-    { return buffer; }
-
     virtual section_flags get_pdu_section(bool to_server) const;
 
+    // these methods are only available to the instantiator method (IpsNewFunc)
+    static bool has_plugin(IpsInfo&, const char* name);
+
+    static void set_priority(const IpsInfo&, uint32_t);
+    static void set_classtype(IpsInfo&, const char*);
+    static void set_reference(IpsInfo&, const char* scheme, const char* id);
+
+    enum Enable { NO, YES, INHERIT };
+    static void set_enabled(IpsInfo&, Enable);
+
+    static void set_flowbits_check(IpsInfo&);
+    static void set_detection_filter(IpsInfo&, bool track_src, uint32_t count, uint32_t seconds); // don't install header
+
+    static void set_stateless(IpsInfo&);
+    static void set_to_client(IpsInfo&);
+    static void set_to_server(IpsInfo&);
+
+    static void set_gid(const IpsInfo&, uint32_t);
+    static void set_sid(const IpsInfo&, uint32_t);
+    static void set_rev(const IpsInfo&, uint32_t);
+
+    static void set_message(const IpsInfo&, const char*);
+    static void set_metadata_match(IpsInfo&);
+
+    static void set_tag(IpsInfo&, TagData*);
+    static void set_target(const IpsInfo&, bool src_ip);
+
+    static void set_file_id(const IpsInfo&, uint64_t);
+    static void add_reference(IpsInfo&, const char*, const char*);
+    static void add_service(IpsInfo&, const char*);
+
+    static void set_soid(IpsInfo&, const char*);
+    static const char* get_soid(const IpsInfo&);
+
+    typedef snort::IpsOption::EvalStatus (* SoEvalFunc)(void*, class Cursor&, snort::Packet*);
+    static SoEvalFunc get_so_eval(IpsInfo&, const char* name, void*& data);
+
+    static SnortProtocolId get_protocol_id(const IpsInfo&);
+
+    static SoRules* get_so_rules(const IpsInfo&);
+
 protected:
     IpsOption(const char* s, option_type_t t = RULE_OPTION_TYPE_OTHER);
 
 private:
     const char* name;
-    const char* buffer = "error"; // FIXIT-API to be deleted; here to avoid an api update
     option_type_t type;
 };
 
@@ -129,7 +172,7 @@ enum RuleOptType
 
 typedef void (* IpsOptFunc)(const SnortConfig*);
 
-typedef IpsOption* (* IpsNewFunc)(Module*, OptTreeNode*);
+typedef IpsOption* (* IpsNewFunc)(Module*, IpsInfo&);
 typedef void (* IpsDelFunc)(IpsOption*);
 
 struct IpsApi
@@ -137,8 +180,8 @@ struct IpsApi
     BaseApi base;
     RuleOptType type;
 
-    unsigned max_per_rule;
-    unsigned protos;
+    unsigned max_per_rule;  // max instances of this keyword per IPS rule
+    unsigned protos;        // bitmask of PROTO_BIT_* from decode_data.h
 
     IpsOptFunc pinit;
     IpsOptFunc pterm;
index a0db8cfbeedfad8d7cb649b2758002e8753df881..233c032a0e64a49e32078b88c4fe1666c41aa01c 100644 (file)
 #ifndef LOGGER_H
 #define LOGGER_H
 
-// Logger is used to log packets and events.  Events are thresholded before
+// Logger is used to log packets and IPS events.  Events are thresholded before
 // they reach the Logger.  Packets may be logged along with events or as a
 // result of tagging.
 
+// the LOGAPI_VERSION will change if anything in this file changes.
+// see also framework/base_api.h.
+
 #include "framework/base_api.h"
 #include "main/snort_types.h"
 
-struct Event;
+class Event;
+
 namespace snort
 {
 struct Packet;
 
 // this is the current version of the api
-#define LOGAPI_VERSION ((BASE_API_VERSION << 16) | 0)
+#define LOGAPI_VERSION ((BASE_API_VERSION << 16) | 1)
 
 #define OUTPUT_TYPE_FLAG__NONE  0x0
 #define OUTPUT_TYPE_FLAG__ALERT 0x1
@@ -79,7 +83,7 @@ typedef void (* LogDelFunc)(Logger*);
 struct LogApi
 {
     BaseApi base;
-    unsigned flags;
+    unsigned flags;  // bitmask of OUTPUT_TYPE_FLAG__*
     LogNewFunc ctor;
     LogDelFunc dtor;
 };
index 08aac4f498ba4660104943f18975e0296b680dc1..607ce76e3fb8a704c51e036206e1bc1f350593d7 100644 (file)
@@ -25,6 +25,7 @@
 #include "main/thread_config.h"
 
 #include "trace/trace.h"
+#include "utils/stats.h"
 
 using namespace snort;
 
@@ -185,7 +186,7 @@ void Module::sum_stats(bool dump_stats)
     }
 }
 
-void Module::show_interval_stats(IndexVec& peg_idxs, FILE* fh)
+void Module::show_interval_stats(std::vector<unsigned>& peg_idxs, FILE* fh)
 {
     if ( num_counts > 0 )
         ::show_stats(get_counts(), get_pegs(), peg_idxs, get_name(), fh);
index f2f97bfabee2a4d094c262a05caca50353f8a459..08b640aa02aef83b437dee7241d571e838277687 100644 (file)
 //--------------------------------------------------------------------------
 // module.h author Russ Combs <rucombs@cisco.com>
 
-// FIXIT-M add trace param(s)
-// FIXIT-M add memcap related
-// FIXIT-L add set_default method
-
 #ifndef MODULE_H
 #define MODULE_H
 
@@ -46,7 +42,7 @@
 #include "framework/parameter.h"
 #include "framework/value.h"
 #include "main/snort_types.h"
-#include "utils/stats.h"
+#include "main/thread.h"
 
 struct lua_State;
 
@@ -182,8 +178,8 @@ public:
     { return false; }
 
     virtual void sum_stats(bool dump_stats);
-    virtual void show_interval_stats(IndexVec&, FILE*);
     virtual void show_stats();
+    virtual void show_interval_stats(std::vector<unsigned>&, FILE*);
     virtual void reset_stats();
     virtual void init_stats(bool new_thread=false);
     virtual void main_accumulate_stats();
@@ -195,13 +191,7 @@ public:
     bool verified_set(const char*, Value&, SnortConfig*);
     bool verified_end(const char*, int, SnortConfig*);
 
-    enum Usage
-    {
-        GLOBAL,
-        CONTEXT,
-        INSPECT,
-        DETECT
-    };
+    enum Usage { GLOBAL, CONTEXT, INSPECT, DETECT };
 
     virtual Usage get_usage() const
     { return CONTEXT; }
index 597a9f394a63bb69518336b79fa17c07a605f839..5093baa63bb5adbe7b05900b71a47746f6302c61 100644 (file)
@@ -26,7 +26,6 @@
 #include <cassert>
 
 #include "profiler/profiler_defs.h"
-#include "search_engines/pat_stats.h"
 #include "managers/mpse_manager.h"
 #include "managers/module_manager.h"
 #include "main/snort_config.h"
@@ -46,28 +45,14 @@ namespace snort
 Mpse::Mpse(const char* m) : method(m)
 { }
 
-int Mpse::search(
-    const unsigned char* T, int n, MpseMatch match,
-    void* context, int* current_state)
-{
-    pmqs.matched_bytes += n;
-    return _search(T, n, match, context, current_state);
-}
-
 int Mpse::search_all(
     const unsigned char* T, int n, MpseMatch match,
     void* context, int* current_state)
 {
-    pmqs.matched_bytes += n;
-    return _search(T, n, match, context, current_state);
+    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;
 
index ad5fea0f1cb98c8344dacf390e3ddba7e6e9f8d9..1b3f629b253db71ff0f34b3024e78282bae0b025 100644 (file)
 // machine from the patterns, and search either a single buffer or a set
 // of (related) buffers for patterns.
 
-#include <cassert>
+// the SEAPI_VERSION will change if anything in this file changes.
+// see also framework/base_api.h.
+
 #include <string>
 
 #include "framework/base_api.h"
 #include "main/snort_types.h"
-#include "main/thread.h"
 #include "search_engines/search_common.h"
+//#include "framework/mpse_batch.h"
 
 namespace snort
 {
 // this is the current version of the api
-#define SEAPI_VERSION ((BASE_API_VERSION << 16) | 0)
+#define SEAPI_VERSION ((BASE_API_VERSION << 16) | 1)
 
 struct SnortConfig;
-class Mpse;
 struct MpseApi;
 struct MpseBatch;
-struct ProfileStats;
 
 class SO_PUBLIC Mpse
 {
@@ -83,13 +83,13 @@ public:
 
     virtual void reuse_search() { }
 
-    int search(
-        const uint8_t* T, int n, MpseMatch, void* context, int* current_state);
+    virtual int search(
+        const uint8_t* T, int n, MpseMatch, void* context, int* current_state) = 0;
 
     virtual int search_all(
         const uint8_t* T, int n, MpseMatch, void* context, int* current_state);
 
-    void search(MpseBatch&, MpseType);
+    virtual void search(MpseBatch&, MpseType);
 
     virtual MpseRespType receive_responses(MpseBatch&, MpseType)
     { return MPSE_RESP_COMPLETE_SUCCESS; }
@@ -113,11 +113,6 @@ public:
 protected:
     Mpse(const char* method);
 
-    virtual int _search(
-        const uint8_t* T, int n, MpseMatch, void* context, int* current_state) = 0;
-
-    virtual void _search(MpseBatch&, MpseType);
-
 private:
     std::string method;
     int verbose = 0;
@@ -140,7 +135,7 @@ typedef Mpse::MpseRespType (* MpsePollFunc)(MpseBatch*&, Mpse::MpseType);
 struct MpseApi
 {
     BaseApi base;
-    uint32_t flags;
+    uint32_t flags;  // bitmask of MPSE_*
 
     MpseOptFunc activate;
     MpseOptFunc setup;
index 448da8a994836a21dcc6b88f811460f2fdd22b66..153ab23e3f75681cacbc450b8aeb607731149a54 100644 (file)
@@ -24,7 +24,6 @@
 #include "mpse_batch.h"
 
 #include "profiler/profiler_defs.h"
-#include "search_engines/pat_stats.h"
 #include "managers/mpse_manager.h"
 #include "managers/module_manager.h"
 #include "main/snort_config.h"
index 781d0ac19c4cb5c6a99ac8b4d275f32b88d8b6dc..47549b7a3f3928606a19a9d57343b4abfcebc2e4 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef MPSE_BATCH_H
 #define MPSE_BATCH_H
 
+#include <cassert>
 #include <unordered_map>
 #include <vector>
 
index 0226a9a3fbedcede8087a70ed4205e66bd409842..4d41da1d6c1951c776d6f5f47a853f8748587447 100644 (file)
@@ -36,8 +36,7 @@ namespace snort
 // PS_ERROR is used for invalid combination of sections:
 // trailer and body sections can be combined only if it's a request trailer in a to_client direction
 // When updating this enum, also update section_to_str
-enum PduSection { PS_NONE = 0, PS_HEADER, PS_HEADER_BODY, PS_BODY, PS_TRAILER, PS_MAX = PS_TRAILER,
-    PS_ERROR };
+enum PduSection { PS_NONE = 0, PS_HEADER, PS_HEADER_BODY, PS_BODY, PS_TRAILER, PS_MAX = PS_TRAILER, PS_ERROR };
 
 // Bitmask with all of supported sections
 using section_flags = uint16_t;
diff --git a/src/framework/pig_pen.cc b/src/framework/pig_pen.cc
new file mode 100644 (file)
index 0000000..a8b7f10
--- /dev/null
@@ -0,0 +1,103 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2024-2024 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.
+//--------------------------------------------------------------------------
+// pig_pen.cc author Russ Combs <rucombs@cisco.com>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "pig_pen.h"
+
+#include "detection/detection_engine.h"
+#include "log/log.h"
+#include "main/process.h"
+#include "main/snort.h"
+#include "managers/inspector_manager.h"
+#include "profiler/profiler_impl.h"
+#include "utils/stats.h"
+
+using namespace snort;
+
+//--------------------------------------------------------------------------
+// inspector foo
+//--------------------------------------------------------------------------
+
+Inspector* PigPen::get_binder()
+{ return InspectorManager::get_binder(); }
+
+Inspector* PigPen::get_file_inspector(const SnortConfig* sc)
+{ return InspectorManager::get_file_inspector(sc); }
+
+Inspector* PigPen::acquire_file_inspector()
+{ return InspectorManager::acquire_file_inspector(); }
+
+Inspector* PigPen::get_service_inspector(const SnortProtocolId id)
+{ return InspectorManager::get_service_inspector(id); }
+
+Inspector* PigPen::get_service_inspector(const char* svc)
+{ return InspectorManager::get_service_inspector(svc); }
+
+Inspector* PigPen::get_inspector(const char* key, bool dflt_only, const SnortConfig* sc)
+{ return InspectorManager::get_inspector(key, dflt_only, sc); }
+
+Inspector* PigPen::get_inspector(const char* key, Module::Usage use, InspectorType type)
+{ return InspectorManager::get_inspector(key, use, type); }
+
+void PigPen::release(Inspector* pi)
+{ InspectorManager::release(pi); }
+
+//--------------------------------------------------------------------------
+// process foo
+//--------------------------------------------------------------------------
+
+bool PigPen::snort_is_reloading()
+{ return Snort::is_reloading(); }
+
+void PigPen::install_oops_handler()
+{ ::install_oops_handler(); }
+
+void PigPen::remove_oops_handler()
+{ ::remove_oops_handler(); }
+
+//--------------------------------------------------------------------------
+// detection foo
+//--------------------------------------------------------------------------
+
+bool PigPen::inspect_rebuilt(Packet* pdu)
+{
+    DetectionEngine de;
+    return de.inspect(pdu);
+}
+
+//--------------------------------------------------------------------------
+// stats foo
+//--------------------------------------------------------------------------
+
+uint64_t PigPen::get_packet_number()
+{ return pc.analyzed_pkts; }
+
+void PigPen::show_runtime_memory_stats()
+{ Profiler::show_runtime_memory_stats(); }
+
+//--------------------------------------------------------------------------
+// log foo
+//--------------------------------------------------------------------------
+
+const char* PigPen::get_protocol_name(uint8_t ip_proto)
+{ return ::get_protocol_name(ip_proto); }
+
diff --git a/src/framework/pig_pen.h b/src/framework/pig_pen.h
new file mode 100644 (file)
index 0000000..2ada69f
--- /dev/null
@@ -0,0 +1,73 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2024-2024 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.
+//--------------------------------------------------------------------------
+// pig_pen.h author Russ Combs <rucombs@cisco.com>
+
+#ifndef FRAMEWORK_PIG_PEN_H
+#define FRAMEWORK_PIG_PEN_H
+
+#include "framework/inspector.h"
+#include "framework/module.h"
+#include "main/snort_types.h"
+#include "target_based/snort_protocols.h"
+
+struct PacketCount;
+
+namespace snort
+{
+struct Packet;
+
+struct SO_PUBLIC PigPen
+{
+    // inspector foo
+    static Inspector* get_binder();
+
+    static Inspector* get_file_inspector(const SnortConfig* = nullptr);
+    static Inspector* acquire_file_inspector();
+
+    static Inspector* get_service_inspector(const SnortProtocolId);
+    static Inspector* get_service_inspector(const char*);
+
+    // This assumes that, in a multi-tenant scenario, this is called with the correct network and inspection
+    // policies are set correctly
+    static Inspector* get_inspector(const char* key, bool dflt_only = false, const SnortConfig* = nullptr);
+
+    // This cannot be called in or before the inspector configure phase for a new snort config during reload
+    static Inspector* get_inspector(const char* key, Module::Usage, InspectorType);
+
+    static void release(Inspector*);
+
+    // process foo
+    static bool snort_is_reloading();
+
+    static void install_oops_handler();
+    static void remove_oops_handler();
+
+    // analyzer foo
+    static bool inspect_rebuilt(Packet*);
+
+    // stats foo
+    static uint64_t get_packet_number();
+    static void show_runtime_memory_stats();
+
+    // log foo
+    static const char* get_protocol_name(uint8_t ip_proto);
+};
+
+}
+#endif
+
diff --git a/src/framework/plug_gen.sh b/src/framework/plug_gen.sh
new file mode 100755 (executable)
index 0000000..26203a7
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+cxx=$1
+src=$2
+bin=$3
+
+plugs=framework/plugins.h
+
+cd $src/..
+
+echo "// the set of versioned headers installed by Snort"
+echo "// this file is generated automatically - do not edit"
+echo "// see framework/plugins.h for details"
+echo
+
+$cxx -MM $plugs -I. -I$bin/.. | \
+    sed -e "s/ /\n/g" | \
+    grep ".*.h$" | grep -v "$plugs" | \
+    sed -e "s/^/#include \"/" -e "s/$/\"/" -e 's/.*api_options.h.*/#include "framework\/api_options.h"/' | \
+    sort
+
diff --git a/src/framework/plugins.h b/src/framework/plugins.h
new file mode 100644 (file)
index 0000000..3694bc5
--- /dev/null
@@ -0,0 +1,49 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2024-2024 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.
+//--------------------------------------------------------------------------
+// plugins.h author Russ Combs <rucombs@cisco.com>
+
+#ifndef PLUGINS_H
+#define PLUGINS_H
+
+// top level headers required by plugins
+// used to establish base header dependencies
+
+// the base API is comprised of the set of headers installed
+// in framework/snort_api.h less these plugin specific headers
+// which have their own API versions:
+
+#include "framework/codec.h"
+#include "framework/connector.h"
+#include "framework/inspector.h"
+#include "framework/ips_action.h"
+#include "framework/ips_option.h"
+#include "framework/logger.h"
+#include "framework/mpse.h"
+#include "framework/policy_selector.h"
+#include "framework/so_rule.h"
+
+// forward decls we must explicitly include here to 
+// generate the complete set of API dependencies:
+
+#include "flow/flow.h"
+#include "framework/module.h"
+#include "framework/pig_pen.h"
+#include "protocols/packet.h"
+
+#endif
+
index 7b8777c5409f318bc2abee799e4029fba33f5425..8a0f87ef5979d9d8eb84e72e2caf3299b3d2ca40 100644 (file)
@@ -23,6 +23,9 @@
 // Policy selectors provide a method to select the network policy and default inspection
 // and IPS policies for a given packet
 
+// the POLICY_SELECTOR_API_VERSION will change if anything in this file changes.
+// see also framework/base_api.h.
+
 #include <string>
 
 #include "framework/base_api.h"
@@ -34,7 +37,7 @@ struct _daq_pkt_hdr;
 
 namespace snort
 {
-#define POLICY_SELECTOR_API_VERSION ((BASE_API_VERSION << 16) | 0)
+#define POLICY_SELECTOR_API_VERSION ((BASE_API_VERSION << 16) | 1)
 
 struct Packet;
 class PolicySelector;
index db54813e8cef265438af5fe99eb003ae1f637dde..8b6829a86425cc5ced5f8d49bb97fb86f7110756 100644 (file)
@@ -21,7 +21,7 @@
 #include "config.h"
 #endif
 
-#include "framework/range.h"
+#include "range.h"
 
 #include <cerrno>
 #include <cstdlib>
index 8025574fc266edc7226e23ee9710a2e47f021313..b2154ae93fccbc4fe64d224b32301672b6168b27 100644 (file)
@@ -25,6 +25,9 @@
 // like a text rule except that it can call function hooks. It can also
 // define its own rule options and any other plugins it may need.
 
+// the SOAPI_VERSION will change if anything in this file changes.
+// see also framework/base_api.h.
+
 #include "framework/base_api.h"
 #include "framework/ips_option.h"
 #include "main/snort_types.h"
@@ -35,7 +38,7 @@ struct Packet;
 }
 
 // this is the current version of the api
-#define SOAPI_VERSION ((BASE_API_VERSION << 16) | 0)
+#define SOAPI_VERSION ((BASE_API_VERSION << 16) | 1)
 
 //-------------------------------------------------------------------------
 // rule format is:  header ( [<stub opts>;] soid:<tag>; [<remaining opts>;] )
@@ -45,6 +48,7 @@ struct Packet;
 
 typedef snort::IpsOption::EvalStatus (* SoEvalFunc)(void*, class Cursor&, snort::Packet*);
 typedef SoEvalFunc (* SoNewFunc)(const char* key, void**);
+
 typedef void (* SoDelFunc)(void*);
 typedef void (* SoAuxFunc)();
 
index ba7457616da6e13d4a0f6353bc857b7876721d36..0f554e0f6ad4edc6309b6c937990732a744c0438 100644 (file)
@@ -2,3 +2,13 @@
 add_cpputest( data_bus_test
     SOURCES ../data_bus.cc
 )
+
+# libapi_def.a is actually a text file with the preprocessed header source
+
+if ( ENABLE_UNIT_TESTS )
+    add_library(api_def api_def.cc)
+    target_compile_options(api_def PRIVATE -E)
+    install(TARGETS api_def)
+endif ()
+
+
diff --git a/src/framework/test/api_def.cc b/src/framework/test/api_def.cc
new file mode 100644 (file)
index 0000000..e59884e
--- /dev/null
@@ -0,0 +1,33 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2024-2024 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.
+//--------------------------------------------------------------------------
+// api_def.cpp author Russ Combs <rucombs@cisco.com>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+// this file is solely used to produce compiler preprocessor output
+// for detecting changes to the Snort plugin interface.
+
+#undef API_OPTIONS
+#define API_OPTIONS 0
+
+#include "framework/plugins.h"
+
+int main() { return 0; }
+
index f9678930367fb4939f61669bae15062fae0e31fb..b372e543d93da288e2c5b2b66bd4c795d33983a5 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "framework/data_bus.h"
 #include "main/snort_config.h"
-#include "main/thread.h"
 #include "utils/stats.h"
 
 #include <CppUTest/CommandLineTestRunner.h>
index a935b164a0a236df765574061950bab767f14e2f..3ec96ce28dd25e3c3dffb10d15f2848e7ef05ac8 100644 (file)
@@ -26,9 +26,9 @@
 #include <cstring>
 #include <sstream>
 
-#include "framework/bits.h"
 #include "framework/parameter.h"
 #include "main/snort_types.h"
+#include "utils/bits.h"
 
 namespace snort
 {
index 72e3139d7462e24f4545c21755c744c2ae13ee31..9fac8b4287ed67698ac93cf454d174fd75017fae 100644 (file)
@@ -1,8 +1,6 @@
 
 set (HASH_INCLUDES
-    ghash.h
     hashes.h
-    hash_defs.h
     hash_key_operations.h
     lru_cache_local.h
     lru_cache_shared.h
@@ -13,6 +11,8 @@ set (HASH_INCLUDES
 add_library( hash OBJECT
     ${HASH_INCLUDES}
     ghash.cc
+    ghash.h
+    hash_defs.h
     hashes.cc
     hash_lru_cache.cc
     hash_lru_cache.h
index be27622fd1bf7679cbe1e90d97adc42183ed310e..e25ff5f93c04cbc3f74add4e96761c9ee1fb7060 100644 (file)
@@ -40,7 +40,7 @@ struct GHashNode
 
 typedef void (* gHashFree)(void*);
 
-class SO_PUBLIC GHash
+class GHash
 {
 public:
     GHash(int nrows, unsigned keysize, bool userkey, gHashFree);
index 79e0a2645038f5a36dd6dd63e103b2d14bd33f31..93b861f35c5921739f8c37fac54693f805f0ee7c 100644 (file)
@@ -28,6 +28,7 @@
 #include <random>
 
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "utils/util.h"
 
 #include "primetable.h"
index cf8b35201e2e211d2714bdde00adeb03db54318f..9e29c4609b95d9494b5cb5c6501aafd522bb1098 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "hash/hash_defs.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "utils/util.h"
 
 #include <CppUTest/CommandLineTestRunner.h>
index 3b6112f5398f3f05263d4d0abc1f347308d0e9f9..ee9ddadff615d03b4c29ba31ec7095cdc708458f 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "hash/hash_defs.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "utils/util.h"
 
 #include <CppUTest/CommandLineTestRunner.h>
index 31c5d4f7eefe19f3ab5d0ef1f6488c0f05ab9907..6ecf6206c9206f4bca1fcd15f9577c56a303296c 100644 (file)
@@ -27,8 +27,8 @@
 #include <vector>
 
 #include "framework/counts.h"
+#include "helpers/memcap_allocator.h"
 #include "main/snort_types.h"
-#include "utils/memcap_allocator.h"
 
 class HashLruCache;
 
index de23cd7f02b6c10f4be7be78cf66671b30915314..a94f72d2c214a41d25f582591bbbfc50e4df5d5c 100644 (file)
@@ -13,39 +13,47 @@ endif ()
 set (HELPERS_INCLUDES
     ${HYPER_HEADERS}
     base64_encoder.h
+    ber.h
     bitop.h
+    boyer_moore.h
     boyer_moore_search.h
     buffer_data.h
+    event_gen.h
+    infractions.h
     json_stream.h
     literal_search.h
-    process.h
+    memcap_allocator.h
     scratch_allocator.h
     sigsafe.h
+    utf.h
 )
 
 add_library (helpers OBJECT
     ${HELPERS_INCLUDES}
     ${HYPER_SOURCES}
     base64_encoder.cc
+    ber.cc
+    boyer_moore.cc
     boyer_moore_search.cc
     buffer_data.cc
-    chunk.cc
-    chunk.h
     directory.cc
     directory.h
     discovery_filter.cc
     discovery_filter.h
     flag_context.h
+    grouped_list.h
     json_stream.cc
-    json_stream.h
     literal_search.cc
     markup.cc
     markup.h
-    process.cc
+    primed_allocator.h
     ring.h
     ring_logic.h
     sigsafe.cc
     scratch_allocator.cc
+    streambuf.cc
+    streambuf.h
+    utf.cc
 )
 
 install (FILES ${HELPERS_INCLUDES}
similarity index 99%
rename from src/utils/util_ber.cc
rename to src/helpers/ber.cc
index 7951a26680c92fdac49d7da82df7d9285551de90..7ec11b2de790ff926eb767ad37abebeda7469b15 100644 (file)
@@ -21,7 +21,7 @@
 #include "config.h"
 #endif
 
-#include "util_ber.h"
+#include "ber.h"
 
 namespace snort
 {
similarity index 95%
rename from src/utils/util_ber.h
rename to src/helpers/ber.h
index 9707cf06ca02039e15f79a2d7df4cfaabbb3792b..98a91481a5be3db73e8c81756ba81f3bc516ab3b 100644 (file)
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
-// util_ber.h author Brandon Stultz <brastult@cisco.com>
+// ber.h author Brandon Stultz <brastult@cisco.com>
 
-#ifndef UTIL_BER_H
-#define UTIL_BER_H
+#ifndef BER_H
+#define BER_H
 
 #include "main/snort_types.h"
 #include "framework/cursor.h"
index 7a8271a90ba71be632a45d3e9568a88dd73f91c2..637afe3eb2514bea6203b8ace7701ca0ab89c455 100644 (file)
@@ -16,6 +16,7 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 // buffer_data.h author Amarnath Nayak <amarnaya@cisco.com>
+
 #ifndef BUFFER_DATA_H
 #define BUFFER_DATA_H
 
index 8f1dd3b10a3aeafba7f6afdcf7f295bde786fb7c..c794ea78c085ebd1f3cc699cf110a880b4ad9370 100644 (file)
@@ -1,3 +1,48 @@
 This directory contains new utility classes and methods for use by the
-framework.
+framework. Utility funcitons, defines, etc. should go in src/utils/.
+
+On stream buffer, there are two classes inherited from std::streambuf:
+
+* istreambuf_glue class for reading operations
+* ostreambuf_infl class for writing operations
+
+The input stream buffer presents a continuous sequence of bytes to the client,
+gathered from different sources. For example:
+
+    char* s1 = "world";
+    char* s2 = "!";
+    char* s3 = "Hello ";
+
+These sources being fed to the stream buffer as s3, s1, s2 will form
+"Hello world!" sequence.
+
+In order to do that, istreambuf_glue class represents each source as a chunk of
+data, which has its own position in the resulting sequence.
+The chunk structure contains a pointer to the source, source size, and
+the chunk's offset in the resulting sequence.
+
+Reading is done sequentially within the current chunk. When the end of chunk
+reached, the buffer switches to the next one, setting std::streambuf pointers.
+
+Positioning the cursor is done in two steps:
+
+1. Calculate the final cursor position (absolute or by offset).
+
+2. Find the right chunk and local offset in it to set cursor there.
+
+Currently, no intermediate buffering done between chunks (like alignment,
+prepending/appending the next chunk). The buffer doesn't take ownership over
+the source's memory.
+
+The output stream buffer is mostly like std::stringbuf. The main purpose of it
+is having an extensible dynamic array, where clients could write their data,
+not worrying about resizing and memory management.
+
+Aside from that, ostreambuf_infl can give away ownership over its memory,
+which could be useful for final consumer.
+
+From performance perspective, ostreambuf_infl can reserve an amount of memory
+before actual operations. Also, memory extending is done by predefined
+portions of 2^11^, 2^12^, 2^13^, 2^14^, 2^15^, 2^15^, 2^15^...
+This tries to minimize the number of memory reallocation.
 
index 052a02d7e24a102e57217a6bb07dad7ff2ecfdf3..46510128227eaaad87b2fdab62eb549a6e274ac0 100644 (file)
@@ -32,7 +32,6 @@
 
 #include "log/messages.h"
 #include "main/snort_config.h"
-#include "main/thread.h"
 #include "utils/util.h"
 
 #include "hyper_scratch_allocator.h"
@@ -104,11 +103,14 @@ HyperSearch::~HyperSearch()
 
 }
 
+namespace
+{
 struct ScanContext
 {
     unsigned index;
     bool found = false;
 };
+}
 
 static int hs_match(unsigned int, unsigned long long, unsigned long long to, unsigned int, void* context)
 {
index 5255dd7e0846cce26383a401e65c3324ea4961eb..1e41ac818f63d9e2348af59c36cbe517879c5e93 100644 (file)
@@ -1,8 +1,21 @@
+
+add_catch_test( bitop_test )
+
+add_cpputest( boyer_moore_test
+    SOURCES
+        ../boyer_moore.cc
+)
+
 add_cpputest( boyer_moore_search_test
     SOURCES
         ../boyer_moore_search.cc
 )
 
+add_catch_test( grouped_list_test
+    SOURCES
+        ../grouped_list.h
+)
+
 if ( HAVE_HYPERSCAN )
     add_cpputest( hyper_search_test
         SOURCES
@@ -14,11 +27,16 @@ if ( HAVE_HYPERSCAN )
     )
 endif()
 
-add_catch_test( bitop_test )
-
 add_catch_test( json_stream_test
     SOURCES
         json_stream_test.cc
         ../json_stream.cc
 )
 
+add_cpputest( memcap_allocator_test )
+
+add_catch_test( streambuf_test
+    SOURCES
+        ../streambuf.cc
+)
+
similarity index 99%
rename from src/utils/test/grouped_list_test.cc
rename to src/helpers/test/grouped_list_test.cc
index 70187b7d40e6b1768db5b5cf4d57981ca625c449..375b1a60236295022ca745fb71b142397ea11f1f 100644 (file)
@@ -27,7 +27,7 @@
 #include <cstring>
 #include <vector>
 
-#include "utils/grouped_list.h"
+#include "helpers/grouped_list.h"
 
 using namespace snort;
 using namespace std;
similarity index 99%
rename from src/utils/test/streambuf_test.cc
rename to src/helpers/test/streambuf_test.cc
index 0771a55802df8cc731f3cd7546c910d2b4e6b4e8..e934fdad529098025cdc792a1c8e201cda9ce4ea 100644 (file)
@@ -26,7 +26,7 @@
 #include <iostream>
 #include <vector>
 
-#include "utils/streambuf.h"
+#include "helpers/streambuf.h"
 
 using namespace snort;
 using namespace std;
similarity index 99%
rename from src/utils/util_utf.cc
rename to src/helpers/utf.cc
index f5ad383353e245c52258a54ac7dcf61a29762044..6d445262178d1e8b45f3c193c084acdaf5768057 100644 (file)
@@ -23,7 +23,7 @@
 #include "config.h"
 #endif
 
-#include "util_utf.h"
+#include "utf.h"
 
 #include <cassert>
 #include <cstring>
similarity index 100%
rename from src/utils/util_utf.h
rename to src/helpers/utf.h
index 8625723b52015d0e073bd49380861ce61823894e..1cb414d30b05432c7871a7cfa3a66d51312788b2 100644 (file)
@@ -2,7 +2,6 @@ set (HOST_TRACKER_INCLUDES
     cache_allocator.h
     cache_interface.h
     host_cache.h
-    host_cache_segmented.h
     host_tracker.h
 )
 
@@ -16,6 +15,7 @@ add_library( host_tracker OBJECT
     host_tracker_module.cc
     host_tracker_module.h
     host_tracker.cc
+    host_tracker_stats.h
 )
 
 add_subdirectory ( test )
index b006f50aa53f3fc64cddb716c0d73a5a6fae460b..c42dbe5c3ea751c8b06bc18c98d233bf2ff8a9c0 100644 (file)
@@ -89,13 +89,13 @@ public:
     CacheInterface* get_cache_ptr() { return Base::get_lru(); }
 
     template <class U>
-    HostCacheAllocIp(const HostCacheAllocIp<U>& other) 
+    HostCacheAllocIp(const HostCacheAllocIp<U>& other)
     {
         this->lru = other.get_lru();
     }
 
     template <class U>
-    HostCacheAllocIp(HostCacheAllocIp<U>&& other)  noexcept 
+    HostCacheAllocIp(HostCacheAllocIp<U>&& other) noexcept
     {
         this->lru = other.get_lru();
     }
index 156e46906a64f6a34eca713e3f886d1696cfc70d..76c89420e37566aa7d48f92e15edca90e90b182f 100644 (file)
 
 #include "hash/lru_cache_shared.h"
 #include "host_tracker.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
 #include "sfip/sf_ip.h"
-#include "utils/stats.h"
 
 #include "cache_allocator.h"
 #include "cache_interface.h"
index 9612d28dfb6f3721b02a382cad62900ebffb69dc..1bb3e8fb4af6792d4aea77132ab8578341276c00 100644 (file)
@@ -563,8 +563,6 @@ string HostCacheModule::get_host_cache_stats()
         }
 
     }
-
-
     return str;
 }
 
index 01e6601098ae0a75ae217b9dfa94a94d84b3781b..d73905a645cba21f7d09d0a4e290f5d02f20c905 100644 (file)
@@ -1,5 +1,5 @@
 //--------------------------------------------------------------------------
-// Copyright (C) 2015-2024 Cisco and/or its affiliates. All rights reserved.
+// Copyright (C) 2023-2024 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
 #ifndef HOST_CACHE_SEGMENTED_H
 #define HOST_CACHE_SEGMENTED_H
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 #include <atomic>
 #include <cassert>
 #include <numeric>
 
 #include "host_cache.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
 
 #define DEFAULT_HOST_CACHE_SEGMENTS 4
index 52f9b74585f0f2d98c9c9d0dc1939c05c08e0ba0..df4b361d7fd3616d59ec42cf1720e84a074b9261 100644 (file)
@@ -22,6 +22,9 @@
 #include "config.h"
 #endif
 
+#include "host_tracker.h"
+#include "host_tracker_stats.h"
+
 #include <algorithm>
 
 #include "flow/flow.h"
@@ -31,7 +34,6 @@
 #include "cache_allocator.cc"
 #include "host_cache.h"
 #include "host_cache_segmented.h"
-#include "host_tracker.h"
 
 using namespace snort;
 using namespace std;
index 9ef80e4b59ab364abc0be097c786bf30cfbfafcf..ef43d1673ac1ade099d2acd2cc5d1fa8d690d635 100644 (file)
 #include <mutex>
 #include <list>
 #include <set>
+#include <string>
 #include <unordered_set>
 #include <vector>
 
 #include "framework/counts.h"
 #include "main/snort_types.h"
-#include "main/thread.h"
 #include "network_inspectors/appid/application_ids.h"
 #include "protocols/protocol_ids.h"
 #include "protocols/vlan.h"
 
 #include "cache_allocator.h"
 
-struct HostTrackerStats
-{
-    PegCount service_adds;
-    PegCount service_finds;
-};
-
-extern THREAD_LOCAL struct HostTrackerStats host_tracker_stats;
-
 class RNAFlow;
 
 namespace snort
@@ -387,13 +379,13 @@ public:
         return ++nat_count;
     }
 
-    void set_cache_idx(uint8_t idx) 
-    { 
+    void set_cache_idx(uint8_t idx)
+    {
         std::lock_guard<std::mutex> lck(host_tracker_lock);
-        cache_idx = idx; 
+        cache_idx = idx;
     }
 
-    void init_visibility(size_t v) 
+    void init_visibility(size_t v)
     {
         std::lock_guard<std::mutex> lck(host_tracker_lock);
         visibility = v;
@@ -474,12 +466,12 @@ private:
     uint32_t nat_count_start;     // the time nat counting starts for this host
 
     size_t visibility;
-    uint8_t cache_idx = 0; 
+    uint8_t cache_idx = 0;
 
     uint32_t num_visible_services = 0;
     uint32_t num_visible_clients = 0;
     uint32_t num_visible_macs = 0;
-    
+
     CacheInterface * cache_interface = nullptr;
 
     // These three do not lock independently; they are used by payload discovery and called
index b04d0743b3ee2a9eac5449a3f05e9e793f3430d8..09b817fa0a3e756695d77bdc11a59af04cbea471 100644 (file)
@@ -23,6 +23,7 @@
 #endif
 
 #include "host_tracker_module.h"
+#include "host_tracker_stats.h"
 #include "host_cache_segmented.h"
 
 #include "log/messages.h"
diff --git a/src/host_tracker/host_tracker_stats.h b/src/host_tracker/host_tracker_stats.h
new file mode 100644 (file)
index 0000000..46c5037
--- /dev/null
@@ -0,0 +1,37 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2024-2024 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.
+//--------------------------------------------------------------------------
+
+// host_tracker_stats.h author Russ Combs <rucombs@cisco.com>
+
+#ifndef HOST_TRACKER_STATS_H
+#define HOST_TRACKER_STATS_H
+
+// private HostTracker data (not installed)
+
+#include "framework/counts.h"
+
+struct HostTrackerStats
+{
+    PegCount service_adds;
+    PegCount service_finds;
+};
+
+extern THREAD_LOCAL struct HostTrackerStats host_tracker_stats;
+
+#endif
+
index fc0ff89c589d76d7a71df99425cc093babd598b3..1371a73280d6988643a6004a5cf33ddb52e15c5d 100644 (file)
@@ -65,12 +65,12 @@ public:
     CacheInterface* get_cache_ptr() { return Base::get_lru(); }
 
     template <class U>
-    Allocator(const Allocator<U>& other) 
+    Allocator(const Allocator<U>& other)
     {
         lru = other.lru;
     }
     template <class U>
-    Allocator(const Allocator<U>&& other) 
+    Allocator(const Allocator<U>&& other)
     {
         lru = other.lru;
     }
@@ -102,7 +102,7 @@ TEST_GROUP(host_cache_allocator_ht)
 };
 
 TEST(host_cache_allocator_ht, allocate_update)
-{   
+{
     //declare a list with allocator cache
     std::list<string, Allocator<string>> test_list;
     CHECK(test_list.get_allocator().get_lru() == &cache1);
index bfa4c4955587a0b34206dc52b3378ec2f5294a7f..3e1bc2f5ec19249fff53ecf12d403e4d3c9502e8 100644 (file)
@@ -92,7 +92,7 @@ unsigned ThreadConfig::get_instance_max() { return 1; }
 } // end of namespace snort
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 template <class T>
 HostCacheAllocIp<T>::HostCacheAllocIp()
@@ -177,12 +177,12 @@ TEST(host_cache_module, misc)
     // cache, because sum_stats resets the pegs.
     module.sum_stats(true);
 
-    // add 3 entries to segment 3 
+    // add 3 entries to segment 3
     SfIp ip1, ip2, ip3;
     ip1.set("1.1.1.1");
     ip2.set("2.2.2.2");
     ip3.set("3.3.3.3");
-    
+
     host_cache.find_else_create(ip1, nullptr);
     host_cache.find_else_create(ip2, nullptr);
     host_cache.find_else_create(ip3, nullptr);
@@ -206,7 +206,7 @@ TEST(host_cache_module, misc)
     // pruning in thread is not done when reload_mutex is already locked
     for(auto cache : host_cache.seg_list)
         cache->reload_mutex.lock();
-        
+
     std::thread test_negative(try_reload_prune, false);
     test_negative.join();
 
@@ -268,8 +268,6 @@ TEST(host_cache_module, get_segment_stats)
     str = module.get_host_cache_segment_stats(-1);
     contain = str.find("total cache segments: 4") != std::string::npos;
     CHECK_TRUE(contain);
-    
-
 }
 
 TEST(host_cache_module, log_host_cache_messages)
index 5d429d2beb9bf64c4cf154a5327fdabf74f116b5..8f4ccccb0db97f4feb0295afc7336558a2424fca 100644 (file)
@@ -28,6 +28,7 @@
 #include "host_tracker/host_cache.h"
 #include "host_tracker/host_cache_segmented.h"
 #include "host_tracker/host_tracker_module.h"
+#include "host_tracker/host_tracker_stats.h"
 #include "main/snort_config.h"
 #include "main/thread_config.h"
 #include "target_based/snort_protocols.h"
@@ -50,7 +51,7 @@ unsigned ThreadConfig::get_instance_max() { return 1; }
 
 //  Fake show_stats to avoid bringing in a ton of dependencies.
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 SfIp expected_addr;
 
index 4ae54c65e0496376fc16dd8906f1f35fafcd9ee4..3512b4860b01ca6813e3d23cf771fce60ab9845e 100644 (file)
@@ -1,6 +1,3 @@
-set(IPS_INCLUDES
-    extract.h
-)
 
 SET( PLUGIN_LIST
     ips_ack.cc
@@ -12,13 +9,20 @@ SET( PLUGIN_LIST
     ips_byte_jump.cc
     ips_byte_math.cc
     ips_byte_test.cc
+    ips_classtype.cc
+    ips_content.cc
     ips_cvs.cc
+    ips_dsize.cc
     ips_enable.cc
+    ips_file_data.cc
+    ips_file_meta.cc
     ips_file_type.cc
     ips_flags.cc
+    ips_flow.cc
     ips_fragbits.cc
     ips_fragoffset.cc
     ips_gid.cc
+    ips_hash.cc
     ips_icmp_id.cc
     ips_icmp_seq.cc
     ips_icode.cc
@@ -27,14 +31,19 @@ SET( PLUGIN_LIST
     ips_ip_proto.cc
     ips_isdataat.cc
     ips_itype.cc
+    ips_js_data.cc
+    ips_metadata.cc
     ips_msg.cc
     ips_pcre.cc
+    ips_pkt_data.cc
     ips_priority.cc
     ips_raw_data.cc
+    ips_reference.cc
     ips_rem.cc
     ips_rev.cc
     ips_rpc.cc
     ips_seq.cc
+    ips_service.cc
     ips_sid.cc
     ips_soid.cc
     ips_tag.cc
@@ -42,33 +51,16 @@ SET( PLUGIN_LIST
     ips_tos.cc
     ips_ttl.cc
     ips_window.cc
-    ips_vba_data.cc
-    ips_vba_data.h
 )
 
-
 set (IPS_SOURCES
-    ${IPS_INCLUDES}
-    extract.cc
-    ips_classtype.cc
-    ips_content.cc
     ips_detection_filter.cc
-    ips_dsize.cc
-    ips_file_data.cc
-    ips_file_meta.cc
-    ips_flow.cc
     ips_flowbits.cc
     ips_flowbits.h
-    ips_hash.cc
-    ips_js_data.cc
     ips_luajit.cc
-    ips_metadata.cc
     ips_options.cc
     ips_options.h
-    ips_pkt_data.cc
-    ips_reference.cc
     ips_replace.cc
-    ips_service.cc
     ips_so.cc
     ips_vba_data.cc
     ips_vba_data.h
@@ -86,7 +78,6 @@ if (STATIC_IPS_OPTIONS)
 
     add_library ( ips_options OBJECT
         ${IPS_SOURCES}
-        ${OPTION_LIST}
         ${PLUGIN_LIST}
     )
 
@@ -94,22 +85,28 @@ else (STATIC_IPS_OPTIONS)
 
     add_library ( ips_options OBJECT
         ${IPS_SOURCES}
-        ${OPTION_LIST}
     )
 
+    add_dynamic_module(ips_content ips_options ips_content.cc)
+    add_dynamic_module(ips_hash ips_options ips_hash.cc)
     add_dynamic_module(ips_ack ips_options ips_ack.cc)
     add_dynamic_module(ips_base64 ips_options ips_base64.cc)
     add_dynamic_module(ips_ber_data ips_options ips_ber_data.cc)
     add_dynamic_module(ips_ber_skip ips_options ips_ber_skip.cc)
     add_dynamic_module(ips_bufferlen ips_options ips_bufferlen.cc)
-    add_dynamic_module(ips_byte_extract ips_options extract.cc ips_byte_extract.cc)
-    add_dynamic_module(ips_byte_jump ips_options extract.cc ips_byte_jump.cc)
-    add_dynamic_module(ips_byte_math ips_options extract.cc ips_byte_math.cc)
-    add_dynamic_module(ips_byte_test ips_options extract.cc ips_byte_test.cc)
+    add_dynamic_module(ips_byte_extract ips_options ips_byte_extract.cc)
+    add_dynamic_module(ips_byte_jump ips_options ips_byte_jump.cc)
+    add_dynamic_module(ips_byte_math ips_options ips_byte_math.cc)
+    add_dynamic_module(ips_byte_test ips_options ips_byte_test.cc)
+    add_dynamic_module(ips_classtype ips_options ips_classtype.cc)
     add_dynamic_module(ips_cvs ips_options ips_cvs.cc)
+    add_dynamic_module(ips_dsize ips_options ips_dsize.cc)
     add_dynamic_module(ips_enable ips_options ips_enable.cc)
+    add_dynamic_module(ips_file_data ips_options ips_file_data.cc)
+    add_dynamic_module(ips_file_meta ips_options ips_file_meta.cc)
     add_dynamic_module(ips_file_type ips_options ips_file_type.cc)
     add_dynamic_module(ips_flags ips_options ips_flags.cc)
+    add_dynamic_module(ips_flow ips_options ips_flow.cc)
     add_dynamic_module(ips_fragbits ips_options ips_fragbits.cc)
     add_dynamic_module(ips_fragoffset ips_options ips_fragoffset.cc)
     add_dynamic_module(ips_gid ips_options ips_gid.cc)
@@ -121,13 +118,18 @@ else (STATIC_IPS_OPTIONS)
     add_dynamic_module(ips_ip_proto ips_options ips_ip_proto.cc)
     add_dynamic_module(ips_isdataat ips_options ips_isdataat.cc)
     add_dynamic_module(ips_itype ips_options ips_itype.cc)
+    add_dynamic_module(ips_js_data ips_options ips_js_data.cc)
+    add_dynamic_module(ips_metadata ips_options ips_metadata.cc)
     add_dynamic_module(ips_msg ips_options ips_msg.cc)
     add_dynamic_module(ips_pcre ips_options ips_pcre.cc)
+    add_dynamic_module(ips_pkt_data ips_options ips_pkt_data.cc)
     add_dynamic_module(ips_priority ips_options ips_priority.cc)
     add_dynamic_module(ips_raw_data ips_options ips_raw_data.cc)
+    add_dynamic_module(ips_reference ips_options ips_reference.cc)
     add_dynamic_module(ips_rem ips_options ips_rem.cc)
     add_dynamic_module(ips_rev ips_options ips_rev.cc)
     add_dynamic_module(ips_rpc ips_options ips_rpc.cc)
+    add_dynamic_module(ips_service ips_options ips_service.cc)
     add_dynamic_module(ips_sid ips_options ips_sid.cc)
     add_dynamic_module(ips_seq ips_options ips_seq.cc)
     add_dynamic_module(ips_soid ips_options ips_soid.cc)
@@ -145,6 +147,3 @@ endif (STATIC_IPS_OPTIONS)
 
 add_subdirectory(test)
 
-install(FILES ${IPS_INCLUDES}
-    DESTINATION "${INCLUDE_INSTALL_PATH}/ips_options/"
-)
index f978c77ade32de44c3152041fff6f4a02975b6af..178d619f28d5a8ca56a2a8c27d7919ef3fe50f3f 100644 (file)
@@ -148,7 +148,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* ack_ctor(Module* p, OptTreeNode*)
+static IpsOption* ack_ctor(Module* p, IpsInfo&)
 {
     AckModule* m = (AckModule*)p;
     return new TcpAckOption(m->data);
index 6b56627cbaccf9a3d6d9f9a1a7f5a258a3c03cf8..da3ea0f7196e1a0fa9f9cdc3a0f9819d78b6cc2f 100644 (file)
@@ -24,7 +24,6 @@
 #endif
 
 #include "detection/detection_engine.h"
-#include "detection/treenodes.h"
 #include "hash/hash_key_operations.h"
 #include "framework/cursor.h"
 #include "framework/ips_option.h"
@@ -229,7 +228,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* base64_decode_ctor(Module* p, OptTreeNode*)
+static IpsOption* base64_decode_ctor(Module* p, IpsInfo&)
 {
     B64DecodeModule* m = (B64DecodeModule*)p;
     return new Base64DecodeOption(m->data);
@@ -302,9 +301,9 @@ IpsOption::EvalStatus Base64DataOption::eval(Cursor& c, Packet* p)
 //-------------------------------------------------------------------------
 
 static class IpsOption* base64_data_ctor(
-    Module*, OptTreeNode* otn)
+    Module*, IpsInfo& info)
 {
-    if ( !otn_has_plugin(otn, "base64_decode") )
+    if ( !IpsOption::has_plugin(info, "base64_decode") )
     {
         ParseError("base64_decode needs to be specified before base64_data in a rule");
         return nullptr;
index a0527d7c63f67f7ee5c714b4dba7f1dd231fadb5..e7797821f1aac58fbb4531cebafaab8d1110b4cf 100644 (file)
@@ -25,8 +25,8 @@
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "hash/hash_key_operations.h"
+#include "helpers/ber.h"
 #include "profiler/profiler.h"
-#include "utils/util_ber.h"
 
 using namespace snort;
 
@@ -165,7 +165,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* ber_data_ctor(Module* p, OptTreeNode*)
+static IpsOption* ber_data_ctor(Module* p, IpsInfo&)
 {
     BerDataModule* m = (BerDataModule*)p;
     return new BerDataOption(m->type);
index f54e404b74a12112df8d4ede8d4b1f9d5322bd64..2ac03eb0b996690160bd04f0e7cd4d3f02c21e8f 100644 (file)
@@ -25,8 +25,8 @@
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "hash/hash_key_operations.h"
+#include "helpers/ber.h"
 #include "profiler/profiler.h"
-#include "utils/util_ber.h"
 
 using namespace snort;
 
@@ -182,7 +182,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* ber_skip_ctor(Module* p, OptTreeNode*)
+static IpsOption* ber_skip_ctor(Module* p, IpsInfo&)
 {
     BerSkipModule* m = (BerSkipModule*)p;
     return new BerSkipOption(m->type, m->optional);
index 1d7769e0576d3700372f9eaa7dcc2f65cb1e2a3a..fbfbcd84a68fa4a0ec5e9723416063d6712a6e0f 100644 (file)
@@ -162,7 +162,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* len_ctor(Module* p, OptTreeNode*)
+static IpsOption* len_ctor(Module* p, IpsInfo&)
 {
     LenModule* m = (LenModule*)p;
     return new LenOption(m->data, m->relative);
index 26cb745e640ac9454719dabc19817aa539124715..5f94cb05dce1e7d2ba9ac46e8948e147e5df132f 100644 (file)
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
+#include "detection/extract.h"
 #include "framework/cursor.h"
 #include "framework/endianness.h"
+#include "framework/ips_info.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "hash/hash_key_operations.h"
@@ -33,8 +34,6 @@
 #include "protocols/packet.h"
 #include "utils/util.h"
 
-#include "extract.h"
-
 #ifdef UNIT_TEST
 #include <catch/snort_catch.h>
 #include "service_inspectors/dce_rpc/dce_common.h"
@@ -386,7 +385,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* byte_extract_ctor(Module* p, OptTreeNode*)
+static IpsOption* byte_extract_ctor(Module* p, IpsInfo&)
 {
     ExtractModule* m = (ExtractModule*)p;
     ByteExtractData& data = m->data;
@@ -878,17 +877,19 @@ TEST_CASE("Test of byte_extract_ctor", "[ips_byte_extract]")
             "~name", Parameter::PT_STRING, nullptr, nullptr,
             "name of the variable that will be used in other rule options"};
         v.set(&p);
+
         obj.set(nullptr, v, nullptr);
+        IpsInfo info(nullptr, nullptr);
 
         if (i < NUM_IPS_OPTIONS_VARS)
         {
-            IpsOption* res = byte_extract_ctor(&obj, nullptr);
+            IpsOption* res = byte_extract_ctor(&obj, info);
             delete res;
         }
         else
         {
-            IpsOption* res_null = byte_extract_ctor(&obj, nullptr);
-            CHECK(nullptr == res_null);
+            IpsOption* res_null = byte_extract_ctor(&obj, info);
+            CHECK(res_null == nullptr);
             delete[] obj.data.name;
         }
     }
index 1ddd416b463db8f7bd68231eb4cf4a83a1dc2e74..7f203f4df4ffd17addb55e0de3a9bd927ea2b78c 100644 (file)
@@ -77,6 +77,7 @@
 #include "config.h"
 #endif
 
+#include "detection/extract.h"
 #include "framework/cursor.h"
 #include "framework/endianness.h"
 #include "framework/ips_option.h"
@@ -86,8 +87,6 @@
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 
-#include "extract.h"
-
 using namespace snort;
 using namespace std;
 
@@ -499,7 +498,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* byte_jump_ctor(Module* p, OptTreeNode*)
+static IpsOption* byte_jump_ctor(Module* p, IpsInfo&)
 {
     ByteJumpModule* m = (ByteJumpModule*)p;
     return new ByteJumpOption(m->data);
index 08f030c0f093651f32d861183224332a24f04d0d..d8932c4fd577d989cca950e948fa4158a87f6ab5 100644 (file)
 #include "config.h"
 #endif
 
+#include "detection/extract.h"
 #include "framework/cursor.h"
 #include "framework/endianness.h"
+#include "framework/ips_info.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "hash/hash_key_operations.h"
@@ -33,8 +35,6 @@
 #include "protocols/packet.h"
 #include "utils/util.h"
 
-#include "extract.h"
-
 #ifdef UNIT_TEST
 #include "catch/snort_catch.h"
 #include "service_inspectors/dce_rpc/dce_common.h"
@@ -492,7 +492,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* byte_math_ctor(Module* p, OptTreeNode*)
+static IpsOption* byte_math_ctor(Module* p, IpsInfo&)
 {
     ByteMathModule* m = (ByteMathModule*)p;
     ByteMathData& data = m->data;
@@ -1233,16 +1233,19 @@ TEST_CASE("Test of byte_math_ctor", "[ips_byte_math]")
         Parameter p{"result", Parameter::PT_STRING, nullptr, nullptr,
             "name of the variable to store the result"};
         v.set(&p);
+
         obj.set(nullptr, v, nullptr);
+        IpsInfo info(nullptr, nullptr);
+
         if (i < NUM_IPS_OPTIONS_VARS)
         {
-            IpsOption* res = byte_math_ctor(&obj, nullptr);
+            IpsOption* res = byte_math_ctor(&obj, info);
             delete res;
         }
         else
         {
-            IpsOption* res_null = byte_math_ctor(&obj, nullptr);
-            CHECK(nullptr == res_null);
+            IpsOption* res_null = byte_math_ctor(&obj, info);
+            CHECK(res_null == nullptr);
             delete[] obj.data.result_name;
         }
     }
index 6de64ada2faea5ebe95edb733bc6cbdd40d689e9..4a5bb078e19530768020a0b53c3b65d4f096df8c 100644 (file)
@@ -93,6 +93,7 @@
 #include "config.h"
 #endif
 
+#include "detection/extract.h"
 #include "framework/cursor.h"
 #include "framework/endianness.h"
 #include "framework/ips_option.h"
 #include "catch/snort_catch.h"
 #endif
 
-#include "extract.h"
-
 using namespace snort;
 using namespace std;
 
@@ -564,7 +563,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* byte_test_ctor(Module* p, OptTreeNode*)
+static IpsOption* byte_test_ctor(Module* p, IpsInfo&)
 {
     ByteTestModule* m = (ByteTestModule*)p;
     return new ByteTestOption(m->data);
index 2594ae9879fa1f476e23e11cbd9b69345e7ead35..b582f46db1540f8d94e6e232ee4f139cbbca07c0 100644 (file)
@@ -21,7 +21,8 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
+#include <string>
+
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -56,21 +57,14 @@ public:
     { return DETECT; }
 
 public:
-    const ClassType* type = nullptr;
+    std::string classtype;
 };
 
-bool ClassTypeModule::set(const char*, Value& v, SnortConfig* sc)
+bool ClassTypeModule::set(const char*, Value& v, SnortConfig*)
 {
     assert(v.is("~"));
-    type = get_classification(sc, v.get_string());
-
-    if ( !type and sc->dump_rule_info() )
-    {
-        const char* s = v.get_string();
-        add_classification(sc, s, s, 1);
-        type = get_classification(sc, s);
-    }
-    return type != nullptr;
+    classtype = v.get_string();
+    return true;
 }
 
 //-------------------------------------------------------------------------
@@ -87,16 +81,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* classtype_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* classtype_ctor(Module* p, IpsInfo& info)
 {
     ClassTypeModule* m = (ClassTypeModule*)p;
-    otn->sigInfo.class_type = m->type;
-
-    if ( m->type )
-    {
-        otn->sigInfo.class_id = m->type->id;
-        otn->sigInfo.priority = m->type->priority;
-    }
+    IpsOption::set_classtype(info, m->classtype.c_str());
     return nullptr;
 }
 
@@ -125,5 +113,13 @@ static const IpsApi classtype_api =
     nullptr
 };
 
-const BaseApi* ips_classtype = &classtype_api.base;
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* ips_classtype[] =
+#endif
+{
+    &classtype_api.base,
+    nullptr
+};
 
index a81da92680b407de52a35715aa044f8312ba2f20..e394bb10df3e53c0f5562ddfed6a13209c32f835 100644 (file)
@@ -22,8 +22,8 @@
 #include "config.h"
 #endif
 
+#include "detection/extract.h"
 #include "detection/pattern_match_data.h"
-#include "detection/treenodes.h"
 #include "framework/cursor.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -34,9 +34,6 @@
 #include "parser/parse_utils.h"
 #include "profiler/profiler.h"
 #include "utils/util.h"
-#include "utils/stats.h"
-
-#include "extract.h"
 
 using namespace snort;
 
@@ -147,7 +144,7 @@ public:
     bool is_relative() override
     { return config->pmd.is_relative(); }
 
-    bool retry(Cursor&, const Cursor&) override;
+    bool retry(Cursor&) override;
 
     ContentData* get_data()
     { return config; }
@@ -180,7 +177,7 @@ static inline bool retry(const PatternMatchData& pmd, const Cursor& c)
     return c.get_delta() + pmd.pattern_size <= pmd.depth;
 }
 
-bool ContentOption::retry(Cursor& c, const Cursor&)
+bool ContentOption::retry(Cursor& c)
 {
     return ::retry(config->pmd, c);
 }
@@ -794,7 +791,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* content_ctor(Module* p, OptTreeNode*)
+static IpsOption* content_ctor(Module* p, IpsInfo&)
 {
     ContentModule* m = (ContentModule*)p;
     ContentData* cd = m->get_data();
@@ -831,15 +828,13 @@ static const IpsApi content_api =
     nullptr
 };
 
-// FIXIT-L need boyer_moore.cc funcs but they
-// aren't otherwise called
-//#ifdef BUILDING_SO
-//SO_PUBLIC const BaseApi* snort_plugins[] =
-//{
-//    &content_api.base,
-//    nullptr
-//};
-//#else
-const BaseApi* ips_content = &content_api.base;
-//#endif
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* ips_content[] =
+#endif
+{
+    &content_api.base,
+    nullptr
+};
 
index 65a7aa6e45ac9f67c52d4204af12958725386a4a..367a6d4a0dafe5f072149f722ebb9ba4995c6fa0 100644 (file)
@@ -409,7 +409,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cvs_ctor(Module* p, OptTreeNode*)
+static IpsOption* cvs_ctor(Module* p, IpsInfo&)
 {
     CvsModule* m = (CvsModule*)p;
     return new CvsOption(m->data);
@@ -465,9 +465,7 @@ const BaseApi* ips_cvs[] =
 class StubIpsOption : public IpsOption
 {
 public:
-    StubIpsOption(const char* name, option_type_t option_type) :
-        IpsOption(name, option_type)
-    {}
+    StubIpsOption(const char* name) : IpsOption(name) { }
 };
 
 TEST_CASE("CvsOption test", "[ips_cvs]")
@@ -479,8 +477,7 @@ TEST_CASE("CvsOption test", "[ips_cvs]")
 
         SECTION("not equal as IpsOptions")
         {
-            StubIpsOption opt_other("not_cvs",
-                option_type_t::RULE_OPTION_TYPE_OTHER);
+            StubIpsOption opt_other("not_cvs");
             REQUIRE_FALSE(cvs_opt == opt_other);
         }
 
index 9576025d21c2176baaa55260e7fcc42e2f7d4e73..edd18c8d74c69a2333a8e1c7798f4f7ff864f2e2 100644 (file)
@@ -1,7 +1,5 @@
 //--------------------------------------------------------------------------
 // Copyright (C) 2014-2024 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2002-2013 Sourcefire, Inc.
-// Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
 //
 // 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
@@ -24,7 +22,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "filters/detection_filter.h"
 #include "filters/sfthd.h"
 #include "framework/decode_data.h"
@@ -62,7 +59,6 @@ class DetectionFilterModule : public Module
 public:
     DetectionFilterModule() : Module(s_name, s_help, s_params) { }
     bool set(const char*, Value&, SnortConfig*) override;
-    bool begin(const char*, int, SnortConfig*) override;
 
     ProfileStats* get_profile() const override
     { return &detectionFilterPerfStats; }
@@ -71,28 +67,20 @@ public:
     { return DETECT; }
 
 public:
-    THDX_STRUCT thdx = {};
-    DetectionFilterConfig* dfc = nullptr;
+    bool trk_src = false;
+    uint32_t count = 0, seconds = 0;
 };
 
-bool DetectionFilterModule::begin(const char*, int, SnortConfig* sc)
-{
-    memset(&thdx, 0, sizeof(thdx));
-    thdx.type = THD_TYPE_DETECT;
-    dfc = sc->detection_filter_config;
-    return true;
-}
-
 bool DetectionFilterModule::set(const char*, Value& v, SnortConfig*)
 {
     if ( v.is("track") )
-        thdx.tracking = v.get_uint8() ? THD_TRK_DST : THD_TRK_SRC;
+        trk_src = v.get_uint8() == 0;
 
     else if ( v.is("count") )
-        thdx.count = v.get_uint32();
+        count = v.get_uint32();
 
     else if ( v.is("seconds") )
-        thdx.seconds = v.get_uint32();
+        seconds = v.get_uint32();
 
     return true;
 }
@@ -111,10 +99,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* detection_filter_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* detection_filter_ctor(Module* p, IpsInfo& info)
 {
     DetectionFilterModule* m = (DetectionFilterModule*)p;
-    otn->detection_filter = detection_filter_create(m->dfc, &m->thdx);
+    IpsOption::set_detection_filter(info, m->trk_src, m->count, m->seconds);
     return nullptr;
 }
 
@@ -143,5 +131,9 @@ static const IpsApi detection_filter_api =
     nullptr
 };
 
-const BaseApi* ips_detection_filter = &detection_filter_api.base;
+const BaseApi* ips_detection_filter[] =
+{
+    &detection_filter_api.base,
+    nullptr
+};
 
index 532b7a501304260c7348ecad8ce928749b7aff5d..813d84f41694dcb7a816435d6a057dbe27f338f7 100644 (file)
@@ -152,7 +152,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* dsize_ctor(Module* p, OptTreeNode*)
+static IpsOption* dsize_ctor(Module* p, IpsInfo&)
 {
     DsizeModule* m = (DsizeModule*)p;
     return new DsizeOption(m->data);
index f310a96a7dc34b8fff0ead46610f5d02b384b87f..68d4256ea88db4a0390e69e04990d707611b62e7 100644 (file)
@@ -21,8 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
-#include "detection/rules.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -58,22 +56,19 @@ public:
     { return DETECT; }
 
 public:
-    IpsPolicy::Enable enable = IpsPolicy::Enable::ENABLED;
+    IpsOption::Enable enable = IpsOption::NO;
 };
 
-bool EnableModule::begin(const char*, int, SnortConfig* sc)
+bool EnableModule::begin(const char*, int, SnortConfig*)
 {
-    if ( !sc->rule_states )
-        sc->rule_states = new RuleStateMap;
-
-    enable = IpsPolicy::Enable::ENABLED;
+    enable = IpsOption::YES;
     return true;
 }
 
 bool EnableModule::set(const char*, Value& v, SnortConfig*)
 {
     assert(v.is("~enable"));
-    enable = IpsPolicy::Enable(v.get_uint8());
+    enable = IpsOption::Enable(v.get_uint8());
     return true;
 }
 
@@ -91,10 +86,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* enable_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* enable_ctor(Module* p, IpsInfo& info)
 {
     EnableModule* m = (EnableModule*)p;
-    otn->set_enabled(m->enable);
+    IpsOption::set_enabled(info, m->enable);
     return nullptr;
 }
 
index 8eb2cb4a617d72da070aa5887aa1eef8852431c6..db591bf19c0c5cecfc03157fd421cbab1ca3d5dc 100644 (file)
@@ -105,7 +105,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* file_data_ctor(Module*, OptTreeNode*)
+static IpsOption* file_data_ctor(Module*, IpsInfo&)
 {
     return new FileDataOption;
 }
index b23e52371e2612f1bc16252b6478bba787793f82..3b57698b0367f11110f63555a9e9e0320c3dbd69 100644 (file)
 #include "config.h"
 #endif
 
-#include <unordered_map>
-
-#include "detection/detection_engine.h"
-#include "detection/treenodes.h"
 #include "file_api/file_flows.h"
-#include "framework/cursor.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
-#include "main/thread_config.h"
-#include "profiler/profiler.h"
-#include "protocols/packet.h"
 
 using namespace snort;
 
@@ -127,7 +119,7 @@ bool FileMetaModule::set(const char*, Value& v, SnortConfig*)
 
 bool FileMetaModule::end(const char*, int, SnortConfig* sc)
 {
-    set_rule_id_from_type(sc, fmc.file_id, fmc.file_type,fmc.category, fmc.version, fmc.groups);
+    set_rule_id_from_type(sc, fmc.file_id, fmc.file_type, fmc.category, fmc.version, fmc.groups);
     return true;
 }
 
@@ -145,10 +137,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* file_meta_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* file_meta_ctor(Module* p, IpsInfo& info)
 {
     FileMetaModule* m = (FileMetaModule*)p;
-    otn->sigInfo.file_id = m->fmc.file_id;
+    IpsOption::set_file_id(info, m->fmc.file_id);
     return nullptr;
 }
 
@@ -178,5 +170,13 @@ static const IpsApi file_meta_api =
     nullptr
 };
 
-const BaseApi* ips_file_meta = &file_meta_api.base;
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* ips_file_meta[] =
+#endif
+{
+    &file_meta_api.base,
+    nullptr
+};
 
index ad6edd00551e06ee2623cf158f9213930deb85d7..f63521b328a8771d00a31e89a0a971e0d7e4da24 100644 (file)
@@ -237,7 +237,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* file_type_ctor(Module* m, OptTreeNode*)
+static IpsOption* file_type_ctor(Module* m, IpsInfo&)
 {
     FileTypeModule* mod = (FileTypeModule*)m;
     return new FileTypeOption(mod->types);
index 37c891ca2c00c42439ee030931953a1cbb61bb95..4b75f26991a612f0ecce78dd36142c6a9ab585a3 100644 (file)
@@ -387,7 +387,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* flags_ctor(Module* p, OptTreeNode*)
+static IpsOption* flags_ctor(Module* p, IpsInfo&)
 {
     FlagsModule* m = (FlagsModule*)p;
     return new TcpFlagOption(m->data);
index 7cdc5c49f174701b16d44fefb3dca6bc90a20e42..15986db8e7a5ce099f5628af087c42a820134e45 100644 (file)
@@ -22,7 +22,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "hash/hash_key_operations.h"
@@ -376,20 +375,20 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* flow_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* flow_ctor(Module* p, IpsInfo& info)
 {
     FlowModule* m = (FlowModule*)p;
 
     if ( m->data.stateless )
-        otn->set_stateless();
+        IpsOption::set_stateless(info);
 
     if ( m->data.from_server )
-        otn->set_to_client();
+        IpsOption::set_to_client(info);
 
     else if ( m->data.from_client )
-        otn->set_to_server();
+        IpsOption::set_to_server(info);
 
-    if (otn->snort_protocol_id == SNORT_PROTO_ICMP)
+    if (IpsOption::get_protocol_id(info) == SNORT_PROTO_ICMP)
     {
         if ( (m->data.only_reassembled != ONLY_FRAG) &&
             (m->data.ignore_reassembled != IGNORE_FRAG) )
@@ -431,5 +430,13 @@ static const IpsApi flow_api =
     nullptr
 };
 
-const BaseApi* ips_flow = &flow_api.base;
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* ips_flow[] =
+#endif
+{
+    &flow_api.base,
+    nullptr
+};
 
index 51efe5b0cabf168947c7cb84334684baa14866dd..c38bb3963e625d779ee54b9431c6bfc34068f807 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <unordered_map>
 
-#include "detection/treenodes.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "hash/hash_defs.h"
@@ -35,8 +34,6 @@
 #include "log/messages.h"
 #include "protocols/packet.h"
 #include "profiler/profiler.h"
-#include "utils/sflsq.h"
-#include "utils/util.h"
 
 using namespace snort;
 
@@ -509,14 +506,14 @@ static void mod_dtor(Module* m)
     delete fb;
 }
 
-static IpsOption* flowbits_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* flowbits_ctor(Module* p, IpsInfo& info)
 {
     FlowbitsModule* m = (FlowbitsModule*)p;
     FlowBitCheck* fbc = m->get_data();
     FlowBitsOption* opt = new FlowBitsOption(fbc);
 
     if ( opt->is_checker() )
-        otn->set_flowbits_check();
+        IpsOption::set_flowbits_check(info);
 
     return opt;
 }
@@ -551,5 +548,9 @@ static const IpsApi flowbits_api =
     nullptr
 };
 
-const BaseApi* ips_flowbits = &flowbits_api.base;
+const BaseApi* ips_flowbits[] =
+{
+    &flowbits_api.base,
+    nullptr
+};
 
index 7b82e652d6cb9d1040989dae60a77d9687fa3f58..0679e05b091d6004eb1a20dcf43bac7b6fa51919 100644 (file)
@@ -400,7 +400,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* fragbits_ctor(Module* p, OptTreeNode*)
+static IpsOption* fragbits_ctor(Module* p, IpsInfo&)
 {
     FragBitsModule* fragBitsModule = (FragBitsModule*)p;
     return new FragBitsOption( fragBitsModule->get_fragBits_data() );
index 7ec3ec906362e1303277e7f1ae88269e3c8310bc..3ba31fd6c719f97bbc3629d23f202944d804542a 100644 (file)
@@ -149,7 +149,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* fragoffset_ctor(Module* p, OptTreeNode*)
+static IpsOption* fragoffset_ctor(Module* p, IpsInfo&)
 {
     FragOffsetModule* m = (FragOffsetModule*)p;
     return new FragOffsetOption(m->data);
index c4ba1211a28b65a8c6ee38ace2877f4c0d389e2a..b96f2369aa6a9ad4a9d6d61278f70df061c95f0b 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -79,10 +78,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* gid_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* gid_ctor(Module* p, IpsInfo& info)
 {
     GidModule* m = (GidModule*)p;
-    otn->sigInfo.gid = m->gid;
+    IpsOption::set_gid(info, m->gid);
     return nullptr;
 }
 
index a58835b4eef27b262299ad5a2c6b112f5e751194..a796be33eb3df22c3558aef63b43506c1359a20f 100644 (file)
@@ -23,6 +23,7 @@
 #include <array>
 #include <cassert>
 
+#include "detection/extract.h"
 #include "framework/cursor.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -32,8 +33,6 @@
 #include "parser/parse_utils.h"
 #include "profiler/profiler.h"
 
-#include "extract.h"
-
 using namespace snort;
 
 enum HashPsIdx
@@ -366,7 +365,7 @@ static Module* md5_mod_ctor()
     return new HashModule(IPS_OPT, HPI_MD5);
 }
 
-static IpsOption* md5_opt_ctor(Module* p, OptTreeNode*)
+static IpsOption* md5_opt_ctor(Module* p, IpsInfo&)
 {
     HashModule* m = (HashModule*)p;
     HashMatchData* hmd = m->get_data();
@@ -410,7 +409,7 @@ static Module* sha256_mod_ctor()
     return new HashModule(IPS_OPT, HPI_SHA256);
 }
 
-static IpsOption* sha256_opt_ctor(Module* p, OptTreeNode*)
+static IpsOption* sha256_opt_ctor(Module* p, IpsInfo&)
 {
     HashModule* m = (HashModule*)p;
     HashMatchData* hmd = m->get_data();
@@ -454,7 +453,7 @@ static Module* sha512_mod_ctor()
     return new HashModule(IPS_OPT, HPI_SHA512);
 }
 
-static IpsOption* sha512_opt_ctor(Module* p, OptTreeNode*)
+static IpsOption* sha512_opt_ctor(Module* p, IpsInfo&)
 {
     HashModule* m = (HashModule*)p;
     HashMatchData* hmd = m->get_data();
@@ -490,20 +489,17 @@ static const IpsApi sha512_api =
 // plugins
 //-------------------------------------------------------------------------
 
-// can't be linked dynamically yet
-//#ifdef BUILDING_SO
-//SO_PUBLIC const BaseApi* snort_plugins[] =
-//{
-//    &md5_api.base,
-//    &sha256_api.base,
-//    &sha512_api.base,
-//    nullptr
-//};
-//#else
-const BaseApi* ips_md5 = &md5_api.base;
-const BaseApi* ips_sha256 = &sha256_api.base;
-const BaseApi* ips_sha512 = &sha512_api.base;
-//#endif
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* ips_hash[] =
+#endif
+{
+    &md5_api.base,
+    &sha256_api.base,
+    &sha512_api.base,
+    nullptr
+};
 
 //-------------------------------------------------------------------------
 // UNIT TESTS
index 7a7b159d77f873781b57dc1f775aadc3a50d5d48..7608e562d083a1988f5fa56daae69a7bd97d4aa4 100644 (file)
@@ -178,7 +178,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* icmp_id_ctor(Module* p, OptTreeNode*)
+static IpsOption* icmp_id_ctor(Module* p, IpsInfo&)
 {
     IcmpIdModule* m = (IcmpIdModule*)p;
     return new IcmpIdOption(m->data);
index 53ac6a5b48928712214eb23222a2507e9bcdb3de..d9b3b78e27cee7220ccfaaa395f08c09bdbb8203 100644 (file)
@@ -179,7 +179,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* icmp_seq_ctor(Module* p, OptTreeNode*)
+static IpsOption* icmp_seq_ctor(Module* p, IpsInfo&)
 {
     IcmpSeqModule* m = (IcmpSeqModule*)p;
     return new IcmpSeqOption(m->data);
index 597a1601e62349615abc556eddb7d15ab56030ea..c770bd9329bbcbbd7d11ec364544e2c3f3da9e72 100644 (file)
@@ -150,7 +150,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* icode_ctor(Module* p, OptTreeNode*)
+static IpsOption* icode_ctor(Module* p, IpsInfo&)
 {
     IcodeModule* m = (IcodeModule*)p;
     return new IcodeOption(m->data);
index 33bcb60a19f945e424c20a79fe6d15881ac189eb..d04fa4f91f9a9a4415361c942da0601accb38720 100644 (file)
@@ -152,7 +152,7 @@ static void mod_dtor(Module* m)
 // api methods
 //-------------------------------------------------------------------------
 
-static IpsOption* id_ctor(Module* p, OptTreeNode*)
+static IpsOption* id_ctor(Module* p, IpsInfo&)
 {
     IpIdModule* m = (IpIdModule*)p;
     return new IpIdOption(m->data);
index d4a9c373fed9afab585e5c00870eeb45ee91a17b..21cd2f0fe78708a59cd4321c977de4be301409e8 100644 (file)
@@ -259,7 +259,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* ip_proto_ctor(Module* p, OptTreeNode*)
+static IpsOption* ip_proto_ctor(Module* p, IpsInfo&)
 {
     IpProtoModule* m = (IpProtoModule*)p;
     return new IpProtoOption(m->data);
index 109d1536fe85399ed049e6d9ac35f908915f8733..24e72bbeedce9eba4d4187cf564a4e4f60c6d268 100644 (file)
@@ -236,7 +236,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* ipopts_ctor(Module* p, OptTreeNode*)
+static IpsOption* ipopts_ctor(Module* p, IpsInfo&)
 {
     IpOptModule* m = (IpOptModule*)p;
     return new IpOptOption(m->data);
index 07685ae70fe45b6e3d46dd09226fe318f83a0134..91846bc772002f3c0825ce0ee80ac344e04dfcc2 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <cstdlib>
 
+#include "detection/extract.h"
 #include "framework/cursor.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -47,8 +48,6 @@
 #include "profiler/profiler.h"
 #include "utils/snort_bounds.h"
 
-#include "extract.h"
-
 using namespace snort;
 
 #define s_name "isdataat"
@@ -280,7 +279,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* isdataat_ctor(Module* p, OptTreeNode*)
+static IpsOption* isdataat_ctor(Module* p, IpsInfo&)
 {
     IsDataAtModule* m = (IsDataAtModule*)p;
     return new IsDataAtOption(m->data);
index 62326085700ca9b3ac79390845962a6e206e3909..42f76274ad7f9d2b482ac1667e64793118366309 100644 (file)
@@ -150,7 +150,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* itype_ctor(Module* p, OptTreeNode*)
+static IpsOption* itype_ctor(Module* p, IpsInfo&)
 {
     ItypeModule* m = (ItypeModule*)p;
     return new IcmpTypeOption(m->data);
index bf3d48d67d7053a39fd3738ce349293547b0b8b9..d27bce9dd12d117902f5cfe099c598e7f6304c9a 100644 (file)
@@ -87,7 +87,7 @@ static Module* mod_ctor()
 static void mod_dtor(Module* m)
 { delete m; }
 
-static IpsOption* js_data_ctor(Module*, OptTreeNode*)
+static IpsOption* js_data_ctor(Module*, IpsInfo&)
 { return new JSDataOption; }
 
 static void js_data_dtor(IpsOption* opt)
index 654c355a8da5a337fc82c5cc31d5d16ba475776b..49afe0bf7e2dbc547e704cb3a4245c6b0881d3be 100644 (file)
@@ -25,7 +25,6 @@
 #include "framework/decode_data.h"
 #include "framework/module.h"
 #include "hash/hash_key_operations.h"
-#include "helpers/chunk.h"
 #include "lua/lua.h"
 #include "log/messages.h"
 #include "main/thread_config.h"
@@ -34,6 +33,7 @@
 #include "managers/plugin_manager.h"
 #include "managers/script_manager.h"
 #include "profiler/profiler.h"
+#include "utils/chunk.h"
 #include "utils/util.h"
 
 using namespace snort;
@@ -211,7 +211,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, struct OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, struct IpsInfo&)
 {
     const char* key = IpsManager::get_option_keyword();
     std::string* chunk = ScriptManager::get_chunk(key);
index 47b7eeec7dc27a3b494537ee6fd7234937ccf048..5868e579b6653bece54b36ea6c5a71ef650fbad2 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -91,11 +90,13 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* metadata_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* metadata_ctor(Module* p, IpsInfo& info)
 {
     MetadataModule* m = (MetadataModule*)p;
+
     if ( m->match )
-        otn->set_metadata_match();
+        IpsOption::set_metadata_match(info);
+
     return nullptr;
 }
 
@@ -124,5 +125,13 @@ static const IpsApi metadata_api =
     nullptr
 };
 
-const BaseApi* ips_metadata = &metadata_api.base;
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* ips_metadata[] =
+#endif
+{
+    &metadata_api.base,
+    nullptr
+};
 
index 4b2b850dddc6d8e41a864045b320164b3adc04fe..a49eccc3ea2115a1decb243667891b6b710d7eea 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -80,10 +79,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* msg_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* msg_ctor(Module* p, IpsInfo& info)
 {
     MsgModule* m = (MsgModule*)p;
-    otn->sigInfo.message = m->msg;
+    IpsOption::set_message(info, m->msg.c_str());
     return nullptr;
 }
 
index e6cdd3713e34027886fbe6fad06ac2bcad731a96..9181aea05c9c24c828c1bf67f79931e81f4de8f3 100644 (file)
 
 using namespace snort;
 
-extern const BaseApi* ips_classtype;
-extern const BaseApi* ips_content;
-extern const BaseApi* ips_detection_filter;
-extern const BaseApi* ips_dsize;
-extern const BaseApi* ips_file_data;
-extern const BaseApi* ips_file_meta;
-extern const BaseApi* ips_flow;
-extern const BaseApi* ips_flowbits;
-extern const BaseApi* ips_js_data;
-extern const BaseApi* ips_md5;
-extern const BaseApi* ips_metadata;
-extern const BaseApi* ips_pkt_data;
-extern const BaseApi* ips_reference;
-extern const BaseApi* ips_replace;
-extern const BaseApi* ips_service;
-extern const BaseApi* ips_sha256;
-extern const BaseApi* ips_sha512;
-extern const BaseApi* ips_so;
-extern const BaseApi* ips_vba_data;
+// these have various dependencies:
+extern const BaseApi* ips_detection_filter[]; // perf stats 
+extern const BaseApi* ips_flowbits[];         // public methods like flowbits_setter
+extern const BaseApi* ips_replace[];          // needs snort::SFDAQ::can_replace
+extern const BaseApi* ips_so[];               // needs SO manager
+extern const BaseApi* ips_vba_data[];         // FIXIT-L some trace dependency
 
 #ifdef STATIC_IPS_OPTIONS
 extern const BaseApi* ips_ack[];
 extern const BaseApi* ips_base64[];
 extern const BaseApi* ips_ber_data[];
 extern const BaseApi* ips_ber_skip[];
+extern const BaseApi* ips_bufferlen[];
 extern const BaseApi* ips_byte_extract[];
 extern const BaseApi* ips_byte_jump[];
 extern const BaseApi* ips_byte_math[];
 extern const BaseApi* ips_byte_test[];
+extern const BaseApi* ips_classtype[];
+extern const BaseApi* ips_content[];
 extern const BaseApi* ips_cvs[];
+extern const BaseApi* ips_dsize[];
 extern const BaseApi* ips_enable[];
+extern const BaseApi* ips_file_data[];
+extern const BaseApi* ips_file_meta[];
 extern const BaseApi* ips_file_type[];
 extern const BaseApi* ips_flags[];
+extern const BaseApi* ips_flow[];
 extern const BaseApi* ips_fragbits[];
 extern const BaseApi* ips_fragoffset[];
 extern const BaseApi* ips_gid[];
+extern const BaseApi* ips_hash[];
 extern const BaseApi* ips_icmp_id[];
 extern const BaseApi* ips_icmp_seq[];
 extern const BaseApi* ips_icode[];
@@ -71,72 +66,65 @@ extern const BaseApi* ips_ipopts[];
 extern const BaseApi* ips_ip_proto[];
 extern const BaseApi* ips_isdataat[];
 extern const BaseApi* ips_itype[];
+extern const BaseApi* ips_js_data[];
+extern const BaseApi* ips_metadata[];
 extern const BaseApi* ips_msg[];
 extern const BaseApi* ips_pcre[];
+extern const BaseApi* ips_pkt_data[];
 extern const BaseApi* ips_priority[];
 extern const BaseApi* ips_raw_data[];
+extern const BaseApi* ips_reference[];
 extern const BaseApi* ips_rem[];
 extern const BaseApi* ips_rev[];
 extern const BaseApi* ips_rpc[];
 extern const BaseApi* ips_seq[];
+extern const BaseApi* ips_service[];
 extern const BaseApi* ips_sid[];
 extern const BaseApi* ips_soid[];
 extern const BaseApi* ips_target[];
 extern const BaseApi* ips_tag[];
 extern const BaseApi* ips_tos[];
 extern const BaseApi* ips_ttl[];
-extern const BaseApi* ips_bufferlen[];
 extern const BaseApi* ips_window[];
+
 #ifdef HAVE_HYPERSCAN
 extern const BaseApi* ips_regex[];
 extern const BaseApi* ips_sd_pattern[];
 #endif
 #endif
 
-static const BaseApi* ips_options[] =
-{
-    ips_classtype,
-    ips_content,
-    ips_detection_filter,
-    ips_dsize,
-    ips_file_data,
-    ips_file_meta,
-    ips_flow,
-    ips_flowbits,
-    ips_js_data,
-    ips_md5,
-    ips_metadata,
-    ips_pkt_data,
-    ips_reference,
-    ips_replace,
-    ips_service,
-    ips_sha256,
-    ips_sha512,
-    ips_so,
-    ips_vba_data,
-    nullptr
-};
-
 void load_ips_options()
 {
-    PluginManager::load_plugins(ips_options);
+    PluginManager::load_plugins(ips_detection_filter);
+    PluginManager::load_plugins(ips_flowbits);
+    PluginManager::load_plugins(ips_replace);
+    PluginManager::load_plugins(ips_so);
+    PluginManager::load_plugins(ips_vba_data);
 
 #ifdef STATIC_IPS_OPTIONS
+    PluginManager::load_plugins(ips_content);
     PluginManager::load_plugins(ips_ack);
     PluginManager::load_plugins(ips_base64);
     PluginManager::load_plugins(ips_ber_data);
     PluginManager::load_plugins(ips_ber_skip);
+    PluginManager::load_plugins(ips_bufferlen);
     PluginManager::load_plugins(ips_byte_extract);
     PluginManager::load_plugins(ips_byte_jump);
     PluginManager::load_plugins(ips_byte_math);
     PluginManager::load_plugins(ips_byte_test);
+    PluginManager::load_plugins(ips_classtype);
     PluginManager::load_plugins(ips_cvs);
+    PluginManager::load_plugins(ips_dsize);
     PluginManager::load_plugins(ips_enable);
+    PluginManager::load_plugins(ips_file_data);
+    PluginManager::load_plugins(ips_file_meta);
     PluginManager::load_plugins(ips_file_type);
     PluginManager::load_plugins(ips_flags);
+    PluginManager::load_plugins(ips_flow);
     PluginManager::load_plugins(ips_fragbits);
     PluginManager::load_plugins(ips_fragoffset);
     PluginManager::load_plugins(ips_gid);
+    PluginManager::load_plugins(ips_hash);
     PluginManager::load_plugins(ips_icmp_id);
     PluginManager::load_plugins(ips_icmp_seq);
     PluginManager::load_plugins(ips_icode);
@@ -145,21 +133,25 @@ void load_ips_options()
     PluginManager::load_plugins(ips_ip_proto);
     PluginManager::load_plugins(ips_isdataat);
     PluginManager::load_plugins(ips_itype);
+    PluginManager::load_plugins(ips_js_data);
+    PluginManager::load_plugins(ips_metadata);
     PluginManager::load_plugins(ips_msg);
     PluginManager::load_plugins(ips_pcre);
+    PluginManager::load_plugins(ips_pkt_data);
     PluginManager::load_plugins(ips_priority);
     PluginManager::load_plugins(ips_raw_data);
+    PluginManager::load_plugins(ips_reference);
     PluginManager::load_plugins(ips_rem);
     PluginManager::load_plugins(ips_rev);
     PluginManager::load_plugins(ips_rpc);
     PluginManager::load_plugins(ips_seq);
+    PluginManager::load_plugins(ips_service);
     PluginManager::load_plugins(ips_sid);
     PluginManager::load_plugins(ips_soid);
     PluginManager::load_plugins(ips_target);
     PluginManager::load_plugins(ips_tag);
     PluginManager::load_plugins(ips_tos);
     PluginManager::load_plugins(ips_ttl);
-    PluginManager::load_plugins(ips_bufferlen);
     PluginManager::load_plugins(ips_window);
 #ifdef HAVE_HYPERSCAN
     PluginManager::load_plugins(ips_regex);
index 56c063706521ccc3eeec53f1a8ac12767ded952a..731fef9ed2db7f55cafd4db653ac358c68a8b924 100644 (file)
@@ -32,6 +32,7 @@
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "framework/parameter.h"
+#include "framework/pig_pen.h"
 #include "hash/hash_key_operations.h"
 #include "helpers/scratch_allocator.h"
 #include "log/messages.h"
@@ -39,6 +40,7 @@
 #include "managers/ips_manager.h"
 #include "managers/module_manager.h"
 #include "profiler/profiler.h"
+#include "utils/stats.h"
 #include "utils/util.h"
 
 using namespace snort;
@@ -88,6 +90,40 @@ static ScratchAllocator* scratcher = nullptr;
 
 static THREAD_LOCAL ProfileStats pcrePerfStats;
 
+//-------------------------------------------------------------------------
+// stats foo
+//-------------------------------------------------------------------------
+
+struct PcreStats
+{
+    PegCount pcre_rules;
+#ifdef HAVE_HYPERSCAN
+    PegCount pcre_to_hyper;
+#endif
+    PegCount pcre_native;
+    PegCount pcre_negated;
+    PegCount pcre_match_limit;
+    PegCount pcre_recursion_limit;
+    PegCount pcre_error;
+};
+
+const PegInfo pcre_pegs[] =
+{
+    { CountType::SUM, "pcre_rules", "total rules processed with pcre option" },
+#ifdef HAVE_HYPERSCAN
+    { CountType::SUM, "pcre_to_hyper", "total pcre rules by hyperscan engine" },
+#endif
+    { CountType::SUM, "pcre_native", "total pcre rules compiled by pcre engine" },
+    { CountType::SUM, "pcre_negated", "total pcre rules using negation syntax" },
+    { CountType::SUM, "pcre_match_limit", "total number of times pcre hit the match limit" },
+    { CountType::SUM, "pcre_recursion_limit", "total number of times pcre hit the recursion limit" },
+    { CountType::SUM, "pcre_error", "total number of times pcre returns error" },
+
+    { CountType::END, nullptr, nullptr }
+};
+
+PcreStats pcre_stats;
+
 //-------------------------------------------------------------------------
 // implementation foo
 //-------------------------------------------------------------------------
@@ -398,17 +434,17 @@ static bool pcre_search(
     }
     else if (result == PCRE_ERROR_MATCHLIMIT)
     {
-        pc.pcre_match_limit++;
+        pcre_stats.pcre_match_limit++;
         matched = false;
     }
     else if (result == PCRE_ERROR_RECURSIONLIMIT)
     {
-        pc.pcre_recursion_limit++;
+        pcre_stats.pcre_recursion_limit++;
         matched = false;
     }
     else
     {
-        pc.pcre_error++;
+        pcre_stats.pcre_error++;
         return false;
     }
 
@@ -444,7 +480,7 @@ public:
     { return (config->options & SNORT_PCRE_RELATIVE) != 0; }
 
     EvalStatus eval(Cursor&, Packet*) override;
-    bool retry(Cursor&, const Cursor&) override;
+    bool retry(Cursor&) override;
 
     PcreData* get_data()
     { return config; }
@@ -595,7 +631,7 @@ IpsOption::EvalStatus PcreOption::eval(Cursor& c, Packet* p)
 // using content, but more advanced pcre won't work for the relative /
 // overlap case.
 
-bool PcreOption::retry(Cursor&, const Cursor&)
+bool PcreOption::retry(Cursor&)
 {
     if ((config->options & (SNORT_PCRE_INVERT | SNORT_PCRE_ANCHORED)))
     {
@@ -616,29 +652,6 @@ static const Parameter s_params[] =
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-struct PcreStats
-{
-    PegCount pcre_rules;
-#ifdef HAVE_HYPERSCAN
-    PegCount pcre_to_hyper;
-#endif
-    PegCount pcre_native;
-    PegCount pcre_negated;
-};
-
-const PegInfo pcre_pegs[] =
-{
-    { CountType::SUM, "pcre_rules", "total rules processed with pcre option" },
-#ifdef HAVE_HYPERSCAN
-    { CountType::SUM, "pcre_to_hyper", "total pcre rules by hyperscan engine" },
-#endif
-    { CountType::SUM, "pcre_native", "total pcre rules compiled by pcre engine" },
-    { CountType::SUM, "pcre_negated", "total pcre rules using negation syntax" },
-    { CountType::END, nullptr, nullptr }
-};
-
-PcreStats pcre_stats;
-
 #define s_help \
     "rule option for matching payload data with pcre"
 
@@ -785,7 +798,7 @@ static Module* mod_ctor()
 static void mod_dtor(Module* m)
 { delete m; }
 
-static IpsOption* pcre_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* pcre_ctor(Module* p, IpsInfo& info)
 {
     pcre_stats.pcre_rules++;
     PcreModule* m = (PcreModule*)p;
@@ -796,11 +809,11 @@ static IpsOption* pcre_ctor(Module* p, OptTreeNode* otn)
     {
         pcre_stats.pcre_to_hyper++;
         const IpsApi* opt_api = IpsManager::get_option_api(mod_regex_name);
-        return opt_api->ctor(mod_regex, otn);
+        return opt_api->ctor(mod_regex, info);
     }
     else
 #else
-    UNUSED(otn);
+    UNUSED(info);
 #endif
     {
         pcre_stats.pcre_native++;
index 2efb8c28752822883e1992b9f9a04957fbcc4e1f..74aaf7c21b2f06a156ea276e4f85f7ad7694ab46 100644 (file)
@@ -89,7 +89,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* pkt_data_ctor(Module*, OptTreeNode*)
+static IpsOption* pkt_data_ctor(Module*, IpsInfo&)
 {
     return new PktDataOption;
 }
@@ -124,5 +124,13 @@ static const IpsApi pkt_data_api =
     nullptr
 };
 
-const BaseApi* ips_pkt_data = &pkt_data_api.base;
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* ips_pkt_data[] =
+#endif
+{
+    &pkt_data_api.base,
+    nullptr
+};
 
index c27ad0b201e7b9842ff43cc788414f56e7c0a327..a1256dd28c6fdeda5479ee5cbaf3cee8fe92a8e1 100644 (file)
@@ -55,7 +55,7 @@ public:
     { return DETECT; }
 
 public:
-    int priority = 0;
+    uint32_t priority = 0;
 };
 
 bool PriorityModule::set(const char*, Value& v, SnortConfig*)
@@ -79,10 +79,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* priority_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* priority_ctor(Module* p, IpsInfo& info)
 {
     PriorityModule* m = (PriorityModule*)p;
-    otn->sigInfo.priority = m->priority;
+    IpsOption::set_priority(info, m->priority);
     return nullptr;
 }
 
index 669f3cf66805a4b318c638a84729f65142fa3a4c..e76ebc70c29b153a040ddadfb86e1e7f9e2e6acb 100644 (file)
@@ -86,7 +86,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* raw_data_ctor(Module*, OptTreeNode*)
+static IpsOption* raw_data_ctor(Module*, IpsInfo&)
 {
     return new RawDataOption;
 }
index d25edf83acee2ab2e440bd0076b2c5d2c0619eaf..cad93069f5db0e3e18633b6d043eacc9fbe40fff 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -59,14 +58,12 @@ public:
 public:
     std::string scheme;
     std::string id;
-    SnortConfig* snort_config = nullptr;
 };
 
-bool ReferenceModule::begin(const char*, int, SnortConfig* sc)
+bool ReferenceModule::begin(const char*, int, SnortConfig*)
 {
     scheme.clear();
     id.clear();
-    snort_config = sc;
     return true;
 }
 
@@ -100,10 +97,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* reference_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* reference_ctor(Module* p, IpsInfo& info)
 {
     ReferenceModule* m = (ReferenceModule*)p;
-    add_reference(m->snort_config, otn, m->scheme, m->id);
+    IpsOption::add_reference(info, m->scheme.c_str(), m->id.c_str());
     return nullptr;
 }
 
@@ -132,5 +129,13 @@ static const IpsApi reference_api =
     nullptr
 };
 
-const BaseApi* ips_reference = &reference_api.base;
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* ips_reference[] =
+#endif
+{
+    &reference_api.base,
+    nullptr
+};
 
index 16236b2e806bebb19c45d3755444fd9594b1c0d9..8221b7ffabdd4bc4147a6e0adabe683770e2e165 100644 (file)
@@ -29,7 +29,6 @@
 #include <cassert>
 
 #include "detection/pattern_match_data.h"
-#include "detection/treenodes.h"
 #include "framework/cursor.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -87,7 +86,7 @@ public:
     bool is_relative() override
     { return config.pmd.is_relative(); }
 
-    bool retry(Cursor&, const Cursor&) override;
+    bool retry(Cursor&) override;
 
     PatternMatchData* get_pattern(SnortProtocolId, RuleDirection) override
     { return &config.pmd; }
@@ -145,11 +144,14 @@ bool RegexOption::operator==(const IpsOption& ips) const
     return false;
 }
 
+namespace
+{
 struct ScanContext
 {
     unsigned index;
     bool found = false;
 };
+}
 
 static int hs_match(
     unsigned int /*id*/, unsigned long long /*from*/, unsigned long long to,
@@ -190,7 +192,7 @@ IpsOption::EvalStatus RegexOption::eval(Cursor& c, Packet*)
     return NO_MATCH;
 }
 
-bool RegexOption::retry(Cursor&, const Cursor&)
+bool RegexOption::retry(Cursor&)
 { return !is_relative(); }
 
 //-------------------------------------------------------------------------
@@ -405,7 +407,7 @@ static Module* mod_ctor()
 static void mod_dtor(Module* p)
 { delete p; }
 
-static IpsOption* regex_ctor(Module* m, OptTreeNode*)
+static IpsOption* regex_ctor(Module* m, IpsInfo&)
 {
     RegexModule* mod = (RegexModule*)m;
     RegexConfig c;
index 1efb89c0403760721c42d985c2261469e5c285e3..2d304aefd2a8c4ff9455d994b7984cc053d6575c 100644 (file)
@@ -67,7 +67,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* rem_ctor(Module*, OptTreeNode*)
+static IpsOption* rem_ctor(Module*, IpsInfo&)
 {
     return nullptr;
 }
index b5655bd8e1829c9e165838e7463c5805384a4b12..6cd63d53747663ab8b63b5bf36e11e812c1d92bb 100644 (file)
@@ -23,7 +23,6 @@
 #endif
 
 #include "detection/detection_engine.h"
-#include "detection/treenodes.h"
 #include "framework/cursor.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -240,7 +239,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* replace_ctor(Module* p, OptTreeNode*)
+static IpsOption* replace_ctor(Module* p, IpsInfo&)
 {
     ReplModule* m = (ReplModule*)p;
     return new ReplaceOption(m->data);
index 876dd81211d49cd4e746d951a47b4cd54fca5f56..2eeb3851d13f7128550f0b93fbaaa89869922183 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -79,10 +78,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* rev_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* rev_ctor(Module* p, IpsInfo& info)
 {
     RevModule* m = (RevModule*)p;
-    otn->sigInfo.rev = m->rev;
+    IpsOption::set_rev(info, m->rev);
     return nullptr;
 }
 
index d019ac57c115735135e57cff9cd08395cf90bd24..5b26f0f2fd23d4ee4cd311d203369e31b1f3719b 100644 (file)
@@ -310,7 +310,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* rpc_ctor(Module* p, OptTreeNode*)
+static IpsOption* rpc_ctor(Module* p, IpsInfo&)
 {
     RpcModule* m = (RpcModule*)p;
     return new RpcOption(m->data);
index 371653016d6aadc5ee0ea01b2c12b3e40f16bf76..f02dc7443d45f237f341daa91dd5c15c01d9d687 100644 (file)
@@ -29,7 +29,6 @@
 #include <hs_runtime.h>
 
 #include "detection/pattern_match_data.h"
-#include "detection/treenodes.h"
 #include "framework/cursor.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -488,7 +487,7 @@ static void mod_dtor(Module* p)
     delete p;
 }
 
-static IpsOption* sd_pattern_ctor(Module* m, OptTreeNode*)
+static IpsOption* sd_pattern_ctor(Module* m, IpsInfo&)
 {
     SdPatternModule* mod = (SdPatternModule*)m;
     SdPatternConfig c;
index c7fccac5c2af68ec6f909ff797f6566ef1bd3811..593e330f9db7faf5e69342c990497d9e37d48216 100644 (file)
@@ -149,7 +149,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* seq_ctor(Module* p, OptTreeNode*)
+static IpsOption* seq_ctor(Module* p, IpsInfo&)
 {
     SeqModule* m = (SeqModule*)p;
     return new TcpSeqOption(m->data);
index 7d47181299d906038ec648a2812dc2e49495a20a..13c55424987495146167de810182e92dba6085af 100644 (file)
@@ -50,8 +50,7 @@ static const Parameter s_params[] =
 class ServiceModule : public Module
 {
 public:
-    ServiceModule() : Module(s_name, s_help, s_params)
-    { snort_config = nullptr; }
+    ServiceModule() : Module(s_name, s_help, s_params) { }
 
     bool set(const char*, Value&, SnortConfig*) override;
     bool begin(const char*, int, SnortConfig*) override;
@@ -60,13 +59,11 @@ public:
     { return DETECT; }
 
 public:
-    struct SnortConfig* snort_config;
     vector<string> services;
 };
 
-bool ServiceModule::begin(const char*, int, SnortConfig* sc)
+bool ServiceModule::begin(const char*, int, SnortConfig*)
 {
-    snort_config = sc;
     services.clear();
     return true;
 }
@@ -99,12 +96,12 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* service_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* service_ctor(Module* p, IpsInfo& info)
 {
     ServiceModule* m = (ServiceModule*)p;
 
     for ( const auto& service : m->services )
-        add_service_to_otn(m->snort_config, otn, service.c_str());
+        IpsOption::add_service(info, service.c_str());
 
     return nullptr;
 }
@@ -134,5 +131,13 @@ static const IpsApi service_api =
     nullptr
 };
 
-const BaseApi* ips_service = &service_api.base;
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* ips_service[] =
+#endif
+{
+    &service_api.base,
+    nullptr
+};
 
index d4572622bb95d596ae7ea6d85290f96fbebe59a5..6e9f8dff196be54c685fa0e0d08dc4fc4ab7e68a 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -79,10 +78,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* sid_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* sid_ctor(Module* p, IpsInfo& info)
 {
     SidModule* m = (SidModule*)p;
-    otn->sigInfo.sid = m->sid;
+    IpsOption::set_sid(info, m->sid);
     return nullptr;
 }
 
index 41ecb353bc3b84ba932013ecf79c8141941256b2..4f309d3825b73acbdca6e18f407843990f6a6f16 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "framework/so_rule.h"
@@ -41,7 +40,7 @@ static THREAD_LOCAL ProfileStats soPerfStats;
 class SoOption : public IpsOption
 {
 public:
-    SoOption(const char*, const char*, bool, SoEvalFunc f, void* v, SnortConfig*);
+    SoOption(const char*, const char*, bool, SoEvalFunc f, void* v, SoRules*);
     ~SoOption() override;
 
     uint32_t hash() const override;
@@ -65,7 +64,7 @@ private:
 };
 
 SoOption::SoOption(
-    const char* id, const char* s, bool r, SoEvalFunc f, void* v, SnortConfig* sc)
+    const char* id, const char* s, bool r, SoEvalFunc f, void* v, SoRules* sos)
     : IpsOption(s_name)
 {
     soid = id;
@@ -73,7 +72,7 @@ SoOption::SoOption(
     relative_flag = r;
     func = f;
     data = v;
-    so_rules = sc->so_rules;
+    so_rules = sos;
 }
 
 SoOption::~SoOption()
@@ -151,14 +150,12 @@ public:
 public:
     string name;
     bool relative_flag = false;
-    SnortConfig* cfg = nullptr;
 };
 
-bool SoModule::begin(const char*, int, SnortConfig* sc)
+bool SoModule::begin(const char*, int, SnortConfig*)
 {
     name.clear();
     relative_flag = false;
-    cfg = sc;
     return true;
 }
 
@@ -187,26 +184,29 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* so_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* so_ctor(Module* p, IpsInfo& info)
 {
     void* data = nullptr;
     SoModule* m = (SoModule*)p;
     const char* name = m->name.c_str();
     bool relative_flag = m->relative_flag;
+    const char* soid = IpsOption::get_soid(info);
 
-    if ( !otn->soid )
+    if ( !soid )
     {
         ParseError("no soid before so:%s", name);
         return nullptr;
     }
-    SoEvalFunc func = SoManager::get_so_eval(otn->soid, name, &data, m->cfg);
+    SoEvalFunc func = IpsOption::get_so_eval(info, name, data);
 
     if ( !func )
     {
         ParseError("can't link so:%s", name);
         return nullptr;
     }
-    return new SoOption(otn->soid, name, relative_flag, func, data, m->cfg);
+    SoRules* sos = IpsOption::get_so_rules(info);
+
+    return new SoOption(soid, name, relative_flag, func, data, sos);
 }
 
 static void so_dtor(IpsOption* p)
@@ -239,5 +239,9 @@ static const IpsApi so_api =
     nullptr
 };
 
-const BaseApi* ips_so = &so_api.base;
+const BaseApi* ips_so[] =
+{
+    &so_api.base,
+    nullptr
+};
 
index e8d668dc5fcb544a6039787f567ce51c0bd32e94..4c78d57b3f697e9248521d1ac1df9fc3a4e0fe5d 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -80,10 +79,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* soid_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* soid_ctor(Module* p, IpsInfo& info)
 {
     SoidModule* m = (SoidModule*)p;
-    otn->soid = snort_strdup(m->soid.c_str());
+    IpsOption::set_soid(info, m->soid.c_str());
     return nullptr;
 }
 
index 2e0be3fe1687558a7075e26da2241094a013b815..6495f10e714beaf12734b050c821ba5b04aa963c 100644 (file)
@@ -23,7 +23,6 @@
 #endif
 
 #include "detection/tag.h"
-#include "detection/treenodes.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -154,10 +153,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* tag_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* tag_ctor(Module* p, IpsInfo& info)
 {
     TagModule* m = (TagModule*)p;
-    otn->tag = m->get_data();
+    IpsOption::set_tag(info, m->get_data());
     return nullptr;
 }
 
index 29d38ac26aa5da6b03c971f847810e7af819cf93..c7d2f75799d3fd78cd52b822c46ca547576c2123 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #endif
 
-#include "detection/treenodes.h"
 #include "framework/decode_data.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
@@ -55,14 +54,13 @@ public:
     { return DETECT; }
 
 public:
-    Target target = Target::TARGET_NONE;
+    bool target = false;
 };
 
 bool TargetModule::set(const char*, Value& v, SnortConfig*)
 {
     assert(v.is("~"));
-    assert(v.get_uint8() <= TARGET_MAX);
-    target = static_cast<Target>(v.get_uint8() + 1);
+    target = v.get_uint8() ? false : true;
     return true;
 }
 
@@ -80,10 +78,10 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* target_ctor(Module* p, OptTreeNode* otn)
+static IpsOption* target_ctor(Module* p, IpsInfo& info)
 {
     TargetModule* m = (TargetModule*)p;
-    otn->sigInfo.target = m->target;
+    IpsOption::set_target(info, m->target);
     return nullptr;
 }
 
index e4daa8d6caf0b42bd28c9ff64b73bda46f934824..ccf0c3d610a6a607c0b9561e17558e4345899802 100644 (file)
@@ -152,7 +152,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* tos_ctor(Module* p, OptTreeNode*)
+static IpsOption* tos_ctor(Module* p, IpsInfo&)
 {
     TosModule* m = (TosModule*)p;
     return new IpTosOption(m->data);
index 526a2372119d49a0a61029cb51697efc6b503877..422c59e5ecdf84f21cf5dfdc1728776b7a0adfb4 100644 (file)
@@ -149,7 +149,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* ttl_ctor(Module* p, OptTreeNode*)
+static IpsOption* ttl_ctor(Module* p, IpsInfo&)
 {
     TtlModule* m = (TtlModule*)p;
     return new TtlOption(m->data);
index 82753a30ed384a29b8d25fa42824a396e435f8e5..511ae18195e042e15dad5f4bd190dcdc78bb063d 100644 (file)
@@ -106,7 +106,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* vba_data_ctor(Module*, OptTreeNode*)
+static IpsOption* vba_data_ctor(Module*, IpsInfo&)
 {
     return new VbaDataOption;
 }
@@ -141,11 +141,7 @@ static const IpsApi vba_data_api =
     nullptr
 };
 
-#ifdef BUILDING_SO
-SO_PUBLIC const BaseApi* snort_plugins[] =
-#else
 const BaseApi* ips_vba_data[] =
-#endif
 {
     &vba_data_api.base,
     nullptr
index 1e79249eab0b97999fbb3c6495694f1001ead975..7e391e29448154122c6c8384e78f04d0948f94c7 100644 (file)
@@ -149,7 +149,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* window_ctor(Module* p, OptTreeNode*)
+static IpsOption* window_ctor(Module* p, IpsInfo&)
 {
     WindowModule* m = (WindowModule*)p;
     return new TcpWinOption(m->data);
index 7c2c4fb34ff5d23022085a8f972e3826e576a5bf..246876bd417829334d70f854afff71a2bec4be6a 100644 (file)
@@ -3,11 +3,11 @@ if ( HAVE_HYPERSCAN )
     add_cpputest( ips_regex_test
         SOURCES
             ../ips_regex.cc
-            ../../framework/module.cc
             ../../framework/ips_option.cc
+            ../../framework/module.cc
             ../../framework/value.cc
-            ../../helpers/scratch_allocator.cc
             ../../helpers/hyper_scratch_allocator.cc
+            ../../helpers/scratch_allocator.cc
             ../../sfip/sf_ip.cc
             $<TARGET_OBJECTS:catch_tests>
         LIBS
index f040d1ae7499c1d3c7daf1095bf50e0afaa9ecbf..97f33c3f4e67f08c973fd520cc4e4576b9bde5db 100644 (file)
 #include "framework/base_api.h"
 #include "framework/counts.h"
 #include "framework/cursor.h"
+#include "framework/ips_info.h"
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
 #include "main/thread_config.h"
+#include "managers/so_manager.h"
 #include "ports/port_group.h"
 #include "profiler/profiler_defs.h"
 #include "protocols/packet.h"
@@ -104,8 +106,6 @@ char* snort_strdup(const char* s)
 
 MemoryContext::MemoryContext(MemoryTracker&) { }
 MemoryContext::~MemoryContext() = default;
-
-THREAD_LOCAL bool TimeProfilerStats::enabled = false;
 }
 
 extern const BaseApi* ips_regex;
@@ -114,10 +114,34 @@ Cursor::Cursor(Packet* p)
 { set("pkt_data", p->data, p->dsize); }
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 OptTreeNode::~OptTreeNode() = default;
 
+SO_PUBLIC bool snort::otn_has_plugin(OptTreeNode*, const char*)
+{ return false; }
+
+const ClassType* get_classification(snort::SnortConfig*, const char*)
+{ return nullptr; }
+
+void add_classification(snort::SnortConfig*, const char*, const char*, unsigned)
+{ }
+
+struct THD_NODE* detection_filter_create(DetectionFilterConfig*, struct THDX_STRUCT*)
+{ return nullptr; }
+
+void add_reference(snort::SnortConfig*, OptTreeNode*, const std::string&, const std::string&)
+{ }
+
+void add_reference(IpsInfo&, const char*, const char*)
+{ }
+
+void add_service_to_otn(snort::SnortConfig*, OptTreeNode*, const char*)
+{ }
+
+SoEvalFunc SoManager::get_so_eval(const char*, const char*, void**, snort::SnortConfig*)
+{ return nullptr; }
+
 //-------------------------------------------------------------------------
 // helpers
 //-------------------------------------------------------------------------
@@ -145,10 +169,10 @@ static IpsOption* get_option(Module* mod, const char* pat)
     mod->set(ips_regex->name, vs, nullptr);
     mod->end(ips_regex->name, 0, nullptr);
 
-    OptTreeNode otn;
+    IpsInfo info(nullptr, nullptr);
 
     const IpsApi* api = (const IpsApi*) ips_regex;
-    IpsOption* opt = api->ctor(mod, &otn);
+    IpsOption* opt = api->ctor(mod, info);
 
     return opt;
 }
@@ -308,7 +332,7 @@ TEST(ips_regex_option, match_absolute)
     Cursor c(&pkt);
     CHECK(opt->eval(c, &pkt) == IpsOption::MATCH);
     CHECK(!strcmp((const char*) c.start(), " stew *"));
-    CHECK(opt->retry(c,c));
+    CHECK(opt->retry(c));
 }
 
 TEST(ips_regex_option, no_match_delta)
@@ -363,7 +387,7 @@ TEST(ips_regex_option_relative, no_match)
 
     CHECK(opt->is_relative());
     CHECK(opt->eval(c, &pkt) == IpsOption::NO_MATCH);
-    CHECK(!opt->retry(c,c));
+    CHECK(!opt->retry(c));
 }
 
 //-------------------------------------------------------------------------
index fecd9613b3d490735d0bef97db768c1ce124f7fd..9fb7c6e1e902f7556adc794bf66b849f84283b6b 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef JS_ENUM_H
 #define JS_ENUM_H
 
-#include "utils/event_gen.h"
+#include "helpers/event_gen.h"
 
 namespace jsn
 {
index 5c90cd20efadba26690a0721e357ea27fe698ec4..b3cf3aae531192cfb13d57ff8b2313995ec55b27 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef JS_NORM_H
 #define JS_NORM_H
 
-#include "utils/event_gen.h"
+#include "helpers/event_gen.h"
 
 #include "js_config.h"
 #include "js_enum.h"
index 63cbc663669f4c9325d97864ca81bf86b45b8605..911d255ac16f38721c6fe70c1c2759dd84ed1d6e 100644 (file)
 
 #include <FlexLexer.h>
 
+#include "helpers/streambuf.h"
 #include "js_tokenizer.h"
 
-#include "utils/streambuf.h"
-
 namespace jsn
 {
 
index 74b92f2e34ec0b1f35022a69a241b33cf4bfb56b..edc54fadffa84b866eaef1132aec8beab1be972b 100644 (file)
@@ -23,9 +23,9 @@
 #include <FlexLexer.h>
 #include <cstring>
 
+#include "helpers/streambuf.h"
 #include "js_norm/js_norm.h"
 #include "js_norm/pdf_tokenizer.h"
-#include "utils/streambuf.h"
 
 namespace snort
 {
index 66d0ff0b6d1882d91e8338e71128a9b5c161e27c..5ba935362318a72db0e3f92c5f632a7f6cafee5c 100644 (file)
@@ -13,7 +13,7 @@ add_catch_test( js_normalizer_test
         ${js_tokenizer_OUTPUTS}
         ../js_identifier_ctx.cc
         ../js_normalizer.cc
-        ${CMAKE_SOURCE_DIR}/src/utils/streambuf.cc
+        ${CMAKE_SOURCE_DIR}/src/helpers/streambuf.cc
         ${CMAKE_SOURCE_DIR}/src/utils/util_cstring.cc
         js_test_options.cc
         js_test_stubs.cc
@@ -25,7 +25,7 @@ add_catch_test( js_dealias_test
         ${js_tokenizer_OUTPUTS}
         ../js_identifier_ctx.cc
         ../js_normalizer.cc
-        ${CMAKE_SOURCE_DIR}/src/utils/streambuf.cc
+        ${CMAKE_SOURCE_DIR}/src/helpers/streambuf.cc
         ${CMAKE_SOURCE_DIR}/src/utils/util_cstring.cc
         js_test_options.cc
         js_test_stubs.cc
@@ -37,7 +37,7 @@ add_catch_test( js_unescape_test
         ${js_tokenizer_OUTPUTS}
         ../js_identifier_ctx.cc
         ../js_normalizer.cc
-        ${CMAKE_SOURCE_DIR}/src/utils/streambuf.cc
+        ${CMAKE_SOURCE_DIR}/src/helpers/streambuf.cc
         ${CMAKE_SOURCE_DIR}/src/utils/util_cstring.cc
         js_test_options.cc
         js_test_stubs.cc
@@ -56,7 +56,7 @@ add_catch_test( jsn_test
         ../js_identifier_ctx.cc
         ../js_norm.cc
         ../js_normalizer.cc
-        ${CMAKE_SOURCE_DIR}/src/utils/streambuf.cc
+        ${CMAKE_SOURCE_DIR}/src/helpers/streambuf.cc
         js_test_stubs.cc
 )
 
@@ -73,7 +73,7 @@ if (ENABLE_BENCHMARK_TESTS)
             ${js_tokenizer_OUTPUTS}
             ../js_identifier_ctx.cc
             ../js_normalizer.cc
-            ${CMAKE_SOURCE_DIR}/src/utils/streambuf.cc
+            ${CMAKE_SOURCE_DIR}/src/helpers/streambuf.cc
             ${CMAKE_SOURCE_DIR}/src/utils/util_cstring.cc
             js_test_options.cc
             js_test_stubs.cc
@@ -83,7 +83,7 @@ if (ENABLE_BENCHMARK_TESTS)
     add_catch_test( pdf_tokenizer_benchmark
         SOURCES
             ${pdf_tokenizer_OUTPUTS}
-            ${CMAKE_SOURCE_DIR}/src/utils/streambuf.cc
+            ${CMAKE_SOURCE_DIR}/src/helpers/streambuf.cc
             ${CMAKE_SOURCE_DIR}/src/utils/util_cstring.cc
             js_test_stubs.cc
     )
index c99162fda05dbb3f98a232f5aba54b17867b467e..f484fe1bd36c8724b1e4b4af340c29bc0dcc745e 100644 (file)
@@ -29,8 +29,8 @@
 #include <FlexLexer.h>
 
 #include "catch/catch.hpp"
+#include "helpers/streambuf.h"
 #include "js_norm/pdf_tokenizer.h"
-#include "utils/streambuf.h"
 
 using namespace jsn;
 using namespace snort;
index 0865d70666a37e78b4b4571544a8d53e1135c745..1ecb689d90dfa1539bf6fce0fd7254e794712252 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef LATENCY_STATS_H
 #define LATENCY_STATS_H
 
-#include "main/thread.h"
 #include "framework/counts.h"
 
 struct LatencyStats
index fffe97a96ccac67aa638ecb5009c726cfd60e931..7ba03f048520538304bcfd74d706c29d5d0d3ed0 100644 (file)
@@ -28,6 +28,7 @@
 #include "detection/detection_options.h"
 #include "detection/treenodes.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "log/messages.h"
 #include "protocols/packet.h"
 #include "utils/stats.h"
index 6a6209355254cf1e8a8b6d356ad892ae29480bfc..99de682d2c70e7c5625ff5021ac31effeb07fb81 100644 (file)
@@ -1,6 +1,6 @@
 
 set (LOG_INCLUDES
-    log.h
+    log_stats.h
     log_text.h
     messages.h
     obfuscator.h
@@ -12,6 +12,9 @@ set (LOG_INCLUDES
 add_library ( log OBJECT
     ${LOG_INCLUDES}
     log.cc
+    log.h
+    log_errors.h
+    log_stats.cc
     log_text.cc
     messages.cc
     obfuscator.cc
index 47b4cd083edf58b3f823ebcc5ae6e61b30985a60..d963f941af07b9b31e4fcfc311fddd10664aa009 100644 (file)
 
 #include "log.h"
 
+#include <netdb.h>
 #include <mutex>
 
+#include "main/thread.h"
 #include "protocols/packet.h"
-#include "protocols/tcp.h"
 #include "utils/util.h"
 #include "utils/util_cstring.h"
 
@@ -38,25 +39,6 @@ using namespace snort;
 
 #define DEFAULT_DAEMON_ALERT_FILE  "alert"
 
-namespace snort
-{
-// Input is packet and an nine-byte (including null) character array.  Results
-// are put into the character array.
-void CreateTCPFlagString(const tcp::TCPHdr* const tcph, char* flagBuffer)
-{
-    /* parse TCP flags */
-    *flagBuffer++ = (char)((tcph->th_flags & TH_RES1) ? '1' : '*');
-    *flagBuffer++ = (char)((tcph->th_flags & TH_RES2) ? '2' : '*');
-    *flagBuffer++ = (char)((tcph->th_flags & TH_URG)  ? 'U' : '*');
-    *flagBuffer++ = (char)((tcph->th_flags & TH_ACK)  ? 'A' : '*');
-    *flagBuffer++ = (char)((tcph->th_flags & TH_PUSH) ? 'P' : '*');
-    *flagBuffer++ = (char)((tcph->th_flags & TH_RST)  ? 'R' : '*');
-    *flagBuffer++ = (char)((tcph->th_flags & TH_SYN)  ? 'S' : '*');
-    *flagBuffer++ = (char)((tcph->th_flags & TH_FIN)  ? 'F' : '*');
-    *flagBuffer = '\0';
-}
-}
-
 /****************************************************************************
  *
  * Function: OpenAlertFile(char *)
@@ -172,3 +154,57 @@ void LogNetData(const uint8_t* data, const int len, Packet* p)
     log_mutex.unlock();
 }
 
+//--------------------------------------------------------------------
+// protocol translation
+//--------------------------------------------------------------------
+
+static char** protocol_names = nullptr;
+
+const char* get_protocol_name(uint8_t ip_proto)
+{
+    assert(protocol_names and protocol_names[ip_proto]);
+    return protocol_names[ip_proto];
+}
+
+void InitProtoNames()
+{
+    if ( !protocol_names )
+        protocol_names = (char**)snort_calloc(NUM_IP_PROTOS, sizeof(char*));
+
+    for ( int i = 0; i < NUM_IP_PROTOS; i++ )
+    {
+        struct protoent* pt = getprotobynumber(i);  // main thread only
+
+        if (pt != nullptr)
+        {
+            protocol_names[i] = snort_strdup(pt->p_name);
+
+            for ( size_t j = 0; j < strlen(protocol_names[i]); j++ )
+                protocol_names[i][j] = toupper(protocol_names[i][j]);
+        }
+        else
+        {
+            char protoname[10];
+            SnortSnprintf(protoname, sizeof(protoname), "PROTO:%03d", i);
+            protocol_names[i] = snort_strdup(protoname);
+        }
+    }
+}
+
+void CleanupProtoNames()
+{
+    if (protocol_names != nullptr)
+    {
+        int i;
+
+        for (i = 0; i < NUM_IP_PROTOS; i++)
+        {
+            if (protocol_names[i] != nullptr)
+                snort_free(protocol_names[i]);
+        }
+
+        snort_free(protocol_names);
+        protocol_names = nullptr;
+    }
+}
+
index 8fbd38f145c6e261c61a17535a31e1b545bd3206..937bc9cf3b70a2ca4b35d4b43164cfb109042a01 100644 (file)
 #ifndef LOG_H
 #define LOG_H
 
+// this is for legacy logging like stream_ip debug and stream_tcp show rebuilt.
+// it should not be used for new code. existing uses should be converted to the
+// trace logger system or directly call TextLog which this wraps.
+
 #include <cstdio>
 
 #include "main/snort_types.h"
 
 namespace snort
 {
-namespace tcp { struct TCPHdr; }
-struct Packet;
-
-SO_PUBLIC void CreateTCPFlagString(const tcp::TCPHdr* const, char*);
+    struct Packet;
 }
 
 FILE* OpenAlertFile(const char*, bool is_critical=true);
@@ -42,5 +43,10 @@ void LogIPPkt(snort::Packet*);
 void LogFlow(snort::Packet*);
 void LogNetData(const uint8_t* data, const int len, snort::Packet*);
 
+void InitProtoNames();
+void CleanupProtoNames();
+
+const char* get_protocol_name(uint8_t ip_proto);
+
 #endif
 
diff --git a/src/log/log_errors.h b/src/log/log_errors.h
new file mode 100644 (file)
index 0000000..b088058
--- /dev/null
@@ -0,0 +1,30 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2023 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.
+//--------------------------------------------------------------------------
+
+#ifndef LOG_ERRORS_H
+#define LOG_ERRORS_H
+
+void reset_parse_errors();
+unsigned get_parse_errors();
+unsigned get_parse_warnings();
+void reset_reload_errors();
+unsigned get_reload_errors();
+std::string& get_reload_errors_description();
+
+#endif
+
diff --git a/src/log/log_stats.cc b/src/log/log_stats.cc
new file mode 100644 (file)
index 0000000..2c05043
--- /dev/null
@@ -0,0 +1,114 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2023 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.
+//--------------------------------------------------------------------------
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "log_stats.h"
+
+#include "control/control.h"
+
+#include "messages.h"
+
+//using namespace snort;
+
+//-------------------------------------------------------------------------
+
+static THREAD_LOCAL ControlConn* s_ctrlcon = nullptr;
+
+void snort::set_log_conn(ControlConn* cc)
+{ s_ctrlcon = cc; }
+
+//-------------------------------------------------------------------------
+
+#define STATS_SEPARATOR \
+    "--------------------------------------------------"
+
+static inline void LogSeparator(FILE* fh = stdout)
+{
+    LogfRespond(s_ctrlcon, fh, "%s\n", STATS_SEPARATOR);
+}
+
+static double CalcPct(uint64_t cnt, uint64_t total)
+{
+    double pct = 0.0;
+
+    if (total == 0.0)
+    {
+        pct = (double)cnt;
+    }
+    else
+    {
+        pct = (double)cnt / (double)total;
+    }
+
+    pct *= 100.0;
+
+    return pct;
+}
+
+//-------------------------------------------------------------------------
+
+void snort::LogText(const char* s, FILE* fh)
+{
+    LogfRespond(s_ctrlcon, fh, "%s\n", s);
+}
+
+void snort::LogLabel(const char* s, FILE* fh)
+{
+    if ( *s == ' ' )
+    {
+        LogfRespond(s_ctrlcon, fh, "%s\n", s);
+    }
+    else
+    {
+        LogSeparator(fh);
+        LogfRespond(s_ctrlcon, fh, "%s\n", s);
+    }
+}
+
+void snort::LogValue(const char* s, const char* v, FILE* fh)
+{
+    LogfRespond(s_ctrlcon, fh, "%25.25s: %s\n", s, v);
+}
+
+void snort::LogCount(const char* s, uint64_t c, FILE* fh)
+{
+    if ( c )
+    {
+        LogfRespond(s_ctrlcon, fh, "%25.25s: " STDu64 "\n", s, c);
+    }
+}
+
+void snort::LogStat(const char* s, uint64_t n, uint64_t tot, FILE* fh)
+{
+    if ( n )
+    {
+        LogfRespond(s_ctrlcon, fh, "%25.25s: " FMTu64("-12") "\t(%7.3f%%)\n", s, n, CalcPct(n, tot));
+    }
+}
+
+void snort::LogStat(const char* s, double d, FILE* fh)
+{
+    if ( d )
+    {
+        LogfRespond(s_ctrlcon, fh, "%25.25s: %g\n", s, d);
+    }
+}
+
diff --git a/src/log/log_stats.h b/src/log/log_stats.h
new file mode 100644 (file)
index 0000000..6246cb2
--- /dev/null
@@ -0,0 +1,45 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2023 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.
+//--------------------------------------------------------------------------
+
+#ifndef LOG_STATS_H
+#define LOG_STATS_H
+
+// used for logging pegs
+
+#include <cstdint>
+#include <cstdio>
+
+#include "main/snort_types.h"
+
+class ControlConn;
+
+namespace snort
+{
+void set_log_conn(ControlConn*);
+
+SO_PUBLIC void LogLabel(const char*, FILE* = stdout);
+SO_PUBLIC void LogText(const char*, FILE* = stdout);
+SO_PUBLIC void LogValue(const char*, const char*, FILE* = stdout);
+SO_PUBLIC void LogCount(const char*, uint64_t, FILE* = stdout);
+
+SO_PUBLIC void LogStat(const char*, uint64_t n, uint64_t tot, FILE* = stdout);
+SO_PUBLIC void LogStat(const char*, double, FILE* = stdout);
+}
+
+#endif
+
index ab9f3f516115c5142816ccba220aab9d3c15544e..faf09fbdd820f7cd7b98a99ca3bb6f35cbbd49e7 100644 (file)
@@ -31,6 +31,7 @@
 #include "detection/detection_engine.h"
 #include "detection/signature.h"
 #include "events/event.h"
+#include "framework/pig_pen.h"
 #include "main/snort_config.h"
 #include "network_inspectors/appid/appid_api.h"
 #include "packet_io/sfdaq.h"
@@ -45,7 +46,6 @@
 #include "utils/util.h"
 #include "utils/util_net.h"
 
-#include "log.h"
 #include "messages.h"
 #include "obfuscator.h"
 
@@ -72,10 +72,12 @@ void LogTimeStamp(TextLog* log, Packet* p)
  */
 void LogPriorityData(TextLog* log, const Event& e)
 {
-    if ( e.sig_info->class_type and !e.sig_info->class_type->text.empty() )
-        TextLog_Print(log, "[Classification: %s] ", e.sig_info->class_type->text.c_str());
+    const char* ct = e.get_class_type();
 
-    TextLog_Print(log, "[Priority: %d] ", e.sig_info->priority);
+    if ( ct )
+        TextLog_Print(log, "[Classification: %s] ", ct);
+
+    TextLog_Print(log, "[Priority: %d] ", e.get_priority());
 }
 
 /*--------------------------------------------------------------------
@@ -343,13 +345,10 @@ void LogIPHeader(TextLog* log, Packet* p)
     {
         const ip::IP6Hdr* const ip6h = p->ptrs.ip_api.get_ip6h(); // nullptr if ipv4
         const ip::IP6Frag* const ip6_frag = layer::get_inner_ip6_frag();
+        const char* proto = PigPen::get_protocol_name(to_utype(p->get_ip_proto_next()));
 
         TextLog_Print(log, "%s TTL:%u TOS:0x%X ID:%u IpLen:%u DgmLen:%u",
-            protocol_names[to_utype(p->get_ip_proto_next())],
-            ip6h->hop_lim(),
-            ip6h->tos(),
-            (ip6_frag ? ip6_frag->id() : 0),
-            ip::IP6_HEADER_LEN,
+            proto, ip6h->hop_lim(), ip6h->tos(), (ip6_frag ? ip6_frag->id() : 0), ip::IP6_HEADER_LEN,
             (ip6h->len() + ip::IP6_HEADER_LEN));
 
         if (!ip6_frag)
@@ -369,13 +368,10 @@ void LogIPHeader(TextLog* log, Packet* p)
     }
     else
     {
+        const char* proto = PigPen::get_protocol_name(to_utype(ip4h->proto()));
+
         TextLog_Print(log, "%s TTL:%u TOS:0x%X ID:%u IpLen:%u DgmLen:%u",
-            protocol_names[to_utype(ip4h->proto())],
-            ip4h->ttl(),
-            ip4h->tos(),
-            ip4h->id(),
-            ip4h->hlen(),
-            ip4h->len());
+            proto, ip4h->ttl(), ip4h->tos(), ip4h->id(), ip4h->hlen(), ip4h->len());
 
         if (ip4h->rb())
             TextLog_Puts(log, " RB");
@@ -582,8 +578,8 @@ void LogTCPHeader(TextLog* log, Packet* p)
         return;
     }
     /* print TCP flags */
-    CreateTCPFlagString(tcph, tcpFlags);
-    TextLog_Puts(log, tcpFlags); /* We don't care about the null */
+    tcph->stringify_flags(tcpFlags);
+    TextLog_Puts(log, tcpFlags);
 
     /* print other TCP info */
     TextLog_Print(log, " Seq: 0x%lX  Ack: 0x%lX  Win: 0x%X  TcpLen: %d",
@@ -1024,7 +1020,9 @@ void LogICMPHeader(TextLog* log, Packet* p)
 
 void LogXrefs(TextLog* log, const Event& e)
 {
-    for ( const auto ref : e.sig_info->refs )
+    const SigInfo& sig_info = e.get_sig_info();
+
+    for ( const auto ref : sig_info.refs )
     {
         if ( !ref->system )
             TextLog_Print(log, "[Xref => %s]", ref->id.c_str());
index 92313def8257951085dc3a3c11821e23f6fe541a..14b4262f93ddfbc33fcbfdbe5bb0954ff43b9fd1 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "log/text_log.h"
 
-struct Event;
+class Event;
 
 namespace snort
 {
index c21f5140d7c9858d71ae6e115aac8c8f5a1ebc82..dbe5083b4b4aa109d0b40fd96ab4bfd570a6c6dc 100644 (file)
@@ -22,6 +22,7 @@
 #endif
 
 #include "messages.h"
+#include "log_errors.h"
 
 #include <syslog.h>
 
@@ -29,6 +30,7 @@
 #include <cstring>
 
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "parser/parser.h"
 #include "time/packet_time.h"
 #include "utils/util_cstring.h"
index 0e91f0cdabeffed5eb1a701b9d5bff914e21205c..33ec292dbf2a14374eb2083a1366772a278a2e46 100644 (file)
@@ -45,13 +45,6 @@ enum WarningGroup
     WARN_MAX
 };
 
-void reset_parse_errors();
-unsigned get_parse_errors();
-unsigned get_parse_warnings();
-void reset_reload_errors();
-unsigned get_reload_errors();
-std::string& get_reload_errors_description();
-
 namespace snort
 {
 SO_PUBLIC void ParseWarning(WarningGroup, const char*, ...) __attribute__((format (printf, 2, 3)));
index 22bc0e89a23f6e79f31ddb4970f2edd17bb25720..7a6a1b4f4b668dad935145ac3e8e87921f223bfb 100644 (file)
 
 #include "detection/detection_engine.h"
 #include "detection/ips_context.h"
-#include "detection/signature.h"
 #include "events/event.h"
 #include "flow/flow_key.h"
 #include "framework/logger.h"
 #include "framework/module.h"
 #include "helpers/base64_encoder.h"
-#include "log/log.h"
 #include "log/log_text.h"
 #include "log/text_log.h"
 #include "packet_io/active.h"
@@ -48,7 +46,6 @@
 #include "protocols/udp.h"
 #include "protocols/vlan.h"
 #include "protocols/geneve.h"
-#include "utils/stats.h"
 
 using namespace snort;
 using namespace std;
@@ -64,12 +61,15 @@ static THREAD_LOCAL TextLog* csv_log;
 // field formatting functions
 //-------------------------------------------------------------------------
 
+namespace
+{
 struct Args
 {
     Packet* pkt;
     const char* msg;
     const Event& event;
 };
+}
 
 static void ff_action(const Args& a)
 {
@@ -78,9 +78,8 @@ static void ff_action(const Args& a)
 
 static void ff_class(const Args& a)
 {
-    const char* cls = "none";
-    if ( a.event.sig_info->class_type and !a.event.sig_info->class_type->text.empty() )
-        cls = a.event.sig_info->class_type->text.c_str();
+    const char* cls = a.event.get_class_type();
+    if ( !cls ) cls = "none";
     TextLog_Puts(csv_log, cls);
 }
 
@@ -219,7 +218,7 @@ static void ff_geneve_vni(const Args& a)
 
 static void ff_gid(const Args& a)
 {
-    TextLog_Print(csv_log, "%u",  a.event.sig_info->gid);
+    TextLog_Print(csv_log, "%u",  a.event.get_gid());
 }
 
 static void ff_icmp_code(const Args& a)
@@ -304,7 +303,7 @@ static void ff_pkt_num(const Args& a)
 
 static void ff_priority(const Args& a)
 {
-    TextLog_Print(csv_log, "%u", a.event.sig_info->priority);
+    TextLog_Print(csv_log, "%u", a.event.get_priority());
 }
 
 static void ff_proto(const Args& a)
@@ -314,13 +313,14 @@ static void ff_proto(const Args& a)
 
 static void ff_rev(const Args& a)
 {
-    TextLog_Print(csv_log, "%u",  a.event.sig_info->rev);
+    TextLog_Print(csv_log, "%u",  a.event.get_rev());
 }
 
 static void ff_rule(const Args& a)
 {
-    TextLog_Print(csv_log, "%u:%u:%u",
-        a.event.sig_info->gid, a.event.sig_info->sid, a.event.sig_info->rev);
+    uint32_t gid, sid, rev;
+    a.event.get_sig_ids(gid, sid, rev);
+    TextLog_Print(csv_log, "%u:%u:%u", gid, sid, rev);
 }
 
 static void ff_seconds(const Args& a)
@@ -359,7 +359,7 @@ static void ff_sgt(const Args& a)
 
 static void ff_sid(const Args& a)
 {
-    TextLog_Print(csv_log, "%u",  a.event.sig_info->sid);
+    TextLog_Print(csv_log, "%u",  a.event.get_sid());
 }
 
 static void ff_src_addr(const Args& a)
@@ -394,15 +394,15 @@ static void ff_src_port(const Args& a)
 static void ff_target(const Args& a)
 {
     SfIpString addr = "";
+    bool src;
 
-    if ( a.event.sig_info->target == TARGET_SRC )
-        a.pkt->ptrs.ip_api.get_src()->ntop(addr);
-
-    else if ( a.event.sig_info->target == TARGET_DST )
-        a.pkt->ptrs.ip_api.get_dst()->ntop(addr);
+    if ( !a.event.get_target(src) )
+        return;
 
+    if ( src )
+        a.pkt->ptrs.ip_api.get_src()->ntop(addr);
     else
-        return;
+        a.pkt->ptrs.ip_api.get_dst()->ntop(addr);
 
     TextLog_Print(csv_log, "%s", addr);
 }
@@ -418,7 +418,7 @@ static void ff_tcp_flags(const Args& a)
     if (a.pkt->ptrs.tcph )
     {
         char tcpFlags[9];
-        CreateTCPFlagString(a.pkt->ptrs.tcph, tcpFlags);
+        a.pkt->ptrs.tcph->stringify_flags(tcpFlags);
         TextLog_Print(csv_log, "%s", tcpFlags);
     }
 }
index 40d98457a62a87d810eb9a0a356aa2f4974b8f71..cb2d4a30c0dc94cfb7ce566fbddf53f9a5cee880 100644 (file)
@@ -27,7 +27,6 @@
 #include <vector>
 
 #include "detection/detection_engine.h"
-#include "detection/signature.h"
 #include "events/event.h"
 #include "flow/flow.h"
 #include "flow/session.h"
@@ -303,8 +302,9 @@ void FastLogger::alert(Packet* p, const char* msg, const Event& event)
 
     TextLog_Puts(fast_log, " [**] ");
 
-    TextLog_Print(fast_log, "[%u:%u:%u] ",
-        event.sig_info->gid, event.sig_info->sid, event.sig_info->rev);
+    uint32_t gid, sid, rev;
+    event.get_sig_ids(gid, sid, rev);
+    TextLog_Print(fast_log, "[%u:%u:%u] ", gid, sid, rev);
 
     if (p->context->conf->alert_interface())
         TextLog_Print(fast_log, " <%s> ", SFDAQ::get_input_spec());
@@ -386,11 +386,11 @@ void FastLogger::log_data(Packet* p, const Event& event)
 
     const DataPointer& buf = DetectionEngine::get_alt_buffer(p);
 
-    if ( buf.len and event.sig_info->gid != 116 )
+    if ( buf.len and event.get_gid() != 116 )
         LogNetData(fast_log, buf.data, buf.len, p, "alt");
 
     if ( log_buffers )
-        log_ips_buffers(p, event.buffs_to_dump, buffers_depth);
+        log_ips_buffers(p, event.get_buffers(), buffers_depth);
 }
 
 //-------------------------------------------------------------------------
index ae5aeaaee6604ed2b919a0716b825282501b4f6b..5104b85ba8672ecf70f836e4ae9b4cd7ed7b9327 100644 (file)
@@ -38,7 +38,6 @@
 #endif
 
 #include "detection/ips_context.h"
-#include "detection/signature.h"
 #include "events/event.h"
 #include "framework/logger.h"
 #include "framework/module.h"
@@ -147,8 +146,9 @@ void FullLogger::alert(Packet* p, const char* msg, const Event& event)
 {
     TextLog_Puts(full_log, "[**] ");
 
-    TextLog_Print(full_log, "[%u:%u:%u] ",
-        event.sig_info->gid, event.sig_info->sid, event.sig_info->rev);
+    uint32_t gid, sid, rev;
+    event.get_sig_ids(gid, sid, rev);
+    TextLog_Print(full_log, "[%u:%u:%u] ", gid, sid, rev);
 
     if (p->context->conf->alert_interface())
     {
index 5358b4f056fc0665fcb7351ab43e50de940a3807..119614938eb46d69b247d74b50ee1d0fb4a51866 100644 (file)
 #endif
 
 #include "detection/detection_engine.h"
-#include "detection/signature.h"
 #include "events/event.h"
 #include "flow/flow_key.h"
 #include "framework/logger.h"
 #include "framework/module.h"
 #include "helpers/base64_encoder.h"
-#include "log/log.h"
 #include "log/log_text.h"
 #include "log/text_log.h"
 #include "packet_io/active.h"
@@ -48,7 +46,6 @@
 #include "protocols/tcp.h"
 #include "protocols/udp.h"
 #include "protocols/vlan.h"
-#include "utils/stats.h"
 
 using namespace snort;
 using namespace std;
@@ -64,6 +61,8 @@ static THREAD_LOCAL TextLog* json_log;
 // field formatting functions
 //-------------------------------------------------------------------------
 
+namespace
+{
 struct Args
 {
     Packet* pkt;
@@ -71,6 +70,7 @@ struct Args
     const Event& event;
     bool comma;
 };
+}
 
 static void print_label(const Args& a, const char* label)
 {
@@ -89,10 +89,8 @@ static bool ff_action(const Args& a)
 
 static bool ff_class(const Args& a)
 {
-    const char* cls = "none";
-
-    if ( a.event.sig_info->class_type and !a.event.sig_info->class_type->text.empty() )
-        cls = a.event.sig_info->class_type->text.c_str();
+    const char* cls = a.event.get_class_type();
+    if ( !cls ) cls = "none";
 
     print_label(a, "class");
     TextLog_Quote(json_log, cls);
@@ -281,7 +279,7 @@ static bool ff_geneve_vni(const Args& a)
 static bool ff_gid(const Args& a)
 {
     print_label(a, "gid");
-    TextLog_Print(json_log, "%u",  a.event.sig_info->gid);
+    TextLog_Print(json_log, "%u",  a.event.get_gid());
     return true;
 }
 
@@ -412,7 +410,7 @@ static bool ff_pkt_num(const Args& a)
 static bool ff_priority(const Args& a)
 {
     print_label(a, "priority");
-    TextLog_Print(json_log, "%u", a.event.sig_info->priority);
+    TextLog_Print(json_log, "%u", a.event.get_priority());
     return true;
 }
 
@@ -426,7 +424,7 @@ static bool ff_proto(const Args& a)
 static bool ff_rev(const Args& a)
 {
     print_label(a, "rev");
-    TextLog_Print(json_log, "%u",  a.event.sig_info->rev);
+    TextLog_Print(json_log, "%u",  a.event.get_rev());
     return true;
 }
 
@@ -434,9 +432,10 @@ static bool ff_rule(const Args& a)
 {
     print_label(a, "rule");
 
-    TextLog_Print(json_log, "\"%u:%u:%u\"",
-        a.event.sig_info->gid, a.event.sig_info->sid, a.event.sig_info->rev);
+    uint32_t gid, sid, rev;
+    a.event.get_sig_ids(gid, sid, rev);
 
+    TextLog_Print(json_log, "\"%u:%u:%u\"", gid, sid, rev);
     return true;
 }
 
@@ -496,7 +495,7 @@ static bool ff_sgt(const Args& a)
 static bool ff_sid(const Args& a)
 {
     print_label(a, "sid");
-    TextLog_Print(json_log, "%u",  a.event.sig_info->sid);
+    TextLog_Print(json_log, "%u",  a.event.get_sid());
     return true;
 }
 
@@ -542,15 +541,16 @@ static bool ff_src_port(const Args& a)
 static bool ff_target(const Args& a)
 {
     SfIpString addr = "";
+    bool src;
 
-    if ( a.event.sig_info->target == TARGET_SRC )
-        a.pkt->ptrs.ip_api.get_src()->ntop(addr);
+    if ( !a.event.get_target(src) )
+        return false;
 
-    else if ( a.event.sig_info->target == TARGET_DST )
-        a.pkt->ptrs.ip_api.get_dst()->ntop(addr);
+    if ( src )
+        a.pkt->ptrs.ip_api.get_src()->ntop(addr);
 
     else
-        return false;
+        a.pkt->ptrs.ip_api.get_dst()->ntop(addr);
 
     print_label(a, "target");
     TextLog_Quote(json_log, addr);
@@ -573,7 +573,7 @@ static bool ff_tcp_flags(const Args& a)
     if (a.pkt->ptrs.tcph )
     {
         char tcpFlags[9];
-        CreateTCPFlagString(a.pkt->ptrs.tcph, tcpFlags);
+        a.pkt->ptrs.tcph->stringify_flags(tcpFlags);
 
         print_label(a, "tcp_flags");
         TextLog_Quote(json_log, tcpFlags);
index 61cc5b7f2a781f39107e593c5feb9eaa0f4d2f15..d4eef4fd31bfbd08731937932bdf7e48ada565ed 100644 (file)
 #endif
 
 #include "detection/ips_context.h"
-#include "detection/signature.h"
 #include "events/event.h"
 #include "framework/logger.h"
 #include "framework/module.h"
-#include "helpers/chunk.h"
 #include "log/messages.h"
 #include "lua/lua.h"
 #include "main/thread_config.h"
@@ -35,6 +33,7 @@
 #include "managers/script_manager.h"
 #include "profiler/profiler_defs.h"
 #include "protocols/packet.h"
+#include "utils/chunk.h"
 
 using namespace snort;
 
@@ -49,18 +48,13 @@ static THREAD_LOCAL SnortPacket lua_packet;
 SO_PUBLIC const SnortEvent* get_event()
 {
     assert(event);
-
-    lua_event.gid = event->sig_info->gid;
-    lua_event.sid = event->sig_info->sid;
-    lua_event.rev = event->sig_info->rev;
+    event->get_sig_ids(lua_event.gid, lua_event.sid, lua_event.rev);
 
     lua_event.event_id = event->get_event_id();
     lua_event.event_ref = event->get_event_reference();
 
-    if ( !event->sig_info->message.empty() )
-        lua_event.msg = event->sig_info->message.c_str();
-    else
-        lua_event.msg = "";
+    lua_event.msg = event->get_msg();
+    if ( !lua_event.msg ) lua_event.msg = "";
 
     return &lua_event;
 }
index 92e06a33c8776843542dfef3e77d20332547ae0a..ae092fff29d626fe1561713cdeeda9e243a4878e 100644 (file)
 #include <syslog.h>
 
 #include "detection/ips_context.h"
-#include "detection/signature.h"
 #include "events/event.h"
 #include "framework/logger.h"
 #include "framework/module.h"
+#include "framework/pig_pen.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
 #include "packet_io/sfdaq.h"
@@ -203,24 +203,25 @@ static void AlertSyslog(
 
     if ((p != nullptr) && p->ptrs.ip_api.is_valid())
     {
-        SnortSnprintfAppend(event_string, sizeof(event_string),
-            "[%u:%u:%u] ", event.sig_info->gid, event.sig_info->sid, event.sig_info->rev);
+        uint32_t gid, sid, rev;
+        event.get_sig_ids(gid, sid, rev);
+        SnortSnprintfAppend(event_string, sizeof(event_string), "[%u:%u:%u] ", gid, sid, rev);
 
         if (msg != nullptr)
             SnortSnprintfAppend(event_string, sizeof(event_string), "%s ", msg);
         else
             SnortSnprintfAppend(event_string, sizeof(event_string), "ALERT ");
 
-        if ( event.sig_info->class_type and !event.sig_info->class_type->text.empty() )
+        if ( auto cls = event.get_class_type() )
         {
             SnortSnprintfAppend(event_string, sizeof(event_string),
-                "[Classification: %s] ", event.sig_info->class_type->text.c_str());
+                "[Classification: %s] ", cls);
         }
 
-        if (event.sig_info->priority != 0)
+        if (event.get_priority() != 0)
         {
             SnortSnprintfAppend(event_string, sizeof(event_string),
-                "[Priority: %u] ", event.sig_info->priority);
+                "[Priority: %u] ", event.get_priority());
         }
 
         if (p->context->conf->alert_interface())
@@ -229,17 +230,10 @@ static void AlertSyslog(
                 "<%s> ", SFDAQ::get_input_spec());
         }
 
-       IpProtocol ip_proto = p->get_ip_proto_next();
-        if (protocol_names[to_utype(ip_proto)] != nullptr)
-        {
-            SnortSnprintfAppend(event_string, sizeof(event_string),
-                "{%s} ", protocol_names[to_utype(ip_proto)]);
-        }
-        else
-        {
-            SnortSnprintfAppend(event_string, sizeof(event_string),
-                "{%d} ", static_cast<uint8_t>(ip_proto));
-        }
+           IpProtocol ip_proto = p->get_ip_proto_next();
+
+        const char* proto = PigPen::get_protocol_name(to_utype(ip_proto));
+        SnortSnprintfAppend(event_string, sizeof(event_string), "{%s} ", proto);
 
         if ((p->ptrs.decode_flags & DECODE_FRAG)
             || ((ip_proto != IpProtocol::TCP)
index d040dac55ac3f76003320af9e0a199f621c836b0..70fd8b2e3ad098357dceb361ff16525c9f350f2e 100644 (file)
@@ -28,7 +28,6 @@
 #include <map>
 #include <sstream>
 
-#include "detection/signature.h"
 #include "events/event.h"
 #include "framework/logger.h"
 #include "framework/module.h"
@@ -162,11 +161,9 @@ void TalosLogger::alert(Packet*, const char* msg, const Event& event)
     stringstream key;
     string message;
 
-    key << "["
-        << event.sig_info->gid << ":"
-        << event.sig_info->sid << ":"
-        << event.sig_info->rev
-        << "]";
+    uint32_t gid, sid, rev;
+    event.get_sig_ids(gid, sid, rev);
+    key << "[" << gid << ":" << sid << ":" << rev << "]";
 
     auto rule_iter = alerts.find(key.str());
 
@@ -189,9 +186,9 @@ void TalosLogger::alert(Packet*, const char* msg, const Event& event)
 
     rule.key = key.str();
     rule.msg = message;
-    rule.gid = event.sig_info->gid;
-    rule.sid = event.sig_info->sid;
-    rule.rev = event.sig_info->rev;
+    rule.gid = gid;
+    rule.sid = sid;
+    rule.rev = rev;
     rule.count = 1;
 
     // rule not in map, add it
index eb86d004a4089c26a29f2985dbfe20c294603229..bd9339423e52599843223a73fa5fe45067701b4a 100644 (file)
 
 #include <sys/un.h>
 
-#include "detection/signature.h"
 #include "events/event.h"
 #include "framework/logger.h"
 #include "framework/module.h"
 #include "log/messages.h"
+#include "main/thread.h"
 #include "protocols/packet.h"
 #include "utils/util.h"
 #include "utils/util_cstring.h"
@@ -41,7 +41,8 @@ using namespace snort;
  */
 struct pcap_pkthdr32
 {
-    struct sf_timeval32 ts;   /* packet timestamp */
+    uint32_t ts_sec;          /* packet timestamp */
+    uint32_t ts_usec;
     uint32_t caplen;          /* packet capture length */
     uint32_t len;             /* packet "real" length */
 };
@@ -73,7 +74,9 @@ struct Alertpkt
 
     uint32_t event_id;
     uint32_t event_ref;
-    struct sf_timeval32 ref_time;
+
+    uint32_t ts_sec;
+    uint32_t ts_usec;
 };
 
 struct UnixSock
@@ -121,21 +124,20 @@ static void get_alert_pkt(
     // FIXIT-L minimize or eliminate memset
     memset((char*)&us.alert,0,sizeof(us.alert));
 
-    us.alert.gid = event.sig_info->gid;
-    us.alert.sid = event.sig_info->sid;
-    us.alert.rev = event.sig_info->rev;
+    event.get_sig_ids(us.alert.gid, us.alert.sid, us.alert.rev);
 
-    us.alert.class_id = event.sig_info->class_id;
-    us.alert.priority = event.sig_info->priority;
+    us.alert.class_id = event.get_class_id();
+    us.alert.priority = event.get_priority();
 
     us.alert.event_id = event.get_event_id();
     us.alert.event_ref = event.get_event_reference();
-    us.alert.ref_time = event.ref_time;
+
+    event.get_timestamp(us.alert.ts_sec, us.alert.ts_usec);
 
     if (p && p->pkt)
     {
-        us.alert.pkth.ts.tv_sec = (uint32_t)p->pkth->ts.tv_sec;
-        us.alert.pkth.ts.tv_usec = (uint32_t)p->pkth->ts.tv_usec;
+        us.alert.pkth.ts_sec = (uint32_t)p->pkth->ts.tv_sec;
+        us.alert.pkth.ts_usec = (uint32_t)p->pkth->ts.tv_usec;
         us.alert.pkth.caplen = p->pktlen;
         us.alert.pkth.len = p->pkth->pktlen;
         memmove(us.alert.pkt, (const void*)p->pkt, us.alert.pkth.caplen);
index f749e33d449f81dbceb812a888684c8af5f80007..0855957ab29be9f12e87b433c34fbb31f9d80170 100644 (file)
@@ -23,7 +23,6 @@
 #endif
 
 #include "detection/ips_context.h"
-#include "detection/signature.h"
 #include "events/event.h"
 #include "framework/logger.h"
 #include "framework/module.h"
@@ -139,8 +138,9 @@ void CodecLogger::log(Packet* p, const char* msg, Event* e)
 
     if (e != nullptr)
     {
-        TextLog_Print(test_file, "    gid:%u    sid:%u    rev:%u\t",
-            e->sig_info->gid, e->sig_info->sid, e->sig_info->rev);
+        uint32_t gid, sid, rev;
+        e->get_sig_ids(gid, sid, rev);
+        TextLog_Print(test_file, "    gid:%u    sid:%u    rev:%u\t", gid, sid, rev);
     }
 
     if (flags & ALERT_FLAG_MSG)
index a5ca5488b596e128326f10935bbda28106591bef..89d4e9d33b18ec810862f0276ca4cbec9a757d16 100644 (file)
@@ -29,6 +29,7 @@
 #include "framework/module.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "packet_io/sfdaq.h"
 #include "packet_io/sfdaq_config.h"
 #include "protocols/packet.h"
index 022ec4799456342314357f602b1ee83dec4c86ac..fd3596393827ec72c5e269a6cad163015d63efdf 100644 (file)
@@ -31,8 +31,6 @@
 
 #include <cassert>
 
-#include "detection/signature.h"
-#include "detection/detection_util.h"
 #include "detection/detection_engine.h"
 #include "events/event.h"
 #include "framework/logger.h"
@@ -42,6 +40,7 @@
 #include "log/unified2.h"
 #include "log/u2_packet.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "network_inspectors/appid/appid_api.h"
 #include "packet_io/active.h"
 #include "packet_io/sfdaq.h"
@@ -170,14 +169,21 @@ static void alert_event(Packet* p, const char*, Unified2Config* config, const Ev
     u2_event.snort_id = 0;  // FIXIT-H alert_event define / use
 
     u2_event.event_id = htonl(event->get_event_id());
-    u2_event.event_second = htonl(event->ref_time.tv_sec);
-    u2_event.event_microsecond = htonl(event->ref_time.tv_usec);
 
-    u2_event.rule_gid = htonl(event->sig_info->gid);
-    u2_event.rule_sid = htonl(event->sig_info->sid);
-    u2_event.rule_rev = htonl(event->sig_info->rev);
-    u2_event.rule_class = htonl(event->sig_info->class_id);
-    u2_event.rule_priority = htonl(event->sig_info->priority);
+    uint32_t sec, usec;
+    event->get_timestamp(sec, usec);
+    u2_event.event_second = htonl(sec);
+    u2_event.event_microsecond = htonl(usec);
+
+    uint32_t gid, sid, rev;
+    event->get_sig_ids(gid, sid, rev);
+
+    u2_event.rule_gid = htonl(gid);
+    u2_event.rule_sid = htonl(sid);
+    u2_event.rule_rev = htonl(rev);
+
+    u2_event.rule_class = htonl(event->get_class_id());
+    u2_event.rule_priority = htonl(event->get_priority());
 
     if ( p )
     {
@@ -380,10 +386,11 @@ static void _Unified2LogPacketAlert(
     logheader.linktype = u2.base_proto;
 
     logheader.event_id = htonl(event->get_event_reference());
-    logheader.event_second = htonl(event->ref_time.tv_sec);
+    logheader.event_second = htonl(event->get_seconds());
 
     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;
@@ -637,13 +644,21 @@ static void _AlertIP4_v2(Packet* p, const char*, Unified2Config* config, const E
     memset(&alertdata, 0, sizeof(alertdata));
 
     alertdata.event_id = htonl(event->get_event_id());
-    alertdata.event_second = htonl(event->ref_time.tv_sec);
-    alertdata.event_microsecond = htonl(event->ref_time.tv_usec);
-    alertdata.generator_id = htonl(event->sig_info->gid);
-    alertdata.signature_id = htonl(event->sig_info->sid);
-    alertdata.signature_revision = htonl(event->sig_info->rev);
-    alertdata.classification_id = htonl(event->sig_info->class_id);
-    alertdata.priority_id = htonl(event->sig_info->priority);
+
+    uint32_t sec, usec;
+    event->get_timestamp(sec, usec);
+    alertdata.event_second = htonl(sec);
+    alertdata.event_microsecond = htonl(usec);
+
+    uint32_t gid, sid, rev;
+    event->get_sig_ids(gid, sid, rev);
+
+    alertdata.generator_id = htonl(gid);
+    alertdata.signature_id = htonl(sid);
+    alertdata.signature_revision = htonl(rev);
+
+    alertdata.classification_id = htonl(event->get_class_id());
+    alertdata.priority_id = htonl(event->get_priority());
 
     if (p)
     {
@@ -724,13 +739,21 @@ static void _AlertIP6_v2(Packet* p, const char*, Unified2Config* config, const E
     memset(&alertdata, 0, sizeof(alertdata));
 
     alertdata.event_id = htonl(event->get_event_id());
-    alertdata.event_second = htonl(event->ref_time.tv_sec);
-    alertdata.event_microsecond = htonl(event->ref_time.tv_usec);
-    alertdata.generator_id = htonl(event->sig_info->gid);
-    alertdata.signature_id = htonl(event->sig_info->sid);
-    alertdata.signature_revision = htonl(event->sig_info->rev);
-    alertdata.classification_id = htonl(event->sig_info->class_id);
-    alertdata.priority_id = htonl(event->sig_info->priority);
+
+    uint32_t sec, usec;
+    event->get_timestamp(sec, usec);
+    alertdata.event_second = htonl(sec);
+    alertdata.event_microsecond = htonl(usec);
+
+    uint32_t gid, sid, rev;
+    event->get_sig_ids(gid, sid, rev);
+
+    alertdata.generator_id = htonl(gid);
+    alertdata.signature_id = htonl(sid);
+    alertdata.signature_revision = htonl(rev);
+
+    alertdata.classification_id = htonl(event->get_class_id());
+    alertdata.priority_id = htonl(event->get_priority());
 
     if (p)
     {
@@ -940,11 +963,14 @@ void U2Logger::alert_legacy(Packet* p, const char* msg, const Event& event)
         if (p->ptrs.ip_api.is_ip6())
         {
             uint32_t tenant_id = p->pkth->tenant_id;
+            uint32_t sec = event.get_seconds();
+
             const SfIp* ip = p->ptrs.ip_api.get_src();
-            _WriteExtraData(&config, p->obfuscator, event.get_event_id(), tenant_id, event.ref_time.tv_sec,
+            _WriteExtraData(&config, p->obfuscator, event.get_event_id(), tenant_id, sec,
                 (const uint8_t*) ip->get_ip6_ptr(), sizeof(struct in6_addr), EVENT_INFO_IPV6_SRC);
+
             ip = p->ptrs.ip_api.get_dst();
-            _WriteExtraData(&config, p->obfuscator, event.get_event_id(), tenant_id, event.ref_time.tv_sec,
+            _WriteExtraData(&config, p->obfuscator, event.get_event_id(), tenant_id, sec,
                 (const uint8_t*) ip->get_ip6_ptr(), sizeof(struct in6_addr), EVENT_INFO_IPV6_DST);
         }
     }
@@ -954,18 +980,20 @@ void U2Logger::alert_legacy(Packet* p, const char* msg, const Event& event)
     }
 
     if ( p->flow )
-        Stream::update_flow_alert(
-            p->flow, p, event.sig_info->gid, event.sig_info->sid,
-            event.get_event_id(), event.ref_time.tv_sec);
+    {
+        uint32_t sec = event.get_seconds();
+        Stream::update_flow_alert(p->flow, p, event.get_gid(), event.get_sid(), event.get_event_id(), sec);
+    }
 
     if ( p->xtradata_mask )
     {
         LogFunction* log_funcs;
         uint32_t max_count = Stream::get_xtra_data_map(log_funcs);
+        uint32_t sec = event.get_seconds();
 
         if ( max_count > 0 )
             AlertExtraData(p->flow, &config, log_funcs, max_count, p->xtradata_mask,
-                { /* gid */ 0, /* sid */ 0, event.get_event_id(), event.ref_time.tv_sec });
+                { /* gid */ 0, /* sid */ 0, event.get_event_id(), sec });
     }
 }
 
@@ -977,11 +1005,13 @@ void U2Logger::alert(Packet* p, const char* msg, const Event& event)
         return;
     }
     alert_event(p, msg, &config, &event);
+    uint32_t sec = event.get_seconds();
+
 
     if ( p->flow )
-        Stream::update_flow_alert(
-            p->flow, p, event.sig_info->gid, event.sig_info->sid,
-            event.get_event_id(), event.ref_time.tv_sec);
+    {
+        Stream::update_flow_alert( p->flow, p, event.get_gid(), event.get_sid(), event.get_event_id(), sec);
+    }
 
     if ( p->xtradata_mask )
     {
@@ -990,7 +1020,7 @@ void U2Logger::alert(Packet* p, const char* msg, const Event& event)
 
         if ( max_count > 0 )
             AlertExtraData(p->flow, &config, log_funcs, max_count, p->xtradata_mask,
-                { /* gid */ 0, /* sid */ 0, event.get_event_id(), event.ref_time.tv_sec });
+                { /* gid */ 0, /* sid */ 0, event.get_event_id(), sec });
     }
 }
 
index b6f21df8ae0ef428decea14aba0ab4ada640b416..229235fd51428658e7341fffa1aed35a69c2f9cf 100644 (file)
 #include "control/control.h"
 #include "detection/signature.h"
 #include "framework/module.h"
-#include "helpers/process.h"
 #include "helpers/ring.h"
+#include "log/log_errors.h"
 #include "log/messages.h"
 #include "lua/lua.h"
 #include "main/analyzer.h"
 #include "main/analyzer_command.h"
+#include "main/process.h"
 #include "main/reload_tracker.h"
 #include "main/shell.h"
 #include "main/snort.h"
@@ -54,8 +55,9 @@
 #include "trace/trace_api.h"
 #include "trace/trace_config.h"
 #include "trace/trace_logger.h"
-#include "utils/util.h"
 #include "utils/safec.h"
+#include "utils/stats.h"
+#include "utils/util.h"
 
 #if defined(UNIT_TEST) || defined(BENCHMARK_TEST)
 #include "catch/unit_test.h"
index 1c7d59edb37aa2641b55592a4ad427c3d6bbfe54..94c06f1f8a06310315b7ab5e24fcae0b3cc3e937 100644 (file)
@@ -1,14 +1,11 @@
 
 set (INCLUDES
-    analyzer.h
     analyzer_command.h
     policy.h
     reload_tracker.h
     reload_tuner.h
-    snort.h
     snort_config.h
     snort_types.h
-    swapper.h
     thread.h
     thread_config.h
 )
@@ -26,6 +23,7 @@ add_subdirectory(test)
 
 add_library (main OBJECT
     analyzer.cc
+    analyzer.h
     analyzer_command.cc
     help.cc
     help.h
@@ -33,9 +31,12 @@ add_library (main OBJECT
     modules.h
     network_module.cc
     network_module.h
+    numa.h
     oops_handler.cc
     oops_handler.h
     policy.cc
+    process.cc
+    process.h
     reload_tracker.cc
     shell.h
     shell.cc
@@ -45,6 +46,7 @@ add_library (main OBJECT
     snort_module.h
     snort_module.cc
     swapper.cc
+    swapper.h
     thread.cc
     thread_config.h
     thread_config.cc
index 7a951acd888de7f6c02e8f3cacdd4d487d1a7c79..af72e6e9a7129c3bdcf4224066a4d9c269b1a47c 100644 (file)
@@ -35,6 +35,7 @@
 #include "detection/detect.h"
 #include "detection/detection_engine.h"
 #include "detection/ips_context.h"
+#include "detection/event_trace.h"
 #include "detection/tag.h"
 #include "file_api/file_service.h"
 #include "filters/detection_filter.h"
 #include "main/swapper.h"
 #include "main.h"
 #include "managers/action_manager.h"
+#include "managers/codec_manager.h"
 #include "managers/inspector_manager.h"
 #include "managers/ips_manager.h"
 #include "managers/event_manager.h"
 #include "managers/module_manager.h"
 #include "memory/memory_cap.h"
 #include "packet_io/active.h"
+#include "packet_io/packet_tracer.h"
 #include "packet_io/sfdaq.h"
 #include "packet_io/sfdaq_config.h"
 #include "packet_io/sfdaq_instance.h"
 #include "packet_io/sfdaq_module.h"
-#include "packet_tracer/packet_tracer.h"
-#include "profiler/profiler.h"
+#include "profiler/profiler_impl.h"
 #include "pub_sub/daq_message_event.h"
 #include "pub_sub/finalize_packet_event.h"
 #include "side_channel/side_channel.h"
@@ -407,7 +409,7 @@ void Analyzer::process_daq_pkt_msg(DAQ_Msg_h msg, bool retry)
 
     Packet* p = switcher->get_context()->packet;
     p->context->wire_packet = p;
-    p->context->packet_number = get_packet_number();
+    p->context->packet_number = pc.analyzed_pkts;
     select_default_policy(*pkthdr, p->context->conf);
 
     DetectionEngine::reset();
@@ -497,12 +499,6 @@ void Analyzer::process_retry_queue()
 /*
  * Public packet processing methods
  */
-bool Analyzer::inspect_rebuilt(Packet* p)
-{
-    DetectionEngine de;
-    return main_hook(p);
-}
-
 bool Analyzer::process_rebuilt_packet(Packet* p, const DAQ_PktHdr_t* pkthdr, const uint8_t* pkt,
     uint32_t pktlen)
 {
@@ -631,7 +627,7 @@ void Analyzer::init_unprivileged()
     // to handle all trace log messages
     TraceApi::thread_init(sc->trace_config);
 
-    CodecManager::thread_init(sc);
+    CodecManager::thread_init();
 
     // this depends on instantiated daq capabilities
     // so it is done here instead of init()
index 54c28420ad8421b5ff7a9d655c65ea1024e68325..e868d7334e5d26547038fe2bdbbf593194e1990e 100644 (file)
@@ -76,7 +76,7 @@ public:
         NUM_STATES
     };
 
-    SO_PUBLIC static Analyzer* get_local_analyzer();
+    static Analyzer* get_local_analyzer();
     static ContextSwitcher* get_switcher();
     static void set_main_hook(MainHook_f);
 
@@ -97,7 +97,6 @@ public:
 
     void post_process_packet(snort::Packet*);
     bool process_rebuilt_packet(snort::Packet*, const DAQ_PktHdr_t*, const uint8_t* pkt, uint32_t pktlen);
-    SO_PUBLIC bool inspect_rebuilt(snort::Packet*);
     void finalize_daq_message(DAQ_Msg_h, DAQ_Verdict);
     void add_to_retry_queue(DAQ_Msg_h, snort::Flow*);
 
index fc0e4e9afd17946e041903638940298ab76e9c78..25278c10b7203dc3eb5875ccf196dee9031b0251 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "framework/module.h"
 #include "helpers/markup.h"
-#include "helpers/process.h"
+#include "main/process.h"
 #include "managers/event_manager.h"
 #include "managers/inspector_manager.h"
 #include "managers/module_manager.h"
index e6db41f74ea1cd8547f41c960dc03e65ab611f0f..448a5b9840008f958b041a7186d3272bb9ecc692 100644 (file)
@@ -32,6 +32,8 @@
 #include "detection/fp_config.h"
 #include "detection/rules.h"
 #include "detection/tag.h"
+#include "events/event_queue.h"
+#include "file_api/file_policy.h"
 #include "file_api/file_service.h"
 #include "filters/detection_filter.h"
 #include "filters/rate_filter.h"
@@ -39,7 +41,6 @@
 #include "filters/sfthd.h"
 #include "filters/sfthreshold.h"
 #include "flow/ha_module.h"
-#include "framework/file_policy.h"
 #include "framework/module.h"
 #include "host_tracker/host_tracker_module.h"
 #include "host_tracker/host_cache_module.h"
@@ -50,8 +51,9 @@
 #include "managers/plugin_manager.h"
 #include "memory/memory_module.h"
 #include "packet_io/active.h"
+#include "packet_io/active_counts.h"
+#include "packet_io/packet_tracer_module.h"
 #include "packet_io/sfdaq_module.h"
-#include "packet_tracer/packet_tracer_module.h"
 #include "parser/config_file.h"
 #include "parser/parse_conf.h"
 #include "parser/parse_ip.h"
@@ -225,7 +227,6 @@ const PegInfo mpse_pegs[] =
     { CountType::SUM, "total_unique", "total unique fast pattern hits" },
     { CountType::SUM, "non_qualified_events", "total non-qualified events" },
     { CountType::SUM, "qualified_events", "total qualified events" },
-    { CountType::SUM, "searched_bytes", "total bytes searched" },
     { CountType::END, nullptr, nullptr }
 };
 
@@ -699,7 +700,7 @@ public:
     { return active_pegs; }
 
     PegCount* get_counts() const override
-    { return (PegCount*) &active_counts; }
+    { return (PegCount*) get_active_counts(); }
 
     Usage get_usage() const override
     { return GLOBAL; }
@@ -1649,9 +1650,9 @@ bool RateFilterModule::set(const char*, Value& v, SnortConfig*)
 
     else if ( v.is("new_action") )
     {
-        thdx.newAction = Actions::get_type(v.get_string());
+        thdx.newAction = IpsAction::get_type(v.get_string());
 
-        if ( !Actions::is_valid_action(thdx.newAction) )
+        if ( !IpsAction::is_valid_action(thdx.newAction) )
             ParseError("unknown new_action type rate_filter configuration %s",
                     v.get_string());
     }
index 02edb222e30daf3e023ccf816e5613ea09a49122..dc607a07c5dbd74d37693248aee6573d14daf545 100644 (file)
@@ -25,8 +25,6 @@
 // ideally, modules.cc would be refactored into several files.
 
 #include "framework/counts.h"
-#include "main/thread.h"
-
 
 void module_init();
 const char* get_lua_defaults();
similarity index 93%
rename from src/utils/util_numa.h
rename to src/main/numa.h
index 95019f67cc6628428d686baa60fac943fa0e66bc..2d9063f30b53bb7c0f77680b8cf83d36774f1c67 100644 (file)
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
-// util_numa.h author Raza Shafiq <rshafiq@cisco.com>
+// numa.h author Raza Shafiq <rshafiq@cisco.com>
 
-#ifndef NUMA_UTILS_H
-#define NUMA_UTILS_H
-
-#ifdef HAVE_NUMA
+#ifndef NUMA_H
+#define NUMA_H
 
 #include <numa.h>
 #include <numaif.h>
@@ -49,6 +47,7 @@ public:
         return set_mempolicy(mode, nodemask, maxnode);
     }
 };
+
 class HwlocWrapper
 {
 public:
@@ -70,5 +69,5 @@ public:
         return hwloc_bitmap_intersects(set1, set2);
     }
 };
-#endif // HAVE_NUMA
-#endif // NUMA_UTILS_H
+#endif
+
index 312c3714162bd31a7b743bf27e78ce8f7360b219..c6c3e10dd9f0e848611f882a9ba0d145b31d4e34 100644 (file)
@@ -25,9 +25,9 @@
 
 #include "daq_common.h"
 
-#include "actions/actions.h"
 #include "detection/detection_engine.h"
-#include "framework/file_policy.h"
+#include "file_api/file_policy.h"
+#include "framework/ips_action.h"
 #include "framework/policy_selector.h"
 #include "js_norm/js_config.h"
 #include "log/messages.h"
@@ -188,7 +188,7 @@ void InspectionPolicy::configure()
 // detection policy
 //-------------------------------------------------------------------------
 
-IpsPolicy::IpsPolicy(PolicyId id) : action(Actions::get_max_types(), nullptr)
+IpsPolicy::IpsPolicy(PolicyId id) : action(IpsAction::get_max_types(), nullptr)
 {
     policy_id = id;
     policy_mode = POLICY_MODE__MAX;
similarity index 61%
rename from src/helpers/process.cc
rename to src/main/process.cc
index 6540aa191d1f60f6ecbc87ef70e22647526725c2..50b8cbbe1da83060506a2c3f0cc3819d7ae47f3c 100644 (file)
 #include "process.h"
 
 #include <fcntl.h>
+#include <grp.h>
+#include <luajit.h>
+#include <openssl/crypto.h>
+#include <pcap.h>
+#include <pcre.h>
+#include <pwd.h>
+#include <sys/file.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <zlib.h>
+
+#ifdef HAVE_HYPERSCAN
+#include <hs_compile.h>
+#endif
+
+#ifdef HAVE_LZMA
+#include <lzma.h>
+#endif
+
+#ifdef HAVE_JEMALLOC
+#include <jemalloc/jemalloc.h>
+#endif
 
 #ifdef HAVE_LIBUNWIND
 #define UNW_LOCAL_ONLY
 #include <malloc.h>
 #endif
 
+extern "C" {
+#include <daq.h>
+}
+
 #include <csignal>
+#include <fstream>
 #include <iostream>
 
 #include "log/messages.h"
-#include "main.h"
-#include "main/oops_handler.h"
-#include "main/snort_config.h"
+#include "helpers/markup.h"
+#include "helpers/ring.h"
+#include "helpers/sigsafe.h"
+#include "packet_io/sfdaq.h"
+#include "protocols/packet.h"   // For NUM_IP_PROTOS
 #include "utils/cpp_macros.h"
 #include "utils/stats.h"
 #include "utils/util.h"
 
-#include "markup.h"
-#include "ring.h"
-#include "sigsafe.h"
+#include "main.h"
+#include "oops_handler.h"
+#include "snort_config.h"
 
 using namespace snort;
 
@@ -604,3 +633,381 @@ void trim_heap()
     malloc_trim(0);
 #endif
 }
+
+//-------------------------------------------------------------------------
+// other foo
+//-------------------------------------------------------------------------
+
+// Store interesting data in memory that would not otherwise be visible
+// in a CORE(5) file
+
+#ifdef BUILD
+    #define SNORT_VERSION_STRING ("### Snort Version " VERSION " Build " BUILD "\n")
+#else
+    #define SNORT_VERSION_STRING ("### Snort Version " VERSION "\n")
+#endif
+#define SNORT_VERSION_STRLEN sizeof(SNORT_VERSION_STRING)
+char __snort_version_string[SNORT_VERSION_STRLEN];
+
+void StoreSnortInfoStrings()
+{
+    strncpy(__snort_version_string, SNORT_VERSION_STRING,
+        sizeof(__snort_version_string));
+}
+
+#undef SNORT_VERSION_STRING
+#undef SNORT_VERSION_STRLEN
+
+int DisplayBanner()
+{
+    const char* ljv = LUAJIT_VERSION;
+    while ( *ljv && !isdigit(*ljv) )
+        ++ljv;
+
+    LogMessage("\n");
+    LogMessage("   ,,_     -*> Snort++ <*-\n");
+#ifdef BUILD
+    LogMessage("  o\"  )~   Version %s (Build %s)\n", VERSION, BUILD);
+#else
+    LogMessage("  o\"  )~   Version %s\n", VERSION);
+#endif
+    LogMessage("   ''''    By Martin Roesch & The Snort Team\n");
+    LogMessage("           http://snort.org/contact#team\n");
+    LogMessage("           Copyright (C) 2014-2024 Cisco and/or its affiliates."
+                           " All rights reserved.\n");
+    LogMessage("           Copyright (C) 1998-2013 Sourcefire, Inc., et al.\n");
+    LogMessage("           Using DAQ version %s\n", daq_version_string());
+#ifdef HAVE_HYPERSCAN
+    LogMessage("           Using Hyperscan version %s\n", hs_version());
+#endif
+#ifdef HAVE_JEMALLOC
+    const char* jv;
+    size_t sz = sizeof(jv);
+    mallctl("version", &jv,  &sz, NULL, 0);
+    LogMessage("           Using Jemalloc version %s\n", jv);
+#endif
+    LogMessage("           Using %s\n", pcap_lib_version());
+    LogMessage("           Using LuaJIT version %s\n", ljv);
+#ifdef HAVE_LZMA
+    LogMessage("           Using LZMA version %s\n", lzma_version_string());
+#endif
+    LogMessage("           Using %s\n", OpenSSL_version(SSLEAY_VERSION));
+    LogMessage("           Using PCRE version %s\n", pcre_version());
+    LogMessage("           Using ZLIB version %s\n", zlib_version);
+
+    LogMessage("\n");
+
+    return 0;
+}
+
+// get offset seconds from GMT
+int gmt2local(time_t t)
+{
+    if (t == 0)
+        t = time(nullptr);
+
+    struct tm gmt;
+    struct tm* lt = gmtime_r(&t, &gmt);
+    if (lt == nullptr)
+        return 0;
+
+    struct tm loc;
+    localtime_r(&t, &loc);
+
+    int dt = (loc.tm_hour - gmt.tm_hour) * 60 * 60 +
+        (loc.tm_min - gmt.tm_min) * 60;
+
+    int dir = loc.tm_year - gmt.tm_year;
+
+    if (dir == 0)
+        dir = loc.tm_yday - gmt.tm_yday;
+
+    dt += dir * 24 * 60 * 60;
+
+    return(dt);
+}
+
+static FILE* pid_lockfile = nullptr;
+static FILE* pid_file = nullptr;
+
+void CreatePidFile(pid_t pid)
+{
+    SnortConfig* sc = SnortConfig::get_main_conf();
+
+    sc->pid_filename = sc->log_dir;
+    sc->pid_filename += "/snort.pid";
+
+    std::string pid_lockfilename;
+
+    if ( !sc->no_lock_pid_file() )
+    {
+        pid_lockfilename = sc->pid_filename;
+        pid_lockfilename += ".lck";
+
+        /* First, lock the PID file */
+        pid_lockfile = fopen(pid_lockfilename.c_str(), "w");
+
+        if ( pid_lockfile )
+        {
+            struct flock lock;
+            int lock_fd = fileno(pid_lockfile);
+
+            lock.l_type = F_WRLCK;
+            lock.l_whence = SEEK_SET;
+            lock.l_start = 0;
+            lock.l_len = 0;
+
+            if (fcntl(lock_fd, F_SETLK, &lock) == -1)
+            {
+                ClosePidFile();
+                ParseError("Failed to Lock PID File \"%s\" for PID \"%d\"",
+                    sc->pid_filename.c_str(), (int)pid);
+                return;
+            }
+        }
+    }
+
+    /* Okay, were able to lock PID file, now open and write PID */
+    pid_file = fopen(sc->pid_filename.c_str(), "w");
+    if (pid_file)
+    {
+        LogMessage("Writing PID \"%d\" to file \"%s\"\n", (int)pid,
+            sc->pid_filename.c_str());
+        fprintf(pid_file, "%d\n", (int)pid);
+        fflush(pid_file);
+    }
+    else
+    {
+        if (pid_lockfile)
+        {
+            fclose(pid_lockfile);
+            pid_lockfile = nullptr;
+        }
+        const char* error = get_error(errno);
+        ErrorMessage("Failed to create pid file %s, Error: %s\n",
+            sc->pid_filename.c_str(), error);
+        sc->pid_filename.clear();
+    }
+    if ( !pid_lockfilename.empty() )
+        unlink(pid_lockfilename.c_str());
+}
+
+void ClosePidFile()
+{
+    if (pid_file)
+    {
+        fclose(pid_file);
+        pid_file = nullptr;
+    }
+    if (pid_lockfile)
+    {
+        fclose(pid_lockfile);
+        pid_lockfile = nullptr;
+    }
+}
+
+// set safe UserID and GroupID, if needed
+bool SetUidGid(int user_id, int group_id)
+{
+    // Were any changes requested?
+    if (group_id == -1 && user_id == -1)
+        return true;
+
+    if (group_id != -1)
+    {
+        if (setgid(group_id) < 0)
+        {
+            ParseError("Cannot set GID: %d", group_id);
+            return false;
+        }
+        LogMessage("Set GID to %d\n", group_id);
+    }
+
+    if (user_id != -1)
+    {
+        if (setuid(user_id) < 0)
+        {
+            ParseError("Cannot set UID: %d", user_id);
+            return false;
+        }
+        LogMessage("Set UID to %d\n", user_id);
+    }
+
+    return true;
+}
+
+// set the groups of the process based on the UserID with the GroupID added
+void InitGroups(int user_id, int group_id)
+{
+    if ((user_id != -1) && (getuid() == 0))
+    {
+        struct passwd* pw = getpwuid(user_id);  // main thread only
+
+        if (pw != nullptr)
+        {
+            /* getpwuid and initgroups may use the same static buffers */
+            char* username = snort_strdup(pw->pw_name);
+
+            if (initgroups(username, group_id) < 0)
+                ParseError("Can not initgroups(%s,%d)", username, group_id);
+
+            snort_free(username);
+        }
+
+        /** Just to be on the safe side... **/
+        endgrent();
+        endpwent();
+    }
+}
+
+//-------------------------------------------------------------------------
+
+// read the BPF filters in from a file, return the processed BPF string
+std::string read_infile(const char* key, const char* fname)
+{
+    int fd = open(fname, O_RDONLY);
+    struct stat buf;
+
+    if (fd < 0)
+    {
+        ErrorMessage("Failed to open file: %s with error: %s", fname, get_error(errno));
+        return "";
+    }
+
+    if (fstat(fd, &buf) < 0)
+    {
+        ParseError("can't stat %s: %s", fname, get_error(errno));
+        close(fd);
+        return "";
+    }
+
+    //check that its a regular file and not a directory or special file
+    if (!S_ISREG(buf.st_mode) )
+    {
+        ParseError("not a regular file: %s", fname);
+        close(fd);
+        return "";
+    }
+
+    std::string line;
+    std::ifstream bpf_file(fname);
+
+    if (bpf_file.is_open())
+    {
+        std::stringstream file_content;
+        file_content << bpf_file.rdbuf();
+        line = file_content.str();
+
+        bpf_file.close();
+    }
+    else
+    {
+        ParseError("can't open file %s = %s: %s", key, fname, get_error(errno));
+        close(fd);
+        return "";
+    }
+    close(fd);
+    return line;
+}
+
+typedef char PathBuf[PATH_MAX+1];
+
+static const char* CurrentWorkingDir(PathBuf& buf)
+{
+    if ( !getcwd(buf, sizeof(buf)-1) )
+        return nullptr;
+
+    buf[sizeof(buf)-1] = '\0';
+    return buf;
+}
+
+static char* GetAbsolutePath(const char* dir, PathBuf& buf)
+{
+    assert(dir);
+    errno = 0;
+
+    if ( !realpath(dir, buf) )
+    {
+        LogMessage("Couldn't determine absolute path for '%s': %s\n", dir, get_error(errno));
+        return nullptr;
+    }
+
+    return buf;
+}
+
+// Chroot and adjust the log_dir reference
+bool EnterChroot(std::string& root_dir, std::string& log_dir)
+{
+    if (log_dir.empty())
+    {
+        ParseError("Log directory not specified");
+        return false;
+    }
+    PathBuf pwd;
+    PathBuf abs_log_dir;
+
+    if ( !GetAbsolutePath(log_dir.c_str(), abs_log_dir) )
+        return false;
+
+    /* change to the desired root directory */
+    if (chdir(root_dir.c_str()) != 0)
+    {
+        ParseError("EnterChroot: Can not chdir to \"%s\": %s", root_dir.c_str(),
+            get_error(errno));
+        return false;
+    }
+
+    /* always returns an absolute pathname */
+    const char* abs_root_dir = CurrentWorkingDir(pwd);
+    if (!abs_root_dir)
+    {
+        ParseError("Couldn't retrieve current working directory");
+        return false;
+    }
+    size_t abs_root_dir_len = strlen(abs_root_dir);
+
+    if (strncmp(abs_root_dir, abs_log_dir, abs_root_dir_len))
+    {
+        ParseError("Specified log directory is not contained with the chroot jail");
+        return false;
+    }
+
+    if (chroot(abs_root_dir) < 0)
+    {
+        ParseError("Can not chroot to \"%s\": absolute: %s: %s",
+            root_dir.c_str(), abs_root_dir, get_error(errno));
+        return false;
+    }
+
+
+    /* Immediately change to the root directory of the jail. */
+    if (chdir("/") < 0)
+    {
+        ParseError("Can not chdir to \"/\" after chroot: %s",
+            get_error(errno));
+        return false;
+    }
+
+
+    if (abs_root_dir_len >= strlen(abs_log_dir))
+        log_dir = "/";
+    else
+        log_dir = abs_log_dir + abs_root_dir_len;
+
+
+    LogMessage("Chroot directory = %s\n", root_dir.c_str());
+
+    return true;
+}
+
+#if defined(NOCOREFILE)
+void SetNoCores()
+{
+    struct rlimit rlim;
+
+    getrlimit(RLIMIT_CORE, &rlim);
+    rlim.rlim_max = 0;
+    setrlimit(RLIMIT_CORE, &rlim);
+}
+#endif
+
similarity index 77%
rename from src/helpers/process.h
rename to src/main/process.h
index 60a6b3e78e75c04f9f7d0370e5dad5eb9239d798..77c2366760a61cea153c300645ba8ba4c45df8b3 100644 (file)
 #ifndef PROCESS_H
 #define PROCESS_H
 
+#include <sys/time.h>
+#include <string>
 #include "main/snort_types.h"
 
+
 // process oriented services like signal handling, heap info, etc.
 
 enum PigSignal
@@ -41,8 +44,8 @@ const char* get_signal_name(PigSignal);
 
 void init_signals();
 void term_signals();
-SO_PUBLIC void install_oops_handler();
-SO_PUBLIC void remove_oops_handler();
+void install_oops_handler();
+void remove_oops_handler();
 void help_signals();
 
 void daemonize();
@@ -51,5 +54,23 @@ void set_main_thread();
 
 void trim_heap();
 
+void StoreSnortInfoStrings();
+int DisplayBanner();
+
+int gmt2local(time_t);
+std::string read_infile(const char* key, const char* fname);
+
+void CreatePidFile(pid_t);
+void ClosePidFile();
+
+bool SetUidGid(int, int);
+void InitGroups(int, int);
+
+bool EnterChroot(std::string& root_dir, std::string& log_dir);
+
+#if defined(NOCOREFILE)
+void SetNoCores();
+#endif
+
 #endif
 
index 55e3a5c15ad0225a9b37fcb9fff0cb33b42155b1..67590c2b7527d16d70e5ae38e522b7f7bf5dd1a7 100644 (file)
 #include "filters/sfthreshold.h"
 #include "flow/ha.h"
 #include "framework/mpse.h"
-#include "helpers/process.h"
 #include "host_tracker/host_cache.h"
 #include "host_tracker/host_cache_segmented.h"
 #include "host_tracker/host_tracker_module.h"
 #include "ips_options/ips_options.h"
 #include "log/log.h"
-#include "log/messages.h"
+#include "log/log_errors.h"
 #include "loggers/loggers.h"
 #include "main.h"
+#include "main/process.h"
 #include "main/shell.h"
 #include "managers/codec_manager.h"
 #include "managers/inspector_manager.h"
@@ -76,6 +76,7 @@
 #include "trace/trace_api.h"
 #include "trace/trace_config.h"
 #include "trace/trace_logger.h"
+#include "utils/stats.h"
 #include "utils/util.h"
 
 #ifdef SHELL
@@ -176,7 +177,7 @@ void Snort::init(int argc, char** argv)
     ModuleManager::reset_stats(sc);
 
     if (sc->alert_before_pass())
-        sc->rule_order = Actions::get_default_priorities(true);
+        sc->rule_order = IpsAction::get_default_priorities(true);
 
     sc->setup();
 
@@ -210,6 +211,7 @@ void Snort::init(int argc, char** argv)
 
     /* Need to do this after dynamic detection stuff is initialized, too */
     IpsManager::global_init(sc);
+    PacketManager::global_init(sc->num_layers);
 
     sc->post_setup();
     sc->update_reload_id();
@@ -219,9 +221,10 @@ void Snort::init(int argc, char** argv)
     const MpseApi* search_api = sc->fast_pattern_config->get_search_api();
     const MpseApi* offload_search_api = sc->fast_pattern_config->get_offload_search_api();
 
-    MpseManager::activate_search_engine(search_api, sc);
+    if ( search_api )
+        MpseManager::activate_search_engine(search_api, sc);
 
-    if ((offload_search_api != nullptr) and (offload_search_api != search_api))
+    if ( offload_search_api and offload_search_api != search_api )
         MpseManager::activate_search_engine(offload_search_api, sc);
 
     /* Finish up the pcap list and put in the queues */
@@ -361,7 +364,6 @@ void Snort::term()
     detection_filter_term();
 
     term_signals();
-
 }
 
 void Snort::clean_exit(int)
@@ -604,12 +606,3 @@ SnortConfig* Snort::get_updated_policy(
     return sc;
 }
 
-OopsHandlerSuspend::OopsHandlerSuspend()
-{
-    remove_oops_handler();
-}
-
-OopsHandlerSuspend::~OopsHandlerSuspend()
-{
-    install_oops_handler();
-}
index d04fccc80a551a8df33ce57ce3317fc5d59cb66f..0ce5186d759c123dffecaf3990f8724c48217990 100644 (file)
@@ -24,8 +24,6 @@
 // Snort is the top-level application class.
 #include <daq_common.h>
 
-#include "main/snort_types.h"
-
 class ContextSwitcher;
 
 namespace snort
@@ -47,8 +45,8 @@ public:
     static void cleanup();
 
     static bool has_dropped_privileges();
-    SO_PUBLIC static bool is_reloading();
-    inline SO_PUBLIC static bool is_exiting() { return already_exiting; }
+    static bool is_exiting() { return already_exiting; }
+    static bool is_reloading();
 
 private:
     static void init(int, char**);
@@ -62,14 +60,6 @@ private:
     static bool privileges_dropped;
     static bool already_exiting;
 };
-
-// RAII-style mechanism for removal and reinstallation of Snort's crash handler
-class SO_PUBLIC OopsHandlerSuspend
-{
-public:
-    OopsHandlerSuspend();
-    ~OopsHandlerSuspend();
-};
 }
 
 #endif
index afcd762b1e7fc849975fa1fb2dd315e64d09bddf..7464a2920b9f0da8f30da397b37cf6a473100caf 100644 (file)
@@ -36,6 +36,7 @@
 #include "detection/fp_create.h"
 #include "dump_config/json_config_output.h"
 #include "dump_config/text_config_output.h"
+#include "events/event_queue.h"
 #include "file_api/file_service.h"
 #include "filters/detection_filter.h"
 #include "filters/rate_filter.h"
 #include "flow/ha_module.h"
 #include "framework/policy_selector.h"
 #include "hash/xhash.h"
-#include "helpers/process.h"
 #include "host_tracker/host_cache_segmented.h"
 #include "latency/latency_config.h"
 #include "log/messages.h"
+#include "main/policy.h"
+#include "main/process.h"
 #include "managers/action_manager.h"
 #include "managers/event_manager.h"
 #include "managers/inspector_manager.h"
@@ -265,7 +267,8 @@ SnortConfig::~SnortConfig()
         (fast_pattern_config->get_search_api() !=
         get_conf()->fast_pattern_config->get_search_api())) )
     {
-        MpseManager::stop_search_engine(fast_pattern_config->get_search_api());
+        if ( fast_pattern_config->get_search_api() )
+            MpseManager::stop_search_engine(fast_pattern_config->get_search_api());
     }
     delete fast_pattern_config;
 
@@ -308,7 +311,7 @@ void SnortConfig::setup()
     ParseRules(this);
 
     // Allocate evalOrder before calling the OrderRuleLists
-    evalOrder = new int[Actions::get_max_types()]();
+    evalOrder = new int[IpsAction::get_max_types()]();
 
     OrderRuleLists(this);
 
@@ -1082,3 +1085,15 @@ const char* SnortConfig::get_static_name(const char* name)
     static_names.emplace(name, name);
     return static_names[name].c_str();
 }
+
+int SnortConfig::get_classification_id(const char* name)
+{
+    auto& cls = get_conf()->classifications;
+    auto itr = cls.find(name);
+
+    if (itr != cls.end())
+        return itr->second->id;
+
+    return 0;
+}
+
index 5e661a6906c42bf714aa8378f9ce5f2bce41db09..52e713b10f65356e91e38245b17a0f4c9afbe0c6 100644 (file)
 #include <unordered_map>
 #include <vector>
 
-#include "actions/actions.h"
-#include "events/event_queue.h"
-#include "framework/bits.h"
+#include "framework/inspector.h"
+#include "framework/ips_action.h"
 #include "helpers/scratch_allocator.h"
 #include "main/policy.h"
-#include "main/thread.h"
 #include "sfip/sf_cidr.h"
+#include "utils/bits.h"
 
 #define DEFAULT_LOG_DIR "."
 
@@ -544,10 +543,7 @@ public:
     uint16_t get_event_log_id() const
     { return event_log_id; }
 
-    bool process_all_events() const
-    { return event_queue_config->process_all_events; }
-
-    int get_eval_index(Actions::Type type) const
+    int get_eval_index(IpsAction::Type type) const
     { return evalOrder[type]; }
 
     // output stuff
@@ -739,6 +735,7 @@ public:
     { return logging_flags & LOGGING_FLAG__SHOW_PLUGINS; }
 
     SO_PUBLIC static const char* get_static_name(const char* name);
+    SO_PUBLIC static int get_classification_id(const char* name);
 };
 }
 
index 3c7069d281f131f44ab9696a6dc252b0b573f4ae..1d9032b0b1fdf6f4f939993eaafa352018a3a830 100644 (file)
@@ -42,6 +42,7 @@
 #include "parser/vars.h"
 #include "trace/trace_api.h"
 #include "trace/trace_config.h"
+#include "utils/stats.h"
 
 #if defined(UNIT_TEST) || defined(BENCHMARK_TEST)
 #include "catch/unit_test.h"
index a353da2f37763c72007f24fec48419ba034e227b..ffb27a34c757064c33de4f2790032e98ca719a08 100644 (file)
@@ -24,7 +24,7 @@
 // the snort module is for handling command line args,
 // shell commands, and basic application stats
 
-#include "main/thread.h"
+#include "main/snort_types.h"
 
 namespace snort
 {
index 823937fc8afb8d2ccee0df0b8bf2d04d92a8e9f6..c9567c537c1d9ae456f038b49aa8a12786c18d78 100644 (file)
@@ -65,6 +65,14 @@ typedef uint16_t Port;
 #endif
 #endif
 
+// `__thread` is a gnu extension that at present is slightly faster than
+// `thread_local` (possibly due to the lack of dynamic initialization)
+#ifdef USE_THREAD_LOCAL
+#    define THREAD_LOCAL thread_local
+#else
+#    define THREAD_LOCAL __thread
+#endif
+
 #if !defined(__GNUC__) || __GNUC__ < 2 || \
     (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
 #define __attribute__(x)    /* delete __attribute__ if non-gcc or gcc1 */
index 8449408767c3993ea8791680a10602865bcbaeaf..34ced393f1b1028ec4294c756d57d33ab6057e13 100644 (file)
@@ -31,7 +31,7 @@ struct SnortConfig;
 
 class Analyzer;
 
-class SO_PUBLIC Swapper
+class Swapper
 {
 public:
     Swapper(snort::SnortConfig*);
index 5613c64c0b46360ca81129991ce696f42dd6d96e..7bc5e90adedfcec3e65be35c53e92d3c09268db2 100644 (file)
@@ -18,8 +18,8 @@
 // distill_verdict_stubs.h author Ron Dempster <rdempste@cisco.com>
 
 #include "detection/context_switcher.h"
+#include "detection/detection_buf.h"
 #include "detection/detection_engine.h"
-#include "detection/detection_util.h"
 #include "detection/ips_context.h"
 #include "detection/tag.h"
 #include "file_api/file_service.h"
 #include "main/swapper.h"
 #include "main/thread_config.h"
 #include "memory/memory_cap.h"
-#include "network_inspectors/packet_tracer/packet_tracer.h"
 #include "packet_io/active.h"
+#include "packet_io/packet_tracer.h"
 #include "packet_io/sfdaq.h"
 #include "packet_io/sfdaq_instance.h"
 #include "packet_io/sfdaq_module.h"
-#include "profiler/profiler.h"
-#include "profiler/profiler_defs.h"
+#include "profiler/profiler_impl.h"
+#include "profiler/time_profiler_defs.h"
 #include "protocols/packet.h"
 #include "protocols/packet_manager.h"
 #include "side_channel/side_channel.h"
@@ -65,6 +65,8 @@
 
 THREAD_LOCAL DAQStats daq_stats;
 THREAD_LOCAL bool RuleContext::enabled = false;
+THREAD_LOCAL bool snort::TimeProfilerStats::enabled;
+THREAD_LOCAL snort::PacketTracer* snort::PacketTracer::s_pkt_trace;
 
 void Profiler::start() { }
 void Profiler::stop(uint64_t) { }
@@ -97,7 +99,7 @@ void RuleLatency::tterm() { }
 void PacketLatency::tterm() { }
 void SideChannelManager::thread_init() { }
 void SideChannelManager::thread_term() { }
-void CodecManager::thread_init(const snort::SnortConfig*) { }
+void CodecManager::thread_init() { }
 void CodecManager::thread_term() { }
 void EventManager::open_outputs() { }
 void EventManager::close_outputs() { }
@@ -126,9 +128,6 @@ void select_default_policy(const _daq_flow_stats&, const snort::SnortConfig*) {
 namespace snort
 {
 static struct timeval s_packet_time = { 0, 0 };
-THREAD_LOCAL PacketTracer* s_pkt_trace;
-THREAD_LOCAL TimeContext* ProfileContext::curr_time = nullptr;
-THREAD_LOCAL bool TimeProfilerStats::enabled = false;
 THREAD_LOCAL PacketCount pc;
 
 void packet_gettimeofday(struct timeval* tv) { *tv = s_packet_time; }
index a0f03377f73d1fc8e257d25bafbb593fe9bacdef..972e41a3772949f82ce0ab5631d273190368dd49 100644 (file)
 
 #include "main/snort_types.h"
 
-#define THREAD_LOCAL_TBD
-//#define THREAD_LOCAL // for single-threaded debugging
-
-// `__thread` is a gnu extension that at present is slightly faster than
-// `thread_local` (possibly due to the lack of dynamic initialization)
-#ifdef USE_THREAD_LOCAL
-#    define THREAD_LOCAL thread_local
-#else
-#    define THREAD_LOCAL __thread
-#endif
-
 enum SThreadType
 {
     STHREAD_TYPE_OTHER,
index 07c7249ca56d6e372a19cd5354d67ae1bfde0720..072816f0b1bb8e007aa7c1d7e1c917177a4cac2d 100644 (file)
 #include "time/periodic.h"
 #include "utils/util.h"
 
-#ifdef HAVE_NUMA
-#include "utils/util_numa.h"
-#endif
-
 #ifdef UNIT_TEST
 #include "catch/snort_catch.h"
 #endif
 
+#ifdef HAVE_NUMA
+#include "numa.h"
+#endif
+
 using namespace snort;
 using namespace std;
 
index f4db4a8729149de269de47d2e504852d0618c9f4..d748f99e4128e21af35f2d314f3e36f9318d37e6 100644 (file)
@@ -8,23 +8,19 @@ set (CPP_INCLUDES
     ${CMAKE_CURRENT_BINARY_DIR}/lua_coreinit.h
 )
 
-set( MANAGERS_INCLUDES
-    codec_manager.h
-    event_manager.h
-    inspector_manager.h
-)
-
 add_subdirectory(test)
 
 add_library( managers OBJECT
     ${LUA_INCLUDES}
-    ${MANAGERS_INCLUDES}
     ${CPP_INCLUDES}
     action_manager.h
     action_manager.cc
     codec_manager.cc
+    codec_manager.h
     event_manager.cc
+    event_manager.h
     inspector_manager.cc
+    inspector_manager.h
     ips_manager.cc
     ips_manager.h
     lua_plugin_defs.h
@@ -58,10 +54,6 @@ add_custom_command (
 
 include_directories (${CMAKE_CURRENT_BINARY_DIR})
 
-install (FILES ${MANAGERS_INCLUDES}
-    DESTINATION "${INCLUDE_INSTALL_PATH}/managers"
-)
-
 install (FILES ${LUA_INCLUDES}
     DESTINATION "${INCLUDE_INSTALL_PATH}/lua"
 )
index 939c0abac1685049a244fcf0b03fa1545016dd8b..0537684c048f8e1c2d57b940bb0f7662334d0d46 100644 (file)
@@ -59,13 +59,13 @@ struct IpsActionsConfig
 };
 
 using ACList = vector<ActionClass>;
-using ACTypeList = unordered_map<string, Actions::Type>;
+using ACTypeList = unordered_map<string, IpsAction::Type>;
 using ACPriorityList = map<IpsAction::IpsActionPriority, string, std::greater<int>>;
 
 static ACList s_actors;
 static ACTypeList s_act_types;
 static ACPriorityList s_act_priorities;
-static Actions::Type s_act_index = 0;
+static IpsAction::Type s_act_index = 0;
 
 static THREAD_LOCAL ACList* s_tl_actors = nullptr;
 
@@ -81,12 +81,12 @@ void ActionManager::add_plugin(const ActionApi* api)
     s_act_priorities.emplace(api->priority, api->base.name);
 }
 
-std::string ActionManager::get_action_string(Actions::Type action)
+std::string ActionManager::get_action_string(IpsAction::Type action)
 {
     if ( action < s_act_index )
     {
         auto it = std::find_if(s_act_types.cbegin(), s_act_types.cend(),
-            [action](const std::pair<const std::string, Actions::Type>& type){ return type.second == action; });
+            [action](const std::pair<const std::string, IpsAction::Type>& type){ return type.second == action; });
         if ( it != s_act_types.cend())
             return (*it).first;
     }
@@ -94,7 +94,7 @@ std::string ActionManager::get_action_string(Actions::Type action)
     return "ERROR";
 }
 
-Actions::Type ActionManager::get_action_type(const char* s)
+IpsAction::Type ActionManager::get_action_type(const char* s)
 {
     auto type = s_act_types.find(s);
 
@@ -104,7 +104,7 @@ Actions::Type ActionManager::get_action_type(const char* s)
     return get_max_action_types();
 }
 
-Actions::Type ActionManager::get_max_action_types()
+IpsAction::Type ActionManager::get_max_action_types()
 {
     return s_act_index;
 }
@@ -218,7 +218,7 @@ void ActionManager::instantiate(const ActionApi* api, Module* mod, SnortConfig*
         if ( !ips )
             ips = get_ips_policy();
 
-        Actions::Type idx = rln->mode;
+        IpsAction::Type idx = rln->mode;
         if (ips->action[idx] == nullptr)
         {
             ips->action[idx] = act;
index 987a38077a0504f301c39d0f5e162cd27d9ef5c2..13e1be934b12d1c56a8c55bb16ec451fecd5e2fa 100644 (file)
 // which is just a single response deferred until end of current packet
 // processing.
 
-#include "actions/actions.h"
 #include "framework/ips_action.h"
 #include "framework/module.h"
 
 namespace snort
 {
 struct ActionApi;
-class IpsAction;
 struct SnortConfig;
 struct Packet;
 }
@@ -54,9 +52,9 @@ public:
             snort::SnortConfig*, IpsPolicy* ips = nullptr );
     static void initialize_policies(snort::SnortConfig*);
 
-    static std::string get_action_string(Actions::Type);
-    static Actions::Type get_action_type(const char*);
-    static Actions::Type get_max_action_types();
+    static std::string get_action_string(snort::IpsAction::Type);
+    static snort::IpsAction::Type get_action_type(const char*);
+    static snort::IpsAction::Type get_max_action_types();
     static std::string get_action_priorities(bool);
 
     static void thread_init(const snort::SnortConfig*);
index 9580882b7351cd957a02b0bc7f93d20f765539e2..8bcadf2ab4a959886bec0626b31998276d1b3495 100644 (file)
@@ -49,7 +49,6 @@ std::array<Codec*, UINT8_MAX> CodecManager::s_protocols {
 
 THREAD_LOCAL ProtocolId CodecManager::grinder_id = ProtocolId::ETHERTYPE_NOT_SET;
 THREAD_LOCAL uint8_t CodecManager::grinder = 0;
-THREAD_LOCAL uint8_t CodecManager::max_layers = DEFAULT_LAYERMAX;
 
 // This is hardcoded into Snort++
 extern const CodecApi* default_codec;
@@ -134,7 +133,7 @@ void CodecManager::release_plugins()
     s_proto_map.fill(0);
 }
 
-void CodecManager::instantiate(CodecApiWrapper& wrap, Module* m, SnortConfig*)
+void CodecManager::instantiate(CodecApiWrapper& wrap, Module* m)
 {
     if (!wrap.init)
     {
@@ -168,10 +167,10 @@ void CodecManager::instantiate(CodecApiWrapper& wrap, Module* m, SnortConfig*)
     }
 }
 
-void CodecManager::instantiate(const CodecApi* cd_api, Module* m, SnortConfig* sc)
+void CodecManager::instantiate(const CodecApi* cd_api, Module* m)
 {
     CodecApiWrapper& wrap = get_api_wrapper(cd_api);
-    instantiate(wrap, m, sc);
+    instantiate(wrap, m);
 }
 
 void CodecManager::instantiate()
@@ -179,20 +178,18 @@ void CodecManager::instantiate()
     CodecApiWrapper tmp_wrap;
     tmp_wrap.api = default_codec;
     tmp_wrap.init = false;
-    instantiate(tmp_wrap, nullptr, nullptr);
+    instantiate(tmp_wrap, nullptr);
 
     // default codec is the api ... I want the codec.
     s_protocols[0] = s_protocols[get_codec(default_codec->base.name)];
 
     // and instantiate every codec which does not have a module
     for (CodecApiWrapper& wrap : s_codecs)
-        instantiate(wrap, nullptr, nullptr);
+        instantiate(wrap, nullptr);
 }
 
-void CodecManager::thread_init(const SnortConfig* sc)
+void CodecManager::thread_init()
 {
-    max_layers = sc->num_layers;
-
     for ( CodecApiWrapper& wrap : s_codecs )
         if (wrap.api->tinit)
             wrap.api->tinit();
index 1faa8fec7d1108bb69a7dcd44852557ce6527709..302e27d4e9512ca683f6a35fc62ad869f93538e3 100644 (file)
@@ -26,7 +26,7 @@
 #include <array>
 #include <vector>
 
-#include "main/thread.h"
+#include "main/snort_types.h"
 #include "protocols/protocol_ids.h"
 
 namespace snort
@@ -36,7 +36,6 @@ struct CodecApi;
 class Module;
 class PacketManager;
 struct ProfileStats;
-struct SnortConfig;
 }
 
 //-------------------------------------------------------------------------
@@ -54,31 +53,27 @@ public:
     // global plugin initializer
     static void add_plugin(const struct snort::CodecApi*);
     // instantiate a specific codec with a codec specific Module
-    static void instantiate(const snort::CodecApi*, snort::Module*, snort::SnortConfig*);
+    static void instantiate(const snort::CodecApi*, snort::Module*);
     // instantiate any codec for which a module has not been provided.
     static void instantiate();
     // destroy all global codec related information
     static void release_plugins();
     // initialize the current threads DLT and Packet struct
-    static void thread_init(const snort::SnortConfig*);
+    static void thread_init();
     // destroy thread_local data
     static void thread_term();
     // print all of the codec plugins
     static void dump_plugins();
 
-    static uint8_t get_max_layers()
-    { return max_layers; }
-
 private:
     struct CodecApiWrapper;
 
     static std::vector<CodecApiWrapper> s_codecs;
     static std::array<ProtocolIndex, num_protocol_ids> s_proto_map;
-    static std::array<snort::Codec*, UINT8_MAX> s_protocols;
+    static std::array<snort::Codec*, num_protocol_idx> s_protocols;
 
     static THREAD_LOCAL ProtocolId grinder_id;
     static THREAD_LOCAL ProtocolIndex grinder;
-    static THREAD_LOCAL uint8_t max_layers;
 
     /*
      * Private helper functions.  These are all declared here
@@ -86,7 +81,7 @@ private:
      */
 
     // Private struct defined in an anonymous namespace.
-    static void instantiate(CodecApiWrapper&, snort::Module*, snort::SnortConfig*);
+    static void instantiate(CodecApiWrapper&, snort::Module*);
     static CodecApiWrapper& get_api_wrapper(const snort::CodecApi* cd_api);
     static uint8_t get_codec(const char* const keyword);
 };
index 4b5173678165df330723cad5fbaaa9138e4d61ab..bc9dd4af9cf8f97a2ecea83edc364a2df3feefa2 100644 (file)
@@ -37,7 +37,7 @@ struct LogApi;
 struct Packet;
 struct SnortConfig;
 }
-struct Event;
+class Event;
 struct OutputSet;
 
 //-------------------------------------------------------------------------
index aa58eb756f7cdc6f89026dac4c094dd857b51e44..e07d19a2898a85ba9e5fd8611e2152daee847e1e 100644 (file)
 #include <vector>
 
 #include "binder/bind_module.h"
-#include "detection/detect.h"
 #include "detection/detection_engine.h"
 #include "detection/fp_utils.h"
-#include "flow/expect_cache.h"
+#include "flow/expect_flow.h"
 #include "flow/flow.h"
 #include "flow/session.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
 #include "main/shell.h"
 #include "main/snort.h"
@@ -293,7 +293,7 @@ void InspectorList::tterm(PHObjectList* handlers)
 void InspectorList::tterm_removed()
 {
     for ( auto& ri : removed_ilist )
-        ri.instance->tterm(ri.handlers[Inspector::slot]);
+        ri.instance->tterm(ri.handlers[Inspector::get_slot()]);
 }
 
 static PHInstance* get_instance(InspectorList* il, const char* keyword);
@@ -459,12 +459,13 @@ void TrafficPolicy::vectorize(SnortConfig*)
 
 PHObjectList* TrafficPolicy::get_specific_handlers()
 {
+    unsigned slot = Inspector::get_slot();
     assert(ts_handlers);
-    PHObjectList* handlers = ts_handlers->olists[Inspector::slot];
+    PHObjectList* handlers = ts_handlers->olists[slot];
     if (!handlers)
     {
         handlers = new PHObjectList;
-        ts_handlers->olists[Inspector::slot] = handlers;
+        ts_handlers->olists[slot] = handlers;
     }
     return handlers;
 }
@@ -606,7 +607,7 @@ void SingleInstanceInspectorPolicy::tterm(PHObjectList* handlers)
 void SingleInstanceInspectorPolicy::tterm_removed()
 {
     if (removed_instance)
-        removed_instance->tterm(s_tl_handlers[Inspector::slot]);
+        removed_instance->tterm(s_tl_handlers[Inspector::get_slot()]);
 }
 
 void SingleInstanceInspectorPolicy::print_config(SnortConfig* sc, const char* title)
@@ -1120,17 +1121,6 @@ void InspectorManager::update_policy(SnortConfig* sc)
     }
 }
 
-Binder* InspectorManager::get_binder()
-{
-    InspectionPolicy* pi = get_inspection_policy();
-
-    if ( !pi )
-        return nullptr;
-
-    assert(pi->framework_policy);
-    return (Binder*)pi->framework_policy->binder;
-}
-
 void InspectorManager::clear_removed_inspectors(SnortConfig* sc)
 {
     SingleInstanceInspectorPolicy* fid = sc->policy_map->get_file_id();
@@ -1210,158 +1200,7 @@ void InspectorManager::reconcile_inspectors(const SnortConfig* old, SnortConfig*
     }
 }
 
-Inspector* InspectorManager::get_file_inspector(const SnortConfig* sc)
-{
-    if ( !sc )
-        sc = SnortConfig::get_conf();
-    SingleInstanceInspectorPolicy* fid = sc->policy_map->get_file_id();
-    return fid->instance ? fid->instance->handler : nullptr;
-}
-
-// FIXIT-P cache get_inspector() returns or provide indexed lookup
-Inspector* InspectorManager::get_inspector(const char* key, bool dflt_only, const SnortConfig* snort_config)
-{
-    InspectionPolicy* pi;
-    NetworkPolicy* ni;
-
-    const SnortConfig* sc = snort_config;
-    if ( !sc )
-        sc = SnortConfig::get_conf();
-    assert(sc);
-    if ( dflt_only )
-    {
-        ni = get_default_network_policy(sc);
-        pi = ni->get_inspection_policy(0);
-    }
-    else
-    {
-        pi = get_inspection_policy();
-        // During reload, get_network_policy will return the network policy from the new snort config
-        // for a given tenant
-        ni = get_network_policy();
-        if (!snort_config)
-        {
-            // If no snort config is passed in, it means that this is either a normally running system with
-            // the correct network policy set or that get_inspector is being called from Inspector::configure
-            // and it is expecting the inspector from the running configuration and not the new snort config
-            if (ni)
-            {
-                PolicyMap* pm = sc->policy_map;
-                NetworkPolicy* np = pm->get_user_network(ni->user_policy_id);
-                if (np)
-                {
-                    // If network policy is correct, then no need to change the inspection policy
-                    if (np != ni && pi)
-                        pi = np->get_user_inspection_policy(pi->user_policy_id);
-                    ni = np;
-                }
-                else
-                    pi = nullptr;
-            }
-            else
-                pi = nullptr;
-        }
-    }
-
-    if ( pi )
-    {
-        PHInstance* p = get_instance(pi->framework_policy, key);
-        if ( p )
-            return p->handler;
-    }
-
-    if ( ni && ni->traffic_policy )
-    {
-        PHInstance* p = get_instance(ni->traffic_policy, key);
-        if ( p )
-            return p->handler;
-    }
-
-    GlobalInspectorPolicy* pp = sc->policy_map->get_global_inspector_policy();
-    PHInstance* p = get_instance(pp, key);
-    if ( p )
-        return p->handler;
-
-    SingleInstanceInspectorPolicy* ft = sc->policy_map->get_flow_tracking();
-    if ( ft->instance && ft->instance->name == key )
-        return ft->instance->handler;
-
-    SingleInstanceInspectorPolicy* fid = sc->policy_map->get_file_id();
-    if ( fid->instance && fid->instance->name == key )
-        return fid->instance->handler;
-
-    return nullptr;
-}
-
-Inspector* InspectorManager::get_inspector(const char* key, Module::Usage usage, InspectorType type)
-{
-    const SnortConfig* sc = SnortConfig::get_conf();
-    if (!sc)
-        return nullptr;
-
-    if (Module::GLOBAL == usage && IT_FILE == type)
-    {
-        SingleInstanceInspectorPolicy* fid = sc->policy_map->get_file_id();
-        assert(fid);
-        return (fid->instance && fid->instance->name == key) ? fid->instance->handler : nullptr;
-    }
-    else if (Module::GLOBAL == usage && IT_STREAM == type)
-    {
-        SingleInstanceInspectorPolicy* ft = sc->policy_map->get_flow_tracking();
-        assert(ft);
-        return (ft->instance && ft->instance->name == key) ? ft->instance->handler : nullptr;
-    }
-    else
-    {
-        if (Module::GLOBAL == usage && IT_SERVICE != type)
-        {
-            GlobalInspectorPolicy* il = sc->policy_map->get_global_inspector_policy();
-            assert(il);
-            PHInstance* p = il->get_instance_by_type(key, type);
-            return p ? p->handler : nullptr;
-        }
-        else if (Module::CONTEXT == usage)
-        {
-            NetworkPolicy* np = get_network_policy();
-            if (!np)
-                return nullptr;
-            PolicyMap* pm = sc->policy_map;
-            np = pm->get_user_network(np->user_policy_id);
-            if (!np)
-                return nullptr;
-            TrafficPolicy* il = np->traffic_policy;
-            assert(il);
-            PHInstance* p = il->get_instance_by_type(key, type);
-            return p ? p->handler : nullptr;
-        }
-        else
-        {
-            NetworkPolicy* orig_np = get_network_policy();
-            if (!orig_np)
-                return nullptr;
-            PolicyMap* pm = sc->policy_map;
-            NetworkPolicy* np = pm->get_user_network(orig_np->user_policy_id);
-            if (!np)
-                return nullptr;
-            InspectionPolicy* ip = get_inspection_policy();
-            if (!ip)
-                return nullptr;
-            // If network policy is correct, then no need to change the inspection policy
-            if (np != orig_np)
-            {
-                ip = np->get_user_inspection_policy(ip->user_policy_id);
-                if (!ip)
-                    return nullptr;
-            }
-            FrameworkPolicy* il = ip->framework_policy;
-            assert(il);
-            PHInstance* p = il->get_instance_by_type(key, type);
-            return p ? p->handler : nullptr;
-        }
-    }
-}
-
-Inspector* InspectorManager::get_service_inspector_by_service(const char* key)
+Inspector* InspectorManager::get_service_inspector(const char* key)
 {
     InspectionPolicy* pi = get_inspection_policy();
 
@@ -1373,7 +1212,7 @@ Inspector* InspectorManager::get_service_inspector_by_service(const char* key)
     return (g != pi->framework_policy->inspector_cache_by_service.end()) ? g->second : nullptr;
 }
 
-Inspector* InspectorManager::get_service_inspector_by_id(const SnortProtocolId protocol_id)
+Inspector* InspectorManager::get_service_inspector(const SnortProtocolId protocol_id)
 {
     InspectionPolicy* pi = get_inspection_policy();
 
@@ -1504,11 +1343,13 @@ void PHInstance::tterm(PHObjectList* handlers)
 void InspectorManager::thread_init(const SnortConfig* sc)
 {
     SnortConfig::update_thread_reload_id();
+#ifndef _WIN64
     Inspector::slot = get_instance_id();
+#endif
 
     // Initial build out of this thread's configured plugin registry
     PHObjectList* g_handlers = new PHObjectList;
-    s_tl_handlers[Inspector::slot] = g_handlers;
+    s_tl_handlers[Inspector::get_slot()] = g_handlers;
     for ( auto* p : sc->framework_config->clist )
     {
         PHObject& phg = get_thread_local_plugin(p->api, g_handlers);
@@ -1551,7 +1392,7 @@ void InspectorManager::thread_reinit(const SnortConfig* sc)
         sc->policy_map->set_inspector_tinit_complete(instance_id, true);
 
         // Update this thread's configured plugin registry with any newly configured inspectors
-        PHObjectList* g_handlers = s_tl_handlers[Inspector::slot];
+        PHObjectList* g_handlers = s_tl_handlers[Inspector::get_slot()];
         for ( auto* p : sc->framework_config->clist )
         {
             PHObject& phg = get_thread_local_plugin(p->api, g_handlers);
@@ -1621,7 +1462,7 @@ void InspectorManager::thread_stop_removed(const SnortConfig* sc)
 void InspectorManager::thread_stop(const SnortConfig* sc)
 {
     // If thread_init() was never called, we have nothing to do.
-    PHObjectList* g_handlers = s_tl_handlers[Inspector::slot];
+    PHObjectList* g_handlers = s_tl_handlers[Inspector::get_slot()];
     if ( !g_handlers )
         return;
 
@@ -1653,7 +1494,7 @@ void InspectorManager::thread_stop(const SnortConfig* sc)
 void InspectorManager::thread_term()
 {
     // If thread_init() was never called, we have nothing to do.
-    PHObjectList* handlers = s_tl_handlers[Inspector::slot];
+    PHObjectList* handlers = s_tl_handlers[Inspector::get_slot()];
     if ( !handlers )
         return;
 
@@ -1664,7 +1505,7 @@ void InspectorManager::thread_term()
             phg.api.tterm();
     }
     delete handlers;
-    s_tl_handlers[Inspector::slot] = nullptr;
+    s_tl_handlers[Inspector::get_slot()] = nullptr;
 }
 
 //-------------------------------------------------------------------------
@@ -1806,24 +1647,6 @@ static bool configure(SnortConfig* sc, InspectorList* il, bool cloned, bool& new
     return ok;
 }
 
-Inspector* InspectorManager::acquire_file_inspector()
-{
-    Inspector* pi = get_file_inspector();
-
-    if ( !pi )
-        FatalError("unconfigured file inspector\n");
-    else
-        pi->add_global_ref();
-
-    return pi;
-}
-
-void InspectorManager::release(Inspector* pi)
-{
-    assert(pi);
-    pi->rem_global_ref();
-}
-
 bool InspectorManager::configure(SnortConfig* sc, bool cloned)
 {
     if ( !s_sorted )
@@ -2290,3 +2113,183 @@ void InspectorManager::clear(Packet* p)
     p->context->clear_inspectors = false;
 }
 
+Inspector* InspectorManager::get_binder()
+{
+    InspectionPolicy* pi = get_inspection_policy();
+
+    if ( !pi )
+        return nullptr;
+
+    assert(pi->framework_policy);
+    return pi->framework_policy->binder;
+}
+
+Inspector* InspectorManager::get_file_inspector(const SnortConfig* sc)
+{
+    if ( !sc )
+        sc = SnortConfig::get_conf();
+    SingleInstanceInspectorPolicy* fid = sc->policy_map->get_file_id();
+    return fid->instance ? fid->instance->handler : nullptr;
+}
+
+Inspector* InspectorManager::acquire_file_inspector()
+{
+    Inspector* pi = get_file_inspector();
+
+    if ( !pi )
+        FatalError("unconfigured file inspector\n");
+    else
+        pi->add_global_ref();
+
+    return pi;
+}
+
+// FIXIT-P cache get_inspector() returns or provide indexed lookup
+Inspector* InspectorManager::get_inspector(const char* key, bool dflt_only, const SnortConfig* snort_config)
+{
+    InspectionPolicy* pi;
+    NetworkPolicy* ni;
+
+    const SnortConfig* sc = snort_config;
+    if ( !sc )
+        sc = SnortConfig::get_conf();
+    assert(sc);
+    if ( dflt_only )
+    {
+        ni = get_default_network_policy(sc);
+        pi = ni->get_inspection_policy(0);
+    }
+    else
+    {
+        pi = get_inspection_policy();
+        // During reload, get_network_policy will return the network policy from the new snort config
+        // for a given tenant
+        ni = get_network_policy();
+        if (!snort_config)
+        {
+            // If no snort config is passed in, it means that this is either a normally running system with
+            // the correct network policy set or that get_inspector is being called from Inspector::configure
+            // and it is expecting the inspector from the running configuration and not the new snort config
+            if (ni)
+            {
+                PolicyMap* pm = sc->policy_map;
+                NetworkPolicy* np = pm->get_user_network(ni->user_policy_id);
+                if (np)
+                {
+                    // If network policy is correct, then no need to change the inspection policy
+                    if (np != ni && pi)
+                        pi = np->get_user_inspection_policy(pi->user_policy_id);
+                    ni = np;
+                }
+                else
+                    pi = nullptr;
+            }
+            else
+                pi = nullptr;
+        }
+    }
+
+    if ( pi )
+    {
+        PHInstance* p = get_instance(pi->framework_policy, key);
+        if ( p )
+            return p->handler;
+    }
+
+    if ( ni && ni->traffic_policy )
+    {
+        PHInstance* p = get_instance(ni->traffic_policy, key);
+        if ( p )
+            return p->handler;
+    }
+
+    GlobalInspectorPolicy* pp = sc->policy_map->get_global_inspector_policy();
+    PHInstance* p = get_instance(pp, key);
+    if ( p )
+        return p->handler;
+
+    SingleInstanceInspectorPolicy* ft = sc->policy_map->get_flow_tracking();
+    if ( ft->instance && ft->instance->name == key )
+        return ft->instance->handler;
+
+    SingleInstanceInspectorPolicy* fid = sc->policy_map->get_file_id();
+    if ( fid->instance && fid->instance->name == key )
+        return fid->instance->handler;
+
+    return nullptr;
+}
+
+Inspector* InspectorManager::get_inspector(const char* key, Module::Usage usage, InspectorType type)
+{
+    const SnortConfig* sc = SnortConfig::get_conf();
+    if (!sc)
+        return nullptr;
+
+    if (Module::GLOBAL == usage && IT_FILE == type)
+    {
+        SingleInstanceInspectorPolicy* fid = sc->policy_map->get_file_id();
+        assert(fid);
+        return (fid->instance && fid->instance->name == key) ? fid->instance->handler : nullptr;
+    }
+    else if (Module::GLOBAL == usage && IT_STREAM == type)
+    {
+        SingleInstanceInspectorPolicy* ft = sc->policy_map->get_flow_tracking();
+        assert(ft);
+        return (ft->instance && ft->instance->name == key) ? ft->instance->handler : nullptr;
+    }
+    else
+    {
+        if (Module::GLOBAL == usage && IT_SERVICE != type)
+        {
+            GlobalInspectorPolicy* il = sc->policy_map->get_global_inspector_policy();
+            assert(il);
+            PHInstance* p = il->get_instance_by_type(key, type);
+            return p ? p->handler : nullptr;
+        }
+        else if (Module::CONTEXT == usage)
+        {
+            NetworkPolicy* np = get_network_policy();
+            if (!np)
+                return nullptr;
+            PolicyMap* pm = sc->policy_map;
+            np = pm->get_user_network(np->user_policy_id);
+            if (!np)
+                return nullptr;
+            TrafficPolicy* il = np->traffic_policy;
+            assert(il);
+            PHInstance* p = il->get_instance_by_type(key, type);
+            return p ? p->handler : nullptr;
+        }
+        else
+        {
+            NetworkPolicy* orig_np = get_network_policy();
+            if (!orig_np)
+                return nullptr;
+            PolicyMap* pm = sc->policy_map;
+            NetworkPolicy* np = pm->get_user_network(orig_np->user_policy_id);
+            if (!np)
+                return nullptr;
+            InspectionPolicy* ip = get_inspection_policy();
+            if (!ip)
+                return nullptr;
+            // If network policy is correct, then no need to change the inspection policy
+            if (np != orig_np)
+            {
+                ip = np->get_user_inspection_policy(ip->user_policy_id);
+                if (!ip)
+                    return nullptr;
+            }
+            FrameworkPolicy* il = ip->framework_policy;
+            assert(il);
+            PHInstance* p = il->get_instance_by_type(key, type);
+            return p ? p->handler : nullptr;
+        }
+    }
+}
+
+void InspectorManager::release(Inspector* pi)
+{
+    assert(pi);
+    pi->rem_global_ref();
+}
+
index 62ee48dd07136dc3f42170a36183c85c16e53965..032a6179e2b3de0a6d3f4a38f9dd13cb8d561784 100644 (file)
@@ -78,23 +78,6 @@ public:
     static void destroy_global_inspector_policy(GlobalInspectorPolicy*, bool cloned);
     static InspectSsnFunc get_session(uint16_t proto);
 
-    SO_PUBLIC static Inspector* get_file_inspector(const SnortConfig* = nullptr);
-
-    // This assumes that, in a multi-tenant scenario, this is called with the correct network and inspection
-    // policies are set correctly
-    SO_PUBLIC static Inspector* get_inspector(const char* key, bool dflt_only = false, const SnortConfig* = nullptr);
-
-    // This cannot be called in or before the inspector configure phase for a new snort config during reload
-    SO_PUBLIC static Inspector* get_inspector(const char* key, Module::Usage, InspectorType);
-
-    SO_PUBLIC static Inspector* get_service_inspector_by_service(const char*);
-    static Inspector* get_service_inspector_by_id(const SnortProtocolId);
-
-    SO_PUBLIC static Binder* get_binder();
-
-    SO_PUBLIC static Inspector* acquire_file_inspector();
-    SO_PUBLIC static void release(Inspector*);
-
     static bool configure(SnortConfig*, bool cloned = false);
     static void prepare_inspectors(SnortConfig*);
     static void prepare_controls(SnortConfig*);
@@ -116,6 +99,23 @@ public:
     static void reconcile_inspectors(const SnortConfig*, SnortConfig*, bool cloned = false);
     static void clear_removed_inspectors(SnortConfig*);
 
+    static Inspector* get_binder();
+
+    static Inspector* acquire_file_inspector();
+    static Inspector* get_file_inspector(const SnortConfig* = nullptr);
+
+    static Inspector* get_service_inspector(const SnortProtocolId);
+    static Inspector* get_service_inspector(const char*);
+
+    // This assumes that, in a multi-tenant scenario, this is called with the correct network and inspection
+    // policies are set correctly
+    static Inspector* get_inspector(const char* key, bool dflt_only = false, const SnortConfig* = nullptr);
+
+    // This cannot be called in or before the inspector configure phase for a new snort config during reload
+    static Inspector* get_inspector(const char* key, Module::Usage, InspectorType);
+
+    static void release(Inspector*);
+
 private:
     static void bumble(Packet*);
     template<bool T> static void full_inspection(Packet*);
index d3c13aa214d78d8ecf1e8e91731eb463bf173d66..80af347a1be7f9b15933a9ec84732a92f4c873ac 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "detection/fp_detect.h"
 #include "detection/treenodes.h"
+#include "framework/ips_info.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
 
@@ -300,7 +301,8 @@ IpsOption* IpsManager::option_end(
         return nullptr;
     }
 
-    IpsOption* ips = opt->api->ctor(mod, otn);
+    IpsInfo info(otn, sc);
+    IpsOption* ips = opt->api->ctor(mod, info);
     type = opt->api->type;
     current_keyword.clear();
 
index 32747e3521e73ede4f81de067088b60682fb2f00..2a8366b505318c4d9ddaae85547e6a7517cc4607 100644 (file)
@@ -45,7 +45,7 @@
 #include "managers/inspector_manager.h"
 #include "parser/parse_conf.h"
 #include "parser/parser.h"
-#include "profiler/profiler.h"
+#include "profiler/profiler_impl.h"
 #include "protocols/packet_manager.h"
 #include "utils/util.h"
 
index 429db50a35bbc2bd09a75e189ab436753b4b74d3..ea83dc4bf96817f483d53f3621d6767ed88dbf65 100644 (file)
 #include <sstream>
 #include <sys/stat.h>
 
-#include "framework/codec.h"
-#include "framework/connector.h"
-#include "framework/logger.h"
-#include "framework/mpse.h"
-#include "framework/policy_selector.h"
+#include "framework/plugins.h"
 #include "helpers/directory.h"
 #include "helpers/markup.h"
 #include "log/messages.h"
@@ -155,11 +151,9 @@ static void set_key(string& key, Symbol* sym, const char* name)
 static bool compatible_builds(const char* plug_opts)
 {
     const char* snort_opts = API_OPTIONS;
+    assert(snort_opts);
 
-    if ( !snort_opts and !plug_opts )
-        return true;
-
-    if ( !snort_opts or !plug_opts )
+    if ( !plug_opts )
         return false;
 
     if ( strcmp(snort_opts, plug_opts) )
@@ -180,7 +174,10 @@ static bool register_plugin(
     const BaseApi* api, SoHandlePtr handle, const char* file, SnortConfig* sc)
 {
     if ( api->type >= PT_MAX )
+    {
+        ParseWarning(WARN_PLUGINS, "%s: invalid plugin type: %u", file, (unsigned)api->type);
         return false;
+    }
 
     Symbol* sym = symbols + api->type;
 
@@ -250,12 +247,8 @@ static void load_list(
 
 static bool load_lib(const char* file, SnortConfig* sc)
 {
-    struct stat fs;
     void* handle;
 
-    if ( stat(file, &fs) || !(fs.st_mode & S_IFREG) )
-        return false;
-
     if ( !(handle = dlopen(file, RTLD_NOW|RTLD_LOCAL)) )
     {
         if ( const char* err = dlerror() )
@@ -349,8 +342,10 @@ static void load_plugins(const std::string& paths, SnortConfig* sc = nullptr)
     for ( auto& path : path_list )
     {
         if ( stat(path.c_str(), &sb) )
+        {
+            ParseWarning(WARN_PLUGINS, "%s: can't get file status", path.c_str());
             continue;
-
+        }
         if ( sb.st_mode & S_IFDIR )
         {
             Directory d(path.c_str(), lib_pattern);
@@ -358,13 +353,15 @@ static void load_plugins(const std::string& paths, SnortConfig* sc = nullptr)
             while ( const char* f = d.next() )
                 load_lib(f, sc);
         }
-        else
+        else if ( sb.st_mode & S_IFREG )
         {
             if ( path.find("/") == string::npos )
                 path = "./" + path;
 
             load_lib(path.c_str(), sc);
         }
+        else
+            ParseWarning(WARN_PLUGINS, "%s: not a directory or regular file", path.c_str());
     }
 }
 
@@ -516,7 +513,7 @@ void PluginManager::instantiate(
     switch ( api->type )
     {
     case PT_CODEC:
-        CodecManager::instantiate((const CodecApi*)api, mod, sc);
+        CodecManager::instantiate((const CodecApi*)api, mod);
         break;
 
     case PT_INSPECTOR:
index 1446f0e0dd0de24d1b066568edbd8a6018256e2a..d6053d6e0946d39d8c50a23b9adf0984efd64790 100644 (file)
@@ -29,6 +29,7 @@
 #include "framework/policy_selector.h"
 #include "framework/module.h"
 #include "main/snort_config.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
 #include "utils/util.h"
 
index cca82ba26c469e0d7e27ffe2060252e2ef8a4172..d12a73512298acdba6a0756fbe7a1308ffa8df20 100644 (file)
@@ -350,7 +350,6 @@ static const char* sp_help = "a proxy inspector to track flow data from SO rules
 class SoProxy : public Inspector
 {
 public:
-    void eval(Packet*) override { }
     bool configure(SnortConfig* sc) override
     {
         copy(sc->so_rules->handles.begin(), sc->so_rules->handles.end(), back_inserter(handles));
index 27e80aefe71d9bc40b7f89676f0f9942b4f72ac8..21a48ad68466c96be2947cfdc795e57133d9f103 100644 (file)
@@ -18,7 +18,7 @@
 // stubs.h author Ron Dempster <rdempste@cisco.com>
 
 #include "detection/detection_engine.h"
-#include "flow/expect_cache.h"
+#include "flow/expect_flow.h"
 #include "main/policy.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
@@ -45,19 +45,24 @@ void update_buffer_map(const char**, const char*) { }
 
 namespace snort
 {
-unsigned THREAD_LOCAL Inspector::slot = 0;
 [[noreturn]] void FatalError(const char*,...) { exit(-1); }
 void LogMessage(const char*, ...) { }
 void LogLabel(const char*, FILE*) { }
 void ParseError(const char*, ...) { }
 void WarningMessage(const char*, ...) { }
+
 DataBus::DataBus() { }
 DataBus::~DataBus() { }
 void DataBus::publish(unsigned, unsigned, Packet*, Flow*) { }
 unsigned DataBus::get_id(const PubKey&) { return 0; }
+
 void DetectionEngine::disable_content(Packet*) { }
+
 unsigned SnortConfig::get_thread_reload_id() { return 1; }
 void SnortConfig::update_thread_reload_id() { }
+
+THREAD_LOCAL unsigned Inspector::slot = 0;
+bool Inspector::is_inactive() { return true; }
 Inspector::Inspector() { ref_count = nullptr; }
 Inspector::~Inspector() { }
 bool Inspector::likes(Packet*) { return false; }
@@ -69,6 +74,7 @@ void Inspector::rem_global_ref() { }
 void Inspector::allocate_thread_storage() { }
 void Inspector::copy_thread_storage(snort::Inspector*) { }
 const char* InspectApi::get_type(InspectorType) { return ""; }
+
 unsigned ThreadConfig::get_instance_max() { return 1; }
 bool Snort::is_reloading() { return false; }
 SnortProtocolId ProtocolReference::find(const char*) const { return UNKNOWN_PROTOCOL_ID; }
@@ -79,7 +85,7 @@ PegCount Module::get_global_count(const char*) const { return 0; }
 void Module::sum_stats(bool) { }
 void Module::init_stats(bool) { }
 void Module::main_accumulate_stats() { }
-void Module::show_interval_stats(IndexVec&, FILE*) { }
+void Module::show_interval_stats(std::vector<unsigned>&, FILE*) { }
 void Module::show_stats() { }
 void Module::reset_stats() { }
 Module* ModuleManager::get_module(const char*) { return nullptr; }
index 56bd7ccf6a09925dfe2dc485fd79e8572d4c0669..2a3016a3d3a04ec29232e7f0eb54c4be7529e4f7 100644 (file)
@@ -31,8 +31,6 @@
 
 using namespace snort;
 
-bool Inspector::is_inactive() { return true; }
-
 NetworkPolicy* snort::get_network_policy()
 { return (NetworkPolicy*)mock().getData("network_policy").getObjectPointer(); }
 NetworkPolicy* PolicyMap::get_user_network(uint64_t) const
@@ -97,7 +95,6 @@ class TestInspector : public Inspector
 public:
     TestInspector() = default;
     ~TestInspector() override = default;
-    void eval(Packet*) override { }
 };
 
 class TestModule : public Module
index f438b09663bbedb6b510b87b3e7c6138970e49ce..88dbd345fff63a242f3cf6eb11ebd0198b8cd620 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "control/control.h"
 #include "log/messages.h"
-#include "main/thread.h"
 
 namespace memory
 {
index 2254999941fc2379c40fc18a57b04899cf577516..a157f3f978bc63a89e4d6eceeef58f8ed459eb29 100644 (file)
@@ -30,6 +30,7 @@
 #include <cassert>
 #include <vector>
 
+#include "log/log_stats.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
 #include "main/snort_types.h"
index f56d21288314e9a29ac5f7bd74a79c05e6645a00..69083ecf5f9223d1bf7298b688c13aef96bef883 100644 (file)
@@ -26,8 +26,6 @@
 
 #include <cassert>
 
-#include "main/snort.h"
-#include "main/thread.h"
 #include "profiler/memory_profiler_active_context.h"
 
 #include "memory_allocator.h"
index 403cb39ea3472c22fd88ff527f1e176bce370f7c..8d26a6ce748d2a51b6985ddaa0a08c86bf55f352 100644 (file)
@@ -64,10 +64,6 @@ unsigned get_instance_id()
 
 THREAD_LOCAL const Trace* memory_trace = nullptr;
 
-void Periodic::register_handler(PeriodicHook, void*, uint16_t, uint32_t) { }
-
-void Profiler::register_module(const char*, const char*, snort::Module*) { }
-
 void ModuleManager::accumulate_module(const char*) { }
 
 //--------------------------------------------------------------------------
index 31f0f119bb7901559dbaf357821a0393ddbf33a6..0ce5353f1dd145772d8c6ee9aa6015ad72b69bf1 100644 (file)
@@ -3,7 +3,6 @@ set( MIME_INCLUDES
     decode_b64.h
     decode_base.h
     file_mime_config.h
-    file_mime_context_data.h
     file_mime_decode.h
     file_mime_log.h
     file_mime_paf.h
@@ -12,14 +11,8 @@ set( MIME_INCLUDES
 
 add_library ( mime OBJECT
     ${MIME_INCLUDES}
-    file_mime_config.cc
-    file_mime_context_data.cc
-    file_mime_decode.cc
-    file_mime_log.cc
-    file_mime_paf.cc
-    file_mime_process.cc
-    decode_base.cc
     decode_b64.cc
+    decode_base.cc
     decode_bit.cc
     decode_bit.h
     decode_buffer.cc
@@ -28,6 +21,13 @@ add_library ( mime OBJECT
     decode_qp.h
     decode_uu.cc
     decode_uu.h
+    file_mime_config.cc
+    file_mime_context_data.cc
+    file_mime_context_data.h
+    file_mime_decode.cc
+    file_mime_log.cc
+    file_mime_paf.cc
+    file_mime_process.cc
 )
 
 install (FILES ${MIME_INCLUDES}
index 91d150c470549a3c1c890e3d0c94f0df141db37f..db4490770590f56e8ed25cecd4d2f7d819496fdb 100644 (file)
@@ -44,10 +44,7 @@ namespace snort
 {
 // FIXIT-L inbuf should probably be const uint8_t*
 SO_PUBLIC int sf_base64decode(
-    uint8_t* inbuf, uint32_t inbuf_size,
-    uint8_t* outbuf, uint32_t outbuf_size,
-    uint32_t* bytes_written
-    );
+    uint8_t* inbuf, uint32_t inbuf_size, uint8_t* outbuf, uint32_t outbuf_size, uint32_t* bytes_written);
 }
 #endif
 
index deefca43308265c3aa0fbddeaaf80e6bf31817e0..0b7b881e6e865d1b4e5d06f60dc7c0da15a443ec 100644 (file)
@@ -5,7 +5,6 @@ add_subdirectory(binder)
 add_subdirectory(kaizen)
 add_subdirectory(normalize)
 add_subdirectory(packet_capture)
-add_subdirectory(packet_tracer)
 add_subdirectory(perf_monitor)
 add_subdirectory(port_scan)
 add_subdirectory(reputation)
@@ -24,7 +23,6 @@ set(STATIC_NETWORK_INSPECTOR_PLUGINS
     $<TARGET_OBJECTS:binder>
     $<TARGET_OBJECTS:kaizen>
     $<TARGET_OBJECTS:normalize>
-    $<TARGET_OBJECTS:packet_tracer>
     $<TARGET_OBJECTS:port_scan>
     $<TARGET_OBJECTS:reputation>
     $<TARGET_OBJECTS:rna>
index a0f27ce2527e0dfcff7780398d0d33e6f8e8bc0a..5ddbef5c3792dfa62114156d59a4fc009fd5da9e 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "flow/flow.h"
 #include "framework/counts.h"
-#include "main/thread.h"
 #include "target_based/snort_protocols.h"
 #include "utils/util.h"
 
index 65fb7ce48fc1876ad550bdd6ceb6bd5f63366dce..f7ccfec6660825fb4c5c73b27f3f696b41eb1c4c 100644 (file)
@@ -252,8 +252,7 @@ const AppIdSessionApi* AppIdApi::get_appid_session_api(const Flow& flow) const
 
 bool AppIdApi::is_inspection_needed(const Inspector& inspector) const
 {
-    AppIdInspector* appid_inspector = (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME,
-        true);
+    AppIdInspector* appid_inspector = (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, true);
 
     if (!appid_inspector)
         return false;
@@ -269,7 +268,7 @@ bool AppIdApi::is_inspection_needed(const Inspector& inspector) const
 
 const char* AppIdApi::get_appid_detector_directory() const
 {
-    AppIdInspector* inspector = (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME, true);
+    AppIdInspector* inspector = (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, true);
     if (!inspector)
         return "";
 
index e1e99db640a476088e3f1e6a4bf6ece78ab6c04f..dc6ad285953ce84bb09f783653347e1df9e96b08 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef APPID_DEBUG_H
 #define APPID_DEBUG_H
 
+#include <algorithm>
 #include <cstring>
 
 #include <daq_common.h>
@@ -29,7 +30,6 @@
 #include "detection/detection_engine.h"
 #include "protocols/ipv6.h"
 #include "protocols/protocol_ids.h"
-#include "main/thread.h"
 #include "sfip/sf_ip.h"
 
 class AppIdSession;
index b766cbea95b89ed07a433ba58b23a797700f0313..b43e71e234c57c70ce9615c59b8032589c4e2c18 100644 (file)
@@ -27,7 +27,8 @@
 #include "host_tracker/host_cache.h"
 #include "host_tracker/host_cache_segmented.h"
 
-#include "packet_tracer/packet_tracer.h"
+#include "log/messages.h"
+#include "packet_io/packet_tracer.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 #include "protocols/tcp.h"
@@ -67,7 +68,7 @@ static void populate_trace_data(AppIdSession& session)
 
     PacketTracer::daq_log("AppID+%" PRId64"++service: %s(%d), "
         "client: %s(%d), payload: %s(%d), misc: %s(%d)$",
-        TO_NSECS(pt_timer->get()),
+        PacketTracer::get_time(),
         (service_app_name ? service_app_name : ""), service_id,
         (client_app_name ? client_app_name : ""), client_id,
         (payload_app_name ? payload_app_name : ""), payload_id,
index 109e4f592ab31e43eb47a558cf4900e82032e643..4900cce4fd32e28afac0f00ec485c882fdf8b24a 100644 (file)
@@ -66,8 +66,8 @@ bool AppIdHAAppsClient::consume(Flow*& flow, const FlowKey* key, HAMessage& msg,
         return false;
 
     AppIdInspector* inspector =
-        static_cast<AppIdInspector*>(
-            InspectorManager::get_inspector(MOD_NAME, MOD_USAGE, appid_inspector_api.type));
+        static_cast<AppIdInspector*>(InspectorManager::get_inspector(MOD_NAME, MOD_USAGE, appid_inspector_api.type));
+
     if (!inspector or !pkt_thread_odp_ctxt)
         return false;
 
@@ -227,8 +227,8 @@ bool AppIdHAHttpClient::consume(Flow*& flow, const FlowKey* key, HAMessage& msg,
         return false;
 
     AppIdInspector* inspector =
-        static_cast<AppIdInspector*>(
-            InspectorManager::get_inspector(MOD_NAME, MOD_USAGE, appid_inspector_api.type));
+        static_cast<AppIdInspector*>(InspectorManager::get_inspector(MOD_NAME, MOD_USAGE, appid_inspector_api.type));
+
     if (!inspector or !pkt_thread_odp_ctxt)
         return false;
 
@@ -315,8 +315,8 @@ bool AppIdHATlsHostClient::consume(Flow*& flow, const FlowKey* key, HAMessage& m
         return false;
 
     AppIdInspector* inspector =
-        static_cast<AppIdInspector*>(
-            InspectorManager::get_inspector(MOD_NAME, MOD_USAGE, appid_inspector_api.type));
+        static_cast<AppIdInspector*>(InspectorManager::get_inspector(MOD_NAME, MOD_USAGE, appid_inspector_api.type));
+
     if (!inspector or !pkt_thread_odp_ctxt)
         return false;
 
index 32a5807076e65e28af72dd27e5155ab915c13da4..194af507797b0f6cd84062eb5e0a27a2bb1bd360 100644 (file)
@@ -30,6 +30,8 @@
 #include <cassert>
 
 #include "detection/detection_engine.h"
+#include "flow/stream_flow.h"
+
 #include "app_info_table.h"
 #include "app_cpu_profile_table.h"
 #include "appid_debug.h"
index ea17d1562569b35f5bffcc2089cb8b8ec21b382e..ad1a5ff94fbb3a793d667345c63c8c5bf5d85079 100644 (file)
@@ -30,9 +30,9 @@
 
 #include "flow/flow.h"
 #include "main/analyzer_command.h"
-#include "managers/inspector_manager.h"
+#include "main/snort_config.h"
 #include "managers/module_manager.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "profiler/profiler.h"
 #include "pub_sub/appid_event_ids.h"
 #include "pub_sub/intrinsic_event_ids.h"
@@ -237,7 +237,7 @@ void AppIdInspector::eval(Packet* p)
     if (p->flow)
     {
         if (PacketTracer::is_daq_activated())
-            PacketTracer::pt_timer_start();
+            PacketTracer::restart_timer();
 
         AppIdDiscovery::do_application_discovery(p, *this, *pkt_thread_odp_ctxt, pkt_thread_tp_appid_ctxt);
         // FIXIT-L tag verdict reason as appid for daq
index abdcde5e7af0c2f2e3958ca1bb9b5de3046f7f60..c6c4c85f06f5aa329f81164c51b683e71438eff8 100644 (file)
@@ -344,7 +344,8 @@ static int reload_third_party(lua_State* L)
         return 0;
     }
 
-    AppIdInspector* inspector = (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME);
+    AppIdInspector* inspector = (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, true);
+
     if (!inspector)
     {
         ReloadTracker::failed(ctrlcon, "appid not enabled");
@@ -442,7 +443,8 @@ static int reload_detectors(lua_State* L)
         ctrlcon->respond("== reload pending; retry\n");
         return 0;
     }
-    AppIdInspector* inspector = (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME);
+    AppIdInspector* inspector = (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, true);
+
     if (!inspector)
     {
         ctrlcon->respond("== reload detectors failed - appid not enabled\n");
index 92bab107f4d1cabfeb21e4214bba1a4dc5693e94..2bd77928e5316ddb2bb489d229916c84823fde09 100644 (file)
 #include <unordered_map>
 #include <vector>
 
+#include "framework/inspector.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
-#include "main/thread.h"
+#include "main/thread_config.h"
 #include "trace/trace.h"
-#include "utils/stats.h"
 
 #include "app_info_table.h"
 #include "appid_debug.h"
index 6134f959b5e1c7d35430990c354841d31e955128..ce40543f0c3e83279c1fa471947c4d10e6f4f334 100644 (file)
@@ -36,6 +36,8 @@
 
 #include "application_ids.h"
 #include "framework/counts.h"
+#include "log/messages.h"
+#include "utils/util.h"
 
 struct AppIdStats
 {
index 1c9ff25559c713869835087daca7a9e240a91006..cc5e58e5b22d8b2d78227dd2e8ababb9cce03af1 100644 (file)
@@ -26,7 +26,6 @@
 #include "appid_session_api.h"
 
 #include "flow/ha.h"
-#include "managers/inspector_manager.h"
 #include "appid_inspector.h"
 #include "appid_peg_counts.h"
 #include "appid_session.h"
 
 using namespace snort;
 
-THREAD_LOCAL uint32_t AppIdSessionApi::appid_flow_data_id = 0;
+static THREAD_LOCAL uint32_t appid_flow_data_id = 0;
 
 AppIdSessionApi::AppIdSessionApi(const AppIdSession* asd, const SfIp& ip) :
-    StashGenericObject(STASH_GENERIC_OBJECT_APPID), asd(asd), initiator_ip(ip)
-{
-    session_id = std::to_string(get_instance_id()) + "." + std::to_string(++appid_flow_data_id);
-}
+    StashGenericObject(STASH_GENERIC_OBJECT_APPID), asd(asd), initiator_ip(ip),
+    session_id(std::to_string(get_instance_id()) + "." + std::to_string(++appid_flow_data_id))
+{ }
 
 AppId AppIdSessionApi::get_service_app_id() const
 {
index 6d72078b74cddb8de06ac0886861232f03a71d8d..fd6c4e12fea951c645300665c1ddbb261f3c6cb6 100644 (file)
@@ -186,8 +186,6 @@ private:
     ClientAppDescriptor client;
     PayloadAppDescriptor payload;
 
-    static THREAD_LOCAL uint32_t appid_flow_data_id;
-
     void set_ss_application_ids(AppId service, AppId client, AppId payload, AppId misc,
         AppId referred, AppidChangeBits& change_bits, Flow& flow);
     void set_ss_application_ids(AppId client, AppId payload, AppidChangeBits& change_bits, Flow& flow);
index d953594bb1c86b12aa677266cfb2821442eb96a3..39f13c0faad2d022bfbe761e5f4bca5ee84ed5d9 100644 (file)
@@ -17,7 +17,7 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 
-// appid_session.h author Sourcefire Inc.
+// appid_types.h author Sourcefire Inc.
 
 #ifndef APPID_TYPES_H
 #define APPID_TYPES_H
index 441eefdf462eb5307776498e47591d0a78c24499..0f9d26862034d07db58493a9976771e768ded29f 100644 (file)
@@ -23,6 +23,8 @@
 #include "config.h"
 #endif
 
+#include <cassert>
+
 #include "sf_mlmp.h"
 
 #include "search_engines/search_tool.h"
index b2292e9b5de9c0060fc7b20265353f817093cf73..724771e4256625d8e736e9518420695dd7a249a1 100644 (file)
@@ -37,6 +37,8 @@ static const char BIT_BANNER[] = "\023BitTorrent protocol";
 #define MAX_VER_LEN 4
 #define LAST_BANNER_OFFSET  (BIT_BANNER_LEN+RES_LEN+SHA_LEN+PEER_ID_LEN - 1)
 
+namespace
+{
 enum BITState
 {
     BIT_STATE_BANNER = 0,
@@ -64,6 +66,7 @@ struct ClientBITMsg
     uint8_t code;
 };
 #pragma pack()
+} // anonymous
 
 BitClientDetector::BitClientDetector(ClientDiscovery* cdm)
 {
index 63e5b3c3150722008a917c948483e85c697837e7..3c9e7ff5ab93b8aebddc06efe55deaf15b9c1759 100644 (file)
@@ -42,6 +42,8 @@ static const char UDP_BIT_COMMON_END[] = "1:y1:";
 #define UDP_BIT_COMMON_END_LEN (sizeof(UDP_BIT_COMMON_END)-1)
 #define UDP_BIT_END_LEN (UDP_BIT_COMMON_END_LEN+2)
 
+namespace
+{
 enum  BITState
 {
     BIT_STATE_BANNER = 0,
@@ -65,6 +67,7 @@ struct ClientBITData
     BITType type;
     unsigned pos;
 };
+} // anonymous
 
 BitTrackerClientDetector::BitTrackerClientDetector(ClientDiscovery* cdm)
 {
index d9d6a85f7e7eb55d5e551be6542ea24e96dc9691..29c9d075ce5d63a126394327d43586ad784a0019 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <algorithm>
 
+#include "log/messages.h"
 #include "managers/inspector_manager.h"
 #include "utils/util.h"
 #include "appid_debug.h"
@@ -115,7 +116,7 @@ void EveCaPatternMatchers::finalize_patterns()
 
         #ifdef REG_TEST
         AppIdInspector* inspector =
-            (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME, true);
+            (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, true);
         if (inspector and inspector->get_ctxt().config.log_eve_process_client_mappings)
             appid_log(nullptr, TRACE_INFO_LEVEL, "Adding EVE Client App pattern %d %s %d\n",
                 p->app_id, p->pattern.c_str(), p->confidence);
index f8b9393889ed24e99becc65404b156c8c6f4daf1..f877d6681d6cfc124a6f63be3960fabb3b783d0a 100644 (file)
@@ -144,6 +144,8 @@ static const char GOOGLE_TB_PATTERN[] = "toolbarqueries.google.com";
 
 #define COMPATIBLE_BROWSER_STRING " (Compat)"
 
+namespace
+{
 struct MatchedPatterns
 {
     DetectorHTTPPattern* mpattern;
@@ -152,6 +154,7 @@ struct MatchedPatterns
                           // matching character.
     MatchedPatterns* next;
 };
+}
 
 static DetectorHTTPPatterns static_content_type_patterns =
 {
index e9f4e6a606797b3d0213f3a15f9fc01a78090e97..eb6719e2d77f195c8127b720ede430b8f6017956 100644 (file)
@@ -81,7 +81,7 @@ static int cname_pattern_match(void* id, void*, int match_end_pos, void* data, v
     }
     return 0;
 }
-/*  
+/*
 Only patterns that match end of the payload AND
 (match the start of the payload
 or match after '.'
@@ -116,7 +116,7 @@ static bool scan_patterns(SearchTool& matcher, const uint8_t* data, size_t size,
 
     if (!mp)
         return false;
-    
+
     MatchedSslPatterns* tmp = mp;
 
     while (tmp)
index 3ec89ef90510e066c03a5de0b83eb5d14f3c0973..c9a397094225ee74cc1ed38515b6f52039aded29 100644 (file)
@@ -85,7 +85,7 @@ char* snort_strdup(const char* str)
 // 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*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 // LCOV_EXCL_STOP
 
 #ifndef SIP_UNIT_TEST
@@ -95,12 +95,6 @@ public:
     AppIdInspector(AppIdModule&) { }
     ~AppIdInspector() override = default;
     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;
 };
index db0761f498d8db170ffb74b68618ef31154bca0b..1b9db194100f7423f42012130cd15213659f1894 100644 (file)
 #include <map>
 
 #include "host_port_app_cache.h"
-#include "main/thread.h"
+
+#include "log/messages.h"
 #include "managers/inspector_manager.h"
+
 #include "appid_config.h"
 #include "appid_debug.h"
 #include "appid_inspector.h"
@@ -125,9 +127,9 @@ bool HostPortCache::add(const SnortConfig* sc, const SfIp* ip, uint16_t port, Ip
     HostPortVal hv;
 
     hk.ip = *ip;
-    AppIdInspector* inspector =
-        (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, false, sc);
+    AppIdInspector* inspector = (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, true, sc);
     assert(inspector);
+
     const AppIdContext& ctxt = inspector->get_ctxt();
     hk.port = (ctxt.get_odp_ctxt().allow_port_wildcard_host_cache)? 0 : port;
     hk.proto = proto;
@@ -180,9 +182,9 @@ bool HostPortCache::add_host(const SnortConfig* sc, const SfIp* ip, uint32_t* ne
         HostAppIdsVal hv;
 
         hk.ip = *ip;
-        AppIdInspector* inspector =
-            (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, false, sc);
+        AppIdInspector* inspector = (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, true, sc);
         assert(inspector);
+
         const AppIdContext& ctxt = inspector->get_ctxt();
         hk.port = (ctxt.get_odp_ctxt().allow_port_wildcard_host_cache)? 0 : port;
         hk.proto = proto;
@@ -206,9 +208,9 @@ bool HostPortCache::add_host(const SnortConfig* sc, const SfIp* ip, uint32_t* ne
 
         memcpy(&hk.netmask[0], netmask, 16);
 
-        AppIdInspector* inspector =
-            (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, false, sc);
+        AppIdInspector* inspector = (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, true, sc);
         assert(inspector);
+
         const AppIdContext& ctxt = inspector->get_ctxt();
         hk.port = (ctxt.get_odp_ctxt().allow_port_wildcard_host_cache)? 0 : port;
         hk.proto = proto;
index 2a888a756ca7b5d7cb12e10a6c15d079828ca013..a5753dc1f72e25096013c9404af8b54b6f608b0e 100644 (file)
@@ -237,7 +237,7 @@ static void appid_option_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* appid_option_ips_ctor(Module* p, OptTreeNode*)
+static IpsOption* appid_option_ips_ctor(Module* p, IpsInfo&)
 {
     AppIdOptionModule* m = (AppIdOptionModule*)p;
     return new AppIdIpsOption(m->appid_table);
index 554f810d82365b3bf8ebf0b0edd6bf2c437e9260..439e4d465f9441905938915dcd68cd3fe55120c0 100644 (file)
@@ -33,6 +33,7 @@
 #include <fstream>
 
 #include "log/messages.h"
+#include "main/snort_config.h"
 
 #include "appid_config.h"
 #include "appid_debug.h"
index b8a46fd95797b4b6203685e44f921aa22ad6dac9..85582240f4b1bb72f3af76cfa630e9dc2a403f88 100644 (file)
@@ -30,7 +30,6 @@
 #include <lua.hpp>
 #include <lua/lua.h>
 
-#include "main/thread.h"
 #include "main/thread_config.h"
 #include "protocols/protocol_ids.h"
 
index e8462a6b068fe00ab5cb38079d3e021c63bba492..5be483617c78ed537e82928a6037c69067be8801 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <algorithm>
 
+#include "log/messages.h"
 #include "managers/inspector_manager.h"
 #include "utils/util.h"
 #include "appid_debug.h"
@@ -105,7 +106,7 @@ void AlpnPatternMatchers::finalize_patterns()
 
         #ifdef REG_TEST
         AppIdInspector* inspector =
-            (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME, true);
+            (AppIdInspector*)InspectorManager::get_inspector(MOD_NAME, true);
         if (inspector and inspector->get_ctxt().config.log_alpn_service_mappings)
             appid_log(nullptr, TRACE_INFO_LEVEL, "Adding ALPN service App pattern %d %s\n",
                 p->app_id, p->pattern.c_str());
diff --git a/src/network_inspectors/appid/service_plugins/test/service_netbios_test.cc b/src/network_inspectors/appid/service_plugins/test/service_netbios_test.cc
deleted file mode 100644 (file)
index 7843ad9..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-//--------------------------------------------------------------------------
-// Copyright (C) 2020-2024 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.
-//--------------------------------------------------------------------------
-
-// service_netbios_test.cc author Kani Murthi<kamurthi@cisco.com>
-// unit test for service_netbios
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "network_inspectors/appid/service_plugins/service_detector.cc"
-#include "network_inspectors/appid/service_plugins/service_netbios.cc"
-#include "protocols/packet.h"
-#include "service_plugin_mock.h"
-
-#include <CppUTest/CommandLineTestRunner.h>
-#include <CppUTest/TestHarness.h>
-#include <CppUTestExt/MockSupport.h>
-
-void ServiceDiscovery::initialize(AppIdInspector&) {}
-void ServiceDiscovery::reload() {}
-void ServiceDiscovery::finalize_service_patterns() {}
-void ServiceDiscovery::match_by_pattern(AppIdSession&, const Packet*, IpProtocol) {}
-void ServiceDiscovery::get_port_based_services(IpProtocol, uint16_t, AppIdSession&) {}
-void ServiceDiscovery::get_next_service(const Packet*, const AppidSessionDirection, AppIdSession&)
-{}
-int ServiceDiscovery::identify_service(AppIdSession&, Packet*, AppidSessionDirection,
-    AppidChangeBits&) { return 0; }
-int ServiceDiscovery::add_ftp_service_state(AppIdSession&) { return 0; }
-bool ServiceDiscovery::do_service_discovery(AppIdSession&, Packet*, AppidSessionDirection,
-    AppidChangeBits&) { return false; }
-int ServiceDiscovery::incompatible_data(AppIdSession&, const Packet*,AppidSessionDirection,
-    ServiceDetector*) { return 0; }
-int ServiceDiscovery::fail_service(AppIdSession&, const Packet*, AppidSessionDirection,
-    ServiceDetector*, ServiceDiscoveryState*) { return 0; }
-int ServiceDiscovery::add_service_port(AppIdDetector*,
-    const ServiceDetectorPort&) { return APPID_EINVALID; }
-void AppIdSessionApi::set_netbios_name(AppidChangeBits&, const char*) {}
-void AppIdSessionApi::set_netbios_domain(AppidChangeBits&, const char*) {}
-
-TEST_GROUP(service_netbios_test){};
-
-TEST(service_netbios_test, check_add_smb_info_pointer )
-{
-    const uint8_t data[] = { 0x11, 0x02, 0x45, 0x63, 0xac, 0x1f, 0x13, 0x49, 0x00, 0x8a, 0x00, 0xd7,
-        0x00, 0x00, 0x20, 0x45, 0x50, 0x45, 0x4c, 0x45, 0x4a, 0x43, 0x4e, 0x44, 0x42, 0x44, 0x46,
-        0x45, 0x46, 0x44, 0x47, 0x45, 0x43, 0x45, 0x44, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43,
-        0x41, 0x43, 0x41, 0x41, 0x41, 0x00, 0x20, 0x46, 0x48, 0x45, 0x50, 0x46, 0x43, 0x45, 0x4c,
-        0x45, 0x48, 0x46, 0x43, 0x45, 0x50, 0x46, 0x46, 0x46, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43,
-        0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x42, 0x4e, 0x00, 0xff, 0x53, 0x4d, 0x42, 0x25,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00,
-        0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x56, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00,
-        0x02, 0x00, 0x40, 0x00, 0x5c, 0x4d, 0x41, 0x49, 0x4c, 0x53, 0x4c, 0x4f, 0x54, 0x5c, 0x42,
-        0x52, 0x4f, 0x57, 0x53, 0x45, 0x00, 0x01, 0x00, 0x60, 0xea, 0x00, 0x00, 0x4f, 0x4b, 0x49,
-        0x2d, 0x31, 0x35, 0x45, 0x36, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
-        0x03, 0x22, 0x41, 0x00, 0x0f, 0x01, 0x55, 0xaa, 0x43, 0x68, 0x61, 0x6e, 0x64, 0x72, 0x61,
-        0x27, 0x73, 0x20, 0x63, 0x75, 0x62, 0x65, 0x01};
-    uint16_t size =215;
-    AppidSessionDirection dir = APP_ID_FROM_INITIATOR;
-    AppIdInspector ins;
-    OdpContext odp_ctxt(config, nullptr);
-    snort::Packet pkt;
-    AppidChangeBits cb;
-    SfIp ip;
-    AppIdSession asd(IpProtocol::TCP, &ip, 21, ins, odp_ctxt);
-    AppIdDiscoveryArgs args(data, size, dir, asd, &pkt,cb);
-    ServiceDiscovery& s_discovery_manager = asd.get_odp_ctxt().get_service_disco_mgr();
-    args.pkt->ptrs.sp = args.pkt->ptrs.dp = 138;
-    NbdgmServiceDetector nsd(&s_discovery_manager);
-    nsd.validate(args);
-    FpSMBData *smb_ptr1 = (FpSMBData*)(asd.get_flow_data(APPID_SESSION_DATA_SMB_DATA));
-    nsd.validate(args);
-    FpSMBData *smb_ptr2 = (FpSMBData*)(asd.get_flow_data(APPID_SESSION_DATA_SMB_DATA));
-    CHECK(smb_ptr1 == smb_ptr2);
-    asd.free_flow_data();
-    delete &asd.get_api();
-}
-
-int main(int argc, char** argv)
-{
-    int return_value = CommandLineTestRunner::RunAllTests(argc, argv);
-    return return_value;
-}
index bebe043518b74ba8cf8c28c45c5c062ca7f929c3..0e255657db93c8b5d2014aa6154560d3c3bd9702 100644 (file)
@@ -22,7 +22,6 @@
 #include "appid_detector.h"
 #include "appid_module.h"
 #include "appid_peg_counts.h"
-#include "utils/stats.h"
 
 #define APPID_UT_ID 1492
 
@@ -65,11 +64,6 @@ char* snort_strdup(const char* str)
     memcpy(p, str, n);
     return p;
 }
-class InspectorManager
-{
-public:
-SO_PUBLIC static Inspector* get_inspector(const char*, bool, SnortConfig*) {return nullptr;}
-};
 Module::Module(const char*, const char*) {}
 Module::Module(const char*, const char*, const Parameter*, bool)
 {}
@@ -118,13 +112,12 @@ int AppIdSession::add_flow_data(void*, unsigned, AppIdFreeFCN) { return 0; }
 int dcerpc_validate(const uint8_t*, int){return 0; }
 AppIdDiscovery::~AppIdDiscovery() { }
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const vector<unsigned>&, const char*, FILE*) { }
 AppIdConfig config;
 AppIdContext ctxt(config);
 class AppIdInspector : public snort::Inspector
 {
 public:
-    void eval(Packet*) override { }
     bool configure(snort::SnortConfig*) override { return true; }
 };
 
index c62636992088729ba9022febd66eb7f4329fb9b8..ec552b19c9065d7ca777ddc7249a0865b1e16f43 100644 (file)
@@ -27,6 +27,7 @@
 #include <string>
 
 #include "framework/data_bus.h"
+#include "managers/inspector_manager.h"
 #include "protocols/protocol_ids.h"
 #include "pub_sub/appid_event_ids.h"
 #include "service_inspectors/http_inspect/http_msg_header.h"
index d9c1dd3df08e1e69eed22fe46c5dac19335b8aa3..92ae8dd1d4afcf7011cdb512d4d94d6f1f99fdad 100644 (file)
@@ -28,7 +28,7 @@
 #include "host_tracker/host_cache.h"
 #include "network_inspectors/appid/appid_discovery.cc"
 #include "network_inspectors/appid/appid_peg_counts.h"
-#include "network_inspectors/packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "pub_sub/appid_event_ids.h"
 #include "search_engines/search_tool.h"
 #include "utils/sflsq.cc"
@@ -52,11 +52,9 @@ AppIdApi appid_api;
 const char* AppIdApi::get_application_name(AppId, OdpContext&) { return NULL; }
 
 // Stubs for packet tracer
-THREAD_LOCAL PacketTracer* s_pkt_trace = nullptr;
-THREAD_LOCAL Stopwatch<SnortClock>* pt_timer = nullptr;
 void PacketTracer::daq_log(const char*, ...) { }
-void FatalError(const char* fmt, ...) { (void)fmt; exit(1); }
-void WarningMessage(const char*,...) { }
+uint64_t PacketTracer::get_time() { return 0; }
+THREAD_LOCAL PacketTracer* PacketTracer::s_pkt_trace = nullptr;
 
 // Stubs for packet
 Packet::Packet(bool) {}
@@ -87,6 +85,9 @@ PegCount Module::get_global_count(char const*) const { return 0; }
 void LogLabel(const char*, FILE*) {}
 void LogText(const char*, FILE*) {}
 
+void FatalError(const char* fmt, ...) { (void)fmt; exit(1); }
+void WarningMessage(const char*,...) { }
+
 // Stubs for utils
 char* snort_strdup(const char* str)
 {
index 81adda7ad1bcdb52bc779e96aeca13eb97873ace..9c9eb7c1c4994432d7be3484711e3b4e23364378 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "framework/data_bus.h"
 #include "protocols/protocol_ids.h"
+#include "profiler/profiler_impl.h"
 #include "service_inspectors/http_inspect/http_msg_header.h"
 #include "tp_appid_module_api.h"
 #include "tp_appid_session_api.h"
index af5093fbe2c6b2872e452aa1a624018fcff38b95..5ada0ec6f4348f4665e494893192a77881a14b7b 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "network_inspectors/appid/appid_session_api.cc"
 
+#include "managers/inspector_manager.h"
+
 #include "appid_mock_definitions.h"
 #include "appid_mock_session.h"
 
index 1dc854b7e50dbdcf22e30855ed67f6b950305d0a..421e6f7a6cb9bcb82931d99cf54cbd04716f2a2a 100644 (file)
@@ -28,6 +28,9 @@
 #define TP_SUPPORTED 1
 
 #include "tp_lib_handler.h"
+
+#include "profiler/profiler.h"
+
 #include "appid_config.h"
 #include "log_message_mock.h"
 
@@ -73,13 +76,8 @@ int ServiceDiscovery::add_service_port(AppIdDetector*, const ServiceDetectorPort
 { return 0; }
 void appid_log(const snort::Packet*, unsigned char, char const*, ...) { }
 
-
 THREAD_LOCAL ProfileStats tp_appid_perf_stats;
 THREAD_LOCAL bool TimeProfilerStats::enabled = false;
-MemoryContext::MemoryContext(MemoryTracker&) { }
-MemoryContext::~MemoryContext() = default;
-THREAD_LOCAL TimeContext* ProfileContext::curr_time = nullptr;
-
 
 TEST_GROUP(tp_lib_handler)
 {
index 6574ece61ab7792fc5b84fc17f7ec4c2ba00fd49..a40148bdd36c92fe9b6123be29b1ab219c1e1ec0 100644 (file)
 #endif
 
 #include "tp_appid_module_api.h"
+
 #include "managers/module_manager.h"
+#include "profiler/profiler.h"
+
 #include "appid_module.h"
 #include "tp_lib_handler.h"
 
index 96eb57b7590ce3beb5513b13be52b11aa174953b..a56e18ff0c33cc6e2d1ea96feeaa1c7c799843fa 100644 (file)
@@ -24,8 +24,8 @@
 #include <vector>
 #include <string>
 
-#include "main/thread.h"
-#include "profiler/profiler_defs.h"
+#include "main/snort_types.h"
+
 #include "tp_appid_types.h"
 
 #define THIRD_PARTY_APPID_API_VERSION 6
index cb2c6264b11bfca7d8f1d0d40c74bfe6ef716663..daa70ac90197cff6dfeb5dd381eb4fc31b8d5118 100644 (file)
@@ -26,6 +26,7 @@
 #include <iostream>
 #include <dlfcn.h>
 
+#include "main/snort_config.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 #include "stream/stream.h"
index c04bc7c6e04d457576ff729b24029165a899169f..6fb55c524996e6e104b3a3c039a3618d79b9a8c6 100644 (file)
@@ -75,7 +75,6 @@
 #include <sstream>
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "log/messages.h"
 #include "profiler/profiler.h"
 #include "protocols/arp.h"
index 5bbc9f01cbbebd68d78642d2c5e5cdbacd4710dc..6d034702cce60a887bc51add9d7195c4d2ef0721 100644 (file)
@@ -124,16 +124,6 @@ static const Parameter binder_when_params[] =
     { "service", Parameter::PT_STRING, nullptr, nullptr,
       "override default configuration" },
 
-    // FIXIT-D deprecated zone parameters to be removed
-    { "zones", Parameter::PT_STRING, nullptr, nullptr,
-      "deprecated alias for groups" },
-
-    { "src_zone", Parameter::PT_STRING, nullptr, nullptr,
-      "deprecated alias for src_groups" },
-
-    { "dst_zone", Parameter::PT_STRING, nullptr, nullptr,
-      "deprecated alias for dst_groups" },
-
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
@@ -325,19 +315,19 @@ bool BinderModule::set(const char* fqn, Value& v, SnortConfig*)
             return false;
         binding.when.add_criteria(BindWhen::Criteria::BWC_SPLIT_INTFS);
     }
-    else if ( v.is("groups") || v.is("zones") )
+    else if ( v.is("groups") )
     {
         if (!parse_int_set<int16_t>(v, binding.when.src_groups))
             return false;
         binding.when.add_criteria(BindWhen::Criteria::BWC_GROUPS);
     }
-    else if ( v.is("src_groups") || v.is("src_zone") )
+    else if ( v.is("src_groups") )
     {
         if (!parse_int_set<int16_t>(v, binding.when.src_groups))
             return false;
         binding.when.add_criteria(BindWhen::Criteria::BWC_SPLIT_GROUPS);
     }
-    else if ( v.is("dst_groups") || v.is("dst_zone") )
+    else if ( v.is("dst_groups") )
     {
         if (!parse_int_set<int16_t>(v, binding.when.dst_groups))
             return false;
index 171b61cebd4702af96dc1f3189ca340d34c5213f..ccef0efb19ad413025bef9c4f630e1cfac79d0a4 100644 (file)
@@ -23,7 +23,9 @@
 
 #include "detection/detection_engine.h"
 #include "flow/flow.h"
+#include "framework/pig_pen.h"
 #include "log/messages.h"
+#include "main/snort_config.h"
 #include "managers/inspector_manager.h"
 #include "packet_io/active.h"
 #include "profiler/profiler.h"
@@ -31,6 +33,7 @@
 #include "pub_sub/assistant_gadget_event.h"
 #include "pub_sub/intrinsic_event_ids.h"
 #include "pub_sub/stream_event_ids.h"
+#include "sfip/sf_cidr.h"
 #include "stream/stream.h"
 #include "stream/stream_splitter.h"
 #include "target_based/host_attributes.h"
@@ -51,7 +54,7 @@ static Inspector* get_gadget(const SnortProtocolId protocol_id)
     if (protocol_id == UNKNOWN_PROTOCOL_ID)
         return nullptr;
 
-    return InspectorManager::get_service_inspector_by_id(protocol_id);
+    return InspectorManager::get_service_inspector(protocol_id);
 }
 
 static std::string to_string(const sfip_var_t* list)
@@ -460,7 +463,7 @@ void Stuff::apply_service(Flow& flow)
 void Stuff::apply_assistant(Flow& flow, const char* service)
 {
     if (!gadget)
-        gadget = InspectorManager::get_service_inspector_by_service(service);
+        gadget = InspectorManager::get_service_inspector(service);
 
     if (gadget)
         flow.set_assistant_gadget(gadget);
@@ -481,8 +484,6 @@ public:
     bool configure(SnortConfig*) override;
     void show(const SnortConfig*) const override;
 
-    void eval(Packet*) override { }
-
     void handle_packet(const Packet*);
     void handle_flow_setup(Flow&, bool standby = false);
     void handle_flow_service_change(Flow&);
@@ -512,7 +513,7 @@ public:
 
     void handle(DataEvent& e, Flow*) override
     {
-        Binder* binder = InspectorManager::get_binder();
+        Binder* binder = (Binder*)InspectorManager::get_binder();
         if (binder)
             binder->handle_packet(e.get_packet());
     }
@@ -526,7 +527,7 @@ public:
 
     void handle(DataEvent&, Flow* flow) override
     {
-        Binder* binder = InspectorManager::get_binder();
+        Binder* binder = (Binder*)InspectorManager::get_binder();
         if (binder && flow && !flow->flags.ha_flow)
             binder->handle_flow_setup(*flow);
     }
@@ -540,7 +541,7 @@ public:
 
     void handle(DataEvent&, Flow* flow) override
     {
-        Binder* binder = InspectorManager::get_binder();
+        Binder* binder = (Binder*)InspectorManager::get_binder();
         if (binder && flow)
             binder->handle_flow_service_change(*flow);
     }
@@ -554,7 +555,7 @@ public:
 
     void handle(DataEvent&, Flow* flow) override
     {
-        Binder* binder = InspectorManager::get_binder();
+        Binder* binder = (Binder*)InspectorManager::get_binder();
         if (binder && flow)
             binder->handle_flow_setup(*flow, true);
     }
@@ -567,7 +568,7 @@ public:
 
     void handle(DataEvent& event, Flow* flow) override
     {
-        Binder* binder = InspectorManager::get_binder();
+        Binder* binder = (Binder*)InspectorManager::get_binder();
         AssistantGadgetEvent* assistant_event = (AssistantGadgetEvent*)&event;
 
         if (binder && flow)
@@ -584,7 +585,7 @@ public:
     {
         if (flow && Flow::FlowState::INSPECT == flow->flow_state)
         {
-            Binder* binder = InspectorManager::get_binder();
+            Binder* binder = (Binder*)InspectorManager::get_binder();
             if (binder)
                 binder->handle_flow_after_reload(*flow);
         }
@@ -939,7 +940,7 @@ void Binder::get_bindings(Flow& flow, Stuff& stuff, const char* service)
     get_policy_bindings(flow, service);
 
     // If policy selection produced a new binder to use, use that instead.
-    Binder* sub = InspectorManager::get_binder();
+    Binder* sub = (Binder*)InspectorManager::get_binder();
     if (sub && sub != this)
     {
         sub->get_bindings(flow, stuff, service);
@@ -970,7 +971,7 @@ void Binder::get_bindings(Packet* p, Stuff& stuff)
     get_policy_bindings(p);
 
     // If policy selection produced a new binder to use, use that instead.
-    Binder* sub = InspectorManager::get_binder();
+    Binder* sub = (Binder*)InspectorManager::get_binder();
     if (sub && sub != this)
     {
         sub->get_bindings(p, stuff);
index b6710d4a8d2e6ee33ad82d2f412b112df051e335..2b548007fd2b60061e0cfb78dcf5378fe4154062 100644 (file)
@@ -107,6 +107,7 @@ void Binding::configure(const SnortConfig* sc)
     {
         const char* name = use.name.c_str();
         Inspector* ins = InspectorManager::get_inspector(name, use.global_type, sc);
+
         if (ins)
         {
             switch (ins->get_api()->type)
index adf6977892b7bdb52ae3d34e0e753fb36c40e01f..bc27133fba95a422daf7021839312efe24c4fafc 100644 (file)
@@ -22,9 +22,9 @@
 
 #include <string>
 
-#include "framework/bits.h"
 #include "main/policy.h"
 #include "sfip/sf_ipvar.h"
+#include "utils/bits.h"
 
 namespace snort
 {
index bf3e745afb03ca4e4cce925f7684d8df633702ad..a84eaad4a53999e5859790eac4504a9f6931bd7e 100644 (file)
@@ -22,7 +22,6 @@
 #define NORM_STATS_H
 
 #include "framework/counts.h"
-#include "main/thread.h"
 
 #include "normalize.h"
 
index f778e0574cd2666d8a6e305d93963845094c7271..b546bef4b6d5673b698e5d6861f463450243d273 100644 (file)
@@ -29,7 +29,6 @@
 #include "framework/inspector.h"
 #include "log/messages.h"
 #include "packet_io/sfdaq.h"
-#include "packet_io/sfdaq_instance.h"
 #include "protocols/packet.h"
 #include "utils/util.h"
 
diff --git a/src/network_inspectors/packet_tracer/CMakeLists.txt b/src/network_inspectors/packet_tracer/CMakeLists.txt
deleted file mode 100644 (file)
index e4bcc19..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-set (PACKET_TRACER_INCLUDES
-    packet_tracer.h
-)
-
-add_library ( packet_tracer OBJECT
-    ${PACKET_TRACER_INCLUDES}
-    packet_tracer.cc
-    packet_tracer_module.h
-    packet_tracer_module.cc
-)
-
-install(FILES ${PACKET_TRACER_INCLUDES}
-    DESTINATION "${INCLUDE_INSTALL_PATH}/network_inspectors/packet_tracer"
-)
\ No newline at end of file
index bfc8d83e80d7922fa4637f18bfa9696f84dc728e..79cec8dc5100d9894efe88b95fbf18a3a3a19c60 100644 (file)
@@ -36,6 +36,8 @@
 #include "catch/snort_catch.h"
 #endif
 
+#include "main/thread.h"
+
 #define TRACKER_NAME PERF_NAME "_cpu"
 
 using namespace snort;
index 7a62076b1c9e2eaedfc2b7b72980ca36d76287b2..422c2ba5bca1f05372197a5cd57b4d3105a26f5d 100644 (file)
@@ -22,8 +22,6 @@
 
 #include <sstream>
 
-#include "utils/stats.h"
-
 #if HAVE_CONFIG_H
 #include "config.h"
 #endif
index 3019d053d68e75c3134363397a70cb0c6cd40e0c..b3c46afd73d8e8d7283fbc319e2f395c38c370d9 100644 (file)
 #include <lua.hpp>
 
 #include "control/control.h"
+#include "framework/pig_pen.h"
 #include "log/messages.h"
 #include "main/analyzer_command.h"
-#include "main/snort.h"
+#include "main/snort_config.h"
 #include "managers/module_manager.h"
 
 #include "perf_monitor.h"
@@ -138,7 +139,7 @@ bool PerfMonFlowIPDebug::execute(Analyzer&, void**)
 static int enable_flow_ip_profiling(lua_State* L)
 {
     PerfMonitor* perf_monitor =
-        (PerfMonitor*)InspectorManager::get_inspector(PERF_NAME, true);
+        (PerfMonitor*)PigPen::get_inspector(PERF_NAME, true);
 
     if (!perf_monitor)
     {
@@ -162,7 +163,7 @@ static int enable_flow_ip_profiling(lua_State* L)
 static int disable_flow_ip_profiling(lua_State* L)
 {
     PerfMonitor* perf_monitor =
-        (PerfMonitor*)InspectorManager::get_inspector(PERF_NAME, true);
+        (PerfMonitor*)PigPen::get_inspector(PERF_NAME, true);
 
     if (!perf_monitor)
     {
@@ -193,7 +194,7 @@ static int show_flow_ip_profiling(lua_State* L)
     bool status = false;
     ControlConn* ctrlcon = ControlConn::query_from_lua(L);
 
-    PerfMonitor* perf_monitor = (PerfMonitor*)InspectorManager::get_inspector(PERF_NAME, true);
+    PerfMonitor* perf_monitor = (PerfMonitor*)PigPen::get_inspector(PERF_NAME, true);
 
     if (perf_monitor)
         status = perf_monitor->is_flow_ip_enabled();
@@ -324,7 +325,7 @@ bool PerfMonModule::begin(const char* fqn, int idx, SnortConfig*)
 bool PerfMonModule::end(const char* fqn, int idx, SnortConfig* sc)
 {
 
-    if ( Snort::is_reloading() && strcmp(fqn, "perf_monitor") == 0 )
+    if ( PigPen::snort_is_reloading() && strcmp(fqn, "perf_monitor") == 0 )
         sc->register_reload_handler(new PerfMonReloadTuner(config->flowip_memcap));
 
     if ( idx != 0 && strcmp(fqn, "perf_monitor.modules") == 0 )
index 0b223e19d61671e2532cb11b5d35087ef418f017..2625e0384c4e4b71488da74c24bb9ced3625b50f 100644 (file)
@@ -61,7 +61,7 @@ struct ModuleConfig
     // state optimized for run time using indices
     // can't be determined until all modules have loaded (PerfMonitor::configure)
     snort::Module* ptr;
-    IndexVec pegs;
+    std::vector<unsigned> pegs;
 
     void set_name(const std::string& name);
     void set_peg_names(snort::Value& peg_names);
index 160027f69ebb9449749cb79edd768c3a3d2682f0..59a08f4398326d2c63cc8e9b89be1b6543b7f3f2 100644 (file)
 #include "perf_monitor.h"
 
 #include "framework/data_bus.h"
+#include "framework/pig_pen.h"
 #include "hash/hash_defs.h"
 #include "hash/xhash.h"
 #include "log/messages.h"
 #include "main/analyzer_command.h"
-#include "main/thread.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 #include "pub_sub/intrinsic_event_ids.h"
@@ -231,7 +231,7 @@ void PerfMonitor::tinit()
 
 bool PerfMonReloadTuner::tinit()
 {
-    PerfMonitor* pm = (PerfMonitor*)InspectorManager::get_inspector(PERF_NAME, true);
+    PerfMonitor* pm = (PerfMonitor*)PigPen::get_inspector(PERF_NAME, true);
     auto* new_constraints = pm->get_constraints();
 
     if (new_constraints->flow_ip_enabled)
@@ -351,7 +351,7 @@ void PerfMonitor::eval(Packet* p)
         if (ready_to_process(p))
         {
 #ifdef ENABLE_MEMORY_PROFILER
-            Profiler::show_runtime_memory_stats();
+            PigPen::show_runtime_memory_stats();
 #endif
             for (unsigned i = 0; i < trackers->size(); i++)
             {
index 31424c7528d0052ec7b2c0e50d181835c161ceea..f0704cf342ea3e08a3514878c445b38745d0a0c3 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef PERF_MONITOR_H
 #define PERF_MONITOR_H
 
-#include "managers/inspector_manager.h"
 #include "protocols/packet.h"
 
 #include "base_tracker.h"
index 0c7cda2f811b0361c853b0e5ed2ce31d853ba2c7..fc74e81a721f188705575c0ee331fab026a433c5 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "log/messages.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "utils/util.h"
 #include "utils/util_cstring.h"
 
index 7d913ade8647d1cb999cbb4de1e8e4faea5c4132..4219938cd6edc449d3a8b512a2686b39cd4c8cea 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <sstream>
 
-#include "utils/stats.h"
+#include "log/log_stats.h"
 
 #ifdef UNIT_TEST
 #include <cstdio>
index c58a956eac83d59d1cd0f702b3eae710ed1cac39..44e47215afaceb9d7cd67c233f6506ad569cd97e 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "detection/detection_engine.h"
 #include "log/messages.h"
-#include "managers/inspector_manager.h"
 #include "profiler/profiler.h"
 #include "utils/util.h"
 #include "utils/util_cstring.h"
index cb64e18a2626bd89eba7e34fd0ac34aba317dbc5..1c5fd8dd5462ec677bd3134b7b5687e3475c5246 100644 (file)
@@ -42,7 +42,6 @@
 #include "stream/stream.h"
 #include "time/packet_time.h"
 #include "utils/cpp_macros.h"
-#include "utils/stats.h"
 
 #include "ps_inspect.h"
 #include "ps_pegs.h"
index 922c4726104fbc548ad1cf1173d05fe9d8ffb823..06b9577b612b4581f96eafe0eabc85522f8c91f7 100644 (file)
@@ -23,8 +23,9 @@
 #endif
 
 #include "ps_module.h"
+
+#include "framework/pig_pen.h"
 #include "log/messages.h"
-#include "main/snort.h"
 #include "main/snort_config.h"
 
 #include <cassert>
@@ -329,7 +330,7 @@ bool PortScanModule::set(const char* fqn, Value& v, SnortConfig*)
 
 bool PortScanModule::end(const char* fqn, int, SnortConfig* sc)
 {
-    if ( Snort::is_reloading() && strcmp(fqn, "port_scan") == 0 )
+    if ( PigPen::snort_is_reloading() && strcmp(fqn, "port_scan") == 0 )
         sc->register_reload_handler(new PortScanReloadTuner(config->memcap));
     return true;
 }
index 4f4a683385c12237dfb790dbe60a1f8e4e09e995..9270e3df5ad32e73df466392a3b06c131209db51 100644 (file)
 #include "reputation_commands.h"
 
 #include "control/control.h"
+#include "framework/pig_pen.h"
 #include "log/messages.h"
 #include "main/analyzer_command.h"
-#include "managers/inspector_manager.h"
+#include "main/snort_config.h"
 
 #include "reputation_common.h"
 #include "reputation_inspect.h"
@@ -75,7 +76,8 @@ bool ReputationReload::execute(Analyzer&, void**)
 static int reload(lua_State* L)
 {
     ControlConn* ctrlcon = ControlConn::query_from_lua(L);
-    Reputation* ins = static_cast<Reputation*>(InspectorManager::get_inspector(REPUTATION_NAME));
+    Reputation* ins = static_cast<Reputation*>(PigPen::get_inspector(REPUTATION_NAME));
+
     if (ins)
         main_broadcast_command(new ReputationReload(ctrlcon, *ins), ctrlcon);
     else
index 7c3548bbeee77e821ec2ddfa4ae5d22faa781e90..9c718b945e62687b6260ff9b9d7a523ed223aeb4 100644 (file)
 #ifndef REPUTATION_COMMON_H
 #define REPUTATION_COMMON_H
 
-#define REPUTATION_NAME "reputation"
-#define REPUTATION_HELP "reputation inspection"
-
 #define GID_REPUTATION 136
 
-#define REPUTATION_EVENT_BLOCKLIST_SRC   1
-#define REPUTATION_EVENT_ALLOWLIST_SRC   2
-#define REPUTATION_EVENT_MONITOR_SRC     3
-#define REPUTATION_EVENT_BLOCKLIST_DST   4
-#define REPUTATION_EVENT_ALLOWLIST_DST   5
-#define REPUTATION_EVENT_MONITOR_DST     6
-
 #endif
index a57150e446cfb0ea664dfdf4f9f3117d2cb81a6a..3e6bc6ff8de9bfe65cdda3e15e3878d2ce55c6c1 100644 (file)
@@ -21,7 +21,6 @@
 #define REPUTATION_CONFIG_H
 
 #include "framework/counts.h"
-#include "main/thread.h"
 #include "sfrt/sfrt.h"
 
 #include <vector>
index 9aa0f5f5c98cfa0891410c546da0ab6484095a95..06aa63cc79f9522537ad775823609202aff2cad3 100644 (file)
 
 #include "reputation_inspect.h"
 
-#include "detection/detect.h"
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "log/messages.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
-#include "managers/inspector_manager.h"
-#include "network_inspectors/packet_tracer/packet_tracer.h"
 #include "packet_io/active.h"
+#include "packet_io/packet_tracer.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 #include "pub_sub/auxiliary_ip_event.h"
@@ -348,7 +345,7 @@ static void populate_trace_data(IPdecision& decision, Packet* p, uint32_t iplist
     sfip_ntop(ip, addr, sizeof(addr));
 
     PacketTracer::daq_log("SI-IP+%" PRId64"+%s list id %u+Matched ip %s, action %s$",
-        TO_NSECS(pt_timer->get()),
+        PacketTracer::get_time(),
         (TRUSTED_SRC == decision or TRUSTED_DST == decision)?"Do_not_block":"Block",
         iplist_id, addr, to_string(decision));
 }
@@ -482,7 +479,7 @@ void IpRepHandler::handle(DataEvent& event, Flow*)
         return;
 
     if (PacketTracer::is_daq_activated())
-        PacketTracer::pt_timer_start();
+        PacketTracer::restart_timer();
 
     ReputationData* data = static_cast<ReputationData*>(inspector.get_thread_specific_data());
     assert(data);
index 37ea19d2cb6606e4490dfefc262167ec52744e2e..a1ee0bf27bfe7e71205ee8608a4063ff04f7167b 100644 (file)
 #include "reputation_config.h"
 #include "reputation_common.h"
 
+#define REPUTATION_NAME "reputation"
+#define REPUTATION_HELP "reputation inspection"
+
+#define REPUTATION_EVENT_BLOCKLIST_SRC   1
+#define REPUTATION_EVENT_ALLOWLIST_SRC   2
+#define REPUTATION_EVENT_MONITOR_SRC     3
+#define REPUTATION_EVENT_BLOCKLIST_DST   4
+#define REPUTATION_EVENT_ALLOWLIST_DST   5
+#define REPUTATION_EVENT_MONITOR_DST     6
+
 namespace snort
 {
 struct SnortConfig;
index fb2e957d2c611fd1069a2b82b56fe906c1af23b8..95fa15cbf50a96437fb3d202bd51af3c2c43979e 100644 (file)
@@ -1,14 +1,14 @@
 set (RNA_INCLUDES
+    rna_cpe_os.h
     rna_fingerprint.h
     rna_fingerprint_smb.h
     rna_fingerprint_tcp.h
     rna_fingerprint_ua.h
     rna_fingerprint_udp.h
-    rna_flow.h
     rna_inspector.h
-    rna_logger.h
+    rna_logger_event.h
     rna_name.h
-    rna_cpe_os.h
+    rna_tracker.h
 )
 
 set ( RNA_SOURCES
@@ -26,7 +26,9 @@ set ( RNA_SOURCES
     rna_fingerprint_udp.cc
     rna_inspector.cc
     rna_flow.cc
+    rna_flow.h
     rna_logger.cc
+    rna_logger.h
     rna_logger_common.h
     rna_mac_cache.cc
     rna_mac_cache.h
index 5027203dea13236755ca74b7c3fd2634961c0623..615662d02bcc0059d60820b097573a20e8d24e0f 100644 (file)
@@ -24,8 +24,6 @@
 
 #include "data_purge_cmd.h"
 
-#include "managers/inspector_manager.h"
-
 #include "rna_inspector.h"
 #include "rna_name.h"
 #include "rna_pnd.h"
index b98764ed2b95e27bfdc16088683a8ed274cbdc2d..1c377fc9ce3d73fe5cd7238b7b44537bbf2b8e09 100644 (file)
@@ -27,7 +27,6 @@
 #include <algorithm>
 #include <cstring>
 
-#include "main/thread.h"
 
 using namespace snort;
 using namespace std;
index 00074e568bc9450d0e2ca41f0f467cc15b1316b2..96db02787b487bdaef6e5a117f504338f8bbf777 100644 (file)
@@ -31,7 +31,6 @@
 #include "catch/snort_catch.h"
 #endif
 
-#include "main/thread.h"
 #include "pub_sub/dhcp_events.h"
 
 using namespace snort;
index 5678638701c43e802cce519febe451303c3a5824..88d4b860d2efaf0c49d8791c498936e5476d85ee 100644 (file)
@@ -29,6 +29,7 @@
 #include "sfip/sf_ip.h"
 
 #include "rna_fingerprint_tcp.h"
+#include "rna_tracker.h"
 
 namespace snort
 {
@@ -37,8 +38,6 @@ struct Packet;
 
 class DiscoveryFilter;
 
-using RnaTracker = std::shared_ptr<snort::HostTracker>;
-
 class RNAFlow : public snort::FlowData
 {
 public:
index 209bbafea61aa84e3a0243855b6ae877be96edf0..bdd8ccf620658027315a40d053d4677a698fadbd 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "log/messages.h"
 #include "main/snort.h"
-#include "managers/inspector_manager.h"
 #include "protocols/packet.h"
 #include "pub_sub/appid_event_ids.h"
 #include "pub_sub/dhcp_events.h"
index 3d84872a9bb535dc28dacce43031503b4608c63b..b896402e3961d80ee860ab8a829a179aef134108 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "rna_fingerprint.h"
 #include "rna_logger_common.h"
+#include "rna_logger_event.h"
 #include "rna_module.h"
 
 #ifdef UNIT_TEST
index 6d95dcdcd3c7d476468ac39d007486b637ca7295..0700d94ab80e65c2ff79ab784e085f03fc9458b1 100644 (file)
 #ifndef RNA_LOGGER_H
 #define RNA_LOGGER_H
 
-#include "events/event.h"
 #include "host_tracker/host_cache.h"
 #include "host_tracker/host_tracker.h"
 #include "rna_cpe_os.h"
-#include "rna_flow.h"
+#include "rna_tracker.h"
 
 namespace snort
 {
-class Flow;
 struct Packet;
 class FpFingerprint;
 }
 
-struct RnaLoggerEvent : public Event
-{
-    RnaLoggerEvent (uint16_t t, uint16_t st, const uint8_t* mc, const RnaTracker* rt,
-        const snort::HostMac* hmp, uint16_t pr, void* cv, const snort::HostApplication* hap,
-        const snort::FpFingerprint* fpr, const snort::HostClient* hcp, const char* u,
-        int32_t app, const char* di, bool jb, uint32_t ls, uint32_t nm,
-        const struct in6_addr* rtr, const snort::Packet* p, const char* nb_name,
-        const std::vector<const char*>* cpe) : type(t), subtype(st),
-        mac(mc), ht(rt), hm(hmp), proto(pr), cond_var(cv), ha(hap), fp(fpr), hc(hcp),
-        user(u), appid(app), device_info(di), jail_broken(jb), lease(ls), netmask(nm),
-        router(rtr), pkt(p), netbios_name(nb_name), cpe_os(cpe) { }
-
-    uint32_t event_time = 0;
-    uint16_t type;
-    uint16_t subtype;
-    const struct in6_addr* ip = nullptr;
-    const uint8_t* mac;
-    const RnaTracker* ht;
-    const snort::HostMac* hm;
-    uint16_t proto;
-    void* cond_var;
-    const snort::HostApplication* ha;
-    const snort::FpFingerprint* fp;
-    const snort::HostClient* hc;
-    const char* user;
-    AppId appid;
-    const char* device_info;
-    bool jail_broken;
-    uint32_t lease;
-    uint32_t netmask;
-    const struct in6_addr* router;
-    const snort::Packet* pkt;
-    const char* netbios_name = nullptr;
-    const std::vector<const char*>* cpe_os = nullptr;
-};
-
 class RnaLogger
 {
 public:
diff --git a/src/network_inspectors/rna/rna_logger_event.h b/src/network_inspectors/rna/rna_logger_event.h
new file mode 100644 (file)
index 0000000..11641d7
--- /dev/null
@@ -0,0 +1,72 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2023 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.
+//--------------------------------------------------------------------------
+
+#ifndef RNA_LOGGER_EVENT_H
+#define RNA_LOGGER_EVENT_H
+
+#include "events/event.h"
+#include "host_tracker/host_cache.h"
+#include "host_tracker/host_tracker.h"
+#include "rna_cpe_os.h"
+#include "rna_tracker.h"
+
+namespace snort
+{
+struct Packet;
+class FpFingerprint;
+}
+
+struct RnaLoggerEvent : public Event
+{
+    RnaLoggerEvent (uint16_t t, uint16_t st, const uint8_t* mc, const RnaTracker* rt,
+        const snort::HostMac* hmp, uint16_t pr, void* cv, const snort::HostApplication* hap,
+        const snort::FpFingerprint* fpr, const snort::HostClient* hcp, const char* u,
+        int32_t app, const char* di, bool jb, uint32_t ls, uint32_t nm,
+        const struct in6_addr* rtr, const snort::Packet* p, const char* nb_name,
+        const std::vector<const char*>* cpe) :
+
+        type(t), subtype(st), mac(mc), ht(rt), hm(hmp), proto(pr), cond_var(cv), ha(hap),
+        fp(fpr), hc(hcp), user(u), appid(app), device_info(di), jail_broken(jb), lease(ls),
+        netmask(nm), router(rtr), pkt(p), netbios_name(nb_name), cpe_os(cpe) { }
+
+    uint32_t event_time = 0;
+    uint16_t type;
+    uint16_t subtype;
+    const struct in6_addr* ip = nullptr;
+    const uint8_t* mac;
+    const RnaTracker* ht;
+    const snort::HostMac* hm;
+    uint16_t proto;
+    void* cond_var;
+    const snort::HostApplication* ha;
+    const snort::FpFingerprint* fp;
+    const snort::HostClient* hc;
+    const char* user;
+    AppId appid;
+    const char* device_info;
+    bool jail_broken;
+    uint32_t lease;
+    uint32_t netmask;
+    const struct in6_addr* router;
+    const snort::Packet* pkt;
+    const char* netbios_name = nullptr;
+    const std::vector<const char*>* cpe_os = nullptr;
+};
+
+#endif
index ff2cb97e42923295992c79da933b14c9001c4d1c..0ed4d22f9927fb21f26af3cfbd352e1a8e7df301 100644 (file)
 #include <sys/stat.h>
 
 #include "control/control.h"
+#include "framework/pig_pen.h"
 #include "host_tracker/host_cache.h"
 #include "host_tracker/host_cache_segmented.h"
 #include "log/messages.h"
 #include "lua/lua.h"
 #include "main/snort_config.h"
-#include "managers/inspector_manager.h"
 #include "managers/module_manager.h"
 #include "utils/util.h"
 
@@ -66,7 +66,7 @@ THREAD_LOCAL const Trace* rna_trace = nullptr;
 static int dump_mac_cache(lua_State* L)
 {
     RnaModule* mod = (RnaModule*) ModuleManager::get_module(RNA_NAME);
-    Inspector* rna = InspectorManager::get_inspector(RNA_NAME, true);
+    Inspector* rna = PigPen::get_inspector(RNA_NAME, true);
     if ( rna && mod )
         mod->log_mac_cache( luaL_optstring(L, 1, nullptr) );
     return 0;
@@ -89,7 +89,7 @@ static inline string format_dump_mac(const uint8_t mac[MAC_SIZE])
 
 static int purge_data(lua_State* L)
 {
-    Inspector* rna = InspectorManager::get_inspector(RNA_NAME, true);
+    Inspector* rna = PigPen::get_inspector(RNA_NAME, true);
     if ( rna )
     {
         HostCacheMac* mac_cache = new HostCacheMac(MAC_CACHE_INITIAL_SIZE);
@@ -164,7 +164,7 @@ static bool get_mac_from_args(lua_State* L, uint8_t* mac_addr)
 
 static int delete_mac_host(lua_State* L)
 {
-    Inspector* rna = InspectorManager::get_inspector(RNA_NAME, true);
+    Inspector* rna = PigPen::get_inspector(RNA_NAME, true);
     if ( rna )
     {
         uint8_t mac[MAC_SIZE] = {0};
@@ -200,7 +200,7 @@ static int delete_mac_host(lua_State* L)
 
 static int delete_mac_host_proto(lua_State* L)
 {
-    Inspector* rna = InspectorManager::get_inspector(RNA_NAME, true);
+    Inspector* rna = PigPen::get_inspector(RNA_NAME, true);
     if ( rna )
     {
         uint8_t mac[MAC_SIZE] = {0};
diff --git a/src/network_inspectors/rna/rna_tracker.h b/src/network_inspectors/rna/rna_tracker.h
new file mode 100644 (file)
index 0000000..c71f78b
--- /dev/null
@@ -0,0 +1,29 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2021-2023 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_tracker.h author Silviu Minut <sminut@cisco.com>
+
+#ifndef RNA_TRACKER_H
+#define RNA_TRACKER_H
+
+#include "host_tracker/host_tracker.h"
+
+using RnaTracker = std::shared_ptr<snort::HostTracker>;
+
+#endif
+
index 34043ca35ae3013df08ec1d55bc0f939c85b4696..9e47944d1f0afe58f52a8fb42b9a5f87b411c9e9 100644 (file)
@@ -81,10 +81,8 @@ bool DataPurgeAC::execute(Analyzer&, void**) { return true;}
 
 void set_host_cache_mac(HostCacheMac*) { }
 
-Inspector* InspectorManager::get_inspector(const char*, bool, const SnortConfig*)
-{
-    return nullptr;
-}
+Inspector* PigPen::get_inspector(const char*, bool, const SnortConfig*)
+{ return nullptr; }
 
 void HostTracker::remove_flows() { }
 
index fa17cb110b91c561e2f7832178d4d93fb6cea982..4b5a581f107c7daabbe274040fe8d7bc04e4d07b 100644 (file)
@@ -1,6 +1,9 @@
 
 set ( PACKET_IO_INCLUDES
     active.h
+    active_action.h
+    packet_constraints.h
+    packet_tracer.h
     sfdaq.h
     sfdaq_instance.h
 )
@@ -26,15 +29,17 @@ if (ENABLE_STATIC_DAQ)
 endif ()
 
 add_library (packet_io OBJECT
+    ${PACKET_IO_INCLUDES}
     active.cc
-    active.h
-    active_action.h
+    active_counts.h
+    packet_constraints.cc
+    packet_tracer.cc
+    packet_tracer_module.cc
+    packet_tracer_module.h
     sfdaq.cc
-    sfdaq.h
     sfdaq_config.cc
     sfdaq_config.h
     sfdaq_instance.cc
-    sfdaq_instance.h
     sfdaq_module.cc
     sfdaq_module.h
     trough.cc
index 54266b031d0a4abf43e223d633b4c929cd6bed46..fb1e228892956f2533d6112bd9dcfcc58e7d4108 100644 (file)
@@ -36,6 +36,7 @@
 #include "utils/dnet_header.h"
 
 #include "active_action.h"
+#include "active_counts.h"
 #include "sfdaq.h"
 #include "sfdaq_instance.h"
 #include "sfdaq_module.h"
@@ -67,10 +68,11 @@ const char* Active::act_str[Active::ACT_MAX][Active::AST_MAX] =
     { "reset", "cant_reset", "would_reset", "force_reset" },
 };
 
-THREAD_LOCAL uint8_t Active::s_attempts = 0;
-THREAD_LOCAL bool Active::s_suspend = false;
-THREAD_LOCAL Active::ActiveSuspendReason Active::s_suspend_reason = Active::ASP_NONE;
-THREAD_LOCAL Active::Counts snort::active_counts;
+static THREAD_LOCAL uint8_t s_attempts = 0;
+static THREAD_LOCAL bool s_suspend = false;
+static THREAD_LOCAL Active::ActiveSuspendReason s_suspend_reason = Active::ASP_NONE;
+
+static THREAD_LOCAL Active::Counts active_counts;
 
 typedef int (* send_t) (
     DAQ_Msg_h msg, int rev, const uint8_t* buf, uint32_t len);
@@ -84,6 +86,9 @@ static int default_drop_reason_id = -1;
 
 static std::unordered_map<std::string, uint8_t> drop_reason_id_map;
 
+PegCount* get_active_counts()
+{ return (PegCount*)&active_counts; }
+
 //--------------------------------------------------------------------
 // helpers
 
@@ -546,6 +551,43 @@ void Active::update_status_actionable(const Packet* p)
     }
 }
 
+void Active::suspend(ActiveSuspendReason suspend_reason)
+{
+    s_suspend = true;
+    s_suspend_reason = suspend_reason;
+}
+
+bool Active::is_suspended()
+{ return s_suspend; }
+
+void Active::resume()
+{
+    s_suspend = false;
+    s_suspend_reason = ASP_NONE;
+}
+
+bool Active::can_partial_block_session() const
+{ return active_status == AST_CANT and s_suspend_reason > ASP_NONE and s_suspend_reason != ASP_TIMEOUT; }
+
+bool Active::keep_pruned_flow() const
+{ return ( s_suspend_reason == ASP_PRUNE ) or ( s_suspend_reason == ASP_RELOAD ); }
+
+bool Active::keep_timedout_flow() const
+{ return ( s_suspend_reason == ASP_TIMEOUT ); }
+
+Active::ActiveWouldReason Active::get_whd_reason_from_suspend_reason()
+{
+    switch ( s_suspend_reason )
+    {
+    case ASP_NONE: return WHD_NONE;
+    case ASP_PRUNE: return WHD_PRUNE;
+    case ASP_TIMEOUT: return WHD_TIMEOUT;
+    case ASP_RELOAD: return WHD_RELOAD;
+    case ASP_EXIT: return WHD_EXIT;
+    }
+    return WHD_NONE;
+}
+
 void Active::update_status(const Packet* p, bool force)
 {
     if ( s_suspend )
index ce07196559aa39f2dce36775672a2d73b145d131..df84c4631fd5efd8323d7b62179733a89ba3139b 100644 (file)
@@ -69,33 +69,11 @@ public:
     static bool thread_init(const SnortConfig*);
     static void thread_term();
 
-    static void suspend(ActiveSuspendReason suspend_reason)
-    {
-        s_suspend = true;
-        s_suspend_reason = suspend_reason;
-    }
-
-    static bool is_suspended()
-    { return s_suspend; }
+    static void suspend(ActiveSuspendReason);
+    static bool is_suspended();
+    static void resume();
 
-    static void resume()
-    {
-        s_suspend = false;
-        s_suspend_reason = ASP_NONE;
-    }
-
-    static ActiveWouldReason get_whd_reason_from_suspend_reason()
-    {
-        switch ( s_suspend_reason )
-        {
-        case ASP_NONE: return WHD_NONE;
-        case ASP_PRUNE: return WHD_PRUNE;
-        case ASP_TIMEOUT: return WHD_TIMEOUT;
-        case ASP_RELOAD: return WHD_RELOAD;
-        case ASP_EXIT: return WHD_EXIT;
-        }
-        return WHD_NONE;
-    }
+    static ActiveWouldReason get_whd_reason_from_suspend_reason();
 
     void send_reset(Packet*, EncodeFlags);
     void send_unreach(Packet*, snort::UnreachResponse);
@@ -161,14 +139,9 @@ public:
     ActiveWouldReason get_would_be_dropped_reason() const
     { return active_would_reason; }
 
-    bool can_partial_block_session() const
-    { return active_status == AST_CANT and s_suspend_reason > ASP_NONE and s_suspend_reason != ASP_TIMEOUT; }
-
-    bool keep_pruned_flow() const
-    { return ( s_suspend_reason == ASP_PRUNE ) or ( s_suspend_reason == ASP_RELOAD ); }
-
-    bool keep_timedout_flow() const
-    { return ( s_suspend_reason == ASP_TIMEOUT ); }
+    bool can_partial_block_session() const;
+    bool keep_pruned_flow() const;
+    bool keep_timedout_flow() const;
 
     bool packet_retry_requested() const
     { return active_action == ACT_RETRY; }
@@ -231,9 +204,6 @@ private:
 
 private:
     static const char* act_str[ACT_MAX][AST_MAX];
-    static THREAD_LOCAL uint8_t s_attempts;
-    static THREAD_LOCAL bool s_suspend;
-    static THREAD_LOCAL ActiveSuspendReason s_suspend_reason;
 
     int active_tunnel_bypass = 0;
     const char* drop_reason = nullptr;
@@ -248,7 +218,7 @@ private:
     ActiveAction* delayed_reject = nullptr; // set with set_delayed_action()
 };
 
-struct SO_PUBLIC ActiveSuspendContext
+struct ActiveSuspendContext
 {
     ActiveSuspendContext(Active::ActiveSuspendReason suspend_reason)
     { Active::suspend(suspend_reason); }
@@ -257,7 +227,6 @@ struct SO_PUBLIC ActiveSuspendContext
     { Active::resume(); }
 };
 
-extern THREAD_LOCAL Active::Counts active_counts;
 }
 #endif
 
diff --git a/src/packet_io/active_counts.h b/src/packet_io/active_counts.h
new file mode 100644 (file)
index 0000000..8757350
--- /dev/null
@@ -0,0 +1,32 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2023 Cisco and/or its affiliates. All rights reserved.
+// Copyright (C) 2005-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.
+//--------------------------------------------------------------------------
+
+// active_counts.h author Russ Combs <rcombs@sourcefire.com>
+
+#ifndef ACTIVE_COUNTS_H
+#define ACTIVE_COUNTS_H
+
+// private Active accessors (not installed)
+
+#include "framework/counts.h"
+
+PegCount* get_active_counts();
+
+#endif
+
similarity index 99%
rename from src/framework/packet_constraints.cc
rename to src/packet_io/packet_constraints.cc
index 67ccdad999d92c47e65f77b7a5b1955642039973..7fd2e29c9ab2db39ac08887ed94deca3dca73a60 100644 (file)
 
 #include "packet_constraints.h"
 
-#include "protocols/packet.h"
-
+#include <algorithm>
 #include <cstring>
 
+#include "protocols/packet.h"
+
 namespace {
 
 inline bool match_constraints(const snort::PacketConstraints& cs,
similarity index 91%
rename from src/network_inspectors/packet_tracer/packet_tracer.cc
rename to src/packet_io/packet_tracer.cc
index 22d3c69bf2819db6778e296eadaa593b2400f793..2a19685f4a939e680dfebaf2999345a235dd5c5f 100644 (file)
 #include <sstream>
 
 #include "detection/ips_context.h"
-#include "log/log.h"
 #include "log/messages.h"
-#include "packet_io/active.h"
-#include "packet_io/sfdaq_instance.h"
+#include "main/thread.h"
 #include "protocols/eth.h"
 #include "protocols/icmp4.h"
 #include "protocols/ip.h"
@@ -41,6 +39,9 @@
 #include "protocols/tcp.h"
 #include "utils/util.h"
 
+#include "active.h"
+#include "sfdaq_instance.h"
+
 #ifdef UNIT_TEST
 #include "catch/snort_catch.h"
 #endif
@@ -52,9 +53,14 @@ using namespace snort;
 // -----------------------------------------------------------------------------
 
 // FIXIT-M refactor the way this is used so all methods are members called against this pointer
-THREAD_LOCAL PacketTracer* snort::s_pkt_trace = nullptr;
-
-THREAD_LOCAL Stopwatch<SnortClock>* snort::pt_timer = nullptr;
+#ifdef _WIN64
+static THREAD_LOCAL PacketTracer* s_pkt_trace = nullptr;
+#else
+namespace snort
+{
+THREAD_LOCAL PacketTracer* PacketTracer::s_pkt_trace = nullptr;
+};
+#endif
 
 // so modules can register regardless of when packet trace is activated
 static THREAD_LOCAL struct{ unsigned val = 0; } global_mutes;
@@ -62,44 +68,40 @@ static THREAD_LOCAL struct{ unsigned val = 0; } global_mutes;
 static std::string log_file = "-";
 static bool config_status = false;
 
+// %s %u -> %s %u %u AS=%u ID=%u GR=%hd-%hd
+// IPv6 Port -> IPv6 Port Proto AS=ASNum ID=InstanceNum GR=SrcGroupNum-DstGroupNum
+#define PT_DEBUG_SESSION_ID_SIZE ((39+1+5+1+2+1+39+1+5+1+3+1+2+1+10+1+2+1+10+32)+1)
+static constexpr int max_buff_size = 2048;
+
 // -----------------------------------------------------------------------------
 // static functions
 // -----------------------------------------------------------------------------
 
+#ifdef _WIN64
+bool PacketTracer::is_active()
+{ return s_pkt_trace ? s_pkt_trace->active : false; }
+
+bool PacketTracer::is_daq_activated()
+{ return s_pkt_trace ? s_pkt_trace->daq_activated : false; }
+#endif
+
 void PacketTracer::set_log_file(const std::string& file)
 { log_file = file; }
 
 // template needed for unit tests
 template<typename T> void PacketTracer::_thread_init()
 {
-    if ( s_pkt_trace == nullptr )
-        s_pkt_trace = new T();
-
-    if ( pt_timer == nullptr )
-        pt_timer = new Stopwatch<SnortClock>;
-
-    s_pkt_trace->mutes.resize(global_mutes.val, false);
-    s_pkt_trace->open_file();
-    s_pkt_trace->user_enabled = config_status;
+    assert(!s_pkt_trace);
+    s_pkt_trace = new T();
 }
-template void PacketTracer::_thread_init<PacketTracer>();
 
 void PacketTracer::thread_init()
-{ _thread_init(); }
+{ _thread_init<PacketTracer>(); }
 
 void PacketTracer::thread_term()
 {
-    if ( s_pkt_trace )
-    {
-        delete s_pkt_trace;
-        s_pkt_trace = nullptr;
-    }
-
-    if (pt_timer)
-    {
-        delete pt_timer;
-        pt_timer = nullptr;
-    }
+    delete s_pkt_trace;
+    s_pkt_trace = nullptr;
 }
 
 void PacketTracer::dump(char* output_buff, unsigned int len)
@@ -269,17 +271,37 @@ void PacketTracer::activate(const Packet& p)
         s_pkt_trace->active = false;
 }
 
-void PacketTracer::pt_timer_start()
+uint64_t PacketTracer::get_time()
+{ return TO_NSECS(s_pkt_trace->pt_timer->get()); }
+
+void PacketTracer::start_timer()
+{ s_pkt_trace->pt_timer->start(); }
+
+void PacketTracer::reset_timer()
+{ s_pkt_trace->pt_timer->reset(); }
+
+void PacketTracer::restart_timer()
 {
-    pt_timer->reset();
-    pt_timer->start();
+    s_pkt_trace->pt_timer->reset();
+    s_pkt_trace->pt_timer->start();
 }
 
 // -----------------------------------------------------------------------------
 // non-static functions
 // -----------------------------------------------------------------------------
 
-// destructor
+PacketTracer::PacketTracer()
+{
+    pt_timer = new Stopwatch<SnortClock>;
+    buffer = new char[max_buff_size] { };
+    daq_buffer = new char[max_buff_size] { };
+    debug_session = new char[PT_DEBUG_SESSION_ID_SIZE];
+
+    mutes.resize(global_mutes.val, false);
+    open_file();
+    user_enabled = config_status;
+}
+
 PacketTracer::~PacketTracer()
 {
     if ( log_fh && log_fh != stdout )
@@ -287,6 +309,10 @@ PacketTracer::~PacketTracer()
         fclose(log_fh);
         log_fh = nullptr;
     }
+    delete[] debug_session;
+    delete[] daq_buffer;
+    delete[] buffer;
+    delete pt_timer;
 }
 
 void PacketTracer::populate_buf(const char* format, va_list ap, char* buffer, uint32_t& buff_len)
@@ -398,7 +424,7 @@ void PacketTracer::add_packet_type_info(const Packet& p)
         case PktType::TCP:
         {
             char tcpFlags[10];
-            CreateTCPFlagString(p.ptrs.tcph, tcpFlags);
+            p.ptrs.tcph->stringify_flags(tcpFlags);
 
             if (p.ptrs.tcph->th_flags & TH_ACK)
                 PacketTracer::log("Packet %" PRIu64 ": TCP %s, %s, seq %u, ack %u, dsize %u%s\n",
@@ -643,32 +669,32 @@ TEST_CASE("corner cases", "[PacketTracer]")
         TestPacketTracer::daq_log("%s", test_str);
     }
     // when buffer limit is  reached, buffer length will stopped at max_buff_size-1
-    CHECK((TestPacketTracer::get_buff_len() == (TestPacketTracer::max_buff_size-1)));
-    CHECK((TestPacketTracer::get_daq_buff_len() == (TestPacketTracer::max_buff_size-1)));
+    CHECK((TestPacketTracer::get_buff_len() == (max_buff_size-1)));
+    CHECK((TestPacketTracer::get_daq_buff_len() == (max_buff_size-1)));
 
     // continue logging will not change anything
     TestPacketTracer::log("%s", test_str);
-    CHECK((TestPacketTracer::get_buff_len() == (TestPacketTracer::max_buff_size-1)));
+    CHECK((TestPacketTracer::get_buff_len() == (max_buff_size-1)));
     TestPacketTracer::daq_log("%s", test_str);
-    CHECK((TestPacketTracer::get_daq_buff_len() == (TestPacketTracer::max_buff_size-1)));
+    CHECK((TestPacketTracer::get_daq_buff_len() == (max_buff_size-1)));
 
     TestPacketTracer::thread_term();
 }
 
 TEST_CASE("dump", "[PacketTracer]")
 {
-    char test_string[TestPacketTracer::max_buff_size];
+    char test_string[max_buff_size];
     char test_str[] = "ABCD", results[] = "ABCD3=400";
 
     TestPacketTracer::thread_init();
     TestPacketTracer::set_user_enable(true);
     TestPacketTracer::log("%s%d=%d", test_str, 3, 400);
-    TestPacketTracer::dump(test_string, TestPacketTracer::max_buff_size);
+    TestPacketTracer::dump(test_string, max_buff_size);
     CHECK(!strcmp(test_string, results));
     CHECK((TestPacketTracer::get_buff_len() == 0));
 
     // dump again
-    TestPacketTracer::dump(test_string, TestPacketTracer::max_buff_size);
+    TestPacketTracer::dump(test_string, max_buff_size);
     CHECK(!strcmp(test_string, ""));
     CHECK((TestPacketTracer::get_buff_len() == 0));
 
similarity index 83%
rename from src/network_inspectors/packet_tracer/packet_tracer.h
rename to src/packet_io/packet_tracer.h
index 8776b5f6333ba00b92aa3d9292f9e9e2523d2e53..152fa2b48f2accb244aebdb32e92498b8d94eab0 100644 (file)
@@ -26,9 +26,8 @@
 #include <cstring>
 #include <vector>
 
-#include "framework/packet_constraints.h"
 #include "main/snort_types.h"
-#include "main/thread.h"
+#include "packet_io/packet_constraints.h"
 #include "protocols/ipv6.h"
 #include "protocols/protocol_ids.h"
 #include "sfip/sf_ip.h"
@@ -42,11 +41,10 @@ struct Packet;
 class PacketTracer
 {
 public:
-    PacketTracer() = default;
+    PacketTracer();
     virtual ~PacketTracer();
 
     typedef uint8_t TracerMute;
-    static const int max_buff_size = 2048;
 
     // static functions
     static void set_log_file(const std::string&);
@@ -64,8 +62,17 @@ public:
     static SO_PUBLIC void pause();
     static SO_PUBLIC void unpause();
     static SO_PUBLIC bool is_paused();
+
+#ifdef _WIN64
     static SO_PUBLIC bool is_active();
     static SO_PUBLIC bool is_daq_activated();
+#else
+    static bool is_active()
+    { return s_pkt_trace ? s_pkt_trace->active : false; }
+
+    static bool is_daq_activated()
+    { return s_pkt_trace ? s_pkt_trace->daq_activated : false; }
+#endif
 
     static SO_PUBLIC TracerMute get_mute();
 
@@ -74,20 +81,32 @@ public:
     static SO_PUBLIC void log_msg_only(const char* format, ...) __attribute__((format (printf, 1, 2)));
 
     static SO_PUBLIC void daq_log(const char* format, ...) __attribute__((format (printf, 1, 2)));
-    static SO_PUBLIC void pt_timer_start();
 
-protected:
+    static SO_PUBLIC void start_timer();
+    static SO_PUBLIC void restart_timer();
+    static SO_PUBLIC void reset_timer();
 
+    static SO_PUBLIC uint64_t get_time();
+
+protected:
+#ifndef _WIN64
+    static SO_PUBLIC THREAD_LOCAL PacketTracer* s_pkt_trace;
+#endif
 
     // non-static variable
+    Stopwatch<SnortClock>* pt_timer = nullptr;
     FILE* log_fh = stdout;
+
+    char* buffer;
+    char* daq_buffer;
+    char* debug_session;
+
     std::vector<bool> mutes;
-    char buffer[max_buff_size] = {0};
+
     unsigned buff_len = 0;
-    char daq_buffer[max_buff_size] = {0};
     unsigned daq_buff_len = 0;
-
     unsigned pause_count = 0;
+
     bool user_enabled = false;
     bool daq_activated = false;
     bool shell_enabled = false;
@@ -108,21 +127,12 @@ protected:
     void update_constraints(const PacketConstraints* constraints);
     const char *get_debug_session() { return debugstr.c_str(); }
 
-    virtual void open_file();
+    void open_file();
     virtual void dump_to_daq(Packet*);
-    virtual void reset(bool);
+    void reset(bool);
 };
 
-SO_PUBLIC extern THREAD_LOCAL PacketTracer* s_pkt_trace;
-SO_PUBLIC extern THREAD_LOCAL Stopwatch<SnortClock>* pt_timer;
-
-inline bool PacketTracer::is_active()
-{ return s_pkt_trace ? s_pkt_trace->active : false; }
-
-inline bool PacketTracer::is_daq_activated()
-{ return s_pkt_trace ? s_pkt_trace->daq_activated : false; }
-
-struct SO_PUBLIC PacketTracerSuspend
+struct PacketTracerSuspend
 {
     PacketTracerSuspend()
     { PacketTracer::pause(); }
index 76b4ee591997eeb494b50c4d6aeddc4446f59346..c52a67c48041040d4b9c6d98a55944f0e0175af9 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "log/messages.h"
 #include "main/snort_config.h"
+#include "main/thread.h"
 #include "protocols/packet.h"
 #include "protocols/vlan.h"
 
index f3eb249cdd45013efdb67de82333ab20c5108a8b..ca1008b00ffb7f0ef19f015b5ad1ebe9dd5d7a77 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef SFDAQ_MODULE_H
 #define SFDAQ_MODULE_H
 
+#include <daq_common.h>
+
 #include "framework/module.h"
 
 namespace snort
index c601bb3400d759cc5d36dff334a7299a1ee920d8..3ca380c890184b0eb9930671fe652a56bae09c2d 100644 (file)
@@ -24,6 +24,7 @@
 #include "cmd_line.h"
 
 #include "framework/module.h"
+#include "log/log_errors.h"
 #include "log/messages.h"
 #include "main/help.h"
 #include "main/snort_config.h"
index bfb7f23f33e090a1e3adb716f446d218d55faf7d..f734ecc23ab7b784e386d39c3737da1e5dfb377c 100644 (file)
@@ -27,7 +27,6 @@
 #include <sstream>
 #include <string>
 
-#include "detection/detect.h"
 #include "detection/detection_engine.h"
 #include "log/messages.h"
 #include "main/analyzer.h"
index 9be773a43ccdb9ce03b46ba1bd020538a749bf3c..8a6d7ba73e74ce85233e84a11b572b95d80d9edf 100644 (file)
 
 #include "parse_rule.h"
 
-#include "actions/actions.h"
-#include "detection/detect.h"
+#include "detection/extract.h"
 #include "detection/fp_config.h"
 #include "detection/fp_utils.h"
 #include "detection/rtn_checks.h"
 #include "detection/treenodes.h"
 #include "framework/decode_data.h"
+#include "framework/ips_action.h"
 #include "hash/xhash.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
 #include "main/thread_config.h"
@@ -42,7 +43,6 @@
 #include "sfip/sf_vartable.h"
 #include "target_based/snort_protocols.h"
 #include "utils/util.h"
-#include "ips_options/extract.h"
 
 #include "parser.h"
 #include "parse_conf.h"
@@ -788,15 +788,15 @@ void parse_rule_type(SnortConfig* sc, const char* s, RuleTreeNode& rtn)
 
     assert(s);
 
-    rtn.action = Actions::get_type(s);
+    rtn.action = IpsAction::get_type(s);
 
-    if ( !Actions::is_valid_action(rtn.action) )
+    if ( !IpsAction::is_valid_action(rtn.action) )
     {
         s_ignore = true;
         ParseError("unknown rule action '%s'", s);
         return;
     }
-    if (!strcmp(s,"file_id"))
+    if (!strcmp(s, "file_id"))
         action_file_id = true;
     else
         action_file_id = false;
index 1224077b316bf3241f9060e90db641fd51df89a8..712dd5d2acfabaa9e40fc2bf950b7de343b9feee 100644 (file)
 
 #include <string>
 
-bool parse_byte_code(const char*, bool& negate, std::string&);
-int parse_int(const char*, const char* tag, int low = -65535, int high = 65535);
+#include "main/snort_types.h"
+
+SO_PUBLIC bool parse_byte_code(const char*, bool& negate, std::string&);
+SO_PUBLIC int parse_int(const char*, const char* tag, int low = -65535, int high = 65535);
 
 #endif
 
index fa02a74a552dc35f7cb149b0843437b6b5ee2f0a..42467185bf0d45c28b9b3236dd0faadfb7cf0ea3 100644 (file)
@@ -34,6 +34,7 @@
 #include "detection/rules.h"
 #include "detection/sfrim.h"
 #include "dump_config/config_output.h"
+#include "events/event_queue.h"
 #include "filters/detection_filter.h"
 #include "filters/rate_filter.h"
 #include "filters/sfthreshold.h"
@@ -42,6 +43,7 @@
 #include "hash/xhash.h"
 #include "helpers/directory.h"
 #include "ips_options/ips_flowbits.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
 #include "main/modules.h"
 #include "main/shell.h"
@@ -632,7 +634,7 @@ void ParseRulesFinish(SnortConfig* sc)
  * Returns: the ListHead for the rule type
  *
  ***************************************************************************/
-RuleListNode* CreateRuleType(SnortConfig* sc, const char* name, Actions::Type mode)
+RuleListNode* CreateRuleType(SnortConfig* sc, const char* name, IpsAction::Type mode)
 {
     RuleListNode* node;
 
@@ -710,7 +712,7 @@ void OrderRuleLists(SnortConfig* sc)
     const char* order = sc->rule_order.c_str();
     if ( !*order )
     {
-        default_priorities = Actions::get_default_priorities();
+        default_priorities = IpsAction::get_default_priorities();
         order = default_priorities.c_str();
     }
 
index 267f4869e1d52fae8aefb8f0afa938a776687676..b0c583718d97c4ae200246e50ca36e4f4fcc3c8a 100644 (file)
@@ -29,6 +29,8 @@ namespace snort
 struct SnortConfig;
 }
 
+struct OptTreeNode;
+
 void parser_init();
 void parser_term(snort::SnortConfig*);
 
@@ -60,15 +62,15 @@ const char* parser_get_special_includer();
 
 int ParseBool(const char* arg);
 
-int addRtnToOtn(snort::SnortConfig*, struct OptTreeNode*, RuleTreeNode*);
-int addRtnToOtn(snort::SnortConfig*, struct OptTreeNode*, RuleTreeNode*, PolicyId);
+int addRtnToOtn(snort::SnortConfig*, OptTreeNode*, RuleTreeNode*);
+int addRtnToOtn(snort::SnortConfig*, OptTreeNode*, RuleTreeNode*, PolicyId);
 
 void set_strict_rtn_reduction(bool);
 bool same_headers(RuleTreeNode*, RuleTreeNode*);
 RuleTreeNode* deleteRtnFromOtn(OptTreeNode*, snort::SnortConfig* sc = nullptr);
-RuleTreeNode* deleteRtnFromOtn(struct OptTreeNode*, PolicyId, snort::SnortConfig* sc = nullptr, bool remove = true);
+RuleTreeNode* deleteRtnFromOtn(OptTreeNode*, PolicyId, snort::SnortConfig* sc = nullptr, bool remove = true);
 
-inline RuleTreeNode* getRtnFromOtn(const struct OptTreeNode* otn, PolicyId policyId)
+inline RuleTreeNode* getRtnFromOtn(const OptTreeNode* otn, PolicyId policyId)
 {
     if (otn && otn->proto_nodes && (otn->proto_node_num > (unsigned)policyId))
     {
@@ -77,12 +79,12 @@ inline RuleTreeNode* getRtnFromOtn(const struct OptTreeNode* otn, PolicyId polic
     return nullptr;
 }
 
-inline RuleTreeNode* getRtnFromOtn(const struct OptTreeNode* otn)
+inline RuleTreeNode* getRtnFromOtn(const OptTreeNode* otn)
 {
     return getRtnFromOtn(otn, snort::get_ips_policy()->policy_id);
 }
 
-RuleListNode* CreateRuleType(snort::SnortConfig* sc, const char* name, Actions::Type action_type);
+RuleListNode* CreateRuleType(snort::SnortConfig* sc, const char* name, snort::IpsAction::Type action_type);
 
 void FreeRuleTreeNode(RuleTreeNode*);
 void DestroyRuleTreeNode(RuleTreeNode*);
index fbcbf508607fa11299320f8d0df0f1b8816abcfd..da77f0d9cc728dc053b55570054340fa846206a8 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "detection/detection_engine.h"
 #include "flow/session.h"
+#include "main/snort_config.h"
 #include "packet_io/active.h"
 #include "protocols/packet.h"
 #include "service_inspectors/http2_inspect/http2_flow_data.h"
index 1e1bbb17c4110834c97bbdecd06024f4044e46d8..ce4589f384ba8626bbc8677077f88e44fe17f365 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "detection/detection_engine.h"
 #include "flow/flow.h"
+#include "main/snort_config.h"
 #include "main/thread_config.h"
 #include "packet_io/active.h"
 #include "protocols/packet.h"
@@ -99,7 +100,7 @@ class StreamSplitter* Inspector::get_splitter(bool) { return nullptr; }
 }
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 // MockInspector class
 
index f9fe1dabd36680266bcf4501b4e051057cda5394..03f7117165bd155cca19a51078bdc51026831033 100644 (file)
@@ -28,6 +28,7 @@
 #include "detection/ips_context.h"
 #include "framework/policy_selector.h"
 #include "log/messages.h"
+#include "main/policy.h"
 #include "policy_selectors/int_set_to_string.h"
 #include "profiler/profiler.h"
 
index b29fa4ddd7d7df1f13b8f7047ed6295eb208a210..97039419493d29d996ce7ebe2cce82fcc6c332c4 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "framework/module.h"
 #include "framework/policy_selector.h"
+
 #include "address_space_selection.h"
 
 #define ADDRESS_SPACE_SELECT_NAME "address_space_selector"
index 8c45147c4a3cf9da840715c61b4dd0436f46d4b1..b0390ce99b6668a1e7f60e0baac1c88aa816065b 100644 (file)
@@ -28,6 +28,7 @@
 #include "detection/ips_context.h"
 #include "framework/policy_selector.h"
 #include "log/messages.h"
+#include "main/policy.h"
 #include "policy_selectors/int_set_to_string.h"
 #include "profiler/profiler.h"
 
index ccb406627129847fe4e98998b9c18b9f820e5492..fd21df80bd52bc62adfc08551aa0321b3f894887 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef PORT_OBJECT2_H
 #define PORT_OBJECT2_H
 
-#include "framework/bits.h"
+#include "utils/bits.h"
 #include "utils/sflsq.h"
 
 //-------------------------------------------------------------------------
index 236dfc49f4d03c36af34a1b90ba49e955802695b..205c798b03efdbbf7abe695aedefcaa65453451b 100644 (file)
@@ -22,8 +22,8 @@
 #ifndef PORT_UTILS_H
 #define PORT_UTILS_H
 
-#include "framework/bits.h"
 #include "protocols/packet.h"
+#include "utils/bits.h"
 #include "utils/sflsq.h"
 
 struct PortObject;
index f13d66abc4cc63bfaaf38e29a9487868596b40c1..be260f85c135ed4cf99212428947038a33506608 100644 (file)
@@ -1,6 +1,5 @@
 set ( PROFILER_INCLUDES
     memory_defs.h
-    memory_context.h
     memory_profiler_defs.h
     profiler.h
     profiler_defs.h
@@ -13,9 +12,11 @@ set ( PROFILER_SOURCES
     json_view.cc
     json_view.h
     memory_context.cc
+    memory_context.h
     memory_profiler.cc
     memory_profiler.h
     profiler.cc
+    profiler_impl.h
     profiler_module.cc
     profiler_module.h
     profiler_nodes.cc
index 56e0d0cfd5952ddb0ba7b0420f5397d3c8626bb0..a4fe165277f12b4202f98936aafa93d544009768 100644 (file)
@@ -22,7 +22,7 @@
 #include "config.h"
 #endif
 
-#include "profiler.h"
+#include "profiler_impl.h"
 
 #include <cassert>
 #include <numeric>
@@ -31,6 +31,7 @@
 #include "main/snort_config.h"
 #include "main/thread_config.h"
 #include "time/stopwatch.h"
+#include "utils/stats.h"
 
 #include "memory_context.h"
 #include "memory_profiler.h"
 
 using namespace snort;
 
-THREAD_LOCAL ProfileStats totalPerfStats;
-THREAD_LOCAL ProfileStats otherPerfStats;
+static THREAD_LOCAL ProfileStats totalPerfStats;
+static THREAD_LOCAL ProfileStats otherPerfStats;
 
-THREAD_LOCAL TimeContext* ProfileContext::curr_time = nullptr;
 THREAD_LOCAL Stopwatch<SnortClock>* run_timer = nullptr;
 THREAD_LOCAL uint64_t first_pkt_num = 0;
 THREAD_LOCAL bool consolidated_once = false;
 
 static ProfilerNodeMap s_profiler_nodes;
 
+#ifndef _WIN64
+THREAD_LOCAL TimeContext* ProfileContext::curr_time = nullptr;
+#else
+static THREAD_LOCAL TimeContext* curr_time = nullptr;
+
+TimeContext* ProfileContext::get_curr_time()
+{ return curr_time; }
+
+void ProfileContext::set_curr_time(TimeContext* t)
+{ curr_time = t; }
+#endif
+
+ProfileStats* Profiler::get_total_perf_stats()
+{ return &totalPerfStats; }
+
+ProfileStats* Profiler::get_other_perf_stats()
+{ return &otherPerfStats; }
+
 void Profiler::register_module(Module* m)
 {
     if ( m->get_profile() )
@@ -78,7 +96,7 @@ void Profiler::register_module(const char* n, const char* pn, Module* m)
 
 void Profiler::start()
 {
-    first_pkt_num = (uint64_t)get_packet_number();
+    first_pkt_num = pc.analyzed_pkts;
     run_timer = new Stopwatch<SnortClock>;
     run_timer->start();
     consolidated_once = false;
index 01f406355ef5a668bfc2364ea2a4735205b3e9fb..4cdff94541b8d09b526c5480f0ba61a48d916c7f 100644 (file)
 #ifndef PROFILER_H
 #define PROFILER_H
 
-#include "main/thread.h"
 #include "profiler_defs.h"
 
-namespace snort
-{
-class Module;
-}
-class ControlConn;
-class ProfilerNodeMap;
-class Profiler
-{
-public:
-    static void register_module(snort::Module*);
-    static void register_module(const char*, const char*, snort::Module*);
-
-    static void start();
-    static void stop(uint64_t);
-
-    static void consolidate_stats(snort::ProfilerType = snort::PROFILER_TYPE_BOTH);
-
-    static void reset_stats(snort::ProfilerType = snort::PROFILER_TYPE_BOTH);
-    static void prepare_stats();
-    static void show_stats();
-    static ProfilerNodeMap& get_profiler_nodes();
-    SO_PUBLIC static void show_runtime_memory_stats();
-};
-
-extern THREAD_LOCAL snort::ProfileStats totalPerfStats;
-extern THREAD_LOCAL snort::ProfileStats otherPerfStats;
-
 #endif
index 559e7480dc7410d952b0a824fdd882262f62bfdd..4d90d4431fbfc76b7af64817a16fd25ad6821282 100644 (file)
@@ -22,7 +22,6 @@
 #define PROFILER_DEFS_H
 
 #include "main/snort_types.h"
-#include "main/thread.h"
 #include "memory_defs.h"
 #include "memory_profiler_defs.h"
 #include "rule_profiler_defs.h"
@@ -104,24 +103,37 @@ class SO_PUBLIC ProfileContext
 public:
     ProfileContext(ProfileStats& stats) : time(stats.time), memory(stats.memory)
     {
-        prev_time = curr_time;
+        prev_time = get_curr_time();
         if ( prev_time )
             prev_time->pause();
-        curr_time = &time;
+        set_curr_time(&time);
     }
 
     ~ProfileContext()
     {
         if ( prev_time )
             prev_time->resume();
-        curr_time = prev_time;
+        set_curr_time(prev_time);
     }
 
+private:
+#ifdef _WIN64
+    static TimeContext* get_curr_time();
+    static void set_curr_time(TimeContext*);
+#else
+    static THREAD_LOCAL TimeContext* curr_time;
+
+    static TimeContext* get_curr_time()
+    { return curr_time; }
+
+    static void set_curr_time(TimeContext* t)
+    { curr_time = t; }
+#endif
+
 private:
     TimeContext time;
     MemoryContext memory;
     TimeContext* prev_time;
-    static THREAD_LOCAL TimeContext* curr_time;
 };
 
 using get_profile_stats_fn = ProfileStats* (*)(const char*);
diff --git a/src/profiler/profiler_impl.h b/src/profiler/profiler_impl.h
new file mode 100644 (file)
index 0000000..056765e
--- /dev/null
@@ -0,0 +1,57 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2015-2023 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.
+//--------------------------------------------------------------------------
+
+// profiler_impl.h author Joel Cornett <jocornet@cisco.com>
+
+#ifndef PROFILER_IMPL_H
+#define PROFILER_IMPL_H
+
+#include "profiler_defs.h"
+
+namespace snort
+{
+class Module;
+struct ProfileStats;
+}
+
+class ProfilerNodeMap;
+
+class Profiler
+{
+public:
+    static void register_module(snort::Module*);
+    static void register_module(const char*, const char*, snort::Module*);
+
+    static void start();
+    static void stop(uint64_t);
+
+    static void consolidate_stats(snort::ProfilerType = snort::PROFILER_TYPE_BOTH);
+
+    static void reset_stats(snort::ProfilerType = snort::PROFILER_TYPE_BOTH);
+    static void prepare_stats();
+
+    static void show_stats();
+    static void show_runtime_memory_stats();
+
+    static ProfilerNodeMap& get_profiler_nodes();
+
+    static snort::ProfileStats* get_total_perf_stats();
+    static snort::ProfileStats* get_other_perf_stats();
+};
+
+#endif
index 7434a0d2fb5427f5dc6c6c0f13e2c36a8cd560b7..526f29b5d05ad391de70bfaf4cfa0dd17a0afe1a 100644 (file)
@@ -35,6 +35,7 @@
 #include "managers/module_manager.h"
 #include "utils/stats.h"
 
+#include "profiler_impl.h"
 #include "rule_profiler.h"
 #include "rule_profiler_defs.h"
 #include "time_profiler.h"
@@ -269,7 +270,7 @@ static void time_profiling_start_cmd()
 static void time_profiling_stop_cmd()
 {
     TimeProfilerStats::set_enabled(false);
-    Profiler::stop((uint64_t)get_packet_number());
+    Profiler::stop(pc.analyzed_pkts);
     Profiler::consolidate_stats(snort::PROFILER_TYPE_TIME);
 }
 
@@ -456,7 +457,7 @@ static const Parameter profiler_params[] =
 class ProfilerReloadTuner : public snort::ReloadResourceTuner
 {
 public:
-    explicit ProfilerReloadTuner(bool enable_rule, bool enable_time) 
+    explicit ProfilerReloadTuner(bool enable_rule, bool enable_time)
         : enable_rule(enable_rule), enable_time(enable_time)
     {}
     ~ProfilerReloadTuner() override = default;
@@ -568,12 +569,12 @@ ProfileStats* ProfilerModule::get_profile(
     case 0:
         name = "total";
         parent = nullptr;
-        return &totalPerfStats;
+        return Profiler::get_total_perf_stats();
 
     case 1:
         name = "other";
         parent = nullptr;
-        return &otherPerfStats;
+        return Profiler::get_other_perf_stats();
     }
     return nullptr;
 }
index a4af665309cee3764cb7510e1a64225cb151f583..51ac758d7994aa06b40e190461d8c39d3a2375d9 100644 (file)
@@ -42,7 +42,17 @@ using namespace snort;
 // enabled is not in SnortConfig to avoid that ugly dependency
 // enabled is not in TimeContext because declaring it SO_PUBLIC made TimeContext visible
 // putting enabled in TimeProfilerStats seems to be the best solution
+#ifndef _WIN64
 THREAD_LOCAL bool TimeProfilerStats::enabled = false;
+#else
+static THREAD_LOCAL bool enabled;
+
+void TimeProfilerStats::set_enabled(bool b)
+{ enabled = b; }
+
+bool TimeProfilerStats::is_enabled()
+{ return enabled; }
+#endif
 
 namespace time_stats
 {
index 09c4b91b5b99a481ee3a2cb0bf2e8d3a60243b06..4b50920f5f6ce8ae5ede0358801720797e4eb3c9 100644 (file)
@@ -47,6 +47,8 @@ struct SO_PUBLIC TimeProfilerStats
     hr_duration elapsed;
     uint64_t checks;
     mutable unsigned int ref_count;
+
+#ifndef _WIN64
     static THREAD_LOCAL bool enabled;
 
     static void set_enabled(bool b)
@@ -54,6 +56,10 @@ struct SO_PUBLIC TimeProfilerStats
 
     static bool is_enabled()
     { return enabled; }
+#else
+    static void set_enabled(bool);
+    static bool is_enabled();
+#endif
 
     void update(hr_duration delta)
     { elapsed += delta; ++checks; }
index 442443d94d74b30926db6ad29a74ab0461c4671b..0b747a20de3d0abfaae5a83a5baa3738ca28dce8 100644 (file)
@@ -31,19 +31,14 @@ namespace snort
 {
 struct Packet;
 
-// FIXIT-L can I assume api is always valid?
-// i.e. if not ip4, then ipv6?
-// or if not ip4, also make sure its not ip6
-
 namespace ip
 {
-// keeping this as a class to avoid confusion.
 class SO_PUBLIC IpApi
 {
 public:
     enum Type { IAT_NONE, IAT_4, IAT_6, IAT_DATA };
 
-    // constructor and destructor MUST remain trivial. Adding
+    // constructor and destructor MUST remain trivial. Adding
     // any non-trivial code will cause a compilation failure.
     IpApi() = default;
 
index a0f623b02989df734d9e1f6541e35b917fb96a52..d6c44b75dbfbf73dd39edf031896c71b5246beb6 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef PROTOCOLS_LAYER_H
 #define PROTOCOLS_LAYER_H
 
+// Packet contains a Layer for each decoded encapsulation.
+
 #include "main/snort_types.h"
 #include "protocols/protocol_ids.h"
 
index 5b70d427d3d6e209bd89e5275f248e120bf2b7ec..0180fbd1ee34fb2434305bd49eb4b4f257bb13f9 100644 (file)
@@ -33,7 +33,7 @@ struct MplsHdr
     uint8_t bos;
     uint8_t ttl;
 };
-} // namespace mpls
+}
 }
 #endif
 
index 04161f1c4bdc27932bfada67eb96d858c635e831..e0785230a57835ede4ff773333b146c7b049be19 100644 (file)
 #include "packet.h"
 
 #include "detection/ips_context.h"
-#include "flow/expect_cache.h"
+#include "flow/expect_flow.h"
+#include "flow/flow_key.h"
 #include "framework/endianness.h"
 #include "log/obfuscator.h"
+#include "main/snort_config.h"
 #include "packet_io/active.h"
-#include "managers/codec_manager.h"
 
 #include "packet_manager.h"
 #include "vlan.h"
@@ -38,7 +39,7 @@ namespace snort
 {
 Packet::Packet(bool packet_data)
 {
-    layers = new Layer[CodecManager::get_max_layers()];
+    layers = new Layer[PacketManager::get_max_layers()];
     allocated = packet_data;
 
     if (!packet_data)
index c12708df7b2897f5fcd1be15f83fd5854b828531..475fe5b5293c84a3663ee5aea5753afc7e74a001 100644 (file)
 #ifndef PROTOCOLS_PACKET_H
 #define PROTOCOLS_PACKET_H
 
+// Packet is an abstraction describing a unit of work.  it may define a
+// wire packet or it may define a cooked packet.  the latter contains
+// payload data only, no headers.
+
 #include <daq_common.h>
 
 #include "flow/flow.h"
@@ -42,7 +46,7 @@ class SFDAQInstance;
 #define PKT_REBUILT_FRAG          0x00000001  // is a rebuilt fragment
 #define PKT_REBUILT_STREAM        0x00000002  // is a rebuilt stream
 #define PKT_STREAM_UNEST_UNI      0x00000004  // is from an unestablished stream and
-                                         // we've only seen traffic in one direction
+                                              // we've only seen traffic in one direction
 #define PKT_STREAM_EST            0x00000008  // is from an established stream
 
 #define PKT_STREAM_INSERT         0x00000010  // this packet has been queued for stream reassembly
@@ -108,9 +112,6 @@ constexpr uint16_t NUM_IP_PROTOS = 256;
 constexpr uint8_t TCP_OPTLENMAX = 40; /* (((2^4) - 1) * 4  - TCP_HEADER_LEN) */
 constexpr uint8_t DEFAULT_LAYERMAX = 40;
 
-// Packet is an abstraction describing a unit of work.  it may define a
-// wire packet or it may define a cooked packet.  the latter contains
-// payload data only, no headers.
 struct SO_PUBLIC Packet
 {
     Packet(bool packet_data = true);
@@ -376,13 +377,6 @@ private:
     bool allocated;
 };
 
-/* Macros to deal with sequence numbers - p810 TCP Illustrated vol 2 */
-#define SEQ_LT(a,b)  ((int)((a) - (b)) <  0)
-#define SEQ_LEQ(a,b) ((int)((a) - (b)) <= 0)
-#define SEQ_GT(a,b)  ((int)((a) - (b)) >  0)
-#define SEQ_GEQ(a,b) ((int)((a) - (b)) >= 0)
-#define SEQ_EQ(a,b)  ((int)((a) - (b)) == 0)
-
 #define BIT(i) (0x1 << ((i)-1))
 
 inline void SetExtraData(Packet* p, const uint32_t xid) { p->xtradata_mask |= BIT(xid); }
index 17fc08e6921997502835a6490984bb3e8c50b491..f8ea3a99a9b5829d7de8a1761d37274a80c4f1ad 100644 (file)
 #include "detection/detection_engine.h"
 #include "log/text_log.h"
 #include "main/snort_config.h"
+#include "managers/codec_manager.h"
 #include "packet_io/active.h"
+#include "packet_io/packet_tracer.h"
 #include "packet_io/sfdaq.h"
-#include "packet_tracer/packet_tracer.h"
 #include "profiler/profiler_defs.h"
 #include "stream/stream.h"
 #include "trace/trace_api.h"
+#include "utils/stats.h"
 
 #include "eth.h"
 #include "icmp4.h"
 using namespace snort;
 
 THREAD_LOCAL ProfileStats decodePerfStats;
+uint8_t PacketManager::max_layers = DEFAULT_LAYERMAX;
+
+ProtocolIndex PacketManager::proto_idx(ProtocolId prot_id)
+{ return CodecManager::s_proto_map[to_utype(prot_id)]; }
 
 // Decoding statistics
 
-// this may be my longer member declaration ... ever
-THREAD_LOCAL std::array<PegCount,PacketManager::stat_offset +
-CodecManager::s_protocols.size()> PacketManager::s_stats {
-    { 0 }
-};
+static THREAD_LOCAL std::array<PegCount, PacketManager::stat_offset + num_protocol_idx> s_stats
+{ { 0 } };
 
-//PacketManager::s_stats{{0}};
-std::array<PegCount, PacketManager::s_stats.size()> PacketManager::g_stats;
+static std::array<PegCount, s_stats.size()> g_stats;
 
 // names which will be printed for the first three statistics
 // in s_stats/g_stats
@@ -72,15 +74,14 @@ const std::array<const char*, PacketManager::stat_offset> PacketManager::stat_na
 // Encoder Foo
 static THREAD_LOCAL std::array<uint8_t, Codec::PKT_MAX>* s_pkt;
 
+void PacketManager::global_init(uint8_t max)
+{ max_layers = max; }
+
 void PacketManager::thread_init()
-{
-    s_pkt = new std::array<uint8_t, Codec::PKT_MAX>{ {0} };
-}
+{ s_pkt = new std::array<uint8_t, Codec::PKT_MAX>{ {0} }; }
 
 void PacketManager::thread_term()
-{
-    delete s_pkt;
-}
+{ delete s_pkt; }
 
 //-------------------------------------------------------------------------
 // Private helper functions
@@ -89,7 +90,7 @@ void PacketManager::thread_term()
 inline bool PacketManager::push_layer(Packet* p, CodecData& codec_data, ProtocolId prot_id,
     const uint8_t* hdr_start, uint32_t len)
 {
-    if ( p->num_layers == CodecManager::get_max_layers() )
+    if ( p->num_layers == max_layers )
     {
         if (!(codec_data.codec_flags & CODEC_LAYERS_EXCEEDED))
         {
index d9969c7e5f8f199edd5a03639126e285999343f3..9b14de1575d451ed7327059fb66fb4e874a3a308 100644 (file)
@@ -27,8 +27,8 @@
 #include "framework/codec.h"
 #include "framework/counts.h"
 #include "main/snort_types.h"
-#include "managers/codec_manager.h"
 #include "protocols/packet.h"
+#include "protocols/protocol_ids.h"
 
 struct TextLog;
 
@@ -57,6 +57,8 @@ enum class UnreachResponse
 class SO_PUBLIC PacketManager
 {
 public:
+    static void global_init(uint8_t max_layers);
+
     static void thread_init();
     static void thread_term();
 
@@ -122,17 +124,21 @@ public:
      *
      * The equivalent of Snort's PROTO_ID */
     static constexpr std::size_t max_protocols() // compile time constant
-    { return CodecManager::s_protocols.size(); }
+    { return num_protocol_idx; }
 
     /* If a proto was registered in a Codec's get_protocol_ids() function,
      * this function will return the 'ProtocolIndex' of the Codec to which the proto belongs.
      * If none of the loaded Codecs registered that proto, this function will
      * return zero. */
-    static ProtocolIndex proto_idx(ProtocolId prot_id)
-    { return CodecManager::s_proto_map[to_utype(prot_id)]; }
+    static ProtocolIndex proto_idx(ProtocolId);
 
     static void accumulate();
 
+    static uint8_t get_max_layers()
+    { return max_layers; }
+
+    static constexpr uint8_t stat_offset = 4;
+
 private:
     static bool push_layer(Packet*, CodecData&, ProtocolId, const uint8_t* hdr_start, uint32_t len);
     static Codec* get_layer_codec(const Layer&, int idx);
@@ -144,20 +150,12 @@ private:
 
     // constant offsets into the s_stats array.  Notice the stat_offset
     // constant which is used when adding a protocol specific codec
-    static const uint8_t total_processed = 0;
-    static const uint8_t other_codecs = 1;
-    static const uint8_t discards = 2;
-    static const uint8_t depth_exceeded = 3;
-    static const uint8_t stat_offset = 4;
-
-    // declared in header so it can access s_protocols
-    static THREAD_LOCAL std::array<PegCount, stat_offset +
-    CodecManager::s_protocols.size()> s_stats;
-    // FIXIT-L gcc apparently does not consider thread_local variables to be valid in
-    // constexpr expressions. As long as __thread is used instead of thread_local in gcc,
-    // this is not a problem. However, if we use thread_local and gcc, the declaration
-    // below will not compile.
-    static std::array<PegCount, s_stats.size()> g_stats;
+    static constexpr uint8_t total_processed = 0;
+    static constexpr uint8_t other_codecs = 1;
+    static constexpr uint8_t discards = 2;
+    static constexpr uint8_t depth_exceeded = 3;
+
+    static uint8_t max_layers;
     static const std::array<const char*, stat_offset> stat_names;
 };
 }
index 665b98462a52b2f6dd82abb5c78af1dcb8efee28..8d89d20ed1021cb5d2fc462468e7c611bc8825b0 100644 (file)
@@ -161,6 +161,8 @@ enum class ProtocolId : std::uint16_t
     ETHERTYPE_CISCO_META = 0x8909,
 };
 
+constexpr auto num_protocol_idx = UINT8_MAX;
+
 static const auto num_protocol_ids =
     std::numeric_limits<std::underlying_type<ProtocolId>::type>::max() + 1;
 
index 17eb8b0402a85eb5eded6250e706e27ae9a795fe..0089d0323c60bcae877a5aa7f484955b60f560a0 100644 (file)
@@ -201,14 +201,14 @@ struct SSLv2_shello_t
     uint8_t minor;
 };
 
-struct SSLV3ClientHelloData
+struct SO_PUBLIC SSLV3ClientHelloData
 {
     ~SSLV3ClientHelloData();
     void clear();
     char* host_name = nullptr;
 };
 
-struct SSLV3ServerCertData
+struct SO_PUBLIC SSLV3ServerCertData
 {
     ~SSLV3ServerCertData();
     void clear();
@@ -306,7 +306,7 @@ struct ServiceSSLV3ExtensionServerName
 
 namespace snort
 {
-uint32_t SSL_decode(
+SO_PUBLIC uint32_t SSL_decode(
     const uint8_t* pkt, int size, uint32_t pktflags, uint32_t prevflags,
     uint8_t* alert_flags, uint16_t* partial_rec_len, int hblen, uint32_t* info_flags = nullptr,
     SSLV3ClientHelloData* data = nullptr, SSLV3ServerCertData* server_cert_data = nullptr);
index 74468154dcf2482b01ced0786949fccea21c3b27..3f79f254309fa75e0b8b4c74d8b8fc87b5ddda86 100644 (file)
@@ -65,6 +65,13 @@ namespace tcp
 
 #define GET_PKT_SEQ(p) (ntohl((p)->ptrs.tcph->th_seq))
 
+/* Macros to deal with sequence numbers - p810 TCP Illustrated vol 2 */
+#define SEQ_LT(a,b)  ((int)((a) - (b)) <  0)
+#define SEQ_LEQ(a,b) ((int)((a) - (b)) <= 0)
+#define SEQ_GT(a,b)  ((int)((a) - (b)) >  0)
+#define SEQ_GEQ(a,b) ((int)((a) - (b)) >= 0)
+#define SEQ_EQ(a,b)  ((int)((a) - (b)) == 0)
+
 constexpr uint8_t TCP_MIN_HEADER_LEN = 20; // this is actually the minimal TCP header length
 constexpr int OPT_TRUNC = -1;
 constexpr int OPT_BADLEN = -2;
@@ -176,6 +183,19 @@ struct TCPHdr
 
     inline void set_seq(uint32_t new_seq)
     { th_seq = htonl(new_seq); }
+
+    void stringify_flags(char* buf) const
+    {
+        *buf++ = (char)((th_flags & TH_RES1) ? '1' : '*');
+        *buf++ = (char)((th_flags & TH_RES2) ? '2' : '*');
+        *buf++ = (char)((th_flags & TH_URG)  ? 'U' : '*');
+        *buf++ = (char)((th_flags & TH_ACK)  ? 'A' : '*');
+        *buf++ = (char)((th_flags & TH_PUSH) ? 'P' : '*');
+        *buf++ = (char)((th_flags & TH_RST)  ? 'R' : '*');
+        *buf++ = (char)((th_flags & TH_SYN)  ? 'S' : '*');
+        *buf++ = (char)((th_flags & TH_FIN)  ? 'F' : '*');
+        *buf = '\0';
+    }
 };
 }  // namespace tcp
 }  // namespace snort
index 29620e2d7c6b40acdebc89a88612402652be5a03..e15031b6b1e458ef47ce8cb69e5a49c77fec6032 100644 (file)
 #include "detection/detection_engine.h"
 #include "detection/ips_context.h"
 #include "flow/expect_cache.h"
+#include "flow/expect_flow.h"
 #include "log/text_log.h"
 #include "main/snort_config.h"
 #include "managers/codec_manager.h"
+#include "packet_io/packet_tracer.h"
 #include "packet_io/sfdaq.h"
-#include "packet_tracer/packet_tracer.h"
 #include "profiler/profiler_defs.h"
 #include "stream/stream.h"
 #include "trace/trace_api.h"
@@ -109,7 +110,6 @@ public:
 
 MockCodec mock_cd;
 std::array<Codec*, UINT8_MAX> CodecManager::s_protocols { { &mock_cd } };
-THREAD_LOCAL uint8_t CodecManager::max_layers = 1;
 
 //-----------------------------
 // Test
index b9ff274d3c38d3b1429de8b8030c8f6b453883f3..a28aab8715db1a01cdcec7714a33277fc6294e9e 100644 (file)
@@ -21,7 +21,7 @@
 #include "config.h"
 #endif
 
-#include "flow/expect_cache.h"
+#include "flow/expect_flow.h"
 #include "framework/api_options.h"
 #include "protocols/packet.h"
 #include "protocols/packet_manager.h"
@@ -37,8 +37,8 @@ const char* PacketManager::get_proto_name(ProtocolId) { return nullptr; }
 const vlan::VlanTagHdr* layer::get_vlan_layer(const Packet*) { return nullptr; }
 const geneve::GeneveLyr* layer::get_geneve_layer(const Packet*, bool) { return nullptr; }
 void ip::IpApi::reset() {}
-THREAD_LOCAL uint8_t CodecManager::max_layers = 0;
 
+uint8_t PacketManager::max_layers = DEFAULT_LAYERMAX;
 
 TEST_GROUP(get_geneve_opt_tests)
 {
index d730b7a0866d5f25f88b9e05160395c72800f622..318e2c7eabd98bfff0a547bfbfdb5bd34251b4c2 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "dns_events.h"
 
+#include <algorithm>
+
 #include "service_inspectors/dns/dns.h"
 
 using namespace snort;
@@ -43,7 +45,7 @@ void IPFqdnCacheItem::add_fqdn(const FqdnTtl& fqdn_ttl)
             return;
 
     fqdns.emplace_back(fqdn_ttl);
-} 
+}
 
 void DnsResponseDataEvents::add_ip(const DnsResponseIp& ip)
 {
index f1bfa3329669dba9087439c3227dbcae3671bf17..99715b885f14ce0bf21d907d521ade5194a5d4ae 100644 (file)
 #include "config.h"
 #endif
 
+#include "framework/module.h"
 #include "framework/mpse.h"
+#include "main/snort_types.h"
+#include "profiler/profiler.h"
 
 #include "bnfa_search.h"
 
 using namespace snort;
 
+#define MOD_NAME "ac_bnfa"
+#define MOD_HELP "Aho-Corasick Binary NFA (low memory, low performance) MPSE"
+
+struct BnfaCounts
+{
+    PegCount searches;
+    PegCount matches;
+    PegCount bytes;
+};
+
+static THREAD_LOCAL BnfaCounts bnfa_counts;
+static THREAD_LOCAL ProfileStats bnfa_stats;
+
+const PegInfo bnfa_pegs[] =
+{
+    { CountType::SUM, "searches", "number of search attempts" },
+    { CountType::SUM, "matches", "number of times a match was found" },
+    { CountType::SUM, "bytes", "total bytes searched" },
+
+    { CountType::END, nullptr, nullptr }
+};
+
 //-------------------------------------------------------------------------
-// "ac_bnfa"
+// module
+//-------------------------------------------------------------------------
+
+class AcBnfaModule : public Module
+{
+public:
+    AcBnfaModule() : Module(MOD_NAME, MOD_HELP) { }
+
+    ProfileStats* get_profile() const override
+    { return &bnfa_stats; }
+
+    const PegInfo* get_pegs() const override
+    { return bnfa_pegs; }
+
+    PegCount* get_counts() const override
+    { return (PegCount*)&bnfa_counts; }
+
+    Usage get_usage() const override
+    { return GLOBAL; }
+};
+
+//-------------------------------------------------------------------------
+// mpse
 //-------------------------------------------------------------------------
 
 class AcBnfaMpse : public Mpse
@@ -58,27 +105,14 @@ public:
             bnfaFree(obj);
     }
 
-    int add_pattern(
-        const uint8_t* P, unsigned m, const PatternDescriptor& desc, void* user) override
-    {
-        return bnfaAddPattern(obj, P, m, desc.no_case, desc.negated, user);
-    }
+    int add_pattern(const uint8_t* P, unsigned m, const PatternDescriptor& desc, void* user) override
+    { return bnfaAddPattern(obj, P, m, desc.no_case, desc.negated, user); }
 
     int prep_patterns(SnortConfig* sc) override
-    {
-        return bnfaCompile(sc, obj);
-    }
-
-    int _search(
-        const uint8_t* T, int n, MpseMatch match,
-        void* context, int* current_state) override
-    {
-        /* return is actually the state */
-        return _bnfa_search_csparse_nfa(
-            obj, T, n, match, context, 0 /* start-state */, current_state);
-    }
+    { return bnfaCompile(sc, obj); }
 
-    //  FIXIT-L Implement search_all method for AC_BNFA.
+    int get_pattern_count() const override
+    { return bnfaPatternCount(obj); }
 
     int print_info() override
     {
@@ -86,16 +120,38 @@ public:
         return 0;
     }
 
-    int get_pattern_count() const override
-    {
-        return bnfaPatternCount(obj);
-    }
+    int search(const uint8_t*, int, MpseMatch, void*, int*) override;
+    //  FIXIT-L Implement search_all method for AC_BNFA.
 };
 
+int AcBnfaMpse::search( const uint8_t* T, int n, MpseMatch match, void* context, int* current_state)
+{
+    Profile profile(bnfa_stats);  // cppcheck-suppress unreadVariable
+
+    bnfa_counts.searches++;
+    bnfa_counts.bytes += n;
+
+    int found = _bnfa_search_csparse_nfa(
+        obj, T, n, match, context, 0 /* start-state */, current_state);
+
+    bnfa_counts.matches += found;
+    return found;
+}
+
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
 
+static Module* mod_ctor()
+{
+    return new AcBnfaModule;
+}
+
+static void mod_dtor(Module* p)
+{
+    delete p;
+}
+
 static Mpse* bnfa_ctor(
     const SnortConfig*, class Module*, const MpseAgent* agent)
 {
@@ -127,10 +183,10 @@ static const MpseApi bnfa_api =
         0,
         API_RESERVED,
         API_OPTIONS,
-        "ac_bnfa",
-        "Aho-Corasick Binary NFA (low memory, high performance) MPSE",
-        nullptr,
-        nullptr
+        MOD_NAME,
+        MOD_HELP,
+        mod_ctor,
+        mod_dtor
     },
     MPSE_BASE,
     nullptr,
index 7a44c83334e34a62ab6a5d8c7ecfd2956de68828..d8d5b699577e9ddb090f2baa43a65ce8c71157cb 100644 (file)
 #include "config.h"
 #endif
 
+#include "framework/module.h"
 #include "framework/mpse.h"
+#include "main/snort_types.h"
+#include "profiler/profiler.h"
 
 #include "acsmx2.h"
 
 using namespace snort;
 
+#define MOD_NAME "ac_full"
+#define MOD_HELP "Aho-Corasick Full (high memory, best performance), implements search_all()"
+
+struct FullCounts
+{
+    PegCount searches;
+    PegCount matches;
+    PegCount bytes;
+};
+
+static THREAD_LOCAL FullCounts full_counts;
+static THREAD_LOCAL ProfileStats full_stats;
+
+const PegInfo full_pegs[] =
+{
+    { CountType::SUM, "searches", "number of search attempts" },
+    { CountType::SUM, "matches", "number of times a match was found" },
+    { CountType::SUM, "bytes", "total bytes searched" },
+
+    { CountType::END, nullptr, nullptr }
+};
+
+//-------------------------------------------------------------------------
+// module
+//-------------------------------------------------------------------------
+
+class AcFullModule : public Module
+{
+public:
+    AcFullModule() : Module(MOD_NAME, MOD_HELP) { }
+
+    ProfileStats* get_profile() const override
+    { return &full_stats; }
+
+    const PegInfo* get_pegs() const override
+    { return full_pegs; }
+
+    PegCount* get_counts() const override
+    { return (PegCount*)&full_counts; }
+
+    Usage get_usage() const override
+    { return GLOBAL; }
+};
+
 //-------------------------------------------------------------------------
-// "ac_full"
+// mpse
 //-------------------------------------------------------------------------
 
 class AcfMpse : public Mpse
@@ -43,40 +90,60 @@ public:
     ~AcfMpse() override
     { acsmFree2(obj); }
 
-    int add_pattern(
-        const uint8_t* P, unsigned m, const PatternDescriptor& desc, void* user) override
-    {
-        return acsmAddPattern2(obj, P, m, desc.no_case, desc.negated, user);
-    }
+    int add_pattern(const uint8_t* P, unsigned m, const PatternDescriptor& desc, void* user) override
+    { return acsmAddPattern2(obj, P, m, desc.no_case, desc.negated, user); }
 
     int prep_patterns(SnortConfig* sc) override
     { return acsmCompile2(sc, obj); }
 
-    int _search(
-        const uint8_t* T, int n, MpseMatch match,
-        void* context, int* current_state) override
-    {
-        return acsm_search_dfa_full(obj, T, n, match, context, current_state);
-    }
-
-    int search_all(
-        const uint8_t* T, int n, MpseMatch match,
-        void* context, int* current_state) override
-    {
-        return acsm_search_dfa_full_all(obj, T, n, match, context, current_state);
-    }
-
     int print_info() override
     { return acsmPrintDetailInfo2(obj); }
 
     int get_pattern_count() const override
     { return acsmPatternCount2(obj); }
+
+    int search(const uint8_t*, int, MpseMatch, void*, int*) override;
+    int search_all(const uint8_t*, int n, MpseMatch, void*, int*) override;
 };
 
+int AcfMpse::search(const uint8_t* T, int n, MpseMatch match, void* context, int* current_state)
+{
+    Profile profile(full_stats);  // cppcheck-suppress unreadVariable
+
+    full_counts.searches++;
+    full_counts.bytes += n;
+
+    int found = acsm_search_dfa_full(obj, T, n, match, context, current_state);
+
+    full_counts.matches += found;
+    return found;
+}
+
+int AcfMpse::search_all(const uint8_t* T, int n, MpseMatch match, void* context, int* current_state)
+{
+    full_counts.searches++;
+    full_counts.bytes += n;
+
+    int found = acsm_search_dfa_full_all(obj, T, n, match, context, current_state);
+
+    full_counts.matches += found;
+    return found;
+}
+
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
 
+static Module* mod_ctor()
+{
+    return new AcFullModule;
+}
+
+static void mod_dtor(Module* p)
+{
+    delete p;
+}
+
 static Mpse* acf_ctor(
     const SnortConfig*, class Module*, const MpseAgent* agent)
 {
@@ -108,10 +175,10 @@ static const MpseApi acf_api =
         0,
         API_RESERVED,
         API_OPTIONS,
-        "ac_full",
-        "Aho-Corasick Full (high memory, best performance), implements search_all()",
-        nullptr,
-        nullptr
+        MOD_NAME,
+        MOD_HELP,
+        mod_ctor,
+        mod_dtor
     },
     MPSE_BASE,
     nullptr,
index bf3a21a3be97c4e04c2bcffe22db0ee41df7e8a9..6340b6229e68219069b4be11eac702ab11c49b54 100644 (file)
 #include <list>
 #include <mutex>
 
+#include "log/log_stats.h"
 #include "log/messages.h"
-#include "utils/stats.h"
 #include "utils/util.h"
 
 using namespace snort;
index 19de47ad787a028492179531b313f05b3ef58892..8047ca9eaf0dfac594923e297160e1609d3b8707 100644 (file)
 
 #include <list>
 
+#include "log/log_stats.h"
 #include "log/messages.h"
-#include "utils/stats.h"
 #include "utils/util.h"
 
 using namespace snort;
index 49cb26c6e066005a51de9681ba1852eb2fd3195d..da57d2225d769effa2b8a7e28734d6c322d26536 100644 (file)
 #include "framework/mpse.h"
 #include "hash/hashes.h"
 #include "helpers/scratch_allocator.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
 #include "main/thread.h"
-#include "utils/stats.h"
+#include "profiler/profiler.h"
 
 using namespace snort;
 
 static const char* s_name = "hyperscan";
-static const char* s_help = "intel hyperscan-based mpse with regex support";
+static const char* s_help = "intel hyperscan-based MPSE with regex support";
 
+//-------------------------------------------------------------------------
+// pattern foo
+//-------------------------------------------------------------------------
+
+namespace
+{
 struct Pattern
 {
     std::string pat;
@@ -61,6 +68,7 @@ struct Pattern
     Pattern(const uint8_t*, unsigned, const Mpse::PatternDescriptor&, void*);
     void escape(const uint8_t*, unsigned, bool);
 };
+}
 
 Pattern::Pattern(
     const uint8_t* s, unsigned n, const Mpse::PatternDescriptor& d, void* u)
@@ -113,21 +121,98 @@ static bool compare(const Pattern& a, const Pattern& b)
 
 typedef std::vector<Pattern> PatternVector;
 
+//-------------------------------------------------------------------------
+// scratch
+//-------------------------------------------------------------------------
+
 static std::mutex s_mutex;
 static hs_scratch_t* s_scratch = nullptr;
 static unsigned int scratch_index;
 static ScratchAllocator* scratcher = nullptr;
 
-struct ScanContext
+static bool scratch_setup(SnortConfig* sc)
 {
-    class HyperscanMpse* mpse;
-    MpseMatch match_cb;
-    void* match_ctx;
-    int nfound = 0;
+    for ( unsigned i = 0; i < sc->num_slots; ++i )
+    {
+        hs_scratch_t** ss = (hs_scratch_t**) &sc->state[i][scratch_index];
+        hs_clone_scratch(s_scratch, ss);
+    }
 
-    ScanContext(HyperscanMpse* m, MpseMatch cb, void* ctx)
-    { mpse = m; match_cb = cb; match_ctx = ctx; }
+    return true;
+}
+
+static void scratch_cleanup(SnortConfig* sc)
+{
+    for ( unsigned i = 0; i < sc->num_slots; ++i )
+    {
+        hs_scratch_t* ss = (hs_scratch_t*)sc->state[i][scratch_index];
+        hs_free_scratch(ss);
+        sc->state[i][scratch_index] = nullptr;
+    }
+}
+
+static void scratch_update(SnortConfig* sc)
+{
+    hs_scratch_t** ss = (hs_scratch_t**) &sc->state[get_instance_id()][scratch_index];
+
+    if ( *ss == s_scratch )
+        return;
+
+    hs_free_scratch(*ss);
+    *ss = nullptr;
+
+    hs_clone_scratch(s_scratch, ss);
+}
+
+//-------------------------------------------------------------------------
+// module
+//-------------------------------------------------------------------------
+
+struct FullCounts
+{
+    PegCount searches;
+    PegCount matches;
+    PegCount bytes;
+};
+
+static THREAD_LOCAL FullCounts hyper_counts;
+static THREAD_LOCAL ProfileStats hyper_stats;
+
+const PegInfo hyper_pegs[] =
+{
+    { CountType::SUM, "searches", "number of search attempts" },
+    { CountType::SUM, "matches", "number of times a match was found" },
+    { CountType::SUM, "bytes", "total bytes searched" },
+
+    { CountType::END, nullptr, nullptr }
+};
+
+class HyperscanModule : public Module
+{
+public:
+    HyperscanModule() : Module(s_name, s_help)
+    {
+        scratcher = new SimpleScratchAllocator(scratch_setup, scratch_cleanup, scratch_update);
+        scratch_index = scratcher->get_id();
+    }
+
+    ~HyperscanModule() override
+    {
+        delete scratcher;
+        hs_free_scratch(s_scratch);
+        s_scratch = nullptr;
+    }
+    ProfileStats* get_profile() const override
+    { return &hyper_stats; }
+
+    const PegInfo* get_pegs() const override
+    { return hyper_pegs; }
 
+    PegCount* get_counts() const override
+    { return (PegCount*)&hyper_counts; }
+
+    Usage get_usage() const override
+    { return GLOBAL; }
 };
 
 //-------------------------------------------------------------------------
@@ -165,7 +250,7 @@ public:
     int prep_patterns(SnortConfig*) override;
     void reuse_search() override;
 
-    int _search(const uint8_t*, int, MpseMatch, void*, int*) override;
+    int search(const uint8_t*, int, MpseMatch, void*, int*) override;
 
     int get_pattern_count() const override
     { return pvector.size(); }
@@ -351,9 +436,25 @@ int HyperscanMpse::match(unsigned id, unsigned long long to, MpseMatch match_cb,
 {
     assert(id < pvector.size());
     Pattern& p = pvector[id];
+    hyper_counts.matches++;
     return match_cb(p.user, p.user_tree, (int)to, match_ctx, p.user_list);
 }
 
+namespace
+{
+struct ScanContext
+{
+    HyperscanMpse* mpse;
+    MpseMatch match_cb;
+    void* match_ctx;
+    int nfound = 0;
+
+    ScanContext(HyperscanMpse* m, MpseMatch cb, void* ctx)
+    { mpse = m; match_cb = cb; match_ctx = ctx; }
+
+};
+}
+
 int HyperscanMpse::match(
     unsigned id, unsigned long long /*from*/, unsigned long long to,
     unsigned /*flags*/, void* pv)
@@ -363,9 +464,11 @@ int HyperscanMpse::match(
     return  scan->mpse->match(id, to, scan->match_cb, scan->match_ctx);
 }
 
-int HyperscanMpse::_search(
+int HyperscanMpse::search(
     const uint8_t* buf, int n, MpseMatch mf, void* pv, int* current_state)
 {
+    Profile profile(hyper_stats);  // cppcheck-suppress unreadVariable
+
     *current_state = 0;
     ScanContext scan(this, mf, pv);
 
@@ -375,62 +478,14 @@ int HyperscanMpse::_search(
     // scratch is null for the degenerate case w/o patterns
     assert(!hs_db or ss);
 
+    hyper_counts.searches++;
+    hyper_counts.bytes += n;
+
     hs_scan(hs_db, (const char*)buf, n, 0, ss, HyperscanMpse::match, &scan);
 
     return scan.nfound;
 }
 
-static bool scratch_setup(SnortConfig* sc)
-{
-    for ( unsigned i = 0; i < sc->num_slots; ++i )
-    {
-        hs_scratch_t** ss = (hs_scratch_t**) &sc->state[i][scratch_index];
-        hs_clone_scratch(s_scratch, ss);
-    }
-
-    return true;
-}
-
-static void scratch_cleanup(SnortConfig* sc)
-{
-    for ( unsigned i = 0; i < sc->num_slots; ++i )
-    {
-        hs_scratch_t* ss = (hs_scratch_t*)sc->state[i][scratch_index];
-        hs_free_scratch(ss);
-        sc->state[i][scratch_index] = nullptr;
-    }
-}
-
-static void scratch_update(SnortConfig* sc)
-{
-    hs_scratch_t** ss = (hs_scratch_t**) &sc->state[get_instance_id()][scratch_index];
-
-    if ( *ss == s_scratch )
-        return;
-
-    hs_free_scratch(*ss);
-    *ss = nullptr;
-
-    hs_clone_scratch(s_scratch, ss);
-}
-
-class HyperscanModule : public Module
-{
-public:
-    HyperscanModule() : Module(s_name, s_help)
-    {
-        scratcher = new SimpleScratchAllocator(scratch_setup, scratch_cleanup, scratch_update);
-        scratch_index = scratcher->get_id();
-    }
-
-    ~HyperscanModule() override
-    {
-        delete scratcher;
-        hs_free_scratch(s_scratch);
-        s_scratch = nullptr;
-    }
-};
-
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
index fbba49b44313d50c0bf77533c3b5fda05ec62fc9..21a2bf7ca31813231f1e8cc865cc966a1bb2d8cb 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "framework/counts.h"
 #include "main/snort_types.h"
-#include "main/thread.h"
 
 // pattern matcher queue statistics
 
@@ -35,12 +34,11 @@ struct PatMatQStat
     PegCount tot_inq_uinserts;
     PegCount non_qualified_events;
     PegCount qualified_events;
-    PegCount matched_bytes;
 };
 
 namespace snort
 {
-SO_PUBLIC extern THREAD_LOCAL PatMatQStat pmqs;
+extern THREAD_LOCAL PatMatQStat pmqs;
 }
 #endif
 
index 4433dabd62e396c00fb3cc1761f1bcf0f5284a35..f8206db9448f5df87fb9185f8884b77641c0b193 100644 (file)
@@ -39,7 +39,7 @@ SearchTool::SearchTool(bool multi, const char* override_method)
     assert(!override_method || strcmp(override_method, "hyperscan"));
     const char* method = override_method ? override_method : sc->fast_pattern_config->get_search_method();
 
-    if ( strcmp(method, "hyperscan") )
+    if ( !method or strcmp(method, "hyperscan") )
         method = "ac_full";
 
     mpsegrp = new MpseGroup;
index a01686db79cae7976be8fc84c0a2afca3354c073..ee1f566e61c2c1e9f3bd1163c9be578b48f169c7 100644 (file)
@@ -6,6 +6,7 @@ add_cpputest( ac_bnfa_test
         ../ac_bnfa.cc
         ../bnfa_search.cc
         ../search_tool.cc
+        ../../framework/module.cc
         ../../framework/mpse.cc
 )
 
@@ -16,6 +17,7 @@ add_cpputest( search_tool_test
         ../ac_full.cc
         ../acsmx2.cc
         ../search_tool.cc
+        ../../framework/module.cc
         ../../framework/mpse.cc
 )
 
index a9afc3e6d4c21855f0b0fb59d83fcac7e208ebc5..c88a445c8d967c63befd0f1e3fe6c6dba20cfaa7 100644 (file)
 
 using namespace snort;
 
-namespace snort
-{
-    unsigned get_instance_id() { return 0; }
-    unsigned ThreadConfig::get_instance_max() { return 1; }
-}
-
 //-------------------------------------------------------------------------
 // stubs, spies, etc.
 //-------------------------------------------------------------------------
index a3f8c16c2ddc7cc1877c623bd6133fa23f4d2fcc..107ff7330fce48d780a3728cf72016ec894d8805 100644 (file)
 
 using namespace snort;
 
-namespace snort
-{
-    unsigned get_instance_id() { return 0; }
-    unsigned ThreadConfig::get_instance_max() { return 1; }
-}
-
 //-------------------------------------------------------------------------
 // stubs, spies, etc.
 //-------------------------------------------------------------------------
index 74bc48349afcaea8945369fb2b1bd0e198c98452..39e45f0ef2f34adb1fbb3f1bc2ae095b2fbf932c 100644 (file)
@@ -32,9 +32,9 @@
 #include "framework/mpse_batch.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
+#include "main/thread_config.h"
 #include "managers/mpse_manager.h"
-#include "search_engines/pat_stats.h"
-#include "utils/stats.h"
+#include "profiler/time_profiler_defs.h"
 
 //-------------------------------------------------------------------------
 // base stuff
@@ -76,7 +76,10 @@ void SnortConfig::release_scratch(int)
 DataBus::DataBus() = default;
 DataBus::~DataBus() = default;
 
-THREAD_LOCAL PatMatQStat pmqs;
+THREAD_LOCAL bool snort::TimeProfilerStats::enabled;
+
+unsigned get_instance_id() { return 0; }
+unsigned ThreadConfig::get_instance_max() { return 1; }
 
 unsigned parse_errors = 0;
 void ParseError(const char*, ...)
@@ -105,7 +108,7 @@ const char* FastPatternConfig::get_search_method() const
 using namespace snort;
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 Mpse* mpse = nullptr;
 
index 710c9d1bcb508257d0a8d845b97a99eca4d39e30..7d4b960e6d87ce1a0e5466bce02c1f5a6ca62f35 100644 (file)
@@ -29,9 +29,6 @@
 #include "framework/mpse_batch.h"
 #include "main/snort_config.h"
 #include "managers/mpse_manager.h"
-#include "utils/stats.h"
-
-#include "search_engines/pat_stats.h"
 
 extern std::vector<void *> s_state;
 extern snort::ScratchAllocator* scratcher;
@@ -41,7 +38,6 @@ namespace snort
 extern SnortConfig s_conf;
 
 extern THREAD_LOCAL SnortConfig* snort_conf;
-extern THREAD_LOCAL PatMatQStat pmqs;
 
 extern unsigned parse_errors;
 } // namespace snort
index bfac57111aaaa695c90d0a45fc88626e5b108ea7..fa902c17059e0ecb2c8f7449d005f31aacad5a8d 100644 (file)
@@ -40,6 +40,7 @@ if (STATIC_INSPECTORS)
         $<TARGET_OBJECTS:s7commplus>
         $<TARGET_OBJECTS:smtp>
         $<TARGET_OBJECTS:ssh>
+        $<TARGET_OBJECTS:ssl>
         $<TARGET_OBJECTS:wizard>
     )
 endif()
@@ -48,7 +49,6 @@ set(STATIC_SERVICE_INSPECTOR_PLUGINS
     $<TARGET_OBJECTS:http_inspect>
     $<TARGET_OBJECTS:http2_inspect>
     $<TARGET_OBJECTS:sip>
-    $<TARGET_OBJECTS:ssl>
     $<TARGET_OBJECTS:dns>
     ${STATIC_INSPECTOR_OBJS}
     CACHE INTERNAL "STATIC_SERVICE_INSPECTOR_PLUGINS"
index 416f3892cdba904ffcdf2500e2eaf85434792c2f..d5d261fe4f54cfac3d4283040fd9dd406fb0a33a 100644 (file)
 #endif
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "framework/inspector.h"
 #include "framework/module.h"
 #include "log/messages.h"
index 8993d06abe22860d025e9227d8422fdb8eb6ca8b..d143e4a95218e42914a19fb4c7fb9b6f27c66e89 100644 (file)
@@ -27,9 +27,7 @@
 #include "cip.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "log/messages.h"
-#include "managers/inspector_manager.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 #include "pub_sub/cip_events.h"
index 630d5e874bd60f83e14b8caba55cccc7ce09bb4b..e998c99e6feadcad2409f5d1342713680df3a8b9 100644 (file)
@@ -25,7 +25,6 @@
 #include "flow/flow.h"
 #include "framework/counts.h"
 #include "framework/data_bus.h"
-#include "main/thread.h"
 #include "protocols/packet.h"
 
 #include "cip_definitions.h"
index fb085735ec862d3215b965e4bd8d34631f27b547..d57d62037437702a2cb144e58dbc0300f88ed263 100644 (file)
@@ -171,7 +171,7 @@ static void cip_attribute_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_attribute_ctor(Module* p, OptTreeNode*)
+static IpsOption* cip_attribute_ctor(Module* p, IpsInfo&)
 {
     CipAttributeModule* m = static_cast<CipAttributeModule*>(p);
     return new CipAttributeOption(m->cip_attr);
index 9eca53034dc40ba5e49e7868e0797d4e8cf50c9f..db60dd69abfcc78f54da2c7ef5f2d43208bfea08 100644 (file)
@@ -170,7 +170,7 @@ static void cip_class_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_class_ctor(Module* p, OptTreeNode*)
+static IpsOption* cip_class_ctor(Module* p, IpsInfo&)
 {
     CipClassModule* m = static_cast<CipClassModule*>(p);
     return new CipClassOption(m->cip_class);
index 0ba5f82f59f56241e03a99a680df8c924fec182c..3f4114f1f23ecd08c7081eca4a186840188cd276 100644 (file)
@@ -171,7 +171,7 @@ static void cip_connpathclass_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_connpathclass_ctor(Module* p, OptTreeNode*)
+static IpsOption* cip_connpathclass_ctor(Module* p, IpsInfo&)
 {
     CipConnpathclassModule* m = static_cast<CipConnpathclassModule*>(p);
     return new CipConnpathclassOption(m->cip_cpc);
index beb741412010001a6b9dc477b0e01c7ac3d07e50..54a7211e659d5170c56f62418ecb1847fe9fdd29 100644 (file)
@@ -164,7 +164,7 @@ static void cip_enipcommand_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_enipcommand_ctor(Module* p, OptTreeNode*)
+static IpsOption* cip_enipcommand_ctor(Module* p, IpsInfo&)
 {
     CipEnipCommandModule* m = static_cast<CipEnipCommandModule*>(p);
     return new CipEnipCommandOption(m->cip_enip_cmd);
index a060664e54fb331558e88b99aeea3c654b33118f..a424a5fd0712edd15220d123abd5504f07bbd4d0 100644 (file)
@@ -127,7 +127,7 @@ static void cip_enipreq_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_enipreq_ctor(Module*, OptTreeNode*)
+static IpsOption* cip_enipreq_ctor(Module*, IpsInfo&)
 {
     return new CipEnipreqOption;
 }
index 4fbb8636cc895334a66c70f0664073328ef64e17..83dec6f9e1a4adc97c32a42cfcc1a8c9d2d7936f 100644 (file)
@@ -127,7 +127,7 @@ static void cip_eniprsp_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_eniprsp_ctor(Module*, OptTreeNode*)
+static IpsOption* cip_eniprsp_ctor(Module*, IpsInfo&)
 {
     return new CipEnipRspOption;
 }
index baa504d9ac8559616ab739b7eb84418e24a3cb8f..f629dc57c2bfb386052e484ef607a29b4eadebf0 100644 (file)
@@ -171,7 +171,7 @@ static void cip_instance_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_instance_ctor(Module* p, OptTreeNode*)
+static IpsOption* cip_instance_ctor(Module* p, IpsInfo&)
 {
     CipInstanceModule* m = static_cast<CipInstanceModule*>(p);
     return new CipInstanceOption(m->cip_inst);
index 7cd52636a9b83eae7f2a7a6048d67cf719d41dcd..642427d68e4144ef1931841d134a2e5040dce6c0 100644 (file)
@@ -128,7 +128,7 @@ static void cip_req_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_req_ctor(Module*, OptTreeNode*)
+static IpsOption* cip_req_ctor(Module*, IpsInfo&)
 {
     return new CipReqOption;
 }
index d65e79ac48ef856bac90d72d9bd5c9f5c61ecd34..d5a5d5bcf74213950b2b302d4f198785b143c320 100644 (file)
@@ -128,7 +128,7 @@ static void cip_rsp_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_rsp_ctor(Module*, OptTreeNode*)
+static IpsOption* cip_rsp_ctor(Module*, IpsInfo&)
 {
     return new CipRspOption;
 }
index 26da01f8f2695dcf2072c646fa427a527425478e..228921d255bcd2c78af9e9c2bac81bf4d25c5507 100644 (file)
@@ -175,7 +175,7 @@ static void cip_service_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_service_ctor(Module* p, OptTreeNode*)
+static IpsOption* cip_service_ctor(Module* p, IpsInfo&)
 {
     CipServiceModule* m = static_cast<CipServiceModule*>(p);
     return new CipServiceOption(m->cip_serv);
index f24a4ba910c81bd45abf8e79d06dab66acc40f3a..f4604a05de3debc4810586928cd082b410881e76 100644 (file)
@@ -170,7 +170,7 @@ static void cip_status_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* cip_status_ctor(Module* p, OptTreeNode*)
+static IpsOption* cip_status_ctor(Module* p, IpsInfo&)
 {
     CipStatusModule* m = static_cast<CipStatusModule*>(p);
     return new CipStatusOption(m->cip_status);
index 54a0542539e53291942f06bb1e1612aa1018455a..ac80725f6444eb484d76361acc23b1bb8b81b2cb 100644 (file)
@@ -25,7 +25,7 @@
 #include "dce_common.h"
 
 #include "detection/detection_engine.h"
-#include "ips_options/extract.h"
+#include "detection/extract.h"
 #include "log/messages.h"
 #include "utils/safec.h"
 
index 8fd8139d664b6598f372ee3f5aab2679ac51b117..50f971a1b18b6488d95e79befaf226cbf8bd19ac 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "dce_expected_session.h"
 
-#include "managers/inspector_manager.h"
+#include "framework/pig_pen.h"
 #include "pub_sub/dcerpc_events.h"
 #include "stream/stream.h"
 
@@ -36,7 +36,7 @@ void DceExpSsnManager::create_expected_session(const SfIp* ept_ip,
     uint16_t ept_port, const char* mod_name)
 {
     Packet* pkt = DetectionEngine::get_current_packet();
-    Dce2Tcp* inspector = (Dce2Tcp*)InspectorManager::get_inspector(mod_name, true);
+    Dce2Tcp* inspector = (Dce2Tcp*)PigPen::get_inspector(mod_name, true);
     DceExpSsnManager& esm = inspector->get_esm();
 
     const SfIp* src_ip = pkt->ptrs.ip_api.get_dst();
index e929b6f77fe8e790d779e5e42d81d4f88a1273bc..174222b595925625da29d6eddf38ee50fb531819 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "dce_http_proxy_module.h"
 
-#include "managers/inspector_manager.h"
 #include "stream/tcp/tcp_stream_session.h"
 
 #include "dce_http_proxy_splitter.h"
index f6889892f160ba2597235750ade0d51a77a159a6..1541fd3e4427c79e6ae74abdbcfa9da338b67e0b 100644 (file)
@@ -24,7 +24,6 @@
 #include "dce_common.h"
 #include "framework/counts.h"
 #include "framework/module.h"
-#include "main/thread.h"
 
 class DceHttpProxyModule : public snort::Module
 {
index 444b4570ff2a18c15029473b641e9f4384ce1e61..65391880f3c1ec2ab5bdb8ddeb9b3291f3e1c82a 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "dce_http_server_module.h"
 
-#include "managers/inspector_manager.h"
 #include "stream/tcp/tcp_stream_session.h"
 
 #include "dce_http_server_splitter.h"
index 19c7f5cd97c388d898ec60e9c41dcbb47f00c72b..a214643bf7186050fd0aac1c982359326a0f0c73 100644 (file)
@@ -24,7 +24,6 @@
 #include "dce_common.h"
 #include "framework/counts.h"
 #include "framework/module.h"
-#include "main/thread.h"
 
 class DceHttpServerModule : public snort::Module
 {
index e6c1cd8a3ef8bee37edec8de444b89644720ea7f..1835058760feca29908a7dc4d4d97d24a035a469 100644 (file)
@@ -510,9 +510,6 @@ public:
     static void init()
     { inspector_id = snort::FlowData::create_flow_data_id(); }
 
-    size_t size_of() override
-    { return sizeof(*this); }
-
 public:
     static unsigned inspector_id;
     DCE2_SmbVersion smb_version;
index b5981c504357134de53ef23286d22712d96574c1..4e6b48f110ba9125a253f96b8195599ae86878bd 100644 (file)
 #endif
 
 #include "dce_smb2.h"
-#include "dce_smb2_commands.h"
-#include "detection/detection_util.h"
+
+#include "flow/flow_key.h"
 #include "stream/stream.h"
 
+#include "dce_smb2_commands.h"
+
 using namespace snort;
 
 const char* smb2_command_string[SMB2_COM_MAX] = {
index 0103254de1922f3f7e1550e72f6a25b99ee0d1d0..6f7893ea51ad0db9dc3522699c12f2839e89a6a1 100644 (file)
@@ -26,6 +26,8 @@
 #endif
 
 #include "dce_smb2_commands.h"
+
+#include "file_api/file_lib.h"
 #include "hash/hash_key_operations.h"
 #include "log/messages.h"
 #include "packet_io/active.h"
index 20c771b3af3216dfb3670a8670baa5bef26870c1..1845261232a34f75f23d52afa58e5fd2d79dd272 100644 (file)
 #ifndef DCE_SMB2_COMMANDS_H
 #define DCE_SMB2_COMMANDS_H
 
+#include "file_api/file_flows.h"
+#include "file_api/file_service.h"
+
 #include "dce_smb_module.h"
 #include "dce_smb_utils.h"
 #include "dce_smb2_utils.h"
-#include "detection/detection_util.h"
-#include "file_api/file_flows.h"
-#include "file_api/file_service.h"
 
 void DCE2_Smb2Setup(DCE2_Smb2SsnData*, const Smb2Hdr*,
     const uint64_t sid, const uint8_t* smb_data, const uint8_t* end);
index 5cb22e7a215361bec7300cde286e9c0f6a108a26..6e66caf6a3e0130e04433df76335bb55b9e66910 100644 (file)
 #include "config.h"
 #endif
 
+#include "flow/flow_key.h"
+
 #include "dce_smb_module.h"
 #include "dce_smb_utils.h"
 #include "dce_smb2_utils.h"
-#include "detection/detection_util.h"
-#include "flow/flow_key.h"
 
 using namespace snort;
 
index d01c6ebb1a87644cc096dea883ebeba6a7d63e90..0d96db6ec10454264ae9f1992d3d4761e71e9566 100644 (file)
@@ -231,9 +231,6 @@ static const Parameter s_params[] =
     { "valid_smb_versions", Parameter::PT_MULTI, "v1 | v2 | all", "all",
       "valid SMB versions" },
 
-    { "smb_file_inspection", Parameter::PT_ENUM, "off | on | only", nullptr,
-      "deprecated (not used): file inspection controlled by smb_file_depth" },
-
     { "smb_file_depth", Parameter::PT_INT, "-1:32767", "16384",
       "SMB file depth for file data (-1 = disabled, 0 = unlimited)" },
 
@@ -510,9 +507,6 @@ bool Dce2SmbModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("valid_smb_versions") )
         set_smb_versions_mask(config,v.get_string());
 
-    else if ( v.is("smb_file_inspection") )
-        ParseWarning(WARN_CONF, "smb_file_inspection is deprecated (not used): use smb_file_depth");
-
     else if ( v.is("smb_file_depth") )
         config.smb_file_depth = v.get_int16();
 
index 98126780e1349c4dec5d0d5c5ad97c0f4fc7893d..11bdf03c5ddb07d0ec42c110c1e5af61da303820 100644 (file)
 #include "dce_smb_utils.h"
 
 #include "detection/detection_engine.h"
-#include "detection/detection_util.h"
 #include "file_api/file_api.h"
+#include "file_api/file_lib.h"
 #include "hash/hash_key_operations.h"
 #include "main/snort.h"
-#include "network_inspectors/packet_tracer/packet_tracer.h"
 #include "packet_io/active.h"
+#include "packet_io/packet_tracer.h"
 #include "trace/trace_api.h"
 #include "utils/util.h"
 
index 5be45a8b0fe1caa8a90d2d58a86bc6b419c41448..ee469a4ac6ddcf386b409050e97d0be7611340be 100644 (file)
@@ -26,6 +26,7 @@
 #include "dce_tcp.h"
 
 #include "detection/detection_engine.h"
+#include "main/snort_config.h"
 #include "pub_sub/dcerpc_events.h"
 #include "utils/util.h"
 
index 81a5f7f38fd887f0aed2dfdf7b703ff4d9364af5..815bfb3016c0051914428f655b129b64887f1c47 100644 (file)
@@ -511,7 +511,7 @@ static void dce2_iface_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* dce2_iface_ctor(Module* p, OptTreeNode*)
+static IpsOption* dce2_iface_ctor(Module* p, IpsInfo&)
 {
     Dce2IfaceModule* m = (Dce2IfaceModule*)p;
     return new Dce2IfaceOption(m->version, m->any_frag, m->uuid);
index d9f54134d862dfefa4b8130e38c50f18b18dd781..84ce965223d4588d78b5976f57f3e197b62dcc63 100644 (file)
@@ -524,7 +524,7 @@ static void dce2_opnum_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* dce2_opnum_ctor(Module* p, OptTreeNode*)
+static IpsOption* dce2_opnum_ctor(Module* p, IpsInfo&)
 {
     Dce2OpnumModule* m = (Dce2OpnumModule*)p;
     DCE2_Opnum opnum = m->opnum;
index 3611b306dd912b4170e4bdec79fea28609b95111..6ada2ecb8a8aef2b0cbec02f90efb25a89da149e 100644 (file)
@@ -136,7 +136,7 @@ static void dce2_stub_data_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* dce2_stub_data_ctor(Module*, OptTreeNode*)
+static IpsOption* dce2_stub_data_ctor(Module*, IpsInfo&)
 {
     return new Dce2StubDataOption;
 }
index c3592a26e44131fbcacbe2f92b4fa9065354bc83..963de3ba9a896416d737cd7e8d9f61819e10cc40 100644 (file)
 
 #include "smb_message.h"
 
-#include "dce_smb.h"
-#include "dce_smb_commands.h"
-#include "dce_smb_module.h"
-#include "dce_smb_paf.h"
-#include "dce_smb_transaction.h"
-#include "dce_smb2_utils.h"
-#include "detection/detect.h"
 #include "file_api/file_service.h"
 #include "memory/memory_cap.h"
 #include "packet_io/active.h"
 #include "trace/trace_api.h"
 #include "utils/util.h"
 
+#include "dce_smb.h"
+#include "dce_smb2.h"
+#include "dce_smb_commands.h"
+#include "dce_smb_module.h"
+#include "dce_smb_paf.h"
+#include "dce_smb_transaction.h"
+
 using namespace snort;
 
 /********************************************************************
index 7f3a18cc0698f3eb36273c8cc18419abda1fdd6e..9f6344c53d533cef016ea2cb3da7017aee7131bb 100644 (file)
@@ -26,7 +26,6 @@
 #include "dnp3.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "log/messages.h"
 #include "protocols/packet.h"
 
index bac2a3aae09a242f3fa9d6d061bf3abf2b73e2be..f300ceea234a7c5104b0ccff48cd1b6a0ee8d026 100644 (file)
@@ -27,7 +27,6 @@
 #include "dnp3_reassembly.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "protocols/packet.h"
 
 #include "dnp3_map.h"
index 89a80eb6d72527d71b1f3fd0b92822b58428a894..439637b615862d4c60c05e3608ec8235799044da 100644 (file)
@@ -136,7 +136,7 @@ static void dnp3_data_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* dnp3_data_ctor(Module*, OptTreeNode*)
+static IpsOption* dnp3_data_ctor(Module*, IpsInfo&)
 {
     return new Dnp3DataOption;
 }
index 06fa8a744fd7081351e3a3a195f6c66620c153ad..96612d90a230ffa3ac9ff3b6c9b7451cce4f98b1 100644 (file)
@@ -176,7 +176,7 @@ static void dnp3_func_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* dnp3_func_ctor(Module* p, OptTreeNode*)
+static IpsOption* dnp3_func_ctor(Module* p, IpsInfo&)
 {
     Dnp3FuncModule* m = (Dnp3FuncModule*)p;
     return new Dnp3FuncOption(m->func);
index 207f6b867fe98bbba7d95af5a4c6163d472cdf9c..383ce115e39322bb255df56996ce56b313431e9e 100644 (file)
@@ -185,7 +185,7 @@ static void dnp3_ind_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* dnp3_ind_ctor(Module* p, OptTreeNode*)
+static IpsOption* dnp3_ind_ctor(Module* p, IpsInfo&)
 {
     Dnp3IndModule* m = (Dnp3IndModule*)p;
     return new Dnp3IndOption(m->flags);
index 0b4d4dda5ead7203e709e46e065962e1fe69ded6..38ad1d836de7208aa54e88ea8ca90f60cc466617 100644 (file)
@@ -218,7 +218,7 @@ static void dnp3_obj_mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* dnp3_obj_ctor(Module* p, OptTreeNode*)
+static IpsOption* dnp3_obj_ctor(Module* p, IpsInfo&)
 {
     Dnp3ObjModule* m = (Dnp3ObjModule*)p;
     return new Dnp3ObjOption(m->group, m->var);
index 484edb815f80818ad73e519edcf4e832281ff63c..26d5813448c3f39819e20bd3ca7655ffa09b7b43 100644 (file)
@@ -22,9 +22,8 @@
 #define DNS_MODULE_H
 //Interface to the DNS service inspector
 
-#include "framework/bits.h"
 #include "framework/module.h"
-#include "main/thread.h"
+#include "utils/bits.h"
 
 namespace snort
 {
index c0ee5e28f882fcae58371bd1c03ce3dd7defec0c..f11e1afc2fedee1657bbdd72c68118f14b97667f 100644 (file)
@@ -17,6 +17,8 @@ set (FILE_LIST
     ftp_print.cc
     ftp_print.h
     ftp_server.h
+    kmap.cc
+    kmap.h
     telnet_splitter.h
     telnet_splitter.cc
     ftpdata_splitter.h
index ddcac74c20748854f0c1849fe6cb1b65fa1f5651..dc715d4773db362ccd47df0428ff5dfdd847d782 100644 (file)
@@ -46,8 +46,8 @@
 
 #include "detection/detection_engine.h"
 #include "framework/data_bus.h"
+#include "framework/pig_pen.h"
 #include "log/messages.h"
-#include "managers/inspector_manager.h"
 #include "pub_sub/intrinsic_event_ids.h"
 #include "utils/util.h"
 
@@ -176,13 +176,13 @@ int FTPCheckConfigs(SnortConfig* sc, void* pData)
         return rval;
 
     //  Verify that FTP client and FTP data inspectors are initialized.
-    if(!InspectorManager::get_inspector(FTP_CLIENT_NAME, false, sc))
+    if(!PigPen::get_inspector(FTP_CLIENT_NAME, false, sc))
     {
         ParseError("ftp_server requires that %s also be configured.", FTP_CLIENT_NAME);
         return -1;
     }
 
-    if(!InspectorManager::get_inspector(FTP_DATA_NAME, false, sc))
+    if(!PigPen::get_inspector(FTP_DATA_NAME, false, sc))
     {
         ParseError("ftp_server requires that %s also be configured.", FTP_DATA_NAME);
         return -1;
index 3cc1fa5dac5a20e20851290d39a65d48cf6c2f25..37ae42e352ee2694afc93129f9d50dbeaf8ba28c 100644 (file)
@@ -21,8 +21,8 @@
 #include "config.h"
 #endif
 
+#include "framework/pig_pen.h"
 #include "main/snort_config.h"
-#include "managers/inspector_manager.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 #include "stream/stream.h"
@@ -196,7 +196,6 @@ public:
     { delete ftp_client; }
 
     void show(const SnortConfig*) const override;
-    void eval(Packet*) override { }
 
     FTP_CLIENT_PROTO_CONF* ftp_client;
 };
@@ -272,7 +271,7 @@ FTP_CLIENT_PROTO_CONF* get_ftp_client(Packet* p)
     FtpClient* client = (FtpClient*)p->flow->data;
     if ( !client )
     {
-        client = (FtpClient*)InspectorManager::get_inspector(FTP_CLIENT_NAME);
+        client = (FtpClient*)PigPen::get_inspector(FTP_CLIENT_NAME);
         assert(client);
         p->flow->set_data(client);
     }
index a23fff5a77c309f342e8ebf548791a32ce5d2fdc..8a4d4351b1b82a90ccf5b2a5a99b9a88db2bb019 100644 (file)
@@ -30,7 +30,7 @@
 #include "file_api/file_flows.h"
 #include "file_api/file_service.h"
 #include "packet_io/active.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "parser/parse_rule.h"
 #include "profiler/profiler.h"
 #include "protocols/tcp.h"
index f768c6f5f9ffa64a229e3af1d2f7ef11f017cd26..730fd428b9d1ffd5c4e557ca1f1b0720008d9a5b 100644 (file)
@@ -189,9 +189,6 @@ public:
     static void init()
     { inspector_id = snort::FlowData::create_flow_data_id(); }
 
-    size_t size_of() override
-    { return sizeof(*this); }
-
 public:
     static unsigned inspector_id;
     FTP_SESSION session;
@@ -230,8 +227,6 @@ public:
 
     void handle_expected(snort::Packet*) override;
     void handle_eof(snort::Packet*) override;
-    size_t size_of() override
-    { return sizeof(*this); }
 
 public:
     static unsigned inspector_id;
index 67425b42df599cf933ad176bf25f03ceb76936d0..1f1a70d008cee6890bc0b3bdb47a6389e6c9f2bf 100644 (file)
@@ -39,7 +39,8 @@
 #define FTPP_UI_CONFIG_H
 
 #include "sfip/sf_ip.h"
-#include "utils/kmap.h"
+
+#include "kmap.h"
 
 /*
  * Defines
similarity index 99%
rename from src/utils/kmap.cc
rename to src/service_inspectors/ftp_telnet/kmap.cc
index a0c4d0317f3dba54e8cecae5761de5d7600e5913..12fb42c466bc6acc6200507eec90a1be7fc9e996 100644 (file)
@@ -29,7 +29,7 @@
 #include <cassert>
 #include <string>
 
-#include "util.h"
+#include "utils/util.h"
 
 namespace snort
 {
similarity index 89%
rename from src/utils/kmap.h
rename to src/service_inspectors/ftp_telnet/kmap.h
index db4bece12c08e1bb7e845c97b91181ffeae4429d..601882c67ec0ef88b6287ca3b8e185dfca503c78 100644 (file)
@@ -74,14 +74,14 @@ typedef struct _kmap
 
 namespace snort
 {
-SO_PUBLIC KMAP* KMapNew(KMapUserFreeFunc, bool nocase);
-SO_PUBLIC void KMapDelete(KMAP*);
+KMAP* KMapNew(KMapUserFreeFunc, bool nocase);
+void KMapDelete(KMAP*);
 
-SO_PUBLIC int KMapAdd(KMAP*, void* key, int ksize, void* userdata);
+int KMapAdd(KMAP*, void* key, int ksize, void* userdata);
 
-SO_PUBLIC void* KMapFind(KMAP*, void* key, int ksize);
-SO_PUBLIC void* KMapFindFirst(KMAP*);
-SO_PUBLIC void* KMapFindNext(KMAP*);
+void* KMapFind(KMAP*, void* key, int ksize);
+void* KMapFindFirst(KMAP*);
+void* KMapFindNext(KMAP*);
 }
 #endif
 
index 2c1208a1992ea9a7a5af262fdac08068b1f9669a..f7018eab21d17a01910320d8b8cf45271e4864db 100644 (file)
@@ -28,8 +28,8 @@
 
 #include "pp_ftp.h"
 
+#include "detection/detection_buf.h"
 #include "detection/detection_engine.h"
-#include "detection/detection_util.h"
 #include "hash/hash_key_operations.h"
 #include "file_api/file_service.h"
 #include "protocols/packet.h"
index f3b118daba9e2df39284dc2c6992d3247b4d0c8a..4373d3a0227b71b004b4510de850f6993cb7b93b 100644 (file)
@@ -32,8 +32,8 @@
 
 #include "pp_telnet.h"
 
+#include "detection/detection_buf.h"
 #include "detection/detection_engine.h"
-#include "detection/detection_util.h"
 #include "protocols/packet.h"
 #include "stream/stream.h"
 
index 752b64cccbc38d6fe0c4db599631d5c82af16a37..d6989ffa76b66c82e60dbb839e29381aabdd6301 100644 (file)
@@ -27,7 +27,6 @@
 #include <string>
 
 #include "framework/counts.h"
-#include "main/thread.h"
 
 namespace snort
 {
index 229f7f5763ea220da956f5222598220a0eaefbfe..3675950a1b4edb38436f41635c99b1873b497823 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "detection/detection_engine.h"
 #include "detection/ips_context_data.h"
-#include "managers/inspector_manager.h"
+#include "framework/pig_pen.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 
@@ -156,7 +156,7 @@ int GtpInspect::get_message_type(int version, const char* name)
 
 int get_message_type(int version, const char* name, snort::SnortConfig* sc)
 {
-    GtpInspect* ins = (GtpInspect*)InspectorManager::get_inspector(GTP_NAME, false, sc);
+    GtpInspect* ins = (GtpInspect*)PigPen::get_inspector(GTP_NAME, false, sc);
 
     if ( !ins )
         return -1;
@@ -178,7 +178,7 @@ int GtpInspect::get_info_type(int version, const char* name)
 
 int get_info_type(int version, const char* name, SnortConfig* sc)
 {
-    GtpInspect* ins = (GtpInspect*)InspectorManager::get_inspector(GTP_NAME, false, sc);
+    GtpInspect* ins = (GtpInspect*)PigPen::get_inspector(GTP_NAME, false, sc);
 
     if ( !ins )
         return -1;
index 50cbefcbeae2cddd9106777fa45ed72519f1fb0a..094e1507ebbea949e18c818942e050a293c7c20b 100644 (file)
@@ -29,7 +29,6 @@
 #include <arpa/inet.h>
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "log/messages.h"
 #include "trace/trace_api.h"
 #include "utils/util_cstring.h"
index a81c418ed9ec1ed20c14a378df190723ac6f6553..06863f62dca07fed8f48403b82811333f89ec4ed 100644 (file)
@@ -217,7 +217,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     GtpInfoModule* mod = (GtpInfoModule*)m;
     return new GtpInfoOption(mod->types);
index 733e59cd1e053bb2d51c245f1976dd4f20ad0203..87c6b3efc72cccd1a919f36b4f7142a36db4ae47 100644 (file)
@@ -231,7 +231,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     GtpTypeModule* mod = (GtpTypeModule*)m;
     return new GtpTypeOption(mod->types);
index b7c9132874258c14ad8f90a478114ec06f173a9c..92185fffdf13195daaadc5c90a0b220b090e8b97 100644 (file)
@@ -145,7 +145,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     GtpVersionModule* mod = (GtpVersionModule*)m;
     return new GtpVersionOption(mod->version);
index 4b19deadffab20f2852ecbd69d56c338d20c9bb9..729aabb230a105fcb6e3920d21ab4a9e9713bc27 100644 (file)
 #include <queue>
 #include <vector>
 
-#include "main/snort_types.h"
-#include "utils/event_gen.h"
-#include "utils/infractions.h"
 #include "flow/flow.h"
+#include "flow/stream_flow.h"
+#include "helpers/event_gen.h"
+#include "helpers/infractions.h"
+#include "main/snort_types.h"
 #include "service_inspectors/http_inspect/http_common.h"
 #include "service_inspectors/http_inspect/http_field.h"
 #include "stream/stream_splitter.h"
index e0f5da74b34b66a519529808a102b6714c601a08..f8dfae38c71377d7cd1bbaef08cfa426cb381529 100644 (file)
@@ -20,9 +20,9 @@
 #ifndef HTTP2_HPACK_H
 #define HTTP2_HPACK_H
 
+#include "helpers/event_gen.h"
+#include "helpers/infractions.h"
 #include "service_inspectors/http_inspect/http_common.h"
-#include "utils/event_gen.h"
-#include "utils/infractions.h"
 
 #include "http2_hpack_int_decode.h"
 #include "http2_hpack_string_decode.h"
index c59f4ae2ed5e6ecd06ba0e27dadcc622a4eaf81f..ce3a9225ef851a397ee23898f25495bf8b419ebe 100644 (file)
@@ -23,9 +23,9 @@
 #include "http2_enum.h"
 #include "http2_varlen_int_decode.h"
 
+#include "helpers/event_gen.h"
+#include "helpers/infractions.h"
 #include "main/snort_types.h"
-#include "utils/event_gen.h"
-#include "utils/infractions.h"
 
 using Http2Infractions = Infractions<Http2Enums::INF__MAX_VALUE, Http2Enums::INF__NONE>;
 
index 03803178202bce903c4a896bba9c8a6d2061f37a..7ef3f79b464d8efddd814f629a72e4103dc7ab84 100644 (file)
@@ -20,9 +20,9 @@
 #ifndef HTTP2_PUSH_PROMISE_FRAME_H
 #define HTTP2_PUSH_PROMISE_FRAME_H
 
+#include "helpers/event_gen.h"
+#include "helpers/infractions.h"
 #include "service_inspectors/http_inspect/http_common.h"
-#include "utils/event_gen.h"
-#include "utils/infractions.h"
 
 #include "http2_enum.h"
 #include "http2_frame.h"
index 82bd92ca58c0515cf3fb7863ecab22ed040e484a..3fb71b15987f9da937de0b6a4715a2c94435cec7 100644 (file)
 #ifndef HTTP2_START_LINE_H
 #define HTTP2_START_LINE_H
 
+#include "helpers/event_gen.h"
+#include "helpers/infractions.h"
 #include "service_inspectors/http_inspect/http_common.h"
 #include "service_inspectors/http_inspect/http_field.h"
-#include "utils/event_gen.h"
-#include "utils/infractions.h"
 
 #include "http2_enum.h"
 
index d4089b27349e42074e173446efdaca578ba43461..3a6b4263bd16bafbb734354a2af622d46f21e67a 100644 (file)
@@ -73,7 +73,7 @@ public:
     EvalStatus eval(Cursor&, snort::Packet*) override;
     uint32_t hash() const override;
     bool operator==(const snort::IpsOption& ips) const override;
-    static snort::IpsOption* opt_ctor(snort::Module* m, OptTreeNode*)
+    static snort::IpsOption* opt_ctor(snort::Module* m, IpsInfo&)
         { return new Http2IpsOption((Http2CursorModule*)m); }
     static void opt_dtor(IpsOption* p) { delete p; }
 private:
index 628c06aa816f8b76cc380f3ac2fc64da2666f5eb..b0b2dbef4648e1559677661def37e1b716a860fa 100644 (file)
@@ -20,8 +20,8 @@
 #ifndef HTTP_EVENT_H
 #define HTTP_EVENT_H
 
-#include "utils/event_gen.h"
-#include "utils/infractions.h"
+#include "helpers/event_gen.h"
+#include "helpers/infractions.h"
 #include "utils/util_cstring.h"
 
 #include "http_enum.h"
index 63baa554d0f09e1c60876853bc7ee13e70cc0508..23de3cc198f3cddf0c3d71bb5f9cd0adbae595a3 100644 (file)
@@ -26,7 +26,7 @@
 #include <list>
 
 #include "flow/flow.h"
-#include "utils/util_utf.h"
+#include "helpers/utf.h"
 #include "decompress/file_decomp.h"
 
 #include "http_common.h"
index 21f8520503ce1d220a42d2dbbc04aabd307f42f2..c4f9b37c65440f6017a9939aa643200e456a5105 100755 (executable)
@@ -28,7 +28,6 @@
 #include <sstream>
 
 #include "detection/detection_engine.h"
-#include "detection/detection_util.h"
 #include "service_inspectors/http2_inspect/http2_flow_data.h"
 #include "log/unified2.h"
 #include "protocols/packet.h"
index 8b8bd119aff36c234436d8354ff27cdc482cbadc..63436f9d6c68bb1858d1291f3de24c9d7a01f060 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "http_msg_request.h"
 
+#include "main/snort_config.h"
 #include "pub_sub/intrinsic_event_ids.h"
 
 #include "http_api.h"
index e40bcd9e16437ab4d9de06d51ccb88e65b6ab4d9..8a25c6cd61d04576797737a576aebcb26619e5e2 100644 (file)
@@ -20,7 +20,6 @@
 #ifndef HTTP_MSG_SECTION_H
 #define HTTP_MSG_SECTION_H
 
-#include "detection/detection_util.h"
 #include "framework/cursor.h"
 #include "framework/pdu_section.h"
 #include "protocols/packet.h"
index 7114fe897b8e0cbaf21f12bbb55478996dcdde6b..2fb87cc226408948cf50be4cf3fa086c3ba2c011 100644 (file)
@@ -73,7 +73,7 @@ public:
         key(cm->key), fp_buffer_info(cm->rule_opt_index) {}
     EvalStatus eval(Cursor&, snort::Packet*) override;
 
-    static IpsOption* opt_ctor(snort::Module* m, OptTreeNode*)
+    static IpsOption* opt_ctor(snort::Module* m, IpsInfo&)
     { return new HttpBufferIpsOption((HttpBufferRuleOptModule*)m); }
 
     static void opt_dtor(snort::IpsOption* p) { delete p; }
index f8eea48cd90448164c2944cc7dc35c2017f7d0c1..62b3ccb083772c33c2aef3306f2590c5341b668c 100644 (file)
@@ -101,7 +101,7 @@ class HttpNumIpsOption : public HttpRangeIpsOption
 public:
     using HttpRangeIpsOption::HttpRangeIpsOption;
 
-    static IpsOption* opt_ctor(snort::Module* m, OptTreeNode*)
+    static IpsOption* opt_ctor(snort::Module* m, IpsInfo&)
     { return new HttpNumIpsOption((const HttpRangeRuleOptModule*)m); }
 
     int32_t get_num(const HttpInspect* hi, snort::Packet* p) override
index daad74dbc156ef78246e6ceb45ff78a555258afa..9aba6a241b88294473bbc8bd4e4ed8b9c5619050 100644 (file)
@@ -96,7 +96,7 @@ bool HttpParamIpsOption::operator==(const IpsOption& ips) const
            http_param == hio.http_param;
 }
 
-bool HttpParamIpsOption::retry(Cursor& current_cursor, const Cursor&)
+bool HttpParamIpsOption::retry(Cursor& current_cursor)
 {
     HttpCursorData* cd = (HttpCursorData*)current_cursor.get_data(HttpCursorData::id);
 
index 4f4882c2f4a92d1d0ef2886c8cf44d5bb353ac79..2b07ce819fbb42f92d892987273c01aa1e94953f 100644 (file)
@@ -67,11 +67,11 @@ public:
     uint32_t hash() const override;
     bool operator==(const snort::IpsOption& ips) const override;
 
-    static IpsOption* opt_ctor(snort::Module* m, OptTreeNode*)
+    static IpsOption* opt_ctor(snort::Module* m, IpsInfo&)
     { return new HttpParamIpsOption((HttpParamRuleOptModule*)m); }
 
     static void opt_dtor(snort::IpsOption* p) { delete p; }
-    bool retry(Cursor& , const Cursor&) override;
+    bool retry(Cursor&) override;
 
     snort::section_flags get_pdu_section(bool) const override;
 
index 2781d00b540a22744bacde1d5b87d96168198c9c..fc7fe3b361d1656dea699fc5e6af00b67cd944ee 100644 (file)
@@ -68,7 +68,7 @@ public:
     EvalStatus eval(Cursor&, snort::Packet*) override;
     uint32_t hash() const override;
     bool operator==(const snort::IpsOption& ips) const override;
-    static IpsOption* opt_ctor(snort::Module* m, OptTreeNode*)
+    static IpsOption* opt_ctor(snort::Module* m, IpsInfo&)
         { return new HttpTestIpsOption((HttpTestRuleOptModule*)m); }
     static void opt_dtor(snort::IpsOption* p) { delete p; }
 
index 6f98ea9847c8b10218fe534ca4ecb1e2d7ac9863..9c17c552b66ae268c224845e0a8d118a08a8b677 100644 (file)
@@ -58,7 +58,7 @@ public:
     uint32_t hash() const override;
     bool operator==(const snort::IpsOption& ips) const override;
 
-    static IpsOption* opt_ctor(snort::Module* m, OptTreeNode*)
+    static IpsOption* opt_ctor(snort::Module* m, IpsInfo&)
     { return new HttpVersionIpsOption((HttpVersionRuleOptModule*)m); }
 
     static void opt_dtor(snort::IpsOption* p) { delete p; }
index 60a977d00ecd2b2c727eb85d9e4d94e49a4dbb2f..d6ff9db832757547f16ee40c17b5c418e1c266d3 100755 (executable)
@@ -67,7 +67,7 @@ unsigned ThreadConfig::get_instance_max() { return 1; }
 }
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 int32_t str_to_code(const char*, const StrCode []) { return 0; }
 int32_t str_to_code(const uint8_t*, const int32_t, const StrCode []) { return 0; }
index c7f5dfc18285f669d734c9124d531b16b1681ecd..5d764c5eb4364f520655e923c6638359a3fc85b3 100755 (executable)
@@ -65,7 +65,7 @@ snort::SearchTool* js_create_mpse_tag_type() { return nullptr; }
 snort::SearchTool* js_create_mpse_tag_attr() { return nullptr; }
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 int64_t Parameter::get_int(char const*) { return 0; }
 
index ea807fd87b8a6f61ac330ec721783687361f679f..573504bb68a4f155bb3bd6197fa5a1619bcdf05f 100644 (file)
@@ -27,7 +27,6 @@
 #include "iec104.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 
index f112b6c08028bc531df0f6bd0d85937c9c98ebc7..2582916550330ae75f86e0d6a1968602823f56e0 100644 (file)
@@ -27,7 +27,6 @@
 #include "iec104_decode.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "log/messages.h"
 #include "protocols/packet.h"
 #include "trace/trace_api.h"
index 2c46cefc032ce1aa4f5b098260f85df156b3efc3..46251a088fc660d0bd8bf26b9a5bc31c4643b73a 100644 (file)
@@ -29,7 +29,6 @@
 #include "iec104_paf.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "profiler/profiler.h"
 
 #include "iec104.h"
index d348b37fac136ff6578e649b21826ef736311cec..6e8ec5c777ac33b1458b44d9188db88ce5ba6328 100644 (file)
@@ -25,7 +25,6 @@
 #include "iec104_parse_apdu.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "protocols/packet.h"
 
 #include "iec104.h"
index 4ec7337ef32103a4be43c79bc67844ddcad7a790..e409ac7e7b425b6b7ec6de1400d44dbad8ca06b8 100644 (file)
@@ -27,7 +27,6 @@
 #include <cmath>
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "protocols/packet.h"
 
 #include "iec104.h"
index 057324b3b53511d6426a257578c22015a36a73bf..875edbfded9e7a77d503f8257bef5bb3e73b7c52 100644 (file)
@@ -25,7 +25,6 @@
 // Detection trace utility
 
 #include "main/snort_types.h"
-#include "main/thread.h"
 
 namespace snort
 {
index f1c2b68c31b93ea3b24fa42239ac93113a80466b..2a66a7e042a297609b53d7797a308c856c7bab7f 100644 (file)
@@ -212,7 +212,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     Iec104ApciTypeModule* mod = (Iec104ApciTypeModule*) m;
     return new Iec104ApciTypeOption(mod->apci_type);
index 08e9637bae28f7376339050afeb292ceb4b6405e..659b1bc40453ea9b67ac936bb3ae70a276e348b2 100644 (file)
@@ -285,7 +285,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     Iec104AsduFuncModule* mod = (Iec104AsduFuncModule*) m;
     return new Iec104AsduFuncOption(mod->func);
index 90fcbb3e7f7a7eed80712cb58e2a92198b7eb42b..9402b3d3d4309747fd2ba0da2e90bf1ae07e112c 100644 (file)
@@ -123,7 +123,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module*, OptTreeNode*)
+static IpsOption* opt_ctor(Module*, IpsInfo&)
 {
     return new MmsDataOption;
 }
index 626230e7737f62d1aecd4190c4ecef65c4fccc9d..67bc9be38900cba26a953073e51b9cbb72d366d4 100644 (file)
@@ -27,9 +27,9 @@
 #include "framework/ips_option.h"
 #include "framework/module.h"
 #include "hash/hash_key_operations.h"
+#include "helpers/ber.h"
 #include "protocols/packet.h"
 #include "profiler/profiler.h"
-#include "utils/util_ber.h"
 
 #include "mms.h"
 
@@ -393,7 +393,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     MmsFuncModule* mod = (MmsFuncModule*)m;
 
index 35c1bb768c79b2578830c48eb4614b9c89bbfa88..9c7506d4430ea61577e5c6637b7389bf881c926c 100644 (file)
@@ -27,7 +27,6 @@
 #include "mms.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 
index 25d4293ec06ff62fc3e5d767532bf92b148c1884..df749eecf4e016c0179fd7e9128d144c2d82aefe 100644 (file)
 #include "mms_decode.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
+#include "helpers/ber.h"
 #include "log/messages.h"
 #include "managers/plugin_manager.h"
 #include "protocols/packet.h"
 #include "trace/trace_api.h"
-#include "utils/util_ber.h"
 
 #include "mms.h"
 #include "mms_module.h"
index ca035f63add3e156d6f50ec53bb77d2f0821b702..33b1111b346be02abd6b86494dfab68761659082 100644 (file)
@@ -25,9 +25,8 @@
 #include "mms_splitter.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
+#include "helpers/ber.h"
 #include "profiler/profiler.h"
-#include "utils/util_ber.h"
 
 #include "mms.h"
 #include "mms_decode.h"
index 548b2995b1a67fed9e703a6df6374190304025f4..549ec660d30d9a7dd7f59ec27a2a64c799bc9e08 100644 (file)
@@ -28,9 +28,9 @@
 #include "flow/flow.h"
 #include "framework/counts.h"
 #include "framework/cursor.h"
+#include "helpers/ber.h"
 #include "protocols/packet.h"
 #include "service_inspectors/mms/mms.h"
-#include "utils/util_ber.h"
 
 namespace snort
 {
@@ -161,11 +161,6 @@ public:
         ssn_data.packet_data_reset(direction);
     }
 
-    size_t size_of() override
-    {
-        return sizeof(*this);
-    }
-
 public:
     static unsigned inspector_id;
     TpktSessionData ssn_data;
index 2a473c81e9af0c920ecc99b4f53dc0df6f66a35e..d7d7192267dfc871ac54162f798cfd51bd107f99 100644 (file)
@@ -122,7 +122,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module*, OptTreeNode*)
+static IpsOption* opt_ctor(Module*, IpsInfo&)
 {
     return new ModbusDataOption;
 }
index a795b9ee3d4bc35ee5d6f1ebac8bc49ab199447d..f55105755c4a7d089595348a4b01cfb4b77f1123 100644 (file)
@@ -202,7 +202,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     ModbusFuncModule* mod = (ModbusFuncModule*)m;
     return new ModbusFuncOption(mod->func);
index 5d08572e9ca02538f0cdbf05188b752c3af897ff..cdf50ce25ad28ba78d18497b9e58702695056e93 100644 (file)
@@ -147,7 +147,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     ModbusUnitModule* mod = (ModbusUnitModule*)m;
     return new ModbusUnitOption(mod->unit);
index 215571149d8ab17213cb1c4cb192cb7a6a102835..80efed276793bef933acd1e9b31b80256205cbf5 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "modbus.h"
 
-#include "events/event_queue.h"
 #include "detection/detection_engine.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
index 6a8a6c4cb8df45e6586e44f4ff7e59bee03c4cf8..f29f3cf54acd9ea1637cfd2ecb720fec52b7c7e4 100644 (file)
@@ -26,7 +26,6 @@
 #include "modbus_decode.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "protocols/packet.h"
 
 #include "modbus.h"
index c52836b789c6ede7c6ee41c1a4c341131f617a68..c981411cf338d45f5403e244ee057d3914df1cbb 100644 (file)
@@ -27,7 +27,6 @@
 #include "modbus_paf.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 
 #include "modbus.h"
 #include "modbus_module.h"
index 97a9cb26fbdbfccdf32eba133c608d7382919366..a23e95d4ae7a45d649d38618516f4d0268e92e75 100644 (file)
@@ -1,15 +1,16 @@
 
 set ( NETFLOW_INCLUDES
-    netflow_cache.h
-    netflow_headers.h
-    netflow_module.h
     netflow_record.h
-    netflow.h
 )
+
 set ( FILE_LIST
     ${NETFLOW_INCLUDES}
+    netflow_cache.h
+    netflow_headers.h
     netflow_module.cc
+    netflow_module.h
     netflow.cc
+    netflow.h
 )
 
 if (STATIC_INSPECTORS)
@@ -22,4 +23,4 @@ endif (STATIC_INSPECTORS)
 
 install(FILES ${NETFLOW_INCLUDES}
     DESTINATION "${INCLUDE_INSTALL_PATH}/service_inspectors/netflow"
-)
\ No newline at end of file
+)
index 7915df06f0ef2559a5ee549341106473f3bef673..db6094e724aa2e54d21d19c17947a17ed8175ba4 100644 (file)
@@ -34,6 +34,7 @@
 #include "log/messages.h"
 #include "managers/module_manager.h"
 #include "main/reload_tuner.h"
+#include "main/snort_config.h"
 #include "pub_sub/netflow_event.h"
 #include "src/utils/endian.h"
 #include "time/packet_time.h"
index 0ced92ebc02821a35935af074773c26c411e480c..ebde7edb21367ecefa13134888b21a4a8e82582c 100644 (file)
@@ -38,7 +38,7 @@
 #include "config.h"
 #endif
 
-#include "detection/detection_util.h"
+#include "detection/detection_buf.h"
 #include "detection/detection_engine.h"
 #include "framework/data_bus.h"
 #include "log/messages.h"
index ad668cfe3eb8cf1a9c22661576275baae44697c3..15405ab3fba0498c16d2b9be10e36e99040d3f03 100644 (file)
@@ -122,7 +122,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module*, OptTreeNode*)
+static IpsOption* opt_ctor(Module*, IpsInfo&)
 {
     return new S7commplusContentOption;
 }
index 8e9d10a29676611ddce13d3cce0459828724082d..ccda787935a460b9afe11c02aac9382b569567f1 100644 (file)
@@ -196,7 +196,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     S7commplusFuncModule* mod = (S7commplusFuncModule*)m;
     return new S7commplusFuncOption(mod->func);
index 5e27bddeca8f6a581b83882c145e90a18661fae6..52e815b1a98fc7667d99a6ee61db2a85bea2f871 100644 (file)
@@ -188,7 +188,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* opt_ctor(Module* m, OptTreeNode*)
+static IpsOption* opt_ctor(Module* m, IpsInfo&)
 {
     S7commplusOpcodeModule* mod = (S7commplusOpcodeModule*)m;
     return new S7commplusOpcodeOption(mod->opcode);
index ba8fa138607aa14710c08baebe92722ee3ea309f..007e430a6858cbf8ec79db6ce0f7caac63066ce0 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "s7comm.h"
 
-#include "events/event_queue.h"
 #include "detection/detection_engine.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
index 1d9e1407fdb4c9c0261a3a332698ede4ad8153d0..cd4425bc0897ac09e8430c525c538aef2f409fde 100644 (file)
@@ -30,7 +30,6 @@
 #include "s7comm_decode.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "protocols/packet.h"
 
 #include "s7comm.h"
index 91d9efe3f579c050b816c5f5d84be0ee9944c9d4..2c39a4d61783b7d342a9b3da08e6892dae1c869c 100644 (file)
@@ -27,7 +27,6 @@
 #include "s7comm_paf.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 
 #include "s7comm.h"
 #include "s7comm_decode.h"
index a67d6d312071810ae42e9a4c141cf7820332adc0..86a5b01db0394975a39aa3e410c722229fba66c4 100644 (file)
 
 using namespace snort;
 
+extern const BaseApi* sin_dns[];
 extern const BaseApi* sin_file[];
 extern const BaseApi* sin_http[];
 extern const BaseApi* sin_http2[];
 extern const BaseApi* sin_sip[];
-extern const BaseApi* sin_ssl[];
-extern const BaseApi* sin_dns[];
 
 #ifdef STATIC_INSPECTORS
 extern const BaseApi* sin_bo;
@@ -57,6 +56,7 @@ extern const BaseApi* sin_mms[];
 extern const BaseApi* sin_modbus[];
 extern const BaseApi* sin_netflow[];
 extern const BaseApi* sin_s7commplus[];
+extern const BaseApi* sin_ssl[];
 #endif
 
 const BaseApi* service_inspectors[] =
@@ -87,7 +87,6 @@ void load_service_inspectors()
     PluginManager::load_plugins(sin_http);
     PluginManager::load_plugins(sin_http2);
     PluginManager::load_plugins(sin_sip);
-    PluginManager::load_plugins(sin_ssl);
 
 #ifdef STATIC_INSPECTORS
     PluginManager::load_plugins(sin_cip);
@@ -99,6 +98,7 @@ void load_service_inspectors()
     PluginManager::load_plugins(sin_modbus);
     PluginManager::load_plugins(sin_netflow);
     PluginManager::load_plugins(sin_s7commplus);
+    PluginManager::load_plugins(sin_ssl);
 #endif
 }
 
index 890a4003e59ac1862b6b822017eaddcf5f136200..58e271d417c20836b5261d05398dc9d97cfd96a6 100644 (file)
@@ -151,7 +151,7 @@ static Module* header_mod_ctor()
     return new SipCursorModule(IPS_OPT, header_help, SIP_HEADER);
 }
 
-static IpsOption* header_opt_ctor(Module*, OptTreeNode*)
+static IpsOption* header_opt_ctor(Module*, IpsInfo&)
 {
     return new SipIpsOption(IPS_OPT, SIP_HEADER, CAT_SET_FAST_PATTERN);
 }
@@ -196,7 +196,7 @@ static Module* body_mod_ctor()
     return new SipCursorModule(IPS_OPT, cb_help, SIP_BODY);
 }
 
-static IpsOption* body_opt_ctor(Module*, OptTreeNode*)
+static IpsOption* body_opt_ctor(Module*, IpsInfo&)
 {
     return new SipIpsOption(IPS_OPT, SIP_BODY, CAT_SET_FAST_PATTERN);
 }
index c700a2aa0284059ae4e66b0c3b923c611682f557..bff4af3c0b7c83c2a4cb58b5344f7beb0817aa43 100644 (file)
@@ -210,7 +210,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* sip_method_ctor(Module* p, OptTreeNode*)
+static IpsOption* sip_method_ctor(Module* p, IpsInfo&)
 {
     SipMethodModule* m = (SipMethodModule*)p;
     return new SipMethodOption(m->methods);
index 7db83936e0412b288673a1e6d4493f602269dcaf..6132c563c7b2655c6ad9266cc5205df262964aa7 100644 (file)
@@ -193,7 +193,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* sip_stat_code_ctor(Module* p, OptTreeNode*)
+static IpsOption* sip_stat_code_ctor(Module* p, IpsInfo&)
 {
     SipStatCodeModule* m = (SipStatCodeModule*)p;
     return new SipStatCodeOption(m->ssod);
index 5dcba942e00cf843695eea40080bf920266e1841..ba3c2a82432ab1272450fdeabbcde90d7f6995a0 100644 (file)
@@ -24,9 +24,7 @@
 #include "sip.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "log/messages.h"
-#include "managers/inspector_manager.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 #include "pub_sub/sip_events.h"
index e54a2d134301999a123dbcabce2e8ddd762ec4b0..5e7b891ed1debd190f9c7d60db2abdd5b4ea3d9c 100644 (file)
@@ -25,7 +25,6 @@
 // Configuration for SIP service inspector
 
 #include "framework/counts.h"
-#include "main/thread.h"
 #include "sip_common.h"
 
 #define SIP_METHOD_DEFAULT     0x003f
index f98f98cd94d54783a630957e42d610494b5b03e2..665d4c182373659fa286a1e60550c74fa8fd25d5 100644 (file)
@@ -26,7 +26,6 @@
 #include "sip_dialog.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "framework/data_bus.h"
 #include "protocols/packet.h"
 #include "protocols/vlan.h"
index 77cf1913d4d1fa2833150332b72c2dc124989792..22f1c8b1dba10537c12367ba1d16328e68a5f4e1 100644 (file)
@@ -81,9 +81,6 @@ static const Parameter s_params[] =
     { "max_request_name_len", Parameter::PT_INT, "0:65535", "20",
       "maximum request name field size" },
 
-    { "max_requestName_len", Parameter::PT_INT, "0:65535", "20",
-      "deprecated - use max_request_name_len instead" },
-
     { "max_to_len", Parameter::PT_INT, "0:65535", "256",
       "maximum to field size" },
 
@@ -218,8 +215,7 @@ bool SipModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("max_from_len") )
         conf->maxFromLen = v.get_uint16();
 
-    // FIXIT-L max_requestName_len is deprecated - delete
-    else if ( v.is("max_request_name_len") or v.is("max_requestName_len") )
+    else if ( v.is("max_request_name_len") )
         conf->maxRequestNameLen = v.get_uint16();
 
     else if ( v.is("max_to_len") )
index 87963268b03095e9b98d18142b4a8045a0a12ca1..6e5c2f58148b010633a81def9f20d4597e5b6b4a 100644 (file)
@@ -26,7 +26,6 @@
 #include "sip_parser.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "utils/util.h"
 #include "utils/util_cstring.h"
 
index 9f9c8b0be54d92228427f32fe355ee07c96b9e71..3375336294f47d921c6c907b59ec7f9031243cf0 100644 (file)
@@ -25,7 +25,6 @@
 #include <string>
 
 #include "detection/detection_engine.h"
-#include "detection/detection_util.h"
 #include "js_norm/js_pdf_norm.h"
 #include "log/messages.h"
 #include "log/unified2.h"
index a3b0e6190920f7b2bc3f227da9c579593755f890..fd12c91b6a41a4f78381340c7534bc96b844d3c0 100644 (file)
@@ -23,7 +23,6 @@
 #include "smtp_paf.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "protocols/packet.h"
 #include "stream/stream.h"
 
index 63265e804c6329a1085b95b11a56600233fe6841..1c323a85e7d07c20c5079e9328fc5b33b556e9b8 100644 (file)
@@ -25,8 +25,8 @@
 
 #include "smtp_util.h"
 
+#include "detection/detection_buf.h"
 #include "detection/detection_engine.h"
-#include "detection/detection_util.h"
 #include "protocols/packet.h"
 #include "stream/stream.h"
 #include "utils/safec.h"
index ebbde81d3a673b303f257e2a0e5892d2f35abdb9..382fa7fe3ee4188965f6957e307fc5a90f707873 100644 (file)
@@ -27,7 +27,6 @@
 #include "smtp_xlink2state.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "packet_io/active.h"
 
 #include "smtp_module.h"
index 0f75475ad87a479ae4d40ded8465530626277dfa..ae6a04db73cfe5f98b1db3f0630e950d079f3859 100644 (file)
@@ -30,7 +30,6 @@
 #include "ssh.h"
 
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "log/messages.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
index 4ab2e345abba3526082d3d562998ccf0445a6625..9bd4f0a14714fb37fca42aed64be2f37ae1b272c 100644 (file)
@@ -16,14 +16,13 @@ set( FILE_LIST
     ${SSL_INCLUDES}
 )
 
-# can't be be linked dynamically yet
-#if (STATIC_INSPECTORS)
+if (STATIC_INSPECTORS)
     add_library( ssl OBJECT ${FILE_LIST})
 
-#else (STATIC_INSPECTORS)
-    #add_dynamic_module(ssl inspectors ${FILE_LIST})
+else (STATIC_INSPECTORS)
+    add_dynamic_module(ssl inspectors ${FILE_LIST})
 
-#endif (STATIC_INSPECTORS)
+endif (STATIC_INSPECTORS)
 
 install(FILES ${SSL_INCLUDES}
     DESTINATION "${INCLUDE_INSTALL_PATH}/service_inspectors/ssl/"
index dbb9f4da65e7fc641d7308a9317b03f7c6d611cb..5d5aefa16d9187071be50f02df01b5ebcb154623 100644 (file)
@@ -235,7 +235,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* ssl_state_ctor(Module* p, OptTreeNode*)
+static IpsOption* ssl_state_ctor(Module* p, IpsInfo&)
 {
     SslStateModule* m = (SslStateModule*)p;
     return new SslStateOption(m->ssod);
index 0b8fc1474821a2e4dcf13d7edb5ea95843d64c64..e040563b080e7e07f749195955e31fb82685e352 100644 (file)
@@ -236,7 +236,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* ssl_version_ctor(Module* p, OptTreeNode*)
+static IpsOption* ssl_version_ctor(Module* p, IpsInfo&)
 {
     SslVersionModule* m = (SslVersionModule*)p;
     return new SslVersionOption(m->svod);
index 0845e62d79a1bfca5d3855b95ccaa20e5bc30a84..0fd4fe45aa9301a4dd6580ac90eed3d18b7de008 100644 (file)
@@ -28,9 +28,7 @@
 #include <memory>
 #include <string>
 
-#include "detection/detect.h"
 #include "detection/detection_engine.h"
-#include "events/event_queue.h"
 #include "log/messages.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
@@ -577,8 +575,6 @@ const InspectApi ssl_api =
     nullptr  // reset
 };
 
-#undef BUILDING_SO  // FIXIT-L can't be linked dynamically yet
-
 extern const BaseApi* ips_ssl_state;
 extern const BaseApi* ips_ssl_version;
 
index 0ba6fcc76971dc71519177e3bc51c44c1ca180c6..569869b694248619ec319d260355723791481248 100644 (file)
@@ -67,7 +67,7 @@ private:
     static bool s7commplus_curse(const uint8_t* data, unsigned len, CurseTracker*);
 #ifdef CATCH_TEST_BUILD
 public:
-#endif  
+#endif
     static bool ssl_v2_curse(const uint8_t* data, unsigned len, CurseTracker*);
 };
 
index f8ad532e837a3ad35c3e905d997d7bb512c42153..477182bf68514b49a62469ae820fb1305bc929d8 100644 (file)
@@ -42,7 +42,7 @@ enum DCE_State
 
 class DceTracker
 {
-public:  
+public:
     DCE_State state = DCE_State::DCE_STATE__0;
     uint32_t helper;
 };
index 29a5b06129346d63eb6529da6858771d5f8c616c..77ef3c06d9a7f2052c6d6bcb70dc9607d948ff6f 100644 (file)
@@ -42,7 +42,7 @@ enum MMS_State
 
 class MmsTracker
 {
-public:  
+public:
     MMS_State state = MMS_State::MMS_STATE__TPKT_VER;
     MMS_State last_state = MMS_State::MMS_STATE__TPKT_VER;
 };
index a541b281cdb1bcce94d141d4588f6e04a0735f08..447c6308c3af74b26d4757e9982401c137901842 100644 (file)
@@ -50,7 +50,7 @@ enum S7commplus_State
 
 class S7commplusTracker
 {
-public:  
+public:
     S7commplus_State state = S7commplus_State::S7COMMPLUS_STATE__TPKT_VER;
     S7commplus_State last_state = S7commplus_State::S7COMMPLUS_STATE__TPKT_VER;
     uint16_t func = 0;
index 2b2589632ea539e3c61af94fc2e2960fcf218b80..e2857cdeccacdeeec6ae068666e3292b899c8776 100644 (file)
@@ -29,7 +29,6 @@
 
 #include <cmath> // For ceil
 
-#include "main/thread.h"
 #include "utils/util.h"
 #include "utils/util_net.h"
 
index bb31fb2199e9d53ceae3cf6efede38b309c8b1f1..ced35af0ce0e23d6e3f7b91f5957a1b97bc85d3e 100644 (file)
@@ -546,3 +546,4 @@ inline std::ostream& operator<<(std::ostream& os, const SfIp* addr)
 SO_PUBLIC const char* snort_inet_ntop(int family, const void* ip_raw, char* buf, int bufsize);
 } // namespace snort
 #endif
+
index 061d2b4d0b76d4f344fc232be4e1c40f1d5224fb..c73b4326114d4e3d098f97b8d06bbf50e8e255f8 100644 (file)
@@ -21,8 +21,8 @@
 
 #include <functional>
 
-#include "framework/bits.h"
 #include "framework/connector.h"
+#include "utils/bits.h"
 
 #define MAXIMUM_SC_MESSAGE_CONTENT 1024
 #define DISPATCH_ALL_RECEIVE 0
index 6c5ec19593cca4bbf71f0fba8339dd7d4dcc3ede..fcd1d0e8f6bfc99e59b47b8770bd18d11624cd2f 100644 (file)
@@ -57,7 +57,7 @@ void SideChannelManager::instantiate(const SCConnectors*, const PortBitSet* port
 }
 
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char*, FILE*) { }
 
 namespace snort
 {
index b531c27b05836e3eb92e7ca40e454ed14110a2e6..a31e9b29a7ac2b34eadb2fe7ddbd0d969ebb73c7 100644 (file)
@@ -25,6 +25,7 @@ add_library( stream_paf OBJECT
     flush_bucket.cc
     flush_bucket.h
     paf.cc
+    paf_stats.h
 )
 
 install (FILES ${STREAM_INCLUDES}
index 6dd545150134976b942c1ede8c1582011902d00c..d3e2ba05cfe239b0dc20c17ff69c1280754fba7b 100644 (file)
 
 #include "stream_ha.h"
 
+#include <algorithm>
 #include <unordered_map>
 
 #include "flow/flow_key.h"
-#include "managers/inspector_manager.h"
 #include "pub_sub/stream_event_ids.h"
 #include "stream/stream.h"
 
index 27e845bb50dd1a3b58dd70bec89159fda2ed594f..f67ccc22976dc875c7babd4ad141d41202a44d8c 100644 (file)
@@ -70,7 +70,6 @@
 
 #include "ip_defrag.h"
 
-#include "detection/detect.h"
 #include "detection/detection_engine.h"
 #include "log/messages.h"
 #include "main/analyzer.h"
@@ -82,7 +81,6 @@
 #include "time/timersub.h"
 #include "trace/trace_api.h"
 #include "utils/safec.h"
-#include "utils/stats.h"
 #include "utils/util.h"
 
 #include "ip_session.h"
index 2873dd844d746fabadcba5985af67a3dbcdad8d1..22dde5f7849367581b49862a028d69d2fb78fded 100644 (file)
 #endif
 
 #include "paf.h"
+#include "paf_stats.h"
 
 #include "detection/detection_engine.h"
 #include "protocols/packet.h"
+#include "protocols/tcp.h"
 
 using namespace snort;
 
index 67e6c367751f07eb42abe806af31d8de075690ff..6d5606b275786d3b415ad30b76363cedf271795b 100644 (file)
@@ -26,8 +26,6 @@
 #define PAF_H
 
 #include "main/snort_types.h"
-#include "main/thread.h"
-#include "profiler/profiler_defs.h"
 #include "stream/stream_splitter.h"
 
 namespace snort
@@ -35,12 +33,10 @@ namespace snort
 struct Packet;
 }
 
-extern THREAD_LOCAL snort::ProfileStats pafPerfStats;
-
 void* paf_new(unsigned max);     // create new paf config (per policy)
 void paf_delete(void*);  // free config
 
-struct SO_PUBLIC PAF_State     // per session direction
+struct PAF_State     // per session direction
 {
     uint32_t seq;    // stream cursor
     uint32_t pos;    // last flush position
@@ -60,7 +56,7 @@ inline uint32_t paf_position (PAF_State* ps)
     return ps->seq;
 }
 
-SO_PUBLIC inline uint32_t paf_initialized (PAF_State* ps)
+inline uint32_t paf_initialized (PAF_State* ps)
 {
     return ( ps->paf != snort::StreamSplitter::START );
 }
diff --git a/src/stream/paf_stats.h b/src/stream/paf_stats.h
new file mode 100644 (file)
index 0000000..28b3fdf
--- /dev/null
@@ -0,0 +1,31 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2024-2024 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.
+//--------------------------------------------------------------------------
+
+// paf_stats.h author Russ Combs <rcombs@sourcefire.com>
+
+#ifndef PAF_STATS_H
+#define PAF_STATS_H
+
+// private PAF accessors (not installed)
+
+#include "profiler/profiler_defs.h"
+
+extern THREAD_LOCAL snort::ProfileStats pafPerfStats;
+
+#endif
+
index 9d73723ae9075e5411997b07a40a69ed8b739691..05b5159767048dfa4f088fe88c151c45725a13aa 100644 (file)
@@ -35,8 +35,8 @@
 #include "framework/data_bus.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
-#include "network_inspectors/packet_tracer/packet_tracer.h"
 #include "packet_io/active.h"
+#include "packet_io/packet_tracer.h"
 #include "protocols/vlan.h"
 #include "pub_sub/stream_event_ids.h"
 #include "stream/base/stream_module.h"
@@ -79,15 +79,10 @@ Flow* Stream::new_flow(const FlowKey* key)
 { return flow_con->new_flow(key); }
 
 void Stream::delete_flow(const FlowKey* key)
-{
-    flow_con->release_flow(key);
-}
+{ flow_con->release_flow(key); }
 
 void Stream::delete_flow(Flow* flow)
-{
-    if (flow_con)
-        flow_con->release_flow(flow, PruneReason::NONE);
-}
+{ flow_con->release_flow(flow, PruneReason::NONE); }
 
 //-------------------------------------------------------------------------
 // key foo
@@ -153,26 +148,6 @@ FlowData* Stream::get_flow_data(
     return flow->get_flow_data(flowdata_id);
 }
 
-FlowData* Stream::get_flow_data(
-    PktType type, IpProtocol proto,
-    const SfIp* srcIP, uint16_t srcPort,
-    const SfIp* dstIP, uint16_t dstPort,
-    uint16_t vlan, uint32_t mplsId,
-    uint32_t addressSpaceID, unsigned flowdata_id, uint32_t tenant_id,
-    int16_t ingress_group, int16_t egress_group)
-{
-    Flow* flow = get_flow(
-        type, proto, srcIP, srcPort, dstIP, dstPort,
-        vlan, mplsId, addressSpaceID, tenant_id, ingress_group,
-        egress_group);
-
-    if (!flow)
-        return nullptr;
-
-    return flow->get_flow_data(flowdata_id);
-}
-
-//-------------------------------------------------------------------------
 //-------------------------------------------------------------------------
 // session status
 //-------------------------------------------------------------------------
index 28e2577096d10efa45e37f2fe2f07c43b972bf8b..6f57a74773094d61f6b64a8416bb80fa6f0571f2 100644 (file)
@@ -193,15 +193,6 @@ public:
         bool swap_app_direction = false, bool expect_multi = false, bool bidirectional = false,
         bool expect_persist = false);
 
-    // Get pointer to application data for a flow based on the lookup tuples for cases where
-    // Snort does not have an active packet that is relevant.
-    static FlowData* get_flow_data(
-        PktType type, IpProtocol proto,
-        const snort::SfIp* a1, uint16_t p1, const snort::SfIp* a2, uint16_t p2,
-        uint16_t vlanId, uint32_t mplsId, uint32_t addrSpaceId, unsigned flowdata_id,
-        uint32_t tenant_id, int16_t ingress_group = DAQ_PKTHDR_UNKNOWN,
-        int16_t egress_group = DAQ_PKTHDR_UNKNOWN);
-
     // Get pointer to application data for a flow using the FlowKey as the lookup criteria
     static FlowData* get_flow_data(const FlowKey*, unsigned flowdata_id);
 
@@ -223,7 +214,6 @@ public:
     // Handle session block pending state
     static void check_flow_closed(Packet*);
 
-    //  Populate a flow key from the Packet
     static void populate_flow_key(const Packet*, FlowKey*);
 
     static void set_snort_protocol_id_from_ha(Flow*, const SnortProtocolId);
index ad359447ce7242697193bbd31286e5d0fda016b8..39286e7c24cc43aa67398ee399c27283d9219807 100644 (file)
@@ -238,7 +238,7 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static IpsOption* reassemble_ctor(Module* p, OptTreeNode*)
+static IpsOption* reassemble_ctor(Module* p, IpsInfo&)
 {
     ReassembleModule* m = (ReassembleModule*)p;
     return new ReassembleOption(m->srod);
@@ -286,7 +286,6 @@ const BaseApi* ips_stream_reassemble = &reassemble_api.base;
 TEST_CASE("IPS Stream Reassemble", "[ips_stream_reassemble][stream_tcp]")
 {
     // initialization code here
-    REQUIRE( ( ips_stream_reassemble->api_version == (BASE_API_VERSION << 16) ) );
     REQUIRE( ( strcmp(ips_stream_reassemble->name, s_name) == 0 ) );
     ReassembleModule* reassembler = ( ReassembleModule* )ips_stream_reassemble->mod_ctor();
     REQUIRE( reassembler != nullptr );
index 225d1b7e601fe498d570fad982cf18539fb5abc4..f4ff3ab7ac97c84b2851f06143cef05f0596fecb 100644 (file)
@@ -213,7 +213,7 @@ static Module* size_mod_ctor()
 static void mod_dtor(Module* m)
 {  delete m; }
 
-static IpsOption* size_ctor(Module* p, OptTreeNode*)
+static IpsOption* size_ctor(Module* p, IpsInfo&)
 {
     SizeModule* m = (SizeModule*)p;
     return new SizeOption(m->ssod, m->direction);
index c76e847b2666e9a15412b5226d4f84e15af45ef5..5cf65a71cc1e73834892b5e7a3115e6c656a1695 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef TCP_DEFS_H
 #define TCP_DEFS_H
 
-#include "main/thread.h"
+#include <cstdint>
 
 namespace snort
 {
index c3de7576dc0f5e49dd8beee09d8e7efaf0918ef5..11bb79c81b32dc5ec10199bb7aafce9d2fcc42e6 100644 (file)
@@ -29,7 +29,7 @@
 #include "detection/rules.h"
 #include "filters/sfrf.h"
 #include "main/snort_config.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 
 #include "tcp_module.h"
 
@@ -64,7 +64,6 @@ struct tcp_event_sid tcp_event_sids[] =
     { EVENT_DATA_AFTER_RST_RCVD, STREAM_TCP_DATA_AFTER_RST_RCVD, "DATA_AFTER_RST_RCVD" },
     { EVENT_WINDOW_SLAM, STREAM_TCP_WINDOW_SLAM, "WINDOW_SLAM" },
     { EVENT_NO_3WHS, STREAM_TCP_NO_3WHS, "NO_3WHS" },
-    { EVENT_BAD_SEGMENT, STREAM_TCP_BAD_SEGMENT, "BAD_SEGMENT" },
     { EVENT_EXCESSIVE_OVERLAP, STREAM_TCP_EXCESSIVE_TCP_OVERLAPS, "EXCESSIVE_OVERLAP" },
     { EVENT_MAX_SMALL_SEGS_EXCEEDED, STREAM_TCP_SMALL_SEGMENT, "MAX_SMALL_SEGS_EXCEEDED" },
     { EVENT_MAX_QUEUED_BYTES_EXCEEDED, STREAM_TCP_MAX_QUEUED_BYTES_EXCEEDED, "MAX_QUEUED_BYTES_EXCEEDED" },
index eb346a9af6894a5959b56fc61ababa1bde17f9e2..3d8a9a27546cadb6c807fdc5140b2cfde6e3fbf7 100644 (file)
 #define EVENT_DATA_AFTER_RST_RCVD       0x00004000
 #define EVENT_WINDOW_SLAM               0x00008000
 #define EVENT_NO_3WHS                   0x00010000
-#define EVENT_BAD_SEGMENT               0x00020000
-#define EVENT_EXCESSIVE_OVERLAP         0x00040000
-#define EVENT_MAX_SMALL_SEGS_EXCEEDED   0x00080000
-#define EVENT_MAX_QUEUED_BYTES_EXCEEDED 0x00100000
-#define EVENT_MAX_QUEUED_SEGS_EXCEEDED  0x00200000
+#define EVENT_EXCESSIVE_OVERLAP         0x00020000
+#define EVENT_MAX_SMALL_SEGS_EXCEEDED   0x00040000
+#define EVENT_MAX_QUEUED_BYTES_EXCEEDED 0x00080000
+#define EVENT_MAX_QUEUED_SEGS_EXCEEDED  0x00100000
 
 class TcpEventLogger
 {
index 183ece6740c0909b7fd1f841a9a60e581c3aa784..f99d60399158f92abe6325aa84e36d7b80c866ae 100644 (file)
@@ -28,6 +28,7 @@
 #include "main/snort_config.h"
 #include "profiler/profiler_defs.h"
 #include "stream/paf.h"
+#include "stream/paf_stats.h"
 #include "trace/trace.h"
 
 #include "tcp_trace.h"
@@ -133,8 +134,6 @@ THREAD_LOCAL TcpStats tcpStats;
     "data sent on stream not accepting data"
 #define STREAM_TCP_BAD_TIMESTAMP_STR \
     "TCP timestamp is outside of PAWS window"
-#define STREAM_TCP_BAD_SEGMENT_STR \
-    "bad segment, adjusted size <= 0 (deprecated)"
 #define STREAM_TCP_WINDOW_TOO_LARGE_STR \
     "window size (after scaling) larger than policy allows"
 #define STREAM_TCP_EXCESSIVE_TCP_OVERLAPS_STR \
@@ -248,7 +247,6 @@ static const RuleMap stream_tcp_rules[] =
     { STREAM_TCP_DATA_ON_SYN, STREAM_TCP_DATA_ON_SYN_STR },
     { STREAM_TCP_DATA_ON_CLOSED, STREAM_TCP_DATA_ON_CLOSED_STR },
     { STREAM_TCP_BAD_TIMESTAMP, STREAM_TCP_BAD_TIMESTAMP_STR },
-    { STREAM_TCP_BAD_SEGMENT, STREAM_TCP_BAD_SEGMENT_STR },
     { STREAM_TCP_WINDOW_TOO_LARGE, STREAM_TCP_WINDOW_TOO_LARGE_STR },
     { STREAM_TCP_EXCESSIVE_TCP_OVERLAPS, STREAM_TCP_EXCESSIVE_TCP_OVERLAPS_STR },
     { STREAM_TCP_DATA_AFTER_RESET, STREAM_TCP_DATA_AFTER_RESET_STR },
index 95c87e2ebfb49aaa9b4d0aeb55c64b926877be06..4b6f00999b050eb6810b7d3dbe4bb466d6c57de9 100644 (file)
@@ -31,7 +31,7 @@
 #define STREAM_TCP_DATA_ON_SYN                     2
 #define STREAM_TCP_DATA_ON_CLOSED                  3
 #define STREAM_TCP_BAD_TIMESTAMP                   4
-#define STREAM_TCP_BAD_SEGMENT                     5
+//#define STREAM_TCP_BAD_SEGMENT                   5   deleted
 #define STREAM_TCP_WINDOW_TOO_LARGE                6
 #define STREAM_TCP_EXCESSIVE_TCP_OVERLAPS          7
 #define STREAM_TCP_DATA_AFTER_RESET                8
index 4471cda88f224d0757af55b4215e38ee7867319b..79f5326d76e35d1c011bac0e9a14b6fb2d1a08a4 100644 (file)
 #include "tcp_normalizer.h"
 
 #include "stream/stream.h"
+#include "packet_io/packet_tracer.h"
 
 #include "tcp_module.h"
 #include "tcp_stream_session.h"
 #include "tcp_stream_tracker.h"
-#include "packet_tracer/packet_tracer.h"
 
 using namespace snort;
 
index 7ddd568a0a4ba43f07cfdf8f960a050d00544b2d..17c5c8d629debe754f14938f87daeff5a4254594 100644 (file)
@@ -24,7 +24,8 @@
 
 #include "tcp_defs.h"
 
-#include "main/thread.h"
+#include <string>
+
 #include "normalize/normalize.h"
 #include "normalize/norm_stats.h"
 #include "protocols/tcp_options.h"
index fc003fcfdb6c278f93ff5d28456df9d1af52e636..cba454cdebb8afcbb2e2ab083394f02b32d9e32d 100644 (file)
@@ -29,9 +29,8 @@
 
 #include "detection/detection_engine.h"
 #include "log/log.h"
-#include "main/analyzer.h"
 #include "packet_io/active.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "profiler/profiler.h"
 #include "protocols/packet_manager.h"
 #include "time/packet_time.h"
@@ -597,7 +596,9 @@ int TcpReassembler::flush_to_seq(
         tcpStats.rebuilt_packets++;
         tcpStats.rebuilt_bytes += flushed_bytes;
 
-        if ( !Analyzer::get_local_analyzer()->inspect_rebuilt(pdu) )
+        DetectionEngine de;
+
+        if ( !de.inspect(pdu) )
             last_pdu = pdu;
         else
             last_pdu = nullptr;
@@ -641,7 +642,9 @@ int TcpReassembler::do_zero_byte_flush(TcpReassemblerState& trs, Packet* p, uint
 
         trs.flush_count++;
         show_rebuilt_packet(trs, pdu);
-        Analyzer::get_local_analyzer()->inspect_rebuilt(pdu);
+
+        DetectionEngine de;
+        de.inspect(pdu);
      }
 
      return bytes_copied;
index ac2b5aee2509b8f4f9afbec5a1b7242f436734e9..23fc6c23e2c77cb82da0c7eb297e0ad3368d6319 100644 (file)
@@ -26,7 +26,7 @@
 #include "tcp_segment_descriptor.h"
 
 #include "detection/rules.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "protocols/tcp_options.h"
 #include "stream/tcp/tcp_defs.h"
 #include "stream/tcp/tcp_stream_tracker.h"
index 64361e8d0f608990ccc8e6942815268b824b87c1..6ba4dd128f81bea492832a5036c4bebdcec233b2 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "flow/flow.h"
 #include "detection/ips_context.h"
+#include "main/snort_config.h"
 #include "packet_io/active.h"
 #include "protocols/packet.h"
 #include "protocols/tcp.h"
index 42ea2671e0253fd12ad6e808aa8429f436da14ec..8836165e3f071553c352e948bacaadf6de30b1a1 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "tcp_segment_node.h"
 
-#include "main/thread.h"
 #include "utils/util.h"
 
 #include "segment_overlap_editor.h"
index 60a3201c6b9430f5371ccd1241f9d2e93ba54ecc..a0c4e39a8ed049f9c2359941e296dae40e461025 100644 (file)
 #include "detection/detection_engine.h"
 #include "detection/rules.h"
 #include "log/log.h"
+#include "packet_io/packet_tracer.h"
 #include "profiler/profiler.h"
 #include "protocols/eth.h"
 #include "pub_sub/intrinsic_event_ids.h"
-#include "packet_tracer/packet_tracer.h"
 
 #include "stream_tcp.h"
 #include "tcp_ha.h"
index 12b7efc53d9745e52a6f682c1b4f799846088550..49ef29170a9c00ca67283ab2d287354ab8a62a9f 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "tcp_state_listen.h"
 
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "pub_sub/stream_event_ids.h"
 #include "stream/stream.h"
 
index 55727ac3cd6db389b334bce9f4d047148fb6c64e..de26c2a6f7a0e1cffd33540769f2e4d9bd20cb27 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "tcp_state_none.h"
 
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "pub_sub/stream_event_ids.h"
 #include "stream/stream.h"
 
index d005ef5b4ab5abf15d137b727ec0dfe3b49deb84..513e9f40cf68e4d01758ca44afe71542bddfc8f1 100644 (file)
@@ -26,7 +26,7 @@
 #include "tcp_stream_session.h"
 
 #include "framework/data_bus.h"
-#include "packet_tracer/packet_tracer.h"
+#include "packet_io/packet_tracer.h"
 #include "pub_sub/stream_event_ids.h"
 #include "stream/stream.h"
 #include "stream/tcp/tcp_ha.h"
index 611e62993dbb7841d0655fc87909be39649f36ab..bfbf7ee4e82ea1044aa473f5113b3711d54a33ca 100644 (file)
@@ -26,7 +26,6 @@
 #include "tcp_trace.h"
 
 #include "trace/trace_api.h"
-#include "utils/stats.h"
 
 #include "tcp_module.h"
 #include "tcp_session.h"
index fddf362c69150762fbd1f42ac6e281996b22e190..0ae6597b2f6ef0f7fee87e1bfb08f57df4d7407e 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef TCP_TRACE_H
 #define TCP_TRACE_H
 
-#include "main/thread.h"
 
 namespace snort
 {
index 3e089110b8c940667714f896f9af670a5d43562a..b2f51ecfd2e01376dff3659e5dd1a506310af2cc 100644 (file)
@@ -24,6 +24,7 @@
 #include "stream/stream_splitter.h"
 
 #include "detection/detection_engine.h"
+#include "main/snort_config.h"
 #include "stream/flush_bucket.h"
 #include "stream/stream.h"
 
index 7c23d6917bf2789c3d9c07cfc7479dcf6c946b0b..9020a0394366c66aca84df1bd8b16959c15fc9a5 100644 (file)
@@ -1,17 +1,17 @@
 set(UDP_STREAM_INCLUDES
-   stream_udp.h
-   udp_ha.h
-   udp_module.h
-   udp_session.h
+    udp_session.h
 )
 
 add_library( stream_udp OBJECT
     stream_udp.cc
+    stream_udp.h
     udp_ha.cc
+    udp_ha.h
     udp_module.cc
+    udp_module.h
     udp_session.cc
 )
 
 install(FILES ${UDP_STREAM_INCLUDES}
     DESTINATION "${INCLUDE_INSTALL_PATH}/stream/udp"
-)
\ No newline at end of file
+)
index 0d94b91f0deafa95d0394bd737ff649f5070b01b..e1d0f16d0cf52de5d46040f6c7a53190297a1ff4 100644 (file)
@@ -23,7 +23,6 @@
 #include <sys/time.h>
 
 #include "flow/session.h"
-#include "main/snort_types.h"
 
 class SO_PUBLIC UdpSession : public Session
 {
@@ -40,8 +39,5 @@ public:
     struct timeval ssn_time = {};
 };
 
-void udp_stats();
-void udp_reset();
-
 #endif
 
index 3f8e41c1e72ae2a682666dcf19436b59e4af34f9..ef9bd9a2dd2d3024c9fd162545f7f11a7f60de79 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "detection/detection_engine.h"
 #include "detection/rules.h"
-#include "main/analyzer.h"
+#include "framework/pig_pen.h"
 #include "profiler/profiler_defs.h"
 #include "protocols/packet.h"
 #include "trace/trace_api.h"
@@ -165,7 +165,7 @@ void UserTracker::detect(
     up->packet_flags |= (p->packet_flags & (PKT_STREAM_EST|PKT_STREAM_UNEST_UNI));
 
     debug_logf(stream_user_trace, up, "detect[%d]\n", up->dsize);
-    Analyzer::get_local_analyzer()->inspect_rebuilt(up);
+    PigPen::inspect_rebuilt(up);
 }
 
 int UserTracker::scan(Packet* p, uint32_t& flags)
index c031c8647da26d3c317d5711890d19d62f425fe4..ca2777752b89b62e75641cd38251c3cbb9d17a8f 100644 (file)
@@ -30,7 +30,6 @@
 #include "main/shell.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
-#include "main/thread.h"
 
 using namespace snort;
 
index 18b69dbef0b16fda71d76fb9f6278406013019d8..2a16326e7561bd1b1410f27a63db159bffb5546d 100644 (file)
@@ -35,7 +35,6 @@
 
 #include "packet_time.h"
 
-#include "main/thread.h"
 #include "time/timersub.h"
 
 static THREAD_LOCAL struct timeval s_recent_packet = { 0, 0 };
index 3c8ee695927a0928e7eea51199c92cb503eace66..4a658eddfbf4c5c5022855dc90e4a56cdf384a9a 100644 (file)
 #define TRACE_H
 
 #include <cassert>
+#include <cstdint>
 #include <map>
+#include <string>
 #include <vector>
 
-#include "main/thread.h"
-
 #define DEFAULT_TRACE_LOG_LEVEL 1
 #define TRACE_CRITICAL_LEVEL 2
 #define TRACE_ERROR_LEVEL 3
index 58fe56f5965e12a51a22eb82c882a9e4208b0cf7..08e1760ff44f5f9dfd629070ae96e5dc80c636fe 100644 (file)
 
 #include <cstring>
 
-#include "framework/packet_constraints.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
-#include "main/thread.h"
+#include "packet_io/packet_constraints.h"
 #include "protocols/packet.h"
 #include "utils/safec.h"
 
index 0aad4443e54072704c81c9dbf33e38e1d86b2a08..d2c832c387b32ba7f04d210f14c9127fbee1b6c3 100644 (file)
@@ -26,8 +26,8 @@
 #include <cstring>
 
 #include "framework/module.h"
-#include "framework/packet_constraints.h"
 #include "managers/module_manager.h"
+#include "packet_io/packet_constraints.h"
 
 #include "trace_logger.h"
 
index 018b26181474efe2fbab6fcb7239f754cbaa82f0..04dc106df8a7d447f284023cccaca9f0c4a496a9 100644 (file)
@@ -25,9 +25,9 @@
 
 #include <syslog.h>
 
-#include "framework/packet_constraints.h"
 #include "main/snort_config.h"
 #include "managers/module_manager.h"
+#include "packet_io/packet_constraints.h"
 
 #include "trace_config.h"
 #include "trace_loggers.h"
index 84d02f87bd12e43bf1c3ace30ba95d8766107d64..20802584932365d7c3ca19f80922d7468bc370a7 100644 (file)
@@ -23,7 +23,7 @@
 #include <map>
 #include <string>
 
-#include "framework/packet_constraints.h"
+#include "packet_io/packet_constraints.h"
 
 namespace snort
 {
index cdb8123e9903502f73ddc13ad74e0a6969ecb2e1..bba83c184a586b3e5859e9d9d61d64074780b49a 100644 (file)
 
 #include "control/control.h"
 #include "framework/module.h"
-#include "framework/packet_constraints.h"
 #include "log/messages.h"
 #include "main/analyzer_command.h"
 #include "main/snort_config.h"
+#include "packet_io/packet_constraints.h"
 
 #include "trace_api.h"
 #include "trace_config.h"
index 8e9766f735dfcfbd0122f5e045e67b113e5ae299..26cda0a55c7f9263152a425fa39ee0233038fd01 100644 (file)
@@ -1,45 +1,32 @@
 
 set( UTIL_INCLUDES
-    boyer_moore.h
+    bits.h
     cpp_macros.h
     endian.h
-    event_gen.h
-    infractions.h
-    kmap.h
-    memcap_allocator.h
-    primed_allocator.h
     safec.h
-    sflsq.h
-    stats.h
     util.h
-    util_ber.h
     util_cstring.h
     util_unfold.h
-    util_utf.h
-    util_numa.h
 )
 
 add_library ( utils OBJECT
     ${UTIL_INCLUDES}
     ${SNPRINTF_SOURCES}
-    boyer_moore.cc
+    chunk.cc
+    chunk.h
     dnet_header.h
-    kmap.cc
     sflsq.cc
+    sflsq.h
     snort_bounds.h
     stats.cc
-    streambuf.cc
-    streambuf.h
+    stats.h
     util.cc
-    util_ber.cc
     util_cstring.cc
     util_jsnorm.cc
     util_jsnorm.h
     util_net.cc
     util_net.h
     util_unfold.cc
-    util_utf.cc
-    util_numa.h
     ${TEST_FILES}
 )
 
@@ -47,5 +34,3 @@ install (FILES ${UTIL_INCLUDES}
     DESTINATION "${INCLUDE_INSTALL_PATH}/utils"
 )
 
-add_subdirectory(test)
-
similarity index 100%
rename from src/framework/bits.h
rename to src/utils/bits.h
similarity index 100%
rename from src/helpers/chunk.cc
rename to src/utils/chunk.cc
similarity index 100%
rename from src/helpers/chunk.h
rename to src/utils/chunk.h
index 5d5d1f1b780b20da4183c8975d1eec7c6011a56d..c2649ac9d6eac1df3400df7608b303876fe9fac0 100644 (file)
@@ -1,48 +1,4 @@
-This unit contains a mixed bag of legacy utilities that haven't found a home in any
-other directory.  In many cases, the STL provides better options.
+This unit contains a mixed bag of legacy utilities that haven't found a home in
+any other directory.  In many cases, the STL provides better options. Fully
+formed utility classes should go in src/helpers/.
 
-
-On stream buffer, there are two classes inherited from std::streambuf:
-
-* istreambuf_glue class for reading operations
-* ostreambuf_infl class for writing operations
-
-The input stream buffer presents a continuous sequence of bytes to the client,
-gathered from different sources. For example:
-
-    char* s1 = "world";
-    char* s2 = "!";
-    char* s3 = "Hello ";
-
-These sources being fed to the stream buffer as s3, s1, s2 will form
-"Hello world!" sequence.
-
-In order to do that, istreambuf_glue class represents each source as a chunk of
-data, which has its own position in the resulting sequence.
-The chunk structure contains a pointer to the source, source size, and
-the chunk's offset in the resulting sequence.
-
-Reading is done sequentially within the current chunk. When the end of chunk
-reached, the buffer switches to the next one, setting std::streambuf pointers.
-
-Positioning the cursor is done in two steps:
-
-1. Calculate the final cursor position (absolute or by offset).
-
-2. Find the right chunk and local offset in it to set cursor there.
-
-Currently, no intermediate buffering done between chunks (like alignment,
-prepending/appending the next chunk). The buffer doesn't take ownership over
-the source's memory.
-
-The output stream buffer is mostly like std::stringbuf. The main purpose of it
-is having an extensible dynamic array, where clients could write their data,
-not worrying about resizing and memory management.
-
-Aside from that, ostreambuf_infl can give away ownership over its memory,
-which could be useful for final consumer.
-
-From performance perspective, ostreambuf_infl can reserve an amount of memory
-before actual operations. Also, memory extending is done by predefined
-portions of 2^11^, 2^12^, 2^13^, 2^14^, 2^15^, 2^15^, 2^15^...
-This tries to minimize the number of memory reallocation.
index bdf3ba82caff8cb1e986fad17cf2a3e3dbd9c38e..b1f73ea97e9d9f178657ffe33553bebea73c178c 100644 (file)
 #include <cassert>
 #include <cmath>
 
-#include "control/control.h"
 #include "detection/detection_engine.h"
 #include "file_api/file_stats.h"
 #include "filters/sfthreshold.h"
 #include "framework/module.h"
-#include "helpers/process.h"
+#include "log/log_stats.h"
 #include "log/messages.h"
+#include "main/process.h"
 #include "main/snort_config.h"
 #include "memory/memory_cap.h"
 #include "managers/module_manager.h"
 #include "packet_io/active.h"
 #include "packet_io/sfdaq.h"
 #include "packet_io/trough.h"
-#include "profiler/profiler.h"
+#include "profiler/profiler_impl.h"
 #include "protocols/packet_manager.h"
 #include "time/timersub.h"
 
 #include "util.h"
 
-#define STATS_SEPARATOR \
-    "--------------------------------------------------"
 #define USECS_PER_SEC 1000000.0
 
 ProcessCount proc_stats;
 
 namespace snort
 {
-
 THREAD_LOCAL PacketCount pc;
-static THREAD_LOCAL ControlConn* s_ctrlcon = nullptr;
-
-//-------------------------------------------------------------------------
-
-static inline void LogSeparator(FILE* fh = stdout)
-{
-    LogfRespond(s_ctrlcon, fh, "%s\n", STATS_SEPARATOR);
-}
-
-void LogText(const char* s, FILE* fh)
-{
-    LogfRespond(s_ctrlcon, fh, "%s\n", s);
-}
-
-void LogLabel(const char* s, FILE* fh)
-{
-    if ( *s == ' ' )
-    {
-        LogfRespond(s_ctrlcon, fh, "%s\n", s);
-    }
-    else
-    {
-        LogSeparator(fh);
-        LogfRespond(s_ctrlcon, fh, "%s\n", s);
-    }
-}
-
-void LogValue(const char* s, const char* v, FILE* fh)
-{
-    LogfRespond(s_ctrlcon, fh, "%25.25s: %s\n", s, v);
-}
-
-void LogCount(const char* s, uint64_t c, FILE* fh)
-{
-    if ( c )
-    {
-        LogfRespond(s_ctrlcon, fh, "%25.25s: " STDu64 "\n", s, c);
-    }
-}
-
-void LogStat(const char* s, uint64_t n, uint64_t tot, FILE* fh)
-{
-    if ( n )
-    {
-        LogfRespond(s_ctrlcon, fh, "%25.25s: " FMTu64("-12") "\t(%7.3f%%)\n", s, n, CalcPct(n, tot));
-    }
-}
-
-void LogStat(const char* s, double d, FILE* fh)
-{
-    if ( d )
-    {
-        LogfRespond(s_ctrlcon, fh, "%25.25s: %g\n", s, d);
-    }
-}
 }
 
 using namespace snort;
 
 //-------------------------------------------------------------------------
 
-double CalcPct(uint64_t cnt, uint64_t total)
-{
-    double pct = 0.0;
-
-    if (total == 0.0)
-    {
-        pct = (double)cnt;
-    }
-    else
-    {
-        pct = (double)cnt / (double)total;
-    }
-
-    pct *= 100.0;
-
-    return pct;
-}
-
-//-------------------------------------------------------------------------
-
 static struct timeval starttime = {0, 0}, endtime = {0, 0}, currtime = {0, 0};
 
 void TimeStart()
@@ -195,7 +117,7 @@ static void timing_stats()
     if ( uint64_t pps = (uint64_t)llround(num_pkts / total_secs) )
         LogMessage("%25.25s: " STDu64 "\n", "pkts/sec", pps);
 
-    if ( uint64_t mbps = (uint64_t)llround(8 * num_byts / total_secs / 1024 / 1024) )
+    if ( uint64_t mbps = (uint64_t)llround(8 * num_byts / total_secs / 1e6) )
         LogMessage("%25.25s: " STDu64 "\n", "Mbits/sec", mbps);
 }
 
@@ -227,9 +149,6 @@ const PegInfo pc_names[] =
     { CountType::SUM, "offload_fallback", "fast pattern offload search fallback attempts" },
     { CountType::SUM, "offload_failures", "fast pattern offload search failures" },
     { CountType::SUM, "offload_suspends", "fast pattern search suspends due to offload context chains" },
-    { CountType::SUM, "pcre_match_limit", "total number of times pcre hit the match limit" },
-    { CountType::SUM, "pcre_recursion_limit", "total number of times pcre hit the recursion limit" },
-    { CountType::SUM, "pcre_error", "total number of times pcre returns error" },
     { CountType::SUM, "cont_creations", "total number of continuations created" },
     { CountType::SUM, "cont_recalls", "total number of continuations recalled" },
     { CountType::SUM, "cont_flows", "total number of flows using continuation" },
@@ -262,7 +181,8 @@ const PegInfo proc_names[] =
 
 void DropStats(ControlConn* ctrlcon)
 {
-    s_ctrlcon = ctrlcon;
+    set_log_conn(ctrlcon);
+
     ModuleManager::accumulate_dump_stats();
     LogLabel("Packet Statistics");
     ModuleManager::get_module("daq")->show_stats();
@@ -278,7 +198,7 @@ void DropStats(ControlConn* ctrlcon)
     ModuleManager::get_module("memory")->show_stats();
     memory::MemoryCap::print(SnortConfig::log_verbose());
 
-    s_ctrlcon = nullptr;
+    set_log_conn(nullptr);
 }
 
 //-------------------------------------------------------------------------
@@ -351,7 +271,7 @@ void show_stats(
 
 void show_stats(
     PegCount* pegs, const PegInfo* info,
-    const IndexVec& peg_idxs, const char* module_name, FILE* fh)
+    const std::vector<unsigned>& peg_idxs, const char* module_name, FILE* fh)
 {
     bool head = false;
 
index 1599588cc0f1ea5c44b19519d1b1417a2b0f9de0..b36e2ac40e42ec4442df3d5379893cfcdbcab715 100644 (file)
 // Provides facilities for displaying Snort exit stats
 
 #include <daq_common.h>
+#include <cstdio>
 #include <vector>
 
 #include "framework/counts.h"
 #include "main/snort_types.h"
-#include "main/thread.h"
-
-using IndexVec = std::vector<unsigned>;
 
 class ControlConn;
 
@@ -60,9 +58,6 @@ struct PacketCount
     PegCount offload_fallback;
     PegCount offload_failures;
     PegCount offload_suspends;
-    PegCount pcre_match_limit;
-    PegCount pcre_recursion_limit;
-    PegCount pcre_error;
     PegCount cont_creations;
     PegCount cont_recalls;
     PegCount cont_flows;
@@ -97,29 +92,18 @@ extern const PegInfo proc_names[];
 
 namespace snort
 {
-extern SO_PUBLIC THREAD_LOCAL PacketCount pc;
-
-SO_PUBLIC inline PegCount get_packet_number() { return pc.analyzed_pkts; }
-
-SO_PUBLIC void LogLabel(const char*, FILE* = stdout);
-SO_PUBLIC void LogText(const char*, FILE* = stdout);
-SO_PUBLIC void LogValue(const char*, const char*, FILE* = stdout);
-SO_PUBLIC void LogCount(const char*, uint64_t, FILE* = stdout);
-
-SO_PUBLIC void LogStat(const char*, uint64_t n, uint64_t tot, FILE* = stdout);
-SO_PUBLIC void LogStat(const char*, double, FILE* = stdout);
+extern THREAD_LOCAL PacketCount pc;
 }
 
 void sum_stats(PegCount* sums, PegCount* counts, unsigned n, bool dump_stats = false);
 void show_stats(PegCount*, const PegInfo*, const char* module_name = nullptr);
 void show_stats(PegCount*, const PegInfo*, unsigned n, const char* module_name = nullptr);
-void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char* module_name, FILE*);
+void show_stats(PegCount*, const PegInfo*, const std::vector<unsigned>&, const char* module_name, FILE*);
 void show_percent_stats(PegCount*, const char*[], unsigned n, const char* module_name = nullptr);
 
 void sum_stats(SimpleStats* sums, SimpleStats* counts);
 void show_stats(SimpleStats*, const char* module_name);
 
-double CalcPct(uint64_t, uint64_t);
 void DropStats(ControlConn* ctrlcon = nullptr);
 void PrintStatistics();
 void TimeStart();
diff --git a/src/utils/test/CMakeLists.txt b/src/utils/test/CMakeLists.txt
deleted file mode 100644 (file)
index 1c6a91c..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-add_cpputest( boyer_moore_test
-    SOURCES
-        ../boyer_moore.cc
-)
-
-add_cpputest( memcap_allocator_test )
-
-add_catch_test( streambuf_test
-    SOURCES
-        ../streambuf.cc
-)
-
-add_catch_test( grouped_list_test
-    SOURCES
-        ../grouped_list.h
-)
index 7b8610def6dac67f2841e187c709e5528bdece8f..80561ad524665f039c426ab045ba0e9b06be826f 100644 (file)
 
 #include "util.h"
 
-#include <fcntl.h>
-#include <grp.h>
-#include <luajit.h>
-#include <netdb.h>
-#include <openssl/crypto.h>
-#include <pcap.h>
-#include <pcre.h>
-#include <pwd.h>
-#include <sys/file.h>
-#include <sys/resource.h>
 #include <sys/stat.h>
-#include <zlib.h>
-
-#ifdef HAVE_HYPERSCAN
-#include <hs_compile.h>
-#endif
-
-#ifdef HAVE_LZMA
-#include <lzma.h>
-#endif
-
-#ifdef HAVE_LIBML
-#include <libml.h>
-#endif
-
-extern "C" {
-#include <daq.h>
-}
 
 #include <chrono>
-#include <fstream>
 #include <random>
 
 #include "log/messages.h"
 #include "main/snort_config.h"
-#include "packet_io/sfdaq.h"
-#include "protocols/packet.h"   // For NUM_IP_PROTOS
 
 #include "util_cstring.h"
 
@@ -82,408 +52,6 @@ extern "C" {
 
 using namespace snort;
 
-/****************************************************************************
- * Store interesting data in memory that would not otherwise be visible
- * in a CORE(5) file
- ***************************************************************************/
-#ifdef BUILD
-    #define SNORT_VERSION_STRING ("### Snort Version " VERSION " Build " BUILD "\n")
-#else
-    #define SNORT_VERSION_STRING ("### Snort Version " VERSION "\n")
-#endif
-#define SNORT_VERSION_STRLEN sizeof(SNORT_VERSION_STRING)
-char __snort_version_string[SNORT_VERSION_STRLEN];
-
-void StoreSnortInfoStrings()
-{
-    strncpy(__snort_version_string, SNORT_VERSION_STRING,
-        sizeof(__snort_version_string));
-}
-
-#undef SNORT_VERSION_STRING
-#undef SNORT_VERSION_STRLEN
-
-int DisplayBanner()
-{
-    const char* ljv = LUAJIT_VERSION;
-    while ( *ljv && !isdigit(*ljv) )
-        ++ljv;
-
-    LogMessage("\n");
-    LogMessage("   ,,_     -*> Snort++ <*-\n");
-#ifdef BUILD
-    LogMessage("  o\"  )~   Version %s (Build %s)\n", VERSION, BUILD);
-#else
-    LogMessage("  o\"  )~   Version %s\n", VERSION);
-#endif
-    LogMessage("   ''''    By Martin Roesch & The Snort Team\n");
-    LogMessage("           http://snort.org/contact#team\n");
-    LogMessage("           Copyright (C) 2014-2024 Cisco and/or its affiliates."
-                           " All rights reserved.\n");
-    LogMessage("           Copyright (C) 1998-2013 Sourcefire, Inc., et al.\n");
-    LogMessage("           Using DAQ version %s\n", daq_version_string());
-    LogMessage("           Using LuaJIT version %s\n", ljv);
-    LogMessage("           Using %s\n", OpenSSL_version(SSLEAY_VERSION));
-    LogMessage("           Using %s\n", pcap_lib_version());
-    LogMessage("           Using PCRE version %s\n", pcre_version());
-    LogMessage("           Using ZLIB version %s\n", zlib_version);
-#ifdef HAVE_HYPERSCAN
-    LogMessage("           Using Hyperscan version %s\n", hs_version());
-#endif
-#ifdef HAVE_LZMA
-    LogMessage("           Using LZMA version %s\n", lzma_version_string());
-#endif
-#ifdef HAVE_LIBML
-    LogMessage("           Using LibML version %s\n", libml_version());
-#endif
-    LogMessage("\n");
-
-    return 0;
-}
-
-// get offset seconds from GMT
-int gmt2local(time_t t)
-{
-    if (t == 0)
-        t = time(nullptr);
-
-    struct tm gmt;
-    struct tm* lt = gmtime_r(&t, &gmt);
-    if (lt == nullptr)
-        return 0;
-
-    struct tm loc;
-    localtime_r(&t, &loc);
-
-    int dt = (loc.tm_hour - gmt.tm_hour) * 60 * 60 +
-        (loc.tm_min - gmt.tm_min) * 60;
-
-    int dir = loc.tm_year - gmt.tm_year;
-
-    if (dir == 0)
-        dir = loc.tm_yday - gmt.tm_yday;
-
-    dt += dir * 24 * 60 * 60;
-
-    return(dt);
-}
-
-static FILE* pid_lockfile = nullptr;
-static FILE* pid_file = nullptr;
-
-void CreatePidFile(pid_t pid)
-{
-    SnortConfig* sc = SnortConfig::get_main_conf();
-
-    sc->pid_filename = sc->log_dir;
-    sc->pid_filename += "/snort.pid";
-
-    std::string pid_lockfilename;
-
-    if ( !sc->no_lock_pid_file() )
-    {
-        pid_lockfilename = sc->pid_filename;
-        pid_lockfilename += ".lck";
-
-        /* First, lock the PID file */
-        pid_lockfile = fopen(pid_lockfilename.c_str(), "w");
-
-        if ( pid_lockfile )
-        {
-            struct flock lock;
-            int lock_fd = fileno(pid_lockfile);
-
-            lock.l_type = F_WRLCK;
-            lock.l_whence = SEEK_SET;
-            lock.l_start = 0;
-            lock.l_len = 0;
-
-            if (fcntl(lock_fd, F_SETLK, &lock) == -1)
-            {
-                ClosePidFile();
-                ParseError("Failed to Lock PID File \"%s\" for PID \"%d\"",
-                    sc->pid_filename.c_str(), (int)pid);
-                return;
-            }
-        }
-    }
-
-    /* Okay, were able to lock PID file, now open and write PID */
-    pid_file = fopen(sc->pid_filename.c_str(), "w");
-    if (pid_file)
-    {
-        LogMessage("Writing PID \"%d\" to file \"%s\"\n", (int)pid,
-            sc->pid_filename.c_str());
-        fprintf(pid_file, "%d\n", (int)pid);
-        fflush(pid_file);
-    }
-    else
-    {
-        if (pid_lockfile)
-        {
-            fclose(pid_lockfile);
-            pid_lockfile = nullptr;
-        }
-        const char* error = get_error(errno);
-        ErrorMessage("Failed to create pid file %s, Error: %s\n",
-            sc->pid_filename.c_str(), error);
-        sc->pid_filename.clear();
-    }
-    if ( !pid_lockfilename.empty() )
-        unlink(pid_lockfilename.c_str());
-}
-
-void ClosePidFile()
-{
-    if (pid_file)
-    {
-        fclose(pid_file);
-        pid_file = nullptr;
-    }
-    if (pid_lockfile)
-    {
-        fclose(pid_lockfile);
-        pid_lockfile = nullptr;
-    }
-}
-
-// set safe UserID and GroupID, if needed
-bool SetUidGid(int user_id, int group_id)
-{
-    // Were any changes requested?
-    if (group_id == -1 && user_id == -1)
-        return true;
-
-    if (group_id != -1)
-    {
-        if (setgid(group_id) < 0)
-        {
-            ParseError("Cannot set GID: %d", group_id);
-            return false;
-        }
-        LogMessage("Set GID to %d\n", group_id);
-    }
-
-    if (user_id != -1)
-    {
-        if (setuid(user_id) < 0)
-        {
-            ParseError("Cannot set UID: %d", user_id);
-            return false;
-        }
-        LogMessage("Set UID to %d\n", user_id);
-    }
-
-    return true;
-}
-
-// set the groups of the process based on the UserID with the GroupID added
-void InitGroups(int user_id, int group_id)
-{
-    if ((user_id != -1) && (getuid() == 0))
-    {
-        struct passwd* pw = getpwuid(user_id);  // main thread only
-
-        if (pw != nullptr)
-        {
-            /* getpwuid and initgroups may use the same static buffers */
-            char* username = snort_strdup(pw->pw_name);
-
-            if (initgroups(username, group_id) < 0)
-                ParseError("Can not initgroups(%s,%d)", username, group_id);
-
-            snort_free(username);
-        }
-
-        /** Just to be on the safe side... **/
-        endgrent();
-        endpwent();
-    }
-}
-
-//-------------------------------------------------------------------------
-
-// FIXIT-L this is a duplicate of PacketManager::get_proto_name()
-void InitProtoNames()
-{
-    if ( !protocol_names )
-        protocol_names = (char**)snort_calloc(NUM_IP_PROTOS, sizeof(char*));
-
-    for ( int i = 0; i < NUM_IP_PROTOS; i++ )
-    {
-        struct protoent* pt = getprotobynumber(i);  // main thread only
-
-        if (pt != nullptr)
-        {
-            protocol_names[i] = snort_strdup(pt->p_name);
-
-            for ( size_t j = 0; j < strlen(protocol_names[i]); j++ )
-                protocol_names[i][j] = toupper(protocol_names[i][j]);
-        }
-        else
-        {
-            char protoname[10];
-            SnortSnprintf(protoname, sizeof(protoname), "PROTO:%03d", i);
-            protocol_names[i] = snort_strdup(protoname);
-        }
-    }
-}
-
-void CleanupProtoNames()
-{
-    if (protocol_names != nullptr)
-    {
-        int i;
-
-        for (i = 0; i < NUM_IP_PROTOS; i++)
-        {
-            if (protocol_names[i] != nullptr)
-                snort_free(protocol_names[i]);
-        }
-
-        snort_free(protocol_names);
-        protocol_names = nullptr;
-    }
-}
-
-// read the BPF filters in from a file, return the processed BPF string
-std::string read_infile(const char* key, const char* fname)
-{
-    int fd = open(fname, O_RDONLY);
-    struct stat buf;
-
-    if (fd < 0)
-    {
-        ErrorMessage("Failed to open file: %s with error: %s", fname, get_error(errno));
-        return "";
-    }
-
-    if (fstat(fd, &buf) < 0)
-    {
-        ParseError("can't stat %s: %s", fname, get_error(errno));
-        close(fd);
-        return "";
-    }
-
-    //check that its a regular file and not a directory or special file
-    if (!S_ISREG(buf.st_mode) )
-    {
-        ParseError("not a regular file: %s", fname);
-        close(fd);
-        return "";
-    }
-
-    std::string line;
-    std::ifstream bpf_file(fname);
-
-    if (bpf_file.is_open())
-    {
-        std::stringstream file_content;
-        file_content << bpf_file.rdbuf();
-        line = file_content.str();
-
-        bpf_file.close();
-    }
-    else
-    {
-        ParseError("can't open file %s = %s: %s", key, fname, get_error(errno));
-        close(fd);
-        return "";
-    }
-    close(fd);
-    return line;
-}
-
-typedef char PathBuf[PATH_MAX+1];
-
-static const char* CurrentWorkingDir(PathBuf& buf)
-{
-    if ( !getcwd(buf, sizeof(buf)-1) )
-        return nullptr;
-
-    buf[sizeof(buf)-1] = '\0';
-    return buf;
-}
-
-static char* GetAbsolutePath(const char* dir, PathBuf& buf)
-{
-    assert(dir);
-    errno = 0;
-
-    if ( !realpath(dir, buf) )
-    {
-        LogMessage("Couldn't determine absolute path for '%s': %s\n", dir, get_error(errno));
-        return nullptr;
-    }
-
-    return buf;
-}
-
-// Chroot and adjust the log_dir reference
-bool EnterChroot(std::string& root_dir, std::string& log_dir)
-{
-    if (log_dir.empty())
-    {
-        ParseError("Log directory not specified");
-        return false;
-    }
-    PathBuf pwd;
-    PathBuf abs_log_dir;
-
-    if ( !GetAbsolutePath(log_dir.c_str(), abs_log_dir) )
-        return false;
-
-    /* change to the desired root directory */
-    if (chdir(root_dir.c_str()) != 0)
-    {
-        ParseError("EnterChroot: Can not chdir to \"%s\": %s", root_dir.c_str(),
-            get_error(errno));
-        return false;
-    }
-
-    /* always returns an absolute pathname */
-    const char* abs_root_dir = CurrentWorkingDir(pwd);
-    if (!abs_root_dir)
-    {
-        ParseError("Couldn't retrieve current working directory");
-        return false;
-    }
-    size_t abs_root_dir_len = strlen(abs_root_dir);
-
-    if (strncmp(abs_root_dir, abs_log_dir, abs_root_dir_len))
-    {
-        ParseError("Specified log directory is not contained with the chroot jail");
-        return false;
-    }
-
-    if (chroot(abs_root_dir) < 0)
-    {
-        ParseError("Can not chroot to \"%s\": absolute: %s: %s",
-            root_dir.c_str(), abs_root_dir, get_error(errno));
-        return false;
-    }
-
-
-    /* Immediately change to the root directory of the jail. */
-    if (chdir("/") < 0)
-    {
-        ParseError("Can not chdir to \"/\" after chroot: %s",
-            get_error(errno));
-        return false;
-    }
-
-
-    if (abs_root_dir_len >= strlen(abs_log_dir))
-        log_dir = "/";
-    else
-        log_dir = abs_log_dir + abs_root_dir_len;
-
-
-    LogMessage("Chroot directory = %s\n", root_dir.c_str());
-
-    return true;
-}
-
 unsigned int get_random_seed()
 {
     unsigned int seed;
@@ -527,8 +95,6 @@ void SetNoCores()
 
 namespace snort
 {
-char** protocol_names = nullptr;
-
 const char* get_error(int errnum)
 {
     static THREAD_LOCAL char buf[128];
@@ -882,11 +448,6 @@ bool rotate_file_for_max_size(const char* file_owner, const char* old_file,
 }
 
 #ifdef UNIT_TEST
-TEST_CASE("gmt2local_time_out_of_range", "[util]")
-{
-    REQUIRE((gmt2local(0xffffffff1fff2f)==0));
-}
-
 TEST_CASE("uint8_to_printable_str go over all options", "[util]")
 {
     std::string print_str;
@@ -910,5 +471,5 @@ TEST_CASE("uint8_to_printable_str end with |", "[util]")
     uint8_to_printable_str(pattern, 2, print_str);
     CHECK((strcmp(print_str.c_str(),"a|00 |") == 0));
 }
-
 #endif
+
index 4926790be0636a906183b8b491526d2426270ef6..c6916d6c01a0c7e10086ac2c3be47321e6984df5 100644 (file)
 #define SECONDS_PER_HOUR  3600  /* number of seconds in a hour */
 #define SECONDS_PER_MIN     60     /* number of seconds in a minute */
 
-void StoreSnortInfoStrings();
-int DisplayBanner();
-int gmt2local(time_t);
-std::string read_infile(const char* key, const char* fname);
-void CleanupProtoNames();
-void CreatePidFile(pid_t);
-void ClosePidFile();
-bool SetUidGid(int, int);
-void InitGroups(int, int);
-bool EnterChroot(std::string& root_dir, std::string& log_dir);
-void InitProtoNames();
 unsigned int get_random_seed();
 bool get_file_size(const std::string&, size_t&);
 
-#if defined(NOCOREFILE)
-void SetNoCores();
-#endif
-
 namespace
 {
 inline void COPY4(uint32_t* dst, const uint32_t* src)
@@ -123,9 +108,6 @@ inline pid_t gettid()
 
 namespace snort
 {
-// FIXIT-M provide getter function to for standardized access into the protocol_names array
-SO_PUBLIC extern char** protocol_names;
-
 SO_PUBLIC const char* get_error(int errnum);
 SO_PUBLIC char* snort_strdup(const char*);
 SO_PUBLIC char* snort_strndup(const char*, size_t);
index e2a87d6aedd6940baa4359aa6e27cc6be9aa4e93..fc1dd46508c46632d38c30f7c7732d08e7155ded 100644 (file)
@@ -22,6 +22,7 @@
 #define UTIL_CSTRING_H
 
 // Utility functions and macros for interacting with and parsing C strings
+// these functions are deprecated; use C++ strings instead
 
 #include <cctype>
 #include <cerrno>
@@ -42,7 +43,6 @@ namespace snort
 
 SO_PUBLIC int safe_snprintf(char*, size_t, const char*, ... )
     __attribute__((format (printf, 3, 4)));
-// these functions are deprecated; use C++ strings instead
 SO_PUBLIC int SnortSnprintf(char*, size_t, const char*, ...)
     __attribute__((format (printf, 3, 4)));
 SO_PUBLIC int SnortSnprintfAppend(char*, size_t, const char*, ...)
index e33623619563c24bd32d74b330bda6a9d23e7f4f..5ddc16637bbfdd1ceb0c564e7918caa97a672f6e 100644 (file)
 
 #include "util_jsnorm.h"
 
+#include <ctype.h>
+
 #include <cstdlib>
 #include <cstring>
 #include <vector>
 
-#include "main/thread.h"
-
-namespace snort
-{
 #define INVALID_HEX_VAL (-1)
 #define MAX_BUF 8
 #define NON_ASCII_CHAR 0xff
@@ -51,6 +49,8 @@ namespace snort
 
 #define ANY '\0'
 
+namespace
+{
 enum ActionPNorm
 {
     PNORM_ACT_DQUOTES,
@@ -102,6 +102,70 @@ enum ActionJSNorm
     ACT_UNESCAPE
 };
 
+struct JSNorm
+{
+    uint8_t state;  // cppcheck-suppress unusedStructMember
+    uint8_t event;
+    uint8_t match;
+    uint8_t other;
+    uint8_t action;
+};
+
+struct Dbuf
+{
+    char* data;
+    uint16_t size;
+    uint16_t len;
+};
+
+struct PNormState
+{
+    uint8_t fsm;
+    uint8_t fsm_other;
+    uint8_t prev_event;
+    uint8_t d_quotes;
+    uint8_t s_quotes;
+    uint16_t num_spaces;
+    char* overwrite;
+    Dbuf output;
+};
+
+struct SFCCState
+{
+    uint8_t fsm;
+    uint8_t buf[MAX_BUF];
+    uint8_t buflen;
+    uint16_t cur_flags;
+    uint16_t alert_flags;
+    Dbuf output;
+};
+
+struct JSNormState
+{
+    uint8_t fsm;
+    uint8_t prev_event;
+    uint16_t num_spaces;
+    uint8_t* unicode_map;
+    char* overwrite;
+    Dbuf dest;
+};
+
+struct UnescapeState
+{
+    uint8_t fsm;
+    uint8_t multiple_levels;
+    uint8_t prev_event;
+    uint16_t alert_flags;
+    uint16_t num_spaces;
+    int iNorm;
+    int paren_count;
+    uint8_t* unicode_map;
+    char* overwrite;
+    ActionUnsc prev_action;
+    Dbuf output;
+};
+}  // anonymous
+
 static const int hex_lookup[256] =
 {
     INVALID_HEX_VAL, INVALID_HEX_VAL, INVALID_HEX_VAL, INVALID_HEX_VAL, INVALID_HEX_VAL, INVALID_HEX_VAL, INVALID_HEX_VAL, INVALID_HEX_VAL,
@@ -170,69 +234,6 @@ static const int valid_chars[256] =
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
-struct JSNorm
-{
-    uint8_t state;  // cppcheck-suppress unusedStructMember
-    uint8_t event;
-    uint8_t match;
-    uint8_t other;
-    uint8_t action;
-};
-
-struct Dbuf
-{
-    char* data;
-    uint16_t size;
-    uint16_t len;
-};
-
-struct PNormState
-{
-    uint8_t fsm;
-    uint8_t fsm_other;
-    uint8_t prev_event;
-    uint8_t d_quotes;
-    uint8_t s_quotes;
-    uint16_t num_spaces;
-    char* overwrite;
-    Dbuf output;
-};
-
-struct SFCCState
-{
-    uint8_t fsm;
-    uint8_t buf[MAX_BUF];
-    uint8_t buflen;
-    uint16_t cur_flags;
-    uint16_t alert_flags;
-    Dbuf output;
-};
-
-struct JSNormState
-{
-    uint8_t fsm;
-    uint8_t prev_event;
-    uint16_t num_spaces;
-    uint8_t* unicode_map;
-    char* overwrite;
-    Dbuf dest;
-};
-
-struct UnescapeState
-{
-    uint8_t fsm;
-    uint8_t multiple_levels;
-    uint8_t prev_event;
-    uint16_t alert_flags;
-    uint16_t num_spaces;
-    int iNorm;
-    int paren_count;
-    uint8_t* unicode_map;
-    char* overwrite;
-    ActionUnsc prev_action;
-    Dbuf output;
-};
-
 // STATES for SFCC
 #define S0  0
 #define S1 (S0+3)
@@ -441,6 +442,8 @@ static const JSNorm javascript_norm[] =
     { Z6+ 0, ANY, Z0+ 0, Z0+ 0, ACT_NOP }
 };
 
+using snort::JSState;
+
 static void UnescapeDecode(const char* src, uint16_t srclen, const char** ptr, char** dst, size_t dst_len,
     uint16_t* bytes_copied, JSState* js, uint8_t* iis_unicode_map);
 
@@ -1228,6 +1231,8 @@ static int JSNorm_scan_fsm(JSNormState* s, int c, const char* src, uint16_t srcl
     return(JSNorm_exec(s, (ActionJSNorm)m->action, c, src, srclen, ptr, js));
 }
 
+namespace snort
+{
 int JSNormalizeDecode(const char* src, uint16_t srclen, char* dst, uint16_t destlen, const char** ptr,
     int* bytes_copied, JSState* js, uint8_t* iis_unicode_map)
 {
@@ -1273,4 +1278,3 @@ int JSNormalizeDecode(const char* src, uint16_t srclen, char* dst, uint16_t dest
 }
 }
 
-