]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #740 in SNORT/snort3 from thread_local2 to master
authorShawn Turner (shaturne) <shaturne@cisco.com>
Thu, 8 Dec 2016 16:42:42 +0000 (11:42 -0500)
committerShawn Turner (shaturne) <shaturne@cisco.com>
Thu, 8 Dec 2016 16:42:42 +0000 (11:42 -0500)
Squashed commit of the following:

commit 0e098bc439fea33fe8dafd4c07c6767630370441
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Wed Dec 7 12:50:51 2016 -0500

    fixed dynamic build issues by forcing cross-unit THREAD_LOCAL access through functions

extra/src/inspectors/http_server/hi_main.cc
src/detection/detect.cc
src/detection/detect.h
src/detection/detection_util.cc
src/detection/detection_util.h
src/ips_options/ips_file_data.cc
src/log/log_text.cc
src/service_inspectors/http_inspect/http_msg_body.cc

index 71b0b5609df2e0a1e7938e35f23f498f9533d0a1..5f4c17b851b9f84750683990f3b83c1f4fe63566 100644 (file)
@@ -1225,7 +1225,7 @@ int IsGzipData(Flow* flow)
     if (hsd == NULL)
         return -1;
 
-    if ((hsd->log_flags & HTTP_LOG_GZIP_DATA) && (g_file_data.len > 0 ))
+    if ((hsd->log_flags & HTTP_LOG_GZIP_DATA) && ( get_file_data().len > 0 ))
         return 0;
     else
         return -1;
@@ -1235,8 +1235,10 @@ int GetHttpGzipData(Flow* flow, uint8_t** buf, uint32_t* len, uint32_t* type)
 {
     if (!IsGzipData(flow))
     {
-        *buf = g_file_data.data;
-        *len = g_file_data.len;
+        DataPointer& gzip = get_file_data();
+
+        *buf = gzip.data;
+        *len = gzip.len;
         *type = EVENT_INFO_GZIP_DATA;
         return 1;
     }
@@ -1256,7 +1258,7 @@ int IsJSNormData(Flow* flow)
     if (hsd == NULL)
         return -1;
 
-    if ((hsd->log_flags & HTTP_LOG_JSNORM_DATA) && (g_file_data.len > 0 ))
+    if ((hsd->log_flags & HTTP_LOG_JSNORM_DATA) && ( get_file_data().len > 0 ))
         return 0;
     else
         return -1;
@@ -1266,8 +1268,10 @@ int GetHttpJSNormData(Flow* flow, uint8_t** buf, uint32_t* len, uint32_t* type)
 {
     if (!IsJSNormData(flow))
     {
-        *buf = g_file_data.data;
-        *len = g_file_data.len;
+        DataPointer& js = get_file_data();
+
+        *buf = js.data;
+        *len = js.len;
         *type = EVENT_INFO_JSNORM_DATA;
         return 1;
     }
index 1a62e18eff405d61a3a91d1cea3a46c2c35a5848..eb71b1b57261cade5af61f3c0ecedb701289e55d 100644 (file)
@@ -62,6 +62,12 @@ THREAD_LOCAL ProfileStats rebuiltPacketPerfStats;
 THREAD_LOCAL bool do_detect;
 THREAD_LOCAL bool do_detect_content;
 
+SO_PUBLIC void DisableDetect()
+{ do_detect_content = false; }
+
+SO_PUBLIC void DisableInspection()
+{ do_detect = do_detect_content = false; }
+
 static THREAD_LOCAL char check_tags_flag;
 
 static int CheckTagging(Packet*);
index c8bc2af7b3906da34f7c4f025c5cc2f725e9418c..0e055cfa9d1f0984544f2e49554a9aa520025a1a 100644 (file)
@@ -35,8 +35,8 @@
 
 struct ProfileStats;
 
-extern SO_PUBLIC THREAD_LOCAL bool do_detect;
-extern SO_PUBLIC THREAD_LOCAL bool do_detect_content;
+extern THREAD_LOCAL bool do_detect;
+extern THREAD_LOCAL bool do_detect_content;
 
 extern THREAD_LOCAL ProfileStats eventqPerfStats;
 extern THREAD_LOCAL ProfileStats detectPerfStats;
@@ -70,17 +70,11 @@ void CallAlertFuncs(Packet*, const OptTreeNode*, ListHead*);
 
 // don't eval content rules
 // non-content rules are still evaluated
-inline void DisableDetect()
-{
-    do_detect_content = false;
-}
+SO_PUBLIC void DisableDetect();
 
 // don't want to do any detection with rules
 // (no content and no non-content)
-inline void DisableInspection()
-{
-    do_detect = do_detect_content = false;
-}
+SO_PUBLIC void DisableInspection();
 
 #endif
 
index 4254cf70108135f5a2233e4a7f6dab2d7608fad2..482ec572c22aefea416999e19341ef5e6d50ff4b 100644 (file)
@@ -35,6 +35,15 @@ THREAD_LOCAL DataPointer g_file_data;
 static THREAD_LOCAL TextLog* tlog = NULL;
 static THREAD_LOCAL unsigned nEvents = 0;
 
+SO_PUBLIC DataPointer& get_file_data()
+{ return g_file_data; }
+
+SO_PUBLIC void set_file_data(uint8_t* p, unsigned n)
+{
+    g_file_data.data = p;
+    g_file_data.len = n;
+}
+
 static void LogBuffer(const char* s, const uint8_t* p, unsigned n)
 {
     char hex[(3*LOG_CHARS)+1];
index 50d63a6e9ebc92c955316707c4c5c6b62358328c..dd6c1b6bb9ce6e2fe8a51558f6dc4562c7e7aa9f 100644 (file)
@@ -47,7 +47,7 @@ struct DataBuffer
     unsigned len;
 };
 
-extern SO_PUBLIC THREAD_LOCAL DataPointer g_file_data;
+extern THREAD_LOCAL DataPointer g_file_data;
 
 #define SetDetectLimit(pktPtr, altLen) \
 { \
@@ -56,11 +56,8 @@ extern SO_PUBLIC THREAD_LOCAL DataPointer g_file_data;
 
 #define IsLimitedDetect(pktPtr) (pktPtr->packet_flags & PKT_HTTP_DECODE)
 
-inline void set_file_data(uint8_t* p, unsigned n)
-{
-    g_file_data.data = p;
-    g_file_data.len = n;
-}
+SO_PUBLIC DataPointer& get_file_data();
+SO_PUBLIC void set_file_data(uint8_t*, unsigned);
 
 // FIXIT-L event trace should be placed in its own files
 void EventTrace_Init();
@@ -74,9 +71,7 @@ inline int EventTrace_IsEnabled()
 }
 
 inline void DetectReset()
-{
-    g_file_data.len = 0;
-}
+{ set_file_data(nullptr, 0); }
 
 #endif
 
index bad3fadf82f0167b915f7163b1d807e2173cfb18..94715dffa2f537c0d7a9d6beef9249281e31ad53 100644 (file)
@@ -60,13 +60,12 @@ int FileDataOption::eval(Cursor& c, Packet*)
 {
     Profile profile(fileDataPerfStats);
 
-    uint8_t* data = g_file_data.data;
-    uint16_t len = g_file_data.len;
+    DataPointer& dp = get_file_data();
 
-    if ( !data || !len )
+    if ( !dp.data || !dp.len )
         return DETECTION_OPTION_NO_MATCH;
 
-    c.set(s_name, data, len);
+    c.set(s_name, dp.data, dp.len);
 
     return DETECTION_OPTION_MATCH;
 }
index 224421aed3bca948049b130d96e27fd121fb2aca..12dae1bc375e7da27787884ba650a53b1e9ef517 100644 (file)
@@ -1466,10 +1466,12 @@ void LogPayload(TextLog* log, Packet* p)
         {
             LogCharData(log, (const char*)p->data, p->dsize);
 
-            if ( g_file_data.len > 0 )
+            DataPointer& fdata = get_file_data();
+
+            if ( fdata.len > 0 )
             {
                 TextLog_Print(log, "%s\n", "File data");
-                LogCharData(log, (const char*)g_file_data.data, g_file_data.len);
+                LogCharData(log, (const char*)fdata.data, fdata.len);
             }
         }
         else
index cb3996580becba978802f804113971579fc14b39..b46f1d2915742c7ece14db6910479c16a523e765 100644 (file)
@@ -201,9 +201,11 @@ void HttpMsgBody::print_body_section(FILE* output)
     detect_data.print(output, "Detect data");
     get_classic_buffer(HTTP_BUFFER_CLIENT_BODY, 0, 0).print(output,
         HttpApi::classic_buffer_names[HTTP_BUFFER_CLIENT_BODY-1]);
-    if (g_file_data.len > 0)
+
+    DataPointer& body = get_file_data();
+    if (body.len > 0)
     {
-        Field(g_file_data.len, g_file_data.data).print(output, "file_data");
+        Field(body.len, body.data).print(output, "file_data");
     }
     HttpMsgSection::print_section_wrapup(output);
 }