]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4451: binder: change binding to have single service
authorOleksandr Stepanov -X (ostepano - SOFTSERVE INC at Cisco) <ostepano@cisco.com>
Tue, 24 Sep 2024 18:39:27 +0000 (18:39 +0000)
committerChris Sherwin (chsherwi) <chsherwi@cisco.com>
Tue, 24 Sep 2024 18:39:27 +0000 (18:39 +0000)
Merge in SNORT/snort3 from ~OSTEPANO/snort3:binder_service to master

Squashed commit of the following:

commit 14207b6c9c45c1eac1494a04589a3891195d3a3d
Author: Oleksandr Stepanov <ostepano@cisco.com>
Date:   Wed Sep 18 13:04:28 2024 -0400

    binder: change binding to have single service

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

index 1f8c095bedde75135d05f455024e076a11ae2f3f..d69a3f8d463a0071801ec2a161e9174aaa22b6bf 100644 (file)
@@ -124,7 +124,7 @@ static const Parameter binder_when_params[] =
       "use the given configuration on one or any end of a session" },
 
     { "service", Parameter::PT_STRING, nullptr, nullptr,
-      "space separated list of services" },
+      "name of service to match" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
@@ -245,7 +245,7 @@ bool BinderModule::set(const char* fqn, Value& v, SnortConfig*)
     // both
     if ( !strcmp(fqn, "binder.when.service") )
     {
-        binding.when.parse_service(v.get_string());
+        binding.when.svc = v.get_string();
         binding.when.add_criteria(BindWhen::Criteria::BWC_SVC);
     }
     else if ( !strcmp(fqn, "binder.use.service") )
@@ -488,7 +488,7 @@ bool BinderModule::end(const char* fqn, int idx, SnortConfig* sc)
 void BinderModule::add(const char* svc, const char* type)
 {
     binding.clear();
-    binding.when.parse_service(svc);
+    binding.when.svc = svc;
     binding.when.add_criteria(BindWhen::Criteria::BWC_SVC);
     binding.use.type = type;
     binding.use.name = type;
index cab438ebcb14d44078dbe2bcaaed5054040e8b47..5481d0215731b3aba6338888363a7ba348d5914c 100644 (file)
@@ -201,7 +201,7 @@ static std::string to_string(const BindWhen& bw)
     }
 
     if (bw.has_criteria(BindWhen::Criteria::BWC_SVC))
-        when += " service = " + bw.get_service_list() + ",";
+        when += " service = " + bw.svc + ",";
 
     if (bw.has_criteria(BindWhen::Criteria::BWC_SPLIT_NETS))
     {
index 9519343e46dbb9e948d0d853d92d91ee1e77ea88..bac7f5a0f023b8741b71419b3554884e41c59d87 100644 (file)
@@ -45,7 +45,7 @@ void Binding::clear()
     when.ips_id_user = 0;
     when.protos = PROTO_BIT__ANY_TYPE;
     when.role = BindWhen::BR_EITHER;
-    when.svc_list.clear();
+    when.svc.clear();
 
     if (when.src_nets)
     {
@@ -587,7 +587,7 @@ inline bool Binding::check_service(const Flow& flow) const
     if (!flow.service)
         return false;
 
-    return when.svc_list.find(flow.service) != when.svc_list.end();
+    return when.svc == flow.service;
 }
 
 inline bool Binding::check_service(const char* service) const
@@ -597,7 +597,7 @@ inline bool Binding::check_service(const char* service) const
     if (!when.has_criteria(BindWhen::Criteria::BWC_SVC))
         return false;
 
-    return when.svc_list.find(service) != when.svc_list.end();
+    return when.svc == service;
 }
 
 inline bool Binding::check_service() const
index d96d4bd702973af1b9c24ed084a87d68089a3cc9..bc27133fba95a422daf7021839312efe24c4fafc 100644 (file)
@@ -21,7 +21,6 @@
 #define BINDING_H
 
 #include <string>
-#include <sstream>
 
 #include "main/policy.h"
 #include "sfip/sf_ipvar.h"
@@ -43,6 +42,7 @@ struct BindWhen
     unsigned ips_id_user;
     unsigned protos;
     Role role;
+    std::string svc;
 
     sfip_var_t* src_nets;
     sfip_var_t* dst_nets;
@@ -52,8 +52,6 @@ struct BindWhen
     PortBitSet src_ports;
     PortBitSet dst_ports;
 
-    std::unordered_set<std::string> svc_list;
-
     std::unordered_set<int32_t> src_intfs;
     std::unordered_set<int32_t> dst_intfs;
 
@@ -87,28 +85,6 @@ struct BindWhen
     { criteria_flags |= flags; }
     bool has_criteria(uint16_t flags) const
     { return (criteria_flags & flags) == flags; }
-
-    void parse_service(const std::string& service)
-    {
-        if (service.find(" ") == std::string::npos)
-        {
-            svc_list.emplace(service);
-            return;
-        }
-
-        std::string buf;
-        std::stringstream ss(service);
-        while(getline(ss, buf, ' '))
-            svc_list.emplace(buf);
-    }
-
-    std::string get_service_list() const
-    {
-        std::string res;
-        for(const auto& entry : svc_list)
-            res += entry;
-        return res;
-    }
 };
 
 struct BindUse