]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricata: expose the SuricataContext with a function
authorJason Ish <jason.ish@oisf.net>
Tue, 25 Aug 2020 16:12:04 +0000 (10:12 -0600)
committerVictor Julien <victor@inliniac.net>
Thu, 3 Sep 2020 11:04:14 +0000 (13:04 +0200)
Expose the "SuricataContext" required by Rust as a function. During
normal startup we register this context with the Rust code, but
plugins written in Rust will need to get the same registration
done, but to do this in a plugin, the plugin code must
call and set the context within its address space.

src/Makefile.am
src/rust-context.c [new file with mode: 0644]
src/rust-context.h
src/suricata.c

index a9ec84e269b97a8f41848ef040d3a7689a624a06..e707ca962772d9422af1ca3f4623be7ed6245970 100755 (executable)
@@ -422,7 +422,7 @@ runmode-unix-socket.c runmode-unix-socket.h \
 runmode-windivert.c runmode-windivert.h \
 runmodes.c runmodes.h \
 rust.h \
-rust-context.h \
+rust-context.c rust-context.h \
 source-af-packet.c source-af-packet.h \
 source-erf-dag.c source-erf-dag.h \
 source-erf-file.c source-erf-file.h \
diff --git a/src/rust-context.c b/src/rust-context.c
new file mode 100644 (file)
index 0000000..c536d94
--- /dev/null
@@ -0,0 +1,26 @@
+/* Copyright (C) 2020 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "suricata-common.h"
+#include "rust-context.h"
+
+SuricataContext suricata_context;
+
+SuricataContext *SCGetContext(void)
+{
+    return &suricata_context;
+}
\ No newline at end of file
index 6a68b673541b012b189d052698adc3945ac0e57c..8efd2678a3d44d6d73e4fa1134050520e4db7db4 100644 (file)
@@ -48,10 +48,14 @@ typedef struct SuricataContext_ {
 
 } SuricataContext;
 
+extern SuricataContext suricata_context;
+
 typedef struct SuricataFileContext_ {
 
     const StreamingBufferConfig *sbcfg;
 
 } SuricataFileContext;
 
+SuricataContext *SCGetContext(void);
+
 #endif /* !__RUST_CONTEXT_H__ */
index 78d07bde80ca25be52f5f3170fb86cd3ae4f8047..676fc7dfa7e631677c08e80454cf13cb1c857751 100644 (file)
@@ -2664,8 +2664,6 @@ static void SuricataMainLoop(SCInstance *suri)
     }
 }
 
-SuricataContext context;
-
 /**
  * \brief Global initialization common to all runmodes.
  *
@@ -2673,21 +2671,20 @@ SuricataContext context;
  */
 
 int InitGlobal(void) {
-    context.SCLogMessage = SCLogMessage;
-    context.DetectEngineStateFree = DetectEngineStateFree;
-    context.AppLayerDecoderEventsSetEventRaw =
-        AppLayerDecoderEventsSetEventRaw;
-    context.AppLayerDecoderEventsFreeEvents = AppLayerDecoderEventsFreeEvents;
-
-    context.FileOpenFileWithId = FileOpenFileWithId;
-    context.FileCloseFileById = FileCloseFileById;
-    context.FileAppendDataById = FileAppendDataById;
-    context.FileAppendGAPById = FileAppendGAPById;
-    context.FileContainerRecycle = FileContainerRecycle;
-    context.FilePrune = FilePrune;
-    context.FileSetTx = FileContainerSetTx;
-
-    rs_init(&context);
+    suricata_context.SCLogMessage = SCLogMessage;
+    suricata_context.DetectEngineStateFree = DetectEngineStateFree;
+    suricata_context.AppLayerDecoderEventsSetEventRaw = AppLayerDecoderEventsSetEventRaw;
+    suricata_context.AppLayerDecoderEventsFreeEvents = AppLayerDecoderEventsFreeEvents;
+
+    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;
+
+    rs_init(&suricata_context);
 
     SC_ATOMIC_INIT(engine_stage);