]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4551: Api Tweaks
authorRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 6 Jan 2025 17:11:35 +0000 (17:11 +0000)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 6 Jan 2025 17:11:35 +0000 (17:11 +0000)
Merge in SNORT/snort3 from ~RUCOMBS/snort3:api_tweaks to master

Squashed commit of the following:

commit 50b83b5e26510b702a5c896fe02198a09f024f53
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Dec 16 11:24:58 2024 -0500

    tcp_pdu: rename to tlv_pdu

commit 325cbe349a3c4065244d82d391bad748d40e6d6f
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Dec 16 11:13:33 2024 -0500

    data_bus: remove unsubscribe methods

commit f37fc721d0417d20ef6679ad7871c8b06b187bf2
Author: Russ Combs <rucombs@cisco.com>
Date:   Mon Dec 16 11:13:06 2024 -0500

    ips: add access to Event references

21 files changed:
src/detection/signature.cc
src/detection/signature.h
src/events/event.cc
src/events/event.h
src/framework/base_api.h
src/framework/data_bus.cc
src/framework/data_bus.h
src/framework/ips_option.h
src/framework/logger.h
src/framework/test/data_bus_test.cc
src/log/log_text.cc
src/service_inspectors/CMakeLists.txt
src/service_inspectors/service_inspectors.cc
src/service_inspectors/tcp_pdu/CMakeLists.txt [deleted file]
src/service_inspectors/tlv_pdu/CMakeLists.txt [new file with mode: 0644]
src/service_inspectors/tlv_pdu/dev_notes.txt [moved from src/service_inspectors/tcp_pdu/dev_notes.txt with 52% similarity]
src/service_inspectors/tlv_pdu/test/CMakeLists.txt [moved from src/service_inspectors/tcp_pdu/test/CMakeLists.txt with 50% similarity]
src/service_inspectors/tlv_pdu/test/tlv_pdu_test.cc [moved from src/service_inspectors/tcp_pdu/test/tcp_pdu_test.cc with 92% similarity]
src/service_inspectors/tlv_pdu/tlv_pdu.cc [moved from src/service_inspectors/tcp_pdu/tcp_pdu.cc with 87% similarity]
src/service_inspectors/tlv_pdu/tlv_pdu.h [moved from src/service_inspectors/tcp_pdu/tcp_pdu.h with 89% similarity]
src/service_inspectors/tlv_pdu/tlv_pdu_splitter.cc [moved from src/service_inspectors/tcp_pdu/tcp_pdu_splitter.cc with 93% similarity]

index 025d007be471e098f0b899ff756d292ded8d3cfe..52684d67c271193fb547192a742007fe6bb8e165 100644 (file)
@@ -54,9 +54,6 @@ using namespace snort;
 const ReferenceSystem* reference_system_add(
     SnortConfig* sc, const std::string& name, const char* url)
 {
-    if ( !sc->alert_refs() )
-        return nullptr;
-
     assert(!name.empty());
 
     ReferenceSystem* sys = new ReferenceSystem(name, url);
@@ -65,7 +62,7 @@ const ReferenceSystem* reference_system_add(
     return sys;
 }
 
-static const ReferenceSystem* reference_system_lookup(SnortConfig* sc, const std::string& key)
+const ReferenceSystem* reference_system_lookup(const SnortConfig* sc, const std::string& key)
 {
     const auto it = sc->references.find(key);
 
index 919e8e7becb8b8d9d513e3020ba7088c916b6d7c..d65948fbd7c704873642b55672a069e8356ee09d 100644 (file)
@@ -48,6 +48,8 @@ struct ReferenceSystem
 
 const ReferenceSystem* reference_system_add(snort::SnortConfig*, const std::string&, const char* = "");
 
+const ReferenceSystem* reference_system_lookup(const snort::SnortConfig*, const std::string& key);
+
 struct ReferenceNode
 {
     ReferenceNode(const ReferenceSystem* sys, const std::string& id) : system(sys), id(id) { }
index 30c4d08602548a55b751a3935a5baa5629b4a9b9..18b435375a10735d6b88c9b8a968d272a65edb72 100644 (file)
@@ -153,6 +153,17 @@ bool Event::get_target(bool& src) const
     return false;
 }
 
-const SigInfo& Event::get_sig_info() const
-{ return sig_info; }
+bool Event::get_reference(unsigned idx, const char*& name, const char*& id, const char*& url) const
+{
+    if ( idx >= sig_info.refs.size() )
+        return false;
+
+    name = sig_info.refs[idx]->system->name.c_str();
+    id = sig_info.refs[idx]->id.c_str();
+
+    auto* ref = reference_system_lookup(SnortConfig::get_conf(), sig_info.refs[idx]->system->name);
+    url = (ref ? ref->url.c_str() : nullptr);
+
+    return true;
+}
 
index 2bf8a58557116409340d4103a6d54d8351b85cf0..faddf297cf971a26eb74905f833b2051417f229c 100644 (file)
@@ -34,8 +34,6 @@ public:
     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;
 
@@ -57,6 +55,9 @@ public:
     uint32_t get_class_id() const;
     uint32_t get_priority() const;
 
+    // start at idx 0 and increment while true to get all refs
+    bool get_reference(unsigned idx, const char*& name, const char*& id, const char*& url) const;
+
     // returns false if not specified; otherwise src indicates target is source or dest
     bool get_target(bool& src) const;
 
index 09be4cb201cf7dde911eac319df888bce1d9516d..581e982449fa85a5263c32e092a6c4583c90bc81 100644 (file)
@@ -38,7 +38,7 @@
 // depends on includes installed in framework/snort_api.h
 // see framework/plugins.h
 
-#define BASE_API_VERSION 20
+#define BASE_API_VERSION 21
 
 // set the reserved field to this to be future proof
 #define API_RESERVED 0
index ab91596173c051a00e3d46adb89eb057c9c740ae..02132fec7ac6de3462a0070617ffa3ddf9df781f 100644 (file)
@@ -145,21 +145,6 @@ void DataBus::subscribe_global(const PubKey& key, unsigned eid, DataHandler* h,
     sc.global_dbus->_subscribe(key, eid, h);
 }
 
-void DataBus::unsubscribe(const PubKey& key, unsigned eid, DataHandler* h)
-{
-    get_data_bus()._unsubscribe(key, eid, h);
-}
-
-void DataBus::unsubscribe_network(const PubKey& key, unsigned eid, DataHandler* h)
-{
-    get_network_data_bus()._unsubscribe(key, eid, h);
-}
-
-void DataBus::unsubscribe_global(const PubKey& key, unsigned eid, DataHandler* h, SnortConfig& sc)
-{
-    sc.global_dbus->_unsubscribe(key, eid, h);
-}
-
 // notify subscribers of event
 void DataBus::publish(unsigned pid, unsigned eid, DataEvent& e, Flow* f)
 {
@@ -246,24 +231,6 @@ void DataBus::_subscribe(const PubKey& key, unsigned eid, DataHandler* h)
     _subscribe(pid, eid, h);
 }
 
-void DataBus::_unsubscribe(const PubKey& key, unsigned eid, const DataHandler* h)
-{
-    unsigned pid = get_id(key);
-    unsigned idx = pid + eid;
-    assert(idx < pub_sub.size());
-
-    SubList& subs = pub_sub[idx];
-
-    for ( unsigned i = 0; i < subs.size(); i++ )
-    {
-        if ( subs[i] == h )
-        {
-            subs.erase(subs.begin() + i--);
-            break;
-        }
-    }
-}
-
 void DataBus::_publish(unsigned pid, unsigned eid, DataEvent& e, Flow* f) const
 {
     unsigned idx = pid + eid;
index 6f27e4a65fff3f92c39f6bb0b138959fa185903d..f46bdf853675bd7054423aa68e62e054a0befa39 100644 (file)
@@ -113,11 +113,6 @@ public:
     static void subscribe_network(const PubKey&, unsigned id, DataHandler*);
     static void subscribe_global(const PubKey&, unsigned id, DataHandler*, SnortConfig&);
 
-    // FIXIT-L these should be called during cleanup
-    static void unsubscribe(const PubKey&, unsigned id, DataHandler*);
-    static void unsubscribe_network(const PubKey&, unsigned id, DataHandler*);
-    static void unsubscribe_global(const PubKey&, unsigned id, DataHandler*, SnortConfig&);
-
     // runtime methods
     static void publish(unsigned pub_id, unsigned evt_id, DataEvent&, Flow* = nullptr);
 
@@ -129,7 +124,6 @@ public:
 private:
     void _subscribe(unsigned pub_id, unsigned evt_id, DataHandler*);
     void _subscribe(const PubKey&, unsigned evt_id, DataHandler*);
-    void _unsubscribe(const PubKey&, unsigned evt_id, const DataHandler*);
     void _publish(unsigned pub_id, unsigned evt_id, DataEvent&, Flow*) const;
 
 private:
index a693a6352baf4adc314ef9b09baf4d313375558b..1a3dc445cd023c712f7a30a8380ad3ce1fa2f1f8 100644 (file)
@@ -119,7 +119,6 @@ public:
 
     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);
index 233c032a0e64a49e32078b88c4fe1666c41aa01c..ffd9fcf50cd852a33cc71368d0365a8286a27af1 100644 (file)
 // the LOGAPI_VERSION will change if anything in this file changes.
 // see also framework/base_api.h.
 
+#include "events/event.h"
 #include "framework/base_api.h"
 #include "main/snort_types.h"
 
-class Event;
-
 namespace snort
 {
 struct Packet;
 
 // this is the current version of the api
-#define LOGAPI_VERSION ((BASE_API_VERSION << 16) | 1)
+#define LOGAPI_VERSION ((BASE_API_VERSION << 16) | 2)
 
 #define OUTPUT_TYPE_FLAG__NONE  0x0
 #define OUTPUT_TYPE_FLAG__ALERT 0x1
index b372e543d93da288e2c5b2b66bd4c795d33983a5..4bb7f9734de25e630ccb9ffa12426f3f917df5bb 100644 (file)
@@ -142,22 +142,16 @@ TEST_GROUP(data_bus)
 
 TEST(data_bus, subscribe_global)
 {
-    UTestHandler h;
-    DataBus::subscribe_global(pub_key, DbUtIds::EVENT, &h, *snort_conf);
+    UTestHandler* h = new UTestHandler();
+    DataBus::subscribe_global(pub_key, DbUtIds::EVENT, h, *snort_conf);
 
     UTestEvent event(100);
     DataBus::publish(pub_id, DbUtIds::EVENT, event);
-    CHECK(100 == h.evt_msg);
+    CHECK(100 == h->evt_msg);
 
     UTestEvent event1(200);
     DataBus::publish(pub_id, DbUtIds::EVENT, event1);
-    CHECK(200 == h.evt_msg);
-
-    DataBus::unsubscribe_global(pub_key, DbUtIds::EVENT, &h, *snort_conf);
-
-    UTestEvent event2(300);
-    DataBus::publish(pub_id, DbUtIds::EVENT, event2);
-    CHECK(200 == h.evt_msg); // unsubscribed!
+    CHECK(200 == h->evt_msg);
 }
 
 TEST(data_bus, subscribe_network)
@@ -172,14 +166,6 @@ TEST(data_bus, subscribe_network)
     UTestEvent event1(200);
     DataBus::publish(pub_id, DbUtIds::EVENT, event1);
     CHECK(200 == h->evt_msg);
-
-    DataBus::unsubscribe_network(pub_key, DbUtIds::EVENT, h);
-
-    UTestEvent event2(300);
-    DataBus::publish(pub_id, DbUtIds::EVENT, event2);
-    CHECK(200 == h->evt_msg); // unsubscribed!
-
-    delete h;
 }
 
 TEST(data_bus, subscribe)
@@ -194,14 +180,6 @@ TEST(data_bus, subscribe)
     UTestEvent event1(200);
     DataBus::publish(pub_id, DbUtIds::EVENT, event1);
     CHECK(200 == h->evt_msg);
-
-    DataBus::unsubscribe(pub_key, DbUtIds::EVENT, h);
-
-    UTestEvent event2(300);
-    DataBus::publish(pub_id, DbUtIds::EVENT, event2);
-    CHECK(200 == h->evt_msg); // unsubscribed!
-
-    delete h;
 }
 
 TEST(data_bus, order1)
@@ -222,14 +200,6 @@ TEST(data_bus, order1)
     CHECK(1 == h1->seq);
     CHECK(2 == h9->seq);
     CHECK(3 == h0->seq);
-
-    DataBus::unsubscribe(pub_key, DbUtIds::EVENT, h0);
-    DataBus::unsubscribe(pub_key, DbUtIds::EVENT, h1);
-    DataBus::unsubscribe(pub_key, DbUtIds::EVENT, h9);
-
-    delete h0;
-    delete h1;
-    delete h9;
 }
 
 TEST(data_bus, order2)
@@ -250,14 +220,6 @@ TEST(data_bus, order2)
     CHECK(1 == h1->seq);
     CHECK(2 == h9->seq);
     CHECK(3 == h0->seq);
-
-    DataBus::unsubscribe(pub_key, DbUtIds::EVENT, h0);
-    DataBus::unsubscribe(pub_key, DbUtIds::EVENT, h1);
-    DataBus::unsubscribe(pub_key, DbUtIds::EVENT, h9);
-
-    delete h0;
-    delete h1;
-    delete h9;
 }
 
 //-------------------------------------------------------------------------
index faf09fbdd820f7cd7b98a99ca3bb6f35cbbd49e7..7e48e7f718c10d56afd69d2a27fe729279080a4f 100644 (file)
@@ -1020,18 +1020,17 @@ void LogICMPHeader(TextLog* log, Packet* p)
 
 void LogXrefs(TextLog* log, const Event& e)
 {
-    const SigInfo& sig_info = e.get_sig_info();
+    unsigned idx = 0;
+    const char* name = nullptr;
+    const char* id = nullptr;
+    const char* url = nullptr;
 
-    for ( const auto ref : sig_info.refs )
+    while ( e.get_reference(idx++, name, id, url) )
     {
-        if ( !ref->system )
-            TextLog_Print(log, "[Xref => %s]", ref->id.c_str());
-
-        else if ( !ref->system->url.empty() )
-            TextLog_Print(log, "[Xref => %s%s]", ref->system->url.c_str(), ref->id.c_str());
-
+        if ( url and *url )
+            TextLog_Print(log, "[Xref => %s%s]", url, id);
         else
-            TextLog_Print(log, "[Xref => %s %s]", ref->system->name.c_str(), ref->id.c_str());
+            TextLog_Print(log, "[Xref => %s %s]", name, id);
     }
 }
 
index 55aafe03660b9d728ffe4f80e43f04e5b465efcf..bb2637545b440c45ca3a726a9b271380ca9a53d6 100644 (file)
@@ -20,7 +20,7 @@ add_subdirectory(sip)
 add_subdirectory(smtp)
 add_subdirectory(ssh)
 add_subdirectory(ssl)
-add_subdirectory(tcp_pdu)
+add_subdirectory(tlv_pdu)
 add_subdirectory(wizard)
 
 if (STATIC_INSPECTORS)
@@ -42,7 +42,7 @@ if (STATIC_INSPECTORS)
         $<TARGET_OBJECTS:smtp>
         $<TARGET_OBJECTS:ssh>
         $<TARGET_OBJECTS:ssl>
-        $<TARGET_OBJECTS:tcp_pdu>
+        $<TARGET_OBJECTS:tlv_pdu>
         $<TARGET_OBJECTS:wizard>
     )
 endif()
index d790acca3fd677bdf58ecbdf154a08f0be7a0dcc..b879b922b6ac9ab2f915accd1a1adc81c6cec2db 100644 (file)
@@ -43,7 +43,7 @@ extern const BaseApi* sin_pop;
 extern const BaseApi* sin_rpc_decode;
 extern const BaseApi* sin_smtp;
 extern const BaseApi* sin_ssh;
-extern const BaseApi* sin_tcp_pdu;
+extern const BaseApi* sin_tlv_pdu;
 extern const BaseApi* sin_telnet;
 extern const BaseApi* sin_wizard;
 
@@ -72,7 +72,7 @@ const BaseApi* service_inspectors[] =
     sin_rpc_decode,
     sin_smtp,
     sin_ssh,
-    sin_tcp_pdu,
+    sin_tlv_pdu,
     sin_telnet,
     sin_wizard,
 #endif
diff --git a/src/service_inspectors/tcp_pdu/CMakeLists.txt b/src/service_inspectors/tcp_pdu/CMakeLists.txt
deleted file mode 100644 (file)
index 453b053..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-
-set( FILE_LIST
-    tcp_pdu.cc
-    tcp_pdu.h
-    tcp_pdu_splitter.cc
-)
-
-if (STATIC_INSPECTORS)
-    add_library( tcp_pdu OBJECT ${FILE_LIST})
-
-else (STATIC_INSPECTORS)
-    add_dynamic_module(tcp_pdu inspectors ${FILE_LIST})
-
-endif (STATIC_INSPECTORS)
-
-add_subdirectory(test)
-
diff --git a/src/service_inspectors/tlv_pdu/CMakeLists.txt b/src/service_inspectors/tlv_pdu/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d85f905
--- /dev/null
@@ -0,0 +1,17 @@
+
+set( FILE_LIST
+    tlv_pdu.cc
+    tlv_pdu.h
+    tlv_pdu_splitter.cc
+)
+
+if (STATIC_INSPECTORS)
+    add_library(tlv_pdu OBJECT ${FILE_LIST})
+
+else (STATIC_INSPECTORS)
+    add_dynamic_module(tlv_pdu inspectors ${FILE_LIST})
+
+endif (STATIC_INSPECTORS)
+
+add_subdirectory(test)
+
similarity index 52%
rename from src/service_inspectors/tcp_pdu/dev_notes.txt
rename to src/service_inspectors/tlv_pdu/dev_notes.txt
index c6a9a2e696ef369cbaee73f391d0d467900066fe..07d9b1cb4cf44dc1047102a65bcaccd9e62a4ebb 100644 (file)
@@ -1,5 +1,5 @@
 
-The TcpPdu splitter provides a generic TCP stream flush function to support
+The TlvPdu splitter provides a generic TCP stream flush function to support
 IPS.  This works for PDUs that contain a length field at a fixed offset that
 can be extracted and used to set a flush point.
 
@@ -23,27 +23,27 @@ Where:
 So a PDU with a 4 byte length field in the middle of a 12 byte header would be
 configured with offset = size = skip = 4.
 
-tcp_pdu is not service specific. An appropriate wizard pattern must direct the
-paylaod to a tcp_pdu instance configured for the flow.
+tlv_pdu is not service specific. An appropriate wizard pattern must direct the
+payload to a tlv_pdu instance configured for the flow.
 
 The initial implementation supports these parameters:
 
-* int tcp_pdu.offset = 0: index to first byte of length field { 0:65535 }
-* int tcp_pdu.size = 4: number of bytes in length field { 1:4 }
-* int tcp_pdu.skip = 0: bytes after length field to end of header { 0:65535 }
-* bool tcp_pdu.relative = false: extracted length follows field (instead of whole PDU)
+* int tlv_pdu.offset = 0: index to first byte of length field { 0:65535 }
+* int tlv_pdu.size = 4: number of bytes in length field { 1:4 }
+* int tlv_pdu.skip = 0: bytes after length field to end of header { 0:65535 }
+* bool tlv_pdu.relative = false: extracted length follows field (instead of whole PDU)
 
 Additional parameters that may be supported in the future if required:
 
-* int tcp_pdu.bitmask = 0xFFFFFFFF: applies as an AND to the extracted value to get length { 0x1:0xFFFFFFFF }
-* int tcp_pdu.multiplier = 1: scale extracted value by given amount after masking { 1:65535 }
+* int tlv_pdu.bitmask = 0xFFFFFFFF: applies as an AND to the extracted value to get length { 0x1:0xFFFFFFFF }
+* int tlv_pdu.multiplier = 1: scale extracted value by given amount after masking { 1:65535 }
 
 Still other possibilities:
 
-* bool tcp_pdu.big = false: big endian
-* bool tcp_pdu.little = false: little endian
-* bool tcp_pdu.string = false: convert from string
-* bool tcp_pdu.hex = false: convert from hex string
-* bool tcp_pdu.oct = false: convert from octal string
-* bool tcp_pdu.dec = false: convert from decimal string
+* bool tlv_pdu.big = false: big endian
+* bool tlv_pdu.little = false: little endian
+* bool tlv_pdu.string = false: convert from string
+* bool tlv_pdu.hex = false: convert from hex string
+* bool tlv_pdu.oct = false: convert from octal string
+* bool tlv_pdu.dec = false: convert from decimal string
 
similarity index 50%
rename from src/service_inspectors/tcp_pdu/test/CMakeLists.txt
rename to src/service_inspectors/tlv_pdu/test/CMakeLists.txt
index cea38ffd9b2e906f2720599fa9423508b1ae418e..83272ba7c9f3f6c63cd5acf605c24a91c3c5595e 100644 (file)
@@ -1,7 +1,7 @@
 
-add_cpputest( tcp_pdu_test
+add_cpputest( tlv_pdu_test
     SOURCES
-        ../tcp_pdu_splitter.cc
+        ../tlv_pdu_splitter.cc
         ../../../stream/stream_splitter.cc
 )
 
similarity index 92%
rename from src/service_inspectors/tcp_pdu/test/tcp_pdu_test.cc
rename to src/service_inspectors/tlv_pdu/test/tlv_pdu_test.cc
index 1973efc704c481915853fa5f500a8104e1f7728d..77f5497af45b7d4ec465525fd1e3ad3b37a1402a 100644 (file)
@@ -16,7 +16,7 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 
-// tcp_pdu_test.cc author Russ Combs <rucombs@cisco.com>
+// tlv_pdu_test.cc author Russ Combs <rucombs@cisco.com>
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -29,7 +29,7 @@
 #include "stream/flush_bucket.h"
 #include "stream/stream.h"
 
-#include "../tcp_pdu.h"
+#include "../tlv_pdu.h"
 
 // must appear after snort_config.h to avoid broken c++ map include
 #include <CppUTest/CommandLineTestRunner.h>
@@ -77,8 +77,8 @@ TEST_GROUP(relative_length_only)
 
     void setup() override
     {
-        TcpPduConfig c = { 4, 0, 0, true };
-        ss = new TcpPduSplitter(true, c);  // cppcheck-suppress unreadVariable
+        TlvPduConfig c = { 4, 0, 0, true };
+        ss = new TlvPduSplitter(true, c);  // cppcheck-suppress unreadVariable
     }
     void teardown() override
     { delete ss; }
@@ -158,8 +158,8 @@ TEST_GROUP(relative_offset_length)
 
     void setup() override
     {
-        TcpPduConfig c = { 4, 3, 2, true };
-        ss = new TcpPduSplitter(true, c);  // cppcheck-suppress unreadVariable
+        TlvPduConfig c = { 4, 3, 2, true };
+        ss = new TlvPduSplitter(true, c);  // cppcheck-suppress unreadVariable
     }
     void teardown() override
     { delete ss; }
@@ -261,8 +261,8 @@ TEST_GROUP(various)
 
 TEST(various, absolute2)
 {
-    TcpPduConfig c = { 2, 3, 0, false };
-    ss = new TcpPduSplitter(true, c);
+    TlvPduConfig c = { 2, 3, 0, false };
+    ss = new TlvPduSplitter(true, c);
 
     uint32_t fp = 0;
     StreamSplitter::Status result;
@@ -277,8 +277,8 @@ TEST(various, absolute2)
 
 TEST(various, absolute3)
 {
-    TcpPduConfig c = { 3, 2, 0, false };
-    ss = new TcpPduSplitter(true, c);
+    TlvPduConfig c = { 3, 2, 0, false };
+    ss = new TlvPduSplitter(true, c);
 
     uint32_t fp = 0;
     StreamSplitter::Status result;
@@ -293,8 +293,8 @@ TEST(various, absolute3)
 
 TEST(various, abort)
 {
-    TcpPduConfig c = { 1, 2, 0, false };
-    ss = new TcpPduSplitter(true, c);
+    TlvPduConfig c = { 1, 2, 0, false };
+    ss = new TlvPduSplitter(true, c);
 
     uint32_t fp = 0;
     StreamSplitter::Status result;
@@ -305,8 +305,8 @@ TEST(various, abort)
 
 TEST(various, header_only)
 {
-    TcpPduConfig c = { 1, 2, 0, true };
-    ss = new TcpPduSplitter(true, c);
+    TlvPduConfig c = { 1, 2, 0, true };
+    ss = new TlvPduSplitter(true, c);
 
     uint32_t fp = 0;
     StreamSplitter::Status result;
@@ -331,8 +331,8 @@ TEST_GROUP(multi_flush)
 
     void setup() override
     {
-        TcpPduConfig c = { 1, 2, 0, true };
-        ss = new TcpPduSplitter(true, c);  // cppcheck-suppress unreadVariable
+        TlvPduConfig c = { 1, 2, 0, true };
+        ss = new TlvPduSplitter(true, c);  // cppcheck-suppress unreadVariable
     }
     void teardown() override
     { delete ss; }
similarity index 87%
rename from src/service_inspectors/tcp_pdu/tcp_pdu.cc
rename to src/service_inspectors/tlv_pdu/tlv_pdu.cc
index f70d91dbca60846f19b48efe1d5b599de2de7684..d4dfd85a2b2b442190b7e6dd271df015a4f3d424 100644 (file)
@@ -16,7 +16,7 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 
-// tcp_pdu.cc author Russ Combs <rucombs@cisco.com>
+// tlv_pdu.cc author Russ Combs <rucombs@cisco.com>
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -27,7 +27,7 @@
 #include "framework/module.h"
 #include "profiler/profiler.h"
 
-#include "tcp_pdu.h"
+#include "tlv_pdu.h"
 
 using namespace snort;
 using namespace std;
@@ -36,7 +36,7 @@ using namespace std;
 // common foo
 //-------------------------------------------------------------------------
 
-#define s_name "tcp_pdu"
+#define s_name "tlv_pdu"
 #define s_help "set TCP flush points based on PDU length field"
 
 static const PegInfo pdu_pegs[] =
@@ -72,10 +72,10 @@ static const Parameter s_params[] =
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-class TcpPduModule : public snort::Module
+class TlvPduModule : public snort::Module
 {
 public:
-    TcpPduModule() : Module(s_name, s_help, s_params)
+    TlvPduModule() : Module(s_name, s_help, s_params)
     { }
 
     const PegInfo* get_pegs() const override
@@ -95,14 +95,14 @@ public:
 
     bool set(const char*, Value&, SnortConfig*) override;
 
-    TcpPduConfig& get_config()
+    TlvPduConfig& get_config()
     { return config; }
 
 private:
-    TcpPduConfig config;
+    TlvPduConfig config;
 };
 
-bool TcpPduModule::set(const char*, Value& v, SnortConfig*)
+bool TlvPduModule::set(const char*, Value& v, SnortConfig*)
 {
     if (v.is("offset"))
         config.offset = v.get_int32();
@@ -123,16 +123,16 @@ bool TcpPduModule::set(const char*, Value& v, SnortConfig*)
 // inspector foo
 //-------------------------------------------------------------------------
 
-class TcpPdu : public Inspector
+class TlvPdu : public Inspector
 {
 public:
-    TcpPdu(TcpPduConfig& c) : config(c) { }
+    TlvPdu(TlvPduConfig& c) : config(c) { }
 
     StreamSplitter* get_splitter(bool c2s) override
-    { return new TcpPduSplitter(c2s, config); }
+    { return new TlvPduSplitter(c2s, config); }
 
 private:
-    TcpPduConfig config;
+    TlvPduConfig config;
 };
 
 //-------------------------------------------------------------------------
@@ -140,15 +140,15 @@ private:
 //-------------------------------------------------------------------------
 
 static Module* mod_ctor()
-{ return new TcpPduModule; }
+{ return new TlvPduModule; }
 
 static void mod_dtor(Module* m)
 { delete m; }
 
 static Inspector* pdu_ctor(Module* m)
 {
-    TcpPduModule* tpm = (TcpPduModule*)m;
-    return new TcpPdu(tpm->get_config());
+    TlvPduModule* tpm = (TlvPduModule*)m;
+    return new TlvPdu(tpm->get_config());
 }
 
 static void pdu_dtor(Inspector* p)
@@ -191,6 +191,6 @@ SO_PUBLIC const BaseApi* snort_plugins[] =
     nullptr
 };
 #else
-const BaseApi* sin_tcp_pdu = &pdu_api.base;
+const BaseApi* sin_tlv_pdu = &pdu_api.base;
 #endif
 
similarity index 89%
rename from src/service_inspectors/tcp_pdu/tcp_pdu.h
rename to src/service_inspectors/tlv_pdu/tlv_pdu.h
index 5c32181f2499730871d2d4d805c090f29e52a8a2..7aa7770535e16074b51132a9e8f09340bbc8aa0e 100644 (file)
@@ -16,7 +16,7 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 
-// tcp_pdu.h author Russ Combs <rucombs@cisco.com>
+// tlv_pdu.h author Russ Combs <rucombs@cisco.com>
 
 // provides a simple flush mechanism for TCP PDUs with
 // a fixed size header containing a length field
@@ -28,7 +28,7 @@
 #include "main/snort_types.h"
 #include "stream/stream_splitter.h"
 
-struct TcpPduConfig
+struct TlvPduConfig
 {
     unsigned size = 0;
     unsigned offset = 0;
@@ -45,17 +45,17 @@ struct PduCounts
 
 extern THREAD_LOCAL PduCounts pdu_counts;
 
-class TcpPduSplitter : public snort::StreamSplitter
+class TlvPduSplitter : public snort::StreamSplitter
 {
 public:
-    TcpPduSplitter(bool b, TcpPduConfig& c) : snort::StreamSplitter(b), config(c) { }
+    TlvPduSplitter(bool b, TlvPduConfig& c) : snort::StreamSplitter(b), config(c) { }
 
     bool is_paf() override { return true; }
 
     Status scan(struct snort::Packet*, const uint8_t*, uint32_t, uint32_t, uint32_t*) override;
 
 private:
-    TcpPduConfig config;
+    TlvPduConfig config;
     unsigned index = 0;
     uint32_t value = 0;
 };
similarity index 93%
rename from src/service_inspectors/tcp_pdu/tcp_pdu_splitter.cc
rename to src/service_inspectors/tlv_pdu/tlv_pdu_splitter.cc
index 5a3e3dcc10eee0428256f90b851d13e3c4d9b88e..b3b05d9c7b4b0d3d5741869b5207804e6e355de3 100644 (file)
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
 
-// tcp_pdu_splitter.cc author Russ Combs <rucombs@cisco.com>
+// tlv_pdu_splitter.cc author Russ Combs <rucombs@cisco.com>
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include "tcp_pdu.h"
+#include "tlv_pdu.h"
 
 using namespace snort;
 
@@ -30,7 +30,7 @@ using namespace snort;
 // splitter foo
 //-------------------------------------------------------------------------
 
-StreamSplitter::Status TcpPduSplitter::scan(Packet*, const uint8_t* data, uint32_t len, uint32_t, uint32_t* fp)
+StreamSplitter::Status TlvPduSplitter::scan(Packet*, const uint8_t* data, uint32_t len, uint32_t, uint32_t* fp)
 {
     ++pdu_counts.scans;
     unsigned prefix = config.offset + config.size;