From: Shawn Turner (shaturne) Date: Thu, 8 Dec 2016 16:42:42 +0000 (-0500) Subject: Merge pull request #740 in SNORT/snort3 from thread_local2 to master X-Git-Tag: 3.0.0-233~154 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5307186b24650b7bfca9851db35aa15c89a7f8f2;p=thirdparty%2Fsnort3.git Merge pull request #740 in SNORT/snort3 from thread_local2 to master Squashed commit of the following: commit 0e098bc439fea33fe8dafd4c07c6767630370441 Author: Carter Waxman Date: Wed Dec 7 12:50:51 2016 -0500 fixed dynamic build issues by forcing cross-unit THREAD_LOCAL access through functions --- diff --git a/extra/src/inspectors/http_server/hi_main.cc b/extra/src/inspectors/http_server/hi_main.cc index 71b0b5609..5f4c17b85 100644 --- a/extra/src/inspectors/http_server/hi_main.cc +++ b/extra/src/inspectors/http_server/hi_main.cc @@ -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; } diff --git a/src/detection/detect.cc b/src/detection/detect.cc index 1a62e18ef..eb71b1b57 100644 --- a/src/detection/detect.cc +++ b/src/detection/detect.cc @@ -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*); diff --git a/src/detection/detect.h b/src/detection/detect.h index c8bc2af7b..0e055cfa9 100644 --- a/src/detection/detect.h +++ b/src/detection/detect.h @@ -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 diff --git a/src/detection/detection_util.cc b/src/detection/detection_util.cc index 4254cf701..482ec572c 100644 --- a/src/detection/detection_util.cc +++ b/src/detection/detection_util.cc @@ -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]; diff --git a/src/detection/detection_util.h b/src/detection/detection_util.h index 50d63a6e9..dd6c1b6bb 100644 --- a/src/detection/detection_util.h +++ b/src/detection/detection_util.h @@ -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 diff --git a/src/ips_options/ips_file_data.cc b/src/ips_options/ips_file_data.cc index bad3fadf8..94715dffa 100644 --- a/src/ips_options/ips_file_data.cc +++ b/src/ips_options/ips_file_data.cc @@ -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; } diff --git a/src/log/log_text.cc b/src/log/log_text.cc index 224421aed..12dae1bc3 100644 --- a/src/log/log_text.cc +++ b/src/log/log_text.cc @@ -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 diff --git a/src/service_inspectors/http_inspect/http_msg_body.cc b/src/service_inspectors/http_inspect/http_msg_body.cc index cb3996580..b46f1d291 100644 --- a/src/service_inspectors/http_inspect/http_msg_body.cc +++ b/src/service_inspectors/http_inspect/http_msg_body.cc @@ -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); }