From: Jason Ish Date: Tue, 25 Aug 2020 18:51:26 +0000 (-0600) Subject: rust: plugin bootstrap function X-Git-Tag: suricata-6.0.0-rc1~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bac8016d1779eabe3d56077f597e7318b71b911c;p=thirdparty%2Fsuricata.git rust: plugin bootstrap function Functions written in Rust will need to suricata::plugin::init() to bootstrap themselves. This bootstrap process sets the log level within the Rust address space, and hooks up function pointers that are expected to be set during normal runs of Suricata. --- diff --git a/rust/src/core.rs b/rust/src/core.rs index 5026cd8dd4..07e49be071 100644 --- a/rust/src/core.rs +++ b/rust/src/core.rs @@ -84,7 +84,7 @@ pub type AppLayerDecoderEventsSetEventRawFunc = pub type AppLayerDecoderEventsFreeEventsFunc = extern "C" fn (events: *mut *mut AppLayerDecoderEvents); -pub struct SuricataStreamingBufferConfig; +pub enum SuricataStreamingBufferConfig {} pub type SCFileOpenFileWithId = extern "C" fn ( file_container: &FileContainer, @@ -145,10 +145,14 @@ pub struct SuricataFileContext { pub files_sbcfg: &'static SuricataStreamingBufferConfig, } +extern { + pub fn SCGetContext() -> &'static mut SuricataContext; + pub fn SCLogGetLogLevel() -> i32; +} + pub static mut SC: Option<&'static SuricataContext> = None; -#[no_mangle] -pub extern "C" fn rs_init(context: &'static mut SuricataContext) +pub fn init_ffi(context: &'static mut SuricataContext) { unsafe { SC = Some(context); @@ -156,6 +160,12 @@ pub extern "C" fn rs_init(context: &'static mut SuricataContext) } } +#[no_mangle] +pub extern "C" fn rs_init(context: &'static mut SuricataContext) +{ + init_ffi(context); +} + /// DetectEngineStateFree wrapper. pub fn sc_detect_engine_state_free(state: *mut DetectEngineState) { diff --git a/rust/src/lib.rs b/rust/src/lib.rs index f0af87bcff..abf9d27e5b 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -82,3 +82,4 @@ pub mod x509; pub mod asn1; pub mod ssh; pub mod http2; +pub mod plugin; \ No newline at end of file diff --git a/rust/src/plugin.rs b/rust/src/plugin.rs new file mode 100644 index 0000000000..f9daef7de4 --- /dev/null +++ b/rust/src/plugin.rs @@ -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. + */ + +pub fn init() { + unsafe { + let context = super::core::SCGetContext(); + super::core::init_ffi(context); + + let level = super::core::SCLogGetLogLevel(); + super::log::log_set_level(level); + } +}