From: Jason Ish Date: Tue, 25 Aug 2020 16:12:04 +0000 (-0600) Subject: suricata: expose the SuricataContext with a function X-Git-Tag: suricata-6.0.0-rc1~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=335e4e728f3ec3ebd1fc7b6e10b1b9e9ca885d78;p=thirdparty%2Fsuricata.git suricata: expose the SuricataContext with a function 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. --- diff --git a/src/Makefile.am b/src/Makefile.am index a9ec84e269..e707ca9627 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 0000000000..c536d94fb9 --- /dev/null +++ b/src/rust-context.c @@ -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 diff --git a/src/rust-context.h b/src/rust-context.h index 6a68b67354..8efd2678a3 100644 --- a/src/rust-context.h +++ b/src/rust-context.h @@ -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__ */ diff --git a/src/suricata.c b/src/suricata.c index 78d07bde80..676fc7dfa7 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -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);