rust: move DetectEngineStateFree out of RustContext

Ticket: 7667

just use it directly, with bindgen, and cfg not test
pull/13884/head
Philippe Antoine 5 months ago committed by Victor Julien
parent 573dd2367e
commit bf6b8510fe

@ -18,7 +18,7 @@
//! Parser registration functions and common interface module.
use std;
use crate::core::{self,DetectEngineState,AppLayerEventType, GenericVar, STREAM_TOSERVER};
use crate::core::{self,AppLayerEventType, GenericVar, STREAM_TOSERVER};
use crate::direction::Direction;
use crate::filecontainer::FileContainer;
use crate::flow::Flow;
@ -29,7 +29,9 @@ use crate::core::StreamingBufferConfig;
// Make the AppLayerEvent derive macro available to users importing
// AppLayerEvent from this module.
pub use suricata_derive::AppLayerEvent;
use suricata_sys::sys::{AppLayerParserState, AppProto};
use suricata_sys::sys::{AppLayerParserState, AppProto, DetectEngineState};
#[cfg(not(test))]
use suricata_sys::sys::{SCDetectEngineStateFree};
/// Cast pointer to a variable, as a mutable reference to an object
///
@ -170,8 +172,11 @@ pub unsafe extern "C" fn SCAppLayerTxDataCleanup(txd: *mut AppLayerTxData) {
impl AppLayerTxData {
pub fn cleanup(&mut self) {
#[cfg(not(test))]
if !self.de_state.is_null() {
core::sc_detect_engine_state_free(self.de_state);
unsafe {
SCDetectEngineStateFree(self.de_state);
}
}
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);

@ -24,7 +24,6 @@ use crate::filecontainer::*;
use crate::flow::Flow;
/// Opaque C types.
pub enum DetectEngineState {}
pub enum AppLayerDecoderEvents {}
pub enum GenericVar {}
@ -81,9 +80,6 @@ pub type SCLogMessageFunc =
subsystem: *const std::os::raw::c_char,
message: *const std::os::raw::c_char) -> std::os::raw::c_int;
pub type DetectEngineStateFreeFunc =
extern "C" fn(state: *mut DetectEngineState);
pub type AppLayerParserTriggerRawStreamInspectionFunc =
extern "C" fn (flow: *mut Flow, direction: i32);
pub type AppLayerDecoderEventsSetEventRawFunc =
@ -148,7 +144,6 @@ pub type GenericVarFreeFunc =
#[repr(C)]
pub struct SuricataContext {
pub SCLogMessage: SCLogMessageFunc,
DetectEngineStateFree: DetectEngineStateFreeFunc,
AppLayerDecoderEventsSetEventRaw: AppLayerDecoderEventsSetEventRawFunc,
AppLayerDecoderEventsFreeEvents: AppLayerDecoderEventsFreeEventsFunc,
pub AppLayerParserTriggerRawStreamInspection: AppLayerParserTriggerRawStreamInspectionFunc,
@ -192,16 +187,6 @@ pub extern "C" fn SCRustInit(context: &'static SuricataContext)
init_ffi(context);
}
/// DetectEngineStateFree wrapper.
pub fn sc_detect_engine_state_free(state: *mut DetectEngineState)
{
unsafe {
if let Some(c) = SC {
(c.DetectEngineStateFree)(state);
}
}
}
/// GenericVarFree wrapper.
pub fn sc_generic_var_free(gvar: *mut GenericVar)
{

@ -386,6 +386,44 @@ extern "C" {
kw: *const SCTransformTableElmt,
) -> ::std::os::raw::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct DeStateStoreItem_ {
pub flags: u32,
pub sid: u32,
}
pub type DeStateStoreItem = DeStateStoreItem_;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct DeStateStore_ {
pub store: [DeStateStoreItem; 15usize],
pub next: *mut DeStateStore_,
}
pub type DeStateStore = DeStateStore_;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct DetectEngineStateDirection_ {
#[doc = "< head of the list"]
pub head: *mut DeStateStore,
#[doc = "< current active store"]
pub cur: *mut DeStateStore,
#[doc = "< tail of the list"]
pub tail: *mut DeStateStore,
pub cnt: u32,
pub filestore_cnt: u16,
pub flags: u8,
}
pub type DetectEngineStateDirection = DetectEngineStateDirection_;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct DetectEngineState_ {
pub dir_state: [DetectEngineStateDirection; 2usize],
}
pub type DetectEngineState = DetectEngineState_;
extern "C" {
#[doc = " \\brief Frees a DetectEngineState object.\n\n \\param state DetectEngineState instance to free."]
pub fn SCDetectEngineStateFree(state: *mut DetectEngineState);
}
extern "C" {
pub fn SCSigMatchAppendSMToList(
arg1: *mut DetectEngineCtx, arg2: *mut Signature, arg3: u16, arg4: *mut SigMatchCtx,

@ -40,6 +40,7 @@
#include "detect-engine-register.h"
#include "detect-engine-buffer.h"
#include "detect-engine-helper.h"
#include "detect-engine-state.h"
#include "detect-parse.h"
#include "util-debug.h"

@ -166,7 +166,7 @@ DetectEngineState *DetectEngineStateAlloc(void)
return d;
}
void DetectEngineStateFree(DetectEngineState *state)
void SCDetectEngineStateFree(DetectEngineState *state)
{
DeStateStore *store;
DeStateStore *store_next;
@ -417,7 +417,7 @@ static int DeStateTest02(void)
FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->next->store[0].sid != 155);
FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->next->store[1].sid != 166);
DetectEngineStateFree(state);
SCDetectEngineStateFree(state);
PASS;
}
@ -443,7 +443,7 @@ static int DeStateTest03(void)
FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[1].sid != 22);
FAIL_IF(!(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[1].flags & BIT_U32(DE_STATE_FLAG_BASE)));
DetectEngineStateFree(state);
SCDetectEngineStateFree(state);
PASS;
}

@ -34,6 +34,9 @@
#ifndef SURICATA_DETECT_ENGINE_STATE_H
#define SURICATA_DETECT_ENGINE_STATE_H
// forward declaration for bindgen
#define SigIntId uint32_t
#define DETECT_ENGINE_INSPECT_SIG_NO_MATCH 0
#define DETECT_ENGINE_INSPECT_SIG_MATCH 1
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH 2
@ -105,7 +108,7 @@ DetectEngineState *DetectEngineStateAlloc(void);
*
* \param state DetectEngineState instance to free.
*/
void DetectEngineStateFree(DetectEngineState *state);
void SCDetectEngineStateFree(DetectEngineState *state);
#endif /* SURICATA_DETECT_ENGINE_STATE_H */

@ -26,7 +26,6 @@
const SuricataContext suricata_context = {
SCLogMessage,
DetectEngineStateFree,
AppLayerDecoderEventsSetEventRaw,
AppLayerDecoderEventsFreeEvents,
AppLayerParserTriggerRawStreamInspection,

@ -37,7 +37,6 @@ struct AppLayerParser;
typedef struct SuricataContext_ {
SCError (*SCLogMessage)(const SCLogLevel, const char *, const unsigned int, const char *,
const char *, const char *message);
void (*DetectEngineStateFree)(DetectEngineState *);
void (*AppLayerDecoderEventsSetEventRaw)(AppLayerDecoderEvents **,
uint8_t);
void (*AppLayerDecoderEventsFreeEvents)(AppLayerDecoderEvents **);

Loading…
Cancel
Save