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.
pull/5356/head
Jason Ish 5 years ago committed by Victor Julien
parent 3de98b3595
commit bac8016d17

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

@ -82,3 +82,4 @@ pub mod x509;
pub mod asn1;
pub mod ssh;
pub mod http2;
pub mod plugin;

@ -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);
}
}
Loading…
Cancel
Save