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.
pull/5356/head
Jason Ish 6 years ago committed by Victor Julien
parent 87a91e6aa8
commit 335e4e728f

@ -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 \

@ -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;
}

@ -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__ */

@ -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);

Loading…
Cancel
Save