]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #899 in SNORT/snort3 from appid_sip_event_handler to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Wed, 17 May 2017 22:09:12 +0000 (18:09 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Wed, 17 May 2017 22:09:12 +0000 (18:09 -0400)
Squashed commit of the following:

commit e0c2723bd9c1e6c9b0c9b2830df5aaa57b615a5b
Author: davis mcpherson <davmcphe.cisco.com>
Date:   Wed May 17 08:50:53 2017 -0400

    refactor appid to instantiate a single instance of the SIP event handler with THREAD_LOCAL variables to hold the pointer to the client/service SIP detectors instantiated in each packet thread.  Subscription to the SIP events moved to the appid inspector configure function that is called from the main thread

src/network_inspectors/appid/appid_inspector.cc
src/network_inspectors/appid/detector_plugins/detector_sip.cc
src/network_inspectors/appid/detector_plugins/detector_sip.h

index 45ce3fd913d66f18223481e26d3764e0a456a1e2..e8d0719042e77a718a0c840a0f1af38b295a616c 100644 (file)
@@ -121,6 +121,8 @@ bool AppIdInspector::configure(SnortConfig*)
     get_data_bus().subscribe(HTTP_RESPONSE_HEADER_EVENT_KEY, new HttpEventHandler(
         HttpEventHandler::RESPONSE_EVENT));
 
+    SipEventHandler::get_instance().subscribe();
+
     return active_config->init_appid();
 
     // FIXIT-M some of this stuff may be needed in some fashion...
index 0c332984e70d0277392f4a0ebac9ff1b5559281a..1b3c1c1b2a465ed6d43af9cded12af4e63ba834f 100644 (file)
@@ -85,7 +85,6 @@ struct DetectorSipConfig
 };
 
 static THREAD_LOCAL DetectorSipConfig detector_sip_config;
-std::mutex SipEventHandler::db_sub_mutex;
 
 static void clean_sip_ua()
 {
@@ -156,9 +155,7 @@ SipUdpClientDetector::SipUdpClientDetector(ClientDiscovery* cdm)
         { APP_ID_SIP, APPINFO_FLAG_CLIENT_ADDITIONAL | APPINFO_FLAG_CLIENT_USER },
     };
 
-    sip_event_handler = &SipEventHandler::get_instance();
-    sip_event_handler->set_client(this);
-    sip_event_handler->subscribe();
+    SipEventHandler::get_instance().set_client(this);
     handler->register_detector(name, this, proto);
 }
 
@@ -351,8 +348,7 @@ void SipServiceDetector::createRtpFlow(AppIdSession* asd, const Packet* pkt, con
 
     // create an RTCP flow as well
     fp2 = AppIdSession::create_future_session(pkt, cliIp, cliPort + 1, srvIp, srvPort + 1, proto,
-        app_id,
-        APPID_EARLY_SESSION_FLAG_FW_RULE);
+        app_id, APPID_EARLY_SESSION_FLAG_FW_RULE);
     if ( fp2 )
     {
         fp2->client_app_id = asd->client_app_id;
@@ -470,6 +466,9 @@ int SipServiceDetector::validate(AppIdDiscoveryArgs& args)
     return APPID_INPROCESS;
 }
 
+THREAD_LOCAL SipUdpClientDetector* SipEventHandler::client = nullptr;
+THREAD_LOCAL SipServiceDetector* SipEventHandler::service = nullptr;
+
 void SipEventHandler::handle(DataEvent& event, Flow* flow)
 {
     AppIdSession* asd = nullptr;
@@ -516,9 +515,6 @@ void SipEventHandler::client_handler(SipEvent& sip_event, AppIdSession* asd)
         asd->set_session_flags(APPID_SESSION_CLIENT_GETS_SERVER_PACKETS);
     }
 
-    if ( fd->owner != client && fd->owner != client )
-        return;
-
     int direction = (sip_event.get_packet()->is_from_client()) ?
         APP_ID_FROM_INITIATOR : APP_ID_FROM_RESPONDER;
 
index c597e3aacf513c310529cb5c9cceff009a56fd6e..2cb491ba6bac8b4dede73fda99cbf6d4e9c487c0 100644 (file)
@@ -55,9 +55,6 @@ public:
     static int sipUaPatternAdd(AppId, const char* clientVersion, const char* uaPattern);
     static int sipServerPatternAdd(AppId, const char* clientVersion, const char* uaPattern);
     static int finalize_sip_ua();
-
-private:
-    SipEventHandler* sip_event_handler = nullptr;
 };
 
 class SipTcpClientDetector : public ClientDetector
@@ -89,17 +86,16 @@ public:
     ~SipEventHandler() { }
     static SipEventHandler& get_instance()
     {
-        static THREAD_LOCAL SipEventHandler* seh = nullptr;
-        if (!seh)
+        static SipEventHandler* seh = nullptr;
+        if(!seh)
             seh = new SipEventHandler;
         return *seh;
     }
 
-    void set_client(SipUdpClientDetector* cd) { client = cd; }
-    void set_service(SipServiceDetector* sd) { service = sd; }
+    void set_client(SipUdpClientDetector* cd) { SipEventHandler::client = cd; }
+    void set_service(SipServiceDetector* sd) { SipEventHandler::service = sd; }
     void subscribe()
     {
-        std::lock_guard<std::mutex> lock(SipEventHandler::db_sub_mutex);
         get_data_bus().subscribe(SIP_EVENT_TYPE_SIP_DIALOG_KEY, this);
     }
 
@@ -110,9 +106,8 @@ private:
     void client_handler(SipEvent&, AppIdSession*);
     void service_handler(SipEvent&, AppIdSession*);
 
-    SipUdpClientDetector* client = nullptr;
-    SipServiceDetector* service = nullptr;
-    static std::mutex db_sub_mutex;
+    static THREAD_LOCAL SipUdpClientDetector* client;
+    static THREAD_LOCAL SipServiceDetector* service;
 };
 #endif