]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: make suricata context const
authorPhilippe Antoine <contact@catenacyber.fr>
Tue, 31 May 2022 11:43:56 +0000 (13:43 +0200)
committerVictor Julien <vjulien@oisf.net>
Thu, 2 Jun 2022 05:33:19 +0000 (07:33 +0200)
So that it is read only and its pointers do not get modified

rust/src/core.rs
src/app-layer-htp-file.h
src/app-layer-register.h
src/rust-context.c
src/rust-context.h
src/suricata.c

index 3ca568bf1c3b3a348020b9386c1d15bba7a4c58f..8c3fee58cb086eb0c307a04e13c3b67939105da5 100644 (file)
@@ -219,7 +219,7 @@ extern {
 
 pub static mut SC: Option<&'static SuricataContext> = None;
 
-pub fn init_ffi(context: &'static mut SuricataContext)
+pub fn init_ffi(context: &'static SuricataContext)
 {
     unsafe {
         SC = Some(context);
@@ -228,7 +228,7 @@ pub fn init_ffi(context: &'static mut SuricataContext)
 }
 
 #[no_mangle]
-pub extern "C" fn rs_init(context: &'static mut SuricataContext)
+pub extern "C" fn rs_init(context: &'static SuricataContext)
 {
     init_ffi(context);
 }
index aa3f132ba0479679386bd2989addb73cce6b7049..8e955c53ef37748e026cff04ec098ac10bd63eb0 100644 (file)
@@ -25,6 +25,8 @@
 #ifndef __APP_LAYER_HTP_FILE_H__
 #define __APP_LAYER_HTP_FILE_H__
 
+#include "app-layer-htp.h"
+
 int HTPFileOpen(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *, uint32_t,
         uint64_t, uint8_t);
 int HTPParseContentRange(bstr *rawvalue, HTTPContentRange *range);
index 4772747eabe4f04a35ab73bddb4fe7d0dc42b52d..2c104fe76a67bd467bb42202a1789ea8bb07fdb5 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef __APP_LAYER_REGISTER_H__
 #define __APP_LAYER_REGISTER_H__
 
+#include "app-layer-detect-proto.h"
+
 typedef struct AppLayerParser {
     const char *name;
     const char *default_port;
index c536d94fb9c1f69c32c79a0b79c2c569dce3bd7d..0e3dd263906fe4640db4f63bf354d50f87c8fa74 100644 (file)
 
 #include "suricata-common.h"
 #include "rust-context.h"
+#include "app-layer-parser.h"
+#include "app-layer-register.h"
+#include "app-layer-htp-range.h"
+#include "app-layer-htp-file.h"
 
-SuricataContext suricata_context;
+const SuricataContext suricata_context = {
+    SCLogMessage,
+    DetectEngineStateFree,
+    AppLayerDecoderEventsSetEventRaw,
+    AppLayerDecoderEventsFreeEvents,
+    AppLayerParserTriggerRawStreamReassembly,
 
-SuricataContext *SCGetContext(void)
+    HttpRangeFreeBlock,
+    HTPFileCloseHandleRange,
+
+    FileOpenFileWithId,
+    FileCloseFileById,
+    FileAppendDataById,
+    FileAppendGAPById,
+    FileContainerRecycle,
+    FilePrune,
+    FileContainerSetTx,
+
+    AppLayerRegisterParser,
+};
+
+const SuricataContext *SCGetContext(void)
 {
     return &suricata_context;
-}
\ No newline at end of file
+}
index 4c43c98d9b471eed63f8521dc835b0e19265badb..a832fc06fe25c1ace29b24883cab41cc3494b028 100644 (file)
@@ -60,7 +60,7 @@ typedef struct SuricataContext_ {
 
 } SuricataContext;
 
-extern SuricataContext suricata_context;
+extern const SuricataContext suricata_context;
 
 typedef struct SuricataFileContext_ {
 
@@ -68,6 +68,6 @@ typedef struct SuricataFileContext_ {
 
 } SuricataFileContext;
 
-SuricataContext *SCGetContext(void);
+const SuricataContext *SCGetContext(void);
 
 #endif /* !__RUST_CONTEXT_H__ */
index 9dcf8b3aa34d6531b1de6bdb631dc7a3969fa4f0..82fd121b572e1a03bd3f682bea0af64a3d3de3f5 100644 (file)
@@ -2786,26 +2786,6 @@ static void SuricataMainLoop(SCInstance *suri)
  */
 
 int InitGlobal(void) {
-    suricata_context.SCLogMessage = SCLogMessage;
-    suricata_context.DetectEngineStateFree = DetectEngineStateFree;
-    suricata_context.AppLayerDecoderEventsSetEventRaw = AppLayerDecoderEventsSetEventRaw;
-    suricata_context.AppLayerDecoderEventsFreeEvents = AppLayerDecoderEventsFreeEvents;
-    suricata_context.AppLayerParserTriggerRawStreamReassembly =
-            AppLayerParserTriggerRawStreamReassembly;
-
-    suricata_context.HttpRangeFreeBlock = HttpRangeFreeBlock;
-    suricata_context.HTPFileCloseHandleRange = HTPFileCloseHandleRange;
-
-    suricata_context.FileOpenFileWithId = FileOpenFileWithId;
-    suricata_context.FileCloseFileById = FileCloseFileById;
-    suricata_context.FileAppendDataById = FileAppendDataById;
-    suricata_context.FileAppendGAPById = FileAppendGAPById;
-    suricata_context.FileContainerRecycle = FileContainerRecycle;
-    suricata_context.FilePrune = FilePrune;
-    suricata_context.FileSetTx = FileContainerSetTx;
-
-    suricata_context.AppLayerRegisterParser = AppLayerRegisterParser;
-
     rs_init(&suricata_context);
 
     SC_ATOMIC_INIT(engine_stage);